lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / writerfilter / source / dmapper / BorderHandler.cxx
blobec37f8aa26e357d6481e1fcbff91360c3dbf1d91
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 {
33 namespace dmapper {
35 using namespace ::com::sun::star;
38 BorderHandler::BorderHandler( bool bOOXML ) :
39 LoggedProperties("BorderHandler"),
40 m_nLineWidth(15), // Word default, in twips
41 m_nLineType(0),
42 m_nLineColor(0),
43 m_nLineDistance(0),
44 m_bShadow(false),
45 m_bOOXML( bOOXML )
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();
58 switch( rName )
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));
64 break;
65 case NS_ooxml::LN_CT_Border_val:
66 m_nLineType = nIntValue;
67 appendGrabBag("val", TDefTableHandler::getBorderTypeString(nIntValue));
68 break;
69 case NS_ooxml::LN_CT_Border_color:
70 m_nLineColor = nIntValue;
71 appendGrabBag("color", OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue)));
72 break;
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));
76 break;
77 case NS_ooxml::LN_CT_Border_shadow:
78 m_bShadow = nIntValue;
79 break;
80 case NS_ooxml::LN_CT_Border_frame:
81 case NS_ooxml::LN_CT_Border_themeTint:
82 appendGrabBag("themeTint", OUString::number(nIntValue, 16));
83 break;
84 case NS_ooxml::LN_CT_Border_themeColor:
85 appendGrabBag("themeColor", TDefTableHandler::getThemeColorTypeString(nIntValue));
86 break;
87 default:
88 OSL_FAIL( "unknown attribute");
92 void BorderHandler::lcl_sprm(Sprm & rSprm)
94 BorderPosition pos;
95 const bool rtl = false; // TODO detect
96 OUString aBorderPos;
97 switch( rSprm.getId())
99 case NS_ooxml::LN_CT_TblBorders_top:
100 pos = BorderPosition::Top;
101 aBorderPos = "top";
102 break;
103 case NS_ooxml::LN_CT_TblBorders_start:
104 pos = rtl ? BorderPosition::Right : BorderPosition::Left;
105 aBorderPos = "start";
106 break;
107 case NS_ooxml::LN_CT_TblBorders_left:
108 pos = BorderPosition::Left;
109 aBorderPos = "left";
110 break;
111 case NS_ooxml::LN_CT_TblBorders_bottom:
112 pos = BorderPosition::Bottom;
113 aBorderPos = "bottom";
114 break;
115 case NS_ooxml::LN_CT_TblBorders_end:
116 pos = rtl ? BorderPosition::Left : BorderPosition::Right;
117 aBorderPos = "end";
118 break;
119 case NS_ooxml::LN_CT_TblBorders_right:
120 pos = BorderPosition::Right;
121 aBorderPos = "right";
122 break;
123 case NS_ooxml::LN_CT_TblBorders_insideH:
124 pos = BorderPosition::Horizontal;
125 aBorderPos = "insideH";
126 break;
127 case NS_ooxml::LN_CT_TblBorders_insideV:
128 pos = BorderPosition::Vertical;
129 aBorderPos = "insideV";
130 break;
131 default:
132 return;
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 =
159 PROP_TOP_BORDER,
160 PROP_LEFT_BORDER,
161 PROP_BOTTOM_BORDER,
162 PROP_RIGHT_BORDER,
163 META_PROP_HORIZONTAL_BORDER,
164 META_PROP_VERTICAL_BORDER
166 PropertyMapPtr pPropertyMap(new PropertyMap);
167 // don't fill in default properties
168 if( m_bOOXML )
170 for( auto nProp: o3tl::enumrange<BorderPosition>())
172 if ( m_aFilledLines[nProp] ) {
173 pPropertyMap->Insert( aPropNames[nProp], uno::makeAny( m_aBorderLines[nProp] ) );
177 return pPropertyMap;
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 );
186 return aBorderLine;
190 void BorderHandler::enableInteropGrabBag(const OUString& aName)
192 m_aInteropGrabBagName = aName;
195 beans::PropertyValue BorderHandler::getInteropGrabBag(const OUString& aName)
197 beans::PropertyValue aRet;
198 if (aName.isEmpty())
199 aRet.Name = m_aInteropGrabBagName;
200 else
201 aRet.Name = aName;
203 aRet.Value <<= comphelper::containerToSequence(m_aInteropGrabBag);
204 return aRet;
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: */