My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
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
#ifndef _PDF_pdf_h_
#define _PDF_pdf_h_

#include <Draw/Draw.h>
#include <plugin/z/z.h>


NAMESPACE_UPP

class TTFReader {
struct TTFStream {
struct Fail {};

virtual void Raw(void *ptr, int count) = 0;

TTFStream& operator%(byte& q);
TTFStream& operator%(int32& q);
TTFStream& operator%(uint32& q);
TTFStream& operator%(int16& q);
TTFStream& operator%(uint16& q);

virtual ~TTFStream() {}
};

struct TTFStreamIn : TTFStream {
const char *beg;
const char *s;
const char *lim;

virtual void Raw(void *ptr, int count);

void Seek(int offset);
int Get8();
int Get16();
int Get32();
String Get(int n);

virtual ~TTFStreamIn() {}
};

struct TTFStreamOut : TTFStream {
String out;

virtual void Raw(void *ptr, int count) { out.Cat((const char *)ptr, count); }

void Put8(int data) { out.Cat(data); }
void Put16(int data) { Put8(HIBYTE(data)); Put8(LOBYTE(data)); }
void Put32(int data) { Put16(HIWORD(data)); Put16(LOWORD(data)); }
void Put(const String& s) { out.Cat(s); }

operator String() const { return out; }

virtual ~TTFStreamOut() {}
};

String font;

struct Table : Moveable<Table> {
int offset;
int length;
};
VectorMap<String, Table> table;

word zero[256];
word *cmap[256];

struct GlyphInfo : Moveable<GlyphInfo> {
int offset;
int size;
uint16 advanceWidth;
int16 leftSideBearing;
};

Vector<GlyphInfo> glyphinfo;

void SetGlyph(wchar ch, word glyph);

struct Fail {};

static void Error() { throw Fail(); }

int Peek8(const char *s);
int Peek16(const char *s);
int Peek32(const char *s);
int Peek8(const char *s, int i);
int Peek16(const char *s, int i);
int Peek32(const char *s, int i);
int Read8(const char *&s);
int Read16(const char *&s);
int Read32(const char *&s);
String Read(const char *&s, int n);

void Free();
void Reset();

const char *Seek(const char *tab, int& len);
const char *Seek(const char *tab);
void Seek(const char *tab, TTFStreamIn& s);
String GetTable(const char *tab);

enum {
ARG_1_AND_2_ARE_WORDS = (1<<0),
ARGS_ARE_XY_VALUES = (1<<1),
ROUND_XY_TO_GRID = (1<<2),
WE_HAVE_A_SCALE = (1<<3),
MORE_COMPONENTS = (1<<5),
WE_HAVE_AN_X_AND_Y_SCALE = (1<<6),
WE_HAVE_A_TWO_BY_TWO = (1<<7),
WE_HAVE_INSTRUCTIONS = (1<<8),
USE_MY_METRICS = (1<<9),
};

struct NewTable {
String name;
String data;
dword checksum;
};

static void Add(Array<NewTable>& t, const char *name, const String& data);
static void Set(NewTable& m, const String& data);
static String CreateHeader(const Array<NewTable>& t);

static inline int Copy8(TTFStreamOut& out, TTFStreamIn& in)
{ int q = in.Get8(); out.Put8(q); return q; }
static inline int Copy16(TTFStreamOut& out, TTFStreamIn& in)
{ int q = in.Get16(); out.Put16(q); return q; }
static inline int Copy32(TTFStreamOut& out, TTFStreamIn& in)
{ int q = in.Get32(); out.Put32(q); return q; }
static inline String Copy(TTFStreamOut& out, TTFStreamIn& in, int n)
{ String q = in.Get(n); out.Put(q); return q; }

public:
struct Head {
dword version;
dword fontRevision;
uint32 checkSumAdjustment;
uint32 magicNumber;
uint16 flags;
uint16 unitsPerEm;
byte created[8];
byte modified[8];
int16 xMin;
int16 yMin;
int16 xMax;
int16 yMax;
uint16 macStyle;
uint16 lowestRecPPEM;
int16 fontDirectionHint;
int16 indexToLocFormat;
int16 glyphDataFormat;

void Serialize(TTFStream& s);
};

struct Hhea {
uint32 version;
int16 ascent;
int16 descent;
int16 lineGap;
uint16 advanceWidthMax;
int16 minLeftSideBearing;
int16 minRightSideBearing;
int16 xMaxExtent;
int16 caretSlopeRise;
int16 caretSlopeRun;
int16 caretOffset;
int16 reserved1;
int16 reserved2;
int16 reserved3;
int16 reserved4;
int16 metricDataFormat;
uint16 numOfLongHorMetrics;

void Serialize(TTFStream& s);
};

struct Maxp {
uint32 version;
uint16 numGlyphs;
uint16 maxPoints;
uint16 maxContours;
uint16 maxComponentPoints;
uint16 maxComponentContours;
uint16 maxZones;
uint16 maxTwilightPoints;
uint16 maxStorage;
uint16 maxFunctionDefs;
uint16 maxInstructionDefs;
uint16 maxStackElements;
uint16 maxSizeOfInstructions;
uint16 maxComponentElements;
uint16 maxComponentDepth;

void Serialize(TTFStream& s);
};

struct Post {
uint32 format;
int32 italicAngle;
int16 underlinePosition;
int16 underlineThickness;
uint16 isFixedPitch;
uint16 reserved;
uint32 minMemType42;
uint32 maxMemType42;
uint32 minMemType1;
uint32 maxMemType1;

void Serialize(TTFStream& s);
};

Head head;
Hhea hhea;
Maxp maxp;
Post post;
String ps_name;

int GetGlyph(wchar chr) { return cmap[HIBYTE(chr)][LOBYTE(chr)]; }
word GetAdvanceWidth(wchar chr) { return glyphinfo[GetGlyph(chr)].advanceWidth; }

String Subset(const Vector<wchar>& chars, int first = 0, bool os2 = false);
bool Open(const String& fnt, bool symbol = false, bool justcheck = false);

TTFReader();
~TTFReader();
};

class PdfDraw : public Draw {
public:
virtual dword GetInfo() const;
virtual Size GetPageSize() const;

virtual void StartPage();
virtual void EndPage();

virtual void BeginOp();
virtual void EndOp();
virtual void OffsetOp(Point p);
virtual bool ClipOp(const Rect& r);
virtual bool ClipoffOp(const Rect& r);
virtual bool ExcludeClipOp(const Rect& r);
virtual bool IntersectClipOp(const Rect& r);
virtual bool IsPaintingOp(const Rect& r) const;

virtual void DrawRectOp(int x, int y, int cx, int cy, Color color);
virtual void DrawImageOp(int x, int y, int cx, int cy, const Image& img, const Rect& src, Color color);
virtual void DrawLineOp(int x1, int y1, int x2, int y2, int width, Color color);
virtual void DrawPolyPolylineOp(const Point *vertices, int vertex_count,
const int *counts, int count_count,
int width, Color color, Color doxor);
virtual void DrawPolyPolyPolygonOp(const Point *vertices, int vertex_count,
const int *subpolygon_counts, int scc,
const int *disjunct_polygon_counts, int dpcc,
Color color, int width, Color outline,
uint64 pattern, Color doxor);
virtual void DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor);
virtual void DrawArcOp(const Rect& rc, Point start, Point end, int width, Color color);
virtual void DrawTextOp(int x, int y, int angle, const wchar *text, Font font,
Color ink, int n, const int *dx);

private:
struct CharPos : Moveable<CharPos> { word fi, ci; };

struct OutlineInfo : Moveable<OutlineInfo> {
bool ttf;
bool sitalic;
};

VectorMap<Font, OutlineInfo> outline_info;
VectorMap<Font, Vector<wchar> > pdffont;
VectorMap<Font, VectorMap<wchar, CharPos> > fontchars;
Vector<Image> image;
Vector<Rect> imagerect;
Index<uint64> patterns;

Vector<int> offset;
StringBuffer out;
StringBuffer page;
Size pgsz;
Color rgcolor;
Color RGcolor;
int fontid;
double textht;
double linewidth;
int margin;
uint64 patternid;
bool pdfa;

inline double Pt(double dot) { return 0.12 * dot; }

int Pos() { return offset.GetCount() + 1; }
int BeginObj();
void EndObj();
int PutStream(const String& data, const String& keys = Null, bool compress = true);

void PutRect(const Rect& rc);
void PutrgColor(Color rg, uint64 pattern = 0);
void PutRGColor(Color RG);
void PutFontHeight(int fi, double ht);
void PutLineWidth(int lw);

CharPos GetCharPos(Font fnt, wchar chr);
void FlushText(int dx, int fi, int height, const String& txt);
static String PdfColor(Color c);

OutlineInfo GetOutlineInfo(Font fnt);

struct M22 {
double a, b, c, d;

void Mul(double a1, double b1, double c1, double d1) {
M22 t;
t.a = a * a1 + b * c1;
t.b = a * b1 + b * d1;
t.c = c * a1 + d * c1;
t.d = c * b1 + d * d1;
*this = t;
}

M22(double a, double b, double c, double d) : a(a), b(b), c(c), d(d) {}
M22() : a(1), b(0), c(0), d(1) {}
};

void Init(int pagecx, int pagecy, int margin, bool pdfa);

struct RGlyph : Moveable<RGlyph> {
String data;
Size sz;
int x;
};

RGlyph RasterGlyph(Font fnt, int chr);

public:
String Finish();
void Clear();

PdfDraw(int pagecx, int pagecy, bool pdfa = false) { Init(pagecx, pagecy, 0, pdfa); }
PdfDraw(Size pgsz = Size(5100, 6600), bool pdfa = false) { Init(pgsz.cx, pgsz.cy, 0, pdfa); }
};

String Pdf(const Array<Drawing>& report, Size pagesize, int margin, bool pdfa = false);

END_UPP_NAMESPACE

#endif

Change log

r4191 by cxl on Nov 23, 2011   Diff
.PdfDraw
Go to: 
Project members, sign in to write a code review

Older revisions

r3715 by rylek on Jul 27, 2011   Diff
+Draw/, Report/, PdfDraw/, DocTypes/:
minimalistic PDF/A support
+plugin/wincert: basic Win32
certificate manipulation and PDF
digital signing
r2467 by rylek on Jun 8, 2010   Diff
Basic support for fill patterns in PDF
r1373 by cxl on Jul 6, 2009   Diff
developing new draw
All revisions of this file

File info

Size: 9448 bytes, 346 lines
Powered by Google Project Hosting