1 // Copyright 2014 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 XFA_FWL_THEME_CFWL_WIDGETTP_H_
8 #define XFA_FWL_THEME_CFWL_WIDGETTP_H_
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "core/fxcrt/fx_coordinates.h"
14 #include "core/fxcrt/fx_system.h"
15 #include "core/fxcrt/retain_ptr.h"
16 #include "xfa/fwl/theme/cfwl_utils.h"
17 #include "xfa/fxgraphics/cxfa_graphics.h"
18 
19 class CFDE_TextOut;
20 class CFGAS_FontMgr;
21 class CFGAS_GEFont;
22 class CFWL_ThemeBackground;
23 class CFWL_ThemeText;
24 
25 class CFWL_WidgetTP {
26  public:
27   virtual ~CFWL_WidgetTP();
28 
29   virtual void DrawBackground(const CFWL_ThemeBackground& pParams);
30   virtual void DrawText(const CFWL_ThemeText& pParams);
31 
32   const RetainPtr<CFGAS_GEFont>& GetFont() const;
33 
34  protected:
35   struct CColorData {
36     FX_ARGB clrBorder[4];
37     FX_ARGB clrStart[4];
38     FX_ARGB clrEnd[4];
39     FX_ARGB clrSign[4];
40   };
41 
42   CFWL_WidgetTP();
43 
44   void InitializeArrowColorData();
45   void EnsureTTOInitialized();
46 
47   void DrawBorder(CXFA_Graphics* pGraphics,
48                   const CFX_RectF& rect,
49                   const CFX_Matrix& matrix);
50   void FillBackground(CXFA_Graphics* pGraphics,
51                       const CFX_RectF& rect,
52                       const CFX_Matrix& matrix);
53   void FillSolidRect(CXFA_Graphics* pGraphics,
54                      FX_ARGB fillColor,
55                      const CFX_RectF& rect,
56                      const CFX_Matrix& matrix);
57   void DrawFocus(CXFA_Graphics* pGraphics,
58                  const CFX_RectF& rect,
59                  const CFX_Matrix& matrix);
60   void DrawArrow(CXFA_Graphics* pGraphics,
61                  const CFX_RectF& rect,
62                  FWLTHEME_DIRECTION eDict,
63                  FX_ARGB argSign,
64                  const CFX_Matrix& matrix);
65   void DrawBtn(CXFA_Graphics* pGraphics,
66                const CFX_RectF& rect,
67                FWLTHEME_STATE eState,
68                const CFX_Matrix& matrix);
69   void DrawArrowBtn(CXFA_Graphics* pGraphics,
70                     const CFX_RectF& rect,
71                     FWLTHEME_DIRECTION eDict,
72                     FWLTHEME_STATE eState,
73                     const CFX_Matrix& matrix);
74 
75   std::unique_ptr<CFDE_TextOut> m_pTextOut;
76   RetainPtr<CFGAS_GEFont> m_pFDEFont;
77   std::unique_ptr<CColorData> m_pColorData;
78 };
79 
80 class CFWL_FontData final {
81  public:
82   CFWL_FontData();
83   ~CFWL_FontData();
84 
85   bool Equal(WideStringView wsFontFamily,
86              uint32_t dwFontStyles,
87              uint16_t wCodePage);
88   bool LoadFont(WideStringView wsFontFamily,
89                 uint32_t dwFontStyles,
90                 uint16_t wCodePage);
91   RetainPtr<CFGAS_GEFont> GetFont() const;
92 
93  protected:
94   WideString m_wsFamily;
95   uint32_t m_dwStyles;
96   uint32_t m_dwCodePage;
97   std::unique_ptr<CFGAS_FontMgr> m_pFontMgr;
98   RetainPtr<CFGAS_GEFont> m_pFont;
99 };
100 
101 class CFWL_FontManager final {
102  public:
103   static CFWL_FontManager* GetInstance();
104   static void DestroyInstance();
105 
106   RetainPtr<CFGAS_GEFont> FindFont(WideStringView wsFontFamily,
107                                    uint32_t dwFontStyles,
108                                    uint16_t dwCodePage);
109 
110  private:
111   CFWL_FontManager();
112   ~CFWL_FontManager();
113 
114   std::vector<std::unique_ptr<CFWL_FontData>> m_FontsArray;
115 };
116 
117 #endif  // XFA_FWL_THEME_CFWL_WIDGETTP_H_
118