summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-04-17 13:07:49 -0700
committerTom Sepez <tsepez@chromium.org>2015-04-17 13:07:49 -0700
commit916228365f7f03a51e5fb0e4bab03fa708b107c5 (patch)
tree39b85d94055aaa4a0bd9e1876ecdc26eb48f2246
parent29bc87d102b9e36c1e15385756c9fa9a214f3503 (diff)
downloadpdfium-916228365f7f03a51e5fb0e4bab03fa708b107c5.tar.xz
Set m_FontType in CPDF_Font() constructor.
This can't change for the life of the object, so tidy up some wild uses throughout the code. Also kill pointless Initialize() method. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1060813003
-rw-r--r--core/include/fpdfapi/fpdf_resource.h29
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font.cpp28
-rw-r--r--core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp2
3 files changed, 17 insertions, 42 deletions
diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h
index 86084d0b72..4a85096900 100644
--- a/core/include/fpdfapi/fpdf_resource.h
+++ b/core/include/fpdfapi/fpdf_resource.h
@@ -76,23 +76,16 @@ typedef CFX_MapPtrTemplate<CPDF_Stream*, CPDF_CountedStreamAcc*> CPDF_FontFil
#define PDFFONT_USEEXTERNATTR 0x80000
FX_WCHAR PDF_UnicodeFromAdobeName(const FX_CHAR* name);
CFX_ByteString PDF_AdobeNameFromUnicode(FX_WCHAR unicode);
-class CPDF_Font
+class CPDF_Font
{
public:
-
static CPDF_Font* CreateFontF(CPDF_Document* pDoc, CPDF_Dictionary* pFontDict);
-
static CPDF_Font* GetStockFont(CPDF_Document* pDoc, FX_BSTR fontname);
virtual ~CPDF_Font();
-
-
-
- int GetFontType() const
- {
- return m_FontType;
- }
+ bool IsFontType(int fonttype) const { return fonttype == m_FontType; }
+ int GetFontType() const { return m_FontType; }
CFX_ByteString GetFontTypeName() const;
@@ -256,9 +249,9 @@ public:
class CFX_PathData* LoadGlyphPath(FX_DWORD charcode, int dest_width = 0);
CFX_Font m_Font;
-protected:
- CPDF_Font();
+protected:
+ explicit CPDF_Font(int fonttype);
FX_BOOL Initialize();
@@ -285,8 +278,6 @@ protected:
- int m_FontType;
-
CFX_ByteString m_BaseFont;
CPDF_StreamAcc* m_pFontFile;
@@ -312,6 +303,8 @@ protected:
int m_ItalicAngle;
+private:
+ const int m_FontType;
};
#define PDFFONT_ENCODING_BUILTIN 0
#define PDFFONT_ENCODING_WINANSI 1
@@ -355,10 +348,8 @@ public:
class CPDF_SimpleFont : public CPDF_Font
{
public:
-
- CPDF_SimpleFont();
-
- virtual ~CPDF_SimpleFont();
+ explicit CPDF_SimpleFont(int fonttype);
+ ~CPDF_SimpleFont() override;
CPDF_FontEncoding* GetEncoding()
{
@@ -469,7 +460,7 @@ class CPDF_Type3Font : public CPDF_SimpleFont
{
public:
CPDF_Type3Font();
- virtual ~CPDF_Type3Font();
+ ~CPDF_Type3Font() override;
void SetPageResources(CPDF_Dictionary* pResources)
{
m_pPageResources = pResources;
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
index eee2a12bb3..66d7d4f026 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
@@ -113,21 +113,15 @@ void CPDF_FontGlobals::ClearAll()
m_pStockMap.RemoveKey(key);
}
}
-CPDF_Font::CPDF_Font()
+CPDF_Font::CPDF_Font(int fonttype) : m_FontType(fonttype)
{
- m_FontType = 0;
m_FontBBox.left = m_FontBBox.right = m_FontBBox.top = m_FontBBox.bottom = 0;
m_StemV = m_Ascent = m_Descent = m_ItalicAngle = 0;
m_pFontFile = NULL;
m_Flags = 0;
m_pToUnicodeMap = NULL;
m_bToUnicodeLoaded = FALSE;
- m_pCharMap = NULL;
-}
-FX_BOOL CPDF_Font::Initialize()
-{
m_pCharMap = new CPDF_FontCharMap(this);
- return TRUE;
}
CPDF_Font::~CPDF_Font()
{
@@ -445,8 +439,6 @@ CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc, CPDF_Dictionary* pFontDic
CPDF_Dictionary* pFontDesc = pFontDict->GetDict(FX_BSTRC("FontDescriptor"));
if (pFontDesc == NULL || !pFontDesc->KeyExist(FX_BSTRC("FontFile2"))) {
pFont = new CPDF_CIDFont;
- pFont->Initialize();
- pFont->m_FontType = PDFFONT_CIDFONT;
pFont->m_pFontDict = pFontDict;
pFont->m_pDocument = pDoc;
if (!pFont->Load()) {
@@ -459,20 +451,12 @@ CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc, CPDF_Dictionary* pFontDic
#endif
}
pFont = new CPDF_TrueTypeFont;
- pFont->Initialize();
- pFont->m_FontType = PDFFONT_TRUETYPE;
} else if (type == FX_BSTRC("Type3")) {
pFont = new CPDF_Type3Font;
- pFont->Initialize();
- pFont->m_FontType = PDFFONT_TYPE3;
} else if (type == FX_BSTRC("Type0")) {
pFont = new CPDF_CIDFont;
- pFont->Initialize();
- pFont->m_FontType = PDFFONT_CIDFONT;
} else {
pFont = new CPDF_Type1Font;
- pFont->Initialize();
- pFont->m_FontType = PDFFONT_TYPE1;
}
pFont->m_pFontDict = pFontDict;
pFont->m_pDocument = pDoc;
@@ -833,7 +817,7 @@ FX_BOOL CPDF_Font::IsStandardFont() const
return TRUE;
}
extern FX_LPCSTR PDF_CharNameFromPredefinedCharSet(int encoding, FX_BYTE charcode);
-CPDF_SimpleFont::CPDF_SimpleFont()
+CPDF_SimpleFont::CPDF_SimpleFont(int fonttype) : CPDF_Font(fonttype)
{
FXSYS_memset8(m_CharBBox, 0xff, sizeof m_CharBBox);
FXSYS_memset8(m_CharWidth, 0xff, sizeof m_CharWidth);
@@ -1031,7 +1015,7 @@ void CPDF_SimpleFont::LoadSubstFont()
}
}
int weight = m_StemV < 140 ? m_StemV * 5 : (m_StemV * 4 + 140);
- m_Font.LoadSubst(m_BaseFont, m_FontType == PDFFONT_TRUETYPE, m_Flags, weight, m_ItalicAngle, 0);
+ m_Font.LoadSubst(m_BaseFont, IsFontType(PDFFONT_TRUETYPE), m_Flags, weight, m_ItalicAngle, 0);
if (m_Font.m_pSubstFont->m_SubstFlags & FXFONT_SUBST_NONSYMBOL) {
}
}
@@ -1040,7 +1024,7 @@ FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const
return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN && m_BaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL &&
m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS;
}
-CPDF_Type1Font::CPDF_Type1Font()
+CPDF_Type1Font::CPDF_Type1Font() : CPDF_SimpleFont(PDFFONT_TYPE1)
{
m_Base14Font = -1;
}
@@ -1432,7 +1416,7 @@ CPDF_Object* CPDF_FontEncoding::Realize()
pDict->SetAt(FX_BSTRC("Differences"), pDiff);
return pDict;
}
-CPDF_TrueTypeFont::CPDF_TrueTypeFont()
+CPDF_TrueTypeFont::CPDF_TrueTypeFont() : CPDF_SimpleFont(PDFFONT_TRUETYPE)
{
}
FX_BOOL CPDF_TrueTypeFont::_Load()
@@ -1614,7 +1598,7 @@ void CPDF_TrueTypeFont::LoadGlyphMap()
m_GlyphIndex[charcode] = charcode;
}
}
-CPDF_Type3Font::CPDF_Type3Font()
+CPDF_Type3Font::CPDF_Type3Font() : CPDF_SimpleFont(PDFFONT_TYPE3)
{
m_pPageResources = NULL;
FXSYS_memset32(m_CharWidthL, 0, sizeof m_CharWidthL);
diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
index afdb35e197..6911942c0e 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp
@@ -693,7 +693,7 @@ void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr, int charset, FX_BOOL bPro
FPDFAPI_LoadCID2UnicodeMap(charset, m_pEmbeddedMap, m_EmbeddedCount);
}
#include "ttgsubtable.h"
-CPDF_CIDFont::CPDF_CIDFont()
+CPDF_CIDFont::CPDF_CIDFont() : CPDF_Font(PDFFONT_CIDFONT)
{
m_pCMap = NULL;
m_pAllocatedCMap = NULL;