| OLD | NEW |
| 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 <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "core/fpdfapi/fpdf_cmaps/cmap_int.h" | 12 #include "core/fpdfapi/fpdf_cmaps/cmap_int.h" |
| 13 #include "core/fpdfapi/fpdf_font/font_int.h" | 13 #include "core/fpdfapi/fpdf_font/font_int.h" |
| 14 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" | 14 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" |
| 15 #include "core/fpdfapi/fpdf_font/ttgsubtable.h" | 15 #include "core/fpdfapi/fpdf_font/ttgsubtable.h" |
| 16 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h" | 16 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h" |
| 17 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 17 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 18 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 18 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
| 19 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" | 19 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" |
| 20 #include "core/fpdfapi/include/cpdf_modulemgr.h" | 20 #include "core/fpdfapi/include/cpdf_modulemgr.h" |
| 21 #include "third_party/base/numerics/safe_math.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 const uint16_t g_CharsetCPs[CIDSET_NUM_SETS] = {0, 936, 950, 932, 949, 1200}; | 25 const uint16_t g_CharsetCPs[CIDSET_NUM_SETS] = {0, 936, 950, 932, 949, 1200}; |
| 25 | 26 |
| 26 const struct CIDTransform { | 27 const struct CIDTransform { |
| 27 uint16_t cid; | 28 uint16_t cid; |
| 28 uint8_t a; | 29 uint8_t a; |
| 29 uint8_t b; | 30 uint8_t b; |
| 30 uint8_t c; | 31 uint8_t c; |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 return m_pCMap->AppendChar(str, charcode); | 762 return m_pCMap->AppendChar(str, charcode); |
| 762 } | 763 } |
| 763 | 764 |
| 764 FX_BOOL CPDF_CIDFont::IsUnicodeCompatible() const { | 765 FX_BOOL CPDF_CIDFont::IsUnicodeCompatible() const { |
| 765 if (m_pCID2UnicodeMap && m_pCID2UnicodeMap->IsLoaded() && m_pCMap->IsLoaded()) | 766 if (m_pCID2UnicodeMap && m_pCID2UnicodeMap->IsLoaded() && m_pCMap->IsLoaded()) |
| 766 return TRUE; | 767 return TRUE; |
| 767 return m_pCMap->m_Coding != CIDCODING_UNKNOWN; | 768 return m_pCMap->m_Coding != CIDCODING_UNKNOWN; |
| 768 } | 769 } |
| 769 | 770 |
| 770 void CPDF_CIDFont::LoadSubstFont() { | 771 void CPDF_CIDFont::LoadSubstFont() { |
| 771 m_Font.LoadSubst(m_BaseFont, !m_bType1, m_Flags, m_StemV * 5, m_ItalicAngle, | 772 pdfium::base::CheckedNumeric<int> safeStemV(m_StemV); |
| 773 safeStemV *= 5; |
| 774 m_Font.LoadSubst(m_BaseFont, !m_bType1, m_Flags, |
| 775 safeStemV.ValueOrDefault(FXFONT_FW_NORMAL), m_ItalicAngle, |
| 772 g_CharsetCPs[m_Charset], IsVertWriting()); | 776 g_CharsetCPs[m_Charset], IsVertWriting()); |
| 773 } | 777 } |
| 774 | 778 |
| 775 void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, | 779 void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray, |
| 776 CFX_ArrayTemplate<uint32_t>& result, | 780 CFX_ArrayTemplate<uint32_t>& result, |
| 777 int nElements) { | 781 int nElements) { |
| 778 int width_status = 0; | 782 int width_status = 0; |
| 779 int iCurElement = 0; | 783 int iCurElement = 0; |
| 780 int first_code = 0; | 784 int first_code = 0; |
| 781 int last_code = 0; | 785 int last_code = 0; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 const uint8_t* CPDF_CIDFont::GetCIDTransform(uint16_t CID) const { | 850 const uint8_t* CPDF_CIDFont::GetCIDTransform(uint16_t CID) const { |
| 847 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) | 851 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) |
| 848 return nullptr; | 852 return nullptr; |
| 849 | 853 |
| 850 const auto* pEnd = g_Japan1_VertCIDs + FX_ArraySize(g_Japan1_VertCIDs); | 854 const auto* pEnd = g_Japan1_VertCIDs + FX_ArraySize(g_Japan1_VertCIDs); |
| 851 const auto* pTransform = std::lower_bound( | 855 const auto* pTransform = std::lower_bound( |
| 852 g_Japan1_VertCIDs, pEnd, CID, | 856 g_Japan1_VertCIDs, pEnd, CID, |
| 853 [](const CIDTransform& entry, uint16_t cid) { return entry.cid < cid; }); | 857 [](const CIDTransform& entry, uint16_t cid) { return entry.cid < cid; }); |
| 854 return pTransform < pEnd && CID == pTransform->cid ? &pTransform->a : nullptr; | 858 return pTransform < pEnd && CID == pTransform->cid ? &pTransform->a : nullptr; |
| 855 } | 859 } |
| OLD | NEW |