From: Fridrich S. <str...@us...> - 2010-06-17 10:34:04
|
Update of /cvsroot/libwpg/perfectspot/src In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv11964/src Modified Files: CMakeLists.txt canvas.cpp renderer.cpp Log Message: Adapting perfectspot to recent libwpg and using svg instead of the custom renderer Index: CMakeLists.txt =================================================================== RCS file: /cvsroot/libwpg/perfectspot/src/CMakeLists.txt,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- CMakeLists.txt 5 Dec 2008 18:44:56 -0000 1.11 +++ CMakeLists.txt 17 Jun 2010 10:33:55 -0000 1.12 @@ -35,9 +35,9 @@ add_executable(perfectspot ${perfectspot_SOURCES} ${perfectspot_RESOURCES_SOURCES}) IF (NOT WIN32) -target_link_libraries(perfectspot ${QT_LIBRARIES} ${LIBWPG_LDFLAGS} ${LIBWPD_LDFLAGS} ${LIBWPD_STREAM_LDFLAGS}) +target_link_libraries(perfectspot ${QT_LIBRARIES} ${QT_QTSVG_LIBRARIES} ${LIBWPG_LDFLAGS} ${LIBWPD_LDFLAGS} ${LIBWPD_STREAM_LDFLAGS}) ELSE (NOT WIN32) -target_link_libraries(perfectspot ${QT_LIBRARIES} ${LIBWPG_LDFLAGS} ${LIBWPD_LDFLAGS} ${LIBWPD_STREAM_LDFLAGS} -mwindows) +target_link_libraries(perfectspot ${QT_LIBRARIES} ${LIBWPG_LDFLAGS} ${QT_QTSVG_LIBRARIES} ${LIBWPD_LDFLAGS} ${LIBWPD_STREAM_LDFLAGS} -mwindows) ENDIF (NOT WIN32) install(TARGETS ${PROGNAME} DESTINATION bin) Index: renderer.cpp =================================================================== RCS file: /cvsroot/libwpg/perfectspot/src/renderer.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- renderer.cpp 7 Sep 2009 15:16:52 -0000 1.19 +++ renderer.cpp 17 Jun 2010 10:33:55 -0000 1.20 @@ -32,6 +32,7 @@ #include <QtGui> #include <QFile> +#include <QtSvg> #include "odg/OdgExporter.hxx" #include "odg/femtozip.hxx" @@ -39,192 +40,6 @@ using namespace libwpg; -class Painter : public WPGPaintInterface -{ -public: - double width, height; - Painter(QPainter* target); - - void startGraphics(const ::WPXPropertyList &propList); - void endGraphics(); - void startLayer(const ::WPXPropertyList& propList); - void endLayer(); - void startEmbeddedGraphics(const ::WPXPropertyList& /*propList*/) {} - void endEmbeddedGraphics() {} - - void setStyle(const WPXPropertyListVector& gradient, const ::WPXPropertyList &propList); - - 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); - -private: - QPainter* m_target; - double m_zoomX; - double m_zoomY; -}; - -Painter::Painter(QPainter* t): m_target(t) -{ - width = 100; - height = 100; - m_zoomX = 1.0; - m_zoomY = 1.0; -} - -void Painter::startGraphics(const ::WPXPropertyList &propList) -{ - width = propList["svg:width"]->getDouble(); - height = propList["svg:height"]->getDouble(); - - m_zoomX = m_target->viewport().width() / width; - m_zoomY = m_target->viewport().height() / height; -} - -void Painter::setStyle(const WPXPropertyListVector& gradient, const ::WPXPropertyList &propList) -{ - QPen ppen(Qt::SolidLine); - - if (propList["svg:stroke-width"]) - ppen.setWidth((int)((propList["svg:stroke-width"]->getDouble()) * m_zoomX)); - if(!propList["svg:stroke-width"] || propList["svg:stroke-width"]->getDouble() == 0) - ppen.setStyle(Qt::NoPen); - - if (propList["svg:stroke-color"]) - { - QColor cPen(propList["svg:stroke-color"]->getStr().cstr()); - ppen.setColor(cPen); - } -#if 0 - if(!propList["libwpg:stroke-solid"] || !propList["libwpg:stroke-solid"]->getInt()) - { - QVector<qreal> dashes; - for(unsigned i = 0; i < dashArray.count(); i++) - dashes.append(dashArray.at(i)); - ppen.setDashPattern(dashes); - } -#endif - m_target->setPen(ppen); - - QBrush pbrush(Qt::SolidPattern); - - if (propList["draw:fill-color"]) - { - QColor cBrush(propList["draw:fill-color"]->getStr().cstr()); - pbrush.setColor(cBrush); - } - - if(propList["draw:fill"] && propList["draw:fill"]->getStr() == "none") - pbrush.setStyle(Qt::NoBrush); - - if(propList["draw:fill"] && propList["draw:fill"]->getStr() == "solid") - pbrush.setStyle(Qt::SolidPattern); - - if(propList["draw:fill"] && propList["draw:fill"]->getStr() == "gradient") - { - QLinearGradient pgradient(0, 0, 0, 1); - for(unsigned c = 0; c < gradient.count(); c++) - pgradient.setColorAt(gradient[c]["svg:stop-offset"]->getDouble(), QColor(gradient[c]["svg:stop-color"]->getStr().cstr())); -#if QT_VERSION >= 0x040300 - pgradient.setCoordinateMode(QLinearGradient::ObjectBoundingMode); -#endif - pbrush = QBrush(pgradient); -#if QT_VERSION >= 0x040300 - QMatrix matrix; - matrix.rotate(propList["draw:angle"] ? -propList["draw:angle"]->getDouble() : 0.0); - pbrush.setMatrix(matrix); -#endif - } - - m_target->setBrush(pbrush); -} - -void Painter::startLayer(const ::WPXPropertyList& /* propList */) -{ - // nothing to do -} - -void Painter::endLayer() -{ - // nothing to do -} - -void Painter::endGraphics() -{ - // nothing to do -} - -void Painter::drawRectangle(const ::WPXPropertyList &propList) -{ - m_target->drawRoundRect((int)(m_zoomX*propList["svg:x"]->getDouble()), (int)(m_zoomY*propList["svg:y"]->getDouble()), - (int)(m_zoomX*propList["svg:width"]->getDouble()), (int)(m_zoomY*propList["svg:height"]->getDouble()), - (int)(propList["svg:rx"]->getDouble() * 200 / propList["svg:width"]->getDouble()), - (int)(propList["svg:ry"]->getDouble() * 200 / propList["svg:height"]->getDouble())); -} - -void Painter::drawEllipse(const ::WPXPropertyList &propList) -{ - m_target->drawEllipse((int)(m_zoomX*(propList["svg:cx"]->getDouble() - propList["svg:rx"]->getDouble())), - (int)(m_zoomY*(propList["svg:cy"]->getDouble() - propList["svg:ry"]->getDouble())), - (int)(2*m_zoomX*propList["svg:rx"]->getDouble()), (int)(2*m_zoomY*propList["svg:ry"]->getDouble())); -} - -void Painter::drawPolygon(const ::WPXPropertyListVector& vertices) -{ - QPointF* points = new QPointF[vertices.count()]; - for(unsigned i = 0; i < vertices.count(); i++) - points[i] = QPointF(m_zoomX*vertices[i]["svg:x"]->getDouble(), m_zoomY*vertices[i]["svg:y"]->getDouble()); - - m_target->drawPolygon(points, vertices.count()); - delete [] points; -} - -void Painter::drawPolyline(const ::WPXPropertyListVector& vertices) -{ - QPointF* points = new QPointF[vertices.count()]; - for(unsigned i = 0; i < vertices.count(); i++) - points[i] = QPointF(m_zoomX*vertices[i]["svg:x"]->getDouble(), m_zoomY*vertices[i]["svg:y"]->getDouble()); - - m_target->drawPolyline(points, vertices.count()); - delete [] points; -} - -void Painter::drawPath(const ::WPXPropertyListVector& path) -{ - QPainterPath p; - for(unsigned i = 0; i < path.count(); i++) - { - if (path[i]["libwpg:path-action"]->getStr() == "M") - p.moveTo(m_zoomX*path[i]["svg:x"]->getDouble(), m_zoomY*path[i]["svg:y"]->getDouble()); - else if (path[i]["libwpg:path-action"]->getStr() == "L") - p.lineTo(m_zoomX*path[i]["svg:x"]->getDouble(), m_zoomY*path[i]["svg:y"]->getDouble()); - else if (path[i]["libwpg:path-action"]->getStr() == "C") - p.cubicTo(m_zoomX*path[i]["svg:x1"]->getDouble(), m_zoomY*path[i]["svg:y1"]->getDouble(), - m_zoomX*path[i]["svg:x2"]->getDouble(), m_zoomY*path[i]["svg:y2"]->getDouble(), - m_zoomX*path[i]["svg:x"]->getDouble(), m_zoomY*path[i]["svg:y"]->getDouble()); - else if (path[i]["libwpg:path-action"]->getStr() == "Z" && i == path.count()) - p.closeSubpath(); - } - m_target->drawPath(p); -} - - -void Painter::drawImageObject(const ::WPXPropertyList &propList, const ::WPXBinaryData& binaryData) -{ - QImage image = QImage::fromData(binaryData.getDataBuffer(), binaryData.size()); - if (image.isNull()) - return; - QRectF target; - target.setTopLeft( QPointF(m_zoomX*propList["svg:x"]->getDouble(), m_zoomY*propList["svg:y"]->getDouble()) ); - target.setBottomRight( QPointF(m_zoomX*(propList["svg:x"]->getDouble() + propList["svg:width"]->getDouble()), - m_zoomY*(propList["svg:y"]->getDouble() + propList["svg:height"]->getDouble())) ); - - m_target->drawImage(target, image); -} - class RendererPrivate { public: @@ -258,11 +73,12 @@ // to know the default WPG size QImage buffer(500, 500, QImage::Format_ARGB32); QPainter bufp(&buffer); - Painter painter(&bufp); - WPGraphics::parse(d->stream, &painter); - // and then approximate, from inch to pixel - d->defaultSize = QSize((int)(72*painter.width), (int)(72*painter.height)); + WPXString generatedSVG; + WPGraphics::generateSVG(d->stream, generatedSVG); + QByteArray tempSVG(generatedSVG.cstr()); + QSvgRenderer tmpRenderer(tempSVG, parent); + d->defaultSize = tmpRenderer.defaultSize(); } } @@ -276,8 +92,12 @@ { if(d->stream) { - Painter painter(target); - WPGraphics::parse(d->stream, &painter); + WPXString generatedSVG; + WPGraphics::generateSVG(d->stream, generatedSVG); + QByteArray tempSVG(generatedSVG.cstr()); + + QSvgRenderer tmpRenderer(tempSVG, this); + tmpRenderer.render(target); } } @@ -300,16 +120,16 @@ bool Renderer::renderODG(const QString& outputFile) { - const char* odgfile = outputFile.toLocal8Bit().constData(); const char* mimetype = "application/vnd.oasis.opendocument.graphics"; - const char* manifest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" - "<manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\">" - " <manifest:file-entry manifest:media-type=\"application/vnd.oasis.opendocument.graphics\" manifest:full-path=\"/\"/>" - " <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"content.xml\"/>" - " <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"styles.xml\"/>" - "</manifest:manifest>"; + const char* manifest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\">" + " <manifest:file-entry manifest:media-type=\"application/vnd.oasis.opendocument.graphics\" manifest:version=\"1.0\" manifest:full-path=\"/\"/>" + " <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"content.xml\"/>" + " <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"settings.xml\"/>" + " <manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"styles.xml\"/>" + "</manifest:manifest>"; - FemtoZip zip(odgfile); + FemtoZip zip(outputFile.toLocal8Bit().constData()); zip.createEntry("mimetype", 0); zip.writeString(mimetype); zip.closeEntry(); @@ -319,16 +139,29 @@ zip.closeEntry(); zip.createEntry("content.xml", 0); - std::ostringstream tmpStringStream; - FileOutputHandler tmpHandler(tmpStringStream); - OdgExporter exporter(&tmpHandler); - libwpg::WPGraphics::parse(d->stream, &exporter); - zip.writeString(tmpStringStream.str().c_str()); + std::ostringstream tmpContentStringStream; + FileOutputHandler tmpContentHandler(tmpContentStringStream); + OdgExporter content_exporter(&tmpContentHandler, ODF_CONTENT_XML); + libwpg::WPGraphics::parse(d->stream, &content_exporter); + zip.writeString(tmpContentStringStream.str().c_str()); zip.closeEntry(); zip.createEntry("styles.xml", 0); - zip.writeString(tmpStringStream.str().c_str()); + std::ostringstream tmpStylesStringStream; + FileOutputHandler tmpStylesHandler(tmpStylesStringStream); + OdgExporter styles_exporter(&tmpStylesHandler, ODF_STYLES_XML); + libwpg::WPGraphics::parse(d->stream, &styles_exporter); + zip.writeString(tmpStylesStringStream.str().c_str()); zip.closeEntry(); + + zip.createEntry("settings.xml", 0); + std::ostringstream tmpSettingsStringStream; + FileOutputHandler tmpSettingsHandler(tmpSettingsStringStream); + OdgExporter settings_exporter(&tmpSettingsHandler, ODF_SETTINGS_XML); + libwpg::WPGraphics::parse(d->stream, &settings_exporter); + zip.writeString(tmpSettingsStringStream.str().c_str()); + zip.closeEntry(); + return true; } Index: canvas.cpp =================================================================== RCS file: /cvsroot/libwpg/perfectspot/src/canvas.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- canvas.cpp 11 Jul 2008 22:42:47 -0000 1.24 +++ canvas.cpp 17 Jun 2010 10:33:55 -0000 1.25 @@ -324,7 +324,7 @@ printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(file); //printer.setFullPage(true); - printer.setPageSize(QPrinter::A4); + printer.setPaperSize(renderer->defaultSize(), QPrinter::Point); QPainter painter; painter.begin(&printer); |