diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-01-20 12:15:48 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-01-27 08:57:28 +0100 |
commit | 49b5466f59a3288bb94c2d02147e214bbcacbf37 (patch) | |
tree | 7bdc6b759c0e591cc265681efbc7ab41d5dc2e79 /sw/source/filter/html | |
parent | 76d63bb1f6385175238ab3a44f0aa3d877df4c79 (diff) |
sw HTML import: initial CSS support on tables
This is the import side of commit
6ce374140f3bd1cede959ccc8da69fdacecff191 (sw XHTML export: use CSS
instead of <center> 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 <vmiklos@collabora.com>
Tested-by: Jenkins
(cherry picked from commit 44c75d56cd441ad3d174db75a6e5ae672b7d2a08)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145946
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'sw/source/filter/html')
-rw-r--r-- | sw/source/filter/html/htmltab.cxx | 29 | ||||
-rw-r--r-- | sw/source/filter/html/svxcss1.cxx | 16 | ||||
-rw-r--r-- | sw/source/filter/html/svxcss1.hxx | 2 |
3 files changed, 47 insertions, 0 deletions
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<HTMLTable> 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; |