ooo-build r11589 - in trunk: . patches/svgimport



Author: thorstenb
Date: Fri Feb 15 08:18:37 2008
New Revision: 11589
URL: http://svn.gnome.org/viewvc/ooo-build?rev=11589&view=rev

Log:
        * patches/svgimport/svg-filter.diff: adding attribute parsers
          for paint and color, switching stuff to boost::spirit there.
          Adding gperf-based tokenizer for elements and attributes.



Modified:
   trunk/ChangeLog
   trunk/patches/svgimport/svg-filter.diff

Modified: trunk/patches/svgimport/svg-filter.diff
==============================================================================
--- trunk/patches/svgimport/svg-filter.diff	(original)
+++ trunk/patches/svgimport/svg-filter.diff	Fri Feb 15 08:18:37 2008
@@ -696,12 +696,378 @@
 +        local:
 +                *;
 +}; 
+diff --git a/filter/source/svgimport/gentoken.pl b/filter/source/svgimport/gentoken.pl
+new file mode 100644
+index 0000000..124457f
+--- /dev/null
++++ filter/source/svgimport/gentoken.pl
+@@ -0,0 +1,58 @@
++# from oox/source/token - should really put this into solenv
++
++$ARGV0 = shift @ARGV;
++$ARGV1 = shift @ARGV;
++$ARGV2 = shift @ARGV;
++
++open ( TOKENS, $ARGV0 ) || die "can't open token file: $!";
++my %tokens;
++
++while ( defined ($line = <TOKENS>) )
++{
++	if( !($line =~ /^#/) )
++	{
++		chomp($line);
++		@token = split(/\s+/,$line);
++		if ( not defined ($token[1]) )
++		{
++			$token[1] = "XML_".$token[0];
++			$token[1] =~ tr/\-\.\:/___/;
++			$token[1] =~ s/\+/PLUS/g;
++			$token[1] =~ s/\-/MINUS/g;
++		}
++
++		$tokens{$token[0]} = uc($token[1]);
++	}
++}
++close ( TOKENS );
++
++open ( HXX, ">$ARGV1" ) || die "can't open tokens.hxx file: $!";
++open ( GPERF, ">$ARGV2" ) || die "can't open tokens.gperf file: $!";
++
++print ( GPERF "%language=C++\n" );
++print ( GPERF "%global-table\n" );
++print ( GPERF "%null-strings\n" );
++print ( GPERF "%struct-type\n" );
++print ( GPERF "struct xmltoken\n" );
++print ( GPERF "{\n" );
++print ( GPERF "  const sal_Char *name; sal_Int32 nToken; \n" );
++print ( GPERF "};\n" );
++print ( GPERF "%%\n" );
++
++print ( HXX "#ifndef INCLUDED_AUTOGEN_TOKEN_HXX\n" );
++print ( HXX "#define INCLUDED_AUTOGEN_TOKEN_HXX\n\n" );
++print ( HXX "#include <sal/types.h>\n\n" );
++
++$i = 0;
++foreach( sort(keys(%tokens)) )
++{
++	print( HXX "const sal_Int32 $tokens{$_} = $i;\n" );
++	print( GPERF "$_,$tokens{$_}\n" );
++	$i = $i + 1;
++}
++print ( GPERF "%%\n" );
++print ( HXX "const sal_Int32 XML_TOKEN_COUNT = $i;\n" );
++print ( HXX "const sal_Int32 XML_TOKEN_INVALID = -1;\n\n" );
++print ( HXX "#endif\n" );
++close ( HXX );
++close ( GPERF );
+diff --git a/filter/source/svgimport/gfxtypes.hxx b/filter/source/svgimport/gfxtypes.hxx
+new file mode 100644
+index 0000000..6d77d5e
+--- /dev/null
++++ filter/source/svgimport/gfxtypes.hxx
+@@ -0,0 +1,296 @@
++/*************************************************************************
++ *
++ *    OpenOffice.org - a multi-platform office productivity suite
++ *
++ *    Author:
++ *      Fridrich Strba  <fridrich strba bluewin ch>
++ *      Thorsten Behrens <tbehrens novell com>	   	
++ *
++ *      Copyright (C) 2008, Novell Inc.
++ *
++ *   The Contents of this file are made available subject to
++ *   the terms of GNU Lesser General Public License Version 2.1.
++ *
++ ************************************************************************/
++
++#ifndef INCLUDED_GFXTYPES_HXX
++#define INCLUDED_GFXTYPES_HXX
++
++#include <basegfx/range/b2drange.hxx>
++#include <basegfx/matrix/b2dhommatrix.hxx>
++#include <basegfx/polygon/b2dlinegeometry.hxx>
++
++#include <hash_set>
++
++namespace svgi
++{
++
++struct ARGBColor
++{
++    double toDoubleColor( sal_uInt8 val ) { return val/255.0; }
++
++    ARGBColor() : a(0.0), r(0.0), g(0.0), b(0.0)
++    {}
++    explicit ARGBColor(double fGrey) : a(1.0), r(fGrey), g(fGrey), b(fGrey)
++    {}
++    ARGBColor( double r_, double g_, double b_ ) : 
++        a(1.0), r(r_), g(g_), b(b_)
++    {}
++    ARGBColor( double a_, double r_, double g_, double b_ ) : 
++        a(a_), r(r_), g(g_), b(b_)
++    {}
++    ARGBColor( int r_, int g_, int b_ ) : 
++        a(1.0),
++        r(toDoubleColor(r_)), 
++        g(toDoubleColor(g_)), 
++        b(toDoubleColor(b_))
++    {}
++    ARGBColor( int a_, int r_, int g_, int b_ ) : 
++        a(toDoubleColor(a_)), 
++        r(toDoubleColor(r_)), 
++        g(toDoubleColor(g_)), 
++        b(toDoubleColor(b_))
++    {}
++    double a;
++    double r;
++    double g;
++    double b;
++};
++inline bool operator==( const ARGBColor& rLHS, const ARGBColor& rRHS )
++{ return rLHS.a==rRHS.a && rLHS.r==rRHS.r && rLHS.g==rRHS.g && rLHS.b==rRHS.b; }
++
++struct GradientStop
++{
++    GradientStop() : maStopColor(), mnStopPosition(0.0)
++    {}
++    ARGBColor maStopColor;
++    double    mnStopPosition;
++};
++inline bool operator==( const GradientStop& rLHS, const GradientStop& rRHS )
++{ return rLHS.mnStopPosition==rRHS.mnStopPosition && rLHS.maStopColor==rRHS.maStopColor; }
++
++struct Gradient
++{
++    Gradient() : maStops(), mbBoundingBoxUnits(false)
++    {}
++    std::vector<GradientStop> maStops;
++    bool                      mbBoundingBoxUnits;
++};
++
++inline bool operator==( const Gradient& rLHS, const Gradient& rRHS )
++{ return rLHS.mbBoundingBoxUnits==rRHS.mbBoundingBoxUnits && rLHS.maStops==rRHS.maStops; }
++
++enum PaintType
++{
++    NONE,
++    SOLID,
++    GRADIENT
++};
++
++enum FillRule
++{
++    NON_ZERO,
++    EVEN_ODD
++};
++
++enum TextAlign
++{
++    BEFORE,
++    CENTER,
++    AFTER
++};
++
++enum CapStyle
++{
++    BUTT,
++    RECT,
++    ROUND
++};
++
++enum FontStyle
++{
++    STYLE_NORMAL,
++    STYLE_OBLIQUE,
++    STYLE_ITALIC
++};
++
++enum FontVariant
++{
++    VARIANT_NORMAL,
++    VARIANT_SMALLCAPS
++};
++
++struct State
++{
++    State() :
++        maCTM(),
++        maViewport(0,0,100,100),
++        maFontFamily(), // app-default
++        mnFontSize(12.0),
++        meFontStyle(STYLE_NORMAL),
++        meFontVariant(VARIANT_NORMAL),
++        mnFontWeight(400.0),
++        meTextAnchor(BEFORE),
++        meTextDisplayAlign(BEFORE),
++        mnTextLineIncrement(0.0),
++        maCurrentColor(1.0),
++        mbVisibility(true),
++        meFillType(SOLID),
++        mnFillOpacity(1.0),
++        meStrokeType(NONE),
++        mnStrokeOpacity(1.0),
++        meViewportFillType(NONE),
++        mnViewportFillOpacity(1.0),
++        maFillColor(0.0),
++        maFillGradient(),
++        meFillRule(NON_ZERO),
++        maStrokeColor(0.0),
++        maStrokeGradient(),
++        maDashArray(),
++        mnDashOffset(0.0),
++        meLineCap(BUTT),
++        meLineJoin(basegfx::tools::B2DLINEJOIN_MITER),
++        mnMiterLimit(4.0),
++        mnStrokeWidth(1.0),
++        maViewportFillColor(1.0),
++        maViewportFillGradient()
++    {}
++
++    basegfx::B2DHomMatrix       maCTM;
++    basegfx::B2DRange           maViewport;
++
++    rtl::OUString               maFontFamily;
++    /** Absolute: xx-small=6.94 | x-small=8.33 | small=10 | medium=12 | large=14.4 | x-large=17.28 | xx-large=20.736
++
++        Relative(to parent): larger (enlarge by 1.2)
++                             smaller (shrink by 1.2)
++
++     */
++    double                      mnFontSize;
++    FontStyle                   meFontStyle;
++    FontVariant                 meFontVariant;
++    double                      mnFontWeight;
++
++    TextAlign                   meTextAnchor; // text-anchor
++    TextAlign                   meTextDisplayAlign; // display-align
++    double                      mnTextLineIncrement; // 0.0 means auto
++
++    ARGBColor                   maCurrentColor;
++    bool                        mbVisibility;
++
++    PaintType                   meFillType;
++    double                      mnFillOpacity;
++    PaintType                   meStrokeType;
++    double                      mnStrokeOpacity;
++    PaintType                   meViewportFillType;
++    double                      mnViewportFillOpacity;
++
++    ARGBColor                   maFillColor;
++    Gradient                    maFillGradient;
++    FillRule                    meFillRule;
++
++    ARGBColor                   maStrokeColor;
++    Gradient                    maStrokeGradient;
++    std::vector<double>         maDashArray;
++    double                      mnDashOffset;
++    CapStyle                    meLineCap;
++    basegfx::tools::B2DLineJoin meLineJoin;
++    double                      mnMiterLimit;
++    double                      mnStrokeWidth;
++
++    ARGBColor                   maViewportFillColor;
++    Gradient                    maViewportFillGradient;
++};
++
++inline bool operator==(const State& rLHS, const State& rRHS )
++{
++    return rLHS.maCTM==rRHS.maCTM &&
++        rLHS.maViewport==rRHS.maViewport &&
++        rLHS.maFontFamily==rRHS.maFontFamily &&
++        rLHS.mnFontSize==rRHS.mnFontSize &&
++        rLHS.meFontStyle==rRHS.meFontStyle &&
++        rLHS.meFontVariant==rRHS.meFontVariant &&
++        rLHS.mnFontWeight==rRHS.mnFontWeight &&
++        rLHS.meTextAnchor==rRHS.meTextAnchor &&
++        rLHS.meTextDisplayAlign==rRHS.meTextDisplayAlign &&
++        rLHS.mnTextLineIncrement==rRHS.mnTextLineIncrement &&
++        rLHS.maCurrentColor==rRHS.maCurrentColor &&
++        rLHS.mbVisibility==rRHS.mbVisibility &&
++        rLHS.meFillType==rRHS.meFillType &&
++        rLHS.mnFillOpacity==rRHS.mnFillOpacity &&
++        rLHS.meStrokeType==rRHS.meStrokeType &&
++        rLHS.mnStrokeOpacity==rRHS.mnStrokeOpacity &&
++        rLHS.meViewportFillType==rRHS.meViewportFillType &&
++        rLHS.mnViewportFillOpacity==rRHS.mnViewportFillOpacity &&
++        rLHS.maFillColor==rRHS.maFillColor &&
++        rLHS.maFillGradient==rRHS.maFillGradient &&
++        rLHS.meFillRule==rRHS.meFillRule &&
++        rLHS.maStrokeColor==rRHS.maStrokeColor &&
++        rLHS.maStrokeGradient==rRHS.maStrokeGradient &&
++        rLHS.maDashArray==rRHS.maDashArray &&
++        rLHS.mnDashOffset==rRHS.mnDashOffset &&
++        rLHS.meLineCap==rRHS.meLineCap &&
++        rLHS.meLineJoin==rRHS.meLineJoin &&
++        rLHS.mnMiterLimit==rRHS.mnMiterLimit &&
++        rLHS.mnStrokeWidth==rRHS.mnStrokeWidth &&
++        rLHS.maViewportFillColor==rRHS.maViewportFillColor &&
++        rLHS.maViewportFillGradient==rRHS.maViewportFillGradient;
++}
++        
++struct StateHash
++{
++    size_t operator()(const State& rState ) const
++    {
++        return size_t(rState.maCTM.get( 0, 0 ))
++            ^  size_t(rState.maCTM.get( 1, 0 ))
++            ^  size_t(rState.maCTM.get( 0, 1 ))
++            ^  size_t(rState.maCTM.get( 1, 1 ))
++            ^  size_t(rState.maCTM.get( 0, 2 ))
++            ^  size_t(rState.maCTM.get( 1, 2 ))
++            ^  size_t(rState.maViewport.getWidth())
++            ^  size_t(rState.maViewport.getHeight())
++            ^  size_t(rState.maFontFamily.hashCode())
++            ^  size_t(rState.mnFontSize)
++            ^  size_t(rState.meFontStyle)
++            ^  size_t(rState.meFontVariant)
++            ^  size_t(rState.mnFontWeight)
++            ^  size_t(rState.meTextAnchor)
++            ^  size_t(rState.meTextDisplayAlign)
++            ^  size_t(rState.mnTextLineIncrement)
++            ^  size_t(rState.mbVisibility)
++            ^  size_t(rState.meFillType)
++            ^  size_t(rState.mnFillOpacity)
++            ^  size_t(rState.meStrokeType)
++            ^  size_t(rState.mnStrokeOpacity)
++            ^  size_t(rState.meViewportFillType)
++            ^  size_t(rState.mnViewportFillOpacity)
++            ^  size_t(rState.maFillColor.a)
++            ^  size_t(rState.maFillColor.r)
++            ^  size_t(rState.maFillColor.g)
++            ^  size_t(rState.maFillColor.b)
++            ^  size_t(rState.maFillGradient.maStops.size())
++            ^  size_t(rState.meFillRule)
++            ^  size_t(rState.maStrokeColor.a)
++            ^  size_t(rState.maStrokeColor.r)
++            ^  size_t(rState.maStrokeColor.g)
++            ^  size_t(rState.maStrokeColor.b)
++            ^  size_t(rState.maStrokeGradient.maStops.size())
++            ^  size_t(rState.maDashArray.size())
++            ^  size_t(rState.mnDashOffset)
++            ^  size_t(rState.meLineCap)
++            ^  size_t(rState.meLineJoin)
++            ^  size_t(rState.mnMiterLimit)
++            ^  size_t(rState.mnStrokeWidth)
++            ^  size_t(rState.maViewportFillColor.a)
++            ^  size_t(rState.maViewportFillColor.r)
++            ^  size_t(rState.maViewportFillColor.g)
++            ^  size_t(rState.maViewportFillColor.b)
++            ^  size_t(rState.maViewportFillGradient.maStops.size());
++    }
++};
++
++typedef std::hash_set<State, StateHash > StatePool;
++
++} // namespace svgi
++
++#endif
 diff --git a/filter/source/svgimport/makefile.mk b/filter/source/svgimport/makefile.mk
 new file mode 100644
-index 0000000..78a0ed9
+index 0000000..9da4a72
 --- /dev/null
 +++ filter/source/svgimport/makefile.mk
-@@ -0,0 +1,123 @@
+@@ -0,0 +1,135 @@
 +#*************************************************************************
 +#
 +#    OpenOffice.org - a multi-platform office productivity suite
@@ -738,10 +1104,12 @@
 +# --- Types -------------------------------------
 +
 +SLOFILES=	$(SLO)$/odfserializer.obj   \
++			$(SLO)$/parserfragments.obj	\
 +			$(SLO)$/saxattrlist.obj		\
 +			$(SLO)$/services.obj		\
 +			$(SLO)$/svgimporter.obj		\
-+			$(SLO)$/svgreader.obj
++			$(SLO)$/svgreader.obj       \
++			$(SLO)$/tokenmap.obj
 +
 +# --- Library -----------------------------------
 +
@@ -796,6 +1164,16 @@
 +
 +.INCLUDE : target.mk
 +
++# Generate gperf files - from oox/source/token
++$(INCCOM)$/tokens.hxx $(MISC)$/tokens.gperf : tokens.txt gentoken.pl
++		$(PERL) gentoken.pl tokens.txt $(INCCOM)$/tokens.hxx $(MISC)$/tokens.gperf
++
++$(INCCOM)$/tokens.cxx : $(MISC)$/tokens.gperf makefile.mk
++		gperf --compare-strncmp -C -m 20 $(MISC)$/tokens.gperf | $(SED) -e "s/(char\*)0/(char\*)0, 0/g" >$(INCCOM)$/tokens.cxx
++
++$(SLO)$/tokenmap.obj : $(INCCOM)$/tokens.cxx $(INCCOM)$/tokens.hxx
++
++# Pack extension
 +$(COMPONENT_MANIFEST) : config$/$$(@:f)
 +	@@-$(MKDIRHIER) $(@:d)
 +    $(TYPE) $< | $(SED) "s/SHARED_EXTENSION/$(DLLPOST)/" | $(SED) "s/EXEC_EXTENSION/$(EXECPOST)/" > $@
@@ -1008,6 +1386,173 @@
 +}
 +
 +#endif // _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HDL_
+diff --git a/filter/source/svgimport/parserfragments.cxx b/filter/source/svgimport/parserfragments.cxx
+new file mode 100644
+index 0000000..d2d6f01
+--- /dev/null
++++ filter/source/svgimport/parserfragments.cxx
+@@ -0,0 +1,126 @@
++/*************************************************************************
++ *
++ *    OpenOffice.org - a multi-platform office productivity suite
++ *
++ *    Author:
++ *      Fridrich Strba  <fridrich strba bluewin ch>
++ *      Thorsten Behrens <tbehrens novell com>	   	
++ *
++ *      Copyright (C) 2008, Novell Inc.
++ *
++ *   The Contents of this file are made available subject to
++ *   the terms of GNU Lesser General Public License Version 2.1.
++ *
++ ************************************************************************/
++
++#include "parserfragments.hxx"
++#include "gfxtypes.hxx"
++
++#include <boost/bind.hpp>
++#include <boost/spirit.hpp>
++
++namespace svgi
++{
++
++inline sal_Int8 hex2int( char val )
++{
++    return val <= '9' ? val-'0' : val+10-'A';
++}
++
++void setFourBitColor( double& rChannel, char nChar )
++{
++    const sal_Int8 nVal(hex2int(nChar));
++    rChannel = (nVal*16+nVal)/255.0;
++}
++
++void setEightBitColor( double& rChannel, const char* pStart, const char* )
++{
++    const sal_Int8 nVal0(hex2int(pStart[0]));
++    const sal_Int8 nVal1(hex2int(pStart[1]));
++    rChannel = (nVal0*16+nVal1)/255.0;
++}
++
++void setIntColor( double& rChannel, sal_uInt8 nVal )
++{
++    rChannel = nVal/255.0;
++}
++
++bool parseColor( const char* sColor, ARGBColor& rColor  )
++{
++    using namespace ::boost::spirit;
++
++    int_parser<sal_uInt8,16,1,3> byte_p;
++
++    return parse(sColor,
++        //  Begin grammar
++        (
++            // the #rgb form
++            ('#' >> digit_p[boost::bind(&setFourBitColor,
++                                        boost::ref(rColor.r),_1)] 
++                 >> digit_p[boost::bind(&setFourBitColor,
++                                        boost::ref(rColor.g),_1)] 
++                 >> digit_p[boost::bind(&setFourBitColor,
++                                        boost::ref(rColor.b),_1)]) 
++          |
++            // the #rrggbb form
++            ('#' >> (digit_p >> digit_p)[boost::bind(&setEightBitColor,
++                                                     boost::ref(rColor.r),_1,_2)]
++                 >> (digit_p >> digit_p)[boost::bind(&setEightBitColor,
++                                                     boost::ref(rColor.g),_1,_2)]
++                 >> (digit_p >> digit_p)[boost::bind(&setEightBitColor,
++                                                     boost::ref(rColor.b),_1,_2)]) 
++          |
++            // rgb() form
++            (str_p("rgb") 
++             >> confix_p('(', 
++                         // rgb(int,int,int)
++                         (byte_p[boost::bind(&setIntColor,
++                                             boost::ref(rColor.r),_1)] >> ',' >>
++                          byte_p[boost::bind(&setIntColor,
++                                             boost::ref(rColor.r),_1)] >> ',' >>
++                          byte_p[boost::bind(&setIntColor,
++                                             boost::ref(rColor.r),_1)])
++                       |  
++                         // rgb(double,double,double)
++                         (real_p[assign_a(rColor.r)] >> ',' >>
++                          real_p[assign_a(rColor.g)] >> ',' >>
++                          real_p[assign_a(rColor.b)]),
++                         ')'))
++          |  
++            str_p("black")[assign_a(rColor,ARGBColor(0,0,0))]
++          |
++            str_p("silver")[assign_a(rColor,ARGBColor(192,192,192))]
++          |  
++            str_p("gray")[assign_a(rColor,ARGBColor(128,128,128))]
++          |  
++            str_p("white")[assign_a(rColor,ARGBColor(255,255,255))]
++          |  
++            str_p("maroon")[assign_a(rColor,ARGBColor(128,0,0))]
++          |  
++            str_p("red")[assign_a(rColor,ARGBColor(255,0,0))]
++          |  
++            str_p("purple")[assign_a(rColor,ARGBColor(128,0,128))]
++          |  
++            str_p("fuchsia")[assign_a(rColor,ARGBColor(255,0,255))]
++          |  
++            str_p("green")[assign_a(rColor,ARGBColor(0,128,0))]
++          |  
++            str_p("lime")[assign_a(rColor,ARGBColor(0,255,0))]
++          |  
++            str_p("olive")[assign_a(rColor,ARGBColor(128,128,0))]
++          |  
++            str_p("yellow")[assign_a(rColor,ARGBColor(255,255,0))]
++          |  
++            str_p("navy")[assign_a(rColor,ARGBColor(0,0,128))]
++          |  
++            str_p("blue")[assign_a(rColor,ARGBColor(0,0,255))]
++          |  
++            str_p("teal")[assign_a(rColor,ARGBColor(0,128,128))]
++          |  
++            str_p("aqua")[assign_a(rColor,ARGBColor(0,255,255))]
++        ),
++        //  End grammar
++        space_p).full;
++}
++    
++} // namespace svgi
+diff --git a/filter/source/svgimport/parserfragments.hxx b/filter/source/svgimport/parserfragments.hxx
+new file mode 100644
+index 0000000..a13a243
+--- /dev/null
++++ filter/source/svgimport/parserfragments.hxx
+@@ -0,0 +1,29 @@
++/*************************************************************************
++ *
++ *    OpenOffice.org - a multi-platform office productivity suite
++ *
++ *    Author:
++ *      Fridrich Strba  <fridrich strba bluewin ch>
++ *      Thorsten Behrens <tbehrens novell com>	   	
++ *
++ *      Copyright (C) 2008, Novell Inc.
++ *
++ *   The Contents of this file are made available subject to
++ *   the terms of GNU Lesser General Public License Version 2.1.
++ *
++ ************************************************************************/
++
++#ifndef INCLUDED_PARSERFRAGMENTS_HXX
++#define INCLUDED_PARSERFRAGMENTS_HXX
++
++namespace svgi
++{
++
++    struct ARGBColor;
++
++    /// Parse given string for one of the SVG color grammars
++    bool parseColor( const char* sColor, ARGBColor& rColor );
++
++} // namespace svgi
++
++#endif
 diff --git a/filter/source/svgimport/saxattrlist.cxx b/filter/source/svgimport/saxattrlist.cxx
 new file mode 100644
 index 0000000..6061f9d
@@ -1413,10 +1958,10 @@
 +PDFI_IMPLEMENTATION_IDENTIFIER="com.sun.star.comp.documents.PDFImport"
 diff --git a/filter/source/svgimport/svgreader.cxx b/filter/source/svgimport/svgreader.cxx
 new file mode 100644
-index 0000000..ac29c39
+index 0000000..0eb7a7a
 --- /dev/null
 +++ filter/source/svgimport/svgreader.cxx
-@@ -0,0 +1,269 @@
+@@ -0,0 +1,484 @@
 +/*************************************************************************
 + *
 + *    OpenOffice.org - a multi-platform office productivity suite
@@ -1434,17 +1979,23 @@
 +
 +#include "svgreader.hxx"
 +#include "saxattrlist.hxx"
++#include "gfxtypes.hxx"
++#include "parserfragments.hxx"
++#include "tokenmap.hxx"
 +
 +#include <rtl/math.hxx>
 +#include <rtl/ref.hxx>
++#include <basegfx/range/b2drange.hxx>
++#include <basegfx/matrix/b2dhommatrix.hxx>
 +#include <basegfx/polygon/b2dpolypolygon.hxx>
++#include <basegfx/polygon/b2dlinegeometry.hxx>
 +#include <basegfx/polygon/b2dpolypolygontools.hxx>
 +#include <com/sun/star/io/XSeekable.hpp>
 +#include <com/sun/star/xml/sax/XParser.hpp>
 +#include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
 +#include <com/sun/star/xml/dom/NodeType.hpp>
 +
-+#include <hash_map>
++#include <hash_set>
 +
 +#define USTR(x) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
 +#define OASIS_STR "urn:oasis:names:tc:opendocument:xmlns:"
@@ -1453,43 +2004,250 @@
 +
 +namespace svgi
 +{
++namespace
++{
++/** Visit all elements of the given tree (in-order traversal)
 +
-+static void dumpTree( const uno::Reference<xml::dom::XElement> xElem )
++    Given functor is called for every element, and passed the
++    element's attributes, if any
++ */
++template<typename Func> void visitElements(Func& rFunc,
++                                           const uno::Reference<xml::dom::XElement> xElem)
 +{
-+    // in order tree traversal
-+    fprintf(stderr, "name: %s", 
-+            rtl::OUStringToOString(
-+                xElem->getTagName(),
-+                RTL_TEXTENCODING_UTF8 ).getStr());
 +    if( xElem->hasAttributes() )
++        rFunc(xElem,xElem->getAttributes());
++    else
++        rFunc(xElem);
++
++    // notify children processing
++    rFunc.push();
++
++    // recurse over children
++    uno::Reference<xml::dom::XNodeList> xChildren( xElem->getChildNodes() );
++    const sal_Int32 nNumNodes( xChildren->getLength() );
++    for( sal_Int32 i=0; i<nNumNodes; ++i )
++    {
++        if( xChildren->item(i)->getNodeType() == xml::dom::NodeType_ELEMENT_NODE )
++            visitElements( rFunc,
++                           uno::Reference<xml::dom::XElement>(
++                               xChildren->item(i),
++                               uno::UNO_QUERY_THROW) );
++    }
++
++    // children processing done
++    rFunc.pop();
++}
++
++struct AnnotatingVisitor
++{
++    AnnotatingVisitor() :
++        maCurrState(),
++        maParentStates(1),
++        maStates()
++    {}
++
++    void operator()( const uno::Reference<xml::dom::XElement>& )
++    {}
++
++    void operator()( const uno::Reference<xml::dom::XElement>&      xElem,
++                     const uno::Reference<xml::dom::XNamedNodeMap>& xAttributes )
 +    {
-+        uno::Reference<xml::dom::XNamedNodeMap> xMap( xElem->getAttributes() );
-+        const sal_Int32 nNumElems( xMap->getLength() );
++        // scan for style info
++        const sal_Int32 nNumElems( xAttributes->getLength() );
++        rtl::OUString sAttributeValue;
++        for( sal_Int32 i=0; i<nNumElems; ++i )
++        {
++            sAttributeValue = xAttributes->item(i)->getNodeValue();
++            const sal_Int32 nTokenId( 
++                getTokenId(xAttributes->item(i)->getNodeName()));
++            if( XML_STYLE == nTokenId )
++                parseStyle(sAttributeValue);
++            else 
++                parseAttribute(nTokenId, 
++                               xAttributes->item(i)->getNodeName(),
++                               sAttributeValue);
++        }
++        
++        std::pair<StatePool::iterator,bool> aRes(
++            maStates.insert(maCurrState));
++        xElem->setAttribute(USTR("internal-style-ref"),
++                            rtl::OUString::valueOf(
++                                reinterpret_cast<sal_Int64>(&(*aRes.first)),
++                                16));
++    }
++
++    void push()
++    {
++        maParentStates.push_back(maCurrState);
++        maCurrState = State();
++    }
++
++    void pop()
++    {
++        maParentStates.pop_back();
++    }
++
++    void parseAttribute( const sal_Int32      nTokenId, 
++                         const rtl::OUString& sAttribute, 
++                         const rtl::OUString& sValue )
++    {
++        rtl::OString aValueUtf8( sValue.getStr(), 
++                                 sValue.getLength(), 
++                                 RTL_TEXTENCODING_UTF8 );
++
++        switch(nTokenId)
++        {
++            case XML_FILL:
++            {
++                const State& rParent( maParentStates.back() );
++                parsePaint( aValueUtf8.getStr(),
++                            maCurrState.meFillType,
++                            maCurrState.maFillColor,
++                            maCurrState.maFillGradient,
++                            rParent.meFillType,
++                            rParent.maFillColor,
++                            rParent.maFillGradient );
++                break;
++            }
++            case XML_STROKE:
++            {
++                const State& rParent( maParentStates.back() );
++                parsePaint( aValueUtf8.getStr(),
++                            maCurrState.meStrokeType,
++                            maCurrState.maStrokeColor,
++                            maCurrState.maStrokeGradient,
++                            rParent.meStrokeType,
++                            rParent.maStrokeColor,
++                            rParent.maStrokeGradient );
++                break;
++            }
++            default:
++                fprintf(stderr, 
++                        "unhandled token %s (detected as %s)\n", 
++                        rtl::OUStringToOString(
++                            sAttribute,
++                            RTL_TEXTENCODING_UTF8 ).getStr(),
++                        getTokenName(nTokenId));
++                break;
++        }
++    }
++
++    void parseStyle( const rtl::OUString& sValue )
++    {
++        // split individual style attributes
++        sal_Int32 nIndex, nDummyIndex=0;
++        rtl::OUString aCurrToken;
++        do 
++        {
++            aCurrToken=sValue.getToken(0,';',nIndex);
++            
++            // split attrib & value
++            rtl::OUString aCurrAttrib(
++                aCurrToken.getToken(0,':',nDummyIndex));
++            OSL_ASSERT(nDummyIndex!=-1);
++            nDummyIndex=0;
++            rtl::OUString aCurrValue(
++                aCurrToken.getToken(1,':',nDummyIndex));
++            OSL_ASSERT(nDummyIndex==-1);
++
++            // recurse into normal attribute parsing
++            parseAttribute( getTokenId(aCurrAttrib),
++                            aCurrAttrib,
++                            aCurrValue );
++        }
++        while( nIndex != -1 );
++    }
++
++    void parsePaint( const char*      sValue, 
++                     PaintType&       rType,
++                     ARGBColor&       rColor,
++                     Gradient&        rGradient,
++                     const PaintType& rInheritType,
++                     const ARGBColor& rInheritColor,
++                     const Gradient&  rInheritGradient )
++    {
++        if( strcmp(sValue,"none") )
++            rType = NONE;
++        else if( strcmp(sValue,"currentColor") )
++        {
++            rType = SOLID;
++            rColor = maCurrState.maCurrentColor;
++        }
++        else if( strcmp(sValue,"inherit") )
++        {
++            rType = rInheritType;
++            rColor = rInheritColor;
++            rGradient = rInheritGradient;
++        }
++        else
++        { 
++            rType = SOLID;
++            parseColor(sValue,rColor);
++        }
++    }
++
++    void parseStroke( const rtl::OUString& )
++    {
++    }
++
++    State              maCurrState;
++    std::vector<State> maParentStates;
++    StatePool          maStates;
++};
++
++/// Annotate svg styles with unique references to state pool
++static StatePool annotateStyles( const uno::Reference<xml::dom::XElement> xElem )
++{
++    AnnotatingVisitor aVisitor;
++    visitElements(aVisitor, xElem);
++    return aVisitor.maStates;
++}
++
++#ifdef VERBOSE
++struct DumpingVisitor
++{
++    void operator()( const uno::Reference<xml::dom::XElement>& xElem )
++    {
++        fprintf(stderr, "name: %s\n", 
++                rtl::OUStringToOString(
++                    xElem->getTagName(),
++                    RTL_TEXTENCODING_UTF8 ).getStr());
++    }
++
++    void operator()( const uno::Reference<xml::dom::XElement>&      xElem,
++                     const uno::Reference<xml::dom::XNamedNodeMap>& xAttributes )
++    {
++        fprintf(stderr, "name: %s", 
++                rtl::OUStringToOString(
++                    xElem->getTagName(),
++                    RTL_TEXTENCODING_UTF8 ).getStr());
++        const sal_Int32 nNumElems( xAttributes->getLength() );
 +        for( sal_Int32 i=0; i<nNumElems; ++i )
 +        {
 +            fprintf(stderr, " %s=%s", 
 +                    rtl::OUStringToOString(
-+                        xMap->item(i)->getNodeName(),
++                        xAttributes->item(i)->getNodeName(),
 +                        RTL_TEXTENCODING_UTF8 ).getStr(),
 +                    rtl::OUStringToOString(
-+                        xMap->item(i)->getNodeValue(),
++                        xAttributes->item(i)->getNodeValue(),
 +                        RTL_TEXTENCODING_UTF8 ).getStr());
 +        }
++
++        fprintf(stderr, "\n");
 +    }
 +
-+    fprintf(stderr, "\n");
++    void push() {}
++    void pop)() {}
++};
 +
-+    // recurse over children
-+    uno::Reference<xml::dom::XNodeList> xChildren( xElem->getChildNodes() );
-+    const sal_Int32 nNumNodes( xChildren->getLength() );
-+    for( sal_Int32 i=0; i<nNumNodes; ++i )
-+    {
-+        if( xChildren->item(i)->getNodeType() == xml::dom::NodeType_ELEMENT_NODE )
-+            dumpTree( uno::Reference<xml::dom::XElement>(
-+                          xChildren->item(i),
-+                          uno::UNO_QUERY_THROW) );
-+    }
++static void dumpTree( const uno::Reference<xml::dom::XElement> xElem )
++{
++    DumpingVisitor aVisitor;
++    visitElements(aVisitor, xElem);
 +}
++#endif
++
++} // namespace 
 +
 +
 +SVGReader::SVGReader(const uno::Reference<uno::XComponentContext>&     xServiceFactory,
@@ -1645,6 +2403,8 @@
 +    uno::Reference<xml::dom::XElement> xDocElem( xDom->getDocumentElement(),
 +                                                 uno::UNO_QUERY_THROW );
 +
++    annotateStyles(xDocElem);
++
 +#ifdef VERBOSE
 +    dumpTree(xDocElem);
 +#endif
@@ -6989,3 +7749,362 @@
 +     width="744.09448"
 +     height="1052.3622" />
 +</svg>
+diff --git a/filter/source/svgimport/tokenmap.cxx b/filter/source/svgimport/tokenmap.cxx
+new file mode 100644
+index 0000000..d9fb57a
+--- /dev/null
++++ filter/source/svgimport/tokenmap.cxx
+@@ -0,0 +1,62 @@
++/*************************************************************************
++ *
++ *    OpenOffice.org - a multi-platform office productivity suite
++ *
++ *    Author:
++ *      Fridrich Strba  <fridrich strba bluewin ch>
++ *      Thorsten Behrens <tbehrens novell com>	   	
++ *
++ *      Copyright (C) 2008, Novell Inc.
++ *      Parts copyright 2005 by Sun Microsystems, Inc.
++ *
++ *   The Contents of this file are made available subject to
++ *   the terms of GNU Lesser General Public License Version 2.1.
++ *
++ ************************************************************************/
++
++// MARKER(update_precomp.py): autogen include statement, do not remove
++#include "precompiled_filter.hxx"
++
++#include "tokenmap.hxx"
++#include <string.h>
++
++namespace svgi 
++{
++
++#include "tokens.cxx"
++
++sal_Int32 getTokenId( const char* sIdent, sal_Int32 nLen )
++{
++	const struct xmltoken* t = Perfect_Hash::in_word_set( sIdent, nLen );
++	if( t )
++		return t->nToken;
++	else
++		return XML_TOKEN_INVALID;
++}
++
++sal_Int32 getTokenId( const rtl::OUString& sIdent )
++{
++	rtl::OString aUTF8( sIdent.getStr(), 
++                        sIdent.getLength(), 
++                        RTL_TEXTENCODING_UTF8 );
++    return getTokenId( aUTF8.getStr(), aUTF8.getLength() );
++}
++
++const char* getTokenName( sal_Int32 nTokenId )
++{
++	if( nTokenId >= XML_TOKEN_COUNT )
++		return NULL;
++
++    const xmltoken* pCurr=wordlist;
++    const xmltoken* pEnd=wordlist+sizeof(wordlist)/sizeof(*wordlist);
++    while( pCurr != pEnd )
++    {
++        if(pCurr->nToken == nTokenId)
++            return pCurr->name;
++        ++pCurr;
++    }
++
++    return NULL;
++}
++
++} // namespace svgi
+diff --git a/filter/source/svgimport/tokenmap.hxx b/filter/source/svgimport/tokenmap.hxx
+new file mode 100644
+index 0000000..c77def6
+--- /dev/null
++++ filter/source/svgimport/tokenmap.hxx
+@@ -0,0 +1,32 @@
++/*************************************************************************
++ *
++ *    OpenOffice.org - a multi-platform office productivity suite
++ *
++ *    Author:
++ *      Fridrich Strba  <fridrich strba bluewin ch>
++ *      Thorsten Behrens <tbehrens novell com>	   	
++ *
++ *      Copyright (C) 2008, Novell Inc.
++ *
++ *   The Contents of this file are made available subject to
++ *   the terms of GNU Lesser General Public License Version 2.1.
++ *
++ ************************************************************************/
++
++#ifndef INCLUDED_TOKENMAP_HXX
++#define INCLUDED_TOKENMAP_HXX
++
++#include "tokens.hxx"
++
++#include <rtl/string.hxx>
++#include <rtl/ustring.hxx>
++
++namespace svgi
++{
++    sal_Int32   getTokenId( const char* sIdent, sal_Int32 nLen );
++    sal_Int32   getTokenId( const rtl::OUString& sIdent );
++    const char* getTokenName( sal_Int32 nTokenId );
++
++} // namespace svgi
++
++#endif
+diff --git a/filter/source/svgimport/tokens.txt b/filter/source/svgimport/tokens.txt
+new file mode 100644
+index 0000000..72b3870
+--- /dev/null
++++ filter/source/svgimport/tokens.txt
+@@ -0,0 +1,246 @@
++#######################################
++#
++# elements (SVG Tiny 1.2)
++#
++#######################################
++a
++animate
++animateColor
++animateMotion
++animateTransform
++animation
++audio
++circle
++defs
++desc
++discard
++ellipse
++font
++font-face
++font-face-src
++font-face-uri
++foreignObject
++g
++glyph
++handler
++hkern
++image
++line
++linearGradient
++listener
++metadata
++missing-glyph
++mpath
++path
++polygon
++polyline
++prefetch
++radialGradient
++rect
++script
++set
++solidColor
++stop
++svg
++switch
++tbreak
++text
++textArea
++title
++tspan
++use
++video
++#######################################
++#
++# properties (SVG Tiny 1.2)
++#
++#######################################
++audio-level
++color
++color-rendering
++display
++display-align
++fill
++fill-opacity
++fill-rule
++font-family
++font-size
++font-style
++font-variant
++font-weight
++image-rendering
++line-increment
++opacity
++pointer-events
++shape-rendering
++solid-color
++solid-opacity
++stop-color
++stop-opacity
++stroke
++stroke-dasharray
++stroke-dashoffset
++stroke-linecap
++stroke-linejoin
++stroke-miterlimit
++stroke-opacity
++stroke-width
++text-align
++text-anchor
++text-rendering
++vector-effect
++viewport-fill
++viewport-fill-opacity
++visibility
++#######################################
++#
++# attributes (SVG Tiny 1.2)
++#
++#######################################
++accent-height
++accumulate
++additive
++alphabetic
++arabic-form
++ascent
++attributeName
++attributeType
++bandwidth
++baseProfile
++bbox
++begin
++by
++calcMode
++cap-height
++class
++contentScriptType
++cx
++cy
++d
++defaultAction
++descent
++dur
++editable
++end
++ev:event
++event
++externalResourcesRequired
++fill
++focusHighlight
++focusable
++font-family
++font-stretch
++font-style
++font-variant
++font-weight
++from
++g1
++g2
++glyph-name
++gradientUnits
++handler
++hanging
++height
++height
++horiz-adv-x
++horiz-origin-x
++id
++ideographic
++initialVisibility
++k
++keyPoints
++keySplines
++keyTimes
++lang
++mathematical
++max
++mediaCharacterEncoding
++mediaContentEncodings
++mediaSize
++mediaTime
++min
++nav-down
++nav-down-left
++nav-down-right
++nav-left
++nav-next
++nav-prev
++nav-right
++nav-up
++nav-up-left
++nav-up-right
++observer
++offset
++origin
++overlay
++overline-position
++overline-thickness
++panose-1
++path
++pathLength
++phase
++playbackOrder
++points
++preserveAspectRatio
++propagate
++r
++repeatCount
++repeatDur
++requiredExtensions
++requiredFeatures
++requiredFonts
++requiredFormats
++restart
++rotate
++rx
++ry
++slope
++snapshotTime
++stemh
++stemv
++strikethrough-position
++strikethrough-thickness
++style
++syncBehavior
++syncBehaviorDefault
++syncMaster
++syncTolerance
++syncToleranceDefault
++systemLanguage
++target
++timelineBegin
++to
++transform
++transformBehavior
++type
++u1
++u2
++underline-position
++underline-thickness
++unicode
++unicode-range
++units-per-em
++values
++version
++viewBox
++width
++widths
++x
++x-height
++x1
++x2
++xlink:actuate
++xlink:arcrole
++xlink:href
++xlink:role
++xlink:show
++xlink:title
++xlink:type
++xml:base
++xml:id
++xml:lang
++xml:space
++y
++y1
++y2
++zoomAndPan
+\ No newline at end of file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]