diff --git a/include/oox/drawingml/drawingmltypes.hxx b/include/oox/drawingml/drawingmltypes.hxx index aa00f2a28d98..20c8c988ea43 100644 --- a/include/oox/drawingml/drawingmltypes.hxx +++ b/include/oox/drawingml/drawingmltypes.hxx @@ -126,6 +126,12 @@ sal_Int16 GetCaseMap( sal_Int32 nToken ); /** converts a paragraph align to a ParaAdjust */ sal_Int16 GetParaAdjust( sal_Int32 nAlign ); +// Convert vertical adjust tokens to a TextVerticalAdjust item +::com::sun::star::drawing::TextVerticalAdjust GetTextVerticalAdjust( sal_Int32 nToken ); + +// Convert a TextVerticalAdjust item to string value appearing in ooxml +SAL_DLLPUBLIC const char* GetTextVerticalAdjust( ::com::sun::star::drawing::TextVerticalAdjust eAdjust ); + // ============================================================================ // CT_IndexRange diff --git a/oox/source/drawingml/drawingmltypes.cxx b/oox/source/drawingml/drawingmltypes.cxx index 9dd42eb01595..a96eaf382ffd 100644 --- a/oox/source/drawingml/drawingmltypes.cxx +++ b/oox/source/drawingml/drawingmltypes.cxx @@ -187,6 +187,45 @@ sal_Int16 GetParaAdjust( sal_Int32 nAlign ) return nEnum; } +TextVerticalAdjust GetTextVerticalAdjust( sal_Int32 nToken ) +{ + TextVerticalAdjust aVertAdjust; + switch( nToken ) + { + case XML_b: + aVertAdjust = TextVerticalAdjust_BOTTOM; + break; + case XML_dist: + case XML_just: + case XML_ctr: + aVertAdjust = TextVerticalAdjust_CENTER; + break; + case XML_t: + default: + aVertAdjust = TextVerticalAdjust_TOP; + break; + } + return aVertAdjust; +} + +const char* GetTextVerticalAdjust( TextVerticalAdjust eAdjust ) +{ + const char* sVerticalAdjust = 0; + switch( eAdjust ) + { + case TextVerticalAdjust_BOTTOM: + sVerticalAdjust = "b"; + break; + case TextVerticalAdjust_CENTER: + sVerticalAdjust = "ctr"; + break; + case TextVerticalAdjust_TOP: + default: + sVerticalAdjust = "t"; + break; + } + return sVerticalAdjust; +} TabAlign GetTabAlign( sal_Int32 aToken ) { diff --git a/oox/source/drawingml/textbodypropertiescontext.cxx b/oox/source/drawingml/textbodypropertiescontext.cxx index 358db9f9c987..81a99e824215 100644 --- a/oox/source/drawingml/textbodypropertiescontext.cxx +++ b/oox/source/drawingml/textbodypropertiescontext.cxx @@ -96,16 +96,9 @@ TextBodyPropertiesContext::TextBodyPropertiesContext( ContextHandler2Helper& rPa } // ST_TextAnchoringType - if( rAttribs.hasAttribute( XML_anchor ) ) { - switch( rAttribs.getToken( XML_anchor, XML_t ) ) - { - case XML_b : mrTextBodyProp.meVA = drawing::TextVerticalAdjust_BOTTOM; break; - case XML_dist : - case XML_just : - case XML_ctr : mrTextBodyProp.meVA = drawing::TextVerticalAdjust_CENTER; break; - default: - case XML_t : mrTextBodyProp.meVA = drawing::TextVerticalAdjust_TOP; break; - } + if( rAttribs.hasAttribute( XML_anchor ) ) + { + mrTextBodyProp.meVA = GetTextVerticalAdjust( rAttribs.getToken( XML_anchor, XML_t ) ); mrTextBodyProp.maPropertyMap[ PROP_TextVerticalAdjust ] <<= mrTextBodyProp.meVA; } diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 11fd26afd01f..f2dd046a3cf7 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -1541,17 +1541,8 @@ void DrawingML::WriteText( Reference< XInterface > rXIface, bool bBodyPr, bool b TextVerticalAdjust eVerticalAlignment( TextVerticalAdjust_TOP ); const char* sVerticalAlignment = NULL; GET( eVerticalAlignment, TextVerticalAdjust ); - switch( eVerticalAlignment ) { - case TextVerticalAdjust_BOTTOM: - sVerticalAlignment = "b"; - break; - case TextVerticalAdjust_CENTER: - sVerticalAlignment = "ctr"; - break; - case TextVerticalAdjust_TOP: - default: - ; - } + if( eVerticalAlignment != TextVerticalAdjust_TOP ) + sVerticalAlignment = GetTextVerticalAdjust(eVerticalAlignment); const char* sWritingMode = NULL; sal_Bool bVertical = sal_False; diff --git a/oox/source/shape/WpsContext.cxx b/oox/source/shape/WpsContext.cxx index 04e8a232332c..7d37fc19f54f 100644 --- a/oox/source/shape/WpsContext.cxx +++ b/oox/source/shape/WpsContext.cxx @@ -11,6 +11,7 @@ #include #include #include +#include using namespace com::sun::star; @@ -86,6 +87,13 @@ oox::core::ContextHandlerRef WpsContext::onCreateContext(sal_Int32 nElementToken for (size_t i = 0; i < SAL_N_ELEMENTS(aProps); ++i) if (oInsets[i]) xPropertySet->setPropertyValue(aProps[i], uno::makeAny(*oInsets[i])); + + // Handle text vertical adjustment inside a text frame + if( rAttribs.hasAttribute( XML_anchor ) ) + { + drawing::TextVerticalAdjust eAdjust = drawingml::GetTextVerticalAdjust( rAttribs.getToken( XML_anchor, XML_t ) ); + xPropertySet->setPropertyValue("TextVerticalAdjust", uno::makeAny(eAdjust)); + } return this; } break; diff --git a/sw/qa/extras/ooxmlexport/data/dml-textframe-vertadjust.docx b/sw/qa/extras/ooxmlexport/data/dml-textframe-vertadjust.docx new file mode 100644 index 000000000000..bf5dcdde43a1 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/dml-textframe-vertadjust.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 1284699ca6e1..27fba459a20e 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -2868,6 +2869,21 @@ DECLARE_OOXMLEXPORT_TEST(testSegFaultWhileSave, "test_segfault_while_save.docx") CPPUNIT_ASSERT(getXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tblGrid/w:gridCol[2]", "w").match("6138")); } +DECLARE_OOXMLEXPORT_TEST(testDMLTextFrameVertAdjust, "dml-textframe-vertadjust.docx") +{ + // DOCX textboxes with text are imported as text frames but in Writer text frames did not have + // TextVerticalAdjust attribute so far. + + // 1st frame's context is adjusted to the top + uno::Reference xFrame(getTextFrameByName("Rectangle 1"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(drawing::TextVerticalAdjust_TOP, getProperty(xFrame, "TextVerticalAdjust")); + // 2nd frame's context is adjusted to the center + xFrame.set(getTextFrameByName("Rectangle 2"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(drawing::TextVerticalAdjust_CENTER, getProperty(xFrame, "TextVerticalAdjust")); + // 3rd frame's context is adjusted to the bottom + xFrame.set(getTextFrameByName("Rectangle 3"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(drawing::TextVerticalAdjust_BOTTOM, getProperty(xFrame, "TextVerticalAdjust")); +} #endif CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx index cd2bd55e4563..6278a29f4bb0 100644 --- a/sw/source/filter/ww8/docxsdrexport.cxx +++ b/sw/source/filter/ww8/docxsdrexport.cxx @@ -881,6 +881,12 @@ void DocxSdrExport::writeDMLTextFrame(sw::Frame* pParentFrame, int nAnchorId) FSEND); m_pImpl->m_bDMLTextFrameSyntax = true; m_pImpl->m_pBodyPrAttrList = pFS->createAttrList(); + { + drawing::TextVerticalAdjust eAdjust = drawing::TextVerticalAdjust_TOP; + if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName("TextVerticalAdjust") ) + xPropertySet->getPropertyValue("TextVerticalAdjust") >>= eAdjust; + m_pImpl->m_pBodyPrAttrList->add(XML_anchor, oox::drawingml::GetTextVerticalAdjust(eAdjust)); + } m_pImpl->m_rExport.OutputFormat(pParentFrame->GetFrmFmt(), false, false, true); m_pImpl->m_bDMLTextFrameSyntax = false; writeDMLEffectLst(rFrmFmt);