diff options
author | Michael Stahl <mstahl@redhat.com> | 2017-11-02 22:13:32 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2017-11-02 22:35:31 +0100 |
commit | c79467ba954987f1d239c594c1e1b3af3f5515f6 (patch) | |
tree | 5138f2c58869a486619bdac51814c0093a5c655f /oox | |
parent | 9a236714e539c772cad7b56caf21dc12b79e77df (diff) |
sw: ODF import: default as-char shapes to vertical-pos="top"
The problem is that we don't render ShapesWithWrapping.odt
the same as Word does:
https://beta.opendocumentformat.org/rendercompare/upload/223/86/191/1
The first shape in the file is anchored "as-char" and has no
style:vertical-rel or style:vertical-pos attribute affecting it.
If Word would write either style:vertical-rel="baseline" or
style:vertical-pos="top" explicitly, the rendering in LO would
be the same.
So the problem is that, for drawing shapes (note, text frames are
images, embedded objects handled differently), LO's default
vertical alignment is different, it is hard-coded in
SwShapeDescriptor_Impl::GetVOrient() as
SwFormatVertOrient(0, text::VertOrientation::NONE, text::RelOrientation::FRAME)
This effectively positions as-char shapes *below* the baseline,
which, while technically allowed, isn't really a good default.
So fix this by making the default alignment dependent on the anchor
type, so that as-char shapes sit on top of the baseline.
The ODF filter sets the anchor type before inserting the shape in
XMLTextShapeImportHelper::addShape(), however as it turns out the
various MSO filters insert the shape before setting the anchor,
which means the new default in SwXShape has an unwanted effect
on them, as inserting the shape causes the default to be created.
This requires changes to VML import to always set the VertOrient
property, and to RTF import to set the anchor type before inserting.
The DrawingML import is unaffected as it already sets VertOrient
for every non-as-char shape.
The testDmlTextshape "dml-textshape.docx" test still fails, but it
turns out that the change in alignment for this test document is
a bugfix, as it now has the same vertical alignment as in Word,
so adapt the test.
Change-Id: Ifcabd96a037515f7803f5474ec995f968b3b4de1
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/vml/vmlshape.cxx | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx index 2c1acb029916..74ae15f848f3 100644 --- a/oox/source/vml/vmlshape.cxx +++ b/oox/source/vml/vmlshape.cxx @@ -564,6 +564,39 @@ void lcl_setSurround(PropertySet& rPropSet, const ShapeTypeModel& rTypeModel, co void lcl_SetAnchorType(PropertySet& rPropSet, const ShapeTypeModel& rTypeModel, const GraphicHelper& rGraphicHelper) { + if ( rTypeModel.maPosition == "absolute" ) + { + // Word supports as-character (inline) and at-character only, absolute can't be inline. + rPropSet.setProperty(PROP_AnchorType, text::TextContentAnchorType_AT_CHARACTER); + // anchor is set after insertion, so reset to NONE + rPropSet.setAnyProperty(PROP_VertOrient, makeAny(text::VertOrientation::NONE)); + + if ( rTypeModel.maPositionVerticalRelative == "page" ) + { + rPropSet.setProperty(PROP_VertOrientRelation, text::RelOrientation::PAGE_FRAME); + } + else if ( rTypeModel.maPositionVerticalRelative == "margin" ) + { + rPropSet.setProperty(PROP_VertOrientRelation, text::RelOrientation::PAGE_PRINT_AREA); + } + else + { + rPropSet.setProperty(PROP_VertOrientRelation, text::RelOrientation::FRAME); + } + } + else if( rTypeModel.maPosition == "relative" ) + { // I'm not very sure this is correct either. + rPropSet.setProperty(PROP_AnchorType, text::TextContentAnchorType_AT_PARAGRAPH); + // anchor is set after insertion, so reset to NONE + rPropSet.setAnyProperty(PROP_VertOrient, makeAny(text::VertOrientation::NONE)); + } + else // static (is the default) means anchored inline + { + rPropSet.setProperty(PROP_AnchorType, text::TextContentAnchorType_AS_CHARACTER); + // Use top orientation, this one seems similar to what MSO uses as inline + rPropSet.setAnyProperty(PROP_VertOrient, makeAny(text::VertOrientation::TOP)); + } + if ( rTypeModel.maPositionHorizontal == "center" ) rPropSet.setAnyProperty(PROP_HoriOrient, makeAny(text::HoriOrientation::CENTER)); else if ( rTypeModel.maPositionHorizontal == "left" ) @@ -599,34 +632,6 @@ void lcl_SetAnchorType(PropertySet& rPropSet, const ShapeTypeModel& rTypeModel, else if ( rTypeModel.maPositionVertical == "outside" ) rPropSet.setAnyProperty(PROP_VertOrient, makeAny(text::VertOrientation::LINE_BOTTOM)); - if ( rTypeModel.maPosition == "absolute" ) - { - // Word supports as-character (inline) and at-character only, absolute can't be inline. - rPropSet.setProperty(PROP_AnchorType, text::TextContentAnchorType_AT_CHARACTER); - - if ( rTypeModel.maPositionVerticalRelative == "page" ) - { - rPropSet.setProperty(PROP_VertOrientRelation, text::RelOrientation::PAGE_FRAME); - } - else if ( rTypeModel.maPositionVerticalRelative == "margin" ) - { - rPropSet.setProperty(PROP_VertOrientRelation, text::RelOrientation::PAGE_PRINT_AREA); - } - else - { - rPropSet.setProperty(PROP_VertOrientRelation, text::RelOrientation::FRAME); - } - } - else if( rTypeModel.maPosition == "relative" ) - { // I'm not very sure this is correct either. - rPropSet.setProperty(PROP_AnchorType, text::TextContentAnchorType_AT_PARAGRAPH); - } - else // static (is the default) means anchored inline - { - rPropSet.setProperty(PROP_AnchorType, text::TextContentAnchorType_AS_CHARACTER); - // Use top orientation, this one seems similar to what MSO uses as inline - rPropSet.setAnyProperty(PROP_VertOrient, makeAny(text::VertOrientation::TOP)); - } lcl_setSurround( rPropSet, rTypeModel, rGraphicHelper ); } |