Code

r14551@tres: ted | 2007-02-24 15:22:47 -0800
authorgouldtj <gouldtj@users.sourceforge.net>
Sun, 25 Feb 2007 06:54:05 +0000 (06:54 +0000)
committergouldtj <gouldtj@users.sourceforge.net>
Sun, 25 Feb 2007 06:54:05 +0000 (06:54 +0000)
 Merging in the latest libwpg and some code chages to make it work with
 everything.

34 files changed:
src/extension/internal/libwpg/Makefile_insert
src/extension/internal/libwpg/WPG1Parser.cpp
src/extension/internal/libwpg/WPG1Parser.h
src/extension/internal/libwpg/WPG2Parser.cpp
src/extension/internal/libwpg/WPG2Parser.h
src/extension/internal/libwpg/WPGBrush.cpp [new file with mode: 0644]
src/extension/internal/libwpg/WPGBrush.h
src/extension/internal/libwpg/WPGColor.cpp [new file with mode: 0644]
src/extension/internal/libwpg/WPGColor.h
src/extension/internal/libwpg/WPGGradient.cpp
src/extension/internal/libwpg/WPGHeader.cpp
src/extension/internal/libwpg/WPGHeader.h
src/extension/internal/libwpg/WPGOLEStream.cpp
src/extension/internal/libwpg/WPGOLEStream.h
src/extension/internal/libwpg/WPGPath.cpp
src/extension/internal/libwpg/WPGPath.h
src/extension/internal/libwpg/WPGPen.cpp
src/extension/internal/libwpg/WPGPen.h
src/extension/internal/libwpg/WPGPoint.cpp
src/extension/internal/libwpg/WPGPoint.h
src/extension/internal/libwpg/WPGRect.cpp [new file with mode: 0644]
src/extension/internal/libwpg/WPGRect.h
src/extension/internal/libwpg/WPGSVGGenerator.cpp [new file with mode: 0644]
src/extension/internal/libwpg/WPGSVGGenerator.h [new file with mode: 0644]
src/extension/internal/libwpg/WPGStreamImplementation.cpp
src/extension/internal/libwpg/WPGStreamImplementation.h
src/extension/internal/libwpg/WPGString.cpp [new file with mode: 0644]
src/extension/internal/libwpg/WPGString.h [new file with mode: 0644]
src/extension/internal/libwpg/WPGXParser.cpp
src/extension/internal/libwpg/WPGXParser.h
src/extension/internal/libwpg/WPGraphics.cpp
src/extension/internal/libwpg/WPGraphics.h
src/extension/internal/libwpg/makefile.mk [new file with mode: 0644]
src/extension/internal/wpg-input.cpp

index 179abb81c1a9f8d08a392f36207c39997b4b50d7..8fd555f4c33bcb4a498954f8ab9aaf02479fb86a 100644 (file)
@@ -13,7 +13,9 @@ extension_internal_libwpg_libwpg_a_SOURCES =  \
         extension/internal/libwpg/WPG1Parser.h \
         extension/internal/libwpg/WPG2Parser.cpp \
         extension/internal/libwpg/WPG2Parser.h \
+        extension/internal/libwpg/WPGBrush.cpp \
         extension/internal/libwpg/WPGBrush.h \
+        extension/internal/libwpg/WPGColor.cpp \
         extension/internal/libwpg/WPGColor.h \
         extension/internal/libwpg/WPGGradient.cpp \
         extension/internal/libwpg/WPGGradient.h \
@@ -30,9 +32,14 @@ extension_internal_libwpg_libwpg_a_SOURCES = \
         extension/internal/libwpg/WPGPoint.h \
         extension/internal/libwpg/WPGraphics.cpp \
         extension/internal/libwpg/WPGraphics.h \
+        extension/internal/libwpg/WPGRect.cpp \
         extension/internal/libwpg/WPGRect.h \
         extension/internal/libwpg/WPGStream.h \
         extension/internal/libwpg/WPGStreamImplementation.cpp \
         extension/internal/libwpg/WPGStreamImplementation.h \
+        extension/internal/libwpg/WPGString.cpp \
+        extension/internal/libwpg/WPGString.h \
+        extension/internal/libwpg/WPGSVGGenerator.cpp \
+        extension/internal/libwpg/WPGSVGGenerator.h \
         extension/internal/libwpg/WPGXParser.cpp \
         extension/internal/libwpg/WPGXParser.h
index 9f4a05148082938e856002c244f5aa4b54e3c843..a8b97cbdf63dceefc86af8dec1c178f7631a7e13 100644 (file)
@@ -135,7 +135,7 @@ static const unsigned char defaultWPG1PaletteBlue[] = {
 };
 
 
-WPG1Parser::WPG1Parser(WPGInputStream *input, WPGPaintInterface* painter):
+WPG1Parser::WPG1Parser(libwpg::WPGInputStream *input, libwpg::WPGPaintInterface* painter):
        WPGXParser(input, painter),
        m_success(true), m_exit(false),
        m_width(0), m_height(0)
@@ -175,24 +175,26 @@ bool WPG1Parser::parse()
        m_exit = false;
        
        // default style
-       m_pen.foreColor = WPGColor(0,0,0);
-       m_pen.backColor = WPGColor(0,0,0);
+       m_pen.foreColor = libwpg::WPGColor(0,0,0);
+       m_pen.backColor = libwpg::WPGColor(0,0,0);
        m_pen.width = 0.001;
        m_pen.height = 0.001;
        m_pen.solid = true;
-       m_pen.dashArray = WPGDashArray();
-       m_brush.foreColor = WPGColor(0,0,0);
-       m_brush.backColor = WPGColor(0,0,0);
+       m_pen.dashArray = libwpg::WPGDashArray();
+       m_brush.foreColor = libwpg::WPGColor(0,0,0);
+       m_brush.backColor = libwpg::WPGColor(0,0,0);
        resetPalette();
 
        while(!m_input->atEnd())
        {
+#ifdef DEBUG
                long recordPos = m_input->tell();
+#endif
                int recordType = readU8();
                int length = readVariableLengthInteger();
                long nextPos = m_input->tell() + length;
 #if !defined(DEBUG)
-               (void)recordPos;
+               //(void)recordPos;
 #endif // !defined(DEBUG)
 
                // search function to handler this record
@@ -237,10 +239,11 @@ bool WPG1Parser::parse()
 
 void WPG1Parser::handleStartWPG()
 {
-       unsigned char version = readU8();
-       unsigned char bitFlags = readU8();
-       (void)version;
-       (void)bitFlags;
+       // unsigned char version = readU8();
+       // unsigned char bitFlags = readU8();
+       m_input->seek(m_input->tell() + 2);
+       //(void)version;
+       //(void)bitFlags;
        m_width = readU16();
        m_height = readU16();
 
@@ -265,9 +268,9 @@ void WPG1Parser::handleColormap()
        unsigned numEntries = readU16();
 
        WPG_DEBUG_MSG(("Colormap\n"));
-       for(int i = 0; i < static_cast<int>(numEntries); i++)
+       for(unsigned int i = 0; i < numEntries; i++)
        {
-               WPGColor color;
+               libwpg::WPGColor color;
                color.red = readU8();
                color.green = readU8();
                color.blue = readU8();
@@ -282,9 +285,9 @@ void WPG1Parser::handleFillAttributes()
        unsigned char color = readU8();
 
        if(style == 0)
-               m_brush.style = WPGBrush::NoBrush;
+               m_brush.style = libwpg::WPGBrush::NoBrush;
        if(style == 1)
-               m_brush.style = WPGBrush::Solid;
+               m_brush.style = libwpg::WPGBrush::Solid;
 
        m_brush.foreColor = m_colorPalette[color];
 
@@ -316,9 +319,9 @@ void WPG1Parser::handleLine()
        int ex = readS16();
        int ey = readS16();
 
-       WPGPointArray points;
-       points.add(WPGPoint((double)sx/1200.0, (double)(m_height-sy)/1200.0));
-       points.add(WPGPoint((double)ex/1200.0, (double)(m_height-ey)/1200.0));
+       libwpg::WPGPointArray points;
+       points.add(libwpg::WPGPoint((double)sx/1200.0, (double)(m_height-sy)/1200.0));
+       points.add(libwpg::WPGPoint((double)ex/1200.0, (double)(m_height-ey)/1200.0));
 
        m_painter->setBrush(m_brush);
        m_painter->setPen(m_pen);
@@ -333,15 +336,15 @@ void WPG1Parser::handlePolyline()
 {
        unsigned int count = readU16();
 
-       WPGPointArray points;
+       libwpg::WPGPointArray points;
        for(unsigned int i = 0; i < count; i++ )
        {
                long x = readS16();
                long y = readS16();
-               points.add(WPGPoint((double)x/1200.0, (double)(m_height-y)/1200.0));
+               points.add(libwpg::WPGPoint((double)x/1200.0, (double)(m_height-y)/1200.0));
        }
 
-       m_painter->setBrush(WPGBrush()); // not filled
+       m_painter->setBrush(libwpg::WPGBrush()); // not filled
        m_painter->setPen(m_pen);
        m_painter->drawPolygon(points);
 
@@ -355,7 +358,7 @@ void WPG1Parser::handleRectangle()
        int w = readS16();
        int h = readS16();
 
-       WPGRect rect;
+       libwpg::WPGRect rect;
        rect.x1 = (double)x/1200.0;
        rect.y1 = (double)(m_height-y)/1200.0;
        rect.x2 = rect.x1 + (double)w/1200.0;
@@ -375,12 +378,12 @@ void WPG1Parser::handlePolygon()
 {
        unsigned int count = readU16();
 
-       WPGPointArray points;
+       libwpg::WPGPointArray points;
        for(unsigned int i = 0; i < count; i++ )
        {
                long x = readS16();
                long y = readS16();
-               points.add(WPGPoint((double)x/1200.0, (double)(m_height-y)/1200.0));
+               points.add(libwpg::WPGPoint((double)x/1200.0, (double)(m_height-y)/1200.0));
        }
 
        m_painter->setBrush(m_brush);
@@ -397,7 +400,7 @@ void WPG1Parser::handleEllipse()
        int rx = readS16();
        int ry = readS16();
 
-       WPGPoint center;
+       libwpg::WPGPoint center;
        center.x = (double)cx/1200.0;
        center.y = (double)(m_height-cy)/1200.0;
 
@@ -419,7 +422,7 @@ void WPG1Parser::resetPalette()
        m_colorPalette.clear();
        for (int i=0; i<256; i++)
        {
-               WPGColor color;
+               libwpg::WPGColor color;
                color.red = defaultWPG1PaletteRed[i];
                color.green = defaultWPG1PaletteGreen[i];
                color.blue = defaultWPG1PaletteBlue[i];
index fb238352e548544b3211952843e049376858d2a9..2e7405241d6d43a1487e4cd8a51b3a4da21ad7a6 100644 (file)
@@ -35,7 +35,7 @@
 class WPG1Parser : public WPGXParser
 {
 public:
-       WPG1Parser(WPGInputStream *input, WPGPaintInterface* painter);
+       WPG1Parser(libwpg::WPGInputStream *input, libwpg::WPGPaintInterface* painter);
        bool parse();
 
 private:
@@ -59,8 +59,8 @@ private:
        bool m_exit;
        int m_width;
        int m_height;
-       WPGPen m_pen;
-       WPGBrush m_brush;
+       libwpg::WPGPen m_pen;
+       libwpg::WPGBrush m_brush;
 };
 
 #endif // __WPG1PARSER_H__
index e0b642f0ed5fc0c20309803c0aacce059abce467..a669e5fb884f6a76b1843820bc38b2b126f9f9d8 100644 (file)
@@ -201,7 +201,7 @@ public:
                        {}
 };
 
-WPG2Parser::WPG2Parser(WPGInputStream *input, WPGPaintInterface* painter):
+WPG2Parser::WPG2Parser(libwpg::WPGInputStream *input, libwpg::WPGPaintInterface* painter):
        WPGXParser(input, painter),
        m_success(true), m_exit(false),
        m_xres(1200), m_yres(1200),
@@ -301,27 +301,31 @@ bool WPG2Parser::parse()
        m_compoundClosed = false;
        
        // default style
-       m_pen.foreColor = WPGColor(0,0,0);
-       m_pen.backColor = WPGColor(0,0,0);
+       m_pen.foreColor = libwpg::WPGColor(0,0,0);
+       m_pen.backColor = libwpg::WPGColor(0,0,0);
        m_pen.width = 0.001;
        m_pen.height = 0.001;
        m_pen.solid = true;
-       m_pen.dashArray = WPGDashArray();
-       m_brush.foreColor = WPGColor(0,0,0);
-       m_brush.backColor = WPGColor(0,0,0);
+       m_pen.dashArray = libwpg::WPGDashArray();
+       m_brush.foreColor = libwpg::WPGColor(0,0,0);
+       m_brush.backColor = libwpg::WPGColor(0,0,0);
        resetPalette();
 
        while(!m_input->atEnd())
        {
+#ifdef DEBUG
                long recordPos = m_input->tell();
                int recordClass = readU8();
+#else
+               readU8();
+#endif
                int recordType = readU8();
                int extension = readVariableLengthInteger();
                int length = readVariableLengthInteger();
                long nextPos = m_input->tell() + length;
 #if !defined(DEBUG)
-               (void)recordPos;
-               (void)recordClass;
+               //(void)recordPos;
+               //(void)recordClass;
 #endif // !defined(DEBUG)
                
                // inside a subgroup, one less sub record
@@ -399,7 +403,7 @@ bool WPG2Parser::parse()
        return m_success;
 }
 
-#if defined(DEBUG)
+#ifdef DEBUG
 static const char* describePrecision(unsigned char precision)
 {
        const char* result = "Unknown";
@@ -432,7 +436,7 @@ static const char* describeGradient(unsigned char gradientType)
        }
        return result;
 }
-#endif // defined(DEBUG)
+#endif
 
 #define TO_DOUBLE(x) ( (m_doublePrecision) ? ((double)(x)/65536.0) : (double)(x) )
 #define TRANSFORM_XY(x,y) { m_matrix.transform((x),(y)); (x)-= m_xofs; (y)-= m_yofs; (y)=m_height-(y); }
@@ -462,17 +466,14 @@ void WPG2Parser::handleStartWPG()
        }
        m_doublePrecision = (precision == 1);
        
+#ifdef DEBUG
        long viewportX1 = (m_doublePrecision) ? readS32() : readS16();
        long viewportY1 = (m_doublePrecision) ? readS32() : readS16();
        long viewportX2 = (m_doublePrecision) ? readS32() : readS16();
        long viewportY2 = (m_doublePrecision) ? readS32() : readS16();
-#if !defined(DEBUG)
-       (void)viewportX1;
-       (void)viewportY1;
-       (void)viewportX2;
-       (void)viewportY2;
-#endif // !defined(DEBUG)
-       
+#else
+       m_input->seek(m_input->tell() + ((m_doublePrecision) ? 16 : 8));
+#endif 
        long imageX1 = (m_doublePrecision) ? readS32() : readS16();
        long imageY1 = (m_doublePrecision) ? readS32() : readS16();
        long imageX2 = (m_doublePrecision) ? readS32() : readS16();
@@ -528,11 +529,11 @@ void WPG2Parser::handleStartWPG()
        
        // create default pen styles
        int styleNo = 0;
-       for(int i = 0; i < static_cast<int>(sizeof(WPG2_defaultPenDashes)/sizeof(WPG2_defaultPenDashes[0]));)
+       for(int i = 0; (long)i < (long)(sizeof(WPG2_defaultPenDashes)/sizeof(WPG2_defaultPenDashes[0]));)
        {
                int segments = 2 * WPG2_defaultPenDashes[i++];
                if(segments == 0) break;
-               WPGDashArray dashArray;
+               libwpg::WPGDashArray dashArray;
                for(int j = 0; j < segments; j++, i++)
                        dashArray.add(WPG2_defaultPenDashes[i]*3.6/218.0);
                m_penStyles[styleNo] = dashArray;
@@ -579,12 +580,12 @@ void WPG2Parser::flushCompoundPolygon()
 {
        WPGGroupContext& context = m_groupStack.top();
        
-       m_painter->setBrush( context.compoundFilled ? m_brush : WPGBrush() );
-       m_painter->setPen( context.compoundFramed ? m_pen : WPGPen() );
+       m_painter->setBrush( context.compoundFilled ? m_brush : libwpg::WPGBrush() );
+       m_painter->setPen( context.compoundFramed ? m_pen : libwpg::WPGPen() );
        if(context.compoundWindingRule)
-               m_painter->setFillRule(WPGPaintInterface::WindingFill);
+               m_painter->setFillRule(libwpg::WPGPaintInterface::WindingFill);
        else
-               m_painter->setFillRule(WPGPaintInterface::AlternatingFill);
+               m_painter->setFillRule(libwpg::WPGPaintInterface::AlternatingFill);
        context.compoundPath.closed = context.compoundClosed;
        m_painter->drawPath(context.compoundPath);
 }
@@ -594,7 +595,7 @@ void WPG2Parser::handlePenStyleDefinition()
        unsigned int style = readU16();
        unsigned int segments = readU16();
 
-       WPGDashArray dashArray;
+       libwpg::WPGDashArray dashArray;
        for(unsigned i = 0; i < segments; i++)
        {
                unsigned int p = (m_doublePrecision) ? readU32() : readU16();
@@ -621,7 +622,7 @@ void WPG2Parser::handleColorPalette()
 
        for(unsigned i = 0; i < numEntries; i++)
        {
-               WPGColor color;
+               libwpg::WPGColor color;
                color.red = readU8();
                color.green = readU8();
                color.blue = readU8();
@@ -636,9 +637,9 @@ void WPG2Parser::handleDPColorPalette()
        unsigned startIndex = readU16();
        unsigned numEntries = readU16();
 
-       for(int i = 0; i < static_cast<int>(numEntries); i++)
+       for(unsigned int i = 0; i < numEntries; i++)
        {
-               WPGColor color;
+               libwpg::WPGColor color;
                color.red = readU16() >> 8 ;
                color.green = readU16() >> 8 ;
                color.blue = readU16() >> 8 ;
@@ -650,56 +651,66 @@ void WPG2Parser::handleDPColorPalette()
 
 void WPG2Parser::handlePenForeColor()
 {
+       if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+               return;
        unsigned char red = readU8();
        unsigned char green = readU8();
        unsigned char blue = readU8();
        unsigned char alpha = readU8();
 
-       m_pen.foreColor = WPGColor(red, green, blue, alpha);
+       m_pen.foreColor = libwpg::WPGColor(red, green, blue, alpha);
 
        WPG_DEBUG_MSG(("   Foreground color (RGBA): %d %d %d %d\n", red, green, blue, alpha));
 }
 
 void WPG2Parser::handleDPPenForeColor()
 {
+       if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+               return;
        // we just ignore the least significant 8 bits
        unsigned int red = (m_doublePrecision)   ? readU16()>>8 : readU8();
        unsigned int green = (m_doublePrecision) ? readU16()>>8 : readU8();
        unsigned int blue = (m_doublePrecision)  ? readU16()>>8 : readU8();
        unsigned int alpha = (m_doublePrecision) ? readU16()>>8 : readU8();
 
-       m_pen.foreColor = WPGColor(red, green, blue, alpha);
+       m_pen.foreColor = libwpg::WPGColor(red, green, blue, alpha);
 
        WPG_DEBUG_MSG(("   Foreground color (RGBA): %d %d %d %d\n", red, green, blue, alpha));
 }
 
 void WPG2Parser::handlePenBackColor()
 {
+       if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+               return;
        unsigned char red = readU8();
        unsigned char green = readU8();
        unsigned char blue = readU8();
        unsigned char alpha = readU8();
 
-       m_pen.backColor = WPGColor(red, green, blue, alpha);
+       m_pen.backColor = libwpg::WPGColor(red, green, blue, alpha);
 
        WPG_DEBUG_MSG(("   Background color (RGBA): %d %d %d %d\n", red, green, blue, alpha));
 }
 
 void WPG2Parser::handleDPPenBackColor()
 {
+       if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+               return;
        // we just ignore the least significant 8 bits
        unsigned int red = (m_doublePrecision)   ? readU16()>>8 : readU8();
        unsigned int green = (m_doublePrecision) ? readU16()>>8 : readU8();
        unsigned int blue = (m_doublePrecision)  ? readU16()>>8 : readU8();
        unsigned int alpha = (m_doublePrecision) ? readU16()>>8 : readU8();
 
-       m_pen.backColor = WPGColor(red, green, blue, alpha);
+       m_pen.backColor = libwpg::WPGColor(red, green, blue, alpha);
 
        WPG_DEBUG_MSG(("   Background color (RGBA): %d %d %d %d\n", red, green, blue, alpha));
 }
 
 void WPG2Parser::handlePenStyle()
 {
+       if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+               return;
        unsigned int style = readU16();
 
        m_pen.dashArray = m_penStyles[style];
@@ -711,6 +722,8 @@ void WPG2Parser::handlePenStyle()
 
 void WPG2Parser::handlePenSize()
 {
+       if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+               return;
        unsigned int width = readU16();
        unsigned int height = readU16();
 
@@ -723,6 +736,8 @@ void WPG2Parser::handlePenSize()
 
 void WPG2Parser::handleDPPenSize()
 {
+       if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+               return;
        unsigned long width = readU32();
        unsigned long height = readU32();
 
@@ -735,16 +750,22 @@ void WPG2Parser::handleDPPenSize()
 
 void WPG2Parser::handleBrushGradient()
 {
+       if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+               return;
        unsigned angleFraction = readU16();
        unsigned angleInteger = readU16();
        unsigned xref = readU16();
        unsigned yref = readU16();
+#ifdef DEBUG
        unsigned flag = readU16();
-       bool granular = (flag & (1<<6)) == 1;
-       bool anchor = (flag & (1<<7)) == 1;
+       bool granular = ((flag & (1<<6))>>6) == 1;
+       bool anchor = ((flag & (1<<7))>>7) == 1;
+#else
+       readU16();
+#endif
 #if !defined(DEBUG)
-       (void)granular;
-       (void)anchor;
+       //(void)granular;
+       //(void)anchor;
 #endif // !defined(DEBUG)
        
        // TODO: get gradient extent
@@ -761,17 +782,19 @@ void WPG2Parser::handleBrushGradient()
 
 void WPG2Parser::handleDPBrushGradient()
 {
+       if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+               return;
        unsigned angleFraction = readU16();
        unsigned angleInteger = readU16();
        unsigned xref = readU16();
        unsigned yref = readU16();
+#ifdef DEBUG
        unsigned flag = readU16();
        bool granular = (flag & (1<<6)) == 1;
        bool anchor = (flag & (1<<7)) == 1;
-#if !defined(DEBUG)
-       (void)granular;
-       (void)anchor;
-#endif // !defined(DEBUG)
+#else
+       readU16();
+#endif
        
        // TODO: get gradient extent (in double precision)
        
@@ -787,6 +810,8 @@ void WPG2Parser::handleDPBrushGradient()
 
 void WPG2Parser::handleBrushForeColor()
 {
+       if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+               return;
        unsigned char gradientType = readU8();
        WPG_DEBUG_MSG(("   Gradient type : %d (%s)\n", gradientType, describeGradient(gradientType)));
 
@@ -798,14 +823,14 @@ void WPG2Parser::handleBrushForeColor()
                unsigned char alpha = readU8();
                WPG_DEBUG_MSG(("   Foreground color (RGBA): %d %d %d %d\n", red, green, blue, alpha));
 
-               m_brush.foreColor = WPGColor(red, green, blue, alpha);
-               if(m_brush.style != WPGBrush::Gradient)
-                       m_brush.style = WPGBrush::Solid;
+               m_brush.foreColor = libwpg::WPGColor(red, green, blue, alpha);
+               if(m_brush.style != libwpg::WPGBrush::Gradient)
+                       m_brush.style = libwpg::WPGBrush::Solid;
        }
        else
        {
                unsigned count = readU16();
-               std::vector<WPGColor> colors;
+               std::vector<libwpg::WPGColor> colors;
                std::vector<double> positions;
                WPG_DEBUG_MSG(("  Gradient colors : %d\n", count));
 
@@ -815,7 +840,7 @@ void WPG2Parser::handleBrushForeColor()
                        unsigned char green = readU8();
                        unsigned char blue = readU8();
                        unsigned char alpha = readU8();
-                       WPGColor color(red, green, blue, alpha);
+                       libwpg::WPGColor color(red, green, blue, alpha);
                        colors.push_back(color);
                        WPG_DEBUG_MSG(("   Color #%d (RGBA): %d %d %d %d\n", i+1, red, green, blue, alpha));
                }
@@ -835,21 +860,23 @@ void WPG2Parser::handleBrushForeColor()
                        double yref = (double)m_gradientRef.y/65536.0;
                        double angle = m_gradientAngle*M_PI/180.0;
                        double tanangle = tan(angle);
-                       double ref = (tanangle<1e2) ? (yref+xref*tanangle)/(1+tanangle) : xref;
-                       WPGGradient gradient;
+                       double ref = (tanangle < 1e2 && tanangle > -1e2) ? (yref+xref*tanangle)/(1+tanangle) : xref;
+                       libwpg::WPGGradient gradient;
                        gradient.setAngle(-m_gradientAngle); // upside down
                        gradient.addStop(0, colors[1]);
                        gradient.addStop(ref, colors[0]);
-                       if((m_gradientRef.x != 65535) && (m_gradientRef.y != 65536))
+                       if((m_gradientRef.x != 65535) && (m_gradientRef.y != 65535))
                                gradient.addStop(1, colors[1]);
                        m_brush.gradient = gradient;
-                       m_brush.style = WPGBrush::Gradient;
+                       m_brush.style = libwpg::WPGBrush::Gradient;
                }
        }
 }
 
 void WPG2Parser::handleDPBrushForeColor()
 {
+       if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+               return;
        unsigned char gradientType = readU8();
        WPG_DEBUG_MSG(("   Gradient type : %d (%s)\n", gradientType, describeGradient(gradientType)));
 
@@ -861,14 +888,14 @@ void WPG2Parser::handleDPBrushForeColor()
                unsigned char alpha = (m_doublePrecision)   ? readU16()>>8 : readU8();
                WPG_DEBUG_MSG(("   Foreground color (RGBA): %d %d %d %d\n", red, green, blue, alpha));
 
-               m_brush.foreColor = WPGColor(red, green, blue, alpha);
-               if(m_brush.style != WPGBrush::NoBrush)
-                       m_brush.style = WPGBrush::Solid;
+               m_brush.foreColor = libwpg::WPGColor(red, green, blue, alpha);
+               if(m_brush.style != libwpg::WPGBrush::NoBrush)
+                       m_brush.style = libwpg::WPGBrush::Solid;
        }
        else
        {
                unsigned count = readU16();
-               std::vector<WPGColor> colors;
+               std::vector<libwpg::WPGColor> colors;
                std::vector<double> positions;
                WPG_DEBUG_MSG(("  Gradient colors : %d\n", count));
 
@@ -878,7 +905,7 @@ void WPG2Parser::handleDPBrushForeColor()
                        unsigned char green = (m_doublePrecision)   ? readU16()>>8 : readU8();
                        unsigned char blue = (m_doublePrecision)   ? readU16()>>8 : readU8();
                        unsigned char alpha = (m_doublePrecision)   ? readU16()>>8 : readU8();
-                       WPGColor color(red, green, blue, alpha);
+                       libwpg::WPGColor color(red, green, blue, alpha);
                        colors.push_back(color);
                        WPG_DEBUG_MSG(("   Color #%d (RGBA): %d %d %d %d\n", i+1, red, green, blue, alpha));
                }
@@ -899,53 +926,58 @@ void WPG2Parser::handleDPBrushForeColor()
                        double angle = m_gradientAngle*M_PI/180.0;
                        double tanangle = tan(angle);
                        double ref = (tanangle<1e2) ? (yref+xref*tanangle)/(1+tanangle) : xref;
-                       WPGGradient gradient;
+                       libwpg::WPGGradient gradient;
                        gradient.setAngle(-m_gradientAngle); // upside down
                        gradient.addStop(0, colors[1]);
                        gradient.addStop(ref, colors[0]);
                        if((m_gradientRef.x != 65535) && (m_gradientRef.y != 65536))
                                gradient.addStop(1, colors[1]);
                        m_brush.gradient = gradient;
-                       m_brush.style = WPGBrush::Gradient;
+                       m_brush.style = libwpg::WPGBrush::Gradient;
                }
        }
 }
 
 void WPG2Parser::handleBrushBackColor()
 {
+       if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+               return;
        unsigned char red = readU8();
        unsigned char green = readU8();
        unsigned char blue = readU8();
        unsigned char alpha = readU8();
 
-       m_brush.backColor = WPGColor(red, green, blue, alpha);
-       if(m_brush.style == WPGBrush::NoBrush)
-               m_brush.style = WPGBrush::Solid;
+       m_brush.backColor = libwpg::WPGColor(red, green, blue, alpha);
+       if(m_brush.style == libwpg::WPGBrush::NoBrush)
+               m_brush.style = libwpg::WPGBrush::Solid;
 
        WPG_DEBUG_MSG(("   Backround color (RGBA): %d %d %d %d\n", red, green, blue, alpha));
 }
 
 void WPG2Parser::handleDPBrushBackColor()
 {
+       if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+               return;
        // we just ignore the least significant 8 bits
        unsigned int red = (m_doublePrecision)   ? readU16()>>8 : readU8();
        unsigned int green = (m_doublePrecision) ? readU16()>>8 : readU8();
        unsigned int blue = (m_doublePrecision)  ? readU16()>>8 : readU8();
        unsigned int alpha = (m_doublePrecision) ? readU16()>>8 : readU8();
 
-       m_brush.backColor = WPGColor(red, green, blue, alpha);
-       if(m_brush.style == WPGBrush::NoBrush)
-               m_brush.style = WPGBrush::Solid;
+       m_brush.backColor = libwpg::WPGColor(red, green, blue, alpha);
+       if(m_brush.style == libwpg::WPGBrush::NoBrush)
+               m_brush.style = libwpg::WPGBrush::Solid;
 
        WPG_DEBUG_MSG(("   Background color (RGBA): %d %d %d %d\n", red, green, blue, alpha));
 }
 
 void WPG2Parser::handleBrushPattern()
 {
+       if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+               return;
+#ifdef DEBUG   
        unsigned int pattern = readU16();
-#if !defined(DEBUG)
-       (void)pattern;
-#endif // !defined(DEBUG)
+#endif
 
        // TODO
 
@@ -1048,13 +1080,13 @@ void WPG2Parser::handlePolyline()
 
        unsigned long count = readU16();
 
-       WPGPointArray points;
+       libwpg::WPGPointArray points;
        for(unsigned long i = 0; i < count; i++ )
        {
                long x = (m_doublePrecision) ? readS32() : readS16();
                long y = (m_doublePrecision) ? readS32() : readS16();
                TRANSFORM_XY(x,y);
-               WPGPoint p(TO_DOUBLE(x)/m_xres, TO_DOUBLE(y)/m_yres);
+               libwpg::WPGPoint p(TO_DOUBLE(x)/m_xres, TO_DOUBLE(y)/m_yres);
                points.add(p);
        }
 
@@ -1064,7 +1096,7 @@ void WPG2Parser::handlePolyline()
                {
                        // inside a compound ? convert it into path because for compound 
                        // we will only use paths
-                       WPGPath& path = m_groupStack.top().compoundPath;
+                       libwpg::WPGPath& path = m_groupStack.top().compoundPath;
                        path.moveTo(points[0]);
                        for(unsigned long ii = 1; ii < count; ii++)
                                path.lineTo(points[ii]);
@@ -1073,12 +1105,12 @@ void WPG2Parser::handlePolyline()
        else
        {
                // otherwise draw directly
-               m_painter->setBrush( objCh.filled ? m_brush : WPGBrush() );
-               m_painter->setPen( objCh.framed ? m_pen : WPGPen() );
+               m_painter->setBrush( objCh.filled ? m_brush : libwpg::WPGBrush() );
+               m_painter->setPen( objCh.framed ? m_pen : libwpg::WPGPen() );
                if(objCh.windingRule)
-                       m_painter->setFillRule(WPGPaintInterface::WindingFill);
+                       m_painter->setFillRule(libwpg::WPGPaintInterface::WindingFill);
                else
-                       m_painter->setFillRule(WPGPaintInterface::AlternatingFill);
+                       m_painter->setFillRule(libwpg::WPGPaintInterface::AlternatingFill);
                m_painter->drawPolygon(points);
        }
 
@@ -1102,24 +1134,24 @@ void WPG2Parser::handlePolycurve()
 
        unsigned int count = readU16();
 
-       WPGPointArray vertices;
-       WPGPointArray controlPoints;
-       for(int i = 0; i < static_cast<int>(count); i++ )
+       libwpg::WPGPointArray vertices;
+       libwpg::WPGPointArray controlPoints;
+       for(unsigned int i = 0; i < count; i++ )
        {
                long ix = (m_doublePrecision) ? readS32() : readS16();
                long iy = (m_doublePrecision) ? readS32() : readS16();
                TRANSFORM_XY(ix,iy);
-               WPGPoint initialPoint( TO_DOUBLE(ix)/m_xres, TO_DOUBLE(iy)/m_yres );
+               libwpg::WPGPoint initialPoint( TO_DOUBLE(ix)/m_xres, TO_DOUBLE(iy)/m_yres );
 
                long ax = (m_doublePrecision) ? readS32() : readS16();
                long ay = (m_doublePrecision) ? readS32() : readS16();
                TRANSFORM_XY(ax,ay);
-               WPGPoint anchorPoint( TO_DOUBLE(ax)/m_xres, TO_DOUBLE(ay)/m_yres );
+               libwpg::WPGPoint anchorPoint( TO_DOUBLE(ax)/m_xres, TO_DOUBLE(ay)/m_yres );
 
                long tx = (m_doublePrecision) ? readS32() : readS16();
                long ty = (m_doublePrecision) ? readS32() : readS16();
                TRANSFORM_XY(tx,ty);
-               WPGPoint terminalPoint( TO_DOUBLE(tx)/m_xres, TO_DOUBLE(ty)/m_yres );
+               libwpg::WPGPoint terminalPoint( TO_DOUBLE(tx)/m_xres, TO_DOUBLE(ty)/m_yres );
 
                vertices.add(anchorPoint);
                if(i > 0)
@@ -1127,7 +1159,7 @@ void WPG2Parser::handlePolycurve()
                controlPoints.add(terminalPoint);
        }
 
-       WPGPath path;
+       libwpg::WPGPath path;
        path.closed = objCh.closed;
        path.moveTo(vertices[0]);
        for(unsigned j = 1; j < vertices.count(); j++)
@@ -1139,12 +1171,12 @@ void WPG2Parser::handlePolycurve()
        else
        {
                // otherwise draw directly
-               m_painter->setBrush( objCh.filled ? m_brush : WPGBrush() );
-               m_painter->setPen( objCh.framed ? m_pen : WPGPen() );
+               m_painter->setBrush( objCh.filled ? m_brush : libwpg::WPGBrush() );
+               m_painter->setPen( objCh.framed ? m_pen : libwpg::WPGPen() );
                if(objCh.windingRule)
-                       m_painter->setFillRule(WPGPaintInterface::WindingFill);
+                       m_painter->setFillRule(libwpg::WPGPaintInterface::WindingFill);
                else
-                       m_painter->setFillRule(WPGPaintInterface::AlternatingFill);
+                       m_painter->setFillRule(libwpg::WPGPaintInterface::AlternatingFill);
                m_painter->drawPath(path);
        }
 }
@@ -1171,7 +1203,7 @@ void WPG2Parser::handleRectangle()
        long rx = (m_doublePrecision) ? readS32() : readS16();
        long ry = (m_doublePrecision) ? readS32() : readS16();
 
-       WPGRect rect;
+       libwpg::WPGRect rect;
        rect.x1 = TO_DOUBLE(xs1) / m_xres;
        rect.x2 = TO_DOUBLE(xs2) / m_xres;
        rect.y1 = TO_DOUBLE(ys1) / m_yres;
@@ -1179,8 +1211,8 @@ void WPG2Parser::handleRectangle()
        double roundx = TO_DOUBLE(rx)/m_xres;
        double roundy = TO_DOUBLE(ry)/m_yres;
 
-       m_painter->setBrush( objCh.filled ? m_brush : WPGBrush() );
-       m_painter->setPen( objCh.framed ? m_pen : WPGPen() );
+       m_painter->setBrush( objCh.filled ? m_brush : libwpg::WPGBrush() );
+       m_painter->setPen( objCh.framed ? m_pen : libwpg::WPGPen() );
        m_painter->drawRectangle(rect, roundx, roundy);
        
        WPG_DEBUG_MSG(("      X1 : %d\n", x1));
@@ -1199,6 +1231,7 @@ void WPG2Parser::handleArc()
        
        long cx = (m_doublePrecision) ? readS32() : readS16();
        long cy = (m_doublePrecision) ? readS32() : readS16();
+       TRANSFORM_XY(cx,cy);
 
        long radx = (m_doublePrecision) ? readS32() : readS16();
        long rady = (m_doublePrecision) ? readS32() : readS16();
@@ -1213,14 +1246,14 @@ void WPG2Parser::handleArc()
 
        if((ix==ex) && (iy==ey))
        {
-               WPGPoint center;
+               libwpg::WPGPoint center;
                center.x = TO_DOUBLE(cx) / m_xres;
                center.y = TO_DOUBLE(cy) / m_xres;
                double rx = TO_DOUBLE(radx) / m_xres;
                double ry = TO_DOUBLE(rady) / m_xres;
                
-               m_painter->setBrush( objCh.filled ? m_brush : WPGBrush() );
-               m_painter->setPen( objCh.framed ? m_pen : WPGPen() );
+               m_painter->setBrush( objCh.filled ? m_brush : libwpg::WPGBrush() );
+               m_painter->setPen( objCh.framed ? m_pen : libwpg::WPGPen() );
                m_painter->drawEllipse(center, rx, ry);
        }
 
@@ -1240,7 +1273,7 @@ void WPG2Parser::resetPalette()
        m_colorPalette.clear();
        for (int i=0; i<256; i++)
        {
-               WPGColor color;
+               libwpg::WPGColor color;
                color.red = defaultWPG2PaletteRed[i];
                color.green = defaultWPG2PaletteGreen[i];
                color.blue = defaultWPG2PaletteBlue[i];
index 8fd0ab4cc970a1be1809d81131890d359463aab0..3f5e328b19104688178868f045f44fabe9df142c 100644 (file)
@@ -57,17 +57,17 @@ public:
                y = ry;
        }
 
-       WPGPoint transform(const WPGPoint& p) const
+       libwpg::WPGPoint transform(const libwpg::WPGPoint& p) const
        {
-               WPGPoint point;
+               libwpg::WPGPoint point;
                point.x = element[0][0]*p.x + element[1][0]*p.y + element[2][0]; 
                point.y = element[0][1]*p.x + element[1][1]*p.y + element[2][1]; 
                return point;
        }
 
-       WPGRect transform(const WPGRect& r) const
+       libwpg::WPGRect transform(const libwpg::WPGRect& r) const
        {
-               WPGRect rect;
+               libwpg::WPGRect rect;
                rect.x1 = element[0][0]*r.x1 + element[1][0]*r.y1 + element[2][0]; 
                rect.y1 = element[0][1]*r.x1 + element[1][1]*r.y1 + element[2][1]; 
                rect.x2 = element[0][0]*r.x2 + element[1][0]*r.y2 + element[2][0]; 
@@ -111,7 +111,7 @@ class WPGGroupContext
 public:
        unsigned subIndex;
        int parentType;
-       WPGPath compoundPath;
+       libwpg::WPGPath compoundPath;
        WPG2TransformMatrix compoundMatrix;
        bool compoundWindingRule;
        bool compoundFilled;
@@ -128,7 +128,7 @@ public:
 class WPG2Parser : public WPGXParser
 {
 public:
-       WPG2Parser(WPGInputStream *input, WPGPaintInterface* painter);
+       WPG2Parser(libwpg::WPGInputStream *input, libwpg::WPGPaintInterface* painter);
        bool parse();
        
 private:
@@ -174,14 +174,14 @@ private:
        long m_width;
        long m_height;
        bool m_doublePrecision;  
-       WPGPen m_pen;
-       WPGBrush m_brush;
-       std::map<unsigned int,WPGDashArray> m_penStyles;
+       libwpg::WPGPen m_pen;
+       libwpg::WPGBrush m_brush;
+       std::map<unsigned int,libwpg::WPGDashArray> m_penStyles;
        bool m_layerOpened;
        unsigned int m_layerId;
        WPG2TransformMatrix m_matrix;
        double m_gradientAngle;
-       WPGPoint m_gradientRef;
+       libwpg::WPGPoint m_gradientRef;
        std::stack<WPGGroupContext> m_groupStack;
        WPG2TransformMatrix m_compoundMatrix;
        bool m_compoundWindingRule;
diff --git a/src/extension/internal/libwpg/WPGBrush.cpp b/src/extension/internal/libwpg/WPGBrush.cpp
new file mode 100644 (file)
index 0000000..6f83a5a
--- /dev/null
@@ -0,0 +1,63 @@
+/* libwpg
+ * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the 
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02111-1301 USA
+ *
+ * For further information visit http://libwpg.sourceforge.net
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#include "WPGBrush.h"
+
+libwpg::WPGBrush::WPGBrush(): 
+       style(Solid), 
+       foreColor(0,0,0), 
+       backColor(0xFF,0xFF,0xFF),
+       gradient() 
+{}
+
+libwpg::WPGBrush::WPGBrush(const WPGColor& fore): 
+       style(Solid), 
+       foreColor(fore),  
+       backColor(0xFF,0xFF,0xFF),
+       gradient() 
+{}
+
+libwpg::WPGBrush::WPGBrush(const WPGColor& fore, const WPGColor& back): 
+       style(Solid), 
+       foreColor(fore),  
+       backColor(back),
+       gradient()
+{}
+
+libwpg::WPGBrush::WPGBrush(const WPGBrush& brush):
+       style(brush.style),
+       foreColor(brush.foreColor),
+       backColor(brush.backColor),
+       gradient(brush.gradient)
+{}
+
+libwpg::WPGBrush& libwpg::WPGBrush::operator=(const libwpg::WPGBrush& brush)
+{
+       style = brush.style;
+       foreColor = brush.foreColor; 
+       backColor = brush.backColor; 
+       gradient = brush.gradient;
+       return *this; 
+}
index d8c746a4c15e54aaf87fabf2afc4a6ae03c82283..ca9bab8db553a1a8ce02195f7be9e5767e20cee6 100644 (file)
@@ -50,40 +50,15 @@ public:
        
        WPGGradient gradient;
 
-       WPGBrush(): 
-               style(NoBrush), 
-               foreColor(0,0,0), 
-               backColor(0,0,0) 
-                       {};
+       WPGBrush();
 
-       WPGBrush(const WPGColor& fore): 
-               style(Solid), 
-               foreColor(fore),  
-               backColor(0,0,0) 
-                       {};
+       explicit WPGBrush(const WPGColor& fore);
 
-       WPGBrush(const WPGColor& fore, const WPGColor& back): 
-               style(Solid), 
-               foreColor(fore),  
-               backColor(back) 
-                       {};
+       WPGBrush(const WPGColor& fore, const WPGColor& back);
 
-       WPGBrush(const WPGBrush& brush)
-       {
-               style = brush.style;
-               foreColor = brush.foreColor; 
-               backColor = brush.backColor; 
-               gradient = brush.gradient;
-       }
+       WPGBrush(const WPGBrush& brush);
 
-       WPGBrush& operator=(const WPGBrush& brush)
-       {
-               style = brush.style;
-               foreColor = brush.foreColor; 
-               backColor = brush.backColor; 
-               gradient = brush.gradient;
-               return *this; 
-       }
+       WPGBrush& operator=(const WPGBrush& brush);
 };
 
 } // namespace libwpg
diff --git a/src/extension/internal/libwpg/WPGColor.cpp b/src/extension/internal/libwpg/WPGColor.cpp
new file mode 100644 (file)
index 0000000..fea9395
--- /dev/null
@@ -0,0 +1,63 @@
+/* libwpg
+ * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the 
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02111-1301 USA
+ *
+ * For further information visit http://libwpg.sourceforge.net
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#include "WPGColor.h"
+
+libwpg::WPGColor::WPGColor():
+       red(0),
+       green(0),
+       blue(0),
+       alpha(0)
+{}
+
+libwpg::WPGColor::WPGColor(int r, int g, int b):
+       red(r),
+       green(g),
+       blue(b),
+       alpha(0)
+{}
+
+libwpg::WPGColor::WPGColor(int r, int g, int b, int a):
+       red(r),
+       green(g),
+       blue(b),
+       alpha(a)
+{}
+
+libwpg::WPGColor::WPGColor(const WPGColor& color):
+       red(color.red),
+       green(color.green),
+       blue(color.blue),
+       alpha(color.alpha)
+{}
+
+libwpg::WPGColor& libwpg::WPGColor::operator=(const libwpg::WPGColor& color)
+{
+       red = color.red;
+       green = color.green;
+       blue = color.blue;
+       alpha = color.alpha;
+       return *this;
+}
index 8867ae5ad062d0f11933cb817e139f55f4b50531..0800ea6e8f5668337f58e0237ad1588a23b3de7e 100644 (file)
@@ -34,17 +34,15 @@ class WPGColor
 public:
        int red, green, blue, alpha;
        
-       WPGColor(): red(0), green(0), blue(0), alpha(0) {}
+       WPGColor();
        
-       WPGColor(int r, int g, int b): red(r), green(g), blue(b), alpha(0)  {}
+       WPGColor(int r, int g, int b);
        
-       WPGColor(int r, int g, int b, int a): red(r), green(g), blue(b), alpha(a)  {}
+       WPGColor(int r, int g, int b, int a);
 
-       WPGColor(const WPGColor& color)
-       { red = color.red; green = color.green; blue = color.blue; alpha = color.alpha; }
+       WPGColor(const WPGColor& color);
        
-       WPGColor& operator=(const WPGColor& color)
-       { red = color.red; green = color.green; blue = color.blue; alpha = color.alpha; return *this; }
+       WPGColor& operator=(const WPGColor& color);
 };
 
 } // namespace libwpg
index 566789e56c5e04245e8bd0cb8e33a208498587bf..5d1bcb010a200d70c8402d80602bef9fd843f454 100644 (file)
@@ -45,71 +45,69 @@ public:
 class WPGGradientPrivate
 {
 public:
-    double angle;
+       double angle;
        std::vector<WPGGradientStop> gradientStops;
 };
 
 } // namespace libwpg
 
-using namespace libwpg;
-
-WPGGradient::WPGGradient()
+libwpg::WPGGradient::WPGGradient()
 {
        d = new WPGGradientPrivate;
        d->angle = 0.0;
 }
 
-WPGGradient::~WPGGradient()
+libwpg::WPGGradient::~WPGGradient()
 {
        delete d;
 }
 
-WPGGradient::WPGGradient(const WPGGradient& g)
+libwpg::WPGGradient::WPGGradient(const libwpg::WPGGradient& g)
 {
-       d = new WPGGradientPrivate;
+       d = new libwpg::WPGGradientPrivate;
        d->angle = g.d->angle;
        d->gradientStops = g.d->gradientStops;
 }
        
-WPGGradient& WPGGradient::operator=(const WPGGradient& g)
+libwpg::WPGGradient& libwpg::WPGGradient::operator=(const libwpg::WPGGradient& g)
 {
        d->angle = g.d->angle;
        d->gradientStops = g.d->gradientStops;
        return *this;
 }
 
-double WPGGradient::angle() const
+double libwpg::WPGGradient::angle() const
 {
        return d->angle;
 }
 
-void WPGGradient::setAngle(double a)
+void libwpg::WPGGradient::setAngle(double a)
 {
        d->angle = a;
 }
        
-unsigned WPGGradient::count() const
+unsigned libwpg::WPGGradient::count() const
 {
        return d->gradientStops.size();
 }
 
-double WPGGradient::stopOffset(unsigned index) const
+double libwpg::WPGGradient::stopOffset(unsigned index) const
 {
        return d->gradientStops[index].offset;
 }
 
-WPGColor WPGGradient::stopColor(unsigned index) const
+libwpg::WPGColor libwpg::WPGGradient::stopColor(unsigned index) const
 {
        return d->gradientStops[index].color;
 }
 
-void WPGGradient::clear()
+void libwpg::WPGGradient::clear()
 {
        d->gradientStops.clear();
 }
 
-void WPGGradient::addStop(double offset, const WPGColor& color)
+void libwpg::WPGGradient::addStop(double offset, const libwpg::WPGColor& color)
 {
-       WPGGradientStop stop(offset, color);
+       libwpg::WPGGradientStop stop(offset, color);
        d->gradientStops.push_back(stop);
 }
index 8daf35700c7df80f1b0d7fbe5c5739c158aa1f66..f08aa3678b9aa686eac736a12d1d76dd61b4be39 100644 (file)
@@ -42,8 +42,6 @@ static inline unsigned long readU32( const void* p )
 }
 }
 
-using namespace libwpg;
-
 WPGHeader::WPGHeader()
 {
                // create a sensible default header
@@ -65,7 +63,7 @@ WPGHeader::WPGHeader()
                m_encryptVersion = 0;
 }
 
-bool WPGHeader::load(WPGInputStream *input)
+bool WPGHeader::load(libwpg::WPGInputStream *input)
 {
        input->seek(0);
        
index c68a379aa3d48efffd1dbbb184a61e137eb9be2c..cd5249f333737b1f46a4e0858054dc9dca2d3a10 100644 (file)
 
 #include "WPGStream.h"
 
-using namespace libwpg;
-
 class WPGHeader 
 {
 public:
        WPGHeader();
        
-       bool load(WPGInputStream *input);
+       bool load(libwpg::WPGInputStream *input);
        
        bool isSupported() const;
        
index 65c3b0b195850bda1ae71ad6343fef85ba214eb6..14d18c1e0895e08e03ab5c7d16e0f92ffe45d166 100644 (file)
@@ -194,9 +194,7 @@ class StreamIO
     void updateCache();
 };
 
-}; // namespace libwpg
-
-using namespace libwpg;
+} // namespace libwpg
 
 static inline unsigned long readU16( const unsigned char* ptr )
 {
@@ -213,7 +211,7 @@ static const unsigned char wpgole_magic[] =
 
 // =========== Header ==========
 
-Header::Header()
+libwpg::Header::Header()
 {
   b_shift = 9;
   s_shift = 6;
@@ -228,10 +226,10 @@ Header::Header()
   for( unsigned i = 0; i < 8; i++ )
     id[i] = wpgole_magic[i];  
   for( unsigned j=0; j<109; j++ )
-    bb_blocks[j] = AllocTable::Avail;
+    bb_blocks[j] = libwpg::AllocTable::Avail;
 }
 
-bool Header::valid()
+bool libwpg::Header::valid()
 {
   if( threshold != 4096 ) return false;
   if( num_bat == 0 ) return false;
@@ -244,7 +242,7 @@ bool Header::valid()
   return true;
 }
 
-void Header::load( const unsigned char* buffer )
+void libwpg::Header::load( const unsigned char* buffer )
 {
   b_shift      = readU16( buffer + 0x1e );
   s_shift      = readU16( buffer + 0x20 );
@@ -264,24 +262,24 @@ void Header::load( const unsigned char* buffer )
  
 // =========== AllocTable ==========
 
-const unsigned AllocTable::Avail = 0xffffffff;
-const unsigned AllocTable::Eof = 0xfffffffe;
-const unsigned AllocTable::Bat = 0xfffffffd;
-const unsigned AllocTable::MetaBat = 0xfffffffc;
+const unsigned libwpg::AllocTable::Avail = 0xffffffff;
+const unsigned libwpg::AllocTable::Eof = 0xfffffffe;
+const unsigned libwpg::AllocTable::Bat = 0xfffffffd;
+const unsigned libwpg::AllocTable::MetaBat = 0xfffffffc;
 
-AllocTable::AllocTable()
+libwpg::AllocTable::AllocTable()
 {
   blockSize = 4096;
   // initial size
   resize( 128 );
 }
 
-unsigned long AllocTable::count()
+unsigned long libwpg::AllocTable::count()
 {
   return data.size();
 }
 
-void AllocTable::resize( unsigned long newsize )
+void libwpg::AllocTable::resize( unsigned long newsize )
 {
   unsigned oldsize = data.size();
   data.resize( newsize );
@@ -291,27 +289,27 @@ void AllocTable::resize( unsigned long newsize )
 }
 
 // make sure there're still free blocks
-void AllocTable::preserve( unsigned long n )
+void libwpg::AllocTable::preserve( unsigned long n )
 {
   std::vector<unsigned long> pre;
   for( unsigned i=0; i < n; i++ )
     pre.push_back( unused() );
 }
 
-unsigned long AllocTable::operator[]( unsigned long index )
+unsigned long libwpg::AllocTable::operator[]( unsigned long index )
 {
   unsigned long result;
   result = data[index];
   return result;
 }
 
-void AllocTable::set( unsigned long index, unsigned long value )
+void libwpg::AllocTable::set( unsigned long index, unsigned long value )
 {
   if( index >= count() ) resize( index + 1);
   data[ index ] = value;
 }
 
-void AllocTable::setChain( std::vector<unsigned long> chain )
+void libwpg::AllocTable::setChain( std::vector<unsigned long> chain )
 {
   if( chain.size() )
   {
@@ -322,7 +320,7 @@ void AllocTable::setChain( std::vector<unsigned long> chain )
 }
 
 // follow 
-std::vector<unsigned long> AllocTable::follow( unsigned long start )
+std::vector<unsigned long> libwpg::AllocTable::follow( unsigned long start )
 {
   std::vector<unsigned long> chain;
 
@@ -343,7 +341,7 @@ std::vector<unsigned long> AllocTable::follow( unsigned long start )
   return chain;
 }
 
-unsigned AllocTable::unused()
+unsigned libwpg::AllocTable::unused()
 {
   // find first available block
   for( unsigned i = 0; i < data.size(); i++ )
@@ -356,7 +354,7 @@ unsigned AllocTable::unused()
   return block;      
 }
 
-void AllocTable::load( const unsigned char* buffer, unsigned len )
+void libwpg::AllocTable::load( const unsigned char* buffer, unsigned len )
 {
   resize( len / 4 );
   for( unsigned i = 0; i < count(); i++ )
@@ -365,14 +363,14 @@ void AllocTable::load( const unsigned char* buffer, unsigned len )
 
 // =========== DirTree ==========
 
-const unsigned DirTree::End = 0xffffffff;
+const unsigned libwpg::DirTree::End = 0xffffffff;
 
-DirTree::DirTree()
+libwpg::DirTree::DirTree()
 {
   clear();
 }
 
-void DirTree::clear()
+void libwpg::DirTree::clear()
 {
   // leave only root entry
   entries.resize( 1 );
@@ -386,18 +384,18 @@ void DirTree::clear()
   entries[0].child = End;
 }
 
-unsigned DirTree::entryCount()
+unsigned libwpg::DirTree::entryCount()
 {
   return entries.size();
 }
 
-DirEntry* DirTree::entry( unsigned index )
+libwpg::DirEntry* libwpg::DirTree::entry( unsigned index )
 {
-  if( index >= entryCount() ) return (DirEntry*) 0;
+  if( index >= entryCount() ) return (libwpg::DirEntry*) 0;
   return &entries[ index ];
 }
 
-int DirTree::parent( unsigned index )
+int libwpg::DirTree::parent( unsigned index )
 {
   // brute-force, basically we iterate for each entries, find its children
   // and check if one of the children is 'index'
@@ -412,7 +410,7 @@ int DirTree::parent( unsigned index )
   return -1;
 }
 
-std::string DirTree::fullName( unsigned index )
+std::string libwpg::DirTree::fullName( unsigned index )
 {
   // don't use root name ("Root Entry"), just give "/"
   if( index == 0 ) return "/";
@@ -437,10 +435,10 @@ std::string DirTree::fullName( unsigned index )
 }
 
 // given a fullname (e.g "/ObjectPool/_1020961869"), find the entry
-DirEntry* DirTree::entry( const std::string& name )
+libwpg::DirEntry* libwpg::DirTree::entry( const std::string& name )
 {
 
-   if( !name.length() ) return (DirEntry*)0;
+   if( !name.length() ) return (libwpg::DirEntry*)0;
  
    // quick check for "/" (that's root)
    if( name == "/" ) return entry( 0 );
@@ -471,7 +469,7 @@ DirEntry* DirTree::entry( const std::string& name )
      unsigned child = 0;
      for( unsigned i = 0; i < chi.size(); i++ )
      {
-       DirEntry* ce = entry( chi[i] );
+       libwpg::DirEntry* ce = entry( chi[i] );
        if( ce ) 
        if( ce->valid && ( ce->name.length()>1 ) )
        if( ce->name == *it )
@@ -480,17 +478,17 @@ DirEntry* DirTree::entry( const std::string& name )
      
      // traverse to the child
      if( child > 0 ) index = child;
-     else return (DirEntry*)0;
+     else return (libwpg::DirEntry*)0;
    }
 
    return entry( index );
 }
 
 // helper function: recursively find siblings of index
-void dirtree_find_siblings( DirTree* dirtree, std::vector<unsigned>& result, 
+void dirtree_find_siblings( libwpg::DirTree* dirtree, std::vector<unsigned>& result, 
   unsigned index )
 {
-  DirEntry* e = dirtree->entry( index );
+  libwpg::DirEntry* e = dirtree->entry( index );
   if( !e ) return;
   if( !e->valid ) return;
 
@@ -520,7 +518,7 @@ void dirtree_find_siblings( DirTree* dirtree, std::vector<unsigned>& result,
   }
 }
 
-std::vector<unsigned> DirTree::children( unsigned index )
+std::vector<unsigned> libwpg::DirTree::children( unsigned index )
 {
   std::vector<unsigned> result;
   
@@ -531,7 +529,7 @@ std::vector<unsigned> DirTree::children( unsigned index )
   return result;
 }
 
-void DirTree::load( unsigned char* buffer, unsigned size )
+void libwpg::DirTree::load( unsigned char* buffer, unsigned size )
 {
   entries.clear();
   
@@ -559,7 +557,7 @@ void DirTree::load( unsigned char* buffer, unsigned size )
     // 2 = file (aka stream), 1 = directory (aka storage), 5 = root
     unsigned type = buffer[ 0x42 + p];
     
-    DirEntry e;
+    libwpg::DirEntry e;
     e.valid = true;
     e.name = name;
     e.start = readU32( buffer + 0x74+p );
@@ -579,41 +577,41 @@ void DirTree::load( unsigned char* buffer, unsigned size )
 
 // =========== StorageIO ==========
 
-StorageIO::StorageIO( Storage* st, const std::stringstream &memorystream ) :
+libwpg::StorageIO::StorageIO( libwpg::Storage* st, const std::stringstream &memorystream ) :
        buf( memorystream.str(), std::ios::binary | std::ios::in )
 {
   storage = st;
-  result = Storage::Ok;
+  result = libwpg::Storage::Ok;
   
-  header = new Header();
-  dirtree = new DirTree();
-  bbat = new AllocTable();
-  sbat = new AllocTable();
+  header = new libwpg::Header();
+  dirtree = new libwpg::DirTree();
+  bbat = new libwpg::AllocTable();
+  sbat = new libwpg::AllocTable();
   
   bufsize = 0;
   bbat->blockSize = 1 << header->b_shift;
   sbat->blockSize = 1 << header->s_shift;
 }
 
-StorageIO::~StorageIO()
+libwpg::StorageIO::~StorageIO()
 {
   delete sbat;
   delete bbat;
   delete dirtree;
   delete header;
 
-  std::list<Stream*>::iterator it;
+  std::list<libwpg::Stream*>::iterator it;
   for( it = streams.begin(); it != streams.end(); ++it )
     delete *it;
 }
 
-bool StorageIO::isOle()
+bool libwpg::StorageIO::isOle()
 {
   load();
-  return (result == Storage::Ok);
+  return (result == libwpg::Storage::Ok);
 }
 
-void StorageIO::load()
+void libwpg::StorageIO::load()
 {
   unsigned char* buffer = 0;
   unsigned long buflen = 0;
@@ -631,13 +629,13 @@ void StorageIO::load()
   delete[] buffer;
 
   // check OLE magic id
-  result = Storage::NotOLE;
+  result = libwpg::Storage::NotOLE;
   for( unsigned i=0; i<8; i++ )
     if( header->id[i] != wpgole_magic[i] )
       return;
  
   // sanity checks
-  result = Storage::BadOLE;
+  result = libwpg::Storage::BadOLE;
   if( !header->valid() ) return;
   if( header->threshold != 4096 ) return;
 
@@ -704,28 +702,28 @@ void StorageIO::load()
   sb_blocks = bbat->follow( sb_start ); // small files
   
   // so far so good
-  result = Storage::Ok;
+  result = libwpg::Storage::Ok;
 }
 
-StreamIO* StorageIO::streamIO( const std::string& name )
+libwpg::StreamIO* libwpg::StorageIO::streamIO( const std::string& name )
 {
   load();
 
   // sanity check
-  if( !name.length() ) return (StreamIO*)0;
+  if( !name.length() ) return (libwpg::StreamIO*)0;
 
   // search in the entries
-  DirEntry* entry = dirtree->entry( name );
-  if( !entry ) return (StreamIO*)0;
-  if( entry->dir ) return (StreamIO*)0;
+  libwpg::DirEntry* entry = dirtree->entry( name );
+  if( !entry ) return (libwpg::StreamIO*)0;
+  if( entry->dir ) return (libwpg::StreamIO*)0;
 
-  StreamIO* result = new StreamIO( this, entry );
+  libwpg::StreamIO* result = new libwpg::StreamIO( this, entry );
   result->fullName = name;
   
   return result;
 }
 
-unsigned long StorageIO::loadBigBlocks( std::vector<unsigned long> blocks,
+unsigned long libwpg::StorageIO::loadBigBlocks( std::vector<unsigned long> blocks,
   unsigned char* data, unsigned long maxlen )
 {
   // sentinel
@@ -749,7 +747,7 @@ unsigned long StorageIO::loadBigBlocks( std::vector<unsigned long> blocks,
   return bytes;
 }
 
-unsigned long StorageIO::loadBigBlock( unsigned long block,
+unsigned long libwpg::StorageIO::loadBigBlock( unsigned long block,
   unsigned char* data, unsigned long maxlen )
 {
   // sentinel
@@ -764,7 +762,7 @@ unsigned long StorageIO::loadBigBlock( unsigned long block,
 }
 
 // return number of bytes which has been read
-unsigned long StorageIO::loadSmallBlocks( std::vector<unsigned long> blocks,
+unsigned long libwpg::StorageIO::loadSmallBlocks( std::vector<unsigned long> blocks,
   unsigned char* data, unsigned long maxlen )
 {
   // sentinel
@@ -801,7 +799,7 @@ unsigned long StorageIO::loadSmallBlocks( std::vector<unsigned long> blocks,
   return bytes;
 }
 
-unsigned long StorageIO::loadSmallBlock( unsigned long block,
+unsigned long libwpg::StorageIO::loadSmallBlock( unsigned long block,
   unsigned char* data, unsigned long maxlen )
 {
   // sentinel
@@ -817,7 +815,7 @@ unsigned long StorageIO::loadSmallBlock( unsigned long block,
 
 // =========== StreamIO ==========
 
-StreamIO::StreamIO( StorageIO* s, DirEntry* e)
+libwpg::StreamIO::StreamIO( libwpg::StorageIO* s, libwpg::DirEntry* e)
 {
   io = s;
   entry = e;
@@ -839,17 +837,17 @@ StreamIO::StreamIO( StorageIO* s, DirEntry* e)
 }
 
 // FIXME tell parent we're gone
-StreamIO::~StreamIO()
+libwpg::StreamIO::~StreamIO()
 {
   delete[] cache_data;  
 }
 
-unsigned long StreamIO::tell()
+unsigned long libwpg::StreamIO::tell()
 {
   return m_pos;
 }
 
-int StreamIO::getch()
+int libwpg::StreamIO::getch()
 {
   // past end-of-file ?
   if( m_pos > entry->size ) return -1;
@@ -868,7 +866,7 @@ int StreamIO::getch()
   return data;
 }
 
-unsigned long StreamIO::read( unsigned long pos, unsigned char* data, unsigned long maxlen )
+unsigned long libwpg::StreamIO::read( unsigned long pos, unsigned char* data, unsigned long maxlen )
 {
   // sanity checks
   if( !data ) return 0;
@@ -926,14 +924,14 @@ unsigned long StreamIO::read( unsigned long pos, unsigned char* data, unsigned l
   return totalbytes;
 }
 
-unsigned long StreamIO::read( unsigned char* data, unsigned long maxlen )
+unsigned long libwpg::StreamIO::read( unsigned char* data, unsigned long maxlen )
 {
   unsigned long bytes = read( tell(), data, maxlen );
   m_pos += bytes;
   return bytes;
 }
 
-void StreamIO::updateCache()
+void libwpg::StreamIO::updateCache()
 {
   // sanity check
   if( !cache_data ) return;
@@ -947,45 +945,45 @@ void StreamIO::updateCache()
 
 // =========== Storage ==========
 
-Storage::Storage( const std::stringstream &memorystream )
+libwpg::Storage::Storage( const std::stringstream &memorystream )
 {
   io = new StorageIO( this, memorystream );
 }
 
-Storage::~Storage()
+libwpg::Storage::~Storage()
 {
   delete io;
 }
 
-int Storage::result()
+int libwpg::Storage::result()
 {
   return io->result;
 }
 
-bool Storage::isOle()
+bool libwpg::Storage::isOle()
 {
   return io->isOle();
 }
 
 // =========== Stream ==========
 
-Stream::Stream( Storage* storage, const std::string& name )
+libwpg::Stream::Stream( libwpg::Storage* storage, const std::string& name )
 {
   io = storage->io->streamIO( name );
 }
 
 // FIXME tell parent we're gone
-Stream::~Stream()
+libwpg::Stream::~Stream()
 {
   delete io;
 }
 
-unsigned long Stream::size()
+unsigned long libwpg::Stream::size()
 {
   return io ? io->entry->size : 0;
 }
 
-unsigned long Stream::read( unsigned char* data, unsigned long maxlen )
+unsigned long libwpg::Stream::read( unsigned char* data, unsigned long maxlen )
 {
   return io ? io->read( data, maxlen ) : 0;
 }
index af4a3d02fec8f87662346480c061e2582482ecc3..c14b12421f46a98457ac333e907f90a11a055cc0 100644 (file)
@@ -53,7 +53,7 @@ public:
   /**
    * Constructs a storage with data.
    **/
-  Storage( const std::stringstream &memorystream );
+  explicit Storage( const std::stringstream &memorystream );
 
   /**
    * Destroys the storage.
index a69ff3f72319fa5c65afe531996cb52d06b7739a..2d0567f24232f637481a7a0a51eef9de90e9e3f4 100644 (file)
@@ -39,73 +39,74 @@ public:
 
 } // namespace libwpg
 
-using namespace libwpg;
+libwpg::WPGPathElement::WPGPathElement():
+       type(NullElement),
+       point(WPGPoint()),
+       extra1(WPGPoint()),
+       extra2(WPGPoint())
+{}
 
-WPGPath::WPGPath()
-{
-       d = new WPGPathPrivate;
-       closed = true;
-}
+libwpg::WPGPath::WPGPath(): closed(true), d(new libwpg::WPGPathPrivate())
+{}
        
-WPGPath::~WPGPath()
+libwpg::WPGPath::~WPGPath()
 {
        delete d;
 }
        
-WPGPath::WPGPath(const WPGPath& path)
+libwpg::WPGPath::WPGPath(const libwpg::WPGPath& path): closed(path.closed), d(new libwpg::WPGPathPrivate())
 {
-       d = new WPGPathPrivate;
        d->elements = path.d->elements;
 }
        
-WPGPath& WPGPath::operator=(const WPGPath& path)
+libwpg::WPGPath& libwpg::WPGPath::operator=(const libwpg::WPGPath& path)
 {
        d->elements = path.d->elements;
        return *this;
 }
        
-unsigned WPGPath::count() const
+unsigned libwpg::WPGPath::count() const
 {
        return d->elements.size();
 }
        
-WPGPathElement WPGPath::element(unsigned index) const
+libwpg::WPGPathElement libwpg::WPGPath::element(unsigned index) const
 {
        return d->elements[index];
 }
        
-void WPGPath::moveTo(const WPGPoint& point)
+void libwpg::WPGPath::moveTo(const libwpg::WPGPoint& point)
 {
-       WPGPathElement element;
-       element.type = WPGPathElement::MoveToElement;
+       libwpg::WPGPathElement element;
+       element.type = libwpg::WPGPathElement::MoveToElement;
        element.point = point;
        addElement(element);
 }
        
-void WPGPath::lineTo(const WPGPoint& point)
+void libwpg::WPGPath::lineTo(const libwpg::WPGPoint& point)
 {
-       WPGPathElement element;
-       element.type = WPGPathElement::LineToElement;
+       libwpg::WPGPathElement element;
+       element.type = libwpg::WPGPathElement::LineToElement;
        element.point = point;
        addElement(element);
 }
        
-void WPGPath::curveTo(const WPGPoint& c1, const WPGPoint& c2, const WPGPoint& endPoint)
+void libwpg::WPGPath::curveTo(const libwpg::WPGPoint& c1, const libwpg::WPGPoint& c2, const libwpg::WPGPoint& endPoint)
 {
-       WPGPathElement element;
-       element.type = WPGPathElement::CurveToElement;
+       libwpg::WPGPathElement element;
+       element.type = libwpg::WPGPathElement::CurveToElement;
        element.point = endPoint;
        element.extra1 = c1;
        element.extra2 = c2;
        addElement(element);
 }
        
-void WPGPath::addElement(const WPGPathElement& element)
+void libwpg::WPGPath::addElement(const libwpg::WPGPathElement& element)
 {
        d->elements.push_back(element);
 }
 
-void WPGPath::append(const WPGPath& path)
+void libwpg::WPGPath::append(const libwpg::WPGPath& path)
 {
        for(unsigned i = 0; i < path.count(); i++)
                addElement(path.element(i));
index 85fcc5c8fc98918a2cd2a033d9a71ca42c5fbda1..9ddf47da1eeaccb29b6334a6dfcf394a59a86583 100644 (file)
@@ -47,7 +47,7 @@ public:
        WPGPoint extra1;
        WPGPoint extra2;
        
-       WPGPathElement(): type(NullElement) {}
+       WPGPathElement();
 };
 
 class WPGPathPrivate;
index f59fda661397ff9e14c106baf668a65b0ff6b88b..b7bb6f7c708e2d5e9934f0dd0d3e66e1375c25d6 100644 (file)
@@ -36,41 +36,90 @@ public:
 };
 }
        
-using namespace libwpg;
-
-WPGDashArray::WPGDashArray()
+libwpg::WPGDashArray::WPGDashArray() : d(new libwpg::WPGDashArrayPrivate())
 {
-       d = new WPGDashArrayPrivate;
 }
 
-WPGDashArray::~WPGDashArray()
+libwpg::WPGDashArray::~WPGDashArray()
 {
        delete d;
 }
 
-WPGDashArray::WPGDashArray(const WPGDashArray& dash)
+libwpg::WPGDashArray::WPGDashArray(const libwpg::WPGDashArray& dash):
+       d(new libwpg::WPGDashArrayPrivate())
 {
-       d = new WPGDashArrayPrivate;
        d->dashes = dash.d->dashes;
 }
 
-WPGDashArray& WPGDashArray::operator=(const WPGDashArray& dash)
+libwpg::WPGDashArray& libwpg::WPGDashArray::operator=(const libwpg::WPGDashArray& dash)
 {
        d->dashes = dash.d->dashes;
        return *this;
 }
 
-unsigned WPGDashArray::count() const
+unsigned libwpg::WPGDashArray::count() const
 {
        return d->dashes.size();
 }
 
-double WPGDashArray::at(unsigned i) const
+double libwpg::WPGDashArray::at(unsigned i) const
 {
        return d->dashes[i];
 }
 
-void WPGDashArray::add(double p)
+void libwpg::WPGDashArray::add(double p)
 {
        d->dashes.push_back(p);
 }
+
+libwpg::WPGPen::WPGPen(): 
+       foreColor(0,0,0), 
+       backColor(0xFF,0xFF,0xFF), 
+       width(0), 
+       height(0), 
+       solid(true) ,
+       dashArray(WPGDashArray())
+{
+}
+
+libwpg::WPGPen::WPGPen(const WPGColor& fore): 
+       foreColor(fore), 
+       backColor(0xFF,0xFF,0xFF), 
+       width(0), 
+       height(0), 
+       solid(true),
+       dashArray(WPGDashArray()) 
+{
+}
+
+libwpg::WPGPen::WPGPen(const WPGColor& fore, const WPGColor& back): 
+       foreColor(fore),  
+       backColor(back), 
+       width(0), 
+       height(0), 
+       solid(true) ,
+       dashArray(WPGDashArray())
+{
+}
+
+libwpg::WPGPen::WPGPen(const WPGPen& pen):
+       foreColor(pen.foreColor),
+       backColor(pen.backColor),
+       width(pen.width),
+       height(pen.height),
+       solid(pen.solid),
+       dashArray(pen.dashArray)
+{
+}
+
+libwpg::WPGPen& libwpg::WPGPen::operator=(const libwpg::WPGPen& pen)
+{ 
+       foreColor = pen.foreColor; 
+       backColor = pen.backColor;
+       width = pen.width;
+       height = pen.height;
+       solid = pen.solid;
+       dashArray = pen.dashArray;
+       return *this;
+}
+
index acef05e2bfc83f254f906fee627430ddc15f538a..655d01e21eb20c601dda48a662f3c356ce91ee32 100644 (file)
@@ -58,50 +58,12 @@ public:
        bool solid;
        WPGDashArray dashArray;
 
-       WPGPen(): 
-               foreColor(0,0,0), 
-               backColor(0,0,0), 
-               width(0), 
-               height(0), 
-               solid(true) 
-               {};
+       WPGPen(); 
+       WPGPen(const WPGColor& fore);
+       WPGPen(const WPGColor& fore, const WPGColor& back);
+       WPGPen(const WPGPen& pen);
 
-       WPGPen(const WPGColor& fore): 
-               foreColor(fore), 
-               backColor(0,0,0), 
-               width(0), 
-               height(0), 
-               solid(true) 
-               {};
-
-       WPGPen(const WPGColor& fore, const WPGColor& back): 
-               foreColor(fore),  
-               backColor(back), 
-               width(0), 
-               height(0), 
-               solid(true) 
-               {};
-
-       WPGPen(const WPGPen& pen)
-       { 
-               foreColor = pen.foreColor; 
-               backColor = pen.backColor;
-               width = pen.width;
-               height = pen.height;
-               solid = pen.solid;
-               dashArray = pen.dashArray;
-       }
-
-       WPGPen& operator=(const WPGPen& pen)
-       { 
-               foreColor = pen.foreColor; 
-               backColor = pen.backColor;
-               width = pen.width;
-               height = pen.height;
-               solid = pen.solid;
-               dashArray = pen.dashArray;
-               return *this;
-       }
+       WPGPen& operator=(const WPGPen& pen);
        
        static WPGPen NoPen;
 };
index 4c54c276ad6bc0c9b4d577f884edb5110574c1af..6db5d84086cd9fdacfc0a6ddaeb5da1daa5665a4 100644 (file)
@@ -37,53 +37,70 @@ public:
 };
 
 }
-       
-using namespace libwpg;
 
+libwpg::WPGPoint::WPGPoint():
+       x(0.0),
+       y(0.0)
+{}
+
+libwpg::WPGPoint::WPGPoint(double xx, double yy):
+       x(xx),
+       y(yy)
+{}
+
+libwpg::WPGPoint::WPGPoint(const WPGPoint& point):
+       x(point.x),
+       y(point.y)
+{}
 
-WPGPointArray::WPGPointArray()
+libwpg::WPGPoint& libwpg::WPGPoint::operator=(const libwpg::WPGPoint& point)
 {
-       d = new WPGPointArrayPrivate;
+       x = point.x;
+       y = point.y;
+       return *this;
 }
+       
+libwpg::WPGPointArray::WPGPointArray(): d(new libwpg::WPGPointArrayPrivate())
+{}
 
-WPGPointArray::~WPGPointArray()
+libwpg::WPGPointArray::~WPGPointArray()
 {
        delete d;
 }
 
-WPGPointArray::WPGPointArray(const WPGPointArray& pa)
+libwpg::WPGPointArray::WPGPointArray(const libwpg::WPGPointArray& pa):
+       d(new libwpg::WPGPointArrayPrivate())
 {
-       d = new WPGPointArrayPrivate;
        d->points = pa.d->points;
 }
 
-WPGPointArray& WPGPointArray::operator=(const WPGPointArray& pa)
+libwpg::WPGPointArray& libwpg::WPGPointArray::operator=(const libwpg::WPGPointArray& pa)
 {
        d->points = pa.d->points;
        return *this;
 }
 
-unsigned WPGPointArray::count() const
+unsigned libwpg::WPGPointArray::count() const
 {
        return d->points.size();
 }
 
-WPGPoint& WPGPointArray::at(unsigned i)
+libwpg::WPGPoint& libwpg::WPGPointArray::at(unsigned i)
 {
        return d->points[i];
 }
 
-const WPGPoint& WPGPointArray::at(unsigned i) const
+const libwpg::WPGPoint& libwpg::WPGPointArray::at(unsigned i) const
 {
        return d->points[i];
 }
 
-const WPGPoint& WPGPointArray::operator[](unsigned i) const
+const libwpg::WPGPoint& libwpg::WPGPointArray::operator[](unsigned i) const
 {
        return d->points[i];
 }
 
-void WPGPointArray::add(const WPGPoint& p)
+void libwpg::WPGPointArray::add(const libwpg::WPGPoint& p)
 {
        d->points.push_back(p);
 }
index 2dcb55a4a93ad9beb1ced4091effc763816f1e7b..4df5ae08876739d76827167c9659ccd8b50b0dd9 100644 (file)
@@ -37,15 +37,13 @@ public:
        double x;
        double y;
 
-       WPGPoint(): x(0.0), y(0.0) {}
+       WPGPoint();
 
-       WPGPoint(double xx, double yy): x(xx), y(yy) {}
+       WPGPoint(double xx, double yy);
 
-       WPGPoint(const WPGPoint& point)
-       { x = point.x; y = point.y; }
+       WPGPoint(const WPGPoint& point);
 
-       WPGPoint& operator=(const WPGPoint& point)
-       { x = point.x; y = point.y; return *this; }
+       WPGPoint& operator=(const WPGPoint& point);
 };
 
 class WPGPointArrayPrivate;
diff --git a/src/extension/internal/libwpg/WPGRect.cpp b/src/extension/internal/libwpg/WPGRect.cpp
new file mode 100644 (file)
index 0000000..467cfac
--- /dev/null
@@ -0,0 +1,66 @@
+/* libwpg
+ * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the 
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02111-1301 USA
+ *
+ * For further information visit http://libwpg.sourceforge.net
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#include "WPGRect.h"
+
+libwpg::WPGRect::WPGRect():
+       x1(0.0),
+       y1(0.0),
+       x2(0.0),
+       y2(0.0)
+{}
+
+libwpg::WPGRect::WPGRect(double xx1, double yy1, double xx2, double yy2): 
+       x1(xx1),
+       y1(yy1),
+       x2(xx2),
+       y2(yy2)
+{}
+
+libwpg::WPGRect::WPGRect(const WPGRect& rect):
+       x1(rect.x1),
+       y1(rect.y1),
+       x2(rect.x2),
+       y2(rect.y2)
+{}
+
+libwpg::WPGRect&  libwpg::WPGRect::operator=(const WPGRect& rect)
+{
+       x1 = rect.x1;
+       y1 = rect.y1;
+       x2 = rect.x2;
+       y2 = rect.y2;
+       return *this;
+}
+
+const double libwpg::WPGRect::width() const
+{
+       return x2-x1;
+}
+
+const double libwpg::WPGRect::height() const
+{
+       return y2-y1;
+}
index b122b43bc6f0a008b9af876b77c63dd0a471c42a..c5df91318d64348fd740310f6c131234ba4de075 100644 (file)
@@ -39,19 +39,16 @@ public:
        double x2;
        double y2;
 
-       WPGRect(): x1(0.0), y1(0.0), x2(0.0), y2(0.0) {}
+       WPGRect();
 
-       WPGRect(double xx1, double yy1, double xx2, double yy2): 
-       x1(xx1), y1(yy1), x2(xx2), y2(yy2) {}
+       WPGRect(double xx1, double yy1, double xx2, double yy2);
 
-       WPGRect(const WPGRect& rect)
-       { x1 = rect.x1; y1 = rect.y1; x2 = rect.x2; y2 = rect.y2; }
+       WPGRect(const WPGRect& rect);
 
-       WPGRect& operator=(const WPGRect& rect)
-       { x1 = rect.x1; y1 = rect.y1; x2 = rect.x2; y2 = rect.y2; return *this; }
+       WPGRect& operator=(const WPGRect& rect);
 
-       double width() const { return x2-x1; }
-       double height() const { return y2-y1; }
+       const double width() const;
+       const double height() const;
 };
 
 } // namespace libwpg
diff --git a/src/extension/internal/libwpg/WPGSVGGenerator.cpp b/src/extension/internal/libwpg/WPGSVGGenerator.cpp
new file mode 100644 (file)
index 0000000..aa7272a
--- /dev/null
@@ -0,0 +1,256 @@
+/* libwpg
+ * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
+ * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ * For further information visit http://libwpg.sourceforge.net
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#include "WPGSVGGenerator.h"
+
+libwpg::WPGSVGGenerator::WPGSVGGenerator(std::ostream & output_sink): m_pen(libwpg::WPGPen()), m_brush(libwpg::WPGBrush()), m_fillRule(AlternatingFill), m_gradientIndex(1), m_outputSink(output_sink), m_oldLocale(output_sink.getloc())
+{
+       // set the stream's locale to "C" when printing floats
+       std::locale c_locale("C");
+       m_outputSink.imbue(c_locale);
+}
+
+libwpg::WPGSVGGenerator::~WPGSVGGenerator()
+{
+       m_outputSink.imbue(m_oldLocale);
+}
+
+void libwpg::WPGSVGGenerator::startDocument(double width, double height) 
+{
+       m_outputSink << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
+       m_outputSink << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"";
+       m_outputSink << " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
+
+       // m_outputSink << "<!-- Created with wpg2svg/libwpg " << LIBWPG_VERSION_STRING << " -->\n";
+
+       m_outputSink << "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" ";
+       m_outputSink << "xmlns:xlink=\"http://www.w3.org/1999/xlink\" ";        
+       m_outputSink << "width=\"" << 72*width << "\" height=\"" << 72*height << "\" >\n";
+       
+       m_gradientIndex = 1;
+}
+
+void libwpg::WPGSVGGenerator::endDocument()
+{
+       m_outputSink << "</svg>\n";
+}
+
+void libwpg::WPGSVGGenerator::setPen(const libwpg::WPGPen& pen)
+{
+       m_pen = pen;
+}
+
+void libwpg::WPGSVGGenerator::setBrush(const libwpg::WPGBrush& brush)
+{
+       m_brush = brush;
+       
+       if(m_brush.style == libwpg::WPGBrush::Gradient)
+       {
+               double angle = m_brush.gradient.angle();
+
+               m_outputSink << "<defs>\n";
+               m_outputSink << "  <linearGradient id=\"grad" << m_gradientIndex++ << "\" >\n";
+               for(unsigned c = 0; c < m_brush.gradient.count(); c++)
+               {
+                       // round to nearest percentage
+                       int ofs = (int)((100.0*m_brush.gradient.stopOffset(c))+0.5);
+
+                       libwpg::WPGColor color = m_brush.gradient.stopColor(c);
+
+                       m_outputSink << "    <stop offset=\"" << ofs << "%\"";
+                       // set stream to %02x formatting
+                       size_t old_stream_size = m_outputSink.width(2);
+                       m_outputSink << std::hex;
+
+                       m_outputSink << " stop-color=\"#" << (color.red <= 0xF ? "0" : "") << color.red;
+                       m_outputSink << "" << (color.green <= 0xF ? "0" : "") << color.green;
+                       m_outputSink << "" << (color.blue <=  0xF ? "0" : "") << color.blue << "\" />\n";
+
+                       // reset stream formatting
+                       m_outputSink << std::dec;
+                       m_outputSink.width(old_stream_size);
+               }
+               m_outputSink << "  </linearGradient>\n";
+               
+               // not a simple horizontal gradient
+               if(angle != -90.0)
+               {
+                       m_outputSink << "  <linearGradient xlink:href=\"#grad" << m_gradientIndex-1 << "\"";
+                       m_outputSink << " id=\"grad" << m_gradientIndex++ << "\" ";
+                       m_outputSink << "x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\" "; 
+                       m_outputSink << "gradientTransform=\"rotate(" << angle << ")\" ";
+                       m_outputSink << "gradientUnits=\"objectBoundingBox\" >\n";
+                       m_outputSink << "  </linearGradient>\n";
+               }
+               
+               m_outputSink << "</defs>\n";
+       }
+}
+
+void libwpg::WPGSVGGenerator::setFillRule(FillRule rule)
+{
+       m_fillRule = rule;
+}
+
+void libwpg::WPGSVGGenerator::startLayer(unsigned int id)
+{
+       m_outputSink << "<g id=\"Layer" << id << "\" >\n";
+}
+
+void libwpg::WPGSVGGenerator::endLayer(unsigned int)
+{
+       m_outputSink << "</g>\n";
+}
+
+void libwpg::WPGSVGGenerator::drawRectangle(const libwpg::WPGRect& rect, double rx, double ry)
+{
+       m_outputSink << "<rect ";
+       m_outputSink << "x=\"" << 72*rect.x1 << "\" y=\"" << 72*rect.y1 << "\" ";
+       m_outputSink << "width=\"" << 72*rect.width() << "\" height=\"" << 72*rect.height() << "\" ";
+       if((rx !=0) || (ry !=0))
+               m_outputSink << "rx=\"" << 72*rx << "\" ry=\"" << 72*ry << "\" ";
+       writeStyle();
+       m_outputSink << "/>\n";
+}
+
+void libwpg::WPGSVGGenerator::drawEllipse(const libwpg::WPGPoint& center, double rx, double ry)
+{
+       m_outputSink << "<ellipse ";
+       m_outputSink << "cx=\"" << 72*center.x << "\" cy=\"" << 72*center.y << "\" ";
+       m_outputSink << "rx=\"" << 72*rx << "\" ry=\"" << 72*ry << "\" ";
+       writeStyle();
+       m_outputSink << "/>\n";
+}
+
+void libwpg::WPGSVGGenerator::drawPolygon(const libwpg::WPGPointArray& vertices)
+{
+       if(vertices.count() < 2)
+               return;
+
+       if(vertices.count() == 2)
+       {
+               const libwpg::WPGPoint& p1 = vertices[0];
+               const libwpg::WPGPoint& p2 = vertices[1];
+               m_outputSink << "<line ";
+               m_outputSink << "x1=\"" << 72*p1.x << "\"  y1=\"" << 72*p1.y << "\" ";
+               m_outputSink << "x2=\"" << 72*p2.x << "\"  y2=\"" << 72*p2.y << "\"\n";
+               writeStyle();
+               m_outputSink << "/>\n";
+       }
+       else
+       {
+               m_outputSink << "<polyline ";
+               m_outputSink << "points=\"";
+               for(unsigned i = 0; i < vertices.count(); i++)
+               {
+                       m_outputSink << 72*vertices[i].x << " " << 72*vertices[i].y;
+                       if(i < vertices.count()-1) m_outputSink << ", ";
+               }
+               m_outputSink << "\"\n";
+               writeStyle();
+               m_outputSink << "/>\n";
+       }
+}
+
+void libwpg::WPGSVGGenerator::drawPath(const libwpg::WPGPath& path)
+{
+       m_outputSink << "<path d=\"";
+       for(unsigned i = 0; i < path.count(); i++)
+       {
+               libwpg::WPGPathElement element = path.element(i);
+               libwpg::WPGPoint point = element.point;
+               switch(element.type)
+               {
+                       case libwpg::WPGPathElement::MoveToElement:
+                               m_outputSink << "\n M" << 72*point.x << "," << 72*point.y << " ";
+                               break;
+                               
+                       case libwpg::WPGPathElement::LineToElement:
+                               m_outputSink << "\n L" << 72*point.x << "," << 72*point.y << " ";
+                               break;
+                       
+                       case libwpg::WPGPathElement::CurveToElement:
+                               m_outputSink << "C";
+                               m_outputSink << 72*element.extra1.x << "," << 72*element.extra1.y << " ";
+                               m_outputSink << 72*element.extra2.x << "," << 72*element.extra2.y << " ";
+                               m_outputSink << 72*point.x << "," << 72*point.y;
+                               break;
+                       
+                       default:
+                               break;
+               }
+       }
+       
+       if(path.closed)
+               m_outputSink << "Z";
+
+       m_outputSink << "\" \n";
+       writeStyle();
+       m_outputSink << "/>\n";
+}
+
+// create "style" attribute based on current pen and brush
+void libwpg::WPGSVGGenerator::writeStyle()
+{
+       m_outputSink << "style=\"";
+
+       const libwpg::WPGColor& color = m_pen.foreColor;
+       m_outputSink << "stroke-width: " << 72*m_pen.width << "; ";
+       if(m_pen.width > 0.0)
+       {
+               m_outputSink << "stroke: rgb(" << color.red << "," << color.green << "," << color.blue << "); ";
+               if(color.alpha != 0)
+                       // alpha = 0 means opacity = 1.0, alpha = 256 means opacity = 0
+                       m_outputSink << "stroke-opacity: " << 1.0-(color.alpha/256.0) << "; ";
+       }
+
+       if(!m_pen.solid)
+       {
+               m_outputSink << "stroke-dasharray: ";
+               for(unsigned i = 0; i < m_pen.dashArray.count(); i++)
+               {
+                       m_outputSink << 72*m_pen.dashArray.at(i)*m_pen.width;
+                       if(i < m_pen.dashArray.count()-1) 
+                               m_outputSink << ", ";
+               }
+               m_outputSink << "; ";
+       }
+       
+       if(m_brush.style == libwpg::WPGBrush::NoBrush)
+               m_outputSink << "fill: none; ";
+
+       if(m_fillRule == WPGSVGGenerator::WindingFill)
+               m_outputSink << "fill-rule: nonzero; ";
+       else if(m_fillRule == WPGSVGGenerator::AlternatingFill)
+               m_outputSink << "fill-rule: evenodd; ";
+
+       if(m_brush.style == libwpg::WPGBrush::Gradient)
+               m_outputSink << "fill: url(#grad" << m_gradientIndex-1 << "); ";
+
+       if(m_brush.style == libwpg::WPGBrush::Solid)
+               m_outputSink << "fill: rgb(" << m_brush.foreColor.red << "," << m_brush.foreColor.green << "," << m_brush.foreColor.blue << "); ";
+
+       m_outputSink << "\""; // style
+}
diff --git a/src/extension/internal/libwpg/WPGSVGGenerator.h b/src/extension/internal/libwpg/WPGSVGGenerator.h
new file mode 100644 (file)
index 0000000..a31d2df
--- /dev/null
@@ -0,0 +1,70 @@
+/* libwpg
+ * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
+ * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ * For further information visit http://libwpg.sourceforge.net
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#ifndef __WPGSVGGENERATOR_H__
+#define __WPGSVGGENERATOR_H__
+
+#include <stdio.h>
+#include <iostream>
+#include <locale>
+#include "libwpg.h"
+#include "WPGStreamImplementation.h"
+
+namespace libwpg
+{
+
+class WPGSVGGenerator : public WPGPaintInterface {
+public:
+       WPGSVGGenerator(std::ostream & output_sink);
+       ~WPGSVGGenerator();
+
+       void startDocument(double imageWidth, double imageHeight);
+       void endDocument();
+       void startLayer(unsigned int id);
+       void endLayer(unsigned int id);
+
+       void setPen(const libwpg::WPGPen& pen);
+       void setBrush(const libwpg::WPGBrush& brush);
+       void setFillRule(FillRule rule);
+
+       void drawRectangle(const libwpg::WPGRect& rect, double rx, double ry);
+       void drawEllipse(const libwpg::WPGPoint& center, double rx, double ry);
+       void drawPolygon(const libwpg::WPGPointArray& vertices);
+       void drawPath(const libwpg::WPGPath& path);
+
+private:
+       libwpg::WPGPen m_pen;
+       libwpg::WPGBrush m_brush;
+       FillRule m_fillRule;
+       int m_gradientIndex;
+       void writeStyle();
+
+       std::ostream & m_outputSink;
+       std::locale m_oldLocale;
+};
+
+} // namespace libwpg
+
+#endif // __WPGSVGGENERATOR_H__
index bd0c59cd516549d9edaa016036fcb94c3d5e99b6..dbfd9003cf292f0162e1909d7e0ac5bed3e2658b 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "WPGStreamImplementation.h"
 #include "WPGOLEStream.h"
-#include "libwpg_utils.h"
+#include "libwpg.h"
 
 #include <fstream>
 #include <sstream>
@@ -54,37 +54,36 @@ public:
 
 } // namespace libwpg
 
-using namespace libwpg;
-
-WPGFileStreamPrivate::WPGFileStreamPrivate() :
+libwpg::WPGFileStreamPrivate::WPGFileStreamPrivate() :
+       file(),
        buffer(std::ios::binary | std::ios::in | std::ios::out)
 {
 }
 
-WPGMemoryStreamPrivate::WPGMemoryStreamPrivate(const std::string str) :
+libwpg::WPGMemoryStreamPrivate::WPGMemoryStreamPrivate(const std::string str) :
        buffer(str, std::ios::binary | std::ios::in)
 {
 }
 
 
-WPGFileStream::WPGFileStream(const char* filename)
+libwpg::WPGFileStream::WPGFileStream(const char* filename)
 {
-       d = new WPGFileStreamPrivate;
+       d = new libwpg::WPGFileStreamPrivate;
        
        d->file.open( filename, std::ios::binary | std::ios::in );
 }
 
-WPGFileStream::~WPGFileStream()
+libwpg::WPGFileStream::~WPGFileStream()
 {
        delete d;
 }
 
-unsigned char WPGFileStream::getc()
+unsigned char libwpg::WPGFileStream::getc()
 {
        return d->file.get();
 }
 
-long WPGFileStream::read(long nbytes, char* buffer)
+long libwpg::WPGFileStream::read(long nbytes, char* buffer)
 {
        long nread = 0;
        
@@ -98,23 +97,23 @@ long WPGFileStream::read(long nbytes, char* buffer)
        return nread;
 }
 
-long WPGFileStream::tell()
+long libwpg::WPGFileStream::tell()
 {
        return d->file.good() ? (long)d->file.tellg() : -1L;
 }
 
-void WPGFileStream::seek(long offset)
+void libwpg::WPGFileStream::seek(long offset)
 {
        if(d->file.good())
                d->file.seekg(offset);
 }
 
-bool WPGFileStream::atEnd()
+bool libwpg::WPGFileStream::atEnd()
 {
        return d->file.eof();
 }
 
-bool WPGFileStream::isOle()
+bool libwpg::WPGFileStream::isOle()
 {
        if (d->buffer.str().empty())
                d->buffer << d->file.rdbuf();
@@ -124,17 +123,17 @@ bool WPGFileStream::isOle()
        return false;
 }
 
-WPGInputStream* WPGFileStream::getWPGOleStream()
+libwpg::WPGInputStream* libwpg::WPGFileStream::getWPGOleStream()
 {
        if (d->buffer.str().empty())
                d->buffer << d->file.rdbuf();
-       Storage *tmpStorage = new Storage( d->buffer );
-       Stream tmpStream( tmpStorage, "PerfectOffice_MAIN" );
+       libwpg::Storage *tmpStorage = new libwpg::Storage( d->buffer );
+       libwpg::Stream tmpStream( tmpStorage, "PerfectOffice_MAIN" );
        if (!tmpStorage || (tmpStorage->result() != Storage::Ok)  || !tmpStream.size())
        {
                if (tmpStorage)
                        delete tmpStorage;
-               return (WPGInputStream*)0;
+               return (libwpg::WPGInputStream*)0;
        }
        
        unsigned char *tmpBuffer = new unsigned char[tmpStream.size()];
@@ -148,30 +147,30 @@ WPGInputStream* WPGFileStream::getWPGOleStream()
        {
                if (tmpStorage)
                        delete tmpStorage;
-               return (WPGInputStream*)0;
+               return (libwpg::WPGInputStream*)0;
        }
 
        delete tmpStorage;
-       return new WPGMemoryStream((const char *)tmpBuffer, tmpLength);
+       return new libwpg::WPGMemoryStream((const char *)tmpBuffer, tmpLength);
 }
 
 
-WPGMemoryStream::WPGMemoryStream(const char *data, const unsigned int dataSize)
+libwpg::WPGMemoryStream::WPGMemoryStream(const char *data, const unsigned int dataSize)
 {
-       d = new WPGMemoryStreamPrivate(std::string(data, dataSize));
+       d = new libwpg::WPGMemoryStreamPrivate(std::string(data, dataSize));
 }
 
-WPGMemoryStream::~WPGMemoryStream()
+libwpg::WPGMemoryStream::~WPGMemoryStream()
 {
        delete d;
 }
 
-unsigned char WPGMemoryStream::getc()
+unsigned char libwpg::WPGMemoryStream::getc()
 {
        return d->buffer.get();
 }
 
-long WPGMemoryStream::read(long nbytes, char* buffer)
+long libwpg::WPGMemoryStream::read(long nbytes, char* buffer)
 {
        long nread = 0;
        
@@ -185,39 +184,39 @@ long WPGMemoryStream::read(long nbytes, char* buffer)
        return nread;
 }
 
-long WPGMemoryStream::tell()
+long libwpg::WPGMemoryStream::tell()
 {
        return d->buffer.good() ? (long)d->buffer.tellg() : -1L;
 }
 
-void WPGMemoryStream::seek(long offset)
+void libwpg::WPGMemoryStream::seek(long offset)
 {
        if(d->buffer.good())
                d->buffer.seekg(offset);
 }
 
-bool WPGMemoryStream::atEnd()
+bool libwpg::WPGMemoryStream::atEnd()
 {
        return d->buffer.eof();
 }
 
-bool WPGMemoryStream::isOle()
+bool libwpg::WPGMemoryStream::isOle()
 {
-       Storage tmpStorage( d->buffer );
+       libwpg::Storage tmpStorage( d->buffer );
        if (tmpStorage.isOle())
                return true;
        return false;
 }
 
-WPGInputStream* WPGMemoryStream::getWPGOleStream()
+libwpg::WPGInputStream* libwpg::WPGMemoryStream::getWPGOleStream()
 {
-       Storage *tmpStorage = new Storage( d->buffer );
-       Stream tmpStream( tmpStorage, "PerfectOffice_MAIN" );
-       if (!tmpStorage || (tmpStorage->result() != Storage::Ok)  || !tmpStream.size())
+       libwpg::Storage *tmpStorage = new libwpg::Storage( d->buffer );
+       libwpg::Stream tmpStream( tmpStorage, "PerfectOffice_MAIN" );
+       if (!tmpStorage || (tmpStorage->result() != libwpg::Storage::Ok)  || !tmpStream.size())
        {
                if (tmpStorage)
                        delete tmpStorage;
-               return (WPGInputStream*)0;
+               return (libwpg::WPGInputStream*)0;
        }
        
        unsigned char *tmpBuffer = new unsigned char[tmpStream.size()];
@@ -231,9 +230,9 @@ WPGInputStream* WPGMemoryStream::getWPGOleStream()
        {
                if (tmpStorage)
                        delete tmpStorage;
-               return (WPGInputStream*)0;
+               return (libwpg::WPGInputStream*)0;
        }
 
        delete tmpStorage;
-       return new WPGMemoryStream((const char *)tmpBuffer, tmpLength);
+       return new libwpg::WPGMemoryStream((const char *)tmpBuffer, tmpLength);
 }
index d6ebdf83a8cc2b5a0ae3c5fa4c37de095554b5a9..5de80cc3e64a7edcc852eab8e99ea452416ff649 100644 (file)
@@ -36,17 +36,17 @@ class WPGFileStreamPrivate;
 class WPGFileStream: public WPGInputStream
 {
 public:
-       WPGFileStream(const char* filename);
+       explicit WPGFileStream(const char* filename);
        ~WPGFileStream();
        
-       virtual unsigned char getc();
-       virtual long read(long n, char* buffer);
-       virtual long tell();
-       virtual void seek(long offset);
-       virtual bool atEnd();
+       unsigned char getc();
+       long read(long n, char* buffer);
+       long tell();
+       void seek(long offset);
+       bool atEnd();
 
-       virtual bool isOle();
-       virtual WPGInputStream *getWPGOleStream();
+       bool isOle();
+       WPGInputStream *getWPGOleStream();
 
 private:
        WPGFileStreamPrivate* d;
@@ -62,14 +62,14 @@ public:
        WPGMemoryStream(const char *data, const unsigned int dataSize);
        ~WPGMemoryStream();
 
-       virtual unsigned char getc();
-       virtual long read(long n, char* buffer);
-       virtual long tell();
-       virtual void seek(long offset);
-       virtual bool atEnd();
+       unsigned char getc();
+       long read(long n, char* buffer);
+       long tell();
+       void seek(long offset);
+       bool atEnd();
 
-       virtual bool isOle();
-       virtual WPGInputStream *getWPGOleStream();
+       bool isOle();
+       WPGInputStream *getWPGOleStream();
 
 private:
        WPGMemoryStreamPrivate* d;
@@ -77,6 +77,6 @@ private:
        WPGMemoryStream& operator=(const WPGMemoryStream&); // assignment is not allowed
 };
 
-} // namespace wpg
+} // namespace libwpg
 
 #endif // __WPGSTREAMIMPLEMENTATION_H__
diff --git a/src/extension/internal/libwpg/WPGString.cpp b/src/extension/internal/libwpg/WPGString.cpp
new file mode 100644 (file)
index 0000000..f1579a1
--- /dev/null
@@ -0,0 +1,81 @@
+/* libwpg
+ * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the 
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02111-1301 USA
+ *
+ * For further information visit http://libwpg.sourceforge.net
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#include "WPGString.h"
+#include <string>
+
+namespace libwpg
+{
+class WPGStringPrivate
+{
+public:
+       std::string str;
+};
+
+} // namespace libwpg
+
+libwpg::WPGString::WPGString() :
+       d(new WPGStringPrivate())
+{
+}
+
+
+libwpg::WPGString::WPGString(const char * str):
+       d(new WPGStringPrivate())
+{
+       d->str = str;
+}
+
+libwpg::WPGString::~WPGString()
+{
+       delete d;
+}
+
+const bool libwpg::WPGString::empty() const
+{
+       return d->str.empty();
+}
+
+const char * libwpg::WPGString::cstr() const
+{
+       return d->str.c_str();
+}
+
+const long libwpg::WPGString::length() const
+{
+       return d->str.length();
+}
+
+libwpg::WPGString& libwpg::WPGString::operator=(const libwpg::WPGString& str)
+{
+       d->str = str.d->str;
+       return *this;
+}
+
+libwpg::WPGString& libwpg::WPGString::operator=(const char * str)
+{
+       d->str = str;
+       return *this;
+}
diff --git a/src/extension/internal/libwpg/WPGString.h b/src/extension/internal/libwpg/WPGString.h
new file mode 100644 (file)
index 0000000..4ff3499
--- /dev/null
@@ -0,0 +1,54 @@
+/* libwpg
+ * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the 
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02111-1301 USA
+ *
+ * For further information visit http://libwpg.sourceforge.net
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#ifndef __WPGSTRING_H__
+#define __WPGSTRING_H__
+
+namespace libwpg
+{
+class WPGStringPrivate;
+class WPGString
+{
+public:
+       WPGString();
+       WPGString(const char * str);
+       
+       ~WPGString();
+
+       const bool empty() const;
+
+       const char * cstr() const;
+
+       const long length() const;
+
+       WPGString& operator=(const WPGString& str);
+       WPGString& operator=(const char * str);
+private:
+       WPGStringPrivate * d;
+};
+
+} // namespace libwpg
+
+#endif // __WPGSTRING_H__
index e25b53aabc9d64a7d55999339127a93492b7ed8a..3e23f5f7721ba6146e5f49bc07820a630a3ac941 100644 (file)
@@ -27,9 +27,7 @@
 
 #include "WPGXParser.h"
 
-using namespace libwpg;
-
-WPGXParser::WPGXParser(WPGInputStream *input, WPGPaintInterface* painter):
+WPGXParser::WPGXParser(libwpg::WPGInputStream *input, libwpg::WPGPaintInterface* painter):
   m_input(input), m_painter(painter)
 {
 }
index d7fd4cb5af20ef67ec58813b02b04ff42da158a2..93bc923e068472900cc568f261aeaa1011fee77b 100644 (file)
 
 #include <map>
 
-using namespace libwpg;
-
 class WPGXParser
 {
 public:
-       WPGXParser(WPGInputStream *input, WPGPaintInterface* painter);
-       virtual ~WPGXParser() {}
+       WPGXParser(libwpg::WPGInputStream *input, libwpg::WPGPaintInterface* painter);
+       virtual ~WPGXParser() {};
        virtual bool parse() = 0;
        
        unsigned char readU8();
@@ -52,9 +50,9 @@ public:
        unsigned int readVariableLengthInteger();
        
 protected:
-       WPGInputStream* m_input;
-       WPGPaintInterface* m_painter;
-       std::map<int,WPGColor> m_colorPalette;
+       libwpg::WPGInputStream* m_input;
+       libwpg::WPGPaintInterface* m_painter;
+       std::map<int,libwpg::WPGColor> m_colorPalette;
 };
 
 #endif // __WPGXPARSER_H__
index e120b802e6aee5b17312b7f20e5af8af9613ee7a..ce91e2f610cf0d8724be1fe9102087efd54bd2c0 100644 (file)
 #include "WPG1Parser.h"
 #include "WPG2Parser.h"
 #include "libwpg_utils.h"
+#include "WPGSVGGenerator.h"
+#include <sstream>
 
-using namespace libwpg;
-
-bool WPGraphics::isSupported(WPGInputStream* input)
+/**
+Analyzes the content of an input stream to see if it can be parsed
+\param input The input stream
+\return A value that indicates whether the content from the input
+stream is a WordPerfect Graphics that libwpg is able to parse
+*/
+bool libwpg::WPGraphics::isSupported(libwpg::WPGInputStream* input)
 {
        WPGHeader header;
        if(!header.load(input))
@@ -42,7 +48,15 @@ bool WPGraphics::isSupported(WPGInputStream* input)
        return header.isSupported();
 }
 
-bool WPGraphics::parse(WPGInputStream* input, WPGPaintInterface* painter)
+/**
+Parses the input stream content. It will make callbacks to the functions provided by a
+WPGPaintInterface class implementation when needed. This is often commonly called the
+'main parsing routine'.
+\param input The input stream
+\param painter A WPGPainterInterface implementation
+\return A value that indicates whether the parsing was successful
+*/
+bool libwpg::WPGraphics::parse(libwpg::WPGInputStream* input, libwpg::WPGPaintInterface* painter)
 {
        WPGXParser *parser = 0;
        
@@ -59,25 +73,45 @@ bool WPGraphics::parse(WPGInputStream* input, WPGPaintInterface* painter)
        
        // seek to the start of document
        input->seek(header.startOfDocument());
-       
+
+       bool retval;
        switch (header.majorVersion()) {
                case 0x01: // WPG1
                        WPG_DEBUG_MSG(("Parsing WPG1\n"));
                        parser = new WPG1Parser(input, painter);
-                       parser->parse();
+                       retval = parser->parse();
                        break;
                case 0x02: // WPG2
                        WPG_DEBUG_MSG(("Parsing WPG2\n"));
                        parser = new WPG2Parser(input, painter);
-                       parser->parse();
+                       retval = parser->parse();
                        break;
                default: // other :-)
                        WPG_DEBUG_MSG(("Unknown format\n"));
-                       break;
+                       return false;
        }
        
-       delete parser;
+       if (parser)
+               delete parser;
        
-       return false;
+       return retval;
+}
+
+/**
+Parses the input stream content and generates a valid Scalable Vector Graphics
+Provided as a convenience function for applications that support SVG internally.
+\param input The input stream
+\param output The output string whose content is the resulting SVG
+\return A value that indicates whether the SVG generation was successful.
+*/
+bool libwpg::WPGraphics::generateSVG(libwpg::WPGInputStream* input, libwpg::WPGString& output)
+{
+       std::ostringstream tmpOutputStream;
+       libwpg::WPGSVGGenerator generator(tmpOutputStream);
+       bool result;
+       if (result = libwpg::WPGraphics::parse(input, &generator))
+               output = WPGString(tmpOutputStream.str().c_str());
+       else
+               output = WPGString("");
+       return result;
 }
index 21abddd1b3efaf9656c25baee526bb023ccf1985..58257459b61074aae1d74f73972c8a4ae1ba067a 100644 (file)
@@ -26,6 +26,8 @@
 #ifndef __WPGRAPHICS_H__
 #define __WPGRAPHICS_H__
 
+#include "WPGString.h"
+
 namespace libwpg
 {
 
@@ -39,6 +41,8 @@ public:
        static bool isSupported(WPGInputStream* input);
        
        static bool parse(WPGInputStream* input, WPGPaintInterface* painter);
+
+       static bool generateSVG(WPGInputStream* input, WPGString& output);
 };
 
 } // namespace libwpg
diff --git a/src/extension/internal/libwpg/makefile.mk b/src/extension/internal/libwpg/makefile.mk
new file mode 100644 (file)
index 0000000..65fc6e4
--- /dev/null
@@ -0,0 +1,29 @@
+PRJ=..$/..$/..$/..$/..$/..
+
+PRJNAME=libwpg
+TARGET=wpglib
+ENABLE_EXCEPTIONS=TRUE
+LIBTARGET=NO
+
+.INCLUDE :  svpre.mk
+.INCLUDE :  settings.mk
+.INCLUDE :  sv.mk
+
+SLOFILES= \
+       $(SLO)$/WPGraphics.obj \
+       $(SLO)$/WPGPen.obj \
+       $(SLO)$/WPGGradient.obj \
+       $(SLO)$/WPGPoint.obj \
+       $(SLO)$/WPGPath.obj \
+       $(SLO)$/WPGHeader.obj \
+       $(SLO)$/WPGXParser.obj \
+       $(SLO)$/WPG1Parser.obj \
+       $(SLO)$/WPG2Parser.obj \
+       $(SLO)$/WPGOLEStream.obj \
+       $(SLO)$/WPGStreamImplementation.obj
+
+LIB1ARCHIV=$(LB)$/libwpglib.a
+LIB1TARGET=$(SLB)$/$(TARGET).lib
+LIB1OBJFILES= $(SLOFILES)
+
+.INCLUDE :  target.mk
index 0326b150adc26a6832c6f367a1d1b251f7bd42e0..fd0cdff3947094e98c3ea74c4f21a00f2c812452 100644 (file)
@@ -46,7 +46,7 @@
 #include "document.h"
 
 #include "libwpg/libwpg.h"
-#include "libwpg/WPGStreamImplementation.h"
+#include "libwpg/WPGSVGGenerator.h"
 
 using namespace libwpg;
 
@@ -54,257 +54,6 @@ namespace Inkscape {
 namespace Extension {
 namespace Internal {
 
-class InkscapePainter : public libwpg::WPGPaintInterface {
-public:
-       InkscapePainter();
-
-       void startDocument(double imageWidth, double imageHeight);
-       void endDocument();
-       void startLayer(unsigned int id);
-       void endLayer(unsigned int id);
-
-       void setPen(const WPGPen& pen);
-       void setBrush(const WPGBrush& brush);
-       void setFillRule(FillRule rule);
-
-       void drawRectangle(const WPGRect& rect, double rx, double ry);
-       void drawEllipse(const WPGPoint& center, double rx, double ry);
-       void drawPolygon(const WPGPointArray& vertices);
-       void drawPath(const WPGPath& path);
-
-private:
-       WPGPen m_pen;
-       WPGBrush m_brush;
-       FillRule m_fillRule;
-       int m_gradientIndex;
-       void writeStyle();
-        void printf (char * fmt, ...) {
-            va_list args;
-            va_start(args, fmt);
-            gchar * buf = g_strdup_vprintf(fmt, args);
-            va_end(args);
-            if (buf) {
-                document += buf;
-                g_free(buf);
-            }
-        }
-
-public:
-        Glib::ustring document;
-};
-
-InkscapePainter::InkscapePainter(): m_fillRule(AlternatingFill), m_gradientIndex(1)
-{
-}
-
-void InkscapePainter::startDocument(double width, double height) 
-{
-        document = "";
-       printf("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
-       printf("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"");
-       printf(" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
-
-//     printf("<!-- Created with wpg2svg/libwpg %s -->\n", LIBWPG_VERSION_STRING);
-
-       printf("<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" ");
-       printf("xmlns:xlink=\"http://www.w3.org/1999/xlink\" ");        
-       printf("width=\"%g\" height=\"%f\" >\n", 72*width, 72*height);
-       
-       m_gradientIndex = 1;
-}
-
-void InkscapePainter::endDocument()
-{
-       printf("</svg>\n");
-}
-
-void InkscapePainter::setPen(const WPGPen& pen)
-{
-       m_pen = pen;
-}
-
-void InkscapePainter::setBrush(const WPGBrush& brush)
-{
-       m_brush = brush;
-       
-       if(m_brush.style == WPGBrush::Gradient)
-       {
-               double angle = m_brush.gradient.angle();
-
-               printf("<defs>\n");
-               printf("  <linearGradient id=\"grad%d\" >\n", m_gradientIndex++);
-               for(unsigned c = 0; c < m_brush.gradient.count(); c++)
-               {
-                       // round to nearest percentage
-                       int ofs = (int)(100.0*m_brush.gradient.stopOffset(c)+0.5);
-
-                       WPGColor color = m_brush.gradient.stopColor(c);
-                       printf("    <stop offset=\"%d%%\" stop-color=\"#%02x%02x%02x\" />\n",
-                               ofs, color.red, color.green, color.blue);
-               }
-               printf("  </linearGradient>\n");
-               
-               // not a simple horizontal gradient
-               if(angle != -90.0)
-               {
-                       printf("  <linearGradient xlink:href=\"#grad%d\"", m_gradientIndex-1);
-                       printf(" id=\"grad%d\" ", m_gradientIndex++);
-                       printf("x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\" "); 
-                       printf("gradientTransform=\"rotate(%f)\" ", angle);
-                       printf("gradientUnits=\"objectBoundingBox\" >\n");
-                       printf("  </linearGradient>\n");
-               }
-               
-               printf("</defs>\n");
-       }
-}
-
-void InkscapePainter::setFillRule(FillRule rule)
-{
-       m_fillRule = rule;
-}
-
-void InkscapePainter::startLayer(unsigned int id)
-{
-       printf("<g id=\"Layer%d\" >\n", id);
-}
-
-void InkscapePainter::endLayer(unsigned int)
-{
-       printf("</g>\n");
-}
-
-void InkscapePainter::drawRectangle(const WPGRect& rect, double rx, double ry)
-{
-       printf("<rect ");
-       printf("x=\"%f\" y=\"%f\" ", 72*rect.x1, 72*rect.y1);
-       printf("width=\"%f\" height=\"%f\" ", 72*rect.width(), 72*rect.height());
-       if((rx !=0) || (ry !=0))
-               printf("rx=\"%f\" ry=\"%f\" ", 72*rx, 72*ry);
-       writeStyle();
-       printf("/>\n");
-}
-
-void InkscapePainter::drawEllipse(const WPGPoint& center, double rx, double ry)
-{
-       printf("<ellipse ");
-       printf("cx=\"%f\" cy=\"%f\" ", 72*center.x, 72*center.y);
-       printf("rx=\"%f\" ry=\"%f\" ", 72*rx, 72*ry);
-       writeStyle();
-       printf("/>\n");
-}
-
-void InkscapePainter::drawPolygon(const WPGPointArray& vertices)
-{
-       if(vertices.count() < 2)
-               return;
-
-       if(vertices.count() == 2)
-       {
-               const WPGPoint& p1 = vertices[0];
-               const WPGPoint& p2 = vertices[1];
-               printf("<line ");
-               printf("x1=\"%f\"  y1=\"%f\" ", 72*p1.x, 72*p1.y);
-               printf("x2=\"%f\"  y2=\"%f\"\n", 72*p2.x, 72*p2.y);
-               writeStyle();
-               printf("/>\n");
-       }
-       else
-       {
-               printf("<polyline ");
-               printf("points=\"");
-               for(unsigned i = 0; i < vertices.count(); i++)
-               {
-                       printf("%f %f", 72*vertices[i].x, 72*vertices[i].y);
-                       if(i < vertices.count()-1) printf(", ");
-               }
-               printf("\"\n");
-               writeStyle();
-               printf("/>\n");
-       }
-}
-
-void InkscapePainter::drawPath(const WPGPath& path)
-{
-       printf("<path d=\"");
-       for(unsigned i = 0; i < path.count(); i++)
-       {
-               WPGPathElement element = path.element(i);
-               WPGPoint point = element.point;
-               switch(element.type)
-               {
-                       case WPGPathElement::MoveToElement:
-                               printf("\n M%f,%f ", 72*point.x, 72*point.y );
-                               break;
-                               
-                       case WPGPathElement::LineToElement:
-                               printf("\n L%f,%f ", 72*point.x, 72*point.y );
-                               break;
-                       
-                       case WPGPathElement::CurveToElement:
-                               printf("C");
-                               printf("%f,%f ", 72*element.extra1.x, 72*element.extra1.y );
-                               printf("%f,%f ", 72*element.extra2.x, 72*element.extra2.y );
-                               printf("%f,%f", 72*point.x, 72*point.y );
-                               break;
-                       
-                       default:
-                               break;
-               }
-       }
-       
-       if(path.closed)
-               printf("Z");
-
-       printf("\" \n");
-       writeStyle();
-       printf("/>\n");
-}
-
-// create "style" attribute based on current pen and brush
-void InkscapePainter::writeStyle()
-{
-       printf("style=\"");
-
-       const WPGColor& color = m_pen.foreColor;
-       printf("stroke-width: %f; ", 72*m_pen.width);
-       if(m_pen.width > 0.0)
-       {
-               printf("stroke: rgb(%d,%d,%d); ", color.red, color.green, color.blue);
-               if(color.alpha != 0)
-                       // alpha = 0 means opacity = 1.0, alpha = 256 means opacity = 0
-                       printf("stroke-opacity: %f; ", 1.0-(color.alpha/256.0));
-       }
-
-       if(!m_pen.solid)
-       {
-               printf("stroke-dasharray: ");
-               for(unsigned i = 0; i < m_pen.dashArray.count(); i++)
-               {
-                       printf("%f", 72*m_pen.dashArray.at(i)*m_pen.width);
-                       if(i < m_pen.dashArray.count()-1) 
-                               printf(", ");
-               }
-               printf("; ");
-       }
-       
-       if(m_brush.style == WPGBrush::NoBrush)
-               printf("fill: none; ");
-
-       if(m_fillRule == InkscapePainter::WindingFill)
-               printf("fill-rule: nonzero; ");
-       else if(m_fillRule == InkscapePainter::AlternatingFill)
-               printf("fill-rule: evenodd; ");
-
-       if(m_brush.style == WPGBrush::Gradient)
-               printf("fill: url(#grad%d); ", m_gradientIndex-1);
-
-       if(m_brush.style == WPGBrush::Solid)
-               printf("fill: rgb(%d,%d,%d); ", m_brush.foreColor.red, 
-                       m_brush.foreColor.green, m_brush.foreColor.blue);
-
-       printf("\""); // style
-}
 
 SPDocument *
 WpgInput::open(Inkscape::Extension::Input * mod, const gchar * uri) {
@@ -321,15 +70,21 @@ WpgInput::open(Inkscape::Extension::Input * mod, const gchar * uri) {
         //! \todo Dialog here
         // fprintf(stderr, "ERROR: Unsupported file format (unsupported version) or file is encrypted!\n");
         // printf("I'm giving up not supported\n");
+        delete input;
         return NULL;
     }
 
-    InkscapePainter painter;
-    WPGraphics::parse(input, &painter);
+    libwpg::WPGString output;
+    if (!libwpg::WPGraphics::generateSVG(input, output)) {
+        delete input;
+        return NULL;
+    }
 
     //printf("I've got a doc: \n%s", painter.document.c_str());
 
-    return sp_document_new_from_mem(painter.document.c_str(), strlen(painter.document.c_str()), TRUE);
+    SPDocument * doc = sp_document_new_from_mem(output.cstr(), strlen(output.cstr()), TRUE);
+    delete input;
+    return doc;
 }
 
 #include "clear-n_.h"