static HPDF_INT CharWidth (HPDF_Font font, HPDF_BYTE code) { HPDF_FontAttr attr = (HPDF_FontAttr)font->attr; if (attr->used[code] == 0) { HPDF_UNICODE unicode = HPDF_Encoder_ToUnicode (attr->encoder, code); attr->used[code] = 1; attr->widths[code] = HPDF_TTFontDef_GetCharWidth(attr->fontdef, unicode); } return attr->widths[code]; }
static HPDF_INT CharWidth (HPDF_Font font, HPDF_BOOL converted, HPDF_BYTE irf, const HPDF_BYTE *text, HPDF_UINT *bytes, HPDF_UCS4 *ucs4) { HPDF_FontAttr attr = (HPDF_FontAttr)font->attr; HPDF_CODE code = (HPDF_CODE)text[0]; HPDF_UCS4 tmp_ucs4; if (!ucs4 && !converted) ucs4 = &tmp_ucs4; if (ucs4) *ucs4 = HPDF_Encoder_GetUcs4 (attr->encoder, text, bytes); else if (bytes) *bytes = 1; if (converted) { while (irf-- && font) font = ((HPDF_FontAttr)font->attr)->relief_font; } else { font = HPDF_Font_GetReliefFont (font, *ucs4, NULL); } if (!font) return attr->fontdef->missing_width; attr = (HPDF_FontAttr)font->attr; if (attr->used[code] == 0) { if (!ucs4) { ucs4 = &tmp_ucs4; *ucs4 = HPDF_Encoder_GetUcs4 (attr->encoder, text, bytes); } attr->used[code] = 1; attr->widths[code] = HPDF_TTFontDef_GetCharWidth(attr->fontdef, *ucs4); } return attr->widths[code]; }
HPDF_Font_GetUnicodeWidth (HPDF_Font font, HPDF_UNICODE code) { HPDF_FontAttr attr; HPDF_FontDef fontdef; HPDF_PTRACE((" HPDF_Font_GetUnicodeWidth\n")); if (!HPDF_Font_Validate(font)) return 0; attr = (HPDF_FontAttr)font->attr; fontdef = attr->fontdef; if (fontdef->type == HPDF_FONTDEF_TYPE_TYPE1) { return HPDF_Type1FontDef_GetWidth (fontdef, code); } else if (fontdef->type == HPDF_FONTDEF_TYPE_TRUETYPE) { return HPDF_TTFontDef_GetCharWidth (fontdef, code); } else if (fontdef->type == HPDF_FONTDEF_TYPE_CID) { HPDF_CMapEncoderAttr encoder_attr = (HPDF_CMapEncoderAttr)attr->encoder->attr; HPDF_UINT l, h; for (l = 0; l <= 255; l++) { for (h = 0; h < 255; h++) { if (code == encoder_attr->unicode_map[l][h]) { HPDF_UINT16 cid = encoder_attr->cid_map[l][h]; return HPDF_CIDFontDef_GetCIDWidth (fontdef, cid); } } } } HPDF_PTRACE((" HPDF_Font_GetUnicodeWidth not found (0x%04X)\n", code)); return 0; }