From: Ariya H. <ar...@us...> - 2006-06-17 08:13:11
|
Update of /cvsroot/libwpg/libwpg/src/conv/raw In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv14544/src/conv/raw Modified Files: main.cpp Log Message: - important records for WPG2 (pen, brush, lines, curve) - the listener is now PaintInterface, using PostScript-like rendering model - simplified SVG generation (due to the above PaintInterface) - fixed coding style to follow libwpd (tab-indentation, camelcase function names, correct file names, ...) - fixed FSF address - added notices on implementation details (first commit for my Google Summer of Code project) Index: main.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/conv/raw/main.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- main.cpp 1 Feb 2005 17:15:56 -0000 1.7 +++ main.cpp 17 Jun 2006 08:11:53 -0000 1.8 @@ -1,128 +1,130 @@ -/* libwpg - * Copyright (C) 2004 Marc Oude Kotte (ma...@so...) - * Copyright (C) 2005 Fridrich Strba (fri...@bl...) - * - * 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 <gsf/gsf-utils.h> -#include <gsf/gsf-input-stdio.h> -#include <stdio.h> -#include <libwpg.h> - -class RawListener : public WPGListener { -public: - void StartDocument(const float width, const float height) { - printf("RawListener::StartDocument(width: %.4fin, height: %.4fin)\n", width, height); - } - - void Line(const float startX, const float startY, const float endX, const float endY, const float lineWidth, - const unsigned char lineStyle, const RGBColor lineColor) { - printf("RawListener::Line(startX: %.4fin, startY: %.4fin, endX: %.4fin, endY: %.4fin, lineWidth: %.4fin, lineStyle: %,2x, lineColor: #%.2x%.2x%.2x)\n", - startX, startY, endX, endY, lineWidth, lineStyle, lineColor.red, lineColor.green, lineColor.blue); - } - - void Polyline(const std::vector <WPGPoint> &points, const float lineWidth, const unsigned char lineStyle, const RGBColor lineColor) { - printf("RawListener::Polyline(TODO: list of points, lineWidth: %.4fin, lineStyle: %.2x, lineColor: #%.2x%.2x%.2x)\n", - lineWidth, lineStyle, lineColor.red, lineColor.green, lineColor.blue); - } - - void Rectangle(const float startX, const float startY, const float width, const float height, const float lineWidth, - const unsigned char lineStyle, const RGBColor lineColor, const unsigned char fillStyle, const RGBColor fillColor) { - printf("RawListener::Rectangle(startX: %.4fin, startY: %.4fin, width: %.4fin, height: %.4fin, lineWidth: %.4fin, lineStyle: %.2x, lineColor: #%.2x%.2x%.2x, fillStyle: %.2x, fillColor: #%.2x%.2x%.2x)\n", - startX, startY, width, height, lineWidth, lineStyle, lineColor.red, lineColor.green, lineColor.blue, fillStyle, fillColor.red, fillColor.green, fillColor.blue); - } - - void Polygon(const std::vector <WPGPoint> &points, const float lineWidth, const unsigned char lineStyle, const RGBColor lineColor, - const unsigned char fillStyle, const RGBColor fillColor) { - printf("RawListener::Polygon(TODO: list of points, lineWidth: %.4fin, lineStyle: %.2x, lineColor: #%.2x%.2x%.2x, fillStyle: %.2x, fillColor: #%.2x%.2x%.2x)\n", - lineWidth, lineStyle, lineColor.red, lineColor.green, lineColor.blue, fillStyle, fillColor.red, fillColor.green, fillColor.blue); - } - - void Ellipse(const float centerX, const float centerY, const float radiusX, const float radiusY, const unsigned int rotationAngle, - const float lineWidth, const unsigned char lineStyle, const RGBColor lineColor, const unsigned char fillStyle, const RGBColor fillColor) { - printf("RawListener::Ellipse(centerX: %.4fin, centerY: %.4fin, radiusX: %.4fin, radiusY: %.4fin, rotationAngle: %i, lineWidth: %.4fin, lineStyle: %.2x, lineColor: #%.2x%.2x%.2x, fillStyle: %.2x, fillColor: #%.2x%.2x%.2x)\n", - centerX, centerY, radiusX, radiusY, rotationAngle, lineWidth, lineStyle, lineColor.red, lineColor.green, lineColor.blue, fillStyle, fillColor.red, fillColor.green, fillColor.blue); - } - - void EndDocument() { - printf("RawListener::EndDocument()\n"); - } - -}; - -int main(int argc, char *argv[]) -{ - if (argc < 2) - { - printf("usage: wpg2raw <WordPerfect Graphic>\n"); - return -1; - } - gsf_init(); - - GError *err; - GsfInput * input = GSF_INPUT(gsf_input_stdio_new (argv[1], &err)); - if (input == NULL) - { - g_return_val_if_fail (err != NULL, 1); - - g_warning ("'%s' error: %s", argv[1], err->message); - g_error_free (err); - return 1; - } - - WPGraphics * wpg = new(WPGraphics); - - bool isSupportedFormat = wpg->libwpg_file_supported(input); - if (!isSupportedFormat) - { - printf("ERROR: Unsupported file format (unsupported version) or file is encrypted!\n"); - return 1; - } - - RawListener listener; - try - { - wpg->libwpg_parse(input, &listener); - } - catch (WPGInvalidInputException) - { - printf("ERROR: Invalid input given!\n"); - return 1; - } - catch (WPGEndOfFileException) - { - printf("ERROR: Unexpected end of file!\n"); - return 1; - } - catch (...) - { - printf("ERROR: Unknown Error!\n"); - return 1; - } - - gsf_shutdown(); - - if (wpg) - delete wpg; - - return 0; -} +/* libwpg + * Copyright (C) 2006 Ariya Hidayat (ar...@kd...) + * Copyright (C) 2005 Fridrich Strba (fri...@bl...) + * Copyright (C) 2004 Marc Oude Kotte (ma...@so...) + * + * 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 <stdio.h> + +#include "libwpg.h" + +using namespace libwpg; + +class RawPainter : public libwpg::WPGPaintInterface { +public: + RawPainter(); + void startDocument(double imageWidth, double imageHeight); + void setPen(const WPGPen& pen); + void setBrush(const WPGBrush& brush); + void drawPolyline(const WPGPointArray& vertices); + void drawCurve(const WPGPointArray& vertices, const WPGPointArray& controlPoints); + void drawRectangle(const WPGRect& rect, double rx, double ry); + void drawEllipse(const WPGPoint& center, double rx, double ry); + void startLayer(unsigned int); + void endLayer(unsigned int); + void endDocument(); +}; + +RawPainter::RawPainter(): libwpg::WPGPaintInterface() +{ +} + +void RawPainter::startDocument(double width, double height) +{ + printf("RawPainter::startDocument(width: %.4fin, height: %.4fin)\n", width, height); +} + +void RawPainter::setPen(const WPGPen& pen) +{ + printf("RawPainter::setPen\n"); +} + +void RawPainter::setBrush(const WPGBrush& brush) +{ + printf("RawPainter::setBrush\n"); +} + +void RawPainter::drawPolyline(const WPGPointArray& vertices) +{ + printf("RawPainter::drawPolyline %d points\n", vertices.count()); + for(unsigned i = 0; i < vertices.count(); i++) + printf(" (%g %g)\n", vertices[i].x, vertices[i].y); +} + +void RawPainter::drawCurve(const WPGPointArray& vertices, const WPGPointArray& controlPoints) +{ + printf("RawPainter::drawCurve %d vertices\n", vertices.count()); +} + +void RawPainter::drawRectangle(const WPGRect& rect, double rx, double ry) +{ + printf("RawPainter::drawRoundedRectangle "); + printf(" (%g %g)-(%g,%g)", rect.x1, rect.y1, rect.x2, rect.y2); + printf(" Roundndess: %g %g\n", rx, ry); +} + +void RawPainter::drawEllipse(const WPGPoint& center, double rx, double ry) +{ + printf("RawPainter::drawEllipse "); + printf(" Radius: %g %g\n", rx, ry); +} + +void RawPainter::startLayer(unsigned int id) +{ + printf("RawPainter::startLayer %d\n", id); +} + +void RawPainter::endLayer(unsigned int id) +{ + printf("RawPainter::endLayer %d\n", id); +} + +void RawPainter::endDocument() +{ + printf("RawPainter::endDocument\n"); +} + +int main(int argc, char *argv[]) +{ + if (argc < 2) + { + printf("usage: wpg2raw <WordPerfect Graphic>\n"); + return -1; + } + + const char* filename = argv[1]; + WPGFileStream* input = new WPGFileStream(filename); + if (!WPGraphics::isSupported(input)) + { + printf("ERROR: Unsupported file format (unsupported version) or file is encrypted!\n"); + return 1; + } + + RawPainter painter; + WPGraphics::parse(input, &painter); + + delete input; + return 0; +} + |