xref: /aosp_15_r20/external/pdfium/core/fpdfapi/font/cpdf_type3font.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
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_TYPE3FONT_H_
8 #define CORE_FPDFAPI_FONT_CPDF_TYPE3FONT_H_
9 
10 #include <stdint.h>
11 
12 #include <map>
13 #include <memory>
14 
15 #include "core/fpdfapi/font/cpdf_simplefont.h"
16 #include "core/fxcrt/fx_coordinates.h"
17 #include "core/fxcrt/retain_ptr.h"
18 #include "core/fxcrt/unowned_ptr.h"
19 
20 class CPDF_Dictionary;
21 class CPDF_Document;
22 class CPDF_Type3Char;
23 
24 class CPDF_Type3Font final : public CPDF_SimpleFont {
25  public:
26   CONSTRUCT_VIA_MAKE_RETAIN;
27   ~CPDF_Type3Font() override;
28 
29   // CPDF_Font:
30   bool IsType3Font() const override;
31   const CPDF_Type3Font* AsType3Font() const override;
32   CPDF_Type3Font* AsType3Font() override;
33   void WillBeDestroyed() override;
34   int GetCharWidthF(uint32_t charcode) override;
35   FX_RECT GetCharBBox(uint32_t charcode) override;
36 
SetPageResources(CPDF_Dictionary * pResources)37   void SetPageResources(CPDF_Dictionary* pResources) {
38     m_pPageResources.Reset(pResources);
39   }
40   CPDF_Type3Char* LoadChar(uint32_t charcode);
41   void CheckType3FontMetrics();
42 
GetFontMatrix()43   CFX_Matrix& GetFontMatrix() { return m_FontMatrix; }
44 
45  private:
46   CPDF_Type3Font(CPDF_Document* pDocument,
47                  RetainPtr<CPDF_Dictionary> pFontDict,
48                  FormFactoryIface* pFormFactory);
49 
50   // CPDF_Font:
51   bool Load() override;
52 
53   // CPDF_SimpleFont:
54   void LoadGlyphMap() override;
55 
56   // The depth char loading is in, to avoid recurive calling LoadChar().
57   int m_CharLoadingDepth = 0;
58   CFX_Matrix m_FontMatrix;
59   UnownedPtr<FormFactoryIface> const m_pFormFactory;
60   RetainPtr<CPDF_Dictionary> m_pCharProcs;
61   RetainPtr<CPDF_Dictionary> m_pPageResources;
62   RetainPtr<CPDF_Dictionary> m_pFontResources;
63   std::map<uint32_t, std::unique_ptr<CPDF_Type3Char>> m_CacheMap;
64   int m_CharWidthL[256] = {};
65 };
66 
67 #endif  // CORE_FPDFAPI_FONT_CPDF_TYPE3FONT_H_
68