Update of /cvsroot/libwpg/libwpg/src/lib In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv14544/src/lib Modified Files: Makefile.am WPG1Parser.cpp WPG1Parser.h WPG2Parser.cpp WPG2Parser.h WPGXParser.cpp WPGXParser.h libwpg.h libwpg_utils.h Added Files: WPGBrush.h WPGColor.h WPGHeader.cpp WPGHeader.h WPGPaintInterface.h WPGPen.cpp WPGPen.h WPGPoint.cpp WPGPoint.h WPGRect.h WPGStream.cpp WPGStream.h WPGraphics.cpp WPGraphics.h Removed Files: WPG1Record.cpp WPG1Record.h WPG2Record.cpp WPG2Record.h WPGXRecord.cpp WPGXRecord.h libwpg.cpp libwpg_defaults.h libwpg_exception.h libwpg_utils.cpp wpgheader.cpp wpgheader.h wpglistener.h 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) --- NEW FILE: WPGRect.h --- /* libwpg * Copyright (C) 2006 Ariya Hidayat (ar...@kd...) * * 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." */ #ifndef __WPGRECT_H__ #define __WPGRECT_H__ #include "WPGColor.h" namespace libwpg { class WPGRect { public: double x1; double y1; double x2; double y2; WPGRect(): x1(0.0), y1(0.0), x2(0.0), y2(0.0) {} WPGRect(double xx1, double yy1, double xx2, double yy2): x1(xx1), y1(yy1), x2(xx2), y2(yy2) {} WPGRect(const WPGRect& rect) { x1 = rect.x1; y1 = rect.y1; x2 = rect.x2; y2 = rect.y2; } WPGRect& operator=(const WPGRect& rect) { x1 = rect.x1; y1 = rect.y1; x2 = rect.x2; y2 = rect.y2; return *this; } double width() const { return x2-x1; } double height() const { return y2-y1; } }; } // namespace libwpg #endif // __WPGRECT_H__ Index: WPGXParser.h =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGXParser.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- WPGXParser.h 1 Feb 2005 17:15:58 -0000 1.5 +++ WPGXParser.h 17 Jun 2006 08:11:53 -0000 1.6 @@ -1,49 +1,60 @@ -/* 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." - */ - -#ifndef __WPGXPARSER_H__ -#define __WPGXPARSER_H__ - -#include <gsf/gsf-input.h> -#include "wpglistener.h" -#include "libwpg.h" - -class WPGXParser -{ -public: - WPGXParser(GsfInput *input, WPGListener* listener); - virtual void parse() = 0; - -protected: - std::vector <RGBColor> m_colorPalette; - unsigned char m_lineColorIndex; - unsigned char m_fillColorIndex; - float m_lineWidth; - unsigned char m_lineStyle; - unsigned char m_fillStyle; -}; - - -#endif +/* libwpg + * Copyright (C) 2006 Ariya Hidayat (ar...@kd...) + * 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., 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." + */ + +#ifndef __WPGXPARSER_H__ +#define __WPGXPARSER_H__ + +#include "WPGPaintInterface.h" +#include "WPGStream.h" +#include "WPGColor.h" + +#include <map> + +using namespace libwpg; + +class WPGXParser +{ +public: + WPGXParser(WPGInputStream *input, WPGPaintInterface* painter); + virtual bool parse() = 0; + + unsigned char readU8(); + unsigned short readU16(); + unsigned long readU32(); + char readS8(); + short readS16(); + long readS32(); + unsigned int readVariableLengthInteger(); + +protected: + WPGInputStream* m_input; + WPGPaintInterface* m_painter; + std::map<int,WPGColor> m_colorPalette; + void resetPalette(); +}; + +#endif // __WPGXPARSER_H__ --- libwpg.cpp DELETED --- --- NEW FILE: WPGStream.cpp --- /* libwpg * Copyright (C) 2006 Ariya Hidayat (ar...@kd...) * * 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 "WPGStream.h" #include <fstream> namespace libwpg { class WPGFileStreamPrivate { public: std::fstream file; }; } // namespace libwpg using namespace libwpg; WPGFileStream::WPGFileStream(const char* filename) { d = new WPGFileStreamPrivate; d->file.open( filename, std::ios::binary | std::ios::in ); } WPGFileStream::~WPGFileStream() { delete d; } unsigned char WPGFileStream::getc() { return d->file.get(); } long WPGFileStream::read(long nbytes, char* buffer) { long nread = 0; if(d->file.good()) { long curpos = d->file.tellg(); d->file.read(buffer, nbytes); nread = (long)d->file.tellg() - curpos; } return nread; } long WPGFileStream::tell() { return d->file.good() ? (long)d->file.tellg() : -1L; } void WPGFileStream::seek(long offset) { if(d->file.good()) d->file.seekg(offset); } bool WPGFileStream::atEnd() { return d->file.eof(); } --- wpgheader.h DELETED --- --- NEW FILE: WPGHeader.h --- /* libwpg * Copyright (C) 2006 Ariya Hidayat (ar...@kd...) * 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." */ #ifndef __WPGHEADER_H__ #define __WPGHEADER_H__ #include "WPGStream.h" using namespace libwpg; class WPGHeader { public: WPGHeader(); bool load(WPGInputStream *input); bool isSupported() const; unsigned long startOfDocument() const; int majorVersion() const; private: unsigned char m_identifier[4]; // should always be 0xFF followed by "WPC" unsigned long m_startOfDocument; // index into file unsigned char m_productType; // should always be 1 for WPG files unsigned char m_fileType; // should always be 22 for WPG files unsigned char m_majorVersion; // 2 for WPG 8.0 files unsigned char m_minorVersion; // 0 for WPG 8.0 files unsigned int m_encryptionKey; // 0 when not encrypted unsigned int m_startOfPacketData; // unused, since according to the docs no packets are defined unsigned char m_entryCount; // number of entries in extension unsigned char m_resourceComplete; // resource completeness indicator unsigned int m_encryptionBlockOffset; // encryption block offset unsigned long m_fileSize; // size of the entire wpg file unsigned int m_encryptVersion; // encryption version information }; #endif // WPGHEADER --- NEW FILE: WPGBrush.h --- /* libwpg * Copyright (C) 2006 Ariya Hidayat (ar...@kd...) * * 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." */ #ifndef __WPGBRUSH_H__ #define __WPGBRUSH_H__ #include "WPGColor.h" namespace libwpg { class WPGBrush { public: typedef enum { NoBrush, Solid, Pattern, Gradient } WPGBrushStyle; WPGBrushStyle style; WPGColor foreColor; WPGColor backColor; WPGBrush(): style(NoBrush), foreColor(0,0,0), backColor(0,0,0) {}; WPGBrush(const WPGColor& fore): style(Solid), foreColor(fore), backColor(0,0,0) {}; WPGBrush(const WPGColor& fore, const WPGColor& back): style(Solid), foreColor(fore), backColor(back) {}; WPGBrush(const WPGBrush& brush) { style = brush.style; foreColor = brush.foreColor; backColor = brush.backColor; } WPGBrush& operator=(const WPGBrush& brush) { style = brush.style; foreColor = brush.foreColor; backColor = brush.backColor; return *this; } }; } // namespace libwpg #endif // __WPGBRUSH_H__ --- NEW FILE: WPGStream.h --- /* libwpg * Copyright (C) 2006 Ariya Hidayat (ar...@kd...) * * 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." */ #ifndef __WPGSTREAM_H__ #define __WPGSTREAM_H__ namespace libwpg { class WPGFileStreamPrivate; class WPGInputStream { public: virtual unsigned char getc() = 0; virtual long read(long n, char* buffer) = 0; virtual long tell() = 0; virtual void seek(long offset) = 0; virtual bool atEnd() = 0; }; class WPGFileStream: public WPGInputStream { public: WPGFileStream(const char* filename); ~WPGFileStream(); virtual unsigned char getc(); virtual long read(long n, char* buffer); virtual long tell(); virtual void seek(long offset); virtual bool atEnd(); private: WPGFileStreamPrivate* d; WPGFileStream(const WPGFileStream&); // copy is not allowed WPGFileStream& operator=(const WPGFileStream&); // assignment is not allowed }; } // namespace wpg #endif // __WPGSTREAM_H__ --- NEW FILE: WPGPoint.h --- /* libwpg * Copyright (C) 2006 Ariya Hidayat (ar...@kd...) * * 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." */ #ifndef __WPGPOINT_H__ #define __WPGPOINT_H__ #include "WPGColor.h" namespace libwpg { class WPGPoint { public: double x; double y; WPGPoint(): x(0.0), y(0.0) {} WPGPoint(double xx, double yy): x(xx), y(yy) {} WPGPoint(const WPGPoint& point) { x = point.x; y = point.y; } WPGPoint& operator=(const WPGPoint& point) { x = point.x; y = point.y; return *this; } }; class WPGPointArrayPrivate; class WPGPointArray { public: WPGPointArray(); ~WPGPointArray(); WPGPointArray(const WPGPointArray&); WPGPointArray& operator=(const WPGPointArray&); unsigned count() const; WPGPoint& at(unsigned i); const WPGPoint& at(unsigned i) const; const WPGPoint& operator[](unsigned i) const; void add(const WPGPoint& p); private: WPGPointArrayPrivate *d; }; } // namespace libwpg #endif // __WPGPOINT_H__ --- NEW FILE: WPGraphics.h --- /* libwpg * Copyright (C) 2006 Ariya Hidayat (ar...@kd...) * * 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." */ #ifndef __WPGRAPHICS_H__ #define __WPGRAPHICS_H__ namespace libwpg { class WPGInputStream; class WPGPaintInterface; class WPGraphics { public: static bool isSupported(WPGInputStream* input); static bool parse(WPGInputStream* input, WPGPaintInterface* painter); }; } // namespace libwpg #endif // __WPGRAPHICS_H__ --- NEW FILE: WPGHeader.cpp --- /* libwpg * Copyright (C) 2006 Ariya Hidayat (ar...@kd...) * 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 "WPGHeader.h" #include "libwpg_utils.h" namespace { static inline unsigned short readU16( const void* p ) { const unsigned char* ptr = (const unsigned char*) p; return ptr[0]+(ptr[1]<<8); } static inline unsigned long readU32( const void* p ) { const unsigned char* ptr = (const unsigned char*) p; return ptr[0]+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24); } } using namespace libwpg; WPGHeader::WPGHeader() { // create a sensible default header m_identifier[0] = 0xff; m_identifier[1] = 'W'; m_identifier[2] = 'P'; m_identifier[3] = 'C'; m_productType = 0x01; m_fileType = 0x16; m_encryptionKey = 0x00; m_majorVersion = 0x02; m_minorVersion = 0x00; m_encryptionKey = 0; m_startOfPacketData = 0; m_entryCount = 0; m_resourceComplete = 0; m_encryptionBlockOffset = 0; m_fileSize = 0; m_encryptVersion = 0; } bool WPGHeader::load(WPGInputStream *input) { input->seek(0); unsigned char prefix[26]; long n = input->read(26, (char*)prefix); if(n < 26) return false; m_identifier[0] = prefix[0]; m_identifier[1] = prefix[1]; m_identifier[2] = prefix[2]; m_identifier[3] = prefix[3]; m_startOfDocument = readU32(prefix+4); m_productType = prefix[8]; m_fileType = prefix[9]; m_majorVersion = prefix[10]; m_minorVersion = prefix[11]; m_encryptionKey = readU16(prefix+12); m_startOfPacketData = readU16(prefix+14); WPG_DEBUG_MSG(("Header Identifier = %c%c%c\n", m_identifier[1], m_identifier[2],m_identifier[3])); WPG_DEBUG_MSG(("Product type = 0x%x\n", m_productType)); WPG_DEBUG_MSG(("File type = 0x%x\n", m_fileType)); WPG_DEBUG_MSG(("Major version = 0x%x\n", m_majorVersion)); WPG_DEBUG_MSG(("Minor version = 0x%x\n", m_minorVersion)); WPG_DEBUG_MSG(("Encryption key = 0x%x\n", m_encryptionKey)); return true; } bool WPGHeader::isSupported() const { return ( (m_identifier[0] == 0xFF) && (m_identifier[1] == 'W') && (m_identifier[2] == 'P') && (m_identifier[3] == 'C') && (m_productType == 0x01) && (m_fileType == 0x16) && (m_encryptionKey == 0x00) && // we don't support encryption ((m_majorVersion == 0x02) || (m_majorVersion == 0x01)) && (m_minorVersion == 0x00) ); } unsigned long WPGHeader::startOfDocument() const { return m_startOfDocument; } int WPGHeader::majorVersion() const { return m_majorVersion; } --- WPG2Record.cpp DELETED --- Index: Makefile.am =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/Makefile.am,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Makefile.am 28 Jan 2005 10:23:09 -0000 1.4 +++ Makefile.am 17 Jun 2006 08:11:53 -0000 1.5 @@ -28,9 +28,15 @@ lib_LTLIBRARIES = libwpg-1.la libwpg_1_includedir = $(includedir)/libwpg-1/libwpg libwpg_1_include_HEADERS = \ - wpglistener.h \ - libwpg.h \ - libwpg_exception.h + libwpg.h \ + WPGraphics.h \ + WPGColor.h \ + WPGPen.h \ + WPGBrush.h \ + WPGPoint.h \ + WPGRect.h \ + WPGStream.h \ + WPGPaintInterface.h AM_CXXFLAGS = $(LIBWPG_CXXFLAGS) $(DEBUG_CXXFLAGS) @@ -38,24 +44,24 @@ libwpg_1_la_DEPENDENCIES = @LIBWPG_WIN32_RESOURCE@ libwpg_1_la_LDFLAGS = $(version_info) -export-dynamic $(no_undefined) libwpg_1_la_SOURCES = \ - WPG1Record.cpp \ - WPG2Record.cpp \ - WPGXRecord.cpp \ + WPGraphics.cpp \ + WPGStream.cpp \ + WPGPen.cpp \ + WPGPoint.cpp \ + WPGHeader.cpp \ + WPGXParser.cpp \ WPG1Parser.cpp \ WPG2Parser.cpp \ - WPGXParser.cpp \ - wpgheader.cpp \ - libwpg.cpp \ - libwpg_utils.cpp \ + libwpg.h \ + libwpg_utils.h \ + WPGColor.h \ + WPGPen.h \ + WPGBrush.h \ + WPGHeader.h \ + WPGXParser.h \ WPG1Parser.h \ WPG2Parser.h \ - WPGXParser.h \ - WPG1Record.h \ - WPG2Record.h \ - WPGXRecord.h \ - wpgheader.h \ - libwpg_defaults.h \ - libwpg_utils.h + WPGPaintInterface.h if OS_WIN32 --- NEW FILE: WPGPoint.cpp --- /* libwpg * Copyright (C) 2006 Ariya Hidayat (ar...@kd...) * * 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 "WPGPoint.h" #include <vector> namespace libwpg { class WPGPointArrayPrivate { public: std::vector<WPGPoint> points; }; } using namespace libwpg; WPGPointArray::WPGPointArray() { d = new WPGPointArrayPrivate; } WPGPointArray::~WPGPointArray() { delete d; } WPGPointArray::WPGPointArray(const WPGPointArray& pa) { d = new WPGPointArrayPrivate; d->points = pa.d->points; } WPGPointArray& WPGPointArray::operator=(const WPGPointArray& pa) { d->points = pa.d->points; return *this; } unsigned WPGPointArray::count() const { return d->points.size(); } WPGPoint& WPGPointArray::at(unsigned i) { return d->points[i]; } const WPGPoint& WPGPointArray::at(unsigned i) const { return d->points[i]; } const WPGPoint& WPGPointArray::operator[](unsigned i) const { return d->points[i]; } void WPGPointArray::add(const WPGPoint& p) { d->points.push_back(p); } Index: WPG2Parser.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPG2Parser.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- WPG2Parser.cpp 31 Jan 2005 11:37:47 -0000 1.4 +++ WPG2Parser.cpp 17 Jun 2006 08:11:53 -0000 1.5 @@ -1,6 +1,7 @@ /* libwpg - * Copyright (C) 2004 Marc Oude Kotte (ma...@so...) + * 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 @@ -13,8 +14,9 @@ * 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 + * 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 */ @@ -23,47 +25,811 @@ * Corel Corporation or Corel Corporation Limited." */ -#include <gsf/gsf-input.h> -#include "libwpg.h" -#include "libwpg_defaults.h" -#include "libwpg_utils.h" -#include "WPG2Record.h" #include "WPG2Parser.h" +#include "WPGPaintInterface.h" +#include "libwpg_utils.h" -WPG2Parser::WPG2Parser(GsfInput *input, WPGListener* listener): - WPGXParser(input, listener), - m_exit(false), - m_input(input), - m_listener(listener) +class WPG2Parser::ObjectCharacterization +{ +public: + bool taper; + bool translate; + bool skew; + bool scale; + bool rotate; + bool hasObjectId; + bool editLock; + bool filled; + bool closed; + bool framed; + + unsigned long objectId; + unsigned long lockFlags; + long rotationAngle; + long sxcos; + long sycos; + long kxsin; + long kysin; + long txinteger; + short txfraction; + long tyinteger; + short tyfraction; + long px; + long py; + + ObjectCharacterization(): + taper(false), + translate(false), + skew(false), + scale(false), + rotate(false), + hasObjectId(false), + editLock(false), + objectId(0), + lockFlags(0), + filled(false), + closed(false), + framed(true), + rotationAngle(0), + sxcos(0), + sycos(0), + kxsin(0), + kysin(0), + txinteger(0), + txfraction(0), + tyinteger(0), + tyfraction(0), + px(0), + py(0) + {} +}; + + +WPG2Parser::WPG2Parser(WPGInputStream *input, WPGPaintInterface* painter): + WPGXParser(input, painter), + m_success(true), m_exit(false), + m_xres(1200), m_yres(1200), + m_xofs(0), m_yofs(0), + m_width(0), m_height(0), + m_doublePrecision(false), + m_layerOpened(false), m_layerId(0) { } -void WPG2Parser::parse() +bool WPG2Parser::parse() { - WPG_DEBUG_MSG(("input: %p, listener: %p\n", m_input, m_listener)); + typedef void (WPG2Parser::*Method)(); - // start mainloop - while (!gsf_input_eof(m_input) && !m_exit) { - // create record from stream - WPG2RecordHeader record(m_input); + struct RecordHandler + { + int type; + const char *name; + Method handler; + }; - // check for record type - unsigned int nextPosition = gsf_input_tell(m_input) + record.GetLength(); - switch (record.GetType()) { - case 0x01: // Start WPG - WPG_DEBUG_MSG(("Start WPG record: class=%d, type=%d, extension=%d, length=%d\n", record.GetClass(), record.GetType(), record.GetExtension(), record.GetLength())); - m_listener->StartDocument(0.0f, 0.0f); - break; - case 0x02: // End WPG - WPG_DEBUG_MSG(("End WPG record: class=%d, type=%d, extension=%d, length=%d\n", record.GetClass(), record.GetType(), record.GetExtension(), record.GetLength())); - m_listener->EndDocument(); - m_exit=true; // Exit always after the "End WPG" record. Even though file may contain garbage after. - break; - default: - WPG_DEBUG_MSG(("unsupported record: class=%d, type=%d, extension=%d, length=%d\n", record.GetClass(), record.GetType(), record.GetExtension(), record.GetLength())); - break; + static const struct RecordHandler handlers[] = + { + { 0x01, "Start WPG", &WPG2Parser::handleStartWPG }, + { 0x02, "End WPG", &WPG2Parser::handleEndWPG }, + { 0x03, "Form Settings", 0 }, // ignored + { 0x04, "Ruler Settings", 0 }, // ignored + { 0x05, "Grid Settings", 0 }, // ignored + { 0x06, "Layer", &WPG2Parser::handleLayer }, + { 0x08, "Pen Style Definition", &WPG2Parser::handlePenStyleDefinition }, + { 0x09, "Pattern Definition", 0 }, + { 0x0a, "Comment", 0 }, // ignored + { 0x0b, "Color Transfer", 0 }, + { 0x0c, "Color Palette", &WPG2Parser::handleColorPalette }, + { 0x0d, "DP Color Palette", &WPG2Parser::handleDPColorPalette }, + { 0x0e, "Bitmap Data", 0 }, + { 0x0f, "Text Data", 0 }, + { 0x10, "Chart Style", 0 }, // ignored + { 0x11, "Chart Data", 0 }, // ignored + { 0x12, "Object Image", 0 }, + { 0x15, "Polyline", &WPG2Parser::handlePolyline }, + { 0x16, "Polyspline", 0 }, + { 0x17, "Polycurve", &WPG2Parser::handlePolycurve }, + { 0x18, "Rectangle", &WPG2Parser::handleRectangle }, + { 0x19, "Arc", &WPG2Parser::handleArc }, + { 0x1a, "Compound Polygon", 0 }, + { 0x1b, "Bitmap", 0 }, + { 0x1c, "Text Line", 0 }, + { 0x1d, "Text Block", 0 }, + { 0x1e, "Text Path", 0 }, + { 0x1f, "Chart", 0 }, + { 0x20, "Group", 0 }, + { 0x21, "Object Capsule", 0 }, + { 0x22, "Font Settings", 0 }, + { 0x25, "Pen Fore Color", &WPG2Parser::handlePenForeColor }, + { 0x26, "DP Pen Fore Color", &WPG2Parser::handleDPPenForeColor }, + { 0x27, "Pen Back Color", &WPG2Parser::handlePenBackColor }, + { 0x28, "DP Pen Back Color", &WPG2Parser::handleDPPenBackColor }, + { 0x29, "Pen Style", &WPG2Parser::handlePenStyle }, + { 0x2a, "Pen Pattern", 0 }, + { 0x2b, "Pen Size", &WPG2Parser::handlePenSize }, + { 0x2c, "DP Pen Size", &WPG2Parser::handleDPPenSize }, + { 0x2d, "Line Cap", 0 }, + { 0x2e, "Line Join", 0 }, + { 0x2f, "Brush Gradient", 0 }, + { 0x30, "DP Brush Gradient", 0 }, + { 0x31, "Brush Fore Color", &WPG2Parser::handleBrushForeColor }, + { 0x32, "DP Brush Fore Color", &WPG2Parser::handleDPBrushForeColor }, + { 0x33, "Brush Back Color", &WPG2Parser::handleBrushBackColor }, + { 0x34, "DP Brush Back Color", &WPG2Parser::handleDPBrushBackColor }, + { 0x35, "Brush Pattern", &WPG2Parser::handleBrushPattern }, + { 0x36, "Horizontal Line", 0 }, + { 0x37, "Vertical Line", 0 }, + { 0x38, "Poster Settings", 0 }, + { 0x39, "Image State", 0 }, + { 0x3a, "Envelope Definition", 0 }, + { 0x3b, "Envelope", 0 }, + { 0x3c, "Texture Definition", 0 }, + { 0x3d, "Brush Texture", 0 }, + { 0x3e, "Texture Alignment", 0 }, + { 0x3f, "Pen Texture ", 0 }, + { 0x00, 0, 0 } // end marker + }; + + // initialization + m_success = true; + m_exit = false; + m_xres = m_yres = 1200; + m_doublePrecision = false; + m_layerOpened = false; + + // default style + m_pen.foreColor = WPGColor(0,0,0); + m_pen.backColor = WPGColor(0,0,0); + m_pen.width = 0.001; + m_pen.height = 0.001; + m_pen.solid = true; + m_pen.dashArray = WPGDashArray(); + m_brush.foreColor = WPGColor(0,0,0); + m_brush.backColor = WPGColor(0,0,0); + + while(!m_input->atEnd()) + { + long recordPos = m_input->tell(); + int recordClass = readU8(); + int recordType = readU8(); + int extension = readVariableLengthInteger(); + int length = readVariableLengthInteger(); + long nextPos = m_input->tell() + length; + + // search function to handler this record + int index = -1; + for(int i = 0; (index < 0) && handlers[i].name; i++) + if(handlers[i].type == recordType) + index = i; + + WPG_DEBUG_MSG(("\n")); + if(index < 0) + WPG_DEBUG_MSG(("Unknown record type 0x%02x at %d size %d\n", + recordType, recordPos, length)); + else + { + Method recordHandler = handlers[index].handler; + if(!recordHandler) + WPG_DEBUG_MSG(("Record '%s' (ignored) type 0x%02x at %d size %d\n", + handlers[index].name, recordType, recordPos, length)); + else + { + WPG_DEBUG_MSG(("Record '%s' type 0x%02x at %d size %d\n", + handlers[index].name, recordType, recordPos, length)); + + // invoke the handler for this record + (this->*recordHandler)(); + } } - gsf_input_seek(m_input, nextPosition, G_SEEK_SET); + //if(m_input->tell() > nextPos) + { + //WPG_DEBUG_MSG(("Record 0x%x consumes more bytes than necessary!\n", recordType)); + WPG_DEBUG_MSG(("Current stream position: %d\n", m_input->tell())); + } + + if(m_exit) break; + + m_input->seek(nextPos); + } + + return m_success; +} + +static const char* describePrecision(unsigned char precision) +{ + const char* result = "Unknown"; + switch(precision) + { + case 0: result = "single"; break; + case 1: result = "double"; break; + default: break; + } + return result; +} + +static const char* describeGradient(unsigned char gradientType) +{ + const char* result = "Unknown"; + switch(gradientType) + { + case 0: result = "None"; break; + case 1: result = "Linear"; break; + case 2: result = "Polygonal"; break; + case 3: result = "Concentric Circles"; break; + case 4: result = "Convergent Circles"; break; + case 5: result = "Concentric Ellipses"; break; + case 6: result = "Convergent Ellipses"; break; + case 7: result = "Concentric Squares"; break; + case 8: result = "Convergent Squares"; break; + case 9: result = "Concentric Rectangles"; break; + case 10: result = "Convergent Rectangles"; break; + default: break; + } + return result; +} + +#define TO_DOUBLE(x) ( (m_doublePrecision) ? ((double)(x)/65536.0) : (double)(x) ) +#define TRANSFORM_XY(x,y) { (x)-= m_xofs; (y)-= m_yofs; (y)=m_height-(y); } + +void WPG2Parser::handleStartWPG() +{ + unsigned int horizontalUnit = readU16(); + unsigned int verticalUnit = readU16(); + unsigned char precision = readU8(); + + // sanity check + m_xres = horizontalUnit; + m_yres = verticalUnit; + if((horizontalUnit==0) || (verticalUnit==0)) + { + m_xres = m_yres = 1200; + WPG_DEBUG_MSG(("Warning ! Insane unit of measure")); + } + + // danger if we do not recognize the precision code + if(precision != 0) + if(precision != 1) + { + m_success = false; + m_exit = true; + return; + } + m_doublePrecision = (precision == 1); + + unsigned long viewportX1 = (m_doublePrecision) ? readU32() : readU16(); + unsigned long viewportY1 = (m_doublePrecision) ? readU32() : readU16(); + unsigned long viewportX2 = (m_doublePrecision) ? readU32() : readU16(); + unsigned long viewportY2 = (m_doublePrecision) ? readU32() : readU16(); + + unsigned long imageX1 = (m_doublePrecision) ? readU32() : readU16(); + unsigned long imageY1 = (m_doublePrecision) ? readU32() : readU16(); + unsigned long imageX2 = (m_doublePrecision) ? readU32() : readU16(); + unsigned long imageY2 = (m_doublePrecision) ? readU32() : readU16(); + + // used to adjust coordinates + m_xofs = imageX1; + m_yofs = imageY1; + m_width = imageX2-imageX1; + m_height = imageY2-imageY1; + + WPG_DEBUG_MSG(("StartWPG\n")); + WPG_DEBUG_MSG((" Horizontal unit of measure : %d pixels/inch\n", horizontalUnit)); + WPG_DEBUG_MSG((" Vertical unit of measure : %d pixels/inch\n", verticalUnit)); + WPG_DEBUG_MSG((" Data precision : %d (%s)\n", precision, describePrecision(precision))); + WPG_DEBUG_MSG((" Viewport X1 : %d\n", viewportX1)); + WPG_DEBUG_MSG((" Viewport Y1 : %d\n", viewportY1)); + WPG_DEBUG_MSG((" Viewport X2 : %d\n", viewportX2)); + WPG_DEBUG_MSG((" Viewport Y2 : %d\n", viewportY2)); + WPG_DEBUG_MSG((" Image X1 : %d\n", imageX1)); + WPG_DEBUG_MSG((" Image Y1 : %d\n", imageY1)); + WPG_DEBUG_MSG((" Image X2 : %d\n", imageX2)); + WPG_DEBUG_MSG((" Image Y2 : %d\n", imageY2)); + + double width = (TO_DOUBLE(imageX2)-TO_DOUBLE(imageX1)) / m_xres; + double height = (TO_DOUBLE(imageY2)-TO_DOUBLE(imageY1)) / m_yres; + + m_painter->startDocument(width, height); + + static const int WPG2_defaultPenDashes[] = { + 1, 291, 0, // style #0 (actually solid) + 1, 218, 73, // style #1 + 1, 145, 73, // style #2 + 1, 73, 73, // style #3 + 1, 36, 36, // style #4 + 1, 18, 18, // style #5 + 1, 18, 55, // style #6 + 3, 18, 55, 18, 55, 18, 127, // style #7 + 2, 164, 55, 18, 55, // style #8 + 3, 145, 36, 138, 36, 18, 36, // style #9 + 3, 91, 55, 91, 55, 18, 55, // style #10 + 4, 91, 36, 91, 36, 18, 36, 18, 36, // style #11 + 2, 182, 73, 73, 73, // style #12 + 3, 182, 36, 55, 36, 55, 36, // style #13 + 3, 255, 73, 255, 73, 73, 73, // style #14 + 4, 273, 36, 273, 36, 55, 36, 55, 36, // style #15 + 0 // end marker + }; + + // create default pen styles + int styleNo = 0; + for(int i = 0; i < sizeof(WPG2_defaultPenDashes)/sizeof(WPG2_defaultPenDashes[0]);) + { + int segments = 2 * WPG2_defaultPenDashes[i++]; + if(segments == 0) break; + WPGDashArray dashArray; + for(int j = 0; j < segments; j++, i++) + dashArray.add(WPG2_defaultPenDashes[i]*3.6/218.0); + m_penStyles[styleNo] = dashArray; + styleNo++; + } +} + +void WPG2Parser::handleEndWPG() +{ + // sentinel + if(m_layerOpened) + m_painter->endLayer(m_layerId); + + m_painter->endDocument(); + m_exit = true; + + WPG_DEBUG_MSG(("EndWPG\n")); +} + +void WPG2Parser::handleLayer() +{ + m_layerId = readU16(); + + // close previous one + if(m_layerOpened) + m_painter->endLayer(m_layerId); + + m_painter->startLayer(m_layerId); + m_layerOpened = true; + + WPG_DEBUG_MSG(("Layer\n")); + WPG_DEBUG_MSG((" Id: %d\n", m_layerId)); +} + +void WPG2Parser::handlePenStyleDefinition() +{ + unsigned int style = readU16(); + unsigned int segments = readU16(); + + WPGDashArray dashArray; + for(int i = 0; i < segments; i++) + { + unsigned int p = (m_doublePrecision) ? readU32() : readU16(); + unsigned int q = (m_doublePrecision) ? readU32() : readU16(); + dashArray.add(TO_DOUBLE(p)*3.6/218.0); + dashArray.add(TO_DOUBLE(q)*3.6/218.0); + } + m_penStyles[style] = dashArray; + + WPG_DEBUG_MSG(("PenStyleDefinition\n")); + WPG_DEBUG_MSG((" Style : %d\n", style)); + WPG_DEBUG_MSG((" Segment pairs : %d\n", segments)); +} + +// TODO +void WPG2Parser::handlePatternDefinition() +{ + WPG_DEBUG_MSG(("PatternDefinition\n")); +} + +void WPG2Parser::handleColorPalette() +{ + unsigned startIndex = readU16(); + unsigned numEntries = readU16(); + + WPG_DEBUG_MSG(("Color Palette\n")); + for(int i = 0; i < numEntries; i++) + { + WPGColor color; + color.red = readU8(); + color.green = readU8(); + color.blue = readU8(); + m_colorPalette[startIndex+i] = color; + WPG_DEBUG_MSG(("Index#%d: RGB %d %d %d\n", startIndex+i, color.red, color.green, color.blue)); + } +} + +void WPG2Parser::handleDPColorPalette() +{ + unsigned startIndex = readU16(); + unsigned numEntries = readU16(); + + WPG_DEBUG_MSG(("Color Palette\n")); + for(int i = 0; i < numEntries; i++) + { + WPGColor color; + color.red = readU16() >> 8 ; + color.green = readU16() >> 8 ; + color.blue = readU16() >> 8 ; + m_colorPalette[startIndex+i] = color; + WPG_DEBUG_MSG(("Index#%d: RGB %d %d %d\n", startIndex+i, color.red, color.green, color.blue)); + } +} + +void WPG2Parser::handlePenForeColor() +{ + unsigned char red = readU8(); + unsigned char green = readU8(); + unsigned char blue = readU8(); + unsigned char alpha = readU8(); + + m_pen.foreColor = WPGColor(red, green, blue, alpha); + + WPG_DEBUG_MSG(("PenForeColor\n")); + WPG_DEBUG_MSG((" Foreground color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); +} + +void WPG2Parser::handleDPPenForeColor() +{ + unsigned int red = readU16(); + unsigned int green = readU16(); + unsigned int blue = readU16(); + unsigned int alpha = readU16(); + + // we just ignore the least significant 8 bits + m_pen.foreColor = WPGColor(red>>8, green>>8, blue>>8, alpha>>8); + + WPG_DEBUG_MSG(("PenForeColor\n")); + WPG_DEBUG_MSG((" Foreground color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); +} + +void WPG2Parser::handlePenBackColor() +{ + unsigned char red = readU8(); + unsigned char green = readU8(); + unsigned char blue = readU8(); + unsigned char alpha = readU8(); + + m_pen.backColor = WPGColor(red, green, blue, alpha); + + WPG_DEBUG_MSG(("PenBackColor\n")); + WPG_DEBUG_MSG((" Background color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); +} + +void WPG2Parser::handleDPPenBackColor() +{ + unsigned int red = readU16(); + unsigned int green = readU16(); + unsigned int blue = readU16(); + unsigned int alpha = readU16(); + + // we just ignore the least significant 8 bits + m_pen.backColor = WPGColor(red>>8, green>>8, blue>>8, alpha>>8); + + WPG_DEBUG_MSG(("PenBackColor\n")); + WPG_DEBUG_MSG((" Background color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); +} + +void WPG2Parser::handlePenStyle() +{ + unsigned int style = readU16(); + + m_pen.dashArray = m_penStyles[style]; + m_pen.solid = (style == 0); + + WPG_DEBUG_MSG(("PenStyle\n")); + WPG_DEBUG_MSG((" Pen style : %d\n", style)); + WPG_DEBUG_MSG((" Segments : %d\n", m_pen.dashArray.count())); +} + +void WPG2Parser::handlePenSize() +{ + unsigned int width = readU16(); + unsigned int height = readU16(); + + m_pen.width = TO_DOUBLE(width) / m_xres; + m_pen.height = TO_DOUBLE(height) / m_yres; + + WPG_DEBUG_MSG(("PenSize\n")); + WPG_DEBUG_MSG((" Width: %d\n", width)); + WPG_DEBUG_MSG((" Height: %d\n", height)); +} + +void WPG2Parser::handleDPPenSize() +{ + unsigned long width = readU32(); + unsigned long height = readU32(); + + m_pen.width = TO_DOUBLE(width) / m_xres / 256; + m_pen.height = TO_DOUBLE(height) / m_yres / 256; + + WPG_DEBUG_MSG(("PenSize\n")); + WPG_DEBUG_MSG((" Width: %d\n", width)); + WPG_DEBUG_MSG((" Height: %d\n", height)); +} + +void WPG2Parser::handleBrushForeColor() +{ + unsigned char gradientType = readU8(); + unsigned char red = readU8(); + unsigned char green = readU8(); + unsigned char blue = readU8(); + unsigned char alpha = readU8(); + + m_brush.foreColor = WPGColor(red, green, blue, alpha); + if(m_brush.style == WPGBrush::NoBrush) + m_brush.style = WPGBrush::Solid; + + WPG_DEBUG_MSG(("BrushForeColor\n")); + WPG_DEBUG_MSG((" Gradient type : %d (%s)\n", gradientType, describeGradient(gradientType))); + WPG_DEBUG_MSG((" Foreground color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); +} + +void WPG2Parser::handleDPBrushForeColor() +{ + unsigned char gradientType = readU8(); + unsigned int red = readU16(); + unsigned int green = readU16(); + unsigned int blue = readU16(); + unsigned int alpha = readU16(); + + // we just ignore the least significant 8 bits + m_brush.foreColor = WPGColor(red>>8, green>>8, blue>>8, alpha>>8); + if(m_brush.style == WPGBrush::NoBrush) + m_brush.style = WPGBrush::Solid; + + WPG_DEBUG_MSG(("BrushForeColor\n")); + WPG_DEBUG_MSG((" Gradient type : %d (%s)\n", gradientType, describeGradient(gradientType))); + WPG_DEBUG_MSG((" Foreground color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); +} + +void WPG2Parser::handleBrushBackColor() +{ + unsigned char red = readU8(); + unsigned char green = readU8(); + unsigned char blue = readU8(); + unsigned char alpha = readU8(); + + m_brush.backColor = WPGColor(red, green, blue, alpha); + if(m_brush.style == WPGBrush::NoBrush) + m_brush.style = WPGBrush::Solid; + + WPG_DEBUG_MSG(("BrushBackColor\n")); + WPG_DEBUG_MSG((" Backround color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); +} + +void WPG2Parser::handleDPBrushBackColor() +{ + unsigned int red = readU16(); + unsigned int green = readU16(); + unsigned int blue = readU16(); + unsigned int alpha = readU16(); + + // we just ignore the least significant 8 bits + m_brush.backColor = WPGColor(red>>8, green>>8, blue>>8, alpha>>8); + if(m_brush.style == WPGBrush::NoBrush) + m_brush.style = WPGBrush::Solid; + + WPG_DEBUG_MSG(("PenBackColor\n")); + WPG_DEBUG_MSG((" Background color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); +} + +void WPG2Parser::handleBrushPattern() +{ + unsigned int pattern = readU16(); + + // TODO + + WPG_DEBUG_MSG(("BrushPattern\n")); + WPG_DEBUG_MSG((" Pattern : %d\n", pattern)); +} + +void WPG2Parser::parseCharacterization(ObjectCharacterization* ch) +{ + // sanity check + if(!ch) return; + + unsigned int flags = readU16(); + ch->taper = (flags & 0x01) != 0; + ch->translate = (flags & 0x02) != 0; + ch->skew = (flags & 0x04) != 0; + ch->scale = (flags & 0x08) != 0; + ch->rotate = (flags & 0x10) != 0; + ch->hasObjectId = (flags & 0x20) != 0; + ch->editLock = (flags & 0x80) != 0; + ch->filled = (flags & (1<<13)) != 0; + ch->closed = (flags & (1<<14)) != 0; + ch->framed = (flags & (1<<15)) != 0; + + if(ch->editLock) ch->lockFlags = readU32(); + + // object ID can be 2 or 4 bytes + if(ch->hasObjectId) ch->objectId = readU16(); + if(ch->objectId >> 15) ch->objectId = ((ch->objectId & 0x7fff) << 16) | readU16(); + + if(ch->rotate) ch->rotationAngle = readS32(); + + if(ch->rotate || ch->scale) + { + ch->sxcos = readS32(); + ch->sycos = readS32(); } + + if(ch->rotate || ch->skew) + { + ch->kxsin = readS32(); + ch->kysin = readS32(); + } + + if(ch->translate) + { + ch->txfraction = readU16(); + ch->txinteger = readS32(); + ch->tyfraction = readU16(); + ch->tyinteger = readS32(); + } + + if(ch->taper) + { + ch->px = readS32(); + ch->py = readS32(); + } + + WPG_DEBUG_MSG(("ObjectCharacterization\n")); + WPG_DEBUG_MSG((" taper : %s\n", (ch->taper ? "yes" : "no"))); + WPG_DEBUG_MSG((" translate : %s\n", (ch->translate ? "yes" : "no"))); + WPG_DEBUG_MSG((" skew : %s\n", (ch->skew ? "yes" : "no"))); + WPG_DEBUG_MSG((" scale : %s\n", (ch->scale ? "yes" : "no"))); + WPG_DEBUG_MSG((" rotate : %s\n", (ch->rotate ? "yes" : "no"))); + WPG_DEBUG_MSG((" hasObjectId : %s\n", (ch->hasObjectId ? "yes" : "no"))); + WPG_DEBUG_MSG((" editLock : %s\n", (ch->editLock ? "yes" : "no"))); + if(ch->editLock) WPG_DEBUG_MSG((" lock flags : 0x%x\n", ch->lockFlags)); + if(ch->hasObjectId) WPG_DEBUG_MSG((" object ID : 0x%x\n", ch->objectId)); + if(ch->translate) WPG_DEBUG_MSG((" tx ty : %d %d\n", ch->txinteger, ch->tyinteger)); + if(ch->translate) WPG_DEBUG_MSG((" tx ty : %d %d\n", ch->txfraction, ch->tyfraction)); +} + +void WPG2Parser::handlePolyline() +{ + ObjectCharacterization objCh; + parseCharacterization(&objCh); + + unsigned long count = readU16(); + + WPGPointArray points; + for(unsigned long i = 0; i < count; i++ ) + { + long x = (m_doublePrecision) ? readU32() : readU16(); + long y = (m_doublePrecision) ? readU32() : readU16(); + TRANSFORM_XY(x,y); + points.add(WPGPoint(TO_DOUBLE(x)/m_xres, TO_DOUBLE(y)/m_yres)); + } + + m_painter->setBrush( objCh.filled ? m_brush : WPGBrush() ); + m_painter->setPen( objCh.framed ? m_pen : WPGPen() ); + m_painter->drawPolyline(points); + + WPG_DEBUG_MSG(("Polyline\n")); + WPG_DEBUG_MSG((" Vertices count : %d\n", count)); + for(int i = 0; i < count; i++ ) + WPG_DEBUG_MSG((" Point #%d : %g,%g\n", i+1, points[i].x, points[i].y)); } + +void WPG2Parser::handlePolycurve() +{ + ObjectCharacterization objCh; + parseCharacterization(&objCh); + + unsigned int count = readU16(); + + WPGPointArray vertices; + WPGPointArray controlPoints; + for(int i = 0; i < count; i++ ) + { + long ix = (m_doublePrecision) ? readU32() : readU16(); + long iy = (m_doublePrecision) ? readU32() : readU16(); + TRANSFORM_XY(ix,iy); + WPGPoint initialPoint( TO_DOUBLE(ix)/m_xres, TO_DOUBLE(iy)/m_yres ); + + long ax = (m_doublePrecision) ? readU32() : readU16(); + long ay = (m_doublePrecision) ? readU32() : readU16(); + TRANSFORM_XY(ax,ay); + WPGPoint anchorPoint( TO_DOUBLE(ax)/m_xres, TO_DOUBLE(ay)/m_yres ); + + long tx = (m_doublePrecision) ? readU32() : readU16(); + long ty = (m_doublePrecision) ? readU32() : readU16(); + TRANSFORM_XY(tx,ty); + WPGPoint terminalPoint( TO_DOUBLE(tx)/m_xres, TO_DOUBLE(ty)/m_yres ); + + vertices.add(anchorPoint); + if(i > 0) + controlPoints.add(initialPoint); + controlPoints.add(terminalPoint); + } + + m_painter->setBrush( objCh.filled ? m_brush : WPGBrush() ); + m_painter->setPen( objCh.framed ? m_pen : WPGPen() ); + m_painter->drawCurve(vertices, controlPoints); +} + +void WPG2Parser::handleRectangle() +{ + ObjectCharacterization objCh; + parseCharacterization(&objCh); + + long x1 = (m_doublePrecision) ? readU32() : readU16(); + long y1 = (m_doublePrecision) ? readU32() : readU16(); + TRANSFORM_XY(x1,y1); + + long x2 = (m_doublePrecision) ? readU32() : readU16(); + long y2 = (m_doublePrecision) ? readU32() : readU16(); + TRANSFORM_XY(x2,y2); + + long xs1 = (x1 <= x2) ? x1 : x2; + long xs2 = (x1 <= x2) ? x2 : x1; + long ys1 = (y1 <= y2) ? y1 : y2; + long ys2 = (y1 <= y2) ? y2 : y1; + + unsigned long rx = (m_doublePrecision) ? readU32() : readU16(); + unsigned long ry = (m_doublePrecision) ? readU32() : readU16(); + + WPGRect rect; + rect.x1 = TO_DOUBLE(xs1) / m_xres; + rect.x2 = TO_DOUBLE(xs2) / m_xres; + rect.y1 = TO_DOUBLE(ys1) / m_yres; + rect.y2 = TO_DOUBLE(ys2) / m_yres; + double roundx = TO_DOUBLE(rx)/m_xres; + double roundy = TO_DOUBLE(ry)/m_yres; + + m_painter->setBrush( objCh.filled ? m_brush : WPGBrush() ); + m_painter->setPen( objCh.framed ? m_pen : WPGPen() ); + m_painter->drawRectangle(rect, roundx, roundy); + + WPG_DEBUG_MSG(("Rectangle\n")); + WPG_DEBUG_MSG((" X1 : %d\n", x1)); + WPG_DEBUG_MSG((" Y1 : %d\n", y1)); + WPG_DEBUG_MSG((" X2 : %d\n", x2)); + WPG_DEBUG_MSG((" Y2 : %d\n", y2)); + WPG_DEBUG_MSG((" Round X : %d\n", rx)); + WPG_DEBUG_MSG((" Round Y : %d\n", ry)); +} + +void WPG2Parser::handleArc() +{ + ObjectCharacterization objCh; + parseCharacterization(&objCh); + + unsigned long cx = (m_doublePrecision) ? readU32() : readU16(); + unsigned long cy = (m_doublePrecision) ? readU32() : readU16(); + + unsigned long radx = (m_doublePrecision) ? readU32() : readU16(); + unsigned long rady = (m_doublePrecision) ? readU32() : readU16(); + + long ix = (m_doublePrecision) ? readU32() : readU16(); + long iy = (m_doublePrecision) ? readU32() : readU16(); + TRANSFORM_XY(ix,iy); + + long ex = (m_doublePrecision) ? readU32() : readU16(); + long ey = (m_doublePrecision) ? readU32() : readU16(); + TRANSFORM_XY(ex,ey); + + if((ix==ex) && (iy==ey)) + { + WPGPoint center; + center.x = TO_DOUBLE(cx) / m_xres; + center.y = TO_DOUBLE(cy) / m_xres; + double rx = TO_DOUBLE(radx) / m_xres; + double ry = TO_DOUBLE(rady) / m_xres; + + m_painter->setBrush( objCh.filled ? m_brush : WPGBrush() ); + m_painter->setPen( objCh.framed ? m_pen : WPGPen() ); + m_painter->drawEllipse(center, rx, ry); + } + + WPG_DEBUG_MSG(("Arc\n")); + WPG_DEBUG_MSG((" Center point x : %d\n", cx)); + WPG_DEBUG_MSG((" Center point y : %d\n", cy)); + WPG_DEBUG_MSG((" Radius x : %d\n", radx)); + WPG_DEBUG_MSG((" Radius y : %d\n", rady)); + WPG_DEBUG_MSG((" Initial point x : %d\n", ix)); + WPG_DEBUG_MSG((" Initial point y : %d\n", iy)); + WPG_DEBUG_MSG((" End point x : %d\n", ex)); + WPG_DEBUG_MSG((" End point y : %d\n", ey)); +} + --- libwpg_exception.h DELETED --- --- WPG2Record.h DELETED --- --- libwpg_utils.cpp DELETED --- Index: WPGXParser.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGXParser.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- WPGXParser.cpp 24 May 2006 22:25:57 -0000 1.5 +++ WPGXParser.cpp 17 Jun 2006 08:11:53 -0000 1.6 @@ -1,149 +1,224 @@ -/* 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 "WPGXParser.h" - -static const uint8_t defaultPaletteRed[] = { - 0x00, 0xFF, 0x7F, 0xBF, 0x00, 0x00, 0x00, 0x7F, - 0x7F, 0x7F, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, - 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, - 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE9, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE9, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE9, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x3D, 0x48, 0x53, 0x5E, 0x69, 0x74, 0x7F, 0x8A, - 0x95, 0xA0, 0xAB, 0xB6, 0xC1, 0xCC, 0xD7, 0xE2, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x3D, 0x48, 0x53, 0x5E, 0x69, 0x74, 0x7F, 0x8A, - 0x95, 0xA0, 0xAB, 0xB6, 0xC1, 0xCC, 0xD7, 0xE2, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE4, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE4, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x33, 0x47, 0x61, 0x73, 0x87, 0x9C, 0xB0, 0xC7, - 0xCC, 0xD4, 0xDB, 0xE3, 0xE8, 0xF0, 0xF7, 0xFF, -}; - -static const uint8_t defaultPaletteGreen[] = { - 0x00, 0xFF, 0x7F, 0xBF, 0x00, 0x7F, 0x7F, 0x00, - 0x00, 0x7F, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, - 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, - 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x3D, 0x48, 0x53, 0x5E, 0x69, 0x74, 0x7F, 0x8A, - 0x95, 0xA0, 0xAB, 0xB6, 0xC1, 0xCC, 0xD7, 0xE2, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE9, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE9, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE9, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE9, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE9, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x56, 0x64, 0x72, 0x80, 0x8E, 0x9C, 0xAA, 0xB1, - 0xB8, 0xBF, 0xC6, 0xCD, 0xD4, 0xDB, 0xE2, 0xE9, - 0x2B, 0x32, 0x39, 0x40, 0x47, 0x4E, 0x55, 0x63, - 0x71, 0x7F, 0x8D, 0x9B, 0xA9, 0xB7, 0xC5, 0xD3, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x29, 0x38, 0x45, 0x4F, 0x5C, 0x63, 0x69, 0xD4, - 0x87, 0x8F, 0x9C, 0xA8, 0xB3, 0xC4, 0xCF, 0xE0, -}; - -static const uint8_t defaultPaletteBlue[] = { - 0x00, 0xFF, 0x7F, 0xBF, 0x7F, 0x00, 0x7F, 0x00, - 0x7F, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, - 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, - 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, - 0x2C, 0x42, 0x58, 0x6E, 0x84, 0x9A, 0xB0, 0xC6, - 0x3D, 0x48, 0x53, 0x5E, 0x69, 0x74, 0x7F, 0x8A, - 0x95, 0xA0, 0xAB, 0xB6, 0xC1, 0xCC, 0xD7, 0xE2, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE9, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x7B, 0x91, 0xA7, 0xB0, 0xD3, 0xE4, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE4, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE4, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE4, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x7B, 0x91, 0xA7, 0xBD, 0xD3, 0xE4, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x3D, 0x48, 0x53, 0x5E, 0x69, 0x74, 0x7F, 0x8A, - 0x95, 0xA0, 0xAB, 0xB6, 0xC1, 0xCC, 0xD7, 0xE2, - 0x11, 0x17, 0x1C, 0x24, 0x29, 0x2B, 0x2B, 0x30, - 0x47, 0x57, 0x69, 0x78, 0x8C, 0x9C, 0xB0, 0xC7, -}; - -WPGXParser::WPGXParser(GsfInput *input, WPGListener* listener): - m_lineColorIndex(0x00), - m_fillColorIndex(0x00), - m_lineWidth(1/72), - m_lineStyle(1), - m_fillStyle(1) -{ - RGBColor tempColor; - for (int i=0; i<256; i++) - { - tempColor.red = defaultPaletteRed[i]; - tempColor.green = defaultPaletteGreen[i]; - tempColor.blue = defaultPaletteBlue[i]; - m_colorPalette.push_back(tempColor); - } -} - +/* libwpg + * Copyright (C) 2006 Ariya Hidayat (ar...@kd...) + * 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., 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 "WPGXParser.h" + +using namespace libwpg; + +// FIXME (ariya) this color palette does not seem to be corre... [truncated message content] |