Kaydet (Commit) 6d431ffb authored tarafından Michael Stahl's avatar Michael Stahl

fdo#77454: fix WW8 import/export of negative image crop

The negative crop values were imported as large positive values, which
caused the image to be rendered with 1 pixel width after commit
2e516752.

Change-Id: I0e01b9d9a05d90e868699832085a06ba5aab7e54
üst a0ef37c5
This diff was suppressed by a .gitattributes entry.
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <com/sun/star/view/XViewSettingsSupplier.hpp> #include <com/sun/star/view/XViewSettingsSupplier.hpp>
#include <com/sun/star/table/ShadowFormat.hpp> #include <com/sun/star/table/ShadowFormat.hpp>
#include <com/sun/star/table/TableBorder2.hpp> #include <com/sun/star/table/TableBorder2.hpp>
#include <com/sun/star/text/GraphicCrop.hpp>
class Test : public SwModelTestBase class Test : public SwModelTestBase
{ {
...@@ -150,6 +151,29 @@ DECLARE_WW8EXPORT_TEST(testCharacterBorder, "charborder.odt") ...@@ -150,6 +151,29 @@ DECLARE_WW8EXPORT_TEST(testCharacterBorder, "charborder.odt")
} }
} }
DECLARE_WW8EXPORT_TEST(testFdo77454, "fdo77454.doc")
{
{
// check negative crops round-trip
text::GraphicCrop const crop =
getProperty<text::GraphicCrop>(getShape(1), "GraphicCrop");
CPPUNIT_ASSERT_EQUAL(sal_Int32( -439), crop.Left);
CPPUNIT_ASSERT_EQUAL(sal_Int32(-7040), crop.Right);
CPPUNIT_ASSERT_EQUAL(sal_Int32( -220), crop.Top);
CPPUNIT_ASSERT_EQUAL(sal_Int32(-7040), crop.Bottom);
}
{
// check positive crops round-trip
text::GraphicCrop const crop =
getProperty<text::GraphicCrop>(getShape(2), "GraphicCrop");
CPPUNIT_ASSERT_EQUAL(sal_Int32( 326), crop.Left);
CPPUNIT_ASSERT_EQUAL(sal_Int32( 1208), crop.Right);
CPPUNIT_ASSERT(abs(sal_Int32(1635) - crop.Top) <= 2);
CPPUNIT_ASSERT(abs(sal_Int32( 95) - crop.Bottom) <= 2);
}
}
DECLARE_WW8EXPORT_TEST(testFdo59530, "fdo59530.doc") DECLARE_WW8EXPORT_TEST(testFdo59530, "fdo59530.doc")
{ {
// See ooxmlexport's testFdo38244(). // See ooxmlexport's testFdo38244().
......
...@@ -2182,9 +2182,19 @@ sal_Int32 SwBasicEscherEx::ToFract16(sal_Int32 nVal, sal_uInt32 nMax) const ...@@ -2182,9 +2182,19 @@ sal_Int32 SwBasicEscherEx::ToFract16(sal_Int32 nVal, sal_uInt32 nMax) const
{ {
if (nMax) if (nMax)
{ {
sal_Int32 nMSVal = (nVal / 65536) * nMax; if (nVal >= 0)
nMSVal += (nVal * 65536 ) / nMax; {
return nMSVal; sal_Int32 nMSVal = (nVal / 65536) * nMax;
nMSVal += (nVal * 65536) / nMax;
return nMSVal;
} else {
// negative fraction does not have "-0", fractional part is always
// positive: -0.4 represented as -1 + 0.6
sal_Int32 const nDiv = (nVal / sal_Int32(nMax)) - 1;
sal_uInt32 nMSVal = (nDiv << 16) & 0xffff0000;
nMSVal += (nVal * 65536) / sal_Int32(nMax) + (-nDiv * 65536);
return nMSVal;
}
} }
return 0; return 0;
} }
......
...@@ -1972,6 +1972,13 @@ void SwWW8ImplReader::MapWrapIntoFlyFmt(SvxMSDffImportRec* pRecord, ...@@ -1972,6 +1972,13 @@ void SwWW8ImplReader::MapWrapIntoFlyFmt(SvxMSDffImportRec* pRecord,
} }
} }
static sal_Int32 lcl_ConvertCrop(sal_uInt32 const nCrop, sal_Int32 const nSize)
{
// cast to sal_Int32 to handle negative crop properly
return ((static_cast<sal_Int32>(nCrop) >> 16) * nSize)
+ (((nCrop & 0xffff) * nSize) >> 16) ;
}
void void
SwWW8ImplReader::SetAttributesAtGrfNode(SvxMSDffImportRec const*const pRecord, SwWW8ImplReader::SetAttributesAtGrfNode(SvxMSDffImportRec const*const pRecord,
SwFrmFmt *pFlyFmt, WW8_FSPA *pF ) SwFrmFmt *pFlyFmt, WW8_FSPA *pF )
...@@ -1994,23 +2001,23 @@ SwWW8ImplReader::SetAttributesAtGrfNode(SvxMSDffImportRec const*const pRecord, ...@@ -1994,23 +2001,23 @@ SwWW8ImplReader::SetAttributesAtGrfNode(SvxMSDffImportRec const*const pRecord,
pRecord->nCropFromLeft || pRecord->nCropFromRight ) pRecord->nCropFromLeft || pRecord->nCropFromRight )
{ {
SwCropGrf aCrop; // Cropping is stored in 'fixed floats' SwCropGrf aCrop; // Cropping is stored in 'fixed floats'
// 16.16 (it est fraction times total // 16.16 (fraction times total
if( pRecord->nCropFromTop ) // image width or height resp.) if( pRecord->nCropFromTop ) // image width or height resp.)
aCrop.SetTop( static_cast< sal_Int32 >( {
( ( (pRecord->nCropFromTop >> 16 ) * rHeight ) aCrop.SetTop(lcl_ConvertCrop(pRecord->nCropFromTop, rHeight));
+ (((pRecord->nCropFromTop & 0xffff) * rHeight ) >> 16) ))); }
if( pRecord->nCropFromBottom ) if( pRecord->nCropFromBottom )
aCrop.SetBottom( static_cast< sal_Int32 >( {
( ( (pRecord->nCropFromBottom >> 16 ) * rHeight ) aCrop.SetBottom(lcl_ConvertCrop(pRecord->nCropFromBottom, rHeight));
+ (((pRecord->nCropFromBottom & 0xffff) * rHeight ) >> 16) ))); }
if( pRecord->nCropFromLeft ) if( pRecord->nCropFromLeft )
aCrop.SetLeft( static_cast< sal_Int32 >( {
( ( (pRecord->nCropFromLeft >> 16 ) * rWidth ) aCrop.SetLeft(lcl_ConvertCrop(pRecord->nCropFromLeft, rWidth));
+ (((pRecord->nCropFromLeft & 0xffff) * rWidth ) >> 16) ))); }
if( pRecord->nCropFromRight ) if( pRecord->nCropFromRight )
aCrop.SetRight( static_cast< sal_Int32 >( {
( ( (pRecord->nCropFromRight >> 16 ) * rWidth ) aCrop.SetRight(lcl_ConvertCrop(pRecord->nCropFromRight,rWidth));
+ (((pRecord->nCropFromRight & 0xffff) * rWidth ) >> 16) ))); }
pGrfNd->SetAttr( aCrop ); pGrfNd->SetAttr( aCrop );
} }
......
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