LibreOffice Module writerfilter (master) 1
CellMarginHandler.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#include "CellMarginHandler.hxx"
20#include "ConversionHelper.hxx"
21#include <ooxml/resourceids.hxx>
24#include <sal/log.hxx>
25
26namespace writerfilter::dmapper {
27
28using namespace ::com::sun::star;
29using namespace ::writerfilter;
30
32LoggedProperties("CellMarginHandler"),
33m_nValue( 0 ),
34m_nWidth( 0 ),
35m_nType( 0 ),
36m_nLeftMargin( 0 ),
37m_bLeftMarginValid( false ),
38m_nRightMargin( 0 ),
39m_bRightMarginValid( false ),
40m_nTopMargin( 0 ),
41m_bTopMarginValid( false ),
42m_nBottomMargin( 0 ),
43m_bBottomMarginValid( false )
44{
45}
46
48{
49}
50
52{
53 sal_Int32 nIntValue = rVal.getInt();
54 switch( rName )
55 {
56 case NS_ooxml::LN_CT_TblWidth_w:
57 m_nWidth = nIntValue;
59 break;
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");
62 m_nType = nIntValue;
63 break;
64 default:
65 SAL_WARN("writerfilter", "CellMarginHandler::lcl_attribute: unknown attribute");
66 }
67}
68
69void CellMarginHandler::createGrabBag(const OUString& aName)
70{
71 if (m_aInteropGrabBagName.isEmpty())
72 return;
73
74 beans::PropertyValue aRet;
75 aRet.Name = aName;
76
77 OUString sType;
78 switch (m_nType)
79 {
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;
84 }
86 { "w", uno::Any(m_nWidth) },
87 { "type", uno::Any(sType) }
88 }));
89
90 aRet.Value <<= aSeq;
91 m_aInteropGrabBag.push_back(aRet);
92}
93
95{
97 if( pProperties)
98 {
99 pProperties->resolve( *this );
100 const bool rtl = false; // TODO
101 switch( rSprm.getId() )
102 {
103 case NS_ooxml::LN_CT_TblCellMar_top:
104 case NS_ooxml::LN_CT_TcMar_top:
106 m_bTopMarginValid = true;
107 createGrabBag("top");
108 break;
109 case NS_ooxml::LN_CT_TblCellMar_start:
110 case NS_ooxml::LN_CT_TcMar_start:
111 if( rtl )
112 {
114 m_bRightMarginValid = true;
115 }
116 else
117 {
119 m_bLeftMarginValid = true;
120 }
121 createGrabBag("start");
122 break;
123 case NS_ooxml::LN_CT_TblCellMar_left:
124 case NS_ooxml::LN_CT_TcMar_left:
126 m_bLeftMarginValid = true;
127 createGrabBag("left");
128 break;
129 case NS_ooxml::LN_CT_TblCellMar_bottom:
130 case NS_ooxml::LN_CT_TcMar_bottom:
133 createGrabBag("bottom");
134 break;
135 case NS_ooxml::LN_CT_TblCellMar_end:
136 case NS_ooxml::LN_CT_TcMar_end:
137 if( rtl )
138 {
140 m_bLeftMarginValid = true;
141 }
142 else
143 {
145 m_bRightMarginValid = true;
146 }
147 createGrabBag("end");
148 break;
149 case NS_ooxml::LN_CT_TblCellMar_right:
150 case NS_ooxml::LN_CT_TcMar_right:
152 m_bRightMarginValid = true;
153 createGrabBag("right");
154 break;
155 default:
156 SAL_WARN("writerfilter", "CellMarginHandler::lcl_sprm: unknown sprm");
157 }
158 }
159 m_nValue = 0;
160}
161
163{
165}
166
168{
169 beans::PropertyValue aRet;
170 aRet.Name = m_aInteropGrabBagName;
172 return aRet;
173}
174
175} //namespace writerfilter::dmapper
176
177/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sType
An SPRM: Section, Paragraph and Run Modifier.
virtual sal_uInt32 getId() const =0
Returns id of the SPRM.
virtual writerfilter::Reference< Properties >::Pointer_t getProps()=0
Returns reference to properties contained in the SPRM.
virtual int getInt() const =0
Returns integer representation of the value.
virtual void lcl_sprm(Sprm &sprm) override
void createGrabBag(const OUString &aName)
void enableInteropGrabBag(const OUString &aName)
sal_Int32 m_nType
Unit of the value (dxa, etc).
css::beans::PropertyValue getInteropGrabBag()
virtual void lcl_attribute(Id Name, Value &val) override
std::vector< css::beans::PropertyValue > m_aInteropGrabBag
OUString aName
Sequence< sal_Int8 > aSeq
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
sal_uInt32 convertTwipToMM100Unsigned(sal_Int32 _t)
sal_uInt32 Id