diff options
author | Adam Co <rattles2013@gmail.com> | 2013-07-28 14:58:10 +0300 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2013-07-30 12:03:50 +0000 |
commit | 86166dea7e300d8aee42f141db1c533648254e6c (patch) | |
tree | b121534f27dd1bf8120b2ab026b4a52b98147894 | |
parent | 176fc56e89ca8cad0d390789e7376750765b1b0f (diff) |
fdo#64350: fix for page border shadow export
Change-Id: I3ae7a532eea7e81b9a302a98c00a514d307e8605
Reviewed-on: https://gerrit.libreoffice.org/5146
Reviewed-by: Luboš Luňák <l.lunak@suse.cz>
Tested-by: Luboš Luňák <l.lunak@suse.cz>
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/fdo64350.docx | bin | 0 -> 16139 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 9 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 80 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.hxx | 17 |
4 files changed, 83 insertions, 23 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/fdo64350.docx b/sw/qa/extras/ooxmlexport/data/fdo64350.docx Binary files differnew file mode 100644 index 000000000000..6f41b6664747 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/fdo64350.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 97015da69d1d..b0f98458c787 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -104,6 +104,7 @@ public: void testFdo66781(); void testFdo60990(); void testFdo65718(); + void testFdo64350(); CPPUNIT_TEST_SUITE(Test); #if !defined(MACOSX) && !defined(WNT) @@ -184,6 +185,7 @@ void Test::run() {"fdo66781.docx", &Test::testFdo66781}, {"fdo60990.odt", &Test::testFdo60990}, {"fdo65718.docx", &Test::testFdo65718}, + {"fdo64350.docx", &Test::testFdo64350}, }; // Don't test the first import of these, for some reason those tests fail const char* aBlacklist[] = { @@ -1088,6 +1090,13 @@ void Test::testFdo65718() CPPUNIT_ASSERT_EQUAL(sal_Int32( EMU_TO_MM100(114300) + 1), getProperty<sal_Int32>(xPropertySet, "RightMargin") ); } +void Test::testFdo64350() +{ + // The problem was that page border shadows were not exported + table::ShadowFormat aShadow = getProperty<table::ShadowFormat>(getStyles("PageStyles")->getByName(DEFAULT_STYLE), "ShadowFormat"); + CPPUNIT_ASSERT_EQUAL(table::ShadowLocation_BOTTOM_RIGHT, aShadow.Location); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 16fc3b0cc6f3..820d06cc1917 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -1482,7 +1482,7 @@ void DocxAttributeOutput::ParagraphStyle( sal_uInt16 nStyle ) m_pSerializer->singleElementNS( XML_w, XML_pStyle, FSNS( XML_w, XML_val ), aStyleId.getStr(), FSEND ); } -static void impl_borderLine( FSHelperPtr pSerializer, sal_Int32 elementToken, const SvxBorderLine* pBorderLine, sal_uInt16 nDist ) +static void impl_borderLine( FSHelperPtr pSerializer, sal_Int32 elementToken, const SvxBorderLine* pBorderLine, sal_uInt16 nDist, bool bWriteShadow = false ) { FastAttributeList* pAttr = pSerializer->createAttrList(); @@ -1578,6 +1578,12 @@ static void impl_borderLine( FSHelperPtr pSerializer, sal_Int32 elementToken, co pAttr->add( FSNS( XML_w, XML_color ), sColor ); } + if (bWriteShadow) + { + // Set the shadow value + pAttr->add( FSNS( XML_w, XML_shadow ), "1" ); + } + XFastAttributeListRef xAttrs( pAttr ); pSerializer->singleElementNS( XML_w, elementToken, xAttrs ); } @@ -1591,6 +1597,7 @@ static OutputBorderOptions lcl_getTableDefaultBorderOptions(bool bEcma) rOptions.bWriteTag = true; rOptions.bWriteInsideHV = true; rOptions.bWriteDistance = false; + rOptions.aShadowLocation = SVX_SHADOW_NONE; rOptions.bCheckDistanceSize = false; return rOptions; @@ -1605,6 +1612,7 @@ static OutputBorderOptions lcl_getTableCellBorderOptions(bool bEcma) rOptions.bWriteTag = true; rOptions.bWriteInsideHV = true; rOptions.bWriteDistance = false; + rOptions.aShadowLocation = SVX_SHADOW_NONE; rOptions.bCheckDistanceSize = false; return rOptions; @@ -1619,6 +1627,7 @@ static OutputBorderOptions lcl_getBoxBorderOptions() rOptions.bWriteTag = false; rOptions.bWriteInsideHV = false; rOptions.bWriteDistance = true; + rOptions.aShadowLocation = SVX_SHADOW_NONE; rOptions.bCheckDistanceSize = false; return rOptions; @@ -1665,11 +1674,42 @@ static void impl_borders( FSHelperPtr pSerializer, const SvxBoxItem& rBox, const { const SvxBorderLine* pLn = rBox.GetLine( *pBrd ); - if (!tagWritten && rOptions.bWriteTag) { + if (!tagWritten && rOptions.bWriteTag) + { pSerializer->startElementNS( XML_w, rOptions.tag, FSEND ); tagWritten = true; } + bool bWriteShadow = false; + if (rOptions.aShadowLocation == SVX_SHADOW_NONE) + { + // The border has no shadow + } + else if (rOptions.aShadowLocation == SVX_SHADOW_BOTTOMRIGHT) + { + // Special case of 'Bottom-Right' shadow: + // If the shadow location is 'Bottom-Right' - then turn on the shadow + // for ALL the sides. This is because in Word - if you select a shadow + // for a border - it turn on the shadow for ALL the sides (but shows only + // the bottom-right one). + // This is so that no information will be lost if passed through LibreOffice + bWriteShadow = true; + } + else + { + // If there is a shadow, and it's not the regular 'Bottom-Right', + // then write only the 'shadowed' sides of the border + if ( + ( ( rOptions.aShadowLocation == SVX_SHADOW_TOPLEFT || rOptions.aShadowLocation == SVX_SHADOW_TOPRIGHT ) && *pBrd == BOX_LINE_TOP ) || + ( ( rOptions.aShadowLocation == SVX_SHADOW_TOPLEFT || rOptions.aShadowLocation == SVX_SHADOW_BOTTOMLEFT ) && *pBrd == BOX_LINE_LEFT ) || + ( ( rOptions.aShadowLocation == SVX_SHADOW_BOTTOMLEFT || rOptions.aShadowLocation == SVX_SHADOW_BOTTOMRIGHT ) && *pBrd == BOX_LINE_BOTTOM) || + ( ( rOptions.aShadowLocation == SVX_SHADOW_TOPRIGHT || rOptions.aShadowLocation == SVX_SHADOW_BOTTOMRIGHT ) && *pBrd == BOX_LINE_RIGHT ) + ) + { + bWriteShadow = true; + } + } + sal_uInt16 nDist = 0; if (rOptions.bWriteDistance) { @@ -1691,7 +1731,8 @@ static void impl_borders( FSHelperPtr pSerializer, const SvxBoxItem& rBox, const nDist = rBox.GetDistance( *pBrd ); } } - impl_borderLine( pSerializer, aXmlElements[i], pLn, nDist ); + + impl_borderLine( pSerializer, aXmlElements[i], pLn, nDist, bWriteShadow ); // When exporting default borders, we need to export these 2 attr if ( rOptions.bWriteInsideHV) { @@ -5085,28 +5126,37 @@ void DocxAttributeOutput::FormatBox( const SvxBoxItem& rBox ) OutputBorderOptions aOutputBorderOptions = lcl_getBoxBorderOptions(); - if ( !m_bOpenedSectPr ) - { - // Normally open the borders tag for paragraphs - m_pSerializer->startElementNS( XML_w, XML_pBdr, FSEND ); - } - else + if ( m_bOpenedSectPr ) { - // If inside a section - check if the distance is larger than 31 points + // Inside a section + + // Check if the distance is larger than 31 points aOutputBorderOptions.bCheckDistanceSize = true; - } - impl_borders( m_pSerializer, rBox, aOutputBorderOptions, &m_pageMargins ); + // Check if there is a shadow item + const SfxPoolItem* pItem = GetExport().HasItem( RES_SHADOW ); + if ( pItem ) + { + const SvxShadowItem* pShadowItem = (const SvxShadowItem*)pItem; + aOutputBorderOptions.aShadowLocation = pShadowItem->GetLocation(); + } + + impl_borders( m_pSerializer, rBox, aOutputBorderOptions, &m_pageMargins ); - if ( m_bOpenedSectPr ) - { // Special handling for pgBorder m_pSerializer->mergeTopMarks( sax_fastparser::MERGE_MARKS_PREPEND ); m_pSerializer->mergeTopMarks( ); } else { - // Normally close the borders tag for paragraphs + // Not inside a section + + // Open the paragraph's borders tag + m_pSerializer->startElementNS( XML_w, XML_pBdr, FSEND ); + + impl_borders( m_pSerializer, rBox, aOutputBorderOptions, &m_pageMargins ); + + // Close the paragraph's borders tag m_pSerializer->endElementNS( XML_w, XML_pBdr ); } } diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 2a163a89a485..02aeb45abd8e 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -73,14 +73,15 @@ enum DocxColBreakStatus */ struct OutputBorderOptions { - sal_Int32 tag; - bool bUseStartEnd; - bool bWriteTag; - bool bWriteInsideHV; - bool bWriteDistance; - bool bCheckDistanceSize; - - OutputBorderOptions() : tag(0), bUseStartEnd(false), bWriteTag(true), bWriteInsideHV(false), bWriteDistance(false), bCheckDistanceSize(false) {} + sal_Int32 tag; + bool bUseStartEnd; + bool bWriteTag; + bool bWriteInsideHV; + bool bWriteDistance; + SvxShadowLocation aShadowLocation; + bool bCheckDistanceSize; + + OutputBorderOptions() : tag(0), bUseStartEnd(false), bWriteTag(true), bWriteInsideHV(false), bWriteDistance(false), aShadowLocation(SVX_SHADOW_NONE), bCheckDistanceSize(false) {} }; /** |