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

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: Rename m_pCIDToGIDMap, use std::vector<>. 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
« no previous file with comments | « core/fpdfapi/fpdf_font/cpdf_cidfont.h ('k') | core/fpdfapi/fpdf_font/font_int.h » ('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/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_pStreamAcc.reset(new CPDF_StreamAcc);
439 m_pCIDToGIDMap->LoadAllData(pStream, FALSE); 429 m_pStreamAcc->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 }
449 } 439 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 rect_f.Transform(&matrix); 523 rect_f.Transform(&matrix);
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_AnsiWidths.size() >= 0x80 && charcode < 0x80)
544 return m_pAnsiWidths[charcode]; 534 return m_AnsiWidths[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;
555 } 545 }
(...skipping 57 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 }
634 return index; 624 return index;
635 } 625 }
636 if (pVertGlyph) { 626 if (pVertGlyph) {
637 *pVertGlyph = FALSE; 627 *pVertGlyph = FALSE;
638 } 628 }
639 return index; 629 return index;
640 } 630 }
641 int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, FX_BOOL* pVertGlyph) { 631 int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, FX_BOOL* pVertGlyph) {
642 if (pVertGlyph) { 632 if (pVertGlyph) {
643 *pVertGlyph = FALSE; 633 *pVertGlyph = FALSE;
644 } 634 }
645 if (!m_pFontFile && !m_pCIDToGIDMap) { 635 if (!m_pFontFile && !m_pStreamAcc) {
646 uint16_t cid = CIDFromCharCode(charcode); 636 uint16_t cid = CIDFromCharCode(charcode);
647 FX_WCHAR unicode = 0; 637 FX_WCHAR unicode = 0;
648 if (m_bCIDIsGID) { 638 if (m_bCIDIsGID) {
649 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ 639 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
650 return cid; 640 return cid;
651 #else 641 #else
652 if (m_Flags & PDFFONT_SYMBOLIC) { 642 if (m_Flags & PDFFONT_SYMBOLIC) {
653 return cid; 643 return cid;
654 } 644 }
655 CFX_WideString uni_str = UnicodeFromCharCode(charcode); 645 CFX_WideString uni_str = UnicodeFromCharCode(charcode);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 return -1; 738 return -1;
749 return index; 739 return index;
750 } 740 }
751 return unicode; 741 return unicode;
752 } 742 }
753 if (!m_Font.GetFace()) 743 if (!m_Font.GetFace())
754 return -1; 744 return -1;
755 745
756 uint16_t cid = CIDFromCharCode(charcode); 746 uint16_t cid = CIDFromCharCode(charcode);
757 if (m_bType1) { 747 if (m_bType1) {
758 if (!m_pCIDToGIDMap) { 748 if (!m_pStreamAcc) {
759 return cid; 749 return cid;
760 } 750 }
761 } else { 751 } else {
762 if (!m_pCIDToGIDMap) { 752 if (!m_pStreamAcc) {
763 if (m_pFontFile && !m_pCMap->m_pMapping) 753 if (m_pFontFile && !m_pCMap->m_pMapping)
764 return cid; 754 return cid;
765 if (m_pCMap->m_Coding == CIDCODING_UNKNOWN || 755 if (m_pCMap->m_Coding == CIDCODING_UNKNOWN ||
766 !FXFT_Get_Face_Charmap(m_Font.GetFace())) { 756 !FXFT_Get_Face_Charmap(m_Font.GetFace())) {
767 return cid; 757 return cid;
768 } 758 }
769 if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmap(m_Font.GetFace())) == 759 if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmap(m_Font.GetFace())) ==
770 FXFT_ENCODING_UNICODE) { 760 FXFT_ENCODING_UNICODE) {
771 CFX_WideString unicode_str = UnicodeFromCharCode(charcode); 761 CFX_WideString unicode_str = UnicodeFromCharCode(charcode);
772 if (unicode_str.IsEmpty()) { 762 if (unicode_str.IsEmpty()) {
773 return -1; 763 return -1;
774 } 764 }
775 charcode = unicode_str.GetAt(0); 765 charcode = unicode_str.GetAt(0);
776 } 766 }
777 return GetGlyphIndex(charcode, pVertGlyph); 767 return GetGlyphIndex(charcode, pVertGlyph);
778 } 768 }
779 } 769 }
780 uint32_t byte_pos = cid * 2; 770 uint32_t byte_pos = cid * 2;
781 if (byte_pos + 2 > m_pCIDToGIDMap->GetSize()) 771 if (byte_pos + 2 > m_pStreamAcc->GetSize())
782 return -1; 772 return -1;
783 773
784 const uint8_t* pdata = m_pCIDToGIDMap->GetData() + byte_pos; 774 const uint8_t* pdata = m_pStreamAcc->GetData() + byte_pos;
785 return pdata[0] * 256 + pdata[1]; 775 return pdata[0] * 256 + pdata[1];
786 } 776 }
787 uint32_t CPDF_CIDFont::GetNextChar(const FX_CHAR* pString, 777 uint32_t CPDF_CIDFont::GetNextChar(const FX_CHAR* pString,
788 int nStrLen, 778 int nStrLen,
789 int& offset) const { 779 int& offset) const {
790 return m_pCMap->GetNextChar(pString, nStrLen, offset); 780 return m_pCMap->GetNextChar(pString, nStrLen, offset);
791 } 781 }
792 int CPDF_CIDFont::GetCharSize(uint32_t charcode) const { 782 int CPDF_CIDFont::GetCharSize(uint32_t charcode) const {
793 return m_pCMap->GetCharSize(charcode); 783 return m_pCMap->GetCharSize(charcode);
794 } 784 }
(...skipping 82 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_AnsiWidths.resize(128);
893 for (int i = 32; i < 127; i++) { 883 for (int i = 32; i < 127; i++)
894 m_pAnsiWidths[i] = 500; 884 m_AnsiWidths[i] = 500;
Lei Zhang 2016/05/23 18:32:26 Given the possible contents of |m_AnsiWidths|, we
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
« no previous file with comments | « core/fpdfapi/fpdf_font/cpdf_cidfont.h ('k') | core/fpdfapi/fpdf_font/font_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698