Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2562)

Unified Diff: core/fpdfapi/fpdf_font/cpdf_font.cpp

Issue 1912023002: Remove #ifdef platform which is always true. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Make string ctor match Left(4), just because. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/fpdf_font/cpdf_font.cpp
diff --git a/core/fpdfapi/fpdf_font/cpdf_font.cpp b/core/fpdfapi/fpdf_font/cpdf_font.cpp
index 3dfadeda9e0a74189b2e8f3a38548451259e1887..5056276eba570c4c4884502b5f609ed7d37c39af 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,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698