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