1 // Copyright 2017 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_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/mask.h" 15 #include "core/fxcrt/retain_ptr.h" 16 #include "core/fxcrt/widestring.h" 17 #include "core/fxge/dib/fx_dib.h" 18 #include "third_party/abseil-cpp/absl/types/optional.h" 19 20 class CFX_CSSValueList; 21 22 class CFX_CSSComputedStyle final : public Retainable { 23 public: 24 class InheritedData { 25 public: 26 InheritedData(); 27 ~InheritedData(); 28 29 CFX_CSSLength m_LetterSpacing{CFX_CSSLengthUnit::Normal, 0}; 30 CFX_CSSLength m_WordSpacing{CFX_CSSLengthUnit::Normal, 0}; 31 CFX_CSSLength m_TextIndent{CFX_CSSLengthUnit::Point, 0}; 32 RetainPtr<CFX_CSSValueList> m_pFontFamily; 33 float m_fFontSize = 12.0f; 34 float m_fLineHeight = 14.0f; 35 FX_ARGB m_dwFontColor = 0xFF000000; 36 uint16_t m_wFontWeight = 400; 37 CFX_CSSFontVariant m_eFontVariant = CFX_CSSFontVariant::Normal; 38 CFX_CSSFontStyle m_eFontStyle = CFX_CSSFontStyle::Normal; 39 CFX_CSSTextAlign m_eTextAlign = CFX_CSSTextAlign::Left; 40 }; 41 42 class NonInheritedData { 43 public: 44 NonInheritedData(); 45 46 CFX_CSSRect m_MarginWidth{CFX_CSSLengthUnit::Point, 0}; 47 CFX_CSSRect m_BorderWidth{CFX_CSSLengthUnit::Point, 0}; 48 CFX_CSSRect m_PaddingWidth{CFX_CSSLengthUnit::Point, 0}; 49 CFX_CSSLength m_Top; 50 CFX_CSSLength m_Bottom; 51 CFX_CSSLength m_Left; 52 CFX_CSSLength m_Right; 53 float m_fVerticalAlign = 0.0f; 54 CFX_CSSDisplay m_eDisplay = CFX_CSSDisplay::Inline; 55 CFX_CSSVerticalAlign m_eVerticalAlignType = CFX_CSSVerticalAlign::Baseline; 56 Mask<CFX_CSSTEXTDECORATION> m_dwTextDecoration; 57 bool m_bHasMargin = false; 58 bool m_bHasBorder = false; 59 bool m_bHasPadding = false; 60 }; 61 62 CONSTRUCT_VIA_MAKE_RETAIN; 63 64 absl::optional<WideString> GetLastFontFamily() const; 65 uint16_t GetFontWeight() const; 66 CFX_CSSFontVariant GetFontVariant() const; 67 CFX_CSSFontStyle GetFontStyle() const; 68 float GetFontSize() const; 69 FX_ARGB GetColor() const; 70 void SetFontWeight(uint16_t wFontWeight); 71 void SetFontVariant(CFX_CSSFontVariant eFontVariant); 72 void SetFontStyle(CFX_CSSFontStyle eFontStyle); 73 void SetFontSize(float fFontSize); 74 void SetColor(FX_ARGB dwFontColor); 75 76 const CFX_CSSRect* GetBorderWidth() const; 77 const CFX_CSSRect* GetMarginWidth() const; 78 const CFX_CSSRect* GetPaddingWidth() const; 79 void SetMarginWidth(const CFX_CSSRect& rect); 80 void SetPaddingWidth(const CFX_CSSRect& rect); 81 82 CFX_CSSDisplay GetDisplay() const; 83 84 float GetLineHeight() const; 85 const CFX_CSSLength& GetTextIndent() const; 86 CFX_CSSTextAlign GetTextAlign() const; 87 CFX_CSSVerticalAlign GetVerticalAlign() const; 88 float GetNumberVerticalAlign() const; 89 Mask<CFX_CSSTEXTDECORATION> GetTextDecoration() const; 90 const CFX_CSSLength& GetLetterSpacing() const; 91 void SetLineHeight(float fLineHeight); 92 void SetTextIndent(const CFX_CSSLength& textIndent); 93 void SetTextAlign(CFX_CSSTextAlign eTextAlign); 94 void SetNumberVerticalAlign(float fAlign); 95 void SetTextDecoration(Mask<CFX_CSSTEXTDECORATION> dwTextDecoration); 96 void SetLetterSpacing(const CFX_CSSLength& letterSpacing); 97 void AddCustomStyle(const CFX_CSSCustomProperty& prop); 98 99 bool GetCustomStyle(const WideString& wsName, WideString* pValue) const; 100 101 InheritedData m_InheritedData; 102 NonInheritedData m_NonInheritedData; 103 104 private: 105 CFX_CSSComputedStyle(); 106 ~CFX_CSSComputedStyle() override; 107 108 std::vector<CFX_CSSCustomProperty> m_CustomProperties; 109 }; 110 111 #endif // CORE_FXCRT_CSS_CFX_CSSCOMPUTEDSTYLE_H_ 112