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

Unified Diff: core/src/fxge/ge/fx_ge_fontmap.cpp

Issue 1398383002: core/ difference with XFA (for information only). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: After bidi Created 5 years, 2 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/src/fxge/ge/fx_ge_fontmap.cpp
diff --git a/core/src/fxge/ge/fx_ge_fontmap.cpp b/core/src/fxge/ge/fx_ge_fontmap.cpp
index af0a9efdaadc71e0c0cfa3127adcc9eaec471cf9..f531e2ea0e48208d49a98183559ffa8ba6007f76 100644
--- a/core/src/fxge/ge/fx_ge_fontmap.cpp
+++ b/core/src/fxge/ge/fx_ge_fontmap.cpp
@@ -58,10 +58,18 @@ CTTFontDesc::~CTTFontDesc() {
}
FX_Free(m_pFontData);
}
+#ifndef PDF_ENABLE_XFA
FX_BOOL CTTFontDesc::ReleaseFace(FXFT_Face face) {
+#else
+int32_t CTTFontDesc::ReleaseFace(FXFT_Face face) {
+#endif
if (m_Type == 1) {
if (m_SingleFace.m_pFace != face) {
+#ifndef PDF_ENABLE_XFA
return FALSE;
+#else
+ return -1;
+#endif
}
} else if (m_Type == 2) {
int i;
@@ -70,15 +78,27 @@ FX_BOOL CTTFontDesc::ReleaseFace(FXFT_Face face) {
break;
}
if (i == 16) {
+#ifndef PDF_ENABLE_XFA
return FALSE;
+#else
+ return -1;
+#endif
}
}
m_RefCount--;
if (m_RefCount) {
+#ifndef PDF_ENABLE_XFA
return FALSE;
+#else
+ return m_RefCount;
+#endif
}
delete this;
+#ifndef PDF_ENABLE_XFA
return TRUE;
+#else
+ return 0;
+#endif
}
CFX_FontMgr::CFX_FontMgr() : m_FTLibrary(nullptr) {
@@ -357,13 +377,31 @@ void CFX_FontMgr::ReleaseFace(FXFT_Face face) {
if (!face) {
return;
}
+#ifdef PDF_ENABLE_XFA
+ FX_BOOL bNeedFaceDone = TRUE;
+#endif
auto it = m_FaceMap.begin();
while (it != m_FaceMap.end()) {
auto temp = it++;
+#ifndef PDF_ENABLE_XFA
if (temp->second->ReleaseFace(face)) {
+#else
+ int nRet = temp->second->ReleaseFace(face);
+ if (nRet == 0) {
+#endif
m_FaceMap.erase(temp);
+#ifdef PDF_ENABLE_XFA
+ bNeedFaceDone = FALSE;
+ } else if (nRet > 0) {
+ bNeedFaceDone = FALSE;
+#endif
}
}
+#ifdef PDF_ENABLE_XFA
+ if (bNeedFaceDone && !m_pBuiltinMapper->IsBuiltinFace(face)) {
+ FXFT_Done_Face(face);
+ }
+#endif
}
const FoxitFonts g_FoxitFonts[14] = {
{g_FoxitFixedFontData, 17597},
@@ -413,10 +451,19 @@ CFX_FontMapper::CFX_FontMapper(CFX_FontMgr* mgr)
FXSYS_memset(m_FoxitFaces, 0, sizeof(m_FoxitFaces));
}
CFX_FontMapper::~CFX_FontMapper() {
+#ifndef PDF_ENABLE_XFA
for (size_t i = 0; i < FX_ArraySize(m_FoxitFaces); ++i) {
if (m_FoxitFaces[i])
+#else
+ for (int i = 0; i < 14; i++)
+ if (m_FoxitFaces[i]) {
+#endif
FXFT_Done_Face(m_FoxitFaces[i]);
+#ifndef PDF_ENABLE_XFA
}
+#else
+ }
+#endif
if (m_MMFaces[0]) {
FXFT_Done_Face(m_MMFaces[0]);
}
@@ -1055,6 +1102,11 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
pSubstFont->m_SubstFlags |= FXFONT_SUBST_EXACT;
}
if (hFont == NULL) {
+#ifdef PDF_ENABLE_XFA
+ if (flags & FXFONT_EXACTMATCH) {
+ return NULL;
+ }
+#endif
if (bCJK) {
if (italic_angle != 0) {
bItalic = TRUE;
@@ -1180,6 +1232,90 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
m_pFontInfo->DeleteFont(hFont);
return face;
}
+#ifdef PDF_ENABLE_XFA
+FXFT_Face CFX_FontMapper::FindSubstFontByUnicode(FX_DWORD dwUnicode,
+ FX_DWORD flags,
+ int weight,
+ int italic_angle) {
+ if (m_pFontInfo == NULL) {
+ return NULL;
+ }
+ FX_BOOL bItalic = (flags & FXFONT_ITALIC) != 0;
+ int PitchFamily = 0;
+ if (flags & FXFONT_SERIF) {
+ PitchFamily |= FXFONT_FF_ROMAN;
+ }
+ if (flags & FXFONT_SCRIPT) {
+ PitchFamily |= FXFONT_FF_SCRIPT;
+ }
+ if (flags & FXFONT_FIXED_PITCH) {
+ PitchFamily |= FXFONT_FF_FIXEDPITCH;
+ }
+ void* hFont =
+ m_pFontInfo->MapFontByUnicode(dwUnicode, weight, bItalic, PitchFamily);
+ if (hFont == NULL) {
+ return NULL;
+ }
+ FX_DWORD ttc_size = m_pFontInfo->GetFontData(hFont, 0x74746366, NULL, 0);
+ FX_DWORD font_size = m_pFontInfo->GetFontData(hFont, 0, NULL, 0);
+ if (font_size == 0 && ttc_size == 0) {
+ m_pFontInfo->DeleteFont(hFont);
+ return NULL;
+ }
+ FXFT_Face face = NULL;
+ if (ttc_size) {
+ uint8_t temp[1024];
+ m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024);
+ FX_DWORD checksum = 0;
+ for (int i = 0; i < 256; i++) {
+ checksum += ((FX_DWORD*)temp)[i];
+ }
+ uint8_t* pFontData;
+ face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum,
+ ttc_size - font_size, pFontData);
+ if (face == NULL) {
+ pFontData = FX_Alloc(uint8_t, ttc_size);
+ if (pFontData) {
+ m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size);
+ face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData,
+ ttc_size, ttc_size - font_size);
+ }
+ }
+ } else {
+ CFX_ByteString SubstName;
+ m_pFontInfo->GetFaceName(hFont, SubstName);
+ uint8_t* pFontData;
+ face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData);
+ if (face == NULL) {
+ pFontData = FX_Alloc(uint8_t, font_size);
+ if (!pFontData) {
+ m_pFontInfo->DeleteFont(hFont);
+ return NULL;
+ }
+ m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size);
+ face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontData,
+ font_size,
+ m_pFontInfo->GetFaceIndex(hFont));
+ }
+ }
+ m_pFontInfo->DeleteFont(hFont);
+ return face;
+}
+
+FX_BOOL CFX_FontMapper::IsBuiltinFace(const FXFT_Face face) const {
+ for (int i = 0; i < MM_FACE_COUNT; ++i) {
+ if (m_MMFaces[i] == face) {
+ return TRUE;
+ }
+ }
+ for (int i = 0; i < FOXIT_FACE_COUNT; ++i) {
+ if (m_FoxitFaces[i] == face) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+#endif
extern "C" {
unsigned long _FTStreamRead(FXFT_Stream stream,
unsigned long offset,
@@ -1474,6 +1610,14 @@ void* CFX_FolderFontInfo::MapFont(int weight,
int& iExact) {
return NULL;
}
+#ifdef PDF_ENABLE_XFA
+void* CFX_FolderFontInfo::MapFontByUnicode(FX_DWORD dwUnicode,
+ int weight,
+ FX_BOOL bItalic,
+ int pitch_family) {
+ return NULL;
+}
+#endif
void* CFX_FolderFontInfo::GetFont(const FX_CHAR* face) {
auto it = m_FontList.find(face);
return it != m_FontList.end() ? it->second : nullptr;

Powered by Google App Engine
This is Rietveld 408576698