1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include <BorderHandler.hxx>
24 #include <PropertyMap.hxx>
25 #include <resourcemodel/QNameToString.hxx>
26 #include <doctok/resourceids.hxx>
27 #include <ConversionHelper.hxx>
28 #include <com/sun/star/table/BorderLine.hpp>
29 #include <ooxml/resourceids.hxx>
30 #include <dmapperLoggers.hxx>
31 
32 namespace writerfilter {
33 
34 namespace dmapper {
35 
36 using namespace ::com::sun::star;
37 //using namespace ::std;
38 
39 /*-- 24.04.2007 09:06:35---------------------------------------------------
40 
41   -----------------------------------------------------------------------*/
BorderHandler(bool bOOXML)42 BorderHandler::BorderHandler( bool bOOXML ) :
43 LoggedProperties(dmapper_logger, "BorderHandler"),
44 m_nCurrentBorderPosition( BORDER_TOP ),
45 m_nLineWidth(0),
46 m_nLineType(0),
47 m_nLineColor(0),
48 m_nLineDistance(0),
49 m_bOOXML( bOOXML )
50 {
51     const int nBorderCount(BORDER_COUNT);
52     std::fill_n(m_aFilledLines, nBorderCount, false);
53     std::fill_n(m_aBorderLines, nBorderCount, table::BorderLine());
54 }
55 /*-- 24.04.2007 09:06:35---------------------------------------------------
56 
57   -----------------------------------------------------------------------*/
~BorderHandler()58 BorderHandler::~BorderHandler()
59 {
60 }
61 /*-- 24.04.2007 09:06:35---------------------------------------------------
62 
63   -----------------------------------------------------------------------*/
lcl_attribute(Id rName,Value & rVal)64 void BorderHandler::lcl_attribute(Id rName, Value & rVal)
65 {
66     sal_Int32 nIntValue = rVal.getInt();
67     /* WRITERFILTERSTATUS: table: BorderHandler_attributedata */
68     switch( rName )
69     {
70         /* WRITERFILTERSTATUS: done: 75, planned: 0, spent: 0 */
71         case NS_rtf::LN_rgbrc:
72         {
73             writerfilter::Reference<Properties>::Pointer_t pProperties = rVal.getProperties();
74             if( pProperties.get())
75             {
76                 pProperties->resolve(*this);
77                 ConversionHelper::MakeBorderLine( m_nLineWidth,   m_nLineType, m_nLineColor,
78                                                                                 m_aBorderLines[m_nCurrentBorderPosition], m_bOOXML );
79                 OSL_ENSURE(m_nCurrentBorderPosition < BORDER_COUNT, "too many border values");
80                 ++m_nCurrentBorderPosition;
81             }
82         }
83         break;
84         /* WRITERFILTERSTATUS: done: 75, planned: 0, spent: 0 */
85         case NS_rtf::LN_DPTLINEWIDTH: // 0x2871
86             //  width of a single line in 1/8 pt, max of 32 pt -> twip * 5 / 2.
87             m_nLineWidth = ConversionHelper::convertTwipToMM100( nIntValue * 5 / 2 );
88         break;
89         /* WRITERFILTERSTATUS: done: 75, planned: 0, spent: 0 */
90         case NS_rtf::LN_BRCTYPE:    // 0x2872
91             m_nLineType = nIntValue;
92         break;
93         /* WRITERFILTERSTATUS: done: 75, planned: 0, spent: 0 */
94         case NS_ooxml::LN_CT_Border_color:
95         case NS_rtf::LN_ICO:        // 0x2873
96             m_nLineColor = nIntValue;
97         break;
98         /* WRITERFILTERSTATUS: done: 100, planned: 0, spent: 0 */
99         case NS_rtf::LN_DPTSPACE:   // border distance in points
100             m_nLineDistance = ConversionHelper::convertTwipToMM100( nIntValue * 20 );
101         break;
102         case NS_rtf::LN_FSHADOW:    // 0x2875
103             //if 1 then line has shadow - unsupported
104         case NS_rtf::LN_FFRAME:     // 0x2876
105         case NS_rtf::LN_UNUSED2_15: // 0x2877
106             // ignored
107         break;
108         case NS_ooxml::LN_CT_Border_themeTint: break;
109         case NS_ooxml::LN_CT_Border_themeColor: break;
110         default:
111             OSL_ENSURE( false, "unknown attribute");
112     }
113 }
114 /*-- 24.04.2007 09:06:35---------------------------------------------------
115 
116   -----------------------------------------------------------------------*/
lcl_sprm(Sprm & rSprm)117 void BorderHandler::lcl_sprm(Sprm & rSprm)
118 {
119     /* WRITERFILTERSTATUS: table: BorderHandler_sprm */
120     switch( rSprm.getId())
121     {
122         /* WRITERFILTERSTATUS: done: 75, planned: 0, spent: 0 */
123         case NS_ooxml::LN_CT_TblBorders_top:
124         /* WRITERFILTERSTATUS: done: 75, planned: 0, spent: 0 */
125         case NS_ooxml::LN_CT_TblBorders_left:
126         /* WRITERFILTERSTATUS: done: 75, planned: 0, spent: 0 */
127         case NS_ooxml::LN_CT_TblBorders_bottom:
128         /* WRITERFILTERSTATUS: done: 75, planned: 0, spent: 0 */
129         case NS_ooxml::LN_CT_TblBorders_right:
130         /* WRITERFILTERSTATUS: done: 75, planned: 0, spent: 0 */
131         case NS_ooxml::LN_CT_TblBorders_insideH:
132         /* WRITERFILTERSTATUS: done: 75, planned: 0, spent: 0 */
133         case NS_ooxml::LN_CT_TblBorders_insideV:
134         {
135             writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
136             if( pProperties.get())
137                 pProperties->resolve(*this);
138             ConversionHelper::MakeBorderLine( m_nLineWidth,   m_nLineType, m_nLineColor,
139                                    m_aBorderLines[rSprm.getId() - NS_ooxml::LN_CT_TblBorders_top], m_bOOXML );
140 
141             m_aFilledLines[ rSprm.getId( ) - NS_ooxml::LN_CT_TblBorders_top] = true;
142         }
143         break;
144         default:;
145     }
146 }
147 /*-- 24.04.2007 09:09:01---------------------------------------------------
148 
149   -----------------------------------------------------------------------*/
getProperties()150 PropertyMapPtr  BorderHandler::getProperties()
151 {
152     static const PropertyIds aPropNames[BORDER_COUNT] =
153     {
154         PROP_TOP_BORDER,
155         PROP_LEFT_BORDER,
156         PROP_BOTTOM_BORDER,
157         PROP_RIGHT_BORDER,
158         META_PROP_HORIZONTAL_BORDER,
159         META_PROP_VERTICAL_BORDER
160     };
161     PropertyMapPtr pPropertyMap(new PropertyMap);
162     // don't fill in default properties
163     if( m_bOOXML || m_nCurrentBorderPosition )
164     {
165         for( sal_Int32 nProp = 0; nProp < BORDER_COUNT; ++nProp)
166         {
167             if ( m_aFilledLines[nProp] ) {
168                 pPropertyMap->Insert( aPropNames[nProp], false, uno::makeAny( m_aBorderLines[nProp] ) );
169             }
170         }
171     }
172     return pPropertyMap;
173 }
174 /*-- 14.11.2007 12:42:52---------------------------------------------------
175     used only in OOXML import
176   -----------------------------------------------------------------------*/
getBorderLine()177 table::BorderLine BorderHandler::getBorderLine()
178 {
179     table::BorderLine aBorderLine;
180     ConversionHelper::MakeBorderLine( m_nLineWidth, m_nLineType, m_nLineColor, aBorderLine, m_bOOXML );
181     return aBorderLine;
182 }
183 
184 } //namespace dmapper
185 } //namespace writerfilter
186