summaryrefslogtreecommitdiff
path: root/core/fpdfapi/font/cpdf_font.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-08-04 02:21:44 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-04 02:21:44 +0000
commit03395da5d5827b6b3049d8632d8d3f5545e45293 (patch)
tree910f8e48db49cfc9f88d6e621fd2a183038d6b1d /core/fpdfapi/font/cpdf_font.cpp
parentf21b88ef08d6f6d64e783f55819fc8b86c3b370e (diff)
downloadpdfium-03395da5d5827b6b3049d8632d8d3f5545e45293.tar.xz
Set the CPDF_Font doc / font dict in the ctor.
Then we can mark the doc pointer as const because it never changes again. Also move initialization to headers when possible, add missing dtors, and fix some nits. Change-Id: I461affc8dce14d805b935fb4d8b5aaafb058a789 Reviewed-on: https://pdfium-review.googlesource.com/39413 Reviewed-by: Nicolás Peña Moreno <npm@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/font/cpdf_font.cpp')
-rw-r--r--core/fpdfapi/font/cpdf_font.cpp40
1 files changed, 17 insertions, 23 deletions
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index 0bba1057e7..110770a604 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -31,11 +31,13 @@
namespace {
-const uint8_t kChineseFontNames[][5] = {{0xCB, 0xCE, 0xCC, 0xE5, 0x00},
- {0xBF, 0xAC, 0xCC, 0xE5, 0x00},
- {0xBA, 0xDA, 0xCC, 0xE5, 0x00},
- {0xB7, 0xC2, 0xCB, 0xCE, 0x00},
- {0xD0, 0xC2, 0xCB, 0xCE, 0x00}};
+constexpr size_t kChineseFontNameSize = 4;
+const uint8_t kChineseFontNames[][kChineseFontNameSize] = {
+ {0xCB, 0xCE, 0xCC, 0xE5},
+ {0xBF, 0xAC, 0xCC, 0xE5},
+ {0xBA, 0xDA, 0xCC, 0xE5},
+ {0xB7, 0xC2, 0xCB, 0xCE},
+ {0xD0, 0xC2, 0xCB, 0xCE}};
void GetPredefinedEncoding(const ByteString& value, int* basemap) {
if (value == "WinAnsiEncoding")
@@ -50,15 +52,10 @@ void GetPredefinedEncoding(const ByteString& value, int* basemap) {
} // namespace
-CPDF_Font::CPDF_Font()
- : m_pFontFile(nullptr),
- m_pFontDict(nullptr),
- m_bToUnicodeLoaded(false),
- m_Flags(0),
- m_StemV(0),
- m_Ascent(0),
- m_Descent(0),
- m_ItalicAngle(0) {}
+CPDF_Font::CPDF_Font(CPDF_Document* pDocument, CPDF_Dictionary* pFontDict)
+ : m_pDocument(pDocument),
+ m_pFontDict(pFontDict),
+ m_BaseFont(pFontDict->GetStringFor("BaseFont")) {}
CPDF_Font::~CPDF_Font() {
if (m_pFontFile) {
@@ -323,26 +320,23 @@ std::unique_ptr<CPDF_Font> CPDF_Font::Create(CPDF_Document* pDoc,
if (type == "TrueType") {
ByteString tag = pFontDict->GetStringFor("BaseFont").Left(4);
for (size_t i = 0; i < FX_ArraySize(kChineseFontNames); ++i) {
- if (tag == ByteString(kChineseFontNames[i], 4)) {
+ if (tag == ByteString(kChineseFontNames[i], kChineseFontNameSize)) {
const CPDF_Dictionary* pFontDesc =
pFontDict->GetDictFor("FontDescriptor");
if (!pFontDesc || !pFontDesc->KeyExist("FontFile2"))
- pFont = pdfium::MakeUnique<CPDF_CIDFont>();
+ pFont = pdfium::MakeUnique<CPDF_CIDFont>(pDoc, pFontDict);
break;
}
}
if (!pFont)
- pFont = pdfium::MakeUnique<CPDF_TrueTypeFont>();
+ pFont = pdfium::MakeUnique<CPDF_TrueTypeFont>(pDoc, pFontDict);
} else if (type == "Type3") {
- pFont = pdfium::MakeUnique<CPDF_Type3Font>();
+ pFont = pdfium::MakeUnique<CPDF_Type3Font>(pDoc, pFontDict);
} else if (type == "Type0") {
- pFont = pdfium::MakeUnique<CPDF_CIDFont>();
+ pFont = pdfium::MakeUnique<CPDF_CIDFont>(pDoc, pFontDict);
} else {
- pFont = pdfium::MakeUnique<CPDF_Type1Font>();
+ pFont = pdfium::MakeUnique<CPDF_Type1Font>(pDoc, pFontDict);
}
- pFont->m_pFontDict = pFontDict;
- pFont->m_pDocument = pDoc;
- pFont->m_BaseFont = pFontDict->GetStringFor("BaseFont");
return pFont->Load() ? std::move(pFont) : nullptr;
}