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