[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - include/oox oox/source sw/qa
Miklos Vajna
vmiklos at collabora.co.uk
Mon May 2 07:38:38 UTC 2016
include/oox/vml/vmlshape.hxx | 4 +++
oox/source/vml/vmlshape.cxx | 33 ++++++++++++++++++++++++++++
oox/source/vml/vmlshapecontext.cxx | 6 +++++
sw/qa/extras/ooxmlimport/data/tdf99135.docx |binary
sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 6 +++++
5 files changed, 49 insertions(+)
New commits:
commit 3d447579a6193d8bfe020e86c930a90a627969e1
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Apr 12 09:18:47 2016 +0200
tdf#99135 VML import: handle image crop
The spec says in theory a % suffix could be also supported, but let's
wait till that is seen in a real-world document.
Change-Id: Ie026915e38dcb03c99085a1740075364b00e1c8d
(cherry picked from commit bb646c1472d3b77066b01128baf1c9cafdb40233)
Reviewed-on: https://gerrit.libreoffice.org/24364
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Andras Timar <andras.timar at collabora.com>
diff --git a/include/oox/vml/vmlshape.hxx b/include/oox/vml/vmlshape.hxx
index 927f8c1a..18076c6 100644
--- a/include/oox/vml/vmlshape.hxx
+++ b/include/oox/vml/vmlshape.hxx
@@ -104,6 +104,10 @@ struct OOX_DLLPUBLIC ShapeTypeModel
OUString maWrapDistanceRight; ///< Distance from the right side of the shape to the text that wraps around it.
OUString maWrapDistanceTop; ///< Distance from the top of the shape to the text that wraps around it.
OUString maWrapDistanceBottom; ///< Distance from the bottom of the shape to the text that wraps around it.
+ OptValue<OUString> moCropBottom; ///< Specifies the how much to crop the image from the bottom up as a fraction of picture size.
+ OptValue<OUString> moCropLeft; ///< Specifies how much to crop the image from the left in as a fraction of picture size.
+ OptValue<OUString> moCropRight; ///< Specifies how much to crop the image from the right in as a fraction of picture size.
+ OptValue<OUString> moCropTop; ///< Specifies how much to crop the image from the top down as a fraction of picture size.
OUString maLayoutFlowAlt; ///< Specifies the alternate layout flow for text in textboxes.
explicit ShapeTypeModel();
diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx
index 222e38d..7473141 100644
--- a/oox/source/vml/vmlshape.cxx
+++ b/oox/source/vml/vmlshape.cxx
@@ -44,6 +44,7 @@
#include <com/sun/star/text/XTextFrame.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/text/TextContentAnchorType.hpp>
+#include <com/sun/star/text/GraphicCrop.hpp>
#include <rtl/math.hxx>
#include <rtl/ustrbuf.hxx>
#include <svx/svdtrans.hxx>
@@ -106,6 +107,19 @@ awt::Rectangle lclGetAbsRect( const awt::Rectangle& rRelRect, const awt::Rectang
return aAbsRect;
}
+/// Count the crop value based on a crop fraction and a reference size.
+sal_Int32 lclConvertCrop(const OUString& rCrop, sal_uInt32 nSize)
+{
+ if (rCrop.endsWith("f"))
+ {
+ // Numeric value is specified in 1/65536-ths.
+ sal_uInt32 nCrop = rCrop.copy(0, rCrop.getLength() - 1).toUInt32();
+ return (nCrop * nSize) / 65536;
+ }
+
+ return 0;
+}
+
} // namespace
ShapeTypeModel::ShapeTypeModel():
@@ -851,6 +865,25 @@ Reference< XShape > SimpleShape::createPictureObject( const Reference< XShapes >
const GraphicHelper& rGraphicHelper = mrDrawing.getFilter().getGraphicHelper();
lcl_SetAnchorType(aPropSet, maTypeModel, rGraphicHelper);
+
+ if (maTypeModel.moCropBottom.has() || maTypeModel.moCropLeft.has() || maTypeModel.moCropRight.has() || maTypeModel.moCropTop.has())
+ {
+ text::GraphicCrop aGraphicCrop;
+ uno::Reference<graphic::XGraphic> xGraphic;
+ aPropSet.getProperty(xGraphic, PROP_Graphic);
+ awt::Size aOriginalSize = rGraphicHelper.getOriginalSize(xGraphic);
+
+ if (maTypeModel.moCropBottom.has())
+ aGraphicCrop.Bottom = lclConvertCrop(maTypeModel.moCropBottom.get(), aOriginalSize.Height);
+ if (maTypeModel.moCropLeft.has())
+ aGraphicCrop.Left = lclConvertCrop(maTypeModel.moCropLeft.get(), aOriginalSize.Width);
+ if (maTypeModel.moCropRight.has())
+ aGraphicCrop.Right = lclConvertCrop(maTypeModel.moCropRight.get(), aOriginalSize.Width);
+ if (maTypeModel.moCropTop.has())
+ aGraphicCrop.Top = lclConvertCrop(maTypeModel.moCropTop.get(), aOriginalSize.Height);
+
+ aPropSet.setProperty(PROP_GraphicCrop, aGraphicCrop);
+ }
}
return xShape;
}
diff --git a/oox/source/vml/vmlshapecontext.cxx b/oox/source/vml/vmlshapecontext.cxx
index de0423c..f193227 100644
--- a/oox/source/vml/vmlshapecontext.cxx
+++ b/oox/source/vml/vmlshapecontext.cxx
@@ -347,6 +347,12 @@ ContextHandlerRef ShapeTypeContext::onCreateContext( sal_Int32 nElement, const A
bool bHasORelId = rAttribs.hasAttribute( O_TOKEN( relid ) );
mrTypeModel.moGraphicPath = decodeFragmentPath( rAttribs, bHasORelId ? O_TOKEN( relid ) : R_TOKEN( id ) );
mrTypeModel.moGraphicTitle = rAttribs.getString( O_TOKEN( title ) );
+
+ // Get crop attributes.
+ mrTypeModel.moCropBottom = rAttribs.getString(XML_cropbottom);
+ mrTypeModel.moCropLeft = rAttribs.getString(XML_cropleft);
+ mrTypeModel.moCropRight = rAttribs.getString(XML_cropright);
+ mrTypeModel.moCropTop = rAttribs.getString(XML_croptop);
}
break;
case NMSP_vmlWord | XML_wrap:
diff --git a/sw/qa/extras/ooxmlimport/data/tdf99135.docx b/sw/qa/extras/ooxmlimport/data/tdf99135.docx
new file mode 100644
index 0000000..7ac3836
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf99135.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index d1c5b08..b336fcb 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -2089,6 +2089,12 @@ DECLARE_OOXMLIMPORT_TEST(testPictureWithSchemeColor, "picture-with-schemecolor.d
Bitmap::ReleaseAccess(pAccess);
}
+DECLARE_OOXMLIMPORT_TEST(testTdf99135, "tdf99135.docx")
+{
+ // This was 0, crop was ignored on VML import.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1825), getProperty<text::GraphicCrop>(getShape(1), "GraphicCrop").Bottom);
+}
+
DECLARE_OOXMLIMPORT_TEST(testFdo69656, "Table_cell_auto_width_fdo69656.docx")
{
uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
More information about the Libreoffice-commits
mailing list