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 2000, 2010 Oracle and/or its affiliates.
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 _SWF_WRITER_HXX_
30 : : #define _SWF_WRITER_HXX_
31 : :
32 : : #include <com/sun/star/uno/Sequence.hxx>
33 : : #include <com/sun/star/io/XOutputStream.hpp>
34 : : #include <com/sun/star/i18n/XBreakIterator.hpp>
35 : : #include <vcl/font.hxx>
36 : : #include <vcl/gradient.hxx>
37 : : #include <unotools/tempfile.hxx>
38 : : #include <tools/color.hxx>
39 : : #include <tools/poly.hxx>
40 : : #include <tools/gen.hxx>
41 : : #include <tools/stream.hxx>
42 : :
43 : : // #i73264#
44 : : #include <basegfx/matrix/b2dhommatrix.hxx>
45 : : #include <osl/file.hxx>
46 : :
47 : : #include <vector>
48 : : #include <stack>
49 : : #include <map>
50 : :
51 : : #ifdef AUGUSTUS
52 : : #include "lame.h"
53 : : #include "sndfile.h"
54 : : #endif
55 : :
56 : : #include <stdio.h>
57 : :
58 : : class GDIMetaFile;
59 : : class BitmapEx;
60 : : class PolyPolygon;
61 : : class Gradient;
62 : : class SvtGraphicFill;
63 : : class SvtGraphicStroke;
64 : : class LineInfo;
65 : : namespace basegfx { class B2DPolygon; }
66 : :
67 : 0 : inline sal_uInt16 _uInt16( sal_Int32 nValue )
68 : : {
69 : : OSL_ENSURE( (nValue >= 0) && ((sal_uInt32)nValue <= 0xffff), "overflow while converting sal_Int32 to sal_uInt16" );
70 : 0 : return (sal_uInt16)nValue;
71 : : }
72 : :
73 : 0 : inline sal_Int16 _Int16( sal_Int32 nValue )
74 : : {
75 : : OSL_ENSURE( (nValue >= -32768) && (nValue <= 32767), "overflow while converting sal_Int32 to sal_Int16" );
76 : 0 : return (sal_Int16)nValue;
77 : : }
78 : :
79 : : class VirtualDevice;
80 : :
81 : : namespace swf {
82 : :
83 : : const sal_uInt8 TAG_END = 0;
84 : : const sal_uInt8 TAG_SHOWFRAME = 1;
85 : :
86 : : const sal_uInt8 TAG_DEFINEBUTTON = 7;
87 : :
88 : : const sal_uInt8 TAG_BACKGROUNDCOLOR = 9;
89 : :
90 : : const sal_uInt8 TAG_DOACTION = 12;
91 : : const sal_uInt8 TAG_STARTSOUND = 15;
92 : :
93 : : const sal_uInt8 TAG_SOUNDSTREAMBLOCK = 19;
94 : : const sal_uInt8 TAG_SOUNDSTREAMHEAD = 18;
95 : : const sal_uInt8 TAG_SOUNDSTREAMHEAD2 = 45;
96 : :
97 : : const sal_uInt8 TAG_JPEGTABLES = 8;
98 : : const sal_uInt8 TAG_DEFINEBITS = 6;
99 : : const sal_uInt8 TAG_DEFINEBITSLOSSLESS = 20;
100 : : const sal_uInt8 TAG_DEFINEBITSJPEG2 = 21;
101 : : const sal_uInt8 TAG_DEFINEBITSJPEG3 = 35;
102 : : const sal_uInt8 TAG_DEFINEBITSLOSSLESS2 = 36;
103 : : const sal_uInt8 TAG_DEFINEEDITTEXT= 37;
104 : : const sal_uInt8 TAG_PLACEOBJECT = 4;
105 : : const sal_uInt8 TAG_PLACEOBJECT2 = 26;
106 : : const sal_uInt8 TAG_REMOVEOBJECT2 = 28;
107 : :
108 : : const sal_uInt8 TAG_DEFINEFONT = 10;
109 : : const sal_uInt8 TAG_DEFINETEXT = 11;
110 : : const sal_uInt8 TAG_DEFINESHAPE3 = 32;
111 : : const sal_uInt8 TAG_DEFINESPRITE = 39;
112 : :
113 : : const sal_uInt8 TAG_FRAMELABEL = 43;
114 : :
115 : : const sal_uInt8 TAG_HEADER = 0xff;
116 : :
117 : : ///////////////////////////////////////////////////////////////////////
118 : :
119 : : /** converts a double to a 16.16 flash fixed value */
120 : : sal_uInt32 getFixed( double fValue );
121 : :
122 : : ///////////////////////////////////////////////////////////////////////
123 : :
124 : : typedef ::std::map<sal_uInt32, sal_uInt16> ChecksumCache;
125 : :
126 : : /** unsigned int 16 compare operation for stl */
127 : : struct ltuint16
128 : : {
129 : 0 : bool operator()(sal_uInt16 s1, sal_uInt16 s2) const
130 : : {
131 : 0 : return s1 < s2;
132 : : }
133 : : };
134 : :
135 : : ///////////////////////////////////////////////////////////////////////
136 : :
137 : : /** container class to create bit structures */
138 : 0 : class BitStream
139 : : {
140 : : public:
141 : : BitStream();
142 : :
143 : : void writeUB( sal_uInt32 nValue, sal_uInt16 nBits );
144 : : void writeSB( sal_Int32 nValue, sal_uInt16 nBits );
145 : : void writeFB( sal_uInt32 nValue, sal_uInt16 nBits );
146 : :
147 : : void pad();
148 : : void writeTo( SvStream& out );
149 : :
150 : : sal_uInt32 getOffset() const;
151 : : private:
152 : :
153 : : std::vector< sal_uInt8 > maData;
154 : : sal_uInt8 mnBitPos;
155 : : sal_uInt8 mnCurrentByte;
156 : : };
157 : :
158 : : ///////////////////////////////////////////////////////////////////////
159 : :
160 : : /** this class collects all used glyphs for a given fonts and maps
161 : : characters to glyph ids.
162 : : */
163 : : class FlashFont
164 : : {
165 : : public:
166 : : FlashFont( const Font& rFont, sal_uInt16 nId );
167 : : ~FlashFont();
168 : :
169 : : sal_uInt16 getGlyph( sal_uInt16 nChar, VirtualDevice* pVDev );
170 : :
171 : : void write( SvStream& out );
172 : :
173 : 0 : sal_uInt16 getID() const { return mnId; }
174 : 0 : const Font& getFont() { return maFont; }
175 : :
176 : : private:
177 : : const Font maFont;
178 : : std::map<sal_uInt16, sal_uInt16, ltuint16> maGlyphIndex;
179 : : sal_uInt16 mnNextIndex;
180 : : sal_uInt16 mnId;
181 : : BitStream maGlyphData;
182 : : std::vector< sal_uInt16 > maGlyphOffsets;
183 : : };
184 : :
185 : : typedef std::vector<FlashFont*> FontMap;
186 : :
187 : : ///////////////////////////////////////////////////////////////////////
188 : :
189 : : /** this class helps creating flash tags */
190 : 0 : class Tag : public SvMemoryStream
191 : : {
192 : : public:
193 : : Tag( sal_uInt8 nTagId );
194 : :
195 : 0 : sal_uInt8 getTagId() const { return mnTagId; }
196 : :
197 : : void write( SvStream& out );
198 : :
199 : : void addUI32( sal_uInt32 nValue );
200 : : void addUI16( sal_uInt16 nValue );
201 : : void addUI8( sal_uInt8 nValue );
202 : : void addBits( BitStream& rIn );
203 : :
204 : : void addRGBA( const Color& rColor );
205 : : void addRGB( const Color& rColor );
206 : : void addRect( const Rectangle& rRect );
207 : : void addMatrix( const ::basegfx::B2DHomMatrix& rMatrix ); // #i73264#
208 : : void addString( const char* pString );
209 : : void addStream( SvStream& rIn );
210 : :
211 : : static void writeMatrix( SvStream& rOut, const ::basegfx::B2DHomMatrix& rMatrix ); // #i73264#
212 : : static void writeRect( SvStream& rOut, const Rectangle& rRect );
213 : :
214 : : private:
215 : : sal_uInt8 mnTagId;
216 : : };
217 : :
218 : : ///////////////////////////////////////////////////////////////////////
219 : :
220 : : /** this class helps to define flash sprites */
221 : : class Sprite
222 : : {
223 : : public:
224 : : Sprite( sal_uInt16 nId );
225 : : ~Sprite();
226 : :
227 : : void write( SvStream& out );
228 : :
229 : : sal_uInt16 getId() const { return mnId; }
230 : :
231 : : void addTag( Tag* pNewTag );
232 : :
233 : : private:
234 : : std::vector< Tag* > maTags;
235 : : sal_uInt16 mnId;
236 : : sal_uInt32 mnFrames;
237 : : };
238 : :
239 : : ///////////////////////////////////////////////////////////////////////
240 : :
241 : : /** this class stores a flash fill style for shapes */
242 : 0 : class FillStyle
243 : : {
244 : : public:
245 : : enum FillStyleType { solid = 0x00, linear_gradient = 0x10, radial_gradient = 0x12, tiled_bitmap = 0x40, clipped_bitmap = 0x41 };
246 : :
247 : : /** this c'tor creates a solid fill style */
248 : : FillStyle( const Color& rSolidColor );
249 : :
250 : : /** this c'tor creates a linear or radial gradient fill style */
251 : : FillStyle( const Rectangle& rBoundRect, const Gradient& rGradient );
252 : :
253 : : /** this c'tor creates a tiled or clipped bitmap fill style */
254 : : FillStyle( sal_uInt16 nBitmapId, bool bClipped, const ::basegfx::B2DHomMatrix& rMatrix ); // #i73264#
255 : :
256 : : void addTo( Tag* pTag ) const;
257 : :
258 : : private:
259 : : void Impl_addGradient( Tag* pTag ) const;
260 : :
261 : : FillStyleType meType;
262 : : ::basegfx::B2DHomMatrix maMatrix; // #i73264#
263 : : sal_uInt16 mnBitmapId;
264 : : Color maColor;
265 : : Gradient maGradient;
266 : : Rectangle maBoundRect;
267 : : };
268 : :
269 : : ///////////////////////////////////////////////////////////////////////
270 : :
271 : : /** this class creates a flash movie from vcl geometry */
272 : : class Writer
273 : : {
274 : : friend class FlashFont;
275 : :
276 : : public:
277 : : /** creates a writer for a new flash movie.
278 : : nDocWidth and nDocHeight are the dimensions of the movie.
279 : : They must be in 100th/mm.
280 : :
281 : : An invisible shape with the size of the document is placed at depth 1
282 : : and it clips all shapes on depth 2 and 3.
283 : : */
284 : : Writer( sal_Int32 nDocWidthInput, sal_Int32 nDocHeightInput, sal_Int32 nDocWidth, sal_Int32 nDocHeight, sal_Int32 nJPEGcompressMode = -1 );
285 : : ~Writer();
286 : :
287 : : void storeTo( com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > &xOutStream );
288 : :
289 : : // geometry
290 : : void setClipping( const PolyPolygon* pClipPolyPolygon );
291 : :
292 : : /** defines a flash shape from a filled polygon.
293 : : The coordinates must be in twips */
294 : : sal_uInt16 defineShape( const Polygon& rPoly, const FillStyle& rFillStyle );
295 : :
296 : : /** defines a flash shape from a filled polypolygon.
297 : : The coordinates must be in twips */
298 : : sal_uInt16 defineShape( const PolyPolygon& rPolyPoly, const FillStyle& rFillStyle );
299 : :
300 : : /** defines a flash shape from a outlined polypolygon.
301 : : The coordinates must be in twips */
302 : : sal_uInt16 defineShape( const PolyPolygon& rPolyPoly, sal_uInt16 nLineWidth, const Color& rLineColor );
303 : :
304 : : /** defines a flash shape from a vcl metafile.
305 : : The mapmode of the metafile is used to map all coordinates to twips.
306 : : A character id of a flash sprite is returned that contains all geometry
307 : : from the metafile.
308 : : */
309 : : sal_uInt16 defineShape( const GDIMetaFile& rMtf, sal_Int16 x = 0, sal_Int16 y = 0 );
310 : :
311 : : /** defines a bitmap and returns its flash id.
312 : : */
313 : : sal_uInt16 defineBitmap( const BitmapEx& bmpSource, sal_Int32 nJPEGQualityLevel );
314 : :
315 : : // control tags
316 : :
317 : : /** inserts a place shape tag into the movie stream or the current sprite */
318 : : void placeShape( sal_uInt16 nID, sal_uInt16 nDepth, sal_Int32 x, sal_Int32 y, sal_uInt16 nClipDepth = 0, const char* pName = NULL );
319 : :
320 : : #ifdef THEFUTURE
321 : : /** inserts a move shape tag into the movie stream or the current sprite */
322 : : void moveShape( sal_uInt16 nDepth, sal_Int32 x, sal_Int32 y );
323 : : #endif
324 : :
325 : : /** inserts a remove shape tag into the movie stream or the current sprite */
326 : : void removeShape( sal_uInt16 nDepth );
327 : :
328 : : /** inserts a show frame tag into the movie stream or the current sprite */
329 : : void showFrame();
330 : :
331 : : /** creates a new sprite and sets it as the current sprite for editing.
332 : : Only one sprite can be edited at one time */
333 : : sal_uInt16 startSprite();
334 : :
335 : : /** ends editing of the curent sprites and adds it to the movie stream */
336 : : void endSprite();
337 : :
338 : : /** inserts a doaction tag with an ActionStop */
339 : : void stop();
340 : :
341 : : /** inserts a doaction tag with an ActionStop, place a button on depth nDepth that
342 : : continues playback on click */
343 : : void waitOnClick( sal_uInt16 nDepth );
344 : :
345 : : /** inserts a doaction tag with an ActionGotoFrame */
346 : : void gotoFrame( sal_uInt16 nFrame );
347 : :
348 : : #ifdef AUGUSTUS
349 : : /** stream out a sound. Should make it more intelligent so it interleaves with other items.*/
350 : : sal_Bool streamSound( const char * filename );
351 : : #endif
352 : :
353 : : private:
354 : : Point map( const Point& rPoint ) const;
355 : : Size map( const Size& rSize ) const;
356 : : void map( PolyPolygon& rPolyPolygon ) const;
357 : : sal_Int32 mapRelative( sal_Int32 n100thMM ) const;
358 : :
359 : : void startTag( sal_uInt8 nTagId );
360 : : void endTag();
361 : : sal_uInt16 createID();
362 : :
363 : : void Impl_writeBmp( sal_uInt16 nBitmapId, sal_uInt32 width, sal_uInt32 height, sal_uInt8 *pCompressed, sal_uInt32 compressed_size );
364 : : void Impl_writeImage( const BitmapEx& rBmpEx, const Point& rPt, const Size& rSz, const Point& rSrcPt, const Size& rSrcSz, const Rectangle& rClipRect, bool bMap );
365 : : void Impl_writeJPEG(sal_uInt16 nBitmapId, const sal_uInt8* pJpgData, sal_uInt32 nJpgDataLength, sal_uInt8 *pCompressed, sal_uInt32 compressed_size );
366 : : void Impl_handleLineInfoPolyPolygons(const LineInfo& rInfo, const basegfx::B2DPolygon& rLinePolygon);
367 : : void Impl_writeActions( const GDIMetaFile& rMtf );
368 : : void Impl_writePolygon( const Polygon& rPoly, sal_Bool bFilled );
369 : : void Impl_writePolygon( const Polygon& rPoly, sal_Bool bFilled, const Color& rFillColor, const Color& rLineColor );
370 : : void Impl_writePolyPolygon( const PolyPolygon& rPolyPoly, sal_Bool bFilled, sal_uInt8 nTransparence = 0);
371 : : void Impl_writePolyPolygon( const PolyPolygon& rPolyPoly, sal_Bool bFilled, const Color& rFillColor, const Color& rLineColor );
372 : : void Impl_writeText( const Point& rPos, const String& rText, const sal_Int32* pDXArray, long nWidth );
373 : : void Impl_writeText( const Point& rPos, const String& rText, const sal_Int32* pDXArray, long nWidth, Color aTextColor );
374 : : void Impl_writeGradientEx( const PolyPolygon& rPolyPoly, const Gradient& rGradient );
375 : : void Impl_writeLine( const Point& rPt1, const Point& rPt2, const Color* pLineColor = NULL );
376 : : void Impl_writeRect( const Rectangle& rRect, long nRadX, long nRadY );
377 : : void Impl_writeEllipse( const Point& rCenter, long nRadX, long nRadY );
378 : : bool Impl_writeFilling( SvtGraphicFill& rFilling );
379 : : bool Impl_writeStroke( SvtGraphicStroke& rStroke );
380 : :
381 : : FlashFont& Impl_getFont( const Font& rFont );
382 : :
383 : : static void Impl_addPolygon( BitStream& rBits, const Polygon& rPoly, sal_Bool bFilled );
384 : :
385 : : static void Impl_addShapeRecordChange( BitStream& rBits, sal_Int16 dx, sal_Int16 dy, sal_Bool bFilled );
386 : : static void Impl_addStraightEdgeRecord( BitStream& rBits, sal_Int16 dx, sal_Int16 dy );
387 : : static void Impl_addCurvedEdgeRecord( BitStream& rBits, sal_Int16 control_dx, sal_Int16 control_dy, sal_Int16 anchor_dx, sal_Int16 anchor_dy );
388 : : static void Impl_addEndShapeRecord( BitStream& rBits );
389 : :
390 : : static void Impl_addStraightLine( BitStream& rBits,
391 : : Point& rLastPoint,
392 : : const double P2x, const double P2y );
393 : : static void Impl_addQuadBezier( BitStream& rBits,
394 : : Point& rLastPoint,
395 : : const double P2x, const double P2y,
396 : : const double P3x, const double P3y );
397 : : static void Impl_quadBezierApprox( BitStream& rBits,
398 : : Point& rLastPoint,
399 : : const double d2,
400 : : const double P1x, const double P1y,
401 : : const double P2x, const double P2y,
402 : : const double P3x, const double P3y,
403 : : const double P4x, const double P4y );
404 : :
405 : : com::sun::star::uno::Reference < com::sun::star::i18n::XBreakIterator > Impl_GetBreakIterator();
406 : :
407 : : private:
408 : : com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > mxBreakIterator;
409 : :
410 : : FontMap maFonts;
411 : :
412 : : sal_Int32 mnDocWidth;
413 : : sal_Int32 mnDocHeight;
414 : :
415 : : // AS: Scaling factor for output.
416 : : double mnDocXScale;
417 : : double mnDocYScale;
418 : :
419 : : sal_uInt16 mnWhiteBackgroundShapeId;
420 : : sal_uInt16 mnPageButtonId;
421 : :
422 : : VirtualDevice* mpVDev;
423 : :
424 : : const PolyPolygon* mpClipPolyPolygon;
425 : :
426 : : /** holds the informations of the objects defined in the movie stream
427 : : while executing defineShape
428 : : */
429 : : typedef std::vector<sal_uInt16> CharacterIdVector;
430 : : CharacterIdVector maShapeIds;
431 : :
432 : : Tag* mpTag;
433 : : Sprite* mpSprite;
434 : : std::stack<Sprite*> mvSpriteStack;
435 : : ChecksumCache mBitmapCache;
436 : :
437 : : sal_uInt16 mnNextId;
438 : : sal_uInt32 mnFrames;
439 : :
440 : : // com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > mxOutStream;
441 : : oslFileHandle mxOutStream;
442 : :
443 : : utl::TempFile maMovieTempFile;
444 : : utl::TempFile maFontsTempFile;
445 : :
446 : : SvStream* mpMovieStream;
447 : : SvStream* mpFontsStream;
448 : :
449 : : #ifdef AUGUSTUS
450 : : lame_global_flags *m_lame_flags;
451 : : #endif
452 : :
453 : : sal_uInt8 mnGlobalTransparency;
454 : : sal_Int32 mnJPEGCompressMode;
455 : : };
456 : :
457 : : ///////////////////////////////////////////////////////////////////////
458 : :
459 : : }
460 : :
461 : : #endif
462 : :
463 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|