summaryrefslogtreecommitdiff
path: root/writerfilter/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-09-27 11:10:13 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-09-27 12:21:16 +0200
commit9ef18582310d6f397a811dc5cc3c2cc1c64076ac (patch)
tree61e6e76fd9d20e9a3d71ea14cbe62e94a8344bc7 /writerfilter/source
parent1b7c53db87bb67eeb2591fbb186f7ac20eb00c68 (diff)
sw: paragraph styles: add DOCX filter for a linked character style
And the same in the other direction: link a para style from a char style. This gets the info out of the grab-bag, so later we can store it also in ODF. No new tests, the existing testStyleInheritance in CppunitTest_sw_ooxmlexport3 covers this refactor. Change-Id: I5ada7ea471a253204984ae0466bd0f8ad70046e2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122681 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'writerfilter/source')
-rw-r--r--writerfilter/source/dmapper/StyleSheetTable.cxx43
-rw-r--r--writerfilter/source/dmapper/StyleSheetTable.hxx1
2 files changed, 37 insertions, 7 deletions
diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx b/writerfilter/source/dmapper/StyleSheetTable.cxx
index f1d1df4496b5..1464f3ae4082 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.cxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.cxx
@@ -75,6 +75,7 @@ TableStyleSheetEntry::TableStyleSheetEntry( StyleSheetEntry const & rEntry )
nStyleTypeCode = STYLE_TYPE_TABLE;
sBaseStyleIdentifier = rEntry.sBaseStyleIdentifier;
sNextStyleIdentifier = rEntry.sNextStyleIdentifier;
+ sLinkStyleIdentifier = rEntry.sLinkStyleIdentifier;
sStyleName = rEntry.sStyleName;
sStyleIdentifierD = rEntry.sStyleIdentifierD;
}
@@ -556,6 +557,9 @@ void StyleSheetTable::lcl_sprm(Sprm & rSprm)
pTableEntry->AppendInteropGrabBag(aValue);
}
break;
+ case NS_ooxml::LN_CT_Style_link:
+ m_pImpl->m_pCurrentEntry->sLinkStyleIdentifier = sStringValue;
+ break;
case NS_ooxml::LN_CT_Style_next:
m_pImpl->m_pCurrentEntry->sNextStyleIdentifier = sStringValue;
break;
@@ -591,7 +595,6 @@ void StyleSheetTable::lcl_sprm(Sprm & rSprm)
case NS_ooxml::LN_CT_Style_semiHidden:
case NS_ooxml::LN_CT_Style_unhideWhenUsed:
case NS_ooxml::LN_CT_Style_uiPriority:
- case NS_ooxml::LN_CT_Style_link:
case NS_ooxml::LN_CT_Style_locked:
if (m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN)
{
@@ -626,12 +629,6 @@ void StyleSheetTable::lcl_sprm(Sprm & rSprm)
aValue.Value <<= OUString::number(nIntValue);
}
break;
- case NS_ooxml::LN_CT_Style_link:
- {
- aValue.Name = "link";
- aValue.Value <<= sStringValue;
- }
- break;
case NS_ooxml::LN_CT_Style_locked:
aValue.Name = "locked";
break;
@@ -1006,6 +1003,7 @@ void StyleSheetTable::ApplyStyleSheets( const FontTablePtr& rFontTable )
{
std::vector< ::std::pair<OUString, uno::Reference<style::XStyle>> > aMissingParent;
std::vector< ::std::pair<OUString, uno::Reference<style::XStyle>> > aMissingFollow;
+ std::vector<std::pair<OUString, uno::Reference<style::XStyle>>> aMissingLink;
std::vector<beans::PropertyValue> aTableStylesVec;
for( auto& pEntry : m_pImpl->m_aStyleSheetEntries )
{
@@ -1015,6 +1013,7 @@ void StyleSheetTable::ApplyStyleSheets( const FontTablePtr& rFontTable )
if( pEntry->nStyleTypeCode == STYLE_TYPE_CHAR || pEntry->nStyleTypeCode == STYLE_TYPE_PARA || pEntry->nStyleTypeCode == STYLE_TYPE_LIST )
{
bool bParaStyle = pEntry->nStyleTypeCode == STYLE_TYPE_PARA;
+ bool bCharStyle = pEntry->nStyleTypeCode == STYLE_TYPE_CHAR;
bool bListStyle = pEntry->nStyleTypeCode == STYLE_TYPE_LIST;
bool bInsert = false;
uno::Reference< container::XNameContainer > xStyles = bParaStyle ? xParaStyles : (bListStyle ? xNumberingStyles : xCharStyles);
@@ -1137,6 +1136,19 @@ void StyleSheetTable::ApplyStyleSheets( const FontTablePtr& rFontTable )
auto aPropValues = comphelper::sequenceToContainer< std::vector<beans::PropertyValue> >(pEntry->pProperties->GetPropertyValues());
+ if (bParaStyle || bCharStyle)
+ {
+ // delay adding LinkStyle property: all styles need to be created first
+ if (!pEntry->sLinkStyleIdentifier.isEmpty())
+ {
+ StyleSheetEntryPtr pLinkStyle
+ = FindStyleSheetByISTD(pEntry->sLinkStyleIdentifier);
+ if (pLinkStyle && !pLinkStyle->sStyleName.isEmpty())
+ aMissingLink.emplace_back(ConvertStyleName(pLinkStyle->sStyleName),
+ xStyle);
+ }
+ }
+
if( bParaStyle )
{
// delay adding FollowStyle property: all styles need to be created first
@@ -1320,6 +1332,23 @@ void StyleSheetTable::ApplyStyleSheets( const FontTablePtr& rFontTable )
catch( uno::Exception & ) {}
}
+ // Update the styles that were created before their linked styles.
+ for (auto const& rLinked : aMissingLink)
+ {
+ try
+ {
+ uno::Reference<beans::XPropertySet> xPropertySet(rLinked.second,
+ uno::UNO_QUERY);
+ xPropertySet->setPropertyValue("LinkStyle", uno::makeAny(rLinked.first));
+ }
+ catch (uno::Exception&)
+ {
+ TOOLS_WARN_EXCEPTION(
+ "writerfilter",
+ "StyleSheetTable::ApplyStyleSheets: failed to set LinkStyle");
+ }
+ }
+
if (!aTableStylesVec.empty())
{
// If we had any table styles, add a new document-level InteropGrabBag entry for them.
diff --git a/writerfilter/source/dmapper/StyleSheetTable.hxx b/writerfilter/source/dmapper/StyleSheetTable.hxx
index b0dd24fa6efa..5dcf84b789bb 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.hxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.hxx
@@ -58,6 +58,7 @@ public:
StyleType nStyleTypeCode; //sgc
OUString sBaseStyleIdentifier;
OUString sNextStyleIdentifier;
+ OUString sLinkStyleIdentifier;
OUString sStyleName;
const tools::SvRef<StyleSheetPropertyMap> pProperties;
OUString sConvertedStyleName;