| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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/font_int.h" | 7 #include "core/fpdfapi/font/font_int.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/cmaps/cmap_int.h" | 9 #include "core/fpdfapi/cmaps/cmap_int.h" |
| 10 #include "core/fpdfapi/cpdf_modulemgr.h" | 10 #include "core/fpdfapi/cpdf_modulemgr.h" |
| 11 #include "core/fpdfapi/font/ttgsubtable.h" | 11 #include "core/fpdfapi/font/ttgsubtable.h" |
| 12 #include "core/fpdfapi/page/cpdf_pagemodule.h" | 12 #include "core/fpdfapi/page/cpdf_pagemodule.h" |
| 13 #include "core/fpdfapi/parser/cpdf_array.h" | 13 #include "core/fpdfapi/parser/cpdf_array.h" |
| 14 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 14 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 15 #include "core/fpdfapi/parser/cpdf_simple_parser.h" | 15 #include "core/fpdfapi/parser/cpdf_simple_parser.h" |
| 16 #include "core/fxcrt/fx_ext.h" | 16 #include "core/fxcrt/fx_ext.h" |
| 17 #include "core/fxge/fx_freetype.h" | 17 #include "core/fxge/fx_freetype.h" |
| 18 #include "third_party/base/stl_util.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 const FX_CHAR* const g_CharsetNames[CIDSET_NUM_SETS] = { | 22 const FX_CHAR* const g_CharsetNames[CIDSET_NUM_SETS] = { |
| 22 nullptr, "GB1", "CNS1", "Japan1", "Korea1", "UCS"}; | 23 nullptr, "GB1", "CNS1", "Japan1", "Korea1", "UCS"}; |
| 23 | 24 |
| 24 class CPDF_PredefinedCMap { | 25 class CPDF_PredefinedCMap { |
| 25 public: | 26 public: |
| 26 const FX_CHAR* m_pName; | 27 const FX_CHAR* m_pName; |
| 27 CIDSet m_Charset; | 28 CIDSet m_Charset; |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 } else if (m_Status == 4) { | 397 } else if (m_Status == 4) { |
| 397 m_pCMap->m_Charset = CharsetFromOrdering(CMap_GetString(word)); | 398 m_pCMap->m_Charset = CharsetFromOrdering(CMap_GetString(word)); |
| 398 m_Status = 0; | 399 m_Status = 0; |
| 399 } else if (m_Status == 5) { | 400 } else if (m_Status == 5) { |
| 400 m_Status = 0; | 401 m_Status = 0; |
| 401 } else if (m_Status == 6) { | 402 } else if (m_Status == 6) { |
| 402 m_pCMap->m_bVertical = CMap_GetCode(word) != 0; | 403 m_pCMap->m_bVertical = CMap_GetCode(word) != 0; |
| 403 m_Status = 0; | 404 m_Status = 0; |
| 404 } else if (m_Status == 7) { | 405 } else if (m_Status == 7) { |
| 405 if (word == "endcodespacerange") { | 406 if (word == "endcodespacerange") { |
| 406 int nSegs = m_CodeRanges.GetSize(); | 407 uint32_t nSegs = pdfium::CollectionSize<uint32_t>(m_CodeRanges); |
| 407 if (nSegs > 1) { | 408 if (nSegs > 1) { |
| 408 m_pCMap->m_CodingScheme = CPDF_CMap::MixedFourBytes; | 409 m_pCMap->m_CodingScheme = CPDF_CMap::MixedFourBytes; |
| 409 m_pCMap->m_nCodeRanges = nSegs; | 410 m_pCMap->m_nCodeRanges = nSegs; |
| 410 FX_Free(m_pCMap->m_pLeadingBytes); | 411 FX_Free(m_pCMap->m_pLeadingBytes); |
| 411 m_pCMap->m_pLeadingBytes = | 412 m_pCMap->m_pLeadingBytes = |
| 412 FX_Alloc2D(uint8_t, nSegs, sizeof(CMap_CodeRange)); | 413 FX_Alloc2D(uint8_t, nSegs, sizeof(CMap_CodeRange)); |
| 413 FXSYS_memcpy(m_pCMap->m_pLeadingBytes, m_CodeRanges.GetData(), | 414 FXSYS_memcpy(m_pCMap->m_pLeadingBytes, m_CodeRanges.data(), |
| 414 nSegs * sizeof(CMap_CodeRange)); | 415 nSegs * sizeof(CMap_CodeRange)); |
| 415 } else if (nSegs == 1) { | 416 } else if (nSegs == 1) { |
| 416 m_pCMap->m_CodingScheme = (m_CodeRanges[0].m_CharSize == 2) | 417 m_pCMap->m_CodingScheme = (m_CodeRanges[0].m_CharSize == 2) |
| 417 ? CPDF_CMap::TwoBytes | 418 ? CPDF_CMap::TwoBytes |
| 418 : CPDF_CMap::OneByte; | 419 : CPDF_CMap::OneByte; |
| 419 } | 420 } |
| 420 m_Status = 0; | 421 m_Status = 0; |
| 421 } else { | 422 } else { |
| 422 if (word.GetLength() == 0 || word.GetAt(0) != '<') { | 423 if (word.GetLength() == 0 || word.GetAt(0) != '<') { |
| 423 return; | 424 return; |
| 424 } | 425 } |
| 425 if (m_CodeSeq % 2) { | 426 if (m_CodeSeq % 2) { |
| 426 CMap_CodeRange range; | 427 CMap_CodeRange range; |
| 427 if (CMap_GetCodeRange(range, m_LastWord.AsStringC(), word)) { | 428 if (CMap_GetCodeRange(range, m_LastWord.AsStringC(), word)) |
| 428 m_CodeRanges.Add(range); | 429 m_CodeRanges.push_back(range); |
| 429 } | |
| 430 } | 430 } |
| 431 m_CodeSeq++; | 431 m_CodeSeq++; |
| 432 } | 432 } |
| 433 } | 433 } |
| 434 m_LastWord = word; | 434 m_LastWord = word; |
| 435 } | 435 } |
| 436 | 436 |
| 437 // Static. | 437 // Static. |
| 438 uint32_t CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) { | 438 uint32_t CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) { |
| 439 pdfium::base::CheckedNumeric<uint32_t> num = 0; | 439 pdfium::base::CheckedNumeric<uint32_t> num = 0; |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 m_EmbeddedCount = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count; | 774 m_EmbeddedCount = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count; |
| 775 } | 775 } |
| 776 | 776 |
| 777 CIDSet CharsetFromOrdering(const CFX_ByteStringC& ordering) { | 777 CIDSet CharsetFromOrdering(const CFX_ByteStringC& ordering) { |
| 778 for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) { | 778 for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) { |
| 779 if (ordering == g_CharsetNames[charset]) | 779 if (ordering == g_CharsetNames[charset]) |
| 780 return CIDSetFromSizeT(charset); | 780 return CIDSetFromSizeT(charset); |
| 781 } | 781 } |
| 782 return CIDSET_UNKNOWN; | 782 return CIDSET_UNKNOWN; |
| 783 } | 783 } |
| OLD | NEW |