summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2015-11-21 16:18:38 +1000
committerMichael Meeks <michael.meeks@collabora.com>2015-11-23 11:32:08 +0000
commitd59ef5b2ddb9249905fecf941be6ec83251d12de (patch)
treefc03b5080f7795fad15a79fac66d2dfc9171a7f5 /writerfilter
parent0cda1453a0e24e9ad6884a1345e4514a86900346 (diff)
tdf#60351: Use Wrap Polygon also for PROP_SIZE_PIXEL
Since commit 2b5bf2f1c57d6585ec898c4c44a74c5b47f09ab9 "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/20103 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Tested-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/GraphicImport.cxx39
-rw-r--r--writerfilter/source/dmapper/WrapPolygonHandler.cxx23
-rw-r--r--writerfilter/source/dmapper/WrapPolygonHandler.hxx1
3 files changed, 52 insertions, 11 deletions
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 9cd8852a781f..c5adee73d0c0 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -1136,7 +1136,7 @@ uno::Reference< text::XTextContent > GraphicImport::createGraphicObject( const b
if(xGraphic.is())
{
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);
xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_GRAPHIC), uno::makeAny( xGraphic ));
xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_ANCHOR_TYPE),
@@ -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
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( aGraphicSize.Width && aGraphicSize.Height &&
- m_pImpl->mpWrapPolygon.get() != nullptr)
+ if (m_pImpl->mpWrapPolygon.get() != nullptr)
{
- WrapPolygon::Pointer_t pCorrected = m_pImpl->mpWrapPolygon->correctWordWrapPolygon(aGraphicSize);
- aContourPolyPolygon <<= pCorrected->getPointSequenceSequence();
+ uno::Any aContourPolyPolygon;
+ 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)
{
diff --git a/writerfilter/source/dmapper/WrapPolygonHandler.cxx b/writerfilter/source/dmapper/WrapPolygonHandler.cxx
index 8a66e822bba3..02732cfe1cd0 100644
--- a/writerfilter/source/dmapper/WrapPolygonHandler.cxx
+++ b/writerfilter/source/dmapper/WrapPolygonHandler.cxx
@@ -111,6 +111,29 @@ WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygon(const awt::Size & rSr
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 aPolyPolygon(1L);
diff --git a/writerfilter/source/dmapper/WrapPolygonHandler.hxx b/writerfilter/source/dmapper/WrapPolygonHandler.hxx
index e6f91758c1a3..d5122c51a442 100644
--- a/writerfilter/source/dmapper/WrapPolygonHandler.hxx
+++ b/writerfilter/source/dmapper/WrapPolygonHandler.hxx
@@ -50,6 +50,7 @@ public:
WrapPolygon::Pointer_t move(const css::awt::Point & rMove);
WrapPolygon::Pointer_t scale(const Fraction & rFractionX, const Fraction & rFractionY);
WrapPolygon::Pointer_t correctWordWrapPolygon(const css::awt::Size & rSrcSize);
+ WrapPolygon::Pointer_t correctWordWrapPolygonPixel(const css::awt::Size & rSrcSize);
css::drawing::PointSequenceSequence getPointSequenceSequence() const;
};