void CBC_OneDimWriter::CalcTextInfo(const CFX_ByteString& text, FXTEXT_CHARPOS* charPos, CFX_Font* cFont, FX_FLOAT geWidth, int32_t fontSize, FX_FLOAT& charsLen) { std::unique_ptr<CFX_UnicodeEncodingEx> encoding( FX_CreateFontEncodingEx(cFont)); int32_t length = text.GetLength(); uint32_t* pCharCode = FX_Alloc(uint32_t, text.GetLength()); FX_FLOAT charWidth = 0; for (int32_t j = 0; j < text.GetLength(); j++) { pCharCode[j] = encoding->CharCodeFromUnicode(text[j]); int32_t glyp_code = encoding->GlyphFromCharCode(pCharCode[j]); int32_t glyp_value = cFont->GetGlyphWidth(glyp_code); FX_FLOAT temp = (FX_FLOAT)((glyp_value)*fontSize / 1000.0); charWidth += temp; } charsLen = charWidth; FX_FLOAT leftPositon = (FX_FLOAT)(geWidth - charsLen) / 2.0f; if (leftPositon < 0 && geWidth == 0) { leftPositon = 0; } FX_FLOAT penX = 0.0; FX_FLOAT penY = (FX_FLOAT)FXSYS_abs(cFont->GetDescent()) * (FX_FLOAT)fontSize / 1000.0f; FX_FLOAT left = leftPositon; FX_FLOAT top = 0.0; charPos[0].m_OriginX = penX + left; charPos[0].m_OriginY = penY + top; charPos[0].m_GlyphIndex = encoding->GlyphFromCharCode(pCharCode[0]); charPos[0].m_FontCharWidth = cFont->GetGlyphWidth(charPos[0].m_GlyphIndex); #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ charPos[0].m_ExtGID = charPos[0].m_GlyphIndex; #endif penX += (FX_FLOAT)(charPos[0].m_FontCharWidth) * (FX_FLOAT)fontSize / 1000.0f; for (int32_t i = 1; i < length; i++) { charPos[i].m_OriginX = penX + left; charPos[i].m_OriginY = penY + top; charPos[i].m_GlyphIndex = encoding->GlyphFromCharCode(pCharCode[i]); charPos[i].m_FontCharWidth = cFont->GetGlyphWidth(charPos[i].m_GlyphIndex); #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ charPos[i].m_ExtGID = charPos[i].m_GlyphIndex; #endif penX += (FX_FLOAT)(charPos[i].m_FontCharWidth) * (FX_FLOAT)fontSize / 1000.0f; } FX_Free(pCharCode); }
FX_BOOL CFGAS_GEFont::InitFont() { if (!m_pFont) return FALSE; if (!m_pFontEncoding) { m_pFontEncoding = FX_CreateFontEncodingEx(m_pFont); if (!m_pFontEncoding) return FALSE; } if (!m_pCharWidthMap) m_pCharWidthMap = new CFX_WordDiscreteArray(1024); if (!m_pRectArray) m_pRectArray = new CFX_MassArrayTemplate<CFX_Rect>(16); if (!m_pBBoxMap) m_pBBoxMap = new CFX_MapPtrToPtr(16); return TRUE; }