LCOV - code coverage report
Current view: top level - filter/source/flash - swfwriter.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 12 0.0 %
Date: 2014-04-11 Functions: 0 10 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10