1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_FILTER_SOURCE_FLASH_SWFWRITER_HXX
21 #define INCLUDED_FILTER_SOURCE_FLASH_SWFWRITER_HXX
23 #include <com/sun/star/io/XOutputStream.hpp>
24 #include <com/sun/star/i18n/XBreakIterator.hpp>
25 #include <vcl/checksum.hxx>
26 #include <vcl/font.hxx>
27 #include <vcl/gradient.hxx>
28 #include <vcl/vclptr.hxx>
29 #include <unotools/tempfile.hxx>
30 #include <tools/color.hxx>
31 #include <tools/gen.hxx>
32 #include <tools/stream.hxx>
33 #include <basegfx/matrix/b2dhommatrix.hxx>
34 #include <osl/file.hxx>
44 class SvtGraphicStroke
;
46 namespace basegfx
{ class B2DPolygon
; }
53 inline sal_uInt16
uInt16_( sal_Int32 nValue
)
55 OSL_ENSURE( (nValue
>= 0) && (static_cast<sal_uInt32
>(nValue
) <= 0xffff), "overflow while converting sal_Int32 to sal_uInt16" );
56 return static_cast<sal_uInt16
>(nValue
);
59 inline sal_Int16
Int16_( sal_Int32 nValue
)
61 OSL_ENSURE( (nValue
>= -32768) && (nValue
<= 32767), "overflow while converting sal_Int32 to sal_Int16" );
62 return static_cast<sal_Int16
>(nValue
);
67 sal_uInt16
getMaxBitsSigned( sal_Int32 nValue
);
71 const sal_uInt8 TAG_END
= 0;
72 const sal_uInt8 TAG_SHOWFRAME
= 1;
74 const sal_uInt8 TAG_DEFINEBUTTON
= 7;
76 const sal_uInt8 TAG_BACKGROUNDCOLOR
= 9;
78 const sal_uInt8 TAG_DOACTION
= 12;
79 const sal_uInt8 TAG_STARTSOUND
= 15;
81 const sal_uInt8 TAG_SOUNDSTREAMBLOCK
= 19;
82 const sal_uInt8 TAG_SOUNDSTREAMHEAD
= 18;
83 const sal_uInt8 TAG_SOUNDSTREAMHEAD2
= 45;
85 const sal_uInt8 TAG_JPEGTABLES
= 8;
86 const sal_uInt8 TAG_DEFINEBITS
= 6;
87 const sal_uInt8 TAG_DEFINEBITSLOSSLESS
= 20;
88 const sal_uInt8 TAG_DEFINEBITSJPEG2
= 21;
89 const sal_uInt8 TAG_DEFINEBITSJPEG3
= 35;
90 const sal_uInt8 TAG_DEFINEBITSLOSSLESS2
= 36;
91 const sal_uInt8 TAG_DEFINEEDITTEXT
= 37;
92 const sal_uInt8 TAG_PLACEOBJECT
= 4;
93 const sal_uInt8 TAG_PLACEOBJECT2
= 26;
94 const sal_uInt8 TAG_REMOVEOBJECT2
= 28;
96 const sal_uInt8 TAG_DEFINEFONT
= 10;
97 const sal_uInt8 TAG_DEFINETEXT
= 11;
98 const sal_uInt8 TAG_DEFINESHAPE3
= 32;
99 const sal_uInt8 TAG_DEFINESPRITE
= 39;
101 const sal_uInt8 TAG_FRAMELABEL
= 43;
103 const sal_uInt8 TAG_HEADER
= 0xff;
106 /** converts a double to a 16.16 flash fixed value */
107 sal_uInt32
getFixed( double fValue
);
110 typedef ::std::map
<BitmapChecksum
, sal_uInt16
> ChecksumCache
;
112 /** container class to create bit structures */
118 void writeUB( sal_uInt32 nValue
, sal_uInt16 nBits
);
119 void writeSB( sal_Int32 nValue
, sal_uInt16 nBits
);
120 void writeFB( sal_uInt32 nValue
, sal_uInt16 nBits
);
123 void writeTo( SvStream
& out
);
125 sal_uInt32
getOffset() const;
128 std::vector
< sal_uInt8
> maData
;
130 sal_uInt8 mnCurrentByte
;
134 /** this class collects all used glyphs for a given fonts and maps
135 characters to glyph ids.
140 FlashFont( const vcl::Font
& rFont
, sal_uInt16 nId
);
143 sal_uInt16
getGlyph( sal_uInt16 nChar
, VirtualDevice
* pVDev
);
145 void write( SvStream
& out
);
147 sal_uInt16
getID() const { return mnId
; }
148 const vcl::Font
& getFont() const { return maFont
; }
151 const vcl::Font maFont
;
152 std::map
<sal_uInt16
, sal_uInt16
> maGlyphIndex
;
153 sal_uInt16 mnNextIndex
;
155 BitStream maGlyphData
;
156 std::vector
< sal_uInt16
> maGlyphOffsets
;
159 /** this class helps creating flash tags */
160 class Tag
: public SvMemoryStream
163 explicit Tag( sal_uInt8 nTagId
);
165 sal_uInt8
getTagId() const { return mnTagId
; }
167 void write( SvStream
& out
);
169 void addUI32( sal_uInt32 nValue
);
170 void addUI16( sal_uInt16 nValue
);
171 void addUI8( sal_uInt8 nValue
);
172 void addBits( BitStream
& rIn
);
174 void addRGBA( const Color
& rColor
);
175 void addRGB( const Color
& rColor
);
176 void addRect( const tools::Rectangle
& rRect
);
177 void addMatrix( const ::basegfx::B2DHomMatrix
& rMatrix
); // #i73264#
178 void addStream( SvStream
& rIn
);
180 static void writeMatrix( SvStream
& rOut
, const ::basegfx::B2DHomMatrix
& rMatrix
); // #i73264#
181 static void writeRect( SvStream
& rOut
, const tools::Rectangle
& rRect
);
188 /** this class helps to define flash sprites */
192 explicit Sprite( sal_uInt16 nId
);
195 void write( SvStream
& out
);
196 void addTag( std::unique_ptr
<Tag
> pNewTag
);
199 std::vector
< std::unique_ptr
<Tag
> > maTags
;
205 /** this class stores a flash fill style for shapes */
209 enum FillStyleType
{ solid
= 0x00, linear_gradient
= 0x10, radial_gradient
= 0x12, tiled_bitmap
= 0x40, clipped_bitmap
= 0x41 };
211 /** this c'tor creates a solid fill style */
212 explicit FillStyle( const Color
& rSolidColor
);
214 /** this c'tor creates a linear or radial gradient fill style */
215 FillStyle( const tools::Rectangle
& rBoundRect
, const Gradient
& rGradient
);
217 /** this c'tor creates a tiled or clipped bitmap fill style */
218 FillStyle( sal_uInt16 nBitmapId
, bool bClipped
, const ::basegfx::B2DHomMatrix
& rMatrix
); // #i73264#
220 void addTo( Tag
* pTag
) const;
223 void Impl_addGradient( Tag
* pTag
) const;
225 FillStyleType meType
;
226 ::basegfx::B2DHomMatrix maMatrix
; // #i73264#
227 sal_uInt16 mnBitmapId
;
230 tools::Rectangle maBoundRect
;
234 /** this class creates a flash movie from vcl geometry */
237 friend class FlashFont
;
240 /** creates a writer for a new flash movie.
241 nDocWidth and nDocHeight are the dimensions of the movie.
242 They must be in 100th/mm.
244 An invisible shape with the size of the document is placed at depth 1
245 and it clips all shapes on depth 2 and 3.
247 Writer( sal_Int32 nTWIPWidthOutput
, sal_Int32 nTWIPHeightOutput
, sal_Int32 nDocWidth
, sal_Int32 nDocHeight
, sal_Int32 nJPEGcompressMode
);
250 void storeTo( css::uno::Reference
< css::io::XOutputStream
> const &xOutStream
);
253 void setClipping( const tools::PolyPolygon
* pClipPolyPolygon
);
255 /** defines a flash shape from a filled polygon.
256 The coordinates must be in twips */
257 sal_uInt16
defineShape( const tools::Polygon
& rPoly
, const FillStyle
& rFillStyle
);
259 /** defines a flash shape from a filled polypolygon.
260 The coordinates must be in twips */
261 sal_uInt16
defineShape( const tools::PolyPolygon
& rPolyPoly
, const FillStyle
& rFillStyle
);
263 /** defines a flash shape from an outlined polypolygon.
264 The coordinates must be in twips */
265 sal_uInt16
defineShape( const tools::PolyPolygon
& rPolyPoly
, sal_uInt16 nLineWidth
, const Color
& rLineColor
);
267 /** defines a flash shape from a vcl metafile.
268 The mapmode of the metafile is used to map all coordinates to twips.
269 A character id of a flash sprite is returned that contains all geometry
272 sal_uInt16
defineShape( const GDIMetaFile
& rMtf
);
274 /** defines a bitmap and returns its flash id.
276 sal_uInt16
defineBitmap( const BitmapEx
& bmpSource
, sal_Int32 nJPEGQualityLevel
);
280 /** inserts a place shape tag into the movie stream or the current sprite */
281 void placeShape( sal_uInt16 nID
, sal_uInt16 nDepth
, sal_Int32 x
, sal_Int32 y
);
283 /** inserts a remove shape tag into the movie stream or the current sprite */
284 void removeShape( sal_uInt16 nDepth
);
286 /** inserts a show frame tag into the movie stream or the current sprite */
289 /** creates a new sprite and sets it as the current sprite for editing.
290 Only one sprite can be edited at one time */
291 sal_uInt16
startSprite();
293 /** ends editing of the current sprites and adds it to the movie stream */
296 /** inserts a doaction tag with an ActionStop */
299 /** inserts a doaction tag with an ActionStop, place a button on depth nDepth that
300 continues playback on click */
301 void waitOnClick( sal_uInt16 nDepth
);
303 /** inserts a doaction tag with an ActionGotoFrame */
304 void gotoFrame( sal_uInt16 nFrame
);
307 Point
map( const Point
& rPoint
) const;
308 Size
map( const Size
& rSize
) const;
309 void map( tools::PolyPolygon
& rPolyPolygon
) const;
310 sal_Int32
mapRelative( sal_Int32 n100thMM
) const;
312 void startTag( sal_uInt8 nTagId
);
314 sal_uInt16
createID() { return mnNextId
++; }
316 void Impl_writeBmp( sal_uInt16 nBitmapId
, sal_uInt32 width
, sal_uInt32 height
, sal_uInt8
const *pCompressed
, sal_uInt32 compressed_size
);
317 void Impl_writeImage( const BitmapEx
& rBmpEx
, const Point
& rPt
, const Size
& rSz
, const Point
& rSrcPt
, const Size
& rSrcSz
, const tools::Rectangle
& rClipRect
, bool bMap
);
318 void Impl_writeJPEG(sal_uInt16 nBitmapId
, const sal_uInt8
* pJpgData
, sal_uInt32 nJpgDataLength
, sal_uInt8
const *pCompressed
, sal_uInt32 compressed_size
);
319 void Impl_handleLineInfoPolyPolygons(const LineInfo
& rInfo
, const basegfx::B2DPolygon
& rLinePolygon
);
320 void Impl_writeActions( const GDIMetaFile
& rMtf
);
321 void Impl_writePolygon( const tools::Polygon
& rPoly
, bool bFilled
);
322 void Impl_writePolygon( const tools::Polygon
& rPoly
, bool bFilled
, const Color
& rFillColor
, const Color
& rLineColor
);
323 void Impl_writePolyPolygon( const tools::PolyPolygon
& rPolyPoly
, bool bFilled
, sal_uInt8 nTransparence
= 0);
324 void Impl_writePolyPolygon( const tools::PolyPolygon
& rPolyPoly
, bool bFilled
, const Color
& rFillColor
, const Color
& rLineColor
);
325 void Impl_writeText( const Point
& rPos
, const OUString
& rText
, const long* pDXArray
, long nWidth
);
326 void Impl_writeText( const Point
& rPos
, const OUString
& rText
, const long* pDXArray
, long nWidth
, Color aTextColor
);
327 void Impl_writeGradientEx( const tools::PolyPolygon
& rPolyPoly
, const Gradient
& rGradient
);
328 void Impl_writeLine( const Point
& rPt1
, const Point
& rPt2
, const Color
* pLineColor
= nullptr );
329 void Impl_writeRect( const tools::Rectangle
& rRect
, long nRadX
, long nRadY
);
330 void Impl_writeEllipse( const Point
& rCenter
, long nRadX
, long nRadY
);
331 bool Impl_writeFilling( SvtGraphicFill
const & rFilling
);
332 bool Impl_writeStroke( SvtGraphicStroke
const & rStroke
);
334 FlashFont
& Impl_getFont( const vcl::Font
& rFont
);
336 static void Impl_addPolygon( BitStream
& rBits
, const tools::Polygon
& rPoly
, bool bFilled
);
338 static void Impl_addShapeRecordChange( BitStream
& rBits
, sal_Int16 dx
, sal_Int16 dy
, bool bFilled
);
339 static void Impl_addStraightEdgeRecord( BitStream
& rBits
, sal_Int16 dx
, sal_Int16 dy
);
340 static void Impl_addCurvedEdgeRecord( BitStream
& rBits
, sal_Int16 control_dx
, sal_Int16 control_dy
, sal_Int16 anchor_dx
, sal_Int16 anchor_dy
);
341 static void Impl_addEndShapeRecord( BitStream
& rBits
);
343 static void Impl_addStraightLine( BitStream
& rBits
,
345 const double P2x
, const double P2y
);
346 static void Impl_addQuadBezier( BitStream
& rBits
,
348 const double P2x
, const double P2y
,
349 const double P3x
, const double P3y
);
350 static void Impl_quadBezierApprox( BitStream
& rBits
,
353 const double P1x
, const double P1y
,
354 const double P2x
, const double P2y
,
355 const double P3x
, const double P3y
,
356 const double P4x
, const double P4y
);
358 css::uno::Reference
< css::i18n::XBreakIterator
> const & Impl_GetBreakIterator();
361 css::uno::Reference
< css::i18n::XBreakIterator
> mxBreakIterator
;
363 std::vector
<std::unique_ptr
<FlashFont
>> maFonts
;
365 sal_Int32 mnDocWidth
;
366 sal_Int32 mnDocHeight
;
368 // AS: Scaling factor for output.
372 sal_uInt16 mnPageButtonId
;
374 VclPtrInstance
<VirtualDevice
> mpVDev
;
376 const tools::PolyPolygon
* mpClipPolyPolygon
;
378 /** holds the information of the objects defined in the movie stream
379 while executing defineShape
381 std::vector
<sal_uInt16
> maShapeIds
;
383 std::unique_ptr
<Tag
> mpTag
;
384 std::unique_ptr
<Sprite
> mpSprite
;
385 std::stack
<Sprite
*> mvSpriteStack
;
386 ChecksumCache mBitmapCache
;
391 utl::TempFile maMovieTempFile
;
392 utl::TempFile maFontsTempFile
;
394 SvStream
* mpMovieStream
;
395 SvStream
* mpFontsStream
;
397 sal_uInt8 mnGlobalTransparency
;
398 sal_Int32 mnJPEGCompressMode
;
406 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */