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

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

Issue 2520133002: Remove some WrapUnique() calls by returing unique_ptrs (Closed)
Patch Set: rebase Created 4 years, 1 month 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/font/cpdf_fontencoding.h ('k') | core/fpdfapi/page/cpdf_docpagedata.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_fontencoding.h" 7 #include "core/fpdfapi/font/cpdf_fontencoding.h"
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 for (int i = 0; i < 256; i++) 1665 for (int i = 0; i < 256; i++)
1666 m_Unicodes[i] = pSrc[i]; 1666 m_Unicodes[i] = pSrc[i];
1667 } 1667 }
1668 } 1668 }
1669 1669
1670 bool CPDF_FontEncoding::IsIdentical(CPDF_FontEncoding* pAnother) const { 1670 bool CPDF_FontEncoding::IsIdentical(CPDF_FontEncoding* pAnother) const {
1671 return FXSYS_memcmp(m_Unicodes, pAnother->m_Unicodes, sizeof(m_Unicodes)) == 1671 return FXSYS_memcmp(m_Unicodes, pAnother->m_Unicodes, sizeof(m_Unicodes)) ==
1672 0; 1672 0;
1673 } 1673 }
1674 1674
1675 CPDF_Object* CPDF_FontEncoding::Realize(CFX_WeakPtr<CFX_ByteStringPool> pPool) { 1675 std::unique_ptr<CPDF_Object> CPDF_FontEncoding::Realize(
1676 CFX_WeakPtr<CFX_ByteStringPool> pPool) {
1676 int predefined = 0; 1677 int predefined = 0;
1677 for (int cs = PDFFONT_ENCODING_WINANSI; cs < PDFFONT_ENCODING_ZAPFDINGBATS; 1678 for (int cs = PDFFONT_ENCODING_WINANSI; cs < PDFFONT_ENCODING_ZAPFDINGBATS;
1678 cs++) { 1679 cs++) {
1679 const uint16_t* pSrc = PDF_UnicodesForPredefinedCharSet(cs); 1680 const uint16_t* pSrc = PDF_UnicodesForPredefinedCharSet(cs);
1680 bool match = true; 1681 bool match = true;
1681 for (int i = 0; i < 256; ++i) { 1682 for (int i = 0; i < 256; ++i) {
1682 if (m_Unicodes[i] != pSrc[i]) { 1683 if (m_Unicodes[i] != pSrc[i]) {
1683 match = false; 1684 match = false;
1684 break; 1685 break;
1685 } 1686 }
1686 } 1687 }
1687 if (match) { 1688 if (match) {
1688 predefined = cs; 1689 predefined = cs;
1689 break; 1690 break;
1690 } 1691 }
1691 } 1692 }
1692 if (predefined) { 1693 if (predefined) {
1693 if (predefined == PDFFONT_ENCODING_WINANSI) { 1694 if (predefined == PDFFONT_ENCODING_WINANSI)
1694 return new CPDF_Name(pPool, "WinAnsiEncoding"); 1695 return pdfium::MakeUnique<CPDF_Name>(pPool, "WinAnsiEncoding");
1695 } 1696 if (predefined == PDFFONT_ENCODING_MACROMAN)
1696 if (predefined == PDFFONT_ENCODING_MACROMAN) { 1697 return pdfium::MakeUnique<CPDF_Name>(pPool, "MacRomanEncoding");
1697 return new CPDF_Name(pPool, "MacRomanEncoding"); 1698 if (predefined == PDFFONT_ENCODING_MACEXPERT)
1698 } 1699 return pdfium::MakeUnique<CPDF_Name>(pPool, "MacExpertEncoding");
1699 if (predefined == PDFFONT_ENCODING_MACEXPERT) { 1700
1700 return new CPDF_Name(pPool, "MacExpertEncoding");
1701 }
1702 return nullptr; 1701 return nullptr;
1703 } 1702 }
1704 const uint16_t* pStandard = 1703 const uint16_t* pStandard =
1705 PDF_UnicodesForPredefinedCharSet(PDFFONT_ENCODING_WINANSI); 1704 PDF_UnicodesForPredefinedCharSet(PDFFONT_ENCODING_WINANSI);
1706 auto pDiff = pdfium::MakeUnique<CPDF_Array>(); 1705 auto pDiff = pdfium::MakeUnique<CPDF_Array>();
1707 for (int i = 0; i < 256; i++) { 1706 for (int i = 0; i < 256; i++) {
1708 if (pStandard[i] == m_Unicodes[i]) 1707 if (pStandard[i] == m_Unicodes[i])
1709 continue; 1708 continue;
1710 1709
1711 pDiff->AddNew<CPDF_Number>(i); 1710 pDiff->AddNew<CPDF_Number>(i);
1712 pDiff->AddNew<CPDF_Name>(PDF_AdobeNameFromUnicode(m_Unicodes[i])); 1711 pDiff->AddNew<CPDF_Name>(PDF_AdobeNameFromUnicode(m_Unicodes[i]));
1713 } 1712 }
1714 1713
1715 CPDF_Dictionary* pDict = new CPDF_Dictionary(pPool); 1714 auto pDict = pdfium::MakeUnique<CPDF_Dictionary>(pPool);
1716 pDict->SetNewFor<CPDF_Name>("BaseEncoding", "WinAnsiEncoding"); 1715 pDict->SetNewFor<CPDF_Name>("BaseEncoding", "WinAnsiEncoding");
1717 pDict->SetFor("Differences", std::move(pDiff)); 1716 pDict->SetFor("Differences", std::move(pDiff));
1718 return pDict; 1717 return std::move(pDict);
1719 } 1718 }
1720 1719
1721 uint32_t FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode) { 1720 uint32_t FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode) {
1722 switch (encoding) { 1721 switch (encoding) {
1723 case FXFT_ENCODING_UNICODE: 1722 case FXFT_ENCODING_UNICODE:
1724 return unicode; 1723 return unicode;
1725 case FXFT_ENCODING_ADOBE_STANDARD: 1724 case FXFT_ENCODING_ADOBE_STANDARD:
1726 return PDF_FindCode(StandardEncoding, unicode); 1725 return PDF_FindCode(StandardEncoding, unicode);
1727 case FXFT_ENCODING_ADOBE_EXPERT: 1726 case FXFT_ENCODING_ADOBE_EXPERT:
1728 return PDF_FindCode(MacExpertEncoding, unicode); 1727 return PDF_FindCode(MacExpertEncoding, unicode);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 return MacExpertEncoding[(uint8_t)charcode]; 1810 return MacExpertEncoding[(uint8_t)charcode];
1812 case FXFT_ENCODING_ADOBE_LATIN_1: 1811 case FXFT_ENCODING_ADOBE_LATIN_1:
1813 return AdobeWinAnsiEncoding[(uint8_t)charcode]; 1812 return AdobeWinAnsiEncoding[(uint8_t)charcode];
1814 case FXFT_ENCODING_APPLE_ROMAN: 1813 case FXFT_ENCODING_APPLE_ROMAN:
1815 return MacRomanEncoding[(uint8_t)charcode]; 1814 return MacRomanEncoding[(uint8_t)charcode];
1816 case PDFFONT_ENCODING_PDFDOC: 1815 case PDFFONT_ENCODING_PDFDOC:
1817 return PDFDocEncoding[(uint8_t)charcode]; 1816 return PDFDocEncoding[(uint8_t)charcode];
1818 } 1817 }
1819 return 0; 1818 return 0;
1820 } 1819 }
OLDNEW
« no previous file with comments | « core/fpdfapi/font/cpdf_fontencoding.h ('k') | core/fpdfapi/page/cpdf_docpagedata.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698