1 // Copyright 2017 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FPDFAPI_FONT_CPDF_CMAPPARSER_H_ 8 #define CORE_FPDFAPI_FONT_CPDF_CMAPPARSER_H_ 9 10 #include <utility> 11 #include <vector> 12 13 #include "core/fpdfapi/font/cpdf_cidfont.h" 14 #include "core/fpdfapi/font/cpdf_cmap.h" 15 #include "core/fxcrt/unowned_ptr.h" 16 #include "third_party/base/optional.h" 17 18 class CPDF_CMapParser { 19 public: 20 explicit CPDF_CMapParser(CPDF_CMap* pCMap); 21 ~CPDF_CMapParser(); 22 23 void ParseWord(ByteStringView word); 24 25 static CIDSet CharsetFromOrdering(ByteStringView ordering); 26 27 private: 28 friend class cpdf_cmapparser_GetCode_Test; 29 friend class cpdf_cmapparser_GetCodeRange_Test; 30 31 enum Status { 32 kStart, 33 kProcessingCidChar, 34 kProcessingCidRange, 35 kProcessingRegistry, 36 kProcessingOrdering, 37 kProcessingSupplement, 38 kProcessingWMode, 39 kProcessingCodeSpaceRange, 40 }; 41 42 void HandleCid(ByteStringView word); 43 void HandleCodeSpaceRange(ByteStringView word); 44 45 static uint32_t GetCode(ByteStringView word); 46 static Optional<CPDF_CMap::CodeRange> GetCodeRange(ByteStringView first, 47 ByteStringView second); 48 49 Status m_Status = kStart; 50 int m_CodeSeq = 0; 51 UnownedPtr<CPDF_CMap> const m_pCMap; 52 std::vector<CPDF_CMap::CodeRange> m_Ranges; 53 std::vector<CPDF_CMap::CodeRange> m_PendingRanges; 54 std::vector<CPDF_CMap::CIDRange> m_AdditionalCharcodeToCIDMappings; 55 ByteString m_LastWord; 56 uint32_t m_CodePoints[4]; 57 }; 58 59 #endif // CORE_FPDFAPI_FONT_CPDF_CMAPPARSER_H_ 60