LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/filter/source/svg - svgwriter.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 29 0.0 %
Date: 2013-07-09 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 SVGWRITER_HXX
      21             : #define SVGWRITER_HXX
      22             : 
      23             : #include <stack>
      24             : #include <cppuhelper/implbase1.hxx>
      25             : #include <rtl/ustring.hxx>
      26             : #include <tools/stream.hxx>
      27             : #include <tools/string.hxx>
      28             : #include <vcl/gdimtf.hxx>
      29             : #include <vcl/metaact.hxx>
      30             : #include <vcl/metric.hxx>
      31             : #include <vcl/virdev.hxx>
      32             : #include <vcl/cvtgrf.hxx>
      33             : #include <vcl/graphictools.hxx>
      34             : #include <xmloff/xmlexp.hxx>
      35             : #include <xmloff/nmspmap.hxx>
      36             : 
      37             : #include <com/sun/star/uno/Reference.h>
      38             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      39             : #include <com/sun/star/container/XContentEnumerationAccess.hpp>
      40             : #include <com/sun/star/container/XEnumeration.hpp>
      41             : #include <com/sun/star/container/XIndexReplace.hpp>
      42             : #include <com/sun/star/lang/XServiceInfo.hpp>
      43             : #include <com/sun/star/beans/XPropertySet.hpp>
      44             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      45             : #include <com/sun/star/uno/RuntimeException.hpp>
      46             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      47             : #include <com/sun/star/lang/XComponent.hpp>
      48             : #include <com/sun/star/registry/XRegistryKey.hpp>
      49             : #include <com/sun/star/io/XInputStream.hpp>
      50             : #include <com/sun/star/io/XOutputStream.hpp>
      51             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      52             : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
      53             : #include <com/sun/star/i18n/CharacterIteratorMode.hpp>
      54             : #include <com/sun/star/i18n/XBreakIterator.hpp>
      55             : #include <com/sun/star/drawing/XShape.hpp>
      56             : #include <com/sun/star/text/XText.hpp>
      57             : #include <com/sun/star/text/XTextContent.hpp>
      58             : #include <com/sun/star/text/XTextRange.hpp>
      59             : #include <com/sun/star/text/XTextField.hpp>
      60             : #include <com/sun/star/style/NumberingType.hpp>
      61             : #include <com/sun/star/svg/XSVGWriter.hpp>
      62             : 
      63             : // -----------------------------------------------------------------------------
      64             : 
      65             : using namespace ::com::sun::star::uno;
      66             : using namespace ::com::sun::star::container;
      67             : using namespace ::com::sun::star::lang;
      68             : using namespace ::com::sun::star::text;
      69             : using namespace ::com::sun::star::drawing;
      70             : using namespace ::com::sun::star::style;
      71             : using namespace ::com::sun::star::svg;
      72             : using namespace ::com::sun::star::xml::sax;
      73             : 
      74             : // -----------------------------------------------------------------------------
      75             : 
      76             : #define SVG_DTD_STRING            OUString( "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" )
      77             : #define SVG_TINY_DTD_STRING       OUString( "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG Tiny 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd\">" )
      78             : 
      79             : #define SVGWRITER_WRITE_NONE    0x00000000
      80             : #define SVGWRITER_WRITE_FILL    0x00000001
      81             : #define SVGWRITER_WRITE_TEXT    0x00000002
      82             : #define SVGWRITER_NO_SHAPE_COMMENTS 0x01000000
      83             : 
      84             : // ----------------------
      85             : // - SVGAttributeWriter -
      86             : // ----------------------
      87             : 
      88             : class SVGActionWriter;
      89             : class SVGExport;
      90             : class SVGFontExport;
      91             : 
      92             : class SVGAttributeWriter
      93             : {
      94             : private:
      95             : 
      96             :     Font                       maCurFont;
      97             :     Color                      maCurLineColor;
      98             :     Color                      maCurFillColor;
      99             :     SVGExport&                 mrExport;
     100             :     SVGFontExport&             mrFontExport;
     101             :     SvXMLElementExport*        mpElemFont;
     102             :     SvXMLElementExport*        mpElemPaint;
     103             : 
     104             :     basegfx::B2DLineJoin maLineJoin;
     105             :     com::sun::star::drawing::LineCap maLineCap;
     106             : 
     107             :                             SVGAttributeWriter();
     108             : 
     109             :     double                  ImplRound( double fVal, sal_Int32 nDecs = 3 );
     110             : 
     111             : public:
     112             : 
     113             :                             SVGAttributeWriter( SVGExport& rExport, SVGFontExport& rFontExport );
     114             :     virtual                 ~SVGAttributeWriter();
     115             : 
     116             :     void                    AddColorAttr( const char* pColorAttrName, const char* pColorOpacityAttrName, const Color& rColor );
     117             :     void                    AddGradientDef( const Rectangle& rObjRect,const Gradient& rGradient, OUString& rGradientId );
     118             :     void                    AddPaintAttr( const Color& rLineColor, const Color& rFillColor,
     119             :                                           const Rectangle* pObjBoundRect = NULL, const Gradient* pFillGradient = NULL );
     120             : 
     121             :     void                    SetFontAttr( const Font& rFont );
     122             :     void                    startFontSettings();
     123             :     void                    endFontSettings();
     124             :     void                    setFontFamily();
     125             : 
     126             :     static void             ImplGetColorStr( const Color& rColor, OUString& rColorStr );
     127             : };
     128             : 
     129           0 : struct SVGShapeDescriptor
     130             : {
     131             :     PolyPolygon                 maShapePolyPoly;
     132             :     Color                       maShapeFillColor;
     133             :     Color                       maShapeLineColor;
     134             :     sal_Int32                   mnStrokeWidth;
     135             :     SvtGraphicStroke::DashArray maDashArray;
     136             :     ::std::auto_ptr< Gradient > mapShapeGradient;
     137             :     OUString             maId;
     138             : 
     139             :     basegfx::B2DLineJoin                maLineJoin;
     140             :     com::sun::star::drawing::LineCap    maLineCap;
     141             : 
     142             :     // -------------------------------------------------------------------------
     143             : 
     144           0 :     SVGShapeDescriptor() :
     145             :         maShapeFillColor( Color( COL_TRANSPARENT ) ),
     146             :         maShapeLineColor( Color( COL_TRANSPARENT ) ),
     147             :         mnStrokeWidth( 0 ),
     148             :         maLineJoin(basegfx::B2DLINEJOIN_MITER), // miter is Svg 'stroke-linejoin' default
     149           0 :         maLineCap(com::sun::star::drawing::LineCap_BUTT) // butt is Svg 'stroke-linecap' default
     150             :     {
     151           0 :     }
     152             : };
     153             : 
     154             : 
     155             : 
     156             : class SVGAttributeWriter;
     157             : class SVGExport;
     158             : class GDIMetaFile;
     159             : 
     160             : 
     161             : // ---------------------------
     162             : // - BulletListItemInfo -
     163             : // ---------------------------
     164           0 : struct BulletListItemInfo
     165             : {
     166             :     long nFontSize;
     167             :     Color aColor;
     168             :     Point aPos;
     169             :     sal_Unicode cBulletChar;
     170             : };
     171             : 
     172             : // ---------------------------
     173             : // - OUStringHasher -
     174             : // ---------------------------
     175             : 
     176             : struct OUStringHasher
     177             : {
     178           0 :     size_t operator()( const OUString& oustr ) const { return static_cast< size_t >( oustr.hashCode() ); }
     179             : };
     180             : 
     181             : 
     182             : // -------------------
     183             : // - SVGTextWriter -
     184             : // -------------------
     185             : class SVGTextWriter
     186             : {
     187             :   public:
     188             :     typedef ::boost::unordered_map< OUString, BulletListItemInfo, OUStringHasher >         BulletListItemInfoMap;
     189             : 
     190             :   private:
     191             :     SVGExport&                                  mrExport;
     192             :     SVGAttributeWriter*                         mpContext;
     193             :     VirtualDevice*                              mpVDev;
     194             :     sal_Bool                                    mbIsTextShapeStarted;
     195             :     Reference<XText>                            mrTextShape;
     196             :     OUString                             msShapeId;
     197             :     Reference<XEnumeration>                     mrParagraphEnumeration;
     198             :     Reference<XTextContent>                     mrCurrentTextParagraph;
     199             :     Reference<XEnumeration>                     mrTextPortionEnumeration;
     200             :     Reference<XTextRange>                       mrCurrentTextPortion;
     201             :     const GDIMetaFile*                          mpTextEmbeddedBitmapMtf;
     202             :     MapMode*                                    mpTargetMapMode;
     203             :     SvXMLElementExport*                         mpTextShapeElem;
     204             :     SvXMLElementExport*                         mpTextParagraphElem;
     205             :     SvXMLElementExport*                         mpTextPositionElem;
     206             :     sal_Int32                                   mnLeftTextPortionLength;
     207             :     Point                                       maTextPos;
     208             :     long int                                    mnTextWidth;
     209             :     sal_Bool                                    mbPositioningNeeded;
     210             :     sal_Bool                                    mbIsNewListItem;
     211             :     sal_Int16                                   meNumberingType;
     212             :     sal_Unicode                                 mcBulletChar;
     213             :     BulletListItemInfoMap                       maBulletListItemMap;
     214             :     sal_Bool                                    mbIsListLevelStyleImage;
     215             :     sal_Bool                                    mbLineBreak;
     216             :     sal_Bool                                    mbIsURLField;
     217             :     OUString                             msUrl;
     218             :     OUString                             msHyperlinkIdList;
     219             :     sal_Bool                                    mbIsPlacehlolderShape;
     220             :     sal_Bool                                    mbIWS;
     221             :     Font                                        maCurrentFont;
     222             :     Font                                        maParentFont;
     223             : 
     224             :   public:
     225             :     SVGTextWriter( SVGExport& rExport );
     226             :     virtual ~SVGTextWriter();
     227             : 
     228             :     sal_Int32 setTextPosition( const GDIMetaFile& rMtf, sal_uLong& nCurAction );
     229             :     void setTextProperties( const GDIMetaFile& rMtf, sal_uLong nCurAction );
     230             :     void addFontAttributes( sal_Bool bIsTextContainer );
     231             : 
     232             :     sal_Bool createParagraphEnumeration();
     233             :     sal_Bool nextParagraph();
     234             :     sal_Bool nextTextPortion();
     235             : 
     236           0 :     sal_Bool isTextShapeStarted() { return mbIsTextShapeStarted; }
     237             :     void startTextShape();
     238             :     void endTextShape();
     239             :     void startTextParagraph();
     240             :     void endTextParagraph();
     241             :     void startTextPosition( sal_Bool bExportX = sal_True, sal_Bool bExportY = sal_True);
     242             :     void endTextPosition();
     243             :     void implExportHyperlinkIds();
     244             :     void implWriteBulletChars();
     245             :     template< typename MetaBitmapActionType >
     246             :     void writeBitmapPlaceholder( const MetaBitmapActionType* pAction );
     247             :     void implWriteEmbeddedBitmaps();
     248             :     void writeTextPortion( const Point& rPos, const String& rText,
     249             :                            sal_Bool bApplyMapping = sal_True );
     250             :     void implWriteTextPortion( const Point& rPos, const String& rText,
     251             :                                Color aTextColor, sal_Bool bApplyMapping );
     252             : 
     253           0 :     void setVirtualDevice( VirtualDevice* pVDev, MapMode& rTargetMapMode )
     254             :     {
     255             :         if( !pVDev )
     256             :             OSL_FAIL( "SVGTextWriter::setVirtualDevice: invalid virtual device." );
     257           0 :         mpVDev = pVDev;
     258           0 :         mpTargetMapMode = &rTargetMapMode;
     259           0 :     }
     260             : 
     261           0 :     void setContext( SVGAttributeWriter* pContext )
     262             :     {
     263           0 :         mpContext = pContext;
     264           0 :     }
     265             : 
     266           0 :     void setTextShape( const Reference<XText>& rxText,
     267             :                        const GDIMetaFile* pTextEmbeddedBitmapMtf )
     268             :     {
     269           0 :         mrTextShape.set( rxText );
     270           0 :         mpTextEmbeddedBitmapMtf = pTextEmbeddedBitmapMtf;
     271           0 :     }
     272             : 
     273             :     const Reference<XText>& getTextShape() const
     274             :     {
     275             :         return mrTextShape;
     276             :     }
     277             : 
     278             : 
     279             :     void setPlaceholderShapeFlag( sal_Bool bState )
     280             :     {
     281             :         mbIsPlacehlolderShape = bState;
     282             :     }
     283             : 
     284             :   private:
     285             :     void implMap( const Size& rSz, Size& rDstSz ) const;
     286             :     void implMap( const Point& rPt, Point& rDstPt ) const;
     287             :     void implSetCurrentFont();
     288             :     void implSetFontFamily();
     289             : 
     290             :     template< typename SubType >
     291             :     sal_Bool implGetTextPosition( const MetaAction* pAction, Point& raPos, sal_Bool& bEmpty );
     292             :     template< typename SubType >
     293             :     sal_Bool implGetTextPositionFromBitmap( const MetaAction* pAction, Point& raPos, sal_Bool& rbEmpty );
     294             : 
     295             :     void implRegisterInterface( const Reference< XInterface >& rxIf );
     296             :     const OUString & implGetValidIDFromInterface( const Reference< XInterface >& rxIf );
     297             : 
     298             : 
     299             : };
     300             : 
     301             : // -------------------
     302             : // - SVGActionWriter -
     303             : // -------------------
     304             : 
     305             : class SVGActionWriter
     306             : {
     307             : private:
     308             : 
     309             :     sal_Int32                                   mnCurGradientId;
     310             :     sal_Int32                                   mnCurMaskId;
     311             :     sal_Int32                                   mnCurPatternId;
     312             :     ::std::stack< SVGAttributeWriter* >         maContextStack;
     313             :     ::std::auto_ptr< SVGShapeDescriptor >       mapCurShape;
     314             :     SVGExport&                                  mrExport;
     315             :     SVGFontExport&                              mrFontExport;
     316             :     SVGAttributeWriter*                         mpContext;
     317             :     SVGTextWriter                               maTextWriter;
     318             :     VirtualDevice*                              mpVDev;
     319             :     MapMode                                     maTargetMapMode;
     320             :     sal_uInt32                                  mnInnerMtfCount;
     321             :     sal_Bool                                    mbDestroyVDev;
     322             :     sal_Bool                                    mbPaintAttrChanged;
     323             :     sal_Bool                                    mbFontAttrChanged;
     324             :     sal_Bool                                    mbClipAttrChanged;
     325             :     sal_Bool                                    mbIsPlacehlolderShape;
     326             : 
     327             : 
     328           0 :     SVGAttributeWriter*     ImplAcquireContext()
     329             :     {
     330           0 :         maContextStack.push( mpContext = new SVGAttributeWriter( mrExport, mrFontExport ) );
     331           0 :         maTextWriter.setContext( mpContext );
     332           0 :         return mpContext;
     333             :     }
     334           0 :     void                    ImplReleaseContext()
     335             :     {
     336           0 :         if (!maContextStack.empty())
     337             :         {
     338           0 :             delete maContextStack.top();
     339           0 :             maContextStack.pop();
     340             :         }
     341           0 :         mpContext = (maContextStack.empty() ? NULL : maContextStack.top());
     342           0 :         maTextWriter.setContext( mpContext );
     343           0 :     }
     344             : 
     345             :     long                    ImplMap( sal_Int32 nVal ) const;
     346             :     Point&                  ImplMap( const Point& rPt, Point& rDstPt ) const;
     347             :     Size&                   ImplMap( const Size& rSz, Size& rDstSz ) const;
     348             :     Rectangle&              ImplMap( const Rectangle& rRect, Rectangle& rDstRect ) const;
     349             :     Polygon&                ImplMap( const Polygon& rPoly, Polygon& rDstPoly ) const;
     350             :     PolyPolygon&            ImplMap( const PolyPolygon& rPolyPoly, PolyPolygon& rDstPolyPoly ) const;
     351             : 
     352             :     void                    ImplWriteLine( const Point& rPt1, const Point& rPt2, const Color* pLineColor = NULL,
     353             :                                            sal_Bool bApplyMapping = sal_True );
     354             :     void                    ImplWriteRect( const Rectangle& rRect, long nRadX = 0, long nRadY = 0,
     355             :                                            sal_Bool bApplyMapping = sal_True );
     356             :     void                    ImplWriteEllipse( const Point& rCenter, long nRadX, long nRadY,
     357             :                                               sal_Bool bApplyMapping = sal_True );
     358             :     void                    ImplWritePattern( const PolyPolygon& rPolyPoly, const Hatch* pHatch, const Gradient* pGradient, sal_uInt32 nWriteFlags );
     359             :     void                    ImplAddLineAttr( const LineInfo &rAttrs,
     360             :                                              sal_Bool bApplyMapping = sal_True );
     361             :     void                    ImplWritePolyPolygon( const PolyPolygon& rPolyPoly, sal_Bool bLineOnly,
     362             :                                                   sal_Bool bApplyMapping = sal_True );
     363             :     void                    ImplWriteShape( const SVGShapeDescriptor& rShape, sal_Bool bApplyMapping = sal_True );
     364             :     void                    ImplWriteGradientEx( const PolyPolygon& rPolyPoly, const Gradient& rGradient, sal_uInt32 nWriteFlags,
     365             :                                                  sal_Bool bApplyMapping = sal_True );
     366             :     void                    ImplWriteGradientLinear( const PolyPolygon& rPolyPoly, const Gradient& rGradient );
     367             :     void                    ImplWriteGradientStop( const Color& rColor, double fOffset );
     368             :     Color                   ImplGetColorWithIntensity( const Color& rColor, sal_uInt16 nIntensity );
     369             :     Color                   ImplGetGradientColor( const Color& rStartColor, const Color& rEndColor, double fOffset );
     370             :     void                    ImplWriteMask( GDIMetaFile& rMtf, const Point& rDestPt, const Size& rDestSize, const Gradient& rGradient, sal_uInt32 nWriteFlags );
     371             :     void                    ImplWriteText( const Point& rPos, const String& rText, const sal_Int32* pDXArray, long nWidth, sal_Bool bApplyMapping = sal_True );
     372             :     void                    ImplWriteText( const Point& rPos, const String& rText, const sal_Int32* pDXArray, long nWidth, Color aTextColor, sal_Bool bApplyMapping );
     373             :     void                    ImplWriteBmp( const BitmapEx& rBmpEx, const Point& rPt, const Size& rSz, const Point& rSrcPt, const Size& rSrcSz,
     374             :                                           sal_Bool bApplyMapping = sal_True );
     375             : 
     376             :     void                    ImplCheckFontAttributes();
     377             :     void                    ImplCheckPaintAttributes();
     378             : 
     379             :     void                    ImplWriteActions( const GDIMetaFile& rMtf,
     380             :                                               sal_uInt32 nWriteFlags,
     381             :                                               const OUString* pElementId,
     382             :                                               const Reference< XShape >* pXShape = NULL,
     383             :                                               const GDIMetaFile* pTextEmbeddedBitmapMtf = NULL );
     384             : 
     385             :     Font                    ImplSetCorrectFontHeight() const;
     386             : 
     387             : public:
     388             : 
     389             :     static OUString  GetPathString( const PolyPolygon& rPolyPoly, sal_Bool bLine );
     390             :     static sal_uLong        GetChecksum( const MetaAction* pAction );
     391             : 
     392             : public:
     393             : 
     394             :                             SVGActionWriter( SVGExport& rExport, SVGFontExport& rFontExport );
     395             :     virtual                 ~SVGActionWriter();
     396             : 
     397             :     void                    WriteMetaFile( const Point& rPos100thmm,
     398             :                                            const Size& rSize100thmm,
     399             :                                            const GDIMetaFile& rMtf,
     400             :                                            sal_uInt32 nWriteFlags,
     401             :                                            const OUString* pElementId = NULL,
     402             :                                            const Reference< XShape >* pXShape = NULL,
     403             :                                            const GDIMetaFile* pTextEmbeddedBitmapMtf = NULL );
     404             : };
     405             : 
     406             : class SVGWriter : public cppu::WeakImplHelper1< XSVGWriter >
     407             : {
     408             : private:
     409             :     Reference< XComponentContext >                      mxContext;
     410             :     Sequence< com::sun::star::beans::PropertyValue >    maFilterData;
     411             :     SVGWriter();
     412             : 
     413             : public:
     414             :     explicit SVGWriter( const Sequence<Any>& args,
     415             :                         const Reference< XComponentContext >& rxCtx );
     416             :     virtual ~SVGWriter();
     417             : 
     418             :     // XSVGWriter
     419             :     virtual void SAL_CALL write( const Reference<XDocumentHandler>& rxDocHandler,
     420             :         const Sequence<sal_Int8>& rMtfSeq ) throw( RuntimeException );
     421             : };
     422             : 
     423             : #endif
     424             : 
     425             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10