diff options
75 files changed, 2619 insertions, 2630 deletions
@@ -884,6 +884,47 @@ static_library("fxcrt") { "core/fxcrt/cfx_seekablestreamproxy.h", "core/fxcrt/cfx_wordbreak.cpp", "core/fxcrt/cfx_wordbreak.h", + "core/fxcrt/css/cfx_css.h", + "core/fxcrt/css/cfx_csscolorvalue.cpp", + "core/fxcrt/css/cfx_csscolorvalue.h", + "core/fxcrt/css/cfx_csscomputedstyle.cpp", + "core/fxcrt/css/cfx_csscomputedstyle.h", + "core/fxcrt/css/cfx_csscustomproperty.cpp", + "core/fxcrt/css/cfx_csscustomproperty.h", + "core/fxcrt/css/cfx_cssdatatable.cpp", + "core/fxcrt/css/cfx_cssdatatable.h", + "core/fxcrt/css/cfx_cssdeclaration.cpp", + "core/fxcrt/css/cfx_cssdeclaration.h", + "core/fxcrt/css/cfx_cssenumvalue.cpp", + "core/fxcrt/css/cfx_cssenumvalue.h", + "core/fxcrt/css/cfx_cssexttextbuf.cpp", + "core/fxcrt/css/cfx_cssexttextbuf.h", + "core/fxcrt/css/cfx_cssnumbervalue.cpp", + "core/fxcrt/css/cfx_cssnumbervalue.h", + "core/fxcrt/css/cfx_csspropertyholder.cpp", + "core/fxcrt/css/cfx_csspropertyholder.h", + "core/fxcrt/css/cfx_cssrulecollection.cpp", + "core/fxcrt/css/cfx_cssrulecollection.h", + "core/fxcrt/css/cfx_cssselector.cpp", + "core/fxcrt/css/cfx_cssselector.h", + "core/fxcrt/css/cfx_cssstringvalue.cpp", + "core/fxcrt/css/cfx_cssstringvalue.h", + "core/fxcrt/css/cfx_cssstylerule.cpp", + "core/fxcrt/css/cfx_cssstylerule.h", + "core/fxcrt/css/cfx_cssstyleselector.cpp", + "core/fxcrt/css/cfx_cssstyleselector.h", + "core/fxcrt/css/cfx_cssstylesheet.cpp", + "core/fxcrt/css/cfx_cssstylesheet.h", + "core/fxcrt/css/cfx_csssyntaxparser.cpp", + "core/fxcrt/css/cfx_csssyntaxparser.h", + "core/fxcrt/css/cfx_csstextbuf.cpp", + "core/fxcrt/css/cfx_csstextbuf.h", + "core/fxcrt/css/cfx_cssvalue.cpp", + "core/fxcrt/css/cfx_cssvalue.h", + "core/fxcrt/css/cfx_cssvaluelist.cpp", + "core/fxcrt/css/cfx_cssvaluelist.h", + "core/fxcrt/css/cfx_cssvaluelistparser.cpp", + "core/fxcrt/css/cfx_cssvaluelistparser.h", "core/fxcrt/fx_arabic.cpp", "core/fxcrt/fx_arabic.h", "core/fxcrt/ifx_chariter.h", @@ -1435,47 +1476,6 @@ if (pdf_enable_xfa) { "xfa/fde/cfde_txtedttextset.h", "xfa/fde/cfde_visualsetiterator.cpp", "xfa/fde/cfde_visualsetiterator.h", - "xfa/fde/css/cfde_csscolorvalue.cpp", - "xfa/fde/css/cfde_csscolorvalue.h", - "xfa/fde/css/cfde_csscomputedstyle.cpp", - "xfa/fde/css/cfde_csscomputedstyle.h", - "xfa/fde/css/cfde_csscustomproperty.cpp", - "xfa/fde/css/cfde_csscustomproperty.h", - "xfa/fde/css/cfde_cssdeclaration.cpp", - "xfa/fde/css/cfde_cssdeclaration.h", - "xfa/fde/css/cfde_cssenumvalue.cpp", - "xfa/fde/css/cfde_cssenumvalue.h", - "xfa/fde/css/cfde_cssexttextbuf.cpp", - "xfa/fde/css/cfde_cssexttextbuf.h", - "xfa/fde/css/cfde_cssnumbervalue.cpp", - "xfa/fde/css/cfde_cssnumbervalue.h", - "xfa/fde/css/cfde_csspropertyholder.cpp", - "xfa/fde/css/cfde_csspropertyholder.h", - "xfa/fde/css/cfde_cssrulecollection.cpp", - "xfa/fde/css/cfde_cssrulecollection.h", - "xfa/fde/css/cfde_cssselector.cpp", - "xfa/fde/css/cfde_cssselector.h", - "xfa/fde/css/cfde_cssstringvalue.cpp", - "xfa/fde/css/cfde_cssstringvalue.h", - "xfa/fde/css/cfde_cssstylerule.cpp", - "xfa/fde/css/cfde_cssstylerule.h", - "xfa/fde/css/cfde_cssstyleselector.cpp", - "xfa/fde/css/cfde_cssstyleselector.h", - "xfa/fde/css/cfde_cssstylesheet.cpp", - "xfa/fde/css/cfde_cssstylesheet.h", - "xfa/fde/css/cfde_csssyntaxparser.cpp", - "xfa/fde/css/cfde_csssyntaxparser.h", - "xfa/fde/css/cfde_csstextbuf.cpp", - "xfa/fde/css/cfde_csstextbuf.h", - "xfa/fde/css/cfde_cssvalue.cpp", - "xfa/fde/css/cfde_cssvalue.h", - "xfa/fde/css/cfde_cssvaluelist.cpp", - "xfa/fde/css/cfde_cssvaluelist.h", - "xfa/fde/css/cfde_cssvaluelistparser.cpp", - "xfa/fde/css/cfde_cssvaluelistparser.h", - "xfa/fde/css/fde_css.h", - "xfa/fde/css/fde_cssdatatable.cpp", - "xfa/fde/css/fde_cssdatatable.h", "xfa/fde/ifde_txtedtdorecord.h", "xfa/fde/ifde_txtedtengine.h", "xfa/fde/ifde_txtedtpage.h", @@ -1946,14 +1946,14 @@ test("pdfium_unittests") { include_dirs = [] if (pdf_enable_xfa) { sources += [ + "core/fxcrt/css/cfx_cssdeclaration_unittest.cpp", + "core/fxcrt/css/cfx_cssstylesheet_unittest.cpp", + "core/fxcrt/css/cfx_cssvaluelistparser_unittest.cpp", "core/fxcrt/xml/cfx_saxreader_unittest.cpp", "core/fxcrt/xml/cfx_xmlsyntaxparser_unittest.cpp", "fxbarcode/oned/BC_OnedCode128Writer_unittest.cpp", "fxbarcode/pdf417/BC_PDF417HighLevelEncoder_unittest.cpp", "xfa/fde/cfde_txtedtbuf_unittest.cpp", - "xfa/fde/css/cfde_cssdeclaration_unittest.cpp", - "xfa/fde/css/cfde_cssstylesheet_unittest.cpp", - "xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp", "xfa/fgas/crt/cfgas_formatstring_unittest.cpp", "xfa/fgas/layout/cfx_rtfbreak_unittest.cpp", "xfa/fwl/cfx_barcode_unittest.cpp", diff --git a/xfa/fde/css/fde_css.h b/core/fxcrt/css/cfx_css.h index 663db44de3..7b1d7d3f99 100644 --- a/xfa/fde/css/fde_css.h +++ b/core/fxcrt/css/cfx_css.h @@ -4,24 +4,24 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FDE_CSS_FDE_CSS_H_ -#define XFA_FDE_CSS_FDE_CSS_H_ +#ifndef CORE_FXCRT_CSS_CFX_CSS_H_ +#define CORE_FXCRT_CSS_CFX_CSS_H_ #include "core/fxcrt/cfx_seekablestreamproxy.h" #include "core/fxge/fx_dib.h" -enum FDE_CSSVALUETYPE { - FDE_CSSVALUETYPE_Primitive = 1 << 0, - FDE_CSSVALUETYPE_List = 1 << 1, - FDE_CSSVALUETYPE_Shorthand = 1 << 2, +enum CFX_CSSVALUETYPE { + CFX_CSSVALUETYPE_Primitive = 1 << 0, + CFX_CSSVALUETYPE_List = 1 << 1, + CFX_CSSVALUETYPE_Shorthand = 1 << 2, // Note the values below this comment must be > 0x0F so we can mask the above. - FDE_CSSVALUETYPE_MaybeNumber = 1 << 4, - FDE_CSSVALUETYPE_MaybeEnum = 1 << 5, - FDE_CSSVALUETYPE_MaybeString = 1 << 7, - FDE_CSSVALUETYPE_MaybeColor = 1 << 8 + CFX_CSSVALUETYPE_MaybeNumber = 1 << 4, + CFX_CSSVALUETYPE_MaybeEnum = 1 << 5, + CFX_CSSVALUETYPE_MaybeString = 1 << 7, + CFX_CSSVALUETYPE_MaybeColor = 1 << 8 }; -enum class FDE_CSSPrimitiveType : uint8_t { +enum class CFX_CSSPrimitiveType : uint8_t { Unknown = 0, Number, String, @@ -31,7 +31,7 @@ enum class FDE_CSSPrimitiveType : uint8_t { List, }; -enum class FDE_CSSPropertyValue : uint8_t { +enum class CFX_CSSPropertyValue : uint8_t { Bolder = 0, None, Dot, @@ -79,7 +79,7 @@ enum class FDE_CSSPropertyValue : uint8_t { LAST_MARKER }; -enum class FDE_CSSProperty : uint8_t { +enum class CFX_CSSProperty : uint8_t { BorderLeft = 0, Top, Margin, @@ -123,9 +123,9 @@ enum class FDE_CSSProperty : uint8_t { LAST_MARKER }; -enum class FDE_CSSSelectorType : uint8_t { Element = 0, Descendant }; +enum class CFX_CSSSelectorType : uint8_t { Element = 0, Descendant }; -enum class FDE_CSSLengthUnit : uint8_t { +enum class CFX_CSSLengthUnit : uint8_t { Auto, None, Normal, @@ -133,7 +133,7 @@ enum class FDE_CSSLengthUnit : uint8_t { Percent, }; -enum class FDE_CSSDisplay : uint8_t { +enum class CFX_CSSDisplay : uint8_t { None, ListItem, Block, @@ -142,12 +142,12 @@ enum class FDE_CSSDisplay : uint8_t { InlineTable, }; -enum class FDE_CSSFontStyle : uint8_t { +enum class CFX_CSSFontStyle : uint8_t { Normal, Italic, }; -enum class FDE_CSSTextAlign : uint8_t { +enum class CFX_CSSTextAlign : uint8_t { Left, Right, Center, @@ -155,7 +155,7 @@ enum class FDE_CSSTextAlign : uint8_t { JustifyAll, }; -enum class FDE_CSSVerticalAlign : uint8_t { +enum class CFX_CSSVerticalAlign : uint8_t { Baseline, Sub, Super, @@ -167,68 +167,68 @@ enum class FDE_CSSVerticalAlign : uint8_t { Number, }; -enum class FDE_CSSFontVariant : uint8_t { +enum class CFX_CSSFontVariant : uint8_t { Normal, SmallCaps, }; -enum FDE_CSSTEXTDECORATION { - FDE_CSSTEXTDECORATION_None = 0, - FDE_CSSTEXTDECORATION_Underline = 1 << 0, - FDE_CSSTEXTDECORATION_Overline = 1 << 1, - FDE_CSSTEXTDECORATION_LineThrough = 1 << 2, - FDE_CSSTEXTDECORATION_Blink = 1 << 3, - FDE_CSSTEXTDECORATION_Double = 1 << 4, +enum CFX_CSSTEXTDECORATION { + CFX_CSSTEXTDECORATION_None = 0, + CFX_CSSTEXTDECORATION_Underline = 1 << 0, + CFX_CSSTEXTDECORATION_Overline = 1 << 1, + CFX_CSSTEXTDECORATION_LineThrough = 1 << 2, + CFX_CSSTEXTDECORATION_Blink = 1 << 3, + CFX_CSSTEXTDECORATION_Double = 1 << 4, }; -class FDE_CSSLength { +class CFX_CSSLength { public: - FDE_CSSLength() {} + CFX_CSSLength() {} - explicit FDE_CSSLength(FDE_CSSLengthUnit eUnit) : m_unit(eUnit) {} + explicit CFX_CSSLength(CFX_CSSLengthUnit eUnit) : m_unit(eUnit) {} - FDE_CSSLength(FDE_CSSLengthUnit eUnit, float fValue) + CFX_CSSLength(CFX_CSSLengthUnit eUnit, float fValue) : m_unit(eUnit), m_fValue(fValue) {} - FDE_CSSLength& Set(FDE_CSSLengthUnit eUnit) { + CFX_CSSLength& Set(CFX_CSSLengthUnit eUnit) { m_unit = eUnit; return *this; } - FDE_CSSLength& Set(FDE_CSSLengthUnit eUnit, float fValue) { + CFX_CSSLength& Set(CFX_CSSLengthUnit eUnit, float fValue) { m_unit = eUnit; m_fValue = fValue; return *this; } - FDE_CSSLengthUnit GetUnit() const { return m_unit; } + CFX_CSSLengthUnit GetUnit() const { return m_unit; } float GetValue() const { return m_fValue; } bool NonZero() const { return static_cast<int>(m_fValue) != 0; } private: - FDE_CSSLengthUnit m_unit; + CFX_CSSLengthUnit m_unit; float m_fValue; }; -class FDE_CSSRect { +class CFX_CSSRect { public: - FDE_CSSRect() {} + CFX_CSSRect() {} - FDE_CSSRect(FDE_CSSLengthUnit eUnit, float val) + CFX_CSSRect(CFX_CSSLengthUnit eUnit, float val) : left(eUnit, val), top(eUnit, val), right(eUnit, val), bottom(eUnit, val) {} - FDE_CSSRect& Set(FDE_CSSLengthUnit eUnit) { + CFX_CSSRect& Set(CFX_CSSLengthUnit eUnit) { left.Set(eUnit); top.Set(eUnit); right.Set(eUnit); bottom.Set(eUnit); return *this; } - FDE_CSSRect& Set(FDE_CSSLengthUnit eUnit, float fValue) { + CFX_CSSRect& Set(CFX_CSSLengthUnit eUnit, float fValue) { left.Set(eUnit, fValue); top.Set(eUnit, fValue); right.Set(eUnit, fValue); @@ -236,7 +236,7 @@ class FDE_CSSRect { return *this; } - FDE_CSSLength left, top, right, bottom; + CFX_CSSLength left, top, right, bottom; }; -#endif // XFA_FDE_CSS_FDE_CSS_H_ +#endif // CORE_FXCRT_CSS_CFX_CSS_H_ diff --git a/xfa/fde/css/cfde_csscolorvalue.cpp b/core/fxcrt/css/cfx_csscolorvalue.cpp index 015355136c..8c5473b329 100644 --- a/xfa/fde/css/cfde_csscolorvalue.cpp +++ b/core/fxcrt/css/cfx_csscolorvalue.cpp @@ -4,9 +4,9 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fde/css/cfde_csscolorvalue.h" +#include "core/fxcrt/css/cfx_csscolorvalue.h" -CFDE_CSSColorValue::CFDE_CSSColorValue(FX_ARGB value) - : CFDE_CSSValue(FDE_CSSPrimitiveType::RGB), value_(value) {} +CFX_CSSColorValue::CFX_CSSColorValue(FX_ARGB value) + : CFX_CSSValue(CFX_CSSPrimitiveType::RGB), value_(value) {} -CFDE_CSSColorValue::~CFDE_CSSColorValue() {} +CFX_CSSColorValue::~CFX_CSSColorValue() {} diff --git a/xfa/fde/css/cfde_csscolorvalue.h b/core/fxcrt/css/cfx_csscolorvalue.h index 1d0441ad2a..f59c0c5d3d 100644 --- a/xfa/fde/css/cfde_csscolorvalue.h +++ b/core/fxcrt/css/cfx_csscolorvalue.h @@ -4,15 +4,15 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FDE_CSS_CFDE_CSSCOLORVALUE_H_ -#define XFA_FDE_CSS_CFDE_CSSCOLORVALUE_H_ +#ifndef CORE_FXCRT_CSS_CFX_CSSCOLORVALUE_H_ +#define CORE_FXCRT_CSS_CFX_CSSCOLORVALUE_H_ -#include "xfa/fde/css/cfde_cssvalue.h" +#include "core/fxcrt/css/cfx_cssvalue.h" -class CFDE_CSSColorValue : public CFDE_CSSValue { +class CFX_CSSColorValue : public CFX_CSSValue { public: - explicit CFDE_CSSColorValue(FX_ARGB color); - ~CFDE_CSSColorValue() override; + explicit CFX_CSSColorValue(FX_ARGB color); + ~CFX_CSSColorValue() override; FX_ARGB Value() const { return value_; } @@ -20,4 +20,4 @@ class CFDE_CSSColorValue : public CFDE_CSSValue { FX_ARGB value_; }; -#endif // XFA_FDE_CSS_CFDE_CSSCOLORVALUE_H_ +#endif // CORE_FXCRT_CSS_CFX_CSSCOLORVALUE_H_ diff --git a/core/fxcrt/css/cfx_csscomputedstyle.cpp b/core/fxcrt/css/cfx_csscomputedstyle.cpp new file mode 100644 index 0000000000..953c107ec3 --- /dev/null +++ b/core/fxcrt/css/cfx_csscomputedstyle.cpp @@ -0,0 +1,195 @@ +// Copyright 2017 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 "core/fxcrt/css/cfx_csscomputedstyle.h" + +#include "core/fxcrt/css/cfx_cssstringvalue.h" +#include "core/fxcrt/css/cfx_cssvaluelist.h" +#include "third_party/base/stl_util.h" + +CFX_CSSComputedStyle::CFX_CSSComputedStyle() {} + +CFX_CSSComputedStyle::~CFX_CSSComputedStyle() {} + +bool CFX_CSSComputedStyle::GetCustomStyle(const CFX_WideString& wsName, + CFX_WideString& wsValue) const { + for (auto iter = m_CustomProperties.rbegin(); + iter != m_CustomProperties.rend(); iter++) { + if (wsName == iter->name()) { + wsValue = iter->value(); + return true; + } + } + return false; +} + +int32_t CFX_CSSComputedStyle::CountFontFamilies() const { + return m_InheritedData.m_pFontFamily + ? m_InheritedData.m_pFontFamily->CountValues() + : 0; +} + +const CFX_WideString CFX_CSSComputedStyle::GetFontFamily(int32_t index) const { + return m_InheritedData.m_pFontFamily->GetValue(index) + .As<CFX_CSSStringValue>() + ->Value(); +} + +uint16_t CFX_CSSComputedStyle::GetFontWeight() const { + return m_InheritedData.m_wFontWeight; +} + +CFX_CSSFontVariant CFX_CSSComputedStyle::GetFontVariant() const { + return m_InheritedData.m_eFontVariant; +} + +CFX_CSSFontStyle CFX_CSSComputedStyle::GetFontStyle() const { + return m_InheritedData.m_eFontStyle; +} + +float CFX_CSSComputedStyle::GetFontSize() const { + return m_InheritedData.m_fFontSize; +} + +FX_ARGB CFX_CSSComputedStyle::GetColor() const { + return m_InheritedData.m_dwFontColor; +} + +void CFX_CSSComputedStyle::SetFontWeight(uint16_t wFontWeight) { + m_InheritedData.m_wFontWeight = wFontWeight; +} + +void CFX_CSSComputedStyle::SetFontVariant(CFX_CSSFontVariant eFontVariant) { + m_InheritedData.m_eFontVariant = eFontVariant; +} + +void CFX_CSSComputedStyle::SetFontStyle(CFX_CSSFontStyle eFontStyle) { + m_InheritedData.m_eFontStyle = eFontStyle; +} + +void CFX_CSSComputedStyle::SetFontSize(float fFontSize) { + m_InheritedData.m_fFontSize = fFontSize; +} + +void CFX_CSSComputedStyle::SetColor(FX_ARGB dwFontColor) { + m_InheritedData.m_dwFontColor = dwFontColor; +} + +const CFX_CSSRect* CFX_CSSComputedStyle::GetBorderWidth() const { + return m_NonInheritedData.m_bHasBorder ? &(m_NonInheritedData.m_BorderWidth) + : nullptr; +} + +const CFX_CSSRect* CFX_CSSComputedStyle::GetMarginWidth() const { + return m_NonInheritedData.m_bHasMargin ? &(m_NonInheritedData.m_MarginWidth) + : nullptr; +} + +const CFX_CSSRect* CFX_CSSComputedStyle::GetPaddingWidth() const { + return m_NonInheritedData.m_bHasPadding ? &(m_NonInheritedData.m_PaddingWidth) + : nullptr; +} + +void CFX_CSSComputedStyle::SetMarginWidth(const CFX_CSSRect& rect) { + m_NonInheritedData.m_MarginWidth = rect; + m_NonInheritedData.m_bHasMargin = true; +} + +void CFX_CSSComputedStyle::SetPaddingWidth(const CFX_CSSRect& rect) { + m_NonInheritedData.m_PaddingWidth = rect; + m_NonInheritedData.m_bHasPadding = true; +} + +CFX_CSSDisplay CFX_CSSComputedStyle::GetDisplay() const { + return m_NonInheritedData.m_eDisplay; +} + +float CFX_CSSComputedStyle::GetLineHeight() const { + return m_InheritedData.m_fLineHeight; +} + +const CFX_CSSLength& CFX_CSSComputedStyle::GetTextIndent() const { + return m_InheritedData.m_TextIndent; +} + +CFX_CSSTextAlign CFX_CSSComputedStyle::GetTextAlign() const { + return m_InheritedData.m_eTextAlign; +} + +CFX_CSSVerticalAlign CFX_CSSComputedStyle::GetVerticalAlign() const { + return m_NonInheritedData.m_eVerticalAlign; +} + +float CFX_CSSComputedStyle::GetNumberVerticalAlign() const { + return m_NonInheritedData.m_fVerticalAlign; +} + +uint32_t CFX_CSSComputedStyle::GetTextDecoration() const { + return m_NonInheritedData.m_dwTextDecoration; +} + +const CFX_CSSLength& CFX_CSSComputedStyle::GetLetterSpacing() const { + return m_InheritedData.m_LetterSpacing; +} + +void CFX_CSSComputedStyle::SetLineHeight(float fLineHeight) { + m_InheritedData.m_fLineHeight = fLineHeight; +} + +void CFX_CSSComputedStyle::SetTextIndent(const CFX_CSSLength& textIndent) { + m_InheritedData.m_TextIndent = textIndent; +} + +void CFX_CSSComputedStyle::SetTextAlign(CFX_CSSTextAlign eTextAlign) { + m_InheritedData.m_eTextAlign = eTextAlign; +} + +void CFX_CSSComputedStyle::SetNumberVerticalAlign(float fAlign) { + m_NonInheritedData.m_eVerticalAlign = CFX_CSSVerticalAlign::Number, + m_NonInheritedData.m_fVerticalAlign = fAlign; +} + +void CFX_CSSComputedStyle::SetTextDecoration(uint32_t dwTextDecoration) { + m_NonInheritedData.m_dwTextDecoration = dwTextDecoration; +} + +void CFX_CSSComputedStyle::SetLetterSpacing( + const CFX_CSSLength& letterSpacing) { + m_InheritedData.m_LetterSpacing = letterSpacing; +} + +void CFX_CSSComputedStyle::AddCustomStyle(const CFX_CSSCustomProperty& prop) { + // Force the property to be copied so we aren't dependent on the lifetime + // of whatever currently owns it. + m_CustomProperties.push_back(prop); +} + +CFX_CSSComputedStyle::InheritedData::InheritedData() + : m_LetterSpacing(CFX_CSSLengthUnit::Normal), + m_WordSpacing(CFX_CSSLengthUnit::Normal), + m_TextIndent(CFX_CSSLengthUnit::Point, 0), + m_pFontFamily(nullptr), + m_fFontSize(12.0f), + m_fLineHeight(14.0f), + m_dwFontColor(0xFF000000), + m_wFontWeight(400), + m_eFontVariant(CFX_CSSFontVariant::Normal), + m_eFontStyle(CFX_CSSFontStyle::Normal), + m_eTextAlign(CFX_CSSTextAlign::Left) {} + +CFX_CSSComputedStyle::InheritedData::~InheritedData() {} + +CFX_CSSComputedStyle::NonInheritedData::NonInheritedData() + : m_MarginWidth(CFX_CSSLengthUnit::Point, 0), + m_BorderWidth(CFX_CSSLengthUnit::Point, 0), + m_PaddingWidth(CFX_CSSLengthUnit::Point, 0), + m_fVerticalAlign(0.0f), + m_eDisplay(CFX_CSSDisplay::Inline), + m_eVerticalAlign(CFX_CSSVerticalAlign::Baseline), + m_dwTextDecoration(0), + m_bHasMargin(false), + m_bHasBorder(false), + m_bHasPadding(false) {} diff --git a/core/fxcrt/css/cfx_csscomputedstyle.h b/core/fxcrt/css/cfx_csscomputedstyle.h new file mode 100644 index 0000000000..bd7cd8268b --- /dev/null +++ b/core/fxcrt/css/cfx_csscomputedstyle.h @@ -0,0 +1,111 @@ +// Copyright 2017 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 + +#ifndef CORE_FXCRT_CSS_CFX_CSSCOMPUTEDSTYLE_H_ +#define CORE_FXCRT_CSS_CFX_CSSCOMPUTEDSTYLE_H_ + +#include <vector> + +#include "core/fxcrt/css/cfx_css.h" +#include "core/fxcrt/css/cfx_csscustomproperty.h" +#include "core/fxcrt/fx_basic.h" +#include "core/fxcrt/fx_string.h" + +class CFX_CSSValueList; + +class CFX_CSSComputedStyle : public CFX_Retainable { + public: + class InheritedData { + public: + InheritedData(); + ~InheritedData(); + + CFX_CSSLength m_LetterSpacing; + CFX_CSSLength m_WordSpacing; + CFX_CSSLength m_TextIndent; + CFX_RetainPtr<CFX_CSSValueList> m_pFontFamily; + float m_fFontSize; + float m_fLineHeight; + FX_ARGB m_dwFontColor; + uint16_t m_wFontWeight; + CFX_CSSFontVariant m_eFontVariant; + CFX_CSSFontStyle m_eFontStyle; + CFX_CSSTextAlign m_eTextAlign; + }; + + class NonInheritedData { + public: + NonInheritedData(); + + CFX_CSSRect m_MarginWidth; + CFX_CSSRect m_BorderWidth; + CFX_CSSRect m_PaddingWidth; + CFX_CSSLength m_Top; + CFX_CSSLength m_Bottom; + CFX_CSSLength m_Left; + CFX_CSSLength m_Right; + float m_fVerticalAlign; + CFX_CSSDisplay m_eDisplay; + CFX_CSSVerticalAlign m_eVerticalAlign; + uint8_t m_dwTextDecoration; + bool m_bHasMargin; + bool m_bHasBorder; + bool m_bHasPadding; + }; + + int32_t CountFontFamilies() const; + const CFX_WideString GetFontFamily(int32_t index) const; + uint16_t GetFontWeight() const; + CFX_CSSFontVariant GetFontVariant() const; + CFX_CSSFontStyle GetFontStyle() const; + float GetFontSize() const; + FX_ARGB GetColor() const; + void SetFontWeight(uint16_t wFontWeight); + void SetFontVariant(CFX_CSSFontVariant eFontVariant); + void SetFontStyle(CFX_CSSFontStyle eFontStyle); + void SetFontSize(float fFontSize); + void SetColor(FX_ARGB dwFontColor); + + const CFX_CSSRect* GetBorderWidth() const; + const CFX_CSSRect* GetMarginWidth() const; + const CFX_CSSRect* GetPaddingWidth() const; + void SetMarginWidth(const CFX_CSSRect& rect); + void SetPaddingWidth(const CFX_CSSRect& rect); + + CFX_CSSDisplay GetDisplay() const; + + float GetLineHeight() const; + const CFX_CSSLength& GetTextIndent() const; + CFX_CSSTextAlign GetTextAlign() const; + CFX_CSSVerticalAlign GetVerticalAlign() const; + float GetNumberVerticalAlign() const; + uint32_t GetTextDecoration() const; + const CFX_CSSLength& GetLetterSpacing() const; + void SetLineHeight(float fLineHeight); + void SetTextIndent(const CFX_CSSLength& textIndent); + void SetTextAlign(CFX_CSSTextAlign eTextAlign); + void SetNumberVerticalAlign(float fAlign); + void SetTextDecoration(uint32_t dwTextDecoration); + void SetLetterSpacing(const CFX_CSSLength& letterSpacing); + void AddCustomStyle(const CFX_CSSCustomProperty& prop); + + bool GetCustomStyle(const CFX_WideString& wsName, + CFX_WideString& wsValue) const; + + InheritedData m_InheritedData; + NonInheritedData m_NonInheritedData; + + private: + template <typename T, typename... Args> + friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); + + CFX_CSSComputedStyle(); + ~CFX_CSSComputedStyle() override; + + std::vector<CFX_CSSCustomProperty> m_CustomProperties; +}; + +#endif // CORE_FXCRT_CSS_CFX_CSSCOMPUTEDSTYLE_H_ diff --git a/core/fxcrt/css/cfx_csscustomproperty.cpp b/core/fxcrt/css/cfx_csscustomproperty.cpp new file mode 100644 index 0000000000..8bfb9d961e --- /dev/null +++ b/core/fxcrt/css/cfx_csscustomproperty.cpp @@ -0,0 +1,14 @@ +// Copyright 2017 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. + +#include "core/fxcrt/css/cfx_csscustomproperty.h" + +CFX_CSSCustomProperty::CFX_CSSCustomProperty(const CFX_WideString& name, + const CFX_WideString& value) + : name_(name), value_(value) {} + +CFX_CSSCustomProperty::CFX_CSSCustomProperty(const CFX_CSSCustomProperty& prop) + : name_(prop.name_), value_(prop.value_) {} + +CFX_CSSCustomProperty::~CFX_CSSCustomProperty() {} diff --git a/xfa/fde/css/cfde_csscustomproperty.h b/core/fxcrt/css/cfx_csscustomproperty.h index 6970d49cbb..e062c3e953 100644 --- a/xfa/fde/css/cfde_csscustomproperty.h +++ b/core/fxcrt/css/cfx_csscustomproperty.h @@ -4,17 +4,17 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FDE_CSS_CFDE_CSSCUSTOMPROPERTY_H_ -#define XFA_FDE_CSS_CFDE_CSSCUSTOMPROPERTY_H_ +#ifndef CORE_FXCRT_CSS_CFX_CSSCUSTOMPROPERTY_H_ +#define CORE_FXCRT_CSS_CFX_CSSCUSTOMPROPERTY_H_ #include "core/fxcrt/fx_string.h" -class CFDE_CSSCustomProperty { +class CFX_CSSCustomProperty { public: - CFDE_CSSCustomProperty(const CFX_WideString& name, - const CFX_WideString& value); - CFDE_CSSCustomProperty(const CFDE_CSSCustomProperty& prop); - ~CFDE_CSSCustomProperty(); + CFX_CSSCustomProperty(const CFX_WideString& name, + const CFX_WideString& value); + CFX_CSSCustomProperty(const CFX_CSSCustomProperty& prop); + ~CFX_CSSCustomProperty(); CFX_WideString name() const { return name_; } CFX_WideString value() const { return value_; } @@ -24,4 +24,4 @@ class CFDE_CSSCustomProperty { CFX_WideString value_; }; -#endif // XFA_FDE_CSS_CFDE_CSSCUSTOMPROPERTY_H_ +#endif // CORE_FXCRT_CSS_CFX_CSSCUSTOMPROPERTY_H_ diff --git a/core/fxcrt/css/cfx_cssdatatable.cpp b/core/fxcrt/css/cfx_cssdatatable.cpp new file mode 100644 index 0000000000..ef555b395f --- /dev/null +++ b/core/fxcrt/css/cfx_cssdatatable.cpp @@ -0,0 +1,285 @@ +// Copyright 2014 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 "core/fxcrt/css/cfx_cssdatatable.h" + +#include <utility> + +#include "core/fxcrt/css/cfx_cssstyleselector.h" +#include "core/fxcrt/css/cfx_cssvaluelistparser.h" +#include "core/fxcrt/fx_codepage.h" +#include "core/fxcrt/fx_extension.h" + +static const CFX_CSSPropertyTable g_CFX_CSSProperties[] = { + {CFX_CSSProperty::BorderLeft, L"border-left", 0x04080036, + CFX_CSSVALUETYPE_Shorthand}, + {CFX_CSSProperty::Top, L"top", 0x0BEDAF33, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::Margin, L"margin", 0x0CB016BE, + CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::TextIndent, L"text-indent", 0x169ADB74, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::Right, L"right", 0x193ADE3E, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::PaddingLeft, L"padding-left", 0x228CF02F, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::MarginLeft, L"margin-left", 0x297C5656, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber | + CFX_CSSVALUETYPE_MaybeEnum}, + {CFX_CSSProperty::Border, L"border", 0x2A23349E, + CFX_CSSVALUETYPE_Shorthand}, + {CFX_CSSProperty::BorderTop, L"border-top", 0x2B866ADE, + CFX_CSSVALUETYPE_Shorthand}, + {CFX_CSSProperty::Bottom, L"bottom", 0x399F02B5, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::PaddingRight, L"padding-right", 0x3F616AC2, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::BorderBottom, L"border-bottom", 0x452CE780, + CFX_CSSVALUETYPE_Shorthand}, + {CFX_CSSProperty::FontFamily, L"font-family", 0x574686E6, + CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeString}, + {CFX_CSSProperty::FontWeight, L"font-weight", 0x6692F60C, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::Color, L"color", 0x6E67921F, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeColor}, + {CFX_CSSProperty::LetterSpacing, L"letter-spacing", 0x70536102, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::TextAlign, L"text-align", 0x7553F1BD, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum}, + {CFX_CSSProperty::BorderRightWidth, L"border-right-width", 0x8F5A6036, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::VerticalAlign, L"vertical-align", 0x934A87D2, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::PaddingTop, L"padding-top", 0x959D22B7, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::FontVariant, L"font-variant", 0x9C785779, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum}, + {CFX_CSSProperty::BorderWidth, L"border-width", 0xA8DE4FEB, + CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::BorderBottomWidth, L"border-bottom-width", 0xAE41204D, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::BorderRight, L"border-right", 0xB78E9EA9, + CFX_CSSVALUETYPE_Shorthand}, + {CFX_CSSProperty::FontSize, L"font-size", 0xB93956DF, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::BorderSpacing, L"border-spacing", 0xC72030F0, + CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::FontStyle, L"font-style", 0xCB1950F5, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum}, + {CFX_CSSProperty::Font, L"font", 0xCD308B77, CFX_CSSVALUETYPE_Shorthand}, + {CFX_CSSProperty::LineHeight, L"line-height", 0xCFCACE2E, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::MarginRight, L"margin-right", 0xD13C58C9, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber | + CFX_CSSVALUETYPE_MaybeEnum}, + {CFX_CSSProperty::BorderLeftWidth, L"border-left-width", 0xD1E93D83, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::Display, L"display", 0xD4224C36, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum}, + {CFX_CSSProperty::PaddingBottom, L"padding-bottom", 0xE555B3B9, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::BorderTopWidth, L"border-top-width", 0xED2CB62B, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::WordSpacing, L"word-spacing", 0xEDA63BAE, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::Left, L"left", 0xF5AD782B, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeEnum | + CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::TextDecoration, L"text-decoration", 0xF7C634BA, + CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeEnum}, + {CFX_CSSProperty::Padding, L"padding", 0xF8C373F7, + CFX_CSSVALUETYPE_List | CFX_CSSVALUETYPE_MaybeNumber}, + {CFX_CSSProperty::MarginBottom, L"margin-bottom", 0xF93485A0, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber | + CFX_CSSVALUETYPE_MaybeEnum}, + {CFX_CSSProperty::MarginTop, L"margin-top", 0xFE51DCFE, + CFX_CSSVALUETYPE_Primitive | CFX_CSSVALUETYPE_MaybeNumber | + CFX_CSSVALUETYPE_MaybeEnum}, +}; +const int32_t g_iCSSPropertyCount = + sizeof(g_CFX_CSSProperties) / sizeof(CFX_CSSPropertyTable); +static_assert(g_iCSSPropertyCount == + static_cast<int32_t>(CFX_CSSProperty::LAST_MARKER), + "Property table differs in size from property enum"); + +static const CFX_CSSPropertyValueTable g_CFX_CSSPropertyValues[] = { + {CFX_CSSPropertyValue::Bolder, L"bolder", 0x009F1058}, + {CFX_CSSPropertyValue::None, L"none", 0x048B6670}, + {CFX_CSSPropertyValue::Dot, L"dot", 0x0A48CB27}, + {CFX_CSSPropertyValue::Sub, L"sub", 0x0BD37FAA}, + {CFX_CSSPropertyValue::Top, L"top", 0x0BEDAF33}, + {CFX_CSSPropertyValue::Right, L"right", 0x193ADE3E}, + {CFX_CSSPropertyValue::Normal, L"normal", 0x247CF3E9}, + {CFX_CSSPropertyValue::Auto, L"auto", 0x2B35B6D9}, + {CFX_CSSPropertyValue::Text, L"text", 0x2D08AF85}, + {CFX_CSSPropertyValue::XSmall, L"x-small", 0x2D2FCAFE}, + {CFX_CSSPropertyValue::Thin, L"thin", 0x2D574D53}, + {CFX_CSSPropertyValue::Small, L"small", 0x316A3739}, + {CFX_CSSPropertyValue::Bottom, L"bottom", 0x399F02B5}, + {CFX_CSSPropertyValue::Underline, L"underline", 0x3A0273A6}, + {CFX_CSSPropertyValue::Double, L"double", 0x3D98515B}, + {CFX_CSSPropertyValue::Lighter, L"lighter", 0x45BEB7AF}, + {CFX_CSSPropertyValue::Oblique, L"oblique", 0x53EBDDB1}, + {CFX_CSSPropertyValue::Super, L"super", 0x6A4F842F}, + {CFX_CSSPropertyValue::Center, L"center", 0x6C51AFC1}, + {CFX_CSSPropertyValue::XxLarge, L"xx-large", 0x70BB1508}, + {CFX_CSSPropertyValue::Smaller, L"smaller", 0x849769F0}, + {CFX_CSSPropertyValue::Baseline, L"baseline", 0x87436BA3}, + {CFX_CSSPropertyValue::Thick, L"thick", 0x8CC35EB3}, + {CFX_CSSPropertyValue::Justify, L"justify", 0x8D269CAE}, + {CFX_CSSPropertyValue::Middle, L"middle", 0x947FA00F}, + {CFX_CSSPropertyValue::Medium, L"medium", 0xA084A381}, + {CFX_CSSPropertyValue::ListItem, L"list-item", 0xA32382B8}, + {CFX_CSSPropertyValue::XxSmall, L"xx-small", 0xADE1FC76}, + {CFX_CSSPropertyValue::Bold, L"bold", 0xB18313A1}, + {CFX_CSSPropertyValue::SmallCaps, L"small-caps", 0xB299428D}, + {CFX_CSSPropertyValue::Inline, L"inline", 0xC02D649F}, + {CFX_CSSPropertyValue::Overline, L"overline", 0xC0EC9FA4}, + {CFX_CSSPropertyValue::TextBottom, L"text-bottom", 0xC7D08D87}, + {CFX_CSSPropertyValue::Larger, L"larger", 0xCD3C409D}, + {CFX_CSSPropertyValue::InlineTable, L"inline-table", 0xD131F494}, + {CFX_CSSPropertyValue::InlineBlock, L"inline-block", 0xD26A8BD7}, + {CFX_CSSPropertyValue::Blink, L"blink", 0xDC36E390}, + {CFX_CSSPropertyValue::Block, L"block", 0xDCD480AB}, + {CFX_CSSPropertyValue::Italic, L"italic", 0xE31D5396}, + {CFX_CSSPropertyValue::LineThrough, L"line-through", 0xE4C5A276}, + {CFX_CSSPropertyValue::XLarge, L"x-large", 0xF008E390}, + {CFX_CSSPropertyValue::Large, L"large", 0xF4434FCB}, + {CFX_CSSPropertyValue::Left, L"left", 0xF5AD782B}, + {CFX_CSSPropertyValue::TextTop, L"text-top", 0xFCB58D45}, +}; +const int32_t g_iCSSPropertyValueCount = + sizeof(g_CFX_CSSPropertyValues) / sizeof(CFX_CSSPropertyValueTable); +static_assert(g_iCSSPropertyValueCount == + static_cast<int32_t>(CFX_CSSPropertyValue::LAST_MARKER), + "Property value table differs in size from property value enum"); + +static const CFX_CSSLengthUnitTable g_CFX_CSSLengthUnits[] = { + {0x0672, CFX_CSSNumberType::EMS}, + {0x067D, CFX_CSSNumberType::EXS}, + {0x1AF7, CFX_CSSNumberType::Inches}, + {0x2F7A, CFX_CSSNumberType::MilliMeters}, + {0x3ED3, CFX_CSSNumberType::Picas}, + {0x3EE4, CFX_CSSNumberType::Points}, + {0x3EE8, CFX_CSSNumberType::Pixels}, + {0xFC30, CFX_CSSNumberType::CentiMeters}, +}; + +static const CFX_CSSCOLORTABLE g_CFX_CSSColors[] = { + {0x031B47FE, 0xff000080}, {0x0BB8DF5B, 0xffff0000}, + {0x0D82A78C, 0xff800000}, {0x2ACC82E8, 0xff00ffff}, + {0x2D083986, 0xff008080}, {0x4A6A6195, 0xffc0c0c0}, + {0x546A8EF3, 0xff808080}, {0x65C9169C, 0xffffa500}, + {0x8422BB61, 0xffffffff}, {0x9271A558, 0xff800080}, + {0xA65A3EE3, 0xffff00ff}, {0xB1345708, 0xff0000ff}, + {0xB6D2CF1F, 0xff808000}, {0xD19B5E1C, 0xffffff00}, + {0xDB64391D, 0xff000000}, {0xF616D507, 0xff00ff00}, + {0xF6EFFF31, 0xff008000}, +}; + +const CFX_CSSPropertyTable* CFX_GetCSSPropertyByName( + const CFX_WideStringC& wsName) { + ASSERT(!wsName.IsEmpty()); + uint32_t dwHash = FX_HashCode_GetW(wsName, true); + int32_t iEnd = g_iCSSPropertyCount; + int32_t iMid, iStart = 0; + uint32_t dwMid; + do { + iMid = (iStart + iEnd) / 2; + dwMid = g_CFX_CSSProperties[iMid].dwHash; + if (dwHash == dwMid) { + return g_CFX_CSSProperties + iMid; + } else if (dwHash > dwMid) { + iStart = iMid + 1; + } else { + iEnd = iMid - 1; + } + } while (iStart <= iEnd); + return nullptr; +} + +const CFX_CSSPropertyTable* CFX_GetCSSPropertyByEnum(CFX_CSSProperty eName) { + return g_CFX_CSSProperties + static_cast<int>(eName); +} + +const CFX_CSSPropertyValueTable* CFX_GetCSSPropertyValueByName( + const CFX_WideStringC& wsName) { + ASSERT(!wsName.IsEmpty()); + uint32_t dwHash = FX_HashCode_GetW(wsName, true); + int32_t iEnd = g_iCSSPropertyValueCount; + int32_t iMid, iStart = 0; + uint32_t dwMid; + do { + iMid = (iStart + iEnd) / 2; + dwMid = g_CFX_CSSPropertyValues[iMid].dwHash; + if (dwHash == dwMid) { + return g_CFX_CSSPropertyValues + iMid; + } else if (dwHash > dwMid) { + iStart = iMid + 1; + } else { + iEnd = iMid - 1; + } + } while (iStart <= iEnd); + return nullptr; +} + +const CFX_CSSLengthUnitTable* CFX_GetCSSLengthUnitByName( + const CFX_WideStringC& wsName) { + ASSERT(!wsName.IsEmpty()); + uint16_t wHash = FX_HashCode_GetW(wsName, true); + int32_t iEnd = + sizeof(g_CFX_CSSLengthUnits) / sizeof(CFX_CSSLengthUnitTable) - 1; + int32_t iMid, iStart = 0; + uint16_t wMid; + do { + iMid = (iStart + iEnd) / 2; + wMid = g_CFX_CSSLengthUnits[iMid].wHash; + if (wHash == wMid) { + return g_CFX_CSSLengthUnits + iMid; + } else if (wHash > wMid) { + iStart = iMid + 1; + } else { + iEnd = iMid - 1; + } + } while (iStart <= iEnd); + return nullptr; +} + +const CFX_CSSCOLORTABLE* CFX_GetCSSColorByName(const CFX_WideStringC& wsName) { + ASSERT(!wsName.IsEmpty()); + uint32_t dwHash = FX_HashCode_GetW(wsName, true); + int32_t iEnd = sizeof(g_CFX_CSSColors) / sizeof(CFX_CSSCOLORTABLE) - 1; + int32_t iMid, iStart = 0; + uint32_t dwMid; + do { + iMid = (iStart + iEnd) / 2; + dwMid = g_CFX_CSSColors[iMid].dwHash; + if (dwHash == dwMid) { + return g_CFX_CSSColors + iMid; + } else if (dwHash > dwMid) { + iStart = iMid + 1; + } else { + iEnd = iMid - 1; + } + } while (iStart <= iEnd); + return nullptr; +} diff --git a/core/fxcrt/css/cfx_cssdatatable.h b/core/fxcrt/css/cfx_cssdatatable.h new file mode 100644 index 0000000000..b6188f93bb --- /dev/null +++ b/core/fxcrt/css/cfx_cssdatatable.h @@ -0,0 +1,56 @@ +// Copyright 2014 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 + +#ifndef CORE_FXCRT_CSS_CFX_CSSDATATABLE_H_ +#define CORE_FXCRT_CSS_CFX_CSSDATATABLE_H_ + +#include <memory> +#include <vector> + +#include "core/fxcrt/css/cfx_css.h" +#include "core/fxcrt/css/cfx_cssnumbervalue.h" +#include "core/fxcrt/css/cfx_cssvalue.h" +#include "core/fxcrt/fx_system.h" + +#define CFX_IsOnlyValue(type, enum) \ + (((type) & ~(enum)) == CFX_CSSVALUETYPE_Primitive) + +struct CFX_CSSPropertyTable { + CFX_CSSProperty eName; + const wchar_t* pszName; + uint32_t dwHash; + uint32_t dwType; +}; + +struct CFX_CSSPropertyValueTable { + CFX_CSSPropertyValue eName; + const wchar_t* pszName; + uint32_t dwHash; +}; + +struct CFX_CSSLengthUnitTable { + uint16_t wHash; + CFX_CSSNumberType wValue; +}; + +struct CFX_CSSCOLORTABLE { + uint32_t dwHash; + FX_ARGB dwValue; +}; + +const CFX_CSSPropertyTable* CFX_GetCSSPropertyByName( + const CFX_WideStringC& wsName); +const CFX_CSSPropertyTable* CFX_GetCSSPropertyByEnum(CFX_CSSProperty eName); + +const CFX_CSSPropertyValueTable* CFX_GetCSSPropertyValueByName( + const CFX_WideStringC& wsName); + +const CFX_CSSLengthUnitTable* CFX_GetCSSLengthUnitByName( + const CFX_WideStringC& wsName); + +const CFX_CSSCOLORTABLE* CFX_GetCSSColorByName(const CFX_WideStringC& wsName); + +#endif // CORE_FXCRT_CSS_CFX_CSSDATATABLE_H_ diff --git a/xfa/fde/css/cfde_cssdeclaration.cpp b/core/fxcrt/css/cfx_cssdeclaration.cpp index e15e5f7fe7..b65429edb7 100644 --- a/xfa/fde/css/cfde_cssdeclaration.cpp +++ b/core/fxcrt/css/cfx_cssdeclaration.cpp @@ -4,19 +4,19 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fde/css/cfde_cssdeclaration.h" - +#include "core/fxcrt/css/cfx_cssdeclaration.h" + +#include "core/fxcrt/css/cfx_csscolorvalue.h" +#include "core/fxcrt/css/cfx_csscustomproperty.h" +#include "core/fxcrt/css/cfx_cssenumvalue.h" +#include "core/fxcrt/css/cfx_cssnumbervalue.h" +#include "core/fxcrt/css/cfx_csspropertyholder.h" +#include "core/fxcrt/css/cfx_cssstringvalue.h" +#include "core/fxcrt/css/cfx_cssvaluelist.h" +#include "core/fxcrt/css/cfx_cssvaluelistparser.h" #include "core/fxcrt/fx_extension.h" #include "third_party/base/logging.h" #include "third_party/base/ptr_util.h" -#include "xfa/fde/css/cfde_csscolorvalue.h" -#include "xfa/fde/css/cfde_csscustomproperty.h" -#include "xfa/fde/css/cfde_cssenumvalue.h" -#include "xfa/fde/css/cfde_cssnumbervalue.h" -#include "xfa/fde/css/cfde_csspropertyholder.h" -#include "xfa/fde/css/cfde_cssstringvalue.h" -#include "xfa/fde/css/cfde_cssvaluelist.h" -#include "xfa/fde/css/cfde_cssvaluelistparser.h" namespace { @@ -27,7 +27,7 @@ uint8_t Hex2Dec(uint8_t hexHigh, uint8_t hexLow) { bool ParseCSSNumber(const wchar_t* pszValue, int32_t iValueLen, float& fValue, - FDE_CSSNumberType& eUnit) { + CFX_CSSNumberType& eUnit) { ASSERT(pszValue && iValueLen > 0); int32_t iUsedLen = 0; fValue = FXSYS_wcstof(pszValue, iValueLen, &iUsedLen); @@ -36,12 +36,12 @@ bool ParseCSSNumber(const wchar_t* pszValue, iValueLen -= iUsedLen; pszValue += iUsedLen; - eUnit = FDE_CSSNumberType::Number; + eUnit = CFX_CSSNumberType::Number; if (iValueLen >= 1 && *pszValue == '%') { - eUnit = FDE_CSSNumberType::Percent; + eUnit = CFX_CSSNumberType::Percent; } else if (iValueLen == 2) { - const FDE_CSSLengthUnitTable* pUnit = - FDE_GetCSSLengthUnitByName(CFX_WideStringC(pszValue, 2)); + const CFX_CSSLengthUnitTable* pUnit = + CFX_GetCSSLengthUnitByName(CFX_WideStringC(pszValue, 2)); if (pUnit) eUnit = pUnit->wValue; } @@ -51,10 +51,10 @@ bool ParseCSSNumber(const wchar_t* pszValue, } // namespace // static -bool CFDE_CSSDeclaration::ParseCSSString(const wchar_t* pszValue, - int32_t iValueLen, - int32_t* iOffset, - int32_t* iLength) { +bool CFX_CSSDeclaration::ParseCSSString(const wchar_t* pszValue, + int32_t iValueLen, + int32_t* iOffset, + int32_t* iLength) { ASSERT(pszValue && iValueLen > 0); *iOffset = 0; *iLength = iValueLen; @@ -69,9 +69,9 @@ bool CFDE_CSSDeclaration::ParseCSSString(const wchar_t* pszValue, } // static. -bool CFDE_CSSDeclaration::ParseCSSColor(const wchar_t* pszValue, - int32_t iValueLen, - FX_ARGB* dwColor) { +bool CFX_CSSDeclaration::ParseCSSColor(const wchar_t* pszValue, + int32_t iValueLen, + FX_ARGB* dwColor) { ASSERT(pszValue && iValueLen > 0); ASSERT(dwColor); @@ -102,18 +102,18 @@ bool CFDE_CSSDeclaration::ParseCSSColor(const wchar_t* pszValue, uint8_t rgb[3] = {0}; float fValue; - FDE_CSSPrimitiveType eType; - CFDE_CSSValueListParser list(pszValue + 4, iValueLen - 5, ','); + CFX_CSSPrimitiveType eType; + CFX_CSSValueListParser list(pszValue + 4, iValueLen - 5, ','); for (int32_t i = 0; i < 3; ++i) { if (!list.NextValue(eType, pszValue, iValueLen)) return false; - if (eType != FDE_CSSPrimitiveType::Number) + if (eType != CFX_CSSPrimitiveType::Number) return false; - FDE_CSSNumberType eNumType; + CFX_CSSNumberType eNumType; if (!ParseCSSNumber(pszValue, iValueLen, fValue, eNumType)) return false; - rgb[i] = eNumType == FDE_CSSNumberType::Percent + rgb[i] = eNumType == CFX_CSSNumberType::Percent ? FXSYS_round(fValue * 2.55f) : FXSYS_round(fValue); } @@ -121,8 +121,8 @@ bool CFDE_CSSDeclaration::ParseCSSColor(const wchar_t* pszValue, return true; } - const FDE_CSSCOLORTABLE* pColor = - FDE_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen)); + const CFX_CSSCOLORTABLE* pColor = + CFX_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen)); if (!pColor) return false; @@ -130,12 +130,12 @@ bool CFDE_CSSDeclaration::ParseCSSColor(const wchar_t* pszValue, return true; } -CFDE_CSSDeclaration::CFDE_CSSDeclaration() {} +CFX_CSSDeclaration::CFX_CSSDeclaration() {} -CFDE_CSSDeclaration::~CFDE_CSSDeclaration() {} +CFX_CSSDeclaration::~CFX_CSSDeclaration() {} -CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::GetProperty( - FDE_CSSProperty eProperty, +CFX_RetainPtr<CFX_CSSValue> CFX_CSSDeclaration::GetProperty( + CFX_CSSProperty eProperty, bool* bImportant) const { for (const auto& p : properties_) { if (p->eProperty == eProperty) { @@ -146,18 +146,18 @@ CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::GetProperty( return nullptr; } -void CFDE_CSSDeclaration::AddPropertyHolder(FDE_CSSProperty eProperty, - CFX_RetainPtr<CFDE_CSSValue> pValue, - bool bImportant) { - auto pHolder = pdfium::MakeUnique<CFDE_CSSPropertyHolder>(); +void CFX_CSSDeclaration::AddPropertyHolder(CFX_CSSProperty eProperty, + CFX_RetainPtr<CFX_CSSValue> pValue, + bool bImportant) { + auto pHolder = pdfium::MakeUnique<CFX_CSSPropertyHolder>(); pHolder->bImportant = bImportant; pHolder->eProperty = eProperty; pHolder->pValue = pValue; properties_.push_back(std::move(pHolder)); } -void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyTable* pTable, - const CFX_WideStringC& value) { +void CFX_CSSDeclaration::AddProperty(const CFX_CSSPropertyTable* pTable, + const CFX_WideStringC& value) { ASSERT(!value.IsEmpty()); const wchar_t* pszValue = value.unterminated_c_str(); @@ -172,10 +172,10 @@ void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyTable* pTable, } const uint32_t dwType = pTable->dwType; switch (dwType & 0x0F) { - case FDE_CSSVALUETYPE_Primitive: { + case CFX_CSSVALUETYPE_Primitive: { static const uint32_t g_ValueGuessOrder[] = { - FDE_CSSVALUETYPE_MaybeNumber, FDE_CSSVALUETYPE_MaybeEnum, - FDE_CSSVALUETYPE_MaybeColor, FDE_CSSVALUETYPE_MaybeString, + CFX_CSSVALUETYPE_MaybeNumber, CFX_CSSVALUETYPE_MaybeEnum, + CFX_CSSVALUETYPE_MaybeColor, CFX_CSSVALUETYPE_MaybeString, }; static const int32_t g_ValueGuessCount = sizeof(g_ValueGuessOrder) / sizeof(uint32_t); @@ -184,18 +184,18 @@ void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyTable* pTable, if (dwMatch == 0) { continue; } - CFX_RetainPtr<CFDE_CSSValue> pCSSValue; + CFX_RetainPtr<CFX_CSSValue> pCSSValue; switch (dwMatch) { - case FDE_CSSVALUETYPE_MaybeNumber: + case CFX_CSSVALUETYPE_MaybeNumber: pCSSValue = ParseNumber(pszValue, iValueLen); break; - case FDE_CSSVALUETYPE_MaybeEnum: + case CFX_CSSVALUETYPE_MaybeEnum: pCSSValue = ParseEnum(pszValue, iValueLen); break; - case FDE_CSSVALUETYPE_MaybeColor: + case CFX_CSSVALUETYPE_MaybeColor: pCSSValue = ParseColor(pszValue, iValueLen); break; - case FDE_CSSVALUETYPE_MaybeString: + case CFX_CSSVALUETYPE_MaybeString: pCSSValue = ParseString(pszValue, iValueLen); break; default: @@ -205,54 +205,54 @@ void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyTable* pTable, AddPropertyHolder(pTable->eName, pCSSValue, bImportant); return; } - if (FDE_IsOnlyValue(dwType, g_ValueGuessOrder[i])) + if (CFX_IsOnlyValue(dwType, g_ValueGuessOrder[i])) return; } break; } - case FDE_CSSVALUETYPE_Shorthand: { - CFX_RetainPtr<CFDE_CSSValue> pWidth; + case CFX_CSSVALUETYPE_Shorthand: { + CFX_RetainPtr<CFX_CSSValue> pWidth; switch (pTable->eName) { - case FDE_CSSProperty::Font: + case CFX_CSSProperty::Font: ParseFontProperty(pszValue, iValueLen, bImportant); return; - case FDE_CSSProperty::Border: + case CFX_CSSProperty::Border: if (ParseBorderProperty(pszValue, iValueLen, pWidth)) { - AddPropertyHolder(FDE_CSSProperty::BorderLeftWidth, pWidth, + AddPropertyHolder(CFX_CSSProperty::BorderLeftWidth, pWidth, bImportant); - AddPropertyHolder(FDE_CSSProperty::BorderTopWidth, pWidth, + AddPropertyHolder(CFX_CSSProperty::BorderTopWidth, pWidth, bImportant); - AddPropertyHolder(FDE_CSSProperty::BorderRightWidth, pWidth, + AddPropertyHolder(CFX_CSSProperty::BorderRightWidth, pWidth, bImportant); - AddPropertyHolder(FDE_CSSProperty::BorderBottomWidth, pWidth, + AddPropertyHolder(CFX_CSSProperty::BorderBottomWidth, pWidth, bImportant); return; } break; - case FDE_CSSProperty::BorderLeft: + case CFX_CSSProperty::BorderLeft: if (ParseBorderProperty(pszValue, iValueLen, pWidth)) { - AddPropertyHolder(FDE_CSSProperty::BorderLeftWidth, pWidth, + AddPropertyHolder(CFX_CSSProperty::BorderLeftWidth, pWidth, bImportant); return; } break; - case FDE_CSSProperty::BorderTop: + case CFX_CSSProperty::BorderTop: if (ParseBorderProperty(pszValue, iValueLen, pWidth)) { - AddPropertyHolder(FDE_CSSProperty::BorderTopWidth, pWidth, + AddPropertyHolder(CFX_CSSProperty::BorderTopWidth, pWidth, bImportant); return; } break; - case FDE_CSSProperty::BorderRight: + case CFX_CSSProperty::BorderRight: if (ParseBorderProperty(pszValue, iValueLen, pWidth)) { - AddPropertyHolder(FDE_CSSProperty::BorderRightWidth, pWidth, + AddPropertyHolder(CFX_CSSProperty::BorderRightWidth, pWidth, bImportant); return; } break; - case FDE_CSSProperty::BorderBottom: + case CFX_CSSProperty::BorderBottom: if (ParseBorderProperty(pszValue, iValueLen, pWidth)) { - AddPropertyHolder(FDE_CSSProperty::BorderBottomWidth, pWidth, + AddPropertyHolder(CFX_CSSProperty::BorderBottomWidth, pWidth, bImportant); return; } @@ -261,7 +261,7 @@ void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyTable* pTable, break; } } break; - case FDE_CSSVALUETYPE_List: + case CFX_CSSVALUETYPE_List: ParseValueListProperty(pTable, pszValue, iValueLen, bImportant); return; default: @@ -270,41 +270,40 @@ void CFDE_CSSDeclaration::AddProperty(const FDE_CSSPropertyTable* pTable, } } -void CFDE_CSSDeclaration::AddProperty(const CFX_WideString& prop, - const CFX_WideString& value) { +void CFX_CSSDeclaration::AddProperty(const CFX_WideString& prop, + const CFX_WideString& value) { custom_properties_.push_back( - pdfium::MakeUnique<CFDE_CSSCustomProperty>(prop, value)); + pdfium::MakeUnique<CFX_CSSCustomProperty>(prop, value)); } -CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::ParseNumber( +CFX_RetainPtr<CFX_CSSValue> CFX_CSSDeclaration::ParseNumber( const wchar_t* pszValue, int32_t iValueLen) { float fValue; - FDE_CSSNumberType eUnit; + CFX_CSSNumberType eUnit; if (!ParseCSSNumber(pszValue, iValueLen, fValue, eUnit)) return nullptr; - return pdfium::MakeRetain<CFDE_CSSNumberValue>(eUnit, fValue); + return pdfium::MakeRetain<CFX_CSSNumberValue>(eUnit, fValue); } -CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::ParseEnum( +CFX_RetainPtr<CFX_CSSValue> CFX_CSSDeclaration::ParseEnum( const wchar_t* pszValue, int32_t iValueLen) { - const FDE_CSSPropertyValueTable* pValue = - FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); - return pValue ? pdfium::MakeRetain<CFDE_CSSEnumValue>(pValue->eName) - : nullptr; + const CFX_CSSPropertyValueTable* pValue = + CFX_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); + return pValue ? pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName) : nullptr; } -CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::ParseColor( +CFX_RetainPtr<CFX_CSSValue> CFX_CSSDeclaration::ParseColor( const wchar_t* pszValue, int32_t iValueLen) { FX_ARGB dwColor; if (!ParseCSSColor(pszValue, iValueLen, &dwColor)) return nullptr; - return pdfium::MakeRetain<CFDE_CSSColorValue>(dwColor); + return pdfium::MakeRetain<CFX_CSSColorValue>(dwColor); } -CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::ParseString( +CFX_RetainPtr<CFX_CSSValue> CFX_CSSDeclaration::ParseString( const wchar_t* pszValue, int32_t iValueLen) { int32_t iOffset; @@ -314,61 +313,60 @@ CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSDeclaration::ParseString( if (iValueLen <= 0) return nullptr; - return pdfium::MakeRetain<CFDE_CSSStringValue>( + return pdfium::MakeRetain<CFX_CSSStringValue>( CFX_WideString(pszValue + iOffset, iValueLen)); } -void CFDE_CSSDeclaration::ParseValueListProperty( - const FDE_CSSPropertyTable* pTable, +void CFX_CSSDeclaration::ParseValueListProperty( + const CFX_CSSPropertyTable* pTable, const wchar_t* pszValue, int32_t iValueLen, bool bImportant) { wchar_t separator = - (pTable->eName == FDE_CSSProperty::FontFamily) ? ',' : ' '; - CFDE_CSSValueListParser parser(pszValue, iValueLen, separator); + (pTable->eName == CFX_CSSProperty::FontFamily) ? ',' : ' '; + CFX_CSSValueListParser parser(pszValue, iValueLen, separator); const uint32_t dwType = pTable->dwType; - FDE_CSSPrimitiveType eType; - std::vector<CFX_RetainPtr<CFDE_CSSValue>> list; + CFX_CSSPrimitiveType eType; + std::vector<CFX_RetainPtr<CFX_CSSValue>> list; while (parser.NextValue(eType, pszValue, iValueLen)) { switch (eType) { - case FDE_CSSPrimitiveType::Number: - if (dwType & FDE_CSSVALUETYPE_MaybeNumber) { + case CFX_CSSPrimitiveType::Number: + if (dwType & CFX_CSSVALUETYPE_MaybeNumber) { float fValue; - FDE_CSSNumberType eNumType; + CFX_CSSNumberType eNumType; if (ParseCSSNumber(pszValue, iValueLen, fValue, eNumType)) list.push_back( - pdfium::MakeRetain<CFDE_CSSNumberValue>(eNumType, fValue)); + pdfium::MakeRetain<CFX_CSSNumberValue>(eNumType, fValue)); } break; - case FDE_CSSPrimitiveType::String: - if (dwType & FDE_CSSVALUETYPE_MaybeColor) { + case CFX_CSSPrimitiveType::String: + if (dwType & CFX_CSSVALUETYPE_MaybeColor) { FX_ARGB dwColor; if (ParseCSSColor(pszValue, iValueLen, &dwColor)) { - list.push_back(pdfium::MakeRetain<CFDE_CSSColorValue>(dwColor)); + list.push_back(pdfium::MakeRetain<CFX_CSSColorValue>(dwColor)); continue; } } - if (dwType & FDE_CSSVALUETYPE_MaybeEnum) { - const FDE_CSSPropertyValueTable* pValue = - FDE_GetCSSPropertyValueByName( + if (dwType & CFX_CSSVALUETYPE_MaybeEnum) { + const CFX_CSSPropertyValueTable* pValue = + CFX_GetCSSPropertyValueByName( CFX_WideStringC(pszValue, iValueLen)); if (pValue) { - list.push_back( - pdfium::MakeRetain<CFDE_CSSEnumValue>(pValue->eName)); + list.push_back(pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName)); continue; } } - if (dwType & FDE_CSSVALUETYPE_MaybeString) { - list.push_back(pdfium::MakeRetain<CFDE_CSSStringValue>( + if (dwType & CFX_CSSVALUETYPE_MaybeString) { + list.push_back(pdfium::MakeRetain<CFX_CSSStringValue>( CFX_WideString(pszValue, iValueLen))); } break; - case FDE_CSSPrimitiveType::RGB: - if (dwType & FDE_CSSVALUETYPE_MaybeColor) { + case CFX_CSSPrimitiveType::RGB: + if (dwType & CFX_CSSVALUETYPE_MaybeColor) { FX_ARGB dwColor; if (ParseCSSColor(pszValue, iValueLen, &dwColor)) { - list.push_back(pdfium::MakeRetain<CFDE_CSSColorValue>(dwColor)); + list.push_back(pdfium::MakeRetain<CFX_CSSColorValue>(dwColor)); } } break; @@ -380,39 +378,39 @@ void CFDE_CSSDeclaration::ParseValueListProperty( return; switch (pTable->eName) { - case FDE_CSSProperty::BorderWidth: - Add4ValuesProperty(list, bImportant, FDE_CSSProperty::BorderLeftWidth, - FDE_CSSProperty::BorderTopWidth, - FDE_CSSProperty::BorderRightWidth, - FDE_CSSProperty::BorderBottomWidth); + case CFX_CSSProperty::BorderWidth: + Add4ValuesProperty(list, bImportant, CFX_CSSProperty::BorderLeftWidth, + CFX_CSSProperty::BorderTopWidth, + CFX_CSSProperty::BorderRightWidth, + CFX_CSSProperty::BorderBottomWidth); return; - case FDE_CSSProperty::Margin: - Add4ValuesProperty(list, bImportant, FDE_CSSProperty::MarginLeft, - FDE_CSSProperty::MarginTop, - FDE_CSSProperty::MarginRight, - FDE_CSSProperty::MarginBottom); + case CFX_CSSProperty::Margin: + Add4ValuesProperty(list, bImportant, CFX_CSSProperty::MarginLeft, + CFX_CSSProperty::MarginTop, + CFX_CSSProperty::MarginRight, + CFX_CSSProperty::MarginBottom); return; - case FDE_CSSProperty::Padding: - Add4ValuesProperty(list, bImportant, FDE_CSSProperty::PaddingLeft, - FDE_CSSProperty::PaddingTop, - FDE_CSSProperty::PaddingRight, - FDE_CSSProperty::PaddingBottom); + case CFX_CSSProperty::Padding: + Add4ValuesProperty(list, bImportant, CFX_CSSProperty::PaddingLeft, + CFX_CSSProperty::PaddingTop, + CFX_CSSProperty::PaddingRight, + CFX_CSSProperty::PaddingBottom); return; default: { - auto pList = pdfium::MakeRetain<CFDE_CSSValueList>(list); + auto pList = pdfium::MakeRetain<CFX_CSSValueList>(list); AddPropertyHolder(pTable->eName, pList, bImportant); return; } } } -void CFDE_CSSDeclaration::Add4ValuesProperty( - const std::vector<CFX_RetainPtr<CFDE_CSSValue>>& list, +void CFX_CSSDeclaration::Add4ValuesProperty( + const std::vector<CFX_RetainPtr<CFX_CSSValue>>& list, bool bImportant, - FDE_CSSProperty eLeft, - FDE_CSSProperty eTop, - FDE_CSSProperty eRight, - FDE_CSSProperty eBottom) { + CFX_CSSProperty eLeft, + CFX_CSSProperty eTop, + CFX_CSSProperty eRight, + CFX_CSSProperty eBottom) { switch (list.size()) { case 1: AddPropertyHolder(eLeft, list[0], bImportant); @@ -443,43 +441,43 @@ void CFDE_CSSDeclaration::Add4ValuesProperty( } } -bool CFDE_CSSDeclaration::ParseBorderProperty( +bool CFX_CSSDeclaration::ParseBorderProperty( const wchar_t* pszValue, int32_t iValueLen, - CFX_RetainPtr<CFDE_CSSValue>& pWidth) const { + CFX_RetainPtr<CFX_CSSValue>& pWidth) const { pWidth.Reset(nullptr); - CFDE_CSSValueListParser parser(pszValue, iValueLen, ' '); - FDE_CSSPrimitiveType eType; + CFX_CSSValueListParser parser(pszValue, iValueLen, ' '); + CFX_CSSPrimitiveType eType; while (parser.NextValue(eType, pszValue, iValueLen)) { switch (eType) { - case FDE_CSSPrimitiveType::Number: { + case CFX_CSSPrimitiveType::Number: { if (pWidth) continue; float fValue; - FDE_CSSNumberType eNumType; + CFX_CSSNumberType eNumType; if (ParseCSSNumber(pszValue, iValueLen, fValue, eNumType)) - pWidth = pdfium::MakeRetain<CFDE_CSSNumberValue>(eNumType, fValue); + pWidth = pdfium::MakeRetain<CFX_CSSNumberValue>(eNumType, fValue); break; } - case FDE_CSSPrimitiveType::String: { - const FDE_CSSCOLORTABLE* pColorItem = - FDE_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen)); + case CFX_CSSPrimitiveType::String: { + const CFX_CSSCOLORTABLE* pColorItem = + CFX_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen)); if (pColorItem) continue; - const FDE_CSSPropertyValueTable* pValue = - FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); + const CFX_CSSPropertyValueTable* pValue = + CFX_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); if (!pValue) continue; switch (pValue->eName) { - case FDE_CSSPropertyValue::Thin: - case FDE_CSSPropertyValue::Thick: - case FDE_CSSPropertyValue::Medium: + case CFX_CSSPropertyValue::Thin: + case CFX_CSSPropertyValue::Thick: + case CFX_CSSPropertyValue::Medium: if (!pWidth) - pWidth = pdfium::MakeRetain<CFDE_CSSEnumValue>(pValue->eName); + pWidth = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName); break; default: break; @@ -491,89 +489,87 @@ bool CFDE_CSSDeclaration::ParseBorderProperty( } } if (!pWidth) - pWidth = pdfium::MakeRetain<CFDE_CSSNumberValue>(FDE_CSSNumberType::Number, - 0.0f); + pWidth = + pdfium::MakeRetain<CFX_CSSNumberValue>(CFX_CSSNumberType::Number, 0.0f); return true; } -void CFDE_CSSDeclaration::ParseFontProperty(const wchar_t* pszValue, - int32_t iValueLen, - bool bImportant) { - CFDE_CSSValueListParser parser(pszValue, iValueLen, '/'); - CFX_RetainPtr<CFDE_CSSValue> pStyle; - CFX_RetainPtr<CFDE_CSSValue> pVariant; - CFX_RetainPtr<CFDE_CSSValue> pWeight; - CFX_RetainPtr<CFDE_CSSValue> pFontSize; - CFX_RetainPtr<CFDE_CSSValue> pLineHeight; - std::vector<CFX_RetainPtr<CFDE_CSSValue>> familyList; - FDE_CSSPrimitiveType eType; +void CFX_CSSDeclaration::ParseFontProperty(const wchar_t* pszValue, + int32_t iValueLen, + bool bImportant) { + CFX_CSSValueListParser parser(pszValue, iValueLen, '/'); + CFX_RetainPtr<CFX_CSSValue> pStyle; + CFX_RetainPtr<CFX_CSSValue> pVariant; + CFX_RetainPtr<CFX_CSSValue> pWeight; + CFX_RetainPtr<CFX_CSSValue> pFontSize; + CFX_RetainPtr<CFX_CSSValue> pLineHeight; + std::vector<CFX_RetainPtr<CFX_CSSValue>> familyList; + CFX_CSSPrimitiveType eType; while (parser.NextValue(eType, pszValue, iValueLen)) { switch (eType) { - case FDE_CSSPrimitiveType::String: { - const FDE_CSSPropertyValueTable* pValue = - FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); + case CFX_CSSPrimitiveType::String: { + const CFX_CSSPropertyValueTable* pValue = + CFX_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); if (pValue) { switch (pValue->eName) { - case FDE_CSSPropertyValue::XxSmall: - case FDE_CSSPropertyValue::XSmall: - case FDE_CSSPropertyValue::Small: - case FDE_CSSPropertyValue::Medium: - case FDE_CSSPropertyValue::Large: - case FDE_CSSPropertyValue::XLarge: - case FDE_CSSPropertyValue::XxLarge: - case FDE_CSSPropertyValue::Smaller: - case FDE_CSSPropertyValue::Larger: + case CFX_CSSPropertyValue::XxSmall: + case CFX_CSSPropertyValue::XSmall: + case CFX_CSSPropertyValue::Small: + case CFX_CSSPropertyValue::Medium: + case CFX_CSSPropertyValue::Large: + case CFX_CSSPropertyValue::XLarge: + case CFX_CSSPropertyValue::XxLarge: + case CFX_CSSPropertyValue::Smaller: + case CFX_CSSPropertyValue::Larger: if (!pFontSize) - pFontSize = - pdfium::MakeRetain<CFDE_CSSEnumValue>(pValue->eName); + pFontSize = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName); continue; - case FDE_CSSPropertyValue::Bold: - case FDE_CSSPropertyValue::Bolder: - case FDE_CSSPropertyValue::Lighter: + case CFX_CSSPropertyValue::Bold: + case CFX_CSSPropertyValue::Bolder: + case CFX_CSSPropertyValue::Lighter: if (!pWeight) - pWeight = pdfium::MakeRetain<CFDE_CSSEnumValue>(pValue->eName); + pWeight = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName); continue; - case FDE_CSSPropertyValue::Italic: - case FDE_CSSPropertyValue::Oblique: + case CFX_CSSPropertyValue::Italic: + case CFX_CSSPropertyValue::Oblique: if (!pStyle) - pStyle = pdfium::MakeRetain<CFDE_CSSEnumValue>(pValue->eName); + pStyle = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName); continue; - case FDE_CSSPropertyValue::SmallCaps: + case CFX_CSSPropertyValue::SmallCaps: if (!pVariant) - pVariant = pdfium::MakeRetain<CFDE_CSSEnumValue>(pValue->eName); + pVariant = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName); continue; - case FDE_CSSPropertyValue::Normal: + case CFX_CSSPropertyValue::Normal: if (!pStyle) - pStyle = pdfium::MakeRetain<CFDE_CSSEnumValue>(pValue->eName); + pStyle = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName); else if (!pVariant) - pVariant = pdfium::MakeRetain<CFDE_CSSEnumValue>(pValue->eName); + pVariant = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName); else if (!pWeight) - pWeight = pdfium::MakeRetain<CFDE_CSSEnumValue>(pValue->eName); + pWeight = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName); else if (!pFontSize) - pFontSize = - pdfium::MakeRetain<CFDE_CSSEnumValue>(pValue->eName); + pFontSize = pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName); else if (!pLineHeight) pLineHeight = - pdfium::MakeRetain<CFDE_CSSEnumValue>(pValue->eName); + pdfium::MakeRetain<CFX_CSSEnumValue>(pValue->eName); continue; default: break; } } if (pFontSize) { - familyList.push_back(pdfium::MakeRetain<CFDE_CSSStringValue>( + familyList.push_back(pdfium::MakeRetain<CFX_CSSStringValue>( CFX_WideString(pszValue, iValueLen))); } parser.m_Separator = ','; break; } - case FDE_CSSPrimitiveType::Number: { + case CFX_CSSPrimitiveType::Number: { float fValue; - FDE_CSSNumberType eNumType; + CFX_CSSNumberType eNumType; if (!ParseCSSNumber(pszValue, iValueLen, fValue, eNumType)) break; - if (eType == FDE_CSSPrimitiveType::Number) { + if (eType == CFX_CSSPrimitiveType::Number) { switch ((int32_t)fValue) { case 100: case 200: @@ -585,16 +581,16 @@ void CFDE_CSSDeclaration::ParseFontProperty(const wchar_t* pszValue, case 800: case 900: if (!pWeight) - pWeight = pdfium::MakeRetain<CFDE_CSSNumberValue>( - FDE_CSSNumberType::Number, fValue); + pWeight = pdfium::MakeRetain<CFX_CSSNumberValue>( + CFX_CSSNumberType::Number, fValue); continue; } } if (!pFontSize) - pFontSize = pdfium::MakeRetain<CFDE_CSSNumberValue>(eNumType, fValue); + pFontSize = pdfium::MakeRetain<CFX_CSSNumberValue>(eNumType, fValue); else if (!pLineHeight) pLineHeight = - pdfium::MakeRetain<CFDE_CSSNumberValue>(eNumType, fValue); + pdfium::MakeRetain<CFX_CSSNumberValue>(eNumType, fValue); break; } default: @@ -603,37 +599,36 @@ void CFDE_CSSDeclaration::ParseFontProperty(const wchar_t* pszValue, } if (!pStyle) { - pStyle = - pdfium::MakeRetain<CFDE_CSSEnumValue>(FDE_CSSPropertyValue::Normal); + pStyle = pdfium::MakeRetain<CFX_CSSEnumValue>(CFX_CSSPropertyValue::Normal); } if (!pVariant) { pVariant = - pdfium::MakeRetain<CFDE_CSSEnumValue>(FDE_CSSPropertyValue::Normal); + pdfium::MakeRetain<CFX_CSSEnumValue>(CFX_CSSPropertyValue::Normal); } if (!pWeight) { pWeight = - pdfium::MakeRetain<CFDE_CSSEnumValue>(FDE_CSSPropertyValue::Normal); + pdfium::MakeRetain<CFX_CSSEnumValue>(CFX_CSSPropertyValue::Normal); } if (!pFontSize) { pFontSize = - pdfium::MakeRetain<CFDE_CSSEnumValue>(FDE_CSSPropertyValue::Medium); + pdfium::MakeRetain<CFX_CSSEnumValue>(CFX_CSSPropertyValue::Medium); } if (!pLineHeight) { pLineHeight = - pdfium::MakeRetain<CFDE_CSSEnumValue>(FDE_CSSPropertyValue::Normal); + pdfium::MakeRetain<CFX_CSSEnumValue>(CFX_CSSPropertyValue::Normal); } - AddPropertyHolder(FDE_CSSProperty::FontStyle, pStyle, bImportant); - AddPropertyHolder(FDE_CSSProperty::FontVariant, pVariant, bImportant); - AddPropertyHolder(FDE_CSSProperty::FontWeight, pWeight, bImportant); - AddPropertyHolder(FDE_CSSProperty::FontSize, pFontSize, bImportant); - AddPropertyHolder(FDE_CSSProperty::LineHeight, pLineHeight, bImportant); + AddPropertyHolder(CFX_CSSProperty::FontStyle, pStyle, bImportant); + AddPropertyHolder(CFX_CSSProperty::FontVariant, pVariant, bImportant); + AddPropertyHolder(CFX_CSSProperty::FontWeight, pWeight, bImportant); + AddPropertyHolder(CFX_CSSProperty::FontSize, pFontSize, bImportant); + AddPropertyHolder(CFX_CSSProperty::LineHeight, pLineHeight, bImportant); if (!familyList.empty()) { - auto pList = pdfium::MakeRetain<CFDE_CSSValueList>(familyList); - AddPropertyHolder(FDE_CSSProperty::FontFamily, pList, bImportant); + auto pList = pdfium::MakeRetain<CFX_CSSValueList>(familyList); + AddPropertyHolder(CFX_CSSProperty::FontFamily, pList, bImportant); } } -size_t CFDE_CSSDeclaration::PropertyCountForTesting() const { +size_t CFX_CSSDeclaration::PropertyCountForTesting() const { return properties_.size(); } diff --git a/xfa/fde/css/cfde_cssdeclaration.h b/core/fxcrt/css/cfx_cssdeclaration.h index 3c2e058a43..7b39daef7e 100644 --- a/xfa/fde/css/cfde_cssdeclaration.h +++ b/core/fxcrt/css/cfx_cssdeclaration.h @@ -4,24 +4,24 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FDE_CSS_CFDE_CSSDECLARATION_H_ -#define XFA_FDE_CSS_CFDE_CSSDECLARATION_H_ +#ifndef CORE_FXCRT_CSS_CFX_CSSDECLARATION_H_ +#define CORE_FXCRT_CSS_CFX_CSSDECLARATION_H_ #include <memory> #include <utility> #include <vector> -#include "xfa/fde/css/fde_cssdatatable.h" +#include "core/fxcrt/css/cfx_cssdatatable.h" -class CFDE_CSSPropertyHolder; -class CFDE_CSSCustomProperty; +class CFX_CSSPropertyHolder; +class CFX_CSSCustomProperty; -class CFDE_CSSDeclaration { +class CFX_CSSDeclaration { public: using const_prop_iterator = - std::vector<std::unique_ptr<CFDE_CSSPropertyHolder>>::const_iterator; + std::vector<std::unique_ptr<CFX_CSSPropertyHolder>>::const_iterator; using const_custom_iterator = - std::vector<std::unique_ptr<CFDE_CSSCustomProperty>>::const_iterator; + std::vector<std::unique_ptr<CFX_CSSCustomProperty>>::const_iterator; static bool ParseCSSString(const wchar_t* pszValue, int32_t iValueLen, @@ -31,11 +31,11 @@ class CFDE_CSSDeclaration { int32_t iValueLen, FX_ARGB* dwColor); - CFDE_CSSDeclaration(); - ~CFDE_CSSDeclaration(); + CFX_CSSDeclaration(); + ~CFX_CSSDeclaration(); - CFX_RetainPtr<CFDE_CSSValue> GetProperty(FDE_CSSProperty eProperty, - bool* bImportant) const; + CFX_RetainPtr<CFX_CSSValue> GetProperty(CFX_CSSProperty eProperty, + bool* bImportant) const; const_prop_iterator begin() const { return properties_.begin(); } const_prop_iterator end() const { return properties_.end(); } @@ -47,7 +47,7 @@ class CFDE_CSSDeclaration { bool empty() const { return properties_.empty(); } - void AddProperty(const FDE_CSSPropertyTable* pTable, + void AddProperty(const CFX_CSSPropertyTable* pTable, const CFX_WideStringC& value); void AddProperty(const CFX_WideString& prop, const CFX_WideString& value); @@ -63,31 +63,31 @@ class CFDE_CSSDeclaration { bool bImportant); bool ParseBorderProperty(const wchar_t* pszValue, int32_t iValueLen, - CFX_RetainPtr<CFDE_CSSValue>& pWidth) const; - void ParseValueListProperty(const FDE_CSSPropertyTable* pTable, + CFX_RetainPtr<CFX_CSSValue>& pWidth) const; + void ParseValueListProperty(const CFX_CSSPropertyTable* pTable, const wchar_t* pszValue, int32_t iValueLen, bool bImportant); - void Add4ValuesProperty(const std::vector<CFX_RetainPtr<CFDE_CSSValue>>& list, + void Add4ValuesProperty(const std::vector<CFX_RetainPtr<CFX_CSSValue>>& list, bool bImportant, - FDE_CSSProperty eLeft, - FDE_CSSProperty eTop, - FDE_CSSProperty eRight, - FDE_CSSProperty eBottom); - CFX_RetainPtr<CFDE_CSSValue> ParseNumber(const wchar_t* pszValue, - int32_t iValueLen); - CFX_RetainPtr<CFDE_CSSValue> ParseEnum(const wchar_t* pszValue, + CFX_CSSProperty eLeft, + CFX_CSSProperty eTop, + CFX_CSSProperty eRight, + CFX_CSSProperty eBottom); + CFX_RetainPtr<CFX_CSSValue> ParseNumber(const wchar_t* pszValue, + int32_t iValueLen); + CFX_RetainPtr<CFX_CSSValue> ParseEnum(const wchar_t* pszValue, + int32_t iValueLen); + CFX_RetainPtr<CFX_CSSValue> ParseColor(const wchar_t* pszValue, int32_t iValueLen); - CFX_RetainPtr<CFDE_CSSValue> ParseColor(const wchar_t* pszValue, + CFX_RetainPtr<CFX_CSSValue> ParseString(const wchar_t* pszValue, int32_t iValueLen); - CFX_RetainPtr<CFDE_CSSValue> ParseString(const wchar_t* pszValue, - int32_t iValueLen); - void AddPropertyHolder(FDE_CSSProperty eProperty, - CFX_RetainPtr<CFDE_CSSValue> pValue, + void AddPropertyHolder(CFX_CSSProperty eProperty, + CFX_RetainPtr<CFX_CSSValue> pValue, bool bImportant); - std::vector<std::unique_ptr<CFDE_CSSPropertyHolder>> properties_; - std::vector<std::unique_ptr<CFDE_CSSCustomProperty>> custom_properties_; + std::vector<std::unique_ptr<CFX_CSSPropertyHolder>> properties_; + std::vector<std::unique_ptr<CFX_CSSCustomProperty>> custom_properties_; }; -#endif // XFA_FDE_CSS_CFDE_CSSDECLARATION_H_ +#endif // CORE_FXCRT_CSS_CFX_CSSDECLARATION_H_ diff --git a/xfa/fde/css/cfde_cssdeclaration_unittest.cpp b/core/fxcrt/css/cfx_cssdeclaration_unittest.cpp index f43f941880..535e67da97 100644 --- a/xfa/fde/css/cfde_cssdeclaration_unittest.cpp +++ b/core/fxcrt/css/cfx_cssdeclaration_unittest.cpp @@ -2,60 +2,60 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "xfa/fde/css/cfde_cssdeclaration.h" +#include "core/fxcrt/css/cfx_cssdeclaration.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" -TEST(CFDE_CSSDecalrationTest, HexEncodingParsing) { +TEST(CFX_CSSDeclarationTest, HexEncodingParsing) { FX_ARGB color; // Length value invalid. - EXPECT_FALSE(CFDE_CSSDeclaration::ParseCSSColor(L"#000", 3, &color)); - EXPECT_FALSE(CFDE_CSSDeclaration::ParseCSSColor(L"#000000", 5, &color)); - EXPECT_FALSE(CFDE_CSSDeclaration::ParseCSSColor(L"#000000", 8, &color)); + EXPECT_FALSE(CFX_CSSDeclaration::ParseCSSColor(L"#000", 3, &color)); + EXPECT_FALSE(CFX_CSSDeclaration::ParseCSSColor(L"#000000", 5, &color)); + EXPECT_FALSE(CFX_CSSDeclaration::ParseCSSColor(L"#000000", 8, &color)); // Invalid characters - EXPECT_TRUE(CFDE_CSSDeclaration::ParseCSSColor(L"#zxytlm", 7, &color)); + EXPECT_TRUE(CFX_CSSDeclaration::ParseCSSColor(L"#zxytlm", 7, &color)); EXPECT_EQ(0, FXARGB_R(color)); EXPECT_EQ(0, FXARGB_G(color)); EXPECT_EQ(0, FXARGB_B(color)); - EXPECT_TRUE(CFDE_CSSDeclaration::ParseCSSColor(L"#000", 4, &color)); + EXPECT_TRUE(CFX_CSSDeclaration::ParseCSSColor(L"#000", 4, &color)); EXPECT_EQ(0, FXARGB_R(color)); EXPECT_EQ(0, FXARGB_G(color)); EXPECT_EQ(0, FXARGB_B(color)); - EXPECT_TRUE(CFDE_CSSDeclaration::ParseCSSColor(L"#FFF", 4, &color)); + EXPECT_TRUE(CFX_CSSDeclaration::ParseCSSColor(L"#FFF", 4, &color)); EXPECT_EQ(255, FXARGB_R(color)); EXPECT_EQ(255, FXARGB_G(color)); EXPECT_EQ(255, FXARGB_B(color)); - EXPECT_TRUE(CFDE_CSSDeclaration::ParseCSSColor(L"#F0F0F0", 7, &color)); + EXPECT_TRUE(CFX_CSSDeclaration::ParseCSSColor(L"#F0F0F0", 7, &color)); EXPECT_EQ(240, FXARGB_R(color)); EXPECT_EQ(240, FXARGB_G(color)); EXPECT_EQ(240, FXARGB_B(color)); // Upper and lower case characters. - EXPECT_TRUE(CFDE_CSSDeclaration::ParseCSSColor(L"#1b2F3c", 7, &color)); + EXPECT_TRUE(CFX_CSSDeclaration::ParseCSSColor(L"#1b2F3c", 7, &color)); EXPECT_EQ(27, FXARGB_R(color)); EXPECT_EQ(47, FXARGB_G(color)); EXPECT_EQ(60, FXARGB_B(color)); } -TEST(CFDE_CSSDecalrationTest, RGBEncodingParsing) { +TEST(CFX_CSSDeclarationTest, RGBEncodingParsing) { FX_ARGB color; // Invalid input for rgb() syntax. - EXPECT_FALSE(CFDE_CSSDeclaration::ParseCSSColor(L"blahblahblah", 11, &color)); + EXPECT_FALSE(CFX_CSSDeclaration::ParseCSSColor(L"blahblahblah", 11, &color)); - EXPECT_TRUE(CFDE_CSSDeclaration::ParseCSSColor(L"rgb(0, 0, 0)", 12, &color)); + EXPECT_TRUE(CFX_CSSDeclaration::ParseCSSColor(L"rgb(0, 0, 0)", 12, &color)); EXPECT_EQ(0, FXARGB_R(color)); EXPECT_EQ(0, FXARGB_G(color)); EXPECT_EQ(0, FXARGB_B(color)); EXPECT_TRUE( - CFDE_CSSDeclaration::ParseCSSColor(L"rgb(128,255,48)", 15, &color)); + CFX_CSSDeclaration::ParseCSSColor(L"rgb(128,255,48)", 15, &color)); EXPECT_EQ(128, FXARGB_R(color)); EXPECT_EQ(255, FXARGB_G(color)); EXPECT_EQ(48, FXARGB_B(color)); diff --git a/xfa/fde/css/cfde_cssenumvalue.cpp b/core/fxcrt/css/cfx_cssenumvalue.cpp index c6b9d3ff73..c9b39beb34 100644 --- a/xfa/fde/css/cfde_cssenumvalue.cpp +++ b/core/fxcrt/css/cfx_cssenumvalue.cpp @@ -4,9 +4,9 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fde/css/cfde_cssenumvalue.h" +#include "core/fxcrt/css/cfx_cssenumvalue.h" -CFDE_CSSEnumValue::CFDE_CSSEnumValue(FDE_CSSPropertyValue value) - : CFDE_CSSValue(FDE_CSSPrimitiveType::Enum), value_(value) {} +CFX_CSSEnumValue::CFX_CSSEnumValue(CFX_CSSPropertyValue value) + : CFX_CSSValue(CFX_CSSPrimitiveType::Enum), value_(value) {} -CFDE_CSSEnumValue::~CFDE_CSSEnumValue() {} +CFX_CSSEnumValue::~CFX_CSSEnumValue() {} diff --git a/core/fxcrt/css/cfx_cssenumvalue.h b/core/fxcrt/css/cfx_cssenumvalue.h new file mode 100644 index 0000000000..0d6b87e85d --- /dev/null +++ b/core/fxcrt/css/cfx_cssenumvalue.h @@ -0,0 +1,23 @@ +// Copyright 2017 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 + +#ifndef CORE_FXCRT_CSS_CFX_CSSENUMVALUE_H_ +#define CORE_FXCRT_CSS_CFX_CSSENUMVALUE_H_ + +#include "core/fxcrt/css/cfx_cssvalue.h" + +class CFX_CSSEnumValue : public CFX_CSSValue { + public: + explicit CFX_CSSEnumValue(CFX_CSSPropertyValue value); + ~CFX_CSSEnumValue() override; + + CFX_CSSPropertyValue Value() const { return value_; } + + private: + CFX_CSSPropertyValue value_; +}; + +#endif // CORE_FXCRT_CSS_CFX_CSSENUMVALUE_H_ diff --git a/xfa/fde/css/cfde_cssexttextbuf.cpp b/core/fxcrt/css/cfx_cssexttextbuf.cpp index 86f6776c48..287dc2e954 100644 --- a/xfa/fde/css/cfde_cssexttextbuf.cpp +++ b/core/fxcrt/css/cfx_cssexttextbuf.cpp @@ -4,14 +4,14 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fde/css/cfde_cssexttextbuf.h" +#include "core/fxcrt/css/cfx_cssexttextbuf.h" -CFDE_CSSExtTextBuf::CFDE_CSSExtTextBuf() +CFX_CSSExtTextBuf::CFX_CSSExtTextBuf() : m_pExtBuffer(nullptr), m_iDatLen(0), m_iDatPos(0) {} -CFDE_CSSExtTextBuf::~CFDE_CSSExtTextBuf() {} +CFX_CSSExtTextBuf::~CFX_CSSExtTextBuf() {} -void CFDE_CSSExtTextBuf::AttachBuffer(const wchar_t* pBuffer, int32_t iBufLen) { +void CFX_CSSExtTextBuf::AttachBuffer(const wchar_t* pBuffer, int32_t iBufLen) { m_pExtBuffer = pBuffer; m_iDatLen = iBufLen; } diff --git a/xfa/fde/css/cfde_cssexttextbuf.h b/core/fxcrt/css/cfx_cssexttextbuf.h index 0760182f25..342b91e8aa 100644 --- a/xfa/fde/css/cfde_cssexttextbuf.h +++ b/core/fxcrt/css/cfx_cssexttextbuf.h @@ -4,15 +4,15 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FDE_CSS_CFDE_CSSEXTTEXTBUF_H_ -#define XFA_FDE_CSS_CFDE_CSSEXTTEXTBUF_H_ +#ifndef CORE_FXCRT_CSS_CFX_CSSEXTTEXTBUF_H_ +#define CORE_FXCRT_CSS_CFX_CSSEXTTEXTBUF_H_ #include "core/fxcrt/fx_system.h" -class CFDE_CSSExtTextBuf { +class CFX_CSSExtTextBuf { public: - CFDE_CSSExtTextBuf(); - ~CFDE_CSSExtTextBuf(); + CFX_CSSExtTextBuf(); + ~CFX_CSSExtTextBuf(); void AttachBuffer(const wchar_t* pBuffer, int32_t iBufLen); @@ -31,4 +31,4 @@ class CFDE_CSSExtTextBuf { int32_t m_iDatPos; }; -#endif // XFA_FDE_CSS_CFDE_CSSEXTTEXTBUF_H_ +#endif // CORE_FXCRT_CSS_CFX_CSSEXTTEXTBUF_H_ diff --git a/core/fxcrt/css/cfx_cssnumbervalue.cpp b/core/fxcrt/css/cfx_cssnumbervalue.cpp new file mode 100644 index 0000000000..d8f72479d4 --- /dev/null +++ b/core/fxcrt/css/cfx_cssnumbervalue.cpp @@ -0,0 +1,39 @@ +// Copyright 2017 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 "core/fxcrt/css/cfx_cssnumbervalue.h" + +CFX_CSSNumberValue::CFX_CSSNumberValue(CFX_CSSNumberType type, float value) + : CFX_CSSValue(CFX_CSSPrimitiveType::Number), type_(type), value_(value) { + if (type_ == CFX_CSSNumberType::Number && fabs(value_) < 0.001f) + value_ = 0.0f; +} + +CFX_CSSNumberValue::~CFX_CSSNumberValue() {} + +float CFX_CSSNumberValue::Apply(float percentBase) const { + switch (type_) { + case CFX_CSSNumberType::Pixels: + case CFX_CSSNumberType::Number: + return value_ * 72 / 96; + case CFX_CSSNumberType::EMS: + case CFX_CSSNumberType::EXS: + return value_ * percentBase; + case CFX_CSSNumberType::Percent: + return value_ * percentBase / 100.0f; + case CFX_CSSNumberType::CentiMeters: + return value_ * 28.3464f; + case CFX_CSSNumberType::MilliMeters: + return value_ * 2.8346f; + case CFX_CSSNumberType::Inches: + return value_ * 72.0f; + case CFX_CSSNumberType::Picas: + return value_ / 12.0f; + case CFX_CSSNumberType::Points: + return value_; + } + return value_; +} diff --git a/xfa/fde/css/cfde_cssnumbervalue.h b/core/fxcrt/css/cfx_cssnumbervalue.h index c4d0bd25f0..a49328d663 100644 --- a/xfa/fde/css/cfde_cssnumbervalue.h +++ b/core/fxcrt/css/cfx_cssnumbervalue.h @@ -4,13 +4,13 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FDE_CSS_CFDE_CSSNUMBERVALUE_H_ -#define XFA_FDE_CSS_CFDE_CSSNUMBERVALUE_H_ +#ifndef CORE_FXCRT_CSS_CFX_CSSNUMBERVALUE_H_ +#define CORE_FXCRT_CSS_CFX_CSSNUMBERVALUE_H_ +#include "core/fxcrt/css/cfx_cssvalue.h" #include "core/fxcrt/fx_system.h" -#include "xfa/fde/css/cfde_cssvalue.h" -enum class FDE_CSSNumberType { +enum class CFX_CSSNumberType { Number, Percent, EMS, @@ -23,19 +23,19 @@ enum class FDE_CSSNumberType { Picas, }; -class CFDE_CSSNumberValue : public CFDE_CSSValue { +class CFX_CSSNumberValue : public CFX_CSSValue { public: - CFDE_CSSNumberValue(FDE_CSSNumberType type, float value); - ~CFDE_CSSNumberValue() override; + CFX_CSSNumberValue(CFX_CSSNumberType type, float value); + ~CFX_CSSNumberValue() override; float Value() const { return value_; } - FDE_CSSNumberType Kind() const { return type_; } + CFX_CSSNumberType Kind() const { return type_; } float Apply(float percentBase) const; private: - FDE_CSSNumberType type_; + CFX_CSSNumberType type_; float value_; }; -#endif // XFA_FDE_CSS_CFDE_CSSNUMBERVALUE_H_ +#endif // CORE_FXCRT_CSS_CFX_CSSNUMBERVALUE_H_ diff --git a/xfa/fde/css/cfde_csspropertyholder.cpp b/core/fxcrt/css/cfx_csspropertyholder.cpp index 9f47c8f08b..11e0d4b752 100644 --- a/xfa/fde/css/cfde_csspropertyholder.cpp +++ b/core/fxcrt/css/cfx_csspropertyholder.cpp @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fde/css/cfde_csspropertyholder.h" +#include "core/fxcrt/css/cfx_csspropertyholder.h" -CFDE_CSSPropertyHolder::CFDE_CSSPropertyHolder() {} +CFX_CSSPropertyHolder::CFX_CSSPropertyHolder() {} -CFDE_CSSPropertyHolder::~CFDE_CSSPropertyHolder() {} +CFX_CSSPropertyHolder::~CFX_CSSPropertyHolder() {} diff --git a/core/fxcrt/css/cfx_csspropertyholder.h b/core/fxcrt/css/cfx_csspropertyholder.h new file mode 100644 index 0000000000..ab0e0ae1fb --- /dev/null +++ b/core/fxcrt/css/cfx_csspropertyholder.h @@ -0,0 +1,24 @@ +// Copyright 2017 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 + +#ifndef CORE_FXCRT_CSS_CFX_CSSPROPERTYHOLDER_H_ +#define CORE_FXCRT_CSS_CFX_CSSPROPERTYHOLDER_H_ + +#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/css/cfx_css.h" +#include "core/fxcrt/css/cfx_cssvalue.h" + +class CFX_CSSPropertyHolder { + public: + CFX_CSSPropertyHolder(); + ~CFX_CSSPropertyHolder(); + + CFX_CSSProperty eProperty; + bool bImportant; + CFX_RetainPtr<CFX_CSSValue> pValue; +}; + +#endif // CORE_FXCRT_CSS_CFX_CSSPROPERTYHOLDER_H_ diff --git a/core/fxcrt/css/cfx_cssrulecollection.cpp b/core/fxcrt/css/cfx_cssrulecollection.cpp new file mode 100644 index 0000000000..635ca91c72 --- /dev/null +++ b/core/fxcrt/css/cfx_cssrulecollection.cpp @@ -0,0 +1,56 @@ +// 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 "core/fxcrt/css/cfx_cssrulecollection.h" + +#include <algorithm> +#include <utility> + +#include "core/fxcrt/css/cfx_cssdeclaration.h" +#include "core/fxcrt/css/cfx_cssselector.h" +#include "core/fxcrt/css/cfx_cssstylerule.h" +#include "core/fxcrt/css/cfx_cssstylesheet.h" +#include "core/fxcrt/css/cfx_csssyntaxparser.h" +#include "third_party/base/ptr_util.h" + +CFX_CSSRuleCollection::CFX_CSSRuleCollection() : m_iSelectors(0) {} + +CFX_CSSRuleCollection::~CFX_CSSRuleCollection() { + Clear(); +} + +void CFX_CSSRuleCollection::Clear() { + m_TagRules.clear(); + m_iSelectors = 0; +} + +const std::vector<std::unique_ptr<CFX_CSSRuleCollection::Data>>* +CFX_CSSRuleCollection::GetTagRuleData(const CFX_WideString& tagname) const { + auto it = m_TagRules.find(FX_HashCode_GetW(tagname.c_str(), true)); + return it != m_TagRules.end() ? &it->second : nullptr; +} + +void CFX_CSSRuleCollection::AddRulesFrom(const CFX_CSSStyleSheet* sheet) { + int32_t iRules = sheet->CountRules(); + for (int32_t j = 0; j < iRules; j++) + AddRulesFrom(sheet, sheet->GetRule(j)); +} + +void CFX_CSSRuleCollection::AddRulesFrom(const CFX_CSSStyleSheet* pStyleSheet, + CFX_CSSStyleRule* pStyleRule) { + CFX_CSSDeclaration* pDeclaration = pStyleRule->GetDeclaration(); + int32_t iSelectors = pStyleRule->CountSelectorLists(); + for (int32_t i = 0; i < iSelectors; ++i) { + CFX_CSSSelector* pSelector = pStyleRule->GetSelectorList(i); + m_TagRules[pSelector->GetNameHash()].push_back( + pdfium::MakeUnique<Data>(pSelector, pDeclaration)); + m_iSelectors++; + } +} + +CFX_CSSRuleCollection::Data::Data(CFX_CSSSelector* pSel, + CFX_CSSDeclaration* pDecl) + : pSelector(pSel), pDeclaration(pDecl) {} diff --git a/xfa/fde/css/cfde_cssrulecollection.h b/core/fxcrt/css/cfx_cssrulecollection.h index e9ce7c31d3..6a509d49e7 100644 --- a/xfa/fde/css/cfde_cssrulecollection.h +++ b/core/fxcrt/css/cfx_cssrulecollection.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FDE_CSS_CFDE_CSSRULECOLLECTION_H_ -#define XFA_FDE_CSS_CFDE_CSSRULECOLLECTION_H_ +#ifndef CORE_FXCRT_CSS_CFX_CSSRULECOLLECTION_H_ +#define CORE_FXCRT_CSS_CFX_CSSRULECOLLECTION_H_ #include <map> #include <memory> @@ -13,25 +13,25 @@ #include "core/fxcrt/fx_basic.h" -class CFDE_CSSDeclaration; -class CFDE_CSSSelector; -class CFDE_CSSStyleRule; -class CFDE_CSSStyleSheet; +class CFX_CSSDeclaration; +class CFX_CSSSelector; +class CFX_CSSStyleRule; +class CFX_CSSStyleSheet; -class CFDE_CSSRuleCollection { +class CFX_CSSRuleCollection { public: class Data { public: - Data(CFDE_CSSSelector* pSel, CFDE_CSSDeclaration* pDecl); + Data(CFX_CSSSelector* pSel, CFX_CSSDeclaration* pDecl); - CFDE_CSSSelector* const pSelector; - CFDE_CSSDeclaration* const pDeclaration; + CFX_CSSSelector* const pSelector; + CFX_CSSDeclaration* const pDeclaration; }; - CFDE_CSSRuleCollection(); - ~CFDE_CSSRuleCollection(); + CFX_CSSRuleCollection(); + ~CFX_CSSRuleCollection(); - void AddRulesFrom(const CFDE_CSSStyleSheet* sheet); + void AddRulesFrom(const CFX_CSSStyleSheet* sheet); void Clear(); int32_t CountSelectors() const { return m_iSelectors; } @@ -39,11 +39,11 @@ class CFDE_CSSRuleCollection { const CFX_WideString& tagname) const; private: - void AddRulesFrom(const CFDE_CSSStyleSheet* pStyleSheet, - CFDE_CSSStyleRule* pRule); + void AddRulesFrom(const CFX_CSSStyleSheet* pStyleSheet, + CFX_CSSStyleRule* pRule); std::map<uint32_t, std::vector<std::unique_ptr<Data>>> m_TagRules; int32_t m_iSelectors; }; -#endif // XFA_FDE_CSS_CFDE_CSSRULECOLLECTION_H_ +#endif // CORE_FXCRT_CSS_CFX_CSSRULECOLLECTION_H_ diff --git a/xfa/fde/css/cfde_cssselector.cpp b/core/fxcrt/css/cfx_cssselector.cpp index ad2ec40c2b..6ee81f5610 100644 --- a/xfa/fde/css/cfde_cssselector.cpp +++ b/core/fxcrt/css/cfx_cssselector.cpp @@ -4,7 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fde/css/cfde_cssselector.h" +#include "core/fxcrt/css/cfx_cssselector.h" #include <utility> @@ -26,29 +26,29 @@ int32_t GetCSSNameLen(const wchar_t* psz, const wchar_t* pEnd) { } // namespace -CFDE_CSSSelector::CFDE_CSSSelector(FDE_CSSSelectorType eType, - const wchar_t* psz, - int32_t iLen, - bool bIgnoreCase) +CFX_CSSSelector::CFX_CSSSelector(CFX_CSSSelectorType eType, + const wchar_t* psz, + int32_t iLen, + bool bIgnoreCase) : m_eType(eType), m_dwHash(FX_HashCode_GetW(CFX_WideStringC(psz, iLen), bIgnoreCase)) {} -CFDE_CSSSelector::~CFDE_CSSSelector() {} +CFX_CSSSelector::~CFX_CSSSelector() {} -FDE_CSSSelectorType CFDE_CSSSelector::GetType() const { +CFX_CSSSelectorType CFX_CSSSelector::GetType() const { return m_eType; } -uint32_t CFDE_CSSSelector::GetNameHash() const { +uint32_t CFX_CSSSelector::GetNameHash() const { return m_dwHash; } -CFDE_CSSSelector* CFDE_CSSSelector::GetNextSelector() const { +CFX_CSSSelector* CFX_CSSSelector::GetNextSelector() const { return m_pNext.get(); } // static. -std::unique_ptr<CFDE_CSSSelector> CFDE_CSSSelector::FromString( +std::unique_ptr<CFX_CSSSelector> CFX_CSSSelector::FromString( const CFX_WideStringC& str) { ASSERT(!str.IsEmpty()); @@ -64,15 +64,15 @@ std::unique_ptr<CFDE_CSSSelector> CFDE_CSSSelector::FromString( } } - std::unique_ptr<CFDE_CSSSelector> pFirst = nullptr; + std::unique_ptr<CFX_CSSSelector> pFirst = nullptr; for (psz = pStart; psz < pEnd;) { wchar_t wch = *psz; if (FXSYS_iswalpha(wch) || wch == '*') { int32_t iNameLen = wch == '*' ? 1 : GetCSSNameLen(psz, pEnd); - auto p = pdfium::MakeUnique<CFDE_CSSSelector>( - FDE_CSSSelectorType::Element, psz, iNameLen, true); + auto p = pdfium::MakeUnique<CFX_CSSSelector>(CFX_CSSSelectorType::Element, + psz, iNameLen, true); if (pFirst) { - pFirst->SetType(FDE_CSSSelectorType::Descendant); + pFirst->SetType(CFX_CSSSelectorType::Descendant); p->SetNext(std::move(pFirst)); } pFirst = std::move(p); diff --git a/core/fxcrt/css/cfx_cssselector.h b/core/fxcrt/css/cfx_cssselector.h new file mode 100644 index 0000000000..9fff42a850 --- /dev/null +++ b/core/fxcrt/css/cfx_cssselector.h @@ -0,0 +1,43 @@ +// Copyright 2017 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 + +#ifndef CORE_FXCRT_CSS_CFX_CSSSELECTOR_H_ +#define CORE_FXCRT_CSS_CFX_CSSSELECTOR_H_ + +#include <memory> +#include <utility> + +#include "core/fxcrt/css/cfx_css.h" +#include "core/fxcrt/fx_string.h" + +class CFX_CSSSelector { + public: + static std::unique_ptr<CFX_CSSSelector> FromString( + const CFX_WideStringC& str); + + CFX_CSSSelector(CFX_CSSSelectorType eType, + const wchar_t* psz, + int32_t iLen, + bool bIgnoreCase); + ~CFX_CSSSelector(); + + CFX_CSSSelectorType GetType() const; + uint32_t GetNameHash() const; + CFX_CSSSelector* GetNextSelector() const; + + void SetNext(std::unique_ptr<CFX_CSSSelector> pNext) { + m_pNext = std::move(pNext); + } + + private: + void SetType(CFX_CSSSelectorType eType) { m_eType = eType; } + + CFX_CSSSelectorType m_eType; + uint32_t m_dwHash; + std::unique_ptr<CFX_CSSSelector> m_pNext; +}; + +#endif // CORE_FXCRT_CSS_CFX_CSSSELECTOR_H_ diff --git a/core/fxcrt/css/cfx_cssstringvalue.cpp b/core/fxcrt/css/cfx_cssstringvalue.cpp new file mode 100644 index 0000000000..b66c54505f --- /dev/null +++ b/core/fxcrt/css/cfx_cssstringvalue.cpp @@ -0,0 +1,12 @@ +// Copyright 2017 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 "core/fxcrt/css/cfx_cssstringvalue.h" + +CFX_CSSStringValue::CFX_CSSStringValue(const CFX_WideString& value) + : CFX_CSSValue(CFX_CSSPrimitiveType::String), value_(value) {} + +CFX_CSSStringValue::~CFX_CSSStringValue() {} diff --git a/xfa/fde/css/cfde_cssstringvalue.h b/core/fxcrt/css/cfx_cssstringvalue.h index 33328cf52b..7680360973 100644 --- a/xfa/fde/css/cfde_cssstringvalue.h +++ b/core/fxcrt/css/cfx_cssstringvalue.h @@ -4,15 +4,15 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FDE_CSS_CFDE_CSSSTRINGVALUE_H_ -#define XFA_FDE_CSS_CFDE_CSSSTRINGVALUE_H_ +#ifndef CORE_FXCRT_CSS_CFX_CSSSTRINGVALUE_H_ +#define CORE_FXCRT_CSS_CFX_CSSSTRINGVALUE_H_ -#include "xfa/fde/css/cfde_cssvalue.h" +#include "core/fxcrt/css/cfx_cssvalue.h" -class CFDE_CSSStringValue : public CFDE_CSSValue { +class CFX_CSSStringValue : public CFX_CSSValue { public: - explicit CFDE_CSSStringValue(const CFX_WideString& value); - ~CFDE_CSSStringValue() override; + explicit CFX_CSSStringValue(const CFX_WideString& value); + ~CFX_CSSStringValue() override; const CFX_WideString Value() const { return value_; } @@ -20,4 +20,4 @@ class CFDE_CSSStringValue : public CFDE_CSSValue { const CFX_WideString value_; }; -#endif // XFA_FDE_CSS_CFDE_CSSSTRINGVALUE_H_ +#endif // CORE_FXCRT_CSS_CFX_CSSSTRINGVALUE_H_ diff --git a/core/fxcrt/css/cfx_cssstylerule.cpp b/core/fxcrt/css/cfx_cssstylerule.cpp new file mode 100644 index 0000000000..504771ed46 --- /dev/null +++ b/core/fxcrt/css/cfx_cssstylerule.cpp @@ -0,0 +1,30 @@ +// Copyright 2017 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 "core/fxcrt/css/cfx_cssstylerule.h" + +CFX_CSSStyleRule::CFX_CSSStyleRule() {} + +CFX_CSSStyleRule::~CFX_CSSStyleRule() {} + +size_t CFX_CSSStyleRule::CountSelectorLists() const { + return m_ppSelector.size(); +} + +CFX_CSSSelector* CFX_CSSStyleRule::GetSelectorList(int32_t index) const { + return m_ppSelector[index].get(); +} + +CFX_CSSDeclaration* CFX_CSSStyleRule::GetDeclaration() { + return &m_Declaration; +} + +void CFX_CSSStyleRule::SetSelector( + std::vector<std::unique_ptr<CFX_CSSSelector>>* list) { + ASSERT(m_ppSelector.empty()); + + m_ppSelector.swap(*list); +} diff --git a/core/fxcrt/css/cfx_cssstylerule.h b/core/fxcrt/css/cfx_cssstylerule.h new file mode 100644 index 0000000000..bba1fc53c8 --- /dev/null +++ b/core/fxcrt/css/cfx_cssstylerule.h @@ -0,0 +1,32 @@ +// Copyright 2017 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 + +#ifndef CORE_FXCRT_CSS_CFX_CSSSTYLERULE_H_ +#define CORE_FXCRT_CSS_CFX_CSSSTYLERULE_H_ + +#include <memory> +#include <vector> + +#include "core/fxcrt/css/cfx_cssdeclaration.h" +#include "core/fxcrt/css/cfx_cssselector.h" + +class CFX_CSSStyleRule { + public: + CFX_CSSStyleRule(); + ~CFX_CSSStyleRule(); + + size_t CountSelectorLists() const; + CFX_CSSSelector* GetSelectorList(int32_t index) const; + CFX_CSSDeclaration* GetDeclaration(); + + void SetSelector(std::vector<std::unique_ptr<CFX_CSSSelector>>* list); + + private: + CFX_CSSDeclaration m_Declaration; + std::vector<std::unique_ptr<CFX_CSSSelector>> m_ppSelector; +}; + +#endif // CORE_FXCRT_CSS_CFX_CSSSTYLERULE_H_ diff --git a/core/fxcrt/css/cfx_cssstyleselector.cpp b/core/fxcrt/css/cfx_cssstyleselector.cpp new file mode 100644 index 0000000000..9a2bc8c498 --- /dev/null +++ b/core/fxcrt/css/cfx_cssstyleselector.cpp @@ -0,0 +1,598 @@ +// Copyright 2014 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 "core/fxcrt/css/cfx_cssstyleselector.h" + +#include <algorithm> +#include <utility> + +#include "core/fxcrt/css/cfx_csscolorvalue.h" +#include "core/fxcrt/css/cfx_csscomputedstyle.h" +#include "core/fxcrt/css/cfx_csscustomproperty.h" +#include "core/fxcrt/css/cfx_cssdeclaration.h" +#include "core/fxcrt/css/cfx_cssenumvalue.h" +#include "core/fxcrt/css/cfx_csspropertyholder.h" +#include "core/fxcrt/css/cfx_cssselector.h" +#include "core/fxcrt/css/cfx_cssstylesheet.h" +#include "core/fxcrt/css/cfx_csssyntaxparser.h" +#include "core/fxcrt/css/cfx_cssvaluelist.h" +#include "third_party/base/logging.h" +#include "third_party/base/ptr_util.h" + +CFX_CSSStyleSelector::CFX_CSSStyleSelector() : m_fDefFontSize(12.0f) {} + +CFX_CSSStyleSelector::~CFX_CSSStyleSelector() {} + +void CFX_CSSStyleSelector::SetDefFontSize(float fFontSize) { + ASSERT(fFontSize > 0); + m_fDefFontSize = fFontSize; +} + +CFX_RetainPtr<CFX_CSSComputedStyle> CFX_CSSStyleSelector::CreateComputedStyle( + CFX_CSSComputedStyle* pParentStyle) { + auto pStyle = pdfium::MakeRetain<CFX_CSSComputedStyle>(); + if (pParentStyle) + pStyle->m_InheritedData = pParentStyle->m_InheritedData; + return pStyle; +} + +void CFX_CSSStyleSelector::SetUAStyleSheet( + std::unique_ptr<CFX_CSSStyleSheet> pSheet) { + m_UAStyles = std::move(pSheet); +} + +void CFX_CSSStyleSelector::UpdateStyleIndex() { + m_UARules.Clear(); + m_UARules.AddRulesFrom(m_UAStyles.get()); +} + +std::vector<const CFX_CSSDeclaration*> CFX_CSSStyleSelector::MatchDeclarations( + const CFX_WideString& tagname) { + std::vector<const CFX_CSSDeclaration*> matchedDecls; + if (m_UARules.CountSelectors() == 0 || tagname.IsEmpty()) + return matchedDecls; + + auto* rules = m_UARules.GetTagRuleData(tagname); + if (!rules) + return matchedDecls; + + for (const auto& d : *rules) { + if (MatchSelector(tagname, d->pSelector)) + matchedDecls.push_back(d->pDeclaration); + } + return matchedDecls; +} + +bool CFX_CSSStyleSelector::MatchSelector(const CFX_WideString& tagname, + CFX_CSSSelector* pSel) { + // TODO(dsinclair): The code only supports a single level of selector at this + // point. None of the code using selectors required the complexity so lets + // just say we don't support them to simplify the code for now. + if (!pSel || pSel->GetNextSelector() || + pSel->GetType() == CFX_CSSSelectorType::Descendant) { + return false; + } + return pSel->GetNameHash() == FX_HashCode_GetW(tagname.c_str(), true); +} + +void CFX_CSSStyleSelector::ComputeStyle( + const std::vector<const CFX_CSSDeclaration*>& declArray, + const CFX_WideString& styleString, + const CFX_WideString& alignString, + CFX_CSSComputedStyle* pDest) { + std::unique_ptr<CFX_CSSDeclaration> pDecl; + if (!styleString.IsEmpty() || !alignString.IsEmpty()) { + pDecl = pdfium::MakeUnique<CFX_CSSDeclaration>(); + + if (!styleString.IsEmpty()) + AppendInlineStyle(pDecl.get(), styleString); + if (!alignString.IsEmpty()) { + pDecl->AddProperty(CFX_GetCSSPropertyByEnum(CFX_CSSProperty::TextAlign), + alignString.AsStringC()); + } + } + ApplyDeclarations(declArray, pDecl.get(), pDest); +} + +void CFX_CSSStyleSelector::ApplyDeclarations( + const std::vector<const CFX_CSSDeclaration*>& declArray, + const CFX_CSSDeclaration* extraDecl, + CFX_CSSComputedStyle* pComputedStyle) { + std::vector<const CFX_CSSPropertyHolder*> importants; + std::vector<const CFX_CSSPropertyHolder*> normals; + std::vector<const CFX_CSSCustomProperty*> customs; + + for (auto* decl : declArray) + ExtractValues(decl, &importants, &normals, &customs); + + if (extraDecl) + ExtractValues(extraDecl, &importants, &normals, &customs); + + for (auto* prop : normals) + ApplyProperty(prop->eProperty, prop->pValue, pComputedStyle); + + for (auto* prop : customs) + pComputedStyle->AddCustomStyle(*prop); + + for (auto* prop : importants) + ApplyProperty(prop->eProperty, prop->pValue, pComputedStyle); +} + +void CFX_CSSStyleSelector::ExtractValues( + const CFX_CSSDeclaration* decl, + std::vector<const CFX_CSSPropertyHolder*>* importants, + std::vector<const CFX_CSSPropertyHolder*>* normals, + std::vector<const CFX_CSSCustomProperty*>* custom) { + for (const auto& holder : *decl) { + if (holder->bImportant) + importants->push_back(holder.get()); + else + normals->push_back(holder.get()); + } + for (auto it = decl->custom_begin(); it != decl->custom_end(); it++) + custom->push_back(it->get()); +} + +void CFX_CSSStyleSelector::AppendInlineStyle(CFX_CSSDeclaration* pDecl, + const CFX_WideString& style) { + ASSERT(pDecl && !style.IsEmpty()); + + auto pSyntax = pdfium::MakeUnique<CFX_CSSSyntaxParser>( + style.c_str(), style.GetLength(), 32, true); + int32_t iLen2 = 0; + const CFX_CSSPropertyTable* table = nullptr; + CFX_WideString wsName; + while (1) { + CFX_CSSSyntaxStatus eStatus = pSyntax->DoSyntaxParse(); + if (eStatus == CFX_CSSSyntaxStatus::PropertyName) { + CFX_WideStringC strValue = pSyntax->GetCurrentString(); + table = CFX_GetCSSPropertyByName(strValue); + if (!table) + wsName = CFX_WideString(strValue); + } else if (eStatus == CFX_CSSSyntaxStatus::PropertyValue) { + if (table || iLen2 > 0) { + CFX_WideStringC strValue = pSyntax->GetCurrentString(); + if (!strValue.IsEmpty()) { + if (table) + pDecl->AddProperty(table, strValue); + else if (iLen2 > 0) + pDecl->AddProperty(wsName, CFX_WideString(strValue)); + } + } + } else { + break; + } + } +} + +void CFX_CSSStyleSelector::ApplyProperty( + CFX_CSSProperty eProperty, + const CFX_RetainPtr<CFX_CSSValue>& pValue, + CFX_CSSComputedStyle* pComputedStyle) { + if (pValue->GetType() != CFX_CSSPrimitiveType::List) { + CFX_CSSPrimitiveType eType = pValue->GetType(); + switch (eProperty) { + case CFX_CSSProperty::Display: + if (eType == CFX_CSSPrimitiveType::Enum) { + pComputedStyle->m_NonInheritedData.m_eDisplay = + ToDisplay(pValue.As<CFX_CSSEnumValue>()->Value()); + } + break; + case CFX_CSSProperty::FontSize: { + float& fFontSize = pComputedStyle->m_InheritedData.m_fFontSize; + if (eType == CFX_CSSPrimitiveType::Number) { + fFontSize = pValue.As<CFX_CSSNumberValue>()->Apply(fFontSize); + } else if (eType == CFX_CSSPrimitiveType::Enum) { + fFontSize = + ToFontSize(pValue.As<CFX_CSSEnumValue>()->Value(), fFontSize); + } + } break; + case CFX_CSSProperty::LineHeight: + if (eType == CFX_CSSPrimitiveType::Number) { + CFX_RetainPtr<CFX_CSSNumberValue> v = pValue.As<CFX_CSSNumberValue>(); + if (v->Kind() == CFX_CSSNumberType::Number) { + pComputedStyle->m_InheritedData.m_fLineHeight = + v->Value() * pComputedStyle->m_InheritedData.m_fFontSize; + } else { + pComputedStyle->m_InheritedData.m_fLineHeight = + v->Apply(pComputedStyle->m_InheritedData.m_fFontSize); + } + } + break; + case CFX_CSSProperty::TextAlign: + if (eType == CFX_CSSPrimitiveType::Enum) { + pComputedStyle->m_InheritedData.m_eTextAlign = + ToTextAlign(pValue.As<CFX_CSSEnumValue>()->Value()); + } + break; + case CFX_CSSProperty::TextIndent: + SetLengthWithPercent(pComputedStyle->m_InheritedData.m_TextIndent, + eType, pValue, + pComputedStyle->m_InheritedData.m_fFontSize); + break; + case CFX_CSSProperty::FontWeight: + if (eType == CFX_CSSPrimitiveType::Enum) { + pComputedStyle->m_InheritedData.m_wFontWeight = + ToFontWeight(pValue.As<CFX_CSSEnumValue>()->Value()); + } else if (eType == CFX_CSSPrimitiveType::Number) { + int32_t iValue = + (int32_t)pValue.As<CFX_CSSNumberValue>()->Value() / 100; + if (iValue >= 1 && iValue <= 9) { + pComputedStyle->m_InheritedData.m_wFontWeight = iValue * 100; + } + } + break; + case CFX_CSSProperty::FontStyle: + if (eType == CFX_CSSPrimitiveType::Enum) { + pComputedStyle->m_InheritedData.m_eFontStyle = + ToFontStyle(pValue.As<CFX_CSSEnumValue>()->Value()); + } + break; + case CFX_CSSProperty::Color: + if (eType == CFX_CSSPrimitiveType::RGB) { + pComputedStyle->m_InheritedData.m_dwFontColor = + pValue.As<CFX_CSSColorValue>()->Value(); + } + break; + case CFX_CSSProperty::MarginLeft: + if (SetLengthWithPercent( + pComputedStyle->m_NonInheritedData.m_MarginWidth.left, eType, + pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { + pComputedStyle->m_NonInheritedData.m_bHasMargin = true; + } + break; + case CFX_CSSProperty::MarginTop: + if (SetLengthWithPercent( + pComputedStyle->m_NonInheritedData.m_MarginWidth.top, eType, + pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { + pComputedStyle->m_NonInheritedData.m_bHasMargin = true; + } + break; + case CFX_CSSProperty::MarginRight: + if (SetLengthWithPercent( + pComputedStyle->m_NonInheritedData.m_MarginWidth.right, eType, + pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { + pComputedStyle->m_NonInheritedData.m_bHasMargin = true; + } + break; + case CFX_CSSProperty::MarginBottom: + if (SetLengthWithPercent( + pComputedStyle->m_NonInheritedData.m_MarginWidth.bottom, eType, + pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { + pComputedStyle->m_NonInheritedData.m_bHasMargin = true; + } + break; + case CFX_CSSProperty::PaddingLeft: + if (SetLengthWithPercent( + pComputedStyle->m_NonInheritedData.m_PaddingWidth.left, eType, + pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { + pComputedStyle->m_NonInheritedData.m_bHasPadding = true; + } + break; + case CFX_CSSProperty::PaddingTop: + if (SetLengthWithPercent( + pComputedStyle->m_NonInheritedData.m_PaddingWidth.top, eType, + pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { + pComputedStyle->m_NonInheritedData.m_bHasPadding = true; + } + break; + case CFX_CSSProperty::PaddingRight: + if (SetLengthWithPercent( + pComputedStyle->m_NonInheritedData.m_PaddingWidth.right, eType, + pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { + pComputedStyle->m_NonInheritedData.m_bHasPadding = true; + } + break; + case CFX_CSSProperty::PaddingBottom: + if (SetLengthWithPercent( + pComputedStyle->m_NonInheritedData.m_PaddingWidth.bottom, eType, + pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { + pComputedStyle->m_NonInheritedData.m_bHasPadding = true; + } + break; + case CFX_CSSProperty::BorderLeftWidth: + if (SetLengthWithPercent( + pComputedStyle->m_NonInheritedData.m_BorderWidth.left, eType, + pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { + pComputedStyle->m_NonInheritedData.m_bHasBorder = true; + } + break; + case CFX_CSSProperty::BorderTopWidth: + if (SetLengthWithPercent( + pComputedStyle->m_NonInheritedData.m_BorderWidth.top, eType, + pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { + pComputedStyle->m_NonInheritedData.m_bHasBorder = true; + } + break; + case CFX_CSSProperty::BorderRightWidth: + if (SetLengthWithPercent( + pComputedStyle->m_NonInheritedData.m_BorderWidth.right, eType, + pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { + pComputedStyle->m_NonInheritedData.m_bHasBorder = true; + } + break; + case CFX_CSSProperty::BorderBottomWidth: + if (SetLengthWithPercent( + pComputedStyle->m_NonInheritedData.m_BorderWidth.bottom, eType, + pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { + pComputedStyle->m_NonInheritedData.m_bHasBorder = true; + } + break; + case CFX_CSSProperty::VerticalAlign: + if (eType == CFX_CSSPrimitiveType::Enum) { + pComputedStyle->m_NonInheritedData.m_eVerticalAlign = + ToVerticalAlign(pValue.As<CFX_CSSEnumValue>()->Value()); + } else if (eType == CFX_CSSPrimitiveType::Number) { + pComputedStyle->m_NonInheritedData.m_eVerticalAlign = + CFX_CSSVerticalAlign::Number; + pComputedStyle->m_NonInheritedData.m_fVerticalAlign = + pValue.As<CFX_CSSNumberValue>()->Apply( + pComputedStyle->m_InheritedData.m_fFontSize); + } + break; + case CFX_CSSProperty::FontVariant: + if (eType == CFX_CSSPrimitiveType::Enum) { + pComputedStyle->m_InheritedData.m_eFontVariant = + ToFontVariant(pValue.As<CFX_CSSEnumValue>()->Value()); + } + break; + case CFX_CSSProperty::LetterSpacing: + if (eType == CFX_CSSPrimitiveType::Enum) { + pComputedStyle->m_InheritedData.m_LetterSpacing.Set( + CFX_CSSLengthUnit::Normal); + } else if (eType == CFX_CSSPrimitiveType::Number) { + if (pValue.As<CFX_CSSNumberValue>()->Kind() == + CFX_CSSNumberType::Percent) { + break; + } + + SetLengthWithPercent(pComputedStyle->m_InheritedData.m_LetterSpacing, + eType, pValue, + pComputedStyle->m_InheritedData.m_fFontSize); + } + break; + case CFX_CSSProperty::WordSpacing: + if (eType == CFX_CSSPrimitiveType::Enum) { + pComputedStyle->m_InheritedData.m_WordSpacing.Set( + CFX_CSSLengthUnit::Normal); + } else if (eType == CFX_CSSPrimitiveType::Number) { + if (pValue.As<CFX_CSSNumberValue>()->Kind() == + CFX_CSSNumberType::Percent) { + break; + } + SetLengthWithPercent(pComputedStyle->m_InheritedData.m_WordSpacing, + eType, pValue, + pComputedStyle->m_InheritedData.m_fFontSize); + } + break; + case CFX_CSSProperty::Top: + SetLengthWithPercent(pComputedStyle->m_NonInheritedData.m_Top, eType, + pValue, + pComputedStyle->m_InheritedData.m_fFontSize); + break; + case CFX_CSSProperty::Bottom: + SetLengthWithPercent(pComputedStyle->m_NonInheritedData.m_Bottom, eType, + pValue, + pComputedStyle->m_InheritedData.m_fFontSize); + break; + case CFX_CSSProperty::Left: + SetLengthWithPercent(pComputedStyle->m_NonInheritedData.m_Left, eType, + pValue, + pComputedStyle->m_InheritedData.m_fFontSize); + break; + case CFX_CSSProperty::Right: + SetLengthWithPercent(pComputedStyle->m_NonInheritedData.m_Right, eType, + pValue, + pComputedStyle->m_InheritedData.m_fFontSize); + break; + default: + break; + } + } else if (pValue->GetType() == CFX_CSSPrimitiveType::List) { + CFX_RetainPtr<CFX_CSSValueList> pList = pValue.As<CFX_CSSValueList>(); + int32_t iCount = pList->CountValues(); + if (iCount > 0) { + switch (eProperty) { + case CFX_CSSProperty::FontFamily: + pComputedStyle->m_InheritedData.m_pFontFamily = pList; + break; + case CFX_CSSProperty::TextDecoration: + pComputedStyle->m_NonInheritedData.m_dwTextDecoration = + ToTextDecoration(pList); + break; + default: + break; + } + } + } else { + NOTREACHED(); + } +} + +CFX_CSSDisplay CFX_CSSStyleSelector::ToDisplay(CFX_CSSPropertyValue eValue) { + switch (eValue) { + case CFX_CSSPropertyValue::Block: + return CFX_CSSDisplay::Block; + case CFX_CSSPropertyValue::None: + return CFX_CSSDisplay::None; + case CFX_CSSPropertyValue::ListItem: + return CFX_CSSDisplay::ListItem; + case CFX_CSSPropertyValue::InlineTable: + return CFX_CSSDisplay::InlineTable; + case CFX_CSSPropertyValue::InlineBlock: + return CFX_CSSDisplay::InlineBlock; + case CFX_CSSPropertyValue::Inline: + default: + return CFX_CSSDisplay::Inline; + } +} + +CFX_CSSTextAlign CFX_CSSStyleSelector::ToTextAlign( + CFX_CSSPropertyValue eValue) { + switch (eValue) { + case CFX_CSSPropertyValue::Center: + return CFX_CSSTextAlign::Center; + case CFX_CSSPropertyValue::Right: + return CFX_CSSTextAlign::Right; + case CFX_CSSPropertyValue::Justify: + return CFX_CSSTextAlign::Justify; + case CFX_CSSPropertyValue::Left: + default: + return CFX_CSSTextAlign::Left; + } +} + +uint16_t CFX_CSSStyleSelector::ToFontWeight(CFX_CSSPropertyValue eValue) { + switch (eValue) { + case CFX_CSSPropertyValue::Bold: + return 700; + case CFX_CSSPropertyValue::Bolder: + return 900; + case CFX_CSSPropertyValue::Lighter: + return 200; + case CFX_CSSPropertyValue::Normal: + default: + return 400; + } +} + +CFX_CSSFontStyle CFX_CSSStyleSelector::ToFontStyle( + CFX_CSSPropertyValue eValue) { + switch (eValue) { + case CFX_CSSPropertyValue::Italic: + case CFX_CSSPropertyValue::Oblique: + return CFX_CSSFontStyle::Italic; + default: + return CFX_CSSFontStyle::Normal; + } +} + +bool CFX_CSSStyleSelector::SetLengthWithPercent( + CFX_CSSLength& width, + CFX_CSSPrimitiveType eType, + const CFX_RetainPtr<CFX_CSSValue>& pValue, + float fFontSize) { + if (eType == CFX_CSSPrimitiveType::Number) { + CFX_RetainPtr<CFX_CSSNumberValue> v = pValue.As<CFX_CSSNumberValue>(); + if (v->Kind() == CFX_CSSNumberType::Percent) { + width.Set(CFX_CSSLengthUnit::Percent, + pValue.As<CFX_CSSNumberValue>()->Value() / 100.0f); + return width.NonZero(); + } + + float fValue = v->Apply(fFontSize); + width.Set(CFX_CSSLengthUnit::Point, fValue); + return width.NonZero(); + } else if (eType == CFX_CSSPrimitiveType::Enum) { + switch (pValue.As<CFX_CSSEnumValue>()->Value()) { + case CFX_CSSPropertyValue::Auto: + width.Set(CFX_CSSLengthUnit::Auto); + return true; + case CFX_CSSPropertyValue::None: + width.Set(CFX_CSSLengthUnit::None); + return true; + case CFX_CSSPropertyValue::Thin: + width.Set(CFX_CSSLengthUnit::Point, 2); + return true; + case CFX_CSSPropertyValue::Medium: + width.Set(CFX_CSSLengthUnit::Point, 3); + return true; + case CFX_CSSPropertyValue::Thick: + width.Set(CFX_CSSLengthUnit::Point, 4); + return true; + default: + return false; + } + } + return false; +} + +float CFX_CSSStyleSelector::ToFontSize(CFX_CSSPropertyValue eValue, + float fCurFontSize) { + switch (eValue) { + case CFX_CSSPropertyValue::XxSmall: + return m_fDefFontSize / 1.2f / 1.2f / 1.2f; + case CFX_CSSPropertyValue::XSmall: + return m_fDefFontSize / 1.2f / 1.2f; + case CFX_CSSPropertyValue::Small: + return m_fDefFontSize / 1.2f; + case CFX_CSSPropertyValue::Medium: + return m_fDefFontSize; + case CFX_CSSPropertyValue::Large: + return m_fDefFontSize * 1.2f; + case CFX_CSSPropertyValue::XLarge: + return m_fDefFontSize * 1.2f * 1.2f; + case CFX_CSSPropertyValue::XxLarge: + return m_fDefFontSize * 1.2f * 1.2f * 1.2f; + case CFX_CSSPropertyValue::Larger: + return fCurFontSize * 1.2f; + case CFX_CSSPropertyValue::Smaller: + return fCurFontSize / 1.2f; + default: + return fCurFontSize; + } +} + +CFX_CSSVerticalAlign CFX_CSSStyleSelector::ToVerticalAlign( + CFX_CSSPropertyValue eValue) { + switch (eValue) { + case CFX_CSSPropertyValue::Middle: + return CFX_CSSVerticalAlign::Middle; + case CFX_CSSPropertyValue::Bottom: + return CFX_CSSVerticalAlign::Bottom; + case CFX_CSSPropertyValue::Super: + return CFX_CSSVerticalAlign::Super; + case CFX_CSSPropertyValue::Sub: + return CFX_CSSVerticalAlign::Sub; + case CFX_CSSPropertyValue::Top: + return CFX_CSSVerticalAlign::Top; + case CFX_CSSPropertyValue::TextTop: + return CFX_CSSVerticalAlign::TextTop; + case CFX_CSSPropertyValue::TextBottom: + return CFX_CSSVerticalAlign::TextBottom; + case CFX_CSSPropertyValue::Baseline: + default: + return CFX_CSSVerticalAlign::Baseline; + } +} + +uint32_t CFX_CSSStyleSelector::ToTextDecoration( + const CFX_RetainPtr<CFX_CSSValueList>& pValue) { + uint32_t dwDecoration = 0; + for (int32_t i = pValue->CountValues() - 1; i >= 0; --i) { + const CFX_RetainPtr<CFX_CSSValue> pVal = pValue->GetValue(i); + if (pVal->GetType() != CFX_CSSPrimitiveType::Enum) + continue; + + switch (pVal.As<CFX_CSSEnumValue>()->Value()) { + case CFX_CSSPropertyValue::Underline: + dwDecoration |= CFX_CSSTEXTDECORATION_Underline; + break; + case CFX_CSSPropertyValue::LineThrough: + dwDecoration |= CFX_CSSTEXTDECORATION_LineThrough; + break; + case CFX_CSSPropertyValue::Overline: + dwDecoration |= CFX_CSSTEXTDECORATION_Overline; + break; + case CFX_CSSPropertyValue::Blink: + dwDecoration |= CFX_CSSTEXTDECORATION_Blink; + break; + case CFX_CSSPropertyValue::Double: + dwDecoration |= CFX_CSSTEXTDECORATION_Double; + break; + default: + break; + } + } + return dwDecoration; +} + +CFX_CSSFontVariant CFX_CSSStyleSelector::ToFontVariant( + CFX_CSSPropertyValue eValue) { + return eValue == CFX_CSSPropertyValue::SmallCaps + ? CFX_CSSFontVariant::SmallCaps + : CFX_CSSFontVariant::Normal; +} diff --git a/core/fxcrt/css/cfx_cssstyleselector.h b/core/fxcrt/css/cfx_cssstyleselector.h new file mode 100644 index 0000000000..56d933b614 --- /dev/null +++ b/core/fxcrt/css/cfx_cssstyleselector.h @@ -0,0 +1,85 @@ +// Copyright 2017 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 + +#ifndef CORE_FXCRT_CSS_CFX_CSSSTYLESELECTOR_H_ +#define CORE_FXCRT_CSS_CFX_CSSSTYLESELECTOR_H_ + +#include <memory> +#include <vector> + +#include "core/fxcrt/css/cfx_css.h" +#include "core/fxcrt/css/cfx_cssrulecollection.h" +#include "core/fxcrt/fx_basic.h" +#include "core/fxcrt/fx_system.h" + +class CFX_CSSComputedStyle; +class CFX_CSSCustomProperty; +class CFX_CSSDeclaration; +class CFX_CSSPropertyHolder; +class CFX_CSSSelector; +class CFX_CSSStyleSheet; +class CFX_CSSValue; +class CFX_CSSValueList; + +class CFX_CSSStyleSelector { + public: + CFX_CSSStyleSelector(); + ~CFX_CSSStyleSelector(); + + void SetDefFontSize(float fFontSize); + void SetUAStyleSheet(std::unique_ptr<CFX_CSSStyleSheet> pSheet); + void UpdateStyleIndex(); + + CFX_RetainPtr<CFX_CSSComputedStyle> CreateComputedStyle( + CFX_CSSComputedStyle* pParentStyle); + + // Note, the dest style has to be an out param because the CXFA_TextParser + // adds non-inherited data from the parent style. Attempting to copy + // internally will fail as you'll lose the non-inherited data. + void ComputeStyle(const std::vector<const CFX_CSSDeclaration*>& declArray, + const CFX_WideString& styleString, + const CFX_WideString& alignString, + CFX_CSSComputedStyle* pDestStyle); + + std::vector<const CFX_CSSDeclaration*> MatchDeclarations( + const CFX_WideString& tagname); + + private: + bool MatchSelector(const CFX_WideString& tagname, CFX_CSSSelector* pSel); + + void AppendInlineStyle(CFX_CSSDeclaration* pDecl, + const CFX_WideString& style); + void ApplyDeclarations( + const std::vector<const CFX_CSSDeclaration*>& declArray, + const CFX_CSSDeclaration* extraDecl, + CFX_CSSComputedStyle* pDestStyle); + void ApplyProperty(CFX_CSSProperty eProperty, + const CFX_RetainPtr<CFX_CSSValue>& pValue, + CFX_CSSComputedStyle* pComputedStyle); + void ExtractValues(const CFX_CSSDeclaration* decl, + std::vector<const CFX_CSSPropertyHolder*>* importants, + std::vector<const CFX_CSSPropertyHolder*>* normals, + std::vector<const CFX_CSSCustomProperty*>* custom); + + bool SetLengthWithPercent(CFX_CSSLength& width, + CFX_CSSPrimitiveType eType, + const CFX_RetainPtr<CFX_CSSValue>& pValue, + float fFontSize); + float ToFontSize(CFX_CSSPropertyValue eValue, float fCurFontSize); + CFX_CSSDisplay ToDisplay(CFX_CSSPropertyValue eValue); + CFX_CSSTextAlign ToTextAlign(CFX_CSSPropertyValue eValue); + uint16_t ToFontWeight(CFX_CSSPropertyValue eValue); + CFX_CSSFontStyle ToFontStyle(CFX_CSSPropertyValue eValue); + CFX_CSSVerticalAlign ToVerticalAlign(CFX_CSSPropertyValue eValue); + uint32_t ToTextDecoration(const CFX_RetainPtr<CFX_CSSValueList>& pList); + CFX_CSSFontVariant ToFontVariant(CFX_CSSPropertyValue eValue); + + float m_fDefFontSize; + std::unique_ptr<CFX_CSSStyleSheet> m_UAStyles; + CFX_CSSRuleCollection m_UARules; +}; + +#endif // CORE_FXCRT_CSS_CFX_CSSSTYLESELECTOR_H_ diff --git a/xfa/fde/css/cfde_cssstylesheet.cpp b/core/fxcrt/css/cfx_cssstylesheet.cpp index 369279853e..9bd25c044f 100644 --- a/xfa/fde/css/cfde_cssstylesheet.cpp +++ b/core/fxcrt/css/cfx_cssstylesheet.cpp @@ -4,83 +4,83 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fde/css/cfde_cssstylesheet.h" +#include "core/fxcrt/css/cfx_cssstylesheet.h" #include <utility> +#include "core/fxcrt/css/cfx_cssdatatable.h" +#include "core/fxcrt/css/cfx_cssdeclaration.h" +#include "core/fxcrt/css/cfx_cssstylerule.h" #include "core/fxcrt/fx_codepage.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fde/css/cfde_cssdeclaration.h" -#include "xfa/fde/css/cfde_cssstylerule.h" -#include "xfa/fde/css/fde_cssdatatable.h" -CFDE_CSSStyleSheet::CFDE_CSSStyleSheet() {} +CFX_CSSStyleSheet::CFX_CSSStyleSheet() {} -CFDE_CSSStyleSheet::~CFDE_CSSStyleSheet() { +CFX_CSSStyleSheet::~CFX_CSSStyleSheet() { Reset(); } -void CFDE_CSSStyleSheet::Reset() { +void CFX_CSSStyleSheet::Reset() { m_RuleArray.clear(); m_StringCache.clear(); } -int32_t CFDE_CSSStyleSheet::CountRules() const { +int32_t CFX_CSSStyleSheet::CountRules() const { return pdfium::CollectionSize<int32_t>(m_RuleArray); } -CFDE_CSSStyleRule* CFDE_CSSStyleSheet::GetRule(int32_t index) const { +CFX_CSSStyleRule* CFX_CSSStyleSheet::GetRule(int32_t index) const { return m_RuleArray[index].get(); } -bool CFDE_CSSStyleSheet::LoadBuffer(const wchar_t* pBuffer, int32_t iBufSize) { +bool CFX_CSSStyleSheet::LoadBuffer(const wchar_t* pBuffer, int32_t iBufSize) { ASSERT(pBuffer); ASSERT(iBufSize > 0); - auto pSyntax = pdfium::MakeUnique<CFDE_CSSSyntaxParser>(pBuffer, iBufSize); + auto pSyntax = pdfium::MakeUnique<CFX_CSSSyntaxParser>(pBuffer, iBufSize); Reset(); - FDE_CSSSyntaxStatus eStatus; + CFX_CSSSyntaxStatus eStatus; do { switch (eStatus = pSyntax->DoSyntaxParse()) { - case FDE_CSSSyntaxStatus::StyleRule: + case CFX_CSSSyntaxStatus::StyleRule: eStatus = LoadStyleRule(pSyntax.get(), &m_RuleArray); break; default: break; } - } while (eStatus >= FDE_CSSSyntaxStatus::None); + } while (eStatus >= CFX_CSSSyntaxStatus::None); m_StringCache.clear(); - return eStatus != FDE_CSSSyntaxStatus::Error; + return eStatus != CFX_CSSSyntaxStatus::Error; } -FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::LoadStyleRule( - CFDE_CSSSyntaxParser* pSyntax, - std::vector<std::unique_ptr<CFDE_CSSStyleRule>>* ruleArray) { - std::vector<std::unique_ptr<CFDE_CSSSelector>> selectors; +CFX_CSSSyntaxStatus CFX_CSSStyleSheet::LoadStyleRule( + CFX_CSSSyntaxParser* pSyntax, + std::vector<std::unique_ptr<CFX_CSSStyleRule>>* ruleArray) { + std::vector<std::unique_ptr<CFX_CSSSelector>> selectors; - CFDE_CSSStyleRule* pStyleRule = nullptr; + CFX_CSSStyleRule* pStyleRule = nullptr; int32_t iValueLen = 0; - const FDE_CSSPropertyTable* propertyTable = nullptr; + const CFX_CSSPropertyTable* propertyTable = nullptr; CFX_WideString wsName; while (1) { switch (pSyntax->DoSyntaxParse()) { - case FDE_CSSSyntaxStatus::Selector: { + case CFX_CSSSyntaxStatus::Selector: { CFX_WideStringC strValue = pSyntax->GetCurrentString(); - auto pSelector = CFDE_CSSSelector::FromString(strValue); + auto pSelector = CFX_CSSSelector::FromString(strValue); if (pSelector) selectors.push_back(std::move(pSelector)); break; } - case FDE_CSSSyntaxStatus::PropertyName: { + case CFX_CSSSyntaxStatus::PropertyName: { CFX_WideStringC strValue = pSyntax->GetCurrentString(); - propertyTable = FDE_GetCSSPropertyByName(strValue); + propertyTable = CFX_GetCSSPropertyByName(strValue); if (!propertyTable) wsName = CFX_WideString(strValue); break; } - case FDE_CSSSyntaxStatus::PropertyValue: { + case CFX_CSSSyntaxStatus::PropertyValue: { if (propertyTable || iValueLen > 0) { CFX_WideStringC strValue = pSyntax->GetCurrentString(); auto* decl = pStyleRule->GetDeclaration(); @@ -94,45 +94,45 @@ FDE_CSSSyntaxStatus CFDE_CSSStyleSheet::LoadStyleRule( } break; } - case FDE_CSSSyntaxStatus::DeclOpen: { + case CFX_CSSSyntaxStatus::DeclOpen: { if (!pStyleRule && !selectors.empty()) { - auto rule = pdfium::MakeUnique<CFDE_CSSStyleRule>(); + auto rule = pdfium::MakeUnique<CFX_CSSStyleRule>(); pStyleRule = rule.get(); pStyleRule->SetSelector(&selectors); ruleArray->push_back(std::move(rule)); } else { SkipRuleSet(pSyntax); - return FDE_CSSSyntaxStatus::None; + return CFX_CSSSyntaxStatus::None; } break; } - case FDE_CSSSyntaxStatus::DeclClose: { + case CFX_CSSSyntaxStatus::DeclClose: { if (pStyleRule && pStyleRule->GetDeclaration()->empty()) { ruleArray->pop_back(); pStyleRule = nullptr; } - return FDE_CSSSyntaxStatus::None; + return CFX_CSSSyntaxStatus::None; } - case FDE_CSSSyntaxStatus::EOS: - return FDE_CSSSyntaxStatus::EOS; - case FDE_CSSSyntaxStatus::Error: + case CFX_CSSSyntaxStatus::EOS: + return CFX_CSSSyntaxStatus::EOS; + case CFX_CSSSyntaxStatus::Error: default: - return FDE_CSSSyntaxStatus::Error; + return CFX_CSSSyntaxStatus::Error; } } } -void CFDE_CSSStyleSheet::SkipRuleSet(CFDE_CSSSyntaxParser* pSyntax) { +void CFX_CSSStyleSheet::SkipRuleSet(CFX_CSSSyntaxParser* pSyntax) { while (1) { switch (pSyntax->DoSyntaxParse()) { - case FDE_CSSSyntaxStatus::Selector: - case FDE_CSSSyntaxStatus::DeclOpen: - case FDE_CSSSyntaxStatus::PropertyName: - case FDE_CSSSyntaxStatus::PropertyValue: + case CFX_CSSSyntaxStatus::Selector: + case CFX_CSSSyntaxStatus::DeclOpen: + case CFX_CSSSyntaxStatus::PropertyName: + case CFX_CSSSyntaxStatus::PropertyValue: break; - case FDE_CSSSyntaxStatus::DeclClose: - case FDE_CSSSyntaxStatus::EOS: - case FDE_CSSSyntaxStatus::Error: + case CFX_CSSSyntaxStatus::DeclClose: + case CFX_CSSSyntaxStatus::EOS: + case CFX_CSSSyntaxStatus::Error: default: return; } diff --git a/core/fxcrt/css/cfx_cssstylesheet.h b/core/fxcrt/css/cfx_cssstylesheet.h new file mode 100644 index 0000000000..3f3a94a84b --- /dev/null +++ b/core/fxcrt/css/cfx_cssstylesheet.h @@ -0,0 +1,40 @@ +// Copyright 2017 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 + +#ifndef CORE_FXCRT_CSS_CFX_CSSSTYLESHEET_H_ +#define CORE_FXCRT_CSS_CFX_CSSSTYLESHEET_H_ + +#include <map> +#include <memory> +#include <vector> + +#include "core/fxcrt/css/cfx_csssyntaxparser.h" +#include "core/fxcrt/fx_string.h" + +class CFX_CSSStyleRule; + +class CFX_CSSStyleSheet { + public: + CFX_CSSStyleSheet(); + ~CFX_CSSStyleSheet(); + + bool LoadBuffer(const wchar_t* pBuffer, int32_t iBufSize); + + int32_t CountRules() const; + CFX_CSSStyleRule* GetRule(int32_t index) const; + + private: + void Reset(); + CFX_CSSSyntaxStatus LoadStyleRule( + CFX_CSSSyntaxParser* pSyntax, + std::vector<std::unique_ptr<CFX_CSSStyleRule>>* ruleArray); + void SkipRuleSet(CFX_CSSSyntaxParser* pSyntax); + + std::vector<std::unique_ptr<CFX_CSSStyleRule>> m_RuleArray; + std::map<uint32_t, wchar_t*> m_StringCache; +}; + +#endif // CORE_FXCRT_CSS_CFX_CSSSTYLESHEET_H_ diff --git a/xfa/fde/css/cfde_cssstylesheet_unittest.cpp b/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp index 0f450e9c3a..4194a70490 100644 --- a/xfa/fde/css/cfde_cssstylesheet_unittest.cpp +++ b/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp @@ -4,24 +4,24 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fde/css/cfde_cssstylesheet.h" +#include "core/fxcrt/css/cfx_cssstylesheet.h" #include <memory> #include <vector> +#include "core/fxcrt/css/cfx_cssdeclaration.h" +#include "core/fxcrt/css/cfx_cssenumvalue.h" +#include "core/fxcrt/css/cfx_cssnumbervalue.h" +#include "core/fxcrt/css/cfx_cssstylerule.h" +#include "core/fxcrt/css/cfx_cssvaluelist.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" -#include "xfa/fde/css/cfde_cssdeclaration.h" -#include "xfa/fde/css/cfde_cssenumvalue.h" -#include "xfa/fde/css/cfde_cssnumbervalue.h" -#include "xfa/fde/css/cfde_cssstylerule.h" -#include "xfa/fde/css/cfde_cssvaluelist.h" -class CFDE_CSSStyleSheetTest : public testing::Test { +class CFX_CSSStyleSheetTest : public testing::Test { public: void SetUp() override { - sheet_ = pdfium::MakeUnique<CFDE_CSSStyleSheet>(); + sheet_ = pdfium::MakeUnique<CFX_CSSStyleSheet>(); decl_ = nullptr; } @@ -35,7 +35,7 @@ class CFDE_CSSStyleSheetTest : public testing::Test { EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); EXPECT_EQ(sheet_->CountRules(), 1); - CFDE_CSSStyleRule* style = sheet_->GetRule(0); + CFX_CSSStyleRule* style = sheet_->GetRule(0); EXPECT_EQ(selectors.size(), style->CountSelectorLists()); for (size_t i = 0; i < selectors.size(); i++) { @@ -47,52 +47,52 @@ class CFDE_CSSStyleSheetTest : public testing::Test { EXPECT_EQ(decl_->PropertyCountForTesting(), decl_count); } - void VerifyFloat(FDE_CSSProperty prop, float val, FDE_CSSNumberType type) { + void VerifyFloat(CFX_CSSProperty prop, float val, CFX_CSSNumberType type) { ASSERT(decl_); bool important; - CFX_RetainPtr<CFDE_CSSValue> v = decl_->GetProperty(prop, &important); - EXPECT_EQ(v->GetType(), FDE_CSSPrimitiveType::Number); - EXPECT_EQ(v.As<CFDE_CSSNumberValue>()->Kind(), type); - EXPECT_EQ(v.As<CFDE_CSSNumberValue>()->Value(), val); + CFX_RetainPtr<CFX_CSSValue> v = decl_->GetProperty(prop, &important); + EXPECT_EQ(v->GetType(), CFX_CSSPrimitiveType::Number); + EXPECT_EQ(v.As<CFX_CSSNumberValue>()->Kind(), type); + EXPECT_EQ(v.As<CFX_CSSNumberValue>()->Value(), val); } - void VerifyEnum(FDE_CSSProperty prop, FDE_CSSPropertyValue val) { + void VerifyEnum(CFX_CSSProperty prop, CFX_CSSPropertyValue val) { ASSERT(decl_); bool important; - CFX_RetainPtr<CFDE_CSSValue> v = decl_->GetProperty(prop, &important); - EXPECT_EQ(v->GetType(), FDE_CSSPrimitiveType::Enum); - EXPECT_EQ(v.As<CFDE_CSSEnumValue>()->Value(), val); + CFX_RetainPtr<CFX_CSSValue> v = decl_->GetProperty(prop, &important); + EXPECT_EQ(v->GetType(), CFX_CSSPrimitiveType::Enum); + EXPECT_EQ(v.As<CFX_CSSEnumValue>()->Value(), val); } - void VerifyList(FDE_CSSProperty prop, - std::vector<FDE_CSSPropertyValue> values) { + void VerifyList(CFX_CSSProperty prop, + std::vector<CFX_CSSPropertyValue> values) { ASSERT(decl_); bool important; - CFX_RetainPtr<CFDE_CSSValueList> list = - decl_->GetProperty(prop, &important).As<CFDE_CSSValueList>(); + CFX_RetainPtr<CFX_CSSValueList> list = + decl_->GetProperty(prop, &important).As<CFX_CSSValueList>(); EXPECT_EQ(list->CountValues(), pdfium::CollectionSize<int32_t>(values)); for (size_t i = 0; i < values.size(); i++) { - CFX_RetainPtr<CFDE_CSSValue> val = list->GetValue(i); - EXPECT_EQ(val->GetType(), FDE_CSSPrimitiveType::Enum); - EXPECT_EQ(val.As<CFDE_CSSEnumValue>()->Value(), values[i]); + CFX_RetainPtr<CFX_CSSValue> val = list->GetValue(i); + EXPECT_EQ(val->GetType(), CFX_CSSPrimitiveType::Enum); + EXPECT_EQ(val.As<CFX_CSSEnumValue>()->Value(), values[i]); } } - std::unique_ptr<CFDE_CSSStyleSheet> sheet_; - CFDE_CSSDeclaration* decl_; + std::unique_ptr<CFX_CSSStyleSheet> sheet_; + CFX_CSSDeclaration* decl_; }; -TEST_F(CFDE_CSSStyleSheetTest, ParseMultipleSelectors) { +TEST_F(CFX_CSSStyleSheetTest, ParseMultipleSelectors) { const wchar_t* buf = L"a { border: 10px; }\nb { text-decoration: underline; }"; EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); EXPECT_EQ(2, sheet_->CountRules()); - CFDE_CSSStyleRule* style = sheet_->GetRule(0); + CFX_CSSStyleRule* style = sheet_->GetRule(0); EXPECT_EQ(1UL, style->CountSelectorLists()); bool found_selector = false; @@ -108,13 +108,13 @@ TEST_F(CFDE_CSSStyleSheetTest, ParseMultipleSelectors) { decl_ = style->GetDeclaration(); EXPECT_EQ(4UL, decl_->PropertyCountForTesting()); - VerifyFloat(FDE_CSSProperty::BorderLeftWidth, 10.0, - FDE_CSSNumberType::Pixels); - VerifyFloat(FDE_CSSProperty::BorderRightWidth, 10.0, - FDE_CSSNumberType::Pixels); - VerifyFloat(FDE_CSSProperty::BorderTopWidth, 10.0, FDE_CSSNumberType::Pixels); - VerifyFloat(FDE_CSSProperty::BorderBottomWidth, 10.0, - FDE_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderLeftWidth, 10.0, + CFX_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderRightWidth, 10.0, + CFX_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderTopWidth, 10.0, CFX_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderBottomWidth, 10.0, + CFX_CSSNumberType::Pixels); style = sheet_->GetRule(1); EXPECT_EQ(1UL, style->CountSelectorLists()); @@ -131,16 +131,16 @@ TEST_F(CFDE_CSSStyleSheetTest, ParseMultipleSelectors) { decl_ = style->GetDeclaration(); EXPECT_EQ(1UL, decl_->PropertyCountForTesting()); - VerifyList(FDE_CSSProperty::TextDecoration, - {FDE_CSSPropertyValue::Underline}); + VerifyList(CFX_CSSProperty::TextDecoration, + {CFX_CSSPropertyValue::Underline}); } -TEST_F(CFDE_CSSStyleSheetTest, ParseChildSelectors) { +TEST_F(CFX_CSSStyleSheetTest, ParseChildSelectors) { const wchar_t* buf = L"a b c { border: 10px; }"; EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); EXPECT_EQ(1, sheet_->CountRules()); - CFDE_CSSStyleRule* style = sheet_->GetRule(0); + CFX_CSSStyleRule* style = sheet_->GetRule(0); EXPECT_EQ(1UL, style->CountSelectorLists()); auto* sel = style->GetSelectorList(0); @@ -161,16 +161,16 @@ TEST_F(CFDE_CSSStyleSheetTest, ParseChildSelectors) { decl_ = style->GetDeclaration(); EXPECT_EQ(4UL, decl_->PropertyCountForTesting()); - VerifyFloat(FDE_CSSProperty::BorderLeftWidth, 10.0, - FDE_CSSNumberType::Pixels); - VerifyFloat(FDE_CSSProperty::BorderRightWidth, 10.0, - FDE_CSSNumberType::Pixels); - VerifyFloat(FDE_CSSProperty::BorderTopWidth, 10.0, FDE_CSSNumberType::Pixels); - VerifyFloat(FDE_CSSProperty::BorderBottomWidth, 10.0, - FDE_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderLeftWidth, 10.0, + CFX_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderRightWidth, 10.0, + CFX_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderTopWidth, 10.0, CFX_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderBottomWidth, 10.0, + CFX_CSSNumberType::Pixels); } -TEST_F(CFDE_CSSStyleSheetTest, ParseUnhandledSelectors) { +TEST_F(CFX_CSSStyleSheetTest, ParseUnhandledSelectors) { const wchar_t* buf = L"a > b { padding: 0; }"; EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); EXPECT_EQ(0, sheet_->CountRules()); @@ -188,52 +188,52 @@ TEST_F(CFDE_CSSStyleSheetTest, ParseUnhandledSelectors) { EXPECT_EQ(0, sheet_->CountRules()); } -TEST_F(CFDE_CSSStyleSheetTest, ParseMultipleSelectorsCombined) { +TEST_F(CFX_CSSStyleSheetTest, ParseMultipleSelectorsCombined) { LoadAndVerifyDecl(L"a, b, c { border: 5px; }", {L"a", L"b", L"c"}, 4); } -TEST_F(CFDE_CSSStyleSheetTest, ParseBorder) { +TEST_F(CFX_CSSStyleSheetTest, ParseBorder) { LoadAndVerifyDecl(L"a { border: 5px; }", {L"a"}, 4); - VerifyFloat(FDE_CSSProperty::BorderLeftWidth, 5.0, FDE_CSSNumberType::Pixels); - VerifyFloat(FDE_CSSProperty::BorderRightWidth, 5.0, - FDE_CSSNumberType::Pixels); - VerifyFloat(FDE_CSSProperty::BorderTopWidth, 5.0, FDE_CSSNumberType::Pixels); - VerifyFloat(FDE_CSSProperty::BorderBottomWidth, 5.0, - FDE_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderLeftWidth, 5.0, CFX_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderRightWidth, 5.0, + CFX_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderTopWidth, 5.0, CFX_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderBottomWidth, 5.0, + CFX_CSSNumberType::Pixels); } -TEST_F(CFDE_CSSStyleSheetTest, ParseBorderFull) { +TEST_F(CFX_CSSStyleSheetTest, ParseBorderFull) { LoadAndVerifyDecl(L"a { border: 5px solid red; }", {L"a"}, 4); - VerifyFloat(FDE_CSSProperty::BorderLeftWidth, 5.0, FDE_CSSNumberType::Pixels); - VerifyFloat(FDE_CSSProperty::BorderRightWidth, 5.0, - FDE_CSSNumberType::Pixels); - VerifyFloat(FDE_CSSProperty::BorderTopWidth, 5.0, FDE_CSSNumberType::Pixels); - VerifyFloat(FDE_CSSProperty::BorderBottomWidth, 5.0, - FDE_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderLeftWidth, 5.0, CFX_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderRightWidth, 5.0, + CFX_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderTopWidth, 5.0, CFX_CSSNumberType::Pixels); + VerifyFloat(CFX_CSSProperty::BorderBottomWidth, 5.0, + CFX_CSSNumberType::Pixels); } -TEST_F(CFDE_CSSStyleSheetTest, ParseBorderLeft) { +TEST_F(CFX_CSSStyleSheetTest, ParseBorderLeft) { LoadAndVerifyDecl(L"a { border-left: 2.5pc; }", {L"a"}, 1); - VerifyFloat(FDE_CSSProperty::BorderLeftWidth, 2.5, FDE_CSSNumberType::Picas); + VerifyFloat(CFX_CSSProperty::BorderLeftWidth, 2.5, CFX_CSSNumberType::Picas); } -TEST_F(CFDE_CSSStyleSheetTest, ParseBorderLeftThick) { +TEST_F(CFX_CSSStyleSheetTest, ParseBorderLeftThick) { LoadAndVerifyDecl(L"a { border-left: thick; }", {L"a"}, 1); - VerifyEnum(FDE_CSSProperty::BorderLeftWidth, FDE_CSSPropertyValue::Thick); + VerifyEnum(CFX_CSSProperty::BorderLeftWidth, CFX_CSSPropertyValue::Thick); } -TEST_F(CFDE_CSSStyleSheetTest, ParseBorderRight) { +TEST_F(CFX_CSSStyleSheetTest, ParseBorderRight) { LoadAndVerifyDecl(L"a { border-right: 2.5pc; }", {L"a"}, 1); - VerifyFloat(FDE_CSSProperty::BorderRightWidth, 2.5, FDE_CSSNumberType::Picas); + VerifyFloat(CFX_CSSProperty::BorderRightWidth, 2.5, CFX_CSSNumberType::Picas); } -TEST_F(CFDE_CSSStyleSheetTest, ParseBorderTop) { +TEST_F(CFX_CSSStyleSheetTest, ParseBorderTop) { LoadAndVerifyDecl(L"a { border-top: 2.5pc; }", {L"a"}, 1); - VerifyFloat(FDE_CSSProperty::BorderTopWidth, 2.5, FDE_CSSNumberType::Picas); + VerifyFloat(CFX_CSSProperty::BorderTopWidth, 2.5, CFX_CSSNumberType::Picas); } -TEST_F(CFDE_CSSStyleSheetTest, ParseBorderBottom) { +TEST_F(CFX_CSSStyleSheetTest, ParseBorderBottom) { LoadAndVerifyDecl(L"a { border-bottom: 2.5pc; }", {L"a"}, 1); - VerifyFloat(FDE_CSSProperty::BorderBottomWidth, 2.5, - FDE_CSSNumberType::Picas); + VerifyFloat(CFX_CSSProperty::BorderBottomWidth, 2.5, + CFX_CSSNumberType::Picas); } diff --git a/xfa/fde/css/cfde_csssyntaxparser.cpp b/core/fxcrt/css/cfx_csssyntaxparser.cpp index 51d99f1992..c8082e87fb 100644 --- a/xfa/fde/css/cfde_csssyntaxparser.cpp +++ b/core/fxcrt/css/cfx_csssyntaxparser.cpp @@ -4,15 +4,15 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fde/css/cfde_csssyntaxparser.h" +#include "core/fxcrt/css/cfx_csssyntaxparser.h" #include <algorithm> +#include "core/fxcrt/css/cfx_cssdatatable.h" +#include "core/fxcrt/css/cfx_cssdeclaration.h" #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/fx_extension.h" #include "third_party/base/logging.h" -#include "xfa/fde/css/cfde_cssdeclaration.h" -#include "xfa/fde/css/fde_cssdatatable.h" namespace { @@ -22,91 +22,91 @@ bool IsSelectorStart(wchar_t wch) { } // namespace -CFDE_CSSSyntaxParser::CFDE_CSSSyntaxParser(const wchar_t* pBuffer, - int32_t iBufferSize) - : CFDE_CSSSyntaxParser(pBuffer, iBufferSize, 32, false) {} +CFX_CSSSyntaxParser::CFX_CSSSyntaxParser(const wchar_t* pBuffer, + int32_t iBufferSize) + : CFX_CSSSyntaxParser(pBuffer, iBufferSize, 32, false) {} -CFDE_CSSSyntaxParser::CFDE_CSSSyntaxParser(const wchar_t* pBuffer, - int32_t iBufferSize, - int32_t iTextDatSize, - bool bOnlyDeclaration) +CFX_CSSSyntaxParser::CFX_CSSSyntaxParser(const wchar_t* pBuffer, + int32_t iBufferSize, + int32_t iTextDatSize, + bool bOnlyDeclaration) : m_iTextDataLen(0), m_dwCheck(0xFFFFFFFF), - m_eStatus(FDE_CSSSyntaxStatus::None) { + m_eStatus(CFX_CSSSyntaxStatus::None) { ASSERT(pBuffer && iBufferSize > 0 && iTextDatSize > 0); - m_eMode = bOnlyDeclaration ? FDE_CSSSyntaxMode::PropertyName - : FDE_CSSSyntaxMode::RuleSet; + m_eMode = bOnlyDeclaration ? CFX_CSSSyntaxMode::PropertyName + : CFX_CSSSyntaxMode::RuleSet; m_TextData.InitWithSize(iTextDatSize); m_TextPlane.AttachBuffer(pBuffer, iBufferSize); } -CFDE_CSSSyntaxParser::~CFDE_CSSSyntaxParser() {} +CFX_CSSSyntaxParser::~CFX_CSSSyntaxParser() {} -FDE_CSSSyntaxStatus CFDE_CSSSyntaxParser::DoSyntaxParse() { - while (m_eStatus >= FDE_CSSSyntaxStatus::None) { +CFX_CSSSyntaxStatus CFX_CSSSyntaxParser::DoSyntaxParse() { + while (m_eStatus >= CFX_CSSSyntaxStatus::None) { if (m_TextPlane.IsEOF()) { - if (m_eMode == FDE_CSSSyntaxMode::PropertyValue && + if (m_eMode == CFX_CSSSyntaxMode::PropertyValue && m_TextData.GetLength() > 0) { SaveTextData(); - m_eStatus = FDE_CSSSyntaxStatus::PropertyValue; + m_eStatus = CFX_CSSSyntaxStatus::PropertyValue; return m_eStatus; } - m_eStatus = FDE_CSSSyntaxStatus::EOS; + m_eStatus = CFX_CSSSyntaxStatus::EOS; return m_eStatus; } wchar_t wch; while (!m_TextPlane.IsEOF()) { wch = m_TextPlane.GetChar(); switch (m_eMode) { - case FDE_CSSSyntaxMode::RuleSet: + case CFX_CSSSyntaxMode::RuleSet: switch (wch) { case '}': m_TextPlane.MoveNext(); if (RestoreMode()) - return FDE_CSSSyntaxStatus::DeclClose; + return CFX_CSSSyntaxStatus::DeclClose; - m_eStatus = FDE_CSSSyntaxStatus::Error; + m_eStatus = CFX_CSSSyntaxStatus::Error; return m_eStatus; case '/': if (m_TextPlane.GetNextChar() == '*') { m_ModeStack.push(m_eMode); - SwitchMode(FDE_CSSSyntaxMode::Comment); + SwitchMode(CFX_CSSSyntaxMode::Comment); break; } default: if (wch <= ' ') { m_TextPlane.MoveNext(); } else if (IsSelectorStart(wch)) { - SwitchMode(FDE_CSSSyntaxMode::Selector); - return FDE_CSSSyntaxStatus::StyleRule; + SwitchMode(CFX_CSSSyntaxMode::Selector); + return CFX_CSSSyntaxStatus::StyleRule; } else { - m_eStatus = FDE_CSSSyntaxStatus::Error; + m_eStatus = CFX_CSSSyntaxStatus::Error; return m_eStatus; } break; } break; - case FDE_CSSSyntaxMode::Selector: + case CFX_CSSSyntaxMode::Selector: switch (wch) { case ',': m_TextPlane.MoveNext(); - SwitchMode(FDE_CSSSyntaxMode::Selector); + SwitchMode(CFX_CSSSyntaxMode::Selector); if (m_iTextDataLen > 0) - return FDE_CSSSyntaxStatus::Selector; + return CFX_CSSSyntaxStatus::Selector; break; case '{': if (m_TextData.GetLength() > 0) { SaveTextData(); - return FDE_CSSSyntaxStatus::Selector; + return CFX_CSSSyntaxStatus::Selector; } m_TextPlane.MoveNext(); - m_ModeStack.push(FDE_CSSSyntaxMode::RuleSet); - SwitchMode(FDE_CSSSyntaxMode::PropertyName); - return FDE_CSSSyntaxStatus::DeclOpen; + m_ModeStack.push(CFX_CSSSyntaxMode::RuleSet); + SwitchMode(CFX_CSSSyntaxMode::PropertyName); + return CFX_CSSSyntaxStatus::DeclOpen; case '/': if (m_TextPlane.GetNextChar() == '*') { if (SwitchToComment() > 0) - return FDE_CSSSyntaxStatus::Selector; + return CFX_CSSSyntaxStatus::Selector; break; } default: @@ -114,23 +114,23 @@ FDE_CSSSyntaxStatus CFDE_CSSSyntaxParser::DoSyntaxParse() { break; } break; - case FDE_CSSSyntaxMode::PropertyName: + case CFX_CSSSyntaxMode::PropertyName: switch (wch) { case ':': m_TextPlane.MoveNext(); - SwitchMode(FDE_CSSSyntaxMode::PropertyValue); - return FDE_CSSSyntaxStatus::PropertyName; + SwitchMode(CFX_CSSSyntaxMode::PropertyValue); + return CFX_CSSSyntaxStatus::PropertyName; case '}': m_TextPlane.MoveNext(); if (RestoreMode()) - return FDE_CSSSyntaxStatus::DeclClose; + return CFX_CSSSyntaxStatus::DeclClose; - m_eStatus = FDE_CSSSyntaxStatus::Error; + m_eStatus = CFX_CSSSyntaxStatus::Error; return m_eStatus; case '/': if (m_TextPlane.GetNextChar() == '*') { if (SwitchToComment() > 0) - return FDE_CSSSyntaxStatus::PropertyName; + return CFX_CSSSyntaxStatus::PropertyName; break; } default: @@ -138,17 +138,17 @@ FDE_CSSSyntaxStatus CFDE_CSSSyntaxParser::DoSyntaxParse() { break; } break; - case FDE_CSSSyntaxMode::PropertyValue: + case CFX_CSSSyntaxMode::PropertyValue: switch (wch) { case ';': m_TextPlane.MoveNext(); case '}': - SwitchMode(FDE_CSSSyntaxMode::PropertyName); - return FDE_CSSSyntaxStatus::PropertyValue; + SwitchMode(CFX_CSSSyntaxMode::PropertyName); + return CFX_CSSSyntaxStatus::PropertyValue; case '/': if (m_TextPlane.GetNextChar() == '*') { if (SwitchToComment() > 0) - return FDE_CSSSyntaxStatus::PropertyValue; + return CFX_CSSSyntaxStatus::PropertyValue; break; } default: @@ -156,7 +156,7 @@ FDE_CSSSyntaxStatus CFDE_CSSSyntaxParser::DoSyntaxParse() { break; } break; - case FDE_CSSSyntaxMode::Comment: + case CFX_CSSSyntaxMode::Comment: if (wch == '/' && m_TextData.GetLength() > 0 && m_TextData.GetBuffer()[m_TextData.GetLength() - 1] == '*') { RestoreMode(); @@ -165,9 +165,9 @@ FDE_CSSSyntaxStatus CFDE_CSSSyntaxParser::DoSyntaxParse() { } m_TextPlane.MoveNext(); break; - case FDE_CSSSyntaxMode::UnknownRule: + case CFX_CSSSyntaxMode::UnknownRule: if (wch == ';') - SwitchMode(FDE_CSSSyntaxMode::RuleSet); + SwitchMode(CFX_CSSSyntaxMode::RuleSet); m_TextPlane.MoveNext(); break; default: @@ -179,15 +179,15 @@ FDE_CSSSyntaxStatus CFDE_CSSSyntaxParser::DoSyntaxParse() { return m_eStatus; } -bool CFDE_CSSSyntaxParser::IsImportEnabled() const { - if ((m_dwCheck & FDE_CSSSYNTAXCHECK_AllowImport) == 0) +bool CFX_CSSSyntaxParser::IsImportEnabled() const { + if ((m_dwCheck & CFX_CSSSYNTAXCHECK_AllowImport) == 0) return false; if (m_ModeStack.size() > 1) return false; return true; } -bool CFDE_CSSSyntaxParser::AppendChar(wchar_t wch) { +bool CFX_CSSSyntaxParser::AppendChar(wchar_t wch) { m_TextPlane.MoveNext(); if (m_TextData.GetLength() > 0 || wch > ' ') { m_TextData.AppendChar(wch); @@ -196,25 +196,25 @@ bool CFDE_CSSSyntaxParser::AppendChar(wchar_t wch) { return false; } -int32_t CFDE_CSSSyntaxParser::SaveTextData() { +int32_t CFX_CSSSyntaxParser::SaveTextData() { m_iTextDataLen = m_TextData.TrimEnd(); m_TextData.Clear(); return m_iTextDataLen; } -void CFDE_CSSSyntaxParser::SwitchMode(FDE_CSSSyntaxMode eMode) { +void CFX_CSSSyntaxParser::SwitchMode(CFX_CSSSyntaxMode eMode) { m_eMode = eMode; SaveTextData(); } -int32_t CFDE_CSSSyntaxParser::SwitchToComment() { +int32_t CFX_CSSSyntaxParser::SwitchToComment() { int32_t iLength = m_TextData.GetLength(); m_ModeStack.push(m_eMode); - SwitchMode(FDE_CSSSyntaxMode::Comment); + SwitchMode(CFX_CSSSyntaxMode::Comment); return iLength; } -bool CFDE_CSSSyntaxParser::RestoreMode() { +bool CFX_CSSSyntaxParser::RestoreMode() { if (m_ModeStack.empty()) return false; @@ -223,6 +223,6 @@ bool CFDE_CSSSyntaxParser::RestoreMode() { return true; } -CFX_WideStringC CFDE_CSSSyntaxParser::GetCurrentString() const { +CFX_WideStringC CFX_CSSSyntaxParser::GetCurrentString() const { return CFX_WideStringC(m_TextData.GetBuffer(), m_iTextDataLen); } diff --git a/core/fxcrt/css/cfx_csssyntaxparser.h b/core/fxcrt/css/cfx_csssyntaxparser.h new file mode 100644 index 0000000000..9ddedfe4a7 --- /dev/null +++ b/core/fxcrt/css/cfx_csssyntaxparser.h @@ -0,0 +1,75 @@ +// Copyright 2017 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 + +#ifndef CORE_FXCRT_CSS_CFX_CSSSYNTAXPARSER_H_ +#define CORE_FXCRT_CSS_CFX_CSSSYNTAXPARSER_H_ + +#include <stack> + +#include "core/fxcrt/css/cfx_cssexttextbuf.h" +#include "core/fxcrt/css/cfx_csstextbuf.h" +#include "core/fxcrt/fx_string.h" + +#define CFX_CSSSYNTAXCHECK_AllowCharset 1 +#define CFX_CSSSYNTAXCHECK_AllowImport 2 + +enum class CFX_CSSSyntaxMode { + RuleSet, + Comment, + UnknownRule, + Selector, + PropertyName, + PropertyValue, +}; + +enum class CFX_CSSSyntaxStatus : uint8_t { + Error, + EOS, + None, + StyleRule, + Selector, + DeclOpen, + DeclClose, + PropertyName, + PropertyValue, +}; + +class CFX_CSSSyntaxParser { + public: + CFX_CSSSyntaxParser(const wchar_t* pBuffer, int32_t iBufferSize); + CFX_CSSSyntaxParser(const wchar_t* pBuffer, + int32_t iBufferSize, + int32_t iTextDatSize, + bool bOnlyDeclaration); + ~CFX_CSSSyntaxParser(); + + CFX_CSSSyntaxStatus DoSyntaxParse(); + CFX_WideStringC GetCurrentString() const; + + protected: + void SwitchMode(CFX_CSSSyntaxMode eMode); + int32_t SwitchToComment(); + + bool RestoreMode(); + bool AppendChar(wchar_t wch); + int32_t SaveTextData(); + bool IsCharsetEnabled() const { + return (m_dwCheck & CFX_CSSSYNTAXCHECK_AllowCharset) != 0; + } + void DisableCharset() { m_dwCheck = CFX_CSSSYNTAXCHECK_AllowImport; } + bool IsImportEnabled() const; + void DisableImport() { m_dwCheck = 0; } + + CFX_CSSTextBuf m_TextData; + CFX_CSSExtTextBuf m_TextPlane; + int32_t m_iTextDataLen; + uint32_t m_dwCheck; + CFX_CSSSyntaxMode m_eMode; + CFX_CSSSyntaxStatus m_eStatus; + std::stack<CFX_CSSSyntaxMode> m_ModeStack; +}; + +#endif // CORE_FXCRT_CSS_CFX_CSSSYNTAXPARSER_H_ diff --git a/xfa/fde/css/cfde_csstextbuf.cpp b/core/fxcrt/css/cfx_csstextbuf.cpp index 0d8ba2d6ce..f2f3b94419 100644 --- a/xfa/fde/css/cfde_csstextbuf.cpp +++ b/core/fxcrt/css/cfx_csstextbuf.cpp @@ -4,38 +4,38 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fde/css/cfde_csstextbuf.h" +#include "core/fxcrt/css/cfx_csstextbuf.h" #include "core/fxcrt/fx_memory.h" -CFDE_CSSTextBuf::CFDE_CSSTextBuf() +CFX_CSSTextBuf::CFX_CSSTextBuf() : m_pBuffer(nullptr), m_iBufLen(0), m_iDatLen(0) {} -CFDE_CSSTextBuf::~CFDE_CSSTextBuf() { +CFX_CSSTextBuf::~CFX_CSSTextBuf() { FX_Free(m_pBuffer); m_pBuffer = nullptr; m_iDatLen = m_iBufLen; } -void CFDE_CSSTextBuf::InitWithSize(int32_t iAllocSize) { +void CFX_CSSTextBuf::InitWithSize(int32_t iAllocSize) { ExpandBuf(iAllocSize); } -void CFDE_CSSTextBuf::AppendChar(wchar_t wch) { +void CFX_CSSTextBuf::AppendChar(wchar_t wch) { if (m_iDatLen >= m_iBufLen) ExpandBuf(m_iBufLen * 2); m_pBuffer[m_iDatLen++] = wch; } -int32_t CFDE_CSSTextBuf::TrimEnd() { +int32_t CFX_CSSTextBuf::TrimEnd() { while (m_iDatLen > 0 && m_pBuffer[m_iDatLen - 1] <= ' ') --m_iDatLen; AppendChar(0); return --m_iDatLen; } -void CFDE_CSSTextBuf::ExpandBuf(int32_t iDesiredSize) { +void CFX_CSSTextBuf::ExpandBuf(int32_t iDesiredSize) { ASSERT(iDesiredSize > 0); if (m_pBuffer && m_iBufLen == iDesiredSize) return; diff --git a/xfa/fde/css/cfde_csstextbuf.h b/core/fxcrt/css/cfx_csstextbuf.h index b2c17c95f8..e1b9c64e14 100644 --- a/xfa/fde/css/cfde_csstextbuf.h +++ b/core/fxcrt/css/cfx_csstextbuf.h @@ -4,15 +4,15 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FDE_CSS_CFDE_CSSTEXTBUF_H_ -#define XFA_FDE_CSS_CFDE_CSSTEXTBUF_H_ +#ifndef CORE_FXCRT_CSS_CFX_CSSTEXTBUF_H_ +#define CORE_FXCRT_CSS_CFX_CSSTEXTBUF_H_ #include "core/fxcrt/fx_system.h" -class CFDE_CSSTextBuf { +class CFX_CSSTextBuf { public: - CFDE_CSSTextBuf(); - ~CFDE_CSSTextBuf(); + CFX_CSSTextBuf(); + ~CFX_CSSTextBuf(); void InitWithSize(int32_t iAllocSize); void AppendChar(wchar_t wch); @@ -32,4 +32,4 @@ class CFDE_CSSTextBuf { int32_t m_iDatLen; }; -#endif // XFA_FDE_CSS_CFDE_CSSTEXTBUF_H_ +#endif // CORE_FXCRT_CSS_CFX_CSSTEXTBUF_H_ diff --git a/xfa/fde/css/cfde_cssvalue.cpp b/core/fxcrt/css/cfx_cssvalue.cpp index ef7029f9a5..a55fc742b0 100644 --- a/xfa/fde/css/cfde_cssvalue.cpp +++ b/core/fxcrt/css/cfx_cssvalue.cpp @@ -4,6 +4,6 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fde/css/cfde_cssvalue.h" +#include "core/fxcrt/css/cfx_cssvalue.h" -CFDE_CSSValue::CFDE_CSSValue(FDE_CSSPrimitiveType type) : m_value(type) {} +CFX_CSSValue::CFX_CSSValue(CFX_CSSPrimitiveType type) : m_value(type) {} diff --git a/core/fxcrt/css/cfx_cssvalue.h b/core/fxcrt/css/cfx_cssvalue.h new file mode 100644 index 0000000000..4f11e4e0d7 --- /dev/null +++ b/core/fxcrt/css/cfx_cssvalue.h @@ -0,0 +1,23 @@ +// Copyright 2017 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 + +#ifndef CORE_FXCRT_CSS_CFX_CSSVALUE_H_ +#define CORE_FXCRT_CSS_CFX_CSSVALUE_H_ + +#include "core/fxcrt/css/cfx_css.h" + +class CFX_CSSValue : public CFX_Retainable { + public: + CFX_CSSPrimitiveType GetType() const { return m_value; } + + protected: + explicit CFX_CSSValue(CFX_CSSPrimitiveType type); + + private: + CFX_CSSPrimitiveType m_value; +}; + +#endif // CORE_FXCRT_CSS_CFX_CSSVALUE_H_ diff --git a/core/fxcrt/css/cfx_cssvaluelist.cpp b/core/fxcrt/css/cfx_cssvaluelist.cpp new file mode 100644 index 0000000000..18b5d82054 --- /dev/null +++ b/core/fxcrt/css/cfx_cssvaluelist.cpp @@ -0,0 +1,25 @@ +// Copyright 2017 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 "core/fxcrt/css/cfx_cssvaluelist.h" + +#include <utility> + +#include "core/fxcrt/css/cfx_css.h" + +CFX_CSSValueList::CFX_CSSValueList( + std::vector<CFX_RetainPtr<CFX_CSSValue>>& list) + : CFX_CSSValue(CFX_CSSPrimitiveType::List), m_ppList(std::move(list)) {} + +CFX_CSSValueList::~CFX_CSSValueList() {} + +int32_t CFX_CSSValueList::CountValues() const { + return m_ppList.size(); +} + +CFX_RetainPtr<CFX_CSSValue> CFX_CSSValueList::GetValue(int32_t index) const { + return m_ppList[index]; +} diff --git a/core/fxcrt/css/cfx_cssvaluelist.h b/core/fxcrt/css/cfx_cssvaluelist.h new file mode 100644 index 0000000000..475abf4066 --- /dev/null +++ b/core/fxcrt/css/cfx_cssvaluelist.h @@ -0,0 +1,26 @@ +// Copyright 2017 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 + +#ifndef CORE_FXCRT_CSS_CFX_CSSVALUELIST_H_ +#define CORE_FXCRT_CSS_CFX_CSSVALUELIST_H_ + +#include <vector> + +#include "core/fxcrt/css/cfx_cssvalue.h" + +class CFX_CSSValueList : public CFX_CSSValue { + public: + explicit CFX_CSSValueList(std::vector<CFX_RetainPtr<CFX_CSSValue>>& list); + ~CFX_CSSValueList() override; + + int32_t CountValues() const; + CFX_RetainPtr<CFX_CSSValue> GetValue(int32_t index) const; + + protected: + std::vector<CFX_RetainPtr<CFX_CSSValue>> m_ppList; +}; + +#endif // CORE_FXCRT_CSS_CFX_CSSVALUELIST_H_ diff --git a/xfa/fde/css/cfde_cssvaluelistparser.cpp b/core/fxcrt/css/cfx_cssvaluelistparser.cpp index 79a79818dc..05204e5621 100644 --- a/xfa/fde/css/cfde_cssvaluelistparser.cpp +++ b/core/fxcrt/css/cfx_cssvaluelistparser.cpp @@ -4,62 +4,62 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fde/css/cfde_cssvaluelistparser.h" +#include "core/fxcrt/css/cfx_cssvaluelistparser.h" #include "core/fxcrt/fx_extension.h" -CFDE_CSSValueListParser::CFDE_CSSValueListParser(const wchar_t* psz, - int32_t iLen, - wchar_t separator) +CFX_CSSValueListParser::CFX_CSSValueListParser(const wchar_t* psz, + int32_t iLen, + wchar_t separator) : m_Separator(separator), m_pCur(psz), m_pEnd(psz + iLen) { ASSERT(psz && iLen > 0); } -bool CFDE_CSSValueListParser::NextValue(FDE_CSSPrimitiveType& eType, - const wchar_t*& pStart, - int32_t& iLength) { +bool CFX_CSSValueListParser::NextValue(CFX_CSSPrimitiveType& eType, + const wchar_t*& pStart, + int32_t& iLength) { while (m_pCur < m_pEnd && (*m_pCur <= ' ' || *m_pCur == m_Separator)) ++m_pCur; if (m_pCur >= m_pEnd) return false; - eType = FDE_CSSPrimitiveType::Unknown; + eType = CFX_CSSPrimitiveType::Unknown; pStart = m_pCur; iLength = 0; wchar_t wch = *m_pCur; if (wch == '#') { iLength = SkipTo(' ', false, false); if (iLength == 4 || iLength == 7) - eType = FDE_CSSPrimitiveType::RGB; + eType = CFX_CSSPrimitiveType::RGB; } else if (std::iswdigit(wch) || wch == '.' || wch == '-' || wch == '+') { while (m_pCur < m_pEnd && (*m_pCur > ' ' && *m_pCur != m_Separator)) ++m_pCur; iLength = m_pCur - pStart; - eType = FDE_CSSPrimitiveType::Number; + eType = CFX_CSSPrimitiveType::Number; } else if (wch == '\"' || wch == '\'') { pStart++; m_pCur++; iLength = SkipTo(wch, false, false); m_pCur++; - eType = FDE_CSSPrimitiveType::String; + eType = CFX_CSSPrimitiveType::String; } else if (m_pEnd - m_pCur > 5 && m_pCur[3] == '(') { if (FXSYS_wcsnicmp(L"rgb", m_pCur, 3) == 0) { iLength = SkipTo(')', false, false) + 1; m_pCur++; - eType = FDE_CSSPrimitiveType::RGB; + eType = CFX_CSSPrimitiveType::RGB; } } else { iLength = SkipTo(m_Separator, true, true); - eType = FDE_CSSPrimitiveType::String; + eType = CFX_CSSPrimitiveType::String; } return m_pCur <= m_pEnd && iLength > 0; } -int32_t CFDE_CSSValueListParser::SkipTo(wchar_t wch, - bool breakOnSpace, - bool matchBrackets) { +int32_t CFX_CSSValueListParser::SkipTo(wchar_t wch, + bool breakOnSpace, + bool matchBrackets) { const wchar_t* pStart = m_pCur; int32_t bracketCount = 0; while (m_pCur < m_pEnd && *m_pCur != wch) { diff --git a/xfa/fde/css/cfde_cssvaluelistparser.h b/core/fxcrt/css/cfx_cssvaluelistparser.h index e41ee5c313..514db9e192 100644 --- a/xfa/fde/css/cfde_cssvaluelistparser.h +++ b/core/fxcrt/css/cfx_cssvaluelistparser.h @@ -4,17 +4,17 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef XFA_FDE_CSS_CFDE_CSSVALUELISTPARSER_H_ -#define XFA_FDE_CSS_CFDE_CSSVALUELISTPARSER_H_ +#ifndef CORE_FXCRT_CSS_CFX_CSSVALUELISTPARSER_H_ +#define CORE_FXCRT_CSS_CFX_CSSVALUELISTPARSER_H_ +#include "core/fxcrt/css/cfx_css.h" #include "core/fxcrt/fx_system.h" -#include "xfa/fde/css/fde_css.h" -class CFDE_CSSValueListParser { +class CFX_CSSValueListParser { public: - CFDE_CSSValueListParser(const wchar_t* psz, int32_t iLen, wchar_t separator); + CFX_CSSValueListParser(const wchar_t* psz, int32_t iLen, wchar_t separator); - bool NextValue(FDE_CSSPrimitiveType& eType, + bool NextValue(CFX_CSSPrimitiveType& eType, const wchar_t*& pStart, int32_t& iLength); @@ -27,4 +27,4 @@ class CFDE_CSSValueListParser { const wchar_t* m_pEnd; }; -#endif // XFA_FDE_CSS_CFDE_CSSVALUELISTPARSER_H_ +#endif // CORE_FXCRT_CSS_CFX_CSSVALUELISTPARSER_H_ diff --git a/xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp b/core/fxcrt/css/cfx_cssvaluelistparser_unittest.cpp index 53a0657e12..510c96251d 100644 --- a/xfa/fde/css/cfde_cssvaluelistparser_unittest.cpp +++ b/core/fxcrt/css/cfx_cssvaluelistparser_unittest.cpp @@ -4,140 +4,138 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "xfa/fde/css/cfde_cssvaluelistparser.h" +#include "core/fxcrt/css/cfx_cssvaluelistparser.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" #include "third_party/base/ptr_util.h" -TEST(CFDE_CSSValueListParserTest, rgb_short) { - FDE_CSSPrimitiveType type; +TEST(CFX_CSSValueListParserTest, rgb_short) { + CFX_CSSPrimitiveType type; const wchar_t* start; int32_t len; - auto parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"#abc", 4, L' '); + auto parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"#abc", 4, L' '); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::RGB, type); + EXPECT_EQ(CFX_CSSPrimitiveType::RGB, type); EXPECT_EQ(L"#abc", CFX_WideString(start, len)); EXPECT_FALSE(parser->NextValue(type, start, len)); - parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"#abcdef", 7, L' '); + parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"#abcdef", 7, L' '); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::RGB, type); + EXPECT_EQ(CFX_CSSPrimitiveType::RGB, type); EXPECT_EQ(L"#abcdef", CFX_WideString(start, len)); EXPECT_FALSE(parser->NextValue(type, start, len)); parser = - pdfium::MakeUnique<CFDE_CSSValueListParser>(L"rgb(1, 255, 4)", 14, L' '); + pdfium::MakeUnique<CFX_CSSValueListParser>(L"rgb(1, 255, 4)", 14, L' '); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::RGB, type); + EXPECT_EQ(CFX_CSSPrimitiveType::RGB, type); EXPECT_EQ(L"rgb(1, 255, 4)", CFX_WideString(start, len)); - parser = - pdfium::MakeUnique<CFDE_CSSValueListParser>(L"#abcdefghij", 11, L' '); + parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"#abcdefghij", 11, L' '); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::Unknown, type); + EXPECT_EQ(CFX_CSSPrimitiveType::Unknown, type); EXPECT_EQ(L"#abcdefghij", CFX_WideString(start, len)); EXPECT_FALSE(parser->NextValue(type, start, len)); } -TEST(CFDE_CSSValueListParserTest, number_parsing) { - FDE_CSSPrimitiveType type; +TEST(CFX_CSSValueListParserTest, number_parsing) { + CFX_CSSPrimitiveType type; const wchar_t* start; int32_t len; - auto parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"1234", 4, L' '); + auto parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"1234", 4, L' '); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::Number, type); + EXPECT_EQ(CFX_CSSPrimitiveType::Number, type); EXPECT_EQ(L"1234", CFX_WideString(start, len)); - parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"-1234", 5, L' '); + parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"-1234", 5, L' '); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::Number, type); + EXPECT_EQ(CFX_CSSPrimitiveType::Number, type); EXPECT_EQ(L"-1234", CFX_WideString(start, len)); - parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"+1234", 5, L' '); + parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"+1234", 5, L' '); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::Number, type); + EXPECT_EQ(CFX_CSSPrimitiveType::Number, type); EXPECT_EQ(L"+1234", CFX_WideString(start, len)); - parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L".1234", 5, L' '); + parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L".1234", 5, L' '); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::Number, type); + EXPECT_EQ(CFX_CSSPrimitiveType::Number, type); EXPECT_EQ(L".1234", CFX_WideString(start, len)); - parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"4321.1234", 9, L' '); + parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"4321.1234", 9, L' '); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::Number, type); + EXPECT_EQ(CFX_CSSPrimitiveType::Number, type); EXPECT_EQ(L"4321.1234", CFX_WideString(start, len)); // TODO(dsinclair): These should probably fail but currently don't. - parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"4321.12.34", 10, L' '); + parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"4321.12.34", 10, L' '); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::Number, type); + EXPECT_EQ(CFX_CSSPrimitiveType::Number, type); EXPECT_EQ(L"4321.12.34", CFX_WideString(start, len)); - parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"43a1.12.34", 10, L' '); + parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"43a1.12.34", 10, L' '); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::Number, type); + EXPECT_EQ(CFX_CSSPrimitiveType::Number, type); EXPECT_EQ(L"43a1.12.34", CFX_WideString(start, len)); } -TEST(CFDE_CSSValueListParserTest, string_parsing) { - FDE_CSSPrimitiveType type; +TEST(CFX_CSSValueListParserTest, string_parsing) { + CFX_CSSPrimitiveType type; const wchar_t* start; int32_t len; auto parser = - pdfium::MakeUnique<CFDE_CSSValueListParser>(L"'string'", 8, L' '); + pdfium::MakeUnique<CFX_CSSValueListParser>(L"'string'", 8, L' '); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::String, type); + EXPECT_EQ(CFX_CSSPrimitiveType::String, type); EXPECT_EQ(L"string", CFX_WideString(start, len)); - parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"\"another string\"", - 16, L' '); + parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"\"another string\"", 16, + L' '); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::String, type); + EXPECT_EQ(CFX_CSSPrimitiveType::String, type); EXPECT_EQ(L"another string", CFX_WideString(start, len)); - parser = pdfium::MakeUnique<CFDE_CSSValueListParser>(L"standalone", 10, L' '); + parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"standalone", 10, L' '); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::String, type); + EXPECT_EQ(CFX_CSSPrimitiveType::String, type); EXPECT_EQ(L"standalone", CFX_WideString(start, len)); } -TEST(CFDE_CSSValueListParserTest, multiparsing) { - FDE_CSSPrimitiveType type; +TEST(CFX_CSSValueListParserTest, multiparsing) { + CFX_CSSPrimitiveType type; const wchar_t* start; int32_t len; - auto parser = - pdfium::MakeUnique<CFDE_CSSValueListParser>(L"1, 2, 3", 7, L','); + auto parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"1, 2, 3", 7, L','); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::Number, type); + EXPECT_EQ(CFX_CSSPrimitiveType::Number, type); EXPECT_EQ(L"1", CFX_WideString(start, len)); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::Number, type); + EXPECT_EQ(CFX_CSSPrimitiveType::Number, type); EXPECT_EQ(L"2", CFX_WideString(start, len)); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::Number, type); + EXPECT_EQ(CFX_CSSPrimitiveType::Number, type); EXPECT_EQ(L"3", CFX_WideString(start, len)); EXPECT_FALSE(parser->NextValue(type, start, len)); - parser = pdfium::MakeUnique<CFDE_CSSValueListParser>( - L"'str', rgb(1, 2, 3), 4", 22, L','); + parser = pdfium::MakeUnique<CFX_CSSValueListParser>(L"'str', rgb(1, 2, 3), 4", + 22, L','); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::String, type); + EXPECT_EQ(CFX_CSSPrimitiveType::String, type); EXPECT_EQ(L"str", CFX_WideString(start, len)); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::RGB, type); + EXPECT_EQ(CFX_CSSPrimitiveType::RGB, type); EXPECT_EQ(L"rgb(1, 2, 3)", CFX_WideString(start, len)); EXPECT_TRUE(parser->NextValue(type, start, len)); - EXPECT_EQ(FDE_CSSPrimitiveType::Number, type); + EXPECT_EQ(CFX_CSSPrimitiveType::Number, type); EXPECT_EQ(L"4", CFX_WideString(start, len)); } diff --git a/testing/libfuzzer/pdf_css_fuzzer.cc b/testing/libfuzzer/pdf_css_fuzzer.cc index d3b2e6a996..36b29427ef 100644 --- a/testing/libfuzzer/pdf_css_fuzzer.cc +++ b/testing/libfuzzer/pdf_css_fuzzer.cc @@ -6,9 +6,9 @@ #include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/cfx_seekablestreamproxy.h" +#include "core/fxcrt/css/cfx_css.h" +#include "core/fxcrt/css/cfx_csssyntaxparser.h" #include "core/fxcrt/fx_string.h" -#include "xfa/fde/css/cfde_csssyntaxparser.h" -#include "xfa/fde/css/fde_css.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { CFX_WideString input = CFX_WideString::FromUTF8( @@ -18,11 +18,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (input.GetLength() == 0) return 0; - CFDE_CSSSyntaxParser parser(input.c_str(), input.GetLength()); - FDE_CSSSyntaxStatus status; + CFX_CSSSyntaxParser parser(input.c_str(), input.GetLength()); + CFX_CSSSyntaxStatus status; do { status = parser.DoSyntaxParse(); - } while (status != FDE_CSSSyntaxStatus::Error && - status != FDE_CSSSyntaxStatus::EOS); + } while (status != CFX_CSSSyntaxStatus::Error && + status != CFX_CSSSyntaxStatus::EOS); return 0; } diff --git a/xfa/fde/css/cfde_csscomputedstyle.cpp b/xfa/fde/css/cfde_csscomputedstyle.cpp deleted file mode 100644 index 92184d4259..0000000000 --- a/xfa/fde/css/cfde_csscomputedstyle.cpp +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright 2017 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/cfde_csscomputedstyle.h" - -#include "third_party/base/stl_util.h" -#include "xfa/fde/css/cfde_cssstringvalue.h" -#include "xfa/fde/css/cfde_cssvaluelist.h" - -CFDE_CSSComputedStyle::CFDE_CSSComputedStyle() {} - -CFDE_CSSComputedStyle::~CFDE_CSSComputedStyle() {} - -bool CFDE_CSSComputedStyle::GetCustomStyle(const CFX_WideString& wsName, - CFX_WideString& wsValue) const { - for (auto iter = m_CustomProperties.rbegin(); - iter != m_CustomProperties.rend(); iter++) { - if (wsName == iter->name()) { - wsValue = iter->value(); - return true; - } - } - return false; -} - -int32_t CFDE_CSSComputedStyle::CountFontFamilies() const { - return m_InheritedData.m_pFontFamily - ? m_InheritedData.m_pFontFamily->CountValues() - : 0; -} - -const CFX_WideString CFDE_CSSComputedStyle::GetFontFamily(int32_t index) const { - return m_InheritedData.m_pFontFamily->GetValue(index) - .As<CFDE_CSSStringValue>() - ->Value(); -} - -uint16_t CFDE_CSSComputedStyle::GetFontWeight() const { - return m_InheritedData.m_wFontWeight; -} - -FDE_CSSFontVariant CFDE_CSSComputedStyle::GetFontVariant() const { - return m_InheritedData.m_eFontVariant; -} - -FDE_CSSFontStyle CFDE_CSSComputedStyle::GetFontStyle() const { - return m_InheritedData.m_eFontStyle; -} - -float CFDE_CSSComputedStyle::GetFontSize() const { - return m_InheritedData.m_fFontSize; -} - -FX_ARGB CFDE_CSSComputedStyle::GetColor() const { - return m_InheritedData.m_dwFontColor; -} - -void CFDE_CSSComputedStyle::SetFontWeight(uint16_t wFontWeight) { - m_InheritedData.m_wFontWeight = wFontWeight; -} - -void CFDE_CSSComputedStyle::SetFontVariant(FDE_CSSFontVariant eFontVariant) { - m_InheritedData.m_eFontVariant = eFontVariant; -} - -void CFDE_CSSComputedStyle::SetFontStyle(FDE_CSSFontStyle eFontStyle) { - m_InheritedData.m_eFontStyle = eFontStyle; -} - -void CFDE_CSSComputedStyle::SetFontSize(float fFontSize) { - m_InheritedData.m_fFontSize = fFontSize; -} - -void CFDE_CSSComputedStyle::SetColor(FX_ARGB dwFontColor) { - m_InheritedData.m_dwFontColor = dwFontColor; -} - -const FDE_CSSRect* CFDE_CSSComputedStyle::GetBorderWidth() const { - return m_NonInheritedData.m_bHasBorder ? &(m_NonInheritedData.m_BorderWidth) - : nullptr; -} - -const FDE_CSSRect* CFDE_CSSComputedStyle::GetMarginWidth() const { - return m_NonInheritedData.m_bHasMargin ? &(m_NonInheritedData.m_MarginWidth) - : nullptr; -} - -const FDE_CSSRect* CFDE_CSSComputedStyle::GetPaddingWidth() const { - return m_NonInheritedData.m_bHasPadding ? &(m_NonInheritedData.m_PaddingWidth) - : nullptr; -} - -void CFDE_CSSComputedStyle::SetMarginWidth(const FDE_CSSRect& rect) { - m_NonInheritedData.m_MarginWidth = rect; - m_NonInheritedData.m_bHasMargin = true; -} - -void CFDE_CSSComputedStyle::SetPaddingWidth(const FDE_CSSRect& rect) { - m_NonInheritedData.m_PaddingWidth = rect; - m_NonInheritedData.m_bHasPadding = true; -} - -FDE_CSSDisplay CFDE_CSSComputedStyle::GetDisplay() const { - return m_NonInheritedData.m_eDisplay; -} - -float CFDE_CSSComputedStyle::GetLineHeight() const { - return m_InheritedData.m_fLineHeight; -} - -const FDE_CSSLength& CFDE_CSSComputedStyle::GetTextIndent() const { - return m_InheritedData.m_TextIndent; -} - -FDE_CSSTextAlign CFDE_CSSComputedStyle::GetTextAlign() const { - return m_InheritedData.m_eTextAlign; -} - -FDE_CSSVerticalAlign CFDE_CSSComputedStyle::GetVerticalAlign() const { - return m_NonInheritedData.m_eVerticalAlign; -} - -float CFDE_CSSComputedStyle::GetNumberVerticalAlign() const { - return m_NonInheritedData.m_fVerticalAlign; -} - -uint32_t CFDE_CSSComputedStyle::GetTextDecoration() const { - return m_NonInheritedData.m_dwTextDecoration; -} - -const FDE_CSSLength& CFDE_CSSComputedStyle::GetLetterSpacing() const { - return m_InheritedData.m_LetterSpacing; -} - -void CFDE_CSSComputedStyle::SetLineHeight(float fLineHeight) { - m_InheritedData.m_fLineHeight = fLineHeight; -} - -void CFDE_CSSComputedStyle::SetTextIndent(const FDE_CSSLength& textIndent) { - m_InheritedData.m_TextIndent = textIndent; -} - -void CFDE_CSSComputedStyle::SetTextAlign(FDE_CSSTextAlign eTextAlign) { - m_InheritedData.m_eTextAlign = eTextAlign; -} - -void CFDE_CSSComputedStyle::SetNumberVerticalAlign(float fAlign) { - m_NonInheritedData.m_eVerticalAlign = FDE_CSSVerticalAlign::Number, - m_NonInheritedData.m_fVerticalAlign = fAlign; -} - -void CFDE_CSSComputedStyle::SetTextDecoration(uint32_t dwTextDecoration) { - m_NonInheritedData.m_dwTextDecoration = dwTextDecoration; -} - -void CFDE_CSSComputedStyle::SetLetterSpacing( - const FDE_CSSLength& letterSpacing) { - m_InheritedData.m_LetterSpacing = letterSpacing; -} - -void CFDE_CSSComputedStyle::AddCustomStyle(const CFDE_CSSCustomProperty& prop) { - // Force the property to be copied so we aren't dependent on the lifetime - // of whatever currently owns it. - m_CustomProperties.push_back(prop); -} - -CFDE_CSSComputedStyle::InheritedData::InheritedData() - : m_LetterSpacing(FDE_CSSLengthUnit::Normal), - m_WordSpacing(FDE_CSSLengthUnit::Normal), - m_TextIndent(FDE_CSSLengthUnit::Point, 0), - m_pFontFamily(nullptr), - m_fFontSize(12.0f), - m_fLineHeight(14.0f), - m_dwFontColor(0xFF000000), - m_wFontWeight(400), - m_eFontVariant(FDE_CSSFontVariant::Normal), - m_eFontStyle(FDE_CSSFontStyle::Normal), - m_eTextAlign(FDE_CSSTextAlign::Left) {} - -CFDE_CSSComputedStyle::InheritedData::~InheritedData() {} - -CFDE_CSSComputedStyle::NonInheritedData::NonInheritedData() - : m_MarginWidth(FDE_CSSLengthUnit::Point, 0), - m_BorderWidth(FDE_CSSLengthUnit::Point, 0), - m_PaddingWidth(FDE_CSSLengthUnit::Point, 0), - m_fVerticalAlign(0.0f), - m_eDisplay(FDE_CSSDisplay::Inline), - m_eVerticalAlign(FDE_CSSVerticalAlign::Baseline), - m_dwTextDecoration(0), - m_bHasMargin(false), - m_bHasBorder(false), - m_bHasPadding(false) {} diff --git a/xfa/fde/css/cfde_csscomputedstyle.h b/xfa/fde/css/cfde_csscomputedstyle.h deleted file mode 100644 index 448d2467ab..0000000000 --- a/xfa/fde/css/cfde_csscomputedstyle.h +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2017 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 - -#ifndef XFA_FDE_CSS_CFDE_CSSCOMPUTEDSTYLE_H_ -#define XFA_FDE_CSS_CFDE_CSSCOMPUTEDSTYLE_H_ - -#include <vector> - -#include "core/fxcrt/fx_basic.h" -#include "core/fxcrt/fx_string.h" -#include "xfa/fde/css/cfde_csscustomproperty.h" -#include "xfa/fde/css/fde_css.h" - -class CFDE_CSSValueList; - -class CFDE_CSSComputedStyle : public CFX_Retainable { - public: - class InheritedData { - public: - InheritedData(); - ~InheritedData(); - - FDE_CSSLength m_LetterSpacing; - FDE_CSSLength m_WordSpacing; - FDE_CSSLength m_TextIndent; - CFX_RetainPtr<CFDE_CSSValueList> m_pFontFamily; - float m_fFontSize; - float m_fLineHeight; - FX_ARGB m_dwFontColor; - uint16_t m_wFontWeight; - FDE_CSSFontVariant m_eFontVariant; - FDE_CSSFontStyle m_eFontStyle; - FDE_CSSTextAlign m_eTextAlign; - }; - - class NonInheritedData { - public: - NonInheritedData(); - - FDE_CSSRect m_MarginWidth; - FDE_CSSRect m_BorderWidth; - FDE_CSSRect m_PaddingWidth; - FDE_CSSLength m_Top; - FDE_CSSLength m_Bottom; - FDE_CSSLength m_Left; - FDE_CSSLength m_Right; - float m_fVerticalAlign; - FDE_CSSDisplay m_eDisplay; - FDE_CSSVerticalAlign m_eVerticalAlign; - uint8_t m_dwTextDecoration; - bool m_bHasMargin; - bool m_bHasBorder; - bool m_bHasPadding; - }; - - int32_t CountFontFamilies() const; - const CFX_WideString GetFontFamily(int32_t index) const; - uint16_t GetFontWeight() const; - FDE_CSSFontVariant GetFontVariant() const; - FDE_CSSFontStyle GetFontStyle() const; - float GetFontSize() const; - FX_ARGB GetColor() const; - void SetFontWeight(uint16_t wFontWeight); - void SetFontVariant(FDE_CSSFontVariant eFontVariant); - void SetFontStyle(FDE_CSSFontStyle eFontStyle); - void SetFontSize(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; - - float GetLineHeight() const; - const FDE_CSSLength& GetTextIndent() const; - FDE_CSSTextAlign GetTextAlign() const; - FDE_CSSVerticalAlign GetVerticalAlign() const; - float GetNumberVerticalAlign() const; - uint32_t GetTextDecoration() const; - const FDE_CSSLength& GetLetterSpacing() const; - void SetLineHeight(float fLineHeight); - void SetTextIndent(const FDE_CSSLength& textIndent); - void SetTextAlign(FDE_CSSTextAlign eTextAlign); - void SetNumberVerticalAlign(float fAlign); - void SetTextDecoration(uint32_t dwTextDecoration); - void SetLetterSpacing(const FDE_CSSLength& letterSpacing); - void AddCustomStyle(const CFDE_CSSCustomProperty& prop); - - bool GetCustomStyle(const CFX_WideString& wsName, - CFX_WideString& wsValue) const; - - InheritedData m_InheritedData; - NonInheritedData m_NonInheritedData; - - private: - template <typename T, typename... Args> - friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); - - CFDE_CSSComputedStyle(); - ~CFDE_CSSComputedStyle() override; - - std::vector<CFDE_CSSCustomProperty> m_CustomProperties; -}; - -#endif // XFA_FDE_CSS_CFDE_CSSCOMPUTEDSTYLE_H_ diff --git a/xfa/fde/css/cfde_csscustomproperty.cpp b/xfa/fde/css/cfde_csscustomproperty.cpp deleted file mode 100644 index 92b288eb4f..0000000000 --- a/xfa/fde/css/cfde_csscustomproperty.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017 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. - -#include "xfa/fde/css/cfde_csscustomproperty.h" - -CFDE_CSSCustomProperty::CFDE_CSSCustomProperty(const CFX_WideString& name, - const CFX_WideString& value) - : name_(name), value_(value) {} - -CFDE_CSSCustomProperty::CFDE_CSSCustomProperty( - const CFDE_CSSCustomProperty& prop) - : name_(prop.name_), value_(prop.value_) {} - -CFDE_CSSCustomProperty::~CFDE_CSSCustomProperty() {} diff --git a/xfa/fde/css/cfde_cssenumvalue.h b/xfa/fde/css/cfde_cssenumvalue.h deleted file mode 100644 index 9fb1b69ef5..0000000000 --- a/xfa/fde/css/cfde_cssenumvalue.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017 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 - -#ifndef XFA_FDE_CSS_CFDE_CSSENUMVALUE_H_ -#define XFA_FDE_CSS_CFDE_CSSENUMVALUE_H_ - -#include "xfa/fde/css/cfde_cssvalue.h" - -class CFDE_CSSEnumValue : public CFDE_CSSValue { - public: - explicit CFDE_CSSEnumValue(FDE_CSSPropertyValue value); - ~CFDE_CSSEnumValue() override; - - FDE_CSSPropertyValue Value() const { return value_; } - - private: - FDE_CSSPropertyValue value_; -}; - -#endif // XFA_FDE_CSS_CFDE_CSSENUMVALUE_H_ diff --git a/xfa/fde/css/cfde_cssnumbervalue.cpp b/xfa/fde/css/cfde_cssnumbervalue.cpp deleted file mode 100644 index 45a9c917b1..0000000000 --- a/xfa/fde/css/cfde_cssnumbervalue.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2017 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/cfde_cssnumbervalue.h" - -CFDE_CSSNumberValue::CFDE_CSSNumberValue(FDE_CSSNumberType type, float value) - : CFDE_CSSValue(FDE_CSSPrimitiveType::Number), type_(type), value_(value) { - if (type_ == FDE_CSSNumberType::Number && fabs(value_) < 0.001f) - value_ = 0.0f; -} - -CFDE_CSSNumberValue::~CFDE_CSSNumberValue() {} - -float CFDE_CSSNumberValue::Apply(float percentBase) const { - switch (type_) { - case FDE_CSSNumberType::Pixels: - case FDE_CSSNumberType::Number: - return value_ * 72 / 96; - case FDE_CSSNumberType::EMS: - case FDE_CSSNumberType::EXS: - return value_ * percentBase; - case FDE_CSSNumberType::Percent: - return value_ * percentBase / 100.0f; - case FDE_CSSNumberType::CentiMeters: - return value_ * 28.3464f; - case FDE_CSSNumberType::MilliMeters: - return value_ * 2.8346f; - case FDE_CSSNumberType::Inches: - return value_ * 72.0f; - case FDE_CSSNumberType::Picas: - return value_ / 12.0f; - case FDE_CSSNumberType::Points: - return value_; - } - return value_; -} diff --git a/xfa/fde/css/cfde_csspropertyholder.h b/xfa/fde/css/cfde_csspropertyholder.h deleted file mode 100644 index 7f8526d92e..0000000000 --- a/xfa/fde/css/cfde_csspropertyholder.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2017 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 - -#ifndef XFA_FDE_CSS_CFDE_CSSPROPERTYHOLDER_H_ -#define XFA_FDE_CSS_CFDE_CSSPROPERTYHOLDER_H_ - -#include "core/fxcrt/cfx_retain_ptr.h" -#include "xfa/fde/css/cfde_cssvalue.h" -#include "xfa/fde/css/fde_css.h" - -class CFDE_CSSPropertyHolder { - public: - CFDE_CSSPropertyHolder(); - ~CFDE_CSSPropertyHolder(); - - FDE_CSSProperty eProperty; - bool bImportant; - CFX_RetainPtr<CFDE_CSSValue> pValue; -}; - -#endif // XFA_FDE_CSS_CFDE_CSSPROPERTYHOLDER_H_ diff --git a/xfa/fde/css/cfde_cssrulecollection.cpp b/xfa/fde/css/cfde_cssrulecollection.cpp deleted file mode 100644 index b945fd518b..0000000000 --- a/xfa/fde/css/cfde_cssrulecollection.cpp +++ /dev/null @@ -1,56 +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/cfde_cssrulecollection.h" - -#include <algorithm> -#include <utility> - -#include "third_party/base/ptr_util.h" -#include "xfa/fde/css/cfde_cssdeclaration.h" -#include "xfa/fde/css/cfde_cssselector.h" -#include "xfa/fde/css/cfde_cssstylerule.h" -#include "xfa/fde/css/cfde_cssstylesheet.h" -#include "xfa/fde/css/cfde_csssyntaxparser.h" - -CFDE_CSSRuleCollection::CFDE_CSSRuleCollection() : m_iSelectors(0) {} - -CFDE_CSSRuleCollection::~CFDE_CSSRuleCollection() { - Clear(); -} - -void CFDE_CSSRuleCollection::Clear() { - m_TagRules.clear(); - m_iSelectors = 0; -} - -const std::vector<std::unique_ptr<CFDE_CSSRuleCollection::Data>>* -CFDE_CSSRuleCollection::GetTagRuleData(const CFX_WideString& tagname) const { - auto it = m_TagRules.find(FX_HashCode_GetW(tagname.c_str(), true)); - return it != m_TagRules.end() ? &it->second : nullptr; -} - -void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheet* sheet) { - int32_t iRules = sheet->CountRules(); - for (int32_t j = 0; j < iRules; j++) - AddRulesFrom(sheet, sheet->GetRule(j)); -} - -void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheet* pStyleSheet, - CFDE_CSSStyleRule* pStyleRule) { - CFDE_CSSDeclaration* pDeclaration = pStyleRule->GetDeclaration(); - int32_t iSelectors = pStyleRule->CountSelectorLists(); - for (int32_t i = 0; i < iSelectors; ++i) { - CFDE_CSSSelector* pSelector = pStyleRule->GetSelectorList(i); - m_TagRules[pSelector->GetNameHash()].push_back( - pdfium::MakeUnique<Data>(pSelector, pDeclaration)); - m_iSelectors++; - } -} - -CFDE_CSSRuleCollection::Data::Data(CFDE_CSSSelector* pSel, - CFDE_CSSDeclaration* pDecl) - : pSelector(pSel), pDeclaration(pDecl) {} diff --git a/xfa/fde/css/cfde_cssselector.h b/xfa/fde/css/cfde_cssselector.h deleted file mode 100644 index 048c51339e..0000000000 --- a/xfa/fde/css/cfde_cssselector.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2017 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 - -#ifndef XFA_FDE_CSS_CFDE_CSSSELECTOR_H_ -#define XFA_FDE_CSS_CFDE_CSSSELECTOR_H_ - -#include <memory> -#include <utility> - -#include "core/fxcrt/fx_string.h" -#include "xfa/fde/css/fde_css.h" - -class CFDE_CSSSelector { - public: - static std::unique_ptr<CFDE_CSSSelector> FromString( - const CFX_WideStringC& str); - - CFDE_CSSSelector(FDE_CSSSelectorType eType, - const wchar_t* psz, - int32_t iLen, - bool bIgnoreCase); - ~CFDE_CSSSelector(); - - FDE_CSSSelectorType GetType() const; - uint32_t GetNameHash() const; - CFDE_CSSSelector* GetNextSelector() const; - - void SetNext(std::unique_ptr<CFDE_CSSSelector> pNext) { - m_pNext = std::move(pNext); - } - - private: - void SetType(FDE_CSSSelectorType eType) { m_eType = eType; } - - FDE_CSSSelectorType m_eType; - uint32_t m_dwHash; - std::unique_ptr<CFDE_CSSSelector> m_pNext; -}; - -#endif // XFA_FDE_CSS_CFDE_CSSSELECTOR_H_ diff --git a/xfa/fde/css/cfde_cssstringvalue.cpp b/xfa/fde/css/cfde_cssstringvalue.cpp deleted file mode 100644 index deb9be3dc0..0000000000 --- a/xfa/fde/css/cfde_cssstringvalue.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2017 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/cfde_cssstringvalue.h" - -CFDE_CSSStringValue::CFDE_CSSStringValue(const CFX_WideString& value) - : CFDE_CSSValue(FDE_CSSPrimitiveType::String), value_(value) {} - -CFDE_CSSStringValue::~CFDE_CSSStringValue() {} diff --git a/xfa/fde/css/cfde_cssstylerule.cpp b/xfa/fde/css/cfde_cssstylerule.cpp deleted file mode 100644 index 04f6cfff08..0000000000 --- a/xfa/fde/css/cfde_cssstylerule.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2017 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/cfde_cssstylerule.h" - -CFDE_CSSStyleRule::CFDE_CSSStyleRule() {} - -CFDE_CSSStyleRule::~CFDE_CSSStyleRule() {} - -size_t CFDE_CSSStyleRule::CountSelectorLists() const { - return m_ppSelector.size(); -} - -CFDE_CSSSelector* CFDE_CSSStyleRule::GetSelectorList(int32_t index) const { - return m_ppSelector[index].get(); -} - -CFDE_CSSDeclaration* CFDE_CSSStyleRule::GetDeclaration() { - return &m_Declaration; -} - -void CFDE_CSSStyleRule::SetSelector( - std::vector<std::unique_ptr<CFDE_CSSSelector>>* list) { - ASSERT(m_ppSelector.empty()); - - m_ppSelector.swap(*list); -} diff --git a/xfa/fde/css/cfde_cssstylerule.h b/xfa/fde/css/cfde_cssstylerule.h deleted file mode 100644 index 075ab8d478..0000000000 --- a/xfa/fde/css/cfde_cssstylerule.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2017 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 - -#ifndef XFA_FDE_CSS_CFDE_CSSSTYLERULE_H_ -#define XFA_FDE_CSS_CFDE_CSSSTYLERULE_H_ - -#include <memory> -#include <vector> - -#include "xfa/fde/css/cfde_cssdeclaration.h" -#include "xfa/fde/css/cfde_cssselector.h" - -class CFDE_CSSStyleRule { - public: - CFDE_CSSStyleRule(); - ~CFDE_CSSStyleRule(); - - size_t CountSelectorLists() const; - CFDE_CSSSelector* GetSelectorList(int32_t index) const; - CFDE_CSSDeclaration* GetDeclaration(); - - void SetSelector(std::vector<std::unique_ptr<CFDE_CSSSelector>>* list); - - private: - CFDE_CSSDeclaration m_Declaration; - std::vector<std::unique_ptr<CFDE_CSSSelector>> m_ppSelector; -}; - -#endif // XFA_FDE_CSS_CFDE_CSSSTYLERULE_H_ diff --git a/xfa/fde/css/cfde_cssstyleselector.cpp b/xfa/fde/css/cfde_cssstyleselector.cpp deleted file mode 100644 index 141e74c865..0000000000 --- a/xfa/fde/css/cfde_cssstyleselector.cpp +++ /dev/null @@ -1,599 +0,0 @@ -// Copyright 2014 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/cfde_cssstyleselector.h" - -#include <algorithm> -#include <utility> - -#include "third_party/base/logging.h" -#include "third_party/base/ptr_util.h" -#include "xfa/fde/css/cfde_csscolorvalue.h" -#include "xfa/fde/css/cfde_csscomputedstyle.h" -#include "xfa/fde/css/cfde_csscustomproperty.h" -#include "xfa/fde/css/cfde_cssdeclaration.h" -#include "xfa/fde/css/cfde_cssenumvalue.h" -#include "xfa/fde/css/cfde_csspropertyholder.h" -#include "xfa/fde/css/cfde_cssselector.h" -#include "xfa/fde/css/cfde_cssstylesheet.h" -#include "xfa/fde/css/cfde_csssyntaxparser.h" -#include "xfa/fde/css/cfde_cssvaluelist.h" - -CFDE_CSSStyleSelector::CFDE_CSSStyleSelector() : m_fDefFontSize(12.0f) {} - -CFDE_CSSStyleSelector::~CFDE_CSSStyleSelector() {} - -void CFDE_CSSStyleSelector::SetDefFontSize(float fFontSize) { - ASSERT(fFontSize > 0); - m_fDefFontSize = fFontSize; -} - -CFX_RetainPtr<CFDE_CSSComputedStyle> CFDE_CSSStyleSelector::CreateComputedStyle( - CFDE_CSSComputedStyle* pParentStyle) { - auto pStyle = pdfium::MakeRetain<CFDE_CSSComputedStyle>(); - if (pParentStyle) - pStyle->m_InheritedData = pParentStyle->m_InheritedData; - return pStyle; -} - -void CFDE_CSSStyleSelector::SetUAStyleSheet( - std::unique_ptr<CFDE_CSSStyleSheet> pSheet) { - m_UAStyles = std::move(pSheet); -} - -void CFDE_CSSStyleSelector::UpdateStyleIndex() { - m_UARules.Clear(); - m_UARules.AddRulesFrom(m_UAStyles.get()); -} - -std::vector<const CFDE_CSSDeclaration*> -CFDE_CSSStyleSelector::MatchDeclarations(const CFX_WideString& tagname) { - std::vector<const CFDE_CSSDeclaration*> matchedDecls; - if (m_UARules.CountSelectors() == 0 || tagname.IsEmpty()) - return matchedDecls; - - auto* rules = m_UARules.GetTagRuleData(tagname); - if (!rules) - return matchedDecls; - - for (const auto& d : *rules) { - if (MatchSelector(tagname, d->pSelector)) - matchedDecls.push_back(d->pDeclaration); - } - return matchedDecls; -} - -bool CFDE_CSSStyleSelector::MatchSelector(const CFX_WideString& tagname, - CFDE_CSSSelector* pSel) { - // TODO(dsinclair): The code only supports a single level of selector at this - // point. None of the code using selectors required the complexity so lets - // just say we don't support them to simplify the code for now. - if (!pSel || pSel->GetNextSelector() || - pSel->GetType() == FDE_CSSSelectorType::Descendant) { - return false; - } - return pSel->GetNameHash() == FX_HashCode_GetW(tagname.c_str(), true); -} - -void CFDE_CSSStyleSelector::ComputeStyle( - const std::vector<const CFDE_CSSDeclaration*>& declArray, - const CFX_WideString& styleString, - const CFX_WideString& alignString, - CFDE_CSSComputedStyle* pDest) { - std::unique_ptr<CFDE_CSSDeclaration> pDecl; - if (!styleString.IsEmpty() || !alignString.IsEmpty()) { - pDecl = pdfium::MakeUnique<CFDE_CSSDeclaration>(); - - if (!styleString.IsEmpty()) - AppendInlineStyle(pDecl.get(), styleString); - if (!alignString.IsEmpty()) { - pDecl->AddProperty(FDE_GetCSSPropertyByEnum(FDE_CSSProperty::TextAlign), - alignString.AsStringC()); - } - } - ApplyDeclarations(declArray, pDecl.get(), pDest); -} - -void CFDE_CSSStyleSelector::ApplyDeclarations( - const std::vector<const CFDE_CSSDeclaration*>& declArray, - const CFDE_CSSDeclaration* extraDecl, - CFDE_CSSComputedStyle* pComputedStyle) { - std::vector<const CFDE_CSSPropertyHolder*> importants; - std::vector<const CFDE_CSSPropertyHolder*> normals; - std::vector<const CFDE_CSSCustomProperty*> customs; - - for (auto* decl : declArray) - ExtractValues(decl, &importants, &normals, &customs); - - if (extraDecl) - ExtractValues(extraDecl, &importants, &normals, &customs); - - for (auto* prop : normals) - ApplyProperty(prop->eProperty, prop->pValue, pComputedStyle); - - for (auto* prop : customs) - pComputedStyle->AddCustomStyle(*prop); - - for (auto* prop : importants) - ApplyProperty(prop->eProperty, prop->pValue, pComputedStyle); -} - -void CFDE_CSSStyleSelector::ExtractValues( - const CFDE_CSSDeclaration* decl, - std::vector<const CFDE_CSSPropertyHolder*>* importants, - std::vector<const CFDE_CSSPropertyHolder*>* normals, - std::vector<const CFDE_CSSCustomProperty*>* custom) { - for (const auto& holder : *decl) { - if (holder->bImportant) - importants->push_back(holder.get()); - else - normals->push_back(holder.get()); - } - for (auto it = decl->custom_begin(); it != decl->custom_end(); it++) - custom->push_back(it->get()); -} - -void CFDE_CSSStyleSelector::AppendInlineStyle(CFDE_CSSDeclaration* pDecl, - const CFX_WideString& style) { - ASSERT(pDecl && !style.IsEmpty()); - - auto pSyntax = pdfium::MakeUnique<CFDE_CSSSyntaxParser>( - style.c_str(), style.GetLength(), 32, true); - int32_t iLen2 = 0; - const FDE_CSSPropertyTable* table = nullptr; - CFX_WideString wsName; - while (1) { - FDE_CSSSyntaxStatus eStatus = pSyntax->DoSyntaxParse(); - if (eStatus == FDE_CSSSyntaxStatus::PropertyName) { - CFX_WideStringC strValue = pSyntax->GetCurrentString(); - table = FDE_GetCSSPropertyByName(strValue); - if (!table) - wsName = CFX_WideString(strValue); - } else if (eStatus == FDE_CSSSyntaxStatus::PropertyValue) { - if (table || iLen2 > 0) { - CFX_WideStringC strValue = pSyntax->GetCurrentString(); - if (!strValue.IsEmpty()) { - if (table) - pDecl->AddProperty(table, strValue); - else if (iLen2 > 0) - pDecl->AddProperty(wsName, CFX_WideString(strValue)); - } - } - } else { - break; - } - } -} - -void CFDE_CSSStyleSelector::ApplyProperty( - FDE_CSSProperty eProperty, - const CFX_RetainPtr<CFDE_CSSValue>& pValue, - CFDE_CSSComputedStyle* pComputedStyle) { - if (pValue->GetType() != FDE_CSSPrimitiveType::List) { - FDE_CSSPrimitiveType eType = pValue->GetType(); - switch (eProperty) { - case FDE_CSSProperty::Display: - if (eType == FDE_CSSPrimitiveType::Enum) { - pComputedStyle->m_NonInheritedData.m_eDisplay = - ToDisplay(pValue.As<CFDE_CSSEnumValue>()->Value()); - } - break; - case FDE_CSSProperty::FontSize: { - float& fFontSize = pComputedStyle->m_InheritedData.m_fFontSize; - if (eType == FDE_CSSPrimitiveType::Number) { - fFontSize = pValue.As<CFDE_CSSNumberValue>()->Apply(fFontSize); - } else if (eType == FDE_CSSPrimitiveType::Enum) { - fFontSize = - ToFontSize(pValue.As<CFDE_CSSEnumValue>()->Value(), fFontSize); - } - } break; - case FDE_CSSProperty::LineHeight: - if (eType == FDE_CSSPrimitiveType::Number) { - CFX_RetainPtr<CFDE_CSSNumberValue> v = - pValue.As<CFDE_CSSNumberValue>(); - if (v->Kind() == FDE_CSSNumberType::Number) { - pComputedStyle->m_InheritedData.m_fLineHeight = - v->Value() * pComputedStyle->m_InheritedData.m_fFontSize; - } else { - pComputedStyle->m_InheritedData.m_fLineHeight = - v->Apply(pComputedStyle->m_InheritedData.m_fFontSize); - } - } - break; - case FDE_CSSProperty::TextAlign: - if (eType == FDE_CSSPrimitiveType::Enum) { - pComputedStyle->m_InheritedData.m_eTextAlign = - ToTextAlign(pValue.As<CFDE_CSSEnumValue>()->Value()); - } - break; - case FDE_CSSProperty::TextIndent: - SetLengthWithPercent(pComputedStyle->m_InheritedData.m_TextIndent, - eType, pValue, - pComputedStyle->m_InheritedData.m_fFontSize); - break; - case FDE_CSSProperty::FontWeight: - if (eType == FDE_CSSPrimitiveType::Enum) { - pComputedStyle->m_InheritedData.m_wFontWeight = - ToFontWeight(pValue.As<CFDE_CSSEnumValue>()->Value()); - } else if (eType == FDE_CSSPrimitiveType::Number) { - int32_t iValue = - (int32_t)pValue.As<CFDE_CSSNumberValue>()->Value() / 100; - if (iValue >= 1 && iValue <= 9) { - pComputedStyle->m_InheritedData.m_wFontWeight = iValue * 100; - } - } - break; - case FDE_CSSProperty::FontStyle: - if (eType == FDE_CSSPrimitiveType::Enum) { - pComputedStyle->m_InheritedData.m_eFontStyle = - ToFontStyle(pValue.As<CFDE_CSSEnumValue>()->Value()); - } - break; - case FDE_CSSProperty::Color: - if (eType == FDE_CSSPrimitiveType::RGB) { - pComputedStyle->m_InheritedData.m_dwFontColor = - pValue.As<CFDE_CSSColorValue>()->Value(); - } - break; - case FDE_CSSProperty::MarginLeft: - if (SetLengthWithPercent( - pComputedStyle->m_NonInheritedData.m_MarginWidth.left, eType, - pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { - pComputedStyle->m_NonInheritedData.m_bHasMargin = true; - } - break; - case FDE_CSSProperty::MarginTop: - if (SetLengthWithPercent( - pComputedStyle->m_NonInheritedData.m_MarginWidth.top, eType, - pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { - pComputedStyle->m_NonInheritedData.m_bHasMargin = true; - } - break; - case FDE_CSSProperty::MarginRight: - if (SetLengthWithPercent( - pComputedStyle->m_NonInheritedData.m_MarginWidth.right, eType, - pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { - pComputedStyle->m_NonInheritedData.m_bHasMargin = true; - } - break; - case FDE_CSSProperty::MarginBottom: - if (SetLengthWithPercent( - pComputedStyle->m_NonInheritedData.m_MarginWidth.bottom, eType, - pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { - pComputedStyle->m_NonInheritedData.m_bHasMargin = true; - } - break; - case FDE_CSSProperty::PaddingLeft: - if (SetLengthWithPercent( - pComputedStyle->m_NonInheritedData.m_PaddingWidth.left, eType, - pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { - pComputedStyle->m_NonInheritedData.m_bHasPadding = true; - } - break; - case FDE_CSSProperty::PaddingTop: - if (SetLengthWithPercent( - pComputedStyle->m_NonInheritedData.m_PaddingWidth.top, eType, - pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { - pComputedStyle->m_NonInheritedData.m_bHasPadding = true; - } - break; - case FDE_CSSProperty::PaddingRight: - if (SetLengthWithPercent( - pComputedStyle->m_NonInheritedData.m_PaddingWidth.right, eType, - pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { - pComputedStyle->m_NonInheritedData.m_bHasPadding = true; - } - break; - case FDE_CSSProperty::PaddingBottom: - if (SetLengthWithPercent( - pComputedStyle->m_NonInheritedData.m_PaddingWidth.bottom, eType, - pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { - pComputedStyle->m_NonInheritedData.m_bHasPadding = true; - } - break; - case FDE_CSSProperty::BorderLeftWidth: - if (SetLengthWithPercent( - pComputedStyle->m_NonInheritedData.m_BorderWidth.left, eType, - pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { - pComputedStyle->m_NonInheritedData.m_bHasBorder = true; - } - break; - case FDE_CSSProperty::BorderTopWidth: - if (SetLengthWithPercent( - pComputedStyle->m_NonInheritedData.m_BorderWidth.top, eType, - pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { - pComputedStyle->m_NonInheritedData.m_bHasBorder = true; - } - break; - case FDE_CSSProperty::BorderRightWidth: - if (SetLengthWithPercent( - pComputedStyle->m_NonInheritedData.m_BorderWidth.right, eType, - pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { - pComputedStyle->m_NonInheritedData.m_bHasBorder = true; - } - break; - case FDE_CSSProperty::BorderBottomWidth: - if (SetLengthWithPercent( - pComputedStyle->m_NonInheritedData.m_BorderWidth.bottom, eType, - pValue, pComputedStyle->m_InheritedData.m_fFontSize)) { - pComputedStyle->m_NonInheritedData.m_bHasBorder = true; - } - break; - case FDE_CSSProperty::VerticalAlign: - if (eType == FDE_CSSPrimitiveType::Enum) { - pComputedStyle->m_NonInheritedData.m_eVerticalAlign = - ToVerticalAlign(pValue.As<CFDE_CSSEnumValue>()->Value()); - } else if (eType == FDE_CSSPrimitiveType::Number) { - pComputedStyle->m_NonInheritedData.m_eVerticalAlign = - FDE_CSSVerticalAlign::Number; - pComputedStyle->m_NonInheritedData.m_fVerticalAlign = - pValue.As<CFDE_CSSNumberValue>()->Apply( - pComputedStyle->m_InheritedData.m_fFontSize); - } - break; - case FDE_CSSProperty::FontVariant: - if (eType == FDE_CSSPrimitiveType::Enum) { - pComputedStyle->m_InheritedData.m_eFontVariant = - ToFontVariant(pValue.As<CFDE_CSSEnumValue>()->Value()); - } - break; - case FDE_CSSProperty::LetterSpacing: - if (eType == FDE_CSSPrimitiveType::Enum) { - pComputedStyle->m_InheritedData.m_LetterSpacing.Set( - FDE_CSSLengthUnit::Normal); - } else if (eType == FDE_CSSPrimitiveType::Number) { - if (pValue.As<CFDE_CSSNumberValue>()->Kind() == - FDE_CSSNumberType::Percent) { - break; - } - - SetLengthWithPercent(pComputedStyle->m_InheritedData.m_LetterSpacing, - eType, pValue, - pComputedStyle->m_InheritedData.m_fFontSize); - } - break; - case FDE_CSSProperty::WordSpacing: - if (eType == FDE_CSSPrimitiveType::Enum) { - pComputedStyle->m_InheritedData.m_WordSpacing.Set( - FDE_CSSLengthUnit::Normal); - } else if (eType == FDE_CSSPrimitiveType::Number) { - if (pValue.As<CFDE_CSSNumberValue>()->Kind() == - FDE_CSSNumberType::Percent) { - break; - } - SetLengthWithPercent(pComputedStyle->m_InheritedData.m_WordSpacing, - eType, pValue, - pComputedStyle->m_InheritedData.m_fFontSize); - } - break; - case FDE_CSSProperty::Top: - SetLengthWithPercent(pComputedStyle->m_NonInheritedData.m_Top, eType, - pValue, - pComputedStyle->m_InheritedData.m_fFontSize); - break; - case FDE_CSSProperty::Bottom: - SetLengthWithPercent(pComputedStyle->m_NonInheritedData.m_Bottom, eType, - pValue, - pComputedStyle->m_InheritedData.m_fFontSize); - break; - case FDE_CSSProperty::Left: - SetLengthWithPercent(pComputedStyle->m_NonInheritedData.m_Left, eType, - pValue, - pComputedStyle->m_InheritedData.m_fFontSize); - break; - case FDE_CSSProperty::Right: - SetLengthWithPercent(pComputedStyle->m_NonInheritedData.m_Right, eType, - pValue, - pComputedStyle->m_InheritedData.m_fFontSize); - break; - default: - break; - } - } else if (pValue->GetType() == FDE_CSSPrimitiveType::List) { - CFX_RetainPtr<CFDE_CSSValueList> pList = pValue.As<CFDE_CSSValueList>(); - int32_t iCount = pList->CountValues(); - if (iCount > 0) { - switch (eProperty) { - case FDE_CSSProperty::FontFamily: - pComputedStyle->m_InheritedData.m_pFontFamily = pList; - break; - case FDE_CSSProperty::TextDecoration: - pComputedStyle->m_NonInheritedData.m_dwTextDecoration = - ToTextDecoration(pList); - break; - default: - break; - } - } - } else { - NOTREACHED(); - } -} - -FDE_CSSDisplay CFDE_CSSStyleSelector::ToDisplay(FDE_CSSPropertyValue eValue) { - switch (eValue) { - case FDE_CSSPropertyValue::Block: - return FDE_CSSDisplay::Block; - case FDE_CSSPropertyValue::None: - return FDE_CSSDisplay::None; - case FDE_CSSPropertyValue::ListItem: - return FDE_CSSDisplay::ListItem; - case FDE_CSSPropertyValue::InlineTable: - return FDE_CSSDisplay::InlineTable; - case FDE_CSSPropertyValue::InlineBlock: - return FDE_CSSDisplay::InlineBlock; - case FDE_CSSPropertyValue::Inline: - default: - return FDE_CSSDisplay::Inline; - } -} - -FDE_CSSTextAlign CFDE_CSSStyleSelector::ToTextAlign( - FDE_CSSPropertyValue eValue) { - switch (eValue) { - case FDE_CSSPropertyValue::Center: - return FDE_CSSTextAlign::Center; - case FDE_CSSPropertyValue::Right: - return FDE_CSSTextAlign::Right; - case FDE_CSSPropertyValue::Justify: - return FDE_CSSTextAlign::Justify; - case FDE_CSSPropertyValue::Left: - default: - return FDE_CSSTextAlign::Left; - } -} - -uint16_t CFDE_CSSStyleSelector::ToFontWeight(FDE_CSSPropertyValue eValue) { - switch (eValue) { - case FDE_CSSPropertyValue::Bold: - return 700; - case FDE_CSSPropertyValue::Bolder: - return 900; - case FDE_CSSPropertyValue::Lighter: - return 200; - case FDE_CSSPropertyValue::Normal: - default: - return 400; - } -} - -FDE_CSSFontStyle CFDE_CSSStyleSelector::ToFontStyle( - FDE_CSSPropertyValue eValue) { - switch (eValue) { - case FDE_CSSPropertyValue::Italic: - case FDE_CSSPropertyValue::Oblique: - return FDE_CSSFontStyle::Italic; - default: - return FDE_CSSFontStyle::Normal; - } -} - -bool CFDE_CSSStyleSelector::SetLengthWithPercent( - FDE_CSSLength& width, - FDE_CSSPrimitiveType eType, - const CFX_RetainPtr<CFDE_CSSValue>& pValue, - float fFontSize) { - if (eType == FDE_CSSPrimitiveType::Number) { - CFX_RetainPtr<CFDE_CSSNumberValue> v = pValue.As<CFDE_CSSNumberValue>(); - if (v->Kind() == FDE_CSSNumberType::Percent) { - width.Set(FDE_CSSLengthUnit::Percent, - pValue.As<CFDE_CSSNumberValue>()->Value() / 100.0f); - return width.NonZero(); - } - - float fValue = v->Apply(fFontSize); - width.Set(FDE_CSSLengthUnit::Point, fValue); - return width.NonZero(); - } else if (eType == FDE_CSSPrimitiveType::Enum) { - switch (pValue.As<CFDE_CSSEnumValue>()->Value()) { - case FDE_CSSPropertyValue::Auto: - width.Set(FDE_CSSLengthUnit::Auto); - return true; - case FDE_CSSPropertyValue::None: - width.Set(FDE_CSSLengthUnit::None); - return true; - case FDE_CSSPropertyValue::Thin: - width.Set(FDE_CSSLengthUnit::Point, 2); - return true; - case FDE_CSSPropertyValue::Medium: - width.Set(FDE_CSSLengthUnit::Point, 3); - return true; - case FDE_CSSPropertyValue::Thick: - width.Set(FDE_CSSLengthUnit::Point, 4); - return true; - default: - return false; - } - } - return false; -} - -float CFDE_CSSStyleSelector::ToFontSize(FDE_CSSPropertyValue eValue, - float fCurFontSize) { - switch (eValue) { - case FDE_CSSPropertyValue::XxSmall: - return m_fDefFontSize / 1.2f / 1.2f / 1.2f; - case FDE_CSSPropertyValue::XSmall: - return m_fDefFontSize / 1.2f / 1.2f; - case FDE_CSSPropertyValue::Small: - return m_fDefFontSize / 1.2f; - case FDE_CSSPropertyValue::Medium: - return m_fDefFontSize; - case FDE_CSSPropertyValue::Large: - return m_fDefFontSize * 1.2f; - case FDE_CSSPropertyValue::XLarge: - return m_fDefFontSize * 1.2f * 1.2f; - case FDE_CSSPropertyValue::XxLarge: - return m_fDefFontSize * 1.2f * 1.2f * 1.2f; - case FDE_CSSPropertyValue::Larger: - return fCurFontSize * 1.2f; - case FDE_CSSPropertyValue::Smaller: - return fCurFontSize / 1.2f; - default: - return fCurFontSize; - } -} - -FDE_CSSVerticalAlign CFDE_CSSStyleSelector::ToVerticalAlign( - FDE_CSSPropertyValue eValue) { - switch (eValue) { - case FDE_CSSPropertyValue::Middle: - return FDE_CSSVerticalAlign::Middle; - case FDE_CSSPropertyValue::Bottom: - return FDE_CSSVerticalAlign::Bottom; - case FDE_CSSPropertyValue::Super: - return FDE_CSSVerticalAlign::Super; - case FDE_CSSPropertyValue::Sub: - return FDE_CSSVerticalAlign::Sub; - case FDE_CSSPropertyValue::Top: - return FDE_CSSVerticalAlign::Top; - case FDE_CSSPropertyValue::TextTop: - return FDE_CSSVerticalAlign::TextTop; - case FDE_CSSPropertyValue::TextBottom: - return FDE_CSSVerticalAlign::TextBottom; - case FDE_CSSPropertyValue::Baseline: - default: - return FDE_CSSVerticalAlign::Baseline; - } -} - -uint32_t CFDE_CSSStyleSelector::ToTextDecoration( - const CFX_RetainPtr<CFDE_CSSValueList>& pValue) { - uint32_t dwDecoration = 0; - for (int32_t i = pValue->CountValues() - 1; i >= 0; --i) { - const CFX_RetainPtr<CFDE_CSSValue> pVal = pValue->GetValue(i); - if (pVal->GetType() != FDE_CSSPrimitiveType::Enum) - continue; - - switch (pVal.As<CFDE_CSSEnumValue>()->Value()) { - case FDE_CSSPropertyValue::Underline: - dwDecoration |= FDE_CSSTEXTDECORATION_Underline; - break; - case FDE_CSSPropertyValue::LineThrough: - dwDecoration |= FDE_CSSTEXTDECORATION_LineThrough; - break; - case FDE_CSSPropertyValue::Overline: - dwDecoration |= FDE_CSSTEXTDECORATION_Overline; - break; - case FDE_CSSPropertyValue::Blink: - dwDecoration |= FDE_CSSTEXTDECORATION_Blink; - break; - case FDE_CSSPropertyValue::Double: - dwDecoration |= FDE_CSSTEXTDECORATION_Double; - break; - default: - break; - } - } - return dwDecoration; -} - -FDE_CSSFontVariant CFDE_CSSStyleSelector::ToFontVariant( - FDE_CSSPropertyValue eValue) { - return eValue == FDE_CSSPropertyValue::SmallCaps - ? FDE_CSSFontVariant::SmallCaps - : FDE_CSSFontVariant::Normal; -} diff --git a/xfa/fde/css/cfde_cssstyleselector.h b/xfa/fde/css/cfde_cssstyleselector.h deleted file mode 100644 index 7ead812fd2..0000000000 --- a/xfa/fde/css/cfde_cssstyleselector.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2017 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 - -#ifndef XFA_FDE_CSS_CFDE_CSSSTYLESELECTOR_H_ -#define XFA_FDE_CSS_CFDE_CSSSTYLESELECTOR_H_ - -#include <memory> -#include <vector> - -#include "core/fxcrt/fx_basic.h" -#include "core/fxcrt/fx_system.h" -#include "xfa/fde/css/cfde_cssrulecollection.h" -#include "xfa/fde/css/fde_css.h" - -class CFDE_CSSComputedStyle; -class CFDE_CSSCustomProperty; -class CFDE_CSSDeclaration; -class CFDE_CSSPropertyHolder; -class CFDE_CSSSelector; -class CFDE_CSSStyleSheet; -class CFDE_CSSValue; -class CFDE_CSSValueList; - -class CFDE_CSSStyleSelector { - public: - CFDE_CSSStyleSelector(); - ~CFDE_CSSStyleSelector(); - - void SetDefFontSize(float fFontSize); - void SetUAStyleSheet(std::unique_ptr<CFDE_CSSStyleSheet> pSheet); - void UpdateStyleIndex(); - - CFX_RetainPtr<CFDE_CSSComputedStyle> CreateComputedStyle( - CFDE_CSSComputedStyle* pParentStyle); - - // Note, the dest style has to be an out param because the CXFA_TextParser - // adds non-inherited data from the parent style. Attempting to copy - // internally will fail as you'll lose the non-inherited data. - void ComputeStyle(const std::vector<const CFDE_CSSDeclaration*>& declArray, - const CFX_WideString& styleString, - const CFX_WideString& alignString, - CFDE_CSSComputedStyle* pDestStyle); - - std::vector<const CFDE_CSSDeclaration*> MatchDeclarations( - const CFX_WideString& tagname); - - private: - bool MatchSelector(const CFX_WideString& tagname, CFDE_CSSSelector* pSel); - - void AppendInlineStyle(CFDE_CSSDeclaration* pDecl, - const CFX_WideString& style); - void ApplyDeclarations( - const std::vector<const CFDE_CSSDeclaration*>& declArray, - const CFDE_CSSDeclaration* extraDecl, - CFDE_CSSComputedStyle* pDestStyle); - void ApplyProperty(FDE_CSSProperty eProperty, - const CFX_RetainPtr<CFDE_CSSValue>& pValue, - CFDE_CSSComputedStyle* pComputedStyle); - void ExtractValues(const CFDE_CSSDeclaration* decl, - std::vector<const CFDE_CSSPropertyHolder*>* importants, - std::vector<const CFDE_CSSPropertyHolder*>* normals, - std::vector<const CFDE_CSSCustomProperty*>* custom); - - bool SetLengthWithPercent(FDE_CSSLength& width, - FDE_CSSPrimitiveType eType, - const CFX_RetainPtr<CFDE_CSSValue>& pValue, - float fFontSize); - float ToFontSize(FDE_CSSPropertyValue eValue, float fCurFontSize); - FDE_CSSDisplay ToDisplay(FDE_CSSPropertyValue eValue); - FDE_CSSTextAlign ToTextAlign(FDE_CSSPropertyValue eValue); - uint16_t ToFontWeight(FDE_CSSPropertyValue eValue); - FDE_CSSFontStyle ToFontStyle(FDE_CSSPropertyValue eValue); - FDE_CSSVerticalAlign ToVerticalAlign(FDE_CSSPropertyValue eValue); - uint32_t ToTextDecoration(const CFX_RetainPtr<CFDE_CSSValueList>& pList); - FDE_CSSFontVariant ToFontVariant(FDE_CSSPropertyValue eValue); - - float m_fDefFontSize; - std::unique_ptr<CFDE_CSSStyleSheet> m_UAStyles; - CFDE_CSSRuleCollection m_UARules; -}; - -#endif // XFA_FDE_CSS_CFDE_CSSSTYLESELECTOR_H_ diff --git a/xfa/fde/css/cfde_cssstylesheet.h b/xfa/fde/css/cfde_cssstylesheet.h deleted file mode 100644 index 24bebddcbf..0000000000 --- a/xfa/fde/css/cfde_cssstylesheet.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2017 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 - -#ifndef XFA_FDE_CSS_CFDE_CSSSTYLESHEET_H_ -#define XFA_FDE_CSS_CFDE_CSSSTYLESHEET_H_ - -#include <map> -#include <memory> -#include <vector> - -#include "core/fxcrt/fx_string.h" -#include "xfa/fde/css/cfde_csssyntaxparser.h" - -class CFDE_CSSStyleRule; - -class CFDE_CSSStyleSheet { - public: - CFDE_CSSStyleSheet(); - ~CFDE_CSSStyleSheet(); - - bool LoadBuffer(const wchar_t* pBuffer, int32_t iBufSize); - - int32_t CountRules() const; - CFDE_CSSStyleRule* GetRule(int32_t index) const; - - private: - void Reset(); - FDE_CSSSyntaxStatus LoadStyleRule( - CFDE_CSSSyntaxParser* pSyntax, - std::vector<std::unique_ptr<CFDE_CSSStyleRule>>* ruleArray); - void SkipRuleSet(CFDE_CSSSyntaxParser* pSyntax); - - std::vector<std::unique_ptr<CFDE_CSSStyleRule>> m_RuleArray; - std::map<uint32_t, wchar_t*> m_StringCache; -}; - -#endif // XFA_FDE_CSS_CFDE_CSSSTYLESHEET_H_ diff --git a/xfa/fde/css/cfde_csssyntaxparser.h b/xfa/fde/css/cfde_csssyntaxparser.h deleted file mode 100644 index c17d84aef1..0000000000 --- a/xfa/fde/css/cfde_csssyntaxparser.h +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2017 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 - -#ifndef XFA_FDE_CSS_CFDE_CSSSYNTAXPARSER_H_ -#define XFA_FDE_CSS_CFDE_CSSSYNTAXPARSER_H_ - -#include <stack> - -#include "core/fxcrt/fx_string.h" -#include "xfa/fde/css/cfde_cssexttextbuf.h" -#include "xfa/fde/css/cfde_csstextbuf.h" - -#define FDE_CSSSYNTAXCHECK_AllowCharset 1 -#define FDE_CSSSYNTAXCHECK_AllowImport 2 - -enum class FDE_CSSSyntaxMode { - RuleSet, - Comment, - UnknownRule, - Selector, - PropertyName, - PropertyValue, -}; - -enum class FDE_CSSSyntaxStatus : uint8_t { - Error, - EOS, - None, - StyleRule, - Selector, - DeclOpen, - DeclClose, - PropertyName, - PropertyValue, -}; - -class CFDE_CSSSyntaxParser { - public: - CFDE_CSSSyntaxParser(const wchar_t* pBuffer, int32_t iBufferSize); - CFDE_CSSSyntaxParser(const wchar_t* pBuffer, - int32_t iBufferSize, - int32_t iTextDatSize, - bool bOnlyDeclaration); - ~CFDE_CSSSyntaxParser(); - - FDE_CSSSyntaxStatus DoSyntaxParse(); - CFX_WideStringC GetCurrentString() const; - - protected: - void SwitchMode(FDE_CSSSyntaxMode eMode); - int32_t SwitchToComment(); - - bool RestoreMode(); - bool AppendChar(wchar_t wch); - int32_t SaveTextData(); - bool IsCharsetEnabled() const { - return (m_dwCheck & FDE_CSSSYNTAXCHECK_AllowCharset) != 0; - } - void DisableCharset() { m_dwCheck = FDE_CSSSYNTAXCHECK_AllowImport; } - bool IsImportEnabled() const; - void DisableImport() { m_dwCheck = 0; } - - CFDE_CSSTextBuf m_TextData; - CFDE_CSSExtTextBuf m_TextPlane; - int32_t m_iTextDataLen; - uint32_t m_dwCheck; - FDE_CSSSyntaxMode m_eMode; - FDE_CSSSyntaxStatus m_eStatus; - std::stack<FDE_CSSSyntaxMode> m_ModeStack; -}; - -#endif // XFA_FDE_CSS_CFDE_CSSSYNTAXPARSER_H_ diff --git a/xfa/fde/css/cfde_cssvalue.h b/xfa/fde/css/cfde_cssvalue.h deleted file mode 100644 index 71d254bbea..0000000000 --- a/xfa/fde/css/cfde_cssvalue.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017 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 - -#ifndef XFA_FDE_CSS_CFDE_CSSVALUE_H_ -#define XFA_FDE_CSS_CFDE_CSSVALUE_H_ - -#include "xfa/fde/css/fde_css.h" - -class CFDE_CSSValue : public CFX_Retainable { - public: - FDE_CSSPrimitiveType GetType() const { return m_value; } - - protected: - explicit CFDE_CSSValue(FDE_CSSPrimitiveType type); - - private: - FDE_CSSPrimitiveType m_value; -}; - -#endif // XFA_FDE_CSS_CFDE_CSSVALUE_H_ diff --git a/xfa/fde/css/cfde_cssvaluelist.cpp b/xfa/fde/css/cfde_cssvaluelist.cpp deleted file mode 100644 index 737ffcb045..0000000000 --- a/xfa/fde/css/cfde_cssvaluelist.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2017 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/cfde_cssvaluelist.h" - -#include <utility> - -#include "xfa/fde/css/fde_css.h" - -CFDE_CSSValueList::CFDE_CSSValueList( - std::vector<CFX_RetainPtr<CFDE_CSSValue>>& list) - : CFDE_CSSValue(FDE_CSSPrimitiveType::List), m_ppList(std::move(list)) {} - -CFDE_CSSValueList::~CFDE_CSSValueList() {} - -int32_t CFDE_CSSValueList::CountValues() const { - return m_ppList.size(); -} - -CFX_RetainPtr<CFDE_CSSValue> CFDE_CSSValueList::GetValue(int32_t index) const { - return m_ppList[index]; -} diff --git a/xfa/fde/css/cfde_cssvaluelist.h b/xfa/fde/css/cfde_cssvaluelist.h deleted file mode 100644 index a47f8a3250..0000000000 --- a/xfa/fde/css/cfde_cssvaluelist.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2017 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 - -#ifndef XFA_FDE_CSS_CFDE_CSSVALUELIST_H_ -#define XFA_FDE_CSS_CFDE_CSSVALUELIST_H_ - -#include <vector> - -#include "xfa/fde/css/cfde_cssvalue.h" - -class CFDE_CSSValueList : public CFDE_CSSValue { - public: - explicit CFDE_CSSValueList(std::vector<CFX_RetainPtr<CFDE_CSSValue>>& list); - ~CFDE_CSSValueList() override; - - int32_t CountValues() const; - CFX_RetainPtr<CFDE_CSSValue> GetValue(int32_t index) const; - - protected: - std::vector<CFX_RetainPtr<CFDE_CSSValue>> m_ppList; -}; - -#endif // XFA_FDE_CSS_CFDE_CSSVALUELIST_H_ diff --git a/xfa/fde/css/fde_cssdatatable.cpp b/xfa/fde/css/fde_cssdatatable.cpp deleted file mode 100644 index 79170bc072..0000000000 --- a/xfa/fde/css/fde_cssdatatable.cpp +++ /dev/null @@ -1,285 +0,0 @@ -// Copyright 2014 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_cssdatatable.h" - -#include <utility> - -#include "core/fxcrt/fx_codepage.h" -#include "core/fxcrt/fx_extension.h" -#include "xfa/fde/css/cfde_cssstyleselector.h" -#include "xfa/fde/css/cfde_cssvaluelistparser.h" - -static const FDE_CSSPropertyTable g_FDE_CSSProperties[] = { - {FDE_CSSProperty::BorderLeft, L"border-left", 0x04080036, - FDE_CSSVALUETYPE_Shorthand}, - {FDE_CSSProperty::Top, L"top", 0x0BEDAF33, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::Margin, L"margin", 0x0CB016BE, - FDE_CSSVALUETYPE_List | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::TextIndent, L"text-indent", 0x169ADB74, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::Right, L"right", 0x193ADE3E, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::PaddingLeft, L"padding-left", 0x228CF02F, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::MarginLeft, L"margin-left", 0x297C5656, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeNumber | - FDE_CSSVALUETYPE_MaybeEnum}, - {FDE_CSSProperty::Border, L"border", 0x2A23349E, - FDE_CSSVALUETYPE_Shorthand}, - {FDE_CSSProperty::BorderTop, L"border-top", 0x2B866ADE, - FDE_CSSVALUETYPE_Shorthand}, - {FDE_CSSProperty::Bottom, L"bottom", 0x399F02B5, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::PaddingRight, L"padding-right", 0x3F616AC2, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::BorderBottom, L"border-bottom", 0x452CE780, - FDE_CSSVALUETYPE_Shorthand}, - {FDE_CSSProperty::FontFamily, L"font-family", 0x574686E6, - FDE_CSSVALUETYPE_List | FDE_CSSVALUETYPE_MaybeString}, - {FDE_CSSProperty::FontWeight, L"font-weight", 0x6692F60C, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::Color, L"color", 0x6E67921F, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeColor}, - {FDE_CSSProperty::LetterSpacing, L"letter-spacing", 0x70536102, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::TextAlign, L"text-align", 0x7553F1BD, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum}, - {FDE_CSSProperty::BorderRightWidth, L"border-right-width", 0x8F5A6036, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::VerticalAlign, L"vertical-align", 0x934A87D2, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::PaddingTop, L"padding-top", 0x959D22B7, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::FontVariant, L"font-variant", 0x9C785779, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum}, - {FDE_CSSProperty::BorderWidth, L"border-width", 0xA8DE4FEB, - FDE_CSSVALUETYPE_List | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::BorderBottomWidth, L"border-bottom-width", 0xAE41204D, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::BorderRight, L"border-right", 0xB78E9EA9, - FDE_CSSVALUETYPE_Shorthand}, - {FDE_CSSProperty::FontSize, L"font-size", 0xB93956DF, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::BorderSpacing, L"border-spacing", 0xC72030F0, - FDE_CSSVALUETYPE_List | FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::FontStyle, L"font-style", 0xCB1950F5, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum}, - {FDE_CSSProperty::Font, L"font", 0xCD308B77, FDE_CSSVALUETYPE_Shorthand}, - {FDE_CSSProperty::LineHeight, L"line-height", 0xCFCACE2E, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::MarginRight, L"margin-right", 0xD13C58C9, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeNumber | - FDE_CSSVALUETYPE_MaybeEnum}, - {FDE_CSSProperty::BorderLeftWidth, L"border-left-width", 0xD1E93D83, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::Display, L"display", 0xD4224C36, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum}, - {FDE_CSSProperty::PaddingBottom, L"padding-bottom", 0xE555B3B9, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::BorderTopWidth, L"border-top-width", 0xED2CB62B, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::WordSpacing, L"word-spacing", 0xEDA63BAE, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::Left, L"left", 0xF5AD782B, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeEnum | - FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::TextDecoration, L"text-decoration", 0xF7C634BA, - FDE_CSSVALUETYPE_List | FDE_CSSVALUETYPE_MaybeEnum}, - {FDE_CSSProperty::Padding, L"padding", 0xF8C373F7, - FDE_CSSVALUETYPE_List | FDE_CSSVALUETYPE_MaybeNumber}, - {FDE_CSSProperty::MarginBottom, L"margin-bottom", 0xF93485A0, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeNumber | - FDE_CSSVALUETYPE_MaybeEnum}, - {FDE_CSSProperty::MarginTop, L"margin-top", 0xFE51DCFE, - FDE_CSSVALUETYPE_Primitive | FDE_CSSVALUETYPE_MaybeNumber | - FDE_CSSVALUETYPE_MaybeEnum}, -}; -const int32_t g_iCSSPropertyCount = - sizeof(g_FDE_CSSProperties) / sizeof(FDE_CSSPropertyTable); -static_assert(g_iCSSPropertyCount == - static_cast<int32_t>(FDE_CSSProperty::LAST_MARKER), - "Property table differs in size from property enum"); - -static const FDE_CSSPropertyValueTable g_FDE_CSSPropertyValues[] = { - {FDE_CSSPropertyValue::Bolder, L"bolder", 0x009F1058}, - {FDE_CSSPropertyValue::None, L"none", 0x048B6670}, - {FDE_CSSPropertyValue::Dot, L"dot", 0x0A48CB27}, - {FDE_CSSPropertyValue::Sub, L"sub", 0x0BD37FAA}, - {FDE_CSSPropertyValue::Top, L"top", 0x0BEDAF33}, - {FDE_CSSPropertyValue::Right, L"right", 0x193ADE3E}, - {FDE_CSSPropertyValue::Normal, L"normal", 0x247CF3E9}, - {FDE_CSSPropertyValue::Auto, L"auto", 0x2B35B6D9}, - {FDE_CSSPropertyValue::Text, L"text", 0x2D08AF85}, - {FDE_CSSPropertyValue::XSmall, L"x-small", 0x2D2FCAFE}, - {FDE_CSSPropertyValue::Thin, L"thin", 0x2D574D53}, - {FDE_CSSPropertyValue::Small, L"small", 0x316A3739}, - {FDE_CSSPropertyValue::Bottom, L"bottom", 0x399F02B5}, - {FDE_CSSPropertyValue::Underline, L"underline", 0x3A0273A6}, - {FDE_CSSPropertyValue::Double, L"double", 0x3D98515B}, - {FDE_CSSPropertyValue::Lighter, L"lighter", 0x45BEB7AF}, - {FDE_CSSPropertyValue::Oblique, L"oblique", 0x53EBDDB1}, - {FDE_CSSPropertyValue::Super, L"super", 0x6A4F842F}, - {FDE_CSSPropertyValue::Center, L"center", 0x6C51AFC1}, - {FDE_CSSPropertyValue::XxLarge, L"xx-large", 0x70BB1508}, - {FDE_CSSPropertyValue::Smaller, L"smaller", 0x849769F0}, - {FDE_CSSPropertyValue::Baseline, L"baseline", 0x87436BA3}, - {FDE_CSSPropertyValue::Thick, L"thick", 0x8CC35EB3}, - {FDE_CSSPropertyValue::Justify, L"justify", 0x8D269CAE}, - {FDE_CSSPropertyValue::Middle, L"middle", 0x947FA00F}, - {FDE_CSSPropertyValue::Medium, L"medium", 0xA084A381}, - {FDE_CSSPropertyValue::ListItem, L"list-item", 0xA32382B8}, - {FDE_CSSPropertyValue::XxSmall, L"xx-small", 0xADE1FC76}, - {FDE_CSSPropertyValue::Bold, L"bold", 0xB18313A1}, - {FDE_CSSPropertyValue::SmallCaps, L"small-caps", 0xB299428D}, - {FDE_CSSPropertyValue::Inline, L"inline", 0xC02D649F}, - {FDE_CSSPropertyValue::Overline, L"overline", 0xC0EC9FA4}, - {FDE_CSSPropertyValue::TextBottom, L"text-bottom", 0xC7D08D87}, - {FDE_CSSPropertyValue::Larger, L"larger", 0xCD3C409D}, - {FDE_CSSPropertyValue::InlineTable, L"inline-table", 0xD131F494}, - {FDE_CSSPropertyValue::InlineBlock, L"inline-block", 0xD26A8BD7}, - {FDE_CSSPropertyValue::Blink, L"blink", 0xDC36E390}, - {FDE_CSSPropertyValue::Block, L"block", 0xDCD480AB}, - {FDE_CSSPropertyValue::Italic, L"italic", 0xE31D5396}, - {FDE_CSSPropertyValue::LineThrough, L"line-through", 0xE4C5A276}, - {FDE_CSSPropertyValue::XLarge, L"x-large", 0xF008E390}, - {FDE_CSSPropertyValue::Large, L"large", 0xF4434FCB}, - {FDE_CSSPropertyValue::Left, L"left", 0xF5AD782B}, - {FDE_CSSPropertyValue::TextTop, L"text-top", 0xFCB58D45}, -}; -const int32_t g_iCSSPropertyValueCount = - sizeof(g_FDE_CSSPropertyValues) / sizeof(FDE_CSSPropertyValueTable); -static_assert(g_iCSSPropertyValueCount == - static_cast<int32_t>(FDE_CSSPropertyValue::LAST_MARKER), - "Property value table differs in size from property value enum"); - -static const FDE_CSSLengthUnitTable g_FDE_CSSLengthUnits[] = { - {0x0672, FDE_CSSNumberType::EMS}, - {0x067D, FDE_CSSNumberType::EXS}, - {0x1AF7, FDE_CSSNumberType::Inches}, - {0x2F7A, FDE_CSSNumberType::MilliMeters}, - {0x3ED3, FDE_CSSNumberType::Picas}, - {0x3EE4, FDE_CSSNumberType::Points}, - {0x3EE8, FDE_CSSNumberType::Pixels}, - {0xFC30, FDE_CSSNumberType::CentiMeters}, -}; - -static const FDE_CSSCOLORTABLE g_FDE_CSSColors[] = { - {0x031B47FE, 0xff000080}, {0x0BB8DF5B, 0xffff0000}, - {0x0D82A78C, 0xff800000}, {0x2ACC82E8, 0xff00ffff}, - {0x2D083986, 0xff008080}, {0x4A6A6195, 0xffc0c0c0}, - {0x546A8EF3, 0xff808080}, {0x65C9169C, 0xffffa500}, - {0x8422BB61, 0xffffffff}, {0x9271A558, 0xff800080}, - {0xA65A3EE3, 0xffff00ff}, {0xB1345708, 0xff0000ff}, - {0xB6D2CF1F, 0xff808000}, {0xD19B5E1C, 0xffffff00}, - {0xDB64391D, 0xff000000}, {0xF616D507, 0xff00ff00}, - {0xF6EFFF31, 0xff008000}, -}; - -const FDE_CSSPropertyTable* FDE_GetCSSPropertyByName( - const CFX_WideStringC& wsName) { - ASSERT(!wsName.IsEmpty()); - uint32_t dwHash = FX_HashCode_GetW(wsName, true); - int32_t iEnd = g_iCSSPropertyCount; - int32_t iMid, iStart = 0; - uint32_t dwMid; - do { - iMid = (iStart + iEnd) / 2; - dwMid = g_FDE_CSSProperties[iMid].dwHash; - if (dwHash == dwMid) { - return g_FDE_CSSProperties + iMid; - } else if (dwHash > dwMid) { - iStart = iMid + 1; - } else { - iEnd = iMid - 1; - } - } while (iStart <= iEnd); - return nullptr; -} - -const FDE_CSSPropertyTable* FDE_GetCSSPropertyByEnum(FDE_CSSProperty eName) { - return g_FDE_CSSProperties + static_cast<int>(eName); -} - -const FDE_CSSPropertyValueTable* FDE_GetCSSPropertyValueByName( - const CFX_WideStringC& wsName) { - ASSERT(!wsName.IsEmpty()); - uint32_t dwHash = FX_HashCode_GetW(wsName, true); - int32_t iEnd = g_iCSSPropertyValueCount; - int32_t iMid, iStart = 0; - uint32_t dwMid; - do { - iMid = (iStart + iEnd) / 2; - dwMid = g_FDE_CSSPropertyValues[iMid].dwHash; - if (dwHash == dwMid) { - return g_FDE_CSSPropertyValues + iMid; - } else if (dwHash > dwMid) { - iStart = iMid + 1; - } else { - iEnd = iMid - 1; - } - } while (iStart <= iEnd); - return nullptr; -} - -const FDE_CSSLengthUnitTable* FDE_GetCSSLengthUnitByName( - const CFX_WideStringC& wsName) { - ASSERT(!wsName.IsEmpty()); - uint16_t wHash = FX_HashCode_GetW(wsName, true); - int32_t iEnd = - sizeof(g_FDE_CSSLengthUnits) / sizeof(FDE_CSSLengthUnitTable) - 1; - int32_t iMid, iStart = 0; - uint16_t wMid; - do { - iMid = (iStart + iEnd) / 2; - wMid = g_FDE_CSSLengthUnits[iMid].wHash; - if (wHash == wMid) { - return g_FDE_CSSLengthUnits + iMid; - } else if (wHash > wMid) { - iStart = iMid + 1; - } else { - iEnd = iMid - 1; - } - } while (iStart <= iEnd); - return nullptr; -} - -const FDE_CSSCOLORTABLE* FDE_GetCSSColorByName(const CFX_WideStringC& wsName) { - ASSERT(!wsName.IsEmpty()); - uint32_t dwHash = FX_HashCode_GetW(wsName, true); - int32_t iEnd = sizeof(g_FDE_CSSColors) / sizeof(FDE_CSSCOLORTABLE) - 1; - int32_t iMid, iStart = 0; - uint32_t dwMid; - do { - iMid = (iStart + iEnd) / 2; - dwMid = g_FDE_CSSColors[iMid].dwHash; - if (dwHash == dwMid) { - return g_FDE_CSSColors + iMid; - } else if (dwHash > dwMid) { - iStart = iMid + 1; - } else { - iEnd = iMid - 1; - } - } while (iStart <= iEnd); - return nullptr; -} diff --git a/xfa/fde/css/fde_cssdatatable.h b/xfa/fde/css/fde_cssdatatable.h deleted file mode 100644 index d1745f5d50..0000000000 --- a/xfa/fde/css/fde_cssdatatable.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2014 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 - -#ifndef XFA_FDE_CSS_FDE_CSSDATATABLE_H_ -#define XFA_FDE_CSS_FDE_CSSDATATABLE_H_ - -#include <memory> -#include <vector> - -#include "core/fxcrt/fx_system.h" -#include "xfa/fde/css/cfde_cssnumbervalue.h" -#include "xfa/fde/css/cfde_cssvalue.h" -#include "xfa/fde/css/fde_css.h" - -#define FDE_IsOnlyValue(type, enum) \ - (((type) & ~(enum)) == FDE_CSSVALUETYPE_Primitive) - -struct FDE_CSSPropertyTable { - FDE_CSSProperty eName; - const wchar_t* pszName; - uint32_t dwHash; - uint32_t dwType; -}; - -struct FDE_CSSPropertyValueTable { - FDE_CSSPropertyValue eName; - const wchar_t* pszName; - uint32_t dwHash; -}; - -struct FDE_CSSLengthUnitTable { - uint16_t wHash; - FDE_CSSNumberType wValue; -}; - -struct FDE_CSSCOLORTABLE { - uint32_t dwHash; - FX_ARGB dwValue; -}; - -const FDE_CSSPropertyTable* FDE_GetCSSPropertyByName( - const CFX_WideStringC& wsName); -const FDE_CSSPropertyTable* FDE_GetCSSPropertyByEnum(FDE_CSSProperty eName); - -const FDE_CSSPropertyValueTable* FDE_GetCSSPropertyValueByName( - const CFX_WideStringC& wsName); - -const FDE_CSSLengthUnitTable* FDE_GetCSSLengthUnitByName( - const CFX_WideStringC& wsName); - -const FDE_CSSCOLORTABLE* FDE_GetCSSColorByName(const CFX_WideStringC& wsName); - -#endif // XFA_FDE_CSS_FDE_CSSDATATABLE_H_ diff --git a/xfa/fxfa/cxfa_loadercontext.h b/xfa/fxfa/cxfa_loadercontext.h index 5bf8ed3661..48077ff538 100644 --- a/xfa/fxfa/cxfa_loadercontext.h +++ b/xfa/fxfa/cxfa_loadercontext.h @@ -9,9 +9,9 @@ #include <vector> +#include "core/fxcrt/css/cfx_csscomputedstyle.h" #include "core/fxcrt/fx_basic.h" #include "core/fxcrt/fx_system.h" -#include "xfa/fde/css/cfde_csscomputedstyle.h" class CFX_XMLNode; class CXFA_Node; @@ -32,7 +32,7 @@ class CXFA_LoaderContext { uint32_t m_dwFlags; CFX_XMLNode* m_pXMLNode; CXFA_Node* m_pNode; - CFX_RetainPtr<CFDE_CSSComputedStyle> m_pParentStyle; + CFX_RetainPtr<CFX_CSSComputedStyle> m_pParentStyle; std::vector<float> m_lineHeights; std::vector<float> m_BlocksHeight; }; diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp index 138587c2fc..125c73a11d 100644 --- a/xfa/fxfa/cxfa_textlayout.cpp +++ b/xfa/fxfa/cxfa_textlayout.cpp @@ -9,6 +9,8 @@ #include <algorithm> #include <utility> +#include "core/fxcrt/css/cfx_csscomputedstyle.h" +#include "core/fxcrt/css/cfx_cssstyleselector.h" #include "core/fxcrt/xml/cfx_xmlelement.h" #include "core/fxcrt/xml/cfx_xmlnode.h" #include "core/fxcrt/xml/cfx_xmltext.h" @@ -18,8 +20,6 @@ #include "xfa/fde/cfde_path.h" #include "xfa/fde/cfde_pen.h" #include "xfa/fde/cfde_renderdevice.h" -#include "xfa/fde/css/cfde_csscomputedstyle.h" -#include "xfa/fde/css/cfde_cssstyleselector.h" #include "xfa/fxfa/cxfa_linkuserdata.h" #include "xfa/fxfa/cxfa_loadercontext.h" #include "xfa/fxfa/cxfa_pieceline.h" @@ -155,30 +155,30 @@ void CXFA_TextLayout::InitBreak(float fLineWidth) { m_pBreak->SetLineBreakTolerance(fFontSize * 0.2f); } -void CXFA_TextLayout::InitBreak(CFDE_CSSComputedStyle* pStyle, - FDE_CSSDisplay eDisplay, +void CXFA_TextLayout::InitBreak(CFX_CSSComputedStyle* pStyle, + CFX_CSSDisplay eDisplay, float fLineWidth, CFX_XMLNode* pXMLNode, - CFDE_CSSComputedStyle* pParentStyle) { + CFX_CSSComputedStyle* pParentStyle) { if (!pStyle) { InitBreak(fLineWidth); return; } - if (eDisplay == FDE_CSSDisplay::Block || - eDisplay == FDE_CSSDisplay::ListItem) { + if (eDisplay == CFX_CSSDisplay::Block || + eDisplay == CFX_CSSDisplay::ListItem) { CFX_RTFLineAlignment iAlign = CFX_RTFLineAlignment::Left; switch (pStyle->GetTextAlign()) { - case FDE_CSSTextAlign::Right: + case CFX_CSSTextAlign::Right: iAlign = CFX_RTFLineAlignment::Right; break; - case FDE_CSSTextAlign::Center: + case CFX_CSSTextAlign::Center: iAlign = CFX_RTFLineAlignment::Center; break; - case FDE_CSSTextAlign::Justify: + case CFX_CSSTextAlign::Justify: iAlign = CFX_RTFLineAlignment::Justified; break; - case FDE_CSSTextAlign::JustifyAll: + case CFX_CSSTextAlign::JustifyAll: iAlign = CFX_RTFLineAlignment::Distributed; break; default: @@ -187,8 +187,8 @@ void CXFA_TextLayout::InitBreak(CFDE_CSSComputedStyle* pStyle, m_pBreak->SetAlignment(iAlign); float fStart = 0; - const FDE_CSSRect* pRect = pStyle->GetMarginWidth(); - const FDE_CSSRect* pPaddingRect = pStyle->GetPaddingWidth(); + const CFX_CSSRect* pRect = pStyle->GetMarginWidth(); + const CFX_CSSRect* pPaddingRect = pStyle->GetPaddingWidth(); if (pRect) { fStart = pRect->left.GetValue(); fLineWidth -= pRect->right.GetValue(); @@ -196,9 +196,9 @@ void CXFA_TextLayout::InitBreak(CFDE_CSSComputedStyle* pStyle, fStart += pPaddingRect->left.GetValue(); fLineWidth -= pPaddingRect->right.GetValue(); } - if (eDisplay == FDE_CSSDisplay::ListItem) { - const FDE_CSSRect* pParRect = pParentStyle->GetMarginWidth(); - const FDE_CSSRect* pParPaddingRect = pParentStyle->GetPaddingWidth(); + if (eDisplay == CFX_CSSDisplay::ListItem) { + const CFX_CSSRect* pParRect = pParentStyle->GetMarginWidth(); + const CFX_CSSRect* pParPaddingRect = pParentStyle->GetPaddingWidth(); if (pParRect) { fStart += pParRect->left.GetValue(); fLineWidth -= pParRect->right.GetValue(); @@ -207,11 +207,11 @@ void CXFA_TextLayout::InitBreak(CFDE_CSSComputedStyle* pStyle, fLineWidth -= pParPaddingRect->right.GetValue(); } } - FDE_CSSRect pNewRect; - pNewRect.left.Set(FDE_CSSLengthUnit::Point, fStart); - 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()); + CFX_CSSRect pNewRect; + pNewRect.left.Set(CFX_CSSLengthUnit::Point, fStart); + pNewRect.right.Set(CFX_CSSLengthUnit::Point, pRect->right.GetValue()); + pNewRect.top.Set(CFX_CSSLengthUnit::Point, pRect->top.GetValue()); + pNewRect.bottom.Set(CFX_CSSLengthUnit::Point, pRect->bottom.GetValue()); pStyle->SetMarginWidth(pNewRect); } } @@ -696,7 +696,7 @@ bool CXFA_TextLayout::LoadRichText( CFX_XMLNode* pXMLNode, const CFX_SizeF& szText, float& fLinePos, - const CFX_RetainPtr<CFDE_CSSComputedStyle>& pParentStyle, + const CFX_RetainPtr<CFX_CSSComputedStyle>& pParentStyle, bool bSavePieces, CFX_RetainPtr<CXFA_LinkUserData> pLinkData, bool bEndBreak, @@ -707,10 +707,10 @@ bool CXFA_TextLayout::LoadRichText( CXFA_TextParseContext* pContext = m_textParser.GetParseContextFromMap(pXMLNode); - FDE_CSSDisplay eDisplay = FDE_CSSDisplay::None; + CFX_CSSDisplay eDisplay = CFX_CSSDisplay::None; bool bContentNode = false; float fSpaceBelow = 0; - CFX_RetainPtr<CFDE_CSSComputedStyle> pStyle; + CFX_RetainPtr<CFX_CSSComputedStyle> pStyle; CFX_WideString wsName; if (bEndBreak) { bool bCurOl = false; @@ -733,21 +733,21 @@ bool CXFA_TextLayout::LoadRichText( } if (m_bBlockContinue || bContentNode == false) { eDisplay = pContext->GetDisplay(); - if (eDisplay != FDE_CSSDisplay::Block && - eDisplay != FDE_CSSDisplay::Inline && - eDisplay != FDE_CSSDisplay::ListItem) { + if (eDisplay != CFX_CSSDisplay::Block && + eDisplay != CFX_CSSDisplay::Inline && + eDisplay != CFX_CSSDisplay::ListItem) { return true; } pStyle = m_textParser.ComputeStyle(pXMLNode, pParentStyle.Get()); InitBreak(bContentNode ? pParentStyle.Get() : pStyle.Get(), eDisplay, szText.width, pXMLNode, pParentStyle.Get()); - if ((eDisplay == FDE_CSSDisplay::Block || - eDisplay == FDE_CSSDisplay::ListItem) && + if ((eDisplay == CFX_CSSDisplay::Block || + eDisplay == CFX_CSSDisplay::ListItem) && pStyle && (wsName.IsEmpty() || (wsName != L"body" && wsName != L"html" && wsName != L"ol" && wsName != L"ul"))) { - const FDE_CSSRect* pRect = pStyle->GetMarginWidth(); + const CFX_CSSRect* pRect = pStyle->GetMarginWidth(); if (pRect) { fLinePos += pRect->top.GetValue(); fSpaceBelow = pRect->bottom.GetValue(); @@ -797,9 +797,9 @@ bool CXFA_TextLayout::LoadRichText( (m_pLoader->m_dwFlags & XFA_LOADERCNTXTFLG_FILTERSPACE)) { wsText.TrimLeft(0x20); } - if (FDE_CSSDisplay::Block == eDisplay) { + if (CFX_CSSDisplay::Block == eDisplay) { m_pLoader->m_dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; - } else if (FDE_CSSDisplay::Inline == eDisplay && + } else if (CFX_CSSDisplay::Inline == eDisplay && (m_pLoader->m_dwFlags & XFA_LOADERCNTXTFLG_FILTERSPACE)) { m_pLoader->m_dwFlags &= ~XFA_LOADERCNTXTFLG_FILTERSPACE; } else if (wsText.GetLength() > 0 && @@ -847,7 +847,7 @@ bool CXFA_TextLayout::LoadRichText( } if (m_pLoader) { - if (FDE_CSSDisplay::Block == eDisplay) + if (CFX_CSSDisplay::Block == eDisplay) m_pLoader->m_dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE; } if (bCurLi) @@ -859,11 +859,11 @@ bool CXFA_TextLayout::LoadRichText( if (m_bBlockContinue) { if (pContext && !bContentNode) { - CFX_BreakType dwStatus = (eDisplay == FDE_CSSDisplay::Block) + CFX_BreakType dwStatus = (eDisplay == CFX_CSSDisplay::Block) ? CFX_BreakType::Paragraph : CFX_BreakType::Piece; EndBreak(dwStatus, fLinePos, bSavePieces); - if (eDisplay == FDE_CSSDisplay::Block) { + if (eDisplay == CFX_CSSDisplay::Block) { fLinePos += fSpaceBelow; if (m_pTabstopContext) m_pTabstopContext->RemoveAll(); @@ -952,7 +952,7 @@ void CXFA_TextLayout::EndBreak(CFX_BreakType dwStatus, AppendTextLine(dwStatus, fLinePos, bSavePieces, true); } -void CXFA_TextLayout::DoTabstops(CFDE_CSSComputedStyle* pStyle, +void CXFA_TextLayout::DoTabstops(CFX_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine) { if (!pStyle || !pPieceLine) return; @@ -1015,7 +1015,7 @@ void CXFA_TextLayout::AppendTextLine(CFX_BreakType dwStatus, if (iPieces < 1) return; - CFX_RetainPtr<CFDE_CSSComputedStyle> pStyle; + CFX_RetainPtr<CFX_CSSComputedStyle> pStyle; if (bSavePieces) { auto pNew = pdfium::MakeUnique<CXFA_PieceLine>(); CXFA_PieceLine* pPieceLine = pNew.get(); @@ -1130,7 +1130,7 @@ void CXFA_TextLayout::AppendTextLine(CFX_BreakType dwStatus, if (pStyle) { float fStart = 0; - const FDE_CSSRect* pRect = pStyle->GetMarginWidth(); + const CFX_CSSRect* pRect = pStyle->GetMarginWidth(); if (pRect) fStart = pRect->left.GetValue(); diff --git a/xfa/fxfa/cxfa_textlayout.h b/xfa/fxfa/cxfa_textlayout.h index 079fff8fe2..642fa25dd9 100644 --- a/xfa/fxfa/cxfa_textlayout.h +++ b/xfa/fxfa/cxfa_textlayout.h @@ -10,15 +10,15 @@ #include <memory> #include <vector> +#include "core/fxcrt/css/cfx_css.h" #include "core/fxcrt/fx_basic.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_string.h" -#include "xfa/fde/css/fde_css.h" #include "xfa/fgas/layout/cfx_rtfbreak.h" #include "xfa/fxfa/cxfa_textparser.h" class CFDE_Brush; -class CFDE_CSSComputedStyle; +class CFX_CSSComputedStyle; class CFDE_Pen; class CFDE_RenderDevice; class CFX_XMLNode; @@ -67,11 +67,11 @@ class CXFA_TextLayout { CFX_XMLNode* GetXMLContainerNode(); std::unique_ptr<CFX_RTFBreak> CreateBreak(bool bDefault); void InitBreak(float fLineWidth); - void InitBreak(CFDE_CSSComputedStyle* pStyle, - FDE_CSSDisplay eDisplay, + void InitBreak(CFX_CSSComputedStyle* pStyle, + CFX_CSSDisplay eDisplay, float fLineWidth, CFX_XMLNode* pXMLNode, - CFDE_CSSComputedStyle* pParentStyle = nullptr); + CFX_CSSComputedStyle* pParentStyle = nullptr); bool Loader(const CFX_SizeF& szText, float& fLinePos, bool bSavePieces = true); @@ -82,7 +82,7 @@ class CXFA_TextLayout { bool LoadRichText(CFX_XMLNode* pXMLNode, const CFX_SizeF& szText, float& fLinePos, - const CFX_RetainPtr<CFDE_CSSComputedStyle>& pParentStyle, + const CFX_RetainPtr<CFX_CSSComputedStyle>& pParentStyle, bool bSavePieces, CFX_RetainPtr<CXFA_LinkUserData> pLinkData, bool bEndBreak = true, @@ -116,7 +116,7 @@ class CXFA_TextLayout { FXTEXT_CHARPOS* pCharPos, bool bCharCode = false); bool ToRun(const CXFA_TextPiece* pPiece, FX_RTFTEXTOBJ* tr); - void DoTabstops(CFDE_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine); + void DoTabstops(CFX_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine); bool Layout(int32_t iBlock); int32_t CountBlocks() const; diff --git a/xfa/fxfa/cxfa_textparsecontext.cpp b/xfa/fxfa/cxfa_textparsecontext.cpp index 7231f388e2..bd21afc864 100644 --- a/xfa/fxfa/cxfa_textparsecontext.cpp +++ b/xfa/fxfa/cxfa_textparsecontext.cpp @@ -6,11 +6,11 @@ #include "xfa/fxfa/cxfa_textparsecontext.h" -#include "xfa/fde/css/cfde_csscomputedstyle.h" -#include "xfa/fde/css/cfde_cssdeclaration.h" -#include "xfa/fde/css/cfde_cssstyleselector.h" +#include "core/fxcrt/css/cfx_csscomputedstyle.h" +#include "core/fxcrt/css/cfx_cssdeclaration.h" +#include "core/fxcrt/css/cfx_cssstyleselector.h" CXFA_TextParseContext::CXFA_TextParseContext() - : m_pParentStyle(nullptr), m_eDisplay(FDE_CSSDisplay::None) {} + : m_pParentStyle(nullptr), m_eDisplay(CFX_CSSDisplay::None) {} CXFA_TextParseContext::~CXFA_TextParseContext() {} diff --git a/xfa/fxfa/cxfa_textparsecontext.h b/xfa/fxfa/cxfa_textparsecontext.h index c3236570e5..3cd5710728 100644 --- a/xfa/fxfa/cxfa_textparsecontext.h +++ b/xfa/fxfa/cxfa_textparsecontext.h @@ -10,30 +10,30 @@ #include <utility> #include <vector> +#include "core/fxcrt/css/cfx_css.h" +#include "core/fxcrt/css/cfx_cssdeclaration.h" #include "third_party/base/stl_util.h" -#include "xfa/fde/css/cfde_cssdeclaration.h" -#include "xfa/fde/css/fde_css.h" -class CFDE_CSSComputedStyle; +class CFX_CSSComputedStyle; class CXFA_TextParseContext { public: CXFA_TextParseContext(); ~CXFA_TextParseContext(); - void SetDisplay(FDE_CSSDisplay eDisplay) { m_eDisplay = eDisplay; } - FDE_CSSDisplay GetDisplay() const { return m_eDisplay; } + void SetDisplay(CFX_CSSDisplay eDisplay) { m_eDisplay = eDisplay; } + CFX_CSSDisplay GetDisplay() const { return m_eDisplay; } - void SetDecls(std::vector<const CFDE_CSSDeclaration*>&& decl) { + void SetDecls(std::vector<const CFX_CSSDeclaration*>&& decl) { decls_ = std::move(decl); } - const std::vector<const CFDE_CSSDeclaration*>& GetDecls() { return decls_; } + const std::vector<const CFX_CSSDeclaration*>& GetDecls() { return decls_; } - CFX_RetainPtr<CFDE_CSSComputedStyle> m_pParentStyle; + CFX_RetainPtr<CFX_CSSComputedStyle> m_pParentStyle; private: - std::vector<const CFDE_CSSDeclaration*> decls_; - FDE_CSSDisplay m_eDisplay; + std::vector<const CFX_CSSDeclaration*> decls_; + CFX_CSSDisplay m_eDisplay; }; #endif // XFA_FXFA_CXFA_TEXTPARSECONTEXT_H_ diff --git a/xfa/fxfa/cxfa_textparser.cpp b/xfa/fxfa/cxfa_textparser.cpp index de5490a766..7e16202b16 100644 --- a/xfa/fxfa/cxfa_textparser.cpp +++ b/xfa/fxfa/cxfa_textparser.cpp @@ -10,14 +10,14 @@ #include <utility> #include <vector> +#include "core/fxcrt/css/cfx_css.h" +#include "core/fxcrt/css/cfx_csscomputedstyle.h" +#include "core/fxcrt/css/cfx_cssstyleselector.h" +#include "core/fxcrt/css/cfx_cssstylesheet.h" #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/xml/cfx_xmlelement.h" #include "core/fxcrt/xml/cfx_xmlnode.h" #include "third_party/base/ptr_util.h" -#include "xfa/fde/css/cfde_csscomputedstyle.h" -#include "xfa/fde/css/cfde_cssstyleselector.h" -#include "xfa/fde/css/cfde_cssstylesheet.h" -#include "xfa/fde/css/fde_css.h" #include "xfa/fgas/font/cfgas_fontmgr.h" #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" @@ -56,7 +56,7 @@ void CXFA_TextParser::InitCSSData(CXFA_TextProvider* pTextProvider) { return; if (!m_pSelector) { - m_pSelector = pdfium::MakeUnique<CFDE_CSSStyleSelector>(); + m_pSelector = pdfium::MakeUnique<CFX_CSSStyleSelector>(); CXFA_Font font = pTextProvider->GetFontNode(); m_pSelector->SetDefFontSize(font ? font.GetFontSize() : 10.0f); @@ -71,7 +71,7 @@ void CXFA_TextParser::InitCSSData(CXFA_TextProvider* pTextProvider) { m_pSelector->UpdateStyleIndex(); } -std::unique_ptr<CFDE_CSSStyleSheet> CXFA_TextParser::LoadDefaultSheetStyle() { +std::unique_ptr<CFX_CSSStyleSheet> CXFA_TextParser::LoadDefaultSheetStyle() { static const wchar_t s_pStyle[] = L"html,body,ol,p,ul{display:block}" L"li{display:list-item}" @@ -83,12 +83,12 @@ std::unique_ptr<CFDE_CSSStyleSheet> CXFA_TextParser::LoadDefaultSheetStyle() { L"sup{vertical-align:+15em;font-size:.66em}" L"sub{vertical-align:-15em;font-size:.66em}"; - auto sheet = pdfium::MakeUnique<CFDE_CSSStyleSheet>(); + auto sheet = pdfium::MakeUnique<CFX_CSSStyleSheet>(); return sheet->LoadBuffer(s_pStyle, FXSYS_wcslen(s_pStyle)) ? std::move(sheet) : nullptr; } -CFX_RetainPtr<CFDE_CSSComputedStyle> CXFA_TextParser::CreateRootStyle( +CFX_RetainPtr<CFX_CSSComputedStyle> CXFA_TextParser::CreateRootStyle( CXFA_TextProvider* pTextProvider) { CXFA_Font font = pTextProvider->GetFontNode(); CXFA_Para para = pTextProvider->GetParaNode(); @@ -98,50 +98,50 @@ CFX_RetainPtr<CFDE_CSSComputedStyle> CXFA_TextParser::CreateRootStyle( if (para) { fLineHeight = para.GetLineHeight(); - FDE_CSSLength indent; - indent.Set(FDE_CSSLengthUnit::Point, para.GetTextIndent()); + CFX_CSSLength indent; + indent.Set(CFX_CSSLengthUnit::Point, para.GetTextIndent()); pStyle->SetTextIndent(indent); - FDE_CSSTextAlign hAlign = FDE_CSSTextAlign::Left; + CFX_CSSTextAlign hAlign = CFX_CSSTextAlign::Left; switch (para.GetHorizontalAlign()) { case XFA_ATTRIBUTEENUM_Center: - hAlign = FDE_CSSTextAlign::Center; + hAlign = CFX_CSSTextAlign::Center; break; case XFA_ATTRIBUTEENUM_Right: - hAlign = FDE_CSSTextAlign::Right; + hAlign = CFX_CSSTextAlign::Right; break; case XFA_ATTRIBUTEENUM_Justify: - hAlign = FDE_CSSTextAlign::Justify; + hAlign = CFX_CSSTextAlign::Justify; break; case XFA_ATTRIBUTEENUM_JustifyAll: - hAlign = FDE_CSSTextAlign::JustifyAll; + hAlign = CFX_CSSTextAlign::JustifyAll; break; } 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()); + CFX_CSSRect rtMarginWidth; + rtMarginWidth.left.Set(CFX_CSSLengthUnit::Point, para.GetMarginLeft()); + rtMarginWidth.top.Set(CFX_CSSLengthUnit::Point, para.GetSpaceAbove()); + rtMarginWidth.right.Set(CFX_CSSLengthUnit::Point, para.GetMarginRight()); + rtMarginWidth.bottom.Set(CFX_CSSLengthUnit::Point, para.GetSpaceBelow()); pStyle->SetMarginWidth(rtMarginWidth); } if (font) { pStyle->SetColor(font.GetColor()); - pStyle->SetFontStyle(font.IsItalic() ? FDE_CSSFontStyle::Italic - : FDE_CSSFontStyle::Normal); + pStyle->SetFontStyle(font.IsItalic() ? CFX_CSSFontStyle::Italic + : CFX_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()); + CFX_CSSLength letterSpacing; + letterSpacing.Set(CFX_CSSLengthUnit::Point, font.GetLetterSpacing()); pStyle->SetLetterSpacing(letterSpacing); uint32_t dwDecoration = 0; if (font.GetLineThrough() > 0) - dwDecoration |= FDE_CSSTEXTDECORATION_LineThrough; + dwDecoration |= CFX_CSSTEXTDECORATION_LineThrough; if (font.GetUnderline() > 1) - dwDecoration |= FDE_CSSTEXTDECORATION_Double; + dwDecoration |= CFX_CSSTEXTDECORATION_Double; else if (font.GetUnderline() > 0) - dwDecoration |= FDE_CSSTEXTDECORATION_Underline; + dwDecoration |= CFX_CSSTEXTDECORATION_Underline; pStyle->SetTextDecoration(dwDecoration); } @@ -150,8 +150,8 @@ CFX_RetainPtr<CFDE_CSSComputedStyle> CXFA_TextParser::CreateRootStyle( return pStyle; } -CFX_RetainPtr<CFDE_CSSComputedStyle> CXFA_TextParser::CreateStyle( - CFDE_CSSComputedStyle* pParentStyle) { +CFX_RetainPtr<CFX_CSSComputedStyle> CXFA_TextParser::CreateStyle( + CFX_CSSComputedStyle* pParentStyle) { auto pNewStyle = m_pSelector->CreateComputedStyle(pParentStyle); ASSERT(pNewStyle); if (!pParentStyle) @@ -159,21 +159,21 @@ CFX_RetainPtr<CFDE_CSSComputedStyle> CXFA_TextParser::CreateStyle( uint32_t dwDecoration = pParentStyle->GetTextDecoration(); float fBaseLine = 0; - if (pParentStyle->GetVerticalAlign() == FDE_CSSVerticalAlign::Number) + if (pParentStyle->GetVerticalAlign() == CFX_CSSVerticalAlign::Number) fBaseLine = pParentStyle->GetNumberVerticalAlign(); pNewStyle->SetTextDecoration(dwDecoration); pNewStyle->SetNumberVerticalAlign(fBaseLine); - const FDE_CSSRect* pRect = pParentStyle->GetMarginWidth(); + const CFX_CSSRect* pRect = pParentStyle->GetMarginWidth(); if (pRect) pNewStyle->SetMarginWidth(*pRect); return pNewStyle; } -CFX_RetainPtr<CFDE_CSSComputedStyle> CXFA_TextParser::ComputeStyle( +CFX_RetainPtr<CFX_CSSComputedStyle> CXFA_TextParser::ComputeStyle( CFX_XMLNode* pXMLNode, - CFDE_CSSComputedStyle* pParentStyle) { + CFX_CSSComputedStyle* pParentStyle) { auto it = m_mapXMLNodeToParseContext.find(pXMLNode); if (it == m_mapXMLNodeToParseContext.end()) return nullptr; @@ -207,7 +207,7 @@ void CXFA_TextParser::DoParse(CFX_XMLNode* pXMLContainer, } void CXFA_TextParser::ParseRichText(CFX_XMLNode* pXMLNode, - CFDE_CSSComputedStyle* pParentStyle) { + CFX_CSSComputedStyle* pParentStyle) { if (!pXMLNode) return; @@ -215,11 +215,11 @@ void CXFA_TextParser::ParseRichText(CFX_XMLNode* pXMLNode, if (!tagProvider->m_bTagAvailable) return; - CFX_RetainPtr<CFDE_CSSComputedStyle> pNewStyle; + CFX_RetainPtr<CFX_CSSComputedStyle> pNewStyle; if ((tagProvider->GetTagName() != L"body") || (tagProvider->GetTagName() != L"html")) { auto pTextContext = pdfium::MakeUnique<CXFA_TextParseContext>(); - FDE_CSSDisplay eDisplay = FDE_CSSDisplay::Inline; + CFX_CSSDisplay eDisplay = CFX_CSSDisplay::Inline; if (!tagProvider->m_bContent) { auto declArray = m_pSelector->MatchDeclarations(tagProvider->GetTagName()); @@ -292,21 +292,21 @@ int32_t CXFA_TextParser::GetVAlign(CXFA_TextProvider* pTextProvider) const { return para ? para.GetVerticalAlign() : XFA_ATTRIBUTEENUM_Top; } -float CXFA_TextParser::GetTabInterval(CFDE_CSSComputedStyle* pStyle) const { +float CXFA_TextParser::GetTabInterval(CFX_CSSComputedStyle* pStyle) const { CFX_WideString wsValue; if (pStyle && pStyle->GetCustomStyle(L"tab-interval", wsValue)) return CXFA_Measurement(wsValue.AsStringC()).ToUnit(XFA_UNIT_Pt); return 36; } -int32_t CXFA_TextParser::CountTabs(CFDE_CSSComputedStyle* pStyle) const { +int32_t CXFA_TextParser::CountTabs(CFX_CSSComputedStyle* pStyle) const { CFX_WideString wsValue; if (pStyle && pStyle->GetCustomStyle(L"xfa-tab-count", wsValue)) return wsValue.GetInteger(); return 0; } -bool CXFA_TextParser::IsSpaceRun(CFDE_CSSComputedStyle* pStyle) const { +bool CXFA_TextParser::IsSpaceRun(CFX_CSSComputedStyle* pStyle) const { CFX_WideString wsValue; if (pStyle && pStyle->GetCustomStyle(L"xfa-spacerun", wsValue)) { wsValue.MakeLower(); @@ -317,7 +317,7 @@ bool CXFA_TextParser::IsSpaceRun(CFDE_CSSComputedStyle* pStyle) const { CFX_RetainPtr<CFGAS_GEFont> CXFA_TextParser::GetFont( CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const { + CFX_CSSComputedStyle* pStyle) const { CFX_WideStringC wsFamily = L"Courier"; uint32_t dwStyle = 0; CXFA_Font font = pTextProvider->GetFontNode(); @@ -337,7 +337,7 @@ CFX_RetainPtr<CFGAS_GEFont> CXFA_TextParser::GetFont( dwStyle = 0; if (pStyle->GetFontWeight() > FXFONT_FW_NORMAL) dwStyle |= FX_FONTSTYLE_Bold; - if (pStyle->GetFontStyle() == FDE_CSSFontStyle::Italic) + if (pStyle->GetFontStyle() == CFX_CSSFontStyle::Italic) dwStyle |= FX_FONTSTYLE_Italic; } @@ -347,7 +347,7 @@ CFX_RetainPtr<CFGAS_GEFont> CXFA_TextParser::GetFont( } float CXFA_TextParser::GetFontSize(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const { + CFX_CSSComputedStyle* pStyle) const { if (pStyle) return pStyle->GetFontSize(); @@ -358,7 +358,7 @@ float CXFA_TextParser::GetFontSize(CXFA_TextProvider* pTextProvider, } int32_t CXFA_TextParser::GetHorScale(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, + CFX_CSSComputedStyle* pStyle, CFX_XMLNode* pXMLNode) const { if (pStyle) { CFX_WideString wsValue; @@ -385,7 +385,7 @@ int32_t CXFA_TextParser::GetHorScale(CXFA_TextProvider* pTextProvider, } int32_t CXFA_TextParser::GetVerScale(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const { + CFX_CSSComputedStyle* pStyle) const { if (pStyle) { CFX_WideString wsValue; if (pStyle->GetCustomStyle(L"xfa-font-vertical-scale", wsValue)) @@ -398,7 +398,7 @@ int32_t CXFA_TextParser::GetVerScale(CXFA_TextProvider* pTextProvider, } void CXFA_TextParser::GetUnderline(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, + CFX_CSSComputedStyle* pStyle, int32_t& iUnderline, int32_t& iPeriod) const { iUnderline = 0; @@ -413,9 +413,9 @@ void CXFA_TextParser::GetUnderline(CXFA_TextProvider* pTextProvider, } uint32_t dwDecoration = pStyle->GetTextDecoration(); - if (dwDecoration & FDE_CSSTEXTDECORATION_Double) + if (dwDecoration & CFX_CSSTEXTDECORATION_Double) iUnderline = 2; - else if (dwDecoration & FDE_CSSTEXTDECORATION_Underline) + else if (dwDecoration & CFX_CSSTEXTDECORATION_Underline) iUnderline = 1; CFX_WideString wsValue; @@ -428,11 +428,11 @@ void CXFA_TextParser::GetUnderline(CXFA_TextProvider* pTextProvider, } void CXFA_TextParser::GetLinethrough(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, + CFX_CSSComputedStyle* pStyle, int32_t& iLinethrough) const { if (pStyle) { uint32_t dwDecoration = pStyle->GetTextDecoration(); - iLinethrough = (dwDecoration & FDE_CSSTEXTDECORATION_LineThrough) ? 1 : 0; + iLinethrough = (dwDecoration & CFX_CSSTEXTDECORATION_LineThrough) ? 1 : 0; return; } @@ -442,7 +442,7 @@ void CXFA_TextParser::GetLinethrough(CXFA_TextProvider* pTextProvider, } FX_ARGB CXFA_TextParser::GetColor(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const { + CFX_CSSComputedStyle* pStyle) const { if (pStyle) return pStyle->GetColor(); if (CXFA_Font font = pTextProvider->GetFontNode()) @@ -452,9 +452,9 @@ FX_ARGB CXFA_TextParser::GetColor(CXFA_TextProvider* pTextProvider, } float CXFA_TextParser::GetBaseline(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const { + CFX_CSSComputedStyle* pStyle) const { if (pStyle) { - if (pStyle->GetVerticalAlign() == FDE_CSSVerticalAlign::Number) + if (pStyle->GetVerticalAlign() == CFX_CSSVerticalAlign::Number) return pStyle->GetNumberVerticalAlign(); } else if (CXFA_Font font = pTextProvider->GetFontNode()) { return font.GetBaselineShift(); @@ -463,7 +463,7 @@ float CXFA_TextParser::GetBaseline(CXFA_TextProvider* pTextProvider, } float CXFA_TextParser::GetLineHeight(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, + CFX_CSSComputedStyle* pStyle, bool bFirst, float fVerScale) const { float fLineHeight = 0; @@ -532,7 +532,7 @@ CXFA_TextParseContext* CXFA_TextParser::GetParseContextFromMap( return it != m_mapXMLNodeToParseContext.end() ? it->second.get() : nullptr; } -bool CXFA_TextParser::GetTabstops(CFDE_CSSComputedStyle* pStyle, +bool CXFA_TextParser::GetTabstops(CFX_CSSComputedStyle* pStyle, CXFA_TextTabstopsContext* pTabstopContext) { if (!pStyle || !pTabstopContext) return false; diff --git a/xfa/fxfa/cxfa_textparser.h b/xfa/fxfa/cxfa_textparser.h index 303b10ce07..567aff0189 100644 --- a/xfa/fxfa/cxfa_textparser.h +++ b/xfa/fxfa/cxfa_textparser.h @@ -16,9 +16,9 @@ #include "core/fxge/fx_dib.h" #include "xfa/fgas/font/cfgas_gefont.h" -class CFDE_CSSComputedStyle; -class CFDE_CSSStyleSelector; -class CFDE_CSSStyleSheet; +class CFX_CSSComputedStyle; +class CFX_CSSStyleSelector; +class CFX_CSSStyleSheet; class CFX_XMLNode; class CXFA_TextParseContext; class CXFA_TextProvider; @@ -32,47 +32,47 @@ class CXFA_TextParser { void Reset(); void DoParse(CFX_XMLNode* pXMLContainer, CXFA_TextProvider* pTextProvider); - CFX_RetainPtr<CFDE_CSSComputedStyle> CreateRootStyle( + CFX_RetainPtr<CFX_CSSComputedStyle> CreateRootStyle( CXFA_TextProvider* pTextProvider); - CFX_RetainPtr<CFDE_CSSComputedStyle> ComputeStyle( + CFX_RetainPtr<CFX_CSSComputedStyle> ComputeStyle( CFX_XMLNode* pXMLNode, - CFDE_CSSComputedStyle* pParentStyle); + CFX_CSSComputedStyle* pParentStyle); bool IsParsed() const { return m_bParsed; } int32_t GetVAlign(CXFA_TextProvider* pTextProvider) const; - float GetTabInterval(CFDE_CSSComputedStyle* pStyle) const; - int32_t CountTabs(CFDE_CSSComputedStyle* pStyle) const; + float GetTabInterval(CFX_CSSComputedStyle* pStyle) const; + int32_t CountTabs(CFX_CSSComputedStyle* pStyle) const; - bool IsSpaceRun(CFDE_CSSComputedStyle* pStyle) const; - bool GetTabstops(CFDE_CSSComputedStyle* pStyle, + bool IsSpaceRun(CFX_CSSComputedStyle* pStyle) const; + bool GetTabstops(CFX_CSSComputedStyle* pStyle, CXFA_TextTabstopsContext* pTabstopContext); CFX_RetainPtr<CFGAS_GEFont> GetFont(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const; + CFX_CSSComputedStyle* pStyle) const; float GetFontSize(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const; + CFX_CSSComputedStyle* pStyle) const; int32_t GetHorScale(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, + CFX_CSSComputedStyle* pStyle, CFX_XMLNode* pXMLNode) const; int32_t GetVerScale(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const; + CFX_CSSComputedStyle* pStyle) const; void GetUnderline(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, + CFX_CSSComputedStyle* pStyle, int32_t& iUnderline, int32_t& iPeriod) const; void GetLinethrough(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, + CFX_CSSComputedStyle* pStyle, int32_t& iLinethrough) const; FX_ARGB GetColor(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const; + CFX_CSSComputedStyle* pStyle) const; float GetBaseline(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle) const; + CFX_CSSComputedStyle* pStyle) const; float GetLineHeight(CXFA_TextProvider* pTextProvider, - CFDE_CSSComputedStyle* pStyle, + CFX_CSSComputedStyle* pStyle, bool bFirst, float fVerScale) const; @@ -111,16 +111,15 @@ class CXFA_TextParser { }; void InitCSSData(CXFA_TextProvider* pTextProvider); - void ParseRichText(CFX_XMLNode* pXMLNode, - CFDE_CSSComputedStyle* pParentStyle); + void ParseRichText(CFX_XMLNode* pXMLNode, CFX_CSSComputedStyle* pParentStyle); std::unique_ptr<TagProvider> ParseTagInfo(CFX_XMLNode* pXMLNode); - std::unique_ptr<CFDE_CSSStyleSheet> LoadDefaultSheetStyle(); - CFX_RetainPtr<CFDE_CSSComputedStyle> CreateStyle( - CFDE_CSSComputedStyle* pParentStyle); + std::unique_ptr<CFX_CSSStyleSheet> LoadDefaultSheetStyle(); + CFX_RetainPtr<CFX_CSSComputedStyle> CreateStyle( + CFX_CSSComputedStyle* pParentStyle); bool m_bParsed; bool m_cssInitialized; - std::unique_ptr<CFDE_CSSStyleSelector> m_pSelector; + std::unique_ptr<CFX_CSSStyleSelector> m_pSelector; std::map<CFX_XMLNode*, std::unique_ptr<CXFA_TextParseContext>> m_mapXMLNodeToParseContext; }; diff --git a/xfa/fxfa/cxfa_textuserdata.cpp b/xfa/fxfa/cxfa_textuserdata.cpp index 4cec6b300a..51a2f43194 100644 --- a/xfa/fxfa/cxfa_textuserdata.cpp +++ b/xfa/fxfa/cxfa_textuserdata.cpp @@ -6,17 +6,17 @@ #include "xfa/fxfa/cxfa_textuserdata.h" -#include "xfa/fde/css/cfde_csscomputedstyle.h" -#include "xfa/fde/css/cfde_cssstyleselector.h" -#include "xfa/fde/css/fde_css.h" +#include "core/fxcrt/css/cfx_css.h" +#include "core/fxcrt/css/cfx_csscomputedstyle.h" +#include "core/fxcrt/css/cfx_cssstyleselector.h" #include "xfa/fxfa/cxfa_linkuserdata.h" CXFA_TextUserData::CXFA_TextUserData( - const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle) + const CFX_RetainPtr<CFX_CSSComputedStyle>& pStyle) : m_pStyle(pStyle) {} CXFA_TextUserData::CXFA_TextUserData( - const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle, + const CFX_RetainPtr<CFX_CSSComputedStyle>& pStyle, const CFX_RetainPtr<CXFA_LinkUserData>& pLinkData) : m_pStyle(pStyle), m_pLinkData(pLinkData) {} diff --git a/xfa/fxfa/cxfa_textuserdata.h b/xfa/fxfa/cxfa_textuserdata.h index c9e90aa40f..f84e768166 100644 --- a/xfa/fxfa/cxfa_textuserdata.h +++ b/xfa/fxfa/cxfa_textuserdata.h @@ -10,7 +10,7 @@ #include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_basic.h" -class CFDE_CSSComputedStyle; +class CFX_CSSComputedStyle; class CXFA_LinkUserData; class CXFA_TextUserData : public CFX_Retainable { @@ -18,13 +18,12 @@ class CXFA_TextUserData : public CFX_Retainable { template <typename T, typename... Args> friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); - CFX_RetainPtr<CFDE_CSSComputedStyle> m_pStyle; + CFX_RetainPtr<CFX_CSSComputedStyle> m_pStyle; CFX_RetainPtr<CXFA_LinkUserData> m_pLinkData; private: - explicit CXFA_TextUserData( - const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle); - CXFA_TextUserData(const CFX_RetainPtr<CFDE_CSSComputedStyle>& pStyle, + explicit CXFA_TextUserData(const CFX_RetainPtr<CFX_CSSComputedStyle>& pStyle); + CXFA_TextUserData(const CFX_RetainPtr<CFX_CSSComputedStyle>& pStyle, const CFX_RetainPtr<CXFA_LinkUserData>& pLinkData); ~CXFA_TextUserData() override; }; |