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
#include "RichText.h"

NAMESPACE_UPP

Draw& SimplePageDraw::Page(int)
{
return w;
}

void RichText::ApplyZoom(Zoom z)
{
if(z.m == z.d)
return;
RichStyles ostyle(style, 1);
for(int i = 0; i < style.GetCount(); i++)
style[i].format *= z;
RichTxt::ApplyZoom(z, ostyle, style);
RefreshAll();
}

Zoom& sRichTextStdScreenZoom()
{
static Zoom *zz;
ONCELOCK {
static Zoom z(96, 600);
zz = &z;
}
return *zz;
}

void SetRichTextStdScreenZoom(int m, int d)
{
sRichTextStdScreenZoom() = Zoom(m, d);
}

Zoom GetRichTextStdScreenZoom()
{
return sRichTextStdScreenZoom();
}

struct QTFDisplayCls : Display {
virtual void Paint(Draw& w, const Rect& r, const Value& q,
Color ink, Color paper, dword style) const;
virtual Size GetStdSize(const Value& q) const;
virtual Size RatioSize(const Value& q, int cx, int cy) const;
};

Size QTFDisplayCls::GetStdSize(const Value& q) const
{
Size sz;
RichText txt = ParseQTF((String)q);
txt.ApplyZoom(GetRichTextStdScreenZoom());
sz.cx = txt.GetWidth();
sz.cy = txt.GetHeight(Zoom(1, 1), sz.cx);
return sz;
}

Size QTFDisplayCls::RatioSize(const Value& q, int cx, int cy) const
{
if(cy == 0 && cx > 0) {
RichText txt = ParseQTF((String)q);
txt.ApplyZoom(GetRichTextStdScreenZoom());
return Size(cx, txt.GetHeight(Zoom(1, 1), cx));
}
return GetStdSize(q);
}

void QTFDisplayCls::Paint(Draw& draw, const Rect& r, const Value& v, Color ink, Color paper, dword style) const
{
String s;
s << "[@(" << ink.GetR() << "." << ink.GetG() << "." << ink.GetB() << ") " << v;
RichText rtext = ParseQTF(s);
rtext.ApplyZoom(GetRichTextStdScreenZoom());
draw.DrawRect(r, paper);
draw.Clipoff(r);
rtext.Paint(Zoom(1, 1), draw, 0, 0, r.Width());
draw.End();
}

const Display& QTFDisplay()
{
return Single<QTFDisplayCls>();
}

struct QTFDisplayCCls : QTFDisplayCls {
virtual void Paint(Draw& w, const Rect& r, const Value& q,
Color ink, Color paper, dword style) const;
};

void QTFDisplayCCls::Paint(Draw& draw, const Rect& r, const Value& v, Color ink, Color paper, dword style) const
{
String s;
s << "[@(" << ink.GetR() << "." << ink.GetG() << "." << ink.GetB() << ") " << v;
RichText rtext = ParseQTF(s);
rtext.ApplyZoom(GetRichTextStdScreenZoom());
draw.DrawRect(r, paper);
draw.Clipoff(r);
int cy = rtext.GetHeight(Zoom(1, 1), r.Width());
rtext.Paint(Zoom(1, 1), draw, 0, max(0, (r.Height() - cy) / 2), r.Width());
draw.End();
}

const Display& QTFDisplayVCenter()
{
return Single<QTFDisplayCCls>();
}

RichText AsRichText(const wchar *s, const RichPara::Format& f)
{
RichText clip;
RichPara p;
p.format = f;
p.part.Add().format = f;
RichStyle cs;
cs.format = f;
cs.format.sscript = 0;
cs.format.link.Clear();
cs.format.indexentry.Clear();
cs.format.language = LNG_ENGLISH;
cs.format.label.Clear();
clip.SetStyle(f.styleid, cs);
WString& part = p.part.Top().text;
while(*s) {
if(*s == '\n') {
clip.Cat(p);
part.Clear();
}
if(*s >= 32 || *s == '\t')
part.Cat(*s);
s++;
}
clip.Cat(p);
return clip;
}

struct DrawingPageDraw__ : public DrawingDraw, public PageDraw {
virtual Draw& Page(int i);

Array<Drawing> page;
int pagei;
Size size;

void Flush();

DrawingPageDraw__() { pagei = -1; }
};

Draw& DrawingPageDraw__::Page(int i)
{
ASSERT(i >= 0);
if(i != pagei) {
Flush();
pagei = i;
Create(size);
}
return *this;
}

void DrawingPageDraw__::Flush()
{
if(pagei >= 0) {
Drawing dw = GetResult();
page.At(pagei).Append(dw);
Create(size);
}
}

Array<Drawing> RenderPages(const RichText& txt, Size pagesize)
{
DrawingPageDraw__ pd;
pd.size = pagesize;
PageY py(0, 0);
PaintInfo paintinfo;
paintinfo.top = PageY(0, 0);
paintinfo.bottom = PageY(INT_MAX, INT_MAX);
paintinfo.indexentry = Null;
paintinfo.hyperlink = Null;
txt.Paint(pd, PageY(0, 0), pagesize, paintinfo);
pd.Flush();
return pd.page;
}

String Pdf(const RichText& txt, Size pagesize, int margin, bool pdfa)
{
Array<Drawing> pages = RenderPages(txt, pagesize);
return GetDrawingToPdfFn() && pages.GetCount() ? (*GetDrawingToPdfFn())(pages, pagesize, margin, pdfa)
: String();
}

END_UPP_NAMESPACE

Change log

r4197 by cxl on Nov 25, 2011   Diff
RichText: RenderPages, Pdf
Go to: 
Project members, sign in to write a code review

Older revisions

r3323 by cxl on Apr 5, 2011   Diff
*CtrlCore: Fixed charset encoding
issues in EncodeRTF, RichEdit:
ClipZoom method
r2247 by cxl on Mar 19, 2010   Diff
.theide
r1513 by cxl on Aug 16, 2009   Diff
RichText, Report: RichTextLayoutTracer
ability, theide: workspace
slash/backslash fix
All revisions of this file

File info

Size: 4198 bytes, 190 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting