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

Side by Side Diff: core/fpdfapi/font/cpdf_cidfont.cpp

Issue 2571913002: Avoid the ptr.reset(new XXX()) anti-pattern (Closed)
Patch Set: rebase Created 4 years 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 | « core/fpdfapi/edit/fpdf_edit_create.cpp ('k') | core/fpdfapi/font/cpdf_font.cpp » ('j') | 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/font/cpdf_cidfont.h" 7 #include "core/fpdfapi/font/cpdf_cidfont.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
11 11
12 #include "core/fpdfapi/cmaps/cmap_int.h" 12 #include "core/fpdfapi/cmaps/cmap_int.h"
13 #include "core/fpdfapi/cpdf_modulemgr.h" 13 #include "core/fpdfapi/cpdf_modulemgr.h"
14 #include "core/fpdfapi/font/cpdf_fontencoding.h" 14 #include "core/fpdfapi/font/cpdf_fontencoding.h"
15 #include "core/fpdfapi/font/font_int.h" 15 #include "core/fpdfapi/font/font_int.h"
16 #include "core/fpdfapi/font/ttgsubtable.h" 16 #include "core/fpdfapi/font/ttgsubtable.h"
17 #include "core/fpdfapi/page/cpdf_pagemodule.h" 17 #include "core/fpdfapi/page/cpdf_pagemodule.h"
18 #include "core/fpdfapi/parser/cpdf_array.h" 18 #include "core/fpdfapi/parser/cpdf_array.h"
19 #include "core/fpdfapi/parser/cpdf_dictionary.h" 19 #include "core/fpdfapi/parser/cpdf_dictionary.h"
20 #include "core/fpdfapi/parser/cpdf_stream_acc.h" 20 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
21 #include "third_party/base/numerics/safe_math.h" 21 #include "third_party/base/numerics/safe_math.h"
22 #include "third_party/base/ptr_util.h"
22 23
23 namespace { 24 namespace {
24 25
25 const uint16_t g_CharsetCPs[CIDSET_NUM_SETS] = {0, 936, 950, 932, 949, 1200}; 26 const uint16_t g_CharsetCPs[CIDSET_NUM_SETS] = {0, 936, 950, 932, 949, 1200};
26 27
27 const struct CIDTransform { 28 const struct CIDTransform {
28 uint16_t cid; 29 uint16_t cid;
29 uint8_t a; 30 uint8_t a;
30 uint8_t b; 31 uint8_t b;
31 uint8_t c; 32 uint8_t c;
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 CPDF_Array* pWidthArray = pCIDFontDict->GetArrayFor("W"); 392 CPDF_Array* pWidthArray = pCIDFontDict->GetArrayFor("W");
392 if (pWidthArray) 393 if (pWidthArray)
393 LoadMetricsArray(pWidthArray, m_WidthList, 1); 394 LoadMetricsArray(pWidthArray, m_WidthList, 1);
394 if (!IsEmbedded()) 395 if (!IsEmbedded())
395 LoadSubstFont(); 396 LoadSubstFont();
396 397
397 if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT)) { 398 if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT)) {
398 CPDF_Object* pmap = pCIDFontDict->GetDirectObjectFor("CIDToGIDMap"); 399 CPDF_Object* pmap = pCIDFontDict->GetDirectObjectFor("CIDToGIDMap");
399 if (pmap) { 400 if (pmap) {
400 if (CPDF_Stream* pStream = pmap->AsStream()) { 401 if (CPDF_Stream* pStream = pmap->AsStream()) {
401 m_pStreamAcc.reset(new CPDF_StreamAcc); 402 m_pStreamAcc = pdfium::MakeUnique<CPDF_StreamAcc>();
402 m_pStreamAcc->LoadAllData(pStream, false); 403 m_pStreamAcc->LoadAllData(pStream, false);
403 } else if (pmap->GetString() == "Identity") { 404 } else if (pmap->GetString() == "Identity") {
404 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 405 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
405 if (m_pFontFile) 406 if (m_pFontFile)
406 m_bCIDIsGID = true; 407 m_bCIDIsGID = true;
407 #else 408 #else
408 m_bCIDIsGID = true; 409 m_bCIDIsGID = true;
409 #endif 410 #endif
410 } 411 }
411 } 412 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, 575 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0,
575 nullptr, &length); 576 nullptr, &length);
576 if (!error) 577 if (!error)
577 m_Font.SetSubData(FX_Alloc(uint8_t, length)); 578 m_Font.SetSubData(FX_Alloc(uint8_t, length));
578 } 579 }
579 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, 580 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0,
580 m_Font.GetSubData(), nullptr); 581 m_Font.GetSubData(), nullptr);
581 if (error || !m_Font.GetSubData()) 582 if (error || !m_Font.GetSubData())
582 return index; 583 return index;
583 584
584 m_pTTGSUBTable.reset(new CFX_CTTGSUBTable); 585 m_pTTGSUBTable = pdfium::MakeUnique<CFX_CTTGSUBTable>();
585 m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.GetSubData()); 586 m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.GetSubData());
586 return GetVerticalGlyph(index, pVertGlyph); 587 return GetVerticalGlyph(index, pVertGlyph);
587 } 588 }
588 589
589 int CPDF_CIDFont::GetVerticalGlyph(int index, bool* pVertGlyph) { 590 int CPDF_CIDFont::GetVerticalGlyph(int index, bool* pVertGlyph) {
590 uint32_t vindex = 0; 591 uint32_t vindex = 0;
591 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex); 592 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex);
592 if (!vindex) 593 if (!vindex)
593 return index; 594 return index;
594 595
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) 844 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile)
844 return nullptr; 845 return nullptr;
845 846
846 const auto* pEnd = g_Japan1_VertCIDs + FX_ArraySize(g_Japan1_VertCIDs); 847 const auto* pEnd = g_Japan1_VertCIDs + FX_ArraySize(g_Japan1_VertCIDs);
847 const auto* pTransform = std::lower_bound( 848 const auto* pTransform = std::lower_bound(
848 g_Japan1_VertCIDs, pEnd, CID, 849 g_Japan1_VertCIDs, pEnd, CID,
849 [](const CIDTransform& entry, uint16_t cid) { return entry.cid < cid; }); 850 [](const CIDTransform& entry, uint16_t cid) { return entry.cid < cid; });
850 return (pTransform < pEnd && CID == pTransform->cid) ? &pTransform->a 851 return (pTransform < pEnd && CID == pTransform->cid) ? &pTransform->a
851 : nullptr; 852 : nullptr;
852 } 853 }
OLDNEW
« no previous file with comments | « core/fpdfapi/edit/fpdf_edit_create.cpp ('k') | core/fpdfapi/font/cpdf_font.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698