diff options
author | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2013-05-02 22:38:52 +0200 |
---|---|---|
committer | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2013-05-02 22:38:52 +0200 |
commit | 2aa9ef5e2030e3c4200a3ca198f0728c3ee384cf (patch) | |
tree | 290f7e46774188d1912a8b8e96ecb578df09aecd | |
parent | 8fc935d87115cd4f6f154e0074d55de50a5344ea (diff) |
Astyle action
-rw-r--r-- | src/conv/raw/pict2raw.cpp | 44 | ||||
-rw-r--r-- | src/conv/svg/pict2svg.cpp | 9 | ||||
-rw-r--r-- | src/lib/Pict1Parser.cpp | 4 | ||||
-rw-r--r-- | src/lib/Pict1Parser.h | 8 | ||||
-rw-r--r-- | src/lib/Pict2Parser.cpp | 6 | ||||
-rw-r--r-- | src/lib/Pict2Parser.h | 6 | ||||
-rw-r--r-- | src/lib/PictBitmap.cpp | 23 | ||||
-rw-r--r-- | src/lib/PictBitmap.h | 18 | ||||
-rw-r--r-- | src/lib/PictColor.cpp | 8 | ||||
-rw-r--r-- | src/lib/PictColor.h | 20 | ||||
-rw-r--r-- | src/lib/PictHeader.cpp | 41 | ||||
-rw-r--r-- | src/lib/PictHeader.h | 58 | ||||
-rw-r--r-- | src/lib/PictImage.cpp | 49 | ||||
-rw-r--r-- | src/lib/PictImage.h | 14 | ||||
-rw-r--r-- | src/lib/PictSVGGenerator.cpp | 62 | ||||
-rw-r--r-- | src/lib/PictSVGGenerator.h | 11 | ||||
-rw-r--r-- | src/lib/PictXParser.cpp | 44 | ||||
-rw-r--r-- | src/lib/PictXParser.h | 24 | ||||
-rw-r--r-- | src/lib/libpict_utils.h | 22 |
19 files changed, 258 insertions, 213 deletions
diff --git a/src/conv/raw/pict2raw.cpp b/src/conv/raw/pict2raw.cpp index fb69ce4..15c9d49 100644 --- a/src/conv/raw/pict2raw.cpp +++ b/src/conv/raw/pict2raw.cpp @@ -32,25 +32,26 @@ #include <libwpd-stream/libwpd-stream.h> #include <libwpd/libwpd.h> -class RawPainter : public libwpg::WPGPaintInterface { +class RawPainter : public libwpg::WPGPaintInterface +{ public: RawPainter(); void startGraphics(const ::WPXPropertyList &propList); void endGraphics(); - void startLayer(const ::WPXPropertyList& propList); + void startLayer(const ::WPXPropertyList &propList); void endLayer(); - void startEmbeddedGraphics(const ::WPXPropertyList& propList); + void startEmbeddedGraphics(const ::WPXPropertyList &propList); void endEmbeddedGraphics(); - void setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector& gradient); + 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 drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData& binaryData); + 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 startTextObject(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &path); void endTextObject(); void startTextLine(const ::WPXPropertyList &propList); @@ -64,7 +65,7 @@ WPXString getPropString(const WPXPropertyList &propList) { WPXString propString; WPXPropertyList::Iter i(propList); - if (!i.last()) + if (!i.last()) { propString.append(i.key()); propString.append(": "); @@ -121,7 +122,7 @@ void RawPainter::endGraphics() printf("RawPainter::endGraphics\n"); } -void RawPainter::startLayer(const ::WPXPropertyList& propList) +void RawPainter::startLayer(const ::WPXPropertyList &propList) { printf("RawPainter::startLayer (%s)\n", getPropString(propList).cstr()); } @@ -131,7 +132,7 @@ void RawPainter::endLayer() printf("RawPainter::endLayer\n"); } -void RawPainter::startEmbeddedGraphics(const ::WPXPropertyList& propList) +void RawPainter::startEmbeddedGraphics(const ::WPXPropertyList &propList) { printf("RawPainter::startEmbeddedGraphics (%s)\n", getPropString(propList).cstr()); } @@ -141,7 +142,7 @@ void RawPainter::endEmbeddedGraphics() printf("RawPainter::endEmbeddedGraphics \n"); } -void RawPainter::setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector& gradient) +void RawPainter::setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &gradient) { printf("RawPainter::setStyle(%s, gradient: (%s))\n", getPropString(propList).cstr(), getPropString(gradient).cstr()); } @@ -151,27 +152,27 @@ void RawPainter::drawRectangle(const ::WPXPropertyList &propList) printf("RawPainter::drawRectangle (%s)\n", getPropString(propList).cstr()); } -void RawPainter::drawEllipse(const ::WPXPropertyList& propList) +void RawPainter::drawEllipse(const ::WPXPropertyList &propList) { printf("RawPainter::drawEllipse (%s)\n", getPropString(propList).cstr()); } -void RawPainter::drawPolyline(const ::WPXPropertyListVector& vertices) +void RawPainter::drawPolyline(const ::WPXPropertyListVector &vertices) { printf("RawPainter::drawPolyline (%s)\n", getPropString(vertices).cstr()); } -void RawPainter::drawPolygon(const ::WPXPropertyListVector& vertices) +void RawPainter::drawPolygon(const ::WPXPropertyListVector &vertices) { printf("RawPainter::drawPolygon (%s)\n", getPropString(vertices).cstr()); } -void RawPainter::drawPath(const ::WPXPropertyListVector& path) +void RawPainter::drawPath(const ::WPXPropertyListVector &path) { printf("RawPainter::drawPath (%s)\n", getPropString(path).cstr()); } -void RawPainter::drawGraphicObject(const ::WPXPropertyList& propList, const ::WPXBinaryData& /*binaryData*/) +void RawPainter::drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData & /*binaryData*/) { printf("RawPainter::drawGraphicObject (%s)\n", getPropString(propList).cstr()); } @@ -212,7 +213,8 @@ void RawPainter::insertText(const ::WPXString &str) } -namespace { +namespace +{ int printUsage() { @@ -236,7 +238,7 @@ int main(int argc, char *argv[]) { if (argc < 2) return printUsage(); - + char *file = 0; for (int i = 1; i < argc; i++) @@ -251,7 +253,7 @@ int main(int argc, char *argv[]) if (!file) return printUsage(); - + WPXFileStream input(file); if (!libpict::PictImage::isSupported(&input)) diff --git a/src/conv/svg/pict2svg.cpp b/src/conv/svg/pict2svg.cpp index 39b9dc7..e82b354 100644 --- a/src/conv/svg/pict2svg.cpp +++ b/src/conv/svg/pict2svg.cpp @@ -31,7 +31,8 @@ #include <libwpd-stream/libwpd-stream.h> #include <libwpd/libwpd.h> -namespace { +namespace +{ int printUsage() { @@ -55,7 +56,7 @@ int main(int argc, char *argv[]) { if (argc < 2) return printUsage(); - + char *file = 0; for (int i = 1; i < argc; i++) @@ -70,7 +71,7 @@ int main(int argc, char *argv[]) if (!file) return printUsage(); - + WPXFileStream input(file); if (!libpict::PictImage::isSupported(&input)) @@ -84,7 +85,7 @@ int main(int argc, char *argv[]) { std::cerr << "ERROR: SVG Generation failed!" << std::endl; return 1; - } + } std::cout << output.cstr() << std::endl; return 0; diff --git a/src/lib/Pict1Parser.cpp b/src/lib/Pict1Parser.cpp index 64203da..0ad5b24 100644 --- a/src/lib/Pict1Parser.cpp +++ b/src/lib/Pict1Parser.cpp @@ -23,7 +23,7 @@ #include <libwpd/libwpd.h> #include <libwpg/libwpg.h> -Pict1Parser::Pict1Parser(WPXInputStream *input, libwpg::WPGPaintInterface* painter): +Pict1Parser::Pict1Parser(WPXInputStream *input, libwpg::WPGPaintInterface *painter): PictXParser(input, painter), m_recordSize(0) { @@ -168,7 +168,7 @@ bool Pict1Parser::parse() for(int i=0; i < (int)(sizeof(handlers)/sizeof(RecordHandler)); i++) { if(handlers[i].type == recordType) - { + { index = i; break; } diff --git a/src/lib/Pict1Parser.h b/src/lib/Pict1Parser.h index f1199b0..0dc1c5a 100644 --- a/src/lib/Pict1Parser.h +++ b/src/lib/Pict1Parser.h @@ -12,8 +12,8 @@ * 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, + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02111-1301 USA * */ @@ -29,7 +29,7 @@ class Pict1Parser : public PictXParser { public: - Pict1Parser(WPXInputStream *input, libwpg::WPGPaintInterface* painter); + Pict1Parser(WPXInputStream *input, libwpg::WPGPaintInterface *painter); bool parse(); private: @@ -144,7 +144,7 @@ private: void handleLongComment(); void handleEndOfPicture(); - + void _handlePackBitsData(); void _handlePictureComment(); diff --git a/src/lib/Pict2Parser.cpp b/src/lib/Pict2Parser.cpp index 9fb8306..851eb81 100644 --- a/src/lib/Pict2Parser.cpp +++ b/src/lib/Pict2Parser.cpp @@ -22,7 +22,7 @@ #include <libwpd/libwpd.h> #include <libwpg/libwpg.h> -Pict2Parser::Pict2Parser(WPXInputStream *input, libwpg::WPGPaintInterface* painter): +Pict2Parser::Pict2Parser(WPXInputStream *input, libwpg::WPGPaintInterface *painter): PictXParser(input, painter), m_recordSize(0) { @@ -204,7 +204,7 @@ bool Pict2Parser::parse() { 0xff, "EndOfPicture", &Pict2Parser::handleEndOfPicture, 2 } }; - + while(!m_input->atEOS()) { m_recordSize = -1; @@ -241,7 +241,7 @@ bool Pict2Parser::parse() for(int i=0; i < (int)(sizeof(handlers)/sizeof(RecordHandler)); i++) { if(handlers[i].type == recordType) - { + { index = i; break; } diff --git a/src/lib/Pict2Parser.h b/src/lib/Pict2Parser.h index a09c49e..c0ec598 100644 --- a/src/lib/Pict2Parser.h +++ b/src/lib/Pict2Parser.h @@ -31,7 +31,7 @@ class Pict2Parser : public PictXParser { public: - Pict2Parser(WPXInputStream *input, libwpg::WPGPaintInterface* painter); + Pict2Parser(WPXInputStream *input, libwpg::WPGPaintInterface *painter); bool parse(); private: @@ -76,7 +76,7 @@ private: void handleFontName(); void handleLineJustify(); void handleGlyphState(); - + void handleFrameRect(); void handlePaintRect(); void handleEraseRect(); @@ -161,7 +161,7 @@ private: void handleLongComment(); void handleEndOfPicture(); - + void skipData(); void skipLongData(); diff --git a/src/lib/PictBitmap.cpp b/src/lib/PictBitmap.cpp index e16b0f1..bb54a23 100644 --- a/src/lib/PictBitmap.cpp +++ b/src/lib/PictBitmap.cpp @@ -70,7 +70,7 @@ public: int hRes; bool vFlip; bool hFlip; - PictColor* pixels; + PictColor *pixels; ::WPXBinaryData dib; Private(int w, int h): width(w), height(h), vRes(72), hRes(72), vFlip(false), hFlip(false), pixels(0), dib() {} @@ -96,18 +96,18 @@ libpict::PictBitmap::~PictBitmap() } } -libpict::PictBitmap::PictBitmap(const PictBitmap& bitmap): d(new Private(0,0)) +libpict::PictBitmap::PictBitmap(const PictBitmap &bitmap): d(new Private(0,0)) { copyFrom(bitmap); } -libpict::PictBitmap& libpict::PictBitmap::operator=(const PictBitmap& bitmap) +libpict::PictBitmap &libpict::PictBitmap::operator=(const PictBitmap &bitmap) { copyFrom(bitmap); return *this; } -void libpict::PictBitmap::copyFrom(const PictBitmap& bitmap) +void libpict::PictBitmap::copyFrom(const PictBitmap &bitmap) { d->width = bitmap.d->width; d->height = bitmap.d->height; @@ -137,7 +137,7 @@ int libpict::PictBitmap::hres() const return d->hRes; } -void libpict::PictBitmap::setPixel(int x, int y, const libpict::PictColor& color) +void libpict::PictBitmap::setPixel(int x, int y, const libpict::PictColor &color) { if((x < 0) || (y <0) || (x >= d->width) || (y >= d->height)) return; @@ -145,7 +145,7 @@ void libpict::PictBitmap::setPixel(int x, int y, const libpict::PictColor& color d->pixels[y*d->width + x] = color; } -const ::WPXBinaryData & libpict::PictBitmap::getDIB() const +const ::WPXBinaryData &libpict::PictBitmap::getDIB() const { if (d->dib.size() || d->height <= 0 || d->width <= 0) return d->dib; @@ -177,7 +177,7 @@ const ::WPXBinaryData & libpict::PictBitmap::getDIB() const writeU16(tmpDIBBuffer, tmpBufferPosition, 0); // Reserved1 writeU16(tmpDIBBuffer, tmpBufferPosition, 0); // Reserved2 writeU32(tmpDIBBuffer, tmpBufferPosition, tmpDIBOffsetBits); // OffsetBits - + PICT_DEBUG_MSG(("PictBitmap: DIB file header end = %i\n", tmpBufferPosition - 1)); // Create DIB Info header @@ -190,20 +190,21 @@ const ::WPXBinaryData & libpict::PictBitmap::getDIB() const writeU32(tmpDIBBuffer, tmpBufferPosition, 1); // Height #endif writeU16(tmpDIBBuffer, tmpBufferPosition, 1); // Planes - writeU16(tmpDIBBuffer, tmpBufferPosition, 32); // BitCount + writeU16(tmpDIBBuffer, tmpBufferPosition, 32); // BitCount writeU32(tmpDIBBuffer, tmpBufferPosition, 0); // Compression writeU32(tmpDIBBuffer, tmpBufferPosition, tmpDIBImageSize); // SizeImage writeU32(tmpDIBBuffer, tmpBufferPosition, (int)(hres()*100.0/2.54)); // XPelsPerMeter writeU32(tmpDIBBuffer, tmpBufferPosition, (int)(vres()*100.0/2.54)); // YPelsPerMeter writeU32(tmpDIBBuffer, tmpBufferPosition, 0); // ColorsUsed writeU32(tmpDIBBuffer, tmpBufferPosition, 0); // ColorsImportant - + PICT_DEBUG_MSG(("PictBitmap: DIB info header end = %i\n", tmpBufferPosition - 1)); // Write DIB Image data #ifndef OUTPUT_DUMMY_BITMAPS - int i = 0; int j = 0; + int i = 0; + int j = 0; if (d->vFlip) for (i = 0; i < d->height && tmpBufferPosition < tmpDIBFileSize; i++) { @@ -271,6 +272,6 @@ const ::WPXBinaryData & libpict::PictBitmap::getDIB() const // Cleanup things before returning delete [] tmpDIBBuffer; - + return d->dib; } diff --git a/src/lib/PictBitmap.h b/src/lib/PictBitmap.h index c469aed..408c6a9 100644 --- a/src/lib/PictBitmap.h +++ b/src/lib/PictBitmap.h @@ -38,11 +38,11 @@ class PictBitmap public: PictBitmap(int width, int height, int verticalResolution, int horizontalResolution, bool verticalFlip=false, bool horizontalFlip=false); - PictBitmap(const PictBitmap&); + PictBitmap(const PictBitmap &); - PictBitmap& operator=(const PictBitmap&); + PictBitmap &operator=(const PictBitmap &); - void copyFrom(const PictBitmap&); + void copyFrom(const PictBitmap &); ~PictBitmap(); @@ -51,20 +51,20 @@ public: // return height in pixel int height() const; - + // return vertical resolution in pixels per inch int vres() const; // return horizontal resolution in pixels per inch int hres() const; - - void setPixel(int x, int y, const PictColor& color); - - const ::WPXBinaryData& getDIB() const; + + void setPixel(int x, int y, const PictColor &color); + + const ::WPXBinaryData &getDIB() const; private: class Private; - Private* const d; + Private *const d; }; } // namespace libpict diff --git a/src/lib/PictColor.cpp b/src/lib/PictColor.cpp index 4b7de3b..ff7554f 100644 --- a/src/lib/PictColor.cpp +++ b/src/lib/PictColor.cpp @@ -12,8 +12,8 @@ * 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, + * 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://libpict.sourceforge.net @@ -46,14 +46,14 @@ libpict::PictColor::PictColor(int r, int g, int b, int a): alpha(a) {} -libpict::PictColor::PictColor(const PictColor& color): +libpict::PictColor::PictColor(const PictColor &color): red(color.red), green(color.green), blue(color.blue), alpha(color.alpha) {} -libpict::PictColor& libpict::PictColor::operator=(const libpict::PictColor& color) +libpict::PictColor &libpict::PictColor::operator=(const libpict::PictColor &color) { red = color.red; green = color.green; diff --git a/src/lib/PictColor.h b/src/lib/PictColor.h index fc624cf..91102b9 100644 --- a/src/lib/PictColor.h +++ b/src/lib/PictColor.h @@ -12,8 +12,8 @@ * 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, + * 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://libpict.sourceforge.net @@ -35,19 +35,19 @@ class PictColor { public: int red, green, blue, alpha; - + PictColor(); - + PictColor(int r, int g, int b); - + PictColor(int r, int g, int b, int a); - PictColor(const PictColor& color); - - PictColor& operator=(const PictColor& color); - + PictColor(const PictColor &color); + + PictColor &operator=(const PictColor &color); + const ::WPXString getColorString() const; - + double getOpacity() const; }; diff --git a/src/lib/PictHeader.cpp b/src/lib/PictHeader.cpp index aecdaff..46905e1 100644 --- a/src/lib/PictHeader.cpp +++ b/src/lib/PictHeader.cpp @@ -12,8 +12,8 @@ * 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, + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02111-1301 USA */ @@ -49,7 +49,7 @@ unsigned readU32(WPXInputStream *input) if (numBytesRead != sizeof(unsigned)) ; return (unsigned)((((unsigned char const *)(p))[3] << 0) | (((unsigned char const *)(p))[2] << 8) | - (((unsigned char const *)(p))[1] << 16) | (((unsigned char const *)(p))[0] << 24)); + (((unsigned char const *)(p))[1] << 16) | (((unsigned char const *)(p))[0] << 24)); } } @@ -82,12 +82,14 @@ bool PictHeader::loadPict1Header(WPXInputStream *input) input->seek(10, WPX_SEEK_CUR); if ((0x11 == readU8(input)) && (0x01 == readU8(input))) input->seek(0, WPX_SEEK_CUR); - /* Ok, let us now skip the first 512 bytes and restart */ - else { + /* Ok, let us now skip the first 512 bytes and restart */ + else + { input->seek(512 + 10, WPX_SEEK_SET); if ((0x11 == readU8(input)) && (0x01 == readU8(input))) input->seek(512, WPX_SEEK_SET); - else { + else + { input->seek(0, WPX_SEEK_SET); PICT_DEBUG_MSG(("No Pict1 header present\n")); return false; @@ -100,11 +102,13 @@ bool PictHeader::loadPict1Header(WPXInputStream *input) m_left = readU16(input); m_bottom = readU16(input); m_right = readU16(input); - if (0x11 != readU8(input)) { + if (0x11 != readU8(input)) + { input->seek(0, WPX_SEEK_SET); return false; } - if (0x01 != readU8(input)) { + if (0x01 != readU8(input)) + { input->seek(0, WPX_SEEK_SET); return false; } @@ -112,7 +116,7 @@ bool PictHeader::loadPict1Header(WPXInputStream *input) m_dataStart = input->tell(); input->seek(0, WPX_SEEK_SET); m_pictVersion = 1; - return true; + return true; } bool PictHeader::loadPict2Header(WPXInputStream *input) @@ -122,12 +126,14 @@ bool PictHeader::loadPict2Header(WPXInputStream *input) input->seek(10, WPX_SEEK_CUR); if ((0x0011 == readU16(input)) && (0x02FF == readU16(input))) input->seek(0, WPX_SEEK_CUR); - /* Ok, let us now skip the first 512 bytes and restart */ - else { + /* Ok, let us now skip the first 512 bytes and restart */ + else + { input->seek(512 + 10, WPX_SEEK_SET); if ((0x0011 == readU16(input)) && (0x02FF == readU16(input))) input->seek(512, WPX_SEEK_SET); - else { + else + { input->seek(0, WPX_SEEK_SET); PICT_DEBUG_MSG(("No Pict2 header present\n")); return false; @@ -140,15 +146,18 @@ bool PictHeader::loadPict2Header(WPXInputStream *input) m_left = readU16(input); m_bottom = readU16(input); m_right = readU16(input); - if (0x0011 != readU16(input)) { + if (0x0011 != readU16(input)) + { input->seek(0, WPX_SEEK_SET); return false; } - if (0x02FF != readU16(input)) { + if (0x02FF != readU16(input)) + { input->seek(0, WPX_SEEK_SET); return false; } - if (0x0C00 != readU16(input)) { + if (0x0C00 != readU16(input)) + { input->seek(0, WPX_SEEK_SET); return false; } @@ -158,5 +167,5 @@ bool PictHeader::loadPict2Header(WPXInputStream *input) m_dataStart = input->tell(); input->seek(0, WPX_SEEK_SET); m_pictVersion = 2; - return true; + return true; } diff --git a/src/lib/PictHeader.h b/src/lib/PictHeader.h index 4b2ac9e..26101b7 100644 --- a/src/lib/PictHeader.h +++ b/src/lib/PictHeader.h @@ -12,8 +12,8 @@ * 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, + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02111-1301 USA */ @@ -22,24 +22,48 @@ #include <libwpd-stream/WPXStream.h> -class PictHeader +class PictHeader { public: PictHeader(); - + bool load(WPXInputStream *input); - - unsigned long startOfDocument() const { return m_dataStart; } - - int getVersion() const { return m_pictVersion; } - - unsigned getTop() const { return m_top; } - unsigned getLeft() const { return m_left; } - unsigned getBottom() const { return m_bottom; } - unsigned getRight() const { return m_right; } - unsigned getHorizontalResolution() const { return m_horizontalResolution; } - unsigned getVerticalResolution() const { return m_verticalResolution; } - + + unsigned long startOfDocument() const + { + return m_dataStart; + } + + int getVersion() const + { + return m_pictVersion; + } + + unsigned getTop() const + { + return m_top; + } + unsigned getLeft() const + { + return m_left; + } + unsigned getBottom() const + { + return m_bottom; + } + unsigned getRight() const + { + return m_right; + } + unsigned getHorizontalResolution() const + { + return m_horizontalResolution; + } + unsigned getVerticalResolution() const + { + return m_verticalResolution; + } + private: unsigned short m_fileSize; @@ -52,7 +76,7 @@ private: unsigned long m_verticalResolution; unsigned long m_pictureSize; unsigned long m_dataStart; - + bool loadPict1Header(WPXInputStream *input); bool loadPict2Header(WPXInputStream *input); }; diff --git a/src/lib/PictImage.cpp b/src/lib/PictImage.cpp index 3b9e71f..e2bee15 100644 --- a/src/lib/PictImage.cpp +++ b/src/lib/PictImage.cpp @@ -12,8 +12,8 @@ * 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, + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02111-1301 USA */ @@ -33,14 +33,14 @@ Analyzes the content of an input stream to see if it can be parsed \return A value that indicates whether the content from the input stream is a Macintosh Pict Image that libpict is able to parse */ -bool libpict::PictImage::isSupported(WPXInputStream* input) +bool libpict::PictImage::isSupported(WPXInputStream *input) { input->seek(0, WPX_SEEK_SET); PictHeader header; if(!header.load(input)) return false; - + return true; } @@ -52,41 +52,42 @@ WPGPaintInterface class implementation when needed. This is often commonly calle \param painter A WPGPainterInterface implementation \return A value that indicates whether the parsing was successful */ -bool libpict::PictImage::parse(::WPXInputStream* input, libwpg::WPGPaintInterface* painter) +bool libpict::PictImage::parse(::WPXInputStream *input, libwpg::WPGPaintInterface *painter) { PictXParser *parser = 0; - + input->seek(0, WPX_SEEK_SET); PICT_DEBUG_MSG(("Loading header...\n")); PictHeader header; if(!header.load(input)) return false; - + // seek to the start of document input->seek(header.startOfDocument(), WPX_SEEK_SET); unsigned char tmpVersion = header.getVersion(); bool retval; - switch (tmpVersion) { - case 0x01: // Pict1 - PICT_DEBUG_MSG(("Parsing Pict1\n")); - parser = new Pict1Parser(input, painter); - retval = parser->parse(); - break; - case 0x02: // Pict2 - PICT_DEBUG_MSG(("Parsing Pict2\n")); - parser = new Pict2Parser(input, painter); - retval = parser->parse(); - break; - default: // other :-) - PICT_DEBUG_MSG(("Unknown format\n")); - return false; + switch (tmpVersion) + { + case 0x01: // Pict1 + PICT_DEBUG_MSG(("Parsing Pict1\n")); + parser = new Pict1Parser(input, painter); + retval = parser->parse(); + break; + case 0x02: // Pict2 + PICT_DEBUG_MSG(("Parsing Pict2\n")); + parser = new Pict2Parser(input, painter); + retval = parser->parse(); + break; + default: // other :-) + PICT_DEBUG_MSG(("Unknown format\n")); + return false; } - + if (parser) delete parser; - + return retval; } @@ -97,7 +98,7 @@ Provided as a convenience function for applications that support SVG internally. \param output The output string whose content is the resulting SVG \return A value that indicates whether the SVG generation was successful. */ -bool libpict::PictImage::generateSVG(::WPXInputStream* input, WPXString& output) +bool libpict::PictImage::generateSVG(::WPXInputStream *input, WPXString &output) { std::ostringstream tmpOutputStream; libpict::PictSVGGenerator generator(tmpOutputStream); diff --git a/src/lib/PictImage.h b/src/lib/PictImage.h index 56bdcd7..9e10e5e 100644 --- a/src/lib/PictImage.h +++ b/src/lib/PictImage.h @@ -12,8 +12,8 @@ * 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, + * 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://libpict.sourceforge.net @@ -36,12 +36,12 @@ namespace libpict class PictImage { public: - - static bool isSupported(WPXInputStream* input); - - static bool parse(WPXInputStream* input, libwpg::WPGPaintInterface* painter); - static bool generateSVG(WPXInputStream* input, WPXString& output); + static bool isSupported(WPXInputStream *input); + + static bool parse(WPXInputStream *input, libwpg::WPGPaintInterface *painter); + + static bool generateSVG(WPXInputStream *input, WPXString &output); }; } // namespace libpict diff --git a/src/lib/PictSVGGenerator.cpp b/src/lib/PictSVGGenerator.cpp index 5d28b24..b44c604 100644 --- a/src/lib/PictSVGGenerator.cpp +++ b/src/lib/PictSVGGenerator.cpp @@ -24,23 +24,23 @@ static std::string doubleToString(const double value) { - std::ostringstream tempStream; - tempStream << value; - std::string decimalPoint(localeconv()->decimal_point); - if ((decimalPoint.size() == 0) || (decimalPoint == ".")) - return tempStream.str(); - std::string stringValue(tempStream.str()); - if (!stringValue.empty()) - { - std::string::size_type pos; - while ((pos = stringValue.find(decimalPoint)) != std::string::npos) - stringValue.replace(pos,decimalPoint.size(),"."); - } - return stringValue; + std::ostringstream tempStream; + tempStream << value; + std::string decimalPoint(localeconv()->decimal_point); + if ((decimalPoint.size() == 0) || (decimalPoint == ".")) + return tempStream.str(); + std::string stringValue(tempStream.str()); + if (!stringValue.empty()) + { + std::string::size_type pos; + while ((pos = stringValue.find(decimalPoint)) != std::string::npos) + stringValue.replace(pos,decimalPoint.size(),"."); + } + return stringValue; } -libpict::PictSVGGenerator::PictSVGGenerator(std::ostream & output_sink): m_gradient(), m_style(), m_gradientIndex(1), m_outputSink(output_sink) +libpict::PictSVGGenerator::PictSVGGenerator(std::ostream &output_sink): m_gradient(), m_style(), m_gradientIndex(1), m_outputSink(output_sink) { } @@ -72,7 +72,7 @@ void libpict::PictSVGGenerator::endGraphics() m_outputSink << "</svg>\n"; } -void libpict::PictSVGGenerator::setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector& gradient) +void libpict::PictSVGGenerator::setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &gradient) { m_style = propList; @@ -110,7 +110,7 @@ void libpict::PictSVGGenerator::setStyle(const ::WPXPropertyList &propList, cons } -void libpict::PictSVGGenerator::startLayer(const ::WPXPropertyList& propList) +void libpict::PictSVGGenerator::startLayer(const ::WPXPropertyList &propList) { m_outputSink << "<g id=\"Layer" << propList["svg:id"]->getInt() << "\" >\n"; } @@ -120,7 +120,7 @@ void libpict::PictSVGGenerator::endLayer() m_outputSink << "</g>\n"; } -void libpict::PictSVGGenerator::drawRectangle(const ::WPXPropertyList& propList) +void libpict::PictSVGGenerator::drawRectangle(const ::WPXPropertyList &propList) { m_outputSink << "<rect "; m_outputSink << "x=\"" << doubleToString(72*propList["svg:x"]->getDouble()) << "\" y=\"" << doubleToString(72*propList["svg:y"]->getDouble()) << "\" "; @@ -131,7 +131,7 @@ void libpict::PictSVGGenerator::drawRectangle(const ::WPXPropertyList& propList) m_outputSink << "/>\n"; } -void libpict::PictSVGGenerator::drawEllipse(const WPXPropertyList& propList) +void libpict::PictSVGGenerator::drawEllipse(const WPXPropertyList &propList) { m_outputSink << "<ellipse "; m_outputSink << "cx=\"" << doubleToString(72*propList["svg:cx"]->getDouble()) << "\" cy=\"" << doubleToString(72*propList["svg:cy"]->getDouble()) << "\" "; @@ -139,24 +139,24 @@ void libpict::PictSVGGenerator::drawEllipse(const WPXPropertyList& propList) writeStyle(); if (propList["libpict:rotate"] && propList["libpict:rotate"]->getDouble() != 0.0) m_outputSink << " transform=\" translate(" << doubleToString(72*propList["svg:cx"]->getDouble()) << ", " << doubleToString(72*propList["svg:cy"]->getDouble()) - << ") rotate(" << doubleToString(-propList["libpict:rotate"]->getDouble()) - << ") translate(" << doubleToString(-72*propList["svg:cx"]->getDouble()) - << ", " << doubleToString(-72*propList["svg:cy"]->getDouble()) - << ")\" "; + << ") rotate(" << doubleToString(-propList["libpict:rotate"]->getDouble()) + << ") translate(" << doubleToString(-72*propList["svg:cx"]->getDouble()) + << ", " << doubleToString(-72*propList["svg:cy"]->getDouble()) + << ")\" "; m_outputSink << "/>\n"; } -void libpict::PictSVGGenerator::drawPolyline(const ::WPXPropertyListVector& vertices) +void libpict::PictSVGGenerator::drawPolyline(const ::WPXPropertyListVector &vertices) { drawPolySomething(vertices, false); } -void libpict::PictSVGGenerator::drawPolygon(const ::WPXPropertyListVector& vertices) +void libpict::PictSVGGenerator::drawPolygon(const ::WPXPropertyListVector &vertices) { drawPolySomething(vertices, true); } -void libpict::PictSVGGenerator::drawPolySomething(const ::WPXPropertyListVector& vertices, bool isClosed) +void libpict::PictSVGGenerator::drawPolySomething(const ::WPXPropertyListVector &vertices, bool isClosed) { if(vertices.count() < 2) return; @@ -189,7 +189,7 @@ void libpict::PictSVGGenerator::drawPolySomething(const ::WPXPropertyListVector& } } -void libpict::PictSVGGenerator::drawPath(const ::WPXPropertyListVector& path) +void libpict::PictSVGGenerator::drawPath(const ::WPXPropertyListVector &path) { m_outputSink << "<path d=\" "; bool isClosed = false; @@ -234,14 +234,14 @@ void libpict::PictSVGGenerator::drawPath(const ::WPXPropertyListVector& path) m_outputSink << "/>\n"; } -void libpict::PictSVGGenerator::drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData& binaryData) +void libpict::PictSVGGenerator::drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData &binaryData) { if (!propList["libpict:mime-type"] || propList["libpict:mime-type"]->getStr().len() <= 0) return; WPXString base64 = binaryData.getBase64Data(); m_outputSink << "<image "; if (propList["svg:x"] && propList["svg:y"] && propList["svg:width"] && propList["svg:height"]) - m_outputSink << "x=\"" << doubleToString(72*(propList["svg:x"]->getDouble())) << "\" y=\"" << doubleToString(72*(propList["svg:y"]->getDouble())) << "\" "; + m_outputSink << "x=\"" << doubleToString(72*(propList["svg:x"]->getDouble())) << "\" y=\"" << doubleToString(72*(propList["svg:y"]->getDouble())) << "\" "; m_outputSink << "width=\"" << doubleToString(72*(propList["svg:width"]->getDouble())) << "\" height=\"" << doubleToString(72*(propList["svg:height"]->getDouble())) << "\" "; m_outputSink << "xlink:href=\"data:" << propList["libpict:mime-type"]->getStr().cstr() << ";base64,"; m_outputSink << base64.cstr(); @@ -252,7 +252,7 @@ void libpict::PictSVGGenerator::startTextObject(const ::WPXPropertyList &propLis { 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 << "x=\"" << doubleToString(72*(propList["svg:x"]->getDouble())) << "\" y=\"" << doubleToString(72*(propList["svg:y"]->getDouble())) << "\">\n"; } void libpict::PictSVGGenerator::endTextObject() @@ -331,8 +331,8 @@ void libpict::PictSVGGenerator::writeStyle(bool /* isClosed */) if(m_style["draw:fill"] && m_style["draw:fill"]->getStr() == "gradient") m_outputSink << "fill: url(#grad" << m_gradientIndex-1 << "); "; - if(m_style["draw:fill"] && m_style["draw:fill"]->getStr() == "gradient") - m_outputSink << "fill: url(#grad" << m_gradientIndex-1 << "); "; + if(m_style["draw:fill"] && m_style["draw:fill"]->getStr() == "gradient") + m_outputSink << "fill: url(#grad" << m_gradientIndex-1 << "); "; if(m_style["draw:fill"] && m_style["draw:fill"]->getStr() == "solid") if (m_style["draw:fill-color"]) diff --git a/src/lib/PictSVGGenerator.h b/src/lib/PictSVGGenerator.h index 2053a6e..9541f66 100644 --- a/src/lib/PictSVGGenerator.h +++ b/src/lib/PictSVGGenerator.h @@ -36,14 +36,15 @@ namespace libpict { -class PictSVGGenerator : public libwpg::WPGPaintInterface { +class PictSVGGenerator : public libwpg::WPGPaintInterface +{ public: - PictSVGGenerator(std::ostream & output_sink); + PictSVGGenerator(std::ostream &output_sink); ~PictSVGGenerator(); void startGraphics(const ::WPXPropertyList &propList); void endGraphics(); - void startLayer(const ::WPXPropertyList& propList); + void startLayer(const ::WPXPropertyList &propList); void endLayer(); void startEmbeddedGraphics(const ::WPXPropertyList & /*propList*/) {} void endEmbeddedGraphics() {} @@ -69,9 +70,9 @@ private: ::WPXPropertyList m_style; int m_gradientIndex; void writeStyle(bool isClosed=true); - void drawPolySomething(const ::WPXPropertyListVector& vertices, bool isClosed); + void drawPolySomething(const ::WPXPropertyListVector &vertices, bool isClosed); - std::ostream & m_outputSink; + std::ostream &m_outputSink; }; } // namespace libpict diff --git a/src/lib/PictXParser.cpp b/src/lib/PictXParser.cpp index 7d92112..65c0b98 100644 --- a/src/lib/PictXParser.cpp +++ b/src/lib/PictXParser.cpp @@ -12,22 +12,22 @@ * 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, + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02111-1301 USA */ - + #include "PictXParser.h" #include "libpict_utils.h" -PictXParser::PictXParser(WPXInputStream *input, libwpg::WPGPaintInterface* painter): - m_input(input), m_painter(painter), m_colorPalette(std::map<int,libpict::PictColor>()) +PictXParser::PictXParser(WPXInputStream *input, libwpg::WPGPaintInterface *painter): + m_input(input), m_painter(painter), m_colorPalette(std::map<int,libpict::PictColor>()) { } -PictXParser::PictXParser(const PictXParser& parser): - m_input(parser.m_input), m_painter(parser.m_painter), - m_colorPalette(parser.m_colorPalette) +PictXParser::PictXParser(const PictXParser &parser): + m_input(parser.m_input), m_painter(parser.m_painter), + m_colorPalette(parser.m_colorPalette) { } @@ -36,8 +36,8 @@ unsigned char PictXParser::readU8() if (!m_input || m_input->atEOS()) return (unsigned char)0; unsigned long numBytesRead; - unsigned char const * p = m_input->read(sizeof(unsigned char), numBytesRead); - + unsigned char const *p = m_input->read(sizeof(unsigned char), numBytesRead); + if (p && numBytesRead == 1) return *(unsigned char const *)(p); return (unsigned char)0; @@ -74,28 +74,34 @@ unsigned PictXParser::readVariableLengthInteger() // read a byte unsigned char value8 = readU8(); // if it's in the range 0-0xFE, then we have a 8-bit value - if (value8<=0xFE) { + if (value8<=0xFE) + { return (unsigned)value8; - } else { + } + else + { // now read a 16 bit value unsigned short value16 = readU16(); // if the MSB is 1, we have a 32 bit value - if (value16>>15) { + if (value16>>15) + { // read the next 16 bit value (LSB part, in value16 resides the MSB part) unsigned long lvalue16 = readU16(); unsigned long value32 = value16 & 0x7fff; // mask out the MSB return (value32<<16)+lvalue16; - } else { + } + else + { // we have a 16 bit value, return it return (unsigned)value16; } } } -PictXParser& PictXParser::operator=(const PictXParser& parser) +PictXParser &PictXParser::operator=(const PictXParser &parser) { - m_input = parser.m_input; - m_painter = parser.m_painter; - m_colorPalette = parser.m_colorPalette; - return *this; + m_input = parser.m_input; + m_painter = parser.m_painter; + m_colorPalette = parser.m_colorPalette; + return *this; } diff --git a/src/lib/PictXParser.h b/src/lib/PictXParser.h index d5e1a47..e9bd541 100644 --- a/src/lib/PictXParser.h +++ b/src/lib/PictXParser.h @@ -14,8 +14,8 @@ * 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, + * 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://libpict.sourceforge.net @@ -38,22 +38,22 @@ class PictXParser { public: - PictXParser(WPXInputStream *input, libwpg::WPGPaintInterface* painter); - PictXParser(const PictXParser& parser); + PictXParser(WPXInputStream *input, libwpg::WPGPaintInterface *painter); + PictXParser(const PictXParser &parser); virtual ~PictXParser() {}; virtual bool parse() = 0; - + unsigned char readU8(); - unsigned short readU16(); - unsigned readU32(); - short readS16(); - int readS32(); + unsigned short readU16(); + unsigned readU32(); + short readS16(); + int readS32(); unsigned readVariableLengthInteger(); - PictXParser& operator=(const PictXParser& parser); + PictXParser &operator=(const PictXParser &parser); protected: - WPXInputStream* m_input; - libwpg::WPGPaintInterface* m_painter; + WPXInputStream *m_input; + libwpg::WPGPaintInterface *m_painter; std::map<int,libpict::PictColor> m_colorPalette; }; diff --git a/src/lib/libpict_utils.h b/src/lib/libpict_utils.h index 8a88201..3f9ee7f 100644 --- a/src/lib/libpict_utils.h +++ b/src/lib/libpict_utils.h @@ -12,8 +12,8 @@ * 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, + * 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://libpict.sourceforge.net @@ -35,16 +35,16 @@ // do nothing with debug messages in a release compile #ifdef DEBUG - #ifdef VERBOSE_DEBUG - #define PICT_DEBUG_MSG(M) printf("%15s:%5d: ", __FILE__, __LINE__); printf M - #define Pict_DEBUG(M) M - #else - #define PICT_DEBUG_MSG(M) printf M - #define Pict_DEBUG(M) M - #endif +#ifdef VERBOSE_DEBUG +#define PICT_DEBUG_MSG(M) printf("%15s:%5d: ", __FILE__, __LINE__); printf M +#define Pict_DEBUG(M) M #else - #define PICT_DEBUG_MSG(M) - #define Pict_DEBUG(M) +#define PICT_DEBUG_MSG(M) printf M +#define Pict_DEBUG(M) M +#endif +#else +#define PICT_DEBUG_MSG(M) +#define Pict_DEBUG(M) #endif #endif // __LIBPict_UTILS_H__ |