Kaydet (Commit) 86166dea authored tarafından Adam Co's avatar Adam Co Kaydeden (comit) Luboš Luňák

fdo#64350: fix for page border shadow export

Change-Id: I3ae7a532eea7e81b9a302a98c00a514d307e8605
Reviewed-on: https://gerrit.libreoffice.org/5146Reviewed-by: 's avatarLuboš Luňák <l.lunak@suse.cz>
Tested-by: 's avatarLuboš Luňák <l.lunak@suse.cz>
üst 176fc56e
......@@ -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();
......
......@@ -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 );
}
}
......
......@@ -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) {}
};
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment