CFX_PathData* CPDF_Font::LoadGlyphPath(FX_DWORD charcode, int dest_width) { int glyph_index = GlyphFromCharCode(charcode); if (m_Font.m_Face == NULL) { return NULL; } return m_Font.LoadGlyphPath(glyph_index, dest_width); }
FX_DWORD CFX_UnicodeEncoding::GlyphFromCharCodeEx(FX_DWORD charcode, int encoding) { FXFT_Face face = m_pFont->GetFace(); if (!face) { return charcode; } if (encoding == ENCODING_UNICODE) { return GlyphFromCharCode(charcode); } else { int nmaps = FXFT_Get_Face_CharmapCount(m_pFont->m_Face); int i = 0; while (i < nmaps) { int encoding = FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[i++]); if (encoding != FXFT_ENCODING_UNICODE) { FXFT_Select_Charmap(face, encoding); break; } } } return FXFT_Get_Char_Index(face, charcode); }
FX_RECT CPDF_CIDFont::GetCharBBox(uint32_t charcode) { if (charcode < 256 && m_CharBBox[charcode].right != -1) return m_CharBBox[charcode]; FX_RECT rect; bool bVert = false; int glyph_index = GlyphFromCharCode(charcode, &bVert); FXFT_Face face = m_Font.GetFace(); if (face) { if (FXFT_Is_Face_Tricky(face)) { int err = FXFT_Load_Glyph(face, glyph_index, FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); if (!err) { FXFT_BBox cbox; FXFT_Glyph glyph; err = FXFT_Get_Glyph(((FXFT_Face)face)->glyph, &glyph); if (!err) { FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); int pixel_size_x = ((FXFT_Face)face)->size->metrics.x_ppem; int pixel_size_y = ((FXFT_Face)face)->size->metrics.y_ppem; if (pixel_size_x == 0 || pixel_size_y == 0) { rect = FX_RECT(cbox.xMin, cbox.yMax, cbox.xMax, cbox.yMin); } else { rect = FX_RECT(cbox.xMin * 1000 / pixel_size_x, cbox.yMax * 1000 / pixel_size_y, cbox.xMax * 1000 / pixel_size_x, cbox.yMin * 1000 / pixel_size_y); } rect.top = std::min(rect.top, static_cast<int>(FXFT_Get_Face_Ascender(face))); rect.bottom = std::max( rect.bottom, static_cast<int>(FXFT_Get_Face_Descender(face))); FXFT_Done_Glyph(glyph); } } } else { int err = FXFT_Load_Glyph(face, glyph_index, FXFT_LOAD_NO_SCALE); if (err == 0) { rect = FX_RECT(TT2PDF(FXFT_Get_Glyph_HoriBearingX(face), face), TT2PDF(FXFT_Get_Glyph_HoriBearingY(face), face), TT2PDF(FXFT_Get_Glyph_HoriBearingX(face) + FXFT_Get_Glyph_Width(face), face), TT2PDF(FXFT_Get_Glyph_HoriBearingY(face) - FXFT_Get_Glyph_Height(face), face)); rect.top += rect.top / 64; } } } if (!m_pFontFile && m_Charset == CIDSET_JAPAN1) { uint16_t CID = CIDFromCharCode(charcode); const uint8_t* pTransform = GetCIDTransform(CID); if (pTransform && !bVert) { CFX_Matrix matrix(CIDTransformToFloat(pTransform[0]), CIDTransformToFloat(pTransform[1]), CIDTransformToFloat(pTransform[2]), CIDTransformToFloat(pTransform[3]), CIDTransformToFloat(pTransform[4]) * 1000, CIDTransformToFloat(pTransform[5]) * 1000); CFX_FloatRect rect_f(rect); matrix.TransformRect(rect_f); rect = rect_f.GetOuterRect(); } } if (charcode < 256) m_CharBBox[charcode] = rect; return rect; }
int CPDF_Font::GlyphFromCharCodeExt(uint32_t charcode) { return GlyphFromCharCode(charcode, nullptr); }
CFX_PathData* CPDF_Font::LoadGlyphPath(FX_DWORD charcode, int dest_width) { int glyph_index = GlyphFromCharCode(charcode); if (!m_Font.GetFace()) return nullptr; return m_Font.LoadGlyphPath(glyph_index, dest_width); }