Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3021)

Unified Diff: core/fpdfapi/fpdf_render/fpdf_render_text.cpp

Issue 2276653002: Add fallback fonts in pdfium (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Nits Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/fpdfapi/fpdf_render/fpdf_render_text.cpp
diff --git a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp
index 080a7578a77dfa2f7a97a223e7318edfa6e0a23a..759b0fdbf5bbb24ac4899b381e4d5c92984a8011 100644
--- a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp
+++ b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp
@@ -371,6 +371,7 @@ class CPDF_RefType3Cache {
CPDF_Type3Font* const m_pType3Font;
};
+// TODO(npm) Font fallback for type 3 fonts? (Completely separate code!!)
FX_BOOL CPDF_RenderStatus::ProcessType3Text(const CPDF_TextObject* textobj,
const CFX_Matrix* pObj2Device) {
CPDF_Type3Font* pType3Font = textobj->m_TextState.GetFont()->AsType3Font();
@@ -560,6 +561,8 @@ void CPDF_CharPosList::Load(int nChars,
m_nChars = 0;
CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
FX_BOOL bVertWriting = pCIDFont && pCIDFont->IsVertWriting();
+ if (pFont->m_FontPlusFallbacks.size() == 0)
+ pFont->m_FontPlusFallbacks.push_back(&pFont->m_Font);
dsinclair 2016/08/23 19:41:18 Actually, can you just remove this font from the l
npm 2016/08/23 20:36:57 Done.
for (int iChar = 0; iChar < nChars; iChar++) {
uint32_t CharCode =
nChars == 1 ? (uint32_t)(uintptr_t)pCharCodes : pCharCodes[iChar];
@@ -572,6 +575,17 @@ void CPDF_CharPosList::Load(int nChars,
charpos.m_bFontStyle = true;
}
charpos.m_GlyphIndex = pFont->GlyphFromCharCode(CharCode, &bVert);
+ if (charpos.m_GlyphIndex != (uint32_t)-1) {
dsinclair 2016/08/23 19:41:18 static_cast<uint32_t>(-1)
npm 2016/08/23 20:36:57 Done.
+ charpos.m_FallbackFontPosition = 0;
+ } else {
+ charpos.m_FallbackFontPosition =
+ pFont->FallbackFontFromCharcode(CharCode, &bVert);
+ if (charpos.m_FallbackFontPosition > 0) {
+ charpos.m_GlyphIndex = pFont->FallbackGlyphFromCharcode(
+ charpos.m_FallbackFontPosition, CharCode, &bVert);
+ }
+ }
+// TODO(npm) Figure out how this affects m_ExtGID
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode);
#endif
@@ -629,10 +643,27 @@ FX_BOOL CPDF_TextRenderer::DrawTextPath(CFX_RenderDevice* pDevice,
: nullptr;
CPDF_CharPosList CharPosList;
CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size);
- return pDevice->DrawTextPathWithFlags(
- CharPosList.m_nChars, CharPosList.m_pCharPos, &pFont->m_Font, pCache,
- font_size, pText2User, pUser2Device, pGraphState, fill_argb, stroke_argb,
- pClippingPath, nFlag);
+ FX_BOOL bDraw = TRUE;
+ uint32_t pFontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition;
dsinclair 2016/08/23 19:41:18 This bit would have to become a bit smarter to han
npm 2016/08/23 20:36:57 Done.
+ uint32_t pStartIndex = 0;
+ for (uint32_t i = 0; i < CharPosList.m_nChars; i++) {
+ uint32_t pCurFontPosition =
+ CharPosList.m_pCharPos[i].m_FallbackFontPosition;
+ if (pFontPosition != pCurFontPosition) {
+ bDraw &= pDevice->DrawTextPathWithFlags(
+ i - pStartIndex, CharPosList.m_pCharPos + pStartIndex,
+ pFont->m_FontPlusFallbacks[pFontPosition], pCache, font_size,
+ pText2User, pUser2Device, pGraphState, fill_argb, stroke_argb,
+ pClippingPath, nFlag);
+ pFontPosition = pCurFontPosition;
+ pStartIndex = i;
+ }
+ }
+ bDraw &= pDevice->DrawTextPathWithFlags(
+ CharPosList.m_nChars - pStartIndex, CharPosList.m_pCharPos + pStartIndex,
+ pFont->m_FontPlusFallbacks[pFontPosition], pCache, font_size, pText2User,
+ pUser2Device, pGraphState, fill_argb, stroke_argb, pClippingPath, nFlag);
+ return bDraw;
}
// static
@@ -735,9 +766,26 @@ FX_BOOL CPDF_TextRenderer::DrawNormalText(CFX_RenderDevice* pDevice,
if (pFont->IsCIDFont()) {
FXGE_flags |= FXFONT_CIDFONT;
}
- return pDevice->DrawNormalText(CharPosList.m_nChars, CharPosList.m_pCharPos,
- &pFont->m_Font, pCache, font_size,
- pText2Device, fill_argb, FXGE_flags);
+ FX_BOOL bDraw = TRUE;
+ uint32_t pFontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition;
+ uint32_t pStartIndex = 0;
+ for (uint32_t i = 0; i < CharPosList.m_nChars; i++) {
+ uint32_t pCurFontPosition =
+ CharPosList.m_pCharPos[i].m_FallbackFontPosition;
+ if (pFontPosition != pCurFontPosition) {
+ bDraw &= pDevice->DrawNormalText(
+ i - pStartIndex, CharPosList.m_pCharPos + pStartIndex,
+ pFont->m_FontPlusFallbacks[pFontPosition], pCache, font_size,
+ pText2Device, fill_argb, FXGE_flags);
+ pFontPosition = pCurFontPosition;
+ pStartIndex = i;
+ }
+ }
+ bDraw &= pDevice->DrawNormalText(
+ CharPosList.m_nChars - pStartIndex, CharPosList.m_pCharPos + pStartIndex,
+ pFont->m_FontPlusFallbacks[pFontPosition], pCache, font_size,
+ pText2Device, fill_argb, FXGE_flags);
+ return bDraw;
}
void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj,
@@ -770,15 +818,21 @@ void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj,
} else {
pCache = CFX_GEModule::Get()->GetFontCache();
}
- CFX_FaceCache* pFaceCache = pCache->GetCachedFace(&pFont->m_Font);
- CFX_AutoFontCache autoFontCache(pCache, &pFont->m_Font);
CPDF_CharPosList CharPosList;
CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes,
textobj->m_pCharPos, pFont, font_size);
+ std::vector<CFX_FaceCache*> pFaceCaches;
+ std::vector<CFX_AutoFontCache> autoFontCaches;
+ for (auto& font : pFont->m_FontPlusFallbacks) {
+ pFaceCaches.push_back(pCache->GetCachedFace(font));
+ autoFontCaches.push_back(CFX_AutoFontCache(pCache, font));
+ }
for (uint32_t i = 0; i < CharPosList.m_nChars; i++) {
FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i];
- const CFX_PathData* pPath = pFaceCache->LoadGlyphPath(
- &pFont->m_Font, charpos.m_GlyphIndex, charpos.m_FontCharWidth);
+ const CFX_PathData* pPath =
+ pFaceCaches[charpos.m_FallbackFontPosition]->LoadGlyphPath(
+ pFont->m_FontPlusFallbacks[charpos.m_FallbackFontPosition],
+ charpos.m_GlyphIndex, charpos.m_FontCharWidth);
if (!pPath) {
continue;
}

Powered by Google App Engine
This is Rietveld 408576698