diff options
author | Wei Li <weili@chromium.org> | 2016-02-25 11:35:42 -0800 |
---|---|---|
committer | Wei Li <weili@chromium.org> | 2016-02-25 11:35:42 -0800 |
commit | 6b7b5a52f42aa9b37be5307915885d5f4566c326 (patch) | |
tree | 61c031f3c1f6c7858b04a645f310f41ca0cf42f5 | |
parent | ea1ae9915d1702ab62af520b1487f70a553fc6ae (diff) | |
download | pdfium-6b7b5a52f42aa9b37be5307915885d5f4566c326.tar.xz |
refactor CPDF_Font and subclasses
Get rid of types; use virutal functions instead of type based checking;
remove unused functions; change casts; simplify load()/UnicodeFromCharCode()/CharCodeFromUnicode() calling.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1729823004 .
-rw-r--r-- | core/include/fpdfapi/fpdf_resource.h | 216 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_font/fpdf_font.cpp | 309 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp | 43 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page.cpp | 12 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp | 4 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 8 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp | 18 |
7 files changed, 296 insertions, 314 deletions
diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h index b8504337df..7dbc3fd618 100644 --- a/core/include/fpdfapi/fpdf_resource.h +++ b/core/include/fpdfapi/fpdf_resource.h @@ -82,10 +82,7 @@ class CPDF_CountedObject { }; using CPDF_CountedColorSpace = CPDF_CountedObject<CPDF_ColorSpace>; using CPDF_CountedPattern = CPDF_CountedObject<CPDF_Pattern>; -#define PDFFONT_TYPE1 1 -#define PDFFONT_TRUETYPE 2 -#define PDFFONT_TYPE3 3 -#define PDFFONT_CIDFONT 4 + #define PDFFONT_FIXEDPITCH 1 #define PDFFONT_SERIF 2 #define PDFFONT_SYMBOLIC 4 @@ -96,6 +93,7 @@ using CPDF_CountedPattern = CPDF_CountedObject<CPDF_Pattern>; #define PDFFONT_SMALLCAP 0x20000 #define PDFFONT_FORCEBOLD 0x40000 #define PDFFONT_USEEXTERNATTR 0x80000 + class CPDF_Font { public: static CPDF_Font* CreateFontF(CPDF_Document* pDoc, @@ -106,157 +104,86 @@ class CPDF_Font { virtual ~CPDF_Font(); - bool IsFontType(int fonttype) const { return fonttype == m_FontType; } - int GetFontType() const { return m_FontType; } - - CFX_ByteString GetFontTypeName() const; - - const CFX_ByteString& GetBaseFont() const { return m_BaseFont; } - - const CFX_SubstFont* GetSubstFont() const { return m_Font.GetSubstFont(); } - - FX_DWORD GetFlags() const { return m_Flags; } + virtual bool IsType1Font() const { return false; } + virtual bool IsTrueTypeFont() const { return false; } + virtual bool IsType3Font() const { return false; } + virtual bool IsCIDFont() const { return false; } + virtual const CPDF_Type1Font* AsType1Font() const { return nullptr; } + virtual CPDF_Type1Font* AsType1Font() { return nullptr; } + virtual const CPDF_TrueTypeFont* AsTrueTypeFont() const { return nullptr; } + virtual CPDF_TrueTypeFont* AsTrueTypeFont() { return nullptr; } + virtual const CPDF_Type3Font* AsType3Font() const { return nullptr; } + virtual CPDF_Type3Font* AsType3Font() { return nullptr; } + virtual const CPDF_CIDFont* AsCIDFont() const { return nullptr; } + virtual CPDF_CIDFont* AsCIDFont() { return nullptr; } virtual FX_BOOL IsVertWriting() const; - - CPDF_Type1Font* GetType1Font() const { - return m_FontType == PDFFONT_TYPE1 ? (CPDF_Type1Font*)(void*)this : NULL; - } - - CPDF_TrueTypeFont* GetTrueTypeFont() const { - return m_FontType == PDFFONT_TRUETYPE ? (CPDF_TrueTypeFont*)(void*)this - : NULL; - } - - CPDF_CIDFont* GetCIDFont() const { - return (m_FontType == PDFFONT_CIDFONT) ? (CPDF_CIDFont*)(void*)this : NULL; - } - - CPDF_Type3Font* GetType3Font() const { - return (m_FontType == PDFFONT_TYPE3) ? (CPDF_Type3Font*)(void*)this : NULL; - } - - FX_BOOL IsEmbedded() const { - return m_FontType == PDFFONT_TYPE3 || m_pFontFile != NULL; - } - virtual FX_BOOL IsUnicodeCompatible() const { return FALSE; } - - CPDF_StreamAcc* GetFontFile() const { return m_pFontFile; } - - CPDF_Dictionary* GetFontDict() const { return m_pFontDict; } - - FX_BOOL IsStandardFont() const; - - FXFT_Face GetFace() const { return m_Font.GetFace(); } - virtual FX_DWORD GetNextChar(const FX_CHAR* pString, int nStrLen, - int& offset) const { - if (offset < 0 || nStrLen < 1) { - return 0; - } - uint8_t ch = offset < nStrLen ? pString[offset++] : pString[nStrLen - 1]; - return static_cast<FX_DWORD>(ch); - } - + int& offset) const; virtual int CountChar(const FX_CHAR* pString, int size) const { return size; } - - void AppendChar(CFX_ByteString& str, FX_DWORD charcode) const; - - virtual int AppendChar(FX_CHAR* buf, FX_DWORD charcode) const { - *buf = (FX_CHAR)charcode; - return 1; - } - + virtual int AppendChar(FX_CHAR* buf, FX_DWORD charcode) const; virtual int GetCharSize(FX_DWORD charcode) const { return 1; } - virtual int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph = NULL) = 0; virtual int GlyphFromCharCodeExt(FX_DWORD charcode) { return GlyphFromCharCode(charcode); } + virtual CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const; + virtual FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const; - CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const; - - FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const; + const CFX_ByteString& GetBaseFont() const { return m_BaseFont; } + const CFX_SubstFont* GetSubstFont() const { return m_Font.GetSubstFont(); } + FX_DWORD GetFlags() const { return m_Flags; } + FX_BOOL IsEmbedded() const { return IsType3Font() || m_pFontFile != NULL; } + CPDF_StreamAcc* GetFontFile() const { return m_pFontFile; } + CPDF_Dictionary* GetFontDict() const { return m_pFontDict; } + FX_BOOL IsStandardFont() const; + FXFT_Face GetFace() const { return m_Font.GetFace(); } + void AppendChar(CFX_ByteString& str, FX_DWORD charcode) const; void GetFontBBox(FX_RECT& rect) const { rect = m_FontBBox; } - int GetTypeAscent() const { return m_Ascent; } - int GetTypeDescent() const { return m_Descent; } - int GetItalicAngle() const { return m_ItalicAngle; } - int GetStemV() const { return m_StemV; } - int GetStringWidth(const FX_CHAR* pString, int size); virtual int GetCharWidthF(FX_DWORD charcode, int level = 0) = 0; - - virtual int GetCharTypeWidth(FX_DWORD charcode); - virtual void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) = 0; CPDF_Document* m_pDocument; - - class CFX_PathData* LoadGlyphPath(FX_DWORD charcode, int dest_width = 0); - CFX_Font m_Font; protected: - explicit CPDF_Font(int fonttype); - - FX_BOOL Initialize(); - - FX_BOOL Load(); - - virtual FX_BOOL _Load() = 0; - - virtual FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const = 0; + CPDF_Font(); - virtual FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const = 0; + virtual FX_BOOL Load() = 0; + FX_BOOL Initialize(); void LoadUnicodeMap(); - void LoadPDFEncoding(CPDF_Object* pEncoding, int& iBaseEncoding, CFX_ByteString*& pCharNames, FX_BOOL bEmbedded, FX_BOOL bTrueType); - void LoadFontDescriptor(CPDF_Dictionary*); - - void LoadCharWidths(FX_WORD* pWidths); - void CheckFontMetrics(); CFX_ByteString m_BaseFont; - CPDF_StreamAcc* m_pFontFile; - CPDF_Dictionary* m_pFontDict; - CPDF_ToUnicodeMap* m_pToUnicodeMap; - FX_BOOL m_bToUnicodeLoaded; - int m_Flags; - FX_RECT m_FontBBox; - int m_StemV; - int m_Ascent; - int m_Descent; - int m_ItalicAngle; - - private: - const int m_FontType; }; + #define PDFFONT_ENCODING_BUILTIN 0 #define PDFFONT_ENCODING_WINANSI 1 #define PDFFONT_ENCODING_MACROMAN 2 @@ -267,6 +194,7 @@ class CPDF_Font { #define PDFFONT_ENCODING_PDFDOC 7 #define PDFFONT_ENCODING_MS_SYMBOL 8 #define PDFFONT_ENCODING_UNICODE 9 + class CPDF_FontEncoding { public: CPDF_FontEncoding(); @@ -295,32 +223,25 @@ class CPDF_FontEncoding { class CPDF_SimpleFont : public CPDF_Font { public: - explicit CPDF_SimpleFont(int fonttype); + CPDF_SimpleFont(); ~CPDF_SimpleFont() override; - CPDF_FontEncoding* GetEncoding() { return &m_Encoding; } + // CPDF_Font: int GetCharWidthF(FX_DWORD charcode, int level = 0) override; void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override; int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph = NULL) override; FX_BOOL IsUnicodeCompatible() const override; + CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const override; + FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const override; + + CPDF_FontEncoding* GetEncoding() { return &m_Encoding; } protected: - FX_BOOL LoadCommon(); + virtual void LoadGlyphMap() = 0; + FX_BOOL LoadCommon(); void LoadSubstFont(); - void LoadFaceMetrics(); - - virtual void LoadGlyphMap() = 0; - - FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const override { - return m_Encoding.UnicodeFromCharCode((uint8_t)charcode); - } - - FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const override { - return m_Encoding.CharCodeFromUnicode(Unicode); - } - void LoadCharMetrics(int charcode); CPDF_FontEncoding m_Encoding; @@ -337,23 +258,38 @@ class CPDF_Type1Font : public CPDF_SimpleFont { public: CPDF_Type1Font(); - int GetBase14Font() { return m_Base14Font; } + // CPDF_Font: + bool IsType1Font() const override { return true; } + const CPDF_Type1Font* AsType1Font() const override { return this; } + CPDF_Type1Font* AsType1Font() override { return this; } + int GlyphFromCharCodeExt(FX_DWORD charcode) override; + + int GetBase14Font() const { return m_Base14Font; } protected: + // CPDF_Font: + FX_BOOL Load() override; + // CPDF_SimpleFont: - int GlyphFromCharCodeExt(FX_DWORD charcode) override; - FX_BOOL _Load() override; void LoadGlyphMap() override; int m_Base14Font; }; + class CPDF_TrueTypeFont : public CPDF_SimpleFont { public: CPDF_TrueTypeFont(); + // CPDF_Font: + bool IsTrueTypeFont() const override { return true; } + const CPDF_TrueTypeFont* AsTrueTypeFont() const override { return this; } + CPDF_TrueTypeFont* AsTrueTypeFont() override { return this; } + protected: + // CPDF_Font: + FX_BOOL Load() override; + // CPDF_SimpleFont: - FX_BOOL _Load() override; void LoadGlyphMap() override; }; @@ -378,23 +314,29 @@ class CPDF_Type3Font : public CPDF_SimpleFont { CPDF_Type3Font(); ~CPDF_Type3Font() override; + // CPDF_Font: + bool IsType3Font() const override { return true; } + const CPDF_Type3Font* AsType3Font() const override { return this; } + CPDF_Type3Font* AsType3Font() override { return this; } + int GetCharWidthF(FX_DWORD charcode, int level = 0) override; + void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override; + void SetPageResources(CPDF_Dictionary* pResources) { m_pPageResources = pResources; } CPDF_Type3Char* LoadChar(FX_DWORD charcode, int level = 0); - int GetCharWidthF(FX_DWORD charcode, int level = 0) override; - int GetCharTypeWidth(FX_DWORD charcode) override { - return GetCharWidthF(charcode); - } - void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override; - CFX_Matrix& GetFontMatrix() { return m_FontMatrix; } void CheckType3FontMetrics(); + CFX_Matrix& GetFontMatrix() { return m_FontMatrix; } + protected: CFX_Matrix m_FontMatrix; private: - FX_BOOL _Load() override; + // CPDF_Font: + FX_BOOL Load() override; + + // CPDF_SimpleFont: void LoadGlyphMap() override {} int m_CharWidthL[256]; @@ -417,12 +359,14 @@ enum CIDSet { class CPDF_CIDFont : public CPDF_Font { public: CPDF_CIDFont(); - ~CPDF_CIDFont() override; static FX_FLOAT CIDTransformToFloat(uint8_t ch); // CPDF_Font: + bool IsCIDFont() const override { return true; } + const CPDF_CIDFont* AsCIDFont() const override { return this; } + CPDF_CIDFont* AsCIDFont() override { return this; } int GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph = NULL) override; int GetCharWidthF(FX_DWORD charcode, int level = 0) override; void GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level = 0) override; @@ -434,26 +378,24 @@ class CPDF_CIDFont : public CPDF_Font { int GetCharSize(FX_DWORD charcode) const override; FX_BOOL IsVertWriting() const override; FX_BOOL IsUnicodeCompatible() const override; - FX_BOOL _Load() override; - FX_WCHAR _UnicodeFromCharCode(FX_DWORD charcode) const override; - FX_DWORD _CharCodeFromUnicode(FX_WCHAR Unicode) const override; + FX_BOOL Load() override; + CFX_WideString UnicodeFromCharCode(FX_DWORD charcode) const override; + FX_DWORD CharCodeFromUnicode(FX_WCHAR Unicode) const override; FX_BOOL LoadGB2312(); FX_WORD CIDFromCharCode(FX_DWORD charcode) const; - FX_BOOL IsTrueType() const { return !m_bType1; } const uint8_t* GetCIDTransform(FX_WORD CID) const; short GetVertWidth(FX_WORD CID) const; void GetVertOrigin(FX_WORD CID, short& vx, short& vy) const; virtual FX_BOOL IsFontStyleFromCharCode(FX_DWORD charcode) const; protected: - friend class CPDF_Font; - int GetGlyphIndex(FX_DWORD unicodeb, FX_BOOL* pVertGlyph); void LoadMetricsArray(CPDF_Array* pArray, CFX_DWordArray& result, int nElements); void LoadSubstFont(); + FX_WCHAR GetUnicodeFromCharCode(FX_DWORD charcode) const; CPDF_CMap* m_pCMap; CPDF_CMap* m_pAllocatedCMap; diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp index 1e9335f30f..fb601e7113 100644 --- a/core/src/fpdfapi/fpdf_font/fpdf_font.cpp +++ b/core/src/fpdfapi/fpdf_font/fpdf_font.cpp @@ -19,6 +19,77 @@ #include "core/src/fxge/apple/apple_int.h" #endif +namespace { + +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ +struct GlyphNameMap { + const FX_CHAR* m_pStrAdobe; + const FX_CHAR* m_pStrUnicode; +}; + +const GlyphNameMap g_GlyphNameSubsts[] = {{"ff", "uniFB00"}, + {"fi", "uniFB01"}, + {"fl", "uniFB02"}, + {"ffi", "uniFB03"}, + {"ffl", "uniFB04"}}; + +int compareString(const void* key, const void* element) { + return FXSYS_stricmp((const FX_CHAR*)key, + ((GlyphNameMap*)element)->m_pStrAdobe); +} + +const FX_CHAR* GlyphNameRemap(const FX_CHAR* pStrAdobe) { + GlyphNameMap* found = (GlyphNameMap*)FXSYS_bsearch( + pStrAdobe, g_GlyphNameSubsts, + sizeof(g_GlyphNameSubsts) / sizeof(GlyphNameMap), sizeof(GlyphNameMap), + compareString); + if (found) + return found->m_pStrUnicode; + return NULL; +} +#endif + +const uint8_t ChineseFontNames[][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}}; + +FX_BOOL GetPredefinedEncoding(int& basemap, const CFX_ByteString& value) { + if (value == "WinAnsiEncoding") { + basemap = PDFFONT_ENCODING_WINANSI; + } else if (value == "MacRomanEncoding") { + basemap = PDFFONT_ENCODING_MACROMAN; + } else if (value == "MacExpertEncoding") { + basemap = PDFFONT_ENCODING_MACEXPERT; + } else if (value == "PDFDocEncoding") { + basemap = PDFFONT_ENCODING_PDFDOC; + } else { + return FALSE; + } + return TRUE; +} + +FX_BOOL FT_UseType1Charmap(FXFT_Face face) { + if (FXFT_Get_Face_CharmapCount(face) == 0) { + return FALSE; + } + if (FXFT_Get_Face_CharmapCount(face) == 1 && + FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[0]) == + FXFT_ENCODING_UNICODE) { + return FALSE; + } + if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[0]) == + FXFT_ENCODING_UNICODE) { + FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[1]); + } else { + FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[0]); + } + return TRUE; +} + +} // namespace + FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id) { for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) { if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) == @@ -81,14 +152,17 @@ void CPDF_FontGlobals::Clear(CPDF_Document* pDoc) { m_StockMap.erase(pDoc); } -CPDF_Font::CPDF_Font(int fonttype) : m_FontType(fonttype) { - 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; -} +CPDF_Font::CPDF_Font() + : m_pFontFile(nullptr), + m_pFontDict(nullptr), + m_pToUnicodeMap(nullptr), + m_bToUnicodeLoaded(FALSE), + m_Flags(0), + m_StemV(0), + m_Ascent(0), + m_Descent(0), + m_ItalicAngle(0) {} + CPDF_Font::~CPDF_Font() { delete m_pToUnicodeMap; m_pToUnicodeMap = NULL; @@ -98,9 +172,10 @@ CPDF_Font::~CPDF_Font() { const_cast<CPDF_Stream*>(m_pFontFile->GetStream()->AsStream())); } } + FX_BOOL CPDF_Font::IsVertWriting() const { FX_BOOL bVertWriting = FALSE; - CPDF_CIDFont* pCIDFont = GetCIDFont(); + const CPDF_CIDFont* pCIDFont = AsCIDFont(); if (pCIDFont) { bVertWriting = pCIDFont->IsVertWriting(); } else { @@ -108,19 +183,12 @@ FX_BOOL CPDF_Font::IsVertWriting() const { } return bVertWriting; } -CFX_ByteString CPDF_Font::GetFontTypeName() const { - switch (m_FontType) { - case PDFFONT_TYPE1: - return "Type1"; - case PDFFONT_TRUETYPE: - return "TrueType"; - case PDFFONT_TYPE3: - return "Type3"; - case PDFFONT_CIDFONT: - return "Type0"; - } - return CFX_ByteString(); + +int CPDF_Font::AppendChar(FX_CHAR* buf, FX_DWORD charcode) const { + *buf = (FX_CHAR)charcode; + return 1; } + void CPDF_Font::AppendChar(CFX_ByteString& str, FX_DWORD charcode) const { char buf[4]; int len = AppendChar(buf, charcode); @@ -130,33 +198,23 @@ void CPDF_Font::AppendChar(CFX_ByteString& str, FX_DWORD charcode) const { str += CFX_ByteString(buf, len); } } + CFX_WideString CPDF_Font::UnicodeFromCharCode(FX_DWORD charcode) const { - if (!m_bToUnicodeLoaded) { + if (!m_bToUnicodeLoaded) ((CPDF_Font*)this)->LoadUnicodeMap(); - } - if (m_pToUnicodeMap) { - CFX_WideString wsRet = m_pToUnicodeMap->Lookup(charcode); - if (!wsRet.IsEmpty()) { - return wsRet; - } - } - FX_WCHAR unicode = _UnicodeFromCharCode(charcode); - if (unicode == 0) { - return CFX_WideString(); - } - return unicode; + + if (m_pToUnicodeMap) + return m_pToUnicodeMap->Lookup(charcode); + return CFX_WideString(); } + FX_DWORD CPDF_Font::CharCodeFromUnicode(FX_WCHAR unicode) const { - if (!m_bToUnicodeLoaded) { + if (!m_bToUnicodeLoaded) ((CPDF_Font*)this)->LoadUnicodeMap(); - } - if (m_pToUnicodeMap) { - FX_DWORD charcode = m_pToUnicodeMap->ReverseLookup(unicode); - if (charcode) { - return charcode; - } - } - return _CharCodeFromUnicode(unicode); + + if (m_pToUnicodeMap) + return m_pToUnicodeMap->ReverseLookup(unicode); + return 0; } void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { @@ -233,6 +291,7 @@ short TT2PDF(int m, FXFT_Face face) { } return (m * 1000 + upm / 2) / upm; } + void CPDF_Font::CheckFontMetrics() { if (m_FontBBox.top == 0 && m_FontBBox.bottom == 0 && m_FontBBox.left == 0 && m_FontBBox.right == 0) { @@ -288,6 +347,7 @@ void CPDF_Font::CheckFontMetrics() { } } } + void CPDF_Font::LoadUnicodeMap() { m_bToUnicodeLoaded = TRUE; CPDF_Stream* pStream = m_pFontDict->GetStreamBy("ToUnicode"); @@ -297,6 +357,7 @@ void CPDF_Font::LoadUnicodeMap() { m_pToUnicodeMap = new CPDF_ToUnicodeMap; m_pToUnicodeMap->Load(pStream); } + int CPDF_Font::GetStringWidth(const FX_CHAR* pString, int size) { int offset = 0; int width = 0; @@ -306,16 +367,6 @@ int CPDF_Font::GetStringWidth(const FX_CHAR* pString, int size) { } return width; } -int CPDF_Font::GetCharTypeWidth(FX_DWORD charcode) { - if (!m_Font.GetFace()) - return 0; - - int glyph_index = GlyphFromCharCode(charcode); - if (glyph_index == 0xffff) { - return 0; - } - return m_Font.GetGlyphWidth(glyph_index); -} CPDF_Font* CPDF_Font::GetStockFont(CPDF_Document* pDoc, const CFX_ByteStringC& name) { @@ -339,11 +390,7 @@ CPDF_Font* CPDF_Font::GetStockFont(CPDF_Document* pDoc, pFontGlobals->Set(pDoc, font_id, pFont); return pFont; } -const uint8_t ChineseFontNames[][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}}; + CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc, CPDF_Dictionary* pFontDict) { CFX_ByteString type = pFontDict->GetStringBy("Subtype"); @@ -369,6 +416,7 @@ CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc, pFont = new CPDF_CIDFont; pFont->m_pFontDict = pFontDict; pFont->m_pDocument = pDoc; + pFont->m_BaseFont = pFontDict->GetStringBy("BaseFont"); if (!pFont->Load()) { delete pFont; return NULL; @@ -388,23 +436,13 @@ CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc, } pFont->m_pFontDict = pFontDict; pFont->m_pDocument = pDoc; + pFont->m_BaseFont = pFontDict->GetStringBy("BaseFont"); if (!pFont->Load()) { delete pFont; return NULL; } return pFont; } -FX_BOOL CPDF_Font::Load() { - if (!m_pFontDict) { - return FALSE; - } - CFX_ByteString type = m_pFontDict->GetStringBy("Subtype"); - m_BaseFont = m_pFontDict->GetStringBy("BaseFont"); - if (type == "MMType1") { - type = "Type1"; - } - return _Load(); -} CFX_WideString CPDF_ToUnicodeMap::Lookup(FX_DWORD charcode) { auto it = m_Map.find(charcode); @@ -434,6 +472,7 @@ CFX_WideString CPDF_ToUnicodeMap::Lookup(FX_DWORD charcode) { } return CFX_WideString(); } + FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) { for (const auto& pair : m_Map) { if (pair.second == unicode) @@ -461,6 +500,7 @@ FX_DWORD CPDF_ToUnicodeMap::StringToCode(const CFX_ByteStringC& str) { return result; } + static CFX_WideString StringDataAdd(CFX_WideString str) { CFX_WideString ret; int len = str.GetLength(); @@ -505,6 +545,7 @@ CFX_WideString CPDF_ToUnicodeMap::StringToWideString( } return result; } + void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { CIDSet cid_set = CIDSET_UNKNOWN; CPDF_StreamAcc stream; @@ -612,21 +653,17 @@ void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { m_pBaseMap = NULL; } } -static FX_BOOL GetPredefinedEncoding(int& basemap, - const CFX_ByteString& value) { - if (value == "WinAnsiEncoding") { - basemap = PDFFONT_ENCODING_WINANSI; - } else if (value == "MacRomanEncoding") { - basemap = PDFFONT_ENCODING_MACROMAN; - } else if (value == "MacExpertEncoding") { - basemap = PDFFONT_ENCODING_MACEXPERT; - } else if (value == "PDFDocEncoding") { - basemap = PDFFONT_ENCODING_PDFDOC; - } else { - return FALSE; + +FX_DWORD CPDF_Font::GetNextChar(const FX_CHAR* pString, + int nStrLen, + int& offset) const { + if (offset < 0 || nStrLen < 1) { + return 0; } - return TRUE; + uint8_t ch = offset < nStrLen ? pString[offset++] : pString[nStrLen - 1]; + return static_cast<FX_DWORD>(ch); } + void CPDF_Font::LoadPDFEncoding(CPDF_Object* pEncoding, int& iBaseEncoding, CFX_ByteString*& pCharNames, @@ -697,15 +734,16 @@ void CPDF_Font::LoadPDFEncoding(CPDF_Object* pEncoding, } FX_BOOL CPDF_Font::IsStandardFont() const { - if (m_FontType != PDFFONT_TYPE1) + if (!IsType1Font()) return FALSE; if (m_pFontFile) return FALSE; - if (((CPDF_Type1Font*)this)->GetBase14Font() < 0) + if (AsType1Font()->GetBase14Font() < 0) return FALSE; return TRUE; } -CPDF_SimpleFont::CPDF_SimpleFont(int fonttype) : CPDF_Font(fonttype) { + +CPDF_SimpleFont::CPDF_SimpleFont() { FXSYS_memset(m_CharBBox, 0xff, sizeof m_CharBBox); FXSYS_memset(m_CharWidth, 0xff, sizeof m_CharWidth); FXSYS_memset(m_GlyphIndex, 0xff, sizeof m_GlyphIndex); @@ -713,9 +751,11 @@ CPDF_SimpleFont::CPDF_SimpleFont(int fonttype) : CPDF_Font(fonttype) { m_pCharNames = NULL; m_BaseEncoding = PDFFONT_ENCODING_BUILTIN; } + CPDF_SimpleFont::~CPDF_SimpleFont() { delete[] m_pCharNames; } + int CPDF_SimpleFont::GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph) { if (pVertGlyph) { *pVertGlyph = FALSE; @@ -729,6 +769,7 @@ int CPDF_SimpleFont::GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph) { } return index; } + void CPDF_SimpleFont::LoadCharMetrics(int charcode) { if (!m_Font.GetFace()) return; @@ -772,6 +813,7 @@ void CPDF_SimpleFont::LoadCharMetrics(int charcode) { } } } + int CPDF_SimpleFont::GetCharWidthF(FX_DWORD charcode, int level) { if (charcode > 0xff) { charcode = 0; @@ -784,6 +826,7 @@ int CPDF_SimpleFont::GetCharWidthF(FX_DWORD charcode, int level) { } return (int16_t)m_CharWidth[charcode]; } + void CPDF_SimpleFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) { if (charcode > 0xff) { charcode = 0; @@ -796,6 +839,7 @@ void CPDF_SimpleFont::GetCharBBox(FX_DWORD charcode, FX_RECT& rect, int level) { rect.bottom = m_CharBBox[charcode].Bottom; rect.top = m_CharBBox[charcode].Top; } + const FX_CHAR* GetAdobeCharName(int iBaseEncoding, const CFX_ByteString* pCharNames, int charcode) { @@ -812,6 +856,7 @@ const FX_CHAR* GetAdobeCharName(int iBaseEncoding, } return name && name[0] ? name : nullptr; } + FX_BOOL CPDF_SimpleFont::LoadCommon() { CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictBy("FontDescriptor"); if (pFontDesc) { @@ -880,6 +925,7 @@ FX_BOOL CPDF_SimpleFont::LoadCommon() { CheckFontMetrics(); return TRUE; } + void CPDF_SimpleFont::LoadSubstFont() { if (!m_bUseFontWidth && !(m_Flags & PDFFONT_FIXEDPITCH)) { int width = 0, i; @@ -898,20 +944,38 @@ void CPDF_SimpleFont::LoadSubstFont() { } } int weight = m_StemV < 140 ? m_StemV * 5 : (m_StemV * 4 + 140); - m_Font.LoadSubst(m_BaseFont, IsFontType(PDFFONT_TRUETYPE), m_Flags, weight, - m_ItalicAngle, 0); + m_Font.LoadSubst(m_BaseFont, IsTrueTypeFont(), m_Flags, weight, m_ItalicAngle, + 0); if (m_Font.GetSubstFont()->m_SubstFlags & FXFONT_SUBST_NONSYMBOL) { } } + 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_SimpleFont(PDFFONT_TYPE1) { - m_Base14Font = -1; + +CFX_WideString CPDF_SimpleFont::UnicodeFromCharCode(FX_DWORD charcode) const { + CFX_WideString unicode = CPDF_Font::UnicodeFromCharCode(charcode); + if (!unicode.IsEmpty()) + return unicode; + FX_WCHAR ret = m_Encoding.UnicodeFromCharCode((uint8_t)charcode); + if (ret == 0) + return CFX_WideString(); + return ret; +} + +FX_DWORD CPDF_SimpleFont::CharCodeFromUnicode(FX_WCHAR unicode) const { + FX_DWORD ret = CPDF_Font::CharCodeFromUnicode(unicode); + if (ret) + return ret; + return m_Encoding.CharCodeFromUnicode(unicode); } -FX_BOOL CPDF_Type1Font::_Load() { + +CPDF_Type1Font::CPDF_Type1Font() : m_Base14Font(-1) {} + +FX_BOOL CPDF_Type1Font::Load() { m_Base14Font = PDF_GetStandardFontName(&m_BaseFont); if (m_Base14Font >= 0) { CPDF_Dictionary* pFontDesc = m_pFontDict->GetDictBy("FontDescriptor"); @@ -934,23 +998,7 @@ FX_BOOL CPDF_Type1Font::_Load() { } return LoadCommon(); } -static FX_BOOL FT_UseType1Charmap(FXFT_Face face) { - if (FXFT_Get_Face_CharmapCount(face) == 0) { - return FALSE; - } - if (FXFT_Get_Face_CharmapCount(face) == 1 && - FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[0]) == - FXFT_ENCODING_UNICODE) { - return FALSE; - } - if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmaps(face)[0]) == - FXFT_ENCODING_UNICODE) { - FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[1]); - } else { - FXFT_Set_Charmap(face, FXFT_Get_Face_Charmaps(face)[0]); - } - return TRUE; -} + int CPDF_Type1Font::GlyphFromCharCodeExt(FX_DWORD charcode) { if (charcode > 0xff) { return -1; @@ -961,33 +1009,7 @@ int CPDF_Type1Font::GlyphFromCharCodeExt(FX_DWORD charcode) { } return index; } -#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ -struct _GlyphNameMap { - const FX_CHAR* m_pStrAdobe; - const FX_CHAR* m_pStrUnicode; -}; -static const _GlyphNameMap g_GlyphNameSubsts[] = {{"ff", "uniFB00"}, - {"fi", "uniFB01"}, - {"fl", "uniFB02"}, - {"ffi", "uniFB03"}, - {"ffl", "uniFB04"}}; -extern "C" { -static int compareString(const void* key, const void* element) { - return FXSYS_stricmp((const FX_CHAR*)key, - ((_GlyphNameMap*)element)->m_pStrAdobe); -} -} -static const FX_CHAR* _GlyphNameRemap(const FX_CHAR* pStrAdobe) { - _GlyphNameMap* found = (_GlyphNameMap*)FXSYS_bsearch( - pStrAdobe, g_GlyphNameSubsts, - sizeof g_GlyphNameSubsts / sizeof(_GlyphNameMap), sizeof(_GlyphNameMap), - compareString); - if (found) { - return found->m_pStrUnicode; - } - return NULL; -} -#endif + void CPDF_Type1Font::LoadGlyphMap() { if (!m_Font.GetFace()) return; @@ -1157,7 +1179,7 @@ void CPDF_Type1Font::LoadGlyphMap() { continue; } m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); - const FX_CHAR* pStrUnicode = _GlyphNameRemap(name); + const FX_CHAR* pStrUnicode = GlyphNameRemap(name); if (pStrUnicode && 0 == FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name)) { name = pStrUnicode; @@ -1280,6 +1302,7 @@ void CPDF_Type1Font::LoadGlyphMap() { CPDF_FontEncoding::CPDF_FontEncoding() { FXSYS_memset(m_Unicodes, 0, sizeof(m_Unicodes)); } + int CPDF_FontEncoding::CharCodeFromUnicode(FX_WCHAR unicode) const { for (int i = 0; i < 256; i++) if (m_Unicodes[i] == unicode) { @@ -1287,6 +1310,7 @@ int CPDF_FontEncoding::CharCodeFromUnicode(FX_WCHAR unicode) const { } return -1; } + CPDF_FontEncoding::CPDF_FontEncoding(int PredefinedEncoding) { const FX_WORD* pSrc = PDF_UnicodesForPredefinedCharSet(PredefinedEncoding); if (!pSrc) { @@ -1296,10 +1320,12 @@ CPDF_FontEncoding::CPDF_FontEncoding(int PredefinedEncoding) { m_Unicodes[i] = pSrc[i]; } } + FX_BOOL CPDF_FontEncoding::IsIdentical(CPDF_FontEncoding* pAnother) const { return FXSYS_memcmp(m_Unicodes, pAnother->m_Unicodes, sizeof(m_Unicodes)) == 0; } + CPDF_Object* CPDF_FontEncoding::Realize() { int predefined = 0; for (int cs = PDFFONT_ENCODING_WINANSI; cs < PDFFONT_ENCODING_ZAPFDINGBATS; @@ -1345,10 +1371,13 @@ CPDF_Object* CPDF_FontEncoding::Realize() { pDict->SetAt("Differences", pDiff); return pDict; } -CPDF_TrueTypeFont::CPDF_TrueTypeFont() : CPDF_SimpleFont(PDFFONT_TRUETYPE) {} -FX_BOOL CPDF_TrueTypeFont::_Load() { + +CPDF_TrueTypeFont::CPDF_TrueTypeFont() {} + +FX_BOOL CPDF_TrueTypeFont::Load() { return LoadCommon(); } + void CPDF_TrueTypeFont::LoadGlyphMap() { if (!m_Font.GetFace()) return; @@ -1546,8 +1575,7 @@ void CPDF_TrueTypeFont::LoadGlyphMap() { } CPDF_Type3Font::CPDF_Type3Font() - : CPDF_SimpleFont(PDFFONT_TYPE3), - m_pCharProcs(nullptr), + : m_pCharProcs(nullptr), m_pPageResources(nullptr), m_pFontResources(nullptr) { FXSYS_memset(m_CharWidthL, 0, sizeof(m_CharWidthL)); @@ -1558,7 +1586,7 @@ CPDF_Type3Font::~CPDF_Type3Font() { delete it.second; } -FX_BOOL CPDF_Type3Font::_Load() { +FX_BOOL CPDF_Type3Font::Load() { m_pFontResources = m_pFontDict->GetDictBy("Resources"); CPDF_Array* pMatrix = m_pFontDict->GetArrayBy("FontMatrix"); FX_FLOAT xscale = 1.0f, yscale = 1.0f; @@ -1604,6 +1632,7 @@ FX_BOOL CPDF_Type3Font::_Load() { } return TRUE; } + void CPDF_Type3Font::CheckType3FontMetrics() { CheckFontMetrics(); } diff --git a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp index 34877a866a..63e4a501c4 100644 --- a/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp +++ b/core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp @@ -1038,17 +1038,18 @@ void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr, FPDFAPI_LoadCID2UnicodeMap(charset, m_pEmbeddedMap, m_EmbeddedCount); } -CPDF_CIDFont::CPDF_CIDFont() : CPDF_Font(PDFFONT_CIDFONT) { - m_pCMap = NULL; - m_pAllocatedCMap = NULL; - m_pCID2UnicodeMap = NULL; - m_pAnsiWidths = NULL; - m_pCIDToGIDMap = NULL; - m_bCIDIsGID = FALSE; - m_bAdobeCourierStd = FALSE; - m_pTTGSUBTable = NULL; +CPDF_CIDFont::CPDF_CIDFont() + : m_pCMap(nullptr), + m_pAllocatedCMap(nullptr), + m_pCID2UnicodeMap(nullptr), + m_pCIDToGIDMap(nullptr), + m_bCIDIsGID(FALSE), + m_pAnsiWidths(nullptr), + m_bAdobeCourierStd(FALSE), + m_pTTGSUBTable(nullptr) { FXSYS_memset(m_CharBBox, 0xff, 256 * sizeof(FX_SMALL_RECT)); } + CPDF_CIDFont::~CPDF_CIDFont() { if (m_pAnsiWidths) { FX_Free(m_pAnsiWidths); @@ -1057,17 +1058,29 @@ CPDF_CIDFont::~CPDF_CIDFont() { delete m_pCIDToGIDMap; delete m_pTTGSUBTable; } + FX_WORD CPDF_CIDFont::CIDFromCharCode(FX_DWORD charcode) const { if (!m_pCMap) { return (FX_WORD)charcode; } return m_pCMap->CIDFromCharCode(charcode); } + FX_BOOL CPDF_CIDFont::IsVertWriting() const { return m_pCMap ? m_pCMap->IsVertWriting() : FALSE; } -FX_WCHAR CPDF_CIDFont::_UnicodeFromCharCode(FX_DWORD charcode) const { +CFX_WideString CPDF_CIDFont::UnicodeFromCharCode(FX_DWORD charcode) const { + CFX_WideString str = CPDF_Font::UnicodeFromCharCode(charcode); + if (!str.IsEmpty()) + return str; + FX_WCHAR ret = GetUnicodeFromCharCode(charcode); + if (ret == 0) + return CFX_WideString(); + return ret; +} + +FX_WCHAR CPDF_CIDFont::GetUnicodeFromCharCode(FX_DWORD charcode) const { switch (m_pCMap->m_Coding) { case CIDCODING_UCS2: case CIDCODING_UTF16: @@ -1103,7 +1116,11 @@ FX_WCHAR CPDF_CIDFont::_UnicodeFromCharCode(FX_DWORD charcode) const { } return m_pCID2UnicodeMap->UnicodeFromCID(CIDFromCharCode(charcode)); } -FX_DWORD CPDF_CIDFont::_CharCodeFromUnicode(FX_WCHAR unicode) const { + +FX_DWORD CPDF_CIDFont::CharCodeFromUnicode(FX_WCHAR unicode) const { + FX_DWORD charcode = CPDF_Font::CharCodeFromUnicode(unicode); + if (charcode) + return charcode; switch (m_pCMap->m_Coding) { case CIDCODING_UNKNOWN: return 0; @@ -1152,7 +1169,7 @@ FX_DWORD CPDF_CIDFont::_CharCodeFromUnicode(FX_WCHAR unicode) const { return 0; } -FX_BOOL CPDF_CIDFont::_Load() { +FX_BOOL CPDF_CIDFont::Load() { if (m_pFontDict->GetStringBy("Subtype") == "TrueType") { return LoadGB2312(); } @@ -1479,7 +1496,7 @@ int CPDF_CIDFont::GlyphFromCharCode(FX_DWORD charcode, FX_BOOL* pVertGlyph) { unicode = m_pCID2UnicodeMap->UnicodeFromCID(cid); } if (unicode == 0) { - unicode = _UnicodeFromCharCode(charcode); + unicode = GetUnicodeFromCharCode(charcode); } if (unicode == 0 && !(m_Flags & PDFFONT_SYMBOLIC)) { unicode = UnicodeFromCharCode(charcode).GetAt(0); diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp index d589d5809f..f05c4bea92 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page.cpp @@ -71,17 +71,17 @@ void CPDF_TextObject::GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const { return; } CPDF_Font* pFont = m_TextState.GetFont(); - if (pFont->GetFontType() != PDFFONT_CIDFONT) { + if (!pFont->IsCIDFont()) { return; } - if (!((CPDF_CIDFont*)pFont)->IsVertWriting()) { + if (!pFont->AsCIDFont()->IsVertWriting()) { return; } - FX_WORD CID = ((CPDF_CIDFont*)pFont)->CIDFromCharCode(pInfo->m_CharCode); + FX_WORD CID = pFont->AsCIDFont()->CIDFromCharCode(pInfo->m_CharCode); pInfo->m_OriginY = pInfo->m_OriginX; pInfo->m_OriginX = 0; short vx, vy; - ((CPDF_CIDFont*)pFont)->GetVertOrigin(CID, vx, vy); + pFont->AsCIDFont()->GetVertOrigin(CID, vx, vy); FX_FLOAT fontsize = m_TextState.GetFontSize(); pInfo->m_OriginX -= fontsize * vx / 1000; pInfo->m_OriginY -= fontsize * vy / 1000; @@ -214,7 +214,7 @@ FX_FLOAT CPDF_TextObject::GetCharWidth(FX_DWORD charcode) const { FX_FLOAT fontsize = m_TextState.GetFontSize() / 1000; CPDF_Font* pFont = m_TextState.GetFont(); FX_BOOL bVertWriting = FALSE; - CPDF_CIDFont* pCIDFont = pFont->GetCIDFont(); + CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); if (pCIDFont) { bVertWriting = pCIDFont->IsVertWriting(); } @@ -236,7 +236,7 @@ void CPDF_TextObject::CalcPositionData(FX_FLOAT* pTextAdvanceX, FX_FLOAT max_y = -10000 * 1.0f; CPDF_Font* pFont = m_TextState.GetFont(); FX_BOOL bVertWriting = FALSE; - CPDF_CIDFont* pCIDFont = pFont->GetCIDFont(); + CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); if (pCIDFont) { bVertWriting = pCIDFont->IsVertWriting(); } diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp index 756e08646a..85b026f8e8 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp @@ -261,12 +261,12 @@ CPDF_Font* CPDF_DocPageData::GetStandardFont(const CFX_ByteStringC& fontName, continue; if (pFont->IsEmbedded()) continue; - if (pFont->GetFontType() != PDFFONT_TYPE1) + if (!pFont->IsType1Font()) continue; if (pFont->GetFontDict()->KeyExist("Widths")) continue; - CPDF_Type1Font* pT1Font = pFont->GetType1Font(); + CPDF_Type1Font* pT1Font = pFont->AsType1Font(); if (pEncoding && !pT1Font->GetEncoding()->IsIdentical(pEncoding)) continue; diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 3018630463..465c74a425 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -1258,9 +1258,9 @@ CPDF_Font* CPDF_StreamContentParser::FindFont(const CFX_ByteString& name) { } CPDF_Font* pFont = m_pDocument->LoadFont(pFontDict); - if (pFont && pFont->GetType3Font()) { - pFont->GetType3Font()->SetPageResources(m_pResources); - pFont->GetType3Font()->CheckType3FontMetrics(); + if (pFont && pFont->IsType3Font()) { + pFont->AsType3Font()->SetPageResources(m_pResources); + pFont->AsType3Font()->CheckType3FontMetrics(); } return pFont; } @@ -1336,7 +1336,7 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs, return; } int textmode; - if (pFont->GetFontType() == PDFFONT_TYPE3) { + if (pFont->IsType3Font()) { textmode = 0; } else { textmode = m_pCurStates->m_TextState.GetObject()->m_TextMode; diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp index 3f797c3c5b..215b104162 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp @@ -198,7 +198,7 @@ FX_BOOL CPDF_RenderStatus::ProcessText(const CPDF_TextObject* textobj, return TRUE; } CPDF_Font* pFont = textobj->m_TextState.GetFont(); - if (pFont->GetFontType() == PDFFONT_TYPE3) { + if (pFont->IsType3Font()) { return ProcessType3Text(textobj, pObj2Device); } FX_BOOL bFill = FALSE, bStroke = FALSE, bClip = FALSE; @@ -348,7 +348,7 @@ class CPDF_RefType3Cache { }; FX_BOOL CPDF_RenderStatus::ProcessType3Text(const CPDF_TextObject* textobj, const CFX_Matrix* pObj2Device) { - CPDF_Type3Font* pType3Font = textobj->m_TextState.GetFont()->GetType3Font(); + CPDF_Type3Font* pType3Font = textobj->m_TextState.GetFont()->AsType3Font(); for (int j = 0; j < m_Type3FontCache.GetSize(); j++) { if (m_Type3FontCache.GetAt(j) == pType3Font) return TRUE; @@ -531,7 +531,7 @@ void CPDF_CharPosList::Load(int nChars, FX_FLOAT FontSize) { m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, nChars); m_nChars = 0; - CPDF_CIDFont* pCIDFont = pFont->GetCIDFont(); + CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); FX_BOOL bVertWriting = pCIDFont && pCIDFont->IsVertWriting(); for (int iChar = 0; iChar < nChars; iChar++) { FX_DWORD CharCode = @@ -548,7 +548,7 @@ void CPDF_CharPosList::Load(int nChars, #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode); #endif - if (!pFont->IsEmbedded() && pFont->GetFontType() != PDFFONT_CIDFONT) { + if (!pFont->IsEmbedded() && !pFont->IsCIDFont()) { charpos.m_FontCharWidth = pFont->GetCharWidthF(CharCode); } else { charpos.m_FontCharWidth = 0; @@ -665,7 +665,7 @@ void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice, matrix.e = origin_x; matrix.f = origin_y; - if (pFont->GetFontType() != PDFFONT_TYPE3) { + if (!pFont->IsType3Font()) { if (stroke_argb == 0) { DrawNormalText(pDevice, nChars, pCharCodes, pCharPos, pFont, font_size, &matrix, fill_argb, pOptions); @@ -718,7 +718,7 @@ FX_BOOL CPDF_TextRenderer::DrawNormalText(CFX_RenderDevice* pDevice, } else { FXGE_flags = FXTEXT_CLEARTYPE; } - if (pFont->GetFontType() & PDFFONT_CIDFONT) { + if (pFont->IsCIDFont()) { FXGE_flags |= FXFONT_CIDFONT; } return pDevice->DrawNormalText(CharPosList.m_nChars, CharPosList.m_pCharPos, @@ -784,9 +784,3 @@ void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, } } -CFX_PathData* CPDF_Font::LoadGlyphPath(FX_DWORD charcode, int dest_width) { - int glyph_index = GlyphFromCharCode(charcode); - if (!m_Font.GetFace()) - return nullptr; - return m_Font.LoadGlyphPath(glyph_index, dest_width); -} |