LibreOffice Module writerfilter (master) 1
BorderHandler.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 "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>
29#include <tools/color.hxx>
30
32
33using namespace ::com::sun::star;
34
35
37LoggedProperties("BorderHandler"),
38m_nLineWidth(15), // Word default, in twips
39m_nLineType(0),
40m_nLineColor(0),
41m_nLineDistance(0),
42m_bShadow(false),
43m_bOOXML( bOOXML )
44{
45 m_aFilledLines.fill(false);
46 m_aBorderLines.fill(table::BorderLine2());
47}
48
50{
51}
52
54{
55 sal_Int32 nIntValue = rVal.getInt();
56 switch( rName )
57 {
58 case NS_ooxml::LN_CT_Border_sz:
59 // width of a single line in 1/8 pt, max of 32 pt -> twip * 5 / 2.
60 m_nLineWidth = nIntValue * 5 / 2;
61 appendGrabBag("sz", OUString::number(nIntValue));
62 break;
63 case NS_ooxml::LN_CT_Border_val:
64 m_nLineType = nIntValue;
66 break;
67 case NS_ooxml::LN_CT_Border_color:
68 m_nLineColor = nIntValue;
70 break;
71 case NS_ooxml::LN_CT_Border_space: // border distance in points
73 appendGrabBag("space", OUString::number(nIntValue));
74 break;
75 case NS_ooxml::LN_CT_Border_shadow:
76 m_bShadow = nIntValue;
77 break;
78 case NS_ooxml::LN_CT_Border_frame:
79 appendGrabBag("frame", OUString::number(nIntValue, 16));
80 break;
81 case NS_ooxml::LN_CT_Border_themeTint:
82 m_nThemeTint = nIntValue;
83 appendGrabBag("themeTint", OUString::number(nIntValue, 16));
84 break;
85 case NS_ooxml::LN_CT_Border_themeShade:
86 m_nThemeShade = nIntValue;
87 appendGrabBag("themeShade", OUString::number(nIntValue, 16));
88 break;
89 case NS_ooxml::LN_CT_Border_themeColor:
92 break;
93 default:
94 OSL_FAIL( "unknown attribute");
95 }
96}
97
99{
101 const bool rtl = false; // TODO detect
102 OUString aBorderPos;
103 switch( rSprm.getId())
104 {
105 case NS_ooxml::LN_CT_TblBorders_top:
107 aBorderPos = "top";
108 break;
109 case NS_ooxml::LN_CT_TblBorders_start:
111 aBorderPos = "start";
112 break;
113 case NS_ooxml::LN_CT_TblBorders_left:
115 aBorderPos = "left";
116 break;
117 case NS_ooxml::LN_CT_TblBorders_bottom:
119 aBorderPos = "bottom";
120 break;
121 case NS_ooxml::LN_CT_TblBorders_end:
123 aBorderPos = "end";
124 break;
125 case NS_ooxml::LN_CT_TblBorders_right:
127 aBorderPos = "right";
128 break;
129 case NS_ooxml::LN_CT_TblBorders_insideH:
131 aBorderPos = "insideH";
132 break;
133 case NS_ooxml::LN_CT_TblBorders_insideV:
135 aBorderPos = "insideV";
136 break;
137 default:
138 return;
139 }
141 if( pProperties)
142 {
143 std::vector<beans::PropertyValue> aSavedGrabBag;
144 if (!m_aInteropGrabBagName.isEmpty())
145 {
146 aSavedGrabBag = m_aInteropGrabBag;
147 m_aInteropGrabBag.clear();
148 }
149 pProperties->resolve(*this);
150 if (!m_aInteropGrabBagName.isEmpty())
151 {
152 aSavedGrabBag.push_back(getInteropGrabBag(aBorderPos));
153 m_aInteropGrabBag = aSavedGrabBag;
154 }
155 }
158 m_aFilledLines[ pos ] = true;
159}
160
162{
164 {
171 };
172 PropertyMapPtr pPropertyMap(new PropertyMap);
173 // don't fill in default properties
174 if( m_bOOXML )
175 {
176 for( auto nProp: o3tl::enumrange<BorderPosition>())
177 {
178 if ( m_aFilledLines[nProp] ) {
179 pPropertyMap->Insert( aPropNames[nProp], uno::Any( m_aBorderLines[nProp] ) );
180 }
181 }
182 }
183 return pPropertyMap;
184}
185
187{
188 table::BorderLine2 aBorderLine;
190 return aBorderLine;
191}
192
193
194void BorderHandler::enableInteropGrabBag(const OUString& aName)
195{
197}
198
199beans::PropertyValue BorderHandler::getInteropGrabBag(const OUString& aName)
200{
201 beans::PropertyValue aRet;
202 if (aName.isEmpty())
203 aRet.Name = m_aInteropGrabBagName;
204 else
205 aRet.Name = aName;
206
208 return aRet;
209}
210
211void BorderHandler::appendGrabBag(const OUString& aKey, const OUString& aValue)
212{
213 beans::PropertyValue aProperty;
214 aProperty.Name = aKey;
215 aProperty.Value <<= aValue;
216 m_aInteropGrabBag.push_back(aProperty);
217}
218
220{
221 model::ComplexColor aComplexColor;
223 return aComplexColor;
224
225 aComplexColor.setSchemeColor(m_eThemeColorType);
226
227 if (m_nThemeTint > 0 )
228 {
229 sal_Int16 nTint = sal_Int16((255.0 - m_nThemeTint) * 10000.0 / 255.0);
231 }
232 if (m_nThemeShade > 0)
233 {
234 sal_Int16 nShade = sal_Int16((255.0 - m_nThemeShade) * 10000 / 255.0);
236 }
237
238 return aComplexColor;
239}
240
241} //namespace writerfilter::dmapper
242
243/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setSchemeColor(ThemeColorType eType)
void addTransformation(Transformation const &rTransform)
void fill(V val)
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.
model::ThemeColorType m_eThemeColorType
css::beans::PropertyValue getInteropGrabBag(const OUString &aName=OUString())
std::vector< css::beans::PropertyValue > m_aInteropGrabBag
void appendGrabBag(const OUString &aKey, const OUString &aValue)
css::table::BorderLine2 getBorderLine()
virtual void lcl_attribute(Id Name, Value &val) override
o3tl::enumarray< BorderPosition, css::table::BorderLine2 > m_aBorderLines
virtual void lcl_sprm(Sprm &sprm) override
model::ComplexColor getComplexColor() const
void enableInteropGrabBag(const OUString &aName)
o3tl::enumarray< BorderPosition, bool > m_aFilledLines
static OUString getBorderTypeString(sal_Int32 nType)
static model::ThemeColorType getThemeColorTypeIndex(sal_Int32 nType)
static OUString getThemeColorTypeString(sal_Int32 nType)
ColorTransparency
OUString aName
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
OUString ConvertColorOU(const Color &rColor)
void MakeBorderLine(sal_Int32 nLineThickness, sal_Int32 nLineToken, sal_Int32 nLineColor, table::BorderLine2 &rToFill, bool bIsOOXML)
const PropertyStruct aPropNames[]
sal_uInt32 Id
size_t pos