Kaydet (Commit) 0ed8f752 authored tarafından Miklos Vajna's avatar Miklos Vajna

writerfilter: implement CellMarginHandler::getInteropGrabBag

This allows roundtrip of the whole tblCellMar XML fragment.

Change-Id: I41c5afd6b1cfa7322f5f1bd8c44ed6bffe10eb41
üst 800005b1
......@@ -32,6 +32,8 @@ using namespace ::writerfilter;
CellMarginHandler::CellMarginHandler() :
LoggedProperties(dmapper_logger, "CellMarginHandler"),
m_nValue( 0 ),
m_nWidth( 0 ),
m_nType( 0 ),
m_nLeftMargin( 0 ),
m_bLeftMarginValid( false ),
m_nRightMargin( 0 ),
......@@ -55,16 +57,42 @@ void CellMarginHandler::lcl_attribute(Id rName, Value & rVal)
switch( rName )
{
case NS_ooxml::LN_CT_TblWidth_w:
m_nWidth = nIntValue;
m_nValue = ConversionHelper::convertTwipToMM100( nIntValue );
break;
case NS_ooxml::LN_CT_TblWidth_type:
OSL_ENSURE( NS_ooxml::LN_Value_ST_TblWidth_dxa == sal::static_int_cast<Id>(nIntValue), "cell margins work for absolute values, only");
m_nType = nIntValue;
break;
default:
OSL_FAIL( "unknown attribute");
}
}
void CellMarginHandler::createGrabBag(OUString aName)
{
if (m_aInteropGrabBagName.isEmpty())
return;
beans::PropertyValue aRet;
aRet.Name = aName;
uno::Sequence<beans::PropertyValue> aSeq(2);
aSeq[0].Name = "w";
aSeq[0].Value = uno::makeAny(m_nWidth);
aSeq[1].Name = "type";
switch (m_nType)
{
case NS_ooxml::LN_Value_ST_TblWidth_nil: aSeq[1].Value = uno::makeAny(OUString("nil")); break;
case NS_ooxml::LN_Value_ST_TblWidth_pct: aSeq[1].Value = uno::makeAny(OUString("pct")); break;
case NS_ooxml::LN_Value_ST_TblWidth_dxa: aSeq[1].Value = uno::makeAny(OUString("dxa")); break;
case NS_ooxml::LN_Value_ST_TblWidth_auto: aSeq[1].Value = uno::makeAny(OUString("auto")); break;
}
aRet.Value = uno::makeAny(aSeq);
m_aInteropGrabBag.push_back(aRet);
}
void CellMarginHandler::lcl_sprm(Sprm & rSprm)
{
writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
......@@ -78,6 +106,7 @@ void CellMarginHandler::lcl_sprm(Sprm & rSprm)
case NS_ooxml::LN_CT_TcMar_top:
m_nTopMargin = m_nValue;
m_bTopMarginValid = true;
createGrabBag("top");
break;
case NS_ooxml::LN_CT_TblCellMar_start:
if( rtl )
......@@ -90,16 +119,19 @@ void CellMarginHandler::lcl_sprm(Sprm & rSprm)
m_nLeftMargin = m_nValue;
m_bLeftMarginValid = true;
}
createGrabBag("start");
break;
case NS_ooxml::LN_CT_TblCellMar_left:
case NS_ooxml::LN_CT_TcMar_left:
m_nLeftMargin = m_nValue;
m_bLeftMarginValid = true;
createGrabBag("left");
break;
case NS_ooxml::LN_CT_TblCellMar_bottom:
case NS_ooxml::LN_CT_TcMar_bottom:
m_nBottomMargin = m_nValue;
m_bBottomMarginValid = true;
createGrabBag("bottom");
break;
case NS_ooxml::LN_CT_TblCellMar_end:
if( rtl )
......@@ -112,11 +144,13 @@ void CellMarginHandler::lcl_sprm(Sprm & rSprm)
m_nRightMargin = m_nValue;
m_bRightMarginValid = true;
}
createGrabBag("end");
break;
case NS_ooxml::LN_CT_TblCellMar_right:
case NS_ooxml::LN_CT_TcMar_right:
m_nRightMargin = m_nValue;
m_bRightMarginValid = true;
createGrabBag("right");
break;
default:
OSL_FAIL( "unknown sprm");
......@@ -124,6 +158,26 @@ void CellMarginHandler::lcl_sprm(Sprm & rSprm)
}
m_nValue = 0;
}
void CellMarginHandler::enableInteropGrabBag(OUString aName)
{
m_aInteropGrabBagName = aName;
}
beans::PropertyValue CellMarginHandler::getInteropGrabBag()
{
beans::PropertyValue aRet;
aRet.Name = m_aInteropGrabBagName;
uno::Sequence<beans::PropertyValue> aSeq(m_aInteropGrabBag.size());
beans::PropertyValue* pSeq = aSeq.getArray();
for (std::vector<beans::PropertyValue>::iterator i = m_aInteropGrabBag.begin(); i != m_aInteropGrabBag.end(); ++i)
*pSeq++ = *i;
aRet.Value = uno::makeAny(aSeq);
return aRet;
}
} //namespace dmapper
} //namespace writerfilter
......
......@@ -22,6 +22,7 @@
#include <WriterFilterDllApi.hxx>
#include <resourcemodel/LoggedResources.hxx>
#include <boost/shared_ptr.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
namespace writerfilter {
namespace dmapper
......@@ -30,12 +31,19 @@ class TablePropertyMap;
class WRITERFILTER_DLLPRIVATE CellMarginHandler : public LoggedProperties
{
private:
sal_Int32 m_nValue;
sal_Int32 m_nValue; ///< Converted value.
sal_Int32 m_nWidth; ///< Original value.
sal_Int32 m_nType; ///< Unit of the value (dxa, etc).
OUString m_aInteropGrabBagName;
std::vector<beans::PropertyValue> m_aInteropGrabBag;
// Properties
virtual void lcl_attribute(Id Name, Value & val);
virtual void lcl_sprm(Sprm & sprm);
void createGrabBag(OUString aName);
public:
sal_Int32 m_nLeftMargin;
bool m_bLeftMarginValid;
......@@ -52,6 +60,9 @@ public:
::boost::shared_ptr<TablePropertyMap> getProperties();
void enableInteropGrabBag(OUString aName);
beans::PropertyValue getInteropGrabBag();
};
typedef boost::shared_ptr< CellMarginHandler > CellMarginHandlerPtr;
}}
......
......@@ -84,6 +84,13 @@ void MeasureHandler::lcl_attribute(Id rName, Value & rVal)
case NS_rtf::LN_preferredWidth:
case NS_ooxml::LN_CT_TblWidth_w:// = 90667;
m_nMeasureValue = nIntValue;
if (!m_aInteropGrabBagName.isEmpty())
{
beans::PropertyValue aValue;
aValue.Name = "w";
aValue.Value = uno::makeAny(nIntValue);
m_aInteropGrabBag.push_back(aValue);
}
break;
case NS_ooxml::LN_CT_Height_val: // 90665 -- a string value
{
......
......@@ -242,7 +242,11 @@ namespace dmapper {
if( pProperties.get())
{
CellMarginHandlerPtr pCellMarginHandler( new CellMarginHandler );
if (m_pCurrentInteropGrabBag)
pCellMarginHandler->enableInteropGrabBag("tblCellMar");
pProperties->resolve( *pCellMarginHandler );
if (m_pCurrentInteropGrabBag)
m_pCurrentInteropGrabBag->push_back(pCellMarginHandler->getInteropGrabBag());
TablePropertyMapPtr pMarginProps( new TablePropertyMap );
if( pCellMarginHandler->m_bTopMarginValid )
pMarginProps->setValue( TablePropertyMap::CELL_MAR_TOP, pCellMarginHandler->m_nTopMargin );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment