drawingML export/import: text frames with vertical alignment

Change-Id: I469da0a8234dd2979facfed3d66907aad1a138ab
This commit is contained in:
Zolnai Tamás
2014-02-08 01:49:39 +01:00
parent cf9d819493
commit 718203e370
8 changed files with 80 additions and 21 deletions

View File

@@ -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

View File

@@ -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 )
{

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -11,6 +11,7 @@
#include <oox/drawingml/shapepropertiescontext.hxx>
#include <oox/drawingml/shapestylecontext.hxx>
#include <com/sun/star/beans/XPropertyState.hpp>
#include <oox/drawingml/drawingmltypes.hxx>
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;

View File

@@ -49,6 +49,7 @@
#include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp>
#include <com/sun/star/drawing/EnhancedCustomShapeSegmentCommand.hpp>
#include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
#include <com/sun/star/drawing/TextVerticalAdjust.hpp>
#include <libxml/xpathInternals.h>
#include <libxml/parserInternals.h>
@@ -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<beans::XPropertySet> xFrame(getTextFrameByName("Rectangle 1"), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(drawing::TextVerticalAdjust_TOP, getProperty<drawing::TextVerticalAdjust>(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<drawing::TextVerticalAdjust>(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<drawing::TextVerticalAdjust>(xFrame, "TextVerticalAdjust"));
}
#endif
CPPUNIT_PLUGIN_IMPLEMENT();

View File

@@ -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);