diff options
author | Marco Cecchetti <marco.cecchetti@collabora.com> | 2016-06-17 16:22:47 +0200 |
---|---|---|
committer | Marco Cecchetti <mrcekets@gmail.com> | 2016-07-01 09:41:58 +0000 |
commit | 0f95f4f99cf09b597cb9d7b575aed7ba776919dd (patch) | |
tree | ce6ef1c479dcfb27ee923d53e640a6b443a25a65 /filter/source/svg/svgwriter.hxx | |
parent | 1085035078ac1546238be5de2ec47f70a8caffb1 (diff) |
svg filter - rewritten context handling
Change-Id: I9c18f6ca641de2957cbbf8fd57035f5aa2e5c294
Reviewed-on: https://gerrit.libreoffice.org/26831
Reviewed-by: Marco Cecchetti <mrcekets@gmail.com>
Tested-by: Marco Cecchetti <mrcekets@gmail.com>
Diffstat (limited to 'filter/source/svg/svgwriter.hxx')
-rw-r--r-- | filter/source/svg/svgwriter.hxx | 93 |
1 files changed, 64 insertions, 29 deletions
diff --git a/filter/source/svg/svgwriter.hxx b/filter/source/svg/svgwriter.hxx index 76c2df0b1592..5c3b75772ba9 100644 --- a/filter/source/svg/svgwriter.hxx +++ b/filter/source/svg/svgwriter.hxx @@ -57,9 +57,11 @@ #include <com/sun/star/style/NumberingType.hpp> #include <com/sun/star/svg/XSVGWriter.hpp> +#include <memory> #include <stack> #include <unordered_map> + using namespace ::com::sun::star::uno; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; @@ -75,6 +77,59 @@ using namespace ::com::sun::star::xml::sax; #define SVGWRITER_WRITE_TEXT 0x00000002 #define SVGWRITER_NO_SHAPE_COMMENTS 0x01000000 + +struct SVGState +{ + vcl::Font aFont; +// Color aLineColor; +// Color aFillColor; +// basegfx::B2DLineJoin aLineJoin; +// com::sun::star::drawing::LineCap aLineCap; +}; +// - PartialState - + +struct PartialState +{ + PushFlags meFlags; + ::std::unique_ptr<vcl::Font> mupFont; + + const vcl::Font& getFont( const vcl::Font& rDefaultFont ) const + { return mupFont ? *mupFont : rDefaultFont; } + + void setFont( const vcl::Font& rFont ) + { mupFont.reset( new vcl::Font(rFont) ); } + + PartialState() + : meFlags( PushFlags::NONE ) + {} + + PartialState(PartialState&& aPartialState) + : meFlags( aPartialState.meFlags ) + , mupFont( std::move( aPartialState.mupFont ) ) + { + aPartialState.meFlags = PushFlags::NONE; + } +}; + + +// - SVGContextHandler - + +class SVGContextHandler +{ +private: + ::std::stack<PartialState> maStateStack; + SVGState maCurrentState; + +public: + PushFlags getLastUsedFlags() const; + SVGState& getCurrentState(); + void pushState( PushFlags eFlags ); + void popState(); +}; + + +// - SVGAttributeWriter - + class SVGActionWriter; class SVGExport; class SVGFontExport; @@ -84,16 +139,17 @@ class SVGAttributeWriter { private: - vcl::Font maCurFont; SVGExport& mrExport; SVGFontExport& mrFontExport; + SVGState& mrCurrentState; SvXMLElementExport* mpElemFont; - static double ImplRound( double fVal ); + static double ImplRound( double fVal ); + public: - SVGAttributeWriter( SVGExport& rExport, SVGFontExport& rFontExport ); + SVGAttributeWriter( SVGExport& rExport, SVGFontExport& rFontExport, SVGState& rCurState ); virtual ~SVGAttributeWriter(); void AddColorAttr( const char* pColorAttrName, const char* pColorOpacityAttrName, const Color& rColor ); @@ -154,7 +210,7 @@ class SVGTextWriter private: SVGExport& mrExport; - SVGAttributeWriter* mpContext; + SVGAttributeWriter& mrAttributeWriter; VclPtr<VirtualDevice> mpVDev; bool mbIsTextShapeStarted; Reference<XText> mrTextShape; @@ -187,7 +243,7 @@ class SVGTextWriter vcl::Font maParentFont; public: - explicit SVGTextWriter( SVGExport& rExport ); + explicit SVGTextWriter( SVGExport& rExport, SVGAttributeWriter& rAttributeWriter ); virtual ~SVGTextWriter(); sal_Int32 setTextPosition( const GDIMetaFile& rMtf, sal_uLong& nCurAction ); @@ -222,11 +278,6 @@ class SVGTextWriter mpTargetMapMode = &rTargetMapMode; } - void setContext( SVGAttributeWriter* pContext ) - { - mpContext = pContext; - } - void setTextShape( const Reference<XText>& rxText, const GDIMetaFile* pTextEmbeddedBitmapMtf ) { @@ -257,11 +308,11 @@ private: sal_Int32 mnCurGradientId; sal_Int32 mnCurMaskId; sal_Int32 mnCurPatternId; - ::std::stack< SVGAttributeWriter* > maContextStack; ::std::unique_ptr< SVGShapeDescriptor > mapCurShape; SVGExport& mrExport; - SVGFontExport& mrFontExport; - SVGAttributeWriter* mpContext; + SVGContextHandler maContextHandler; + SVGState& mrCurrentState; + SVGAttributeWriter maAttributeWriter; SVGTextWriter maTextWriter; VclPtr<VirtualDevice> mpVDev; MapMode maTargetMapMode; @@ -269,22 +320,6 @@ private: bool mbIsPlaceholderShape; - void ImplAcquireContext() - { - maContextStack.push( mpContext = new SVGAttributeWriter( mrExport, mrFontExport ) ); - maTextWriter.setContext( mpContext ); - } - void ImplReleaseContext() - { - if (!maContextStack.empty()) - { - delete maContextStack.top(); - maContextStack.pop(); - } - mpContext = (maContextStack.empty() ? nullptr : maContextStack.top()); - maTextWriter.setContext( mpContext ); - } - long ImplMap( sal_Int32 nVal ) const; Point& ImplMap( const Point& rPt, Point& rDstPt ) const; Size& ImplMap( const Size& rSz, Size& rDstSz ) const; |