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
diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h
index 86084d0..4a85096 100644
--- a/core/include/fpdfapi/fpdf_resource.h
+++ b/core/include/fpdfapi/fpdf_resource.h
@@ -76,23 +76,16 @@
 #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 @@
     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 @@
 
 
 
-    int						m_FontType;
-
     CFX_ByteString			m_BaseFont;
 
     CPDF_StreamAcc*			m_pFontFile;
@@ -312,6 +303,8 @@
 
     int						m_ItalicAngle;
 
+private:
+    const int				m_FontType;
 };
 #define PDFFONT_ENCODING_BUILTIN		0
 #define PDFFONT_ENCODING_WINANSI		1
@@ -355,10 +348,8 @@
 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 @@
 {
 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 eee2a12..66d7d4f 100644
--- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
+++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp
@@ -113,21 +113,15 @@
         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_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 @@
 #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 @@
     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 @@
         }
     }
     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 @@
     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 @@
     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 @@
         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 afdb35e..6911942 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 @@
     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;