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 "BorderHandler.hxx"
20 #include "TDefTableHandler.hxx"
21 #include "PropertyMap.hxx"
22 #include "ConversionHelper.hxx"
23 #include <com/sun/star/table/BorderLine2.hpp>
24 #include <o3tl/enumarray.hxx>
25 #include <o3tl/enumrange.hxx>
26 #include <ooxml/resourceids.hxx>
27 #include <filter/msfilter/util.hxx>
28 #include <comphelper/sequence.hxx>
29 #include <tools/color.hxx>
31 namespace writerfilter
{
35 using namespace ::com::sun::star
;
38 BorderHandler::BorderHandler( bool bOOXML
) :
39 LoggedProperties("BorderHandler"),
40 m_nLineWidth(15), // Word default, in twips
47 m_aFilledLines
.fill(false);
48 m_aBorderLines
.fill(table::BorderLine2());
51 BorderHandler::~BorderHandler()
55 void BorderHandler::lcl_attribute(Id rName
, Value
& rVal
)
57 sal_Int32 nIntValue
= rVal
.getInt();
60 case NS_ooxml::LN_CT_Border_sz
:
61 // width of a single line in 1/8 pt, max of 32 pt -> twip * 5 / 2.
62 m_nLineWidth
= nIntValue
* 5 / 2;
63 appendGrabBag("sz", OUString::number(nIntValue
));
65 case NS_ooxml::LN_CT_Border_val
:
66 m_nLineType
= nIntValue
;
67 appendGrabBag("val", TDefTableHandler::getBorderTypeString(nIntValue
));
69 case NS_ooxml::LN_CT_Border_color
:
70 m_nLineColor
= nIntValue
;
71 appendGrabBag("color", OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue
)));
73 case NS_ooxml::LN_CT_Border_space
: // border distance in points
74 m_nLineDistance
= ConversionHelper::convertTwipToMM100( nIntValue
* 20 );
75 appendGrabBag("space", OUString::number(nIntValue
));
77 case NS_ooxml::LN_CT_Border_shadow
:
78 m_bShadow
= nIntValue
;
80 case NS_ooxml::LN_CT_Border_frame
:
81 case NS_ooxml::LN_CT_Border_themeTint
:
82 appendGrabBag("themeTint", OUString::number(nIntValue
, 16));
84 case NS_ooxml::LN_CT_Border_themeColor
:
85 appendGrabBag("themeColor", TDefTableHandler::getThemeColorTypeString(nIntValue
));
88 OSL_FAIL( "unknown attribute");
92 void BorderHandler::lcl_sprm(Sprm
& rSprm
)
95 const bool rtl
= false; // TODO detect
97 switch( rSprm
.getId())
99 case NS_ooxml::LN_CT_TblBorders_top
:
100 pos
= BorderPosition::Top
;
103 case NS_ooxml::LN_CT_TblBorders_start
:
104 pos
= rtl
? BorderPosition::Right
: BorderPosition::Left
;
105 aBorderPos
= "start";
107 case NS_ooxml::LN_CT_TblBorders_left
:
108 pos
= BorderPosition::Left
;
111 case NS_ooxml::LN_CT_TblBorders_bottom
:
112 pos
= BorderPosition::Bottom
;
113 aBorderPos
= "bottom";
115 case NS_ooxml::LN_CT_TblBorders_end
:
116 pos
= rtl
? BorderPosition::Left
: BorderPosition::Right
;
119 case NS_ooxml::LN_CT_TblBorders_right
:
120 pos
= BorderPosition::Right
;
121 aBorderPos
= "right";
123 case NS_ooxml::LN_CT_TblBorders_insideH
:
124 pos
= BorderPosition::Horizontal
;
125 aBorderPos
= "insideH";
127 case NS_ooxml::LN_CT_TblBorders_insideV
:
128 pos
= BorderPosition::Vertical
;
129 aBorderPos
= "insideV";
134 writerfilter::Reference
<Properties
>::Pointer_t pProperties
= rSprm
.getProps();
135 if( pProperties
.get())
137 std::vector
<beans::PropertyValue
> aSavedGrabBag
;
138 if (!m_aInteropGrabBagName
.isEmpty())
140 aSavedGrabBag
= m_aInteropGrabBag
;
141 m_aInteropGrabBag
.clear();
143 pProperties
->resolve(*this);
144 if (!m_aInteropGrabBagName
.isEmpty())
146 aSavedGrabBag
.push_back(getInteropGrabBag(aBorderPos
));
147 m_aInteropGrabBag
= aSavedGrabBag
;
150 ConversionHelper::MakeBorderLine( m_nLineWidth
, m_nLineType
, m_nLineColor
,
151 m_aBorderLines
[ pos
], m_bOOXML
);
152 m_aFilledLines
[ pos
] = true;
155 PropertyMapPtr
BorderHandler::getProperties()
157 static const o3tl::enumarray
<BorderPosition
, PropertyIds
> aPropNames
=
163 META_PROP_HORIZONTAL_BORDER
,
164 META_PROP_VERTICAL_BORDER
166 PropertyMapPtr
pPropertyMap(new PropertyMap
);
167 // don't fill in default properties
170 for( auto nProp
: o3tl::enumrange
<BorderPosition
>())
172 if ( m_aFilledLines
[nProp
] ) {
173 pPropertyMap
->Insert( aPropNames
[nProp
], uno::makeAny( m_aBorderLines
[nProp
] ) );
179 /*-------------------------------------------------------------------------
180 used only in OOXML import
181 -----------------------------------------------------------------------*/
182 table::BorderLine2
BorderHandler::getBorderLine()
184 table::BorderLine2 aBorderLine
;
185 ConversionHelper::MakeBorderLine( m_nLineWidth
, m_nLineType
, m_nLineColor
, aBorderLine
, m_bOOXML
);
190 void BorderHandler::enableInteropGrabBag(const OUString
& aName
)
192 m_aInteropGrabBagName
= aName
;
195 beans::PropertyValue
BorderHandler::getInteropGrabBag(const OUString
& aName
)
197 beans::PropertyValue aRet
;
199 aRet
.Name
= m_aInteropGrabBagName
;
203 aRet
.Value
<<= comphelper::containerToSequence(m_aInteropGrabBag
);
207 void BorderHandler::appendGrabBag(const OUString
& aKey
, const OUString
& aValue
)
209 beans::PropertyValue aProperty
;
210 aProperty
.Name
= aKey
;
211 aProperty
.Value
<<= aValue
;
212 m_aInteropGrabBag
.push_back(aProperty
);
215 } //namespace dmapper
216 } //namespace writerfilter
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */