| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#ifndef PAINTCOMMANDS_H |
| 29 |
#define PAINTCOMMANDS_H |
| 30 |
|
| 31 |
#include <qcolor.h> |
| 32 |
#include <qmap.h> |
| 33 |
#include <qpainterpath.h> |
| 34 |
#include <qregion.h> |
| 35 |
#include <qregularexpression.h> |
| 36 |
#include <qstringlist.h> |
| 37 |
#include <qpixmap.h> |
| 38 |
#include <qbrush.h> |
| 39 |
#include <qhash.h> |
| 40 |
|
| 41 |
QT_FORWARD_DECLARE_CLASS(QPainter) |
| 42 |
#ifndef QT_NO_OPENGL |
| 43 |
QT_FORWARD_DECLARE_CLASS(QOpenGLFramebufferObject) |
| 44 |
QT_FORWARD_DECLARE_CLASS(QOpenGLPaintDevice) |
| 45 |
QT_FORWARD_DECLARE_CLASS(QOpenGLContext) |
| 46 |
#endif |
| 47 |
|
| 48 |
enum DeviceType { |
| 49 |
WidgetType, |
| 50 |
BitmapType, |
| 51 |
PixmapType, |
| 52 |
ImageType, |
| 53 |
ImageMonoType, |
| 54 |
OpenGLType, |
| 55 |
OpenGLBufferType, |
| 56 |
PictureType, |
| 57 |
PrinterType, |
| 58 |
PdfType, |
| 59 |
PsType, |
| 60 |
GrabType, |
| 61 |
CustomDeviceType, |
| 62 |
CustomWidgetType, |
| 63 |
ImageWidgetType |
| 64 |
}; |
| 65 |
|
| 66 |
|
| 67 |
class PaintCommands |
| 68 |
{ |
| 69 |
public: |
| 70 |
|
| 71 |
PaintCommands(const QStringList &cmds, int w, int h, QImage::Format format) |
| 72 |
: m_painter(0) |
| 73 |
, m_surface_painter(0) |
| 74 |
, m_format(format) |
| 75 |
, m_commands(cmds) |
| 76 |
, m_gradientSpread(QGradient::PadSpread) |
| 77 |
, m_gradientCoordinate(QGradient::LogicalMode) |
| 78 |
, m_width(w) |
| 79 |
, m_height(h) |
| 80 |
, m_verboseMode(false) |
| 81 |
, m_type(WidgetType) |
| 82 |
, m_checkers_background(true) |
| 83 |
, m_shouldDrawText(true) |
| 84 |
#ifndef QT_NO_OPENGL |
| 85 |
, m_default_glcontext(0) |
| 86 |
, m_surface_glcontext(0) |
| 87 |
, m_surface_glbuffer(0) |
| 88 |
, m_surface_glpaintdevice(0) |
| 89 |
#endif |
| 90 |
{ staticInit(); } |
| 91 |
|
| 92 |
public: |
| 93 |
void setCheckersBackground(bool b) { staticInit(); m_checkers_background = b; } |
| 94 |
void setContents(const QStringList &cmds) { |
| 95 |
staticInit(); |
| 96 |
m_blockMap.clear(); |
| 97 |
m_pathMap.clear(); |
| 98 |
m_pixmapMap.clear(); |
| 99 |
m_imageMap.clear(); |
| 100 |
m_regionMap.clear(); |
| 101 |
m_gradientStops.clear(); |
| 102 |
m_controlPoints.clear(); |
| 103 |
m_gradientSpread = QGradient::PadSpread; |
| 104 |
m_gradientCoordinate = QGradient::LogicalMode; |
| 105 |
m_commands = cmds; |
| 106 |
|
| 107 |
|
| 108 |
} |
| 109 |
void setPainter(QPainter *pt) { staticInit(); m_painter = pt; } |
| 110 |
void setType(DeviceType t) { staticInit(); m_type = t; } |
| 111 |
void setFilePath(const QString &path) { staticInit(); m_filepath = path; } |
| 112 |
void setControlPoints(const QVector<QPointF> &points) { staticInit(); m_controlPoints = points; } |
| 113 |
void setVerboseMode(bool v) { staticInit(); m_verboseMode = v; } |
| 114 |
void insertAt(int commandIndex, const QStringList &newCommands); |
| 115 |
void setShouldDrawText(bool drawText) { m_shouldDrawText = drawText; } |
| 116 |
|
| 117 |
|
| 118 |
void runCommands(); |
| 119 |
|
| 120 |
private: |
| 121 |
|
| 122 |
void runCommand(const QString &scriptLine); |
| 123 |
|
| 124 |
|
| 125 |
int convertToInt(const QString &str); |
| 126 |
double convertToDouble(const QString &str); |
| 127 |
float convertToFloat(const QString &str); |
| 128 |
QColor convertToColor(const QString &str); |
| 129 |
|
| 130 |
|
| 131 |
void command_comment(QRegularExpressionMatch re); |
| 132 |
|
| 133 |
|
| 134 |
void command_import(QRegularExpressionMatch re); |
| 135 |
|
| 136 |
|
| 137 |
void command_begin_block(QRegularExpressionMatch re); |
| 138 |
void command_end_block(QRegularExpressionMatch re); |
| 139 |
void command_repeat_block(QRegularExpressionMatch re); |
| 140 |
|
| 141 |
|
| 142 |
void command_textlayout_draw(QRegularExpressionMatch re); |
| 143 |
void command_abort(QRegularExpressionMatch re); |
| 144 |
|
| 145 |
|
| 146 |
void command_noop(QRegularExpressionMatch re); |
| 147 |
|
| 148 |
|
| 149 |
void command_setBgMode(QRegularExpressionMatch re); |
| 150 |
void command_setBackground(QRegularExpressionMatch re); |
| 151 |
void command_setOpacity(QRegularExpressionMatch re); |
| 152 |
void command_path_setFillRule(QRegularExpressionMatch re); |
| 153 |
void command_setBrush(QRegularExpressionMatch re); |
| 154 |
void command_setBrushOrigin(QRegularExpressionMatch re); |
| 155 |
void command_brushTranslate(QRegularExpressionMatch re); |
| 156 |
void command_brushRotate(QRegularExpressionMatch re); |
| 157 |
void command_brushScale(QRegularExpressionMatch re); |
| 158 |
void command_brushShear(QRegularExpressionMatch re); |
| 159 |
void command_setClipPath(QRegularExpressionMatch re); |
| 160 |
void command_setClipRect(QRegularExpressionMatch re); |
| 161 |
void command_setClipRectangle(QRegularExpressionMatch re); |
| 162 |
void command_setClipRegion(QRegularExpressionMatch re); |
| 163 |
void command_setClipping(QRegularExpressionMatch re); |
| 164 |
void command_setCompositionMode(QRegularExpressionMatch re); |
| 165 |
void command_setFont(QRegularExpressionMatch re); |
| 166 |
void command_setPen(QRegularExpressionMatch re); |
| 167 |
void command_setPen2(QRegularExpressionMatch re); |
| 168 |
void command_pen_setDashOffset(QRegularExpressionMatch re); |
| 169 |
void command_pen_setDashPattern(QRegularExpressionMatch re); |
| 170 |
void command_pen_setCosmetic(QRegularExpressionMatch re); |
| 171 |
void command_setRenderHint(QRegularExpressionMatch re); |
| 172 |
void command_clearRenderHint(QRegularExpressionMatch re); |
| 173 |
void command_gradient_appendStop(QRegularExpressionMatch re); |
| 174 |
void command_gradient_clearStops(QRegularExpressionMatch re); |
| 175 |
void command_gradient_setConical(QRegularExpressionMatch re); |
| 176 |
void command_gradient_setLinear(QRegularExpressionMatch re); |
| 177 |
void command_gradient_setRadial(QRegularExpressionMatch re); |
| 178 |
void command_gradient_setRadialExtended(QRegularExpressionMatch re); |
| 179 |
void command_gradient_setLinearPen(QRegularExpressionMatch re); |
| 180 |
void command_gradient_setSpread(QRegularExpressionMatch re); |
| 181 |
void command_gradient_setCoordinateMode(QRegularExpressionMatch re); |
| 182 |
|
| 183 |
|
| 184 |
void command_drawArc(QRegularExpressionMatch re); |
| 185 |
void command_drawChord(QRegularExpressionMatch re); |
| 186 |
void command_drawConvexPolygon(QRegularExpressionMatch re); |
| 187 |
void command_drawEllipse(QRegularExpressionMatch re); |
| 188 |
void command_drawImage(QRegularExpressionMatch re); |
| 189 |
void command_drawLine(QRegularExpressionMatch re); |
| 190 |
void command_drawLines(QRegularExpressionMatch re); |
| 191 |
void command_drawPath(QRegularExpressionMatch re); |
| 192 |
void command_drawPie(QRegularExpressionMatch re); |
| 193 |
void command_drawPixmap(QRegularExpressionMatch re); |
| 194 |
void command_drawPoint(QRegularExpressionMatch re); |
| 195 |
void command_drawPolygon(QRegularExpressionMatch re); |
| 196 |
void command_drawPolyline(QRegularExpressionMatch re); |
| 197 |
void command_drawRect(QRegularExpressionMatch re); |
| 198 |
void command_drawRoundedRect(QRegularExpressionMatch re); |
| 199 |
void command_drawRoundRect(QRegularExpressionMatch re); |
| 200 |
void command_drawText(QRegularExpressionMatch re); |
| 201 |
void command_drawStaticText(QRegularExpressionMatch re); |
| 202 |
void command_drawGlyphRun(QRegularExpressionMatch re); |
| 203 |
void command_drawTextDocument(QRegularExpressionMatch re); |
| 204 |
void command_drawTiledPixmap(QRegularExpressionMatch re); |
| 205 |
void command_fillRect(QRegularExpressionMatch re); |
| 206 |
void command_fillRectF(QRegularExpressionMatch re); |
| 207 |
|
| 208 |
|
| 209 |
void command_path_addEllipse(QRegularExpressionMatch re); |
| 210 |
void command_path_addPolygon(QRegularExpressionMatch re); |
| 211 |
void command_path_addRect(QRegularExpressionMatch re); |
| 212 |
void command_path_addText(QRegularExpressionMatch re); |
| 213 |
void command_path_arcTo(QRegularExpressionMatch re); |
| 214 |
void command_path_closeSubpath(QRegularExpressionMatch re); |
| 215 |
void command_path_createOutline(QRegularExpressionMatch re); |
| 216 |
void command_path_cubicTo(QRegularExpressionMatch re); |
| 217 |
void command_path_debugPrint(QRegularExpressionMatch re); |
| 218 |
void command_path_lineTo(QRegularExpressionMatch re); |
| 219 |
void command_path_moveTo(QRegularExpressionMatch re); |
| 220 |
void command_region_addEllipse(QRegularExpressionMatch re); |
| 221 |
void command_region_addRect(QRegularExpressionMatch re); |
| 222 |
|
| 223 |
|
| 224 |
void command_region_getClipRegion(QRegularExpressionMatch re); |
| 225 |
void command_path_getClipPath(QRegularExpressionMatch re); |
| 226 |
|
| 227 |
|
| 228 |
void command_surface_begin(QRegularExpressionMatch re); |
| 229 |
void command_surface_end(QRegularExpressionMatch re); |
| 230 |
|
| 231 |
|
| 232 |
void command_restore(QRegularExpressionMatch re); |
| 233 |
void command_save(QRegularExpressionMatch re); |
| 234 |
|
| 235 |
|
| 236 |
void command_pixmap_load(QRegularExpressionMatch re); |
| 237 |
void command_pixmap_setMask(QRegularExpressionMatch re); |
| 238 |
void command_bitmap_load(QRegularExpressionMatch re); |
| 239 |
void command_pixmap_setDevicePixelRatio(QRegularExpressionMatch re); |
| 240 |
void command_image_convertToFormat(QRegularExpressionMatch re); |
| 241 |
void command_image_load(QRegularExpressionMatch re); |
| 242 |
void command_image_setColor(QRegularExpressionMatch re); |
| 243 |
void command_image_setColorCount(QRegularExpressionMatch re); |
| 244 |
void command_image_setDevicePixelRatio(QRegularExpressionMatch re); |
| 245 |
|
| 246 |
|
| 247 |
void command_resetMatrix(QRegularExpressionMatch re); |
| 248 |
void command_translate(QRegularExpressionMatch re); |
| 249 |
void command_rotate(QRegularExpressionMatch re); |
| 250 |
void command_rotate_x(QRegularExpressionMatch re); |
| 251 |
void command_rotate_y(QRegularExpressionMatch re); |
| 252 |
void command_scale(QRegularExpressionMatch re); |
| 253 |
void command_mapQuadToQuad(QRegularExpressionMatch re); |
| 254 |
void command_setMatrix(QRegularExpressionMatch re); |
| 255 |
|
| 256 |
|
| 257 |
QPainter *m_painter; |
| 258 |
QPainter *m_surface_painter; |
| 259 |
QImage::Format m_format; |
| 260 |
QImage m_surface_image; |
| 261 |
QRectF m_surface_rect; |
| 262 |
QStringList m_commands; |
| 263 |
QString m_currentCommand; |
| 264 |
int m_currentCommandIndex; |
| 265 |
QString m_filepath; |
| 266 |
QMap<QString, QStringList> m_blockMap; |
| 267 |
QMap<QString, QPainterPath> m_pathMap; |
| 268 |
QMap<QString, QPixmap> m_pixmapMap; |
| 269 |
QMap<QString, QImage> m_imageMap; |
| 270 |
QMap<QString, QRegion> m_regionMap; |
| 271 |
QGradientStops m_gradientStops; |
| 272 |
QGradient::Spread m_gradientSpread; |
| 273 |
QGradient::CoordinateMode m_gradientCoordinate; |
| 274 |
bool m_abort; |
| 275 |
int m_width; |
| 276 |
int m_height; |
| 277 |
|
| 278 |
bool m_verboseMode; |
| 279 |
DeviceType m_type; |
| 280 |
bool m_checkers_background; |
| 281 |
bool m_shouldDrawText; |
| 282 |
|
| 283 |
QVector<QPointF> m_controlPoints; |
| 284 |
|
| 285 |
#ifndef QT_NO_OPENGL |
| 286 |
QOpenGLContext *m_default_glcontext; |
| 287 |
QOpenGLContext *m_surface_glcontext; |
| 288 |
QOpenGLFramebufferObject *m_surface_glbuffer; |
| 289 |
QOpenGLPaintDevice *m_surface_glpaintdevice; |
| 290 |
#endif |
| 291 |
|
| 292 |
|
| 293 |
static const char *brushStyleTable[]; |
| 294 |
static const char *penStyleTable[]; |
| 295 |
static const char *fontWeightTable[]; |
| 296 |
static const char *fontHintingTable[]; |
| 297 |
static const char *clipOperationTable[]; |
| 298 |
static const char *spreadMethodTable[]; |
| 299 |
static const char *coordinateMethodTable[]; |
| 300 |
static const char *compositionModeTable[]; |
| 301 |
static const char *imageFormatTable[]; |
| 302 |
static const char *sizeModeTable[]; |
| 303 |
static int translateEnum(const char *table[], const QString &pattern, int limit); |
| 304 |
|
| 305 |
|
| 306 |
template <typename T> T image_load(const QString &filepath); |
| 307 |
|
| 308 |
|
| 309 |
static void staticInit(); |
| 310 |
|
| 311 |
public: |
| 312 |
struct PaintCommandInfos |
| 313 |
{ |
| 314 |
PaintCommandInfos(QString id, void (PaintCommands::*p)(QRegularExpressionMatch), QRegularExpression r, QString sy, QString sa) |
| 315 |
: identifier(id) |
| 316 |
, regExp(r) |
| 317 |
, syntax(sy) |
| 318 |
, sample(sa) |
| 319 |
, paintMethod(p) |
| 320 |
{} |
| 321 |
PaintCommandInfos(QString title) |
| 322 |
: identifier(title), paintMethod(0) {} |
| 323 |
bool isSectionHeader() const { return paintMethod == 0; } |
| 324 |
QString identifier; |
| 325 |
QRegularExpression regExp; |
| 326 |
QString syntax; |
| 327 |
QString sample; |
| 328 |
void (PaintCommands::*paintMethod)(QRegularExpressionMatch); |
| 329 |
}; |
| 330 |
|
| 331 |
static PaintCommandInfos *findCommandById(const QString &identifier) { |
| 332 |
for (int i=0; i<s_commandInfoTable.size(); i++) |
| 333 |
if (s_commandInfoTable[i].identifier == identifier) |
| 334 |
return &s_commandInfoTable[i]; |
| 335 |
return 0; |
| 336 |
} |
| 337 |
|
| 338 |
static QList<PaintCommandInfos> s_commandInfoTable; |
| 339 |
static QList<QPair<QString,QStringList> > s_enumsTable; |
| 340 |
static QMultiHash<QString, int> s_commandHash; |
| 341 |
}; |
| 342 |
|
| 343 |
#endif |