Update of /cvsroot/libwpg/libwpg/src/lib In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv5477/src/lib Modified Files: WPG1Parser.cpp WPG2Parser.cpp WPGBitmap.cpp WPGColor.cpp WPGColor.h WPGGradient.cpp WPGGradient.h WPGSVGGenerator.cpp Log Message: transforming rgb(XX,YY,ZZ) to #XXYYZZ (still need to handle the default brush correctly) Index: WPGColor.h =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGColor.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- WPGColor.h 14 Dec 2006 14:39:57 -0000 1.3 +++ WPGColor.h 3 Dec 2008 23:05:05 -0000 1.4 @@ -26,6 +26,8 @@ #ifndef __WPGCOLOR_H__ #define __WPGCOLOR_H__ +#include <libwpd/libwpd.h> + namespace libwpg { @@ -43,6 +45,10 @@ WPGColor(const WPGColor& color); WPGColor& operator=(const WPGColor& color); + + const ::WPXString getColorString() const; + + double getOpacity() const; }; } // namespace libwpg Index: WPGBitmap.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGBitmap.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- WPGBitmap.cpp 28 Nov 2008 11:53:03 -0000 1.24 +++ WPGBitmap.cpp 3 Dec 2008 23:05:05 -0000 1.25 @@ -173,7 +173,7 @@ WPG_DEBUG_MSG(("WPGBitmap: DIB info header end = %i\n", tmpBufferPosition - 1)); // Write DIB Image data - + int i = 0; int j = 0; if (d->vFlip) for (i = 0; i < d->height && tmpBufferPosition < tmpDIBFileSize; i++) @@ -219,7 +219,7 @@ WPG_DEBUG_MSG(("WPGBitmap: DIB file size = %i\n", tmpBufferPosition - 1)); d->dib.append(tmpDIBBuffer, tmpDIBFileSize); - + // temporary for debug - dump the binary bmp (need to have write access in the current directory #if DUMP_BITMAP std::ostringstream filename; Index: WPGColor.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGColor.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- WPGColor.cpp 8 Jun 2007 11:57:41 -0000 1.2 +++ WPGColor.cpp 3 Dec 2008 23:05:05 -0000 1.3 @@ -61,3 +61,15 @@ alpha = color.alpha; return *this; } + +const ::WPXString libwpg::WPGColor::getColorString() const +{ + ::WPXString sColor; + sColor.sprintf("#%.2x%.2x%.2x", red, green, blue); + return sColor; +} + +double libwpg::WPGColor::getOpacity() const +{ + return 1.0 - ((double)alpha/256.0); +} Index: WPGSVGGenerator.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGSVGGenerator.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- WPGSVGGenerator.cpp 3 Dec 2008 12:51:21 -0000 1.25 +++ WPGSVGGenerator.cpp 3 Dec 2008 23:05:05 -0000 1.26 @@ -96,16 +96,18 @@ // round to nearest percentage int ofs = (int)((100.0*m_brush.gradient.stopOffset(c))+0.5); - libwpg::WPGColor color = m_brush.gradient.stopColor(c); + ::WPXString color = m_brush.gradient.stopColor(c); + double opacity = m_brush.gradient.stopOpacity(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"; + m_outputSink << " stop-color=\"" << color.cstr() << "\""; + if (opacity != 0.0) + m_outputSink << " stop-opacity=\"" << doubleToString(opacity) << "\""; + m_outputSink << " />\n"; // reset stream formatting m_outputSink << std::dec; @@ -198,7 +200,6 @@ m_outputSink << "<polyline "; m_outputSink << "points=\""; - WPXPropertyListVector::Iter i(vertices); for(unsigned i = 0; i < vertices.count(); i++) { m_outputSink << doubleToString(72*(vertices[i]["svg:x"]->getDouble())) << " " << doubleToString(72*(vertices[i]["svg:y"]->getDouble())); @@ -268,10 +269,10 @@ if(m_pen.width > 0.0 || m_pen.solid) { - m_outputSink << "stroke: rgb(" << color.red << "," << color.green << "," << color.blue << "); "; - if(color.alpha != 0) + m_outputSink << "stroke: " << color.getColorString().cstr() << "; "; + if(color.getOpacity() != 1.0) // alpha = 0 means opacity = 1.0, alpha = 256 means opacity = 0 - m_outputSink << "stroke-opacity: " << doubleToString(1.0-(color.alpha/256.0)) << "; "; + m_outputSink << "stroke-opacity: " << doubleToString(color.getOpacity()) << "; "; } if(!m_pen.solid) @@ -289,17 +290,14 @@ if(m_brush.style == libwpg::WPGBrush::NoBrush) m_outputSink << "fill: none; "; - if(m_brush.style == libwpg::WPGBrush::Pattern) - { - if(m_fillRule["svg:fill-rule"]) - m_outputSink << "fill-rule: " << m_fillRule["svg:fill-rule"]->getStr().cstr() << "; "; - } + if(m_fillRule["svg:fill-rule"]) + m_outputSink << "fill-rule: " << m_fillRule["svg:fill-rule"]->getStr().cstr() << "; "; 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 << "fill: " << m_brush.foreColor.getColorString().cstr() << "; "; m_outputSink << "\""; // style } Index: WPGGradient.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGGradient.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- WPGGradient.cpp 28 Nov 2008 11:53:03 -0000 1.7 +++ WPGGradient.cpp 3 Dec 2008 23:05:05 -0000 1.8 @@ -24,7 +24,6 @@ */ #include "WPGGradient.h" -#include "WPGColor.h" #include <vector> @@ -35,11 +34,12 @@ { public: double offset; - WPGColor color; + ::WPXString color; + double opacity; - WPGGradientStop(): offset(0), color(WPGColor()) {} + WPGGradientStop(): offset(0), color("#000000"), opacity(1.0) {} - WPGGradientStop(double ofs, const WPGColor& c): offset(ofs), color(c) {} + WPGGradientStop(double ofs, const ::WPXString& c, double opa): offset(ofs), color(c), opacity(opa) {} }; class WPGGradientPrivate @@ -98,13 +98,18 @@ return d->gradientStops[index].offset; } -libwpg::WPGColor libwpg::WPGGradient::stopColor(unsigned index) const +::WPXString libwpg::WPGGradient::stopColor(unsigned index) const { return d->gradientStops[index].color; } -void libwpg::WPGGradient::addStop(double offset, const libwpg::WPGColor& color) +double libwpg::WPGGradient::stopOpacity(unsigned index) const { - libwpg::WPGGradientStop stop(offset, color); + return d->gradientStops[index].opacity; +} + +void libwpg::WPGGradient::addStop(double offset, const ::WPXString& color, double opacity) +{ + libwpg::WPGGradientStop stop(offset, color, opacity); d->gradientStops.push_back(stop); } Index: WPGGradient.h =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGGradient.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- WPGGradient.h 28 Nov 2008 11:53:03 -0000 1.4 +++ WPGGradient.h 3 Dec 2008 23:05:05 -0000 1.5 @@ -26,7 +26,7 @@ #ifndef __WPGGRADIENT_H__ #define __WPGGRADIENT_H__ -#include "WPGColor.h" +#include <libwpd/libwpd.h> namespace libwpg { @@ -53,9 +53,11 @@ double stopOffset(unsigned index) const; - WPGColor stopColor(unsigned index) const; + ::WPXString stopColor(unsigned index) const; - void addStop(double offset, const WPGColor& color); + double stopOpacity(unsigned index) const; + + void addStop(double offset, const ::WPXString &color, double opacity); private: WPGGradientPrivate *d; Index: WPG2Parser.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPG2Parser.cpp,v retrieving revision 1.91 retrieving revision 1.92 diff -u -d -r1.91 -r1.92 --- WPG2Parser.cpp 3 Dec 2008 13:41:29 -0000 1.91 +++ WPG2Parser.cpp 3 Dec 2008 23:05:05 -0000 1.92 @@ -665,13 +665,13 @@ for(unsigned i = 0; i < numEntries; i++) { - libwpg::WPGColor color; - color.red = readU8(); - color.green = readU8(); - color.blue = readU8(); - color.alpha = readU8(); + unsigned char red = readU8(); + unsigned char green = readU8(); + unsigned char blue = readU8(); + unsigned char alpha = readU8(); + libwpg::WPGColor color(red, green, blue, alpha); m_colorPalette[startIndex+i] = color; - WPG_DEBUG_MSG(("Index#%d: RGB %d %d %d\n", startIndex+i, color.red, color.green, color.blue)); + WPG_DEBUG_MSG(("Index#%d: RGB %s\n", startIndex+i, color.getColorString().cstr())); } } @@ -684,13 +684,13 @@ for(unsigned int i = 0; i < numEntries; i++) { - libwpg::WPGColor color; - color.red = readU16() >> 8 ; - color.green = readU16() >> 8 ; - color.blue = readU16() >> 8 ; - color.alpha = readU16() >> 8 ; + unsigned char red = readU16() >> 8 ; + unsigned char green = readU16() >> 8 ; + unsigned char blue = readU16() >> 8 ; + unsigned char alpha = readU16() >> 8 ; + libwpg::WPGColor color(red, green, blue, alpha); m_colorPalette[startIndex+i] = color; - WPG_DEBUG_MSG(("Index#%d: RGB %d %d %d\n", startIndex+i, color.red, color.green, color.blue)); + WPG_DEBUG_MSG(("Index#%d: RGB %s\n", startIndex+i, color.getColorString().cstr())); } } @@ -717,10 +717,10 @@ 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(); + unsigned char red = (m_doublePrecision) ? readU16()>>8 : readU8(); + unsigned char green = (m_doublePrecision) ? readU16()>>8 : readU8(); + unsigned char blue = (m_doublePrecision) ? readU16()>>8 : readU8(); + unsigned char alpha = (m_doublePrecision) ? readU16()>>8 : readU8(); m_pen.foreColor = libwpg::WPGColor(red, green, blue, alpha); @@ -927,10 +927,10 @@ 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]); + gradient.addStop(0, colors[1].getColorString(), colors[0].getOpacity()); + gradient.addStop(ref, colors[0].getColorString(), colors[0].getOpacity()); if((m_gradientRef["svg:x"]->getInt() != 65535) && (m_gradientRef["svg:y"]->getInt() != 65535)) - gradient.addStop(1, colors[1]); + gradient.addStop(1, colors[1].getColorString(), colors[1].getOpacity()); m_brush.gradient = gradient; m_brush.style = libwpg::WPGBrush::Gradient; } @@ -994,10 +994,10 @@ double ref = (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]); + gradient.addStop(0, colors[1].getColorString(), colors[1].getOpacity()); + gradient.addStop(ref, colors[0].getColorString(), colors[0].getOpacity()); if((m_gradientRef["svg:x"]->getInt() != 65535) && (m_gradientRef["svg:y"]->getInt() != 65536)) - gradient.addStop(1, colors[1]); + gradient.addStop(1, colors[1].getColorString(), colors[1].getOpacity()); m_brush.gradient = gradient; m_brush.style = libwpg::WPGBrush::Gradient; } @@ -1926,10 +1926,10 @@ m_colorPalette.clear(); for (int i=0; i<256; i++) { - libwpg::WPGColor color; - color.red = defaultWPG2PaletteRed[i]; - color.green = defaultWPG2PaletteGreen[i]; - color.blue = defaultWPG2PaletteBlue[i]; + unsigned char red = defaultWPG2PaletteRed[i]; + unsigned char green = defaultWPG2PaletteGreen[i]; + unsigned char blue = defaultWPG2PaletteBlue[i]; + libwpg::WPGColor color(red, green, blue); m_colorPalette[i] = color; } } Index: WPG1Parser.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPG1Parser.cpp,v retrieving revision 1.54 retrieving revision 1.55 diff -u -d -r1.54 -r1.55 --- WPG1Parser.cpp 3 Dec 2008 12:51:21 -0000 1.54 +++ WPG1Parser.cpp 3 Dec 2008 23:05:05 -0000 1.55 @@ -305,12 +305,12 @@ WPG_DEBUG_MSG(("Colormap\n")); for(unsigned int i = 0; i < numEntries; i++) { - libwpg::WPGColor color; - color.red = readU8(); - color.green = readU8(); - color.blue = readU8(); + unsigned char red = readU8(); + unsigned char green = readU8(); + unsigned char blue = readU8(); + libwpg::WPGColor color(red, green, blue); m_colorPalette[startIndex+i] = color; - WPG_DEBUG_MSG(("Index#%d: RGB %d %d %d\n", startIndex+i, color.red, color.green, color.blue)); + WPG_DEBUG_MSG(("Index#%d: RGB %s\n", startIndex+i, color.getColorString().cstr())); } } @@ -504,7 +504,6 @@ path.append(element); for (unsigned i = 1; i < (count-1)/3; i++) { - element.clear(); long xControl1 = readS16(); long yControl1 = readS16(); long xControl2 = readS16(); @@ -512,6 +511,7 @@ long xCoordinate = readS16(); long yCoordinate = readS16(); + element.clear(); element.insert("libwpg:path-action", "C"); element.insert("svg:x1", (double)xControl1/1200.0); element.insert("svg:y1", (double)(m_height-yControl1)/1200.0); @@ -519,6 +519,7 @@ element.insert("svg:y2", (double)(m_height-yControl2)/1200.0); element.insert("svg:x", (double)xCoordinate/1200.0); element.insert("svg:y", (double)(m_height-yCoordinate)/1200.0); + path.append(element); } @@ -868,10 +869,10 @@ m_colorPalette.clear(); for (int i=0; i<256; i++) { - libwpg::WPGColor color; - color.red = defaultWPG1PaletteRed[i]; - color.green = defaultWPG1PaletteGreen[i]; - color.blue = defaultWPG1PaletteBlue[i]; + unsigned char red = defaultWPG1PaletteRed[i]; + unsigned char green = defaultWPG1PaletteGreen[i]; + unsigned char blue = defaultWPG1PaletteBlue[i]; + libwpg::WPGColor color(red, green, blue); m_colorPalette[i] = color; } } |