📄 gfx_drawlib.c.svn-base
字号:
mapped_lib = RUAMap(pRUA, lib, lib_index->size); if (mapped_lib == NULL) { RMDBGLOG((GFXDBG, "Error mapping font buffer\n")); return RM_ERROR; } for (i = 0; i < lib_index->cnt; i++) { lib_index->tab[i].addr = lib_pos; glyph_start = mapped_lib; get_glyph_pos(lib_index->tab[i].index, tp, &pos, NULL); n_contours = (RMint16) RMbeBufToUint16(pos); RMuint16ToBeBuf(n_contours, mapped_lib); mapped_lib += 4; /* skip two extra bytes (alignment) */ pos += 10; /*skip n_contours + bounding box */ RMMemcpy(mapped_lib, pos, 2 * n_contours); mapped_lib += 2 * n_contours + ((n_contours & 0x1) ? 2 : 0); pos += 2 * (n_contours - 1); n_points = RMbeBufToUint16(pos) + 1; pos += 2; inst_size = RMbeBufToUint16(pos); pos += 2 + inst_size; j = k = x_size = repeat = 0; while (j < n_points) { if (!repeat) { flags = (*pos) & 0x3f; pos++; mapped_lib[k] = flags; k++; if (flags & REPEAT) { repeat = *pos; pos++; mapped_lib[k] = repeat; k++; } } else repeat--; if (flags & XSHORT) { //next byte is for x mapped_lib[k] = X_GOES_HERE; k++; x_size++; } else if (!(flags & XSAME)) { //means xlong //two next bytes are for x mapped_lib[k] = X_GOES_HERE; mapped_lib[k + 1] = X_GOES_HERE; k += 2; x_size += 2; } if (flags & YSHORT) { //next byte is for y mapped_lib[k] = Y_GOES_HERE; k++; } else if (!(flags & YSAME)) { //two following bytes are for y mapped_lib[k] = Y_GOES_HERE; mapped_lib[k + 1] = Y_GOES_HERE; k += 2; } j++; } last_k = k; k = 0; xpos = pos; ypos = xpos + x_size; while (k < last_k) { if (mapped_lib[k] == X_GOES_HERE) { mapped_lib[k] = *xpos; xpos++; } else if (mapped_lib[k] == Y_GOES_HERE) { mapped_lib[k] = *ypos; ypos++; } k++; } mapped_lib += last_k; if ((mapped_lib - glyph_start) & 0x3) mapped_lib += 4 - ((mapped_lib - glyph_start) & 0x3); lib_pos += (mapped_lib - glyph_start); } /*add an entry containing the last position*/ lib_index->tab[lib_index->cnt].addr = lib_pos; /*bad*/ RUAUnMap(pRUA, mapped_lib, lib_index->size); err = RUAUnLock(pRUA, lib, lib_index->size); if (RMFAILED(err)) { RMDBGLOG((GFXDBG, "Error locking OSD buffer\n")); return err; } return RM_OK;}/* returns the number of sub_glyph headers used */static inline RMuint32 add_compound_glyph(RMuint32 glyph_index, struct ttf_subglyph *subs_table, struct glyph_lib_index *lib_index, struct table_ptrs *tp, struct ttf_scale_matrix global_matrix){ struct ttf_scale_matrix new_matrix, local_matrix; RMint16 n_contours; RMuint16 flags; RMuint16 sub_glyph_index; RMuint32 len, sub_table_index = 0; RMuint8* pos; get_glyph_pos(glyph_index, tp, &pos, &len); if (!len) { /* this is very bad */ return 0; } n_contours = (RMint16) RMbeBufToUint16(pos); pos += 10; if (n_contours > 0) { /* we got to a simple glyph, add the subglyph entry */ search_glyph_lib(lib_index, glyph_index, &(subs_table->addr), &(subs_table->size)); RMMemcpy(&(subs_table->scale_matrix), &(global_matrix), sizeof(struct ttf_scale_matrix)); return 1; } do { flags = RMbeBufToUint16(pos); pos += 2; sub_glyph_index = RMbeBufToUint16(pos); pos += 2; if (flags & ARG_1_AND_2_ARE_WORDS) { local_matrix.x_offset = RMbeBufToUint16(pos); pos += 2; local_matrix.y_offset = RMbeBufToUint16(pos); pos += 2; } else { local_matrix.x_offset = *pos; pos++; local_matrix.y_offset = *pos; pos++; } local_matrix.xy_scale = local_matrix.yx_scale = 0; if (flags & WE_HAVE_A_SCALE) { local_matrix.x_scale = local_matrix.y_scale = RMbeBufToUint16(pos); pos += 2; } else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) { local_matrix.x_scale = RMbeBufToUint16(pos); pos += 2; local_matrix.y_scale = RMbeBufToUint16(pos); pos += 2; } else if (flags & WE_HAVE_A_TWO_BY_TWO) { local_matrix.x_scale = RMbeBufToUint16(pos); pos += 2; local_matrix.xy_scale = RMbeBufToUint16(pos); pos += 2; local_matrix.yx_scale = RMbeBufToUint16(pos); pos += 2; local_matrix.y_scale = RMbeBufToUint16(pos); pos += 2; } else { local_matrix.x_scale = local_matrix.y_scale = 1 << 14; } /*0x 1xy 2yx 3y 4ox 5oy*/ /* combine matrices */ new_matrix.x_scale = (global_matrix.x_scale * local_matrix.x_scale + global_matrix.yx_scale * local_matrix.xy_scale) >> 14; new_matrix.xy_scale = (global_matrix.x_scale * local_matrix.yx_scale + global_matrix.yx_scale * local_matrix.y_scale) >> 14; new_matrix.yx_scale = (global_matrix.xy_scale * local_matrix.x_scale + global_matrix.y_scale * local_matrix.xy_scale) >> 14; new_matrix.y_scale = (global_matrix.xy_scale * local_matrix.yx_scale + global_matrix.y_scale * local_matrix.y_scale) >> 14; new_matrix.x_offset = (global_matrix.x_scale * local_matrix.x_offset + global_matrix.yx_scale * local_matrix.y_offset + global_matrix.x_offset) >> 14; new_matrix.y_offset = (global_matrix.xy_scale * local_matrix.x_offset + global_matrix.y_scale * local_matrix.y_offset + global_matrix.y_offset) >> 14; sub_table_index += add_compound_glyph(sub_glyph_index, &(subs_table[sub_table_index]), lib_index, tp, new_matrix); } while (flags & MORE_COMPONENTS); return sub_table_index;}static inline RMstatus upload_glyphs(struct RUA *pRUA, struct ttf_glyph **ppglyph_table, struct ttf_charmap *charmap, struct glyph_lib_index *lib_index, struct ttf_charset *char_set, struct table_ptrs *tp){ struct ttf_glyph *table; struct ttf_subglyph *subs_table; RMuint8 *pos; RMuint32 len; RMuint32 i, glyph_index; RMuint32 table_index, subs_index = 0; RMint16 n_contours = 0; RMuint16 n_lhm; RMuint8 *lhm; RMuint16 n_glyphs, n_subs; RMuint32 table_size, sub_count; RMbool lat1_done; n_glyphs = RMbeBufToUint16(tp->maxp_table + 4/*numGlyphs_off*/); n_lhm = RMbeBufToUint16(tp->hhea_table + 34 /*numOfLongHorMetrics_off*/); lhm = tp->hmtx_table; lib_index->cnt = 0; lib_index->sub_cnt = 0; lib_index->size = 0; /* calculate the size of the whole table first, so we can malloc at once */ sub_count = 0; for (i = 0; i < char_set->char_count; i++) { glyph_index = get_glyph_index_from_charmap(charmap, char_set->unicodes[i]); get_glyph_size(glyph_index, lib_index, tp); } /* do the malloc */ table_size = char_set->char_count * sizeof(struct ttf_glyph); table_size += lib_index->sub_cnt * sizeof(struct ttf_subglyph); if (table_size & 0x3) table_size += 4 - (table_size & 0x3); *ppglyph_table = (struct ttf_glyph *) MALLOC(table_size); table = (*ppglyph_table); subs_table = (struct ttf_subglyph *) ((RMuint8*) (*ppglyph_table) + char_set->char_count * sizeof(struct ttf_glyph)); /* create the lib */ create_glyph_lib(pRUA, lib_index, tp); lat1_done = FALSE; for (i = 0; i < char_set->char_count; i++) { glyph_index = get_glyph_index_from_charmap(charmap, char_set->unicodes[i]); table_index = i;/*get_glyph_index(char_set->char_table[i].font_code);*/ get_glyph_pos(glyph_index, tp, &pos, &len); /* get the metrics first */ if (glyph_index < n_lhm) { table[table_index].metrics.advance = RMbeBufToUint16(lhm + 4 * glyph_index); table[table_index].metrics.leftSideBearing = (RMint16) RMbeBufToUint16(lhm + 4 * glyph_index + 2); } else { table[table_index].metrics.advance = RMbeBufToUint16(lhm + 4 * (n_lhm - 1)); table[table_index].metrics.leftSideBearing = (RMint16) RMbeBufToUint16(lhm + 2 * glyph_index); } if (!len) { table[table_index].subglyph_count = 0; table[table_index].addr = 0x0; table[table_index].size = 0x0; continue; } n_contours = (RMint16) RMbeBufToUint16(pos); pos += 2; table[table_index].metrics.xMin = (RMint16) RMbeBufToUint16(pos); pos += 2; table[table_index].metrics.yMin = (RMint16) RMbeBufToUint16(pos); pos += 2; table[table_index].metrics.xMax = (RMint16) RMbeBufToUint16(pos); pos += 2; table[table_index].metrics.yMax = (RMint16) RMbeBufToUint16(pos); pos += 2; if (n_contours > 0) { /* just link to the correct position on the glyph lib */ search_glyph_lib(lib_index, glyph_index, &(table[table_index].addr), &(table[table_index].size)); table[table_index].subglyph_count = 1; } else { struct ttf_scale_matrix id_matrix = { 1 << 14, 1 << 14, 0, 0, 0, 0 }; printf("whe are here\n"); n_subs = add_compound_glyph(glyph_index, &(subs_table[subs_index]), lib_index, tp, id_matrix); table[table_index].subglyph_count = n_subs; table[table_index].addr = (RMuint32) & (subs_table[subs_index]); table[table_index].size = 0; /* this makes this glyph a compound glyph */ subs_index += n_subs; } } return RM_OK;}static inline RMstatus upload_charmap(struct ttf_charmap *charmap, struct table_ptrs *tp){ RMuint16 num_tables; RMuint32 i, offset = 0; RMuint16 platform, encoding_id; RMuint8 *table_head; table_head = tp->cmap_table; table_head += 2; /* skip version (2) */ num_tables = RMbeBufToUint16(table_head); table_head += 2; for (i = 0; i < num_tables; i++) { platform = RMbeBufToUint16(table_head); table_head += 2; encoding_id = RMbeBufToUint16(table_head); table_head += 2; offset = RMbeBufToUint32(table_head); table_head += 4; if ((platform == 3) && (encoding_id == 1)) { RMuint8 *cmap_fmt4; RMuint16 format, length; RMint32 j; cmap_fmt4 = tp->cmap_table + offset; format = RMbeBufToUint16(cmap_fmt4); cmap_fmt4 += 2; length = RMbeBufToUint16(cmap_fmt4); cmap_fmt4 += 4; /* skip version (2) */ charmap->segCountX2 = RMbeBufToUint16(cmap_fmt4); cmap_fmt4 += 8; /* skip searchRange(2), entrySelector(2), rangeShift(2) */ if (format != 4) { RMDBGLOG((GFXDBG,"Wrong CMAP subtable format\n")); return RM_ERROR; } charmap->ttf_cmap = (RMuint16*) MALLOC(length - 14); for (j = 0; j < (length - 14) / 2; j++) { charmap->ttf_cmap[j] = RMbeBufToUint16(cmap_fmt4); cmap_fmt4 += 2; } return RM_OK; } } return RM_ERROR;}static inline RMstatus open_ttf_file(struct RUA *pRUA, struct RMTTFont *rmfont, RMnonAscii *fname, struct ttf_charset *charset){ RMfile ttf_file; struct ttf_charmap charmap; struct glyph_lib_index lib_index; RMuint32 i, j; RMint64 file_size; RMuint32 read_size; RMstatus err; RMuint8 *file_buf, *file_buf_base; RMuint8 *directory; RMuint16 num_tables; RMuint32 fnt_version; struct table_ptrs tp; struct { RMuint8 **pptb; /* pointer to pointer to the table */ RMascii name[5]; /* table name */ } table_dico[] = { { (RMuint8 **) &(tp.head_table), "head" }, { (RMuint8 **) &(tp.hhea_table), "hhea" }, { (RMuint8 **) &(tp.glyf_start), "glyf" }, { (RMuint8 **) &(tp.cmap_table), "cmap" }, { (RMuint8 **) &(tp.maxp_table), "maxp" }, { (RMuint8 **) &(tp.hmtx_table), "hmtx" }, { (RMuint8 **) &(tp.loca_table), "loca" }, { NULL, "" } /* end of table */ }; err = RMSizeOfFile(fname, &file_size); if (RMFAILED(err)) { RMDBGLOG((GFXDBG, "Error getting file size of %s\n", fname )); return RM_ERROR; } if ((file_buf_base = MALLOC(file_size)) == NULL) { RMDBGLOG((GFXDBG, "Could not allocate 0x%08lx bytes for truetype font buffer\n" )); return RM_ERROR; } if ((ttf_file = RMOpenFile(fname, RM_FILE_OPEN_READ)) == (RMfile) NULL) { RMDBGLOG((GFXDBG, "Could not open file %s\n", fname )); return RM_ERROR; } err = RMReadFile(ttf_file, file_buf_base, file_size, &read_size); if (RMFAILED(err)) { RMDBGLOG((GFXDBG, "Could not read truetype font file %s\n", fname )); return RM_ERROR; } err = RMCloseFile(ttf_file); if (RMFAILED(err)) { RMDBGLOG((GFXDBG, "Could not close file %s\n", fname )); return RM_ERROR; } file_buf = file_buf_base; directory = file_buf; fnt_version = RMbeBufToUint32(directory); directory += 4; num_tables = RMbeBufToUint16(directory); directory += 8; /*skip searchRange(2), entrySelector(2), rangeShift(2)*/ if (fnt_version != 0x00010000) { RMDBGLOG((GFXDBG,"Could not store truetype charmap on memory (read 0x%08lx)\n",fnt_version )); return RM_ERROR; } for (j = 0; table_dico[j].pptb != NULL; j++) *(table_dico[j].pptb) = NULL; for (i = 0; i < num_tables; i++) { RMuint8* tag; RMuint32 offset; tag = directory; directory += 8; /*skip checksum (4) */ offset = RMbeBufToUint32(directory); directory += 8; /*skip length (4)*/ for (j = 0; table_dico[j].pptb != NULL; j++) { if (RMMemcmp(tag, table_dico[j].name, 4) == 0) { *(table_dico[j].pptb) = file_buf + offset; } } } for (j = 0; table_dico[j].pptb != NULL; j++) if ((*(table_dico[j].pptb)) == NULL) { RMDBGLOG((GFXDBG, "Font is missing the '%s' table\n", table_dico[j].name)); return RM_ERROR;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -