diff options
author | Miklos Vajna <vmiklos@suse.cz> | 2013-07-01 12:05:23 +0200 |
---|---|---|
committer | Fridrich Strba <fridrich@documentfoundation.org> | 2013-07-02 14:15:30 +0000 |
commit | 2b4d78598c55389b24b4a5016279aed26ac0fb2e (patch) | |
tree | 14238365c69950ecdd159566c566002e4e8b4141 /oox | |
parent | 3820420edfb828e49735becf796803f0558ef844 (diff) |
fdo#46361 oox: fixes for the VML import of groupshape textboxes
(cherry picked from commits b1f78c44c1acc246f06a963383232c9bf649a06b,
f24e4c74d7d6a7d95090c6fa6a584fed7787706c,
6bf79576aeca243db553ed3b5eade492dc35337b,
5a737fca37cd5a5f90aa03a30688d447677d3b8a,
ef53d4aec2a3d690de2c7cdaf73ca95bbe29a433 and
2a2105b002c482e6536d5c3046c9e7783c0cdca3)
Conflicts:
sw/qa/extras/ooxmlimport/ooxmlimport.cxx
Change-Id: Ie7ce4fb5c32ff4b3c1f3d7ee92d8358ae67fc6c1
Reviewed-on: https://gerrit.libreoffice.org/4675
Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org>
Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/vml/vmlshape.cxx | 9 | ||||
-rw-r--r-- | oox/source/vml/vmlshapecontext.cxx | 1 | ||||
-rw-r--r-- | oox/source/vml/vmltextbox.cxx | 34 | ||||
-rw-r--r-- | oox/source/vml/vmltextboxcontext.cxx | 46 |
4 files changed, 80 insertions, 10 deletions
diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx index 0d0f80f0a73c..872ccace661a 100644 --- a/oox/source/vml/vmlshape.cxx +++ b/oox/source/vml/vmlshape.cxx @@ -27,6 +27,7 @@ #include <com/sun/star/awt/XControlModel.hpp> #include <com/sun/star/drawing/PointSequenceSequence.hpp> #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp> +#include <com/sun/star/drawing/TextVerticalAdjust.hpp> #include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp> #include <com/sun/star/drawing/XShapes.hpp> #include <com/sun/star/drawing/XControlShape.hpp> @@ -545,6 +546,14 @@ Reference< XShape > SimpleShape::implConvertAndInsert( const Reference< XShapes } } + // drawinglayer default is center, MSO default is top. + drawing::TextVerticalAdjust eTextVerticalAdjust = drawing::TextVerticalAdjust_TOP; + if (maTypeModel.maVTextAnchor == "middle") + eTextVerticalAdjust = drawing::TextVerticalAdjust_CENTER; + else if (maTypeModel.maVTextAnchor == "bottom") + eTextVerticalAdjust = drawing::TextVerticalAdjust_BOTTOM; + PropertySet(xShape).setAnyProperty(PROP_TextVerticalAdjust, makeAny(eTextVerticalAdjust)); + if (getTextBox()) getTextBox()->convert(xShape); } diff --git a/oox/source/vml/vmlshapecontext.cxx b/oox/source/vml/vmlshapecontext.cxx index efa6e3888cbe..3c47c668cd39 100644 --- a/oox/source/vml/vmlshapecontext.cxx +++ b/oox/source/vml/vmlshapecontext.cxx @@ -417,6 +417,7 @@ void ShapeTypeContext::setStyle( const OUString& rStyle ) else if( aName.equalsAscii( "visibility" ) ) mrTypeModel.mbVisible = !aValue.equalsAscii( "hidden" ); else if( aName == "mso-wrap-style" ) mrTypeModel.maWrapStyle = aValue; + else if ( aName == "v-text-anchor" ) mrTypeModel.maVTextAnchor = aValue; } } } diff --git a/oox/source/vml/vmltextbox.cxx b/oox/source/vml/vmltextbox.cxx index 1499091a8cfd..6fe51b147f0d 100644 --- a/oox/source/vml/vmltextbox.cxx +++ b/oox/source/vml/vmltextbox.cxx @@ -24,6 +24,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/text/XTextAppend.hpp> #include <com/sun/star/text/WritingMode.hpp> +#include <com/sun/star/style/ParagraphAdjust.hpp> namespace oox { namespace vml { @@ -34,7 +35,8 @@ TextFontModel::TextFontModel() { } -TextPortionModel::TextPortionModel( const TextFontModel& rFont, const OUString& rText ) : +TextPortionModel::TextPortionModel( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText ) : + maParagraph( rParagraph ), maFont( rFont ), maText( rText ) { @@ -50,9 +52,9 @@ TextBox::TextBox(ShapeTypeModel& rTypeModel) { } -void TextBox::appendPortion( const TextFontModel& rFont, const OUString& rText ) +void TextBox::appendPortion( const TextParagraphModel& rParagraph, const TextFontModel& rFont, const OUString& rText ) { - maPortions.push_back( TextPortionModel( rFont, rText ) ); + maPortions.push_back( TextPortionModel( rParagraph, rFont, rText ) ); } const TextFontModel* TextBox::getFirstFont() const @@ -75,6 +77,7 @@ void TextBox::convert(uno::Reference<drawing::XShape> xShape) const { beans::PropertyValue aPropertyValue; std::vector<beans::PropertyValue> aPropVec; + const TextParagraphModel& rParagraph = aIt->maParagraph; const TextFontModel& rFont = aIt->maFont; if (rFont.mobBold.has()) { @@ -88,6 +91,24 @@ void TextBox::convert(uno::Reference<drawing::XShape> xShape) const aPropertyValue.Value = uno::makeAny(double(rFont.monSize.get()) / 2.); aPropVec.push_back(aPropertyValue); } + if (rParagraph.moParaAdjust.has()) + { + style::ParagraphAdjust eAdjust = style::ParagraphAdjust_LEFT; + if (rParagraph.moParaAdjust.get() == "center") + eAdjust = style::ParagraphAdjust_CENTER; + else if (rParagraph.moParaAdjust.get() == "right") + eAdjust = style::ParagraphAdjust_RIGHT; + + aPropertyValue.Name = "ParaAdjust"; + aPropertyValue.Value = uno::makeAny(eAdjust); + aPropVec.push_back(aPropertyValue); + } + if (rFont.moColor.has()) + { + aPropertyValue.Name = "CharColor"; + aPropertyValue.Value = uno::makeAny(rFont.moColor.get().toInt32(16)); + aPropVec.push_back(aPropertyValue); + } uno::Sequence<beans::PropertyValue> aPropSeq(aPropVec.size()); beans::PropertyValue* pValues = aPropSeq.getArray(); for (std::vector<beans::PropertyValue>::iterator i = aPropVec.begin(); i != aPropVec.end(); ++i) @@ -95,6 +116,13 @@ void TextBox::convert(uno::Reference<drawing::XShape> xShape) const xTextAppend->appendTextPortion(aIt->maText, aPropSeq); } + // Remove the last character of the shape text, if it would be a newline. + uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursor(); + xCursor->gotoEnd(false); + xCursor->goLeft(1, true); + if (xCursor->getString() == "\n") + xCursor->setString(""); + if ( maLayoutFlow == "vertical" ) { uno::Reference<beans::XPropertySet> xProperties(xShape, uno::UNO_QUERY); diff --git a/oox/source/vml/vmltextboxcontext.cxx b/oox/source/vml/vmltextboxcontext.cxx index 0adf9431ff03..d91c66ade821 100644 --- a/oox/source/vml/vmltextboxcontext.cxx +++ b/oox/source/vml/vmltextboxcontext.cxx @@ -34,10 +34,11 @@ using ::oox::core::ContextHandlerRef; // ============================================================================ TextPortionContext::TextPortionContext( ContextHandler2Helper& rParent, - TextBox& rTextBox, const TextFontModel& rParentFont, + TextBox& rTextBox, TextParagraphModel& rParagraph, const TextFontModel& rParentFont, sal_Int32 nElement, const AttributeList& rAttribs ) : ContextHandler2( rParent ), mrTextBox( rTextBox ), + maParagraph( rParagraph ), maFont( rParentFont ), mnInitialPortions( rTextBox.getPortionCount() ) { @@ -96,7 +97,7 @@ ContextHandlerRef TextPortionContext::onCreateContext( sal_Int32 nElement, const OSL_ENSURE( nElement != XML_font, "TextPortionContext::onCreateContext - nested <font> elements" ); if (getNamespace(getCurrentElement()) == NMSP_doc) return this; - return new TextPortionContext( *this, mrTextBox, maFont, nElement, rAttribs ); + return new TextPortionContext( *this, mrTextBox, maParagraph, maFont, nElement, rAttribs ); } void TextPortionContext::onCharacters( const OUString& rChars ) @@ -108,10 +109,10 @@ void TextPortionContext::onCharacters( const OUString& rChars ) { case XML_span: // replace all NBSP characters with SP - mrTextBox.appendPortion( maFont, rChars.replace( 0xA0, ' ' ) ); + mrTextBox.appendPortion( maParagraph, maFont, rChars.replace( 0xA0, ' ' ) ); break; default: - mrTextBox.appendPortion( maFont, rChars ); + mrTextBox.appendPortion( maParagraph, maFont, rChars ); } } @@ -125,6 +126,12 @@ void TextPortionContext::onStartElement(const AttributeList& rAttribs) case OOX_TOKEN(doc, sz): maFont.monSize = rAttribs.getInteger( OOX_TOKEN(doc, val) ); break; + case OOX_TOKEN(doc, br): + mrTextBox.appendPortion( maParagraph, maFont, "\n" ); + break; + case OOX_TOKEN(doc, color): + maFont.moColor = rAttribs.getString( OOX_TOKEN(doc, val) ); + break; } } @@ -150,7 +157,7 @@ void TextPortionContext::onEndElement() meantime, the space character has to be added manually. */ if( mrTextBox.getPortionCount() == mnInitialPortions ) - mrTextBox.appendPortion( maFont, OUString( sal_Unicode( ' ' ) ) ); + mrTextBox.appendPortion( maParagraph, maFont, OUString( sal_Unicode( ' ' ) ) ); } // ============================================================================ @@ -204,18 +211,43 @@ ContextHandlerRef TextBoxContext::onCreateContext( sal_Int32 nElement, const Att else if (nElement == OOX_TOKEN(doc, txbxContent)) return this; break; case XML_div: - if( nElement == XML_font ) return new TextPortionContext( *this, mrTextBox, TextFontModel(), nElement, rAttribs ); + if( nElement == XML_font ) return new TextPortionContext( *this, mrTextBox, maParagraph, TextFontModel(), nElement, rAttribs ); break; case OOX_TOKEN(doc, txbxContent): if (nElement == OOX_TOKEN(doc, p)) return this; break; case OOX_TOKEN(doc, p): - if (nElement == OOX_TOKEN(doc, r)) return new TextPortionContext( *this, mrTextBox, TextFontModel(), nElement, rAttribs ); + if (nElement == OOX_TOKEN(doc, r)) + return new TextPortionContext( *this, mrTextBox, maParagraph, TextFontModel(), nElement, rAttribs ); + else + return this; + break; + case OOX_TOKEN(doc, pPr): + return this; break; } return 0; } +void TextBoxContext::onStartElement(const AttributeList& rAttribs) +{ + switch (getCurrentElement()) + { + case OOX_TOKEN(doc, jc): + maParagraph.moParaAdjust = rAttribs.getString( OOX_TOKEN(doc, val) ); + break; + } +} + +void TextBoxContext::onEndElement() +{ + if (getCurrentElement() == OOX_TOKEN(doc, p)) + { + mrTextBox.appendPortion( maParagraph, TextFontModel(), "\n" ); + maParagraph = TextParagraphModel(); + } +} + // ============================================================================ } // namespace vml |