1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "CellMarginHandler.hxx"
20 #include "ConversionHelper.hxx"
21 #include <ooxml/resourceids.hxx>
22 #include <comphelper/propertysequence.hxx>
23 #include <comphelper/sequence.hxx>
24 #include <sal/log.hxx>
26 namespace writerfilter::dmapper
{
28 using namespace ::com::sun::star
;
29 using namespace ::writerfilter
;
31 CellMarginHandler::CellMarginHandler() :
32 LoggedProperties("CellMarginHandler"),
37 m_bLeftMarginValid( false ),
39 m_bRightMarginValid( false ),
41 m_bTopMarginValid( false ),
43 m_bBottomMarginValid( false )
47 CellMarginHandler::~CellMarginHandler()
51 void CellMarginHandler::lcl_attribute(Id rName
, Value
& rVal
)
53 sal_Int32 nIntValue
= rVal
.getInt();
56 case NS_ooxml::LN_CT_TblWidth_w
:
58 m_nValue
= ConversionHelper::convertTwipToMM100Unsigned( nIntValue
);
60 case NS_ooxml::LN_CT_TblWidth_type
:
61 SAL_WARN_IF(NS_ooxml::LN_Value_ST_TblWidth_dxa
!= sal::static_int_cast
<Id
>(nIntValue
), "writerfilter", "CellMarginHandler: cell margins work for absolute values only");
65 SAL_WARN("writerfilter", "CellMarginHandler::lcl_attribute: unknown attribute");
69 void CellMarginHandler::createGrabBag(const OUString
& aName
)
71 if (m_aInteropGrabBagName
.isEmpty())
74 beans::PropertyValue aRet
;
80 case NS_ooxml::LN_Value_ST_TblWidth_nil
: sType
= "nil"; break;
81 case NS_ooxml::LN_Value_ST_TblWidth_pct
: sType
= "pct"; break;
82 case NS_ooxml::LN_Value_ST_TblWidth_dxa
: sType
= "dxa"; break;
83 case NS_ooxml::LN_Value_ST_TblWidth_auto
: sType
= "auto"; break;
85 uno::Sequence
<beans::PropertyValue
> aSeq( comphelper::InitPropertySequence({
86 { "w", uno::Any(m_nWidth
) },
87 { "type", uno::Any(sType
) }
91 m_aInteropGrabBag
.push_back(aRet
);
94 void CellMarginHandler::lcl_sprm(Sprm
& rSprm
)
96 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
99 pProperties
->resolve( *this );
100 const bool rtl
= false; // TODO
101 switch( rSprm
.getId() )
103 case NS_ooxml::LN_CT_TblCellMar_top
:
104 case NS_ooxml::LN_CT_TcMar_top
:
105 m_nTopMargin
= m_nValue
;
106 m_bTopMarginValid
= true;
107 createGrabBag("top");
109 case NS_ooxml::LN_CT_TblCellMar_start
:
110 case NS_ooxml::LN_CT_TcMar_start
:
113 m_nRightMargin
= m_nValue
;
114 m_bRightMarginValid
= true;
118 m_nLeftMargin
= m_nValue
;
119 m_bLeftMarginValid
= true;
121 createGrabBag("start");
123 case NS_ooxml::LN_CT_TblCellMar_left
:
124 case NS_ooxml::LN_CT_TcMar_left
:
125 m_nLeftMargin
= m_nValue
;
126 m_bLeftMarginValid
= true;
127 createGrabBag("left");
129 case NS_ooxml::LN_CT_TblCellMar_bottom
:
130 case NS_ooxml::LN_CT_TcMar_bottom
:
131 m_nBottomMargin
= m_nValue
;
132 m_bBottomMarginValid
= true;
133 createGrabBag("bottom");
135 case NS_ooxml::LN_CT_TblCellMar_end
:
136 case NS_ooxml::LN_CT_TcMar_end
:
139 m_nLeftMargin
= m_nValue
;
140 m_bLeftMarginValid
= true;
144 m_nRightMargin
= m_nValue
;
145 m_bRightMarginValid
= true;
147 createGrabBag("end");
149 case NS_ooxml::LN_CT_TblCellMar_right
:
150 case NS_ooxml::LN_CT_TcMar_right
:
151 m_nRightMargin
= m_nValue
;
152 m_bRightMarginValid
= true;
153 createGrabBag("right");
156 SAL_WARN("writerfilter", "CellMarginHandler::lcl_sprm: unknown sprm");
162 void CellMarginHandler::enableInteropGrabBag(const OUString
& aName
)
164 m_aInteropGrabBagName
= aName
;
167 beans::PropertyValue
CellMarginHandler::getInteropGrabBag()
169 beans::PropertyValue aRet
;
170 aRet
.Name
= m_aInteropGrabBagName
;
171 aRet
.Value
<<= comphelper::containerToSequence(m_aInteropGrabBag
);
175 } //namespace writerfilter::dmapper
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */