sw/inc/SwStyleNameMapper.hxx | 1 sw/qa/extras/ww8export/data/bordercolours.odt |binary sw/qa/extras/ww8export/ww8export.cxx | 125 ++++++++++++++++++ sw/source/core/doc/SwStyleNameMapper.cxx | 173 ++++---------------------- 4 files changed, 157 insertions(+), 142 deletions(-)
New commits: commit 19644e657d1ccfa6cd9f57524cb77beb47161ae7 Author: Luke Deller <l...@deller.id.au> Date: Mon Apr 7 23:58:58 2014 +1000 Unit test for .doc export of full colour borders This test exercises the *export* component of recent work to add support for full colour borders in .doc import/export. Change-Id: I2da0b8b488e399d0cd4791678fac6e1c85921c2c Reviewed-on: https://gerrit.libreoffice.org/8887 Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/sw/qa/extras/ww8export/data/bordercolours.odt b/sw/qa/extras/ww8export/data/bordercolours.odt new file mode 100644 index 0000000..f34d595 Binary files /dev/null and b/sw/qa/extras/ww8export/data/bordercolours.odt differ diff --git a/sw/qa/extras/ww8export/ww8export.cxx b/sw/qa/extras/ww8export/ww8export.cxx index 2e3d200..d014dba 100644 --- a/sw/qa/extras/ww8export/ww8export.cxx +++ b/sw/qa/extras/ww8export/ww8export.cxx @@ -16,6 +16,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/view/XViewSettingsSupplier.hpp> #include <com/sun/star/table/ShadowFormat.hpp> +#include <com/sun/star/table/TableBorder2.hpp> class Test : public SwModelTestBase { @@ -196,6 +197,130 @@ DECLARE_WW8EXPORT_TEST(testCommentsNested, "comments-nested.doc") CPPUNIT_ASSERT_EQUAL(OUString("Inner"), getProperty<OUString>(xInner, "Content")); } +DECLARE_WW8EXPORT_TEST(testBorderColoursExport, "bordercolours.odt") +{ + // This is very close to testBorderColours in ww8import.cxx, but for export + + // The following 6 colours can only be represented with WW9 (Word 2000) + // BRC (BoRder Control) structures. We can tell that they have been + // exported/imported using a WW8 (Word '97) BRC if they instead come + // through as one of the 16 colours listed at this link: + // http://msdn.microsoft.com/en-us/library/dd773060.aspx + table::BorderLine2 expectedTop(0xFA670C, 0, 53, 0, 1, 53); + table::BorderLine2 expectedLeft(0xD99594, 0, 79, 0, 0, 79); + table::BorderLine2 expectedRight(0xB2A1C7, 53, 53, 53, 3, 159); + table::BorderLine2 expectedBottom(0xB6DDE8, 0, 106, 0, 14, 106); + table::BorderLine2 expectedDashedRed(0xFA670C, 0, 53, 0, 2, 53); + table::BorderLine2 expectedDoubleGreen(0xC2D69B, 26, 106, 26, 4, 159); + + // Paragraph border + uno::Reference<text::XBookmarksSupplier> bookmarksSupplier(mxComponent, + uno::UNO_QUERY); + uno::Reference<container::XNameAccess> bookmarks( + bookmarksSupplier->getBookmarks(), uno::UNO_QUERY); + uno::Reference<text::XTextContent> bookmark( + bookmarks->getByName("ParagraphBorder"), uno::UNO_QUERY); + uno::Reference<text::XTextRange> anchor(bookmark->getAnchor()); + table::BorderLine2 border; + border = getProperty<table::BorderLine2>(anchor, "TopBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + border = getProperty<table::BorderLine2>(anchor, "LeftBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border); + border = getProperty<table::BorderLine2>(anchor, "RightBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); + border = getProperty<table::BorderLine2>(anchor, "BottomBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border); + + // Page border + OUString pageStyleName = getProperty<OUString>(anchor, "PageStyleName"); + uno::Reference<style::XStyle> pageStyle( + getStyles("PageStyles")->getByName(pageStyleName), uno::UNO_QUERY); + border = getProperty<table::BorderLine2>(pageStyle, "TopBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + border = getProperty<table::BorderLine2>(pageStyle, "LeftBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border); + border = getProperty<table::BorderLine2>(pageStyle, "RightBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); + border = getProperty<table::BorderLine2>(pageStyle, "BottomBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border); + + // Character border + bookmark.set(bookmarks->getByName("CharBorder"), uno::UNO_QUERY); + anchor = bookmark->getAnchor(); + border = getProperty<table::BorderLine2>(anchor, "CharTopBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + border = getProperty<table::BorderLine2>(anchor, "CharLeftBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + border = getProperty<table::BorderLine2>(anchor, "CharRightBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + border = getProperty<table::BorderLine2>(anchor, "CharBottomBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + + // Table border + uno::Reference<text::XTextTablesSupplier> tablesSupplier(mxComponent, + uno::UNO_QUERY); + uno::Reference<container::XNameAccess> tables( + tablesSupplier->getTextTables(), uno::UNO_QUERY); + uno::Reference<text::XTextTable> table( + tables->getByName("Table1"), uno::UNO_QUERY); + table::TableBorder2 tableBorder = getProperty<table::TableBorder2>( + table, "TableBorder2"); + CPPUNIT_ASSERT_EQUAL(expectedTop.Color, tableBorder.TopLine.Color); + CPPUNIT_ASSERT_EQUAL(expectedLeft.Color, tableBorder.LeftLine.Color); + CPPUNIT_ASSERT_EQUAL(expectedRight.Color, tableBorder.RightLine.Color); +#if 0 + // #if'd out because the "fine dashed" border line style for table borders + // does not seem to save or load correctly in odt format at present + CPPUNIT_ASSERT_EQUAL(expectedBottom.Color, tableBorder.BottomLine.Color); +#endif + + // Table cells + uno::Reference<table::XCell> cell( + table->getCellByName("A2"), uno::UNO_QUERY); + border = getProperty<table::BorderLine2>(cell, "TopBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + border = getProperty<table::BorderLine2>(cell, "LeftBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border); + border = getProperty<table::BorderLine2>(cell, "BottomBorder"); +#if 0 + // #if'd out because the "fine dashed" border line style for table borders + // does not seem to save or load correctly in odt format at present + CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border); +#endif + + cell.set(table->getCellByName("B2"), uno::UNO_QUERY); + border = getProperty<table::BorderLine2>(cell, "TopBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border); + border = getProperty<table::BorderLine2>(cell, "LeftBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); + border = getProperty<table::BorderLine2>(cell, "BottomBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border); + + cell.set(table->getCellByName("C2"), uno::UNO_QUERY); + border = getProperty<table::BorderLine2>(cell, "TopBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border); + border = getProperty<table::BorderLine2>(cell, "LeftBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedDashedRed, border); + border = getProperty<table::BorderLine2>(cell, "RightBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); + border = getProperty<table::BorderLine2>(cell, "BottomBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border); + + // Picture border + // (#if'd out as they are not yet exported with correct colours) +#if 0 + bookmark.set(bookmarks->getByName("PictureBorder"),uno::UNO_QUERY); + anchor = bookmark->getAnchor(); + border = getProperty<table::BorderLine2>(anchor, "TopBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + border = getProperty<table::BorderLine2>(anchor, "LeftBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border); + border = getProperty<table::BorderLine2>(anchor, "RightBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); + border = getProperty<table::BorderLine2>(anchor, "BottomBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border); +#endif +} #endif CPPUNIT_PLUGIN_IMPLEMENT(); commit d8802562be87fabbbe7502c2daf39b00aa17f5d0 Author: Chris Laplante <mostthings...@gmail.com> Date: Sun Apr 6 22:20:15 2014 -0400 Fix and deduplicate the test code in SwStyleNameMapper::getHashTable. The original test code didn't work because the same pool (GET_POOLID_TXTCOLL) was being used for every test ID. To cut down on duplication, I refactored the test code and created 'testNameTable', a protected method of SwStyleNameMapper. Change-Id: I8a28f136df2650ec2d246f10a8698e8f462c9973 Reviewed-on: https://gerrit.libreoffice.org/8877 Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/sw/inc/SwStyleNameMapper.hxx b/sw/inc/SwStyleNameMapper.hxx index d806942..44569ca 100644 --- a/sw/inc/SwStyleNameMapper.hxx +++ b/sw/inc/SwStyleNameMapper.hxx @@ -124,6 +124,7 @@ protected: static const OUString& getNameFromId(sal_uInt16 nId, const OUString &rName, bool bProgName); static const NameToIdHash& getHashTable ( SwGetPoolIdFromName, bool bProgName ); + static void testNameTable( SwGetPoolIdFromName const nFamily, sal_uInt16 const nStartIndex, sal_uInt16 const nEndIndex ); public: // This gets the UI Name from the programmatic name diff --git a/sw/source/core/doc/SwStyleNameMapper.cxx b/sw/source/core/doc/SwStyleNameMapper.cxx index 9de494d..e6807d8 100644 --- a/sw/source/core/doc/SwStyleNameMapper.cxx +++ b/sw/source/core/doc/SwStyleNameMapper.cxx @@ -388,7 +388,25 @@ static void lcl_CheckSuffixAndDelete(OUString & rString) rString = rString.copy(0, rString.getLength() - 7); } } +} + +void SwStyleNameMapper::testNameTable( SwGetPoolIdFromName const nFamily, sal_uInt16 const nStartIndex, sal_uInt16 const nEndIndex ) +{ + sal_uInt16 nIndex; + sal_uInt16 nId; + for ( nIndex = 0, nId = nStartIndex ; nId < nEndIndex ; nId++,nIndex++ ) + { + OUString aString, bString; + FillUIName ( nId, aString ); + bString = GetProgName ( nFamily, aString ); + sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nFamily ); + FillProgName ( nNewId, aString ); + bString = GetUIName ( aString, nFamily ); + nNewId = GetPoolIdFromUIName ( aString, nFamily ); + if ( nNewId != nId ) + abort(); + } } const NameToIdHash & SwStyleNameMapper::getHashTable ( SwGetPoolIdFromName eFlags, bool bProgName ) @@ -512,153 +530,24 @@ const NameToIdHash & SwStyleNameMapper::getHashTable ( SwGetPoolIdFromName eFlag } break; } + #ifdef _NEED_TO_DEBUG_MAPPING static bool bTested = false; if ( !bTested ) { bTested = true; - { - for ( sal_uInt16 nIndex = 0, nId = RES_POOLCOLL_TEXT_BEGIN ; nId < RES_POOLCOLL_TEXT_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - for ( nIndex = 0, nId = RES_POOLCOLL_LISTS_BEGIN ; nId < RES_POOLCOLL_LISTS_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - for ( nIndex = 0, nId = RES_POOLCOLL_EXTRA_BEGIN ; nId < RES_POOLCOLL_EXTRA_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - for ( nIndex = 0, nId = RES_POOLCOLL_REGISTER_BEGIN ; nId < RES_POOLCOLL_REGISTER_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - for ( nIndex = 0, nId = RES_POOLCOLL_DOC_BEGIN ; nId < RES_POOLCOLL_DOC_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - for ( nIndex = 0, nId = RES_POOLCOLL_HTML_BEGIN ; nId < RES_POOLCOLL_HTML_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - } - { - for ( sal_uInt16 nIndex = 0, nId = RES_POOLCHR_NORMAL_BEGIN ; nId < RES_POOLCHR_NORMAL_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - for ( nIndex = 0, nId = RES_POOLCHR_HTML_BEGIN ; nId < RES_POOLCHR_HTML_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - } - { - for ( sal_uInt16 nIndex=0,nId = RES_POOLFRM_BEGIN ; nId < RES_POOLFRM_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - } - { - for ( sal_uInt16 nIndex=0,nId = RES_POOLPAGE_BEGIN ; nId < RES_POOLPAGE_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - } - { - for ( sal_uInt16 nIndex=0,nId = RES_POOLNUMRULE_BEGIN ; nId < RES_POOLNUMRULE_END ; nId++,nIndex++ ) - { - OUString aString, bString; - FillUIName ( nId, aString ); - bString = GetProgName ( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, aString ); - sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - FillProgName ( nNewId, aString ); - bString = GetUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - nNewId = GetPoolIdFromUIName ( aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ); - if ( nNewId != nId ) - abort(); - } - } + + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, RES_POOLCOLL_TEXT_BEGIN, RES_POOLCOLL_TEXT_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, RES_POOLCOLL_LISTS_BEGIN, RES_POOLCOLL_LISTS_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, RES_POOLCOLL_EXTRA_BEGIN, RES_POOLCOLL_EXTRA_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, RES_POOLCOLL_REGISTER_BEGIN, RES_POOLCOLL_REGISTER_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, RES_POOLCOLL_DOC_BEGIN, RES_POOLCOLL_DOC_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, RES_POOLCOLL_HTML_BEGIN, RES_POOLCOLL_HTML_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, RES_POOLCHR_NORMAL_BEGIN, RES_POOLCHR_NORMAL_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, RES_POOLCHR_HTML_BEGIN, RES_POOLCHR_HTML_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_FRMFMT, RES_POOLFRM_BEGIN, RES_POOLFRM_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, RES_POOLPAGE_BEGIN, RES_POOLPAGE_END ); + testNameTable( nsSwGetPoolIdFromName::GET_POOLID_NUMRULE, RES_POOLNUMRULE_BEGIN, RES_POOLNUMRULE_END ); } #endif return *pHash;
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits