1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svgwriter.hxx,v $
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 ************************************************************************/
34 #include <cppuhelper/weak.hxx>
35 #include <rtl/ustring.hxx>
36 #include <tools/debug.hxx>
37 #include <tools/stream.hxx>
38 #include <tools/string.hxx>
39 #include <tools/urlobj.hxx>
40 #include <tools/stack.hxx>
42 #include <vcl/salbtype.hxx>
45 #include <vcl/gdimtf.hxx>
48 #include <vcl/metaact.hxx>
51 #include <vcl/metric.hxx>
54 #include <vcl/virdev.hxx>
57 #include <vcl/cvtgrf.hxx>
59 #include <xmloff/xmlexp.hxx>
60 #include <xmloff/nmspmap.hxx>
62 #include <com/sun/star/uno/Reference.h>
63 #include <com/sun/star/uno/RuntimeException.hpp>
64 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
65 #include <com/sun/star/lang/XComponent.hpp>
66 #include <com/sun/star/registry/XRegistryKey.hpp>
67 #include <com/sun/star/lang/XComponent.hpp>
68 #include <com/sun/star/io/XInputStream.hpp>
69 #include <com/sun/star/io/XOutputStream.hpp>
70 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
71 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
73 // -----------------------------------------------------------------------------
75 #define _SVG_USE_NATIVE_TEXTDECORATION
76 #define _SVG_USE_TSPANS 1
77 #undef _SVG_WRITE_EXTENTS
78 #define _SVG_EMBED_FONTS 1
80 // -----------------------------------------------------------------------------
82 #define NMSP_CPPU cppu
84 #define NMSP_UNO com::sun::star::uno
85 #define NMSP_LANG com::sun::star::lang
86 #define NMSP_SAX com::sun::star::xml::sax
87 #define NMSP_SVG com::sun::star::svg
88 #define NMSP_REGISTRY com::sun::star::registry
91 #define REF( _def_Obj ) NMSP_UNO::Reference< _def_Obj >
92 #define SEQ( _def_Obj ) NMSP_UNO::Sequence< _def_Obj >
93 #define B2UCONST( _def_pChar ) (NMSP_RTL::OUString(RTL_CONSTASCII_USTRINGPARAM(_def_pChar )))
94 #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\">" )
96 #define SVGWRITER_WRITE_NONE 0x00000000
97 #define SVGWRITER_WRITE_FILL 0x00000001
98 #define SVGWRITER_WRITE_TEXT 0x00000002
99 #define SVGWRITER_WRITE_ALL 0xFFFFFFFF
112 sal_Unicode
* mpBuffer
;
113 sal_uInt32 mnPartPos
;
114 rtl::OUString maString
;
118 FastString( sal_uInt32 nInitLen
= 2048, sal_uInt32 nIncrement
= 2048 );
119 FastString( sal_Char
* pBufferForBase64Encoding
, sal_uInt32 nBufLen
);
122 FastString
& operator+=( const ::rtl::OUString
& rStr
);
124 const ::rtl::OUString
& GetString() const;
125 sal_Bool
GetFirstPartString( const sal_uInt32 nPartLen
, ::rtl::OUString
& rPartString
);
126 sal_Bool
GetNextPartString( const sal_uInt32 nPartLen
, ::rtl::OUString
& rPartString
);
128 sal_uInt32
GetLength() const { return mnCurLen
; }
129 void Clear() { mnCurLen
= 0, maString
= ::rtl::OUString(); }
132 // ----------------------
133 // - SVGAttributeWriter -
134 // ----------------------
136 class SVGActionWriter
;
139 class SVGAttributeWriter
144 Color maCurLineColor
;
145 Color maCurFillColor
;
146 SvXMLExport
& mrExport
;
147 SVGFontExport
& mrFontExport
;
148 SvXMLElementExport
* mpElemFont
;
149 SvXMLElementExport
* mpElemPaint
;
151 SVGAttributeWriter();
155 SVGAttributeWriter( SvXMLExport
& rExport
, SVGFontExport
& rFontExport
);
156 virtual ~SVGAttributeWriter();
158 ::rtl::OUString
GetFontStyle( const Font
& rFont
);
159 ::rtl::OUString
GetPaintStyle( const Color
& rLineColor
, const Color
& rFillColor
);
161 void SetFontAttr( const Font
& rFont
);
162 void SetPaintAttr( const Color
& rLineColor
, const Color
& rFillColor
);
165 // -------------------
166 // - SVGActionWriter -
167 // -------------------
169 class SVGAttributeWriter
;
173 class SVGActionWriter
177 SvXMLExport
& mrExport
;
178 SVGFontExport
& mrFontExport
;
179 SVGAttributeWriter
* mpContext
;
180 sal_Bool mbClipAttrChanged
;
181 sal_Int32 mnCurClipId
;
182 Stack maContextStack
;
183 VirtualDevice
* mpVDev
;
184 MapMode maTargetMapMode
;
185 sal_Bool mbDestroyVDev
;
186 sal_Bool mbPaintAttrChanged
;
187 sal_Bool mbFontAttrChanged
;
189 SVGAttributeWriter
* ImplAcquireContext() { maContextStack
.Push( mpContext
= new SVGAttributeWriter( mrExport
, mrFontExport
) ); return mpContext
; }
190 void ImplReleaseContext() { delete (SVGAttributeWriter
*) maContextStack
.Pop(); mpContext
= (SVGAttributeWriter
*) maContextStack
.Top(); }
192 long ImplMap( sal_Int32 nVal
) const;
193 Point
ImplMap( const Point
& rPt
) const;
194 Size
ImplMap( const Size
& rSz
) const;
195 inline Rectangle
ImplMap( const Rectangle
& rRect
) const { return Rectangle( ImplMap( rRect
.TopLeft() ), ImplMap( rRect
.GetSize() ) ); }
197 void ImplWriteLine( const Point
& rPt1
, const Point
& rPt2
, const Color
* pLineColor
= NULL
, const ::rtl::OUString
* pStyle
= NULL
);
198 void ImplWriteRect( const Rectangle
& rRect
, long nRadX
= 0, long nRadY
= 0, const ::rtl::OUString
* pStyle
= NULL
);
199 void ImplWriteEllipse( const Point
& rCenter
, long nRadX
, long nRadY
, const ::rtl::OUString
* pStyle
= NULL
);
200 void ImplWritePolyPolygon( const PolyPolygon
& rPolyPoly
, sal_Bool bLineOnly
, const ::rtl::OUString
* pStyle
= NULL
);
201 void ImplWriteGradientEx( const PolyPolygon
& rPolyPoly
, const Gradient
& rGradient
, const ::rtl::OUString
* pStyle
, sal_uInt32 nWriteFlags
);
202 void ImplWriteText( const Point
& rPos
, const String
& rText
, const sal_Int32
* pDXArray
, long nWidth
, const ::rtl::OUString
* pStyle
= NULL
);
203 void ImplWriteBmp( const BitmapEx
& rBmpEx
, const Point
& rPt
, const Size
& rSz
, const Point
& rSrcPt
, const Size
& rSrcSz
, const ::rtl::OUString
* pStyle
= NULL
);
205 void ImplCheckFontAttributes();
206 void ImplCheckPaintAttributes();
208 void ImplWriteActions( const GDIMetaFile
& rMtf
, const ::rtl::OUString
* pStyle
, sal_uInt32 nWriteFlags
);
209 sal_Int32
ImplGetNextClipId() { return mnCurClipId
++; }
213 static ::rtl::OUString
GetValueString( sal_Int32 nVal
);
214 static ::rtl::OUString
GetPathString( const PolyPolygon
& rPolyPoly
, sal_Bool bLine
);
218 SVGActionWriter( SvXMLExport
& rExport
, SVGFontExport
& rFontExport
);
219 virtual ~SVGActionWriter();
221 void WriteMetaFile( const Point
& rPos100thmm
,
222 const Size
& rSize100thmm
,
223 const GDIMetaFile
& rMtf
,
224 sal_uInt32 nWriteFlags
= SVGWRITER_WRITE_ALL
);