diff --git a/sw/qa/extras/ooxmlexport/data/tdf118947_tableStyle.docx b/sw/qa/extras/ooxmlexport/data/tdf118947_tableStyle.docx index 0b40aab5b95b..b5c55f6f3b91 100644 Binary files a/sw/qa/extras/ooxmlexport/data/tdf118947_tableStyle.docx and b/sw/qa/extras/ooxmlexport/data/tdf118947_tableStyle.docx differ diff --git a/sw/qa/extras/ooxmlexport/data/tdf118947_tableStyle2.docx b/sw/qa/extras/ooxmlexport/data/tdf118947_tableStyle2.docx new file mode 100755 index 000000000000..7c0825feba0c Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf118947_tableStyle2.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx index 48e6788b2687..3f217e35d96c 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx @@ -334,7 +334,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf118947_tableStyle, "tdf118947_tableStyle.docx") uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); uno::Reference 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(xPara, "CharHeight")); + CPPUNIT_ASSERT_EQUAL_MESSAGE("TextBody has 10pt font size", 11.f, getProperty(xPara, "CharHeight")); CPPUNIT_ASSERT_EQUAL_MESSAGE("TextBody has 1pt space below paragraph", sal_Int32(35), getProperty(xPara, "ParaBottomMargin")); CPPUNIT_ASSERT_EQUAL_MESSAGE("Table has 10pt space above paragraph", sal_Int32(353), getProperty(xPara, "ParaTopMargin")); CPPUNIT_ASSERT_EQUAL_MESSAGE("Table style sets 0 right margin", sal_Int32(0), getProperty(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(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(getRun(xPara,1), "CharHeight")); CPPUNIT_ASSERT_EQUAL_MESSAGE("Normal has 0pt space below paragraph", sal_Int32(0), getProperty(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(xPara, "ParaRightMargin")); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Table sets 2.5 line-spacing", sal_Int16(250), getProperty(xPara, "ParaLineSpacing").Height, 1); CPPUNIT_ASSERT_EQUAL_MESSAGE("Paragraph background color in cell A2", sal_Int32(-1), getProperty(xPara, "ParaBackColor")); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Compat mode overrides left adjust", style::ParagraphAdjust_RIGHT, + static_cast(getProperty(xPara, "ParaAdjust"))); +} + +DECLARE_OOXMLEXPORT_TEST(testTdf118947_tableStyle2, "tdf118947_tableStyle2.docx") +{ + uno::Reference xTable(getParagraphOrTable(1), uno::UNO_QUERY); + // This cell is affected by compatSetting overrideTableStyleFontSizeAndJustification=1 (no goofy exception) + uno::Reference xCell(xTable->getCellByName("A2"), uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xCell->getText(), uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference 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(getRun(xPara,1), "CharHeight")); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Non-Compat mode keeps the style's left adjust", style::ParagraphAdjust_LEFT, + static_cast(getProperty(xPara, "ParaAdjust"))); } DECLARE_OOXMLEXPORT_TEST(tdf123912_protectedForm, "tdf123912_protectedForm.odt") diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index 0e5a0cfdfd61..b5a737d626b7 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -19,6 +19,7 @@ #include "DomainMapperTableHandler.hxx" #include "DomainMapper_Impl.hxx" #include "StyleSheetTable.hxx" +#include #include #include #include @@ -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 xParagraph( diff --git a/writerfilter/source/dmapper/SettingsTable.cxx b/writerfilter/source/dmapper/SettingsTable.cxx index 824c627f436c..e8a921ff0934 100644 --- a/writerfilter/source/dmapper/SettingsTable.cxx +++ b/writerfilter/source/dmapper/SettingsTable.cxx @@ -767,6 +767,36 @@ void SettingsTable::ApplyProperties(uno::Reference 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 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 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; } } diff --git a/writerfilter/source/dmapper/SettingsTable.hxx b/writerfilter/source/dmapper/SettingsTable.hxx index d8473e423041..3489cf0ac34b 100644 --- a/writerfilter/source/dmapper/SettingsTable.hxx +++ b/writerfilter/source/dmapper/SettingsTable.hxx @@ -87,6 +87,7 @@ class SettingsTable : public LoggedProperties, public LoggedTable void ApplyProperties(css::uno::Reference const& xDoc); + bool GetCompatSettingValue( const OUString& sCompatName ) const; sal_Int32 GetWordCompatibilityMode() const; const OUString & GetCurrentDatabaseDataSource() const;