Line data Source code
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 <resourcemodel/QNameToString.hxx>
23 : #include <ConversionHelper.hxx>
24 : #include <com/sun/star/table/BorderLine2.hpp>
25 : #include <ooxml/resourceids.hxx>
26 : #include <dmapperLoggers.hxx>
27 : #include <filter/msfilter/util.hxx>
28 :
29 : namespace writerfilter {
30 :
31 : namespace dmapper {
32 :
33 : using namespace ::com::sun::star;
34 :
35 :
36 1814 : BorderHandler::BorderHandler( bool bOOXML ) :
37 : LoggedProperties(dmapper_logger, "BorderHandler"),
38 : m_nCurrentBorderPosition( BORDER_TOP ),
39 : m_nLineWidth(15), // Word default, in twips
40 : m_nLineType(0),
41 : m_nLineColor(0),
42 : m_nLineDistance(0),
43 : m_bShadow(false),
44 1814 : m_bOOXML( bOOXML )
45 : {
46 1814 : const int nBorderCount(BORDER_COUNT);
47 1814 : std::fill_n(m_aFilledLines, nBorderCount, false);
48 1814 : std::fill_n(m_aBorderLines, nBorderCount, table::BorderLine2());
49 1814 : }
50 :
51 3628 : BorderHandler::~BorderHandler()
52 : {
53 3628 : }
54 :
55 21222 : void BorderHandler::lcl_attribute(Id rName, Value & rVal)
56 : {
57 21222 : sal_Int32 nIntValue = rVal.getInt();
58 21222 : switch( rName )
59 : {
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 5065 : m_nLineWidth = nIntValue * 5 / 2;
63 5065 : appendGrabBag("sz", OUString::number(nIntValue));
64 5065 : break;
65 : case NS_ooxml::LN_CT_Border_val:
66 5540 : m_nLineType = nIntValue;
67 5540 : appendGrabBag("val", TDefTableHandler::getBorderTypeString(nIntValue));
68 5540 : break;
69 : case NS_ooxml::LN_CT_Border_color:
70 5064 : m_nLineColor = nIntValue;
71 5064 : appendGrabBag("color", OStringToOUString(msfilter::util::ConvertColor(nIntValue, /*bAutoColor=*/true), RTL_TEXTENCODING_UTF8));
72 5064 : break;
73 : case NS_ooxml::LN_CT_Border_space: // border distance in points
74 5065 : m_nLineDistance = ConversionHelper::convertTwipToMM100( nIntValue * 20 );
75 5065 : appendGrabBag("space", OUString::number(nIntValue));
76 5065 : break;
77 : case NS_ooxml::LN_CT_Border_shadow:
78 68 : m_bShadow = nIntValue;
79 68 : break;
80 : case NS_ooxml::LN_CT_Border_frame:
81 : case NS_ooxml::LN_CT_Border_themeTint:
82 32 : appendGrabBag("themeTint", OUString::number(nIntValue, 16));
83 32 : break;
84 : case NS_ooxml::LN_CT_Border_themeColor:
85 364 : appendGrabBag("themeColor", TDefTableHandler::getThemeColorTypeString(nIntValue));
86 364 : break;
87 : default:
88 : OSL_FAIL( "unknown attribute");
89 : }
90 21222 : }
91 :
92 5112 : void BorderHandler::lcl_sprm(Sprm & rSprm)
93 : {
94 5112 : BorderPosition pos = BORDER_COUNT; // invalid pos
95 5112 : bool rtl = false; // TODO detect
96 5112 : OUString aBorderPos;
97 5112 : switch( rSprm.getId())
98 : {
99 : case NS_ooxml::LN_CT_TblBorders_top:
100 919 : pos = BORDER_TOP;
101 919 : aBorderPos = "top";
102 919 : break;
103 : case NS_ooxml::LN_CT_TblBorders_start:
104 106 : pos = rtl ? BORDER_RIGHT : BORDER_LEFT;
105 106 : aBorderPos = "start";
106 106 : break;
107 : case NS_ooxml::LN_CT_TblBorders_left:
108 791 : pos = BORDER_LEFT;
109 791 : aBorderPos = "left";
110 791 : break;
111 : case NS_ooxml::LN_CT_TblBorders_bottom:
112 865 : pos = BORDER_BOTTOM;
113 865 : aBorderPos = "bottom";
114 865 : break;
115 : case NS_ooxml::LN_CT_TblBorders_end:
116 109 : pos = rtl ? BORDER_LEFT : BORDER_RIGHT;
117 109 : aBorderPos = "end";
118 109 : break;
119 : case NS_ooxml::LN_CT_TblBorders_right:
120 791 : pos = BORDER_RIGHT;
121 791 : aBorderPos = "right";
122 791 : break;
123 : case NS_ooxml::LN_CT_TblBorders_insideH:
124 766 : pos = BORDER_HORIZONTAL;
125 766 : aBorderPos = "insideH";
126 766 : break;
127 : case NS_ooxml::LN_CT_TblBorders_insideV:
128 765 : pos = BORDER_VERTICAL;
129 765 : aBorderPos = "insideV";
130 765 : break;
131 : default:
132 0 : break;
133 : }
134 5112 : if( pos != BORDER_COUNT )
135 : {
136 5112 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
137 5112 : if( pProperties.get())
138 : {
139 5112 : std::vector<beans::PropertyValue> aSavedGrabBag;
140 5112 : if (!m_aInteropGrabBagName.isEmpty())
141 : {
142 1857 : aSavedGrabBag = m_aInteropGrabBag;
143 1857 : m_aInteropGrabBag.clear();
144 : }
145 5112 : pProperties->resolve(*this);
146 5112 : if (!m_aInteropGrabBagName.isEmpty())
147 : {
148 1857 : aSavedGrabBag.push_back(getInteropGrabBag(aBorderPos));
149 1857 : m_aInteropGrabBag = aSavedGrabBag;
150 5112 : }
151 : }
152 : ConversionHelper::MakeBorderLine( m_nLineWidth, m_nLineType, m_nLineColor,
153 5112 : m_aBorderLines[ pos ], m_bOOXML );
154 5112 : m_aFilledLines[ pos ] = true;
155 5112 : }
156 5112 : }
157 :
158 1386 : PropertyMapPtr BorderHandler::getProperties()
159 : {
160 : static const PropertyIds aPropNames[BORDER_COUNT] =
161 : {
162 : PROP_TOP_BORDER,
163 : PROP_LEFT_BORDER,
164 : PROP_BOTTOM_BORDER,
165 : PROP_RIGHT_BORDER,
166 : META_PROP_HORIZONTAL_BORDER,
167 : META_PROP_VERTICAL_BORDER
168 : };
169 1386 : PropertyMapPtr pPropertyMap(new PropertyMap);
170 : // don't fill in default properties
171 1386 : if( m_bOOXML || m_nCurrentBorderPosition )
172 : {
173 9702 : for( sal_Int32 nProp = 0; nProp < BORDER_COUNT; ++nProp)
174 : {
175 8316 : if ( m_aFilledLines[nProp] ) {
176 5112 : pPropertyMap->Insert( aPropNames[nProp], uno::makeAny( m_aBorderLines[nProp] ) );
177 : }
178 : }
179 : }
180 1386 : return pPropertyMap;
181 : }
182 : /*-------------------------------------------------------------------------
183 : used only in OOXML import
184 : -----------------------------------------------------------------------*/
185 609 : table::BorderLine2 BorderHandler::getBorderLine()
186 : {
187 609 : table::BorderLine2 aBorderLine;
188 609 : ConversionHelper::MakeBorderLine( m_nLineWidth, m_nLineType, m_nLineColor, aBorderLine, m_bOOXML );
189 609 : return aBorderLine;
190 : }
191 :
192 157 : bool BorderHandler::getShadow()
193 : {
194 157 : return m_bShadow;
195 : }
196 :
197 367 : void BorderHandler::enableInteropGrabBag(const OUString& aName)
198 : {
199 367 : m_aInteropGrabBagName = aName;
200 367 : }
201 :
202 2224 : beans::PropertyValue BorderHandler::getInteropGrabBag(const OUString& aName)
203 : {
204 2224 : beans::PropertyValue aRet;
205 2224 : if (aName.isEmpty())
206 367 : aRet.Name = m_aInteropGrabBagName;
207 : else
208 1857 : aRet.Name = aName;
209 :
210 4448 : uno::Sequence<beans::PropertyValue> aSeq(m_aInteropGrabBag.size());
211 2224 : beans::PropertyValue* pSeq = aSeq.getArray();
212 11827 : for (std::vector<beans::PropertyValue>::iterator i = m_aInteropGrabBag.begin(); i != m_aInteropGrabBag.end(); ++i)
213 9603 : *pSeq++ = *i;
214 :
215 2224 : aRet.Value = uno::makeAny(aSeq);
216 4448 : return aRet;
217 : }
218 :
219 21130 : void BorderHandler::appendGrabBag(const OUString& aKey, const OUString& aValue)
220 : {
221 21130 : beans::PropertyValue aProperty;
222 21130 : aProperty.Name = aKey;
223 21130 : aProperty.Value = uno::makeAny(aValue);
224 21130 : m_aInteropGrabBag.push_back(aProperty);
225 21130 : }
226 :
227 : } //namespace dmapper
228 42 : } //namespace writerfilter
229 :
230 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|