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 <PropertyMap.hxx>
21 : #include <resourcemodel/QNameToString.hxx>
22 : #include <doctok/resourceids.hxx>
23 : #include <ConversionHelper.hxx>
24 : #include <com/sun/star/table/BorderLine2.hpp>
25 : #include <ooxml/resourceids.hxx>
26 : #include <dmapperLoggers.hxx>
27 :
28 : namespace writerfilter {
29 :
30 : namespace dmapper {
31 :
32 : using namespace ::com::sun::star;
33 :
34 :
35 160 : BorderHandler::BorderHandler( bool bOOXML ) :
36 : LoggedProperties(dmapper_logger, "BorderHandler"),
37 : m_nCurrentBorderPosition( BORDER_TOP ),
38 : m_nLineWidth(15), // Word default, in twips
39 : m_nLineType(0),
40 : m_nLineColor(0),
41 : m_nLineDistance(0),
42 : m_bShadow(false),
43 160 : m_bOOXML( bOOXML )
44 : {
45 160 : const int nBorderCount(BORDER_COUNT);
46 160 : std::fill_n(m_aFilledLines, nBorderCount, false);
47 160 : std::fill_n(m_aBorderLines, nBorderCount, table::BorderLine2());
48 160 : }
49 :
50 320 : BorderHandler::~BorderHandler()
51 : {
52 320 : }
53 :
54 3026 : void BorderHandler::lcl_attribute(Id rName, Value & rVal)
55 : {
56 3026 : sal_Int32 nIntValue = rVal.getInt();
57 3026 : switch( rName )
58 : {
59 : case NS_rtf::LN_rgbrc:
60 : {
61 0 : writerfilter::Reference<Properties>::Pointer_t pProperties = rVal.getProperties();
62 0 : if( pProperties.get())
63 : {
64 0 : pProperties->resolve(*this);
65 : ConversionHelper::MakeBorderLine( m_nLineWidth, m_nLineType, m_nLineColor,
66 0 : m_aBorderLines[m_nCurrentBorderPosition], m_bOOXML );
67 : OSL_ENSURE(m_nCurrentBorderPosition < BORDER_COUNT, "too many border values");
68 0 : ++m_nCurrentBorderPosition;
69 0 : }
70 : }
71 0 : break;
72 : case NS_rtf::LN_DPTLINEWIDTH: // 0x2871
73 : // width of a single line in 1/8 pt, max of 32 pt -> twip * 5 / 2.
74 731 : m_nLineWidth = nIntValue * 5 / 2;
75 731 : break;
76 : case NS_rtf::LN_BRCTYPE: // 0x2872
77 735 : m_nLineType = nIntValue;
78 735 : break;
79 : case NS_ooxml::LN_CT_Border_color:
80 : case NS_rtf::LN_ICO: // 0x2873
81 730 : m_nLineColor = nIntValue;
82 730 : break;
83 : case NS_rtf::LN_DPTSPACE: // border distance in points
84 731 : m_nLineDistance = ConversionHelper::convertTwipToMM100( nIntValue * 20 );
85 731 : break;
86 : case NS_rtf::LN_FSHADOW: // 0x2875
87 4 : m_bShadow = nIntValue;
88 4 : break;
89 : case NS_rtf::LN_FFRAME: // 0x2876
90 : case NS_rtf::LN_UNUSED2_15: // 0x2877
91 : // ignored
92 0 : break;
93 9 : case NS_ooxml::LN_CT_Border_themeTint: break;
94 86 : case NS_ooxml::LN_CT_Border_themeColor: break;
95 : default:
96 : OSL_FAIL( "unknown attribute");
97 : }
98 3026 : }
99 :
100 694 : void BorderHandler::lcl_sprm(Sprm & rSprm)
101 : {
102 694 : BorderPosition pos = BORDER_COUNT; // invalid pos
103 694 : bool rtl = false; // TODO detect
104 694 : switch( rSprm.getId())
105 : {
106 : case NS_ooxml::LN_CT_TblBorders_top:
107 116 : pos = BORDER_TOP;
108 116 : break;
109 : case NS_ooxml::LN_CT_TblBorders_start:
110 15 : pos = rtl ? BORDER_RIGHT : BORDER_LEFT;
111 15 : break;
112 : case NS_ooxml::LN_CT_TblBorders_left:
113 99 : pos = BORDER_LEFT;
114 99 : break;
115 : case NS_ooxml::LN_CT_TblBorders_bottom:
116 117 : pos = BORDER_BOTTOM;
117 117 : break;
118 : case NS_ooxml::LN_CT_TblBorders_end:
119 15 : pos = rtl ? BORDER_LEFT : BORDER_RIGHT;
120 15 : break;
121 : case NS_ooxml::LN_CT_TblBorders_right:
122 99 : pos = BORDER_RIGHT;
123 99 : break;
124 : case NS_ooxml::LN_CT_TblBorders_insideH:
125 116 : pos = BORDER_HORIZONTAL;
126 116 : break;
127 : case NS_ooxml::LN_CT_TblBorders_insideV:
128 117 : pos = BORDER_VERTICAL;
129 117 : break;
130 : default:
131 0 : break;
132 : }
133 694 : if( pos != BORDER_COUNT )
134 : {
135 694 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
136 694 : if( pProperties.get())
137 694 : pProperties->resolve(*this);
138 : ConversionHelper::MakeBorderLine( m_nLineWidth, m_nLineType, m_nLineColor,
139 694 : m_aBorderLines[ pos ], m_bOOXML );
140 694 : m_aFilledLines[ pos ] = true;
141 : }
142 694 : }
143 :
144 119 : PropertyMapPtr BorderHandler::getProperties()
145 : {
146 : static const PropertyIds aPropNames[BORDER_COUNT] =
147 : {
148 : PROP_TOP_BORDER,
149 : PROP_LEFT_BORDER,
150 : PROP_BOTTOM_BORDER,
151 : PROP_RIGHT_BORDER,
152 : META_PROP_HORIZONTAL_BORDER,
153 : META_PROP_VERTICAL_BORDER
154 : };
155 119 : PropertyMapPtr pPropertyMap(new PropertyMap);
156 : // don't fill in default properties
157 119 : if( m_bOOXML || m_nCurrentBorderPosition )
158 : {
159 833 : for( sal_Int32 nProp = 0; nProp < BORDER_COUNT; ++nProp)
160 : {
161 714 : if ( m_aFilledLines[nProp] ) {
162 694 : pPropertyMap->Insert( aPropNames[nProp], uno::makeAny( m_aBorderLines[nProp] ) );
163 : }
164 : }
165 : }
166 119 : return pPropertyMap;
167 : }
168 : /*-------------------------------------------------------------------------
169 : used only in OOXML import
170 : -----------------------------------------------------------------------*/
171 41 : table::BorderLine2 BorderHandler::getBorderLine()
172 : {
173 41 : table::BorderLine2 aBorderLine;
174 41 : ConversionHelper::MakeBorderLine( m_nLineWidth, m_nLineType, m_nLineColor, aBorderLine, m_bOOXML );
175 41 : return aBorderLine;
176 : }
177 :
178 12 : bool BorderHandler::getShadow()
179 : {
180 12 : return m_bShadow;
181 : }
182 :
183 : } //namespace dmapper
184 24 : } //namespace writerfilter
185 :
186 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|