diff options
Diffstat (limited to 'xfa')
-rw-r--r-- | xfa/fde/css/cfde_cssrulecollection.cpp | 10 | ||||
-rw-r--r-- | xfa/fde/css/fde_css.cpp | 27 | ||||
-rw-r--r-- | xfa/fde/css/fde_css.h | 141 | ||||
-rw-r--r-- | xfa/fde/css/fde_cssdatatable.cpp | 13 | ||||
-rw-r--r-- | xfa/fde/css/fde_cssdatatable.h | 68 | ||||
-rw-r--r-- | xfa/fde/css/fde_cssdeclaration.cpp | 16 | ||||
-rw-r--r-- | xfa/fde/css/fde_cssdeclaration.h | 4 | ||||
-rw-r--r-- | xfa/fde/css/fde_cssstyleselector.cpp | 67 | ||||
-rw-r--r-- | xfa/fde/css/fde_cssstyleselector.h | 117 | ||||
-rw-r--r-- | xfa/fde/css/fde_cssstylesheet.cpp | 50 | ||||
-rw-r--r-- | xfa/fde/css/fde_cssstylesheet.h | 55 | ||||
-rw-r--r-- | xfa/fxfa/app/cxfa_loadercontext.h | 4 | ||||
-rw-r--r-- | xfa/fxfa/app/cxfa_textlayout.cpp | 43 | ||||
-rw-r--r-- | xfa/fxfa/app/cxfa_textlayout.h | 10 | ||||
-rw-r--r-- | xfa/fxfa/app/cxfa_textparsecontext.cpp | 1 | ||||
-rw-r--r-- | xfa/fxfa/app/cxfa_textparsecontext.h | 4 | ||||
-rw-r--r-- | xfa/fxfa/app/cxfa_textparser.cpp | 138 | ||||
-rw-r--r-- | xfa/fxfa/app/cxfa_textparser.h | 44 | ||||
-rw-r--r-- | xfa/fxfa/app/cxfa_textuserdata.cpp | 5 | ||||
-rw-r--r-- | xfa/fxfa/app/cxfa_textuserdata.h | 8 |
20 files changed, 315 insertions, 510 deletions
diff --git a/xfa/fde/css/cfde_cssrulecollection.cpp b/xfa/fde/css/cfde_cssrulecollection.cpp index baa6eb465a..d9bc9b7545 100644 --- a/xfa/fde/css/cfde_cssrulecollection.cpp +++ b/xfa/fde/css/cfde_cssrulecollection.cpp @@ -33,12 +33,12 @@ CFDE_CSSRuleCollection::~CFDE_CSSRuleCollection() { } void CFDE_CSSRuleCollection::AddRulesFrom( - const CFX_ArrayTemplate<IFDE_CSSStyleSheet*>& sheets, + const CFX_ArrayTemplate<CFDE_CSSStyleSheet*>& sheets, uint32_t dwMediaList, CFGAS_FontMgr* pFontMgr) { int32_t iSheets = sheets.GetSize(); for (int32_t i = 0; i < iSheets; ++i) { - IFDE_CSSStyleSheet* pSheet = sheets.GetAt(i); + CFDE_CSSStyleSheet* pSheet = sheets.GetAt(i); if (uint32_t dwMatchMedia = pSheet->GetMediaList() & dwMediaList) { int32_t iRules = pSheet->CountRules(); for (int32_t j = 0; j < iRules; j++) { @@ -48,13 +48,13 @@ void CFDE_CSSRuleCollection::AddRulesFrom( } } -void CFDE_CSSRuleCollection::AddRulesFrom(IFDE_CSSStyleSheet* pStyleSheet, +void CFDE_CSSRuleCollection::AddRulesFrom(CFDE_CSSStyleSheet* pStyleSheet, IFDE_CSSRule* pRule, uint32_t dwMediaList, CFGAS_FontMgr* pFontMgr) { switch (pRule->GetType()) { case FDE_CSSRuleType::Style: { - IFDE_CSSStyleRule* pStyleRule = static_cast<IFDE_CSSStyleRule*>(pRule); + CFDE_CSSStyleRule* pStyleRule = static_cast<CFDE_CSSStyleRule*>(pRule); CFDE_CSSDeclaration* pDeclaration = pStyleRule->GetDeclaration(); int32_t iSelectors = pStyleRule->CountSelectorLists(); for (int32_t i = 0; i < iSelectors; ++i) { @@ -95,7 +95,7 @@ void CFDE_CSSRuleCollection::AddRulesFrom(IFDE_CSSStyleSheet* pStyleSheet, } } break; case FDE_CSSRuleType::Media: { - IFDE_CSSMediaRule* pMediaRule = static_cast<IFDE_CSSMediaRule*>(pRule); + CFDE_CSSMediaRule* pMediaRule = static_cast<CFDE_CSSMediaRule*>(pRule); if (pMediaRule->GetMediaList() & dwMediaList) { int32_t iRules = pMediaRule->CountRules(); for (int32_t i = 0; i < iRules; ++i) { diff --git a/xfa/fde/css/fde_css.cpp b/xfa/fde/css/fde_css.cpp deleted file mode 100644 index c9122b4bfd..0000000000 --- a/xfa/fde/css/fde_css.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fde/css/fde_css.h" - -FDE_CSSVALUETYPE IFDE_CSSPrimitiveValue::GetType() const { - return FDE_CSSVALUETYPE_Primitive; -} - -FDE_CSSVALUETYPE IFDE_CSSValueList::GetType() const { - return FDE_CSSVALUETYPE_List; -} - -FDE_CSSRuleType IFDE_CSSStyleRule::GetType() const { - return FDE_CSSRuleType::Style; -} - -FDE_CSSRuleType IFDE_CSSMediaRule::GetType() const { - return FDE_CSSRuleType::Media; -} - -FDE_CSSRuleType IFDE_CSSFontFaceRule::GetType() const { - return FDE_CSSRuleType::FontFace; -} diff --git a/xfa/fde/css/fde_css.h b/xfa/fde/css/fde_css.h index 42662cfb73..90763d6c38 100644 --- a/xfa/fde/css/fde_css.h +++ b/xfa/fde/css/fde_css.h @@ -14,17 +14,12 @@ class CFDE_CSSAccelerator; class CFDE_CSSDeclaration; +class CFDE_CSSComputedStyle; class CFDE_CSSSelector; +class CFDE_CSSStyleSheet; class CXFA_CSSTagProvider; -class IFDE_CSSBoundaryStyle; -class IFDE_CSSComputedStyle; -class IFDE_CSSFontStyle; -class IFDE_CSSParagraphStyle; -class IFDE_CSSPositionStyle; class IFDE_CSSRule; -class IFDE_CSSStyleSheet; class IFDE_CSSValue; -class IFDE_CSSValueList; enum FDE_CSSMEDIATYPE { FDE_CSSMEDIATYPE_Braille = 0x01, @@ -268,80 +263,12 @@ class IFDE_CSSValue { virtual FDE_CSSVALUETYPE GetType() const = 0; }; -class IFDE_CSSPrimitiveValue : public IFDE_CSSValue { - public: - // IFDE_CSSValue - FDE_CSSVALUETYPE GetType() const override; - - virtual FDE_CSSPrimitiveType GetPrimitiveType() const = 0; - virtual FX_ARGB GetRGBColor() const = 0; - virtual FX_FLOAT GetFloat() const = 0; - virtual const FX_WCHAR* GetString(int32_t& iLength) const = 0; - virtual FDE_CSSPropertyValue GetEnum() const = 0; - virtual const FX_WCHAR* GetFuncName() const = 0; - virtual int32_t CountArgs() const = 0; - virtual IFDE_CSSValue* GetArgs(int32_t index) const = 0; -}; - -class IFDE_CSSValueList : public IFDE_CSSValue { - public: - // IFDE_CSSValue - FDE_CSSVALUETYPE GetType() const override; - - virtual int32_t CountValues() const = 0; - virtual IFDE_CSSValue* GetValue(int32_t index) const = 0; -}; - class IFDE_CSSRule { public: virtual ~IFDE_CSSRule() {} virtual FDE_CSSRuleType GetType() const = 0; }; -class IFDE_CSSStyleRule : public IFDE_CSSRule { - public: - // IFDE_CSSValue - FDE_CSSRuleType GetType() const override; - - virtual int32_t CountSelectorLists() const = 0; - virtual CFDE_CSSSelector* GetSelectorList(int32_t index) const = 0; - virtual CFDE_CSSDeclaration* GetDeclaration() = 0; -}; - -class IFDE_CSSMediaRule : public IFDE_CSSRule { - public: - // IFDE_CSSValue - FDE_CSSRuleType GetType() const override; - - virtual uint32_t GetMediaList() const = 0; - virtual int32_t CountRules() const = 0; - virtual IFDE_CSSRule* GetRule(int32_t index) = 0; -}; - -class IFDE_CSSFontFaceRule : public IFDE_CSSRule { - public: - // IFDE_CSSValue - FDE_CSSRuleType GetType() const override; - - virtual CFDE_CSSDeclaration* GetDeclaration() = 0; -}; - -class IFDE_CSSStyleSheet : public IFX_Retainable { - public: - static IFDE_CSSStyleSheet* LoadFromBuffer( - const CFX_WideString& szUrl, - const FX_WCHAR* pBuffer, - int32_t iBufSize, - uint16_t wCodePage, - uint32_t dwMediaList = FDE_CSSMEDIATYPE_ALL); - virtual bool GetUrl(CFX_WideString& szUrl) = 0; - virtual uint32_t GetMediaList() const = 0; - virtual uint16_t GetCodePage() const = 0; - - virtual int32_t CountRules() const = 0; - virtual IFDE_CSSRule* GetRule(int32_t index) = 0; -}; - struct FDE_CSSLENGTH { FDE_CSSLENGTH() {} @@ -398,68 +325,4 @@ struct FDE_CSSRECT { FDE_CSSLENGTH left, top, right, bottom; }; -class IFDE_CSSFontStyle { - public: - virtual ~IFDE_CSSFontStyle() {} - - virtual int32_t CountFontFamilies() const = 0; - virtual const FX_WCHAR* GetFontFamily(int32_t index) const = 0; - virtual uint16_t GetFontWeight() const = 0; - virtual FDE_CSSFontVariant GetFontVariant() const = 0; - virtual FDE_CSSFontStyle GetFontStyle() const = 0; - virtual FX_FLOAT GetFontSize() const = 0; - virtual FX_ARGB GetColor() const = 0; - virtual void SetFontWeight(uint16_t wFontWeight) = 0; - virtual void SetFontVariant(FDE_CSSFontVariant eFontVariant) = 0; - virtual void SetFontStyle(FDE_CSSFontStyle eFontStyle) = 0; - virtual void SetFontSize(FX_FLOAT fFontSize) = 0; - virtual void SetColor(FX_ARGB dwFontColor) = 0; -}; - -class IFDE_CSSBoundaryStyle { - public: - virtual ~IFDE_CSSBoundaryStyle() {} - - virtual const FDE_CSSRECT* GetBorderWidth() const = 0; - virtual const FDE_CSSRECT* GetMarginWidth() const = 0; - virtual const FDE_CSSRECT* GetPaddingWidth() const = 0; - virtual void SetMarginWidth(const FDE_CSSRECT& rect) = 0; - virtual void SetPaddingWidth(const FDE_CSSRECT& rect) = 0; -}; - -class IFDE_CSSPositionStyle { - public: - virtual ~IFDE_CSSPositionStyle() {} - virtual FDE_CSSDisplay GetDisplay() const = 0; -}; - -class IFDE_CSSParagraphStyle { - public: - virtual ~IFDE_CSSParagraphStyle() {} - - virtual FX_FLOAT GetLineHeight() const = 0; - virtual const FDE_CSSLENGTH& GetTextIndent() const = 0; - virtual FDE_CSSTextAlign GetTextAlign() const = 0; - virtual FDE_CSSVerticalAlign GetVerticalAlign() const = 0; - virtual FX_FLOAT GetNumberVerticalAlign() const = 0; - virtual uint32_t GetTextDecoration() const = 0; - virtual const FDE_CSSLENGTH& GetLetterSpacing() const = 0; - virtual void SetLineHeight(FX_FLOAT fLineHeight) = 0; - virtual void SetTextIndent(const FDE_CSSLENGTH& textIndent) = 0; - virtual void SetTextAlign(FDE_CSSTextAlign eTextAlign) = 0; - virtual void SetNumberVerticalAlign(FX_FLOAT fAlign) = 0; - virtual void SetTextDecoration(uint32_t dwTextDecoration) = 0; - virtual void SetLetterSpacing(const FDE_CSSLENGTH& letterSpacing) = 0; -}; - -class IFDE_CSSComputedStyle : public IFX_Retainable { - public: - virtual IFDE_CSSFontStyle* GetFontStyles() = 0; - virtual IFDE_CSSBoundaryStyle* GetBoundaryStyles() = 0; - virtual IFDE_CSSPositionStyle* GetPositionStyles() = 0; - virtual IFDE_CSSParagraphStyle* GetParagraphStyles() = 0; - virtual bool GetCustomStyle(const CFX_WideStringC& wsName, - CFX_WideString& wsValue) const = 0; -}; - #endif // XFA_FDE_CSS_FDE_CSS_H_ diff --git a/xfa/fde/css/fde_cssdatatable.cpp b/xfa/fde/css/fde_cssdatatable.cpp index 7421f407b5..7db704a8f5 100644 --- a/xfa/fde/css/fde_cssdatatable.cpp +++ b/xfa/fde/css/fde_cssdatatable.cpp @@ -7,6 +7,7 @@ #include "xfa/fde/css/fde_cssdatatable.h" #include "core/fxcrt/fx_ext.h" +#include "xfa/fde/css/fde_cssstyleselector.h" #include "xfa/fgas/crt/fgas_codepage.h" namespace { @@ -31,7 +32,7 @@ bool FDE_CSSLengthToFloat(const FDE_CSSLENGTH& len, return false; } } -CFX_FloatRect FDE_CSSBoundaryToRect(IFDE_CSSBoundaryStyle* pBoundStyle, +CFX_FloatRect FDE_CSSBoundaryToRect(CFDE_CSSComputedStyle* pBoundStyle, FX_FLOAT fContainerWidth, bool bPadding, bool bBorder, @@ -92,7 +93,7 @@ CFX_FloatRect FDE_CSSBoundaryToRect(IFDE_CSSBoundaryStyle* pBoundStyle, } return rect; } -uint32_t FDE_CSSFontStyleToFDE(IFDE_CSSFontStyle* pFontStyle) { +uint32_t FDE_CSSFontStyleToFDE(CFDE_CSSComputedStyle* pFontStyle) { uint32_t dwFontStyle = FX_FONTSTYLE_Normal; if (pFontStyle->GetFontStyle() == FDE_CSSFontStyle::Italic) { dwFontStyle |= FX_FONTSTYLE_Italic; @@ -544,6 +545,10 @@ int32_t CFDE_CSSValueList::CountValues() const { return m_iCount; } +FDE_CSSVALUETYPE CFDE_CSSValueList::GetType() const { + return FDE_CSSVALUETYPE_List; +} + IFDE_CSSValue* CFDE_CSSValueList::GetValue(int32_t index) const { return m_ppList[index]; } @@ -671,6 +676,10 @@ CFDE_CSSPrimitiveValue::CFDE_CSSPrimitiveValue(FDE_CSSPrimitiveType eType, CFDE_CSSPrimitiveValue::CFDE_CSSPrimitiveValue(CFDE_CSSFunction* pFunction) : m_eType(FDE_CSSPrimitiveType::Function), m_pFunction(pFunction) {} +FDE_CSSVALUETYPE CFDE_CSSPrimitiveValue::GetType() const { + return FDE_CSSVALUETYPE_Primitive; +} + FDE_CSSPrimitiveType CFDE_CSSPrimitiveValue::GetPrimitiveType() const { return m_eType; } diff --git a/xfa/fde/css/fde_cssdatatable.h b/xfa/fde/css/fde_cssdatatable.h index f11cae2eac..d62ddf6b03 100644 --- a/xfa/fde/css/fde_cssdatatable.h +++ b/xfa/fde/css/fde_cssdatatable.h @@ -10,24 +10,9 @@ #include "core/fxcrt/fx_system.h" #include "xfa/fde/css/fde_css.h" -class CFDE_CSSFunction { - public: - CFDE_CSSFunction(const FX_WCHAR* pszFuncName, IFDE_CSSValueList* pArgList) - : m_pArgList(pArgList), m_pszFuncName(pszFuncName) { - ASSERT(pArgList); - } - int32_t CountArgs() const { return m_pArgList->CountValues(); } - IFDE_CSSValue* GetArgs(int32_t index) const { - return m_pArgList->GetValue(index); - } - const FX_WCHAR* GetFuncName() const { return m_pszFuncName; } - - protected: - IFDE_CSSValueList* m_pArgList; - const FX_WCHAR* m_pszFuncName; -}; +class CFDE_CSSFunction; -class CFDE_CSSPrimitiveValue : public IFDE_CSSPrimitiveValue { +class CFDE_CSSPrimitiveValue : public IFDE_CSSValue { public: explicit CFDE_CSSPrimitiveValue(FX_ARGB color); explicit CFDE_CSSPrimitiveValue(FDE_CSSPropertyValue eValue); @@ -36,15 +21,17 @@ class CFDE_CSSPrimitiveValue : public IFDE_CSSPrimitiveValue { CFDE_CSSPrimitiveValue(FDE_CSSPrimitiveType eType, const FX_WCHAR* pValue); CFDE_CSSPrimitiveValue(const CFDE_CSSPrimitiveValue& src); - // IFDE_CSSPrimitiveValue - FDE_CSSPrimitiveType GetPrimitiveType() const override; - FX_ARGB GetRGBColor() const override; - FX_FLOAT GetFloat() const override; - const FX_WCHAR* GetString(int32_t& iLength) const override; - FDE_CSSPropertyValue GetEnum() const override; - const FX_WCHAR* GetFuncName() const override; - int32_t CountArgs() const override; - IFDE_CSSValue* GetArgs(int32_t index) const override; + // IFDE_CSSValue + FDE_CSSVALUETYPE GetType() const override; + + FDE_CSSPrimitiveType GetPrimitiveType() const; + FX_ARGB GetRGBColor() const; + FX_FLOAT GetFloat() const; + const FX_WCHAR* GetString(int32_t& iLength) const; + FDE_CSSPropertyValue GetEnum() const; + const FX_WCHAR* GetFuncName() const; + int32_t CountArgs() const; + IFDE_CSSValue* GetArgs(int32_t index) const; FDE_CSSPrimitiveType m_eType; union { @@ -56,16 +43,18 @@ class CFDE_CSSPrimitiveValue : public IFDE_CSSPrimitiveValue { }; }; -typedef CFX_ArrayTemplate<IFDE_CSSPrimitiveValue*> CFDE_CSSPrimitiveArray; +typedef CFX_ArrayTemplate<CFDE_CSSPrimitiveValue*> CFDE_CSSPrimitiveArray; typedef CFX_ArrayTemplate<IFDE_CSSValue*> CFDE_CSSValueArray; -class CFDE_CSSValueList : public IFDE_CSSValueList { +class CFDE_CSSValueList : public IFDE_CSSValue { public: explicit CFDE_CSSValueList(const CFDE_CSSValueArray& list); - // IFDE_CSSValueList - int32_t CountValues() const override; - IFDE_CSSValue* GetValue(int32_t index) const override; + // IFDE_CSSValue + FDE_CSSVALUETYPE GetType() const override; + + int32_t CountValues() const; + IFDE_CSSValue* GetValue(int32_t index) const; protected: IFDE_CSSValue** m_ppList; @@ -92,6 +81,23 @@ class CFDE_CSSValueListParser { const FX_WCHAR* m_pEnd; }; +class CFDE_CSSFunction { + public: + CFDE_CSSFunction(const FX_WCHAR* pszFuncName, CFDE_CSSValueList* pArgList) + : m_pArgList(pArgList), m_pszFuncName(pszFuncName) { + ASSERT(pArgList); + } + int32_t CountArgs() const { return m_pArgList->CountValues(); } + IFDE_CSSValue* GetArgs(int32_t index) const { + return m_pArgList->GetValue(index); + } + const FX_WCHAR* GetFuncName() const { return m_pszFuncName; } + + protected: + CFDE_CSSValueList* m_pArgList; + const FX_WCHAR* m_pszFuncName; +}; + #define FDE_IsOnlyValue(type, enum) \ (((type) & ~(enum)) == FDE_CSSVALUETYPE_Primitive) diff --git a/xfa/fde/css/fde_cssdeclaration.cpp b/xfa/fde/css/fde_cssdeclaration.cpp index 23c92343d0..50d0b8c854 100644 --- a/xfa/fde/css/fde_cssdeclaration.cpp +++ b/xfa/fde/css/fde_cssdeclaration.cpp @@ -67,7 +67,7 @@ const FX_WCHAR* CFDE_CSSDeclaration::CopyToLocal( return psz; } -IFDE_CSSPrimitiveValue* CFDE_CSSDeclaration::NewNumberValue( +CFDE_CSSPrimitiveValue* CFDE_CSSDeclaration::NewNumberValue( FDE_CSSPrimitiveType eUnit, FX_FLOAT fValue) const { static CFDE_CSSPrimitiveValue s_ZeroValue(FDE_CSSPrimitiveType::Number, 0.0f); @@ -76,7 +76,7 @@ IFDE_CSSPrimitiveValue* CFDE_CSSDeclaration::NewNumberValue( } return new CFDE_CSSPrimitiveValue(eUnit, fValue); } -inline IFDE_CSSPrimitiveValue* CFDE_CSSDeclaration::NewEnumValue( +CFDE_CSSPrimitiveValue* CFDE_CSSDeclaration::NewEnumValue( FDE_CSSPropertyValue eValue) const { return new CFDE_CSSPrimitiveValue(eValue); } @@ -345,7 +345,7 @@ IFDE_CSSValue* CFDE_CSSDeclaration::ParseFunction( break; } } - IFDE_CSSValueList* pArgumentList = new CFDE_CSSValueList(argumentArr); + CFDE_CSSValueList* pArgumentList = new CFDE_CSSValueList(argumentArr); CFDE_CSSFunction* pFunction = new CFDE_CSSFunction(pszFuncName, pArgumentList); return new CFDE_CSSPrimitiveValue(pFunction); @@ -525,11 +525,11 @@ bool CFDE_CSSDeclaration::ParseFontProperty(const FDE_CSSPropertyArgs* pArgs, int32_t iValueLen, bool bImportant) { CFDE_CSSValueListParser parser(pszValue, iValueLen, '/'); - IFDE_CSSPrimitiveValue* pStyle = nullptr; - IFDE_CSSPrimitiveValue* pVariant = nullptr; - IFDE_CSSPrimitiveValue* pWeight = nullptr; - IFDE_CSSPrimitiveValue* pFontSize = nullptr; - IFDE_CSSPrimitiveValue* pLineHeight = nullptr; + CFDE_CSSPrimitiveValue* pStyle = nullptr; + CFDE_CSSPrimitiveValue* pVariant = nullptr; + CFDE_CSSPrimitiveValue* pWeight = nullptr; + CFDE_CSSPrimitiveValue* pFontSize = nullptr; + CFDE_CSSPrimitiveValue* pLineHeight = nullptr; CFDE_CSSValueArray familyList; FDE_CSSPrimitiveType eType; while (parser.NextValue(eType, pszValue, iValueLen)) { diff --git a/xfa/fde/css/fde_cssdeclaration.h b/xfa/fde/css/fde_cssdeclaration.h index 18b769c00e..8db6d7b6a1 100644 --- a/xfa/fde/css/fde_cssdeclaration.h +++ b/xfa/fde/css/fde_cssdeclaration.h @@ -100,9 +100,9 @@ class CFDE_CSSDeclaration { void AddPropertyHolder(FDE_CSSProperty eProperty, IFDE_CSSValue* pValue, bool bImportant); - IFDE_CSSPrimitiveValue* NewNumberValue(FDE_CSSPrimitiveType eUnit, + CFDE_CSSPrimitiveValue* NewNumberValue(FDE_CSSPrimitiveType eUnit, FX_FLOAT fValue) const; - IFDE_CSSPrimitiveValue* NewEnumValue(FDE_CSSPropertyValue eValue) const; + CFDE_CSSPrimitiveValue* NewEnumValue(FDE_CSSPropertyValue eValue) const; FDE_CSSPropertyHolder* m_pFirstProperty; FDE_CSSPropertyHolder* m_pLastProperty; diff --git a/xfa/fde/css/fde_cssstyleselector.cpp b/xfa/fde/css/fde_cssstyleselector.cpp index 4861edfb34..53424a1d30 100644 --- a/xfa/fde/css/fde_cssstyleselector.cpp +++ b/xfa/fde/css/fde_cssstyleselector.cpp @@ -60,19 +60,17 @@ CFDE_CSSAccelerator* CFDE_CSSStyleSelector::InitAccelerator() { return m_pAccelerator.get(); } -IFDE_CSSComputedStyle* CFDE_CSSStyleSelector::CreateComputedStyle( - IFDE_CSSComputedStyle* pParentStyle) { +CFDE_CSSComputedStyle* CFDE_CSSStyleSelector::CreateComputedStyle( + CFDE_CSSComputedStyle* pParentStyle) { CFDE_CSSComputedStyle* pStyle = new CFDE_CSSComputedStyle(); - if (pParentStyle) { - pStyle->m_InheritedData = - static_cast<CFDE_CSSComputedStyle*>(pParentStyle)->m_InheritedData; - } + if (pParentStyle) + pStyle->m_InheritedData = pParentStyle->m_InheritedData; return pStyle; } bool CFDE_CSSStyleSelector::SetStyleSheet(FDE_CSSStyleSheetGroup eType, - IFDE_CSSStyleSheet* pSheet) { - CFX_ArrayTemplate<IFDE_CSSStyleSheet*>& dest = + CFDE_CSSStyleSheet* pSheet) { + CFX_ArrayTemplate<CFDE_CSSStyleSheet*>& dest = m_SheetGroups[static_cast<int32_t>(eType)]; dest.RemoveAt(0, dest.GetSize()); if (pSheet) @@ -82,8 +80,8 @@ bool CFDE_CSSStyleSelector::SetStyleSheet(FDE_CSSStyleSheetGroup eType, bool CFDE_CSSStyleSelector::SetStyleSheets( FDE_CSSStyleSheetGroup eType, - const CFX_ArrayTemplate<IFDE_CSSStyleSheet*>* pArray) { - CFX_ArrayTemplate<IFDE_CSSStyleSheet*>& dest = + const CFX_ArrayTemplate<CFDE_CSSStyleSheet*>* pArray) { + CFX_ArrayTemplate<CFDE_CSSStyleSheet*>& dest = m_SheetGroups[static_cast<int32_t>(eType)]; if (pArray) dest.Copy(*pArray); @@ -223,7 +221,7 @@ void CFDE_CSSStyleSelector::ComputeStyle( CXFA_CSSTagProvider* pTag, const CFDE_CSSDeclaration** ppDeclArray, int32_t iDeclCount, - IFDE_CSSComputedStyle* pDestStyle) { + CFDE_CSSComputedStyle* pDestStyle) { ASSERT(iDeclCount >= 0); ASSERT(pDestStyle); @@ -280,9 +278,8 @@ void CFDE_CSSStyleSelector::ApplyDeclarations( bool bPriority, const CFDE_CSSDeclaration** ppDeclArray, int32_t iDeclCount, - IFDE_CSSComputedStyle* pDestStyle) { - CFDE_CSSComputedStyle* pComputedStyle = - static_cast<CFDE_CSSComputedStyle*>(pDestStyle); + CFDE_CSSComputedStyle* pDestStyle) { + CFDE_CSSComputedStyle* pComputedStyle = pDestStyle; IFDE_CSSValue* pVal; bool bImportant; int32_t i; @@ -388,8 +385,8 @@ void CFDE_CSSStyleSelector::ApplyProperty( IFDE_CSSValue* pValue, CFDE_CSSComputedStyle* pComputedStyle) { if (pValue->GetType() == FDE_CSSVALUETYPE_Primitive) { - IFDE_CSSPrimitiveValue* pPrimitive = - static_cast<IFDE_CSSPrimitiveValue*>(pValue); + CFDE_CSSPrimitiveValue* pPrimitive = + static_cast<CFDE_CSSPrimitiveValue*>(pValue); FDE_CSSPrimitiveType eType = pPrimitive->GetPrimitiveType(); switch (eProperty) { case FDE_CSSProperty::Display: @@ -606,7 +603,7 @@ void CFDE_CSSStyleSelector::ApplyProperty( break; } } else if (pValue->GetType() == FDE_CSSVALUETYPE_List) { - IFDE_CSSValueList* pList = static_cast<IFDE_CSSValueList*>(pValue); + CFDE_CSSValueList* pList = static_cast<CFDE_CSSValueList*>(pValue); int32_t iCount = pList->CountValues(); if (iCount > 0) { switch (eProperty) { @@ -713,7 +710,7 @@ FDE_CSSFontStyle CFDE_CSSStyleSelector::ToFontStyle( bool CFDE_CSSStyleSelector::SetLengthWithPercent( FDE_CSSLENGTH& width, FDE_CSSPrimitiveType eType, - IFDE_CSSPrimitiveValue* pPrimitive, + CFDE_CSSPrimitiveValue* pPrimitive, FX_FLOAT fFontSize) { if (eType == FDE_CSSPrimitiveType::Percent) { width.Set(FDE_CSSLengthUnit::Percent, pPrimitive->GetFloat() / 100.0f); @@ -796,11 +793,11 @@ FDE_CSSVerticalAlign CFDE_CSSStyleSelector::ToVerticalAlign( } } -uint32_t CFDE_CSSStyleSelector::ToTextDecoration(IFDE_CSSValueList* pValue) { +uint32_t CFDE_CSSStyleSelector::ToTextDecoration(CFDE_CSSValueList* pValue) { uint32_t dwDecoration = 0; for (int32_t i = pValue->CountValues() - 1; i >= 0; --i) { - IFDE_CSSPrimitiveValue* pPrimitive = - static_cast<IFDE_CSSPrimitiveValue*>(pValue->GetValue(i)); + CFDE_CSSPrimitiveValue* pPrimitive = + static_cast<CFDE_CSSPrimitiveValue*>(pValue->GetValue(i)); if (pPrimitive->GetPrimitiveType() == FDE_CSSPrimitiveType::Enum) { switch (pPrimitive->GetEnum()) { case FDE_CSSPropertyValue::Underline: @@ -848,22 +845,6 @@ uint32_t CFDE_CSSComputedStyle::Release() { return dwRefCount; } -IFDE_CSSFontStyle* CFDE_CSSComputedStyle::GetFontStyles() { - return static_cast<IFDE_CSSFontStyle*>(this); -} - -IFDE_CSSBoundaryStyle* CFDE_CSSComputedStyle::GetBoundaryStyles() { - return static_cast<IFDE_CSSBoundaryStyle*>(this); -} - -IFDE_CSSPositionStyle* CFDE_CSSComputedStyle::GetPositionStyles() { - return static_cast<IFDE_CSSPositionStyle*>(this); -} - -IFDE_CSSParagraphStyle* CFDE_CSSComputedStyle::GetParagraphStyles() { - return static_cast<IFDE_CSSParagraphStyle*>(this); -} - bool CFDE_CSSComputedStyle::GetCustomStyle(const CFX_WideStringC& wsName, CFX_WideString& wsValue) const { for (int32_t i = pdfium::CollectionSize<int32_t>(m_CustomProperties) - 2; @@ -883,7 +864,7 @@ int32_t CFDE_CSSComputedStyle::CountFontFamilies() const { } const FX_WCHAR* CFDE_CSSComputedStyle::GetFontFamily(int32_t index) const { - return (static_cast<IFDE_CSSPrimitiveValue*>( + return (static_cast<CFDE_CSSPrimitiveValue*>( m_InheritedData.m_pFontFamily->GetValue(index))) ->GetString(index); } @@ -893,11 +874,11 @@ uint16_t CFDE_CSSComputedStyle::GetFontWeight() const { } FDE_CSSFontVariant CFDE_CSSComputedStyle::GetFontVariant() const { - return static_cast<FDE_CSSFontVariant>(m_InheritedData.m_eFontVariant); + return m_InheritedData.m_eFontVariant; } FDE_CSSFontStyle CFDE_CSSComputedStyle::GetFontStyle() const { - return static_cast<FDE_CSSFontStyle>(m_InheritedData.m_eFontStyle); + return m_InheritedData.m_eFontStyle; } FX_FLOAT CFDE_CSSComputedStyle::GetFontSize() const { @@ -954,7 +935,7 @@ void CFDE_CSSComputedStyle::SetPaddingWidth(const FDE_CSSRECT& rect) { } FDE_CSSDisplay CFDE_CSSComputedStyle::GetDisplay() const { - return static_cast<FDE_CSSDisplay>(m_NonInheritedData.m_eDisplay); + return m_NonInheritedData.m_eDisplay; } FX_FLOAT CFDE_CSSComputedStyle::GetLineHeight() const { @@ -966,11 +947,11 @@ const FDE_CSSLENGTH& CFDE_CSSComputedStyle::GetTextIndent() const { } FDE_CSSTextAlign CFDE_CSSComputedStyle::GetTextAlign() const { - return static_cast<FDE_CSSTextAlign>(m_InheritedData.m_eTextAlign); + return m_InheritedData.m_eTextAlign; } FDE_CSSVerticalAlign CFDE_CSSComputedStyle::GetVerticalAlign() const { - return static_cast<FDE_CSSVerticalAlign>(m_NonInheritedData.m_eVerticalAlign); + return m_NonInheritedData.m_eVerticalAlign; } FX_FLOAT CFDE_CSSComputedStyle::GetNumberVerticalAlign() const { diff --git a/xfa/fde/css/fde_cssstyleselector.h b/xfa/fde/css/fde_cssstyleselector.h index 185ba75ba3..6c06f0e4e2 100644 --- a/xfa/fde/css/fde_cssstyleselector.h +++ b/xfa/fde/css/fde_cssstyleselector.h @@ -37,7 +37,7 @@ class CFDE_CSSRuleCollection { CFDE_CSSRuleCollection(); ~CFDE_CSSRuleCollection(); - void AddRulesFrom(const CFX_ArrayTemplate<IFDE_CSSStyleSheet*>& sheets, + void AddRulesFrom(const CFX_ArrayTemplate<CFDE_CSSStyleSheet*>& sheets, uint32_t dwMediaList, CFGAS_FontMgr* pFontMgr); void Clear(); @@ -62,7 +62,7 @@ class CFDE_CSSRuleCollection { FDE_CSSRuleData* GetPseudoRuleData() { return m_pPseudoRules; } protected: - void AddRulesFrom(IFDE_CSSStyleSheet* pStyleSheet, + void AddRulesFrom(CFDE_CSSStyleSheet* pStyleSheet, IFDE_CSSRule* pRule, uint32_t dwMediaList, CFGAS_FontMgr* pFontMgr); @@ -89,15 +89,15 @@ class CFDE_CSSStyleSelector { void SetDefFontSize(FX_FLOAT fFontSize); - bool SetStyleSheet(FDE_CSSStyleSheetGroup eType, IFDE_CSSStyleSheet* pSheet); + bool SetStyleSheet(FDE_CSSStyleSheetGroup eType, CFDE_CSSStyleSheet* pSheet); bool SetStyleSheets(FDE_CSSStyleSheetGroup eType, - const CFX_ArrayTemplate<IFDE_CSSStyleSheet*>* pArray); + const CFX_ArrayTemplate<CFDE_CSSStyleSheet*>* pArray); void SetStylePriority(FDE_CSSStyleSheetGroup eType, FDE_CSSStyleSheetPriority ePriority); void UpdateStyleIndex(uint32_t dwMediaList); CFDE_CSSAccelerator* InitAccelerator(); - IFDE_CSSComputedStyle* CreateComputedStyle( - IFDE_CSSComputedStyle* pParentStyle); + CFDE_CSSComputedStyle* CreateComputedStyle( + CFDE_CSSComputedStyle* pParentStyle); int32_t MatchDeclarations( CXFA_CSSTagProvider* pTag, CFX_ArrayTemplate<CFDE_CSSDeclaration*>& matchedDecls, @@ -105,7 +105,7 @@ class CFDE_CSSStyleSelector { void ComputeStyle(CXFA_CSSTagProvider* pTag, const CFDE_CSSDeclaration** ppDeclArray, int32_t iDeclCount, - IFDE_CSSComputedStyle* pDestStyle); + CFDE_CSSComputedStyle* pDestStyle); protected: void Reset(); @@ -121,7 +121,7 @@ class CFDE_CSSStyleSelector { void ApplyDeclarations(bool bPriority, const CFDE_CSSDeclaration** ppDeclArray, int32_t iDeclCount, - IFDE_CSSComputedStyle* pDestStyle); + CFDE_CSSComputedStyle* pDestStyle); void ApplyProperty(FDE_CSSProperty eProperty, IFDE_CSSValue* pValue, CFDE_CSSComputedStyle* pComputedStyle); @@ -131,7 +131,7 @@ class CFDE_CSSStyleSelector { FX_FLOAT fPercentBase); bool SetLengthWithPercent(FDE_CSSLENGTH& width, FDE_CSSPrimitiveType eType, - IFDE_CSSPrimitiveValue* pPrimitive, + CFDE_CSSPrimitiveValue* pPrimitive, FX_FLOAT fFontSize); FX_FLOAT ToFontSize(FDE_CSSPropertyValue eValue, FX_FLOAT fCurFontSize); FDE_CSSDisplay ToDisplay(FDE_CSSPropertyValue eValue); @@ -139,12 +139,12 @@ class CFDE_CSSStyleSelector { uint16_t ToFontWeight(FDE_CSSPropertyValue eValue); FDE_CSSFontStyle ToFontStyle(FDE_CSSPropertyValue eValue); FDE_CSSVerticalAlign ToVerticalAlign(FDE_CSSPropertyValue eValue); - uint32_t ToTextDecoration(IFDE_CSSValueList* pList); + uint32_t ToTextDecoration(CFDE_CSSValueList* pList); FDE_CSSFontVariant ToFontVariant(FDE_CSSPropertyValue eValue); CFGAS_FontMgr* const m_pFontMgr; FX_FLOAT m_fDefFontSize; - CFX_ArrayTemplate<IFDE_CSSStyleSheet*> m_SheetGroups[3]; + CFX_ArrayTemplate<CFDE_CSSStyleSheet*> m_SheetGroups[3]; CFDE_CSSRuleCollection m_RuleCollection[3]; FDE_CSSStyleSheetGroup m_ePriorities[3]; std::unique_ptr<CFDE_CSSAccelerator> m_pAccelerator; @@ -158,7 +158,7 @@ class CFDE_CSSInheritedData { FDE_CSSLENGTH m_LetterSpacing; FDE_CSSLENGTH m_WordSpacing; FDE_CSSLENGTH m_TextIndent; - IFDE_CSSValueList* m_pFontFamily; + CFDE_CSSValueList* m_pFontFamily; FX_FLOAT m_fFontSize; FX_FLOAT m_fLineHeight; FX_ARGB m_dwFontColor; @@ -188,11 +188,7 @@ class CFDE_CSSNonInheritedData { bool m_bHasPadding; }; -class CFDE_CSSComputedStyle : public IFDE_CSSComputedStyle, - public IFDE_CSSBoundaryStyle, - public IFDE_CSSFontStyle, - public IFDE_CSSPositionStyle, - public IFDE_CSSParagraphStyle { +class CFDE_CSSComputedStyle : public IFX_Retainable { public: CFDE_CSSComputedStyle(); ~CFDE_CSSComputedStyle() override; @@ -201,58 +197,51 @@ class CFDE_CSSComputedStyle : public IFDE_CSSComputedStyle, uint32_t Retain() override; uint32_t Release() override; - // IFDE_CSSComputedStyle - IFDE_CSSFontStyle* GetFontStyles() override; - IFDE_CSSBoundaryStyle* GetBoundaryStyles() override; - IFDE_CSSPositionStyle* GetPositionStyles() override; - IFDE_CSSParagraphStyle* GetParagraphStyles() override; - bool GetCustomStyle(const CFX_WideStringC& wsName, - CFX_WideString& wsValue) const override; - - // IFDE_CSSFontStyle: - int32_t CountFontFamilies() const override; - const FX_WCHAR* GetFontFamily(int32_t index) const override; - uint16_t GetFontWeight() const override; - FDE_CSSFontVariant GetFontVariant() const override; - FDE_CSSFontStyle GetFontStyle() const override; - FX_FLOAT GetFontSize() const override; - FX_ARGB GetColor() const override; - void SetFontWeight(uint16_t wFontWeight) override; - void SetFontVariant(FDE_CSSFontVariant eFontVariant) override; - void SetFontStyle(FDE_CSSFontStyle eFontStyle) override; - void SetFontSize(FX_FLOAT fFontSize) override; - void SetColor(FX_ARGB dwFontColor) override; - - // IFDE_CSSBoundaryStyle: - const FDE_CSSRECT* GetBorderWidth() const override; - const FDE_CSSRECT* GetMarginWidth() const override; - const FDE_CSSRECT* GetPaddingWidth() const override; - void SetMarginWidth(const FDE_CSSRECT& rect) override; - void SetPaddingWidth(const FDE_CSSRECT& rect) override; - - // IFDE_CSSPositionStyle: - FDE_CSSDisplay GetDisplay() const override; - - // IFDE_CSSParagraphStyle: - FX_FLOAT GetLineHeight() const override; - const FDE_CSSLENGTH& GetTextIndent() const override; - FDE_CSSTextAlign GetTextAlign() const override; - FDE_CSSVerticalAlign GetVerticalAlign() const override; - FX_FLOAT GetNumberVerticalAlign() const override; - uint32_t GetTextDecoration() const override; - const FDE_CSSLENGTH& GetLetterSpacing() const override; - void SetLineHeight(FX_FLOAT fLineHeight) override; - void SetTextIndent(const FDE_CSSLENGTH& textIndent) override; - void SetTextAlign(FDE_CSSTextAlign eTextAlign) override; - void SetNumberVerticalAlign(FX_FLOAT fAlign) override; - void SetTextDecoration(uint32_t dwTextDecoration) override; - void SetLetterSpacing(const FDE_CSSLENGTH& letterSpacing) override; + int32_t CountFontFamilies() const; + const FX_WCHAR* GetFontFamily(int32_t index) const; + uint16_t GetFontWeight() const; + FDE_CSSFontVariant GetFontVariant() const; + FDE_CSSFontStyle GetFontStyle() const; + FX_FLOAT GetFontSize() const; + FX_ARGB GetColor() const; + void SetFontWeight(uint16_t wFontWeight); + void SetFontVariant(FDE_CSSFontVariant eFontVariant); + void SetFontStyle(FDE_CSSFontStyle eFontStyle); + void SetFontSize(FX_FLOAT fFontSize); + void SetColor(FX_ARGB dwFontColor); + + const FDE_CSSRECT* GetBorderWidth() const; + const FDE_CSSRECT* GetMarginWidth() const; + const FDE_CSSRECT* GetPaddingWidth() const; + void SetMarginWidth(const FDE_CSSRECT& rect); + void SetPaddingWidth(const FDE_CSSRECT& rect); + + FDE_CSSDisplay GetDisplay() const; + + FX_FLOAT GetLineHeight() const; + const FDE_CSSLENGTH& GetTextIndent() const; + FDE_CSSTextAlign GetTextAlign() const; + FDE_CSSVerticalAlign GetVerticalAlign() const; + FX_FLOAT GetNumberVerticalAlign() const; + uint32_t GetTextDecoration() const; + const FDE_CSSLENGTH& GetLetterSpacing() const; + void SetLineHeight(FX_FLOAT fLineHeight); + void SetTextIndent(const FDE_CSSLENGTH& textIndent); + void SetTextAlign(FDE_CSSTextAlign eTextAlign); + void SetNumberVerticalAlign(FX_FLOAT fAlign); + void SetTextDecoration(uint32_t dwTextDecoration); + void SetLetterSpacing(const FDE_CSSLENGTH& letterSpacing); void AddCustomStyle(const CFX_WideString& wsName, const CFX_WideString& wsValue); - uint32_t m_dwRefCount; + bool GetCustomStyle(const CFX_WideStringC& wsName, + CFX_WideString& wsValue) const; + CFDE_CSSInheritedData m_InheritedData; CFDE_CSSNonInheritedData m_NonInheritedData; + + private: + uint32_t m_dwRefCount; std::vector<CFX_WideString> m_CustomProperties; }; diff --git a/xfa/fde/css/fde_cssstylesheet.cpp b/xfa/fde/css/fde_cssstylesheet.cpp index f48789533c..a3783c3756 100644 --- a/xfa/fde/css/fde_cssstylesheet.cpp +++ b/xfa/fde/css/fde_cssstylesheet.cpp @@ -13,24 +13,10 @@ #include "xfa/fde/css/fde_csssyntax.h" #include "xfa/fgas/crt/fgas_codepage.h" -IFDE_CSSStyleSheet* IFDE_CSSStyleSheet::LoadFromBuffer( - const CFX_WideString& szUrl, - const FX_WCHAR* pBuffer, - int32_t iBufSize, - uint16_t wCodePage, - uint32_t dwMediaList) { - CFDE_CSSStyleSheet* pStyleSheet = new CFDE_CSSStyleSheet(dwMediaList); - if (!pStyleSheet->LoadFromBuffer(szUrl, pBuffer, iBufSize, wCodePage)) { - pStyleSheet->Release(); - pStyleSheet = nullptr; - } - return pStyleSheet; -} - -CFDE_CSSStyleSheet::CFDE_CSSStyleSheet(uint32_t dwMediaList) +CFDE_CSSStyleSheet::CFDE_CSSStyleSheet() : m_wCodePage(FX_CODEPAGE_UTF8), m_wRefCount(1), - m_dwMediaList(dwMediaList), + m_dwMediaList(FDE_CSSMEDIATYPE_ALL), m_RuleArray(100) { ASSERT(m_dwMediaList > 0); } @@ -68,9 +54,8 @@ uint32_t CFDE_CSSStyleSheet::Retain() { uint32_t CFDE_CSSStyleSheet::Release() { uint32_t dwRefCount = --m_wRefCount; - if (dwRefCount == 0) { + if (dwRefCount == 0) delete this; - } return dwRefCount; } @@ -95,16 +80,15 @@ IFDE_CSSRule* CFDE_CSSStyleSheet::GetRule(int32_t index) { return m_RuleArray.GetAt(index); } -bool CFDE_CSSStyleSheet::LoadFromBuffer(const CFX_WideString& szUrl, - const FX_WCHAR* pBuffer, - int32_t iBufSize, - uint16_t wCodePage) { +bool CFDE_CSSStyleSheet::LoadFromBuffer(const FX_WCHAR* pBuffer, + int32_t iBufSize) { ASSERT(pBuffer && iBufSize > 0); - std::unique_ptr<CFDE_CSSSyntaxParser> pSyntax(new CFDE_CSSSyntaxParser); - bool bRet = pSyntax->Init(pBuffer, iBufSize) && LoadFromSyntax(pSyntax.get()); - m_wCodePage = wCodePage; - m_szUrl = szUrl; - return bRet; + + m_wCodePage = FX_CODEPAGE_UTF8; + m_szUrl = CFX_WideString(); + + auto pSyntax = pdfium::MakeUnique<CFDE_CSSSyntaxParser>(); + return pSyntax->Init(pBuffer, iBufSize) && LoadFromSyntax(pSyntax.get()); } bool CFDE_CSSStyleSheet::LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax) { @@ -333,6 +317,10 @@ FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::SkipRuleSet( CFDE_CSSStyleRule::CFDE_CSSStyleRule() : m_ppSelector(nullptr), m_iSelectors(0) {} +FDE_CSSRuleType CFDE_CSSStyleRule::GetType() const { + return FDE_CSSRuleType::Style; +} + int32_t CFDE_CSSStyleRule::CountSelectorLists() const { return m_iSelectors; } @@ -373,6 +361,10 @@ CFDE_CSSMediaRule::~CFDE_CSSMediaRule() { } } +FDE_CSSRuleType CFDE_CSSMediaRule::GetType() const { + return FDE_CSSRuleType::Media; +} + uint32_t CFDE_CSSMediaRule::GetMediaList() const { return m_dwMediaList; } @@ -532,6 +524,6 @@ CFDE_CSSSelector* CFDE_CSSSelector::FromString( return pPseudoFirst; } -CFDE_CSSDeclaration* CFDE_CSSFontFaceRule::GetDeclaration() { - return &m_Declaration; +FDE_CSSRuleType CFDE_CSSFontFaceRule::GetType() const { + return FDE_CSSRuleType::FontFace; } diff --git a/xfa/fde/css/fde_cssstylesheet.h b/xfa/fde/css/fde_cssstylesheet.h index 0d038c9eb5..2fc195c9dd 100644 --- a/xfa/fde/css/fde_cssstylesheet.h +++ b/xfa/fde/css/fde_cssstylesheet.h @@ -38,33 +38,36 @@ class CFDE_CSSSelector { CFDE_CSSSelector* m_pNext; }; -class CFDE_CSSStyleRule : public IFDE_CSSStyleRule { +class CFDE_CSSStyleRule : public IFDE_CSSRule { public: CFDE_CSSStyleRule(); - // IFDE_CSSStyleRule - int32_t CountSelectorLists() const override; - CFDE_CSSSelector* GetSelectorList(int32_t index) const override; - CFDE_CSSDeclaration* GetDeclaration() override; + // IFDE_CSSRule + FDE_CSSRuleType GetType() const override; + int32_t CountSelectorLists() const; + CFDE_CSSSelector* GetSelectorList(int32_t index) const; + CFDE_CSSDeclaration* GetDeclaration(); CFDE_CSSDeclaration& GetDeclImp() { return m_Declaration; } void SetSelector(const CFX_ArrayTemplate<CFDE_CSSSelector*>& list); - protected: + private: CFDE_CSSDeclaration m_Declaration; CFDE_CSSSelector** m_ppSelector; int32_t m_iSelectors; }; -class CFDE_CSSMediaRule : public IFDE_CSSMediaRule { +class CFDE_CSSMediaRule : public IFDE_CSSRule { public: explicit CFDE_CSSMediaRule(uint32_t dwMediaList); ~CFDE_CSSMediaRule() override; - // IFDE_CSSMediaRule - uint32_t GetMediaList() const override; - int32_t CountRules() const override; - IFDE_CSSRule* GetRule(int32_t index) override; + // IFDE_CSSValue + FDE_CSSRuleType GetType() const override; + + uint32_t GetMediaList() const; + int32_t CountRules() const; + IFDE_CSSRule* GetRule(int32_t index); CFX_MassArrayTemplate<IFDE_CSSRule*>& GetArray() { return m_RuleArray; } @@ -73,39 +76,35 @@ class CFDE_CSSMediaRule : public IFDE_CSSMediaRule { CFX_MassArrayTemplate<IFDE_CSSRule*> m_RuleArray; }; -class CFDE_CSSFontFaceRule : public IFDE_CSSFontFaceRule { +class CFDE_CSSFontFaceRule : public IFDE_CSSRule { public: - // IFDE_CSSFontFaceRule - CFDE_CSSDeclaration* GetDeclaration() override; + // IFDE_CSSRule. + FDE_CSSRuleType GetType() const override; CFDE_CSSDeclaration& GetDeclImp() { return m_Declaration; } - protected: + private: CFDE_CSSDeclaration m_Declaration; }; -class CFDE_CSSStyleSheet : public IFDE_CSSStyleSheet { +class CFDE_CSSStyleSheet : public IFX_Retainable { public: - explicit CFDE_CSSStyleSheet(uint32_t dwMediaList); + CFDE_CSSStyleSheet(); ~CFDE_CSSStyleSheet() override; // IFX_Retainable: uint32_t Retain() override; uint32_t Release() override; - // IFDE_CSSStyleSheet: - bool GetUrl(CFX_WideString& szUrl) override; - uint32_t GetMediaList() const override; - uint16_t GetCodePage() const override; - int32_t CountRules() const override; - IFDE_CSSRule* GetRule(int32_t index) override; + bool LoadFromBuffer(const FX_WCHAR* pBuffer, int32_t iBufSize); - bool LoadFromBuffer(const CFX_WideString& szUrl, - const FX_WCHAR* pBuffer, - int32_t iBufSize, - uint16_t wCodePage); + bool GetUrl(CFX_WideString& szUrl); + uint32_t GetMediaList() const; + uint16_t GetCodePage() const; + int32_t CountRules() const; + IFDE_CSSRule* GetRule(int32_t index); - protected: + private: void Reset(); bool LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax); FDE_CSSSyntaxStatus LoadStyleRule( diff --git a/xfa/fxfa/app/cxfa_loadercontext.h b/xfa/fxfa/app/cxfa_loadercontext.h index 39d2adc74d..c647f62a33 100644 --- a/xfa/fxfa/app/cxfa_loadercontext.h +++ b/xfa/fxfa/app/cxfa_loadercontext.h @@ -14,7 +14,7 @@ class CFDE_XMLNode; class CXFA_Node; -class IFDE_CSSComputedStyle; +class CFDE_CSSComputedStyle; class CXFA_LoaderContext { public: @@ -31,7 +31,7 @@ class CXFA_LoaderContext { int32_t m_iTotalLines; CFDE_XMLNode* m_pXMLNode; CXFA_Node* m_pNode; - IFDE_CSSComputedStyle* m_pParentStyle; + CFDE_CSSComputedStyle* m_pParentStyle; CFX_ArrayTemplate<FX_FLOAT> m_lineHeights; uint32_t m_dwFlags; std::vector<FX_FLOAT> m_BlocksHeight; diff --git a/xfa/fxfa/app/cxfa_textlayout.cpp b/xfa/fxfa/app/cxfa_textlayout.cpp index 47f40ac04f..a1870f1f58 100644 --- a/xfa/fxfa/app/cxfa_textlayout.cpp +++ b/xfa/fxfa/app/cxfa_textlayout.cpp @@ -11,6 +11,7 @@ #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" #include "xfa/fde/cfde_path.h" +#include "xfa/fde/css/fde_cssstyleselector.h" #include "xfa/fde/fde_gedevice.h" #include "xfa/fde/fde_object.h" #include "xfa/fde/xml/fde_xml_imp.h" @@ -171,21 +172,20 @@ void CXFA_TextLayout::InitBreak(FX_FLOAT fLineWidth) { m_pBreak->SetLineBreakTolerance(fFontSize * 0.2f); } -void CXFA_TextLayout::InitBreak(IFDE_CSSComputedStyle* pStyle, +void CXFA_TextLayout::InitBreak(CFDE_CSSComputedStyle* pStyle, FDE_CSSDisplay eDisplay, FX_FLOAT fLineWidth, CFDE_XMLNode* pXMLNode, - IFDE_CSSComputedStyle* pParentStyle) { + CFDE_CSSComputedStyle* pParentStyle) { if (!pStyle) { InitBreak(fLineWidth); return; } - IFDE_CSSParagraphStyle* pParaStyle = pStyle->GetParagraphStyles(); if (eDisplay == FDE_CSSDisplay::Block || eDisplay == FDE_CSSDisplay::ListItem) { int32_t iAlign = FX_RTFLINEALIGNMENT_Left; - switch (pParaStyle->GetTextAlign()) { + switch (pStyle->GetTextAlign()) { case FDE_CSSTextAlign::Right: iAlign = FX_RTFLINEALIGNMENT_Right; break; @@ -203,9 +203,8 @@ void CXFA_TextLayout::InitBreak(IFDE_CSSComputedStyle* pStyle, } m_pBreak->SetAlignment(iAlign); FX_FLOAT fStart = 0; - const FDE_CSSRECT* pRect = pStyle->GetBoundaryStyles()->GetMarginWidth(); - const FDE_CSSRECT* pPaddingRect = - pStyle->GetBoundaryStyles()->GetPaddingWidth(); + const FDE_CSSRECT* pRect = pStyle->GetMarginWidth(); + const FDE_CSSRECT* pPaddingRect = pStyle->GetPaddingWidth(); if (pRect) { fStart = pRect->left.GetValue(); fLineWidth -= pRect->right.GetValue(); @@ -214,10 +213,8 @@ void CXFA_TextLayout::InitBreak(IFDE_CSSComputedStyle* pStyle, fLineWidth -= pPaddingRect->right.GetValue(); } if (eDisplay == FDE_CSSDisplay::ListItem) { - const FDE_CSSRECT* pParRect = - pParentStyle->GetBoundaryStyles()->GetMarginWidth(); - const FDE_CSSRECT* pParPaddingRect = - pParentStyle->GetBoundaryStyles()->GetPaddingWidth(); + const FDE_CSSRECT* pParRect = pParentStyle->GetMarginWidth(); + const FDE_CSSRECT* pParPaddingRect = pParentStyle->GetPaddingWidth(); if (pParRect) { fStart += pParRect->left.GetValue(); fLineWidth -= pParRect->right.GetValue(); @@ -231,11 +228,11 @@ void CXFA_TextLayout::InitBreak(IFDE_CSSComputedStyle* pStyle, pNewRect.right.Set(FDE_CSSLengthUnit::Point, pRect->right.GetValue()); pNewRect.top.Set(FDE_CSSLengthUnit::Point, pRect->top.GetValue()); pNewRect.bottom.Set(FDE_CSSLengthUnit::Point, pRect->bottom.GetValue()); - pStyle->GetBoundaryStyles()->SetMarginWidth(pNewRect); + pStyle->SetMarginWidth(pNewRect); } } m_pBreak->SetLineBoundary(fStart, fLineWidth); - FX_FLOAT fIndent = pParaStyle->GetTextIndent().GetValue(); + FX_FLOAT fIndent = pStyle->GetTextIndent().GetValue(); if (fIndent > 0) fStart += fIndent; @@ -257,7 +254,7 @@ void CXFA_TextLayout::InitBreak(IFDE_CSSComputedStyle* pStyle, m_pBreak->SetHorizontalScale( m_textParser.GetHorScale(m_pTextProvider, pStyle, pXMLNode)); m_pBreak->SetVerticalScale(m_textParser.GetVerScale(m_pTextProvider, pStyle)); - m_pBreak->SetCharSpace(pParaStyle->GetLetterSpacing().GetValue()); + m_pBreak->SetCharSpace(pStyle->GetLetterSpacing().GetValue()); } int32_t CXFA_TextLayout::GetText(CFX_WideString& wsText) { @@ -679,7 +676,7 @@ bool CXFA_TextLayout::Loader(const CFX_SizeF& szText, if (!m_textParser.IsParsed()) m_textParser.DoParse(pXMLContainer, m_pTextProvider); - IFDE_CSSComputedStyle* pRootStyle = + CFDE_CSSComputedStyle* pRootStyle = m_textParser.CreateRootStyle(m_pTextProvider); LoadRichText(pXMLContainer, szText, fLinePos, pRootStyle, bSavePieces); pRootStyle->Release(); @@ -726,7 +723,7 @@ void CXFA_TextLayout::LoadText(CXFA_Node* pNode, bool CXFA_TextLayout::LoadRichText(CFDE_XMLNode* pXMLNode, const CFX_SizeF& szText, FX_FLOAT& fLinePos, - IFDE_CSSComputedStyle* pParentStyle, + CFDE_CSSComputedStyle* pParentStyle, bool bSavePieces, CXFA_LinkUserData* pLinkData, bool bEndBreak, @@ -740,7 +737,7 @@ bool CXFA_TextLayout::LoadRichText(CFDE_XMLNode* pXMLNode, FDE_CSSDisplay eDisplay = FDE_CSSDisplay::None; bool bContentNode = false; FX_FLOAT fSpaceBelow = 0; - IFDE_CSSComputedStyle* pStyle = nullptr; + CFDE_CSSComputedStyle* pStyle = nullptr; CFX_WideString wsName; if (bEndBreak) { bool bCurOl = false; @@ -778,8 +775,7 @@ bool CXFA_TextLayout::LoadRichText(CFDE_XMLNode* pXMLNode, (wsName.IsEmpty() || (wsName != FX_WSTRC(L"body") && wsName != FX_WSTRC(L"html") && wsName != FX_WSTRC(L"ol") && wsName != FX_WSTRC(L"ul")))) { - const FDE_CSSRECT* pRect = - pStyle->GetBoundaryStyles()->GetMarginWidth(); + const FDE_CSSRECT* pRect = pStyle->GetMarginWidth(); if (pRect) { fLinePos += pRect->top.GetValue(); fSpaceBelow = pRect->bottom.GetValue(); @@ -1001,7 +997,7 @@ void CXFA_TextLayout::EndBreak(uint32_t dwStatus, AppendTextLine(dwStatus, fLinePos, bSavePieces, true); } -void CXFA_TextLayout::DoTabstops(IFDE_CSSComputedStyle* pStyle, +void CXFA_TextLayout::DoTabstops(CFDE_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine) { if (!m_pTabstopContext || m_pTabstopContext->m_iTabCount == 0) return; @@ -1065,7 +1061,7 @@ void CXFA_TextLayout::AppendTextLine(uint32_t dwStatus, if (iPieces < 1) return; - IFDE_CSSComputedStyle* pStyle = nullptr; + CFDE_CSSComputedStyle* pStyle = nullptr; if (bSavePieces) { CXFA_PieceLine* pPieceLine = new CXFA_PieceLine; m_pieceLines.Add(pPieceLine); @@ -1190,12 +1186,11 @@ void CXFA_TextLayout::AppendTextLine(uint32_t dwStatus, if (pStyle) { FX_FLOAT fStart = 0; - const FDE_CSSRECT* pRect = pStyle->GetBoundaryStyles()->GetMarginWidth(); + const FDE_CSSRECT* pRect = pStyle->GetMarginWidth(); if (pRect) fStart = pRect->left.GetValue(); - FX_FLOAT fTextIndent = - pStyle->GetParagraphStyles()->GetTextIndent().GetValue(); + FX_FLOAT fTextIndent = pStyle->GetTextIndent().GetValue(); if (fTextIndent < 0) fStart -= fTextIndent; diff --git a/xfa/fxfa/app/cxfa_textlayout.h b/xfa/fxfa/app/cxfa_textlayout.h index 7c34d0d323..8575071faa 100644 --- a/xfa/fxfa/app/cxfa_textlayout.h +++ b/xfa/fxfa/app/cxfa_textlayout.h @@ -17,6 +17,7 @@ #include "xfa/fxfa/app/cxfa_textparser.h" class CFDE_Brush; +class CFDE_CSSComputedStyle; class CFDE_Pen; class CFDE_RenderDevice; class CFDE_XMLNode; @@ -27,7 +28,6 @@ class CXFA_Node; class CXFA_PieceLine; class CXFA_TextProvider; class CXFA_TextTabstopsContext; -class IFDE_CSSComputedStyle; class XFA_TextPiece; class CXFA_TextLayout { @@ -64,11 +64,11 @@ class CXFA_TextLayout { CFDE_XMLNode* GetXMLContainerNode(); CFX_RTFBreak* CreateBreak(bool bDefault); void InitBreak(FX_FLOAT fLineWidth); - void InitBreak(IFDE_CSSComputedStyle* pStyle, + void InitBreak(CFDE_CSSComputedStyle* pStyle, FDE_CSSDisplay eDisplay, FX_FLOAT fLineWidth, CFDE_XMLNode* pXMLNode, - IFDE_CSSComputedStyle* pParentStyle = nullptr); + CFDE_CSSComputedStyle* pParentStyle = nullptr); bool Loader(const CFX_SizeF& szText, FX_FLOAT& fLinePos, bool bSavePieces = true); @@ -79,7 +79,7 @@ class CXFA_TextLayout { bool LoadRichText(CFDE_XMLNode* pXMLNode, const CFX_SizeF& szText, FX_FLOAT& fLinePos, - IFDE_CSSComputedStyle* pParentStyle, + CFDE_CSSComputedStyle* pParentStyle, bool bSavePieces, CXFA_LinkUserData* pLinkData = nullptr, bool bEndBreak = true, @@ -113,7 +113,7 @@ class CXFA_TextLayout { FXTEXT_CHARPOS* pCharPos, bool bCharCode = false); bool ToRun(const XFA_TextPiece* pPiece, FX_RTFTEXTOBJ& tr); - void DoTabstops(IFDE_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine); + void DoTabstops(CFDE_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine); bool Layout(int32_t iBlock); int32_t CountBlocks() const; diff --git a/xfa/fxfa/app/cxfa_textparsecontext.cpp b/xfa/fxfa/app/cxfa_textparsecontext.cpp index c1747c2c18..e416242309 100644 --- a/xfa/fxfa/app/cxfa_textparsecontext.cpp +++ b/xfa/fxfa/app/cxfa_textparsecontext.cpp @@ -7,6 +7,7 @@ #include "xfa/fxfa/app/cxfa_textparsecontext.h" #include "xfa/fde/css/fde_cssdeclaration.h" +#include "xfa/fde/css/fde_cssstyleselector.h" CXFA_TextParseContext::CXFA_TextParseContext() : m_pParentStyle(nullptr), diff --git a/xfa/fxfa/app/cxfa_textparsecontext.h b/xfa/fxfa/app/cxfa_textparsecontext.h index db39af7c54..2faaadb440 100644 --- a/xfa/fxfa/app/cxfa_textparsecontext.h +++ b/xfa/fxfa/app/cxfa_textparsecontext.h @@ -10,7 +10,7 @@ #include "xfa/fde/css/fde_css.h" class CFDE_CSSDeclaration; -class IFDE_CSSComputedStyle; +class CFDE_CSSComputedStyle; class CXFA_TextParseContext { public: @@ -26,7 +26,7 @@ class CXFA_TextParseContext { } uint32_t CountDecls() const { return m_dwMatchedDecls; } - IFDE_CSSComputedStyle* m_pParentStyle; + CFDE_CSSComputedStyle* m_pParentStyle; protected: CFDE_CSSDeclaration** m_ppMatchedDecls; diff --git a/xfa/fxfa/app/cxfa_textparser.cpp b/xfa/fxfa/app/cxfa_textparser.cpp index 8fe923b058..77f22515be 100644 --- a/xfa/fxfa/app/cxfa_textparser.cpp +++ b/xfa/fxfa/app/cxfa_textparser.cpp @@ -11,6 +11,7 @@ #include "third_party/base/ptr_util.h" #include "xfa/fde/css/fde_css.h" #include "xfa/fde/css/fde_cssstyleselector.h" +#include "xfa/fde/css/fde_cssstylesheet.h" #include "xfa/fgas/crt/fgas_codepage.h" #include "xfa/fgas/font/cfgas_fontmgr.h" #include "xfa/fxfa/app/cxfa_csstagprovider.h" @@ -80,7 +81,7 @@ void CXFA_TextParser::InitCSSData(CXFA_TextProvider* pTextProvider) { } } -IFDE_CSSStyleSheet* CXFA_TextParser::LoadDefaultSheetStyle() { +CFDE_CSSStyleSheet* CXFA_TextParser::LoadDefaultSheetStyle() { static const FX_WCHAR s_pStyle[] = L"html,body,ol,p,ul{display:block}" L"li{display:list-item}" @@ -90,17 +91,20 @@ IFDE_CSSStyleSheet* CXFA_TextParser::LoadDefaultSheetStyle() { L"style:italic}" L"sup{vertical-align:+15em;font-size:.66em}sub{vertical-align:-15em;font-" L"size:.66em}"; - return IFDE_CSSStyleSheet::LoadFromBuffer( - CFX_WideString(), s_pStyle, FXSYS_wcslen(s_pStyle), FX_CODEPAGE_UTF8); + + CFDE_CSSStyleSheet* pStyleSheet = new CFDE_CSSStyleSheet(); + if (!pStyleSheet->LoadFromBuffer(s_pStyle, FXSYS_wcslen(s_pStyle))) { + pStyleSheet->Release(); + pStyleSheet = nullptr; + } + return pStyleSheet; } -IFDE_CSSComputedStyle* CXFA_TextParser::CreateRootStyle( +CFDE_CSSComputedStyle* CXFA_TextParser::CreateRootStyle( CXFA_TextProvider* pTextProvider) { CXFA_Font font = pTextProvider->GetFontNode(); CXFA_Para para = pTextProvider->GetParaNode(); - IFDE_CSSComputedStyle* pStyle = m_pSelector->CreateComputedStyle(nullptr); - IFDE_CSSFontStyle* pFontStyle = pStyle->GetFontStyles(); - IFDE_CSSParagraphStyle* pParaStyle = pStyle->GetParagraphStyles(); + CFDE_CSSComputedStyle* pStyle = m_pSelector->CreateComputedStyle(nullptr); FX_FLOAT fLineHeight = 0; FX_FLOAT fFontSize = 10; @@ -108,7 +112,7 @@ IFDE_CSSComputedStyle* CXFA_TextParser::CreateRootStyle( fLineHeight = para.GetLineHeight(); FDE_CSSLENGTH indent; indent.Set(FDE_CSSLengthUnit::Point, para.GetTextIndent()); - pParaStyle->SetTextIndent(indent); + pStyle->SetTextIndent(indent); FDE_CSSTextAlign hAlign = FDE_CSSTextAlign::Left; switch (para.GetHorizontalAlign()) { case XFA_ATTRIBUTEENUM_Center: @@ -124,26 +128,25 @@ IFDE_CSSComputedStyle* CXFA_TextParser::CreateRootStyle( hAlign = FDE_CSSTextAlign::JustifyAll; break; } - pParaStyle->SetTextAlign(hAlign); + pStyle->SetTextAlign(hAlign); FDE_CSSRECT rtMarginWidth; rtMarginWidth.left.Set(FDE_CSSLengthUnit::Point, para.GetMarginLeft()); rtMarginWidth.top.Set(FDE_CSSLengthUnit::Point, para.GetSpaceAbove()); rtMarginWidth.right.Set(FDE_CSSLengthUnit::Point, para.GetMarginRight()); rtMarginWidth.bottom.Set(FDE_CSSLengthUnit::Point, para.GetSpaceBelow()); - pStyle->GetBoundaryStyles()->SetMarginWidth(rtMarginWidth); + pStyle->SetMarginWidth(rtMarginWidth); } if (font) { - pFontStyle->SetColor(font.GetColor()); - pFontStyle->SetFontStyle(font.IsItalic() ? FDE_CSSFontStyle::Italic - : FDE_CSSFontStyle::Normal); - pFontStyle->SetFontWeight(font.IsBold() ? FXFONT_FW_BOLD - : FXFONT_FW_NORMAL); - pParaStyle->SetNumberVerticalAlign(-font.GetBaselineShift()); + pStyle->SetColor(font.GetColor()); + pStyle->SetFontStyle(font.IsItalic() ? FDE_CSSFontStyle::Italic + : FDE_CSSFontStyle::Normal); + pStyle->SetFontWeight(font.IsBold() ? FXFONT_FW_BOLD : FXFONT_FW_NORMAL); + pStyle->SetNumberVerticalAlign(-font.GetBaselineShift()); fFontSize = font.GetFontSize(); FDE_CSSLENGTH letterSpacing; letterSpacing.Set(FDE_CSSLengthUnit::Point, font.GetLetterSpacing()); - pParaStyle->SetLetterSpacing(letterSpacing); + pStyle->SetLetterSpacing(letterSpacing); uint32_t dwDecoration = 0; if (font.GetLineThrough() > 0) dwDecoration |= FDE_CSSTEXTDECORATION_LineThrough; @@ -152,43 +155,38 @@ IFDE_CSSComputedStyle* CXFA_TextParser::CreateRootStyle( else if (font.GetUnderline() > 0) dwDecoration |= FDE_CSSTEXTDECORATION_Underline; - pParaStyle->SetTextDecoration(dwDecoration); + pStyle->SetTextDecoration(dwDecoration); } - pParaStyle->SetLineHeight(fLineHeight); - pFontStyle->SetFontSize(fFontSize); + pStyle->SetLineHeight(fLineHeight); + pStyle->SetFontSize(fFontSize); return pStyle; } -IFDE_CSSComputedStyle* CXFA_TextParser::CreateStyle( - IFDE_CSSComputedStyle* pParentStyle) { - IFDE_CSSComputedStyle* pNewStyle = +CFDE_CSSComputedStyle* CXFA_TextParser::CreateStyle( + CFDE_CSSComputedStyle* pParentStyle) { + CFDE_CSSComputedStyle* pNewStyle = m_pSelector->CreateComputedStyle(pParentStyle); ASSERT(pNewStyle); if (!pParentStyle) return pNewStyle; - IFDE_CSSParagraphStyle* pParaStyle = pParentStyle->GetParagraphStyles(); - uint32_t dwDecoration = pParaStyle->GetTextDecoration(); + uint32_t dwDecoration = pParentStyle->GetTextDecoration(); FX_FLOAT fBaseLine = 0; - if (pParaStyle->GetVerticalAlign() == FDE_CSSVerticalAlign::Number) - fBaseLine = pParaStyle->GetNumberVerticalAlign(); - - pParaStyle = pNewStyle->GetParagraphStyles(); - pParaStyle->SetTextDecoration(dwDecoration); - pParaStyle->SetNumberVerticalAlign(fBaseLine); - - IFDE_CSSBoundaryStyle* pBoundarytyle = pParentStyle->GetBoundaryStyles(); - const FDE_CSSRECT* pRect = pBoundarytyle->GetMarginWidth(); - if (pRect) { - pBoundarytyle = pNewStyle->GetBoundaryStyles(); - pBoundarytyle->SetMarginWidth(*pRect); - } + if (pParentStyle->GetVerticalAlign() == FDE_CSSVerticalAlign::Number) + fBaseLine = pParentStyle->GetNumberVerticalAlign(); + + pNewStyle->SetTextDecoration(dwDecoration); + pNewStyle->SetNumberVerticalAlign(fBaseLine); + + const FDE_CSSRECT* pRect = pParentStyle->GetMarginWidth(); + if (pRect) + pNewStyle->SetMarginWidth(*pRect); return pNewStyle; } -IFDE_CSSComputedStyle* CXFA_TextParser::ComputeStyle( +CFDE_CSSComputedStyle* CXFA_TextParser::ComputeStyle( CFDE_XMLNode* pXMLNode, - IFDE_CSSComputedStyle* pParentStyle) { + CFDE_CSSComputedStyle* pParentStyle) { auto it = m_mapXMLNodeToParseContext.find(pXMLNode); if (it == m_mapXMLNodeToParseContext.end()) return nullptr; @@ -205,7 +203,7 @@ IFDE_CSSComputedStyle* CXFA_TextParser::ComputeStyle( if (tagProvider.m_bContent) return nullptr; - IFDE_CSSComputedStyle* pStyle = CreateStyle(pParentStyle); + CFDE_CSSComputedStyle* pStyle = CreateStyle(pParentStyle); CFDE_CSSAccelerator* pCSSAccel = m_pSelector->InitAccelerator(); pCSSAccel->OnEnterTag(&tagProvider); m_pSelector->ComputeStyle(&tagProvider, pContext->GetDecls(), @@ -221,13 +219,13 @@ void CXFA_TextParser::DoParse(CFDE_XMLNode* pXMLContainer, m_bParsed = true; InitCSSData(pTextProvider); - IFDE_CSSComputedStyle* pRootStyle = CreateRootStyle(pTextProvider); + CFDE_CSSComputedStyle* pRootStyle = CreateRootStyle(pTextProvider); ParseRichText(pXMLContainer, pRootStyle); pRootStyle->Release(); } void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode, - IFDE_CSSComputedStyle* pParentStyle) { + CFDE_CSSComputedStyle* pParentStyle) { if (!pXMLNode) return; @@ -236,7 +234,7 @@ void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode, if (!tagProvider.m_bTagAvailable) return; - IFDE_CSSComputedStyle* pNewStyle = nullptr; + CFDE_CSSComputedStyle* pNewStyle = nullptr; if ((tagProvider.GetTagName() != FX_WSTRC(L"body")) || (tagProvider.GetTagName() != FX_WSTRC(L"html"))) { CXFA_TextParseContext* pTextContext = new CXFA_TextParseContext; @@ -256,7 +254,7 @@ void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode, if (iMatchedDecls > 0) pTextContext->SetDecls(ppMatchDecls, iMatchedDecls); - eDisplay = pNewStyle->GetPositionStyles()->GetDisplay(); + eDisplay = pNewStyle->GetDisplay(); } pTextContext->SetDisplay(eDisplay); m_mapXMLNodeToParseContext[pXMLNode] = pTextContext; @@ -318,21 +316,21 @@ int32_t CXFA_TextParser::GetVAlign(CXFA_TextProvider* pTextProvider) const { return para ? para.GetVerticalAlign() : XFA_ATTRIBUTEENUM_Top; } -FX_FLOAT CXFA_TextParser::GetTabInterval(IFDE_CSSComputedStyle* pStyle) const { +FX_FLOAT CXFA_TextParser::GetTabInterval(CFDE_CSSComputedStyle* pStyle) const { CFX_WideString wsValue; if (pStyle && pStyle->GetCustomStyle(FX_WSTRC(L"tab-interval"), wsValue)) return CXFA_Measurement(wsValue.AsStringC()).ToUnit(XFA_UNIT_Pt); return 36; } -int32_t CXFA_TextParser::CountTabs(IFDE_CSSComputedStyle* pStyle) const { +int32_t CXFA_TextParser::CountTabs(CFDE_CSSComputedStyle* pStyle) const { CFX_WideString wsValue; if (pStyle && pStyle->GetCustomStyle(FX_WSTRC(L"xfa-tab-count"), wsValue)) return wsValue.GetInteger(); return 0; } -bool CXFA_TextParser::IsSpaceRun(IFDE_CSSComputedStyle* pStyle) const { +bool CXFA_TextParser::IsSpaceRun(CFDE_CSSComputedStyle* pStyle) const { CFX_WideString wsValue; if (pStyle && pStyle->GetCustomStyle(FX_WSTRC(L"xfa-spacerun"), wsValue)) { wsValue.MakeLower(); @@ -343,7 +341,7 @@ bool CXFA_TextParser::IsSpaceRun(IFDE_CSSComputedStyle* pStyle) const { CFX_RetainPtr<CFGAS_GEFont> CXFA_TextParser::GetFont( CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle) const { + CFDE_CSSComputedStyle* pStyle) const { CFX_WideStringC wsFamily = FX_WSTRC(L"Courier"); uint32_t dwStyle = 0; CXFA_Font font = pTextProvider->GetFontNode(); @@ -356,15 +354,14 @@ CFX_RetainPtr<CFGAS_GEFont> CXFA_TextParser::GetFont( } if (pStyle) { - IFDE_CSSFontStyle* pFontStyle = pStyle->GetFontStyles(); - int32_t iCount = pFontStyle->CountFontFamilies(); + int32_t iCount = pStyle->CountFontFamilies(); if (iCount > 0) - wsFamily = pFontStyle->GetFontFamily(iCount - 1); + wsFamily = pStyle->GetFontFamily(iCount - 1); dwStyle = 0; - if (pFontStyle->GetFontWeight() > FXFONT_FW_NORMAL) + if (pStyle->GetFontWeight() > FXFONT_FW_NORMAL) dwStyle |= FX_FONTSTYLE_Bold; - if (pFontStyle->GetFontStyle() == FDE_CSSFontStyle::Italic) + if (pStyle->GetFontStyle() == FDE_CSSFontStyle::Italic) dwStyle |= FX_FONTSTYLE_Italic; } @@ -374,9 +371,9 @@ CFX_RetainPtr<CFGAS_GEFont> CXFA_TextParser::GetFont( } FX_FLOAT CXFA_TextParser::GetFontSize(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle) const { + CFDE_CSSComputedStyle* pStyle) const { if (pStyle) - return pStyle->GetFontStyles()->GetFontSize(); + return pStyle->GetFontSize(); CXFA_Font font = pTextProvider->GetFontNode(); if (font) @@ -385,7 +382,7 @@ FX_FLOAT CXFA_TextParser::GetFontSize(CXFA_TextProvider* pTextProvider, } int32_t CXFA_TextParser::GetHorScale(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle, + CFDE_CSSComputedStyle* pStyle, CFDE_XMLNode* pXMLNode) const { if (pStyle) { CFX_WideString wsValue; @@ -412,7 +409,7 @@ int32_t CXFA_TextParser::GetHorScale(CXFA_TextProvider* pTextProvider, } int32_t CXFA_TextParser::GetVerScale(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle) const { + CFDE_CSSComputedStyle* pStyle) const { if (pStyle) { CFX_WideString wsValue; if (pStyle->GetCustomStyle(FX_WSTRC(L"xfa-font-vertical-scale"), wsValue)) @@ -425,7 +422,7 @@ int32_t CXFA_TextParser::GetVerScale(CXFA_TextProvider* pTextProvider, } void CXFA_TextParser::GetUnderline(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle, + CFDE_CSSComputedStyle* pStyle, int32_t& iUnderline, int32_t& iPeriod) const { iUnderline = 0; @@ -439,7 +436,7 @@ void CXFA_TextParser::GetUnderline(CXFA_TextProvider* pTextProvider, return; } - uint32_t dwDecoration = pStyle->GetParagraphStyles()->GetTextDecoration(); + uint32_t dwDecoration = pStyle->GetTextDecoration(); if (dwDecoration & FDE_CSSTEXTDECORATION_Double) iUnderline = 2; else if (dwDecoration & FDE_CSSTEXTDECORATION_Underline) @@ -455,10 +452,10 @@ void CXFA_TextParser::GetUnderline(CXFA_TextProvider* pTextProvider, } void CXFA_TextParser::GetLinethrough(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle, + CFDE_CSSComputedStyle* pStyle, int32_t& iLinethrough) const { if (pStyle) { - uint32_t dwDecoration = pStyle->GetParagraphStyles()->GetTextDecoration(); + uint32_t dwDecoration = pStyle->GetTextDecoration(); iLinethrough = (dwDecoration & FDE_CSSTEXTDECORATION_LineThrough) ? 1 : 0; return; } @@ -469,9 +466,9 @@ void CXFA_TextParser::GetLinethrough(CXFA_TextProvider* pTextProvider, } FX_ARGB CXFA_TextParser::GetColor(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle) const { + CFDE_CSSComputedStyle* pStyle) const { if (pStyle) - return pStyle->GetFontStyles()->GetColor(); + return pStyle->GetColor(); if (CXFA_Font font = pTextProvider->GetFontNode()) return font.GetColor(); @@ -479,11 +476,10 @@ FX_ARGB CXFA_TextParser::GetColor(CXFA_TextProvider* pTextProvider, } FX_FLOAT CXFA_TextParser::GetBaseline(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle) const { + CFDE_CSSComputedStyle* pStyle) const { if (pStyle) { - IFDE_CSSParagraphStyle* pParaStyle = pStyle->GetParagraphStyles(); - if (pParaStyle->GetVerticalAlign() == FDE_CSSVerticalAlign::Number) - return pParaStyle->GetNumberVerticalAlign(); + if (pStyle->GetVerticalAlign() == FDE_CSSVerticalAlign::Number) + return pStyle->GetNumberVerticalAlign(); } else if (CXFA_Font font = pTextProvider->GetFontNode()) { return font.GetBaselineShift(); } @@ -491,12 +487,12 @@ FX_FLOAT CXFA_TextParser::GetBaseline(CXFA_TextProvider* pTextProvider, } FX_FLOAT CXFA_TextParser::GetLineHeight(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle, + CFDE_CSSComputedStyle* pStyle, bool bFirst, FX_FLOAT fVerScale) const { FX_FLOAT fLineHeight = 0; if (pStyle) - fLineHeight = pStyle->GetParagraphStyles()->GetLineHeight(); + fLineHeight = pStyle->GetLineHeight(); else if (CXFA_Para para = pTextProvider->GetParaNode()) fLineHeight = para.GetLineHeight(); @@ -563,7 +559,7 @@ CXFA_TextParseContext* CXFA_TextParser::GetParseContextFromMap( return it != m_mapXMLNodeToParseContext.end() ? it->second : nullptr; } -bool CXFA_TextParser::GetTabstops(IFDE_CSSComputedStyle* pStyle, +bool CXFA_TextParser::GetTabstops(CFDE_CSSComputedStyle* pStyle, CXFA_TextTabstopsContext* pTabstopContext) { if (!pStyle || !pTabstopContext) return false; diff --git a/xfa/fxfa/app/cxfa_textparser.h b/xfa/fxfa/app/cxfa_textparser.h index 923c07001a..a0b5ab1f29 100644 --- a/xfa/fxfa/app/cxfa_textparser.h +++ b/xfa/fxfa/app/cxfa_textparser.h @@ -16,14 +16,14 @@ #include "core/fxge/fx_dib.h" #include "xfa/fgas/font/cfgas_gefont.h" +class CFDE_CSSComputedStyle; class CFDE_CSSStyleSelector; +class CFDE_CSSStyleSheet; class CFDE_XMLNode; class CXFA_CSSTagProvider; class CXFA_TextParseContext; class CXFA_TextProvider; class CXFA_TextTabstopsContext; -class IFDE_CSSComputedStyle; -class IFDE_CSSStyleSheet; class CXFA_TextParser { public: @@ -33,45 +33,45 @@ class CXFA_TextParser { void Reset(); void DoParse(CFDE_XMLNode* pXMLContainer, CXFA_TextProvider* pTextProvider); - IFDE_CSSComputedStyle* CreateRootStyle(CXFA_TextProvider* pTextProvider); - IFDE_CSSComputedStyle* ComputeStyle(CFDE_XMLNode* pXMLNode, - IFDE_CSSComputedStyle* pParentStyle); + CFDE_CSSComputedStyle* CreateRootStyle(CXFA_TextProvider* pTextProvider); + CFDE_CSSComputedStyle* ComputeStyle(CFDE_XMLNode* pXMLNode, + CFDE_CSSComputedStyle* pParentStyle); bool IsParsed() const { return m_bParsed; } int32_t GetVAlign(CXFA_TextProvider* pTextProvider) const; - FX_FLOAT GetTabInterval(IFDE_CSSComputedStyle* pStyle) const; - int32_t CountTabs(IFDE_CSSComputedStyle* pStyle) const; + FX_FLOAT GetTabInterval(CFDE_CSSComputedStyle* pStyle) const; + int32_t CountTabs(CFDE_CSSComputedStyle* pStyle) const; - bool IsSpaceRun(IFDE_CSSComputedStyle* pStyle) const; - bool GetTabstops(IFDE_CSSComputedStyle* pStyle, + bool IsSpaceRun(CFDE_CSSComputedStyle* pStyle) const; + bool GetTabstops(CFDE_CSSComputedStyle* pStyle, CXFA_TextTabstopsContext* pTabstopContext); CFX_RetainPtr<CFGAS_GEFont> GetFont(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle) const; + CFDE_CSSComputedStyle* pStyle) const; FX_FLOAT GetFontSize(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle) const; + CFDE_CSSComputedStyle* pStyle) const; int32_t GetHorScale(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle, + CFDE_CSSComputedStyle* pStyle, CFDE_XMLNode* pXMLNode) const; int32_t GetVerScale(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle) const; + CFDE_CSSComputedStyle* pStyle) const; void GetUnderline(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle, + CFDE_CSSComputedStyle* pStyle, int32_t& iUnderline, int32_t& iPeriod) const; void GetLinethrough(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle, + CFDE_CSSComputedStyle* pStyle, int32_t& iLinethrough) const; FX_ARGB GetColor(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle) const; + CFDE_CSSComputedStyle* pStyle) const; FX_FLOAT GetBaseline(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle) const; + CFDE_CSSComputedStyle* pStyle) const; FX_FLOAT GetLineHeight(CXFA_TextProvider* pTextProvider, - IFDE_CSSComputedStyle* pStyle, + CFDE_CSSComputedStyle* pStyle, bool bFirst, FX_FLOAT fVerScale) const; @@ -86,13 +86,13 @@ class CXFA_TextParser { private: void InitCSSData(CXFA_TextProvider* pTextProvider); void ParseRichText(CFDE_XMLNode* pXMLNode, - IFDE_CSSComputedStyle* pParentStyle); + CFDE_CSSComputedStyle* pParentStyle); void ParseTagInfo(CFDE_XMLNode* pXMLNode, CXFA_CSSTagProvider& tagProvider); - IFDE_CSSStyleSheet* LoadDefaultSheetStyle(); - IFDE_CSSComputedStyle* CreateStyle(IFDE_CSSComputedStyle* pParentStyle); + CFDE_CSSStyleSheet* LoadDefaultSheetStyle(); + CFDE_CSSComputedStyle* CreateStyle(CFDE_CSSComputedStyle* pParentStyle); std::unique_ptr<CFDE_CSSStyleSelector> m_pSelector; - IFDE_CSSStyleSheet* m_pUASheet; + CFDE_CSSStyleSheet* m_pUASheet; std::map<CFDE_XMLNode*, CXFA_TextParseContext*> m_mapXMLNodeToParseContext; bool m_bParsed; }; diff --git a/xfa/fxfa/app/cxfa_textuserdata.cpp b/xfa/fxfa/app/cxfa_textuserdata.cpp index 62566deeac..7087810f4d 100644 --- a/xfa/fxfa/app/cxfa_textuserdata.cpp +++ b/xfa/fxfa/app/cxfa_textuserdata.cpp @@ -7,15 +7,16 @@ #include "xfa/fxfa/app/cxfa_textuserdata.h" #include "xfa/fde/css/fde_css.h" +#include "xfa/fde/css/fde_cssstyleselector.h" #include "xfa/fxfa/app/cxfa_linkuserdata.h" -CXFA_TextUserData::CXFA_TextUserData(IFDE_CSSComputedStyle* pStyle) +CXFA_TextUserData::CXFA_TextUserData(CFDE_CSSComputedStyle* pStyle) : m_pStyle(pStyle), m_pLinkData(nullptr), m_dwRefCount(0) { if (m_pStyle) m_pStyle->Retain(); } -CXFA_TextUserData::CXFA_TextUserData(IFDE_CSSComputedStyle* pStyle, +CXFA_TextUserData::CXFA_TextUserData(CFDE_CSSComputedStyle* pStyle, CXFA_LinkUserData* pLinkData) : m_pStyle(pStyle), m_pLinkData(pLinkData), m_dwRefCount(0) { if (m_pStyle) diff --git a/xfa/fxfa/app/cxfa_textuserdata.h b/xfa/fxfa/app/cxfa_textuserdata.h index 308475b0dd..83f762ddbe 100644 --- a/xfa/fxfa/app/cxfa_textuserdata.h +++ b/xfa/fxfa/app/cxfa_textuserdata.h @@ -9,13 +9,13 @@ #include "core/fxcrt/fx_basic.h" +class CFDE_CSSComputedStyle; class CXFA_LinkUserData; -class IFDE_CSSComputedStyle; class CXFA_TextUserData : public IFX_Retainable { public: - explicit CXFA_TextUserData(IFDE_CSSComputedStyle* pStyle); - CXFA_TextUserData(IFDE_CSSComputedStyle* pStyle, + explicit CXFA_TextUserData(CFDE_CSSComputedStyle* pStyle); + CXFA_TextUserData(CFDE_CSSComputedStyle* pStyle, CXFA_LinkUserData* pLinkData); ~CXFA_TextUserData() override; @@ -23,7 +23,7 @@ class CXFA_TextUserData : public IFX_Retainable { uint32_t Retain() override; uint32_t Release() override; - IFDE_CSSComputedStyle* m_pStyle; + CFDE_CSSComputedStyle* m_pStyle; CXFA_LinkUserData* m_pLinkData; protected: |