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 /sw | |
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 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport10.cxx | 8 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport8.cxx | 13 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 5 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 22 |
4 files changed, 24 insertions, 24 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx index b9efb409a456..dada93a93b0f 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx @@ -565,6 +565,14 @@ DECLARE_OOXMLEXPORT_TEST(testFdo74401, "fdo74401.docx") uno::Reference<drawing::XShapeDescriptor> xShape(xGroupShape->getByIndex(1), uno::UNO_QUERY); // The triangle (second child) was a TextShape before, so it was shown as a rectangle. CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.CustomShape"), xShape->getShapeType()); + + uno::Reference<text::XText> xText = uno::Reference<text::XTextRange>(xShape, uno::UNO_QUERY_THROW)->getText(); + uno::Reference<text::XTextRange> xCharRun = getRun(getParagraphOfText(1, xText), 1, "Triangle "); + + // tdf#128153 Paragraph Style Normal (Web) should not overwrite the 11pt directly applied fontsize. + CPPUNIT_ASSERT_EQUAL_MESSAGE("Fontsize", 11.f, getProperty<float>(xCharRun, "CharHeight")); + // but paragraph Style Normal (Web) should provide the font name + CPPUNIT_ASSERT_EQUAL_MESSAGE("Font", OUString("Times New Roman"), getProperty<OUString>(xCharRun, "CharFontName")); } DECLARE_OOXMLEXPORT_TEST(testGridBefore, "gridbefore.docx") diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx index e5b4ffc9cfdd..537e6d5a148b 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx @@ -1028,9 +1028,18 @@ DECLARE_OOXMLEXPORT_TEST(testFdo46361, "fdo46361.docx") // This was black, not green. CPPUNIT_ASSERT_EQUAL(sal_Int32(0x008000), getProperty<sal_Int32>(getRun(xParagraph, 1), "CharColor")); // \n char was missing due to unhandled w:br. - CPPUNIT_ASSERT_EQUAL(OUString("text\ntext"), uno::Reference<text::XTextRange>(xGroupShape->getByIndex(1), uno::UNO_QUERY_THROW)->getString()); + uno::Reference<text::XText> xShapeText(xGroupShape->getByIndex(1), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(OUString("text\ntext"), xShapeText->getString()); // \n chars were missing, due to unhandled multiple w:p tags. - CPPUNIT_ASSERT_EQUAL(OUString("text\ntext\n"), uno::Reference<text::XTextRange>(xGroupShape->getByIndex(2), uno::UNO_QUERY_THROW)->getString()); + xShapeText.set(xGroupShape->getByIndex(2), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(OUString("text\ntext\n"), xShapeText->getString()); + + // tdf#128153 The first and second lines are directly specified as centered. Make sure that doesn't change. + xParagraph.set(getParagraphOfText(2, xShapeText->getText(), "text")); + CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_CENTER, static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(xParagraph, "ParaAdjust"))); + // The last paragraph should be left aligned. + xParagraph.set(getParagraphOfText(3, xShapeText->getText(), "")); + CPPUNIT_ASSERT_MESSAGE("You FIXED me!", style::ParagraphAdjust_LEFT != static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(xParagraph, "ParaAdjust"))); } DECLARE_OOXMLEXPORT_TEST(testFdo65632, "fdo65632.docx") diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx index 26b0b56eacae..2bc6a526fd99 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx @@ -569,7 +569,10 @@ DECLARE_OOXMLIMPORT_TEST(testGroupshapeChildRotation, "groupshape-child-rotation #if HAVE_MORE_FONTS xShape.set(xGroupShape->getByIndex(4), uno::UNO_QUERY); // This was 887, i.e. border distances were included in the height. - CPPUNIT_ASSERT_EQUAL(sal_Int32(686), xShape->getSize().Height); + CPPUNIT_ASSERT_EQUAL(sal_Int32(661), xShape->getSize().Height); + // Paragraph Style Normal should provide the font name - which slightly affects the shape's height (was 686) + uno::Reference<text::XText> xText = uno::Reference<text::XTextRange>(xShape, uno::UNO_QUERY_THROW)->getText(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Font", OUString("Times New Roman"), getProperty<OUString>(getRun(xText, 1), "CharFontName")); #endif uno::Reference<drawing::XShapeDescriptor> xShapeDescriptor(xGroupShape->getByIndex(5), uno::UNO_QUERY); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 4f18582b0d7f..b6caf17412b3 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -4440,26 +4440,6 @@ void DocxAttributeOutput::LatentStyles() m_pSerializer->endElementNS(XML_w, XML_latentStyles); } -namespace -{ - -/// Should the font size we have written out as a default one? -bool lcl_isDefaultFontSize(const SvxFontHeightItem& rFontHeight, SwDoc* pDoc) -{ - bool bRet = rFontHeight.GetHeight() != 200; // see StyleSheetTable_Impl::StyleSheetTable_Impl() where we set this default - // Additionally, if the default para style has the same font size, then don't write it here. - SwTextFormatColl* pDefaultStyle = pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD); - if (pDefaultStyle) - { - const SfxPoolItem* pItem = nullptr; - if (pDefaultStyle->GetAttrSet().HasItem(RES_CHRATR_FONTSIZE, &pItem)) - return static_cast<const SvxFontHeightItem*>(pItem)->GetHeight() != rFontHeight.GetHeight(); - } - return bRet; -} - -} - void DocxAttributeOutput::OutputDefaultItem(const SfxPoolItem& rHt) { bool bMustWrite = true; @@ -4484,7 +4464,7 @@ void DocxAttributeOutput::OutputDefaultItem(const SfxPoolItem& rHt) bMustWrite = true; break; case RES_CHRATR_FONTSIZE: - bMustWrite = lcl_isDefaultFontSize(static_cast< const SvxFontHeightItem& >(rHt), m_rExport.m_pDoc); + bMustWrite = static_cast< const SvxFontHeightItem& >(rHt).GetHeight() != 200; // see StyleSheetTable_Impl::StyleSheetTable_Impl() where we set this default break; case RES_CHRATR_KERNING: bMustWrite = static_cast< const SvxKerningItem& >(rHt).GetValue() != 0; |