This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathcustomprinter.h
More file actions
415 lines (341 loc) · 12.1 KB
/
customprinter.h
File metadata and controls
415 lines (341 loc) · 12.1 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
/* Copyright (C) 2003-2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
////////////////////////////////////////////////////////////////////////////////
//
// Public Header File:
// customprinter.h
//
// Description:
// This file contains the definiton of the custom printer interface and
// related definitions.
//
// Changes:
// 2009-11-25 MW Created.
//
////////////////////////////////////////////////////////////////////////////////
#ifndef __MC_CUSTOM_PRINTER__
#define __MC_CUSTOM_PRINTER__
////////////////////////////////////////////////////////////////////////////////
struct MCCustomPrinterDocument
{
MCCustomPrinterDocument()
: title(nullptr), filename(nullptr),
option_count(0),
option_keys(nullptr), option_values(nullptr)
{}
const char *title;
const char *filename;
uint32_t option_count;
char * const *option_keys;
char * const *option_values;
};
struct MCCustomPrinterPage
{
double width;
double height;
double scale;
};
////////////////////////////////////////////////////////////////////////////////
struct MCCustomPrinterPoint
{
double x;
double y;
};
struct MCCustomPrinterRectangle
{
double left;
double top;
double right;
double bottom;
};
// A standard affine transformation:
// x' = scale_x * x + skew_x * y + translate_x;
// y' = skew_y * x + scale_y * y + translate_y;
//
struct MCCustomPrinterTransform
{
double scale_x, skew_x;
double skew_y, scale_y;
double translate_x, translate_y;
};
////////////////////////////////////////////////////////////////////////////////
struct MCCustomPrinterColor
{
double red;
double green;
double blue;
};
////////////////////////////////////////////////////////////////////////////////
enum MCCustomPrinterImageType
{
// Null image type
kMCCustomPrinterImageNone,
// Raw 32-bit RGB image data, no mask
kMCCustomPrinterImageRawXRGB,
// Raw 32-bit RGB image data, sharp mask
kMCCustomPrinterImageRawMRGB,
// Raw 32-bit RGB image data, soft mask (unpremultiplied)
kMCCustomPrinterImageRawARGB,
// GIF image data
kMCCustomPrinterImageGIF,
// JPEG image data
kMCCustomPrinterImageJPEG,
// PNG image data
kMCCustomPrinterImagePNG
};
#ifdef __LITTLE_ENDIAN__
#define kMCCustomPrinterImagePixelFormat kMCGPixelFormatBGRA
#else
#define kMCCustomPrinterImagePixelFormat kMCGPixelFormatARGB
#endif
struct MCCustomPrinterImage
{
MCCustomPrinterImageType type;
uint32_t id;
uint32_t width;
uint32_t height;
void *data;
uint32_t data_size;
};
////////////////////////////////////////////////////////////////////////////////
struct MCCustomPrinterPattern
{
MCCustomPrinterImage image;
MCCustomPrinterTransform transform;
};
////////////////////////////////////////////////////////////////////////////////
enum MCCustomPrinterGradientType
{
kMCCustomPrinterGradientNone,
kMCCustomPrinterGradientLinear,
kMCCustomPrinterGradientRadial,
kMCCustomPrinterGradientConical,
kMCCustomPrinterGradientDiamond,
kMCCustomPrinterGradientSpiral,
kMCCustomPrinterGradientXY,
kMCCustomPrinterGradientSqrtXY
};
struct MCCustomPrinterGradientStop
{
MCCustomPrinterColor color;
double alpha;
double offset;
};
struct MCCustomPrinterGradient
{
MCCustomPrinterGradientType type;
bool mirror;
bool wrap;
uint32_t repeat;
uint32_t stop_count;
MCCustomPrinterGradientStop *stops;
MCCustomPrinterTransform transform;
};
////////////////////////////////////////////////////////////////////////////////
enum MCCustomPrinterPaintType
{
kMCCustomPrinterPaintNone,
kMCCustomPrinterPaintSolid,
kMCCustomPrinterPaintPattern,
kMCCustomPrinterPaintGradient
};
struct MCCustomPrinterPaint
{
MCCustomPrinterPaintType type;
union
{
MCCustomPrinterColor solid;
MCCustomPrinterPattern pattern;
MCCustomPrinterGradient gradient;
};
};
////////////////////////////////////////////////////////////////////////////////
enum MCCustomPrinterCapStyle
{
kMCCustomPrinterCapButt,
kMCCustomPrinterCapRound,
kMCCustomPrinterCapSquare
};
enum MCCustomPrinterJoinStyle
{
kMCCustomPrinterJoinBevel,
kMCCustomPrinterJoinRound,
kMCCustomPrinterJoinMiter
};
struct MCCustomPrinterStroke
{
double thickness;
MCCustomPrinterCapStyle cap_style;
MCCustomPrinterJoinStyle join_style;
uint32_t dash_count;
double dash_offset;
double *dashes;
double miter_limit;
double aspect;
};
////////////////////////////////////////////////////////////////////////////////
enum MCCustomPrinterBlendMode
{
kMCCustomPrinterBlendSrc,
kMCCustomPrinterBlendDst,
kMCCustomPrinterBlendSrcOver,
kMCCustomPrinterBlendDstOver,
kMCCustomPrinterBlendSrcIn,
kMCCustomPrinterBlendDstIn,
kMCCustomPrinterBlendSrcOut,
kMCCustomPrinterBlendDstOut,
kMCCustomPrinterBlendSrcAtop,
kMCCustomPrinterBlendDstAtop,
kMCCustomPrinterBlendXor,
kMCCustomPrinterBlendPlus,
kMCCustomPrinterBlendMultiply,
kMCCustomPrinterBlendScreen,
kMCCustomPrinterBlendOverlay,
kMCCustomPrinterBlendDarken,
kMCCustomPrinterBlendLighten,
kMCCustomPrinterBlendDodge,
kMCCustomPrinterBlendBurn,
kMCCustomPrinterBlendHardLight,
kMCCustomPrinterBlendSoftLight,
kMCCustomPrinterBlendDifference,
kMCCustomPrinterBlendExclusion
};
struct MCCustomPrinterGroup
{
MCCustomPrinterBlendMode blend_mode;
double opacity;
MCCustomPrinterRectangle region;
};
////////////////////////////////////////////////////////////////////////////////
enum MCCustomPrinterFillRule
{
kMCCustomPrinterFillNonZero,
kMCCustomPrinterFillEvenOdd
};
enum MCCustomPrinterPathCommand
{
kMCCustomPrinterPathEnd,
kMCCustomPrinterPathClose,
kMCCustomPrinterPathMoveTo,
kMCCustomPrinterPathLineTo,
kMCCustomPrinterPathCubicTo,
kMCCustomPrinterPathQuadraticTo
};
struct MCCustomPrinterPath
{
MCCustomPrinterPathCommand *commands;
MCCustomPrinterPoint *coords;
};
////////////////////////////////////////////////////////////////////////////////
struct MCCustomPrinterFont
{
double size;
void *handle;
};
struct MCCustomPrinterGlyph
{
uint32_t id;
double x;
double y;
};
////////////////////////////////////////////////////////////////////////////////
enum MCCustomPrinterLinkType
{
kMCCustomPrinterLinkUnspecified,
kMCCustomPrinterLinkAnchor,
kMCCustomPrinterLinkURI,
};
////////////////////////////////////////////////////////////////////////////////
// The MCCustomPrintingDevice interface encapsulats an alternative output method for
// printing in Rev. If any methods return 'false' the print job is assumed
// to be in an inconsistent state and cancelled. When this occurs the implementation
// of the printing device should clean up after itself - removing any partially
// created output (if possible).
//
class MCCustomPrintingDevice
{
public:
// Destroy the instance of the custom printer.
virtual void Destroy(void) = 0;
// Should return 'true' if the printer can natively draw using the given
// paint. It is assumed that any printer can at least paint primitives with
// a solid (non-alpha) color.
// Note that only the paint.type, paint.gradient.type, paint.image.type and
// paint.pattern.image.type fields will be set on entry to this call.
virtual bool CanRenderPaint(const MCCustomPrinterPaint& paint) = 0;
// Should return 'true' if the printer can natively draw the given image.
// It is assumed that any printer can at least paint sharp-masked raw images.
// Note that only the image.type field will be set on entry to this call.
virtual bool CanRenderImage(const MCCustomPrinterImage& image) = 0;
// Should return 'true' if the printer can natively draw a grouped
// collection of objects with the given options. It is assumed that any
// printer can at least paint a group with the SrcOver blend mode and
// full opacity.
// Note that only the group.blend and group.opacity will be set on entry
// to this call.
virtual bool CanRenderGroup(const MCCustomPrinterGroup& group) = 0;
// Return the error string describing the reason for 'false' being returned
// from one of the action methods. 'nil' should be returned if no error
// has occurred.
virtual const char *GetError(void) = 0;
// Start a new document with the given details as present in the
// passed structure.
virtual bool BeginDocument(const MCCustomPrinterDocument& document) = 0;
// Cancel the current document - this should have the same effect as if
// an error occurred, but obviously no error should be set.
virtual void AbortDocument(void) = 0;
// Mark the end of a document.
virtual bool EndDocument(void) = 0;
// Start a new page with the given configuration.
virtual bool BeginPage(const MCCustomPrinterPage& page) = 0;
// End the current page.
virtual bool EndPage(void) = 0;
// Start a group with the given options. Note that this will only
// ever be called for a group where CanRenderGroup() returns true.
virtual bool BeginGroup(const MCCustomPrinterGroup& group) = 0;
// End the current group.
virtual bool EndGroup(void) = 0;
// Fill the given path using the specified fill rule and paint. The
// path should be transformed using the given matrix and then clipped
// to the given rectangle. Note that paint is specified in path space,
// before the transform is applied.
virtual bool FillPath(const MCCustomPrinterPath& path, MCCustomPrinterFillRule rule, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& clip) = 0;
// Stroke the given path using the specified stroke settings and paint.
// The path should be stroked, then transformed and finally clipped. Note
// that paint is specified in path space, before the transform is applied.
virtual bool StrokePath(const MCCustomPrinterPath& path, const MCCustomPrinterStroke& stroke, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& clip) = 0;
// Draw the given image with the specified transformation matrix and
// clipped to the given rectangle.
virtual bool DrawImage(const MCCustomPrinterImage& image, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& clip) = 0;
// Draw text using the given system font face. The 'text' is the UTF-8
// characters to which the given glyphs correspond. The 'font' is a
// specific font face that exists on the current system, and in which
// all the glyphs exist. The given glyphs should be transformed and then
// clipped. Note that the paint is specified in text space, before
// transformation. Additionally, note that there is not a 1-1
// correspondence between glyph and character - the sequence of glyphs
// should be considered to map to the text 'in one piece'. The clusters
// array maps each byte of the text to the index of the first glyph in
// its cluster.
virtual bool DrawText(const MCCustomPrinterGlyph *glyphs, uint32_t glyph_count, const char *text_bytes, uint32_t text_byte_count, const uint32_t *clusters, const MCCustomPrinterFont& font, const MCCustomPrinterPaint& paint, const MCCustomPrinterTransform& transform, const MCCustomPrinterRectangle& clip) = 0;
// Make an anchor with the given name at the specified position - the name must
// not have the form of a URI.
virtual bool MakeAnchor(const MCCustomPrinterPoint& position, const char *name) = 0;
// Make a link covering the given area. The link is interpreted as either the name
// of an anchor, or a URI if it is of that form.
virtual bool MakeLink(const MCCustomPrinterRectangle& area, const char *link, MCCustomPrinterLinkType type) = 0;
// Make a bookmark with the given title, nested at the given depth.
// If the device does not support bookmarks, this should be a no-op.
virtual bool MakeBookmark(const MCCustomPrinterPoint& position, const char *title, uint32_t depth, bool closed) = 0;
};
////////////////////////////////////////////////////////////////////////////////
#endif