summaryrefslogtreecommitdiff
path: root/writerperfect/source/writer/exp/txtparai.cxx
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-09-06 15:35:40 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-09-06 18:08:55 +0200
commitfe4c6063ec493c986f810ba676e2b12fe7dab7a9 (patch)
tree956e97b7005bca48cffe953676a3e1211a088c68 /writerperfect/source/writer/exp/txtparai.cxx
parentac38af2bb850abab0039d7c9e35644752cf4feb1 (diff)
EPUB export: handle style parents for named styles
Character / paragraph formatting from a style hierarchy should be OK now. Also this time test the actual CSS contents, not just that the rule name for two paragraphs or spans differs. Change-Id: I18a9c11aaf16bb3c4b462415b5e819f16de0893c Reviewed-on: https://gerrit.libreoffice.org/41993 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'writerperfect/source/writer/exp/txtparai.cxx')
-rw-r--r--writerperfect/source/writer/exp/txtparai.cxx54
1 files changed, 37 insertions, 17 deletions
diff --git a/writerperfect/source/writer/exp/txtparai.cxx b/writerperfect/source/writer/exp/txtparai.cxx
index f2df54d0e1b0..9658d79f48b9 100644
--- a/writerperfect/source/writer/exp/txtparai.cxx
+++ b/writerperfect/source/writer/exp/txtparai.cxx
@@ -17,32 +17,52 @@ using namespace com::sun::star;
namespace
{
-/// Looks for rName in rAutomaticStyles (and failing that, in rNamedStyles) and fills rPropertyList based on that.
+/// Looks for rName in rAutomaticStyles (and failing that, in rNamedStyles) and
+/// fills rPropertyList based on that.
+void FillStyles(const OUString &rName,
+ std::map<OUString, librevenge::RVNGPropertyList> &rAutomaticStyles,
+ std::map<OUString, librevenge::RVNGPropertyList> &rNamedStyles,
+ librevenge::RVNGPropertyList &rPropertyList);
+
+/// Looks for rName in rStyles and fills rPropertyList based on that
+/// (rAutomaticStyles and rNamedStyles are a list of possible parents).
void FillStyle(const OUString &rName,
- std::map<OUString, librevenge::RVNGPropertyList> &rNamedStyles,
+ std::map<OUString, librevenge::RVNGPropertyList> &rStyles,
std::map<OUString, librevenge::RVNGPropertyList> &rAutomaticStyles,
+ std::map<OUString, librevenge::RVNGPropertyList> &rNamedStyles,
librevenge::RVNGPropertyList &rPropertyList)
{
- auto itStyle = rAutomaticStyles.find(rName);
- if (itStyle != rAutomaticStyles.end())
- {
- // Apply properties from automatic style.
- librevenge::RVNGPropertyList::Iter itProp(itStyle->second);
- for (itProp.rewind(); itProp.next();)
- rPropertyList.insert(itProp.key(), itProp()->clone());
+ auto itStyle = rStyles.find(rName);
+ if (itStyle == rStyles.end())
return;
+
+ const librevenge::RVNGPropertyList &rStyle = itStyle->second;
+ if (rStyle["style:parent-style-name"])
+ {
+ // Style has a parent.
+ OUString aParent = OStringToOUString(rStyle["style:parent-style-name"]->getStr().cstr(), RTL_TEXTENCODING_UTF8);
+ if (!aParent.isEmpty())
+ FillStyles(aParent, rAutomaticStyles, rNamedStyles, rPropertyList);
}
- itStyle = rNamedStyles.find(rName);
- if (itStyle != rNamedStyles.end())
+ // Apply properties from named style.
+ librevenge::RVNGPropertyList::Iter itProp(rStyle);
+ for (itProp.rewind(); itProp.next();)
{
- // Apply properties from named style.
- librevenge::RVNGPropertyList::Iter itProp(itStyle->second);
- for (itProp.rewind(); itProp.next();)
+ if (OString("style:parent-style-name") != itProp.key())
rPropertyList.insert(itProp.key(), itProp()->clone());
}
}
+void FillStyles(const OUString &rName,
+ std::map<OUString, librevenge::RVNGPropertyList> &rAutomaticStyles,
+ std::map<OUString, librevenge::RVNGPropertyList> &rNamedStyles,
+ librevenge::RVNGPropertyList &rPropertyList)
+{
+ FillStyle(rName, rAutomaticStyles, rAutomaticStyles, rNamedStyles, rPropertyList);
+ FillStyle(rName, rNamedStyles, rAutomaticStyles, rNamedStyles, rPropertyList);
+}
+
}
namespace writerperfect
@@ -83,7 +103,7 @@ void XMLSpanContext::startElement(const OUString &/*rName*/, const css::uno::Ref
const OUString &rAttributeName = xAttribs->getNameByIndex(i);
const OUString &rAttributeValue = xAttribs->getValueByIndex(i);
if (rAttributeName == "text:style-name")
- FillStyle(rAttributeValue, mrImport.GetAutomaticTextStyles(), mrImport.GetTextStyles(), aPropertyList);
+ FillStyles(rAttributeValue, mrImport.GetAutomaticTextStyles(), mrImport.GetTextStyles(), aPropertyList);
else
{
OString sName = OUStringToOString(rAttributeName, RTL_TEXTENCODING_UTF8);
@@ -174,7 +194,7 @@ void XMLParaContext::startElement(const OUString &/*rName*/, const css::uno::Ref
if (rAttributeName == "text:style-name")
{
m_aStyleName = rAttributeValue;
- FillStyle(m_aStyleName, mrImport.GetAutomaticParagraphStyles(), mrImport.GetParagraphStyles(), aPropertyList);
+ FillStyles(m_aStyleName, mrImport.GetAutomaticParagraphStyles(), mrImport.GetParagraphStyles(), aPropertyList);
}
else
{
@@ -196,7 +216,7 @@ void XMLParaContext::characters(const OUString &rChars)
{
librevenge::RVNGPropertyList aPropertyList;
if (!m_aStyleName.isEmpty())
- FillStyle(m_aStyleName, mrImport.GetAutomaticTextStyles(), mrImport.GetTextStyles(), aPropertyList);
+ FillStyles(m_aStyleName, mrImport.GetAutomaticTextStyles(), mrImport.GetTextStyles(), aPropertyList);
mrImport.GetGenerator().openSpan(aPropertyList);
OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8);