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

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

Issue 2003833003: Use unique_ptr in CPDF_CidFont (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 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
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/cpdf_cidfont.h" 7 #include "core/fpdfapi/fpdf_font/cpdf_cidfont.h"
8 8
9 #include "core/fpdfapi/fpdf_cmaps/cmap_int.h" 9 #include "core/fpdfapi/fpdf_cmaps/cmap_int.h"
10 #include "core/fpdfapi/fpdf_font/font_int.h" 10 #include "core/fpdfapi/fpdf_font/font_int.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 198
199 int CompareCIDTransform(const void* key, const void* element) { 199 int CompareCIDTransform(const void* key, const void* element) {
200 uint16_t CID = *static_cast<const uint16_t*>(key); 200 uint16_t CID = *static_cast<const uint16_t*>(key);
201 return CID - static_cast<const struct CIDTransform*>(element)->CID; 201 return CID - static_cast<const struct CIDTransform*>(element)->CID;
202 } 202 }
203 203
204 } // namespace 204 } // namespace
205 205
206 CPDF_CIDFont::CPDF_CIDFont() 206 CPDF_CIDFont::CPDF_CIDFont()
207 : m_pCMap(nullptr), 207 : m_pCMap(nullptr),
208 m_pAllocatedCMap(nullptr),
209 m_pCID2UnicodeMap(nullptr), 208 m_pCID2UnicodeMap(nullptr),
210 m_pCIDToGIDMap(nullptr),
211 m_bCIDIsGID(FALSE), 209 m_bCIDIsGID(FALSE),
212 m_pAnsiWidths(nullptr), 210 m_bAdobeCourierStd(FALSE) {}
213 m_bAdobeCourierStd(FALSE),
214 m_pTTGSUBTable(nullptr) {}
215 211
216 CPDF_CIDFont::~CPDF_CIDFont() { 212 CPDF_CIDFont::~CPDF_CIDFont() {}
217 if (m_pAnsiWidths) {
218 FX_Free(m_pAnsiWidths);
219 }
220 delete m_pAllocatedCMap;
221 delete m_pCIDToGIDMap;
222 delete m_pTTGSUBTable;
223 }
224 213
225 bool CPDF_CIDFont::IsCIDFont() const { 214 bool CPDF_CIDFont::IsCIDFont() const {
226 return true; 215 return true;
227 } 216 }
228 217
229 const CPDF_CIDFont* CPDF_CIDFont::AsCIDFont() const { 218 const CPDF_CIDFont* CPDF_CIDFont::AsCIDFont() const {
230 return this; 219 return this;
231 } 220 }
232 221
233 CPDF_CIDFont* CPDF_CIDFont::AsCIDFont() { 222 CPDF_CIDFont* CPDF_CIDFont::AsCIDFont() {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 m_bType1 = (subtype == "CIDFontType0"); 370 m_bType1 = (subtype == "CIDFontType0");
382 371
383 if (pEncoding->IsName()) { 372 if (pEncoding->IsName()) {
384 CFX_ByteString cmap = pEncoding->GetString(); 373 CFX_ByteString cmap = pEncoding->GetString();
385 m_pCMap = 374 m_pCMap =
386 CPDF_ModuleMgr::Get() 375 CPDF_ModuleMgr::Get()
387 ->GetPageModule() 376 ->GetPageModule()
388 ->GetFontGlobals() 377 ->GetFontGlobals()
389 ->m_CMapManager.GetPredefinedCMap(cmap, m_pFontFile && m_bType1); 378 ->m_CMapManager.GetPredefinedCMap(cmap, m_pFontFile && m_bType1);
390 } else if (CPDF_Stream* pStream = pEncoding->AsStream()) { 379 } else if (CPDF_Stream* pStream = pEncoding->AsStream()) {
391 m_pAllocatedCMap = m_pCMap = new CPDF_CMap; 380 m_pCMap = new CPDF_CMap;
381 m_pAllocatedCMap.reset(m_pCMap);
392 CPDF_StreamAcc acc; 382 CPDF_StreamAcc acc;
393 acc.LoadAllData(pStream, FALSE); 383 acc.LoadAllData(pStream, FALSE);
394 m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize()); 384 m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize());
395 } else { 385 } else {
396 return FALSE; 386 return FALSE;
397 } 387 }
398 if (!m_pCMap) { 388 if (!m_pCMap) {
399 return FALSE; 389 return FALSE;
400 } 390 }
401 m_Charset = m_pCMap->m_Charset; 391 m_Charset = m_pCMap->m_Charset;
(...skipping 26 matching lines...) Expand all
428 LoadMetricsArray(pWidthArray, m_WidthList, 1); 418 LoadMetricsArray(pWidthArray, m_WidthList, 1);
429 } 419 }
430 if (!IsEmbedded()) { 420 if (!IsEmbedded()) {
431 LoadSubstFont(); 421 LoadSubstFont();
432 } 422 }
433 if (1) { 423 if (1) {
434 if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT)) { 424 if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT)) {
435 CPDF_Object* pmap = pCIDFontDict->GetDirectObjectBy("CIDToGIDMap"); 425 CPDF_Object* pmap = pCIDFontDict->GetDirectObjectBy("CIDToGIDMap");
436 if (pmap) { 426 if (pmap) {
437 if (CPDF_Stream* pStream = pmap->AsStream()) { 427 if (CPDF_Stream* pStream = pmap->AsStream()) {
438 m_pCIDToGIDMap = new CPDF_StreamAcc; 428 m_pCIDToGIDMap.reset(new CPDF_StreamAcc);
439 m_pCIDToGIDMap->LoadAllData(pStream, FALSE); 429 m_pCIDToGIDMap->LoadAllData(pStream, FALSE);
440 } else if (pmap->GetString() == "Identity") { 430 } else if (pmap->GetString() == "Identity") {
441 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 431 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
442 if (m_pFontFile) { 432 if (m_pFontFile) {
443 m_bCIDIsGID = TRUE; 433 m_bCIDIsGID = TRUE;
444 } 434 }
445 #else 435 #else
446 m_bCIDIsGID = TRUE; 436 m_bCIDIsGID = TRUE;
447 #endif 437 #endif
448 } 438 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 rect = rect_f.GetOutterRect(); 524 rect = rect_f.GetOutterRect();
535 } 525 }
536 } 526 }
537 if (charcode < 256) 527 if (charcode < 256)
538 m_CharBBox[charcode] = rect.ToSmallRect(); 528 m_CharBBox[charcode] = rect.ToSmallRect();
539 529
540 return rect; 530 return rect;
541 } 531 }
542 int CPDF_CIDFont::GetCharWidthF(uint32_t charcode, int level) { 532 int CPDF_CIDFont::GetCharWidthF(uint32_t charcode, int level) {
543 if (m_pAnsiWidths && charcode < 0x80) { 533 if (m_pAnsiWidths && charcode < 0x80) {
544 return m_pAnsiWidths[charcode]; 534 return m_pAnsiWidths.get()[charcode];
545 } 535 }
546 uint16_t cid = CIDFromCharCode(charcode); 536 uint16_t cid = CIDFromCharCode(charcode);
547 int size = m_WidthList.GetSize(); 537 int size = m_WidthList.GetSize();
548 uint32_t* list = m_WidthList.GetData(); 538 uint32_t* list = m_WidthList.GetData();
549 for (int i = 0; i < size; i += 3) { 539 for (int i = 0; i < size; i += 3) {
550 if (cid >= list[i] && cid <= list[i + 1]) { 540 if (cid >= list[i] && cid <= list[i + 1]) {
551 return (int)list[i + 2]; 541 return (int)list[i + 2];
552 } 542 }
553 } 543 }
554 return m_DefaultWidth; 544 return m_DefaultWidth;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 unsigned long length = 0; 603 unsigned long length = 0;
614 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, 604 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0,
615 NULL, &length); 605 NULL, &length);
616 if (!error) { 606 if (!error) {
617 m_Font.SetSubData(FX_Alloc(uint8_t, length)); 607 m_Font.SetSubData(FX_Alloc(uint8_t, length));
618 } 608 }
619 } 609 }
620 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, 610 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0,
621 m_Font.GetSubData(), NULL); 611 m_Font.GetSubData(), NULL);
622 if (!error && m_Font.GetSubData()) { 612 if (!error && m_Font.GetSubData()) {
623 m_pTTGSUBTable = new CFX_CTTGSUBTable; 613 m_pTTGSUBTable.reset(new CFX_CTTGSUBTable);
624 m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.GetSubData()); 614 m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.GetSubData());
625 uint32_t vindex = 0; 615 uint32_t vindex = 0;
626 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex); 616 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex);
627 if (vindex) { 617 if (vindex) {
628 index = vindex; 618 index = vindex;
629 if (pVertGlyph) { 619 if (pVertGlyph) {
630 *pVertGlyph = TRUE; 620 *pVertGlyph = TRUE;
631 } 621 }
632 } 622 }
633 } 623 }
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 m_Charset = CIDSET_GB1; 867 m_Charset = CIDSET_GB1;
878 m_bType1 = FALSE; 868 m_bType1 = FALSE;
879 m_pCMap = CPDF_ModuleMgr::Get() 869 m_pCMap = CPDF_ModuleMgr::Get()
880 ->GetPageModule() 870 ->GetPageModule()
881 ->GetFontGlobals() 871 ->GetFontGlobals()
882 ->m_CMapManager.GetPredefinedCMap("GBK-EUC-H", FALSE); 872 ->m_CMapManager.GetPredefinedCMap("GBK-EUC-H", FALSE);
883 m_pCID2UnicodeMap = CPDF_ModuleMgr::Get() 873 m_pCID2UnicodeMap = CPDF_ModuleMgr::Get()
884 ->GetPageModule() 874 ->GetPageModule()
885 ->GetFontGlobals() 875 ->GetFontGlobals()
886 ->m_CMapManager.GetCID2UnicodeMap(m_Charset, FALSE); 876 ->m_CMapManager.GetCID2UnicodeMap(m_Charset, FALSE);
887 if (!IsEmbedded()) { 877 if (!IsEmbedded())
888 LoadSubstFont(); 878 LoadSubstFont();
889 } 879
890 CheckFontMetrics(); 880 CheckFontMetrics();
891 m_DefaultWidth = 1000; 881 m_DefaultWidth = 1000;
892 m_pAnsiWidths = FX_Alloc(uint16_t, 128); 882 m_pAnsiWidths.reset(FX_Alloc(uint16_t, 128));
893 for (int i = 32; i < 127; i++) { 883 for (int i = 32; i < 127; i++)
894 m_pAnsiWidths[i] = 500; 884 m_pAnsiWidths.get()[i] = 500;
895 } 885
896 return TRUE; 886 return TRUE;
897 } 887 }
898 888
899 const uint8_t* CPDF_CIDFont::GetCIDTransform(uint16_t CID) const { 889 const uint8_t* CPDF_CIDFont::GetCIDTransform(uint16_t CID) const {
900 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) 890 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile)
901 return nullptr; 891 return nullptr;
902 892
903 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch( 893 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch(
904 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs), 894 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs),
905 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform); 895 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform);
906 return found ? &found->a : nullptr; 896 return found ? &found->a : nullptr;
907 } 897 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698