WPG2Parser.h
Go to the documentation of this file.
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* libwpg
* Version: MPL 2.0 / LGPLv2.1+
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Major Contributor(s):
* Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
* Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2004 Marc Oude Kotte (marc@solcon.nl)
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU Lesser General Public License Version 2.1 or later
* (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
* applicable instead of those above.
*
* For further information visit http://libwpg.sourceforge.net
*/
/* "This product is not manufactured, approved, or supported by
* Corel Corporation or Corel Corporation Limited."
*/
#ifndef __WPG2PARSER_H__
#define __WPG2PARSER_H__
#include <limits>
#include <map>
#include <stack>
#include <vector>
#include <librevenge/librevenge.h>
#include "WPGBitmap.h"
#include "WPGDashArray.h"
#include "WPGXParser.h"
class WPG2TransformMatrix
{
public:
double element[3][3];
WPG2TransformMatrix()
{
// 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
{
const double rx = element[0][0]*x + element[1][0]*y + element[2][0];
const double ry = element[0][1]*x + element[1][1]*y + element[2][1];
x = toLong(rx);
y = toLong(ry);
}
librevenge::RVNGPropertyList transformPoint(const ::librevenge::RVNGPropertyList &p) const
{
librevenge::RVNGPropertyList 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;
}
librevenge::RVNGPropertyList transformRect(const ::librevenge::RVNGPropertyList &r) const
{
librevenge::RVNGPropertyList 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;
}
WPG2TransformMatrix &transformBy(const WPG2TransformMatrix &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;
}
private:
static long toLong(double d)
{
if (d > double(std::numeric_limits<long>::max()))
return std::numeric_limits<long>::max();
else if (d < double(std::numeric_limits<long>::min()))
return std::numeric_limits<long>::min();
else
return long(d);
}
};
class WPGCompoundPolygon
{
public:
WPG2TransformMatrix matrix;
bool isFilled;
bool isFramed;
bool isClosed;
WPGCompoundPolygon(): matrix(), isFilled(true), isFramed(true), isClosed(true) {}
};
class WPGGroupContext
{
public:
unsigned subIndex;
int parentType;
librevenge::RVNGPropertyListVector compoundPath;
WPG2TransformMatrix compoundMatrix;
bool compoundWindingRule;
bool compoundFilled;
bool compoundFramed;
bool compoundClosed;
WPGGroupContext(): subIndex(0), parentType(0),
compoundPath(), compoundMatrix(), compoundWindingRule(false),
compoundFilled(false), compoundFramed(true), compoundClosed(false) {}
bool isCompoundPolygon() const
{
return parentType == 0x1a;
}
};
class WPGBitmapContext
{
public:
double x1, y1, x2, y2;
long hres, vres;
WPGBitmapContext(): x1(0), y1(0), x2(0), y2(0), hres(100), vres(100) {}
};
class WPGBinaryDataContext
{
public:
double x1, y1, x2, y2;
int numObjects, objectIndex;
std::vector<librevenge::RVNGString> mimeTypes;
WPGBinaryDataContext(): x1(0), y1(0), x2(0), y2(0), numObjects(0), objectIndex(0), mimeTypes() {}
};
class WPGTextDataContext
{
public:
double x1, y1, x2, y2;
unsigned short flags;
unsigned char vertAlign;
unsigned char horAlign;
double baseLineAngle;
WPGTextDataContext(): x1(0), y1(0), x2(0), y2(0), flags(), vertAlign(), horAlign(), baseLineAngle(0.0) {}
};
class WPG2Parser : public WPGXParser
{
public:
WPG2Parser(librevenge::RVNGInputStream *input, librevenge::RVNGDrawingInterface *painter, bool isEmbedded = false);
bool parse() override;
private:
void handleStartWPG();
void handleEndWPG();
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();
void setPenStyle();
unsigned int getRemainingRecordLength() const;
bool checkRLESize(unsigned bytes) const;
double toDouble(long x) const;
void transformXY(long &x, long &y) const;
// 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;
librevenge::RVNGPropertyList m_style;
libwpg::WPGColor m_penForeColor;
libwpg::WPGColor m_penBackColor;
libwpg::WPGColor m_brushForeColor;
libwpg::WPGColor m_brushBackColor;
libwpg::WPGDashArray m_dashArray;
librevenge::RVNGPropertyListVector m_gradient;
std::map<unsigned int,libwpg::WPGDashArray> m_dashArrayStyles;
bool m_layerOpened;
#ifdef DEBUG
unsigned int m_layerId;
#endif
WPG2TransformMatrix m_matrix;
double m_gradientAngle;
librevenge::RVNGPropertyList m_gradientRef;
std::stack<WPGGroupContext> m_groupStack;
WPG2TransformMatrix m_compoundMatrix;
bool m_compoundWindingRule;
bool m_compoundFilled;
bool m_compoundFramed;
bool m_compoundClosed;
WPGBitmapContext m_bitmap;
WPGBinaryDataContext m_binaryData;
bool m_hFlipped, m_vFlipped;
WPGTextDataContext m_textData;
bool m_drawTextData;
class ObjectCharacterization;
void parseCharacterization(ObjectCharacterization *);
#if DUMP_BINARY_DATA
unsigned m_binaryId;
#endif
};
#endif // __WPG2PARSER_H__
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPGBitmap.h
WPGDashArray.h
WPGXParser.h
WPG2Parser::ObjectCharacterization
Definition WPG2Parser.cpp:199
WPG2Parser::handleDPBrushForeColor
void handleDPBrushForeColor()
Definition WPG2Parser.cpp:1190
WPG2Parser::m_textData
WPGTextDataContext m_textData
Definition WPG2Parser.h:283
WPG2Parser::m_compoundFramed
bool m_compoundFramed
Definition WPG2Parser.h:278
WPG2Parser::m_bitmap
WPGBitmapContext m_bitmap
Definition WPG2Parser.h:280
WPG2Parser::handleLineCap
void handleLineCap()
Definition WPG2Parser.cpp:997
WPG2Parser::m_width
long m_width
Definition WPG2Parser.h:256
WPG2Parser::handleRectangle
void handleRectangle()
Definition WPG2Parser.cpp:1630
WPG2Parser::handleObjectCapsule
void handleObjectCapsule()
Definition WPG2Parser.cpp:2191
WPG2Parser::parseCharacterization
void parseCharacterization(ObjectCharacterization *)
Definition WPG2Parser.cpp:1351
WPG2Parser::m_xofs
long m_xofs
Definition WPG2Parser.h:254
WPG2Parser::handleBrushGradient
void handleBrushGradient()
Definition WPG2Parser.cpp:1025
WPG2Parser::handleBrushBackColor
void handleBrushBackColor()
Definition WPG2Parser.cpp:1286
WPG2Parser::WPG2Parser
WPG2Parser(librevenge::RVNGInputStream *input, librevenge::RVNGDrawingInterface *painter, bool isEmbedded=false)
Definition WPG2Parser.cpp:258
WPG2Parser::m_style
librevenge::RVNGPropertyList m_style
Definition WPG2Parser.h:259
WPG2Parser::m_matrix
WPG2TransformMatrix m_matrix
Definition WPG2Parser.h:271
WPG2Parser::handlePolyline
void handlePolyline()
Definition WPG2Parser.cpp:1437
WPG2Parser::handleDPColorPalette
void handleDPColorPalette()
Definition WPG2Parser.cpp:812
WPG2Parser::m_vFlipped
bool m_vFlipped
Definition WPG2Parser.h:282
WPG2Parser::m_groupStack
std::stack< WPGGroupContext > m_groupStack
Definition WPG2Parser.h:274
WPG2Parser::flushCompoundPolygon
void flushCompoundPolygon()
Definition WPG2Parser.cpp:727
WPG2Parser::m_gradient
librevenge::RVNGPropertyListVector m_gradient
Definition WPG2Parser.h:265
WPG2Parser::handleDPPenForeColor
void handleDPPenForeColor()
Definition WPG2Parser.cpp:855
WPG2Parser::m_xres
unsigned int m_xres
Definition WPG2Parser.h:252
WPG2Parser::handleTextLine
void handleTextLine()
Definition WPG2Parser.cpp:2329
WPG2Parser::handlePolyspline
void handlePolyspline()
Definition WPG2Parser.cpp:1531
WPG2Parser::m_graphicsStarted
bool m_graphicsStarted
Definition WPG2Parser.h:251
WPG2Parser::handleBitmap
void handleBitmap()
Definition WPG2Parser.cpp:1769
WPG2Parser::handlePenSize
void handlePenSize()
Definition WPG2Parser.cpp:960
WPG2Parser::handleBrushForeColor
void handleBrushForeColor()
Definition WPG2Parser.cpp:1095
WPG2Parser::handleTextData
void handleTextData()
Definition WPG2Parser.cpp:2411
WPG2Parser::handleEndWPG
void handleEndWPG()
Definition WPG2Parser.cpp:661
WPG2Parser::m_recordLength
int m_recordLength
Definition WPG2Parser.h:247
WPG2Parser::handleArc
void handleArc()
Definition WPG2Parser.cpp:1683
WPG2Parser::handleStartWPG
void handleStartWPG()
Definition WPG2Parser.cpp:554
WPG2Parser::handlePenStyleDefinition
void handlePenStyleDefinition()
Definition WPG2Parser.cpp:760
WPG2Parser::handlePenStyle
void handlePenStyle()
Definition WPG2Parser.cpp:935
WPG2Parser::m_layerOpened
bool m_layerOpened
Definition WPG2Parser.h:267
WPG2Parser::m_drawTextData
bool m_drawTextData
Definition WPG2Parser.h:284
WPG2Parser::m_compoundWindingRule
bool m_compoundWindingRule
Definition WPG2Parser.h:276
WPG2Parser::handleCompoundPolygon
void handleCompoundPolygon()
Definition WPG2Parser.cpp:713
WPG2Parser::handleDPBrushGradient
void handleDPBrushGradient()
Definition WPG2Parser.cpp:1060
WPG2Parser::transformXY
void transformXY(long &x, long &y) const
Definition WPG2Parser.cpp:2477
WPG2Parser::m_success
bool m_success
Definition WPG2Parser.h:249
WPG2Parser::handlePenForeColor
void handlePenForeColor()
Definition WPG2Parser.cpp:831
WPG2Parser::handleTextPath
void handleTextPath()
Definition WPG2Parser.cpp:2403
WPG2Parser::m_yres
unsigned int m_yres
Definition WPG2Parser.h:253
WPG2Parser::parse
bool parse() override
Definition WPG2Parser.cpp:317
WPG2Parser::m_dashArray
libwpg::WPGDashArray m_dashArray
Definition WPG2Parser.h:264
WPG2Parser::handleLayer
void handleLayer()
Definition WPG2Parser.cpp:696
WPG2Parser::m_brushBackColor
libwpg::WPGColor m_brushBackColor
Definition WPG2Parser.h:263
WPG2Parser::m_yofs
long m_yofs
Definition WPG2Parser.h:255
WPG2Parser::getRemainingRecordLength
unsigned int getRemainingRecordLength() const
Definition WPG2Parser.cpp:2458
WPG2Parser::m_compoundFilled
bool m_compoundFilled
Definition WPG2Parser.h:277
WPG2Parser::m_brushForeColor
libwpg::WPGColor m_brushForeColor
Definition WPG2Parser.h:262
WPG2Parser::handleBrushPattern
void handleBrushPattern()
Definition WPG2Parser.cpp:1331
WPG2Parser::handleLineJoin
void handleLineJoin()
Definition WPG2Parser.cpp:1011
WPG2Parser::handlePatternDefinition
void handlePatternDefinition()
Definition WPG2Parser.cpp:786
WPG2Parser::handleBitmapData
void handleBitmapData()
Definition WPG2Parser.cpp:1819
WPG2Parser::handleDPPenSize
void handleDPPenSize()
Definition WPG2Parser.cpp:978
WPG2Parser::m_recordEnd
long m_recordEnd
Definition WPG2Parser.h:248
WPG2Parser::m_compoundClosed
bool m_compoundClosed
Definition WPG2Parser.h:279
WPG2Parser::toDouble
double toDouble(long x) const
Definition WPG2Parser.cpp:2472
WPG2Parser::resetPalette
void resetPalette()
Definition WPG2Parser.cpp:2445
WPG2Parser::m_gradientAngle
double m_gradientAngle
Definition WPG2Parser.h:272
WPG2Parser::setPenStyle
void setPenStyle()
Definition WPG2Parser.cpp:921
WPG2Parser::handleTextBlock
void handleTextBlock()
Definition WPG2Parser.cpp:2366
WPG2Parser::handleColorPalette
void handleColorPalette()
Definition WPG2Parser.cpp:793
WPG2Parser::m_binaryData
WPGBinaryDataContext m_binaryData
Definition WPG2Parser.h:281
WPG2Parser::m_doublePrecision
bool m_doublePrecision
Definition WPG2Parser.h:258
WPG2Parser::handlePolycurve
void handlePolycurve()
Definition WPG2Parser.cpp:1544
WPG2Parser::m_penForeColor
libwpg::WPGColor m_penForeColor
Definition WPG2Parser.h:260
WPG2Parser::m_height
long m_height
Definition WPG2Parser.h:257
WPG2Parser::handleFormSettings
void handleFormSettings()
Definition WPG2Parser.cpp:674
WPG2Parser::m_compoundMatrix
WPG2TransformMatrix m_compoundMatrix
Definition WPG2Parser.h:275
WPG2Parser::handleDPPenBackColor
void handleDPPenBackColor()
Definition WPG2Parser.cpp:900
WPG2Parser::handleDPBrushBackColor
void handleDPBrushBackColor()
Definition WPG2Parser.cpp:1308
WPG2Parser::m_hFlipped
bool m_hFlipped
Definition WPG2Parser.h:282
WPG2Parser::m_dashArrayStyles
std::map< unsigned int, libwpg::WPGDashArray > m_dashArrayStyles
Definition WPG2Parser.h:266
WPG2Parser::m_penBackColor
libwpg::WPGColor m_penBackColor
Definition WPG2Parser.h:261
WPG2Parser::handleObjectImage
void handleObjectImage()
Definition WPG2Parser.cpp:2281
WPG2Parser::m_exit
bool m_exit
Definition WPG2Parser.h:250
WPG2Parser::checkRLESize
bool checkRLESize(unsigned bytes) const
Definition WPG2Parser.cpp:2465
WPG2Parser::handlePenBackColor
void handlePenBackColor()
Definition WPG2Parser.cpp:880
WPG2Parser::m_gradientRef
librevenge::RVNGPropertyList m_gradientRef
Definition WPG2Parser.h:273
WPG2TransformMatrix
Definition WPG2Parser.h:43
WPG2TransformMatrix::transformBy
WPG2TransformMatrix & transformBy(const WPG2TransformMatrix &m)
Definition WPG2Parser.h:93
WPG2TransformMatrix::toLong
static long toLong(double d)
Definition WPG2Parser.h:113
WPG2TransformMatrix::transformPoint
librevenge::RVNGPropertyList transformPoint(const ::librevenge::RVNGPropertyList &p) const
Definition WPG2Parser.h:65
WPG2TransformMatrix::transform
void transform(long &x, long &y) const
Definition WPG2Parser.h:57
WPG2TransformMatrix::transformRect
librevenge::RVNGPropertyList transformRect(const ::librevenge::RVNGPropertyList &r) const
Definition WPG2Parser.h:73
WPG2TransformMatrix::element
double element[3][3]
Definition WPG2Parser.h:45
WPG2TransformMatrix::WPG2TransformMatrix
WPG2TransformMatrix()
Definition WPG2Parser.h:47
WPGBinaryDataContext
Definition WPG2Parser.h:166
WPGBinaryDataContext::numObjects
int numObjects
Definition WPG2Parser.h:169
WPGBinaryDataContext::y1
double y1
Definition WPG2Parser.h:168
WPGBinaryDataContext::x2
double x2
Definition WPG2Parser.h:168
WPGBinaryDataContext::x1
double x1
Definition WPG2Parser.h:168
WPGBinaryDataContext::mimeTypes
std::vector< librevenge::RVNGString > mimeTypes
Definition WPG2Parser.h:170
WPGBinaryDataContext::WPGBinaryDataContext
WPGBinaryDataContext()
Definition WPG2Parser.h:171
WPGBinaryDataContext::y2
double y2
Definition WPG2Parser.h:168
WPGBinaryDataContext::objectIndex
int objectIndex
Definition WPG2Parser.h:169
WPGBitmapContext
Definition WPG2Parser.h:158
WPGBitmapContext::y2
double y2
Definition WPG2Parser.h:160
WPGBitmapContext::y1
double y1
Definition WPG2Parser.h:160
WPGBitmapContext::vres
long vres
Definition WPG2Parser.h:161
WPGBitmapContext::x1
double x1
Definition WPG2Parser.h:160
WPGBitmapContext::x2
double x2
Definition WPG2Parser.h:160
WPGBitmapContext::WPGBitmapContext
WPGBitmapContext()
Definition WPG2Parser.h:162
WPGBitmapContext::hres
long hres
Definition WPG2Parser.h:161
WPGCompoundPolygon::isFilled
bool isFilled
Definition WPG2Parser.h:128
WPGCompoundPolygon::WPGCompoundPolygon
WPGCompoundPolygon()
Definition WPG2Parser.h:132
WPGCompoundPolygon::isClosed
bool isClosed
Definition WPG2Parser.h:130
WPGCompoundPolygon::matrix
WPG2TransformMatrix matrix
Definition WPG2Parser.h:127
WPGCompoundPolygon::isFramed
bool isFramed
Definition WPG2Parser.h:129
WPGGroupContext::compoundMatrix
WPG2TransformMatrix compoundMatrix
Definition WPG2Parser.h:141
WPGGroupContext::compoundFilled
bool compoundFilled
Definition WPG2Parser.h:143
WPGGroupContext::compoundPath
librevenge::RVNGPropertyListVector compoundPath
Definition WPG2Parser.h:140
WPGGroupContext::isCompoundPolygon
bool isCompoundPolygon() const
Definition WPG2Parser.h:151
WPGGroupContext::subIndex
unsigned subIndex
Definition WPG2Parser.h:138
WPGGroupContext::compoundWindingRule
bool compoundWindingRule
Definition WPG2Parser.h:142
WPGGroupContext::compoundFramed
bool compoundFramed
Definition WPG2Parser.h:144
WPGGroupContext::WPGGroupContext
WPGGroupContext()
Definition WPG2Parser.h:147
WPGGroupContext::compoundClosed
bool compoundClosed
Definition WPG2Parser.h:145
WPGGroupContext::parentType
int parentType
Definition WPG2Parser.h:139
WPGTextDataContext
Definition WPG2Parser.h:175
WPGTextDataContext::baseLineAngle
double baseLineAngle
Definition WPG2Parser.h:181
WPGTextDataContext::y2
double y2
Definition WPG2Parser.h:177
WPGTextDataContext::x1
double x1
Definition WPG2Parser.h:177
WPGTextDataContext::y1
double y1
Definition WPG2Parser.h:177
WPGTextDataContext::horAlign
unsigned char horAlign
Definition WPG2Parser.h:180
WPGTextDataContext::x2
double x2
Definition WPG2Parser.h:177
WPGTextDataContext::vertAlign
unsigned char vertAlign
Definition WPG2Parser.h:179
WPGTextDataContext::WPGTextDataContext
WPGTextDataContext()
Definition WPG2Parser.h:182
WPGTextDataContext::flags
unsigned short flags
Definition WPG2Parser.h:178
WPGXParser::WPGXParser
WPGXParser(librevenge::RVNGInputStream *input, librevenge::RVNGDrawingInterface *painter)
Definition WPGXParser.cpp:30
libwpg::WPGColor
Definition WPGColor.h:35
libwpg::WPGDashArray
Definition WPGDashArray.h:37