From 92ad689bcb3ad16bd35302e6ff4ee45b872c05a0 Mon Sep 17 00:00:00 2001 From: Luke Deller Date: Wed, 26 Mar 2014 21:58:19 +1100 Subject: Unit test for .doc import of full colour borders This test exercises the import component of commit ad51d4952dc30e0d1cdcc6037556cd7c66a61542 which adds support for full colour borders in .doc import/export. Also this test showed that page border import was not actually covered by ad51d4952dc30e0d1cdcc6037556cd7c66a61542, so that omission is fixed here. Change-Id: I6272e9b22415b5af012145e99360c5765d5aec60 Reviewed-on: https://gerrit.libreoffice.org/8759 Tested-by: Michael Stahl Reviewed-by: Michael Stahl --- sw/qa/extras/ww8import/data/bordercolours.doc | Bin 0 -> 29696 bytes sw/qa/extras/ww8import/ww8import.cxx | 116 ++++++++++++++++++++++++++ sw/source/filter/ww8/ww8par6.cxx | 22 +++-- 3 files changed, 132 insertions(+), 6 deletions(-) create mode 100755 sw/qa/extras/ww8import/data/bordercolours.doc diff --git a/sw/qa/extras/ww8import/data/bordercolours.doc b/sw/qa/extras/ww8import/data/bordercolours.doc new file mode 100755 index 000000000000..c442223ead3b Binary files /dev/null and b/sw/qa/extras/ww8import/data/bordercolours.doc differ diff --git a/sw/qa/extras/ww8import/ww8import.cxx b/sw/qa/extras/ww8import/ww8import.cxx index 17296e4ca5ec..861a960ee78f 100644 --- a/sw/qa/extras/ww8import/ww8import.cxx +++ b/sw/qa/extras/ww8import/ww8import.cxx @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -256,6 +257,121 @@ DECLARE_WW8IMPORT_TEST(testCp1000039, "cp1000039.doc") CPPUNIT_ASSERT_EQUAL(sal_Int16(RTL_TEXTENCODING_DONTKNOW), getProperty(getRun(getParagraph(1), 1), "CharFontCharSet")); } +DECLARE_WW8IMPORT_TEST(testBorderColours, "bordercolours.doc") +{ + // 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 bookmarksSupplier(mxComponent, + uno::UNO_QUERY); + uno::Reference bookmarks( + bookmarksSupplier->getBookmarks(), uno::UNO_QUERY); + uno::Reference bookmark( + bookmarks->getByName("ParagraphBorder"), uno::UNO_QUERY); + uno::Reference anchor(bookmark->getAnchor()); + table::BorderLine2 border; + border = getProperty(anchor, "TopBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + border = getProperty(anchor, "LeftBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border); + border = getProperty(anchor, "RightBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); + border = getProperty(anchor, "BottomBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border); + + // Page border + OUString pageStyleName = getProperty(anchor, "PageStyleName"); + uno::Reference pageStyle( + getStyles("PageStyles")->getByName(pageStyleName), uno::UNO_QUERY); + border = getProperty(pageStyle, "TopBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + border = getProperty(pageStyle, "LeftBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border); + border = getProperty(pageStyle, "RightBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); + border = getProperty(pageStyle, "BottomBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border); + + // Character border + bookmark.set(bookmarks->getByName("CharBorder"), uno::UNO_QUERY); + anchor = bookmark->getAnchor(); + border = getProperty(anchor, "CharTopBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + border = getProperty(anchor, "CharLeftBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + border = getProperty(anchor, "CharRightBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + border = getProperty(anchor, "CharBottomBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + + // Table border + uno::Reference tablesSupplier(mxComponent, + uno::UNO_QUERY); + uno::Reference tables( + tablesSupplier->getTextTables(), uno::UNO_QUERY); + uno::Reference table( + tables->getByName("Table1"), uno::UNO_QUERY); + table::TableBorder2 tableBorder = getProperty( + 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); + CPPUNIT_ASSERT_EQUAL(expectedBottom.Color, tableBorder.BottomLine.Color); + + // Table cells + uno::Reference cell( + table->getCellByName("A2"), uno::UNO_QUERY); + border = getProperty(cell, "TopBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + border = getProperty(cell, "LeftBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border); + border = getProperty(cell, "BottomBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border); + + cell.set(table->getCellByName("B2"), uno::UNO_QUERY); + border = getProperty(cell, "TopBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border); + border = getProperty(cell, "LeftBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); + border = getProperty(cell, "BottomBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border); + + cell.set(table->getCellByName("C2"), uno::UNO_QUERY); + border = getProperty(cell, "TopBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border); + border = getProperty(cell, "LeftBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedDashedRed, border); + border = getProperty(cell, "RightBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); + border = getProperty(cell, "BottomBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border); + + // Picture border + // (#if'd out as they are not yet imported with correct colours) +#if 0 + bookmark.set(bookmarks->getByName("PictureBorder"),uno::UNO_QUERY); + anchor = bookmark->getAnchor(); + border = getProperty(anchor, "TopBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border); + border = getProperty(anchor, "LeftBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border); + border = getProperty(anchor, "RightBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border); + border = getProperty(anchor, "BottomBorder"); + CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border); +#endif +} + #endif CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx index 4923053da591..a9f95705289c 100644 --- a/sw/source/filter/ww8/ww8par6.cxx +++ b/sw/source/filter/ww8/ww8par6.cxx @@ -1223,15 +1223,25 @@ static sal_uInt8 lcl_ReadBorders(bool bVer67, WW8_BRCVer9* brc, WW8PLCFx_Cp_FKP* { if( !bVer67 ) { - sal_uInt8* pSprm[4]; + sal_uInt8* pSprm[4]; - // sprmSBrcTop, sprmSBrcLeft, sprmSBrcBottom, sprmSBrcRight - if( pSep->Find4Sprms( 0x702B, 0x702C, 0x702D, 0x702E, - pSprm[0], pSprm[1], pSprm[2], pSprm[3] ) ) - { + if( pSep->Find4Sprms( + NS_sprm::LN_SBrcTop, NS_sprm::LN_SBrcLeft, + NS_sprm::LN_SBrcBottom, NS_sprm::LN_SBrcRight, + pSprm[0], pSprm[1], pSprm[2], pSprm[3] ) ) + { for( int i = 0; i < 4; ++i ) nBorder |= int(_SetWW8_BRC( 8, brc[ i ], pSprm[ i ] ))<Find4Sprms( + NS_sprm::LN_SBorderTop, NS_sprm::LN_SBorderLeft, + NS_sprm::LN_SBorderBottom, NS_sprm::LN_SBorderRight, + pSprm[0], pSprm[1], pSprm[2], pSprm[3] ) ) + { + for( int i = 0; i < 4; ++i ) + nBorder |= int(_SetWW8_BRC( 9, brc[ i ], pSprm[ i ] ))<