diff options
author | Regényi Balázs <regenyi.balazs@nisz.hu> | 2020-12-01 12:16:12 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-12-10 10:27:33 +0100 |
commit | bda05ba17362222b74727872579b65b3fa14e3d8 (patch) | |
tree | 60d9448754f1a992e7e9695c8f458b55cfb62d69 /oox/source/vml | |
parent | 7720f8cf22718415adb3db2304916581f864f884 (diff) |
tdf#41466 DOCX import: fix VML v:shape/v:textbox
VML v:shape/v:textbox element was imported only as
a text frame, losing (otherwise recognized) preset
shape geometry, i.e. replacing a callout bubble
(wedgeRectCallout) and other special shapes with a
plain rectangle.
Thanks to Attila Bakos for the initial help.
Change-Id: I03a608822ed54a20ed07406a08c3539e72958f5b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105299
Tested-by: Jenkins
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'oox/source/vml')
-rw-r--r-- | oox/source/vml/vmlshape.cxx | 32 | ||||
-rw-r--r-- | oox/source/vml/vmlshapecontext.cxx | 20 |
2 files changed, 45 insertions, 7 deletions
diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx index 1e3e1f72e64d..7ee10203341e 100644 --- a/oox/source/vml/vmlshape.cxx +++ b/oox/source/vml/vmlshape.cxx @@ -69,6 +69,7 @@ #include <comphelper/processfactory.hxx> #include <comphelper/propertyvalue.hxx> #include <comphelper/storagehelper.hxx> +#include <comphelper/sequenceashashmap.hxx> using ::com::sun::star::beans::XPropertySet; using ::com::sun::star::uno::Any; @@ -259,6 +260,7 @@ ShapeModel::ShapeModel() : mbIsSignatureLine(false) , mbSignatureLineShowSignDate(true) , mbSignatureLineCanAddComment(false) + , mbInGroup(false) { } @@ -459,6 +461,8 @@ Reference< XShape > ShapeBase::convertAndInsert( const Reference< XShapes >& rxS PropertySet aControlShapeProp( xControlShape->getControl() ); aControlShapeProp.setProperty( PROP_EnableVisible, uno::makeAny( false ) ); } + + xShape = finalImplConvertAndInsert(xShape); /* Notify the drawing that a new shape has been inserted. For convenience, pass the rectangle that contains position and size of the shape. */ @@ -887,6 +891,34 @@ Reference< XShape > SimpleShape::implConvertAndInsert( const Reference< XShapes return xShape; } +Reference<XShape> SimpleShape::finalImplConvertAndInsert(const css::uno::Reference<css::drawing::XShape>& rxShape) const +{ + // tdf#41466 This setting must be done here, because the position of textbox will be set as an + // effect of the PROP_TextBox property setting, and if we do this setting earlier (setting of + // properties of position and size) then the position of textbox will be set with wrong data. + // TODO: TextShape is set if we have rect shape in group; we should use the shape-with-textbox + // mechanism to handle this situation + if (getTextBox() && maService != "com.sun.star.text.TextFrame" && maService != "com.sun.star.drawing.TextShape" + && !maShapeModel.mbInGroup) + { + const GraphicHelper& rGraphicHelper = mrDrawing.getFilter().getGraphicHelper(); + const auto& nLeft = ConversionHelper::decodeMeasureToHmm( + rGraphicHelper, maTypeModel.maMarginLeft, 0, true, true); + PropertySet aPropertySet(rxShape); + aPropertySet.setProperty(PROP_HoriOrientPosition, nLeft); + const auto& nTop = ConversionHelper::decodeMeasureToHmm( + rGraphicHelper, maTypeModel.maMarginTop, 0, true, true); + aPropertySet.setProperty(PROP_VertOrientPosition, nTop); + aPropertySet.setProperty(PROP_TextBox, true); + + // And these properties must be set after textbox creation (set PROP_Textbox property). + // Note: if you set a new property then you have to handle it in the proper + // SwTextBoxHelper::syncProperty function. + if (maTypeModel.maLayoutFlowAlt == "bottom-to-top") + aPropertySet.setAnyProperty(PROP_TextWritingMode, uno::makeAny(text::WritingMode2::BT_LR)); + } + return ShapeBase::finalImplConvertAndInsert(rxShape); +} Reference< XShape > SimpleShape::createEmbeddedPictureObject( const Reference< XShapes >& rxShapes, const awt::Rectangle& rShapeRect, OUString const & rGraphicPath ) const { Reference<XGraphic> xGraphic = mrDrawing.getFilter().getGraphicHelper().importEmbeddedGraphic(rGraphicPath); diff --git a/oox/source/vml/vmlshapecontext.cxx b/oox/source/vml/vmlshapecontext.cxx index f1ba9e32340c..e8f1b0b1910e 100644 --- a/oox/source/vml/vmlshapecontext.cxx +++ b/oox/source/vml/vmlshapecontext.cxx @@ -499,20 +499,26 @@ ContextHandlerRef ShapeContext::onCreateContext( sal_Int32 nElement, const Attri nShapeType = pShapeType->getTypeModel().moShapeType.get(); } } + mrShapeModel.mbInGroup = (getParentElement() == VML_TOKEN(group)); - if (getParentElement() != VML_TOKEN( group )) + // FIXME: the shape with textbox should be used for the next cases + if (getCurrentElement() == VML_TOKEN(rect) || nShapeType == ESCHER_ShpInst_TextBox) { - // Custom shape in Writer with a textbox are transformed into a frame - dynamic_cast<SimpleShape&>( mrShape ).setService( - "com.sun.star.text.TextFrame"); + if (mrShapeModel.mbInGroup) + // FIXME: without this a text will be added into the group-shape instead of its + // parent shape + dynamic_cast<SimpleShape&>(mrShape).setService("com.sun.star.drawing.TextShape"); + else + // FIXME: without this we does not handle some properties like shadow + dynamic_cast<SimpleShape&>(mrShape).setService("com.sun.star.text.TextFrame"); } - else if (getCurrentElement() == VML_TOKEN(rect) || nShapeType == ESCHER_ShpInst_TextBox) - // Transform only rectangles into a TextShape inside a groupshape. - dynamic_cast<SimpleShape&>(mrShape).setService("com.sun.star.drawing.TextShape"); return new TextBoxContext( *this, mrShapeModel.createTextBox(mrShape.getTypeModel()), rAttribs, mrShape.getDrawing().getFilter().getGraphicHelper()); } case VMLX_TOKEN( ClientData ): + // tdf#41466 ActiveX control shapes with a textbox are transformed into a frame + // (see unit test testActiveXOptionButtonGroup) + dynamic_cast<SimpleShape&>(mrShape).setService("com.sun.star.text.TextFrame"); return new ClientDataContext( *this, mrShapeModel.createClientData(), rAttribs ); case VMLPPT_TOKEN( textdata ): // Force RectangleShape, this is ugly :( |