• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The PDFium Authors
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 <array>
11 #include <optional>
12 #include <utility>
13 #include <vector>
14 
15 #include "core/fpdfapi/font/cpdf_cidfont.h"
16 #include "core/fpdfapi/font/cpdf_cmap.h"
17 #include "core/fxcrt/unowned_ptr.h"
18 
19 class CPDF_CMapParser {
20  public:
21   explicit CPDF_CMapParser(CPDF_CMap* pCMap);
22   ~CPDF_CMapParser();
23 
24   void ParseWord(ByteStringView word);
25 
26   static CIDSet CharsetFromOrdering(ByteStringView ordering);
27 
28  private:
29   friend class CPDFCMapParserTest_GetCode_Test;
30   friend class CPDFCMapParserTest_GetCodeRange_Test;
31 
32   enum Status {
33     kStart,
34     kProcessingCidChar,
35     kProcessingCidRange,
36     kProcessingRegistry,
37     kProcessingOrdering,
38     kProcessingSupplement,
39     kProcessingWMode,
40     kProcessingCodeSpaceRange,
41   };
42 
43   void HandleCid(ByteStringView word);
44   void HandleCodeSpaceRange(ByteStringView word);
45 
46   static uint32_t GetCode(ByteStringView word);
47   static std::optional<CPDF_CMap::CodeRange> GetCodeRange(
48       ByteStringView first,
49       ByteStringView second);
50 
51   Status m_Status = kStart;
52   int m_CodeSeq = 0;
53   UnownedPtr<CPDF_CMap> const m_pCMap;
54   std::vector<CPDF_CMap::CodeRange> m_Ranges;
55   std::vector<CPDF_CMap::CodeRange> m_PendingRanges;
56   std::vector<CPDF_CMap::CIDRange> m_AdditionalCharcodeToCIDMappings;
57   ByteString m_LastWord;
58   std::array<uint32_t, 4> m_CodePoints = {};
59 };
60 
61 #endif  // CORE_FPDFAPI_FONT_CPDF_CMAPPARSER_H_
62