From 2178e48e9dc62143f0442c520807606a3ac5f042 Mon Sep 17 00:00:00 2001 From: tsepez Date: Fri, 22 Apr 2016 08:16:04 -0700 Subject: 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 --- core/fpdfapi/fpdf_font/cpdf_font.cpp | 52 +++++++++++------------------------- 1 file changed, 15 insertions(+), 37 deletions(-) (limited to 'core') 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 + #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 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, -- cgit v1.2.3