diff options
Diffstat (limited to 'core/fpdfapi/fpdf_font')
-rw-r--r-- | core/fpdfapi/fpdf_font/cpdf_font.cpp | 52 |
1 files changed, 15 insertions, 37 deletions
diff --git a/core/fpdfapi/fpdf_font/cpdf_font.cpp b/core/fpdfapi/fpdf_font/cpdf_font.cpp index 3dfadeda9e..5056276eba 100644 --- a/core/fpdfapi/fpdf_font/cpdf_font.cpp +++ b/core/fpdfapi/fpdf_font/cpdf_font.cpp @@ -6,6 +6,8 @@ #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" +#include <memory> + #include "core/fpdfapi/fpdf_font/cpdf_truetypefont.h" #include "core/fpdfapi/fpdf_font/cpdf_type1font.h" #include "core/fpdfapi/fpdf_font/cpdf_type3font.h" @@ -337,54 +339,30 @@ CPDF_Font* CPDF_Font::GetStockFont(CPDF_Document* pDoc, CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc, CPDF_Dictionary* pFontDict) { CFX_ByteString type = pFontDict->GetStringBy("Subtype"); - CPDF_Font* pFont; + std::unique_ptr<CPDF_Font> pFont; if (type == "TrueType") { - { -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ || \ - _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ - _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ || \ - _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - CFX_ByteString basefont = pFontDict->GetStringBy("BaseFont"); - CFX_ByteString tag = basefont.Left(4); - int i; - int count = sizeof(ChineseFontNames) / sizeof(ChineseFontNames[0]); - for (i = 0; i < count; ++i) { - if (tag == CFX_ByteString((const FX_CHAR*)ChineseFontNames[i])) { - break; - } - } - if (i < count) { + CFX_ByteString tag = pFontDict->GetStringBy("BaseFont").Left(4); + for (size_t i = 0; i < FX_ArraySize(ChineseFontNames); ++i) { + if (tag == CFX_ByteString(ChineseFontNames[i], 4)) { CPDF_Dictionary* pFontDesc = pFontDict->GetDictBy("FontDescriptor"); - if (!pFontDesc || !pFontDesc->KeyExist("FontFile2")) { - 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; - } - return pFont; - } + if (!pFontDesc || !pFontDesc->KeyExist("FontFile2")) + pFont.reset(new CPDF_CIDFont); + break; } -#endif } - pFont = new CPDF_TrueTypeFont; + if (!pFont) + pFont.reset(new CPDF_TrueTypeFont); } else if (type == "Type3") { - pFont = new CPDF_Type3Font; + pFont.reset(new CPDF_Type3Font); } else if (type == "Type0") { - pFont = new CPDF_CIDFont; + pFont.reset(new CPDF_CIDFont); } else { - pFont = new CPDF_Type1Font; + pFont.reset(new CPDF_Type1Font); } pFont->m_pFontDict = pFontDict; pFont->m_pDocument = pDoc; pFont->m_BaseFont = pFontDict->GetStringBy("BaseFont"); - if (!pFont->Load()) { - delete pFont; - return NULL; - } - return pFont; + return pFont->Load() ? pFont.release() : nullptr; } uint32_t CPDF_Font::GetNextChar(const FX_CHAR* pString, |