merge the formfield patch from ooo-build
[ooovba.git] / goodies / source / filter.vcl / icgm / actimpr.cxx
blob944b78dc32e1f571fdba7cd68cde59438aedf8a1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: actimpr.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_goodies.hxx"
33 #include <vcl/bitmapex.hxx>
34 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
35 #include <com/sun/star/drawing/LineStyle.hpp>
36 #include <com/sun/star/drawing/LineDash.hpp>
37 #include <com/sun/star/drawing/FillStyle.hpp>
38 #include <com/sun/star/drawing/Hatch.hpp>
39 #include <com/sun/star/awt/FontDescriptor.hpp>
40 #include <com/sun/star/awt/FontWeight.hpp>
41 #include <com/sun/star/awt/FontUnderline.hpp>
42 #include <com/sun/star/drawing/XShapeGrouper.hpp>
43 #include <com/sun/star/drawing/CircleKind.hpp>
44 #include <com/sun/star/awt/XBitmap.hpp>
45 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
46 #include <com/sun/star/drawing/PointSequence.hpp>
47 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
48 #include <com/sun/star/drawing/FlagSequence.hpp>
49 #include <com/sun/star/drawing/TextAdjust.hpp>
50 #include <com/sun/star/text/XText.hpp>
51 #include <com/sun/star/text/XTextRange.hpp>
52 #include <com/sun/star/style/HorizontalAlignment.hpp>
54 #include <unotools/processfactory.hxx>
55 #include <toolkit/helper/vclunohelper.hxx>
57 //#include <toolkit/unohlp.hxx>
59 #include "main.hxx"
60 #include "outact.hxx"
62 using namespace ::com::sun::star;
64 // ---------------------------------------------------------------
65 // ---------------------------------------------------------------
66 // ---------------------------------------------------------------
67 // ---------------------------------------------------------------
69 CGMImpressOutAct::CGMImpressOutAct( CGM& rCGM, const uno::Reference< frame::XModel > & rModel ) :
70 CGMOutAct ( rCGM ),
71 nFinalTextCount ( 0 )
73 sal_Bool bStatRet = sal_False;
75 if ( mpCGM->mbStatus )
77 uno::Reference< drawing::XDrawPagesSupplier > aDrawPageSup( rModel, uno::UNO_QUERY );
78 if( aDrawPageSup.is() )
80 maXDrawPages = aDrawPageSup->getDrawPages();
81 if ( maXDrawPages.is() )
83 maXServiceManagerSC = utl::getProcessServiceFactory();
84 if ( maXServiceManagerSC.is() )
86 uno::Any aAny( rModel->queryInterface( ::getCppuType((const uno::Reference< lang::XMultiServiceFactory >*)0) ));
87 if( aAny >>= maXMultiServiceFactory )
89 maXDrawPage = *(uno::Reference< drawing::XDrawPage > *)maXDrawPages->getByIndex( 0 ).getValue();
90 if ( ImplInitPage() )
91 bStatRet = sal_True;
96 mpCGM->mbStatus = bStatRet;
100 // ---------------------------------------------------------------
102 sal_Bool CGMImpressOutAct::ImplInitPage()
104 sal_Bool bStatRet = sal_False;
105 if( maXDrawPage.is() )
107 maXShapes = uno::Reference< drawing::XShapes >( maXDrawPage, uno::UNO_QUERY );
108 if ( maXShapes.is() )
110 bStatRet = sal_True;
113 return bStatRet;
116 // ---------------------------------------------------------------
118 sal_Bool CGMImpressOutAct::ImplCreateShape( const ::rtl::OUString& rType )
120 uno::Reference< uno::XInterface > xNewShape( maXMultiServiceFactory->createInstance( rType ) );
121 maXShape = uno::Reference< drawing::XShape >( xNewShape, uno::UNO_QUERY );
122 maXPropSet = uno::Reference< beans::XPropertySet >( xNewShape, uno::UNO_QUERY );
123 if ( maXShape.is() && maXPropSet.is() )
125 maXShapes->add( maXShape );
126 return sal_True;
128 return sal_False;
131 // ---------------------------------------------------------------
133 void CGMImpressOutAct::ImplSetOrientation( FloatPoint& rRefPoint, double& rOrientation )
135 uno::Any aAny;
136 aAny <<= (sal_Int32)rRefPoint.X;
137 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("RotationPointX"), aAny );
138 aAny <<= (sal_Int32)rRefPoint.Y;
139 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("RotationPointY"), aAny );
140 aAny <<= (sal_Int32)( rOrientation * 100.0 );
141 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("RotateAngle"), aAny );
144 // ---------------------------------------------------------------
146 void CGMImpressOutAct::ImplSetLineBundle()
148 uno::Any aAny;
149 drawing::LineStyle eLS;
151 sal_uInt32 nLineColor;
152 LineType eLineType;
153 double fLineWidth;
155 if ( mpCGM->pElement->nAspectSourceFlags & ASF_LINECOLOR )
156 nLineColor = mpCGM->pElement->pLineBundle->GetColor();
157 else
158 nLineColor = mpCGM->pElement->aLineBundle.GetColor();
159 if ( mpCGM->pElement->nAspectSourceFlags & ASF_LINETYPE )
160 eLineType = mpCGM->pElement->pLineBundle->eLineType;
161 else
162 eLineType = mpCGM->pElement->aLineBundle.eLineType;
163 if ( mpCGM->pElement->nAspectSourceFlags & ASF_LINEWIDTH )
164 fLineWidth = mpCGM->pElement->pLineBundle->nLineWidth;
165 else
166 fLineWidth = mpCGM->pElement->aLineBundle.nLineWidth;
168 aAny <<= (sal_Int32)nLineColor;
169 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("LineColor"), aAny );
171 aAny <<= (sal_Int32)fLineWidth;
172 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("LineWidth"), aAny );
174 switch( eLineType )
176 case LT_NONE :
177 eLS = drawing::LineStyle_NONE;
178 break;
179 case LT_DASH :
180 case LT_DOT :
181 case LT_DASHDOT :
182 case LT_DOTDOTSPACE :
183 case LT_LONGDASH :
184 case LT_DASHDASHDOT :
185 eLS = drawing::LineStyle_DASH;
186 break;
187 case LT_SOLID :
188 default:
189 eLS = drawing::LineStyle_SOLID;
190 break;
192 aAny <<= eLS;
193 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("LineStyle"), aAny );
194 if ( eLS == drawing::LineStyle_DASH )
196 drawing::LineDash aLineDash( drawing::DashStyle_RECTRELATIVE, 1, 50, 3, 33, 100 );
197 aAny <<= aLineDash;
198 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("LineDash"), aAny );
202 // ---------------------------------------------------------------
204 void CGMImpressOutAct::ImplSetFillBundle()
207 uno::Any aAny;
208 drawing::LineStyle eLS;
209 drawing::FillStyle eFS;
211 sal_uInt32 nEdgeColor = 0;
212 EdgeType eEdgeType;
213 double fEdgeWidth = 0;
215 sal_uInt32 nFillColor;
216 FillInteriorStyle eFillStyle;
217 long nPatternIndex;
218 sal_uInt32 nHatchIndex;
220 if ( mpCGM->pElement->eEdgeVisibility == EV_ON )
222 if ( mpCGM->pElement->nAspectSourceFlags & ASF_EDGETYPE )
223 eEdgeType = mpCGM->pElement->pEdgeBundle->eEdgeType;
224 else
225 eEdgeType = mpCGM->pElement->aEdgeBundle.eEdgeType;
226 if ( mpCGM->pElement->nAspectSourceFlags & ASF_EDGEWIDTH )
227 fEdgeWidth = mpCGM->pElement->pEdgeBundle->nEdgeWidth;
228 else
229 fEdgeWidth = mpCGM->pElement->aEdgeBundle.nEdgeWidth;
230 if ( mpCGM->pElement->nAspectSourceFlags & ASF_EDGECOLOR )
231 nEdgeColor = mpCGM->pElement->pEdgeBundle->GetColor();
232 else
233 nEdgeColor = mpCGM->pElement->aEdgeBundle.GetColor();
235 else
236 eEdgeType = ET_NONE;
238 if ( mpCGM->pElement->nAspectSourceFlags & ASF_FILLINTERIORSTYLE )
239 eFillStyle = mpCGM->pElement->pFillBundle->eFillInteriorStyle;
240 else
241 eFillStyle = mpCGM->pElement->aFillBundle.eFillInteriorStyle;
242 if ( mpCGM->pElement->nAspectSourceFlags & ASF_FILLCOLOR )
243 nFillColor = mpCGM->pElement->pFillBundle->GetColor();
244 else
245 nFillColor = mpCGM->pElement->aFillBundle.GetColor();
246 if ( mpCGM->pElement->nAspectSourceFlags & ASF_HATCHINDEX )
247 nHatchIndex = (sal_uInt32)mpCGM->pElement->pFillBundle->nFillHatchIndex;
248 else
249 nHatchIndex = (sal_uInt32)mpCGM->pElement->aFillBundle.nFillHatchIndex;
250 if ( mpCGM->pElement->nAspectSourceFlags & ASF_PATTERNINDEX )
251 nPatternIndex = mpCGM->pElement->pFillBundle->nFillPatternIndex;
252 else
253 nPatternIndex = mpCGM->pElement->aFillBundle.nFillPatternIndex;
255 aAny <<= (sal_Int32)nFillColor;
256 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("FillColor"), aAny );
258 switch ( eFillStyle )
260 case FIS_HATCH :
262 if ( nHatchIndex == 0 )
263 eFS = drawing::FillStyle_NONE;
264 else
265 eFS = drawing::FillStyle_HATCH;
267 break;
268 case FIS_PATTERN :
269 case FIS_SOLID :
271 eFS = drawing::FillStyle_SOLID;
273 break;
275 case FIS_GEOPATTERN :
277 if ( mpCGM->pElement->eTransparency == T_ON )
278 nFillColor = mpCGM->pElement->nAuxiliaryColor;
279 eFS = drawing::FillStyle_NONE;
281 break;
283 case FIS_INTERPOLATED :
284 case FIS_GRADIENT :
286 eFS = drawing::FillStyle_GRADIENT;
288 break;
290 case FIS_HOLLOW :
291 case FIS_EMPTY :
292 default:
294 eFS = drawing::FillStyle_NONE;
298 if ( mpCGM->mnAct4PostReset & ACT4_GRADIENT_ACTION )
299 eFS = drawing::FillStyle_GRADIENT;
301 if ( eFS == drawing::FillStyle_GRADIENT )
303 aAny <<= *mpGradient;
304 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("FillGradient"), aAny );
306 aAny <<= eFS;
307 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("FillStyle"), aAny );
309 eLS = drawing::LineStyle_NONE;
310 if ( eFillStyle == FIS_HOLLOW )
312 eLS = drawing::LineStyle_SOLID;
313 aAny <<= (sal_Int32)nFillColor;
314 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("LineColor"), aAny );
315 aAny <<= (sal_Int32)0;
316 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("LineWidth"), aAny );
318 else if ( eEdgeType != ET_NONE )
320 aAny <<= (sal_Int32)nEdgeColor;
321 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("LineColor"), aAny );
323 aAny <<= (sal_Int32)fEdgeWidth;
324 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("LineWidth"), aAny );
326 switch( eEdgeType )
328 case ET_DASH :
329 case ET_DOT :
330 case ET_DASHDOT :
331 case ET_DASHDOTDOT :
332 case ET_DOTDOTSPACE :
333 case ET_LONGDASH :
334 case ET_DASHDASHDOT :
335 // {
336 // eLS = LineStyle_DASH;
337 // aAny.setValue( &eLS, ::getCppuType((const drawing::LineStyle*)0) );
338 // maXPropSet->setPropertyValue( L"LineStyle", aAny );
339 // drawing::LineDash aLineDash( DashStyle_RECTRELATIVE, 1, 160, 1, 160, 190 );
340 // aAny.setValue( &aLineDash, ::getCppuType((const drawing::LineDash*)0) );
341 // maXPropSet->setPropertyValue( L"DashStyle", aAny );
342 // }
343 // break;
344 default: // case ET_SOLID :
346 eLS = drawing::LineStyle_SOLID;
348 break;
352 aAny <<= eLS;
353 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("LineStyle"), aAny );
355 if ( eFS == drawing::FillStyle_HATCH )
357 drawing::Hatch aHatch;
359 if ( mpCGM->pElement->nAspectSourceFlags & ASF_LINECOLOR )
360 aHatch.Color = nFillColor;
361 else
362 aHatch.Color = nFillColor;
363 HatchEntry* pHatchEntry = (HatchEntry*)mpCGM->pElement->aHatchTable.Get( nHatchIndex );
364 if ( pHatchEntry )
366 switch ( pHatchEntry->HatchStyle )
368 case 0 : aHatch.Style = drawing::HatchStyle_SINGLE; break;
369 case 1 : aHatch.Style = drawing::HatchStyle_DOUBLE; break;
370 case 2 : aHatch.Style = drawing::HatchStyle_TRIPLE; break;
372 aHatch.Distance = pHatchEntry->HatchDistance;
373 aHatch.Angle = pHatchEntry->HatchAngle;
375 else
377 aHatch.Style = drawing::HatchStyle_TRIPLE;
378 aHatch.Distance = 10 * ( nHatchIndex & 0x1f ) | 100;
379 aHatch.Angle = 15 * ( ( nHatchIndex & 0x1f ) - 5 );
381 aAny <<= aHatch;
382 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("FillHatch"), aAny );
386 // ---------------------------------------------------------------
388 void CGMImpressOutAct::ImplSetTextBundle( const uno::Reference< beans::XPropertySet > & rProperty )
390 uno::Any aAny;
391 TextPrecision eTextPrecision;
392 sal_uInt32 nTextFontIndex;
393 sal_uInt32 nTextColor;
394 double fCharacterExpansion;
395 double fCharacterSpacing;
397 if ( mpCGM->pElement->nAspectSourceFlags & ASF_TEXTFONTINDEX )
398 nTextFontIndex = mpCGM->pElement->pTextBundle->nTextFontIndex;
399 else
400 nTextFontIndex = mpCGM->pElement->aTextBundle.nTextFontIndex;
401 if ( mpCGM->pElement->nAspectSourceFlags & ASF_TEXTPRECISION )
402 eTextPrecision = mpCGM->pElement->pTextBundle->eTextPrecision;
403 else
404 eTextPrecision = mpCGM->pElement->aTextBundle.eTextPrecision;
405 if ( mpCGM->pElement->nAspectSourceFlags & ASF_CHARACTEREXPANSION )
406 fCharacterExpansion = mpCGM->pElement->pTextBundle->nCharacterExpansion;
407 else
408 fCharacterExpansion = mpCGM->pElement->aTextBundle.nCharacterExpansion;
409 if ( mpCGM->pElement->nAspectSourceFlags & ASF_CHARACTERSPACING )
410 fCharacterSpacing = mpCGM->pElement->pTextBundle->nCharacterSpacing;
411 else
412 fCharacterSpacing = mpCGM->pElement->aTextBundle.nCharacterSpacing;
413 if ( mpCGM->pElement->nAspectSourceFlags & ASF_TEXTCOLOR )
414 nTextColor = mpCGM->pElement->pTextBundle->GetColor();
415 else
416 nTextColor = mpCGM->pElement->aTextBundle.GetColor();
418 aAny <<= (sal_Int32)nTextColor;
419 rProperty->setPropertyValue( rtl::OUString::createFromAscii("CharColor"), aAny );
421 sal_uInt32 nFontType = 0;
422 awt::FontDescriptor aFontDescriptor;
423 FontEntry* pFontEntry = mpCGM->pElement->aFontList.GetFontEntry( nTextFontIndex );
424 if ( pFontEntry )
426 nFontType = pFontEntry->nFontType;
427 aFontDescriptor.Name = String::CreateFromAscii( (char*)pFontEntry->pFontName );
429 aFontDescriptor.Height = ( sal_Int16 )( ( mpCGM->pElement->nCharacterHeight * (double)1.50 ) );
430 if ( nFontType & 1 )
431 aFontDescriptor.Slant = awt::FontSlant_ITALIC;
432 if ( nFontType & 2 )
433 aFontDescriptor.Weight = awt::FontWeight::BOLD;
434 else
435 aFontDescriptor.Weight = awt::FontWeight::NORMAL;
437 if ( mpCGM->pElement->eUnderlineMode != UM_OFF )
439 aFontDescriptor.Underline = awt::FontUnderline::SINGLE;
441 aAny <<= aFontDescriptor;
442 rProperty->setPropertyValue( rtl::OUString::createFromAscii("FontDescriptor"), aAny );
445 // ---------------------------------------------------------------
447 void CGMImpressOutAct::InsertPage()
449 if ( mnCurrentPage ) // eine seite ist immer vorhanden, deshalb wird die erste Seite ausgelassen
451 uno::Reference< drawing::XDrawPage > xPage( maXDrawPages->insertNewByIndex( 0xffff ), uno::UNO_QUERY );
452 maXDrawPage = xPage;
453 if ( ImplInitPage() == sal_False )
454 mpCGM->mbStatus = sal_False;
456 mnCurrentPage++;
459 // ---------------------------------------------------------------
461 void CGMImpressOutAct::BeginGroup()
463 if ( mnGroupLevel < CGM_OUTACT_MAX_GROUP_LEVEL )
465 mpGroupLevel[ mnGroupLevel ] = maXShapes->getCount();
467 mnGroupLevel++;
468 mnGroupActCount = mpCGM->mnActCount;
471 // ---------------------------------------------------------------
473 void CGMImpressOutAct::EndGroup()
475 if ( mnGroupLevel ) // preserve overflow
476 mnGroupLevel--;
477 if ( mnGroupLevel < CGM_OUTACT_MAX_GROUP_LEVEL )
479 sal_uInt32 mnFirstIndex = mpGroupLevel[ mnGroupLevel ];
480 if ( mnFirstIndex == 0xffffffff )
481 mnFirstIndex = 0;
482 sal_uInt32 mnCurrentCount = maXShapes->getCount();
483 if ( ( mnCurrentCount - mnFirstIndex ) > 1 )
485 uno::Reference< drawing::XShapeGrouper > aXShapeGrouper;
486 uno::Any aAny( maXDrawPage->queryInterface( ::getCppuType(((const uno::Reference< drawing::XShapeGrouper >*)0) )));
487 if( aAny >>= aXShapeGrouper )
489 uno::Reference< drawing::XShapes > aXShapes;
490 // if ( maXServiceManagerSC->createInstance( L"stardiv.one.drawing.ShapeCollection" )->queryInterface( ::getCppuType((const Reference< drawing::XShapes >*)0), aXShapes ) )
492 uno::Reference< drawing::XShape > aXShapeCollection( maXServiceManagerSC->createInstance( rtl::OUString::createFromAscii("com.sun.star.drawing.ShapeCollection") ), uno::UNO_QUERY );
493 if ( aXShapeCollection.is() )
495 aXShapes = uno::Reference< drawing::XShapes >( aXShapeCollection, uno::UNO_QUERY );
496 if( aXShapes.is() )
498 for ( sal_uInt32 i = mnFirstIndex; i < mnCurrentCount; i++ )
500 uno::Reference< drawing::XShape > aXShape = *(uno::Reference< drawing::XShape > *)maXShapes->getByIndex( i ).getValue();
501 if (aXShape.is() )
503 aXShapes->add( aXShape );
508 uno::Reference< drawing::XShapeGroup > aXShapeGroup = aXShapeGrouper->group( aXShapes );
514 // ---------------------------------------------------------------
516 void CGMImpressOutAct::EndGrouping()
518 while ( mnGroupLevel )
520 EndGroup();
524 // ---------------------------------------------------------------
526 void CGMImpressOutAct::DrawRectangle( FloatRect& rFloatRect )
528 if ( mnGroupActCount != ( mpCGM->mnActCount - 1 ) ) // POWERPOINT HACK !!!
530 if ( ImplCreateShape( rtl::OUString::createFromAscii("com.sun.star.drawing.RectangleShape") ) )
532 awt::Size aSize( (long)(rFloatRect.Right - rFloatRect.Left ), (long)(rFloatRect.Bottom-rFloatRect.Top ) );
533 maXShape->setSize( aSize );
534 maXShape->setPosition( awt::Point( (long)rFloatRect.Left, (long)rFloatRect.Top ) );
535 ImplSetFillBundle();
540 // ---------------------------------------------------------------
542 void CGMImpressOutAct::DrawEllipse( FloatPoint& rCenter, FloatPoint& rSize, double& rOrientation )
544 if ( ImplCreateShape( rtl::OUString::createFromAscii("com.sun.star.drawing.EllipseShape") ) )
546 drawing::CircleKind eCircleKind = drawing::CircleKind_FULL;
547 uno::Any aAny( &eCircleKind, ::getCppuType((const drawing::CircleKind*)0) );
548 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("CircleKind"), aAny );
550 long nXSize = (long)( rSize.X * 2.0 ); // Merkwuerdigkes Verhalten bei einer awt::Size von 0
551 long nYSize = (long)( rSize.Y * 2.0 );
552 if ( nXSize < 1 )
553 nXSize = 1;
554 if ( nYSize < 1 )
555 nYSize = 1;
556 maXShape->setSize( awt::Size( nXSize, nYSize ) );
557 maXShape->setPosition( awt::Point( (long)( rCenter.X - rSize.X ), (long)( rCenter.Y - rSize.Y ) ) );
559 if ( rOrientation != 0 )
561 ImplSetOrientation( rCenter, rOrientation );
563 ImplSetFillBundle();
567 // ---------------------------------------------------------------
569 void CGMImpressOutAct::DrawEllipticalArc( FloatPoint& rCenter, FloatPoint& rSize, double& rOrientation,
570 sal_uInt32 nType, double& fStartAngle, double& fEndAngle )
572 if ( ImplCreateShape( rtl::OUString::createFromAscii("com.sun.star.drawing.EllipseShape") ) )
574 uno::Any aAny;
575 drawing::CircleKind eCircleKind;
578 long nXSize = (long)( rSize.X * 2.0 ); // Merkwuerdigkes Verhalten bei einer awt::Size von 0
579 long nYSize = (long)( rSize.Y * 2.0 );
580 if ( nXSize < 1 )
581 nXSize = 1;
582 if ( nYSize < 1 )
583 nYSize = 1;
585 maXShape->setSize( awt::Size ( nXSize, nYSize ) );
587 if ( rOrientation != 0 )
589 fStartAngle += rOrientation;
590 if ( fStartAngle >= 360 )
591 fStartAngle -= 360;
592 fEndAngle += rOrientation;
593 if ( fEndAngle >= 360 )
594 fEndAngle -= 360;
596 switch( nType )
598 case 0 : eCircleKind = drawing::CircleKind_SECTION; break;
599 case 1 : eCircleKind = drawing::CircleKind_CUT; break;
600 case 2 : eCircleKind = drawing::CircleKind_ARC; break;
601 default : eCircleKind = drawing::CircleKind_FULL; break;
603 if ( (long)fStartAngle == (long)fEndAngle )
605 eCircleKind = drawing::CircleKind_FULL;
606 aAny.setValue( &eCircleKind, ::getCppuType((const drawing::CircleKind*)0) );
608 else
610 aAny.setValue( &eCircleKind, ::getCppuType((const drawing::CircleKind*)0) );
611 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("CircleKind"), aAny );
612 aAny <<= (sal_Int32)( (long)( fStartAngle * 100 ) );
613 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("CircleStartAngle"), aAny );
614 aAny <<= (sal_Int32)( (long)( fEndAngle * 100 ) );
615 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("CircleEndAngle"), aAny );
617 maXShape->setPosition( awt::Point( (long)( rCenter.X - rSize.X ), (long)( rCenter.Y - rSize.Y ) ) );
618 if ( rOrientation != 0 )
620 ImplSetOrientation( rCenter, rOrientation );
622 if ( eCircleKind == drawing::CircleKind_ARC )
624 ImplSetLineBundle();
626 else
628 ImplSetFillBundle();
629 if ( nType == 2 )
631 ImplSetLineBundle();
632 drawing::FillStyle eFillStyle = drawing::FillStyle_NONE;
633 aAny.setValue( &eFillStyle, ::getCppuType((const drawing::FillStyle*)0) );
634 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("FillStyle"), aAny );
640 // ---------------------------------------------------------------
642 void CGMImpressOutAct::DrawBitmap( CGMBitmapDescriptor* pBmpDesc )
644 if ( pBmpDesc->mbStatus && pBmpDesc->mpBitmap )
646 FloatPoint aOrigin = pBmpDesc->mnOrigin;
647 double fdx = pBmpDesc->mndx;
648 double fdy = pBmpDesc->mndy;
650 sal_uInt32 nMirr = BMP_MIRROR_NONE;
651 if ( pBmpDesc->mbVMirror )
652 nMirr |= BMP_MIRROR_VERT;
653 if ( pBmpDesc->mbHMirror )
654 nMirr |= BMP_MIRROR_HORZ;
655 if ( nMirr != BMP_MIRROR_NONE )
656 pBmpDesc->mpBitmap->Mirror( nMirr );
658 mpCGM->ImplMapPoint( aOrigin );
659 mpCGM->ImplMapX( fdx );
660 mpCGM->ImplMapY( fdy );
662 if ( ImplCreateShape( rtl::OUString::createFromAscii("com.sun.star.drawing.GraphicObjectShape") ) )
664 maXShape->setSize( awt::Size( (long)fdx, (long)fdy ) );
665 maXShape->setPosition( awt::Point( (long)aOrigin.X, (long)aOrigin.Y ) );
667 if ( pBmpDesc->mnOrientation != 0 )
669 ImplSetOrientation( aOrigin, pBmpDesc->mnOrientation );
672 uno::Reference< awt::XBitmap > xBitmap( VCLUnoHelper::CreateBitmap( BitmapEx( *( pBmpDesc->mpBitmap ) ) ) );
673 uno::Any aAny;
674 aAny <<= xBitmap;
675 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("GraphicObjectFillBitmap"), aAny );
681 // ---------------------------------------------------------------
683 void CGMImpressOutAct::DrawPolygon( Polygon& rPoly )
685 sal_uInt16 nPoints = rPoly.GetSize();
687 if ( ( nPoints > 1 ) && ImplCreateShape( rtl::OUString::createFromAscii("com.sun.star.drawing.PolyPolygonShape") ) )
689 drawing::PointSequenceSequence aRetval;
691 // Polygone innerhalb vrobereiten
692 aRetval.realloc( 1 );
694 // Zeiger auf aeussere Arrays holen
695 drawing::PointSequence* pOuterSequence = aRetval.getArray();
697 // Platz in Arrays schaffen
698 pOuterSequence->realloc((sal_Int32)nPoints);
700 // Pointer auf arrays holen
701 awt::Point* pInnerSequence = pOuterSequence->getArray();
703 for( sal_uInt16 n = 0; n < nPoints; n++ )
704 *pInnerSequence++ = awt::Point( rPoly[ n ].X(), rPoly[n].Y() );
706 uno::Any aParam;
707 aParam <<= aRetval;
708 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("PolyPolygon"), aParam );
709 ImplSetFillBundle();
714 // ---------------------------------------------------------------
716 void CGMImpressOutAct::DrawPolyLine( Polygon& rPoly )
718 sal_uInt16 nPoints = rPoly.GetSize();
720 if ( ( nPoints > 1 ) && ImplCreateShape( rtl::OUString::createFromAscii("com.sun.star.drawing.PolyLineShape") ) )
722 drawing::PointSequenceSequence aRetval;
724 // Polygone innerhalb vrobereiten
725 aRetval.realloc( 1 );
727 // Zeiger auf aeussere Arrays holen
728 drawing::PointSequence* pOuterSequence = aRetval.getArray();
730 // Platz in Arrays schaffen
731 pOuterSequence->realloc((sal_Int32)nPoints);
733 // Pointer auf arrays holen
734 awt::Point* pInnerSequence = pOuterSequence->getArray();
736 for( sal_uInt16 n = 0; n < nPoints; n++ )
737 *pInnerSequence++ = awt::Point( rPoly[ n ].X(), rPoly[n].Y() );
739 uno::Any aParam;
740 aParam <<= aRetval;
741 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("PolyPolygon"), aParam );
742 ImplSetLineBundle();
746 // ---------------------------------------------------------------
748 void CGMImpressOutAct::DrawPolybezier( Polygon& rPolygon )
750 USHORT nPoints = rPolygon.GetSize();
751 if ( ( nPoints > 1 ) && ImplCreateShape( rtl::OUString::createFromAscii("com.sun.star.drawing.OpenBezierShape") ) )
753 drawing::PolyPolygonBezierCoords aRetval;
755 aRetval.Coordinates.realloc( 1 );
756 aRetval.Flags.realloc( 1 );
758 // Zeiger auf aeussere Arrays holen
759 drawing::PointSequence* pOuterSequence = aRetval.Coordinates.getArray();
760 drawing::FlagSequence* pOuterFlags = aRetval.Flags.getArray();
762 // Platz in Arrays schaffen
763 pOuterSequence->realloc( nPoints );
764 pOuterFlags->realloc( nPoints );
766 awt::Point* pInnerSequence = pOuterSequence->getArray();
767 drawing::PolygonFlags* pInnerFlags = pOuterFlags->getArray();
769 for( USHORT i = 0; i < nPoints; i++ )
771 *pInnerSequence++ = awt::Point( rPolygon[ i ].X(), rPolygon[ i ].Y() );
772 *pInnerFlags++ = (drawing::PolygonFlags)rPolygon.GetFlags( i );
774 uno::Any aParam;
775 aParam <<= aRetval;
776 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("PolyPolygonBezier"), aParam );
777 ImplSetLineBundle();
781 // ---------------------------------------------------------------
783 void CGMImpressOutAct::DrawPolyPolygon( PolyPolygon& rPolyPolygon )
785 sal_uInt32 nNumPolys = rPolyPolygon.Count();
786 if ( nNumPolys && ImplCreateShape( rtl::OUString::createFromAscii("com.sun.star.drawing.ClosedBezierShape") ) )
788 drawing::PolyPolygonBezierCoords aRetval;
790 // Polygone innerhalb vrobereiten
791 aRetval.Coordinates.realloc((sal_Int32)nNumPolys);
792 aRetval.Flags.realloc((sal_Int32)nNumPolys);
794 // Zeiger auf aeussere Arrays holen
795 drawing::PointSequence* pOuterSequence = aRetval.Coordinates.getArray();
796 drawing::FlagSequence* pOuterFlags = aRetval.Flags.getArray();
798 for( sal_uInt16 a = 0; a < nNumPolys; a++ )
800 Polygon aPolygon( rPolyPolygon.GetObject( a ) );
801 sal_uInt32 nNumPoints = aPolygon.GetSize();
803 // Platz in Arrays schaffen
804 pOuterSequence->realloc((sal_Int32)nNumPoints);
805 pOuterFlags->realloc((sal_Int32)nNumPoints);
807 // Pointer auf arrays holen
808 awt::Point* pInnerSequence = pOuterSequence->getArray();
809 drawing::PolygonFlags* pInnerFlags = pOuterFlags->getArray();
811 for( sal_uInt16 b = 0; b < nNumPoints; b++ )
813 *pInnerSequence++ = awt::Point( aPolygon.GetPoint( b ).X(), aPolygon.GetPoint( b ).Y() ) ;
814 *pInnerFlags++ = (drawing::PolygonFlags)aPolygon.GetFlags( b );
816 pOuterSequence++;
817 pOuterFlags++;
819 uno::Any aParam;
820 aParam <<= aRetval;
821 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("PolyPolygonBezier"), aParam);
822 ImplSetFillBundle();
826 // ---------------------------------------------------------------
828 void CGMImpressOutAct::DrawText( awt::Point& rTextPos, awt::Size& rTextSize, char* pString, sal_uInt32 /*nSize*/, FinalFlag eFlag )
830 if ( ImplCreateShape( rtl::OUString::createFromAscii("com.sun.star.drawing.TextShape") ) )
832 uno::Any aAny;
833 long nWidth = rTextSize.Width;
834 long nHeight = rTextSize.Height;
836 awt::Point aTextPos( rTextPos );
837 switch ( mpCGM->pElement->eTextAlignmentV )
839 case TAV_HALF :
841 aTextPos.Y -= static_cast<sal_Int32>( ( mpCGM->pElement->nCharacterHeight * 1.5 ) / 2 );
843 break;
845 case TAV_BASE :
846 case TAV_BOTTOM :
847 case TAV_NORMAL :
848 aTextPos.Y -= static_cast<sal_Int32>( mpCGM->pElement->nCharacterHeight * 1.5 );
849 case TAV_TOP :
850 break;
851 case TAV_CAP:
852 case TAV_CONT:
853 break; // -Wall these two were not here.
856 if ( nWidth < 0 )
858 nWidth = -nWidth;
860 else if ( nWidth == 0 )
862 nWidth = -1;
864 if ( nHeight < 0 )
866 nHeight = -nHeight;
868 else if ( nHeight == 0 )
870 nHeight = -1;
872 maXShape->setPosition( aTextPos );
873 maXShape->setSize( awt::Size( nWidth, nHeight ) );
874 double nX = mpCGM->pElement->nCharacterOrientation[ 2 ];
875 double nY = mpCGM->pElement->nCharacterOrientation[ 3 ];
876 double nOrientation = acos( nX / sqrt( nX * nX + nY * nY ) ) * 57.29577951308;
877 if ( nY < 0 )
878 nOrientation = 360 - nOrientation;
880 if ( nOrientation )
882 aAny <<= (sal_Int32)( aTextPos.X );
883 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("RotationPointX"), aAny );
884 aAny <<= (sal_Int32)( aTextPos.Y + nHeight );
885 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("RotationPointY"), aAny );
886 aAny <<= (sal_Int32)( (sal_Int32)( nOrientation * 100 ) );
887 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("RotateAngle"), aAny );
889 if ( nWidth == -1 )
891 sal_Bool bTrue( sal_True );
892 aAny.setValue( &bTrue, ::getCppuType((const sal_Bool*)0 ));
893 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("TextAutoGrowWidth"), aAny );
895 drawing::TextAdjust eTextAdjust;
896 switch ( mpCGM->pElement->eTextAlignmentH )
898 case TAH_RIGHT :
899 eTextAdjust = drawing::TextAdjust_RIGHT;
900 break;
901 case TAH_LEFT :
902 case TAH_CONT :
903 case TAH_NORMAL :
904 eTextAdjust = drawing::TextAdjust_LEFT;
905 break;
906 case TAH_CENTER :
907 eTextAdjust = drawing::TextAdjust_CENTER;
908 break;
910 aAny <<= eTextAdjust;
911 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("TextHorizontalAdjust"), aAny );
913 if ( nHeight == -1 )
915 sal_Bool bTrue = sal_True;
916 aAny.setValue( &bTrue, ::getCppuType((const sal_Bool*)0) );
917 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("TextAutoGrowHeight"), aAny );
919 uno::Reference< text::XText > xText;
920 uno::Any aFirstQuery( maXShape->queryInterface( ::getCppuType((const uno::Reference< text::XText >*)0) ));
921 if( aFirstQuery >>= xText )
923 String aStr( String::CreateFromAscii( pString ) );
925 uno::Reference< text::XTextCursor > aXTextCursor( xText->createTextCursor() );
927 aXTextCursor->gotoEnd( sal_False );
928 uno::Reference< text::XTextRange > aCursorText;
929 uno::Any aSecondQuery( aXTextCursor->queryInterface( ::getCppuType((const uno::Reference< text::XTextRange >*)0) ));
930 if ( aSecondQuery >>= aCursorText )
932 uno::Reference< beans::XPropertySet > aCursorPropSet;
934 uno::Any aQuery( aCursorText->queryInterface( ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) ));
935 if( aQuery >>= aCursorPropSet )
937 if ( nWidth != -1 ) // paragraph adjusting in a valid textbox ?
939 switch ( mpCGM->pElement->eTextAlignmentH )
941 case TAH_RIGHT :
942 aAny <<= (sal_Int16)style::HorizontalAlignment_RIGHT;
943 break;
944 case TAH_LEFT :
945 case TAH_CONT :
946 case TAH_NORMAL :
947 aAny <<= (sal_Int16)style::HorizontalAlignment_LEFT;
948 break;
949 case TAH_CENTER :
950 aAny <<= (sal_Int16)style::HorizontalAlignment_CENTER;
951 break;
953 aCursorPropSet->setPropertyValue( rtl::OUString::createFromAscii("ParaAdjust"), aAny );
955 if ( nWidth > 0 && nHeight > 0 ) // restricted text
957 sal_Bool bTrue = sal_True;
958 aAny.setValue( &bTrue, ::getCppuType((const sal_Bool*)0));
959 maXPropSet->setPropertyValue( rtl::OUString::createFromAscii("TextFitToSize"), aAny );
961 aCursorText->setString( aStr );
962 aXTextCursor->gotoEnd( sal_True );
963 ImplSetTextBundle( aCursorPropSet );
968 if ( eFlag == FF_NOT_FINAL )
970 nFinalTextCount = maXShapes->getCount();
975 // ---------------------------------------------------------------
977 void CGMImpressOutAct::AppendText( char* pString, sal_uInt32 /*nSize*/, FinalFlag /*eFlag*/ )
979 if ( nFinalTextCount )
981 uno::Reference< drawing::XShape > aShape = *(uno::Reference< drawing::XShape > *)maXShapes->getByIndex( nFinalTextCount - 1 ).getValue();
982 if ( aShape.is() )
984 uno::Reference< text::XText > xText;
985 uno::Any aFirstQuery( aShape->queryInterface( ::getCppuType((const uno::Reference< text::XText >*)0)) );
986 if( aFirstQuery >>= xText )
988 String aStr( String::CreateFromAscii( pString ) );
990 uno::Reference< text::XTextCursor > aXTextCursor( xText->createTextCursor() );
991 if ( aXTextCursor.is() )
993 aXTextCursor->gotoEnd( sal_False );
994 uno::Reference< text::XTextRange > aCursorText;
995 uno::Any aSecondQuery(aXTextCursor->queryInterface( ::getCppuType((const uno::Reference< text::XTextRange >*)0) ));
996 if ( aSecondQuery >>= aCursorText )
998 uno::Reference< beans::XPropertySet > aPropSet;
999 uno::Any aQuery(aCursorText->queryInterface( ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) ));
1000 if( aQuery >>= aPropSet )
1002 aCursorText->setString( aStr );
1003 aXTextCursor->gotoEnd( sal_True );
1004 ImplSetTextBundle( aPropSet );
1013 // ---------------------------------------------------------------
1014 // nCount != 0 -> Append Text
1015 sal_uInt32 CGMImpressOutAct::DrawText( TextEntry* /*pTextEntry*/, NodeFrameSet& /*rNodeFrameSet*/, sal_uInt32 /*nObjCount*/ )
1018 return 0;
1021 uno::Reference< drawing::XShape > aShape;
1023 if ( nObjCount )
1025 aShape = (drawing::XShape*) maXShapes->getElementByIndex( nObjCount - 1 )->queryInterface( ::getCppuType((const Reference< drawing::XShape >*)0) );
1027 else
1029 aShape = maXShapes->insertShape( maXShapeFactory->createShape( L"ShapeText", rNodeFrameSet.nSize ), rNodeFrameSet.nTopLeft );
1031 if ( aShape.is() )
1033 uno::Reference< text::XText > xText = (text::XText*)aShape->queryInterface( ::getCppuType((const Reference< text::XText >*)0) );
1034 if ( xText.is() )
1036 uno::Reference< text::XTextCursor > aXTextCursor = (text::XTextCursor*)xText->createTextCursor()->queryInterface( ::getCppuType((const Reference< text::XTextCursor >*)0) );
1037 if ( aXTextCursor.is() )
1039 uno::Any aAny;
1040 sal_uInt32 nTextOfs = 0;
1041 TextAttribute* pTAttr = pTextEntry->pAttribute;
1044 if ( pTAttr->nTextAttribSize > 0.3 ) // is text readable
1046 aXTextCursor->gotoEnd( sal_False );
1047 char nPushedChar = pTextEntry->pText[ nTextOfs + pTAttr->nTextAttribCount ];
1048 pTextEntry->pText[ nTextOfs + pTAttr->nTextAttribCount ] = 0;
1049 UString aStr( StringToOUString( pTextEntry->pText + nTextOfs, CHARSET_SYSTEM ) );
1051 uno::Reference< text::XText > aCursorText = (text::XText*)aXTextCursor->queryInterface( ::getCppuType((const Reference< text::XText >*)0) );
1052 if ( aCursorText.is() )
1054 uno::Reference< beans::XPropertySet > aPropSet = (beans::XPropertySet*)aCursorText->queryInterface( ::getCppuType((const Reference< beans::XPropertySet >*)0) );
1055 if ( aPropSet.is() )
1057 if ( pTextEntry->nRowOrLineNum )
1059 uno::Reference< XControlCharacterInsertable > aCRef = (XControlCharacterInsertable*)aXTextCursor->queryInterface( ::getCppuType((const Reference< XControlCharacterInsertable >*)0) );
1060 if ( aCRef.is() )
1062 aCRef->insertControlCharacter( TEXTCONTROLCHAR_PARAGRAPH_BREAK );
1065 aCursorText->setText( aStr );
1066 aXTextCursor->gotoEnd( sal_True );
1067 double nSize = mpCGM->mnOutdx;
1068 if ( mpCGM->mnOutdx < mpCGM->mnOutdy )
1069 nSize = mpCGM->mnOutdy;
1070 nSize = ( nSize * (double)pTAttr->nTextAttribSize * (double)1.5 ) / 100;
1072 aAny <<= (sal_Int32)( (sal_Int32)nSize );
1073 aPropSet->setPropertyValue( L"CharHeight", aAny );
1075 sal_uInt32 nTextColor = pTAttr->nTextColorIndex;
1076 if ( nTextColor == 0xff )
1078 nTextColor = ( pTAttr->nTextColorBlue << 16 ) + ( pTAttr->nTextColorGreen << 8 ) + pTAttr->nTextColorRed;
1080 else
1082 nTextColor = mpCGM->pElement->aColorTable[ nTextColor ];
1085 sal_uInt32 nFontType = 0;
1087 if ( pTAttr->nTextFontType == 0xff )
1089 FontEntry* pFontEntry = mpCGM->pElement->aFontList.GetFontEntry( pTAttr->nTextFontFamily );
1090 if ( pFontEntry )
1092 nFontType = pFontEntry->nFontType;
1093 if ( mpCGM->pElement->nAspectSourceFlags & ASF_TEXTCOLOR )
1094 nTextColor = mpCGM->pElement->pTextBundle->GetColor();
1095 else
1096 nTextColor = mpCGM->pElement->aTextBundle.GetColor();
1098 FontItalic eFontItalic = ITALIC_NONE;
1099 if ( nFontType & 1 )
1100 eFontItalic = ITALIC_NORMAL;
1101 aAny.setValue( &eFontItalic, ::getCppuType((const FontItalic*)0) );
1102 aPropSet->setPropertyValue( L"CharPosture", aAny );
1104 aAny <<= (sal_Int32)( (sal_Int32)nTextColor );
1105 aPropSet->setPropertyValue( L"CharColor", aAny );
1107 awt::FontWeight eFontWeight = WEIGHT_NORMAL;
1108 if ( nFontType & 2 )
1109 eFontWeight = WEIGHT_BOLD;
1110 aAny.setValue( &eFontWeight, ::getCppuType((const awt::FontWeight*)0) );
1111 aPropSet->setPropertyValue( L"CharWeight", aAny );
1113 if ( pTAttr->nTextAttribBits & 0x4000 )
1115 awt::FontUnderline eUnderline = UNDERLINE_SINGLE;
1116 aAny.setValue( &eUnderline, ::getCppuType((const awt::FontUnderline*)0) );
1117 aPropSet->setPropertyValue( L"CharUnderline", aAny );
1121 pTextEntry->pText[ nTextOfs + pTAttr->nTextAttribCount ] = nPushedChar;
1123 nTextOfs += pTAttr->nTextAttribCount;
1125 while ( ( ( pTAttr = pTAttr->pNextAttribute ) != NULL ) );
1129 return ( nObjCount ) ? nObjCount : maXShapes->getCount();
1133 // ---------------------------------------------------------------
1135 void CGMImpressOutAct::DrawChart()