summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5c966d6)
raw | patch | inline | side by side (parent: 5c966d6)
author | gouldtj <gouldtj@users.sourceforge.net> | |
Sun, 25 Feb 2007 06:54:05 +0000 (06:54 +0000) | ||
committer | gouldtj <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.
everything.
34 files changed:
diff --git a/src/extension/internal/libwpg/Makefile_insert b/src/extension/internal/libwpg/Makefile_insert
index 179abb81c1a9f8d08a392f36207c39997b4b50d7..8fd555f4c33bcb4a498954f8ab9aaf02479fb86a 100644 (file)
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 \
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
diff --git a/src/extension/internal/libwpg/WPG1Parser.cpp b/src/extension/internal/libwpg/WPG1Parser.cpp
index 9f4a05148082938e856002c244f5aa4b54e3c843..a8b97cbdf63dceefc86af8dec1c178f7631a7e13 100644 (file)
};
-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)
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
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();
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();
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];
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);
{
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);
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;
{
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);
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;
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];
diff --git a/src/extension/internal/libwpg/WPG1Parser.h b/src/extension/internal/libwpg/WPG1Parser.h
index fb238352e548544b3211952843e049376858d2a9..2e7405241d6d43a1487e4cd8a51b3a4da21ad7a6 100644 (file)
class WPG1Parser : public WPGXParser
{
public:
- WPG1Parser(WPGInputStream *input, WPGPaintInterface* painter);
+ WPG1Parser(libwpg::WPGInputStream *input, libwpg::WPGPaintInterface* painter);
bool parse();
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__
diff --git a/src/extension/internal/libwpg/WPG2Parser.cpp b/src/extension/internal/libwpg/WPG2Parser.cpp
index e0b642f0ed5fc0c20309803c0aacce059abce467..a669e5fb884f6a76b1843820bc38b2b126f9f9d8 100644 (file)
{}
};
-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),
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
return m_success;
}
-#if defined(DEBUG)
+#ifdef DEBUG
static const char* describePrecision(unsigned char precision)
{
const char* result = "Unknown";
}
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); }
}
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();
// 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;
{
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);
}
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();
for(unsigned i = 0; i < numEntries; i++)
{
- WPGColor color;
+ libwpg::WPGColor color;
color.red = readU8();
color.green = readU8();
color.blue = readU8();
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 ;
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];
void WPG2Parser::handlePenSize()
{
+ if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+ return;
unsigned int width = readU16();
unsigned int height = readU16();
void WPG2Parser::handleDPPenSize()
{
+ if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon())
+ return;
unsigned long width = readU32();
unsigned long height = readU32();
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
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)
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)));
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));
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));
}
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)));
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));
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));
}
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
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);
}
{
// 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]);
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);
}
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)
controlPoints.add(terminalPoint);
}
- WPGPath path;
+ libwpg::WPGPath path;
path.closed = objCh.closed;
path.moveTo(vertices[0]);
for(unsigned j = 1; j < vertices.count(); j++)
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);
}
}
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;
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));
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();
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);
}
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];
diff --git a/src/extension/internal/libwpg/WPG2Parser.h b/src/extension/internal/libwpg/WPG2Parser.h
index 8fd0ab4cc970a1be1809d81131890d359463aab0..3f5e328b19104688178868f045f44fabe9df142c 100644 (file)
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];
public:
unsigned subIndex;
int parentType;
- WPGPath compoundPath;
+ libwpg::WPGPath compoundPath;
WPG2TransformMatrix compoundMatrix;
bool compoundWindingRule;
bool compoundFilled;
class WPG2Parser : public WPGXParser
{
public:
- WPG2Parser(WPGInputStream *input, WPGPaintInterface* painter);
+ WPG2Parser(libwpg::WPGInputStream *input, libwpg::WPGPaintInterface* painter);
bool parse();
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
--- /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)
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
--- /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)
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
diff --git a/src/extension/internal/libwpg/WPGGradient.cpp b/src/extension/internal/libwpg/WPGGradient.cpp
index 566789e56c5e04245e8bd0cb8e33a208498587bf..5d1bcb010a200d70c8402d80602bef9fd843f454 100644 (file)
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);
}
diff --git a/src/extension/internal/libwpg/WPGHeader.cpp b/src/extension/internal/libwpg/WPGHeader.cpp
index 8daf35700c7df80f1b0d7fbe5c5739c158aa1f66..f08aa3678b9aa686eac736a12d1d76dd61b4be39 100644 (file)
}
}
-using namespace libwpg;
-
WPGHeader::WPGHeader()
{
// create a sensible default header
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;
diff --git a/src/extension/internal/libwpg/WPGOLEStream.cpp b/src/extension/internal/libwpg/WPGOLEStream.cpp
index 65c3b0b195850bda1ae71ad6343fef85ba214eb6..14d18c1e0895e08e03ab5c7d16e0f92ffe45d166 100644 (file)
void updateCache();
};
-}; // namespace libwpg
-
-using namespace libwpg;
+} // namespace libwpg
static inline unsigned long readU16( const unsigned char* ptr )
{
// =========== Header ==========
-Header::Header()
+libwpg::Header::Header()
{
b_shift = 9;
s_shift = 6;
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;
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 );
// =========== 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 );
}
// 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() )
{
}
// 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;
return chain;
}
-unsigned AllocTable::unused()
+unsigned libwpg::AllocTable::unused()
{
// find first available block
for( unsigned i = 0; i < data.size(); i++ )
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++ )
// =========== 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 );
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'
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 "/";
}
// 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 );
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 )
// 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;
}
}
-std::vector<unsigned> DirTree::children( unsigned index )
+std::vector<unsigned> libwpg::DirTree::children( unsigned index )
{
std::vector<unsigned> result;
return result;
}
-void DirTree::load( unsigned char* buffer, unsigned size )
+void libwpg::DirTree::load( unsigned char* buffer, unsigned size )
{
entries.clear();
// 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 );
// =========== 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;
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;
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
return bytes;
}
-unsigned long StorageIO::loadBigBlock( unsigned long block,
+unsigned long libwpg::StorageIO::loadBigBlock( unsigned long block,
unsigned char* data, unsigned long maxlen )
{
// sentinel
}
// 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
return bytes;
}
-unsigned long StorageIO::loadSmallBlock( unsigned long block,
+unsigned long libwpg::StorageIO::loadSmallBlock( unsigned long block,
unsigned char* data, unsigned long maxlen )
{
// sentinel
// =========== StreamIO ==========
-StreamIO::StreamIO( StorageIO* s, DirEntry* e)
+libwpg::StreamIO::StreamIO( libwpg::StorageIO* s, libwpg::DirEntry* e)
{
io = s;
entry = 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;
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;
// =========== 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;
}
diff --git a/src/extension/internal/libwpg/WPGOLEStream.h b/src/extension/internal/libwpg/WPGOLEStream.h
index af4a3d02fec8f87662346480c061e2582482ecc3..c14b12421f46a98457ac333e907f90a11a055cc0 100644 (file)
/**
* Constructs a storage with data.
**/
- Storage( const std::stringstream &memorystream );
+ explicit Storage( const std::stringstream &memorystream );
/**
* Destroys the storage.
index a69ff3f72319fa5c65afe531996cb52d06b7739a..2d0567f24232f637481a7a0a51eef9de90e9e3f4 100644 (file)
} // 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)
WPGPoint extra1;
WPGPoint extra2;
- WPGPathElement(): type(NullElement) {}
+ WPGPathElement();
};
class WPGPathPrivate;
index f59fda661397ff9e14c106baf668a65b0ff6b88b..b7bb6f7c708e2d5e9934f0dd0d3e66e1375c25d6 100644 (file)
};
}
-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)
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;
};
diff --git a/src/extension/internal/libwpg/WPGPoint.cpp b/src/extension/internal/libwpg/WPGPoint.cpp
index 4c54c276ad6bc0c9b4d577f884edb5110574c1af..6db5d84086cd9fdacfc0a6ddaeb5da1daa5665a4 100644 (file)
};
}
-
-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)
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
--- /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)
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
--- /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
--- /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__
diff --git a/src/extension/internal/libwpg/WPGStreamImplementation.cpp b/src/extension/internal/libwpg/WPGStreamImplementation.cpp
index bd0c59cd516549d9edaa016036fcb94c3d5e99b6..dbfd9003cf292f0162e1909d7e0ac5bed3e2658b 100644 (file)
#include "WPGStreamImplementation.h"
#include "WPGOLEStream.h"
-#include "libwpg_utils.h"
+#include "libwpg.h"
#include <fstream>
#include <sstream>
} // 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;
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();
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()];
{
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;
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()];
{
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);
}
diff --git a/src/extension/internal/libwpg/WPGStreamImplementation.h b/src/extension/internal/libwpg/WPGStreamImplementation.h
index d6ebdf83a8cc2b5a0ae3c5fa4c37de095554b5a9..5de80cc3e64a7edcc852eab8e99ea452416ff649 100644 (file)
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;
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;
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
--- /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
--- /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__
diff --git a/src/extension/internal/libwpg/WPGXParser.cpp b/src/extension/internal/libwpg/WPGXParser.cpp
index e25b53aabc9d64a7d55999339127a93492b7ed8a..3e23f5f7721ba6146e5f49bc07820a630a3ac941 100644 (file)
#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)
{
}
diff --git a/src/extension/internal/libwpg/WPGXParser.h b/src/extension/internal/libwpg/WPGXParser.h
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();
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__
diff --git a/src/extension/internal/libwpg/WPGraphics.cpp b/src/extension/internal/libwpg/WPGraphics.cpp
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))
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;
// 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;
}
-
diff --git a/src/extension/internal/libwpg/WPGraphics.h b/src/extension/internal/libwpg/WPGraphics.h
index 21abddd1b3efaf9656c25baee526bb023ccf1985..58257459b61074aae1d74f73972c8a4ae1ba067a 100644 (file)
#ifndef __WPGRAPHICS_H__
#define __WPGRAPHICS_H__
+#include "WPGString.h"
+
namespace libwpg
{
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
--- /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)
#include "document.h"
#include "libwpg/libwpg.h"
-#include "libwpg/WPGStreamImplementation.h"
+#include "libwpg/WPGSVGGenerator.h"
using namespace libwpg;
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) {
//! \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"