tdf#118812 writerfilter: overrideTableStyleFontSizeAndJustification

Surprisingly, there are NO uses of these compatibility options.
Apparently we have a lot of work to do...

MS Word finally throws away a goofy exception clause that must
have caused them countless grief. And LO finally adds support
for that goofy clause now that it should rarely be needed...

I modified my previous unit test slightly to increase the
difficulty level. A fontsize was changed to 11,
and justify was added.

Change-Id: I0c4997324e8ee745bac8316a45e837c5de137509
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90625
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth@sil.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
This commit is contained in:
Justin Luth 2020-03-17 15:57:21 +03:00 committed by Miklos Vajna
parent faddef755d
commit 65bea6cbe7
6 changed files with 90 additions and 19 deletions

Binary file not shown.

View file

@ -334,7 +334,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf118947_tableStyle, "tdf118947_tableStyle.docx")
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
uno::Reference<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("Table grid settings set line-spacing to 250% instead of single-spacing, which is set as a document default."), xPara->getString());
CPPUNIT_ASSERT_EQUAL_MESSAGE("TextBody has 10pt font size", 10.f, getProperty<float>(xPara, "CharHeight"));
CPPUNIT_ASSERT_EQUAL_MESSAGE("TextBody has 10pt font size", 11.f, getProperty<float>(xPara, "CharHeight"));
CPPUNIT_ASSERT_EQUAL_MESSAGE("TextBody has 1pt space below paragraph", sal_Int32(35), getProperty<sal_Int32>(xPara, "ParaBottomMargin"));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Table has 10pt space above paragraph", sal_Int32(353), getProperty<sal_Int32>(xPara, "ParaTopMargin"));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Table style sets 0 right margin", sal_Int32(0), getProperty<sal_Int32>(xPara, "ParaRightMargin"));
@ -342,11 +342,12 @@ DECLARE_OOXMLEXPORT_TEST(testTdf118947_tableStyle, "tdf118947_tableStyle.docx")
// table-style based paragraph background color
CPPUNIT_ASSERT_EQUAL_MESSAGE("Missing paragraph background color in cell A1", sal_Int32(0xCCFFCC), getProperty<sal_Int32>(xPara, "ParaBackColor"));
// This cell is affected by compatSetting overrideTableStyleFontSizeAndJustification=0 (the default value)
xCell.set(xTable->getCellByName("A2"), uno::UNO_QUERY);
xParaEnumAccess.set(xCell->getText(), uno::UNO_QUERY);
xParaEnum = xParaEnumAccess->createEnumeration();
xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("Notice that this is 8pt font in compatibility mode."), xPara->getString());
CPPUNIT_ASSERT_EQUAL(OUString("Notice that this is 8pt font, right aligned in compatibility mode."), xPara->getString());
// Even though not specified, Table-Style distributes the properties in DocDefault. DocDefault fontsize is 8pt.
CPPUNIT_ASSERT_EQUAL_MESSAGE("Compat mode has 8pt font size", 8.f, getProperty<float>(getRun(xPara,1), "CharHeight"));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Normal has 0pt space below paragraph", sal_Int32(0), getProperty<sal_Int32>(xPara, "ParaBottomMargin"));
@ -354,6 +355,25 @@ DECLARE_OOXMLEXPORT_TEST(testTdf118947_tableStyle, "tdf118947_tableStyle.docx")
CPPUNIT_ASSERT_EQUAL_MESSAGE("Table style sets 0 right margin", sal_Int32(0), getProperty<sal_Int32>(xPara, "ParaRightMargin"));
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Table sets 2.5 line-spacing", sal_Int16(250), getProperty<style::LineSpacing>(xPara, "ParaLineSpacing").Height, 1);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Paragraph background color in cell A2", sal_Int32(-1), getProperty<sal_Int32>(xPara, "ParaBackColor"));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Compat mode overrides left adjust", style::ParagraphAdjust_RIGHT,
static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(xPara, "ParaAdjust")));
}
DECLARE_OOXMLEXPORT_TEST(testTdf118947_tableStyle2, "tdf118947_tableStyle2.docx")
{
uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
// This cell is affected by compatSetting overrideTableStyleFontSizeAndJustification=1 (no goofy exception)
uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A2"), uno::UNO_QUERY);
uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xCell->getText(), uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
uno::Reference<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("Notice that this is 12pt font, left aligned in non-compatibility mode."), xPara->getString());
// Even though not specified, Table-Style tries to distribute the properties in DocDefault. DocDefault fontsize is 8pt.
// However, this is overridden by the default style's specified fontsize of 12 and left justify.
CPPUNIT_ASSERT_EQUAL_MESSAGE("Non-Compat mode has 12pt font size", 12.f, getProperty<float>(getRun(xPara,1), "CharHeight"));
CPPUNIT_ASSERT_EQUAL_MESSAGE("Non-Compat mode keeps the style's left adjust", style::ParagraphAdjust_LEFT,
static_cast<style::ParagraphAdjust>(getProperty<sal_Int16>(xPara, "ParaAdjust")));
}
DECLARE_OOXMLEXPORT_TEST(tdf123912_protectedForm, "tdf123912_protectedForm.odt")

View file

@ -19,6 +19,7 @@
#include "DomainMapperTableHandler.hxx"
#include "DomainMapper_Impl.hxx"
#include "StyleSheetTable.hxx"
#include <com/sun/star/style/ParagraphAdjust.hpp>
#include <com/sun/star/table/TableBorderDistances.hpp>
#include <com/sun/star/table/TableBorder.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
@ -1119,11 +1120,29 @@ void DomainMapperTableHandler::ApplyParagraphPropertiesFromTableStyle(TableParag
rParaProp.m_rPropertySet->getPropertyValue("ParaStyleName") >>= sParaStyleName;
StyleSheetEntryPtr pEntry = m_rDMapper_Impl.GetStyleSheetTable()->FindStyleSheetByConvertedStyleName(sParaStyleName);
uno::Any aParaStyle = m_rDMapper_Impl.GetPropertyFromStyleSheet(eId, pEntry, true, true, &bDocDefault);
// A very strange compatibility rule says that the DEFAULT style's specified fontsize of 11 or 12
// or a specified left justify will always be overridden by the table-style.
// Normally this rule is applied, so always do this unless a compatSetting indicates otherwise.
bool bCompatOverride = false;
if ( (eId == PROP_CHAR_HEIGHT || eId == PROP_PARA_ADJUST) && sParaStyleName == m_rDMapper_Impl.GetDefaultParaStyleName() )
{
if ( eId == PROP_CHAR_HEIGHT )
bCompatOverride = aParaStyle == uno::Any(double(11)) || aParaStyle == uno::Any(double(12));
else if ( eId == PROP_PARA_ADJUST )
{
style::ParagraphAdjust eAdjust(style::ParagraphAdjust_CENTER);
aParaStyle >>= eAdjust;
bCompatOverride = eAdjust == style::ParagraphAdjust_LEFT;
}
// The wording is confusing here. Normally, the paragraph style DOES override the table-style.
// But for these two special situations, do not override the table-style. So the default is false.
// If false, then "CompatOverride" the normal behaviour, and apply the table-style's value.
bCompatOverride &= !m_rDMapper_Impl.GetSettingsTable()->GetCompatSettingValue("overrideTableStyleFontSizeAndJustification");
}
// use table style when no paragraph style setting or a docDefault value is applied instead of it
if ( aParaStyle == uno::Any() || bDocDefault ||
// set default behaviour of MSO ("overrideTableStyleFontSizeAndJustification" exception):
// if Normal style defines 11 pt or 12 pt font heights, table style overrides its font size
(eId == PROP_CHAR_HEIGHT && sParaStyleName == "Standard" && (aParaStyle == uno::Any(double(11)) || aParaStyle == uno::Any(double(12))))) try
if ( aParaStyle == uno::Any() || bDocDefault || bCompatOverride ) try
{
// check property state of paragraph
uno::Reference<text::XParagraphCursor> xParagraph(

View file

@ -767,6 +767,36 @@ void SettingsTable::ApplyProperties(uno::Reference<text::XTextDocument> const& x
}
}
bool SettingsTable::GetCompatSettingValue( const OUString& sCompatName ) const
{
bool bRet = false;
for (const auto& rProp : m_pImpl->m_aCompatSettings)
{
if (rProp.Name == "compatSetting") //always true
{
css::uno::Sequence<css::beans::PropertyValue> aCurrentCompatSettings;
rProp.Value >>= aCurrentCompatSettings;
OUString sName;
aCurrentCompatSettings[0].Value >>= sName;
if ( sName != sCompatName )
continue;
OUString sUri;
aCurrentCompatSettings[1].Value >>= sUri;
if ( sUri != "http://schemas.microsoft.com/office/word" )
continue;
OUString sVal;
aCurrentCompatSettings[2].Value >>= sVal;
// if repeated, what happens? Last one wins
bRet = sVal.toBoolean();
}
}
return bRet;
}
//Keep this function in-sync with the one in sw/.../docxattributeoutput.cxx
sal_Int32 SettingsTable::GetWordCompatibilityMode() const
{
@ -775,26 +805,27 @@ sal_Int32 SettingsTable::GetWordCompatibilityMode() const
for (const auto& rProp : m_pImpl->m_aCompatSettings)
{
if (rProp.Name == "compatSetting")
if (rProp.Name == "compatSetting") //always true
{
css::uno::Sequence<css::beans::PropertyValue> aCurrentCompatSettings;
rProp.Value >>= aCurrentCompatSettings;
OUString sName;
OUString sUri;
OUString sVal;
aCurrentCompatSettings[0].Value >>= sName;
aCurrentCompatSettings[1].Value >>= sUri;
aCurrentCompatSettings[2].Value >>= sVal;
if ( sName != "compatibilityMode" )
continue;
if (sName == "compatibilityMode" && sUri == "http://schemas.microsoft.com/office/word")
{
const sal_Int32 nValidMode = sVal.toInt32();
// if repeated, highest mode wins in MS Word. 11 is the first valid mode.
if ( nValidMode > 10 && nValidMode > m_pImpl->m_nWordCompatibilityMode )
m_pImpl->m_nWordCompatibilityMode = nValidMode;
}
OUString sUri;
aCurrentCompatSettings[1].Value >>= sUri;
if ( sUri != "http://schemas.microsoft.com/office/word" )
continue;
OUString sVal;
aCurrentCompatSettings[2].Value >>= sVal;
const sal_Int32 nValidMode = sVal.toInt32();
// if repeated, highest mode wins in MS Word. 11 is the first valid mode.
if ( nValidMode > 10 && nValidMode > m_pImpl->m_nWordCompatibilityMode )
m_pImpl->m_nWordCompatibilityMode = nValidMode;
}
}

View file

@ -87,6 +87,7 @@ class SettingsTable : public LoggedProperties, public LoggedTable
void ApplyProperties(css::uno::Reference<css::text::XTextDocument> const& xDoc);
bool GetCompatSettingValue( const OUString& sCompatName ) const;
sal_Int32 GetWordCompatibilityMode() const;
const OUString & GetCurrentDatabaseDataSource() const;