diff options
author | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2011-01-16 12:13:26 +0100 |
---|---|---|
committer | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2011-01-16 12:13:26 +0100 |
commit | eea7c03648d372755adace1f57bc88cb78a50f53 (patch) | |
tree | 54d8d916d2f1a383281cd87772531270285b2422 | |
parent | 3c7c50b77bfe4256bbe381937f944ce3b1815b19 (diff) |
Initial opcodes for Pict2 file-format
-rw-r--r-- | src/lib/Pict2Parser.cpp | 2465 | ||||
-rw-r--r-- | src/lib/Pict2Parser.h | 333 |
2 files changed, 534 insertions, 2264 deletions
diff --git a/src/lib/Pict2Parser.cpp b/src/lib/Pict2Parser.cpp index 0e43205..e3ef5fa 100644 --- a/src/lib/Pict2Parser.cpp +++ b/src/lib/Pict2Parser.cpp @@ -27,253 +27,13 @@ #include "Pict2Parser.h" #include "libpict_utils.h" - +#include <libwpd/libwpd.h> #include <libwpg/libwpg.h> -#include <math.h> -#include <vector> - -// MSVC++ 6.0 does not have the macro defined, so we define it -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -#define DUMP_BINARY_DATA 0 -#if DUMP_BINARY_DATA -#include <sstream> -#endif - -namespace { - -static double fixedPointToDouble(const unsigned int fixedPointNumber) -{ - short fixedPointNumberIntegerPart = (short)((fixedPointNumber & 0xFFFF0000) >> 16); - double fixedPointNumberFractionalPart = (double)((double)(fixedPointNumber & 0x0000FFFF)/(double)0xFFFF); - return ((fixedPointNumberIntegerPart >= 0) ? - ((double)fixedPointNumberIntegerPart + fixedPointNumberFractionalPart) : - ((double)fixedPointNumberIntegerPart - fixedPointNumberFractionalPart)); -} -} - -static const unsigned char defaultPict2PaletteRed[] = { - 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 unsigned char defaultPict2PaletteGreen[] = { - 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 unsigned char defaultPict2PaletteBlue[] = { - 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, -}; - -class Pict2Parser::ObjectCharacterization -{ -public: - bool taper; - bool translate; - bool skew; - bool scale; - bool rotate; - bool hasObjectId; - bool editLock; - bool windingRule; - bool filled; - bool closed; - bool framed; - - unsigned long objectId; - unsigned long lockFlags; - double rotationAngle; - long sxcos; - long sycos; - long kxsin; - long kysin; - long txinteger; - unsigned short txfraction; - long tyinteger; - unsigned short tyfraction; - long px; - long py; - - Pict2TransformMatrix matrix; - - ObjectCharacterization(): - taper(false), - translate(false), - skew(false), - scale(false), - rotate(false), - hasObjectId(false), - editLock(false), - windingRule(false), - filled(false), - closed(false), - framed(true), - objectId(0), - lockFlags(0), - rotationAngle(0.0), - sxcos(0), - sycos(0), - kxsin(0), - kysin(0), - txinteger(0), - txfraction(0), - tyinteger(0), - tyfraction(0), - px(0), - py(0), - matrix() - {} -}; - -Pict2Parser::Pict2Parser(WPXInputStream *input, libwpg::WPGPaintInterface* painter, bool isEmbedded): +Pict2Parser::Pict2Parser(WPXInputStream *input, libwpg::WPGPaintInterface* painter): PictXParser(input, painter), - m_recordLength(0), - m_recordEnd(0), - m_success(true), m_exit(false), m_graphicsStarted(isEmbedded), - m_xres(1200), m_yres(1200), - m_xofs(0), m_yofs(0), - m_width(0), m_height(0), - m_doublePrecision(false), - m_style(), - m_penForeColor(0,0,0), - m_penBackColor(0xff,0xff,0xff), - m_brushForeColor(0,0,0), - m_brushBackColor(0xff,0xff,0xff), - m_dashArray(), - m_gradient(), - m_dashArrayStyles(), - m_layerOpened(false), m_layerId(0), - m_matrix(), - m_gradientAngle(0.0), - m_gradientRef(), - m_groupStack(), - m_compoundMatrix(), - m_compoundWindingRule(false), - m_compoundFilled(false), - m_compoundFramed(true), - m_compoundClosed(false), - m_bitmap(), - m_binaryData(), - m_hFlipped(false), - m_vFlipped(false), - m_textData(), - m_drawTextData(false), - m_binaryId(0), - m_embedded(isEmbedded) -{ - m_style.insert("draw:fill", "solid"); - // default style - m_penForeColor = ::libpict::PictColor(0,0,0); - m_penBackColor = ::libpict::PictColor(0xff,0xff,0xff); - m_style.insert("svg:stroke-width", 0.001); -// m_pen.height = 0.0; - m_style.insert("libpict:stroke-solid", true); - m_dashArray = libpict::PictDashArray(); - m_brushForeColor = ::libpict::PictColor(0,0,0); - m_brushBackColor = ::libpict::PictColor(0xff,0xff,0xff); - - m_style.insert("svg:stroke-color", m_penForeColor.getColorString()); - m_style.insert("svg:stroke-opacity", m_penForeColor.getOpacity(), WPX_PERCENT); - m_style.insert("draw:fill-color", m_brushForeColor.getColorString()); - m_style.insert("draw:opacity", m_brushForeColor.getOpacity(), WPX_PERCENT); - - resetPalette(); - m_style.insert("draw:fill", "solid"); + m_recordSize(0) +{ } bool Pict2Parser::parse() @@ -285,2008 +45,623 @@ bool Pict2Parser::parse() int type; const char *name; Method handler; + int size; }; static const struct RecordHandler handlers[] = { - { 0x01, "Start Pict", &Pict2Parser::handleStartPict }, - { 0x02, "End Pict", &Pict2Parser::handleEndPict }, - { 0x03, "Form Settings", &Pict2Parser::handleFormSettings }, - { 0x04, "Ruler Settings", 0 }, // ignored - { 0x05, "Grid Settings", 0 }, // ignored - { 0x06, "Layer", &Pict2Parser::handleLayer }, - { 0x08, "Pen Style Definition", &Pict2Parser::handlePenStyleDefinition }, - { 0x09, "Pattern Definition", 0 }, - { 0x0a, "Comment", 0 }, // ignored - { 0x0b, "Color Transfer", 0 }, - { 0x0c, "Color Palette", &Pict2Parser::handleColorPalette }, - { 0x0d, "DP Color Palette", &Pict2Parser::handleDPColorPalette }, - { 0x0e, "Bitmap Data", &Pict2Parser::handleBitmapData }, - { 0x0f, "Text Data", &Pict2Parser::handleTextData }, - { 0x10, "Chart Style", 0 }, // ignored - { 0x11, "Chart Data", 0 }, // ignored - { 0x12, "Object Image", &Pict2Parser::handleObjectImage }, - { 0x15, "Polyline", &Pict2Parser::handlePolyline }, - { 0x16, "Polyspline", &Pict2Parser::handlePolyspline }, - { 0x17, "Polycurve", &Pict2Parser::handlePolycurve }, - { 0x18, "Rectangle", &Pict2Parser::handleRectangle }, - { 0x19, "Arc", &Pict2Parser::handleArc }, - { 0x1a, "Compound Polygon", &Pict2Parser::handleCompoundPolygon }, - { 0x1b, "Bitmap", &Pict2Parser::handleBitmap }, - { 0x1c, "Text Line", &Pict2Parser::handleTextLine }, - { 0x1d, "Text Block", &Pict2Parser::handleTextBlock }, - { 0x1e, "Text Path", &Pict2Parser::handleTextPath }, - { 0x1f, "Chart", 0 }, - { 0x20, "Group", 0 }, - { 0x21, "Object Capsule", &Pict2Parser::handleObjectCapsule }, - { 0x22, "Font Settings", 0 }, - { 0x25, "Pen Fore Color", &Pict2Parser::handlePenForeColor }, - { 0x26, "DP Pen Fore Color", &Pict2Parser::handleDPPenForeColor }, - { 0x27, "Pen Back Color", &Pict2Parser::handlePenBackColor }, - { 0x28, "DP Pen Back Color", &Pict2Parser::handleDPPenBackColor }, - { 0x29, "Pen Style", &Pict2Parser::handlePenStyle }, - { 0x2a, "Pen Pattern", 0 }, - { 0x2b, "Pen Size", &Pict2Parser::handlePenSize }, - { 0x2c, "DP Pen Size", &Pict2Parser::handleDPPenSize }, - { 0x2d, "Line Cap", &Pict2Parser::handleLineCap }, - { 0x2e, "Line Join", &Pict2Parser::handleLineJoin }, - { 0x2f, "Brush Gradient", &Pict2Parser::handleBrushGradient }, - { 0x30, "DP Brush Gradient", &Pict2Parser::handleDPBrushGradient }, - { 0x31, "Brush Fore Color", &Pict2Parser::handleBrushForeColor }, - { 0x32, "DP Brush Fore Color", &Pict2Parser::handleDPBrushForeColor }, - { 0x33, "Brush Back Color", &Pict2Parser::handleBrushBackColor }, - { 0x34, "DP Brush Back Color", &Pict2Parser::handleDPBrushBackColor }, - { 0x35, "Brush Pattern", &Pict2Parser::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 + { 0x00, "NOP", &Pict2Parser::handleNOP, 1 }, + { 0x01, "clipRgn", &Pict2Parser::handleClipRgn, -1 }, + { 0x02, "bkPat", &Pict2Parser::handleBkPat, 9 }, + { 0x03, "txFont", &Pict2Parser::handleTxFont, 3 }, + { 0x04, "txFace", &Pict2Parser::handleTxFace, 2 }, + { 0x05, "txMode", &Pict2Parser::handleTxMode, 3 }, + { 0x06, "spExtra", &Pict2Parser::handleSpExtra, 5 }, + { 0x07, "pnSize", &Pict2Parser::handlePnSize, 5 }, + { 0x08, "pnMode", &Pict2Parser::handlePnMode, 3 }, + { 0x09, "pnPat", &Pict2Parser::handlePnPat, 9 }, + { 0x0a, "thePat", &Pict2Parser::handleThePat, 9 }, + { 0x0b, "owSize", &Pict2Parser::handleOwSize, 5 }, + { 0x0c, "origin", &Pict2Parser::handleOrigin, 5 }, + { 0x0d, "txSize", &Pict2Parser::handleTxSize, 3 }, + { 0x0e, "fgColor", &Pict2Parser::handleFgColor, 5 }, + { 0x0f, "bkColor", &Pict2Parser::handleBkColor, 5 }, + { 0x10, "txRatio", &Pict2Parser::handleTxRatio, 9 }, + { 0x11, "picVersion", &Pict2Parser::handlePicVersion, 2 }, + + { 0x20, "line", &Pict2Parser::handleLine, 9 }, + { 0x21, "line from", &Pict2Parser::handleLineFrom, 5 }, + { 0x22, "short line", &Pict2Parser::handleShortLine, 7 }, + { 0x23, "short line from", &Pict2Parser::handleShortLineFrom, 3 }, + + { 0x28, "long text", &Pict2Parser::handleLongText, -1 }, + { 0x29, "DH text", &Pict2Parser::handleDHText, -1 }, + { 0x2a, "DV text", &Pict2Parser::handleDVText, -1 }, + { 0x2b, "DHDV text", &Pict2Parser::handleDHDVText, -1 }, + + { 0x30, "frameRect", &Pict2Parser::handleFrameRect, 9 }, + { 0x31, "paintRect", &Pict2Parser::handlePaintRect, 9 }, + { 0x32, "eraseRect", &Pict2Parser::handleEraseRect, 9 }, + { 0x33, "invertRect", &Pict2Parser::handleInvertRect, 9 }, + { 0x34, "fillRect", &Pict2Parser::handleFillRect, 9 }, + + { 0x38, "frameSameRect", &Pict2Parser::handleFrameSameRect, 1 }, + { 0x39, "paintSameRect", &Pict2Parser::handlePaintSameRect, 1 }, + { 0x3a, "eraseSameRect", &Pict2Parser::handleEraseSameRect, 1 }, + { 0x3b, "invertSameRect", &Pict2Parser::handleInvertSameRect, 1 }, + { 0x3c, "fillSameRect", &Pict2Parser::handleFillSameRect, 1 }, + + { 0x40, "frameRRect", &Pict2Parser::handleFrameRRect, 9 }, + { 0x41, "paintRRect", &Pict2Parser::handlePaintRRect, 9 }, + { 0x42, "eraseRRect", &Pict2Parser::handleEraseRRect, 9 }, + { 0x43, "invertRRect", &Pict2Parser::handleInvertRRect, 9 }, + { 0x44, "fillRRect", &Pict2Parser::handleFillRRect, 9 }, + + { 0x48, "frameSameRRect", &Pict2Parser::handleFrameSameRRect, 1 }, + { 0x49, "paintSameRRect", &Pict2Parser::handlePaintSameRRect, 1 }, + { 0x4a, "eraseSameRRect", &Pict2Parser::handleEraseSameRRect, 1 }, + { 0x4b, "invertSameRRect", &Pict2Parser::handleInvertSameRRect, 1 }, + { 0x4c, "fillSameRRect", &Pict2Parser::handleFillSameRRect, 1 }, + + { 0x50, "frameOval", &Pict2Parser::handleFrameOval, 9 }, + { 0x51, "paintOval", &Pict2Parser::handlePaintOval, 9 }, + { 0x52, "eraseOval", &Pict2Parser::handleEraseOval, 9 }, + { 0x53, "invertOval", &Pict2Parser::handleInsertOval, 9 }, + { 0x54, "fillOval", &Pict2Parser::handleFillOval, 9 }, + + { 0x58, "frameSameOval", &Pict2Parser::handleFrameSameOval, 1 }, + { 0x59, "paintSameOval", &Pict2Parser::handlePaintSameOval, 1 }, + { 0x5a, "eraseSameOval", &Pict2Parser::handleEraseSameOval, 1 }, + { 0x5b, "invertSameOval", &Pict2Parser::handleInsertSameOval, 1 }, + { 0x5c, "fillSameOval", &Pict2Parser::handleFillSameOval, 1 }, + + { 0x60, "frameArc", &Pict2Parser::handleFrameArc, 13 }, + { 0x61, "paintArc", &Pict2Parser::handlePaintArc, 13 }, + { 0x62, "eraseArc", &Pict2Parser::handleEraseArc, 13 }, + { 0x63, "invertArc", &Pict2Parser::handleInsertArc, 13 }, + { 0x64, "fillArc", &Pict2Parser::handleFillArc, 13 }, + + { 0x68, "frameSameArc", &Pict2Parser::handleFrameSameArc, 5 }, + { 0x69, "paintSameArc", &Pict2Parser::handlePaintSameArc, 5 }, + { 0x6a, "eraseSameArc", &Pict2Parser::handleEraseSameArc, 5 }, + { 0x6b, "inverSameArc", &Pict2Parser::handleInsertSameArc, 5 }, + { 0x6c, "fillSameArc", &Pict2Parser::handleFillSameArc, 5 }, + + { 0x70, "framePoly", &Pict2Parser::handleFramePoly, -1 }, + { 0x71, "paintPoly", &Pict2Parser::handlePaintPoly, -1 }, + { 0x72, "erasePoly", &Pict2Parser::handleErasePoly, -1 }, + { 0x73, "invertPoly", &Pict2Parser::handleInvertPoly, -1 }, + { 0x74, "fillPoly", &Pict2Parser::handleFillPoly, -1 }, + + { 0x78, "frameSamePoly", &Pict2Parser::handleFrameSamePoly, 1 }, + { 0x79, "paintSamePoly", &Pict2Parser::handlePaintSamePoly, 1 }, + { 0x7a, "eraseSamePoly", &Pict2Parser::handleEraseSamePoly, 1 }, + { 0x7b, "invertSamePoly", &Pict2Parser::handleInvertSamePoly, 1 }, + { 0x7c, "fillSamePoly", &Pict2Parser::handleFillSamePoly, 1 }, + + { 0x80, "frameRgn", &Pict2Parser::handleFrameRgn, -1 }, + { 0x81, "paintRgn", &Pict2Parser::handlePaintRgn, -1 }, + { 0x82, "eraseRgn", &Pict2Parser::handleEraseRgn, -1 }, + { 0x83, "invertRgn", &Pict2Parser::handleInvertRgn, -1 }, + { 0x84, "fillRgn", &Pict2Parser::handleFillRgn, -1 }, + + { 0x88, "frameSameRgn", &Pict2Parser::handleFrameSameRgn, 1 }, + { 0x89, "paintSameRgn", &Pict2Parser::handlePaintSameRgn, 1 }, + { 0x8a, "eraseSameRgn", &Pict2Parser::handleEraseSameRgn, 1 }, + { 0x8b, "invertSameRgn", &Pict2Parser::handleInvertSameRgn, 1 }, + { 0x8c, "fillSameRgn", &Pict2Parser::handleFillSameRgn, 1 }, + + { 0x90, "BitsRect", &Pict2Parser::handleBitsRect, -1 }, + { 0x91, "BitsRgn", &Pict2Parser::handleBitsRgn, -1 }, + + { 0x98, "PackBitsRect", &Pict2Parser::handlePackBitsRect, -1 }, + { 0x99, "PackBitsRgn", &Pict2Parser::handlePackBitsRgn, -1 }, + + { 0xa0, "shortComment", &Pict2Parser::handleShortComment, 3 }, + { 0xa1, "longComment", &Pict2Parser::handleLongComment, -1 }, + + { 0xff, "EndOfPicture", &Pict2Parser::handleEndOfPicture, 1 } }; while(!m_input->atEOS()) { -#ifdef DEBUG - long recordPos = m_input->tell(); -#endif - readU8(); - int recordType = readU8(); - if (recordType == 0 || recordType > (int)0x3f) + long initialPosition = m_input->tell(); + // Opcodes are aligned to 2 bytes + if (initialPosition % 2) + m_input->seek((int)(++initialPosition), WPX_SEEK_SET); + int recordType = readU16(); + if (recordType == 0x00ff) break; - int extension = readVariableLengthInteger(); - m_recordLength = readVariableLengthInteger(); - m_recordEnd = m_input->tell() + m_recordLength - 1; - - // inside a subgroup, one less sub record - if(!m_groupStack.empty()) - m_groupStack.top().subIndex--; // search function to handler this record int index = -1; - for(int i = 0; (index < 0) && handlers[i].name; i++) + for(int i=0; i < (int)(sizeof(handlers)/sizeof(RecordHandler)); i++) + { if(handlers[i].type == recordType) + { index = i; - - PICT_DEBUG_MSG(("\n")); - if(index < 0) - { - PICT_DEBUG_MSG(("Unknown record type 0x%02x at %li size %d extension %d\n", - recordType, recordPos, m_recordLength, extension)); + break; + } } - else + + if(index >= 0) { + PICT_DEBUG_MSG(("Position: 0x%.8x, Opcode: 0x%.2x, Opcode Name: %s\n", (int)initialPosition, recordType, handlers[index].name)); + m_recordSize = handlers[index].size; Method recordHandler = handlers[index].handler; - - if(!recordHandler) - PICT_DEBUG_MSG(("Record '%s' (ignored) type 0x%02x at %li size %d extension %d\n", - handlers[index].name, recordType, recordPos, m_recordLength, extension)); - else + if(recordHandler) { - PICT_DEBUG_MSG(("Record '%s' type 0x%02x at %li size %d extension %d\n", - handlers[index].name, recordType, recordPos, m_recordLength, extension)); - // invoke the handler for this record (this->*recordHandler)(); } - } - - // the last subgroup - if(!m_groupStack.empty()) - { - PictGroupContext& context = m_groupStack.top(); - if(context.subIndex == 0) - { - if(context.isCompoundPolygon()) - flushCompoundPolygon(); - m_groupStack.pop(); - } - } - - // we enter another subgroup, save the context to stack - if(extension > 0) - { - PictGroupContext context; - context.parentType = recordType; - context.subIndex = extension; - if(context.isCompoundPolygon()) + if (m_recordSize <= 0) // we were not able to compute variable record size + return false; + else { - context.compoundMatrix = m_compoundMatrix; - context.compoundFilled = m_compoundFilled; - context.compoundFramed = m_compoundFramed; - context.compoundClosed = m_compoundClosed; + m_input->seek(initialPosition + m_recordSize, WPX_SEEK_SET); + m_recordSize = 0; } - m_groupStack.push(context); - } - - //if(m_input->tell() > m_recordEnd+1) - { - //PICT_DEBUG_MSG(("Record 0x%x consumes more bytes than necessary!\n", recordType)); - PICT_DEBUG_MSG(("Current stream position: %li\n", m_input->tell())); } - - if(m_exit) break; - - m_input->seek(m_recordEnd+1, WPX_SEEK_SET); + else + return false; } - - if (!m_exit) - handleEndPict(); - - return m_success; + return true; } -#ifdef DEBUG -static const char* describePrecision(unsigned char precision) +void Pict2Parser::handleNOP() { - 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) +void Pict2Parser::handleClipRgn() { - 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; + m_recordSize = (int)readU16() + 1; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); } -#endif - -#define TO_DOUBLE(x) ( (m_doublePrecision) ? ((double)(x)/65536.0) : (double)(x) ) -#define TRANSFORM_XY(x,y) { m_matrix.transform((x),(y)); (x)-= m_xofs; (y)-= m_yofs; (y)=m_height-(y); } -void Pict2Parser::handleStartPict() +void Pict2Parser::handleBkPat() { - if (m_graphicsStarted) // second start pict in the document == possible corruption, bail out - { - handleEndPict(); - return; - } - - 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; - PICT_DEBUG_MSG(("Warning ! Insane unit of measure")); - } - - // danger if we do not recognize the precision code - if(precision != 0 && precision != 1) - { - m_success = false; - m_exit = true; - return; - } - m_doublePrecision = (precision == 1); - -#ifdef DEBUG - long viewportX1 = (m_doublePrecision) ? readS32() : readS16(); - long viewportY1 = (m_doublePrecision) ? readS32() : readS16(); - long viewportX2 = (m_doublePrecision) ? readS32() : readS16(); - long viewportY2 = (m_doublePrecision) ? readS32() : readS16(); -#else - m_input->seek(((m_doublePrecision) ? 16 : 8), WPX_SEEK_CUR); -#endif - long imageX1 = (m_doublePrecision) ? readS32() : readS16(); - long imageY1 = (m_doublePrecision) ? readS32() : readS16(); - long imageX2 = (m_doublePrecision) ? readS32() : readS16(); - long imageY2 = (m_doublePrecision) ? readS32() : readS16(); - - // used to adjust coordinates - m_xofs = (imageX1 < imageX2) ? imageX1 : imageX2; - m_yofs = (imageY1 < imageY2) ? imageY1 : imageX2; - m_width = (imageX2 > imageX1 ) ? imageX2-imageX1 : imageX1-imageX2; - m_height = (imageY2 > imageY1) ? imageY2-imageY1 : imageY1-imageY2; - - PICT_DEBUG_MSG(("StartPict 2\n")); - PICT_DEBUG_MSG((" Horizontal unit of measure : %d pixels/inch\n", horizontalUnit)); - PICT_DEBUG_MSG((" Vertical unit of measure : %d pixels/inch\n", verticalUnit)); - PICT_DEBUG_MSG((" Data precision : %d (%s)\n", precision, describePrecision(precision))); - PICT_DEBUG_MSG((" Viewport X1 : %li\n", viewportX1)); - PICT_DEBUG_MSG((" Viewport Y1 : %li\n", viewportY1)); - PICT_DEBUG_MSG((" Viewport X2 : %li\n", viewportX2)); - PICT_DEBUG_MSG((" Viewport Y2 : %li\n", viewportY2)); - PICT_DEBUG_MSG((" Image X1 : %li\n", imageX1)); - PICT_DEBUG_MSG((" Image Y1 : %li\n", imageY1)); - PICT_DEBUG_MSG((" Image X2 : %li\n", imageX2)); - PICT_DEBUG_MSG((" Image Y2 : %li\n", imageY2)); - PICT_DEBUG_MSG((" X offset : %li\n", m_xofs)); - PICT_DEBUG_MSG((" Y offset : %li\n", m_yofs)); - PICT_DEBUG_MSG((" width : %li\n", m_width)); - PICT_DEBUG_MSG((" height : %li\n", m_height)); - - ::WPXPropertyList propList; - propList.insert("svg:width", ((TO_DOUBLE(m_width)) / m_xres)); - propList.insert("svg:height", ((TO_DOUBLE(m_height)) / m_yres)); - - m_painter->startGraphics(propList); - - static const int Pict2_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; (long)i < (long)(sizeof(Pict2_defaultPenDashes)/sizeof(Pict2_defaultPenDashes[0]));) - { - int segments = 2 * Pict2_defaultPenDashes[i++]; - if(segments == 0) break; - libpict::PictDashArray dashArray; - for(int j = 0; j < segments; j++, i++) - dashArray.add(Pict2_defaultPenDashes[i]*3.6/218.0); - m_dashArrayStyles[styleNo] = dashArray; - styleNo++; - } - m_graphicsStarted = true; } -void Pict2Parser::handleEndPict() +void Pict2Parser::handleTxFont() { - if (!m_graphicsStarted) - return; - // sentinel - if(m_layerOpened) - m_painter->endLayer(); - - m_painter->endGraphics(); - m_exit = true; } -void Pict2Parser::handleFormSettings() +void Pict2Parser::handleTxFace() { -#ifdef DEBUG - unsigned int w = (m_doublePrecision) ? readU32() : readU16(); - unsigned int h = (m_doublePrecision) ? readU32() : readU16(); - double width = (TO_DOUBLE(w)) / m_xres; - double height = (TO_DOUBLE(h)) / m_yres; - m_input->seek(((m_doublePrecision) ? 4 : 2), WPX_SEEK_CUR); - unsigned int ml = (m_doublePrecision) ? readU32() : readU16(); - unsigned int mr = (m_doublePrecision) ? readU32() : readU16(); - unsigned int mt = (m_doublePrecision) ? readU32() : readU16(); - unsigned int mb = (m_doublePrecision) ? readU32() : readU16(); - double margL = (TO_DOUBLE(ml)) / m_xres; - double margR = (TO_DOUBLE(mr)) / m_xres; - double margT = (TO_DOUBLE(mt)) / m_xres; - double margB = (TO_DOUBLE(mb)) / m_xres; - - PICT_DEBUG_MSG(("Form Settings: width: %f height : %f\n", width, height)); - PICT_DEBUG_MSG(("Form Margins: left: %f right : %f top: %f bottom: %f\n", margL, margR, margT, margB)); -#endif } -void Pict2Parser::handleLayer() +void Pict2Parser::handleTxMode() { - if (!m_graphicsStarted) - return; - WPXPropertyList propList; - propList.insert("svg:id", (int)readU16()); - - // close previous one - if(m_layerOpened) - m_painter->endLayer(); - - m_painter->startLayer(propList); - m_layerOpened = true; - - PICT_DEBUG_MSG((" Layer Id: %d\n", m_layerId)); } -void Pict2Parser::handleCompoundPolygon() +void Pict2Parser::handleSpExtra() { - if (!m_graphicsStarted) - return; - ObjectCharacterization objCh; - parseCharacterization(&objCh); - - m_compoundWindingRule = objCh.windingRule; - m_compoundMatrix = objCh.matrix; - m_compoundFilled = objCh.filled; - m_compoundFramed = objCh.framed; - m_compoundClosed = objCh.closed; } -void Pict2Parser::flushCompoundPolygon() +void Pict2Parser::handlePnSize() { - if (!m_graphicsStarted) - return; - PictGroupContext& context = m_groupStack.top(); - - WPXPropertyList tmpStyle = m_style; - - if (!context.compoundFilled) - tmpStyle.insert("draw:fill", "none"); - - if(context.compoundWindingRule) - tmpStyle.insert("svg:fill-rule", "nonzero"); - else - tmpStyle.insert("svg:fill-rule", "evenodd"); - - m_painter->setStyle( tmpStyle, context.compoundFilled ? m_gradient : ::WPXPropertyListVector() ); - - if (context.compoundClosed) - { - WPXPropertyList element; - element.insert("libpict:path-action", "Z"); - context.compoundPath.append(element); - } - m_painter->drawPath(context.compoundPath); } -void Pict2Parser::handlePenStyleDefinition() +void Pict2Parser::handlePnMode() { - if (!m_graphicsStarted) - return; - unsigned int style = readU16(); - unsigned int segments = readU16(); - - libpict::PictDashArray dashArray; - for(unsigned 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_dashArrayStyles[style] = dashArray; - - PICT_DEBUG_MSG((" Style : %d\n", style)); - PICT_DEBUG_MSG((" Segment pairs : %d\n", segments)); } -#if 0 -// TODO -void Pict2Parser::handlePatternDefinition() +void Pict2Parser::handlePnPat() { - if (!m_graphicsStarted) - return; - PICT_DEBUG_MSG(("PatternDefinition\n")); } -#endif -void Pict2Parser::handleColorPalette() +void Pict2Parser::handleThePat() { - if (!m_graphicsStarted) - return; - unsigned startIndex = readU16(); - unsigned numEntries = readU16(); - - for(unsigned i = 0; i < numEntries; i++) - { - unsigned char red = readU8(); - unsigned char green = readU8(); - unsigned char blue = readU8(); - unsigned char alpha = 0xff - readU8(); - libpict::PictColor color(red, green, blue, alpha); - m_colorPalette[startIndex+i] = color; - PICT_DEBUG_MSG(("Index#%d: RGB %s\n", startIndex+i, color.getColorString().cstr())); - } } -void Pict2Parser::handleDPColorPalette() +void Pict2Parser::handleOwSize() { - if (!m_graphicsStarted) - return; - unsigned startIndex = readU16(); - unsigned numEntries = readU16(); - - for(unsigned int i = 0; i < numEntries; i++) - { - unsigned char red = readU16() >> 8 ; - unsigned char green = readU16() >> 8 ; - unsigned char blue = readU16() >> 8 ; - unsigned char alpha = 0xff - (readU16() >> 8) ; - libpict::PictColor color(red, green, blue, alpha); - m_colorPalette[startIndex+i] = color; - PICT_DEBUG_MSG(("Index#%d: RGB %s\n", startIndex+i, color.getColorString().cstr())); - } } -void Pict2Parser::handlePenForeColor() +void Pict2Parser::handleOrigin() { - if (!m_graphicsStarted) - return; - if(!m_groupStack.empty()) - { - if (m_groupStack.top().isCompoundPolygon()) - return; - if (m_groupStack.top().parentType == 0x01) // we don't handle Page Attributes for now - return; - } - unsigned char red = readU8(); - unsigned char green = readU8(); - unsigned char blue = readU8(); - unsigned char alpha = 0xff - readU8(); - - m_penForeColor = libpict::PictColor(red, green, blue, alpha); - - PICT_DEBUG_MSG((" Foreground color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); } -void Pict2Parser::handleDPPenForeColor() +void Pict2Parser::handleTxSize() { - if (!m_graphicsStarted) - return; - if(!m_groupStack.empty()) - { - if (m_groupStack.top().isCompoundPolygon()) - return; - if (m_groupStack.top().parentType == 0x01) // we don't handle Page Attributes for now - return; - } - // we just ignore the least significant 8 bits - unsigned char red = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned char green = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned char blue = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned char alpha = 0xff - (m_doublePrecision) ? readU16()>>8 : readU8(); - - m_style.insert("svg:stroke-color", libpict::PictColor(red, green, blue, alpha).getColorString()); - m_style.insert("svg:stroke-opacity", libpict::PictColor(red, green, blue, alpha).getOpacity(), WPX_PERCENT); - m_penForeColor = libpict::PictColor(red, green, blue, alpha); - - PICT_DEBUG_MSG((" Foreground color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); } -void Pict2Parser::handlePenBackColor() +void Pict2Parser::handleFgColor() { - if (!m_graphicsStarted) - return; - if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon()) - return; -#if 0 - unsigned char red = readU8(); - unsigned char green = readU8(); - unsigned char blue = readU8(); - unsigned char alpha = 0xff - readU8(); - - m_penBackColor = libpict::PictColor(red, green, blue, alpha); - - m_dashArray.backColor = libpict::PictColor(red, green, blue, alpha); - m_style.insert("svg:stroke-color", m_penForeColor.getColorString()); - m_style.insert("svg:stroke-opacity", m_penForeColor.getOpacity(), WPX_PERCENT); - - PICT_DEBUG_MSG((" Background color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); -#endif } -void Pict2Parser::handleDPPenBackColor() +void Pict2Parser::handleBkColor() { - if (!m_graphicsStarted) - return; - if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon()) - return; -#if 0 - // we just ignore the least significant 8 bits - unsigned int red = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned int green = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned int blue = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned int alpha = 0xff - (m_doublePrecision) ? readU16()>>8 : readU8(); - - m_penBackColor = libpict::PictColor(red, green, blue, alpha); - - m_dashArray.backColor = libpict::PictColor(red, green, blue, alpha); - m_style.insert("svg:stroke-color", m_penForeColor.getColorString()); - m_style.insert("svg:stroke-opacity", m_penForeColor.getOpacity(), WPX_PERCENT); - - PICT_DEBUG_MSG((" Background color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); -#endif } -void Pict2Parser::handlePenStyle() +void Pict2Parser::handleTxRatio() { - if (!m_graphicsStarted) - return; - if(!m_groupStack.empty()) - { - if (m_groupStack.top().isCompoundPolygon()) - return; - if (m_groupStack.top().parentType == 0x01) // we don't handle Page Attributes for now - return; - } - unsigned int style = readU16(); - - m_dashArray = m_dashArrayStyles[style]; - - if (!style) - m_style.insert("draw:stroke", "solid"); - - PICT_DEBUG_MSG((" Pen style : %d\n", style)); - PICT_DEBUG_MSG((" Segments : %d\n", m_dashArray.count())); } -void Pict2Parser::handlePenSize() +void Pict2Parser::handlePicVersion() { - if (!m_graphicsStarted) - return; - if(!m_groupStack.empty()) - { - if (m_groupStack.top().isCompoundPolygon()) - return; - if (m_groupStack.top().parentType == 0x01) // we don't handle Page Attributes for now - return; - } - unsigned int width = readU16(); - - m_style.insert("svg:stroke-width", (TO_DOUBLE(width) / m_xres)); - - PICT_DEBUG_MSG((" Width: %d\n", width)); } -void Pict2Parser::handleDPPenSize() +void Pict2Parser::handleLine() { - if (!m_graphicsStarted) - return; - if(!m_groupStack.empty()) - { - if (m_groupStack.top().isCompoundPolygon()) - return; - if (m_groupStack.top().parentType == 0x01) // we don't handle Page Attributes for now - return; - } - unsigned long width = readU32(); - - m_style.insert("svg:stroke-width", TO_DOUBLE(width) / m_xres / 256); -// m_pen.height = TO_DOUBLE(height) / m_yres / 256; - - PICT_DEBUG_MSG((" Width: %li\n", width)); } -void Pict2Parser::handleLineCap() +void Pict2Parser::handleLineFrom() { - if (!m_graphicsStarted) - return; - if(!m_groupStack.empty()) - { - if (m_groupStack.top().isCompoundPolygon()) - return; - if (m_groupStack.top().parentType == 0x01) // we don't handle Page Attributes for now - return; - } -// PICT_DEBUG_MSG((" Line cap : %d\n", style)); } -void Pict2Parser::handleLineJoin() +void Pict2Parser::handleShortLine() { - if (!m_graphicsStarted) - return; - if(!m_groupStack.empty()) - { - if (m_groupStack.top().isCompoundPolygon()) - return; - if (m_groupStack.top().parentType == 0x01) // we don't handle Page Attributes for now - return; - } -// PICT_DEBUG_MSG((" Line join : %d\n", style)); } -void Pict2Parser::handleBrushGradient() +void Pict2Parser::handleShortLineFrom() { - if (!m_graphicsStarted) - return; - if(!m_groupStack.empty()) - { - if (m_groupStack.top().isCompoundPolygon()) - return; - if (m_groupStack.top().parentType == 0x01) // we don't handle Page Attributes for now - return; - } - unsigned angleFraction = readU16(); - unsigned angleInteger = readU16(); - unsigned xref = readU16(); - unsigned yref = readU16(); -#ifdef DEBUG - unsigned flag = readU16(); - bool granular = ((flag & (1<<6))>>6) == 1; - bool anchor = ((flag & (1<<7))>>7) == 1; -#else - readU16(); -#endif - - // TODO: get gradient extent - - m_gradientAngle = angleInteger + (double)angleFraction/65536.0; - m_gradientRef.insert("svg:x", (double)xref); - m_gradientRef.insert("svg:y", (double)yref); - - PICT_DEBUG_MSG((" Gradient angle : %d.%d\n", angleInteger, angleFraction)); - PICT_DEBUG_MSG((" Gradient reference : %d.%d\n", xref, yref)); - PICT_DEBUG_MSG((" Granular : %s\n", (granular ? "yes" : "no"))); - PICT_DEBUG_MSG((" Anchored : %s\n", (anchor ? "yes" : "no"))); } -void Pict2Parser::handleDPBrushGradient() +void Pict2Parser::handleLongText() { - if (!m_graphicsStarted) - return; - if(!m_groupStack.empty()) - { - if (m_groupStack.top().isCompoundPolygon()) - return; - if (m_groupStack.top().parentType == 0x01) // we don't handle Page Attributes for now - return; - } - unsigned angleFraction = readU16(); - unsigned angleInteger = readU16(); - unsigned xref = readU16(); - unsigned yref = readU16(); -#ifdef DEBUG - unsigned flag = readU16(); - bool granular = (flag & (1<<6)) == 1; - bool anchor = (flag & (1<<7)) == 1; -#else - readU16(); -#endif - - // TODO: get gradient extent (in double precision) - - m_gradientAngle = angleFraction + (double)angleInteger/65536.0; - m_gradientRef.insert("svg:x", (double)xref); - m_gradientRef.insert("svg:y", (double)yref); - - PICT_DEBUG_MSG((" Gradient angle : %d.%d\n", angleInteger, angleFraction)); - PICT_DEBUG_MSG((" Gradient reference : %d.%d\n", xref, yref)); - PICT_DEBUG_MSG((" Granular : %s\n", (granular ? "yes" : "no"))); - PICT_DEBUG_MSG((" Anchored : %s\n", (anchor ? "yes" : "no"))); + m_input->seek(6, WPX_SEEK_CUR); + m_recordSize = (int)readU16() + 6; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); } -void Pict2Parser::handleBrushForeColor() +void Pict2Parser::handleDHText() { - if (!m_graphicsStarted) - return; - if(!m_groupStack.empty()) - { - if (m_groupStack.top().isCompoundPolygon()) - return; - if (m_groupStack.top().parentType == 0x01) // we don't handle Page Attributes for now - return; - } - unsigned char gradientType = readU8(); - PICT_DEBUG_MSG((" Gradient type : %d (%s)\n", gradientType, describeGradient(gradientType))); - - if(gradientType == 0) - { - unsigned char red = readU8(); - unsigned char green = readU8(); - unsigned char blue = readU8(); - unsigned char alpha = 0xff - readU8(); - PICT_DEBUG_MSG((" Foreground color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); - - m_brushForeColor = libpict::PictColor(red, green, blue, alpha); - - m_style.insert("draw:fill-color", m_brushForeColor.getColorString()); - m_style.insert("draw:opacity", m_brushForeColor.getOpacity(), WPX_PERCENT); - - if(!m_style["draw:fill"] || m_style["draw:fill"]->getStr() != "gradient") - m_style.insert("draw:fill", "solid"); - } - else - { - unsigned count = readU16(); - std::vector<libpict::PictColor> colors; - std::vector<double> positions; - PICT_DEBUG_MSG((" Gradient colors : %d\n", count)); - - if (count > 0) - { - for(unsigned i = 0; i < count; i++) - { - unsigned char red = readU8(); - unsigned char green = readU8(); - unsigned char blue = readU8(); - unsigned char alpha = 0xff - readU8(); - libpict::PictColor color(red, green, blue, alpha); - colors.push_back(color); - PICT_DEBUG_MSG((" Color #%d (RGBA): %d %d %d %d\n", i+1, red, green, blue, alpha)); - } - - for(unsigned j = 0; j < count-1; j++) - { - unsigned pos = readU16(); - positions.push_back(TO_DOUBLE(pos)); - PICT_DEBUG_MSG((" Position #%d : %d\n", j+1, pos)); - } - } - - // looks like Corel Presentations only create 2 colors gradient - // and they are actually in reverse order - if(count == 2) - { - double xref = m_gradientRef["svg:x"]->getDouble()/65536.0; - double yref = m_gradientRef["svg:y"]->getDouble()/65536.0; - double angle = m_gradientAngle*M_PI/180.0; - double tanangle = tan(angle); - double ref = (tanangle < 1e2 && tanangle > -1e2) ? (yref+xref*tanangle)/(1+tanangle) : xref; - ::WPXPropertyListVector gradient; - m_style.insert("draw:angle", (int)(-m_gradientAngle)); // upside down - WPXPropertyList propList; - propList.insert("svg:offset", 0.0, WPX_PERCENT); - propList.insert("svg:stop-color", colors[1].getColorString()); - propList.insert("svg:stop-opacity", colors[1].getOpacity(), WPX_PERCENT); - gradient.append(propList); - propList.clear(); - propList.insert("svg:offset", ref, WPX_PERCENT); - propList.insert("svg:stop-color", colors[0].getColorString()); - propList.insert("svg:stop-opacity", colors[0].getOpacity(), WPX_PERCENT); - gradient.append(propList); - propList.clear(); - if((m_gradientRef["svg:x"]->getInt() != 65535) && (m_gradientRef["svg:y"]->getInt() != 65535)) - { - propList.insert("svg:offset", 1.0, WPX_PERCENT); - propList.insert("svg:stop-color", colors[1].getColorString()); - propList.insert("svg:stop-opacity", colors[1].getOpacity(), WPX_PERCENT); - gradient.append(propList); - } - m_gradient = gradient; - m_style.insert("draw:fill", "gradient"); - } - } + m_input->seek(2, WPX_SEEK_CUR); + m_recordSize = (int)readU16() + 3; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); } -void Pict2Parser::handleDPBrushForeColor() +void Pict2Parser::handleDVText() { - if (!m_graphicsStarted) - return; - if(!m_groupStack.empty()) - { - if (m_groupStack.top().isCompoundPolygon()) - return; - if (m_groupStack.top().parentType == 0x01) // we don't handle Page Attributes for now - return; - } - unsigned char gradientType = readU8(); - PICT_DEBUG_MSG((" Gradient type : %d (%s)\n", gradientType, describeGradient(gradientType))); - - if(gradientType == 0) - { - unsigned char red = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned char green = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned char blue = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned char alpha = 0xff - (m_doublePrecision) ? readU16()>>8 : readU8(); - PICT_DEBUG_MSG((" Foreground color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); - - m_brushForeColor = libpict::PictColor(red, green, blue, alpha); - - m_style.insert("draw:fill-color", m_brushForeColor.getColorString()); - m_style.insert("draw:opacity", m_brushForeColor.getOpacity(), WPX_PERCENT); - - if(!m_style["draw:fill"] || m_style["draw:fill"]->getStr() != "none") - m_style.insert("draw:fill", "solid"); - } - else - { - unsigned count = readU16(); - std::vector<libpict::PictColor> colors; - std::vector<double> positions; - PICT_DEBUG_MSG((" Gradient colors : %d\n", count)); - - if (count > 0) - { - for(unsigned i = 0; i < count; i++) - { - unsigned char red = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned char green = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned char blue = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned char alpha = 0xff - (m_doublePrecision) ? readU16()>>8 : readU8(); - libpict::PictColor color(red, green, blue, alpha); - colors.push_back(color); - PICT_DEBUG_MSG((" Color #%d (RGBA): %d %d %d %d\n", i+1, red, green, blue, alpha)); - } - - for(unsigned j = 0; j < count-1; j++) - { - unsigned pos = readU16(); - positions.push_back(TO_DOUBLE(pos)); - PICT_DEBUG_MSG((" Position #%d : %d\n", j+1, pos)); - } - } - - // looks like Corel Presentations only create 2 colors gradient - // and they are actually in reverse order - if(count == 2) - { - double xref = m_gradientRef["svg:x"]->getDouble()/65536.0; - double yref = m_gradientRef["svg:y"]->getDouble()/65536.0; - double angle = m_gradientAngle*M_PI/180.0; - double tanangle = tan(angle); - double ref = (tanangle<1e2) ? (yref+xref*tanangle)/(1+tanangle) : xref; - ::WPXPropertyListVector gradient; - m_style.insert("draw:angle", (int)(-m_gradientAngle)); - - WPXPropertyList propList; - propList.insert("svg:offset", 0.0, WPX_PERCENT); - propList.insert("svg:stop-color", colors[1].getColorString()); - propList.insert("svg:stop-opacity", colors[1].getOpacity(), WPX_PERCENT); - gradient.append(propList); - propList.clear(); - propList.insert("svg:offset", ref, WPX_PERCENT); - propList.insert("svg:stop-color", colors[0].getColorString()); - propList.insert("svg:stop-opacity", colors[0].getOpacity(), WPX_PERCENT); - gradient.append(propList); - propList.clear(); - if((m_gradientRef["svg:x"]->getInt() != 65535) && (m_gradientRef["svg:y"]->getInt() != 65535)) - { - propList.insert("svg:offset", 1.0, WPX_PERCENT); - propList.insert("svg:stop-color", colors[1].getColorString()); - propList.insert("svg:stop-opacity", colors[1].getOpacity(), WPX_PERCENT); - gradient.append(propList); - } - m_gradient = gradient; - } - m_style.insert("draw:fill", "gradient"); - } + m_input->seek(2, WPX_SEEK_CUR); + m_recordSize = (int)readU16() + 3; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); } -void Pict2Parser::handleBrushBackColor() +void Pict2Parser::handleDHDVText() { - if (!m_graphicsStarted) - return; - if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon()) - return; -#if 0 - unsigned char red = readU8(); - unsigned char green = readU8(); - unsigned char blue = readU8(); - unsigned char alpha = 0xff - readU8(); - - m_brushBackColor = libpict::PictColor(red, green, blue, alpha); + m_input->seek(3, WPX_SEEK_CUR); + m_recordSize = (int)readU16() + 4; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); +} - m_gradient.backColor = libpict::PictColor(red, green, blue, alpha); - if(m_gradient.style == libpict::PictGradient::NoBrush) - m_gradient.style = libpict::PictGradient::Solid; - PICT_DEBUG_MSG((" Backround color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); -#endif +void Pict2Parser::handleFrameRect() +{ } -void Pict2Parser::handleDPBrushBackColor() +void Pict2Parser::handlePaintRect() { - if (!m_graphicsStarted) - return; - if (!m_groupStack.empty() && m_groupStack.top().isCompoundPolygon()) - return; -#if 0 - // we just ignore the least significant 8 bits - unsigned int red = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned int green = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned int blue = (m_doublePrecision) ? readU16()>>8 : readU8(); - unsigned int alpha = 0xff - (m_doublePrecision) ? readU16()>>8 : readU8(); - - m_brushBackColor = libpict::PictColor(red, green, blue, alpha); - - m_style.insert("draw:fill-color", m_brushForeColor.getColorString()); - m_style.insert("draw:opacity", m_brushForeColor.getOpacity(), WPX_PERCENT); - - if(m_style["draw:fill"] && m_style["draw:fill"]->getStr() == "none") - m_style.insert("draw:fill", "solid"); - - PICT_DEBUG_MSG((" Background color (RGBA): %d %d %d %d\n", red, green, blue, alpha)); -#endif } -void Pict2Parser::handleBrushPattern() +void Pict2Parser::handleEraseRect() { - if (!m_graphicsStarted) - return; - if(!m_groupStack.empty()) - { - if (m_groupStack.top().isCompoundPolygon()) - return; - if (m_groupStack.top().parentType == 0x01) // we don't handle Page Attributes for now - return; - } -#ifdef DEBUG - unsigned int pattern = readU16(); -#endif - - // TODO - - PICT_DEBUG_MSG((" Pattern : %d\n", pattern)); } -void Pict2Parser::parseCharacterization(ObjectCharacterization* ch) +void Pict2Parser::handleInvertRect() { - // sanity check - if(!ch) return; - - // identity - ch->matrix = Pict2TransformMatrix(); - - 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->windingRule = (flags & (1<<12)) != 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 = fixedPointToDouble(readU32()); - - if(ch->rotate || ch->scale) - { - ch->sxcos = readS32(); - ch->sycos = readS32(); - ch->matrix.element[0][0] = (double)(ch->sxcos)/65536; - ch->matrix.element[1][1] = (double)(ch->sxcos)/65536; - } - - if(ch->rotate || ch->skew) - { - ch->kxsin = readS32(); - ch->kysin = readS32(); - ch->matrix.element[1][0] = (double)(ch->kxsin)/65536; - ch->matrix.element[0][1] = (double)(ch->kysin)/65536; - } - - if(ch->translate) - { - ch->txfraction = readU16(); - ch->txinteger = readS32(); - ch->tyfraction = readU16(); - ch->tyinteger = readS32(); - ch->matrix.element[2][0] = (double)(ch->txinteger); - ch->matrix.element[2][1] = (double)(ch->tyinteger); - } - - if(ch->taper) - { - ch->px = readS32(); - ch->py = readS32(); - ch->matrix.element[0][2] = (double)(ch->px); - ch->matrix.element[1][2] = (double)(ch->py); - } - - PICT_DEBUG_MSG(("ObjectCharacterization\n")); - PICT_DEBUG_MSG((" taper : %s\n", (ch->taper ? "yes" : "no"))); - PICT_DEBUG_MSG((" translate : %s\n", (ch->translate ? "yes" : "no"))); - PICT_DEBUG_MSG((" skew : %s\n", (ch->skew ? "yes" : "no"))); - PICT_DEBUG_MSG((" scale : %s\n", (ch->scale ? "yes" : "no"))); - PICT_DEBUG_MSG((" rotate : %s\n", (ch->rotate ? "yes" : "no"))); - PICT_DEBUG_MSG((" hasObjectId : %s\n", (ch->hasObjectId ? "yes" : "no"))); - PICT_DEBUG_MSG((" editLock : %s\n", (ch->editLock ? "yes" : "no"))); - PICT_DEBUG_MSG((" closed : %s\n", (ch->closed ? "yes" : "no"))); - PICT_DEBUG_MSG((" framed : %s\n", (ch->framed ? "yes" : "no"))); - PICT_DEBUG_MSG((" filled : %s\n", (ch->filled ? "yes" : "no"))); -#ifdef DEBUG - if(ch->editLock) PICT_DEBUG_MSG((" lock flags : 0x%x\n", (unsigned)ch->lockFlags)); - if(ch->hasObjectId) PICT_DEBUG_MSG((" object ID : 0x%x\n", (unsigned)ch->objectId)); - if(ch->translate) PICT_DEBUG_MSG((" tx : %li %d\n", ch->txinteger, ch->txfraction)); - if(ch->translate) PICT_DEBUG_MSG((" ty : %li %d\n", ch->tyinteger, ch->tyfraction)); -#endif - PICT_DEBUG_MSG(("transform matrix:\n")); - PICT_DEBUG_MSG(("%f %f %f\n", ch->matrix.element[0][0], ch->matrix.element[0][1],ch->matrix.element[0][2])); - PICT_DEBUG_MSG(("%f %f %f\n", ch->matrix.element[1][0], ch->matrix.element[1][1],ch->matrix.element[1][2])); - PICT_DEBUG_MSG(("%f %f %f\n", ch->matrix.element[2][0], ch->matrix.element[2][1],ch->matrix.element[2][2])); } -void Pict2Parser::handlePolyline() +void Pict2Parser::handleFillRect() { - if (!m_graphicsStarted) - return; - ObjectCharacterization objCh; - parseCharacterization(&objCh); - m_matrix = objCh.matrix; - - WPXPropertyList tmpStyle = m_style; - - if (!objCh.filled) - tmpStyle.insert("draw:fill", "none"); - - bool insideCompound = m_groupStack.empty() ? false : - m_groupStack.top().isCompoundPolygon(); - - // inside a compound, so take the parent transformation into account - if(insideCompound) - m_matrix.transformBy(m_groupStack.top().compoundMatrix); - - unsigned long count = readU16(); - - ::WPXPropertyListVector points; - ::WPXPropertyList point; - for(unsigned long i = 0; i < count; i++ ) - { - point.clear(); - long x = (m_doublePrecision) ? readS32() : readS16(); - long y = (m_doublePrecision) ? readS32() : readS16(); - TRANSFORM_XY(x,y); - point.insert("svg:x", (TO_DOUBLE(x)/m_xres)); - point.insert("svg:y", (TO_DOUBLE(y)/m_yres)); - points.append(point); - } - - if(insideCompound) - { - if(count > 0) - { - // inside a compound ? convert it into path because for compound - // we will only use paths - ::WPXPropertyListVector& path = m_groupStack.top().compoundPath; - ::WPXPropertyList element; - element = points[0]; - element.insert("libpict:path-action", "M"); - path.append(element); - for(unsigned long ii = 1; ii < count; ii++) - { - element.clear(); - element = points[ii]; - element.insert("libpict:path-action", "L"); - path.append(element); - } - } - } - else - { - // otherwise draw directly - if (count > 2) - { - if(objCh.windingRule) - tmpStyle.insert("svg:fill-rule", "nonzero"); - else - tmpStyle.insert("svg:fill-rule", "evenodd"); - - m_painter->setStyle( tmpStyle, objCh.filled ? m_gradient : ::WPXPropertyListVector() ); - - if (objCh.filled || objCh.closed) - m_painter->drawPolygon(points); - else - m_painter->drawPolyline(points); - } - else - { - - m_painter->setStyle( tmpStyle, ::WPXPropertyListVector() ); - m_painter->drawPolyline(points); - } - } - - PICT_DEBUG_MSG((" Vertices count : %li\n", count)); - for(unsigned int j = 0; j < count; j++ ) - PICT_DEBUG_MSG((" Point #%d : %g,%g\n", j+1, points[j]["svg:x"]->getDouble(), points[j]["svg:x"]->getDouble())); } -void Pict2Parser::handlePolyspline() +void Pict2Parser::handleFrameSameRect() { - // fprintf(stderr, "This is actually not an error, just a crash so that we know "); - // fprintf(stderr, "that there is an actual document containing the Polyspline record\n"); - // crash here !!! - // *((int *)NULL) = 0; - if (!m_graphicsStarted) - return; - // We have never seen a polyspline in a Pict file and we are not even able to generate - // one, so, we draw a polyline instead and wait for bug reports :) - handlePolyline(); } -void Pict2Parser::handlePolycurve() +void Pict2Parser::handlePaintSameRect() { - if (!m_graphicsStarted) - return; - ObjectCharacterization objCh; - parseCharacterization(&objCh); - m_matrix = objCh.matrix; - - WPXPropertyList tmpStyle = m_style; - - if (!objCh.filled) - tmpStyle.insert("draw:fill", "none"); - - bool insideCompound = m_groupStack.empty() ? false : - m_groupStack.top().isCompoundPolygon(); +} - // inside a compound, so take the parent transformation into account - if(insideCompound) - m_matrix.transformBy(m_groupStack.top().compoundMatrix); +void Pict2Parser::handleEraseSameRect() +{ +} - unsigned int count = readU16(); +void Pict2Parser::handleInvertSameRect() +{ +} - ::WPXPropertyListVector path; - ::WPXPropertyList element; - ::WPXPropertyListVector vertices; - ::WPXPropertyListVector controlPoints; - for(unsigned int i = 0; i < count; i++ ) - { - long ix = (m_doublePrecision) ? readS32() : readS16(); - long iy = (m_doublePrecision) ? readS32() : readS16(); - TRANSFORM_XY(ix,iy); - - long ax = (m_doublePrecision) ? readS32() : readS16(); - long ay = (m_doublePrecision) ? readS32() : readS16(); - TRANSFORM_XY(ax,ay); - - long tx = (m_doublePrecision) ? readS32() : readS16(); - long ty = (m_doublePrecision) ? readS32() : readS16(); - TRANSFORM_XY(tx,ty); - - element.insert("svg:x", (TO_DOUBLE(ax)/m_xres)); - element.insert("svg:y", (TO_DOUBLE(ay)/m_yres)); - if (i == 0) - element.insert("libpict:path-action", "M"); - else - { - element.insert("svg:x2", (TO_DOUBLE(ix)/m_xres)); - element.insert("svg:y2", (TO_DOUBLE(iy)/m_yres)); - element.insert("libpict:path-action", "C"); - } - path.append(element); - element.insert("svg:x1", (TO_DOUBLE(tx)/m_xres)); - element.insert("svg:y1", (TO_DOUBLE(ty)/m_yres)); - } +void Pict2Parser::handleFillSameRect() +{ +} - element.clear(); - if (objCh.closed) - { - element.insert("libpict:path-action", "Z"); - path.append(element); - } +void Pict2Parser::handleFrameRRect() +{ +} - if(insideCompound) - // inside a compound ? just collect the path together - m_groupStack.top().compoundPath.append(path); - else - { - // otherwise draw directly - if(objCh.windingRule) - tmpStyle.insert("svg:fill-rule", "nonzero"); - else - tmpStyle.insert("svg:fill-rule", "evenodd"); - m_painter->setStyle( tmpStyle, objCh.filled ? m_gradient : ::WPXPropertyListVector() ); - m_painter->drawPath(path); - } +void Pict2Parser::handlePaintRRect() +{ } -void Pict2Parser::handleRectangle() +void Pict2Parser::handleEraseRRect() { - if (!m_graphicsStarted) - return; - ObjectCharacterization objCh; - parseCharacterization(&objCh); - m_matrix = objCh.matrix; +} - WPXPropertyList tmpStyle = m_style; - - if (!objCh.filled) - tmpStyle.insert("draw:fill", "none"); +void Pict2Parser::handleInvertRRect() +{ +} - long x1 = (m_doublePrecision) ? readS32() : readS16(); - long y1 = (m_doublePrecision) ? readS32() : readS16(); - TRANSFORM_XY(x1,y1); +void Pict2Parser::handleFillRRect() +{ +} - long x2 = (m_doublePrecision) ? readS32() : readS16(); - long y2 = (m_doublePrecision) ? readS32() : readS16(); - TRANSFORM_XY(x2,y2); +void Pict2Parser::handleFrameSameRRect() +{ +} - long xs1 = (x1 <= x2) ? x1 : x2; - long xs2 = (x1 <= x2) ? x2 : x1; - long ys1 = (y1 <= y2) ? y1 : y2; - long ys2 = (y1 <= y2) ? y2 : y1; +void Pict2Parser::handlePaintSameRRect() +{ +} - long rx = (m_doublePrecision) ? readS32() : readS16(); - long ry = (m_doublePrecision) ? readS32() : readS16(); +void Pict2Parser::handleEraseSameRRect() +{ +} - ::WPXPropertyList propList; - propList.insert("svg:x", (TO_DOUBLE(xs1) / m_xres)); - propList.insert("svg:width", (TO_DOUBLE(xs2-xs1) / m_xres)); - propList.insert("svg:y", (TO_DOUBLE(ys1) / m_yres)); - propList.insert("svg:height", (TO_DOUBLE(ys2-ys1) / m_yres)); +void Pict2Parser::handleInvertSameRRect() +{ +} - propList.insert("svg:rx", (TO_DOUBLE(rx)/m_xres)); - propList.insert("svg:ry", (TO_DOUBLE(ry)/m_yres)); +void Pict2Parser::handleFillSameRRect() +{ +} - m_painter->setStyle( tmpStyle, objCh.filled ? m_gradient : ::WPXPropertyListVector() ); - m_painter->drawRectangle(propList); +void Pict2Parser::handleFrameOval() +{ +} - PICT_DEBUG_MSG((" X1 : %li\n", x1)); - PICT_DEBUG_MSG((" Y1 : %li\n", y1)); - PICT_DEBUG_MSG((" X2 : %li\n", x2)); - PICT_DEBUG_MSG((" Y2 : %li\n", y2)); - PICT_DEBUG_MSG((" Round X : %li\n", rx)); - PICT_DEBUG_MSG((" Round Y : %li\n", ry)); +void Pict2Parser::handlePaintOval() +{ } -void Pict2Parser::handleArc() +void Pict2Parser::handleEraseOval() { - if (!m_graphicsStarted) - return; - ObjectCharacterization objCh; - parseCharacterization(&objCh); - m_matrix = objCh.matrix; +} - WPXPropertyList tmpStyle = m_style; - - if (!objCh.filled) - tmpStyle.insert("draw:fill", "none"); +void Pict2Parser::handleInsertOval() +{ +} - long cx = (m_doublePrecision) ? readS32() : readS16(); - long cy = (m_doublePrecision) ? readS32() : readS16(); +void Pict2Parser::handleFillOval() +{ +} - long radx = (m_doublePrecision) ? readS32() : readS16(); - long rady = (m_doublePrecision) ? readS32() : readS16(); +void Pict2Parser::handleFrameSameOval() +{ +} - long ix = (m_doublePrecision) ? readS32() : readS16(); - ix += cx; - long iy = (m_doublePrecision) ? readS32() : readS16(); - iy += cy; +void Pict2Parser::handlePaintSameOval() +{ +} - long ex = (m_doublePrecision) ? readS32() : readS16(); - ex += cx; - long ey = (m_doublePrecision) ? readS32() : readS16(); - ey += cy; +void Pict2Parser::handleEraseSameOval() +{ +} - TRANSFORM_XY(cx,cy); - TRANSFORM_XY(ix,iy); - TRANSFORM_XY(ex,ey); +void Pict2Parser::handleInsertSameOval() +{ +} - m_painter->setStyle( tmpStyle, objCh.filled ? m_gradient : ::WPXPropertyListVector() ); +void Pict2Parser::handleFillSameOval() +{ +} - if (ix == ex && iy == ey) - { - ::WPXPropertyList propList; - propList.insert("svg:cx", (TO_DOUBLE(cx) / m_xres)); - propList.insert("svg:cy", (TO_DOUBLE(cy) / m_xres)); - propList.insert("svg:rx", (TO_DOUBLE(radx) / m_xres)); - propList.insert("svg:ry", (TO_DOUBLE(rady) / m_xres)); - if (objCh.rotate) - propList.insert("libpict:rotate", objCh.rotationAngle, WPX_GENERIC); - - m_painter->drawEllipse(propList); - } - else - { - ::WPXPropertyList element; - ::WPXPropertyListVector path; - - element.insert("libpict:path-action", "M"); - element.insert("svg:x", (TO_DOUBLE(ix)/m_xres)); - element.insert("svg:y", (TO_DOUBLE(iy)/m_yres)); - path.append(element); - element.clear(); - - element.insert("libpict:path-action", "A"); - element.insert("svg:rx", (TO_DOUBLE(radx)/m_xres)); - element.insert("svg:ry", (TO_DOUBLE(rady)/m_yres)); - element.insert("svg:x", (TO_DOUBLE(ex)/m_xres)); - element.insert("svg:y", (TO_DOUBLE(ey)/m_yres)); - if (objCh.rotate) - element.insert("libpict:rotate", objCh.rotationAngle, WPX_GENERIC); - path.append(element); - - m_painter->drawPath(path); - } +void Pict2Parser::handleFrameArc() +{ +} - PICT_DEBUG_MSG((" Center point x : %li\n", cx)); - PICT_DEBUG_MSG((" Center point y : %li\n", cy)); - PICT_DEBUG_MSG((" Radius x : %li\n", radx)); - PICT_DEBUG_MSG((" Radius y : %li\n", rady)); - PICT_DEBUG_MSG((" Initial point x : %li\n", ix)); - PICT_DEBUG_MSG((" Initial point y : %li\n", iy)); - PICT_DEBUG_MSG((" End point x : %li\n", ex)); - PICT_DEBUG_MSG((" End point y : %li\n", ey)); +void Pict2Parser::handlePaintArc() +{ } -void Pict2Parser::handleBitmap() +void Pict2Parser::handleEraseArc() { - if (!m_graphicsStarted) - return; - ObjectCharacterization objCh; - parseCharacterization(&objCh); - - if (objCh.scale) - { - if (objCh.sxcos < 0) - m_hFlipped = true; - if (objCh.sycos < 0) - m_vFlipped = true; - } - m_matrix = objCh.matrix; - - long x1 = (m_doublePrecision) ? readS32() : readS16(); - long y1 = (m_doublePrecision) ? readS32() : readS16(); - long x2 = (m_doublePrecision) ? readS32() : readS16(); - long y2 = (m_doublePrecision) ? readS32() : readS16(); - TRANSFORM_XY(x1,y1); - TRANSFORM_XY(x2,y2); - - long hres = (m_doublePrecision) ? readS32() : readS16(); - long vres = (m_doublePrecision) ? readS32() : readS16(); - - long xs1 = (x1 <= x2) ? x1 : x2; - long xs2 = (x1 <= x2) ? x2 : x1; - long ys1 = (y1 <= y2) ? y1 : y2; - long ys2 = (y1 <= y2) ? y2 : y1; - - m_bitmap.x1 = TO_DOUBLE(xs1) / m_xres; - m_bitmap.y1 = TO_DOUBLE(ys1) / m_yres; - m_bitmap.x2 = TO_DOUBLE(xs2) / m_xres; - m_bitmap.y2 = TO_DOUBLE(ys2) / m_yres; - if (hres == 0) - hres = 72; - m_bitmap.hres = hres; - if (vres == 0) - vres = 72; - m_bitmap.vres = vres; - - PICT_DEBUG_MSG((" x1 : %li\n", x1)); - PICT_DEBUG_MSG((" y1 : %li\n", y1)); - PICT_DEBUG_MSG((" x2 : %li\n", x2)); - PICT_DEBUG_MSG((" y2 : %li\n", y2)); - PICT_DEBUG_MSG((" hres : %li (pixel per inch)\n", hres)); - PICT_DEBUG_MSG((" vres : %li (pixel per inch)\n", vres)); -} - -void Pict2Parser::handleBitmapData() -{ - if (!m_graphicsStarted) - return; - unsigned width = readU16(); - unsigned height = readU16(); - unsigned color_format = readU8(); - unsigned compression_format = readU8(); - - PICT_DEBUG_MSG((" dimension : %g, %g %g, %g\n", m_bitmap.x1, m_bitmap.y1, m_bitmap.x2, m_bitmap.y2)); - PICT_DEBUG_MSG((" width : %i pixels\n", width)); - PICT_DEBUG_MSG((" height : %i pixels\n", height)); - PICT_DEBUG_MSG((" color format : %d\n", color_format)); - PICT_DEBUG_MSG((" compression : %d (%s)\n", compression_format, - (compression_format==0) ? "uncompressed": - (compression_format==1) ? "run-length encoding" : "unknown")); - - if (color_format > 12) // not documented and we are likely not knowing what to do with this - return; - unsigned tmpBufferSize; - unsigned raster_len = width; - if (color_format == 1) - { - tmpBufferSize = (width/8+1)*height; - raster_len = width/8 + ((width % 8) ? 1 : 0); - } - else if (color_format == 2) - { - tmpBufferSize = (width/4+1)*height; - raster_len = width/4 + ((width % 4) ? 1 : 0); - } - else if (color_format == 3) - { - tmpBufferSize = (width/2+1)*height; - raster_len = width/2 + ((width % 2) ? 1 : 0); - } - else if (color_format == 5 || color_format == 6 || color_format == 7) - tmpBufferSize = 2*width*height; - else if (color_format == 8) - tmpBufferSize = 3*width*height; - else if (color_format == 9) - tmpBufferSize = 4*width*height; - else if (color_format == 10) - tmpBufferSize = 6*width*height; - else if (color_format == 11) - tmpBufferSize = 8*width*height; - else - tmpBufferSize = width*height; - - - std::vector<unsigned char> buffer; - buffer.reserve(tmpBufferSize); - - // plain data, uncompression - if(compression_format==0) - for(unsigned ii=0; ii < tmpBufferSize && !m_input->atEOS() && m_input->tell() <= m_recordEnd; ii++) - buffer.push_back( readU8() ); - // run-length encoding - else if(compression_format==1) - { - unsigned char data[256]; - bool xor_raster = false; - unsigned next_scanline = 0; - unsigned data_size = 1; +} - PICT_DEBUG_MSG(("Decoding RLE data\n")); +void Pict2Parser::handleInsertArc() +{ +} - // FIXME check for ptr, it should not go out of bound!! - while (m_input->tell() <= m_recordEnd && !m_input->atEOS() && buffer.size() < tmpBufferSize) - { - unsigned char opcode = readU8(); - // specify data size - if(opcode == 0x7d) - { - unsigned new_data_size = readU8(); - if(new_data_size != data_size) - { - data_size = new_data_size; - if (tmpBufferSize < data_size*width*height) - { - tmpBufferSize = data_size*width*height; - buffer.reserve(tmpBufferSize); - } - raster_len = data_size*width; - } - } +void Pict2Parser::handleFillArc() +{ +} - // a run of black (index #0) - else if(opcode == 0x7f) - { - unsigned count = 1 + readU8(); - for( ; count ; --count ) - for(unsigned j = 0; j < data_size && !m_input->atEOS(); j++) - buffer.push_back( 0 ); - - } +void Pict2Parser::handleFrameSameArc() +{ +} - // a run of white (index #255) - else if(opcode == 0xff) - { - unsigned count = 1 + readU8(); +void Pict2Parser::handlePaintSameArc() +{ +} - for( ; count ; --count ) - for(unsigned j = 0; j < data_size && !m_input->atEOS(); j++) - buffer.push_back( 255 ); - } +void Pict2Parser::handleEraseSameArc() +{ +} - // extend previous run - else if(opcode == 0xfd) - { - unsigned count = 1 + readU8(); - for( ; count; --count) - for(unsigned j = 0; j < data_size && !m_input->atEOS(); j++) - buffer.push_back( data[j] ); - } +void Pict2Parser::handleInsertSameArc() +{ +} - // repeat raster - else if(opcode == 0xfe) - { - unsigned count = 1 + readU8(); - if ( buffer.size() < raster_len ) - break; - unsigned raster_source = buffer.size() - raster_len; - for( ; count; --count) - for(unsigned long r = 0; r < raster_len; r++) - { - unsigned char pixel = buffer[raster_source + r]; - buffer.push_back( pixel ); - } - } +void Pict2Parser::handleFillSameArc() +{ +} - // XOR - else if(opcode == 0x7e) - { - // Xor-ing will happen when about to enter next raster - // see after the last if down below - xor_raster = true; - next_scanline = buffer.size() + raster_len; - } +void Pict2Parser::handleFramePoly() +{ + m_recordSize = (int)readU16() + 1; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); +} - // NOTE: the following two IFs here must be the last ones +void Pict2Parser::handlePaintPoly() +{ + m_recordSize = (int)readU16() + 1; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); +} - // a run of data - else if(opcode >= 0x80) - { - unsigned count = 1 + (opcode & 0x7f); - for(unsigned i = 0; i < data_size && !m_input->atEOS(); i++) - data[i] = readU8(); - for( ; count; --count) - for(unsigned j = 0; j < data_size; j++) - buffer.push_back( data[j] ); - } +void Pict2Parser::handleErasePoly() +{ + m_recordSize = (int)readU16() + 1; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); +} - // simple copy - else if(opcode <= 0x7f) - { - unsigned count = opcode + 1; - for( ; count; --count) - for(unsigned j = 0; j < data_size && !m_input->atEOS(); j++) - buffer.push_back( readU8() ); - } +void Pict2Parser::handleInvertPoly() +{ + m_recordSize = (int)readU16() + 1; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); +} - // unreachable: only sentinel - else - { - PICT_DEBUG_MSG((" ! unknown opcode %02x\n", opcode)); - break; - } +void Pict2Parser::handleFillPoly() +{ + m_recordSize = (int)readU16() + 1; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); +} - // new raster/scanline? if necessary do the XOR now - if(xor_raster && buffer.size() >= next_scanline) - { - // reset, because XOR in one raster at a time - xor_raster = false; +void Pict2Parser::handleFrameSamePoly() +{ +} - // current raster must be XORed with previous raster - unsigned current = next_scanline - raster_len; - unsigned previous = current - raster_len; - if (current >= buffer.size() || previous >= buffer.size()) - return; - for( unsigned r = 0; r < raster_len; r++) - buffer[current++] ^= buffer[previous++]; +void Pict2Parser::handlePaintSamePoly() +{ +} - } +void Pict2Parser::handleEraseSamePoly() +{ +} - } +void Pict2Parser::handleInvertSamePoly() +{ +} - PICT_DEBUG_MSG(("Finish decoding RLE data\n")); - } - - // no buffer? format is unknown - if(!buffer.size()) return; - - while (buffer.size() < tmpBufferSize) - buffer.push_back(0); - - // prepare the bitmap structure for the listener - libpict::PictBitmap bitmap(width, height, m_vFlipped, m_hFlipped); - ::WPXPropertyList propList; - propList.insert("svg:x", (double)m_bitmap.x1); - propList.insert("svg:y", (double)m_bitmap.y1); - propList.insert("svg:width", (m_bitmap.x2 - m_bitmap.x1)); - propList.insert("svg:height", (m_bitmap.y2 - m_bitmap.y1)); - propList.insert("libpict:mime-type", "image/bmp"); - - // format 1: each byte represents 8 pixels, the color fetched from the palette - if(color_format == 1) - { - int i = 0; - for (unsigned long y = 0; y < height; y++) - for (unsigned long x = 0; x < width; x++, i++) - { - if ((x==0) && (i % 8 != 0)) - i = (i/8 + 1) * 8; - unsigned index = ((buffer[i/8] & (0x01 << (7 - (i % 8)))) >> (7 - (i % 8))); - const libpict::PictColor& color = m_colorPalette[index]; - bitmap.setPixel(x, y, color); - } - m_painter->drawGraphicObject(propList, bitmap.getDIB()); - } - // format 2: each byte represents 4 pixels, the color fetched from the palette - else if(color_format == 2) - { - int i = 0; - for (unsigned long y = 0; y < height; y++) - for (unsigned long x = 0; x < width; x++, i++) - { - if ((x==0) && (i % 4 != 0)) - i = (i/4 + 1) * 4; - unsigned index = ((buffer[i/4] & (0x03 << 2*(3 - (i % 4)))) >> 2*(3 - (i % 4))); - const libpict::PictColor& color = m_colorPalette[index]; - bitmap.setPixel(x, y, color); - } - m_painter->drawGraphicObject(propList, bitmap.getDIB()); - } - // format 3: each byte represents 2 pixels, the color fetched from the palette - else if(color_format == 3) - { - int i = 0; - for (unsigned long y = 0; y < height; y++) - for (unsigned long x = 0; x < width; x++, i++) - { - if ((x==0) && (i % 2 != 0)) - i = (i/2 + 1) * 2; - unsigned index = ((buffer[i/2] & (0x0f << 4*(1 - (i % 2)))) >> 4*(1 - (i % 2))); - const libpict::PictColor& color = m_colorPalette[index]; - bitmap.setPixel(x, y, color); - } - m_painter->drawGraphicObject(propList, bitmap.getDIB()); - } - // format 4: each byte represents a pixel, the color fetched from the palette - else if(color_format == 4) - { - int i = 0; - for(unsigned long y = 0; y < height; y++) - for(unsigned long x = 0; x < width; x++, i++) - { - const libpict::PictColor& color = m_colorPalette[buffer[i]]; - bitmap.setPixel(x, y, color); - } +void Pict2Parser::handleFillSamePoly() +{ +} - m_painter->drawGraphicObject(propList, bitmap.getDIB()); - } - // format 5: greyscale of 16 bits - else if (color_format == 5) - { - int i = 0; - for (unsigned long y = 0; y < height; y++) - for (unsigned long x = 0; x < width; x++, i++) - { - - const libpict::PictColor color(buffer[2*i+1], buffer[2*i+1], buffer[2*i+1]); - bitmap.setPixel(x, y, color); - } +void Pict2Parser::handleFrameRgn() +{ + m_recordSize = (int)readU16() + 1; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); +} - m_painter->drawGraphicObject(propList, bitmap.getDIB()); - } - // format 6: RGB, with 5 bits per colour - else if (color_format == 6) - { - int i = 0; - for (unsigned long y = 0; y < height; y++) - for (unsigned long x = 0; x < width; x++, i++) - { - unsigned short tmpColor = (unsigned short)(buffer[2*i] | (buffer[2*i+1] << 8)); - const libpict::PictColor color((tmpColor >> 10) & 0x1f, (tmpColor >> 5) & 0x1f, tmpColor & 0x1f); - bitmap.setPixel(x, y, color); - } +void Pict2Parser::handlePaintRgn() +{ + m_recordSize = (int)readU16() + 1; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); +} - m_painter->drawGraphicObject(propList, bitmap.getDIB()); - } - // format 7: - else if (color_format == 7) - { - int i = 0; - for (unsigned long y = 0; y < height; y++) - for (unsigned long x = 0; x < width; x++, i++) - { - unsigned short tmpColor = (unsigned short)(buffer[2*i] | (buffer[2*i+1] << 8)); - const libpict::PictColor color(tmpColor & 0x0f, (tmpColor >> 4) & 0x0f, (tmpColor >> 8) & 0x0f, (tmpColor >> 12) & 0x0f); - bitmap.setPixel(x, y, color); - } +void Pict2Parser::handleEraseRgn() +{ + m_recordSize = (int)readU16() + 1; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); +} - m_painter->drawGraphicObject(propList, bitmap.getDIB()); - } - else if (color_format == 8) - { - int i = 0; - for (unsigned long y = 0; y < height; y++) - for (unsigned long x = 0; x < width; x++, i++) - { - const libpict::PictColor color(buffer[3*i+2] & 0xff, buffer[3*i+1] & 0xff, buffer[3*i] & 0xff); - bitmap.setPixel(x, y, color); - } +void Pict2Parser::handleInvertRgn() +{ + m_recordSize = (int)readU16() + 1; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); +} - m_painter->drawGraphicObject(propList, bitmap.getDIB()); - } - else if (color_format == 9) - { - int i = 0; - for (unsigned long y = 0; y < height; y++) - for (unsigned long x = 0; x < width; x++, i++) - { - const libpict::PictColor color(buffer[4*i+3], buffer[4*i+2] & 0xff, buffer[4*i+1] & 0xff, buffer[4*i] & 0xff); - bitmap.setPixel(x, y, color); - } +void Pict2Parser::handleFillRgn() +{ + m_recordSize = (int)readU16() + 1; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); +} - m_painter->drawGraphicObject(propList, bitmap.getDIB()); - } - else if (color_format == 12) - { - int i = 0; - for (unsigned long y = 0; y < height; y++) - for (unsigned long x = 0; x < width; x++, i++) - { - - const libpict::PictColor color(buffer[i], buffer[i], buffer[i]); - bitmap.setPixel(x, y, color); - } - m_painter->drawGraphicObject(propList, bitmap.getDIB()); - } - +void Pict2Parser::handleFrameSameRgn() +{ } -void Pict2Parser::handleObjectCapsule() +void Pict2Parser::handlePaintSameRgn() { - if (!m_graphicsStarted) - return; - ObjectCharacterization objCh; - parseCharacterization(&objCh); - m_matrix = objCh.matrix; - - long x1 = (m_doublePrecision) ? readS32() : readS16(); - long y1 = (m_doublePrecision) ? readS32() : readS16(); - long x2 = (m_doublePrecision) ? readS32() : readS16(); - long y2 = (m_doublePrecision) ? readS32() : readS16(); - TRANSFORM_XY(x1,y1); - 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; +} - m_binaryData.x1 = TO_DOUBLE(xs1) / m_xres; - m_binaryData.y1 = TO_DOUBLE(ys1) / m_yres; - m_binaryData.x2 = TO_DOUBLE(xs2) / m_xres; - m_binaryData.y2 = TO_DOUBLE(ys2) / m_yres; - - unsigned long numDescriptions = readU16(); - - m_binaryData.mimeTypes.clear(); - m_binaryData.mimeTypes.reserve(numDescriptions); - - static const char* mimeTypesMap[] = - { - "", // 0 - "", // "image/x-pict", - "", // "image/x-pict", - "", - "", - "", // 5 - "image/bmp", - "image/cgm", - "", - "image/x-dxf", - "image/x-eps", // 0xA - "", - "image/gif", - "application/vnd.hp-hpgl", - "", - "", // 0xF - "", // 0x10 - "", - "", - "image/x-pcx ", - "image/x-lotus-pic", - "", // Ox15 - "", - "image/x-quicktime", - "", - "application/x-postscript", - "", // 0x1A - "", - "image/x-targa", - "image/tiff", - "", - "image/wmf", // 0x1f - "", // 0x20 - "", - "", - "", - "", - "image/png", - "image/gif" // 0x26 - }; +void Pict2Parser::handleEraseSameRgn() +{ +} - for (unsigned long i = 0; m_input->tell() <= m_recordEnd && !m_input->atEOS() && i < numDescriptions; i++) - { - unsigned char description = readU8(); - if (description < 0x27) - m_binaryData.mimeTypes.push_back(WPXString(mimeTypesMap[description])); - m_input->seek(7, WPX_SEEK_CUR); - } +void Pict2Parser::handleInvertSameRgn() +{ +} - m_binaryData.objectIndex = 0; +void Pict2Parser::handleFillSameRgn() +{ +} - PICT_DEBUG_MSG((" x1 : %li\n", x1)); - PICT_DEBUG_MSG((" y1 : %li\n", y1)); - PICT_DEBUG_MSG((" x2 : %li\n", x2)); - PICT_DEBUG_MSG((" y2 : %li\n", y2)); - PICT_DEBUG_MSG(("numDescriptions : %li\n", numDescriptions)); +void Pict2Parser::handleBitsRect() +{ + unsigned short rowBytes = readU16(); + PICT_DEBUG_MSG(("Row bytes: %i\n", rowBytes)); + unsigned short bounds_top = readU16(); + PICT_DEBUG_MSG(("Bounds.top: %i\n", bounds_top)); + readU16(); + unsigned short bounds_bottom = readU16(); + PICT_DEBUG_MSG(("Bounds.bottom: %i\n", bounds_bottom)); + readU16(); + m_input->seek(18, WPX_SEEK_CUR); + m_recordSize = 29 + (0x7fff & rowBytes)*((bounds_bottom > bounds_top) ? bounds_bottom - bounds_top : bounds_top - bounds_bottom); + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); } -void Pict2Parser::handleObjectImage() +void Pict2Parser::handleBitsRgn() { - if (!m_graphicsStarted) - return; - if ((unsigned long)m_binaryData.objectIndex >= m_binaryData.mimeTypes.size()) - return; - unsigned accessoryDataLength = readU16(); - m_input->seek(accessoryDataLength, WPX_SEEK_CUR); + unsigned short rowBytes = readU16(); + PICT_DEBUG_MSG(("Row bytes: %i\n", rowBytes)); + unsigned short bounds_top = readU16(); + PICT_DEBUG_MSG(("Bounds.top: %i\n", bounds_top)); + readU16(); + unsigned short bounds_bottom = readU16(); + PICT_DEBUG_MSG(("Bounds.bottom: %i\n", bounds_bottom)); + readU16(); + m_input->seek(18, WPX_SEEK_CUR); + m_recordSize = 29 + (0x7fff & rowBytes)*((bounds_bottom > bounds_top) ? (int)(bounds_bottom - bounds_top) : (int)(bounds_top - bounds_bottom)); + m_recordSize += readU16(); + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); +} - ::WPXPropertyList propList; - propList.insert("svg:x", (double)m_binaryData.x1); - propList.insert("svg:y", (double)m_binaryData.y1); - propList.insert("svg:width", (m_binaryData.x2 - m_binaryData.x1)); - propList.insert("svg:height", (m_binaryData.y2 - m_binaryData.y1)); - propList.insert("libpict:mime-type", m_binaryData.mimeTypes[m_binaryData.objectIndex]); - - PICT_DEBUG_MSG(("Image Object Mime Type : %s\n", propList["libpict:mime-type"]->getStr().cstr())); - - ::WPXBinaryData binaryData; - while (!m_input->atEOS() && m_input->tell() <= m_recordEnd) - binaryData.append((char)readU8()); - PICT_DEBUG_MSG((" Image Object Size : %li\n", (unsigned long)binaryData.size())); - - // temporary for debug - dump the binary data (need to have write access in the current directory -#if DUMP_BINARY_DATA - std::ostringstream filename; - filename << "binarydump" << m_binaryId++ << ".bin"; - FILE *f = fopen(filename.str().c_str(), "wb"); - if (f) - { - const char *tmpBinaryBuffer = binaryData.getDataBuffer(); - unsigned long tmpBufferSize = binaryData.size(); - for (unsigned long k = 0; k < tmpBufferSize; k++) - fprintf(f, "%c",tmpBinaryBuffer[k]); - fclose(f); - } +void Pict2Parser::handlePackBitsRect() +{ + unsigned short rowBytes = readU16(); + PICT_DEBUG_MSG(("Row bytes: %i\n", rowBytes)); + unsigned short bounds_top = readU16(); + PICT_DEBUG_MSG(("Bounds.top: %i\n", bounds_top)); + readU16(); + unsigned short bounds_bottom = readU16(); + PICT_DEBUG_MSG(("Bounds.bottom: %i\n", bounds_bottom)); + readU16(); + m_input->seek(18, WPX_SEEK_CUR); +#if 0 + m_recordSize = 29 + (0x7fff & rowBytes)*((bounds_bottom > bounds_top) ? bounds_bottom - bounds_top : bounds_top - bounds_bottom); #endif - - - m_painter->drawGraphicObject(propList, binaryData); - m_binaryData.objectIndex++; + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); } -void Pict2Parser::handleTextLine() +void Pict2Parser::handlePackBitsRgn() { - if (!m_graphicsStarted) - return; - ObjectCharacterization objCh; - parseCharacterization(&objCh); - m_matrix = objCh.matrix; - - unsigned short textFlags = readU16(); - long x = (m_doublePrecision) ? readS32() : readS16(); - long y = (m_doublePrecision) ? readS32() : readS16(); - TRANSFORM_XY(x,y); - - unsigned char horizontalAlignment = readU8(); - unsigned char verticalAlignment = readU8(); - - double baseLineAngle = fixedPointToDouble(readU32()); - - PICT_DEBUG_MSG((" text flags : 0x%.4x\n", textFlags)); - PICT_DEBUG_MSG((" x : %li\n", x)); - PICT_DEBUG_MSG((" y : %li\n", y)); - PICT_DEBUG_MSG((" horizontal alignment : 0x%.2x\n", horizontalAlignment)); - PICT_DEBUG_MSG((" vertical alignment : 0x%.2x\n", verticalAlignment)); - PICT_DEBUG_MSG((" baseline angle : %.4f\n", baseLineAngle)); - - m_textData.x1 = TO_DOUBLE(x)/m_xres; - m_textData.y1 = TO_DOUBLE(y)/m_yres; - m_textData.x2 = TO_DOUBLE(x)/m_xres; - m_textData.y2 = TO_DOUBLE(y)/m_yres; - m_textData.flags = textFlags; - m_textData.horAlign = horizontalAlignment; - m_textData.vertAlign = verticalAlignment; - m_textData.baseLineAngle = baseLineAngle; - - m_drawTextData = true; -} - -void Pict2Parser::handleTextBlock() -{ - if (!m_graphicsStarted) - return; - ObjectCharacterization objCh; - parseCharacterization(&objCh); - m_matrix = objCh.matrix; - - long x1 = (m_doublePrecision) ? readS32() : readS16(); - long y1 = (m_doublePrecision) ? readS32() : readS16(); - long x2 = (m_doublePrecision) ? readS32() : readS16(); - long y2 = (m_doublePrecision) ? readS32() : readS16(); - TRANSFORM_XY(x1,y1); - 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; - - PICT_DEBUG_MSG((" x1 : %li\n", xs1)); - PICT_DEBUG_MSG((" y1 : %li\n", ys1)); - PICT_DEBUG_MSG((" x2 : %li\n", xs2)); - PICT_DEBUG_MSG((" y2 : %li\n", ys2)); - - m_textData.x1 = TO_DOUBLE(xs1)/m_xres; - m_textData.y1 = TO_DOUBLE(ys1)/m_yres; - m_textData.x2 = TO_DOUBLE(xs2)/m_xres; - m_textData.y2 = TO_DOUBLE(ys2)/m_yres; - m_textData.flags = 0; - m_textData.horAlign = 0; - m_textData.vertAlign = 0; - m_textData.baseLineAngle = 0.0; - - m_drawTextData = false; + unsigned short rowBytes = readU16(); + PICT_DEBUG_MSG(("Row bytes: %i\n", rowBytes)); + unsigned short bounds_top = readU16(); + PICT_DEBUG_MSG(("Bounds.top: %i\n", bounds_top)); + readU16(); + unsigned short bounds_bottom = readU16(); + PICT_DEBUG_MSG(("Bounds.bottom: %i\n", bounds_bottom)); + readU16(); + m_input->seek(18, WPX_SEEK_CUR); +#if 0 + m_recordSize = 29 + (0x7fff & rowBytes)*((bounds_bottom > bounds_top) ? bounds_bottom - bounds_top : bounds_top - bounds_bottom); + m_recordSize += readU16(); +#endif + PICT_DEBUG_MSG(("Size of the data: %i\n", m_recordSize)); } -void Pict2Parser::handleTextPath() +void Pict2Parser::handleShortComment() { - if (!m_graphicsStarted) - return; - - m_drawTextData = false; } -void Pict2Parser::handleTextData() +void Pict2Parser::handleLongComment() { - if (!m_graphicsStarted) - return; - if (!m_drawTextData) - return; - - ::WPXBinaryData textData; - while (!m_input->atEOS() && m_input->tell() <= m_recordEnd) - textData.append((char)readU8()); - PictTextDataHandler handler(m_painter); - ::WPXPropertyList propList; - - propList.insert("svg:x", (double)m_textData.x1); - propList.insert("svg:y", (double)m_textData.y1); - if (m_textData.x1 != m_textData.x2 && m_textData.y1 != m_textData.y2) - { - propList.insert("svg:width", (m_textData.x2 - m_textData.x1)); - propList.insert("svg:height", (m_textData.y2 - m_textData.y1)); - } - - m_painter->startTextObject(propList, ::WPXPropertyListVector()); - - WPDocument::parseSubDocument(const_cast<WPXInputStream *>(textData.getDataStream()), &handler, WPD_FILE_FORMAT_WP6); - - m_painter->endTextObject(); - - m_drawTextData = false; } -void Pict2Parser::resetPalette() +void Pict2Parser::handleEndOfPicture() { - m_colorPalette.clear(); - for (int i=0; i<256; i++) - { - unsigned char red = defaultPict2PaletteRed[i]; - unsigned char green = defaultPict2PaletteGreen[i]; - unsigned char blue = defaultPict2PaletteBlue[i]; - libpict::PictColor color(red, green, blue); - m_colorPalette[i] = color; - } } diff --git a/src/lib/Pict2Parser.h b/src/lib/Pict2Parser.h index e0236e1..b7a08ab 100644 --- a/src/lib/Pict2Parser.h +++ b/src/lib/Pict2Parser.h @@ -37,231 +37,126 @@ #include <stack> #include <vector> -class Pict2TransformMatrix -{ -public: - double element[3][3]; - - Pict2TransformMatrix() - { - // identity transformation - element[0][0] = element[1][1] = 1; element[2][2] = 1; - element[0][1] = element[0][2] = 0; - element[1][0] = element[1][2] = 0; - element[2][0] = element[2][1] = 0; - } - - void transform(long& x, long& y) const - { - long rx = (long)(element[0][0]*x + element[1][0]*y + element[2][0]); - long ry = (long)(element[0][1]*x + element[1][1]*y + element[2][1]); - x = rx; - y = ry; - } - - ::WPXPropertyList transformPoint(const ::WPXPropertyList& p) const - { - ::WPXPropertyList propList; - propList.insert("svg:x", (element[0][0]*p["svg:x"]->getDouble() + element[1][0]*p["svg:y"]->getDouble() + element[2][0])); - propList.insert("svg:y", (element[0][1]*p["svg:x"]->getDouble() + element[1][1]*p["svg:y"]->getDouble() + element[2][1])); - return propList; - } - - ::WPXPropertyList transformRect(const ::WPXPropertyList& r) const - { - ::WPXPropertyList propList; - double oldx1 = r["svg:x"]->getDouble(); - double oldy1 = r["svg:y"]->getDouble(); - double oldx2 = r["svg:x"]->getDouble() + r["svg:width"]->getDouble(); - double oldy2 = r["svg:y"]->getDouble() + r["svg:height"]->getDouble(); - - double newx1 = element[0][0]*oldx1 + element[1][0]*oldy1 + element[2][0]; - double newy1 = element[0][1]*oldx1 + element[1][1]*oldy1 + element[2][1]; - double newx2 = element[0][0]*oldx2 + element[1][0]*oldy2 + element[2][0]; - double newy2 = element[0][1]*oldx2 + element[1][1]*oldy2 + element[2][1]; - - propList.insert("svg:x", (double)newx1); - propList.insert("svg:y", (double)newy1); - propList.insert("svg:width", (newx2-newx1)); - propList.insert("svg:height", (newy2-newy1)); - return propList; - } - - Pict2TransformMatrix& transformBy(const Pict2TransformMatrix& m) - { - double result[3][3]; - - for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++) - { - result[i][j] = 0; - for(int k = 0; k < 3; k++) - result[i][j] += m.element[i][k]*element[k][j]; - } - - for(int x = 0; x < 3; x++) - for(int y = 0; y < 3; y++) - element[x][y] = result[x][y]; - - return *this; - } -}; - -class PictCompoundPolygon -{ -public: - Pict2TransformMatrix matrix; - bool isFilled; - bool isFramed; - bool isClosed; - - PictCompoundPolygon(): matrix(), isFilled(true), isFramed(true), isClosed(true) {} -}; - -class PictGroupContext -{ -public: - unsigned subIndex; - int parentType; - ::WPXPropertyListVector compoundPath; - Pict2TransformMatrix compoundMatrix; - bool compoundWindingRule; - bool compoundFilled; - bool compoundFramed; - bool compoundClosed; - - PictGroupContext(): subIndex(0), parentType(0), - compoundPath(), compoundMatrix(), compoundWindingRule(false), - compoundFilled(false), compoundFramed(true), compoundClosed(false) {} - - bool isCompoundPolygon() const { return parentType == 0x1a; } -}; - -class PictBitmapContext -{ -public: - double x1, y1, x2, y2; - long hres, vres; - PictBitmapContext(): x1(0), y1(0), x2(0), y2(0), hres(100), vres(100) {} -}; - -class PictBinaryDataContext -{ -public: - double x1, y1, x2, y2; - int numObjects, objectIndex; - std::vector<WPXString> mimeTypes; - PictBinaryDataContext(): x1(0), y1(0), x2(0), y2(0), numObjects(0), objectIndex(0), mimeTypes() {} -}; - -class PictTextDataContext -{ -public: - double x1, y1, x2, y2; - unsigned short flags; - unsigned char vertAlign; - unsigned char horAlign; - double baseLineAngle; - PictTextDataContext(): x1(0), y1(0), x2(0), y2(0), flags(), vertAlign(), horAlign(), baseLineAngle(0.0) {} -}; - class Pict2Parser : public PictXParser { public: - Pict2Parser(WPXInputStream *input, libwpg::WPGPaintInterface* painter, bool isEmbedded = false); + Pict2Parser(WPXInputStream *input, libwpg::WPGPaintInterface* painter); bool parse(); private: - void handleStartPict(); - void handleEndPict(); - void handleFormSettings(); - void handleLayer(); - void handleCompoundPolygon(); - - void handlePenStyleDefinition(); -// void handlePatternDefinition(); - void handleColorPalette(); - void handleDPColorPalette(); - void handlePenForeColor(); - void handleDPPenForeColor(); - void handlePenBackColor(); - void handleDPPenBackColor(); - void handlePenStyle(); - void handlePenSize(); - void handleDPPenSize(); - void handleLineCap(); - void handleLineJoin(); - void handleBrushGradient(); - void handleDPBrushGradient(); - void handleBrushForeColor(); - void handleDPBrushForeColor(); - void handleBrushBackColor(); - void handleDPBrushBackColor(); - void handleBrushPattern(); - - void handlePolyline(); - void handlePolyspline(); - void handlePolycurve(); - void handleRectangle(); - void handleArc(); - - void handleBitmap(); - void handleBitmapData(); - - void handleTextData(); - void handleTextLine(); - void handleTextBlock(); - void handleTextPath(); - - void handleObjectCapsule(); - void handleObjectImage(); - - void resetPalette(); - void flushCompoundPolygon(); - - // parsing context - int m_recordLength; - long m_recordEnd; - bool m_success; - bool m_exit; - bool m_graphicsStarted; - unsigned int m_xres; - unsigned int m_yres; - long m_xofs; - long m_yofs; - long m_width; - long m_height; - bool m_doublePrecision; - ::WPXPropertyList m_style; - libpict::PictColor m_penForeColor; - libpict::PictColor m_penBackColor; - libpict::PictColor m_brushForeColor; - libpict::PictColor m_brushBackColor; - libpict::PictDashArray m_dashArray; - ::WPXPropertyListVector m_gradient; - std::map<unsigned int,libpict::PictDashArray> m_dashArrayStyles; - bool m_layerOpened; - unsigned int m_layerId; - Pict2TransformMatrix m_matrix; - double m_gradientAngle; - ::WPXPropertyList m_gradientRef; - std::stack<PictGroupContext> m_groupStack; - Pict2TransformMatrix m_compoundMatrix; - bool m_compoundWindingRule; - bool m_compoundFilled; - bool m_compoundFramed; - bool m_compoundClosed; - PictBitmapContext m_bitmap; - PictBinaryDataContext m_binaryData; - bool m_hFlipped, m_vFlipped; - PictTextDataContext m_textData; - bool m_drawTextData; - - class ObjectCharacterization; - void parseCharacterization(ObjectCharacterization*); - unsigned m_binaryId; - - bool m_embedded; + void handleNOP(); + void handleClipRgn(); + void handleBkPat(); + void handleTxFont(); + void handleTxFace(); + void handleTxMode(); + void handleSpExtra(); + void handlePnSize(); + void handlePnMode(); + void handlePnPat(); + void handleThePat(); + void handleOwSize(); + void handleOrigin(); + void handleTxSize(); + void handleFgColor(); + void handleBkColor(); + void handleTxRatio(); + void handlePicVersion(); + + void handleLine(); + void handleLineFrom(); + void handleShortLine(); + void handleShortLineFrom(); + + void handleLongText(); + void handleDHText(); + void handleDVText(); + void handleDHDVText(); + + void handleFrameRect(); + void handlePaintRect(); + void handleEraseRect(); + void handleInvertRect(); + void handleFillRect(); + + void handleFrameSameRect(); + void handlePaintSameRect(); + void handleEraseSameRect(); + void handleInvertSameRect(); + void handleFillSameRect(); + + void handleFrameRRect(); + void handlePaintRRect(); + void handleEraseRRect(); + void handleInvertRRect(); + void handleFillRRect(); + + void handleFrameSameRRect(); + void handlePaintSameRRect(); + void handleEraseSameRRect(); + void handleInvertSameRRect(); + void handleFillSameRRect(); + + void handleFrameOval(); + void handlePaintOval(); + void handleEraseOval(); + void handleInsertOval(); + void handleFillOval(); + + void handleFrameSameOval(); + void handlePaintSameOval(); + void handleEraseSameOval(); + void handleInsertSameOval(); + void handleFillSameOval(); + + void handleFrameArc(); + void handlePaintArc(); + void handleEraseArc(); + void handleInsertArc(); + void handleFillArc(); + + void handleFrameSameArc(); + void handlePaintSameArc(); + void handleEraseSameArc(); + void handleInsertSameArc(); + void handleFillSameArc(); + + void handleFramePoly(); + void handlePaintPoly(); + void handleErasePoly(); + void handleInvertPoly(); + void handleFillPoly(); + + void handleFrameSamePoly(); + void handlePaintSamePoly(); + void handleEraseSamePoly(); + void handleInvertSamePoly(); + void handleFillSamePoly(); + + void handleFrameRgn(); + void handlePaintRgn(); + void handleEraseRgn(); + void handleInvertRgn(); + void handleFillRgn(); + + void handleFrameSameRgn(); + void handlePaintSameRgn(); + void handleEraseSameRgn(); + void handleInvertSameRgn(); + void handleFillSameRgn(); + + void handleBitsRect(); + void handleBitsRgn(); + + void handlePackBitsRect(); + void handlePackBitsRgn(); + + void handleShortComment(); + void handleLongComment(); + + void handleEndOfPicture(); + + int m_recordSize; }; #endif // __PICT2PARSER_H__ |