bump product version to 4.1.6.2
[LibreOffice.git] / filter / source / flash / swfwriter.hxx
blob1bd30aff942981c7ede40faff6e497de87c37f9d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _SWF_WRITER_HXX_
21 #define _SWF_WRITER_HXX_
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <com/sun/star/io/XOutputStream.hpp>
25 #include <com/sun/star/i18n/XBreakIterator.hpp>
26 #include <vcl/font.hxx>
27 #include <vcl/gradient.hxx>
28 #include <unotools/tempfile.hxx>
29 #include <tools/color.hxx>
30 #include <tools/poly.hxx>
31 #include <tools/gen.hxx>
32 #include <tools/stream.hxx>
34 // #i73264#
35 #include <basegfx/matrix/b2dhommatrix.hxx>
36 #include <osl/file.hxx>
38 #include <vector>
39 #include <stack>
40 #include <map>
42 #ifdef AUGUSTUS
43 #include "lame.h"
44 #include "sndfile.h"
45 #endif
47 #include <stdio.h>
49 class GDIMetaFile;
50 class BitmapEx;
51 class PolyPolygon;
52 class Gradient;
53 class SvtGraphicFill;
54 class SvtGraphicStroke;
55 class LineInfo;
56 namespace basegfx { class B2DPolygon; }
58 inline sal_uInt16 _uInt16( sal_Int32 nValue )
60 OSL_ENSURE( (nValue >= 0) && ((sal_uInt32)nValue <= 0xffff), "overflow while converting sal_Int32 to sal_uInt16" );
61 return (sal_uInt16)nValue;
64 inline sal_Int16 _Int16( sal_Int32 nValue )
66 OSL_ENSURE( (nValue >= -32768) && (nValue <= 32767), "overflow while converting sal_Int32 to sal_Int16" );
67 return (sal_Int16)nValue;
70 class VirtualDevice;
72 namespace swf {
74 const sal_uInt8 TAG_END = 0;
75 const sal_uInt8 TAG_SHOWFRAME = 1;
77 const sal_uInt8 TAG_DEFINEBUTTON = 7;
79 const sal_uInt8 TAG_BACKGROUNDCOLOR = 9;
81 const sal_uInt8 TAG_DOACTION = 12;
82 const sal_uInt8 TAG_STARTSOUND = 15;
84 const sal_uInt8 TAG_SOUNDSTREAMBLOCK = 19;
85 const sal_uInt8 TAG_SOUNDSTREAMHEAD = 18;
86 const sal_uInt8 TAG_SOUNDSTREAMHEAD2 = 45;
88 const sal_uInt8 TAG_JPEGTABLES = 8;
89 const sal_uInt8 TAG_DEFINEBITS = 6;
90 const sal_uInt8 TAG_DEFINEBITSLOSSLESS = 20;
91 const sal_uInt8 TAG_DEFINEBITSJPEG2 = 21;
92 const sal_uInt8 TAG_DEFINEBITSJPEG3 = 35;
93 const sal_uInt8 TAG_DEFINEBITSLOSSLESS2 = 36;
94 const sal_uInt8 TAG_DEFINEEDITTEXT= 37;
95 const sal_uInt8 TAG_PLACEOBJECT = 4;
96 const sal_uInt8 TAG_PLACEOBJECT2 = 26;
97 const sal_uInt8 TAG_REMOVEOBJECT2 = 28;
99 const sal_uInt8 TAG_DEFINEFONT = 10;
100 const sal_uInt8 TAG_DEFINETEXT = 11;
101 const sal_uInt8 TAG_DEFINESHAPE3 = 32;
102 const sal_uInt8 TAG_DEFINESPRITE = 39;
104 const sal_uInt8 TAG_FRAMELABEL = 43;
106 const sal_uInt8 TAG_HEADER = 0xff;
108 ///////////////////////////////////////////////////////////////////////
110 /** converts a double to a 16.16 flash fixed value */
111 sal_uInt32 getFixed( double fValue );
113 ///////////////////////////////////////////////////////////////////////
115 typedef ::std::map<sal_uInt32, sal_uInt16> ChecksumCache;
117 /** unsigned int 16 compare operation for stl */
118 struct ltuint16
120 bool operator()(sal_uInt16 s1, sal_uInt16 s2) const
122 return s1 < s2;
126 ///////////////////////////////////////////////////////////////////////
128 /** container class to create bit structures */
129 class BitStream
131 public:
132 BitStream();
134 void writeUB( sal_uInt32 nValue, sal_uInt16 nBits );
135 void writeSB( sal_Int32 nValue, sal_uInt16 nBits );
136 void writeFB( sal_uInt32 nValue, sal_uInt16 nBits );
138 void pad();
139 void writeTo( SvStream& out );
141 sal_uInt32 getOffset() const;
142 private:
144 std::vector< sal_uInt8 > maData;
145 sal_uInt8 mnBitPos;
146 sal_uInt8 mnCurrentByte;
149 ///////////////////////////////////////////////////////////////////////
151 /** this class collects all used glyphs for a given fonts and maps
152 characters to glyph ids.
154 class FlashFont
156 public:
157 FlashFont( const Font& rFont, sal_uInt16 nId );
158 ~FlashFont();
160 sal_uInt16 getGlyph( sal_uInt16 nChar, VirtualDevice* pVDev );
162 void write( SvStream& out );
164 sal_uInt16 getID() const { return mnId; }
165 const Font& getFont() { return maFont; }
167 private:
168 const Font maFont;
169 std::map<sal_uInt16, sal_uInt16, ltuint16> maGlyphIndex;
170 sal_uInt16 mnNextIndex;
171 sal_uInt16 mnId;
172 BitStream maGlyphData;
173 std::vector< sal_uInt16 > maGlyphOffsets;
176 typedef std::vector<FlashFont*> FontMap;
178 ///////////////////////////////////////////////////////////////////////
180 /** this class helps creating flash tags */
181 class Tag : public SvMemoryStream
183 public:
184 Tag( sal_uInt8 nTagId );
186 sal_uInt8 getTagId() const { return mnTagId; }
188 void write( SvStream& out );
190 void addUI32( sal_uInt32 nValue );
191 void addUI16( sal_uInt16 nValue );
192 void addUI8( sal_uInt8 nValue );
193 void addBits( BitStream& rIn );
195 void addRGBA( const Color& rColor );
196 void addRGB( const Color& rColor );
197 void addRect( const Rectangle& rRect );
198 void addMatrix( const ::basegfx::B2DHomMatrix& rMatrix ); // #i73264#
199 void addString( const char* pString );
200 void addStream( SvStream& rIn );
202 static void writeMatrix( SvStream& rOut, const ::basegfx::B2DHomMatrix& rMatrix ); // #i73264#
203 static void writeRect( SvStream& rOut, const Rectangle& rRect );
205 private:
206 sal_uInt8 mnTagId;
209 ///////////////////////////////////////////////////////////////////////
211 /** this class helps to define flash sprites */
212 class Sprite
214 public:
215 Sprite( sal_uInt16 nId );
216 ~Sprite();
218 void write( SvStream& out );
220 sal_uInt16 getId() const { return mnId; }
222 void addTag( Tag* pNewTag );
224 private:
225 std::vector< Tag* > maTags;
226 sal_uInt16 mnId;
227 sal_uInt32 mnFrames;
230 ///////////////////////////////////////////////////////////////////////
232 /** this class stores a flash fill style for shapes */
233 class FillStyle
235 public:
236 enum FillStyleType { solid = 0x00, linear_gradient = 0x10, radial_gradient = 0x12, tiled_bitmap = 0x40, clipped_bitmap = 0x41 };
238 /** this c'tor creates a solid fill style */
239 FillStyle( const Color& rSolidColor );
241 /** this c'tor creates a linear or radial gradient fill style */
242 FillStyle( const Rectangle& rBoundRect, const Gradient& rGradient );
244 /** this c'tor creates a tiled or clipped bitmap fill style */
245 FillStyle( sal_uInt16 nBitmapId, bool bClipped, const ::basegfx::B2DHomMatrix& rMatrix ); // #i73264#
247 void addTo( Tag* pTag ) const;
249 private:
250 void Impl_addGradient( Tag* pTag ) const;
252 FillStyleType meType;
253 ::basegfx::B2DHomMatrix maMatrix; // #i73264#
254 sal_uInt16 mnBitmapId;
255 Color maColor;
256 Gradient maGradient;
257 Rectangle maBoundRect;
260 ///////////////////////////////////////////////////////////////////////
262 /** this class creates a flash movie from vcl geometry */
263 class Writer
265 friend class FlashFont;
267 public:
268 /** creates a writer for a new flash movie.
269 nDocWidth and nDocHeight are the dimensions of the movie.
270 They must be in 100th/mm.
272 An invisible shape with the size of the document is placed at depth 1
273 and it clips all shapes on depth 2 and 3.
275 Writer( sal_Int32 nDocWidthInput, sal_Int32 nDocHeightInput, sal_Int32 nDocWidth, sal_Int32 nDocHeight, sal_Int32 nJPEGcompressMode = -1 );
276 ~Writer();
278 void storeTo( com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > &xOutStream );
280 // geometry
281 void setClipping( const PolyPolygon* pClipPolyPolygon );
283 /** defines a flash shape from a filled polygon.
284 The coordinates must be in twips */
285 sal_uInt16 defineShape( const Polygon& rPoly, const FillStyle& rFillStyle );
287 /** defines a flash shape from a filled polypolygon.
288 The coordinates must be in twips */
289 sal_uInt16 defineShape( const PolyPolygon& rPolyPoly, const FillStyle& rFillStyle );
291 /** defines a flash shape from a outlined polypolygon.
292 The coordinates must be in twips */
293 sal_uInt16 defineShape( const PolyPolygon& rPolyPoly, sal_uInt16 nLineWidth, const Color& rLineColor );
295 /** defines a flash shape from a vcl metafile.
296 The mapmode of the metafile is used to map all coordinates to twips.
297 A character id of a flash sprite is returned that contains all geometry
298 from the metafile.
300 sal_uInt16 defineShape( const GDIMetaFile& rMtf, sal_Int16 x = 0, sal_Int16 y = 0 );
302 /** defines a bitmap and returns its flash id.
304 sal_uInt16 defineBitmap( const BitmapEx& bmpSource, sal_Int32 nJPEGQualityLevel );
306 // control tags
308 /** inserts a place shape tag into the movie stream or the current sprite */
309 void placeShape( sal_uInt16 nID, sal_uInt16 nDepth, sal_Int32 x, sal_Int32 y, sal_uInt16 nClipDepth = 0, const char* pName = NULL );
311 #ifdef THEFUTURE
312 /** inserts a move shape tag into the movie stream or the current sprite */
313 void moveShape( sal_uInt16 nDepth, sal_Int32 x, sal_Int32 y );
314 #endif
316 /** inserts a remove shape tag into the movie stream or the current sprite */
317 void removeShape( sal_uInt16 nDepth );
319 /** inserts a show frame tag into the movie stream or the current sprite */
320 void showFrame();
322 /** creates a new sprite and sets it as the current sprite for editing.
323 Only one sprite can be edited at one time */
324 sal_uInt16 startSprite();
326 /** ends editing of the curent sprites and adds it to the movie stream */
327 void endSprite();
329 /** inserts a doaction tag with an ActionStop */
330 void stop();
332 /** inserts a doaction tag with an ActionStop, place a button on depth nDepth that
333 continues playback on click */
334 void waitOnClick( sal_uInt16 nDepth );
336 /** inserts a doaction tag with an ActionGotoFrame */
337 void gotoFrame( sal_uInt16 nFrame );
339 #ifdef AUGUSTUS
340 /** stream out a sound. Should make it more intelligent so it interleaves with other items.*/
341 sal_Bool streamSound( const char * filename );
342 #endif
344 private:
345 Point map( const Point& rPoint ) const;
346 Size map( const Size& rSize ) const;
347 void map( PolyPolygon& rPolyPolygon ) const;
348 sal_Int32 mapRelative( sal_Int32 n100thMM ) const;
350 void startTag( sal_uInt8 nTagId );
351 void endTag();
352 sal_uInt16 createID();
354 void Impl_writeBmp( sal_uInt16 nBitmapId, sal_uInt32 width, sal_uInt32 height, sal_uInt8 *pCompressed, sal_uInt32 compressed_size );
355 void Impl_writeImage( const BitmapEx& rBmpEx, const Point& rPt, const Size& rSz, const Point& rSrcPt, const Size& rSrcSz, const Rectangle& rClipRect, bool bMap );
356 void Impl_writeJPEG(sal_uInt16 nBitmapId, const sal_uInt8* pJpgData, sal_uInt32 nJpgDataLength, sal_uInt8 *pCompressed, sal_uInt32 compressed_size );
357 void Impl_handleLineInfoPolyPolygons(const LineInfo& rInfo, const basegfx::B2DPolygon& rLinePolygon);
358 void Impl_writeActions( const GDIMetaFile& rMtf );
359 void Impl_writePolygon( const Polygon& rPoly, sal_Bool bFilled );
360 void Impl_writePolygon( const Polygon& rPoly, sal_Bool bFilled, const Color& rFillColor, const Color& rLineColor );
361 void Impl_writePolyPolygon( const PolyPolygon& rPolyPoly, sal_Bool bFilled, sal_uInt8 nTransparence = 0);
362 void Impl_writePolyPolygon( const PolyPolygon& rPolyPoly, sal_Bool bFilled, const Color& rFillColor, const Color& rLineColor );
363 void Impl_writeText( const Point& rPos, const String& rText, const sal_Int32* pDXArray, long nWidth );
364 void Impl_writeText( const Point& rPos, const String& rText, const sal_Int32* pDXArray, long nWidth, Color aTextColor );
365 void Impl_writeGradientEx( const PolyPolygon& rPolyPoly, const Gradient& rGradient );
366 void Impl_writeLine( const Point& rPt1, const Point& rPt2, const Color* pLineColor = NULL );
367 void Impl_writeRect( const Rectangle& rRect, long nRadX, long nRadY );
368 void Impl_writeEllipse( const Point& rCenter, long nRadX, long nRadY );
369 bool Impl_writeFilling( SvtGraphicFill& rFilling );
370 bool Impl_writeStroke( SvtGraphicStroke& rStroke );
372 FlashFont& Impl_getFont( const Font& rFont );
374 static void Impl_addPolygon( BitStream& rBits, const Polygon& rPoly, sal_Bool bFilled );
376 static void Impl_addShapeRecordChange( BitStream& rBits, sal_Int16 dx, sal_Int16 dy, sal_Bool bFilled );
377 static void Impl_addStraightEdgeRecord( BitStream& rBits, sal_Int16 dx, sal_Int16 dy );
378 static void Impl_addCurvedEdgeRecord( BitStream& rBits, sal_Int16 control_dx, sal_Int16 control_dy, sal_Int16 anchor_dx, sal_Int16 anchor_dy );
379 static void Impl_addEndShapeRecord( BitStream& rBits );
381 static void Impl_addStraightLine( BitStream& rBits,
382 Point& rLastPoint,
383 const double P2x, const double P2y );
384 static void Impl_addQuadBezier( BitStream& rBits,
385 Point& rLastPoint,
386 const double P2x, const double P2y,
387 const double P3x, const double P3y );
388 static void Impl_quadBezierApprox( BitStream& rBits,
389 Point& rLastPoint,
390 const double d2,
391 const double P1x, const double P1y,
392 const double P2x, const double P2y,
393 const double P3x, const double P3y,
394 const double P4x, const double P4y );
396 com::sun::star::uno::Reference < com::sun::star::i18n::XBreakIterator > Impl_GetBreakIterator();
398 private:
399 com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > mxBreakIterator;
401 FontMap maFonts;
403 sal_Int32 mnDocWidth;
404 sal_Int32 mnDocHeight;
406 // AS: Scaling factor for output.
407 double mnDocXScale;
408 double mnDocYScale;
410 sal_uInt16 mnWhiteBackgroundShapeId;
411 sal_uInt16 mnPageButtonId;
413 VirtualDevice* mpVDev;
415 const PolyPolygon* mpClipPolyPolygon;
417 /** holds the information of the objects defined in the movie stream
418 while executing defineShape
420 typedef std::vector<sal_uInt16> CharacterIdVector;
421 CharacterIdVector maShapeIds;
423 Tag* mpTag;
424 Sprite* mpSprite;
425 std::stack<Sprite*> mvSpriteStack;
426 ChecksumCache mBitmapCache;
428 sal_uInt16 mnNextId;
429 sal_uInt32 mnFrames;
431 // com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > mxOutStream;
432 oslFileHandle mxOutStream;
434 utl::TempFile maMovieTempFile;
435 utl::TempFile maFontsTempFile;
437 SvStream* mpMovieStream;
438 SvStream* mpFontsStream;
440 #ifdef AUGUSTUS
441 lame_global_flags *m_lame_flags;
442 #endif
444 sal_uInt8 mnGlobalTransparency;
445 sal_Int32 mnJPEGCompressMode;
448 ///////////////////////////////////////////////////////////////////////
452 #endif
454 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */