summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-04-12 10:51:04 -0700
committerCommit bot <commit-bot@chromium.org>2016-04-12 10:51:04 -0700
commitea98238666e33cd16b69cb23dcaca047c21c9998 (patch)
treec1a947e835a219872dfacd905188a14b57dc8294 /core
parent6d689942f295565563253e9697a043f87b3796c2 (diff)
downloadpdfium-ea98238666e33cd16b69cb23dcaca047c21c9998.tar.xz
Record all fonts, not just one per charset.
Attempting to open bug_434.pdf on my Linux box would fail with: ../../xfa/fxfa/app/xfa_fwltheme.cpp:96: virtual FWL_ERR CXFA_FWLTheme::Initialize(): Assertion `__null != m_pCalendarFont' failed. I tracked the regression back to [1]. The issue seems to be in CFX_FontManager::AddInstalledFont we will only add one font for a given Charset. In my case I end up loading 6 charsets, but the fonts are all strange ones. When I open the PDF, it fails to find 'Arial' because I've registered these other fonts. To fix this I changed the m_FaceArray into a struct of {name, chraset}. Then we record all fonts into this list and search over that list for the charset when needed. This allows bug_434.pdf to open and the test to pass successfully. 1- https://pdfium.googlesource.com/pdfium/+/fe73e7849b8b4ce49408d2f52f3fc29b370b82b5 Review URL: https://codereview.chromium.org/1874433002
Diffstat (limited to 'core')
-rw-r--r--core/fxge/ge/fx_ge_fontmap.cpp92
-rw-r--r--core/fxge/include/fx_font.h12
2 files changed, 54 insertions, 50 deletions
diff --git a/core/fxge/ge/fx_ge_fontmap.cpp b/core/fxge/ge/fx_ge_fontmap.cpp
index 5ef58b5e79..dc49e3ea37 100644
--- a/core/fxge/ge/fx_ge_fontmap.cpp
+++ b/core/fxge/ge/fx_ge_fontmap.cpp
@@ -741,33 +741,32 @@ CFX_ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont) {
}
void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) {
- if (!m_pFontInfo) {
+ if (!m_pFontInfo)
return;
- }
- if (m_CharsetArray.Find((uint32_t)charset) == -1) {
- m_CharsetArray.Add((uint32_t)charset);
- m_FaceArray.push_back(name);
- }
- if (name == m_LastFamily) {
+
+ m_FaceArray.push_back({name, static_cast<uint32_t>(charset)});
+ if (name == m_LastFamily)
return;
- }
+
const uint8_t* ptr = name.raw_str();
FX_BOOL bLocalized = FALSE;
- for (int i = 0; i < name.GetLength(); i++)
+ for (int i = 0; i < name.GetLength(); i++) {
if (ptr[i] > 0x80) {
bLocalized = TRUE;
break;
}
+ }
+
if (bLocalized) {
void* hFont = m_pFontInfo->GetFont(name);
if (!hFont) {
int iExact;
hFont =
m_pFontInfo->MapFont(0, 0, FXFONT_DEFAULT_CHARSET, 0, name, iExact);
- if (!hFont) {
+ if (!hFont)
return;
- }
}
+
CFX_ByteString new_name = GetPSNameFromTT(hFont);
if (!new_name.IsEmpty()) {
new_name.Insert(0, ' ');
@@ -778,6 +777,7 @@ void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) {
m_InstalledTTFonts.push_back(name);
m_LastFamily = name;
}
+
void CFX_FontMapper::LoadInstalledFonts() {
if (!m_pFontInfo) {
return;
@@ -1155,12 +1155,15 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight,
PitchFamily);
}
- int index = m_CharsetArray.Find(Charset);
- if (index < 0) {
+
+ auto it = std::find_if(
+ m_FaceArray.begin(), m_FaceArray.end(),
+ [Charset](const FaceData& face) { return face.charset == Charset; });
+ if (it == m_FaceArray.end()) {
return UseInternalSubst(pSubstFont, iBaseFont, italic_angle, old_weight,
PitchFamily);
}
- hFont = m_pFontInfo->GetFont(m_FaceArray[index]);
+ hFont = m_pFontInfo->GetFont(it->name);
}
}
pSubstFont->m_ExtHandle = m_pFontInfo->RetainFont(hFont);
@@ -1371,54 +1374,52 @@ void CFX_FolderFontInfo::Release() {
}
FX_BOOL CFX_FolderFontInfo::EnumFontList(CFX_FontMapper* pMapper) {
m_pMapper = pMapper;
- for (const auto& path : m_PathList) {
+ for (const auto& path : m_PathList)
ScanPath(path);
- }
return TRUE;
}
void CFX_FolderFontInfo::ScanPath(const CFX_ByteString& path) {
void* handle = FX_OpenFolder(path);
- if (!handle) {
+ if (!handle)
return;
- }
+
CFX_ByteString filename;
FX_BOOL bFolder;
while (FX_GetNextFile(handle, filename, bFolder)) {
if (bFolder) {
- if (filename == "." || filename == "..") {
+ if (filename == "." || filename == "..")
continue;
- }
} else {
CFX_ByteString ext = filename.Right(4);
ext.MakeUpper();
- if (ext != ".TTF" && ext != ".OTF" && ext != ".TTC") {
+ if (ext != ".TTF" && ext != ".OTF" && ext != ".TTC")
continue;
- }
}
+
CFX_ByteString fullpath = path;
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
fullpath += "\\";
#else
fullpath += "/";
#endif
+
fullpath += filename;
- if (bFolder) {
- ScanPath(fullpath);
- } else {
- ScanFile(fullpath);
- }
+ bFolder ? ScanPath(fullpath) : ScanFile(fullpath);
}
FX_CloseFolder(handle);
}
+
void CFX_FolderFontInfo::ScanFile(const CFX_ByteString& path) {
FXSYS_FILE* pFile = FXSYS_fopen(path, "rb");
- if (!pFile) {
+ if (!pFile)
return;
- }
+
FXSYS_fseek(pFile, 0, FXSYS_SEEK_END);
+
uint32_t filesize = FXSYS_ftell(pFile);
uint8_t buffer[16];
FXSYS_fseek(pFile, 0, FXSYS_SEEK_SET);
+
size_t readCnt = FXSYS_fread(buffer, 12, 1, pFile);
if (readCnt != 1) {
FXSYS_fclose(pFile);
@@ -1455,28 +1456,28 @@ void CFX_FolderFontInfo::ReportFace(const CFX_ByteString& path,
uint32_t offset) {
FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET);
char buffer[16];
- if (!FXSYS_fread(buffer, 12, 1, pFile)) {
+ if (!FXSYS_fread(buffer, 12, 1, pFile))
return;
- }
+
uint32_t nTables = GET_TT_SHORT(buffer + 4);
CFX_ByteString tables = FPDF_ReadStringFromFile(pFile, nTables * 16);
- if (tables.IsEmpty()) {
+ if (tables.IsEmpty())
return;
- }
+
CFX_ByteString names =
FPDF_LoadTableFromTT(pFile, tables.raw_str(), nTables, 0x6e616d65);
- if (names.IsEmpty()) {
+ if (names.IsEmpty())
return;
- }
+
CFX_ByteString facename =
GetNameFromTT(names.raw_str(), names.GetLength(), 1);
- if (facename.IsEmpty()) {
+ if (facename.IsEmpty())
return;
- }
+
CFX_ByteString style = GetNameFromTT(names.raw_str(), names.GetLength(), 2);
- if (style != "Regular") {
+ if (style != "Regular")
facename += " " + style;
- }
+
if (pdfium::ContainsKey(m_FontList, facename))
return;
@@ -1511,24 +1512,21 @@ void CFX_FolderFontInfo::ReportFace(const CFX_ByteString& path,
m_pMapper->AddInstalledFont(facename, FXFONT_ANSI_CHARSET);
pInfo->m_Charsets |= CHARSET_FLAG_ANSI;
pInfo->m_Styles = 0;
- if (style.Find("Bold") > -1) {
+ if (style.Find("Bold") > -1)
pInfo->m_Styles |= FXFONT_BOLD;
- }
- if (style.Find("Italic") > -1 || style.Find("Oblique") > -1) {
+ if (style.Find("Italic") > -1 || style.Find("Oblique") > -1)
pInfo->m_Styles |= FXFONT_ITALIC;
- }
- if (facename.Find("Serif") > -1) {
+ if (facename.Find("Serif") > -1)
pInfo->m_Styles |= FXFONT_SERIF;
- }
+
m_FontList[facename] = pInfo;
}
void* CFX_FolderFontInfo::GetSubstFont(const CFX_ByteString& face) {
for (size_t iBaseFont = 0; iBaseFont < FX_ArraySize(Base14Substs);
iBaseFont++) {
- if (face == Base14Substs[iBaseFont].m_pName) {
+ if (face == Base14Substs[iBaseFont].m_pName)
return GetFont(Base14Substs[iBaseFont].m_pSubstName);
- }
}
return nullptr;
}
diff --git a/core/fxge/include/fx_font.h b/core/fxge/include/fx_font.h
index 48571332ae..37adc832f4 100644
--- a/core/fxge/include/fx_font.h
+++ b/core/fxge/include/fx_font.h
@@ -312,7 +312,9 @@ class CFX_FontMapper {
#endif // PDF_ENABLE_XFA
FX_BOOL IsBuiltinFace(const FXFT_Face face) const;
int GetFaceSize() const;
- CFX_ByteString GetFaceName(int index) const { return m_FaceArray[index]; }
+ CFX_ByteString GetFaceName(int index) const {
+ return m_FaceArray[index].name;
+ }
std::vector<CFX_ByteString> m_InstalledTTFonts;
@@ -328,11 +330,15 @@ class CFX_FontMapper {
int weight,
int picthfamily);
+ struct FaceData {
+ CFX_ByteString name;
+ uint32_t charset;
+ };
+
FX_BOOL m_bListLoaded;
FXFT_Face m_MMFaces[MM_FACE_COUNT];
CFX_ByteString m_LastFamily;
- CFX_ArrayTemplate<uint32_t> m_CharsetArray;
- std::vector<CFX_ByteString> m_FaceArray;
+ std::vector<FaceData> m_FaceArray;
IFX_SystemFontInfo* m_pFontInfo;
FXFT_Face m_FoxitFaces[FOXIT_FACE_COUNT];
CFX_FontMgr* const m_pFontMgr;