Branch data 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 : :
20 : : #include "oox/drawingml/textparagraphpropertiescontext.hxx"
21 : :
22 : : #include <com/sun/star/text/WritingMode.hpp>
23 : : #include <com/sun/star/awt/FontDescriptor.hpp>
24 : :
25 : : #include "oox/drawingml/colorchoicecontext.hxx"
26 : : #include "oox/drawingml/textcharacterpropertiescontext.hxx"
27 : : #include "oox/drawingml/fillproperties.hxx"
28 : : #include "oox/helper/attributelist.hxx"
29 : : #include "textspacingcontext.hxx"
30 : : #include "texttabstoplistcontext.hxx"
31 : :
32 : : using ::rtl::OUString;
33 : : using namespace ::oox::core;
34 : : using ::com::sun::star::awt::FontDescriptor;
35 : : using namespace ::com::sun::star::uno;
36 : : using namespace ::com::sun::star::xml::sax;
37 : : using namespace ::com::sun::star::style;
38 : : using namespace ::com::sun::star::text;
39 : :
40 : : namespace oox { namespace drawingml {
41 : :
42 : : // CT_TextParagraphProperties
43 : 375 : TextParagraphPropertiesContext::TextParagraphPropertiesContext( ContextHandler& rParent,
44 : : const Reference< XFastAttributeList >& xAttribs,
45 : : TextParagraphProperties& rTextParagraphProperties )
46 : : : ContextHandler( rParent )
47 : : , mrTextParagraphProperties( rTextParagraphProperties )
48 : 375 : , mrSpaceBefore( rTextParagraphProperties.getParaTopMargin() )
49 : 375 : , mrSpaceAfter( rTextParagraphProperties.getParaBottomMargin() )
50 [ + - ][ + - ]: 750 : , mrBulletList( rTextParagraphProperties.getBulletList() )
51 : : {
52 : 375 : OUString sValue;
53 [ + - ]: 375 : AttributeList attribs( xAttribs );
54 : :
55 : 375 : PropertyMap& rPropertyMap( mrTextParagraphProperties.getTextParagraphPropertyMap() );
56 : :
57 : : // ST_TextAlignType
58 [ + - ][ + - ]: 375 : rPropertyMap[ PROP_ParaAdjust ] <<= GetParaAdjust( xAttribs->getOptionalValueToken( XML_algn, XML_l ) );
[ + - ][ + - ]
[ + - ]
59 : : // TODO see to do the same with RubyAdjust
60 : :
61 : : // ST_Coordinate32
62 : : // sValue = xAttribs->getOptionalValue( XML_defTabSz ); SJ: we need to be able to set the default tab size for each text object,
63 : : // this is possible at the moment only for the whole document.
64 : : // sal_Int32 nDefTabSize = ( sValue.getLength() == 0 ? 0 : GetCoordinate( sValue ) );
65 : : // TODO
66 : :
67 : : // bool bEaLineBrk = attribs.getBool( XML_eaLnBrk, true );
68 [ + - ][ + - ]: 375 : if ( xAttribs->hasAttribute( XML_latinLnBrk ) )
[ + + ]
69 : : {
70 [ + - ]: 168 : bool bLatinLineBrk = attribs.getBool( XML_latinLnBrk, true );
71 [ + - ][ + - ]: 168 : rPropertyMap[ PROP_ParaIsHyphenation ] <<= bLatinLineBrk;
72 : : }
73 : : // TODO see what to do with Asian hyphenation
74 : :
75 : : // ST_TextFontAlignType
76 : : // TODO
77 : : // sal_Int32 nFontAlign = xAttribs->getOptionalValueToken( XML_fontAlgn, XML_base );
78 : :
79 [ + - ][ + - ]: 375 : if ( xAttribs->hasAttribute( XML_hangingPunct ) )
[ + + ]
80 : : {
81 [ + - ]: 168 : bool bHangingPunct = attribs.getBool( XML_hangingPunct, false );
82 [ + - ][ + - ]: 168 : rPropertyMap[ PROP_ParaIsHangingPunctuation ] <<= bHangingPunct;
83 : : }
84 : :
85 : : // ST_Coordinate
86 [ + - ][ + - ]: 375 : if ( xAttribs->hasAttribute( XML_indent ) )
[ + + ]
87 : : {
88 [ + - ][ + - ]: 81 : sValue = xAttribs->getOptionalValue( XML_indent );
89 [ + - ][ + - ]: 81 : mrTextParagraphProperties.getFirstLineIndentation() = boost::optional< sal_Int32 >( sValue.isEmpty() ? 0 : GetCoordinate( sValue ) );
[ + - ][ + - ]
[ - + ]
90 : : }
91 : :
92 : : // ST_TextIndentLevelType
93 : : // -1 is an invalid value and denote the lack of level
94 [ + - ]: 375 : sal_Int32 nLevel = attribs.getInteger( XML_lvl, 0 );
95 [ + - ][ - + ]: 375 : if( nLevel > 8 || nLevel < 0 )
96 : : {
97 : 0 : nLevel = 0;
98 : : }
99 : :
100 : 375 : mrTextParagraphProperties.setLevel( static_cast< sal_Int16 >( nLevel ) );
101 : :
102 : 375 : char name[] = "Outline X";
103 : 375 : name[8] = static_cast<char>( '1' + nLevel );
104 : 375 : const OUString sStyleNameValue( rtl::OUString::createFromAscii( name ) );
105 [ + - ]: 375 : mrBulletList.setStyleName( sStyleNameValue );
106 : :
107 : : // ST_TextMargin
108 : : // ParaLeftMargin
109 [ + - ][ + - ]: 375 : if ( xAttribs->hasAttribute( XML_marL ) )
[ + + ]
110 : : {
111 [ + - ][ + - ]: 189 : sValue = xAttribs->getOptionalValue( XML_marL );
112 [ + - ][ + - ]: 189 : mrTextParagraphProperties.getParaLeftMargin() = boost::optional< sal_Int32 >( sValue.isEmpty() ? 0 : GetCoordinate( sValue ) );
[ + - ][ + - ]
[ - + ]
113 : : }
114 : :
115 : : // ParaRightMargin
116 [ + - ][ + - ]: 375 : if ( xAttribs->hasAttribute( XML_marR ) )
[ - + ]
117 : : {
118 [ # # ][ # # ]: 0 : sValue = xAttribs->getOptionalValue( XML_marR );
119 [ # # ][ # # ]: 0 : sal_Int32 nMarR = sValue.isEmpty() ? 0 : GetCoordinate( sValue ) ;
120 [ # # ][ # # ]: 0 : rPropertyMap[ PROP_ParaRightMargin ] <<= nMarR;
121 : : }
122 : :
123 [ + - ][ + - ]: 375 : if ( xAttribs->hasAttribute( XML_rtl ) )
[ + + ]
124 : : {
125 [ + - ]: 168 : bool bRtl = attribs.getBool( XML_rtl, false );
126 [ - + ][ + - ]: 168 : rPropertyMap[ PROP_TextWritingMode ] <<= ( bRtl ? WritingMode_RL_TB : WritingMode_LR_TB );
[ + - ]
127 [ + - ]: 375 : }
128 : 375 : }
129 : :
130 : :
131 : :
132 [ + - ]: 375 : TextParagraphPropertiesContext::~TextParagraphPropertiesContext()
133 : : {
134 : 375 : PropertyMap& rPropertyMap( mrTextParagraphProperties.getTextParagraphPropertyMap() );
135 [ + + ]: 375 : if ( maLineSpacing.bHasValue )
136 [ + - ][ + - ]: 9 : rPropertyMap[ PROP_ParaLineSpacing ] <<= maLineSpacing.toLineSpacing();
137 : : else
138 [ + - ][ + - ]: 366 : rPropertyMap[ PROP_ParaLineSpacing ] <<= ::com::sun::star::style::LineSpacing( ::com::sun::star::style::LineSpacingMode::PROP, 100 );
139 : :
140 : :
141 : 375 : ::std::list< TabStop >::size_type nTabCount = maTabList.size();
142 [ - + ]: 375 : if( nTabCount != 0 )
143 : : {
144 [ # # ]: 0 : Sequence< TabStop > aSeq( nTabCount );
145 [ # # ]: 0 : TabStop * aArray = aSeq.getArray();
146 : : OSL_ENSURE( aArray != NULL, "sequence array is NULL" );
147 [ # # ]: 0 : ::std::copy( maTabList.begin(), maTabList.end(), aArray );
148 [ # # ][ # # ]: 0 : rPropertyMap[ PROP_ParaTabStops ] <<= aSeq;
[ # # ]
149 : : }
150 : :
151 [ - + ][ # # ]: 375 : if ( mxBlipProps.get() && mxBlipProps->mxGraphic.is() )
[ - + ]
152 [ # # ]: 0 : mrBulletList.setGraphic( mxBlipProps->mxGraphic );
153 : :
154 [ + - ][ + + ]: 375 : if( mrBulletList.is() )
155 [ + - ][ + - ]: 114 : rPropertyMap[ PROP_IsNumbering ] <<= sal_True;
156 : 375 : sal_Int16 nLevel = mrTextParagraphProperties.getLevel();
157 [ + - ][ + - ]: 375 : rPropertyMap[ PROP_NumberingLevel ] <<= nLevel;
158 [ + - ][ + - ]: 375 : rPropertyMap[ PROP_NumberingIsNumber ] <<= sal_True;
159 [ - + ]: 750 : }
160 : :
161 : : // --------------------------------------------------------------------
162 : :
163 : 597 : void TextParagraphPropertiesContext::endFastElement( sal_Int32 ) throw (SAXException, RuntimeException)
164 : : {
165 : 597 : }
166 : :
167 : :
168 : :
169 : : // --------------------------------------------------------------------
170 : :
171 : 570 : Reference< XFastContextHandler > TextParagraphPropertiesContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& rXAttributes ) throw (SAXException, RuntimeException)
172 : : {
173 [ + - ]: 570 : AttributeList aAttribs( rXAttributes );
174 : 570 : Reference< XFastContextHandler > xRet;
175 [ + + + - : 570 : switch( aElementToken )
- - + - -
+ + - + -
- + - ]
176 : : {
177 : : case A_TOKEN( lnSpc ): // CT_TextSpacing
178 [ + - ][ + - ]: 9 : xRet.set( new TextSpacingContext( *this, maLineSpacing ) );
[ + - ]
179 : 9 : break;
180 : : case A_TOKEN( spcBef ): // CT_TextSpacing
181 [ + - ][ + - ]: 69 : xRet.set( new TextSpacingContext( *this, mrSpaceBefore ) );
[ + - ]
182 : 69 : break;
183 : : case A_TOKEN( spcAft ): // CT_TextSpacing
184 [ + - ][ + - ]: 9 : xRet.set( new TextSpacingContext( *this, mrSpaceAfter ) );
[ + - ]
185 : 9 : break;
186 : :
187 : : // EG_TextBulletColor
188 : : case A_TOKEN( buClrTx ): // CT_TextBulletColorFollowText ???
189 [ # # ]: 0 : mrBulletList.mbBulletColorFollowText <<= sal_True;
190 : 0 : break;
191 : : case A_TOKEN( buClr ): // CT_Color
192 [ # # ][ # # ]: 0 : xRet.set( new ColorContext( *this, *mrBulletList.maBulletColorPtr ) );
[ # # ]
193 : 0 : break;
194 : :
195 : : // EG_TextBulletSize
196 : : case A_TOKEN( buSzTx ): // CT_TextBulletSizeFollowText
197 [ # # ]: 0 : mrBulletList.setBulletSize(100);
198 : 0 : break;
199 : : case A_TOKEN( buSzPct ): // CT_TextBulletSizePercent
200 [ + - ][ + - ]: 27 : mrBulletList.setBulletSize( static_cast<sal_Int16>( GetPercent( rXAttributes->getOptionalValue( XML_val ) ) / 1000 ) );
[ + - ][ + - ]
201 : 27 : break;
202 : : case A_TOKEN( buSzPts ): // CT_TextBulletSizePoint
203 [ # # ]: 0 : mrBulletList.setBulletSize(0);
204 [ # # ][ # # ]: 0 : mrBulletList.setFontSize( static_cast<sal_Int16>(GetTextSize( rXAttributes->getOptionalValue( XML_val ) ) ) );
[ # # ][ # # ]
205 : 0 : break;
206 : :
207 : : // EG_TextBulletTypeface
208 : : case A_TOKEN( buFontTx ): // CT_TextBulletTypefaceFollowText
209 [ # # # # ]: 0 : mrBulletList.mbBulletFontFollowText <<= sal_True;
210 : 0 : break;
211 : : case A_TOKEN( buFont ): // CT_TextFont
212 [ + - ]: 81 : mrBulletList.maBulletFont.setAttributes( aAttribs );
213 : 81 : break;
214 : :
215 : : // EG_TextBullet
216 : : case A_TOKEN( buNone ): // CT_TextNoBullet
217 [ + - ]: 33 : mrBulletList.setNone();
218 : 33 : break;
219 : : case A_TOKEN( buAutoNum ): // CT_TextAutonumberBullet
220 : : {
221 [ # # ]: 0 : AttributeList attribs( rXAttributes );
222 : : try {
223 [ # # ][ # # ]: 0 : sal_Int32 nType = rXAttributes->getValueToken( XML_type );
224 [ # # ]: 0 : sal_Int32 nStartAt = attribs.getInteger( XML_startAt, 1 );
225 [ # # ]: 0 : if( nStartAt > 32767 )
226 : : {
227 : 0 : nStartAt = 32767;
228 : : }
229 [ # # ]: 0 : else if( nStartAt < 1 )
230 : : {
231 : 0 : nStartAt = 1;
232 : : }
233 [ # # ]: 0 : mrBulletList.setStartAt( nStartAt );
234 [ # # ]: 0 : mrBulletList.setType( nType );
235 : : }
236 [ # # ]: 0 : catch(SAXException& /* e */ )
237 : : {
238 : : OSL_TRACE("OOX: SAXException in XML_buAutoNum");
239 : : }
240 [ # # ]: 0 : break;
241 : : }
242 : : case A_TOKEN( buChar ): // CT_TextCharBullet
243 : : try {
244 [ + - ][ + - ]: 81 : mrBulletList.setBulletChar( rXAttributes->getValue( XML_char ) );
[ + - ][ # # ]
245 : : }
246 [ # # ]: 0 : catch(SAXException& /* e */)
247 : : {
248 : : OSL_TRACE("OOX: SAXException in XML_buChar");
249 : : }
250 : 81 : break;
251 : : case A_TOKEN( buBlip ): // CT_TextBlipBullet
252 : : {
253 [ # # ][ # # ]: 0 : mxBlipProps.reset( new BlipFillProperties );
[ # # ]
254 [ # # ][ # # ]: 0 : xRet.set( new BlipFillContext( *this, rXAttributes, *mxBlipProps ) );
[ # # ]
255 : : }
256 : 0 : break;
257 : :
258 : : case A_TOKEN( tabLst ): // CT_TextTabStopList
259 [ # # ][ # # ]: 0 : xRet.set( new TextTabStopListContext( *this, maTabList ) );
[ # # ]
260 : 0 : break;
261 : : case A_TOKEN( defRPr ): // CT_TextCharacterProperties
262 [ + - ][ + - ]: 261 : xRet.set( new TextCharacterPropertiesContext( *this, rXAttributes, mrTextParagraphProperties.getTextCharacterProperties() ) );
[ + - ]
263 : 261 : break;
264 : : }
265 [ + + ]: 570 : if ( !xRet.is() )
266 [ + - ]: 222 : xRet.set( this );
267 [ + - ]: 570 : return xRet;
268 : : }
269 : :
270 : : // --------------------------------------------------------------------
271 : :
272 : : } }
273 : :
274 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|