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
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
#ifndef RICHTEXT_H
#define RICHTEXT_H

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

NAMESPACE_UPP

class PasteClip;
struct RichPara;
class RichTable;
class RichTxt;

struct Zoom {
int m, d;

int operator*(int x) const { return d ? iscale(x, m, d) : 0; }
int operator&(int x) const { int q = d ? iscale(x, m, d) : 0; return x > 0 ? max(q, 1) : q; }

double AsDouble() const { return (double)m / d; }
Zoom Reciprocal() const { return Zoom(d, m); }

Zoom() { m = d = 1; }
Zoom(const Nuller&) { m = d = 0; }
Zoom(int _m, int _d) { m = _m, d = _d; }

void Serialize(Stream& s) { s % m % d; }

bool operator==(Zoom a) { return m == a.m && d == a.d; }
bool operator!=(Zoom a) { return m != a.m || d != a.d; }

friend int operator/(int x, Zoom z) { return z.m ? iscale(x, z.d, z.m) : 0; }
};

inline bool IsNull(Zoom z) { return (z.m | z.d) == 0; }

inline int operator*(int x, Zoom m)
{
return m * x;
}

inline void operator*=(int& i, Zoom m)
{
i = m * i;
}

inline void operator*=(Rect& r, Zoom m)
{
r.left *= m;
r.right *= m;
r.top *= m;
r.bottom *= m;
}

inline Size operator*(Zoom m, Size sz)
{
return Size(m * sz.cx, m * sz.cy);
}

inline Size operator/(Size sz, Zoom m)
{
return Size(sz.cx / m, sz.cy / m);
}

struct PageY : Moveable<PageY, RelOps<PageY> > {
int page;
int y;

PageY(int page, int y) : page(page), y(y) {}
PageY() { page = y = 0; }

#ifdef _DEBUG
String ToString() const { return AsString(page) + ":" + AsString(y); }
#endif
};

inline bool operator<(PageY a, PageY b)
{
return a.page < b.page ? true : a.page == b.page ? a.y < b.y : false;
}

inline bool operator==(PageY a, PageY b)
{
return a.page == b.page && a.y == b.y;
}

inline PageY operator+(PageY a, int b)
{
return PageY(a.page, a.y + b);
}

struct PageRect : public Rect {
int page;

operator int() const { return page; }
operator PageY() const { return PageY(page, top); }
PageRect& operator=(const Rect& r) { (Rect&)(*this) = r; page = 0; return *this; }
PageRect(const Rect& r) { (Rect&)(*this) = r; page = 0; }
PageRect() { Clear(); page = 0; }
};

struct RichTextLayoutTracer {
virtual void Paragraph(const Rect& page, PageY y, const RichPara& para);
virtual void EndParagraph(PageY y);
virtual void Table(const Rect& page, PageY y, const RichTable& table);
virtual void EndTable(PageY y);
virtual void TableRow(const Rect& page, PageY y, int i, const RichTable& table);
virtual void EndTableRow(PageY y);
virtual void TableCell(const Rect& page, PageY y, int i, int j, const RichTable& table, PageY ny);
virtual void EndTableCell(PageY y);
};

struct PageDraw {
virtual Draw& Page(int i) = 0;

RichTextLayoutTracer *tracer;

PageDraw() { tracer = NULL; }

virtual ~PageDraw() {}
};

class RichObject;
class Bar;

struct RichObjectType {
virtual String GetTypeName(const Value& v) const = 0;
virtual String GetCreateName() const;
virtual Value Read(const String& s) const;
virtual String Write(const Value& v) const;
virtual bool IsText() const;

virtual bool Accept(PasteClip& clip);
virtual Value Read(PasteClip& clip);
virtual String GetClipFmts() const;
virtual String GetClip(const Value& data, const String& fmt) const;

virtual Size GetDefaultSize(const Value& data, Size maxsize, void *context) const;
virtual Size GetPhysicalSize(const Value& data, void *context) const;
virtual Size GetPixelSize(const Value& data, void *context) const;
virtual void Paint(const Value& data, Draw& w, Size sz, void *context) const;
virtual Image ToImage(const Value& data, Size sz, void *context) const;
virtual void Menu(Bar& bar, RichObject& ex, void *context) const;
virtual void DefaultAction(RichObject& ex, void *context) const;
virtual String GetLink(const Value& data, Point pt, Size sz, void *context) const;

Size StdDefaultSize(const Value& data, Size maxsize, void *context) const;

RichObjectType();
virtual ~RichObjectType();

protected:
virtual Size GetDefaultSize(const Value& data, Size maxsize) const;
virtual Size GetPhysicalSize(const Value& data) const;
virtual Size GetPixelSize(const Value& data) const;
virtual void Paint(const Value& data, Draw& w, Size sz) const;
virtual Image ToImage(const Value& data, Size sz) const;
virtual void Menu(Bar& bar, RichObject& ex) const;
virtual void DefaultAction(RichObject& ex) const;
virtual String GetLink(const Value& data, Point pt, Size sz) const;
};

class RichObject : Moveable<RichObject> {
Value data;
int ydelta;
Size size;
Size physical_size;
Size pixel_size;
bool keepratio;
const RichObjectType *type;
int64 serial;
String type_name;

static VectorMap<String, RichObjectType *>& Map();

void NewSerial();

public:
static void Register(const char *name, RichObjectType *type) init_;
static int GetTypeCount() { return Map().GetCount(); }
static int FindType(const String& name) { return Map().Find(name); }
static RichObjectType& GetType(int i) { return *Map()[i]; }
static String GetTypeName(int i) { return Map().GetKey(i); }

void SetSize(int cx, int cy) { size = Size(cx, cy); NewSerial(); }
void SetSize(Size sz) { size = sz; NewSerial(); }
Size GetSize() const { return size; }
void Paint(Draw& w, Size sz, void *context = NULL) const;
Image ToImage(Size sz, void *context = NULL) const;
Size GetPhysicalSize() const { return physical_size; }
Size GetPixelSize() const { return pixel_size; }
Size GetDefaultSize(Size maxsize, void *context = NULL) const { return type ? type->GetDefaultSize(data, maxsize, context) : physical_size; }

void Set(RichObjectType *type, const Value& data, Size maxsize = Size(3967, 3967), void *context = NULL);
bool Set(const String& type_name, const Value& data, Size maxsize = Size(3967, 3967), void *context = NULL);
void SetData(const Value& v);

String GetTypeName() const;
Value GetData() const { return data; }
String GetLink(Point pt, Size sz, void *context = NULL) const { return type ? type->GetLink(data, pt, sz, context) : String(); }

const RichObjectType& GetType() const;

bool Read(const String& type, const String& data, Size sz, void *context = NULL);
String Write() const { return type ? type->Write(data) : (String)data; }
bool IsText() const { return type ? type->IsText() : false; }

void KeepRatio(bool b) { keepratio = b; }
bool IsKeepRatio() const { return keepratio; }

void SetYDelta(int yd) { ydelta = yd; }
int GetYDelta() const { return ydelta; }

void Menu(Bar& bar, void *context = NULL) { if(type) type->Menu(bar, *this, context); }
void DefaultAction(void *context = NULL) { if(type) type->DefaultAction(*this, context); }

operator bool() const { return !IsNull(data); }

void Clear();

int64 GetSerialId() const { return serial; }

void InitSize(int cx, int cy, void *context = NULL);

RichObject();
RichObject(RichObjectType *type, const Value& data, Size maxsize = Size(3967, 3967));
RichObject(const String& type, const Value& data, Size maxsize = Size(3967, 3967));
};

RichObject CreateDrawingObject(const Drawing& dwg, Size dot_size, Size size);
RichObject CreateDrawingObject(const Drawing& dwg, int cx = 0, int cy = 0);
RichObject CreatePaintingObject(const Painting& dwg, Size dot_size, Size size);
RichObject CreatePaintingObject(const Painting& dwg, int cx = 0, int cy = 0);
RichObject CreatePNGObject(const Image& img, Size dot_size, Size size);
RichObject CreatePNGObject(const Image& img, int cx = 0, int cy = 0);
RichObject CreateRawImageObject(const String& s, int cx = 0, int cy = 0);

enum {
RICHHOT_LM = -1,
RICHHOT_RM = -2,
};

struct RichHotPos {
int table;
int column;
int delta;
int left, cx;
int textleft, textcx;

RichHotPos() { table = 0; column = Null; left = cx = 0; }
};

struct RichValPos : Moveable<RichValPos> {
PageY py;
int pos;
WString data;
};

struct PaintInfo {
Zoom zoom;
int sell, selh;
int tablesel;
Rect cells;
PageY top;
PageY bottom;
Color hyperlink;
Color indexentry;
bool usecache;
bool sizetracking;
Color showcodes;
Bits (*spellingchecker)(const RichPara& para);
int highlightpara;
Color highlight;
bool coloroverride;
void *context;
bool showlabels;
bool shrink_oversized_objects;

PaintInfo();
};

int LineZoom(Zoom z, int a);

class RichTable;

#include "Para.h"

struct RichPos {
int tabtextparti;
int tabtextpartcount;
int tabposintabtext;
int tabtextlen;

int table;
Size tabsize;
Point cell;

int tablen;
int posintab;

int celllen;
int posincell;

int parai;
int partcount;
int posinpara;
int paralen;

int level;
int parenttab;

RichPara::Format format;
int chr;
RichObject object;
Id field;
String fieldparam;
RichPara::CharFormat fieldformat;

#ifdef _DEBUG
String ToString() const;
#endif

RichPos();
};

inline bool InSameTxt(const RichPos& a, const RichPos& b)
{
return a.table == b.table && (a.table == 0 || a.cell == b.cell);
}

struct RichCaret : PageRect {
int lineascent;
int caretascent;
int caretdescent;
int objectcy;
int objectyd;
int line;
Rect textpage;

RichCaret() { lineascent = caretascent = caretdescent = 0; }
};

struct RichStyle {
RichPara::Format format;
String name;
Uuid next;

static Uuid GetDefaultId();
static const RichStyle& GetDefault();

RichStyle() { next = GetDefaultId(); }
};

typedef ArrayMap<Uuid, RichStyle> RichStyles;

const RichStyle& GetStyle(const RichStyles& s, const Uuid& id);
int FindStyleWithName(const RichStyles& style, const String& name);

struct RichContext {
const RichStyles& styles;
Rect page;
PageY py;

void Page() { py.page++; py.y = page.top; }

RichContext(const RichStyles& styles) : styles(styles) {}
};

struct RichCellPos;

#include "Txt.h"
#include "Table.h"
#include "Text.h"

struct RichCellPos {
int pos;

int textlen;

Size tabsize;
int tabpos;
int tablen;
int cellpos;
int celllen;
int level;
RichCell::Format format;
RichTable::Format tableformat;

#ifdef _DEBUG
String ToString() const;
#endif
};

String DeQtf(const char *s);
String DeQtfLf(const char *s);

String QtfFormat(Color c);

struct QtfRichObject {
RichObject obj;

public:
String ToString() const;

QtfRichObject() {}
QtfRichObject(const RichObject& o);
};

RichText AsRichText(const RichObject& obj);
String AsQTF(const RichObject& obj);

RichText ParseQTF(const char *qtf, int accesskey = 0, void *context = NULL);

RichText AsRichText(const wchar *s, const RichPara::Format& f = RichPara::Format());

enum
{
QTF_BODY = 1,
QTF_ALL_STYLES = 2,
QTF_NOSTYLES = 4,
QTF_CRLF = 8,
QTF_NOCHARSET = 16,
QTF_NOLANG = 32,
};

String AsQTF(const RichText& doc, byte charset = CHARSET_UTF8,
dword options = QTF_BODY|QTF_ALL_STYLES|QTF_CRLF);

inline String StylesAsQTF(const RichText& doc, byte charset = CHARSET_UTF8)
{ return AsQTF(doc, charset, QTF_ALL_STYLES|QTF_CRLF); }

inline String BodyAsQTF(const RichText& doc, byte charset = CHARSET_UTF8)
{ return AsQTF(doc, charset, QTF_BODY|QTF_CRLF); }

enum
{
ROUNDOFF = 1 << 20,
MAX_FONTS = 10000,
MAX_DOTS = 600 * 100,
MAX_DOT_HEIGHT = 1200,
MAX_POINT_HEIGHT = MAX_DOT_HEIGHT * 3 / 25,
};

inline int DotTwips (int dots) { return (dots * 12 + 5 * ROUNDOFF + 2) / 5 - ROUNDOFF; }
inline int TwipDots (int twp) { return (twp * 5 + 12 * ROUNDOFF + 6) / 12 - ROUNDOFF; }
inline int DotPoints(int dots) { return (dots * 3 + 25 * ROUNDOFF + 12) / 25 - ROUNDOFF; }
inline int PointDots(int pts) { return (pts * 25 + 3 * ROUNDOFF + 1) / 3 - ROUNDOFF; }
inline int TwipDotSize(int twp) { return IsNull(twp) ? 0 : minmax<int>(TwipDots(twp), 0, MAX_DOTS); }
inline int PointDotHeight(int p) { return (minmax<int>(Nvl(p, 0), 0, MAX_POINT_HEIGHT) * 25 + 5) / 6; }

void SetRichTextStdScreenZoom(int m, int d);
Zoom GetRichTextStdScreenZoom();

const Display& QTFDisplay();
const Display& QTFDisplayVCenter();

String EncodeHtml(const RichText& text, Index<String>& css,
const VectorMap<String, String>& links,
const VectorMap<String, String>& labels,
const String& path, const String& base = Null, Zoom z = Zoom(8, 40),
const VectorMap<String, String>& escape = VectorMap<String, String>(),
int imtolerance = 0);
String AsCss(Index<String>& ss);

inline //BW - no labels
String EncodeHtml(const RichText& text, Index<String>& css,
const VectorMap<String, String>& links,
const String& path, const String& base = Null, Zoom z = Zoom(8, 40)) {
return EncodeHtml(text, css, links, VectorMap<String, String>(), path, base, z);
}

struct SimplePageDraw : PageDraw {
Draw& w;

virtual Draw& Page(int);

SimplePageDraw(Draw& w) : w(w) {}
virtual ~SimplePageDraw() {}
};

struct PrintPageDraw : PageDraw {
int page;
Draw& w;
NilDraw nw;

Draw& Page(int _page) { return page == _page ? w : (Draw&)nw; }
void SetPage(int _page) { page = _page; }

PrintPageDraw(Draw& w) : w(w) {}
virtual ~PrintPageDraw() {}
};

Array<Drawing> RenderPages(const RichText& txt, Size pagesize = Size(3968, 6074));

String Pdf(const RichText& txt, Size pagesize = Size(3968, 6074), int margin = 200, bool pdfa = false);

END_UPP_NAMESPACE

#endif

Change log

r4457 by cxl on Jan 21, 2012   Diff
*uppsrc: Fixed many GCC warnings
Go to: 
Project members, sign in to write a code review

Older revisions

r4197 by cxl on Nov 25, 2011   Diff
RichText: RenderPages, Pdf
r3952 by cxl on Oct 3, 2011   Diff
RichText: CreatePaintingObject, ide:
fix of errorfiles
r3933 by cxl on Sep 30, 2011   Diff
CtrlLib: ArrayCtrl::AsText,
SetClipboard, AsQtf, AsCsv
All revisions of this file

File info

Size: 14372 bytes, 499 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting