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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
8 8
9 #include <memory>
10
9 #include "core/fpdfapi/fpdf_font/cpdf_truetypefont.h" 11 #include "core/fpdfapi/fpdf_font/cpdf_truetypefont.h"
10 #include "core/fpdfapi/fpdf_font/cpdf_type1font.h" 12 #include "core/fpdfapi/fpdf_font/cpdf_type1font.h"
11 #include "core/fpdfapi/fpdf_font/cpdf_type3font.h" 13 #include "core/fpdfapi/fpdf_font/cpdf_type3font.h"
12 #include "core/fpdfapi/fpdf_font/font_int.h" 14 #include "core/fpdfapi/fpdf_font/font_int.h"
13 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" 15 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h"
14 #include "core/fpdfapi/fpdf_page/pageint.h" 16 #include "core/fpdfapi/fpdf_page/pageint.h"
15 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 17 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
16 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 18 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
17 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 19 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
18 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" 20 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h"
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 pDict->SetAtName("BaseFont", fontname); 332 pDict->SetAtName("BaseFont", fontname);
331 pDict->SetAtName("Encoding", "WinAnsiEncoding"); 333 pDict->SetAtName("Encoding", "WinAnsiEncoding");
332 pFont = CPDF_Font::CreateFontF(NULL, pDict); 334 pFont = CPDF_Font::CreateFontF(NULL, pDict);
333 pFontGlobals->Set(pDoc, font_id, pFont); 335 pFontGlobals->Set(pDoc, font_id, pFont);
334 return pFont; 336 return pFont;
335 } 337 }
336 338
337 CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc, 339 CPDF_Font* CPDF_Font::CreateFontF(CPDF_Document* pDoc,
338 CPDF_Dictionary* pFontDict) { 340 CPDF_Dictionary* pFontDict) {
339 CFX_ByteString type = pFontDict->GetStringBy("Subtype"); 341 CFX_ByteString type = pFontDict->GetStringBy("Subtype");
340 CPDF_Font* pFont; 342 std::unique_ptr<CPDF_Font> pFont;
341 if (type == "TrueType") { 343 if (type == "TrueType") {
342 { 344 CFX_ByteString tag = pFontDict->GetStringBy("BaseFont").Left(4);
343 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ || \ 345 for (size_t i = 0; i < FX_ArraySize(ChineseFontNames); ++i) {
344 _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ 346 if (tag == CFX_ByteString(ChineseFontNames[i], 4)) {
345 _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ || \ 347 CPDF_Dictionary* pFontDesc = pFontDict->GetDictBy("FontDescriptor");
346 _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 348 if (!pFontDesc || !pFontDesc->KeyExist("FontFile2"))
347 CFX_ByteString basefont = pFontDict->GetStringBy("BaseFont"); 349 pFont.reset(new CPDF_CIDFont);
348 CFX_ByteString tag = basefont.Left(4); 350 break;
349 int i;
350 int count = sizeof(ChineseFontNames) / sizeof(ChineseFontNames[0]);
351 for (i = 0; i < count; ++i) {
352 if (tag == CFX_ByteString((const FX_CHAR*)ChineseFontNames[i])) {
353 break;
354 }
355 } 351 }
356 if (i < count) {
357 CPDF_Dictionary* pFontDesc = pFontDict->GetDictBy("FontDescriptor");
358 if (!pFontDesc || !pFontDesc->KeyExist("FontFile2")) {
359 pFont = new CPDF_CIDFont;
360 pFont->m_pFontDict = pFontDict;
361 pFont->m_pDocument = pDoc;
362 pFont->m_BaseFont = pFontDict->GetStringBy("BaseFont");
363 if (!pFont->Load()) {
364 delete pFont;
365 return NULL;
366 }
367 return pFont;
368 }
369 }
370 #endif
371 } 352 }
372 pFont = new CPDF_TrueTypeFont; 353 if (!pFont)
354 pFont.reset(new CPDF_TrueTypeFont);
373 } else if (type == "Type3") { 355 } else if (type == "Type3") {
374 pFont = new CPDF_Type3Font; 356 pFont.reset(new CPDF_Type3Font);
375 } else if (type == "Type0") { 357 } else if (type == "Type0") {
376 pFont = new CPDF_CIDFont; 358 pFont.reset(new CPDF_CIDFont);
377 } else { 359 } else {
378 pFont = new CPDF_Type1Font; 360 pFont.reset(new CPDF_Type1Font);
379 } 361 }
380 pFont->m_pFontDict = pFontDict; 362 pFont->m_pFontDict = pFontDict;
381 pFont->m_pDocument = pDoc; 363 pFont->m_pDocument = pDoc;
382 pFont->m_BaseFont = pFontDict->GetStringBy("BaseFont"); 364 pFont->m_BaseFont = pFontDict->GetStringBy("BaseFont");
383 if (!pFont->Load()) { 365 return pFont->Load() ? pFont.release() : nullptr;
384 delete pFont;
385 return NULL;
386 }
387 return pFont;
388 } 366 }
389 367
390 uint32_t CPDF_Font::GetNextChar(const FX_CHAR* pString, 368 uint32_t CPDF_Font::GetNextChar(const FX_CHAR* pString,
391 int nStrLen, 369 int nStrLen,
392 int& offset) const { 370 int& offset) const {
393 if (offset < 0 || nStrLen < 1) { 371 if (offset < 0 || nStrLen < 1) {
394 return 0; 372 return 0;
395 } 373 }
396 uint8_t ch = offset < nStrLen ? pString[offset++] : pString[nStrLen - 1]; 374 uint8_t ch = offset < nStrLen ? pString[offset++] : pString[nStrLen - 1];
397 return static_cast<uint32_t>(ch); 375 return static_cast<uint32_t>(ch);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 if (charcode < 0 || charcode >= 256) 461 if (charcode < 0 || charcode >= 256)
484 return nullptr; 462 return nullptr;
485 463
486 const FX_CHAR* name = nullptr; 464 const FX_CHAR* name = nullptr;
487 if (pCharNames) 465 if (pCharNames)
488 name = pCharNames[charcode].c_str(); 466 name = pCharNames[charcode].c_str();
489 if ((!name || name[0] == 0) && iBaseEncoding) 467 if ((!name || name[0] == 0) && iBaseEncoding)
490 name = PDF_CharNameFromPredefinedCharSet(iBaseEncoding, charcode); 468 name = PDF_CharNameFromPredefinedCharSet(iBaseEncoding, charcode);
491 return name && name[0] ? name : nullptr; 469 return name && name[0] ? name : nullptr;
492 } 470 }
OLDNEW
« 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