From: Fridrich S. <str...@us...> - 2008-11-28 15:09:57
|
Update of /cvsroot/libwpg/perfectspot/src In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv9173/src Modified Files: CMakeLists.txt renderer.cpp Log Message: Branching off the stable branch STABLE-0-1-0 and porting perfectspot to the recent libwpg changes Index: CMakeLists.txt =================================================================== RCS file: /cvsroot/libwpg/perfectspot/src/CMakeLists.txt,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- CMakeLists.txt 11 Oct 2007 11:44:17 -0000 1.8 +++ CMakeLists.txt 28 Nov 2008 15:09:15 -0000 1.9 @@ -1,3 +1,6 @@ +if(COMMAND cmake_policy) +cmake_policy(SET CMP0005 OLD) +endif(COMMAND cmake_policy) # note: change this BEFORE making a release !! ADD_DEFINITIONS(-DPERFECTSPOT_VERSION=\"CVS\" ) @@ -31,7 +34,7 @@ qt4_add_resources(perfectspot_RESOURCES_SOURCES ${perfectspot_RESOURCES}) add_executable(perfectspot ${perfectspot_SOURCES} ${perfectspot_RESOURCES_SOURCES}) -target_link_libraries(perfectspot ${QT_LIBRARIES} ${LIBWPG_LIBRARIES} ${LIBWPG_STREAM_LIBRARIES}) +target_link_libraries(perfectspot ${QT_LIBRARIES} ${LIBWPG_LIBRARIES} ${LIBWPD_LIBRARIES} ${LIBWPD_STREAM_LIBRARIES}) install(TARGETS ${PROGNAME} DESTINATION bin) install(FILES perfectspot.png DESTINATION share/pixmaps) Index: renderer.cpp =================================================================== RCS file: /cvsroot/libwpg/perfectspot/src/renderer.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- renderer.cpp 12 Jul 2008 00:07:05 -0000 1.14 +++ renderer.cpp 28 Nov 2008 15:09:15 -0000 1.15 @@ -27,7 +27,7 @@ #include <libwpg/libwpg.h> -#include <libwpg/WPGStreamImplementation.h> +#include <libwpd-stream/libwpd-stream.h> #include <QtGui> #include <QFile> @@ -36,7 +36,6 @@ #include "odg/femtozip.hxx" #include "odg/FileOutputHandler.hxx" - using namespace libwpg; class Painter : public WPGPaintInterface @@ -45,30 +44,29 @@ double width, height; Painter(QPainter* target); - void startGraphics(double imageWidth, double imageHeight); - void endGraphics(); - void startLayer(unsigned int id); - void endLayer(unsigned int id); + void startGraphics(const ::WPXPropertyList &propList); + void endGraphics(); + void startLayer(const ::WPXPropertyList& propList); + void endLayer(); + void startEmbeddedGraphics(const ::WPXPropertyList& /*propList*/) {} + void endEmbeddedGraphics() {} - void setPen(const WPGPen& pen); - void setBrush(const WPGBrush& brush); - void setFillRule(FillRule rule); + void setStyle(const libwpg::WPGPen& pen, const libwpg::WPGBrush& brush, const ::WPXPropertyList &propList); - 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); - void drawBitmap(const WPGBitmap& bitmap); - void drawImageObject(const libwpg::WPGBinaryData& binaryData) { /* TODO: how does one do this one in QT ? :-) */ } + 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; - FillRule m_fillRule; }; -Painter::Painter(QPainter* t): m_target(t), m_fillRule(AlternatingFill) +Painter::Painter(QPainter* t): m_target(t) { width = 100; height = 100; @@ -76,16 +74,16 @@ m_zoomY = 1.0; } -void Painter::startGraphics(double w, double h) +void Painter::startGraphics(const ::WPXPropertyList &propList) { - width = w; - height = h; + width = propList["svg:width"]->getFloat(); + height = propList["svg:height"]->getFloat(); - m_zoomX = m_target->viewport().width() / w; - m_zoomY = m_target->viewport().height() / h; + m_zoomX = m_target->viewport().width() / width; + m_zoomY = m_target->viewport().height() / height; } -void Painter::setPen(const WPGPen& pen) +void Painter::setStyle(const libwpg::WPGPen& pen, const libwpg::WPGBrush& brush, const ::WPXPropertyList &propList) { QPen ppen(Qt::SolidLine); @@ -93,8 +91,8 @@ if(pen.width == 0) ppen.setStyle(Qt::NoPen); - QColor c(pen.foreColor.red, pen.foreColor.green, pen.foreColor.blue); - ppen.setColor(c); + QColor cPen(pen.foreColor.red, pen.foreColor.green, pen.foreColor.blue); + ppen.setColor(cPen); if(!pen.solid) { @@ -105,14 +103,11 @@ } m_target->setPen(ppen); -} -void Painter::setBrush(const WPGBrush& brush) -{ QBrush pbrush(Qt::SolidPattern); - QColor c(brush.foreColor.red, brush.foreColor.green, brush.foreColor.blue); - pbrush.setColor(c); + QColor cBrush(brush.foreColor.red, brush.foreColor.green, brush.foreColor.blue); + pbrush.setColor(cBrush); if(brush.style == WPGBrush::NoBrush) pbrush.setStyle(Qt::NoBrush); @@ -144,17 +139,12 @@ m_target->setBrush(pbrush); } -void Painter::setFillRule(FillRule rule) -{ - m_fillRule = rule; -} - -void Painter::startLayer(unsigned int id) +void Painter::startLayer(const ::WPXPropertyList& /* propList */) { // nothing to do } -void Painter::endLayer(unsigned int) +void Painter::endLayer() { // nothing to do } @@ -164,76 +154,72 @@ // nothing to do } -void Painter::drawRectangle(const WPGRect& rect, double rx, double ry) +void Painter::drawRectangle(const ::WPXPropertyList &propList) { - double roundx = rx * 200 / rect.width(); - double roundy = ry * 200 / rect.height(); - m_target->drawRoundRect((int)(m_zoomX*rect.x1), (int)(m_zoomY*rect.y1), (int)(m_zoomX*rect.width()), (int)(m_zoomY*rect.height()), (int)roundx, (int)roundy); + m_target->drawRoundRect((int)(m_zoomX*propList["svg:x"]->getFloat()), (int)(m_zoomY*propList["svg:y"]->getFloat()), + (int)(m_zoomX*propList["svg:width"]->getFloat()), (int)(m_zoomY*propList["svg:height"]->getFloat()), + (int)(propList["svg:rx"]->getFloat() * 200 / propList["svg:width"]->getFloat()), + (int)(propList["svg:ry"]->getFloat() * 200 / propList["svg:height"]->getFloat())); } -void Painter::drawEllipse(const WPGPoint& center, double rx, double ry) +void Painter::drawEllipse(const ::WPXPropertyList &propList) { - m_target->drawEllipse((int)(m_zoomX*(center.x - rx)), (int)(m_zoomY*(center.y - ry)), (int)(2*m_zoomX*rx), (int)(2*m_zoomY*ry)); + m_target->drawEllipse((int)(m_zoomX*(propList["svg:cx"]->getFloat() - propList["svg:rx"]->getFloat())), + (int)(m_zoomY*(propList["svg:cy"]->getFloat() - propList["svg:ry"]->getFloat())), + (int)(2*m_zoomX*propList["svg:rx"]->getFloat()), (int)(2*m_zoomY*propList["svg:ry"]->getFloat())); } -void Painter::drawPolygon(const WPGPointArray& vertices) +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].x, m_zoomY*vertices[i].y); + points[i] = QPointF(m_zoomX*vertices[i]["svg:x"]->getFloat(), m_zoomY*vertices[i]["svg:y"]->getFloat()); m_target->drawPolygon(points, vertices.count()); delete [] points; } -void Painter::drawPath(const WPGPath& path) +void Painter::drawPolyline(const ::WPXPropertyListVector& vertices) { - QPainterPath p; - for(unsigned i = 0; i < path.count(); i++) - { - WPGPathElement element = path.element(i); - WPGPoint point = element.point; - switch(element.type) - { - case WPGPathElement::MoveToElement: - p.moveTo(m_zoomX*point.x, m_zoomY*point.y); - break; - - case WPGPathElement::LineToElement: - p.lineTo(m_zoomX*point.x, m_zoomY*point.y); - break; + QPointF* points = new QPointF[vertices.count()]; + for(unsigned i = 0; i < vertices.count(); i++) + points[i] = QPointF(m_zoomX*vertices[i]["svg:x"]->getFloat(), m_zoomY*vertices[i]["svg:y"]->getFloat()); - case WPGPathElement::CurveToElement: - p.cubicTo(m_zoomX*element.extra1.x, m_zoomY*element.extra1.y, - m_zoomX*element.extra2.x, m_zoomY*element.extra2.y, - m_zoomX*point.x, m_zoomY*point.y); - break; + m_target->drawPolyline(points, vertices.count()); + delete [] points; +} - default: - break; +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"]->getFloat(), m_zoomY*path[i]["svg:y"]->getFloat()); + else if (path[i]["libwpg:path-action"]->getStr() == "L") + p.lineTo(m_zoomX*path[i]["svg:x"]->getFloat(), m_zoomY*path[i]["svg:y"]->getFloat()); + else if (path[i]["libwpg:path-action"]->getStr() == "C") + p.cubicTo(m_zoomX*path[i]["svg:x1"]->getFloat(), m_zoomY*path[i]["svg:y1"]->getFloat(), + m_zoomX*path[i]["svg:x2"]->getFloat(), m_zoomY*path[i]["svg:y2"]->getFloat(), + m_zoomX*path[i]["svg:x"]->getFloat(), m_zoomY*path[i]["svg:y"]->getFloat()); + else if (path[i]["libwpg:path-action"]->getStr() == "Z" && i == path.count()) + p.closeSubpath(); } - } - - m_target->drawPath(p); + m_target->drawPath(p); } -void Painter::drawBitmap(const WPGBitmap& bitmap) +void Painter::drawImageObject(const ::WPXPropertyList &propList, const ::WPXBinaryData& binaryData) { - QImage image; - image = QImage(bitmap.width(), bitmap.height(), QImage::Format_RGB32); - for(int x = 0; x < bitmap.width(); x++) - for(int y = 0; y < bitmap.height(); y++) - { - libwpg::WPGColor color = bitmap.pixel(x, y); - image.setPixel(x, y, qRgb(color.red, color.green, color.blue)); - } - + QImage image = QImage::fromData(binaryData.getDataBuffer(), binaryData.size()); + if (image.isNull()) + return; QRectF target; - target.setTopLeft( QPointF(m_zoomX*bitmap.rect.x1, m_zoomY*bitmap.rect.y1) ); - target.setBottomRight( QPointF(m_zoomX*bitmap.rect.x2, m_zoomY*bitmap.rect.y2) ); + target.setTopLeft( QPointF(m_zoomX*propList["svg:x"]->getFloat(), m_zoomY*propList["svg:y"]->getFloat()) ); + target.setBottomRight( QPointF(m_zoomX*(propList["svg:x"]->getFloat() + propList["svg:width"]->getFloat()), + m_zoomY*(propList["svg:y"]->getFloat() + propList["svg:height"]->getFloat())) ); - m_target->drawImage(target, image, QRectF(0, 0, bitmap.width(), bitmap.height()) ); + m_target->drawImage(target, image); } class RendererPrivate @@ -253,12 +239,12 @@ if(file.open(QFile::ReadOnly)) { QByteArray buf = file.readAll(); - const char* data = buf.data(); + const unsigned char* data = (const unsigned char *)buf.data(); int size = buf.size(); - d->stream = new WPGMemoryStream(data, size); + d->stream = new ::WPXStringStream(data, size); if (d->stream && d->stream->isOLEStream()) { - WPXInputStream *tempStream = d->stream->getDocumentOLEStream(); + WPXInputStream *tempStream = d->stream->getDocumentOLEStream("PerfectOffice_MAIN"); if (tempStream) { delete d->stream; @@ -294,7 +280,7 @@ bool Renderer::renderSVG(const QString& outputFile) { - libwpg::WPGString output; + ::WPXString output; if (!libwpg::WPGraphics::generateSVG(d->stream, output)) return false; @@ -340,7 +326,6 @@ zip.createEntry("styles.xml", 0); zip.writeString(tmpStringStream.str().c_str()); zip.closeEntry(); - return true; } |