• 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 <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/abseil-cpp/absl/types/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 absl::optional<CPDF_CMap::CodeRange> GetCodeRange(
47       ByteStringView first,
48       ByteStringView second);
49 
50   Status m_Status = kStart;
51   int m_CodeSeq = 0;
52   UnownedPtr<CPDF_CMap> const m_pCMap;
53   std::vector<CPDF_CMap::CodeRange> m_Ranges;
54   std::vector<CPDF_CMap::CodeRange> m_PendingRanges;
55   std::vector<CPDF_CMap::CIDRange> m_AdditionalCharcodeToCIDMappings;
56   ByteString m_LastWord;
57   uint32_t m_CodePoints[4] = {};
58 };
59 
60 #endif  // CORE_FPDFAPI_FONT_CPDF_CMAPPARSER_H_
61