1 // Copyright 2017 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_FXCRT_CSS_CFX_CSSCOMPUTEDSTYLE_H_
8 #define CORE_FXCRT_CSS_CFX_CSSCOMPUTEDSTYLE_H_
9 
10 #include <vector>
11 
12 #include "core/fxcrt/css/cfx_css.h"
13 #include "core/fxcrt/css/cfx_csscustomproperty.h"
14 #include "core/fxcrt/fx_string.h"
15 #include "core/fxge/fx_dib.h"
16 
17 class CFX_CSSValueList;
18 
19 class CFX_CSSComputedStyle final : public Retainable {
20  public:
21   class InheritedData {
22    public:
23     InheritedData();
24     ~InheritedData();
25 
26     CFX_CSSLength m_LetterSpacing;
27     CFX_CSSLength m_WordSpacing;
28     CFX_CSSLength m_TextIndent;
29     RetainPtr<CFX_CSSValueList> m_pFontFamily;
30     float m_fFontSize;
31     float m_fLineHeight;
32     FX_ARGB m_dwFontColor;
33     uint16_t m_wFontWeight;
34     CFX_CSSFontVariant m_eFontVariant;
35     CFX_CSSFontStyle m_eFontStyle;
36     CFX_CSSTextAlign m_eTextAlign;
37   };
38 
39   class NonInheritedData {
40    public:
41     NonInheritedData();
42 
43     CFX_CSSRect m_MarginWidth;
44     CFX_CSSRect m_BorderWidth;
45     CFX_CSSRect m_PaddingWidth;
46     CFX_CSSLength m_Top;
47     CFX_CSSLength m_Bottom;
48     CFX_CSSLength m_Left;
49     CFX_CSSLength m_Right;
50     float m_fVerticalAlign;
51     CFX_CSSDisplay m_eDisplay;
52     CFX_CSSVerticalAlign m_eVerticalAlign;
53     uint8_t m_dwTextDecoration;
54     bool m_bHasMargin;
55     bool m_bHasBorder;
56     bool m_bHasPadding;
57   };
58 
59   template <typename T, typename... Args>
60   friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
61 
62   int32_t CountFontFamilies() const;
63   const WideString GetFontFamily(int32_t index) const;
64   uint16_t GetFontWeight() const;
65   CFX_CSSFontVariant GetFontVariant() const;
66   CFX_CSSFontStyle GetFontStyle() const;
67   float GetFontSize() const;
68   FX_ARGB GetColor() const;
69   void SetFontWeight(uint16_t wFontWeight);
70   void SetFontVariant(CFX_CSSFontVariant eFontVariant);
71   void SetFontStyle(CFX_CSSFontStyle eFontStyle);
72   void SetFontSize(float fFontSize);
73   void SetColor(FX_ARGB dwFontColor);
74 
75   const CFX_CSSRect* GetBorderWidth() const;
76   const CFX_CSSRect* GetMarginWidth() const;
77   const CFX_CSSRect* GetPaddingWidth() const;
78   void SetMarginWidth(const CFX_CSSRect& rect);
79   void SetPaddingWidth(const CFX_CSSRect& rect);
80 
81   CFX_CSSDisplay GetDisplay() const;
82 
83   float GetLineHeight() const;
84   const CFX_CSSLength& GetTextIndent() const;
85   CFX_CSSTextAlign GetTextAlign() const;
86   CFX_CSSVerticalAlign GetVerticalAlign() const;
87   float GetNumberVerticalAlign() const;
88   uint32_t GetTextDecoration() const;
89   const CFX_CSSLength& GetLetterSpacing() const;
90   void SetLineHeight(float fLineHeight);
91   void SetTextIndent(const CFX_CSSLength& textIndent);
92   void SetTextAlign(CFX_CSSTextAlign eTextAlign);
93   void SetNumberVerticalAlign(float fAlign);
94   void SetTextDecoration(uint32_t dwTextDecoration);
95   void SetLetterSpacing(const CFX_CSSLength& letterSpacing);
96   void AddCustomStyle(const CFX_CSSCustomProperty& prop);
97 
98   bool GetCustomStyle(const WideString& wsName, WideString* pValue) const;
99 
100   InheritedData m_InheritedData;
101   NonInheritedData m_NonInheritedData;
102 
103  private:
104   CFX_CSSComputedStyle();
105   ~CFX_CSSComputedStyle() override;
106 
107   std::vector<CFX_CSSCustomProperty> m_CustomProperties;
108 };
109 
110 #endif  // CORE_FXCRT_CSS_CFX_CSSCOMPUTEDSTYLE_H_
111