Kaydet (Commit) d59ef5b2 authored tarafından Mike Kaganski's avatar Mike Kaganski Kaydeden (comit) Michael Meeks

tdf#60351: Use Wrap Polygon also for PROP_SIZE_PIXEL

Since commit 2b5bf2f1
"graphic import improved" from 2006-11-20 by Oliver Specht,
there is an unused code reading pixel size (PROP_SIZE_PIXEL) of an
image in a part of GraphicImport::createGraphicObject() that imports
the wrap polygon.
When there's no PROP_SIZE100th_M_M in graphic, the imported wrap
polygon was simply dropped, and then automatic contour was generated
for graphic. Now we import contour correctly in this case.

Also, as paragraph background overlaps non-opaque graphics,
we need to set opaque to true regardless of behindDoc value of
wp:anchor.

Change-Id: Ifa5eec9f8ccaf5ba051732b6e4f965ae8606a1cf
Reviewed-on: https://gerrit.libreoffice.org/20103Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst 0cda1453
...@@ -2931,6 +2931,30 @@ DECLARE_OOXMLIMPORT_TEST(testTdf95775, "tdf95775.docx") ...@@ -2931,6 +2931,30 @@ DECLARE_OOXMLIMPORT_TEST(testTdf95775, "tdf95775.docx")
// This must not fail in layout // This must not fail in layout
} }
DECLARE_OOXMLIMPORT_TEST(testTdf60351, "tdf60351.docx")
{
// Get the first image in the document and check its contour polygon.
// It should contain 6 points. Check their coordinates.
uno::Reference<beans::XPropertySet> xPropertySet(getShape(1), uno::UNO_QUERY);
css::drawing::PointSequenceSequence aPolyPolygon;
xPropertySet->getPropertyValue("ContourPolyPolygon") >>= aPolyPolygon;
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aPolyPolygon.getLength());
const css::drawing::PointSequence& aPolygon = aPolyPolygon[0];
CPPUNIT_ASSERT_EQUAL(sal_Int32(6), aPolygon.getLength());
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aPolygon[0].X);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aPolygon[0].Y);
CPPUNIT_ASSERT_EQUAL(sal_Int32(316), aPolygon[1].X);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aPolygon[1].Y);
CPPUNIT_ASSERT_EQUAL(sal_Int32(316), aPolygon[2].X);
CPPUNIT_ASSERT_EQUAL(sal_Int32(316), aPolygon[2].Y);
CPPUNIT_ASSERT_EQUAL(sal_Int32(158), aPolygon[3].X);
CPPUNIT_ASSERT_EQUAL(sal_Int32(298), aPolygon[3].Y);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aPolygon[4].X);
CPPUNIT_ASSERT_EQUAL(sal_Int32(316), aPolygon[4].Y);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aPolygon[5].X);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aPolygon[5].Y);
}
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -1136,7 +1136,7 @@ uno::Reference< text::XTextContent > GraphicImport::createGraphicObject( const b ...@@ -1136,7 +1136,7 @@ uno::Reference< text::XTextContent > GraphicImport::createGraphicObject( const b
if(xGraphic.is()) if(xGraphic.is())
{ {
uno::Reference< beans::XPropertySet > xGraphicObjectProperties( uno::Reference< beans::XPropertySet > xGraphicObjectProperties(
m_xTextFactory->createInstance("com.sun.star.text.TextGraphicObject"), m_xTextFactory->createInstance("com.sun.star.text.TextGraphicObject"),
uno::UNO_QUERY_THROW); uno::UNO_QUERY_THROW);
xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_GRAPHIC), uno::makeAny( xGraphic )); xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_GRAPHIC), uno::makeAny( xGraphic ));
xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_ANCHOR_TYPE), xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_ANCHOR_TYPE),
...@@ -1320,20 +1320,37 @@ uno::Reference< text::XTextContent > GraphicImport::createGraphicObject( const b ...@@ -1320,20 +1320,37 @@ uno::Reference< text::XTextContent > GraphicImport::createGraphicObject( const b
//there seems to be no way to detect the original size via _real_ API //there seems to be no way to detect the original size via _real_ API
uno::Reference< beans::XPropertySet > xGraphicProperties( xGraphic, uno::UNO_QUERY_THROW ); uno::Reference< beans::XPropertySet > xGraphicProperties( xGraphic, uno::UNO_QUERY_THROW );
awt::Size aGraphicSize, aGraphicSizePixel;
xGraphicProperties->getPropertyValue(getPropertyName( PROP_SIZE100th_M_M )) >>= aGraphicSize;
xGraphicProperties->getPropertyValue(getPropertyName( PROP_SIZE_PIXEL )) >>= aGraphicSizePixel;
uno::Any aContourPolyPolygon; if (m_pImpl->mpWrapPolygon.get() != nullptr)
if( aGraphicSize.Width && aGraphicSize.Height &&
m_pImpl->mpWrapPolygon.get() != nullptr)
{ {
WrapPolygon::Pointer_t pCorrected = m_pImpl->mpWrapPolygon->correctWordWrapPolygon(aGraphicSize); uno::Any aContourPolyPolygon;
aContourPolyPolygon <<= pCorrected->getPointSequenceSequence(); awt::Size aGraphicSize;
WrapPolygon::Pointer_t pCorrected;
xGraphicProperties->getPropertyValue(getPropertyName(PROP_SIZE100th_M_M)) >>= aGraphicSize;
if (aGraphicSize.Width && aGraphicSize.Height)
{
pCorrected = m_pImpl->mpWrapPolygon->correctWordWrapPolygon(aGraphicSize);
}
else
{
xGraphicProperties->getPropertyValue(getPropertyName(PROP_SIZE_PIXEL)) >>= aGraphicSize;
if (aGraphicSize.Width && aGraphicSize.Height)
{
pCorrected = m_pImpl->mpWrapPolygon->correctWordWrapPolygonPixel(aGraphicSize);
}
}
if (pCorrected)
{
aContourPolyPolygon <<= pCorrected->getPointSequenceSequence();
xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_CONTOUR_POLY_POLYGON),
aContourPolyPolygon);
// We should bring it to front, even if wp:anchor's behindDoc="1",
// because otherwise paragraph background (if set) overlaps the graphic
// TODO: if paragraph's background becomes bottommost, then remove this hack
xGraphicObjectProperties->setPropertyValue("Opaque", uno::makeAny(true));
}
} }
xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_CONTOUR_POLY_POLYGON),
aContourPolyPolygon);
if(m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_INLINE || m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR) if(m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_INLINE || m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR)
{ {
......
...@@ -111,6 +111,29 @@ WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygon(const awt::Size & rSr ...@@ -111,6 +111,29 @@ WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygon(const awt::Size & rSr
return pResult; return pResult;
} }
WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygonPixel(const awt::Size & rSrcSize)
{
WrapPolygon::Pointer_t pResult;
/*
* https://msdn.microsoft.com/en-us/library/ee342530.aspx
*
* Image wrapping polygons in Microsoft Word use a fixed coordinate space
* that is 21600 units x 21600 units. Coordinate (0,0) is the upper left
* corner of the image and coordinate (21600,21600) is the lower right
* corner of the image. Microsoft Word scales the size of the wrapping
* polygon units to fit the size of the image. The 21600 value is a legacy
* artifact from the drawing layer of early versions of Microsoft Office.
*/
const long nWrap100Percent = 21600;
Fraction aScaleX(rSrcSize.Width, nWrap100Percent);
Fraction aScaleY(rSrcSize.Height, nWrap100Percent);
pResult = scale(aScaleX, aScaleY);
return pResult;
}
drawing::PointSequenceSequence WrapPolygon::getPointSequenceSequence() const drawing::PointSequenceSequence WrapPolygon::getPointSequenceSequence() const
{ {
drawing::PointSequenceSequence aPolyPolygon(1L); drawing::PointSequenceSequence aPolyPolygon(1L);
......
...@@ -50,6 +50,7 @@ public: ...@@ -50,6 +50,7 @@ public:
WrapPolygon::Pointer_t move(const css::awt::Point & rMove); WrapPolygon::Pointer_t move(const css::awt::Point & rMove);
WrapPolygon::Pointer_t scale(const Fraction & rFractionX, const Fraction & rFractionY); WrapPolygon::Pointer_t scale(const Fraction & rFractionX, const Fraction & rFractionY);
WrapPolygon::Pointer_t correctWordWrapPolygon(const css::awt::Size & rSrcSize); WrapPolygon::Pointer_t correctWordWrapPolygon(const css::awt::Size & rSrcSize);
WrapPolygon::Pointer_t correctWordWrapPolygonPixel(const css::awt::Size & rSrcSize);
css::drawing::PointSequenceSequence getPointSequenceSequence() const; css::drawing::PointSequenceSequence getPointSequenceSequence() const;
}; };
......
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