• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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_SIMPLEFONT_H_
8 #define CORE_FPDFAPI_FONT_CPDF_SIMPLEFONT_H_
9 
10 #include <stdint.h>
11 
12 #include <array>
13 #include <vector>
14 
15 #include "core/fpdfapi/font/cpdf_font.h"
16 #include "core/fpdfapi/font/cpdf_fontencoding.h"
17 #include "core/fxcrt/fx_string.h"
18 
19 class CPDF_SimpleFont : public CPDF_Font {
20  public:
21   ~CPDF_SimpleFont() override;
22 
23   // CPDF_Font
24   int GetCharWidthF(uint32_t charcode) override;
25   FX_RECT GetCharBBox(uint32_t charcode) override;
26   int GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) override;
27   bool IsUnicodeCompatible() const override;
28   WideString UnicodeFromCharCode(uint32_t charcode) const override;
29   uint32_t CharCodeFromUnicode(wchar_t Unicode) const override;
30 
GetEncoding()31   const CPDF_FontEncoding* GetEncoding() const { return &m_Encoding; }
32 
33   bool HasFontWidths() const override;
34 
35  protected:
36   static constexpr size_t kInternalTableSize = 256;
37 
38   CPDF_SimpleFont(CPDF_Document* pDocument,
39                   RetainPtr<CPDF_Dictionary> pFontDict);
40 
41   virtual void LoadGlyphMap() = 0;
42 
43   bool LoadCommon();
44   void LoadSubstFont();
45   void LoadCharMetrics(int charcode);
46   void LoadCharWidths(const CPDF_Dictionary* font_desc);
47   void LoadDifferences(const CPDF_Dictionary* encoding);
48   void LoadPDFEncoding(bool bEmbedded, bool bTrueType);
49 
50   CPDF_FontEncoding m_Encoding{FontEncoding::kBuiltin};
51   FontEncoding m_BaseEncoding = FontEncoding::kBuiltin;
52   bool m_bUseFontWidth = false;
53   std::vector<ByteString> m_CharNames;
54   std::array<uint16_t, kInternalTableSize> m_GlyphIndex;
55   std::array<uint16_t, kInternalTableSize> m_CharWidth;
56   std::array<FX_RECT, kInternalTableSize> m_CharBBox;
57 };
58 
59 #endif  // CORE_FPDFAPI_FONT_CPDF_SIMPLEFONT_H_
60