From 49b5466f59a3288bb94c2d02147e214bbcacbf37 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 20 Jan 2023 12:15:48 +0100 Subject: sw HTML import: initial CSS support on tables This is the import side of commit 6ce374140f3bd1cede959ccc8da69fdacecff191 (sw XHTML export: use CSS instead of
for tables, 2023-01-19), otherwise the import would not handle the new markup of the export. Change-Id: I7d18b06e10adff877dbbf1745861c65a07f807cb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145863 Reviewed-by: Miklos Vajna Tested-by: Jenkins (cherry picked from commit 44c75d56cd441ad3d174db75a6e5ae672b7d2a08) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145946 Reviewed-by: Xisco Fauli --- sw/source/filter/html/htmltab.cxx | 29 +++++++++++++++++++++++++++++ sw/source/filter/html/svxcss1.cxx | 16 ++++++++++++++++ sw/source/filter/html/svxcss1.hxx | 2 ++ 3 files changed, 47 insertions(+) (limited to 'sw/source/filter/html') diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx index fe55cec381ac..7913cd9e85fa 100644 --- a/sw/source/filter/html/htmltab.cxx +++ b/sw/source/filter/html/htmltab.cxx @@ -4917,6 +4917,35 @@ std::shared_ptr SwHTMLParser::BuildTable(SvxAdjust eParentAdjust, else { m_xTable.reset(); + + // Parse CSS on the table. + OUString aStyle; + const HTMLOptions& rHTMLOptions = GetOptions(); + for (size_t i = rHTMLOptions.size(); i;) + { + const HTMLOption& rOption = rHTMLOptions[--i]; + if (rOption.GetToken() == HtmlOptionId::STYLE) + { + aStyle = rOption.GetString(); + } + } + if (!aStyle.isEmpty()) + { + // Have inline CSS. + SfxItemSet aItemSet(m_xDoc->GetAttrPool(), m_pCSS1Parser->GetWhichMap()); + SvxCSS1PropertyInfo aPropInfo; + if (ParseStyleOptions(aStyle, /*aId=*/OUString(), /*aClass=*/OUString(), aItemSet, + aPropInfo)) + { + if (aPropInfo.m_eLeftMarginType == SVX_CSS1_LTYPE_AUTO + && aPropInfo.m_eRightMarginType == SVX_CSS1_LTYPE_AUTO) + { + // Both left & right is set to auto: that's our center. + eParentAdjust = SvxAdjust::Center; + } + } + } + HTMLTableOptions aTableOptions(GetOptions(), eParentAdjust); if (!aTableOptions.aId.isEmpty()) diff --git a/sw/source/filter/html/svxcss1.cxx b/sw/source/filter/html/svxcss1.cxx index 256656a6df1e..9b312e0b3239 100644 --- a/sw/source/filter/html/svxcss1.cxx +++ b/sw/source/filter/html/svxcss1.cxx @@ -399,6 +399,8 @@ SvxCSS1PropertyInfo::SvxCSS1PropertyInfo( const SvxCSS1PropertyInfo& rProp ) : m_eTopType( rProp.m_eTopType ), m_eWidthType( rProp.m_eWidthType ), m_eHeightType( rProp.m_eHeightType ), + m_eLeftMarginType( rProp.m_eLeftMarginType ), + m_eRightMarginType( rProp.m_eRightMarginType ), m_eSizeType( rProp.m_eSizeType ), m_ePageBreakBefore( rProp.m_ePageBreakBefore ), m_ePageBreakAfter( rProp.m_ePageBreakAfter ) @@ -438,6 +440,8 @@ void SvxCSS1PropertyInfo::Clear() m_nLeft = m_nTop = m_nWidth = m_nHeight = 0; m_eLeftType = m_eTopType = m_eWidthType = m_eHeightType = SVX_CSS1_LTYPE_NONE; + m_eLeftMarginType = SVX_CSS1_LTYPE_NONE; + m_eRightMarginType = SVX_CSS1_LTYPE_NONE; // Feature: PrintExt m_eSizeType = SVX_CSS1_STYPE_NONE; @@ -2042,6 +2046,12 @@ static void ParseCSS1_margin_left( const CSS1Expression *pExpr, ; } + if (pExpr->GetString() == "auto") + { + rPropInfo.m_bLeftMargin = true; + rPropInfo.m_eLeftMarginType = SVX_CSS1_LTYPE_AUTO; + } + if( !bSet ) return; @@ -2099,6 +2109,12 @@ static void ParseCSS1_margin_right( const CSS1Expression *pExpr, ; } + if (pExpr->GetString() == "auto") + { + rPropInfo.m_bRightMargin = true; + rPropInfo.m_eRightMarginType = SVX_CSS1_LTYPE_AUTO; + } + if( !bSet ) return; diff --git a/sw/source/filter/html/svxcss1.hxx b/sw/source/filter/html/svxcss1.hxx index 0ca92f314ea9..30c5a7b4accb 100644 --- a/sw/source/filter/html/svxcss1.hxx +++ b/sw/source/filter/html/svxcss1.hxx @@ -136,6 +136,8 @@ public: SvxCSS1LengthType m_eLeftType, m_eTopType; SvxCSS1LengthType m_eWidthType, m_eHeightType; + SvxCSS1LengthType m_eLeftMarginType; + SvxCSS1LengthType m_eRightMarginType; SvxCSS1SizeType m_eSizeType; -- cgit