122e87013SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 322e87013SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 422e87013SAndrew Rist * or more contributor license agreements. See the NOTICE file 522e87013SAndrew Rist * distributed with this work for additional information 622e87013SAndrew Rist * regarding copyright ownership. The ASF licenses this file 722e87013SAndrew Rist * to you under the Apache License, Version 2.0 (the 822e87013SAndrew Rist * "License"); you may not use this file except in compliance 922e87013SAndrew Rist * with the License. You may obtain a copy of the License at 1022e87013SAndrew Rist * 1122e87013SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1222e87013SAndrew Rist * 1322e87013SAndrew Rist * Unless required by applicable law or agreed to in writing, 1422e87013SAndrew Rist * software distributed under the License is distributed on an 1522e87013SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1622e87013SAndrew Rist * KIND, either express or implied. See the License for the 1722e87013SAndrew Rist * specific language governing permissions and limitations 1822e87013SAndrew Rist * under the License. 1922e87013SAndrew Rist * 2022e87013SAndrew Rist *************************************************************/ 2122e87013SAndrew Rist 2222e87013SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SVGWRITER_HXX 25cdf0e10cSrcweir #define SVGWRITER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 28cdf0e10cSrcweir #include <rtl/ustring.hxx> 29cdf0e10cSrcweir #include <tools/debug.hxx> 30cdf0e10cSrcweir #include <tools/stream.hxx> 31cdf0e10cSrcweir #include <tools/string.hxx> 32cdf0e10cSrcweir #include <tools/urlobj.hxx> 33cdf0e10cSrcweir #include <tools/stack.hxx> 34cdf0e10cSrcweir #ifndef _SALBTYPE_HXX 35cdf0e10cSrcweir #include <vcl/salbtype.hxx> 36cdf0e10cSrcweir #endif 37cdf0e10cSrcweir #ifndef _GDIMTF_HXX 38cdf0e10cSrcweir #include <vcl/gdimtf.hxx> 39cdf0e10cSrcweir #endif 40cdf0e10cSrcweir #ifndef _METAACT_HXX 41cdf0e10cSrcweir #include <vcl/metaact.hxx> 42cdf0e10cSrcweir #endif 43cdf0e10cSrcweir #ifndef _METAACT_HXX 44cdf0e10cSrcweir #include <vcl/metric.hxx> 45cdf0e10cSrcweir #endif 46cdf0e10cSrcweir #ifndef _VIRDEV_HXX 47cdf0e10cSrcweir #include <vcl/virdev.hxx> 48cdf0e10cSrcweir #endif 49cdf0e10cSrcweir #ifndef _CVTGRF_HXX 50cdf0e10cSrcweir #include <vcl/cvtgrf.hxx> 51cdf0e10cSrcweir #endif 52cdf0e10cSrcweir #include <vcl/graphictools.hxx> 53cdf0e10cSrcweir #include <xmloff/xmlexp.hxx> 54cdf0e10cSrcweir #include <xmloff/nmspmap.hxx> 55cdf0e10cSrcweir 56cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h> 57cdf0e10cSrcweir #include <com/sun/star/uno/RuntimeException.hpp> 58cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 59cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 60cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp> 61cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 62cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 63cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 64cdf0e10cSrcweir #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 65cdf0e10cSrcweir #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> 66cdf0e10cSrcweir #include <com/sun/star/i18n/CharacterIteratorMode.hpp> 67cdf0e10cSrcweir #include <com/sun/star/i18n/XBreakIterator.hpp> 68cb0a2370SArmin Le Grand #include <com/sun/star/svg/XSVGWriter.hpp> 69*bac862b1SArmin Le Grand #include <com/sun/star/lang/XInitialization.hpp> 70cdf0e10cSrcweir 71cdf0e10cSrcweir // ----------------------------------------------------------------------------- 72cdf0e10cSrcweir 73cdf0e10cSrcweir #define _SVG_WRITE_EXTENTS 1 74cdf0e10cSrcweir #undef _SVG_WRITE_TEXT_DESC 75cdf0e10cSrcweir #undef _SVG_USE_CONFIG 76cdf0e10cSrcweir 77cdf0e10cSrcweir // ----------------------------------------------------------------------------- 78cdf0e10cSrcweir 79cdf0e10cSrcweir #define NMSP_CPPU cppu 80cdf0e10cSrcweir #define NMSP_UNO com::sun::star::uno 81cdf0e10cSrcweir #define NMSP_LANG com::sun::star::lang 82cdf0e10cSrcweir #define NMSP_SAX com::sun::star::xml::sax 83cdf0e10cSrcweir #define NMSP_SVG com::sun::star::svg 84cdf0e10cSrcweir #define NMSP_REGISTRY com::sun::star::registry 85cdf0e10cSrcweir 86cdf0e10cSrcweir 87cdf0e10cSrcweir #define REF( _def_Obj ) NMSP_UNO::Reference< _def_Obj > 88cdf0e10cSrcweir #define SEQ( _def_Obj ) NMSP_UNO::Sequence< _def_Obj > 89cdf0e10cSrcweir #define B2UCONST( _def_pChar ) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(_def_pChar ))) 90cdf0e10cSrcweir #define SVG_DTD_STRING B2UCONST( "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" ) 91cdf0e10cSrcweir #define SVG_TINY_DTD_STRING B2UCONST( "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG Tiny 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd\">" ) 92cdf0e10cSrcweir 93cdf0e10cSrcweir #define SVGWRITER_WRITE_NONE 0x00000000 94cdf0e10cSrcweir #define SVGWRITER_WRITE_FILL 0x00000001 95cdf0e10cSrcweir #define SVGWRITER_WRITE_TEXT 0x00000002 96cdf0e10cSrcweir #define SVGWRITER_NO_SHAPE_COMMENTS 0x01000000 97cdf0e10cSrcweir 98cdf0e10cSrcweir // ---------------------- 99cdf0e10cSrcweir // - SVGAttributeWriter - 100cdf0e10cSrcweir // ---------------------- 101cdf0e10cSrcweir 102cdf0e10cSrcweir class SVGActionWriter; 103cdf0e10cSrcweir class SVGExport; 104cdf0e10cSrcweir class SVGFontExport; 105cdf0e10cSrcweir 106cdf0e10cSrcweir class SVGAttributeWriter 107cdf0e10cSrcweir { 108cdf0e10cSrcweir private: 109cdf0e10cSrcweir 110cdf0e10cSrcweir Font maCurFont; 111cdf0e10cSrcweir Color maCurLineColor; 112cdf0e10cSrcweir Color maCurFillColor; 113cb0a2370SArmin Le Grand SVGExport& mrExport; 114cdf0e10cSrcweir SVGFontExport& mrFontExport; 115cdf0e10cSrcweir SvXMLElementExport* mpElemFont; 116cdf0e10cSrcweir SvXMLElementExport* mpElemPaint; 117cdf0e10cSrcweir 118cdf0e10cSrcweir SVGAttributeWriter(); 119cdf0e10cSrcweir 120cdf0e10cSrcweir void ImplGetColorStr( const Color& rColor, ::rtl::OUString& rColorStr ); 121cdf0e10cSrcweir double ImplRound( double fVal, sal_Int32 nDecs = 3 ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir public: 124cdf0e10cSrcweir 125cdf0e10cSrcweir SVGAttributeWriter( SVGExport& rExport, SVGFontExport& rFontExport ); 126cdf0e10cSrcweir virtual ~SVGAttributeWriter(); 127cdf0e10cSrcweir 128cdf0e10cSrcweir void AddColorAttr( const char* pColorAttrName, const char* pColorOpacityAttrName, const Color& rColor ); 129cdf0e10cSrcweir void AddGradientDef( const Rectangle& rObjRect,const Gradient& rGradient, ::rtl::OUString& rGradientId ); 130cdf0e10cSrcweir void AddPaintAttr( const Color& rLineColor, const Color& rFillColor, 131cdf0e10cSrcweir const Rectangle* pObjBoundRect = NULL, const Gradient* pFillGradient = NULL ); 132cdf0e10cSrcweir 133cdf0e10cSrcweir void SetFontAttr( const Font& rFont ); 134cdf0e10cSrcweir }; 135cdf0e10cSrcweir 136cdf0e10cSrcweir // ---------------------- 137cdf0e10cSrcweir // - SVGShapeDescriptor - 138cdf0e10cSrcweir // ---------------------- 139cdf0e10cSrcweir 140cdf0e10cSrcweir struct SVGShapeDescriptor 141cdf0e10cSrcweir { 1425aaf853bSArmin Le Grand PolyPolygon maShapePolyPoly; 1435aaf853bSArmin Le Grand Color maShapeFillColor; 1445aaf853bSArmin Le Grand Color maShapeLineColor; 1455aaf853bSArmin Le Grand sal_Int32 mnStrokeWidth; 1465aaf853bSArmin Le Grand SvtGraphicStroke::DashArray maDashArray; 1475aaf853bSArmin Le Grand ::std::auto_ptr< Gradient > mapShapeGradient; 1485aaf853bSArmin Le Grand ::rtl::OUString maId; 1495aaf853bSArmin Le Grand 1505aaf853bSArmin Le Grand // added support for LineJoin and LineCap 1515aaf853bSArmin Le Grand basegfx::B2DLineJoin maLineJoin; 1525aaf853bSArmin Le Grand com::sun::star::drawing::LineCap maLineCap; 153cdf0e10cSrcweir 154cdf0e10cSrcweir // ------------------------------------------------------------------------- 155cdf0e10cSrcweir SVGShapeDescriptorSVGShapeDescriptor156cdf0e10cSrcweir SVGShapeDescriptor() : 157cdf0e10cSrcweir maShapeFillColor( Color( COL_TRANSPARENT ) ), 158cdf0e10cSrcweir maShapeLineColor( Color( COL_TRANSPARENT ) ), 1595aaf853bSArmin Le Grand mnStrokeWidth( 0 ), 1605aaf853bSArmin Le Grand maLineJoin(basegfx::B2DLINEJOIN_MITER), // miter is Svg 'stroke-linejoin' default 1615aaf853bSArmin Le Grand maLineCap(com::sun::star::drawing::LineCap_BUTT) // butt is Svg 'stroke-linecap' default 162cdf0e10cSrcweir { 163cdf0e10cSrcweir } 164cdf0e10cSrcweir }; 165cdf0e10cSrcweir 166cdf0e10cSrcweir // ------------------- 167cdf0e10cSrcweir // - SVGActionWriter - 168cdf0e10cSrcweir // ------------------- 169cdf0e10cSrcweir 170cdf0e10cSrcweir class SVGAttributeWriter; 171cb0a2370SArmin Le Grand class SVGExport; 172cdf0e10cSrcweir class GDIMetaFile; 173cdf0e10cSrcweir 174cdf0e10cSrcweir class SVGActionWriter 175cdf0e10cSrcweir { 176cdf0e10cSrcweir private: 177cdf0e10cSrcweir 178cdf0e10cSrcweir Stack maContextStack; 179cdf0e10cSrcweir ::std::auto_ptr< SVGShapeDescriptor > mapCurShape; 180cb0a2370SArmin Le Grand SVGExport& mrExport; 181cdf0e10cSrcweir SVGFontExport& mrFontExport; 182cdf0e10cSrcweir SVGAttributeWriter* mpContext; 183cdf0e10cSrcweir VirtualDevice* mpVDev; 184cdf0e10cSrcweir MapMode maTargetMapMode; 185cdf0e10cSrcweir sal_uInt32 mnInnerMtfCount; 186cdf0e10cSrcweir sal_Bool mbDestroyVDev; 187cdf0e10cSrcweir sal_Bool mbPaintAttrChanged; 188cdf0e10cSrcweir sal_Bool mbFontAttrChanged; 189cdf0e10cSrcweir sal_Bool mbClipAttrChanged; 190cdf0e10cSrcweir ImplAcquireContext()191cdf0e10cSrcweir SVGAttributeWriter* ImplAcquireContext() { maContextStack.Push( mpContext = new SVGAttributeWriter( mrExport, mrFontExport ) ); return mpContext; } ImplReleaseContext()192cdf0e10cSrcweir void ImplReleaseContext() { delete (SVGAttributeWriter*) maContextStack.Pop(); mpContext = (SVGAttributeWriter*) maContextStack.Top(); } 193cdf0e10cSrcweir 194cdf0e10cSrcweir long ImplMap( sal_Int32 nVal ) const; 195cdf0e10cSrcweir Point& ImplMap( const Point& rPt, Point& rDstPt ) const; 196cdf0e10cSrcweir Size& ImplMap( const Size& rSz, Size& rDstSz ) const; 197cdf0e10cSrcweir Rectangle& ImplMap( const Rectangle& rRect, Rectangle& rDstRect ) const; 198cdf0e10cSrcweir Polygon& ImplMap( const Polygon& rPoly, Polygon& rDstPoly ) const; 199cdf0e10cSrcweir PolyPolygon& ImplMap( const PolyPolygon& rPolyPoly, PolyPolygon& rDstPolyPoly ) const; 200cdf0e10cSrcweir 201cdf0e10cSrcweir void ImplWriteLine( const Point& rPt1, const Point& rPt2, const Color* pLineColor = NULL, 202cdf0e10cSrcweir sal_Bool bApplyMapping = sal_True ); 203cdf0e10cSrcweir void ImplWriteRect( const Rectangle& rRect, long nRadX = 0, long nRadY = 0, 204cdf0e10cSrcweir sal_Bool bApplyMapping = sal_True ); 205cdf0e10cSrcweir void ImplWriteEllipse( const Point& rCenter, long nRadX, long nRadY, 206cdf0e10cSrcweir sal_Bool bApplyMapping = sal_True ); 207cdf0e10cSrcweir void ImplWritePolyPolygon( const PolyPolygon& rPolyPoly, sal_Bool bLineOnly, 208cdf0e10cSrcweir sal_Bool bApplyMapping = sal_True ); 209cdf0e10cSrcweir void ImplWriteShape( const SVGShapeDescriptor& rShape, sal_Bool bApplyMapping = sal_True ); 210cdf0e10cSrcweir void ImplWriteGradientEx( const PolyPolygon& rPolyPoly, const Gradient& rGradient, sal_uInt32 nWriteFlags, 211cdf0e10cSrcweir sal_Bool bApplyMapping = sal_True ); 212cdf0e10cSrcweir void ImplWriteText( const Point& rPos, const String& rText, const sal_Int32* pDXArray, long nWidth, 213cdf0e10cSrcweir sal_Bool bApplyMapping = sal_True ); 214cdf0e10cSrcweir void ImplWriteBmp( const BitmapEx& rBmpEx, const Point& rPt, const Size& rSz, const Point& rSrcPt, const Size& rSrcSz, 215cdf0e10cSrcweir sal_Bool bApplyMapping = sal_True ); 216cdf0e10cSrcweir 217cdf0e10cSrcweir void ImplCheckFontAttributes(); 218cdf0e10cSrcweir void ImplCheckPaintAttributes(); 219cdf0e10cSrcweir 220cdf0e10cSrcweir void ImplWriteActions( const GDIMetaFile& rMtf, sal_uInt32 nWriteFlags, const ::rtl::OUString* pElementId ); 221cdf0e10cSrcweir 222cdf0e10cSrcweir public: 223cdf0e10cSrcweir 224cdf0e10cSrcweir static ::rtl::OUString GetPathString( const PolyPolygon& rPolyPoly, sal_Bool bLine ); 225cdf0e10cSrcweir 226cdf0e10cSrcweir public: 227cdf0e10cSrcweir 228cdf0e10cSrcweir SVGActionWriter( SVGExport& rExport, SVGFontExport& rFontExport ); 229cdf0e10cSrcweir virtual ~SVGActionWriter(); 230cdf0e10cSrcweir 231cdf0e10cSrcweir void WriteMetaFile( const Point& rPos100thmm, 232cdf0e10cSrcweir const Size& rSize100thmm, 233cdf0e10cSrcweir const GDIMetaFile& rMtf, 234cdf0e10cSrcweir sal_uInt32 nWriteFlags, 235cdf0e10cSrcweir const ::rtl::OUString* pElementId = NULL ); 236cdf0e10cSrcweir }; 237cdf0e10cSrcweir 238*bac862b1SArmin Le Grand class SVGWriter : public NMSP_CPPU::OWeakObject, NMSP_SVG::XSVGWriter, com::sun::star::lang::XInitialization 239cb0a2370SArmin Le Grand { 240cb0a2370SArmin Le Grand private: 241cb0a2370SArmin Le Grand 242*bac862b1SArmin Le Grand REF( NMSP_LANG::XMultiServiceFactory ) mxFact; 243*bac862b1SArmin Le Grand com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > maFilterData; 244*bac862b1SArmin Le Grand 245cb0a2370SArmin Le Grand SVGWriter(); 246cb0a2370SArmin Le Grand 247cb0a2370SArmin Le Grand public: 248cb0a2370SArmin Le Grand 249cb0a2370SArmin Le Grand SVGWriter( const REF( NMSP_LANG::XMultiServiceFactory )& rxMgr ); 250cb0a2370SArmin Le Grand virtual ~SVGWriter(); 251cb0a2370SArmin Le Grand 252cb0a2370SArmin Le Grand // XInterface 253cb0a2370SArmin Le Grand virtual NMSP_UNO::Any SAL_CALL queryInterface( const NMSP_UNO::Type & rType ) throw( NMSP_UNO::RuntimeException ); 254cb0a2370SArmin Le Grand virtual void SAL_CALL acquire() throw(); 255cb0a2370SArmin Le Grand virtual void SAL_CALL release() throw(); 256cb0a2370SArmin Le Grand 257cb0a2370SArmin Le Grand // XSVGWriter 258cb0a2370SArmin Le Grand virtual void SAL_CALL write( const REF( NMSP_SAX::XDocumentHandler )& rxDocHandler, 259cb0a2370SArmin Le Grand const SEQ( sal_Int8 )& rMtfSeq ) throw( NMSP_UNO::RuntimeException ); 260*bac862b1SArmin Le Grand 261*bac862b1SArmin Le Grand // ::com::sun::star::lang::XInitialization 262*bac862b1SArmin Le Grand void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 263*bac862b1SArmin Le Grand 264cb0a2370SArmin Le Grand }; 265cb0a2370SArmin Le Grand 266cb0a2370SArmin Le Grand ::rtl::OUString SVGWriter_getImplementationName () 267cb0a2370SArmin Le Grand throw ( ::com::sun::star::uno::RuntimeException ); 268cb0a2370SArmin Le Grand 269cb0a2370SArmin Le Grand // ----------------------------------------------------------------------------- 270cb0a2370SArmin Le Grand 271cb0a2370SArmin Le Grand sal_Bool SAL_CALL SVGWriter_supportsService( const ::rtl::OUString& ServiceName ) 272cb0a2370SArmin Le Grand throw ( ::com::sun::star::uno::RuntimeException ); 273cb0a2370SArmin Le Grand 274cb0a2370SArmin Le Grand // ----------------------------------------------------------------------------- 275cb0a2370SArmin Le Grand 276cb0a2370SArmin Le Grand ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL SVGWriter_getSupportedServiceNames( ) 277cb0a2370SArmin Le Grand throw ( ::com::sun::star::uno::RuntimeException ); 278cb0a2370SArmin Le Grand 279cb0a2370SArmin Le Grand // ----------------------------------------------------------------------------- 280cb0a2370SArmin Le Grand 281cb0a2370SArmin Le Grand ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 282cb0a2370SArmin Le Grand SAL_CALL SVGWriter_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) 283cb0a2370SArmin Le Grand throw ( ::com::sun::star::uno::Exception ); 284cb0a2370SArmin Le Grand 285cdf0e10cSrcweir #endif 286