diff options
author | tsepez <tsepez@chromium.org> | 2016-04-22 08:16:04 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-22 08:16:04 -0700 |
commit | 2178e48e9dc62143f0442c520807606a3ac5f042 (patch) | |
tree | 41fb3532af2ed440446239182575a1b97e603839 /core/fpdfapi | |
parent | b88b8dc91ff8987f327c2c5180cacdad1d4464d4 (diff) | |
download | pdfium-2178e48e9dc62143f0442c520807606a3ac5f042.tar.xz |
Remove #ifdef platform which is always true.
fx_system.h errors out during compile if _FXM_PLATFORM_ is not
one of the four values tested in the ifdef.
Remove duplicated code, and use unique_ptr for cleanup.
Review URL: https://codereview.chromium.org/1912023002
Diffstat (limited to 'core/fpdfapi')
-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, |