diff options
author | Justin Luth <justin.luth@collabora.com> | 2019-10-22 15:50:19 +0300 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-11-22 10:47:44 +0100 |
commit | 334409fbde555a957cd34e295cc27f2c2bf6e194 (patch) | |
tree | 24367e1330f55490077fa89ec2cd7550ddab2080 /oox | |
parent | a2fbc48afdaf693f1a24e1de5cea21250bfab5ed (diff) |
tdf#128153 docx/VML: apply style properties to shape text
This replaces LO 4.3 commit 8766011bccfd0f12f8dd77d2f94eb16e2e8c3471
DOCX import: set document-level font size default based on default para style
...and is needed for tdf#118947, since bogus DEFAULT_VALUEs
really hinder determining what a table style should override.
Shape text should inherit the font size from the style that is specified.
In many cases, it will not be specified, and therefore the default style
was appropriate, but in cases where a style IS specified, then of course
use that fontsize ... and every other character and paragraph property.
HOWEVER, I only added the properties used in vml import for now,
and I skipped asian/complex fontnames since VML only handles CharHeight,
and not CharHeightAsian/Complex.
-note: this does not affect direct formatting - it just sets
default value at the shape level, not at the paragraph level.
So far I have only looked at DOCX:VML - which satisfies the
unit tests. There are other codepaths that lead to PushShapeContext
though, and this should be easy to expand to other import
situations. I've tried lots of asserts to find unit tests
that should be modified, and so far they all seemed to point
to VML - although round-tripping doesn't use VML and still
requires at minimum the CharHeight property to be overridden,
so limiting non-VML to that to maintain backward compatibility,
and reduce regression footprint.
Since we have to emulate here (since paragraph styles are not
supported on Draw text), a perfect solution cannot possibly be
found - specifically in cases where multiple paragraphs exist
in one shape with different styles applied, or where some
pararaphs apply a paragraph property and others do not.
Compromise 1: For ambiguous paragraph styles, fallback to the
default paragraph style. Rationale: Normally, most styles
inherit from default and only change a couple of properties.
So MOST of the properties will match the normal style.
The chances that the default style will be correct are
more likely than that some other random default would be.
-note: no existing unit tests were ambiguous
Compromise 2: Ideally, each paragraph could report whether
it had DIRECT formatting, and the paragraphs could be
walked through instead of the shapes. But I don't think
that is reasonably possible in this SyncProperties situation.
At first I had a grabbag framework setup that monitored
when a paragraph property was set, and then skipped applying
that property. But I later noticed that the PropertyState
for paragraph properties actually did seem to reflect
that - which is a better solution if it works properly.
Regression potential:
-for VML: should be limited to non-charheight properties
where the default style sets some weird default, and
an ambiguous style sets it back to the program default.
Prior to this patch, the default style value wouldn't apply.
On the flip side (and more likely scenario), non-ambiguous
cases will use the correct value and look more like MSWord,
as seen in many existing unit tests that now use corrected fonts.
-for non-VML: should be none since I limit it to only
CharHeight which was previously emulated by changing the
program default.
Change-Id: I8f1fb7ed01f990dbf998ebe04064c2645a68e1aa
Reviewed-on: https://gerrit.libreoffice.org/81365
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth@sil.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/vml/vmltextbox.cxx | 34 | ||||
-rw-r--r-- | oox/source/vml/vmltextboxcontext.cxx | 3 |
2 files changed, 37 insertions, 0 deletions
diff --git a/oox/source/vml/vmltextbox.cxx b/oox/source/vml/vmltextbox.cxx index ec56cb049fb2..c170c8db4414 100644 --- a/oox/source/vml/vmltextbox.cxx +++ b/oox/source/vml/vmltextbox.cxx @@ -28,6 +28,7 @@ #include <com/sun/star/text/WritingMode.hpp> #include <com/sun/star/style/ParagraphAdjust.hpp> #include <comphelper/sequence.hxx> +#include <comphelper/sequenceashashmap.hxx> namespace oox { namespace vml { @@ -76,6 +77,9 @@ OUString TextBox::getText() const void TextBox::convert(const uno::Reference<drawing::XShape>& xShape) const { uno::Reference<text::XTextAppend> xTextAppend(xShape, uno::UNO_QUERY); + OUString sParaStyle; + bool bAmbiguousStyle = true; + for (auto const& portion : maPortions) { beans::PropertyValue aPropertyValue; @@ -129,6 +133,25 @@ void TextBox::convert(const uno::Reference<drawing::XShape>& xShape) const aPropertyValue.Value <<= eAdjust; aPropVec.push_back(aPropertyValue); } + + // All paragraphs should be either undefined (default) or the same style, + // because it will only be applied to the entire shape, and not per-paragraph. + if (sParaStyle.isEmpty() ) + { + if ( rParagraph.moParaStyleName.has() ) + sParaStyle = rParagraph.moParaStyleName.get(); + if ( bAmbiguousStyle ) + bAmbiguousStyle = false; // both empty parastyle and ambiguous can only be true at the first paragraph + else + bAmbiguousStyle = rParagraph.moParaStyleName.has(); // ambiguous if both default and specified style used. + } + else if ( !bAmbiguousStyle ) + { + if ( !rParagraph.moParaStyleName.has() ) + bAmbiguousStyle = true; // ambiguous if both specified and default style used. + else if ( rParagraph.moParaStyleName.get() != sParaStyle ) + bAmbiguousStyle = true; // ambiguous if two different styles specified. + } if (rFont.moColor.has()) { aPropertyValue.Name = "CharColor"; @@ -138,6 +161,17 @@ void TextBox::convert(const uno::Reference<drawing::XShape>& xShape) const xTextAppend->appendTextPortion(portion.maText, comphelper::containerToSequence(aPropVec)); } + try + { + // Track the style in a grabBag for use later when style details are known. + comphelper::SequenceAsHashMap aGrabBag; + uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY_THROW); + aGrabBag.update( xPropertySet->getPropertyValue("CharInteropGrabBag") ); + aGrabBag["mso-pStyle"] <<= sParaStyle; + xPropertySet->setPropertyValue("CharInteropGrabBag", uno::makeAny(aGrabBag.getAsConstPropertyValueList())); + } + catch (uno::Exception&) {} + // Remove the last character of the shape text, if it would be a newline. uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursor(); xCursor->gotoEnd(false); diff --git a/oox/source/vml/vmltextboxcontext.cxx b/oox/source/vml/vmltextboxcontext.cxx index 7f5072536983..5f84ca33c2c6 100644 --- a/oox/source/vml/vmltextboxcontext.cxx +++ b/oox/source/vml/vmltextboxcontext.cxx @@ -270,6 +270,9 @@ void TextBoxContext::onStartElement(const AttributeList& rAttribs) case W_TOKEN(jc): maParagraph.moParaAdjust = rAttribs.getString( W_TOKEN(val) ); break; + case W_TOKEN(pStyle): + maParagraph.moParaStyleName = rAttribs.getString( W_TOKEN(val) ); + break; } } |