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

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

Issue 1425023003: Fix / simplify CFX_FolderFontInfo::GetFontData() behavior. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: cleanup Created 5 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 446744328a7fc192e653ecb013d357137ea79684..d17af0a737c7a52588823ef6b466fbc0655d1668 100644
--- a/core/src/fxge/ge/fx_ge_fontmap.cpp
+++ b/core/src/fxge/ge/fx_ge_fontmap.cpp
@@ -10,6 +10,7 @@
#include "../../../include/fxge/fx_freetype.h"
#include "../fontdata/chromefontdata/chromefontdata.h"
#include "text_int.h"
+#include "third_party/base/stl_util.h"
#define GET_TT_SHORT(w) (FX_WORD)(((w)[0] << 8) | (w)[1])
#define GET_TT_LONG(w) \
@@ -44,6 +45,9 @@ const BuiltinFont g_MMFonts[2] = {
{g_FoxitSansMMFontData, 66919},
};
+const FX_DWORD kTableNAME = 0x6e616d65;
Tom Sepez 2015/11/09 18:27:51 nit: again, want to use a macro to make a big-endi
Lei Zhang 2015/11/09 19:20:00 Done. I locally added a static_assert(kFoo, kFooM
+const FX_DWORD kTableTTCF = 0x74746366;
Tom Sepez 2015/11/09 18:27:51 nit: and FXDWORD_GET_MSBFIRST("ttcf") but doublech
Lei Zhang 2015/11/09 19:20:00 Done.
+
CFX_ByteString KeyNameFromFace(const CFX_ByteString& face_name,
int weight,
FX_BOOL bItalic) {
@@ -514,20 +518,25 @@ CFX_ByteString _FPDF_LoadTableFromTTStreamFile(IFX_FileStream* pFile,
}
return CFX_ByteString();
}
+
CFX_ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont) {
- if (m_pFontInfo == NULL) {
- return CFX_ByteString();
- }
CFX_ByteString result;
Tom Sepez 2015/11/09 18:27:51 nit: no need for "result" local, just return CFX_B
Lei Zhang 2015/11/09 19:20:00 Done. Some say, it makes it easier for compilers t
- FX_DWORD size = m_pFontInfo->GetFontData(hFont, 0x6e616d65, NULL, 0);
- if (size) {
- uint8_t* buffer = FX_Alloc(uint8_t, size);
- m_pFontInfo->GetFontData(hFont, 0x6e616d65, buffer, size);
- result = GetNameFromTT(buffer, 6);
- FX_Free(buffer);
- }
+ if (!m_pFontInfo)
+ return result;
+
+ FX_DWORD size = m_pFontInfo->GetFontData(hFont, kTableNAME, nullptr, 0);
+ if (!size)
+ return result;
+
+ std::vector<uint8_t> buffer(size);
+ uint8_t* buffer_ptr = pdfium::vector_as_array(&buffer);
+ FX_DWORD bytes_read =
+ m_pFontInfo->GetFontData(hFont, kTableNAME, buffer_ptr, size);
+ if (bytes_read == size)
+ result = GetNameFromTT(buffer_ptr, 6);
Tom Sepez 2015/11/09 18:27:51 nit: prefer early return on error.
Lei Zhang 2015/11/09 19:20:00 Acknowledged.
return result;
}
+
void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) {
if (m_pFontInfo == NULL) {
return;
@@ -1112,23 +1121,23 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
}
}
pSubstFont->m_ExtHandle = m_pFontInfo->RetainFont(hFont);
- if (hFont == NULL) {
- return NULL;
- }
+ if (!hFont)
+ return nullptr;
+
m_pFontInfo->GetFaceName(hFont, SubstName);
if (Charset == FXFONT_DEFAULT_CHARSET) {
m_pFontInfo->GetFontCharset(hFont, Charset);
}
- FX_DWORD ttc_size = m_pFontInfo->GetFontData(hFont, 0x74746366, NULL, 0);
- FX_DWORD font_size = m_pFontInfo->GetFontData(hFont, 0, NULL, 0);
+ FX_DWORD ttc_size = m_pFontInfo->GetFontData(hFont, kTableTTCF, nullptr, 0);
+ FX_DWORD font_size = m_pFontInfo->GetFontData(hFont, 0, nullptr, 0);
if (font_size == 0 && ttc_size == 0) {
m_pFontInfo->DeleteFont(hFont);
- return NULL;
+ return nullptr;
}
- FXFT_Face face = NULL;
+ FXFT_Face face = nullptr;
if (ttc_size) {
uint8_t temp[1024];
- m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024);
+ m_pFontInfo->GetFontData(hFont, kTableTTCF, temp, 1024);
FX_DWORD checksum = 0;
for (int i = 0; i < 256; i++) {
checksum += ((FX_DWORD*)temp)[i];
@@ -1138,7 +1147,7 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
ttc_size - font_size, pFontData);
if (face == NULL) {
pFontData = FX_Alloc(uint8_t, ttc_size);
- m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size);
+ m_pFontInfo->GetFontData(hFont, kTableTTCF, pFontData, ttc_size);
face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData,
ttc_size, ttc_size - font_size);
}
@@ -1267,7 +1276,7 @@ void CFX_FolderFontInfo::ScanFile(CFX_ByteString& path) {
return;
}
- if (GET_TT_LONG(buffer) == 0x74746366) {
+ if (GET_TT_LONG(buffer) == kTableTTCF) {
FX_DWORD nFaces = GET_TT_LONG(buffer + 8);
if (nFaces > std::numeric_limits<FX_DWORD>::max() / 4) {
FXSYS_fclose(pFile);
@@ -1306,7 +1315,7 @@ void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path,
return;
}
CFX_ByteString names =
- _FPDF_LoadTableFromTT(pFile, tables, nTables, 0x6e616d65);
+ _FPDF_LoadTableFromTT(pFile, tables, nTables, kTableNAME);
CFX_ByteString facename = GetNameFromTT(names, 1);
CFX_ByteString style = GetNameFromTT(names, 2);
if (style != "Regular") {
@@ -1469,48 +1478,48 @@ void* CFX_FolderFontInfo::GetFont(const FX_CHAR* face) {
auto it = m_FontList.find(face);
return it != m_FontList.end() ? it->second : nullptr;
}
+
FX_DWORD CFX_FolderFontInfo::GetFontData(void* hFont,
FX_DWORD table,
uint8_t* buffer,
FX_DWORD size) {
- if (hFont == NULL) {
+ if (!hFont)
return 0;
- }
- CFX_FontFaceInfo* pFont = (CFX_FontFaceInfo*)hFont;
- FXSYS_FILE* pFile = NULL;
- if (size > 0) {
- pFile = FXSYS_fopen(pFont->m_FilePath, "rb");
- if (pFile == NULL) {
- return 0;
- }
- }
+
+ const CFX_FontFaceInfo* pFont = static_cast<CFX_FontFaceInfo*>(hFont);
FX_DWORD datasize = 0;
FX_DWORD offset = 0;
if (table == 0) {
datasize = pFont->m_FontOffset ? 0 : pFont->m_FileSize;
- } else if (table == 0x74746366) {
+ } else if (table == kTableTTCF) {
datasize = pFont->m_FontOffset ? pFont->m_FileSize : 0;
} else {
FX_DWORD nTables = pFont->m_FontTables.GetLength() / 16;
for (FX_DWORD i = 0; i < nTables; i++) {
- const uint8_t* p = (const uint8_t*)pFont->m_FontTables + i * 16;
+ const uint8_t* p =
+ static_cast<const uint8_t*>(pFont->m_FontTables) + i * 16;
if (GET_TT_LONG(p) == table) {
offset = GET_TT_LONG(p + 8);
datasize = GET_TT_LONG(p + 12);
}
}
}
- if (datasize && size >= datasize && pFile) {
- if (FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET) < 0 ||
- FXSYS_fread(buffer, datasize, 1, pFile) != 1) {
- datasize = 0;
- }
- }
- if (pFile) {
- FXSYS_fclose(pFile);
+
+ if (!datasize || size < datasize)
+ return datasize;
+
+ FXSYS_FILE* pFile = FXSYS_fopen(pFont->m_FilePath, "rb");
+ if (!pFile)
+ return 0;
+
+ if (FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET) < 0 ||
+ FXSYS_fread(buffer, datasize, 1, pFile) != 1) {
+ datasize = 0;
}
+ FXSYS_fclose(pFile);
return datasize;
}
+
void CFX_FolderFontInfo::DeleteFont(void* hFont) {}
FX_BOOL CFX_FolderFontInfo::GetFaceName(void* hFont, CFX_ByteString& name) {
if (hFont == NULL) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698