Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2008 by Sun Microsystems, Inc.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SVGWRITER_HXX
30 : : #define SVGWRITER_HXX
31 : :
32 : : #include <stack>
33 : : #include <cppuhelper/weak.hxx>
34 : : #include <rtl/ustring.hxx>
35 : : #include <tools/stream.hxx>
36 : : #include <tools/string.hxx>
37 : : #include <vcl/gdimtf.hxx>
38 : : #include <vcl/metaact.hxx>
39 : : #include <vcl/metric.hxx>
40 : : #include <vcl/virdev.hxx>
41 : : #include <vcl/cvtgrf.hxx>
42 : : #include <vcl/graphictools.hxx>
43 : : #include <vcl/rendergraphicrasterizer.hxx>
44 : : #include <xmloff/xmlexp.hxx>
45 : : #include <xmloff/nmspmap.hxx>
46 : :
47 : : #include <com/sun/star/uno/Reference.h>
48 : : #include <com/sun/star/uno/RuntimeException.hpp>
49 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 : : #include <com/sun/star/lang/XComponent.hpp>
51 : : #include <com/sun/star/registry/XRegistryKey.hpp>
52 : : #include <com/sun/star/io/XInputStream.hpp>
53 : : #include <com/sun/star/io/XOutputStream.hpp>
54 : : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
55 : : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
56 : : #include <com/sun/star/i18n/CharacterIteratorMode.hpp>
57 : : #include <com/sun/star/i18n/XBreakIterator.hpp>
58 : :
59 : : // -----------------------------------------------------------------------------
60 : :
61 : : #define NMSP_CPPU cppu
62 : : #define NMSP_UNO com::sun::star::uno
63 : : #define NMSP_LANG com::sun::star::lang
64 : : #define NMSP_SAX com::sun::star::xml::sax
65 : : #define NMSP_REGISTRY com::sun::star::registry
66 : :
67 : :
68 : : #define REF( _def_Obj ) NMSP_UNO::Reference< _def_Obj >
69 : : #define SEQ( _def_Obj ) NMSP_UNO::Sequence< _def_Obj >
70 : : #define B2UCONST( _def_pChar ) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(_def_pChar )))
71 : : #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\">" )
72 : : #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\">" )
73 : :
74 : : #define SVGWRITER_WRITE_NONE 0x00000000
75 : : #define SVGWRITER_WRITE_FILL 0x00000001
76 : : #define SVGWRITER_WRITE_TEXT 0x00000002
77 : : #define SVGWRITER_NO_SHAPE_COMMENTS 0x01000000
78 : : #define SVGWRITER_WRITE_ALL 0xFFFFFFFF
79 : :
80 : : // ----------------------
81 : : // - SVGAttributeWriter -
82 : : // ----------------------
83 : :
84 : : class SVGActionWriter;
85 : : class SVGExport;
86 : : class SVGFontExport;
87 : :
88 : : class SVGAttributeWriter
89 : : {
90 : : private:
91 : :
92 : : Font maCurFont;
93 : : Color maCurLineColor;
94 : : Color maCurFillColor;
95 : : SVGExport& mrExport;
96 : : SVGFontExport& mrFontExport;
97 : : SvXMLElementExport* mpElemFont;
98 : : SvXMLElementExport* mpElemPaint;
99 : :
100 : : SVGAttributeWriter();
101 : :
102 : : double ImplRound( double fVal, sal_Int32 nDecs = 3 );
103 : :
104 : : public:
105 : :
106 : : SVGAttributeWriter( SVGExport& rExport, SVGFontExport& rFontExport );
107 : : virtual ~SVGAttributeWriter();
108 : :
109 : : ::rtl::OUString GetFontStyle( const Font& rFont );
110 : : ::rtl::OUString GetPaintStyle( const Color& rLineColor, const Color& rFillColor, const LineInfo* pLineInfo );
111 : : void AddColorAttr( const char* pColorAttrName, const char* pColorOpacityAttrName, const Color& rColor );
112 : : void AddGradientDef( const Rectangle& rObjRect,const Gradient& rGradient, ::rtl::OUString& rGradientId );
113 : : void AddPaintAttr( const Color& rLineColor, const Color& rFillColor,
114 : : const Rectangle* pObjBoundRect = NULL, const Gradient* pFillGradient = NULL );
115 : :
116 : : void SetFontAttr( const Font& rFont );
117 : :
118 : : static void ImplGetColorStr( const Color& rColor, ::rtl::OUString& rColorStr );
119 : : };
120 : :
121 [ # # ]: 0 : struct SVGShapeDescriptor
122 : : {
123 : : PolyPolygon maShapePolyPoly;
124 : : Color maShapeFillColor;
125 : : Color maShapeLineColor;
126 : : sal_Int32 mnStrokeWidth;
127 : : SvtGraphicStroke::DashArray maDashArray;
128 : : ::std::auto_ptr< Gradient > mapShapeGradient;
129 : : ::rtl::OUString maId;
130 : :
131 : : // -------------------------------------------------------------------------
132 : :
133 : 0 : SVGShapeDescriptor() :
134 : : maShapeFillColor( Color( COL_TRANSPARENT ) ),
135 : : maShapeLineColor( Color( COL_TRANSPARENT ) ),
136 [ # # ]: 0 : mnStrokeWidth( 0 )
137 : : {
138 : 0 : }
139 : : };
140 : :
141 : : // -------------------
142 : : // - SVGActionWriter -
143 : : // -------------------
144 : :
145 : : class SVGAttributeWriter;
146 : : class GDIMetaFile;
147 : :
148 : : class SVGActionWriter
149 : : {
150 : : private:
151 : :
152 : : sal_Int32 mnCurGradientId;
153 : : sal_Int32 mnCurMaskId;
154 : : sal_Int32 mnCurPatternId;
155 : : ::std::stack< SVGAttributeWriter* > maContextStack;
156 : : ::std::auto_ptr< SVGShapeDescriptor > mapCurShape;
157 : : SVGExport& mrExport;
158 : : SVGFontExport& mrFontExport;
159 : : SVGAttributeWriter* mpContext;
160 : : VirtualDevice* mpVDev;
161 : : MapMode maTargetMapMode;
162 : : sal_uInt32 mnInnerMtfCount;
163 : : sal_Bool mbDestroyVDev;
164 : : sal_Bool mbPaintAttrChanged;
165 : : sal_Bool mbFontAttrChanged;
166 : : sal_Bool mbClipAttrChanged;
167 : : sal_Bool mbIsPlacehlolderShape;
168 : :
169 : :
170 : 0 : SVGAttributeWriter* ImplAcquireContext()
171 : : {
172 [ # # ]: 0 : maContextStack.push( mpContext = new SVGAttributeWriter( mrExport, mrFontExport ) );
173 : 0 : return mpContext;
174 : : }
175 : 0 : void ImplReleaseContext()
176 : : {
177 [ # # ]: 0 : if (!maContextStack.empty())
178 : : {
179 [ # # ]: 0 : delete maContextStack.top();
180 : 0 : maContextStack.pop();
181 : : }
182 [ # # ]: 0 : mpContext = (maContextStack.empty() ? NULL : maContextStack.top());
183 : 0 : }
184 : :
185 : : long ImplMap( sal_Int32 nVal ) const;
186 : : Point& ImplMap( const Point& rPt, Point& rDstPt ) const;
187 : : Size& ImplMap( const Size& rSz, Size& rDstSz ) const;
188 : : Rectangle& ImplMap( const Rectangle& rRect, Rectangle& rDstRect ) const;
189 : : Polygon& ImplMap( const Polygon& rPoly, Polygon& rDstPoly ) const;
190 : : PolyPolygon& ImplMap( const PolyPolygon& rPolyPoly, PolyPolygon& rDstPolyPoly ) const;
191 : :
192 : : void ImplWriteLine( const Point& rPt1, const Point& rPt2, const Color* pLineColor = NULL,
193 : : sal_Bool bApplyMapping = sal_True );
194 : : void ImplWriteRect( const Rectangle& rRect, long nRadX = 0, long nRadY = 0,
195 : : sal_Bool bApplyMapping = sal_True );
196 : : void ImplWriteEllipse( const Point& rCenter, long nRadX, long nRadY,
197 : : sal_Bool bApplyMapping = sal_True );
198 : : void ImplWritePattern( const PolyPolygon& rPolyPoly, const Hatch* pHatch, const Gradient* pGradient, sal_uInt32 nWriteFlags );
199 : : void ImplWritePolyPolygon( const PolyPolygon& rPolyPoly, sal_Bool bLineOnly,
200 : : sal_Bool bApplyMapping = sal_True );
201 : : void ImplWriteShape( const SVGShapeDescriptor& rShape, sal_Bool bApplyMapping = sal_True );
202 : : void ImplWriteGradientEx( const PolyPolygon& rPolyPoly, const Gradient& rGradient, sal_uInt32 nWriteFlags,
203 : : sal_Bool bApplyMapping = sal_True );
204 : : void ImplWriteGradientLinear( const PolyPolygon& rPolyPoly, const Gradient& rGradient );
205 : : void ImplWriteGradientStop( const Color& rColor, double fOffset );
206 : : Color ImplGetColorWithIntensity( const Color& rColor, sal_uInt16 nIntensity );
207 : : Color ImplGetGradientColor( const Color& rStartColor, const Color& rEndColor, double fOffset );
208 : : void ImplWriteMask( GDIMetaFile& rMtf, const Point& rDestPt, const Size& rDestSize, const Gradient& rGradient, sal_uInt32 nWriteFlags );
209 : : void ImplWriteText( const Point& rPos, const String& rText, const sal_Int32* pDXArray, long nWidth, sal_Bool bApplyMapping = sal_True );
210 : : void ImplWriteText( const Point& rPos, const String& rText, const sal_Int32* pDXArray, long nWidth, Color aTextColor, sal_Bool bApplyMapping );
211 : : void ImplWriteBmp( const BitmapEx& rBmpEx, const Point& rPt, const Size& rSz, const Point& rSrcPt, const Size& rSrcSz,
212 : : sal_Bool bApplyMapping = sal_True );
213 : :
214 : : void ImplCheckFontAttributes();
215 : : void ImplCheckPaintAttributes();
216 : :
217 : : void ImplWriteActions( const GDIMetaFile& rMtf, sal_uInt32 nWriteFlags, const ::rtl::OUString* pElementId );
218 : :
219 : : public:
220 : :
221 : : static ::rtl::OUString GetPathString( const PolyPolygon& rPolyPoly, sal_Bool bLine );
222 : :
223 : : public:
224 : :
225 : : SVGActionWriter( SVGExport& rExport, SVGFontExport& rFontExport );
226 : : virtual ~SVGActionWriter();
227 : :
228 : : void WriteMetaFile( const Point& rPos100thmm,
229 : : const Size& rSize100thmm,
230 : : const GDIMetaFile& rMtf,
231 : : sal_uInt32 nWriteFlags,
232 : : const ::rtl::OUString* pElementId = NULL );
233 : : };
234 : :
235 : : #endif
236 : :
237 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|