From: Fridrich S. <str...@us...> - 2010-06-08 13:47:16
|
Update of /cvsroot/libwpg/libwpg/src/lib In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv8337/src/lib Modified Files: WPG1Parser.cpp WPG1Parser.h WPG2Parser.cpp WPGPaintInterface.h WPGSVGGenerator.cpp WPGSVGGenerator.h Log Message: Starting to support some text elements embedded in WPG documents Index: WPGSVGGenerator.h =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGSVGGenerator.h,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- WPGSVGGenerator.h 7 Sep 2009 09:41:29 -0000 1.22 +++ WPGSVGGenerator.h 8 Jun 2010 13:47:08 -0000 1.23 @@ -47,14 +47,15 @@ void startEmbeddedGraphics(const ::WPXPropertyList & /*propList*/) {} void endEmbeddedGraphics() {} - void setStyle(const ::WPXPropertyListVector& gradient, const ::WPXPropertyList &propList); + void setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &gradient); - void drawRectangle(const ::WPXPropertyList& propList); - void drawEllipse(const ::WPXPropertyList& propList); - void drawPolyline(const ::WPXPropertyListVector& vertices); - void drawPolygon(const ::WPXPropertyListVector& vertices); - void drawPath(const ::WPXPropertyListVector& path); - void drawImageObject(const ::WPXPropertyList &propList, const ::WPXBinaryData& binaryData); + void drawRectangle(const ::WPXPropertyList &propList); + void drawEllipse(const ::WPXPropertyList &propList); + void drawPolyline(const ::WPXPropertyListVector &vertices); + void drawPolygon(const ::WPXPropertyListVector &vertices); + void drawPath(const ::WPXPropertyListVector &path); + void drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData &binaryData); + void drawTextLine(const ::WPXPropertyList &propList, const ::WPXString &str); private: ::WPXPropertyListVector m_gradient; Index: WPG1Parser.h =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPG1Parser.h,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- WPG1Parser.h 7 Sep 2009 08:10:18 -0000 1.23 +++ WPG1Parser.h 8 Jun 2010 13:47:08 -0000 1.24 @@ -63,6 +63,11 @@ void handlePostscriptTypeOne(); void handlePostscriptTypeTwo(); + void handleGraphicsTextAttributes(); + void handleGraphicsTextTypeOne(); + void handleGraphicsTextTypeTwo(); + void handleGraphicsTextTypeThree(); + void resetPalette(); // parsing context Index: WPGSVGGenerator.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGSVGGenerator.cpp,v retrieving revision 1.37 retrieving revision 1.38 diff -u -d -r1.37 -r1.38 --- WPGSVGGenerator.cpp 7 Jun 2010 12:47:51 -0000 1.37 +++ WPGSVGGenerator.cpp 8 Jun 2010 13:47:08 -0000 1.38 @@ -79,7 +79,7 @@ m_outputSink << "</svg>\n"; } -void libwpg::WPGSVGGenerator::setStyle(const ::WPXPropertyListVector& gradient, const ::WPXPropertyList &propList) +void libwpg::WPGSVGGenerator::setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector& gradient) { m_style = propList; @@ -241,7 +241,7 @@ m_outputSink << "/>\n"; } -void libwpg::WPGSVGGenerator::drawImageObject(const ::WPXPropertyList &propList, const ::WPXBinaryData& binaryData) +void libwpg::WPGSVGGenerator::drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData& binaryData) { if (!propList["libwpg:mime-type"] || propList["libwpg:mime-type"]->getStr().len() <= 0) return; @@ -255,6 +255,15 @@ m_outputSink << "\" />\n"; } +void libwpg::WPGSVGGenerator::drawTextLine(const ::WPXPropertyList &propList, const ::WPXString &str) +{ + m_outputSink << "<text "; + if (propList["svg:x"] && propList["svg:y"]) + m_outputSink << "x=\"" << doubleToString(72*(propList["svg:x"]->getDouble())) << "\" y=\"" << doubleToString(72*(propList["svg:y"]->getDouble())) << "\" >\n"; + m_outputSink << str.cstr() << "\n"; + m_outputSink << "</text >\n"; +} + // create "style" attribute based on current pen and brush void libwpg::WPGSVGGenerator::writeStyle(bool isClosed) { Index: WPGPaintInterface.h =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGPaintInterface.h,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- WPGPaintInterface.h 7 Sep 2009 09:41:29 -0000 1.20 +++ WPGPaintInterface.h 8 Jun 2010 13:47:08 -0000 1.21 @@ -40,9 +40,9 @@ // none of the other callback functions will be called before this function is called virtual void startGraphics(const ::WPXPropertyList &propList) = 0; - virtual void setStyle(const ::WPXPropertyListVector& gradient, const ::WPXPropertyList &propList) = 0; + virtual void setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &gradient) = 0; - virtual void startLayer(const ::WPXPropertyList& propList) = 0; + virtual void startLayer(const ::WPXPropertyList &propList) = 0; virtual void endLayer() = 0; @@ -54,13 +54,15 @@ virtual void drawEllipse(const ::WPXPropertyList& propList) = 0; - virtual void drawPolygon(const ::WPXPropertyListVector& vertices) = 0; + virtual void drawPolygon(const ::WPXPropertyListVector &vertices) = 0; virtual void drawPolyline(const ::WPXPropertyListVector &vertices) = 0; - virtual void drawPath(const ::WPXPropertyListVector& path) = 0; + virtual void drawPath(const ::WPXPropertyListVector &path) = 0; - virtual void drawImageObject(const ::WPXPropertyList &propList, const ::WPXBinaryData& binaryData) = 0; + virtual void drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData &binaryData) = 0; + + virtual void drawTextLine(const ::WPXPropertyList &propList, const ::WPXString &str) = 0; // none of the other callback functions will be called after this function is called virtual void endGraphics() = 0; Index: WPG2Parser.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPG2Parser.cpp,v retrieving revision 1.107 retrieving revision 1.108 diff -u -d -r1.107 -r1.108 --- WPG2Parser.cpp 7 Jun 2010 12:47:48 -0000 1.107 +++ WPG2Parser.cpp 8 Jun 2010 13:47:08 -0000 1.108 @@ -653,7 +653,7 @@ else tmpStyle.insert("svg:fill-rule", "evenodd"); - m_painter->setStyle( context.compoundFilled ? m_gradient : ::WPXPropertyListVector(), tmpStyle ); + m_painter->setStyle( tmpStyle, context.compoundFilled ? m_gradient : ::WPXPropertyListVector() ); if (context.compoundClosed) { @@ -1385,7 +1385,7 @@ else tmpStyle.insert("svg:fill-rule", "evenodd"); - m_painter->setStyle( objCh.filled ? m_gradient : ::WPXPropertyListVector(), tmpStyle ); + m_painter->setStyle( tmpStyle, objCh.filled ? m_gradient : ::WPXPropertyListVector() ); if (objCh.filled || objCh.closed) m_painter->drawPolygon(points); @@ -1395,7 +1395,7 @@ else { - m_painter->setStyle( ::WPXPropertyListVector(), tmpStyle ); + m_painter->setStyle( tmpStyle, ::WPXPropertyListVector() ); m_painter->drawPolyline(points); } } @@ -1490,7 +1490,7 @@ tmpStyle.insert("svg:fill-rule", "nonzero"); else tmpStyle.insert("svg:fill-rule", "evenodd"); - m_painter->setStyle( objCh.filled ? m_gradient : ::WPXPropertyListVector(), tmpStyle ); + m_painter->setStyle( tmpStyle, objCh.filled ? m_gradient : ::WPXPropertyListVector() ); m_painter->drawPath(path); } } @@ -1533,7 +1533,7 @@ propList.insert("svg:rx", (TO_DOUBLE(rx)/m_xres)); propList.insert("svg:ry", (TO_DOUBLE(ry)/m_yres)); - m_painter->setStyle( objCh.filled ? m_gradient : ::WPXPropertyListVector(), tmpStyle ); + m_painter->setStyle( tmpStyle, objCh.filled ? m_gradient : ::WPXPropertyListVector() ); m_painter->drawRectangle(propList); WPG_DEBUG_MSG((" X1 : %li\n", x1)); @@ -1577,7 +1577,7 @@ TRANSFORM_XY(ix,iy); TRANSFORM_XY(ex,ey); - m_painter->setStyle( objCh.filled ? m_gradient : ::WPXPropertyListVector(), tmpStyle ); + m_painter->setStyle( tmpStyle, objCh.filled ? m_gradient : ::WPXPropertyListVector() ); if (ix == ex && iy == ey) { @@ -1892,7 +1892,7 @@ const libwpg::WPGColor& color = m_colorPalette[index]; bitmap.setPixel(x, y, color); } - m_painter->drawImageObject(propList, bitmap.getDIB()); + m_painter->drawGraphicObject(propList, bitmap.getDIB()); } // format 2: each byte represents 4 pixels, the color fetched from the palette else if(color_format == 2) @@ -1907,7 +1907,7 @@ const libwpg::WPGColor& color = m_colorPalette[index]; bitmap.setPixel(x, y, color); } - m_painter->drawImageObject(propList, bitmap.getDIB()); + m_painter->drawGraphicObject(propList, bitmap.getDIB()); } // format 3: each byte represents 2 pixels, the color fetched from the palette else if(color_format == 3) @@ -1922,7 +1922,7 @@ const libwpg::WPGColor& color = m_colorPalette[index]; bitmap.setPixel(x, y, color); } - m_painter->drawImageObject(propList, bitmap.getDIB()); + m_painter->drawGraphicObject(propList, bitmap.getDIB()); } // format 4: each byte represents a pixel, the color fetched from the palette else if(color_format == 4) @@ -1935,7 +1935,7 @@ bitmap.setPixel(x, y, color); } - m_painter->drawImageObject(propList, bitmap.getDIB()); + m_painter->drawGraphicObject(propList, bitmap.getDIB()); } // format 5: greyscale of 16 bits else if (color_format == 5) @@ -1949,7 +1949,7 @@ bitmap.setPixel(x, y, color); } - m_painter->drawImageObject(propList, bitmap.getDIB()); + m_painter->drawGraphicObject(propList, bitmap.getDIB()); } // format 6: RGB, with 5 bits per colour else if (color_format == 6) @@ -1963,7 +1963,7 @@ bitmap.setPixel(x, y, color); } - m_painter->drawImageObject(propList, bitmap.getDIB()); + m_painter->drawGraphicObject(propList, bitmap.getDIB()); } // format 7: else if (color_format == 7) @@ -1977,7 +1977,7 @@ bitmap.setPixel(x, y, color); } - m_painter->drawImageObject(propList, bitmap.getDIB()); + m_painter->drawGraphicObject(propList, bitmap.getDIB()); } else if (color_format == 8) { @@ -1989,7 +1989,7 @@ bitmap.setPixel(x, y, color); } - m_painter->drawImageObject(propList, bitmap.getDIB()); + m_painter->drawGraphicObject(propList, bitmap.getDIB()); } else if (color_format == 9) { @@ -2001,7 +2001,7 @@ bitmap.setPixel(x, y, color); } - m_painter->drawImageObject(propList, bitmap.getDIB()); + m_painter->drawGraphicObject(propList, bitmap.getDIB()); } else if (color_format == 12) { @@ -2014,7 +2014,7 @@ bitmap.setPixel(x, y, color); } - m_painter->drawImageObject(propList, bitmap.getDIB()); + m_painter->drawGraphicObject(propList, bitmap.getDIB()); } } @@ -2148,7 +2148,7 @@ #endif - m_painter->drawImageObject(propList, binaryData); + m_painter->drawGraphicObject(propList, binaryData); m_binaryData.objectIndex++; } Index: WPG1Parser.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPG1Parser.cpp,v retrieving revision 1.62 retrieving revision 1.63 diff -u -d -r1.62 -r1.63 --- WPG1Parser.cpp 7 Sep 2009 12:09:32 -0000 1.62 +++ WPG1Parser.cpp 8 Jun 2010 13:47:08 -0000 1.63 @@ -179,8 +179,8 @@ { 0x09, "Ellipse", &WPG1Parser::handleEllipse }, { 0x0a, "Reserved", 0 }, { 0x0b, "Bitmap (Type 1)", &WPG1Parser::handleBitmapTypeOne }, - { 0x0c, "Graphics Text (Type 1)", 0 }, - { 0x0d, "Grephics Text Attributes", 0 }, + { 0x0c, "Graphics Text (Type 1)", &WPG1Parser::handleGraphicsTextTypeOne }, + { 0x0d, "Graphics Text Attributes", &WPG1Parser::handleGraphicsTextAttributes }, { 0x0e, "Colormap", &WPG1Parser::handleColormap }, { 0x0f, "Start WPG", &WPG1Parser::handleStartWPG }, { 0x10, "End WPG", &WPG1Parser::handleEndWPG }, @@ -191,7 +191,7 @@ { 0x15, "Start Figure", 0 }, { 0x16, "Start Chart", 0 }, { 0x17, "Planperfect Data", 0 }, - { 0x18, "Graphics Text (Type 2)", 0 }, + { 0x18, "Graphics Text (Type 2)", &WPG1Parser::handleGraphicsTextTypeTwo }, { 0x19, "Start WPG (Type 2)", 0 }, { 0x1a, "Graphics Text (Type 3)", 0 }, { 0x1b, "Postscript Data (Type 2)", &WPG1Parser::handlePostscriptTypeTwo }, @@ -391,7 +391,7 @@ point.insert("svg:y", (double)(m_height-ey)/1200.0); points.append(point); - m_painter->setStyle(m_gradient, m_style); + m_painter->setStyle(m_style, m_gradient); m_painter->drawPolyline(points); @@ -418,7 +418,7 @@ points.append(point); } - m_painter->setStyle(::WPXPropertyListVector(), m_style); + m_painter->setStyle(m_style, ::WPXPropertyListVector()); m_painter->drawPolyline(points); @@ -441,7 +441,7 @@ propList.insert("svg:width", (double)w/1200.0); propList.insert("svg:height",(double)h/1200.0); - m_painter->setStyle(m_gradient, m_style); + m_painter->setStyle(m_style, m_gradient); m_painter->drawRectangle(propList); @@ -469,7 +469,7 @@ points.append(point); } - m_painter->setStyle(m_gradient, m_style); + m_painter->setStyle(m_style, m_gradient); m_painter->drawPolygon(points); @@ -493,7 +493,7 @@ int endAngle = readS16(); unsigned flags = readU16(); #endif - m_painter->setStyle(m_gradient, m_style); + m_painter->setStyle(m_style, m_gradient); m_painter->drawEllipse(propList); @@ -541,7 +541,7 @@ } - m_painter->setStyle(m_gradient, m_style); + m_painter->setStyle(m_style, m_gradient); m_painter->drawPath(path); @@ -734,7 +734,7 @@ if (buffer.size() && buffer.size() == (unsigned long)((width*depth + 7)/8)*height) { fillPixels(bitmap, &buffer[0], width, height, depth); - m_painter->drawImageObject(propList, bitmap.getDIB()); + m_painter->drawGraphicObject(propList, bitmap.getDIB()); } } @@ -803,7 +803,7 @@ if (buffer.size() && buffer.size() == (unsigned long)((width*depth + 7)/8)*height) { fillPixels(bitmap, &buffer[0], width, height, depth); - m_painter->drawImageObject(propList, bitmap.getDIB()); + m_painter->drawGraphicObject(propList, bitmap.getDIB()); } } @@ -829,7 +829,7 @@ while (!m_input->atEOS() && m_input->tell() <= m_recordEnd) data.append((char)readU8()); if (data.size()) - m_painter->drawImageObject(propList, data); + m_painter->drawGraphicObject(propList, data); } void WPG1Parser::handlePostscriptTypeTwo() @@ -880,7 +880,69 @@ while (!m_input->atEOS() && m_input->tell() <= m_recordEnd) data.append((char)readU8()); if (data.size()) - m_painter->drawImageObject(propList, data); + m_painter->drawGraphicObject(propList, data); +} + +void WPG1Parser::handleGraphicsTextAttributes() +{ + if (!m_graphicsStarted) + return; +} + +void WPG1Parser::handleGraphicsTextTypeOne() +{ + if (!m_graphicsStarted) + return; + unsigned short textLength = readU16(); + int x = readS16(); + int y = readS16(); + WPXString textString; + for (unsigned short i=0; i < textLength; i++) + textString.append(readU8()); + + WPG_DEBUG_MSG(("Graphics Text (Type 1)\n")); + WPG_DEBUG_MSG((" Length of String: %d\n", textLength)); + WPG_DEBUG_MSG((" String position: %d,%d\n", x, y)); + WPG_DEBUG_MSG((" String: %s\n", textString.cstr())); + + y = m_height - y; + + ::WPXPropertyList propList; + + propList.insert("svg:x", (double)x/1200.0); + propList.insert("svg:y", (double)(y)/1200.0); + + m_painter->drawTextLine(propList, textString); +} + +void WPG1Parser::handleGraphicsTextTypeTwo() +{ + if (!m_graphicsStarted) + return; +#ifdef DEBUG + int sizeEquivalentData = readU32(); + short rotationAngle = readS16(); + unsigned short textLength = readU16(); + int x1 = readS16(); + int y1 = readS16(); + int x2 = readS16(); + int y2 = readS16(); + int sx = readS16(); + int sy = readS16(); + unsigned char type = readU8(); + WPXBinaryData textString; + for (unsigned short i=0; i < textLength; i++) + textString.append(readU8()); + + WPG_DEBUG_MSG(("Graphics Text (Type 1)\n")); + WPG_DEBUG_MSG((" Size of Equivalent data: %d\n", sizeEquivalentData)); + WPG_DEBUG_MSG((" Rotation Angle: %d\n", rotationAngle)); + WPG_DEBUG_MSG((" Length of String: %d\n", textLength)); + WPG_DEBUG_MSG((" Start position: %d,%d\n", x1, y1)); + WPG_DEBUG_MSG((" End position: %d,%d\n", x2, y2)); + WPG_DEBUG_MSG((" Scale factor: %d,%d\n", sx, sy)); + WPG_DEBUG_MSG((" Type: %d\n", type)); +#endif } void WPG1Parser::resetPalette() |