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 "svgfilter.hxx"
21 : #include "svgfontexport.hxx"
22 : #include "svgwriter.hxx"
23 :
24 : #include <rtl/crc.h>
25 : #include <vcl/unohelp.hxx>
26 : #include <vcl/outdev.hxx>
27 : #include <vcl/settings.hxx>
28 : #include <tools/helpers.hxx>
29 : #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
30 : #include <sax/tools/converter.hxx>
31 :
32 : #include <boost/scoped_ptr.hpp>
33 : #include <boost/shared_array.hpp>
34 :
35 :
36 : static const char aXMLElemG[] = "g";
37 : static const char aXMLElemA[] = "a";
38 : static const char aXMLElemDefs[] = "defs";
39 : static const char aXMLElemLine[] = "line";
40 : static const char aXMLElemRect[] = "rect";
41 : static const char aXMLElemEllipse[] = "ellipse";
42 : static const char aXMLElemPath[] = "path";
43 : static const char aXMLElemText[] = "text";
44 : static const char aXMLElemTspan[] = "tspan";
45 : static const char aXMLElemImage[] = "image";
46 : static const char aXMLElemMask[] = "mask";
47 : static const char aXMLElemPattern[] = "pattern";
48 : static const char aXMLElemLinearGradient[] = "linearGradient";
49 : static const char aXMLElemRadialGradient[] = "radialGradient";
50 : static const char aXMLElemStop[] = "stop";
51 :
52 : static const char aXMLAttrTransform[] = "transform";
53 : static const char aXMLAttrStyle[] = "style";
54 : static const char aXMLAttrId[] = "id";
55 : static const char aXMLAttrD[] = "d";
56 : static const char aXMLAttrX[] = "x";
57 : static const char aXMLAttrY[] = "y";
58 : static const char aXMLAttrX1[] = "x1";
59 : static const char aXMLAttrY1[] = "y1";
60 : static const char aXMLAttrX2[] = "x2";
61 : static const char aXMLAttrY2[] = "y2";
62 : static const char aXMLAttrCX[] = "cx";
63 : static const char aXMLAttrCY[] = "cy";
64 : static const char aXMLAttrR[] = "r";
65 : static const char aXMLAttrRX[] = "rx";
66 : static const char aXMLAttrRY[] = "ry";
67 : static const char aXMLAttrWidth[] = "width";
68 : static const char aXMLAttrHeight[] = "height";
69 : static const char aXMLAttrStroke[] = "stroke";
70 : static const char aXMLAttrStrokeOpacity[] = "stroke-opacity";
71 : static const char aXMLAttrStrokeWidth[] = "stroke-width";
72 : static const char aXMLAttrStrokeDashArray[] = "stroke-dasharray";
73 : static const char aXMLAttrFill[] = "fill";
74 : static const char aXMLAttrFillOpacity[] = "fill-opacity";
75 : static const char aXMLAttrFontFamily[] = "font-family";
76 : static const char aXMLAttrFontSize[] = "font-size";
77 : static const char aXMLAttrFontStyle[] = "font-style";
78 : static const char aXMLAttrFontWeight[] = "font-weight";
79 : static const char aXMLAttrTextDecoration[] = "text-decoration";
80 : static const char aXMLAttrXLinkHRef[] = "xlink:href";
81 : static const char aXMLAttrGradientUnits[] = "gradientUnits";
82 : static const char aXMLAttrPatternUnits[] = "patternUnits";
83 : static const char aXMLAttrOffset[] = "offset";
84 : static const char aXMLAttrStopColor[] = "stop-color";
85 : static const char aXMLAttrStrokeLinejoin[] = "stroke-linejoin";
86 : static const char aXMLAttrStrokeLinecap[] = "stroke-linecap";
87 :
88 :
89 : #define NSPREFIX "ooo:"
90 :
91 : static const char aOOOAttrNumberingType[] = NSPREFIX "numbering-type";
92 :
93 :
94 : static sal_Char const XML_UNO_NAME_NRULE_NUMBERINGTYPE[] = "NumberingType";
95 : static sal_Char const XML_UNO_NAME_NRULE_BULLET_CHAR[] = "BulletChar";
96 :
97 0 : SVGAttributeWriter::SVGAttributeWriter( SVGExport& rExport, SVGFontExport& rFontExport )
98 : : mrExport( rExport )
99 : , mrFontExport( rFontExport )
100 : , mpElemFont( NULL )
101 : , mpElemPaint( NULL )
102 : , maLineJoin(basegfx::B2DLINEJOIN_NONE)
103 0 : , maLineCap(css::drawing::LineCap_BUTT)
104 : {
105 0 : }
106 :
107 0 : SVGAttributeWriter::~SVGAttributeWriter()
108 : {
109 0 : if( mpElemPaint )
110 0 : delete mpElemPaint;
111 0 : if( mpElemFont )
112 0 : delete mpElemFont;
113 0 : }
114 :
115 0 : double SVGAttributeWriter::ImplRound( double fValue, sal_Int32 nDecs )
116 : {
117 0 : return( floor( fValue * pow( 10.0, (int)nDecs ) + 0.5 ) / pow( 10.0, (int)nDecs ) );
118 : }
119 :
120 0 : void SVGAttributeWriter::ImplGetColorStr( const Color& rColor, OUString& rColorStr )
121 : {
122 0 : if( rColor.GetTransparency() == 255 )
123 0 : rColorStr = "none";
124 : else
125 : {
126 0 : rColorStr = "rgb(" + OUString::number(rColor.GetRed()) + "," + OUString::number(rColor.GetGreen()) +
127 0 : "," + OUString::number(rColor.GetBlue()) + ")";
128 : }
129 0 : }
130 :
131 0 : void SVGAttributeWriter::AddColorAttr( const char* pColorAttrName,
132 : const char* pColorOpacityAttrName,
133 : const Color& rColor )
134 : {
135 0 : OUString aColor, aColorOpacity;
136 :
137 0 : ImplGetColorStr( rColor, aColor );
138 :
139 0 : if( rColor.GetTransparency() > 0 && rColor.GetTransparency() < 255 )
140 0 : aColorOpacity = OUString::number( ImplRound( ( 255.0 - rColor.GetTransparency() ) / 255.0 ) );
141 :
142 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, pColorAttrName, aColor );
143 :
144 0 : if( !aColorOpacity.isEmpty() && mrExport.IsUseOpacity() )
145 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, pColorOpacityAttrName, aColorOpacity );
146 0 : }
147 :
148 0 : void SVGAttributeWriter::AddPaintAttr( const Color& rLineColor, const Color& rFillColor,
149 : const Rectangle* pObjBoundRect, const Gradient* pFillGradient )
150 : {
151 : // Fill
152 0 : if( pObjBoundRect && pFillGradient )
153 : {
154 0 : OUString aGradientId;
155 :
156 0 : AddGradientDef( *pObjBoundRect, *pFillGradient, aGradientId );
157 :
158 0 : if( !aGradientId.isEmpty() )
159 : {
160 0 : OUString aGradientURL = "url(#" + aGradientId + ")";
161 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrFill, aGradientURL );
162 0 : }
163 : }
164 : else
165 0 : AddColorAttr( aXMLAttrFill, aXMLAttrFillOpacity, rFillColor );
166 :
167 : // Stroke
168 0 : AddColorAttr( aXMLAttrStroke, aXMLAttrStrokeOpacity, rLineColor );
169 0 : }
170 :
171 0 : void SVGAttributeWriter::AddGradientDef( const Rectangle& rObjRect, const Gradient& rGradient, OUString& rGradientId )
172 : {
173 0 : if( rObjRect.GetWidth() && rObjRect.GetHeight() &&
174 0 : ( rGradient.GetStyle() == GradientStyle_LINEAR || rGradient.GetStyle() == GradientStyle_AXIAL ||
175 0 : rGradient.GetStyle() == GradientStyle_RADIAL || rGradient.GetStyle() == GradientStyle_ELLIPTICAL ) )
176 : {
177 0 : SvXMLElementExport aDesc( mrExport, XML_NAMESPACE_NONE, aXMLElemDefs, true, true );
178 0 : Color aStartColor( rGradient.GetStartColor() ), aEndColor( rGradient.GetEndColor() );
179 0 : sal_uInt16 nAngle = rGradient.GetAngle() % 3600;
180 0 : Point aObjRectCenter( rObjRect.Center() );
181 0 : Polygon aPoly( rObjRect );
182 : static sal_Int32 nCurGradientId = 1;
183 :
184 0 : aPoly.Rotate( aObjRectCenter, nAngle );
185 0 : Rectangle aRect( aPoly.GetBoundRect() );
186 :
187 : // adjust start/end colors with intensities
188 0 : aStartColor.SetRed( (sal_uInt8)( (long) aStartColor.GetRed() * rGradient.GetStartIntensity() ) / 100 );
189 0 : aStartColor.SetGreen( (sal_uInt8)( (long) aStartColor.GetGreen() * rGradient.GetStartIntensity() ) / 100 );
190 0 : aStartColor.SetBlue( (sal_uInt8)( (long) aStartColor.GetBlue() * rGradient.GetStartIntensity() ) / 100 );
191 :
192 0 : aEndColor.SetRed( (sal_uInt8)( (long) aEndColor.GetRed() * rGradient.GetEndIntensity() ) / 100 );
193 0 : aEndColor.SetGreen( (sal_uInt8)( (long) aEndColor.GetGreen() * rGradient.GetEndIntensity() ) / 100 );
194 0 : aEndColor.SetBlue( (sal_uInt8)( (long) aEndColor.GetBlue() * rGradient.GetEndIntensity() ) / 100 );
195 :
196 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrId,
197 0 : ( rGradientId = "Gradient_" ) += OUString::number( nCurGradientId++ ) );
198 :
199 : {
200 0 : boost::scoped_ptr< SvXMLElementExport > apGradient;
201 0 : OUString aColorStr;
202 :
203 0 : if( rGradient.GetStyle() == GradientStyle_LINEAR || rGradient.GetStyle() == GradientStyle_AXIAL )
204 : {
205 0 : Polygon aLinePoly( 2 );
206 :
207 0 : aLinePoly[ 0 ] = Point( aObjRectCenter.X(), aRect.Top() );
208 0 : aLinePoly[ 1 ] = Point( aObjRectCenter.X(), aRect.Bottom() );
209 :
210 0 : aLinePoly.Rotate( aObjRectCenter, nAngle );
211 :
212 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrGradientUnits, "userSpaceOnUse" );
213 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX1, OUString::number( aLinePoly[ 0 ].X() ) );
214 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY1, OUString::number( aLinePoly[ 0 ].Y() ) );
215 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX2, OUString::number( aLinePoly[ 1 ].X() ) );
216 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY2, OUString::number( aLinePoly[ 1 ].Y() ) );
217 :
218 0 : apGradient.reset( new SvXMLElementExport( mrExport, XML_NAMESPACE_NONE, aXMLElemLinearGradient, true, true ) );
219 :
220 : // write stop values
221 0 : double fBorder = static_cast< double >( rGradient.GetBorder() ) *
222 0 : ( ( rGradient.GetStyle() == GradientStyle_AXIAL ) ? 0.005 : 0.01 );
223 :
224 0 : ImplGetColorStr( ( rGradient.GetStyle() == GradientStyle_AXIAL ) ? aEndColor : aStartColor, aColorStr );
225 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrOffset, OUString::number( fBorder ) );
226 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStopColor, aColorStr );
227 :
228 : {
229 0 : SvXMLElementExport aDesc2( mrExport, XML_NAMESPACE_NONE, aXMLElemStop, true, true );
230 : }
231 :
232 0 : if( rGradient.GetStyle() == GradientStyle_AXIAL )
233 : {
234 0 : ImplGetColorStr( aStartColor, aColorStr );
235 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrOffset, OUString::number( 0.5 ) );
236 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStopColor, aColorStr );
237 :
238 : {
239 0 : SvXMLElementExport aDesc3( mrExport, XML_NAMESPACE_NONE, aXMLElemStop, true, true );
240 : }
241 : }
242 :
243 0 : if( rGradient.GetStyle() != GradientStyle_AXIAL )
244 0 : fBorder = 0.0;
245 :
246 0 : ImplGetColorStr( aEndColor, aColorStr );
247 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrOffset, OUString::number( ImplRound( 1.0 - fBorder ) ) );
248 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStopColor, aColorStr );
249 :
250 : {
251 0 : SvXMLElementExport aDesc4( mrExport, XML_NAMESPACE_NONE, aXMLElemStop, true, true );
252 0 : }
253 : }
254 : else
255 : {
256 0 : const double fCenterX = rObjRect.Left() + rObjRect.GetWidth() * rGradient.GetOfsX() * 0.01;
257 0 : const double fCenterY = rObjRect.Top() + rObjRect.GetHeight() * rGradient.GetOfsY() * 0.01;
258 0 : const double fRadius = sqrt( static_cast< double >( rObjRect.GetWidth() ) * rObjRect.GetWidth() +
259 0 : rObjRect.GetHeight() * rObjRect.GetHeight() ) * 0.5;
260 :
261 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrGradientUnits, "userSpaceOnUse" );
262 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrCX, OUString::number( ImplRound( fCenterX ) ) );
263 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrCY, OUString::number( ImplRound( fCenterY ) ) );
264 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrR, OUString::number( ImplRound( fRadius ) ) );
265 :
266 0 : apGradient.reset( new SvXMLElementExport( mrExport, XML_NAMESPACE_NONE, aXMLElemRadialGradient, true, true ) );
267 :
268 : // write stop values
269 0 : ImplGetColorStr( aEndColor, aColorStr );
270 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrOffset, OUString::number( 0.0 ) );
271 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStopColor, aColorStr );
272 :
273 : {
274 0 : SvXMLElementExport aDesc5( mrExport, XML_NAMESPACE_NONE, aXMLElemStop, true, true );
275 : }
276 :
277 0 : ImplGetColorStr( aStartColor, aColorStr );
278 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrOffset,
279 0 : OUString::number( ImplRound( 1.0 - rGradient.GetBorder() * 0.01 ) ) );
280 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStopColor, aColorStr );
281 :
282 : {
283 0 : SvXMLElementExport aDesc6( mrExport, XML_NAMESPACE_NONE, aXMLElemStop, true, true );
284 : }
285 0 : }
286 0 : }
287 : }
288 : else
289 0 : rGradientId = "";
290 0 : }
291 :
292 0 : void SVGAttributeWriter::SetFontAttr( const vcl::Font& rFont )
293 : {
294 0 : if( rFont != maCurFont )
295 : {
296 0 : OUString aFontStyle, aTextDecoration;
297 : sal_Int32 nFontWeight;
298 :
299 0 : maCurFont = rFont;
300 :
301 : // Font Family
302 0 : setFontFamily();
303 :
304 : // Font Size
305 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrFontSize,
306 0 : OUString::number( rFont.GetHeight() ) + "px" );
307 :
308 : // Font Style
309 0 : if( rFont.GetItalic() != ITALIC_NONE )
310 : {
311 0 : if( rFont.GetItalic() == ITALIC_OBLIQUE )
312 0 : aFontStyle = "oblique";
313 : else
314 0 : aFontStyle = "italic";
315 : }
316 : else
317 0 : aFontStyle = "normal";
318 :
319 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrFontStyle, aFontStyle );
320 :
321 : // Font Weight
322 0 : switch( rFont.GetWeight() )
323 : {
324 0 : case WEIGHT_THIN: nFontWeight = 100; break;
325 0 : case WEIGHT_ULTRALIGHT: nFontWeight = 200; break;
326 0 : case WEIGHT_LIGHT: nFontWeight = 300; break;
327 0 : case WEIGHT_SEMILIGHT: nFontWeight = 400; break;
328 0 : case WEIGHT_NORMAL: nFontWeight = 400; break;
329 0 : case WEIGHT_MEDIUM: nFontWeight = 500; break;
330 0 : case WEIGHT_SEMIBOLD: nFontWeight = 600; break;
331 0 : case WEIGHT_BOLD: nFontWeight = 700; break;
332 0 : case WEIGHT_ULTRABOLD: nFontWeight = 800; break;
333 0 : case WEIGHT_BLACK: nFontWeight = 900; break;
334 0 : default: nFontWeight = 400; break;
335 : }
336 :
337 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrFontWeight, OUString::number( nFontWeight ) );
338 :
339 0 : if( mrExport.IsUseNativeTextDecoration() )
340 : {
341 0 : if( rFont.GetUnderline() != UNDERLINE_NONE || rFont.GetStrikeout() != STRIKEOUT_NONE )
342 : {
343 0 : if( rFont.GetUnderline() != UNDERLINE_NONE )
344 0 : aTextDecoration = "underline ";
345 :
346 0 : if( rFont.GetStrikeout() != STRIKEOUT_NONE )
347 0 : aTextDecoration += "line-through ";
348 : }
349 : else
350 0 : aTextDecoration = "none";
351 :
352 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrTextDecoration, aTextDecoration );
353 : }
354 :
355 0 : startFontSettings();
356 : }
357 0 : }
358 :
359 0 : void SVGAttributeWriter::startFontSettings()
360 : {
361 0 : endFontSettings();
362 0 : if( mrExport.IsUsePositionedCharacters() )
363 : {
364 0 : mpElemFont = new SvXMLElementExport( mrExport, XML_NAMESPACE_NONE, aXMLElemG, true, true );
365 : }
366 : else
367 : {
368 0 : mpElemFont = new SvXMLElementExport( mrExport, XML_NAMESPACE_NONE, aXMLElemTspan, true, true );
369 : }
370 0 : }
371 :
372 0 : void SVGAttributeWriter::endFontSettings()
373 : {
374 0 : if( mpElemFont )
375 : {
376 0 : delete mpElemFont;
377 0 : mpElemFont = NULL;
378 : }
379 0 : }
380 :
381 0 : void SVGAttributeWriter::setFontFamily()
382 : {
383 0 : if( mrExport.IsUsePositionedCharacters() )
384 : {
385 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrFontFamily, mrFontExport.GetMappedFontName( maCurFont.GetName() ) );
386 : }
387 : else
388 : {
389 0 : sal_Int32 nNextTokenPos( 0 );
390 0 : const OUString& rsFontName = maCurFont.GetName();
391 0 : OUString sFontFamily( rsFontName.getToken( 0, ';', nNextTokenPos ) );
392 0 : FontPitch ePitch = maCurFont.GetPitch();
393 0 : if( ePitch == PITCH_FIXED )
394 : {
395 0 : sFontFamily += ", monospace";
396 : }
397 : else
398 : {
399 0 : FontFamily eFamily = maCurFont.GetFamily();
400 0 : if( eFamily == FAMILY_ROMAN )
401 0 : sFontFamily += ", serif";
402 0 : else if( eFamily == FAMILY_SWISS )
403 0 : sFontFamily += ", sans-serif";
404 : }
405 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrFontFamily, sFontFamily );
406 : }
407 0 : }
408 :
409 0 : SVGTextWriter::SVGTextWriter( SVGExport& rExport )
410 : : mrExport( rExport ),
411 : mpContext( NULL ),
412 : mpVDev( NULL ),
413 : mbIsTextShapeStarted( false ),
414 : mrTextShape(),
415 : msShapeId(),
416 : mrParagraphEnumeration(),
417 : mrCurrentTextParagraph(),
418 : mrTextPortionEnumeration(),
419 : mrCurrentTextPortion(),
420 : mpTextEmbeddedBitmapMtf( NULL ),
421 : mpTargetMapMode( NULL ),
422 : mpTextShapeElem( NULL ),
423 : mpTextParagraphElem( NULL ),
424 : mpTextPositionElem( NULL ),
425 : mnLeftTextPortionLength( 0 ),
426 : maTextPos(0,0),
427 : mnTextWidth(0),
428 : mbPositioningNeeded( false ),
429 : mbIsNewListItem( false ),
430 : meNumberingType(0),
431 : mcBulletChar(0),
432 : maBulletListItemMap(),
433 : mbIsListLevelStyleImage( false ),
434 : mbLineBreak( false ),
435 : mbIsURLField( false ),
436 : msUrl(),
437 : mbIsPlacehlolderShape( false ),
438 : mbIWS( false ),
439 : maCurrentFont(),
440 0 : maParentFont()
441 : {
442 0 : }
443 :
444 0 : SVGTextWriter::~SVGTextWriter()
445 : {
446 0 : endTextParagraph();
447 0 : }
448 :
449 0 : void SVGTextWriter::implRegisterInterface( const Reference< XInterface >& rxIf )
450 : {
451 0 : if( rxIf.is() )
452 0 : (mrExport.getInterfaceToIdentifierMapper()).registerReference( rxIf );
453 0 : }
454 :
455 0 : const OUString & SVGTextWriter::implGetValidIDFromInterface( const Reference< XInterface >& rxIf )
456 : {
457 0 : return (mrExport.getInterfaceToIdentifierMapper()).getIdentifier( rxIf );
458 : }
459 :
460 0 : void SVGTextWriter::implMap( const Size& rSz, Size& rDstSz ) const
461 : {
462 0 : if( mpVDev && mpTargetMapMode )
463 0 : rDstSz = OutputDevice::LogicToLogic( rSz, mpVDev->GetMapMode(), *mpTargetMapMode );
464 : else
465 : OSL_FAIL( "SVGTextWriter::implMap: invalid virtual device or map mode." );
466 0 : }
467 :
468 0 : void SVGTextWriter::implMap( const Point& rPt, Point& rDstPt ) const
469 : {
470 0 : if( mpVDev && mpTargetMapMode )
471 0 : rDstPt = OutputDevice::LogicToLogic( rPt, mpVDev->GetMapMode(), *mpTargetMapMode );
472 : else
473 : OSL_FAIL( "SVGTextWriter::implMap: invalid virtual device or map mode." );
474 0 : }
475 :
476 0 : void SVGTextWriter::implSetCurrentFont()
477 : {
478 0 : if( mpVDev )
479 : {
480 0 : maCurrentFont = mpVDev->GetFont();
481 0 : Size aSz;
482 :
483 0 : implMap( Size( 0, maCurrentFont.GetHeight() ), aSz );
484 :
485 0 : maCurrentFont.SetHeight( aSz.Height() );
486 : }
487 : else
488 : {
489 : OSL_FAIL( "SVGTextWriter::implSetCorrectFontHeight: invalid virtual device." );
490 : }
491 0 : }
492 :
493 : template< typename SubType >
494 0 : bool SVGTextWriter::implGetTextPosition( const MetaAction* pAction, Point& raPos, bool& rbEmpty )
495 : {
496 0 : const SubType* pA = static_cast<const SubType*>(pAction);
497 0 : sal_uInt16 nLength = pA->GetLen();
498 0 : rbEmpty = ( nLength == 0 );
499 0 : if( !rbEmpty )
500 : {
501 0 : raPos = pA->GetPoint();
502 0 : return true;
503 : }
504 0 : return false;
505 : }
506 :
507 : template<>
508 0 : bool SVGTextWriter::implGetTextPosition<MetaTextRectAction>( const MetaAction* pAction, Point& raPos, bool& rbEmpty )
509 : {
510 0 : const MetaTextRectAction* pA = static_cast<const MetaTextRectAction*>(pAction);
511 0 : sal_uInt16 nLength = pA->GetText().getLength();
512 0 : rbEmpty = ( nLength == 0 );
513 0 : if( !rbEmpty )
514 : {
515 0 : raPos = pA->GetRect().TopLeft();
516 0 : return true;
517 : }
518 0 : return false;
519 : }
520 :
521 : template< typename SubType >
522 0 : bool SVGTextWriter::implGetTextPositionFromBitmap( const MetaAction* pAction, Point& raPos, bool& rbEmpty )
523 : {
524 0 : const SubType* pA = static_cast<const SubType*>(pAction);
525 0 : raPos = pA->GetPoint();
526 0 : rbEmpty = false;
527 0 : return true;
528 : }
529 :
530 : /** setTextPosition
531 : * Set the start position of the next line of text. In case no text is found
532 : * the current action index is updated to the index value we reached while
533 : * searching for text.
534 : *
535 : * @returns {sal_Int32}
536 : * -2 if no text found and end of line is reached
537 : * -1 if no text found and end of paragraph is reached
538 : * 0 if no text found and end of text shape is reached
539 : * 1 if text found!
540 : */
541 0 : sal_Int32 SVGTextWriter::setTextPosition( const GDIMetaFile& rMtf, sal_uLong& nCurAction )
542 : {
543 0 : Point aPos;
544 0 : sal_uLong nCount = rMtf.GetActionSize();
545 0 : bool bEOL = false;
546 0 : bool bEOP = false;
547 0 : bool bETS = false;
548 0 : bool bConfigured = false;
549 0 : bool bEmpty = true;
550 :
551 0 : sal_uLong nActionIndex = nCurAction + 1;
552 0 : for( ; nActionIndex < nCount; ++nActionIndex )
553 : {
554 0 : const MetaAction* pAction = rMtf.GetAction( nActionIndex );
555 0 : const sal_uInt16 nType = pAction->GetType();
556 :
557 0 : switch( nType )
558 : {
559 : case( META_TEXT_ACTION ):
560 : {
561 0 : bConfigured = implGetTextPosition<MetaTextAction>( pAction, aPos, bEmpty );
562 : }
563 0 : break;
564 :
565 : case( META_TEXTRECT_ACTION ):
566 : {
567 0 : bConfigured = implGetTextPosition<MetaTextRectAction>( pAction, aPos, bEmpty );
568 : }
569 0 : break;
570 :
571 : case( META_TEXTARRAY_ACTION ):
572 : {
573 0 : bConfigured = implGetTextPosition<MetaTextArrayAction>( pAction, aPos, bEmpty );
574 : }
575 0 : break;
576 :
577 : case( META_STRETCHTEXT_ACTION ):
578 : {
579 0 : bConfigured = implGetTextPosition<MetaStretchTextAction>( pAction, aPos, bEmpty );
580 : }
581 0 : break;
582 :
583 : case( META_BMPSCALE_ACTION ):
584 : {
585 0 : bConfigured = implGetTextPositionFromBitmap<MetaBmpScaleAction>( pAction, aPos, bEmpty );
586 : }
587 0 : break;
588 :
589 : case( META_BMPEXSCALE_ACTION ):
590 : {
591 0 : bConfigured = implGetTextPositionFromBitmap<MetaBmpExScaleAction>( pAction, aPos, bEmpty );
592 : }
593 0 : break;
594 :
595 : // If we reach the end of the current line, paragraph or text shape
596 : // without finding any text we stop searching
597 : case( META_COMMENT_ACTION ):
598 : {
599 0 : const MetaCommentAction* pA = static_cast<const MetaCommentAction*>(pAction);
600 0 : const OString& rsComment = pA->GetComment();
601 0 : if( rsComment.equalsIgnoreAsciiCase( "XTEXT_EOL" ) )
602 : {
603 0 : bEOL = true;
604 : }
605 0 : else if( rsComment.equalsIgnoreAsciiCase( "XTEXT_EOP" ) )
606 : {
607 0 : bEOP = true;
608 :
609 0 : OUString sContent;
610 0 : while( nextTextPortion() )
611 : {
612 0 : sContent = mrCurrentTextPortion->getString();
613 0 : if( sContent.isEmpty() )
614 : {
615 0 : continue;
616 : }
617 : else
618 : {
619 0 : if( sContent.equalsAscii( "\n" ) )
620 0 : mbLineBreak = true;
621 : }
622 : }
623 0 : if( nextParagraph() )
624 : {
625 0 : while( nextTextPortion() )
626 : {
627 0 : sContent = mrCurrentTextPortion->getString();
628 0 : if( sContent.isEmpty() )
629 : {
630 0 : continue;
631 : }
632 : else
633 : {
634 0 : if( sContent.equalsAscii( "\n" ) )
635 0 : mbLineBreak = true;
636 : }
637 : }
638 0 : }
639 : }
640 0 : else if( rsComment.equalsIgnoreAsciiCase( "XTEXT_PAINTSHAPE_END" ) )
641 : {
642 0 : bETS = true;
643 : }
644 : }
645 0 : break;
646 : }
647 0 : if( bConfigured || bEOL || bEOP || bETS ) break;
648 : }
649 0 : implMap( aPos, maTextPos );
650 :
651 0 : if( bEmpty )
652 : {
653 0 : nCurAction = nActionIndex;
654 0 : return ( (bEOL) ? -2 : ( (bEOP) ? -1 : 0 ) );
655 : }
656 : else
657 : {
658 0 : return 1;
659 : }
660 : }
661 :
662 0 : void SVGTextWriter::setTextProperties( const GDIMetaFile& rMtf, sal_uLong nCurAction )
663 : {
664 0 : sal_uLong nCount = rMtf.GetActionSize();
665 0 : bool bEOP = false;
666 0 : bool bConfigured = false;
667 0 : for( sal_uLong nActionIndex = nCurAction + 1; nActionIndex < nCount; ++nActionIndex )
668 : {
669 0 : const MetaAction* pAction = rMtf.GetAction( nActionIndex );
670 0 : const sal_uInt16 nType = pAction->GetType();
671 0 : switch( nType )
672 : {
673 : case( META_TEXTLINECOLOR_ACTION ):
674 : case( META_TEXTFILLCOLOR_ACTION ):
675 : case( META_TEXTCOLOR_ACTION ):
676 : case( META_TEXTALIGN_ACTION ):
677 : case( META_FONT_ACTION ):
678 : case( META_LAYOUTMODE_ACTION ):
679 : {
680 0 : ( (MetaAction*) pAction )->Execute( mpVDev );
681 : }
682 0 : break;
683 :
684 : case( META_TEXT_ACTION ):
685 : {
686 0 : const MetaTextAction* pA = static_cast<const MetaTextAction*>(pAction);
687 0 : if( pA->GetLen() > 2 )
688 0 : bConfigured = true;
689 : }
690 0 : break;
691 : case( META_TEXTRECT_ACTION ):
692 : {
693 0 : const MetaTextRectAction* pA = static_cast<const MetaTextRectAction*>(pAction);
694 0 : if( pA->GetText().getLength() > 2 )
695 0 : bConfigured = true;
696 : }
697 0 : break;
698 : case( META_TEXTARRAY_ACTION ):
699 : {
700 0 : const MetaTextArrayAction* pA = static_cast<const MetaTextArrayAction*>(pAction);
701 0 : if( pA->GetLen() > 2 )
702 0 : bConfigured = true;
703 : }
704 0 : break;
705 : case( META_STRETCHTEXT_ACTION ):
706 : {
707 0 : const MetaStretchTextAction* pA = static_cast<const MetaStretchTextAction*>(pAction);
708 0 : if( pA->GetLen() > 2 )
709 0 : bConfigured = true;
710 : }
711 0 : break;
712 : // If we reach the end of the paragraph without finding any text
713 : // we stop searching
714 : case( META_COMMENT_ACTION ):
715 : {
716 0 : const MetaCommentAction* pA = static_cast<const MetaCommentAction*>(pAction);
717 0 : const OString& rsComment = pA->GetComment();
718 0 : if( rsComment.equalsIgnoreAsciiCase( "XTEXT_EOP" ) )
719 : {
720 0 : bEOP = true;
721 : }
722 : }
723 0 : break;
724 : }
725 0 : if( bConfigured || bEOP ) break;
726 : }
727 0 : }
728 :
729 0 : void SVGTextWriter::addFontAttributes( bool bIsTextContainer )
730 : {
731 0 : implSetCurrentFont();
732 :
733 0 : if( maCurrentFont != maParentFont )
734 : {
735 0 : const OUString& rsCurFontName = maCurrentFont.GetName();
736 0 : long int nCurFontSize = maCurrentFont.GetHeight();
737 0 : FontItalic eCurFontItalic = maCurrentFont.GetItalic();
738 0 : FontWeight eCurFontWeight = maCurrentFont.GetWeight();
739 :
740 0 : const OUString& rsParFontName = maParentFont.GetName();
741 0 : long int nParFontSize = maParentFont.GetHeight();
742 0 : FontItalic eParFontItalic = maParentFont.GetItalic();
743 0 : FontWeight eParFontWeight = maParentFont.GetWeight();
744 :
745 :
746 : // Font Family
747 0 : if( rsCurFontName != rsParFontName )
748 : {
749 0 : implSetFontFamily();
750 : }
751 :
752 : // Font Size
753 0 : if( nCurFontSize != nParFontSize )
754 : {
755 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrFontSize,
756 0 : OUString::number( nCurFontSize ) + "px" );
757 : }
758 :
759 : // Font Style
760 0 : if( eCurFontItalic != eParFontItalic )
761 : {
762 0 : OUString sFontStyle;
763 0 : if( eCurFontItalic != ITALIC_NONE )
764 : {
765 0 : if( eCurFontItalic == ITALIC_OBLIQUE )
766 0 : sFontStyle = "oblique";
767 : else
768 0 : sFontStyle = "italic";
769 : }
770 : else
771 : {
772 0 : sFontStyle = "normal";
773 : }
774 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrFontStyle, sFontStyle );
775 : }
776 :
777 : // Font Weight
778 0 : if( eCurFontWeight != eParFontWeight )
779 : {
780 : sal_Int32 nFontWeight;
781 0 : switch( eCurFontWeight )
782 : {
783 0 : case WEIGHT_THIN: nFontWeight = 100; break;
784 0 : case WEIGHT_ULTRALIGHT: nFontWeight = 200; break;
785 0 : case WEIGHT_LIGHT: nFontWeight = 300; break;
786 0 : case WEIGHT_SEMILIGHT: nFontWeight = 400; break;
787 0 : case WEIGHT_NORMAL: nFontWeight = 400; break;
788 0 : case WEIGHT_MEDIUM: nFontWeight = 500; break;
789 0 : case WEIGHT_SEMIBOLD: nFontWeight = 600; break;
790 0 : case WEIGHT_BOLD: nFontWeight = 700; break;
791 0 : case WEIGHT_ULTRABOLD: nFontWeight = 800; break;
792 0 : case WEIGHT_BLACK: nFontWeight = 900; break;
793 0 : default: nFontWeight = 400; break;
794 : }
795 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrFontWeight, OUString::number( nFontWeight ) );
796 : }
797 :
798 0 : if( bIsTextContainer )
799 0 : maParentFont = maCurrentFont;
800 : }
801 :
802 0 : if( mrExport.IsUseNativeTextDecoration() )
803 : {
804 0 : FontUnderline eCurFontUnderline = maCurrentFont.GetUnderline();
805 0 : FontStrikeout eCurFontStrikeout = maCurrentFont.GetStrikeout();
806 :
807 0 : FontUnderline eParFontUnderline = maParentFont.GetUnderline();
808 0 : FontStrikeout eParFontStrikeout = maParentFont.GetStrikeout();
809 :
810 0 : OUString sTextDecoration;
811 :
812 0 : if( eCurFontUnderline != eParFontUnderline )
813 : {
814 0 : if( eCurFontUnderline != UNDERLINE_NONE )
815 0 : sTextDecoration = "underline ";
816 : }
817 0 : if( eCurFontStrikeout != eParFontStrikeout )
818 : {
819 0 : if( eCurFontStrikeout != STRIKEOUT_NONE )
820 0 : sTextDecoration += "line-through ";
821 : }
822 0 : if( !sTextDecoration.isEmpty() )
823 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrTextDecoration, sTextDecoration );
824 : }
825 0 : }
826 :
827 0 : void SVGTextWriter::implSetFontFamily()
828 : {
829 0 : sal_Int32 nNextTokenPos( 0 );
830 0 : const OUString& rsFontName = maCurrentFont.GetName();
831 0 : OUString sFontFamily( rsFontName.getToken( 0, ';', nNextTokenPos ) );
832 0 : FontPitch ePitch = maCurrentFont.GetPitch();
833 0 : if( ePitch == PITCH_FIXED )
834 : {
835 0 : sFontFamily += ", monospace";
836 : }
837 : else
838 : {
839 0 : FontFamily eFamily = maCurrentFont.GetFamily();
840 0 : if( eFamily == FAMILY_ROMAN )
841 0 : sFontFamily += ", serif";
842 0 : else if( eFamily == FAMILY_SWISS )
843 0 : sFontFamily += ", sans-serif";
844 : }
845 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrFontFamily, sFontFamily );
846 0 : }
847 :
848 0 : bool SVGTextWriter::createParagraphEnumeration()
849 : {
850 0 : if( mrTextShape.is() )
851 : {
852 0 : msShapeId = implGetValidIDFromInterface( Reference<XInterface>(mrTextShape, UNO_QUERY) );
853 :
854 0 : Reference< XEnumerationAccess > xEnumerationAccess( mrTextShape, UNO_QUERY_THROW );
855 0 : Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
856 0 : if( xEnumeration.is() )
857 : {
858 0 : mrParagraphEnumeration.set( xEnumeration );
859 0 : return true;
860 : }
861 : else
862 : {
863 : OSL_FAIL( "SVGTextWriter::createParagraphEnumeration: no valid xEnumeration interface found." );
864 0 : }
865 : }
866 : else
867 : {
868 : OSL_FAIL( "SVGTextWriter::createParagraphEnumeration: no valid XText interface found." );
869 : }
870 0 : return false;
871 : }
872 :
873 0 : bool SVGTextWriter::nextParagraph()
874 : {
875 0 : mrTextPortionEnumeration.clear();
876 0 : mrCurrentTextParagraph.clear();
877 0 : mbIsNewListItem = false;
878 0 : mbIsListLevelStyleImage = false;
879 :
880 0 : if( mrParagraphEnumeration.is() && mrParagraphEnumeration->hasMoreElements() )
881 : {
882 0 : Reference < XTextContent > xTextContent( mrParagraphEnumeration->nextElement(), UNO_QUERY_THROW );
883 0 : if( xTextContent.is() )
884 : {
885 0 : Reference< XServiceInfo > xServiceInfo( xTextContent, UNO_QUERY_THROW );
886 0 : if( xServiceInfo.is() )
887 : {
888 : #if OSL_DEBUG_LEVEL > 0
889 : OUString sInfo;
890 : #endif
891 0 : if( xServiceInfo->supportsService( "com.sun.star.text.Paragraph" ) )
892 : {
893 0 : mrCurrentTextParagraph.set( xTextContent );
894 0 : Reference< XPropertySet > xPropSet( xTextContent, UNO_QUERY_THROW );
895 0 : Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
896 0 : if( xPropSetInfo->hasPropertyByName( "NumberingLevel" ) )
897 : {
898 0 : sal_Int16 nListLevel = 0;
899 0 : if( xPropSet->getPropertyValue( "NumberingLevel" ) >>= nListLevel )
900 : {
901 0 : mbIsNewListItem = true;
902 : #if OSL_DEBUG_LEVEL > 0
903 : sInfo = "NumberingLevel: " + OUString::number( nListLevel );
904 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "style", sInfo );
905 : #endif
906 0 : Reference< XIndexReplace > xNumRules;
907 0 : if( xPropSetInfo->hasPropertyByName( "NumberingRules" ) )
908 : {
909 0 : xPropSet->getPropertyValue( "NumberingRules" ) >>= xNumRules;
910 : }
911 0 : if( xNumRules.is() && ( nListLevel < xNumRules->getCount() ) )
912 : {
913 0 : bool bIsNumbered = true;
914 0 : OUString msNumberingIsNumber("NumberingIsNumber");
915 0 : if( xPropSetInfo->hasPropertyByName( msNumberingIsNumber ) )
916 : {
917 0 : if( !(xPropSet->getPropertyValue( msNumberingIsNumber ) >>= bIsNumbered ) )
918 : {
919 : OSL_FAIL( "numbered paragraph without number info" );
920 0 : bIsNumbered = false;
921 : }
922 : #if OSL_DEBUG_LEVEL > 0
923 : if( bIsNumbered )
924 : {
925 : sInfo = "true";
926 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "is-numbered", sInfo );
927 : }
928 : #endif
929 : }
930 0 : mbIsNewListItem = bIsNumbered;
931 :
932 0 : if( bIsNumbered )
933 : {
934 0 : Sequence<PropertyValue> aProps;
935 0 : if( xNumRules->getByIndex( nListLevel ) >>= aProps )
936 : {
937 0 : sal_Int16 eType = NumberingType::CHAR_SPECIAL;
938 0 : sal_Unicode cBullet = 0xf095;
939 0 : const sal_Int32 nCount = aProps.getLength();
940 0 : const PropertyValue* pPropArray = aProps.getConstArray();
941 0 : for( sal_Int32 i = 0; i < nCount; ++i )
942 : {
943 0 : const PropertyValue& rProp = pPropArray[i];
944 0 : if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_NUMBERINGTYPE, sizeof(XML_UNO_NAME_NRULE_NUMBERINGTYPE)-1 ) )
945 : {
946 0 : rProp.Value >>= eType;
947 : }
948 0 : else if( rProp.Name.equalsAsciiL( XML_UNO_NAME_NRULE_BULLET_CHAR, sizeof(XML_UNO_NAME_NRULE_BULLET_CHAR)-1 ) )
949 : {
950 0 : OUString sValue;
951 0 : rProp.Value >>= sValue;
952 0 : if( !sValue.isEmpty() )
953 : {
954 0 : cBullet = (sal_Unicode)sValue[0];
955 0 : }
956 : }
957 : }
958 0 : meNumberingType = eType;
959 0 : mbIsListLevelStyleImage = ( NumberingType::BITMAP == meNumberingType );
960 0 : if( NumberingType::CHAR_SPECIAL == meNumberingType )
961 : {
962 0 : if( cBullet )
963 : {
964 0 : if( cBullet < ' ' )
965 : {
966 0 : cBullet = 0xF000 + 149;
967 : }
968 0 : mcBulletChar = cBullet;
969 : #if OSL_DEBUG_LEVEL > 0
970 : sInfo = OUString::number( (sal_Int32) cBullet );
971 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "bullet-char", sInfo );
972 : #endif
973 : }
974 :
975 : }
976 0 : }
977 0 : }
978 0 : }
979 :
980 : }
981 : }
982 :
983 0 : Reference< XEnumerationAccess > xEnumerationAccess( xTextContent, UNO_QUERY_THROW );
984 0 : Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW );
985 0 : if( xEnumeration.is() && xEnumeration->hasMoreElements() )
986 : {
987 0 : mrTextPortionEnumeration.set( xEnumeration );
988 0 : }
989 : #if OSL_DEBUG_LEVEL > 0
990 : sInfo = "Paragraph";
991 : #endif
992 : }
993 0 : else if( xServiceInfo->supportsService( "com.sun.star.text.Table" ) )
994 : {
995 : OSL_FAIL( "SVGTextWriter::nextParagraph: text tables are not handled." );
996 : #if OSL_DEBUG_LEVEL > 0
997 : sInfo = "Table";
998 : #endif
999 : }
1000 : else
1001 : {
1002 : OSL_FAIL( "SVGTextWriter::nextParagraph: Unknown text content." );
1003 0 : return false;
1004 : }
1005 : #if OSL_DEBUG_LEVEL > 0
1006 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", sInfo );
1007 : SvXMLElementExport aParaElem( mrExport, XML_NAMESPACE_NONE, "desc", mbIWS, mbIWS );
1008 : #endif
1009 : }
1010 : else
1011 : {
1012 : OSL_FAIL( "SVGTextWriter::nextParagraph: no XServiceInfo interface available for text content." );
1013 0 : return false;
1014 : }
1015 :
1016 0 : const OUString& rParagraphId = implGetValidIDFromInterface( Reference<XInterface>(xTextContent, UNO_QUERY) );
1017 0 : if( !rParagraphId.isEmpty() )
1018 : {
1019 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "id", rParagraphId );
1020 : }
1021 0 : return true;
1022 0 : }
1023 : }
1024 :
1025 0 : return false;
1026 : }
1027 :
1028 0 : bool SVGTextWriter::nextTextPortion()
1029 : {
1030 0 : mrCurrentTextPortion.clear();
1031 0 : mbIsURLField = false;
1032 0 : mbIsPlacehlolderShape = false;
1033 0 : if( mrTextPortionEnumeration.is() && mrTextPortionEnumeration->hasMoreElements() )
1034 : {
1035 : #if OSL_DEBUG_LEVEL > 0
1036 : OUString sInfo;
1037 : #endif
1038 0 : Reference< XPropertySet > xPortionPropSet( mrTextPortionEnumeration->nextElement(), UNO_QUERY );
1039 0 : Reference< XPropertySetInfo > xPortionPropInfo( xPortionPropSet->getPropertySetInfo() );
1040 0 : Reference < XTextRange > xPortionTextRange( xPortionPropSet, UNO_QUERY);
1041 0 : if( xPortionPropSet.is() && xPortionPropInfo.is()
1042 0 : && xPortionPropInfo->hasPropertyByName( "TextPortionType" ) )
1043 : {
1044 : #if OSL_DEBUG_LEVEL > 0
1045 : OUString sPortionType;
1046 : if( xPortionPropSet->getPropertyValue( "TextPortionType" ) >>= sPortionType )
1047 : {
1048 : sInfo = "type: " + sPortionType + "; ";
1049 : }
1050 : #endif
1051 0 : if( xPortionTextRange.is() )
1052 : {
1053 : #if OSL_DEBUG_LEVEL > 0
1054 : sInfo += "content: " + xPortionTextRange->getString() + "; ";
1055 : #endif
1056 0 : mrCurrentTextPortion.set( xPortionTextRange );
1057 :
1058 0 : Reference < XPropertySet > xRangePropSet( xPortionTextRange, UNO_QUERY );
1059 0 : if( xRangePropSet.is() && xRangePropSet->getPropertySetInfo()->hasPropertyByName( "TextField" ) )
1060 : {
1061 0 : Reference < XTextField > xTextField( xRangePropSet->getPropertyValue( "TextField" ), UNO_QUERY );
1062 0 : if( xTextField.is() )
1063 : {
1064 0 : const OUString sServicePrefix("com.sun.star.text.textfield.");
1065 0 : const OUString sPresentationServicePrefix("com.sun.star.presentation.TextField.");
1066 :
1067 0 : Reference< XServiceInfo > xService( xTextField, UNO_QUERY );
1068 0 : const Sequence< OUString > aServices = xService->getSupportedServiceNames();
1069 :
1070 0 : const OUString* pNames = aServices.getConstArray();
1071 0 : sal_Int32 nCount = aServices.getLength();
1072 :
1073 0 : OUString sFieldName; // service name postfix of current field
1074 :
1075 : // search for TextField service name
1076 0 : while( nCount-- )
1077 : {
1078 0 : if ( pNames->matchIgnoreAsciiCase( sServicePrefix ) )
1079 : {
1080 : // TextField found => postfix is field type!
1081 0 : sFieldName = pNames->copy( sServicePrefix.getLength() );
1082 0 : break;
1083 : }
1084 0 : else if( 0 == pNames->compareTo( sPresentationServicePrefix, sPresentationServicePrefix.getLength() ) )
1085 : {
1086 : // TextField found => postfix is field type!
1087 0 : sFieldName = pNames->copy( sPresentationServicePrefix.getLength() );
1088 0 : break;
1089 : }
1090 :
1091 0 : ++pNames;
1092 : }
1093 :
1094 : #if OSL_DEBUG_LEVEL > 0
1095 : sInfo += "text field type: " + sFieldName + "; content: " + xTextField->getPresentation( /* show command: */ sal_False ) + "; ";
1096 : #endif
1097 0 : if( sFieldName.equalsAscii( "DateTime" ) || sFieldName.equalsAscii( "Header" )
1098 0 : || sFieldName.equalsAscii( "Footer" ) || sFieldName.equalsAscii( "PageNumber" ) )
1099 : {
1100 0 : mbIsPlacehlolderShape = true;
1101 : }
1102 : else
1103 : {
1104 0 : mbIsURLField = sFieldName.equalsAscii( "URL" );
1105 :
1106 0 : if( mbIsURLField )
1107 : {
1108 0 : Reference<XPropertySet> xTextFieldPropSet(xTextField, UNO_QUERY);
1109 0 : if( xTextFieldPropSet.is() )
1110 : {
1111 0 : OUString sURL;
1112 0 : if( ( xTextFieldPropSet->getPropertyValue( sFieldName ) ) >>= sURL )
1113 : {
1114 : #if OSL_DEBUG_LEVEL > 0
1115 : sInfo += "url: ";
1116 : sInfo += mrExport.GetRelativeReference( sURL );
1117 : #endif
1118 0 : msUrl = mrExport.GetRelativeReference( sURL );
1119 0 : if( !msUrl.isEmpty() )
1120 : {
1121 0 : implRegisterInterface( xPortionTextRange );
1122 :
1123 0 : const OUString& rTextPortionId = implGetValidIDFromInterface( Reference<XInterface>(xPortionTextRange, UNO_QUERY) );
1124 0 : if( !rTextPortionId.isEmpty() )
1125 : {
1126 0 : msHyperlinkIdList += rTextPortionId;
1127 0 : msHyperlinkIdList += " ";
1128 : }
1129 : }
1130 0 : }
1131 0 : }
1132 : }
1133 0 : }
1134 0 : }
1135 0 : }
1136 : }
1137 : #if OSL_DEBUG_LEVEL > 0
1138 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "TextPortion" );
1139 : SvXMLElementExport aPortionElem( mrExport, XML_NAMESPACE_NONE, "desc", mbIWS, mbIWS );
1140 : mrExport.GetDocHandler()->characters( sInfo );
1141 : #endif
1142 0 : return true;
1143 0 : }
1144 : }
1145 :
1146 0 : return false;
1147 : }
1148 :
1149 0 : void SVGTextWriter::startTextShape()
1150 : {
1151 0 : if( mpTextShapeElem )
1152 : {
1153 : OSL_FAIL( "SVGTextWriter::startTextShape: text shape already defined." );
1154 : }
1155 :
1156 : {
1157 0 : mbIsTextShapeStarted = true;
1158 0 : maParentFont = vcl::Font();
1159 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "TextShape" );
1160 0 : mpTextShapeElem = new SvXMLElementExport( mrExport, XML_NAMESPACE_NONE, aXMLElemText, true, mbIWS );
1161 0 : startTextParagraph();
1162 : }
1163 0 : }
1164 :
1165 0 : void SVGTextWriter::endTextShape()
1166 : {
1167 0 : endTextParagraph();
1168 0 : if( mrTextShape.is() )
1169 0 : mrTextShape.clear();
1170 0 : if( mrParagraphEnumeration.is() )
1171 0 : mrParagraphEnumeration.clear();
1172 0 : if( mrCurrentTextParagraph.is() )
1173 0 : mrCurrentTextParagraph.clear();
1174 0 : if( mpTextShapeElem )
1175 : {
1176 0 : delete mpTextShapeElem;
1177 0 : mpTextShapeElem = NULL;
1178 : }
1179 0 : mbIsTextShapeStarted = false;
1180 : // these need to be invoked after the <text> element has been closed
1181 0 : implExportHyperlinkIds();
1182 0 : implWriteBulletChars();
1183 0 : implWriteEmbeddedBitmaps();
1184 :
1185 0 : }
1186 :
1187 0 : void SVGTextWriter::startTextParagraph()
1188 : {
1189 0 : endTextParagraph();
1190 0 : nextParagraph();
1191 0 : if( mbIsNewListItem )
1192 : {
1193 0 : OUString sNumberingType;
1194 0 : switch( meNumberingType )
1195 : {
1196 : case( NumberingType::CHAR_SPECIAL ):
1197 0 : sNumberingType = "bullet-style";
1198 0 : break;
1199 : case( NumberingType::BITMAP ):
1200 0 : sNumberingType = "image-style";
1201 0 : break;
1202 : default:
1203 0 : sNumberingType = "number-style";
1204 0 : break;
1205 : }
1206 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aOOOAttrNumberingType, sNumberingType );
1207 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "ListItem" );
1208 : }
1209 : else
1210 : {
1211 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "TextParagraph" );
1212 : }
1213 0 : maParentFont = vcl::Font();
1214 0 : addFontAttributes( /* isTexTContainer: */ true );
1215 0 : mpTextParagraphElem = new SvXMLElementExport( mrExport, XML_NAMESPACE_NONE, aXMLElemTspan, mbIWS, mbIWS );
1216 0 : if( !mbIsListLevelStyleImage )
1217 : {
1218 0 : startTextPosition();
1219 : }
1220 0 : }
1221 :
1222 0 : void SVGTextWriter::endTextParagraph()
1223 : {
1224 0 : mrCurrentTextPortion.clear();
1225 0 : endTextPosition();
1226 0 : mbIsNewListItem = false;
1227 0 : mbIsListLevelStyleImage = false;
1228 0 : mbPositioningNeeded = false;
1229 :
1230 0 : if( mpTextParagraphElem )
1231 : {
1232 0 : delete mpTextParagraphElem;
1233 0 : mpTextParagraphElem = NULL;
1234 : }
1235 :
1236 0 : }
1237 :
1238 0 : void SVGTextWriter::startTextPosition( bool bExportX, bool bExportY )
1239 : {
1240 0 : endTextPosition();
1241 0 : mnTextWidth = 0;
1242 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "TextPosition" );
1243 0 : if( bExportX )
1244 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX, OUString::number( maTextPos.X() ) );
1245 0 : if( bExportY )
1246 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY, OUString::number( maTextPos.Y() ) );
1247 :
1248 : // if text is rotated, set transform matrix at new tspan element
1249 0 : const vcl::Font& rFont = mpVDev->GetFont();
1250 0 : if( rFont.GetOrientation() )
1251 : {
1252 0 : Point aRot( maTextPos );
1253 : OUString aTransform =
1254 0 : OUString("translate(") + OUString::number( aRot.X() ) +
1255 0 : "," + OUString::number( aRot.Y() ) + ") rotate(" +
1256 0 : OUString::number( rFont.GetOrientation() * -0.1 ) +
1257 0 : ") translate(" + OUString::number( -aRot.X() ) +
1258 0 : "," + OUString::number( -aRot.Y() ) + ")";
1259 :
1260 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrTransform, aTransform );
1261 : }
1262 :
1263 0 : mpTextPositionElem = new SvXMLElementExport( mrExport, XML_NAMESPACE_NONE, aXMLElemTspan, mbIWS, mbIWS );
1264 0 : }
1265 :
1266 0 : void SVGTextWriter::endTextPosition()
1267 : {
1268 0 : if( mpTextPositionElem )
1269 : {
1270 0 : delete mpTextPositionElem;
1271 0 : mpTextPositionElem = NULL;
1272 : }
1273 0 : }
1274 :
1275 0 : void SVGTextWriter::implExportHyperlinkIds()
1276 : {
1277 0 : if( !msHyperlinkIdList.isEmpty() )
1278 : {
1279 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "HyperlinkIdList" );
1280 0 : SvXMLElementExport aDescElem( mrExport, XML_NAMESPACE_NONE, "desc", true, false );
1281 0 : mrExport.GetDocHandler()->characters( msHyperlinkIdList.trim() );
1282 0 : msHyperlinkIdList = "";
1283 : }
1284 0 : }
1285 :
1286 0 : void SVGTextWriter::implWriteBulletChars()
1287 : {
1288 0 : if( maBulletListItemMap.empty() )
1289 0 : return;
1290 :
1291 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "BulletChars" );
1292 0 : SvXMLElementExport aGroupElem( mrExport, XML_NAMESPACE_NONE, aXMLElemG, true, true );
1293 :
1294 0 : BulletListItemInfoMap::const_iterator it = maBulletListItemMap.begin();
1295 0 : BulletListItemInfoMap::const_iterator end = maBulletListItemMap.end();
1296 0 : OUString sId, sPosition, sScaling, sRefId;
1297 0 : for( ; it != end; ++it )
1298 : {
1299 : // <g id="?" > (used by animations)
1300 : {
1301 : // As id we use the id of the text portion placeholder wrapped
1302 : // by bullet-char(*)
1303 0 : sId = "bullet-char(" + it->first+ ")";
1304 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "id", sId );
1305 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "BulletChar" );
1306 0 : SvXMLElementExport aBulletCharElem( mrExport, XML_NAMESPACE_NONE, aXMLElemG, true, true );
1307 :
1308 : // <g transform="translate(x,y)" >
1309 : {
1310 0 : const BulletListItemInfo& rInfo = it->second;
1311 :
1312 : // Add positioning attribute through a translation
1313 0 : sPosition = "translate(" +
1314 0 : OUString::number( rInfo.aPos.X() ) +
1315 0 : "," + OUString::number( rInfo.aPos.Y() ) + ")";
1316 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "transform", sPosition );
1317 :
1318 0 : mpContext->AddPaintAttr( COL_TRANSPARENT, rInfo.aColor );
1319 :
1320 0 : SvXMLElementExport aPositioningElem( mrExport, XML_NAMESPACE_NONE, aXMLElemG, true, true );
1321 :
1322 : // <use transform="scale(font-size)" xlink:ref="/" >
1323 : {
1324 : // Add size attribute through a scaling
1325 0 : sScaling = "scale(" + OUString::number( rInfo.nFontSize ) +
1326 0 : "," + OUString::number( rInfo.nFontSize )+ ")";
1327 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "transform", sScaling );
1328 :
1329 : // Add ref attribute
1330 0 : sRefId = "#bullet-char-template(" +
1331 0 : OUString::number( ( rInfo.cBulletChar ) ) +
1332 0 : ")";
1333 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrXLinkHRef, sRefId );
1334 :
1335 0 : SvXMLElementExport aRefElem( mrExport, XML_NAMESPACE_NONE, "use", true, true );
1336 0 : }
1337 0 : } // close aPositioningElem
1338 : } // close aBulletCharElem
1339 : }
1340 :
1341 :
1342 : // clear the map
1343 0 : maBulletListItemMap.clear();
1344 : }
1345 :
1346 : template< typename MetaBitmapActionType >
1347 0 : void SVGTextWriter::writeBitmapPlaceholder( const MetaBitmapActionType* pAction )
1348 : {
1349 : // text position element
1350 0 : const Point& rPos = pAction->GetPoint();
1351 0 : implMap( rPos, maTextPos );
1352 0 : startTextPosition();
1353 0 : mbPositioningNeeded = true;
1354 0 : if( mbIsNewListItem )
1355 : {
1356 0 : mbIsNewListItem = false;
1357 0 : mbIsListLevelStyleImage = false;
1358 : }
1359 :
1360 : // bitmap placeholder element
1361 0 : sal_uLong nId = SVGActionWriter::GetChecksum( pAction );
1362 0 : OUString sId = "bitmap-placeholder(" + msShapeId + "." +
1363 0 : OUString::number( nId ) + ")";
1364 :
1365 : {
1366 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "id", sId );
1367 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "BitmapPlaceholder" );
1368 0 : SvXMLElementExport aSVGTspanElem( mrExport, XML_NAMESPACE_NONE, aXMLElemTspan, mbIWS, mbIWS );
1369 : }
1370 0 : endTextPosition();
1371 0 : }
1372 :
1373 0 : void SVGTextWriter::implWriteEmbeddedBitmaps()
1374 : {
1375 0 : if( mpTextEmbeddedBitmapMtf && mpTextEmbeddedBitmapMtf->GetActionSize() )
1376 : {
1377 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "EmbeddedBitmaps" );
1378 0 : SvXMLElementExport aEmbBitmapGroupElem( mrExport, XML_NAMESPACE_NONE, aXMLElemG, true, true );
1379 :
1380 0 : const GDIMetaFile& rMtf = *mpTextEmbeddedBitmapMtf;
1381 :
1382 0 : OUString sId, sRefId;
1383 0 : sal_uLong nId, nChecksum = 0;
1384 0 : Point aPt;
1385 0 : Size aSz;
1386 0 : sal_uLong nCount = rMtf.GetActionSize();
1387 0 : for( sal_uLong nCurAction = 0; nCurAction < nCount; nCurAction++ )
1388 : {
1389 :
1390 0 : const MetaAction* pAction = rMtf.GetAction( nCurAction );
1391 0 : const sal_uInt16 nType = pAction->GetType();
1392 :
1393 0 : switch( nType )
1394 : {
1395 : case( META_BMPSCALE_ACTION ):
1396 : {
1397 0 : const MetaBmpScaleAction* pA = static_cast<const MetaBmpScaleAction*>(pAction);
1398 0 : nChecksum = pA->GetBitmap().GetChecksum();
1399 0 : aPt = pA->GetPoint();
1400 0 : aSz = pA->GetSize();
1401 : }
1402 0 : break;
1403 : case( META_BMPEXSCALE_ACTION ):
1404 : {
1405 0 : const MetaBmpExScaleAction* pA = static_cast<const MetaBmpExScaleAction*>(pAction);
1406 0 : nChecksum = pA->GetBitmapEx().GetChecksum();
1407 0 : aPt = pA->GetPoint();
1408 0 : aSz = pA->GetSize();
1409 : }
1410 0 : break;
1411 : }
1412 :
1413 : // <g id="?" > (used by animations)
1414 : {
1415 : // embedded bitmap id
1416 0 : nId = SVGActionWriter::GetChecksum( pAction );
1417 0 : sId = "embedded-bitmap(";
1418 0 : sId += msShapeId;
1419 0 : sId += ".";
1420 0 : sId += OUString::number( nId );
1421 0 : sId += ")";
1422 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "id", sId );
1423 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "EmbeddedBitmap" );
1424 :
1425 0 : SvXMLElementExport aEmbBitmapElem( mrExport, XML_NAMESPACE_NONE, aXMLElemG, true, true );
1426 :
1427 : // <use x="?" y="?" xlink:ref="?" >
1428 : {
1429 : // referenced bitmap template
1430 0 : sRefId = "#bitmap(";
1431 0 : sRefId += OUString::number( nChecksum );
1432 0 : sRefId += ")";
1433 :
1434 0 : Point aPoint;
1435 0 : Size aSize;
1436 0 : implMap( aPt, aPoint );
1437 0 : implMap( aSz, aSize );
1438 :
1439 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX, OUString::number( aPoint.X() ) );
1440 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY, OUString::number( aPoint.Y() ) );
1441 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrXLinkHRef, sRefId );
1442 :
1443 0 : SvXMLElementExport aRefElem( mrExport, XML_NAMESPACE_NONE, "use", true, true );
1444 0 : }
1445 : } // close aEmbBitmapElem
1446 0 : }
1447 : }
1448 0 : }
1449 :
1450 0 : void SVGTextWriter::writeTextPortion( const Point& rPos,
1451 : const OUString& rText,
1452 : bool bApplyMapping )
1453 : {
1454 0 : if( rText.isEmpty() )
1455 0 : return;
1456 :
1457 0 : mbLineBreak = false;
1458 :
1459 0 : if( !mbIsNewListItem || mbIsListLevelStyleImage )
1460 : {
1461 0 : bool bNotSync = true;
1462 0 : OUString sContent;
1463 : sal_Int32 nStartPos;
1464 0 : while( bNotSync )
1465 : {
1466 0 : if( mnLeftTextPortionLength <= 0 || !mrCurrentTextPortion.is() )
1467 : {
1468 0 : if( !nextTextPortion() )
1469 0 : break;
1470 : else
1471 : {
1472 0 : sContent = mrCurrentTextPortion->getString();
1473 0 : if( mbIsURLField && sContent.isEmpty() )
1474 : {
1475 0 : Reference < XPropertySet > xPropSet( mrCurrentTextPortion, UNO_QUERY );
1476 0 : Reference < XTextField > xTextField( xPropSet->getPropertyValue( "TextField" ), UNO_QUERY );
1477 0 : sContent = xTextField->getPresentation( /* show command: */ sal_False );
1478 0 : if( sContent.isEmpty() )
1479 0 : OSL_FAIL( "SVGTextWriter::writeTextPortion: content of URL TextField is empty." );
1480 : }
1481 0 : mnLeftTextPortionLength = sContent.getLength();
1482 : }
1483 : }
1484 : else
1485 : {
1486 0 : sContent = mrCurrentTextPortion->getString();
1487 : }
1488 :
1489 0 : nStartPos = sContent.getLength() - mnLeftTextPortionLength;
1490 0 : if( nStartPos < 0 ) nStartPos = 0;
1491 0 : mnLeftTextPortionLength -= rText.getLength();
1492 :
1493 0 : if( sContent.isEmpty() )
1494 0 : continue;
1495 0 : if( sContent.equalsAscii( "\n" ) )
1496 0 : mbLineBreak = true;
1497 0 : if( sContent.match( rText, nStartPos ) )
1498 0 : bNotSync = false;
1499 0 : }
1500 : }
1501 :
1502 : assert(mpVDev); //invalid virtual device
1503 :
1504 : #if 0
1505 : const FontMetric aMetric( mpVDev->GetFontMetric() );
1506 :
1507 : bool bTextSpecial = aMetric.IsShadow() || aMetric.IsOutline() || (aMetric.GetRelief() != RELIEF_NONE);
1508 :
1509 : if( true || !bTextSpecial )
1510 : {
1511 : implWriteTextPortion( rPos, rText, mpVDev->GetTextColor(), bApplyMapping );
1512 : }
1513 : else
1514 : {
1515 : // to be implemented
1516 : }
1517 : #else
1518 0 : implWriteTextPortion( rPos, rText, mpVDev->GetTextColor(), bApplyMapping );
1519 : #endif
1520 :
1521 : }
1522 :
1523 0 : void SVGTextWriter::implWriteTextPortion( const Point& rPos,
1524 : const OUString& rText,
1525 : Color aTextColor,
1526 : bool bApplyMapping )
1527 : {
1528 0 : Point aPos;
1529 0 : Point aBaseLinePos( rPos );
1530 0 : const FontMetric aMetric( mpVDev->GetFontMetric() );
1531 0 : const vcl::Font& rFont = mpVDev->GetFont();
1532 :
1533 0 : if( rFont.GetAlign() == ALIGN_TOP )
1534 0 : aBaseLinePos.Y() += aMetric.GetAscent();
1535 0 : else if( rFont.GetAlign() == ALIGN_BOTTOM )
1536 0 : aBaseLinePos.Y() -= aMetric.GetDescent();
1537 :
1538 0 : if( bApplyMapping )
1539 0 : implMap( rPos, aPos );
1540 : else
1541 0 : aPos = rPos;
1542 :
1543 0 : if( mbPositioningNeeded )
1544 : {
1545 0 : mbPositioningNeeded = false;
1546 0 : maTextPos.setX( aPos.X() );
1547 0 : maTextPos.setY( aPos.Y() );
1548 0 : startTextPosition();
1549 : }
1550 0 : else if( maTextPos.Y() != aPos.Y() )
1551 : {
1552 : // In case the text position moved backward we could have a line break
1553 : // so we end the current line and start a new one.
1554 0 : if( mbLineBreak || ( ( maTextPos.X() + mnTextWidth ) > aPos.X() ) )
1555 : {
1556 0 : mbLineBreak = false;
1557 0 : maTextPos.setX( aPos.X() );
1558 0 : maTextPos.setY( aPos.Y() );
1559 0 : startTextPosition();
1560 : }
1561 : else // superscript, subscript, list item numbering
1562 : {
1563 0 : maTextPos.setY( aPos.Y() );
1564 0 : startTextPosition( false /* do not export x attribute */ );
1565 : }
1566 : }
1567 : // we are dealing with a bullet, so set up this for the next text portion
1568 0 : if( mbIsNewListItem )
1569 : {
1570 0 : mbIsNewListItem = false;
1571 0 : mbPositioningNeeded = true;
1572 :
1573 0 : if( meNumberingType == NumberingType::CHAR_SPECIAL )
1574 : {
1575 : // Create an id for the current text portion
1576 0 : implRegisterInterface( mrCurrentTextParagraph );
1577 :
1578 : // Add the needed info to the BulletListItemMap
1579 0 : OUString sId = implGetValidIDFromInterface( Reference<XInterface>(mrCurrentTextParagraph, UNO_QUERY) );
1580 0 : if( !sId.isEmpty() )
1581 : {
1582 0 : sId += ".bp";
1583 0 : BulletListItemInfo& aBulletListItemInfo = maBulletListItemMap[ sId ];
1584 0 : aBulletListItemInfo.nFontSize = rFont.GetHeight();
1585 0 : aBulletListItemInfo.aColor = aTextColor;
1586 0 : aBulletListItemInfo.aPos = maTextPos;
1587 0 : aBulletListItemInfo.cBulletChar = mcBulletChar;
1588 :
1589 : // Make this text portion a bullet placeholder
1590 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "id", sId );
1591 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "BulletPlaceholder" );
1592 0 : SvXMLElementExport aSVGTspanElem( mrExport, XML_NAMESPACE_NONE, aXMLElemTspan, mbIWS, mbIWS );
1593 0 : return;
1594 0 : }
1595 : }
1596 : }
1597 :
1598 0 : const OUString& rTextPortionId = implGetValidIDFromInterface( Reference<XInterface>(mrCurrentTextPortion, UNO_QUERY) );
1599 0 : if( !rTextPortionId.isEmpty() )
1600 : {
1601 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "id", rTextPortionId );
1602 : }
1603 :
1604 0 : if( mbIsPlacehlolderShape )
1605 : {
1606 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "PlaceholderText" );
1607 0 : mbIsPlacehlolderShape = false;
1608 : }
1609 :
1610 0 : addFontAttributes( /* isTexTContainer: */ false );
1611 : assert(mpContext); //invalid context object
1612 :
1613 0 : mpContext->AddPaintAttr( COL_TRANSPARENT, aTextColor );
1614 :
1615 0 : OUString sTextContent = rText;
1616 :
1617 : // <a> tag for link should be the innermost tag, inside <tspan>
1618 0 : if( !mbIsPlacehlolderShape && mbIsURLField && !msUrl.isEmpty() )
1619 : {
1620 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "UrlField" );
1621 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrXLinkHRef, msUrl );
1622 :
1623 0 : SvXMLElementExport aSVGTspanElem( mrExport, XML_NAMESPACE_NONE, aXMLElemTspan, mbIWS, mbIWS );
1624 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrXLinkHRef, msUrl );
1625 : {
1626 0 : SvXMLElementExport aSVGAElem( mrExport, XML_NAMESPACE_NONE, aXMLElemA, mbIWS, mbIWS );
1627 0 : mrExport.GetDocHandler()->characters( sTextContent );
1628 0 : }
1629 : }
1630 : else
1631 : {
1632 0 : SvXMLElementExport aSVGTspanElem( mrExport, XML_NAMESPACE_NONE, aXMLElemTspan, mbIWS, mbIWS );
1633 0 : mrExport.GetDocHandler()->characters( sTextContent );
1634 : }
1635 :
1636 0 : mnTextWidth += mpVDev->GetTextWidth( sTextContent );
1637 : }
1638 :
1639 0 : SVGActionWriter::SVGActionWriter( SVGExport& rExport, SVGFontExport& rFontExport ) :
1640 : mnCurGradientId( 1 ),
1641 : mnCurMaskId( 1 ),
1642 : mnCurPatternId( 1 ),
1643 : mrExport( rExport ),
1644 : mrFontExport( rFontExport ),
1645 : mpContext( NULL ),
1646 : maTextWriter( rExport ),
1647 : mnInnerMtfCount( 0 ),
1648 : mbClipAttrChanged( false ),
1649 0 : mbIsPlacehlolderShape( false )
1650 : {
1651 0 : mpVDev = new VirtualDevice;
1652 0 : mpVDev->EnableOutput( false );
1653 0 : maTargetMapMode = MAP_100TH_MM;
1654 0 : maTextWriter.setVirtualDevice( mpVDev, maTargetMapMode );
1655 0 : }
1656 :
1657 0 : SVGActionWriter::~SVGActionWriter()
1658 : {
1659 : DBG_ASSERT( !mpContext, "Not all contexts are closed" );
1660 0 : delete mpVDev;
1661 0 : }
1662 :
1663 0 : long SVGActionWriter::ImplMap( sal_Int32 nVal ) const
1664 : {
1665 0 : Size aSz( nVal, nVal );
1666 :
1667 0 : return( ImplMap( aSz, aSz ).Width() );
1668 : }
1669 :
1670 0 : Point& SVGActionWriter::ImplMap( const Point& rPt, Point& rDstPt ) const
1671 : {
1672 0 : return( rDstPt = OutputDevice::LogicToLogic( rPt, mpVDev->GetMapMode(), maTargetMapMode ) );
1673 : }
1674 :
1675 0 : Size& SVGActionWriter::ImplMap( const Size& rSz, Size& rDstSz ) const
1676 : {
1677 0 : return( rDstSz = OutputDevice::LogicToLogic( rSz, mpVDev->GetMapMode(), maTargetMapMode ) );
1678 : }
1679 :
1680 0 : Rectangle& SVGActionWriter::ImplMap( const Rectangle& rRect, Rectangle& rDstRect ) const
1681 : {
1682 0 : Point aTL( rRect.TopLeft() );
1683 0 : Size aSz( rRect.GetSize() );
1684 :
1685 0 : return( rDstRect = Rectangle( ImplMap( aTL, aTL ), ImplMap( aSz, aSz ) ) );
1686 : }
1687 :
1688 0 : Polygon& SVGActionWriter::ImplMap( const Polygon& rPoly, Polygon& rDstPoly ) const
1689 : {
1690 0 : rDstPoly = Polygon( rPoly.GetSize() );
1691 :
1692 0 : for( sal_uInt16 i = 0, nSize = rPoly.GetSize(); i < nSize; ++i )
1693 : {
1694 0 : ImplMap( rPoly[ i ], rDstPoly[ i ] );
1695 0 : rDstPoly.SetFlags( i, rPoly.GetFlags( i ) );
1696 : }
1697 :
1698 0 : return( rDstPoly );
1699 : }
1700 :
1701 0 : tools::PolyPolygon& SVGActionWriter::ImplMap( const tools::PolyPolygon& rPolyPoly, tools::PolyPolygon& rDstPolyPoly ) const
1702 : {
1703 0 : Polygon aPoly;
1704 :
1705 0 : rDstPolyPoly = tools::PolyPolygon();
1706 :
1707 0 : for( sal_uInt16 i = 0, nCount = rPolyPoly.Count(); i < nCount; ++i )
1708 : {
1709 0 : rDstPolyPoly.Insert( ImplMap( rPolyPoly[ i ], aPoly ) );
1710 : }
1711 :
1712 0 : return( rDstPolyPoly );
1713 : }
1714 :
1715 0 : OUString SVGActionWriter::GetPathString( const tools::PolyPolygon& rPolyPoly, bool bLine )
1716 : {
1717 0 : OUString aPathData;
1718 0 : const OUString aBlank( " " );
1719 0 : const OUString aComma( "," );
1720 0 : Point aPolyPoint;
1721 :
1722 0 : for( long i = 0, nCount = rPolyPoly.Count(); i < nCount; i++ )
1723 : {
1724 0 : const Polygon& rPoly = rPolyPoly[ (sal_uInt16) i ];
1725 0 : sal_uInt16 n = 1, nSize = rPoly.GetSize();
1726 :
1727 0 : if( nSize > 1 )
1728 : {
1729 0 : aPathData += "M ";
1730 0 : aPathData += OUString::number( ( aPolyPoint = rPoly[ 0 ] ).X() );
1731 0 : aPathData += aComma;
1732 0 : aPathData += OUString::number( aPolyPoint.Y() );
1733 :
1734 0 : sal_Char nCurrentMode = 0;
1735 0 : const bool bClose(!bLine || rPoly[0] == rPoly[nSize - 1]);
1736 0 : while( n < nSize )
1737 : {
1738 0 : aPathData += aBlank;
1739 :
1740 0 : if ( ( rPoly.GetFlags( n ) == POLY_CONTROL ) && ( ( n + 2 ) < nSize ) )
1741 : {
1742 0 : if ( nCurrentMode != 'C' )
1743 : {
1744 0 : nCurrentMode = 'C';
1745 0 : aPathData += "C ";
1746 : }
1747 0 : for ( int j = 0; j < 3; j++ )
1748 : {
1749 0 : if ( j )
1750 0 : aPathData += aBlank;
1751 0 : aPathData += OUString::number( ( aPolyPoint = rPoly[ n++ ] ).X() );
1752 0 : aPathData += aComma;
1753 0 : aPathData += OUString::number( aPolyPoint.Y() );
1754 : }
1755 : }
1756 : else
1757 : {
1758 0 : if ( nCurrentMode != 'L' )
1759 : {
1760 0 : nCurrentMode = 'L';
1761 0 : aPathData += "L ";
1762 : }
1763 0 : aPathData += OUString::number( ( aPolyPoint = rPoly[ n++ ] ).X() );
1764 0 : aPathData += aComma;
1765 0 : aPathData += OUString::number( aPolyPoint.Y() );
1766 : }
1767 : }
1768 :
1769 0 : if(bClose)
1770 0 : aPathData += " Z";
1771 :
1772 0 : if( i < ( nCount - 1 ) )
1773 0 : aPathData += aBlank;
1774 : }
1775 : }
1776 :
1777 0 : return aPathData;
1778 : }
1779 :
1780 0 : sal_uLong SVGActionWriter::GetChecksum( const MetaAction* pAction )
1781 : {
1782 0 : GDIMetaFile aMtf;
1783 0 : MetaAction* pA = (MetaAction*)pAction;
1784 0 : pA->Duplicate();
1785 0 : aMtf.AddAction( pA );
1786 0 : return aMtf.GetChecksum();
1787 : }
1788 :
1789 0 : void SVGActionWriter::ImplWriteLine( const Point& rPt1, const Point& rPt2,
1790 : const Color* pLineColor, bool bApplyMapping )
1791 : {
1792 0 : Point aPt1, aPt2;
1793 :
1794 0 : if( bApplyMapping )
1795 : {
1796 0 : ImplMap( rPt1, aPt1 );
1797 0 : ImplMap( rPt2, aPt2 );
1798 : }
1799 : else
1800 : {
1801 0 : aPt1 = rPt1;
1802 0 : aPt2 = rPt2;
1803 : }
1804 :
1805 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX1, OUString::number( aPt1.X() ) );
1806 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY1, OUString::number( aPt1.Y() ) );
1807 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX2, OUString::number( aPt2.X() ) );
1808 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY2, OUString::number( aPt2.Y() ) );
1809 :
1810 : if( pLineColor )
1811 : {
1812 : // !!! mrExport.AddAttribute( XML_NAMESPACE_NONE, ... )
1813 : OSL_FAIL( "SVGActionWriter::ImplWriteLine: Line color not implemented" );
1814 : }
1815 :
1816 : {
1817 0 : SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemLine, true, true );
1818 : }
1819 0 : }
1820 :
1821 0 : void SVGActionWriter::ImplWriteRect( const Rectangle& rRect, long nRadX, long nRadY,
1822 : bool bApplyMapping )
1823 : {
1824 0 : Rectangle aRect;
1825 :
1826 0 : if( bApplyMapping )
1827 0 : ImplMap( rRect, aRect );
1828 : else
1829 0 : aRect = rRect;
1830 :
1831 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX, OUString::number( aRect.Left() ) );
1832 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY, OUString::number( aRect.Top() ) );
1833 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrWidth, OUString::number( aRect.GetWidth() ) );
1834 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrHeight, OUString::number( aRect.GetHeight() ) );
1835 :
1836 0 : if( nRadX )
1837 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrRX, OUString::number( bApplyMapping ? ImplMap( nRadX ) : nRadX ) );
1838 :
1839 0 : if( nRadY )
1840 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrRY, OUString::number( bApplyMapping ? ImplMap( nRadY ) : nRadY ) );
1841 :
1842 : {
1843 0 : SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemRect, true, true );
1844 : }
1845 0 : }
1846 :
1847 0 : void SVGActionWriter::ImplWriteEllipse( const Point& rCenter, long nRadX, long nRadY,
1848 : bool bApplyMapping )
1849 : {
1850 0 : Point aCenter;
1851 :
1852 0 : if( bApplyMapping )
1853 0 : ImplMap( rCenter, aCenter );
1854 : else
1855 0 : aCenter = rCenter;
1856 :
1857 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrCX, OUString::number( aCenter.X() ) );
1858 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrCY, OUString::number( aCenter.Y() ) );
1859 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrRX, OUString::number( bApplyMapping ? ImplMap( nRadX ) : nRadX ) );
1860 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrRY, OUString::number( bApplyMapping ? ImplMap( nRadY ) : nRadY ) );
1861 :
1862 : {
1863 0 : SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemEllipse, true, true );
1864 : }
1865 0 : }
1866 :
1867 0 : void SVGActionWriter::ImplAddLineAttr( const LineInfo &rAttrs,
1868 : bool bApplyMapping )
1869 : {
1870 0 : if ( !rAttrs.IsDefault() )
1871 : {
1872 0 : sal_Int32 nStrokeWidth = bApplyMapping ? ImplMap( rAttrs.GetWidth() ) : rAttrs.GetWidth();
1873 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStrokeWidth,
1874 0 : OUString::number( nStrokeWidth ) );
1875 : // support for LineJoint
1876 0 : switch(rAttrs.GetLineJoin())
1877 : {
1878 : default: // B2DLINEJOIN_NONE, B2DLINEJOIN_MIDDLE
1879 : case basegfx::B2DLINEJOIN_MITER:
1880 : {
1881 0 : mrExport.AddAttribute(XML_NAMESPACE_NONE, aXMLAttrStrokeLinejoin, "miter");
1882 0 : break;
1883 : }
1884 : case basegfx::B2DLINEJOIN_BEVEL:
1885 : {
1886 0 : mrExport.AddAttribute(XML_NAMESPACE_NONE, aXMLAttrStrokeLinejoin, "bevel");
1887 0 : break;
1888 : }
1889 : case basegfx::B2DLINEJOIN_ROUND:
1890 : {
1891 0 : mrExport.AddAttribute(XML_NAMESPACE_NONE, aXMLAttrStrokeLinejoin, "round");
1892 0 : break;
1893 : }
1894 : }
1895 :
1896 : // support for LineCap
1897 0 : switch(rAttrs.GetLineCap())
1898 : {
1899 : default: /* com::sun::star::drawing::LineCap_BUTT */
1900 : {
1901 : // butt is Svg default, so no need to write until the exporter might write styles.
1902 : // If this happens, activate here
1903 : // mrExport.AddAttribute(XML_NAMESPACE_NONE, aXMLAttrStrokeLinecap, "butt");
1904 0 : break;
1905 : }
1906 : case com::sun::star::drawing::LineCap_ROUND:
1907 : {
1908 0 : mrExport.AddAttribute(XML_NAMESPACE_NONE, aXMLAttrStrokeLinecap, "round");
1909 0 : break;
1910 : }
1911 : case com::sun::star::drawing::LineCap_SQUARE:
1912 : {
1913 0 : mrExport.AddAttribute(XML_NAMESPACE_NONE, aXMLAttrStrokeLinecap, "square");
1914 0 : break;
1915 : }
1916 : }
1917 :
1918 : }
1919 :
1920 0 : }
1921 :
1922 0 : void SVGActionWriter::ImplWritePolyPolygon( const tools::PolyPolygon& rPolyPoly, bool bLineOnly,
1923 : bool bApplyMapping )
1924 : {
1925 0 : tools::PolyPolygon aPolyPoly;
1926 :
1927 0 : if( bApplyMapping )
1928 0 : ImplMap( rPolyPoly, aPolyPoly );
1929 : else
1930 0 : aPolyPoly = rPolyPoly;
1931 :
1932 : // add path data attribute
1933 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrD, GetPathString( aPolyPoly, bLineOnly ) );
1934 :
1935 : {
1936 : // write polyline/polygon element
1937 0 : SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemPath, true, true );
1938 0 : }
1939 0 : }
1940 :
1941 0 : void SVGActionWriter::ImplWriteShape( const SVGShapeDescriptor& rShape, bool bApplyMapping )
1942 : {
1943 0 : tools::PolyPolygon aPolyPoly;
1944 :
1945 0 : if( bApplyMapping )
1946 0 : ImplMap( rShape.maShapePolyPoly, aPolyPoly );
1947 : else
1948 0 : aPolyPoly = rShape.maShapePolyPoly;
1949 :
1950 0 : const bool bLineOnly = ( rShape.maShapeFillColor == Color( COL_TRANSPARENT ) ) && ( !rShape.mapShapeGradient.get() );
1951 0 : Rectangle aBoundRect( aPolyPoly.GetBoundRect() );
1952 :
1953 0 : mpContext->AddPaintAttr( rShape.maShapeLineColor, rShape.maShapeFillColor, &aBoundRect, rShape.mapShapeGradient.get() );
1954 :
1955 0 : if( !rShape.maId.isEmpty() )
1956 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrId, rShape.maId );
1957 :
1958 0 : if( rShape.mnStrokeWidth )
1959 : {
1960 0 : sal_Int32 nStrokeWidth = ( bApplyMapping ? ImplMap( rShape.mnStrokeWidth ) : rShape.mnStrokeWidth );
1961 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStrokeWidth, OUString::number( nStrokeWidth ) );
1962 : }
1963 :
1964 : // support for LineJoin
1965 0 : switch(rShape.maLineJoin)
1966 : {
1967 : default: // B2DLINEJOIN_NONE, B2DLINEJOIN_MIDDLE
1968 : case basegfx::B2DLINEJOIN_MITER:
1969 : {
1970 : // miter is Svg default, so no need to write until the exporter might write styles.
1971 : // If this happens, activate here
1972 : // mrExport.AddAttribute(XML_NAMESPACE_NONE, aXMLAttrStrokeLinejoin, "miter");
1973 0 : break;
1974 : }
1975 : case basegfx::B2DLINEJOIN_BEVEL:
1976 : {
1977 0 : mrExport.AddAttribute(XML_NAMESPACE_NONE, aXMLAttrStrokeLinejoin, "bevel");
1978 0 : break;
1979 : }
1980 : case basegfx::B2DLINEJOIN_ROUND:
1981 : {
1982 0 : mrExport.AddAttribute(XML_NAMESPACE_NONE, aXMLAttrStrokeLinejoin, "round");
1983 0 : break;
1984 : }
1985 : }
1986 :
1987 : // support for LineCap
1988 0 : switch(rShape.maLineCap)
1989 : {
1990 : default: /* com::sun::star::drawing::LineCap_BUTT */
1991 : {
1992 : // butt is Svg default, so no need to write until the exporter might write styles.
1993 : // If this happens, activate here
1994 : // mrExport.AddAttribute(XML_NAMESPACE_NONE, aXMLAttrStrokeLinecap, "butt");
1995 0 : break;
1996 : }
1997 : case com::sun::star::drawing::LineCap_ROUND:
1998 : {
1999 0 : mrExport.AddAttribute(XML_NAMESPACE_NONE, aXMLAttrStrokeLinecap, "round");
2000 0 : break;
2001 : }
2002 : case com::sun::star::drawing::LineCap_SQUARE:
2003 : {
2004 0 : mrExport.AddAttribute(XML_NAMESPACE_NONE, aXMLAttrStrokeLinecap, "square");
2005 0 : break;
2006 : }
2007 : }
2008 :
2009 0 : if( rShape.maDashArray.size() )
2010 : {
2011 0 : const OUString aComma( "," );
2012 0 : OUString aDashArrayStr;
2013 :
2014 0 : for( unsigned int k = 0; k < rShape.maDashArray.size(); ++k )
2015 : {
2016 : const sal_Int32 nDash = ( bApplyMapping ?
2017 0 : ImplMap( FRound( rShape.maDashArray[ k ] ) ) :
2018 0 : FRound( rShape.maDashArray[ k ] ) );
2019 :
2020 0 : if( k )
2021 0 : aDashArrayStr += aComma;
2022 :
2023 0 : aDashArrayStr += OUString::number( nDash );
2024 : }
2025 :
2026 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStrokeDashArray, aDashArrayStr );
2027 : }
2028 :
2029 0 : ImplWritePolyPolygon( aPolyPoly, bLineOnly, false );
2030 0 : }
2031 :
2032 0 : void SVGActionWriter::ImplWritePattern( const tools::PolyPolygon& rPolyPoly,
2033 : const Hatch* pHatch,
2034 : const Gradient* pGradient,
2035 : sal_uInt32 nWriteFlags )
2036 : {
2037 0 : if( rPolyPoly.Count() )
2038 : {
2039 0 : SvXMLElementExport aElemG( mrExport, XML_NAMESPACE_NONE, aXMLElemG, true, true );
2040 :
2041 0 : OUString aPatternId = "pattern" + OUString::number( mnCurPatternId++ );
2042 :
2043 : {
2044 0 : SvXMLElementExport aElemDefs( mrExport, XML_NAMESPACE_NONE, aXMLElemDefs, true, true );
2045 :
2046 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrId, aPatternId );
2047 :
2048 0 : Rectangle aRect;
2049 0 : ImplMap( rPolyPoly.GetBoundRect(), aRect );
2050 :
2051 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX, OUString::number( aRect.Left() ) );
2052 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY, OUString::number( aRect.Top() ) );
2053 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrWidth, OUString::number( aRect.GetWidth() ) );
2054 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrHeight, OUString::number( aRect.GetHeight() ) );
2055 :
2056 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrPatternUnits, OUString( "userSpaceOnUse") );
2057 :
2058 : {
2059 0 : SvXMLElementExport aElemPattern( mrExport, XML_NAMESPACE_NONE, aXMLElemPattern, true, true );
2060 :
2061 : // The origin of a pattern is positioned at (aRect.Left(), aRect.Top()).
2062 : // So we need to adjust the pattern coordinate.
2063 0 : OUString aTransform = "translate(" +
2064 0 : OUString::number( -aRect.Left() ) +
2065 0 : "," + OUString::number( -aRect.Top() ) +
2066 0 : ")";
2067 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrTransform, aTransform );
2068 :
2069 : {
2070 0 : SvXMLElementExport aElemG2( mrExport, XML_NAMESPACE_NONE, aXMLElemG, true, true );
2071 :
2072 0 : GDIMetaFile aTmpMtf;
2073 0 : if( pHatch )
2074 0 : mpVDev->AddHatchActions( rPolyPoly, *pHatch, aTmpMtf );
2075 0 : else if ( pGradient )
2076 0 : mpVDev->AddGradientActions( rPolyPoly.GetBoundRect(), *pGradient, aTmpMtf );
2077 0 : ImplWriteActions( aTmpMtf, nWriteFlags, NULL );
2078 0 : }
2079 0 : }
2080 : }
2081 :
2082 0 : OUString aPatternStyle = "fill:url(#" + aPatternId + ")";
2083 :
2084 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStyle, aPatternStyle );
2085 0 : ImplWritePolyPolygon( rPolyPoly, false );
2086 : }
2087 0 : }
2088 :
2089 0 : void SVGActionWriter::ImplWriteGradientEx( const tools::PolyPolygon& rPolyPoly, const Gradient& rGradient,
2090 : sal_uInt32 nWriteFlags)
2091 : {
2092 0 : if ( rGradient.GetStyle() == GradientStyle_LINEAR ||
2093 0 : rGradient.GetStyle() == GradientStyle_AXIAL )
2094 : {
2095 0 : ImplWriteGradientLinear( rPolyPoly, rGradient );
2096 : }
2097 : else
2098 : {
2099 0 : ImplWritePattern( rPolyPoly, NULL, &rGradient, nWriteFlags );
2100 : }
2101 0 : }
2102 :
2103 0 : void SVGActionWriter::ImplWriteGradientLinear( const tools::PolyPolygon& rPolyPoly,
2104 : const Gradient& rGradient )
2105 : {
2106 0 : if( rPolyPoly.Count() )
2107 : {
2108 0 : SvXMLElementExport aElemG( mrExport, XML_NAMESPACE_NONE, aXMLElemG, true, true );
2109 :
2110 0 : OUString aGradientId = "gradient" + OUString::number( mnCurGradientId++ );
2111 :
2112 : {
2113 0 : SvXMLElementExport aElemDefs( mrExport, XML_NAMESPACE_NONE, aXMLElemDefs, true, true );
2114 :
2115 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrId, aGradientId );
2116 : {
2117 0 : Rectangle aTmpRect, aRect;
2118 0 : Point aTmpCenter, aCenter;
2119 :
2120 0 : rGradient.GetBoundRect( rPolyPoly.GetBoundRect(), aTmpRect, aTmpCenter );
2121 0 : ImplMap( aTmpRect, aRect );
2122 0 : ImplMap( aTmpCenter, aCenter );
2123 0 : const sal_uInt16 nAngle = rGradient.GetAngle() % 3600;
2124 :
2125 0 : Polygon aPoly( 2 );
2126 : // Setting x value of a gradient vector to rotation center to
2127 : // place a gradient vector in a target polygon.
2128 : // This would help editing it in SVG editors like inkscape.
2129 0 : aPoly[ 0 ].X() = aPoly[ 1 ].X() = aCenter.X();
2130 0 : aPoly[ 0 ].Y() = aRect.Top();
2131 0 : aPoly[ 1 ].Y() = aRect.Bottom();
2132 0 : aPoly.Rotate( aCenter, nAngle );
2133 :
2134 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX1, OUString::number( aPoly[ 0 ].X() ) );
2135 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY1, OUString::number( aPoly[ 0 ].Y() ) );
2136 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX2, OUString::number( aPoly[ 1 ].X() ) );
2137 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY2, OUString::number( aPoly[ 1 ].Y() ) );
2138 :
2139 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrGradientUnits,
2140 0 : OUString( "userSpaceOnUse" ) );
2141 : }
2142 :
2143 : {
2144 0 : SvXMLElementExport aElemLinearGradient( mrExport, XML_NAMESPACE_NONE, aXMLElemLinearGradient, true, true );
2145 :
2146 0 : const Color aStartColor = ImplGetColorWithIntensity( rGradient.GetStartColor(), rGradient.GetStartIntensity() );
2147 0 : const Color aEndColor = ImplGetColorWithIntensity( rGradient.GetEndColor(), rGradient.GetEndIntensity() );
2148 0 : double fBorderOffset = rGradient.GetBorder() / 100.0;
2149 0 : const sal_uInt16 nSteps = rGradient.GetSteps();
2150 0 : if( rGradient.GetStyle() == GradientStyle_LINEAR )
2151 : {
2152 : // Emulate non-smooth gradient
2153 0 : if( 0 < nSteps && nSteps < 100 )
2154 : {
2155 0 : double fOffsetStep = ( 1.0 - fBorderOffset ) / (double)nSteps;
2156 0 : for( sal_uInt16 i = 0; i < nSteps; i++ ) {
2157 0 : Color aColor = ImplGetGradientColor( aStartColor, aEndColor, i / (double) nSteps );
2158 0 : ImplWriteGradientStop( aColor, fBorderOffset + ( i + 1 ) * fOffsetStep );
2159 0 : aColor = ImplGetGradientColor( aStartColor, aEndColor, ( i + 1 ) / (double) nSteps );
2160 0 : ImplWriteGradientStop( aColor, fBorderOffset + ( i + 1 ) * fOffsetStep );
2161 0 : }
2162 : }
2163 : else
2164 : {
2165 0 : ImplWriteGradientStop( aStartColor, fBorderOffset );
2166 0 : ImplWriteGradientStop( aEndColor, 1.0 );
2167 : }
2168 : }
2169 : else
2170 : {
2171 0 : fBorderOffset /= 2;
2172 : // Emulate non-smooth gradient
2173 0 : if( 0 < nSteps && nSteps < 100 )
2174 : {
2175 0 : double fOffsetStep = ( 0.5 - fBorderOffset ) / (double)nSteps;
2176 : // Upper half
2177 0 : for( sal_uInt16 i = 0; i < nSteps; i++ )
2178 : {
2179 0 : Color aColor = ImplGetGradientColor( aEndColor, aStartColor, i / (double) nSteps );
2180 0 : ImplWriteGradientStop( aColor, fBorderOffset + i * fOffsetStep );
2181 0 : aColor = ImplGetGradientColor( aEndColor, aStartColor, (i + 1 ) / (double) nSteps );
2182 0 : ImplWriteGradientStop( aColor, fBorderOffset + i * fOffsetStep );
2183 : }
2184 : // Lower half
2185 0 : for( sal_uInt16 i = 0; i < nSteps; i++ )
2186 : {
2187 0 : Color aColor = ImplGetGradientColor( aStartColor, aEndColor, i / (double) nSteps );
2188 0 : ImplWriteGradientStop( aColor, 0.5 + (i + 1) * fOffsetStep );
2189 0 : aColor = ImplGetGradientColor( aStartColor, aEndColor, (i + 1 ) / (double) nSteps );
2190 0 : ImplWriteGradientStop( aColor, 0.5 + (i + 1) * fOffsetStep );
2191 0 : }
2192 : }
2193 : else
2194 : {
2195 0 : ImplWriteGradientStop( aEndColor, fBorderOffset );
2196 0 : ImplWriteGradientStop( aStartColor, 0.5 );
2197 0 : ImplWriteGradientStop( aEndColor, 1.0 - fBorderOffset );
2198 : }
2199 0 : }
2200 0 : }
2201 : }
2202 :
2203 0 : OUString aGradientStyle = "fill:url(#" + aGradientId + ")";
2204 :
2205 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStyle, aGradientStyle );
2206 0 : ImplWritePolyPolygon( rPolyPoly, false );
2207 : }
2208 0 : }
2209 :
2210 0 : void SVGActionWriter::ImplWriteGradientStop( const Color& rColor, double fOffset )
2211 : {
2212 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrOffset, OUString::number( fOffset ) );
2213 :
2214 0 : OUString aStyle, aColor;
2215 0 : aStyle += "stop-color:";
2216 0 : SVGAttributeWriter::ImplGetColorStr ( rColor, aColor );
2217 0 : aStyle += aColor;
2218 :
2219 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStyle, aStyle );
2220 : {
2221 0 : SvXMLElementExport aElemStartStop( mrExport, XML_NAMESPACE_NONE, aXMLElemStop, true, true );
2222 0 : }
2223 0 : }
2224 :
2225 0 : Color SVGActionWriter::ImplGetColorWithIntensity( const Color& rColor,
2226 : sal_uInt16 nIntensity )
2227 : {
2228 0 : sal_uInt8 nNewRed = (sal_uInt8)( (long)rColor.GetRed() * nIntensity / 100L );
2229 0 : sal_uInt8 nNewGreen = (sal_uInt8)( (long)rColor.GetGreen() * nIntensity / 100L );
2230 0 : sal_uInt8 nNewBlue = (sal_uInt8)( (long)rColor.GetBlue() * nIntensity / 100L );
2231 0 : return Color( nNewRed, nNewGreen, nNewBlue);
2232 : }
2233 :
2234 0 : Color SVGActionWriter::ImplGetGradientColor( const Color& rStartColor,
2235 : const Color& rEndColor,
2236 : double fOffset )
2237 : {
2238 0 : long nRedStep = rEndColor.GetRed() - rStartColor.GetRed();
2239 0 : long nNewRed = rStartColor.GetRed() + (long)( nRedStep * fOffset );
2240 0 : nNewRed = ( nNewRed < 0 ) ? 0 : ( nNewRed > 0xFF) ? 0xFF : nNewRed;
2241 :
2242 0 : long nGreenStep = rEndColor.GetGreen() - rStartColor.GetGreen();
2243 0 : long nNewGreen = rStartColor.GetGreen() + (long)( nGreenStep * fOffset );
2244 0 : nNewGreen = ( nNewGreen < 0 ) ? 0 : ( nNewGreen > 0xFF) ? 0xFF : nNewGreen;
2245 :
2246 0 : long nBlueStep = rEndColor.GetBlue() - rStartColor.GetBlue();
2247 0 : long nNewBlue = rStartColor.GetBlue() + (long)( nBlueStep * fOffset );
2248 0 : nNewBlue = ( nNewBlue < 0 ) ? 0 : ( nNewBlue > 0xFF) ? 0xFF : nNewBlue;
2249 :
2250 0 : return Color( (sal_uInt8)nNewRed, (sal_uInt8)nNewGreen, (sal_uInt8)nNewBlue );
2251 : }
2252 :
2253 0 : void SVGActionWriter::ImplWriteMask( GDIMetaFile& rMtf,
2254 : const Point& rDestPt,
2255 : const Size& rDestSize,
2256 : const Gradient& rGradient,
2257 : sal_uInt32 nWriteFlags )
2258 : {
2259 0 : Point aSrcPt( rMtf.GetPrefMapMode().GetOrigin() );
2260 0 : const Size aSrcSize( rMtf.GetPrefSize() );
2261 0 : const double fScaleX = aSrcSize.Width() ? (double) rDestSize.Width() / aSrcSize.Width() : 1.0;
2262 0 : const double fScaleY = aSrcSize.Height() ? (double) rDestSize.Height() / aSrcSize.Height() : 1.0;
2263 : long nMoveX, nMoveY;
2264 :
2265 0 : if( fScaleX != 1.0 || fScaleY != 1.0 )
2266 : {
2267 0 : rMtf.Scale( fScaleX, fScaleY );
2268 0 : aSrcPt.X() = FRound( aSrcPt.X() * fScaleX ), aSrcPt.Y() = FRound( aSrcPt.Y() * fScaleY );
2269 : }
2270 :
2271 0 : nMoveX = rDestPt.X() - aSrcPt.X(), nMoveY = rDestPt.Y() - aSrcPt.Y();
2272 :
2273 0 : if( nMoveX || nMoveY )
2274 0 : rMtf.Move( nMoveX, nMoveY );
2275 :
2276 0 : OUString aMaskId = "mask" + OUString::number( mnCurMaskId++ );
2277 :
2278 : {
2279 0 : SvXMLElementExport aElemDefs( mrExport, XML_NAMESPACE_NONE, aXMLElemDefs, true, true );
2280 :
2281 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrId, aMaskId );
2282 : {
2283 0 : SvXMLElementExport aElemMask( mrExport, XML_NAMESPACE_NONE, aXMLElemMask, true, true );
2284 :
2285 0 : const tools::PolyPolygon aPolyPolygon( tools::PolyPolygon( Rectangle( rDestPt, rDestSize ) ) );
2286 0 : Gradient aGradient( rGradient );
2287 :
2288 : // swap gradient stops to adopt SVG mask
2289 0 : Color aTmpColor( aGradient.GetStartColor() );
2290 0 : sal_uInt16 nTmpIntensity( aGradient.GetStartIntensity() );
2291 0 : aGradient.SetStartColor( aGradient.GetEndColor() );
2292 0 : aGradient.SetStartIntensity( aGradient.GetEndIntensity() ) ;
2293 0 : aGradient.SetEndColor( aTmpColor );
2294 0 : aGradient.SetEndIntensity( nTmpIntensity );
2295 :
2296 0 : ImplWriteGradientEx( aPolyPolygon, aGradient, nWriteFlags );
2297 0 : }
2298 : }
2299 :
2300 0 : OUString aMaskStyle = "mask:url(#" + aMaskId + ")";
2301 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrStyle, aMaskStyle );
2302 :
2303 : {
2304 0 : SvXMLElementExport aElemG( mrExport, XML_NAMESPACE_NONE, aXMLElemG, true, true );
2305 :
2306 0 : mpVDev->Push();
2307 0 : ImplWriteActions( rMtf, nWriteFlags, NULL );
2308 0 : mpVDev->Pop();
2309 0 : }
2310 0 : }
2311 :
2312 0 : void SVGActionWriter::ImplWriteText( const Point& rPos, const OUString& rText,
2313 : const long* pDXArray, long nWidth,
2314 : bool bApplyMapping )
2315 : {
2316 0 : const FontMetric aMetric( mpVDev->GetFontMetric() );
2317 :
2318 0 : bool bTextSpecial = aMetric.IsShadow() || aMetric.IsOutline() || (aMetric.GetRelief() != RELIEF_NONE);
2319 :
2320 0 : if( !bTextSpecial )
2321 : {
2322 0 : ImplWriteText( rPos, rText, pDXArray, nWidth, mpVDev->GetTextColor(), bApplyMapping );
2323 : }
2324 : else
2325 : {
2326 0 : if( aMetric.GetRelief() != RELIEF_NONE )
2327 : {
2328 0 : Color aReliefColor( COL_LIGHTGRAY );
2329 0 : Color aTextColor( mpVDev->GetTextColor() );
2330 :
2331 0 : if ( aTextColor.GetColor() == COL_BLACK )
2332 0 : aTextColor = Color( COL_WHITE );
2333 :
2334 0 : if ( aTextColor.GetColor() == COL_WHITE )
2335 0 : aReliefColor = Color( COL_BLACK );
2336 :
2337 :
2338 0 : Point aPos( rPos );
2339 0 : Point aOffset( 6, 6 );
2340 :
2341 0 : if ( aMetric.GetRelief() == RELIEF_ENGRAVED )
2342 : {
2343 0 : aPos -= aOffset;
2344 : }
2345 : else
2346 : {
2347 0 : aPos += aOffset;
2348 : }
2349 :
2350 0 : ImplWriteText( aPos, rText, pDXArray, nWidth, aReliefColor, bApplyMapping );
2351 0 : ImplWriteText( rPos, rText, pDXArray, nWidth, aTextColor, bApplyMapping );
2352 : }
2353 : else
2354 : {
2355 0 : if( aMetric.IsShadow() )
2356 : {
2357 0 : long nOff = 1 + ((aMetric.GetLineHeight()-24)/24);
2358 0 : if ( aMetric.IsOutline() )
2359 0 : nOff += 6;
2360 :
2361 0 : Color aTextColor( mpVDev->GetTextColor() );
2362 0 : Color aShadowColor = Color( COL_BLACK );
2363 :
2364 0 : if ( (aTextColor.GetColor() == COL_BLACK) || (aTextColor.GetLuminance() < 8) )
2365 0 : aShadowColor = Color( COL_LIGHTGRAY );
2366 :
2367 0 : Point aPos( rPos );
2368 0 : aPos += Point( nOff, nOff );
2369 0 : ImplWriteText( aPos, rText, pDXArray, nWidth, aShadowColor, bApplyMapping );
2370 :
2371 0 : if( !aMetric.IsOutline() )
2372 : {
2373 0 : ImplWriteText( rPos, rText, pDXArray, nWidth, aTextColor, bApplyMapping );
2374 : }
2375 : }
2376 :
2377 0 : if( aMetric.IsOutline() )
2378 : {
2379 0 : Point aPos = rPos + Point( -6, -6 );
2380 0 : ImplWriteText( aPos, rText, pDXArray, nWidth, mpVDev->GetTextColor(), bApplyMapping );
2381 0 : aPos = rPos + Point( +6, +6);
2382 0 : ImplWriteText( aPos, rText, pDXArray, nWidth, mpVDev->GetTextColor(), bApplyMapping );
2383 0 : aPos = rPos + Point( -6, +0);
2384 0 : ImplWriteText( aPos, rText, pDXArray, nWidth, mpVDev->GetTextColor(), bApplyMapping );
2385 0 : aPos = rPos + Point( -6, +6);
2386 0 : ImplWriteText( aPos, rText, pDXArray, nWidth, mpVDev->GetTextColor(), bApplyMapping );
2387 0 : aPos = rPos + Point( +0, +6);
2388 0 : ImplWriteText( aPos, rText, pDXArray, nWidth, mpVDev->GetTextColor(), bApplyMapping );
2389 0 : aPos = rPos + Point( +0, -6);
2390 0 : ImplWriteText( aPos, rText, pDXArray, nWidth, mpVDev->GetTextColor(), bApplyMapping );
2391 0 : aPos = rPos + Point( +6, -1);
2392 0 : ImplWriteText( aPos, rText, pDXArray, nWidth, mpVDev->GetTextColor(), bApplyMapping );
2393 0 : aPos = rPos + Point( +6, +0);
2394 0 : ImplWriteText( aPos, rText, pDXArray, nWidth, mpVDev->GetTextColor(), bApplyMapping );
2395 :
2396 0 : ImplWriteText( rPos, rText, pDXArray, nWidth, Color( COL_WHITE ), bApplyMapping );
2397 : }
2398 : }
2399 0 : }
2400 0 : }
2401 :
2402 0 : void SVGActionWriter::ImplWriteText( const Point& rPos, const OUString& rText,
2403 : const long* pDXArray, long nWidth,
2404 : Color aTextColor, bool bApplyMapping )
2405 : {
2406 0 : sal_Int32 nLen = rText.getLength();
2407 0 : Size aNormSize;
2408 0 : Point aPos;
2409 0 : Point aBaseLinePos( rPos );
2410 0 : const FontMetric aMetric( mpVDev->GetFontMetric() );
2411 0 : const vcl::Font& rFont = mpVDev->GetFont();
2412 :
2413 0 : if( rFont.GetAlign() == ALIGN_TOP )
2414 0 : aBaseLinePos.Y() += aMetric.GetAscent();
2415 0 : else if( rFont.GetAlign() == ALIGN_BOTTOM )
2416 0 : aBaseLinePos.Y() -= aMetric.GetDescent();
2417 :
2418 0 : if( bApplyMapping )
2419 0 : ImplMap( rPos, aPos );
2420 : else
2421 0 : aPos = rPos;
2422 :
2423 0 : boost::shared_array<long> xTmpArray(new long[nLen]);
2424 : // get text sizes
2425 0 : if( pDXArray )
2426 : {
2427 0 : aNormSize = Size( mpVDev->GetTextWidth( rText ), 0 );
2428 0 : memcpy(xTmpArray.get(), pDXArray, nLen * sizeof(long));
2429 : }
2430 : else
2431 : {
2432 0 : aNormSize = Size( mpVDev->GetTextArray( rText, xTmpArray.get() ), 0 );
2433 : }
2434 0 : long* pDX = xTmpArray.get();
2435 :
2436 : // if text is rotated, set transform matrix at new g element
2437 0 : if( rFont.GetOrientation() )
2438 : {
2439 0 : Point aRot( aPos );
2440 : OUString aTransform =
2441 0 : "translate(" + OUString::number( aRot.X() ) +
2442 0 : "," + OUString::number( aRot.Y() ) + ") rotate(" +
2443 0 : OUString::number( rFont.GetOrientation() * -0.1 ) +
2444 0 : ") translate(" + OUString::number( -aRot.X() ) +
2445 0 : "," + OUString::number( -aRot.Y() ) + ")";
2446 :
2447 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrTransform, aTransform );
2448 : }
2449 :
2450 :
2451 0 : mpContext->AddPaintAttr( COL_TRANSPARENT, aTextColor );
2452 :
2453 : // for each line of text there should be at least one group element
2454 0 : SvXMLElementExport aSVGGElem( mrExport, XML_NAMESPACE_NONE, aXMLElemG, true, false );
2455 :
2456 0 : bool bIsPlaceholderField = false;
2457 :
2458 0 : if( mbIsPlacehlolderShape )
2459 : {
2460 0 : OUString sTextContent = rText;
2461 0 : bIsPlaceholderField = sTextContent.match( sPlaceholderTag );
2462 : // for a placeholder text field we export only one <text> svg element
2463 0 : if( bIsPlaceholderField )
2464 : {
2465 0 : OUString sCleanTextContent;
2466 0 : static const sal_Int32 nFrom = sPlaceholderTag.getLength();
2467 0 : if( sTextContent.getLength() > nFrom )
2468 : {
2469 0 : sCleanTextContent = sTextContent.copy( nFrom );
2470 : }
2471 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, "class", "PlaceholderText" );
2472 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX, OUString::number( aPos.X() ) );
2473 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY, OUString::number( aPos.Y() ) );
2474 : {
2475 0 : SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemText, true, false );
2476 : // At least for the single slide case we need really to export placeholder text
2477 0 : mrExport.GetDocHandler()->characters( sCleanTextContent );
2478 0 : }
2479 0 : }
2480 : }
2481 :
2482 0 : if( !bIsPlaceholderField )
2483 : {
2484 0 : if( nLen > 1 )
2485 : {
2486 0 : aNormSize.Width() = pDX[ nLen - 2 ] + mpVDev->GetTextWidth( OUString(rText[nLen - 1]) );
2487 :
2488 0 : if( nWidth && aNormSize.Width() && ( nWidth != aNormSize.Width() ) )
2489 : {
2490 : long i;
2491 0 : const double fFactor = (double) nWidth / aNormSize.Width();
2492 :
2493 0 : for( i = 0; i < ( nLen - 1 ); i++ )
2494 0 : pDX[ i ] = FRound( pDX[ i ] * fFactor );
2495 : }
2496 : else
2497 : {
2498 0 : ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > xBI( ::vcl::unohelper::CreateBreakIterator() );
2499 0 : const ::com::sun::star::lang::Locale& rLocale = Application::GetSettings().GetLanguageTag().getLocale();
2500 0 : sal_Int32 nCurPos = 0, nLastPos = 0, nX = aPos.X();
2501 :
2502 : // write single glyphs at absolute text positions
2503 0 : for( bool bCont = true; bCont; )
2504 : {
2505 0 : sal_Int32 nCount = 1;
2506 :
2507 0 : nLastPos = nCurPos;
2508 0 : nCurPos = xBI->nextCharacters( rText, nCurPos, rLocale,
2509 : ::com::sun::star::i18n::CharacterIteratorMode::SKIPCELL,
2510 0 : nCount, nCount );
2511 :
2512 0 : nCount = nCurPos - nLastPos;
2513 0 : bCont = ( nCurPos < rText.getLength() ) && nCount;
2514 :
2515 0 : if( nCount )
2516 : {
2517 0 : const OUString aGlyph( rText.copy( nLastPos, nCount ) );
2518 :
2519 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX, OUString::number( nX ) );
2520 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY, OUString::number( aPos.Y() ) );
2521 :
2522 : {
2523 0 : SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemText, true, false );
2524 0 : mrExport.GetDocHandler()->characters( aGlyph );
2525 : }
2526 :
2527 0 : if( bCont )
2528 : {
2529 : // #118796# do NOT access pDXArray, it may be zero (!)
2530 0 : sal_Int32 nDXWidth = pDX[ nCurPos - 1 ];
2531 0 : if ( bApplyMapping )
2532 0 : nDXWidth = ImplMap( nDXWidth );
2533 0 : nX = aPos.X() + nDXWidth;
2534 0 : }
2535 : }
2536 0 : }
2537 : }
2538 : }
2539 : else
2540 : {
2541 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX, OUString::number( aPos.X() ) );
2542 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY, OUString::number( aPos.Y() ) );
2543 :
2544 : {
2545 0 : SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemText, true, false );
2546 0 : mrExport.GetDocHandler()->characters( rText );
2547 : }
2548 : }
2549 : }
2550 :
2551 :
2552 0 : if( !mrExport.IsUseNativeTextDecoration() )
2553 : {
2554 0 : if( rFont.GetStrikeout() != STRIKEOUT_NONE || rFont.GetUnderline() != UNDERLINE_NONE )
2555 : {
2556 0 : Polygon aPoly( 4 );
2557 0 : const long nLineHeight = std::max( (long) FRound( aMetric.GetLineHeight() * 0.05 ), (long) 1 );
2558 :
2559 0 : if( rFont.GetStrikeout() )
2560 : {
2561 0 : const long nYLinePos = aBaseLinePos.Y() - FRound( aMetric.GetAscent() * 0.26 );
2562 :
2563 0 : aPoly[ 0 ].X() = aBaseLinePos.X(); aPoly[ 0 ].Y() = nYLinePos - ( nLineHeight >> 1 );
2564 0 : aPoly[ 1 ].X() = aBaseLinePos.X() + aNormSize.Width() - 1; aPoly[ 1 ].Y() = aPoly[ 0 ].Y();
2565 0 : aPoly[ 2 ].X() = aPoly[ 1 ].X(); aPoly[ 2 ].Y() = aPoly[ 0 ].Y() + nLineHeight - 1;
2566 0 : aPoly[ 3 ].X() = aPoly[ 0 ].X(); aPoly[ 3 ].Y() = aPoly[ 2 ].Y();
2567 :
2568 0 : ImplWritePolyPolygon( aPoly, false );
2569 : }
2570 :
2571 0 : if( rFont.GetUnderline() )
2572 : {
2573 0 : const long nYLinePos = aBaseLinePos.Y() + ( nLineHeight << 1 );
2574 :
2575 0 : aPoly[ 0 ].X() = aBaseLinePos.X(); aPoly[ 0 ].Y() = nYLinePos - ( nLineHeight >> 1 );
2576 0 : aPoly[ 1 ].X() = aBaseLinePos.X() + aNormSize.Width() - 1; aPoly[ 1 ].Y() = aPoly[ 0 ].Y();
2577 0 : aPoly[ 2 ].X() = aPoly[ 1 ].X(); aPoly[ 2 ].Y() = aPoly[ 0 ].Y() + nLineHeight - 1;
2578 0 : aPoly[ 3 ].X() = aPoly[ 0 ].X(); aPoly[ 3 ].Y() = aPoly[ 2 ].Y();
2579 :
2580 0 : ImplWritePolyPolygon( aPoly, false );
2581 0 : }
2582 : }
2583 0 : }
2584 0 : }
2585 :
2586 0 : void SVGActionWriter::ImplWriteBmp( const BitmapEx& rBmpEx,
2587 : const Point& rPt, const Size& rSz,
2588 : const Point& rSrcPt, const Size& rSrcSz,
2589 : bool bApplyMapping )
2590 : {
2591 0 : if( !!rBmpEx )
2592 : {
2593 0 : BitmapEx aBmpEx( rBmpEx );
2594 0 : Point aPoint = Point();
2595 0 : const Rectangle aBmpRect( aPoint, rBmpEx.GetSizePixel() );
2596 0 : const Rectangle aSrcRect( rSrcPt, rSrcSz );
2597 :
2598 0 : if( aSrcRect != aBmpRect )
2599 0 : aBmpEx.Crop( aSrcRect );
2600 :
2601 0 : if( !!aBmpEx )
2602 : {
2603 0 : SvMemoryStream aOStm( 65535, 65535 );
2604 :
2605 0 : if( GraphicConverter::Export( aOStm, rBmpEx, CVT_PNG ) == ERRCODE_NONE )
2606 : {
2607 0 : Point aPt;
2608 0 : Size aSz;
2609 0 : Sequence< sal_Int8 > aSeq( (sal_Int8*) aOStm.GetData(), aOStm.Tell() );
2610 0 : OUStringBuffer aBuffer( "data:image/png;base64," );
2611 0 : ::sax::Converter::encodeBase64( aBuffer, aSeq );
2612 :
2613 0 : if( bApplyMapping )
2614 : {
2615 0 : ImplMap( rPt, aPt );
2616 0 : ImplMap( rSz, aSz );
2617 : }
2618 : else
2619 : {
2620 0 : aPt = rPt;
2621 0 : aSz = rSz;
2622 : }
2623 :
2624 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX, OUString::number( aPt.X() ) );
2625 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY, OUString::number( aPt.Y() ) );
2626 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrWidth, OUString::number( aSz.Width() ) );
2627 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrHeight, OUString::number( aSz.Height() ) );
2628 0 : mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrXLinkHRef, aBuffer.makeStringAndClear() );
2629 : {
2630 0 : SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemImage, true, true );
2631 0 : }
2632 0 : }
2633 0 : }
2634 : }
2635 0 : }
2636 :
2637 0 : void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf,
2638 : sal_uInt32 nWriteFlags,
2639 : const OUString* pElementId,
2640 : const Reference< XShape >* pxShape,
2641 : const GDIMetaFile* pTextEmbeddedBitmapMtf )
2642 : {
2643 : // need a counter fo rthe actions written per shape to avoid double ID
2644 : // generation
2645 0 : sal_Int32 nEntryCount(0);
2646 :
2647 0 : if( mnInnerMtfCount )
2648 0 : nWriteFlags |= SVGWRITER_NO_SHAPE_COMMENTS;
2649 :
2650 :
2651 : #if OSL_DEBUG_LEVEL > 0
2652 : bool bIsTextShape = false;
2653 : if( !mrExport.IsUsePositionedCharacters() && pxShape
2654 : && Reference< XText >( *pxShape, UNO_QUERY ).is() )
2655 : {
2656 : bIsTextShape = true;
2657 : }
2658 : #endif
2659 0 : mbIsPlacehlolderShape = false;
2660 0 : if( ( pElementId != NULL ) && ( *pElementId == sPlaceholderTag ) )
2661 : {
2662 0 : mbIsPlacehlolderShape = true;
2663 : // since we utilize pElementId in an improper way we reset it to NULL before to go on
2664 0 : pElementId = NULL;
2665 : }
2666 :
2667 0 : for( sal_uLong nCurAction = 0, nCount = rMtf.GetActionSize(); nCurAction < nCount; nCurAction++ )
2668 : {
2669 0 : const MetaAction* pAction = rMtf.GetAction( nCurAction );
2670 0 : const sal_uInt16 nType = pAction->GetType();
2671 :
2672 : #if OSL_DEBUG_LEVEL > 0
2673 : if( bIsTextShape )
2674 : {
2675 : try
2676 : {
2677 : SvXMLElementExport aElem( mrExport,
2678 : XML_NAMESPACE_NONE, "desc", false, false );
2679 : OUStringBuffer sType(OUString::number(nType));
2680 : if (pAction && (nType == META_COMMENT_ACTION))
2681 : {
2682 : sType.append(": ");
2683 : const MetaCommentAction* pA = static_cast<const MetaCommentAction*>(pAction);
2684 : OString sComment = pA->GetComment();
2685 : if (!sComment.isEmpty())
2686 : {
2687 : sType.append(OStringToOUString(
2688 : sComment, RTL_TEXTENCODING_UTF8));
2689 : }
2690 : if (sComment.equalsIgnoreAsciiCase("FIELD_SEQ_BEGIN"))
2691 : {
2692 : sal_uInt8 const*const pData = pA->GetData();
2693 : if (pData && (pA->GetDataSize()))
2694 : {
2695 : sal_uInt16 sz = (sal_uInt16)((pA->GetDataSize()) / 2);
2696 : if (sz)
2697 : {
2698 : sType.append("; ");
2699 : sType.append(
2700 : reinterpret_cast<sal_Unicode const*>(pData),
2701 : sz);
2702 : }
2703 : }
2704 : }
2705 : }
2706 : if (sType.getLength())
2707 : {
2708 : mrExport.GetDocHandler()->characters(
2709 : sType.makeStringAndClear());
2710 : }
2711 : }
2712 : catch( ... )
2713 : {
2714 : const MetaCommentAction* pA = static_cast<const MetaCommentAction*>(pAction);
2715 : OSL_FAIL( pA->GetComment().getStr() );
2716 : }
2717 :
2718 : }
2719 : #endif
2720 0 : switch( nType )
2721 : {
2722 : case( META_PIXEL_ACTION ):
2723 : {
2724 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2725 : {
2726 0 : const MetaPixelAction* pA = static_cast<const MetaPixelAction*>(pAction);
2727 :
2728 0 : mpContext->AddPaintAttr( pA->GetColor(), pA->GetColor() );
2729 0 : ImplWriteLine( pA->GetPoint(), pA->GetPoint(), &pA->GetColor() );
2730 : }
2731 : }
2732 0 : break;
2733 :
2734 : case( META_POINT_ACTION ):
2735 : {
2736 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2737 : {
2738 0 : const MetaPointAction* pA = static_cast<const MetaPointAction*>(pAction);
2739 :
2740 0 : mpContext->AddPaintAttr( mpVDev->GetLineColor(), mpVDev->GetLineColor() );
2741 0 : ImplWriteLine( pA->GetPoint(), pA->GetPoint(), NULL );
2742 : }
2743 : }
2744 0 : break;
2745 :
2746 : case( META_LINE_ACTION ):
2747 : {
2748 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2749 : {
2750 0 : const MetaLineAction* pA = static_cast<const MetaLineAction*>(pAction);
2751 :
2752 0 : mpContext->AddPaintAttr( mpVDev->GetLineColor(), mpVDev->GetLineColor() );
2753 0 : ImplWriteLine( pA->GetStartPoint(), pA->GetEndPoint(), NULL );
2754 : }
2755 : }
2756 0 : break;
2757 :
2758 : case( META_RECT_ACTION ):
2759 : {
2760 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2761 : {
2762 0 : mpContext->AddPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() );
2763 0 : ImplWriteRect( static_cast<const MetaRectAction*>(pAction)->GetRect(), 0, 0 );
2764 : }
2765 : }
2766 0 : break;
2767 :
2768 : case( META_ROUNDRECT_ACTION ):
2769 : {
2770 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2771 : {
2772 0 : const MetaRoundRectAction* pA = static_cast<const MetaRoundRectAction*>(pAction);
2773 :
2774 0 : mpContext->AddPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() );
2775 0 : ImplWriteRect( pA->GetRect(), pA->GetHorzRound(), pA->GetVertRound() );
2776 : }
2777 : }
2778 0 : break;
2779 :
2780 : case( META_ELLIPSE_ACTION ):
2781 : {
2782 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2783 : {
2784 0 : const MetaEllipseAction* pA = static_cast<const MetaEllipseAction*>(pAction);
2785 0 : const Rectangle& rRect = pA->GetRect();
2786 :
2787 0 : mpContext->AddPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() );
2788 0 : ImplWriteEllipse( rRect.Center(), rRect.GetWidth() >> 1, rRect.GetHeight() >> 1 );
2789 : }
2790 : }
2791 0 : break;
2792 :
2793 : case( META_ARC_ACTION ):
2794 : case( META_PIE_ACTION ):
2795 : case( META_CHORD_ACTION ):
2796 : case( META_POLYGON_ACTION ):
2797 : {
2798 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2799 : {
2800 0 : Polygon aPoly;
2801 :
2802 0 : switch( nType )
2803 : {
2804 : case( META_ARC_ACTION ):
2805 : {
2806 0 : const MetaArcAction* pA = static_cast<const MetaArcAction*>(pAction);
2807 0 : aPoly = Polygon( pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_ARC );
2808 : }
2809 0 : break;
2810 :
2811 : case( META_PIE_ACTION ):
2812 : {
2813 0 : const MetaPieAction* pA = static_cast<const MetaPieAction*>(pAction);
2814 0 : aPoly = Polygon( pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_PIE );
2815 : }
2816 0 : break;
2817 :
2818 : case( META_CHORD_ACTION ):
2819 : {
2820 0 : const MetaChordAction* pA = static_cast<const MetaChordAction*>(pAction);
2821 0 : aPoly = Polygon( pA->GetRect(), pA->GetStartPoint(), pA->GetEndPoint(), POLY_CHORD );
2822 : }
2823 0 : break;
2824 :
2825 : case( META_POLYGON_ACTION ):
2826 0 : aPoly = static_cast<const MetaPolygonAction*>(pAction)->GetPolygon();
2827 0 : break;
2828 : }
2829 :
2830 0 : if( aPoly.GetSize() )
2831 : {
2832 0 : mpContext->AddPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() );
2833 0 : ImplWritePolyPolygon( aPoly, false );
2834 0 : }
2835 : }
2836 : }
2837 0 : break;
2838 :
2839 : case( META_POLYLINE_ACTION ):
2840 : {
2841 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2842 : {
2843 0 : const MetaPolyLineAction* pA = static_cast<const MetaPolyLineAction*>(pAction);
2844 0 : const Polygon& rPoly = pA->GetPolygon();
2845 :
2846 0 : if( rPoly.GetSize() )
2847 : {
2848 0 : mpContext->AddPaintAttr( mpVDev->GetLineColor(), Color( COL_TRANSPARENT ) );
2849 0 : ImplAddLineAttr( pA->GetLineInfo() );
2850 0 : ImplWritePolyPolygon( rPoly, true );
2851 : }
2852 : }
2853 : }
2854 0 : break;
2855 :
2856 : case( META_POLYPOLYGON_ACTION ):
2857 : {
2858 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2859 : {
2860 0 : const MetaPolyPolygonAction* pA = static_cast<const MetaPolyPolygonAction*>(pAction);
2861 0 : const tools::PolyPolygon& rPolyPoly = pA->GetPolyPolygon();
2862 :
2863 0 : if( rPolyPoly.Count() )
2864 : {
2865 0 : mpContext->AddPaintAttr( mpVDev->GetLineColor(), mpVDev->GetFillColor() );
2866 0 : ImplWritePolyPolygon( rPolyPoly, false );
2867 : }
2868 : }
2869 : }
2870 0 : break;
2871 :
2872 : case( META_GRADIENT_ACTION ):
2873 : {
2874 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2875 : {
2876 0 : const MetaGradientAction* pA = static_cast<const MetaGradientAction*>(pAction);
2877 0 : const Polygon aRectPoly( pA->GetRect() );
2878 0 : const tools::PolyPolygon aRectPolyPoly( aRectPoly );
2879 :
2880 0 : ImplWriteGradientEx( aRectPolyPoly, pA->GetGradient(), nWriteFlags );
2881 : }
2882 : }
2883 0 : break;
2884 :
2885 : case( META_GRADIENTEX_ACTION ):
2886 : {
2887 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2888 : {
2889 0 : const MetaGradientExAction* pA = static_cast<const MetaGradientExAction*>(pAction);
2890 0 : ImplWriteGradientEx( pA->GetPolyPolygon(), pA->GetGradient(), nWriteFlags );
2891 : }
2892 : }
2893 0 : break;
2894 :
2895 : case META_HATCH_ACTION:
2896 : {
2897 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2898 : {
2899 0 : const MetaHatchAction* pA = static_cast<const MetaHatchAction*>(pAction);
2900 0 : ImplWritePattern( pA->GetPolyPolygon(), &pA->GetHatch(), NULL, nWriteFlags );
2901 : }
2902 : }
2903 0 : break;
2904 :
2905 : case( META_TRANSPARENT_ACTION ):
2906 : {
2907 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2908 : {
2909 0 : const MetaTransparentAction* pA = static_cast<const MetaTransparentAction*>(pAction);
2910 0 : const tools::PolyPolygon& rPolyPoly = pA->GetPolyPolygon();
2911 :
2912 0 : if( rPolyPoly.Count() )
2913 : {
2914 0 : Color aNewLineColor( mpVDev->GetLineColor() ), aNewFillColor( mpVDev->GetFillColor() );
2915 :
2916 0 : aNewLineColor.SetTransparency( sal::static_int_cast<sal_uInt8>( FRound( pA->GetTransparence() * 2.55 ) ) );
2917 0 : aNewFillColor.SetTransparency( sal::static_int_cast<sal_uInt8>( FRound( pA->GetTransparence() * 2.55 ) ) );
2918 :
2919 0 : mpContext->AddPaintAttr( aNewLineColor, aNewFillColor );
2920 0 : ImplWritePolyPolygon( rPolyPoly, false );
2921 : }
2922 : }
2923 : }
2924 0 : break;
2925 :
2926 : case( META_FLOATTRANSPARENT_ACTION ):
2927 : {
2928 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2929 : {
2930 0 : const MetaFloatTransparentAction* pA = static_cast<const MetaFloatTransparentAction*>(pAction);
2931 0 : GDIMetaFile aTmpMtf( pA->GetGDIMetaFile() );
2932 0 : ImplWriteMask( aTmpMtf, pA->GetPoint(), pA->GetSize(),
2933 0 : pA->GetGradient(), nWriteFlags );
2934 : }
2935 : }
2936 0 : break;
2937 :
2938 : case( META_EPS_ACTION ):
2939 : {
2940 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
2941 : {
2942 0 : const MetaEPSAction* pA = static_cast<const MetaEPSAction*>(pAction);
2943 0 : const GDIMetaFile aGDIMetaFile( pA->GetSubstitute() );
2944 0 : bool bFound = false;
2945 :
2946 0 : for( sal_uInt32 k = 0, nCount2 = aGDIMetaFile.GetActionSize(); ( k < nCount2 ) && !bFound; ++k )
2947 : {
2948 0 : const MetaAction* pSubstAct = aGDIMetaFile.GetAction( k );
2949 :
2950 0 : if( pSubstAct->GetType() == META_BMPSCALE_ACTION )
2951 : {
2952 0 : bFound = true;
2953 0 : const MetaBmpScaleAction* pBmpScaleAction = static_cast<const MetaBmpScaleAction*>(pSubstAct);
2954 0 : ImplWriteBmp( pBmpScaleAction->GetBitmap(),
2955 0 : pA->GetPoint(), pA->GetSize(),
2956 0 : Point(), pBmpScaleAction->GetBitmap().GetSizePixel() );
2957 : }
2958 0 : }
2959 : }
2960 : }
2961 0 : break;
2962 :
2963 : case( META_COMMENT_ACTION ):
2964 : {
2965 0 : const MetaCommentAction* pA = static_cast<const MetaCommentAction*>(pAction);
2966 :
2967 0 : if( ( pA->GetComment().equalsIgnoreAsciiCase("XGRAD_SEQ_BEGIN") ) &&
2968 0 : ( nWriteFlags & SVGWRITER_WRITE_FILL ) )
2969 : {
2970 0 : const MetaGradientExAction* pGradAction = NULL;
2971 0 : bool bDone = false;
2972 :
2973 0 : while( !bDone && ( ++nCurAction < nCount ) )
2974 : {
2975 0 : pAction = rMtf.GetAction( nCurAction );
2976 :
2977 0 : if( pAction->GetType() == META_GRADIENTEX_ACTION )
2978 0 : pGradAction = static_cast<const MetaGradientExAction*>(pAction);
2979 0 : else if( ( pAction->GetType() == META_COMMENT_ACTION ) &&
2980 0 : ( static_cast<const MetaCommentAction*>( pAction )->GetComment().
2981 0 : equalsIgnoreAsciiCase("XGRAD_SEQ_END") ) )
2982 : {
2983 0 : bDone = true;
2984 : }
2985 : }
2986 :
2987 0 : if( pGradAction )
2988 0 : ImplWriteGradientEx( pGradAction->GetPolyPolygon(), pGradAction->GetGradient(), nWriteFlags );
2989 : }
2990 0 : else if( ( pA->GetComment().equalsIgnoreAsciiCase("XPATHFILL_SEQ_BEGIN") ) &&
2991 0 : ( nWriteFlags & SVGWRITER_WRITE_FILL ) && !( nWriteFlags & SVGWRITER_NO_SHAPE_COMMENTS ) &&
2992 0 : pA->GetDataSize() )
2993 : {
2994 : // write open shape in every case
2995 0 : if( mapCurShape.get() )
2996 : {
2997 0 : ImplWriteShape( *mapCurShape );
2998 0 : mapCurShape.reset();
2999 : }
3000 :
3001 0 : SvMemoryStream aMemStm( (void*) pA->GetData(), pA->GetDataSize(), STREAM_READ );
3002 0 : SvtGraphicFill aFill;
3003 :
3004 0 : ReadSvtGraphicFill( aMemStm, aFill );
3005 :
3006 0 : bool bGradient = SvtGraphicFill::fillGradient == aFill.getFillType() &&
3007 0 : ( SvtGraphicFill::gradientLinear == aFill.getGradientType() ||
3008 0 : SvtGraphicFill::gradientRadial == aFill.getGradientType() );
3009 0 : bool bSkip = ( SvtGraphicFill::fillSolid == aFill.getFillType() || bGradient );
3010 :
3011 0 : if( bSkip )
3012 : {
3013 0 : tools::PolyPolygon aShapePolyPoly;
3014 :
3015 0 : aFill.getPath( aShapePolyPoly );
3016 :
3017 0 : if( aShapePolyPoly.Count() )
3018 : {
3019 0 : mapCurShape.reset( new SVGShapeDescriptor );
3020 :
3021 0 : if( pElementId )
3022 : {
3023 0 : mapCurShape->maId = *pElementId + "_" + OUString::number(nEntryCount++);
3024 : }
3025 :
3026 0 : mapCurShape->maShapePolyPoly = aShapePolyPoly;
3027 0 : mapCurShape->maShapeFillColor = aFill.getFillColor();
3028 0 : mapCurShape->maShapeFillColor.SetTransparency( (sal_uInt8) FRound( 255.0 * aFill.getTransparency() ) );
3029 :
3030 0 : if( bGradient )
3031 : {
3032 : // step through following actions until the first Gradient/GradientEx action is found
3033 0 : while( !mapCurShape->mapShapeGradient.get() && bSkip && ( ++nCurAction < nCount ) )
3034 : {
3035 0 : pAction = rMtf.GetAction( nCurAction );
3036 :
3037 0 : if( ( pAction->GetType() == META_COMMENT_ACTION ) &&
3038 0 : ( static_cast<const MetaCommentAction*>(pAction)->GetComment().
3039 0 : equalsIgnoreAsciiCase("XPATHFILL_SEQ_END") ) )
3040 : {
3041 0 : bSkip = false;
3042 : }
3043 0 : else if( pAction->GetType() == META_GRADIENTEX_ACTION )
3044 : {
3045 0 : mapCurShape->mapShapeGradient.reset( new Gradient(
3046 0 : static_cast< const MetaGradientExAction* >( pAction )->GetGradient() ) );
3047 : }
3048 0 : else if( pAction->GetType() == META_GRADIENT_ACTION )
3049 : {
3050 0 : mapCurShape->mapShapeGradient.reset( new Gradient(
3051 0 : static_cast< const MetaGradientAction* >( pAction )->GetGradient() ) );
3052 : }
3053 : }
3054 : }
3055 : }
3056 : else
3057 0 : bSkip = false;
3058 : }
3059 :
3060 : // skip rest of comment
3061 0 : while( bSkip && ( ++nCurAction < nCount ) )
3062 : {
3063 0 : pAction = rMtf.GetAction( nCurAction );
3064 :
3065 0 : if( ( pAction->GetType() == META_COMMENT_ACTION ) &&
3066 0 : ( static_cast<const MetaCommentAction*>( pAction )->GetComment().
3067 0 : equalsIgnoreAsciiCase("XPATHFILL_SEQ_END") ) )
3068 : {
3069 0 : bSkip = false;
3070 : }
3071 0 : }
3072 : }
3073 0 : else if( ( pA->GetComment().equalsIgnoreAsciiCase("XPATHSTROKE_SEQ_BEGIN") ) &&
3074 0 : ( nWriteFlags & SVGWRITER_WRITE_FILL ) && !( nWriteFlags & SVGWRITER_NO_SHAPE_COMMENTS ) &&
3075 0 : pA->GetDataSize() )
3076 : {
3077 0 : SvMemoryStream aMemStm( (void*) pA->GetData(), pA->GetDataSize(), STREAM_READ );
3078 0 : SvtGraphicStroke aStroke;
3079 0 : tools::PolyPolygon aStartArrow, aEndArrow;
3080 :
3081 0 : ReadSvtGraphicStroke( aMemStm, aStroke );
3082 0 : aStroke.getStartArrow( aStartArrow );
3083 0 : aStroke.getEndArrow( aEndArrow );
3084 :
3085 : // Currently no support for strokes with start/end arrow(s)
3086 : // added that support
3087 0 : Polygon aPoly;
3088 :
3089 0 : aStroke.getPath(aPoly);
3090 :
3091 0 : if(mapCurShape.get())
3092 : {
3093 0 : if(1 != mapCurShape->maShapePolyPoly.Count()
3094 0 : || !mapCurShape->maShapePolyPoly[0].IsEqual(aPoly))
3095 : {
3096 : // this path action is not covering the same path than the already existing
3097 : // fill polypolygon, so write out the fill polygon
3098 0 : ImplWriteShape( *mapCurShape );
3099 0 : mapCurShape.reset();
3100 : }
3101 : }
3102 :
3103 0 : if( !mapCurShape.get() )
3104 : {
3105 :
3106 0 : mapCurShape.reset( new SVGShapeDescriptor );
3107 :
3108 0 : if( pElementId )
3109 : {
3110 0 : mapCurShape->maId = *pElementId + "_" + OUString::number(nEntryCount++);
3111 : }
3112 :
3113 0 : mapCurShape->maShapePolyPoly = aPoly;
3114 : }
3115 :
3116 0 : mapCurShape->maShapeLineColor = mpVDev->GetLineColor();
3117 0 : mapCurShape->maShapeLineColor.SetTransparency( (sal_uInt8) FRound( aStroke.getTransparency() * 255.0 ) );
3118 0 : mapCurShape->mnStrokeWidth = FRound( aStroke.getStrokeWidth() );
3119 0 : aStroke.getDashArray( mapCurShape->maDashArray );
3120 :
3121 : // added support for LineJoin
3122 0 : switch(aStroke.getJoinType())
3123 : {
3124 : default: /* SvtGraphicStroke::joinMiter, SvtGraphicStroke::joinNone */
3125 : {
3126 0 : mapCurShape->maLineJoin = basegfx::B2DLINEJOIN_MITER;
3127 0 : break;
3128 : }
3129 : case SvtGraphicStroke::joinRound:
3130 : {
3131 0 : mapCurShape->maLineJoin = basegfx::B2DLINEJOIN_ROUND;
3132 0 : break;
3133 : }
3134 : case SvtGraphicStroke::joinBevel:
3135 : {
3136 0 : mapCurShape->maLineJoin = basegfx::B2DLINEJOIN_BEVEL;
3137 0 : break;
3138 : }
3139 : }
3140 :
3141 : // added support for LineCap
3142 0 : switch(aStroke.getCapType())
3143 : {
3144 : default: /* SvtGraphicStroke::capButt */
3145 : {
3146 0 : mapCurShape->maLineCap = com::sun::star::drawing::LineCap_BUTT;
3147 0 : break;
3148 : }
3149 : case SvtGraphicStroke::capRound:
3150 : {
3151 0 : mapCurShape->maLineCap = com::sun::star::drawing::LineCap_ROUND;
3152 0 : break;
3153 : }
3154 : case SvtGraphicStroke::capSquare:
3155 : {
3156 0 : mapCurShape->maLineCap = com::sun::star::drawing::LineCap_SQUARE;
3157 0 : break;
3158 : }
3159 : }
3160 :
3161 0 : if(mapCurShape.get() &&(aStartArrow.Count() || aEndArrow.Count()))
3162 : {
3163 0 : ImplWriteShape( *mapCurShape );
3164 :
3165 0 : mapCurShape->maShapeFillColor = mapCurShape->maShapeLineColor;
3166 0 : mapCurShape->maShapeLineColor = Color(COL_TRANSPARENT);
3167 0 : mapCurShape->mnStrokeWidth = 0;
3168 0 : mapCurShape->maDashArray.clear();
3169 0 : mapCurShape->maLineJoin = basegfx::B2DLINEJOIN_MITER;
3170 0 : mapCurShape->maLineCap = com::sun::star::drawing::LineCap_BUTT;
3171 :
3172 0 : if(aStartArrow.Count())
3173 : {
3174 0 : mapCurShape->maShapePolyPoly = aStartArrow;
3175 :
3176 0 : if( pElementId ) // #i124825# pElementId is optinal, may be zero
3177 : {
3178 0 : mapCurShape->maId = *pElementId + "_" + OUString::number(nEntryCount++);
3179 : }
3180 :
3181 0 : ImplWriteShape( *mapCurShape );
3182 : }
3183 :
3184 0 : if(aEndArrow.Count())
3185 : {
3186 0 : mapCurShape->maShapePolyPoly = aEndArrow;
3187 :
3188 0 : if( pElementId ) // #i124825# pElementId is optinal, may be zero
3189 : {
3190 0 : mapCurShape->maId = *pElementId + "_" + OUString::number(nEntryCount++);
3191 : }
3192 :
3193 0 : ImplWriteShape( *mapCurShape );
3194 : }
3195 :
3196 0 : mapCurShape.reset();
3197 : }
3198 :
3199 : // write open shape in every case
3200 0 : if( mapCurShape.get() )
3201 : {
3202 0 : ImplWriteShape( *mapCurShape );
3203 0 : mapCurShape.reset();
3204 : }
3205 :
3206 : // skip rest of comment
3207 0 : bool bSkip = true;
3208 :
3209 0 : while( bSkip && ( ++nCurAction < nCount ) )
3210 : {
3211 0 : pAction = rMtf.GetAction( nCurAction );
3212 :
3213 0 : if( ( pAction->GetType() == META_COMMENT_ACTION ) &&
3214 0 : ( static_cast<const MetaCommentAction*>(pAction)->GetComment().
3215 0 : equalsIgnoreAsciiCase("XPATHSTROKE_SEQ_END") ) )
3216 : {
3217 0 : bSkip = false;
3218 : }
3219 0 : }
3220 : }
3221 0 : else if( !mrExport.IsUsePositionedCharacters() && ( nWriteFlags & SVGWRITER_WRITE_TEXT ) )
3222 : {
3223 0 : if( ( pA->GetComment().equalsIgnoreAsciiCase( "XTEXT_PAINTSHAPE_BEGIN" ) ) )
3224 : {
3225 0 : if( pxShape )
3226 : {
3227 0 : Reference< XText > xText( *pxShape, UNO_QUERY );
3228 0 : if( xText.is() )
3229 0 : maTextWriter.setTextShape( xText, pTextEmbeddedBitmapMtf );
3230 : }
3231 0 : maTextWriter.createParagraphEnumeration();
3232 : {
3233 : // nTextFound == -1 => no text found
3234 : // nTextFound == 0 => no text found and end of text shape reached
3235 : // nTextFound == 1 => text found!
3236 0 : sal_Int32 nTextFound = -1;
3237 0 : while( ( nTextFound < 0 ) && ( nCurAction < nCount ) )
3238 : {
3239 0 : nTextFound = maTextWriter.setTextPosition( rMtf, nCurAction );
3240 : }
3241 : // We found some text in the current text shape.
3242 0 : if( nTextFound > 0 )
3243 : {
3244 0 : maTextWriter.setTextProperties( rMtf, nCurAction );
3245 0 : maTextWriter.startTextShape();
3246 : }
3247 : // We reached the end of the current text shape
3248 : // without finding any text. So we need to go back
3249 : // by one action in order to handle the
3250 : // XTEXT_PAINTSHAPE_END action because on the next
3251 : // loop the nCurAction is incremented by one.
3252 : else
3253 : {
3254 0 : --nCurAction;
3255 : }
3256 : }
3257 : }
3258 0 : else if( ( pA->GetComment().equalsIgnoreAsciiCase( "XTEXT_PAINTSHAPE_END" ) ) )
3259 : {
3260 0 : maTextWriter.endTextShape();
3261 : }
3262 0 : else if( ( pA->GetComment().equalsIgnoreAsciiCase( "XTEXT_EOP" ) ) )
3263 : {
3264 0 : const MetaAction* pNextAction = rMtf.GetAction( nCurAction + 1 );
3265 0 : if( !( ( pNextAction->GetType() == META_COMMENT_ACTION ) &&
3266 0 : ( static_cast<const MetaCommentAction*>(pNextAction)->GetComment().equalsIgnoreAsciiCase("XTEXT_PAINTSHAPE_END") ) ))
3267 : {
3268 : // nTextFound == -1 => no text found and end of paragraph reached
3269 : // nTextFound == 0 => no text found and end of text shape reached
3270 : // nTextFound == 1 => text found!
3271 0 : sal_Int32 nTextFound = -1;
3272 0 : while( ( nTextFound < 0 ) && ( nCurAction < nCount ) )
3273 : {
3274 0 : nTextFound = maTextWriter.setTextPosition( rMtf, nCurAction );
3275 : }
3276 : // We found a paragraph with some text in the
3277 : // current text shape.
3278 0 : if( nTextFound > 0 )
3279 : {
3280 0 : maTextWriter.setTextProperties( rMtf, nCurAction );
3281 0 : maTextWriter.startTextParagraph();
3282 : }
3283 : // We reached the end of the current text shape
3284 : // without finding any text. So we need to go back
3285 : // by one action in order to handle the
3286 : // XTEXT_PAINTSHAPE_END action because on the next
3287 : // loop the nCurAction is incremented by one.
3288 : else
3289 : {
3290 0 : --nCurAction;
3291 : }
3292 :
3293 : }
3294 : }
3295 0 : else if( ( pA->GetComment().equalsIgnoreAsciiCase( "XTEXT_EOL" ) ) )
3296 : {
3297 0 : const MetaAction* pNextAction = rMtf.GetAction( nCurAction + 1 );
3298 0 : if( !( ( pNextAction->GetType() == META_COMMENT_ACTION ) &&
3299 0 : ( static_cast<const MetaCommentAction*>(pNextAction)->GetComment().equalsIgnoreAsciiCase("XTEXT_EOP") ) ) )
3300 : {
3301 : // nTextFound == -2 => no text found and end of line reached
3302 : // nTextFound == -1 => no text found and end of paragraph reached
3303 : // nTextFound == 1 => text found!
3304 0 : sal_Int32 nTextFound = -2;
3305 0 : while( ( nTextFound < -1 ) && ( nCurAction < nCount ) )
3306 : {
3307 0 : nTextFound = maTextWriter.setTextPosition( rMtf, nCurAction );
3308 : }
3309 : // We found a line with some text in the current
3310 : // paragraph.
3311 0 : if( nTextFound > 0 )
3312 : {
3313 0 : maTextWriter.startTextPosition();
3314 : }
3315 : // We reached the end of the current paragraph
3316 : // without finding any text. So we need to go back
3317 : // by one action in order to handle the XTEXT_EOP
3318 : // action because on the next loop the nCurAction is
3319 : // incremented by one.
3320 : else
3321 : {
3322 0 : --nCurAction;
3323 : }
3324 : }
3325 : }
3326 : }
3327 : }
3328 0 : break;
3329 :
3330 : case( META_BMP_ACTION ):
3331 : {
3332 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
3333 : {
3334 0 : const MetaBmpAction* pA = static_cast<const MetaBmpAction*>(pAction);
3335 :
3336 0 : ImplWriteBmp( pA->GetBitmap(),
3337 0 : pA->GetPoint(), mpVDev->PixelToLogic( pA->GetBitmap().GetSizePixel() ),
3338 0 : Point(), pA->GetBitmap().GetSizePixel() );
3339 : }
3340 : }
3341 0 : break;
3342 :
3343 : case( META_BMPSCALE_ACTION ):
3344 : {
3345 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
3346 : {
3347 0 : const MetaBmpScaleAction* pA = static_cast<const MetaBmpScaleAction*>(pAction);
3348 :
3349 : // Bitmaps embedded into text shapes are collected and exported elsewhere.
3350 0 : if( maTextWriter.isTextShapeStarted() )
3351 : {
3352 0 : maTextWriter.writeBitmapPlaceholder( pA );
3353 : }
3354 : else
3355 : {
3356 0 : ImplWriteBmp( pA->GetBitmap(),
3357 0 : pA->GetPoint(), pA->GetSize(),
3358 0 : Point(), pA->GetBitmap().GetSizePixel() );
3359 : }
3360 : }
3361 : }
3362 0 : break;
3363 :
3364 : case( META_BMPSCALEPART_ACTION ):
3365 : {
3366 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
3367 : {
3368 0 : const MetaBmpScalePartAction* pA = static_cast<const MetaBmpScalePartAction*>(pAction);
3369 :
3370 0 : ImplWriteBmp( pA->GetBitmap(),
3371 0 : pA->GetDestPoint(), pA->GetDestSize(),
3372 0 : pA->GetSrcPoint(), pA->GetSrcSize() );
3373 : }
3374 : }
3375 0 : break;
3376 :
3377 : case( META_BMPEX_ACTION ):
3378 : {
3379 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
3380 : {
3381 0 : const MetaBmpExAction* pA = static_cast<const MetaBmpExAction*>(pAction);
3382 :
3383 0 : ImplWriteBmp( pA->GetBitmapEx(),
3384 0 : pA->GetPoint(), mpVDev->PixelToLogic( pA->GetBitmapEx().GetSizePixel() ),
3385 0 : Point(), pA->GetBitmapEx().GetSizePixel() );
3386 : }
3387 : }
3388 0 : break;
3389 :
3390 : case( META_BMPEXSCALE_ACTION ):
3391 : {
3392 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
3393 : {
3394 0 : const MetaBmpExScaleAction* pA = static_cast<const MetaBmpExScaleAction*>(pAction);
3395 :
3396 : // Bitmaps embedded into text shapes are collected and exported elsewhere.
3397 0 : if( maTextWriter.isTextShapeStarted() )
3398 : {
3399 0 : maTextWriter.writeBitmapPlaceholder( pA );
3400 : }
3401 : else
3402 : {
3403 0 : ImplWriteBmp( pA->GetBitmapEx(),
3404 0 : pA->GetPoint(), pA->GetSize(),
3405 0 : Point(), pA->GetBitmapEx().GetSizePixel() );
3406 : }
3407 : }
3408 : }
3409 0 : break;
3410 :
3411 : case( META_BMPEXSCALEPART_ACTION ):
3412 : {
3413 0 : if( nWriteFlags & SVGWRITER_WRITE_FILL )
3414 : {
3415 0 : const MetaBmpExScalePartAction* pA = static_cast<const MetaBmpExScalePartAction*>(pAction);
3416 :
3417 0 : ImplWriteBmp( pA->GetBitmapEx(),
3418 0 : pA->GetDestPoint(), pA->GetDestSize(),
3419 0 : pA->GetSrcPoint(), pA->GetSrcSize() );
3420 : }
3421 : }
3422 0 : break;
3423 :
3424 : case( META_TEXT_ACTION ):
3425 : {
3426 0 : if( nWriteFlags & SVGWRITER_WRITE_TEXT )
3427 : {
3428 0 : const MetaTextAction* pA = static_cast<const MetaTextAction*>(pAction);
3429 0 : const OUString aText = pA->GetText().copy( pA->GetIndex(), pA->GetLen() );
3430 :
3431 0 : if( !aText.isEmpty() )
3432 : {
3433 0 : if( mrExport.IsUsePositionedCharacters() )
3434 : {
3435 0 : vcl::Font aFont = ImplSetCorrectFontHeight();
3436 0 : mpContext->SetFontAttr( aFont );
3437 0 : ImplWriteText( pA->GetPoint(), aText, NULL, 0 );
3438 : }
3439 : else
3440 : {
3441 0 : maTextWriter.writeTextPortion( pA->GetPoint(), aText );
3442 : }
3443 :
3444 0 : }
3445 : }
3446 : }
3447 0 : break;
3448 :
3449 : case( META_TEXTRECT_ACTION ):
3450 : {
3451 0 : if( nWriteFlags & SVGWRITER_WRITE_TEXT )
3452 : {
3453 0 : const MetaTextRectAction* pA = static_cast<const MetaTextRectAction*>(pAction);
3454 :
3455 0 : if (!pA->GetText().isEmpty())
3456 : {
3457 0 : if( mrExport.IsUsePositionedCharacters() )
3458 : {
3459 0 : vcl::Font aFont = ImplSetCorrectFontHeight();
3460 0 : mpContext->SetFontAttr( aFont );
3461 0 : ImplWriteText( pA->GetRect().TopLeft(), pA->GetText(), NULL, 0 );
3462 : }
3463 : {
3464 0 : maTextWriter.writeTextPortion( pA->GetRect().TopLeft(), pA->GetText() );
3465 : }
3466 : }
3467 : }
3468 : }
3469 0 : break;
3470 :
3471 : case( META_TEXTARRAY_ACTION ):
3472 : {
3473 0 : if( nWriteFlags & SVGWRITER_WRITE_TEXT )
3474 : {
3475 0 : const MetaTextArrayAction* pA = static_cast<const MetaTextArrayAction*>(pAction);
3476 0 : const OUString aText = pA->GetText().copy( pA->GetIndex(), pA->GetLen() );
3477 :
3478 0 : if( !aText.isEmpty() )
3479 : {
3480 0 : if( mrExport.IsUsePositionedCharacters() )
3481 : {
3482 0 : vcl::Font aFont = ImplSetCorrectFontHeight();
3483 0 : mpContext->SetFontAttr( aFont );
3484 0 : ImplWriteText( pA->GetPoint(), aText, pA->GetDXArray(), 0 );
3485 : }
3486 : else
3487 : {
3488 0 : maTextWriter.writeTextPortion( pA->GetPoint(), aText );
3489 : }
3490 0 : }
3491 : }
3492 : }
3493 0 : break;
3494 :
3495 : case( META_STRETCHTEXT_ACTION ):
3496 : {
3497 0 : if( nWriteFlags & SVGWRITER_WRITE_TEXT )
3498 : {
3499 0 : const MetaStretchTextAction* pA = static_cast<const MetaStretchTextAction*>(pAction);
3500 0 : const OUString aText = pA->GetText().copy( pA->GetIndex(), pA->GetLen() );
3501 :
3502 0 : if( !aText.isEmpty() )
3503 : {
3504 0 : if( mrExport.IsUsePositionedCharacters() )
3505 : {
3506 0 : vcl::Font aFont = ImplSetCorrectFontHeight();
3507 0 : mpContext->SetFontAttr( aFont );
3508 0 : ImplWriteText( pA->GetPoint(), aText, NULL, pA->GetWidth() );
3509 : }
3510 : else
3511 : {
3512 0 : maTextWriter.writeTextPortion( pA->GetPoint(), aText );
3513 : }
3514 0 : }
3515 : }
3516 : }
3517 0 : break;
3518 :
3519 : case( META_CLIPREGION_ACTION ):
3520 : case( META_ISECTRECTCLIPREGION_ACTION ):
3521 : case( META_ISECTREGIONCLIPREGION_ACTION ):
3522 : case( META_MOVECLIPREGION_ACTION ):
3523 : {
3524 0 : ( (MetaAction*) pAction )->Execute( mpVDev );
3525 0 : mbClipAttrChanged = true;
3526 : }
3527 0 : break;
3528 :
3529 : case( META_REFPOINT_ACTION ):
3530 : case( META_MAPMODE_ACTION ):
3531 : case( META_LINECOLOR_ACTION ):
3532 : case( META_FILLCOLOR_ACTION ):
3533 : case( META_TEXTLINECOLOR_ACTION ):
3534 : case( META_TEXTFILLCOLOR_ACTION ):
3535 : case( META_TEXTCOLOR_ACTION ):
3536 : case( META_TEXTALIGN_ACTION ):
3537 : case( META_FONT_ACTION ):
3538 : case( META_PUSH_ACTION ):
3539 : case( META_POP_ACTION ):
3540 : case( META_LAYOUTMODE_ACTION ):
3541 : {
3542 0 : ( (MetaAction*) pAction )->Execute( mpVDev );
3543 : }
3544 0 : break;
3545 :
3546 : case( META_RASTEROP_ACTION ):
3547 : case( META_MASK_ACTION ):
3548 : case( META_MASKSCALE_ACTION ):
3549 : case( META_MASKSCALEPART_ACTION ):
3550 : case( META_WALLPAPER_ACTION ):
3551 : case( META_TEXTLINE_ACTION ):
3552 : {
3553 : // !!! >>> we don't want to support these actions
3554 : }
3555 0 : break;
3556 :
3557 : default:
3558 : OSL_FAIL( "SVGActionWriter::ImplWriteActions: unsupported MetaAction #" );
3559 0 : break;
3560 : }
3561 : }
3562 0 : }
3563 :
3564 0 : vcl::Font SVGActionWriter::ImplSetCorrectFontHeight() const
3565 : {
3566 0 : vcl::Font aFont( mpVDev->GetFont() );
3567 0 : Size aSz;
3568 :
3569 0 : ImplMap( Size( 0, aFont.GetHeight() ), aSz );
3570 :
3571 0 : aFont.SetHeight( aSz.Height() );
3572 :
3573 0 : return aFont;
3574 : }
3575 :
3576 0 : void SVGActionWriter::WriteMetaFile( const Point& rPos100thmm,
3577 : const Size& rSize100thmm,
3578 : const GDIMetaFile& rMtf,
3579 : sal_uInt32 nWriteFlags,
3580 : const OUString* pElementId,
3581 : const Reference< XShape >* pXShape,
3582 : const GDIMetaFile* pTextEmbeddedBitmapMtf )
3583 : {
3584 0 : MapMode aMapMode( rMtf.GetPrefMapMode() );
3585 0 : Size aPrefSize( rMtf.GetPrefSize() );
3586 0 : Fraction aFractionX( aMapMode.GetScaleX() );
3587 0 : Fraction aFractionY( aMapMode.GetScaleY() );
3588 :
3589 0 : mpVDev->Push();
3590 :
3591 0 : Size aSize( OutputDevice::LogicToLogic( rSize100thmm, MAP_100TH_MM, aMapMode ) );
3592 0 : aMapMode.SetScaleX( aFractionX *= Fraction( aSize.Width(), aPrefSize.Width() ) );
3593 0 : aMapMode.SetScaleY( aFractionY *= Fraction( aSize.Height(), aPrefSize.Height() ) );
3594 :
3595 0 : Point aOffset( OutputDevice::LogicToLogic( rPos100thmm, MAP_100TH_MM, aMapMode ) );
3596 0 : aMapMode.SetOrigin( aOffset += aMapMode.GetOrigin() );
3597 :
3598 0 : mpVDev->SetMapMode( aMapMode );
3599 0 : ImplAcquireContext();
3600 :
3601 0 : mapCurShape.reset();
3602 :
3603 0 : ImplWriteActions( rMtf, nWriteFlags, pElementId, pXShape, pTextEmbeddedBitmapMtf );
3604 0 : maTextWriter.endTextParagraph();
3605 :
3606 : // draw open shape that doesn't have a border
3607 0 : if( mapCurShape.get() )
3608 : {
3609 0 : ImplWriteShape( *mapCurShape );
3610 0 : mapCurShape.reset();
3611 : }
3612 :
3613 0 : ImplReleaseContext();
3614 0 : mpVDev->Pop();
3615 0 : }
3616 :
3617 :
3618 : // - SVGWriter -
3619 :
3620 :
3621 0 : SVGWriter::SVGWriter( const Sequence<Any>& args, const Reference< XComponentContext >& rxCtx )
3622 0 : : mxContext(rxCtx)
3623 : {
3624 0 : if(args.getLength()==1)
3625 0 : args[0]>>=maFilterData;
3626 0 : }
3627 :
3628 :
3629 :
3630 0 : SVGWriter::~SVGWriter()
3631 : {
3632 0 : }
3633 :
3634 :
3635 :
3636 0 : void SAL_CALL SVGWriter::write( const Reference<XDocumentHandler>& rxDocHandler,
3637 : const Sequence<sal_Int8>& rMtfSeq ) throw( RuntimeException, std::exception )
3638 : {
3639 0 : SvMemoryStream aMemStm( (char*) rMtfSeq.getConstArray(), rMtfSeq.getLength(), STREAM_READ );
3640 0 : GDIMetaFile aMtf;
3641 :
3642 0 : ReadGDIMetaFile( aMemStm, aMtf );
3643 :
3644 0 : const Reference< XDocumentHandler > xDocumentHandler( rxDocHandler );
3645 0 : boost::scoped_ptr<SVGExport> pWriter(new SVGExport( mxContext, xDocumentHandler, maFilterData ));
3646 0 : pWriter->writeMtf( aMtf );
3647 0 : }
3648 :
3649 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|