fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / writerfilter / source / dmapper / BorderHandler.cxx
blobc219d397597cadeb446f6816cbbd281ebf3878e7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
28 namespace writerfilter {
30 namespace dmapper {
32 using namespace ::com::sun::star;
35 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 m_bOOXML( bOOXML )
45 const int nBorderCount(BORDER_COUNT);
46 std::fill_n(m_aFilledLines, nBorderCount, false);
47 std::fill_n(m_aBorderLines, nBorderCount, table::BorderLine2());
50 BorderHandler::~BorderHandler()
54 void BorderHandler::lcl_attribute(Id rName, Value & rVal)
56 sal_Int32 nIntValue = rVal.getInt();
57 switch( rName )
59 case NS_rtf::LN_rgbrc:
61 writerfilter::Reference<Properties>::Pointer_t pProperties = rVal.getProperties();
62 if( pProperties.get())
64 pProperties->resolve(*this);
65 ConversionHelper::MakeBorderLine( m_nLineWidth, m_nLineType, m_nLineColor,
66 m_aBorderLines[m_nCurrentBorderPosition], m_bOOXML );
67 OSL_ENSURE(m_nCurrentBorderPosition < BORDER_COUNT, "too many border values");
68 ++m_nCurrentBorderPosition;
71 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 m_nLineWidth = nIntValue * 5 / 2;
75 break;
76 case NS_rtf::LN_BRCTYPE: // 0x2872
77 m_nLineType = nIntValue;
78 break;
79 case NS_ooxml::LN_CT_Border_color:
80 case NS_rtf::LN_ICO: // 0x2873
81 m_nLineColor = nIntValue;
82 break;
83 case NS_rtf::LN_DPTSPACE: // border distance in points
84 m_nLineDistance = ConversionHelper::convertTwipToMM100( nIntValue * 20 );
85 break;
86 case NS_rtf::LN_FSHADOW: // 0x2875
87 m_bShadow = nIntValue;
88 break;
89 case NS_rtf::LN_FFRAME: // 0x2876
90 case NS_rtf::LN_UNUSED2_15: // 0x2877
91 // ignored
92 break;
93 case NS_ooxml::LN_CT_Border_themeTint: break;
94 case NS_ooxml::LN_CT_Border_themeColor: break;
95 default:
96 OSL_FAIL( "unknown attribute");
100 void BorderHandler::lcl_sprm(Sprm & rSprm)
102 BorderPosition pos = BORDER_COUNT; // invalid pos
103 bool rtl = false; // TODO detect
104 switch( rSprm.getId())
106 case NS_ooxml::LN_CT_TblBorders_top:
107 pos = BORDER_TOP;
108 break;
109 case NS_ooxml::LN_CT_TblBorders_start:
110 pos = rtl ? BORDER_RIGHT : BORDER_LEFT;
111 break;
112 case NS_ooxml::LN_CT_TblBorders_left:
113 pos = BORDER_LEFT;
114 break;
115 case NS_ooxml::LN_CT_TblBorders_bottom:
116 pos = BORDER_BOTTOM;
117 break;
118 case NS_ooxml::LN_CT_TblBorders_end:
119 pos = rtl ? BORDER_LEFT : BORDER_RIGHT;
120 break;
121 case NS_ooxml::LN_CT_TblBorders_right:
122 pos = BORDER_RIGHT;
123 break;
124 case NS_ooxml::LN_CT_TblBorders_insideH:
125 pos = BORDER_HORIZONTAL;
126 break;
127 case NS_ooxml::LN_CT_TblBorders_insideV:
128 pos = BORDER_VERTICAL;
129 break;
130 default:
131 break;
133 if( pos != BORDER_COUNT )
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[ pos ], m_bOOXML );
140 m_aFilledLines[ pos ] = true;
144 PropertyMapPtr BorderHandler::getProperties()
146 static const PropertyIds aPropNames[BORDER_COUNT] =
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
155 PropertyMapPtr pPropertyMap(new PropertyMap);
156 // don't fill in default properties
157 if( m_bOOXML || m_nCurrentBorderPosition )
159 for( sal_Int32 nProp = 0; nProp < BORDER_COUNT; ++nProp)
161 if ( m_aFilledLines[nProp] ) {
162 pPropertyMap->Insert( aPropNames[nProp], false, uno::makeAny( m_aBorderLines[nProp] ) );
166 return pPropertyMap;
168 /*-------------------------------------------------------------------------
169 used only in OOXML import
170 -----------------------------------------------------------------------*/
171 table::BorderLine2 BorderHandler::getBorderLine()
173 table::BorderLine2 aBorderLine;
174 ConversionHelper::MakeBorderLine( m_nLineWidth, m_nLineType, m_nLineColor, aBorderLine, m_bOOXML );
175 return aBorderLine;
178 bool BorderHandler::getShadow()
180 return m_bShadow;
183 } //namespace dmapper
184 } //namespace writerfilter
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */