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

NAMESPACE_UPP

#ifdef flagWINGL
#include <WinGl/FontGl.h>
#include <WinGl/ResGl.h>
#endif

#define LLOG(x) // LOG(x)
#define LTIMING(x) // TIMING(x)

WString TextUnicode(const char *s, int n, byte cs, Font font)
{
if(n < 0)
n = (int)strlen(s);
#ifdef PLATFORM_WIN32
if(font.GetFace() == Font::SYMBOL) {
WStringBuffer b(n);
wchar *t = b;
while(n > 0) {
*t++ = *s++;
n--;
}
return b;
}
#endif
return ToUnicode(s, n, cs);
}

void Draw::DrawText(int x, int y, int angle, const wchar *text, Font font,
Color ink, int n, const int *dx)
{
#ifdef flagWINGL
if(IsNull(ink))
return;
DrawTextOp(x, y, angle, text, font, ink, n, dx);
#else
if(IsNull(ink)) return;
if(n < 0)
n = wstrlen(text);
Std(font);
double sina;
double cosa;
int d = 0;
if(angle)
Draw::SinCos(angle, sina, cosa);
for(int i = 0; i < n; i++) {
wchar chr = text[i];
GlyphInfo gi = GetGlyphInfo(font, chr);
if(gi.IsNormal())
if(angle)
DrawTextOp(int(x + cosa * d), int(y - sina * d), angle, &chr, font, ink, 1, NULL);
else {
int c = 1;
int dd = 0;
while(i + c < n) {
GlyphInfo gi2 = GetGlyphInfo(font, text[i + c]);
if(!gi2.IsNormal())
break;
dd += dx ? dx[c] : gi.width;
c++;
gi = gi2;
}
DrawTextOp(x + d, y, 0, text + i, font, ink, c, dx);
d += dd;
i += c - 1;
if(dx)
dx += c - 1;
}
else
if(gi.IsReplaced()) {
Font fnt = font;
fnt.Face(gi.lspc);
fnt.Height(gi.rspc);
if(angle)
DrawTextOp(int(x + cosa * d), int(y - sina * (font.GetAscent() - fnt.GetAscent() + d)),
angle, &chr, fnt, ink, 1, NULL);
else
DrawTextOp(x + d, y + font.GetAscent() - fnt.GetAscent(), 0, &chr, fnt, ink, 1, NULL);
GlyphMetrics(gi, font, chr);
}
else
if(gi.IsComposed()) {
ComposedGlyph cg;
Compose(font, chr, cg);
if(angle) {
DrawTextOp(int(x + cosa * d), int(y - sina * d), angle, &cg.basic_char, font, ink, 1, NULL);
DrawTextOp(int(x + cosa * (d + cg.mark_pos.x)), int(y - sina * (cg.mark_pos.y + d)), angle, &cg.mark_char, cg.mark_font, ink, 1, NULL);
}
else {
DrawTextOp(x + d, y, 0, &cg.basic_char, font, ink, 1, NULL);
DrawTextOp(x + cg.mark_pos.x + d, y + cg.mark_pos.y, 0, &cg.mark_char, cg.mark_font, ink, 1, NULL);
}
GlyphMetrics(gi, font, chr);
}
else {
Font fnt = Arial(font.GetHeight());
wchar chr = 0x25a1;
gi = GetGlyphInfo(fnt, chr);
if(!gi.IsNormal()) {
chr = ' ';
gi = GetGlyphInfo(fnt, chr);
}
if(angle)
DrawTextOp(int(x + cosa * d), int(y - sina * d), angle, &chr, fnt, ink, 1, NULL);
else
DrawTextOp(x + d, y, 0, &chr, fnt, ink, 1, NULL);
}
d += dx ? *dx++ : gi.width;
}
#endif
}

// ----------------------------

void Draw::DrawText(int x, int y, const wchar *text, Font font,
Color ink, int n, const int *dx)
{
DrawText(x, y, 0, text, font, ink, n, dx);
}

// ---------------------------

void Draw::DrawText(int x, int y, int angle, const WString& text, Font font,
Color ink, const int *dx)
{
DrawText(x, y, angle, ~text, font, ink, text.GetLength(), dx);
}

void Draw::DrawText(int x, int y, const WString& text, Font font, Color ink, const int *dx)
{
DrawText(x, y, 0, text, font, ink, dx);
}

// ---------------------------

void Draw::DrawText(int x, int y, int angle, const char *text, byte charset, Font font,
Color ink, int n, const int *dx)
{
DrawText(x, y, angle, TextUnicode(text, n, charset, font), font, ink, dx);
}

void Draw::DrawText(int x, int y, const char *text, byte charset, Font font,
Color ink, int n, const int *dx)
{
DrawText(x, y, 0, text, charset, font, ink, n, dx);
}

// ---------------------------

void Draw::DrawText(int x, int y, int angle, const char *text,
Font font, Color ink, int n, const int *dx)
{
DrawText(x, y, angle, text, CHARSET_DEFAULT, font, ink, n, dx);
}

void Draw::DrawText(int x, int y, const char *text, Font font,
Color ink, int n, const int *dx)
{
DrawText(x, y, text, CHARSET_DEFAULT, font, ink, n, dx);
}

// ---------------------------

void Draw::DrawText(int x, int y, int angle, const String& text, Font font,
Color ink, const int *dx)
{
DrawText(x, y, angle, text, font, ink, text.GetLength(), dx);
}

void Draw::DrawText(int x, int y, const String& text, Font font, Color ink, const int *dx)
{
WString h = TextUnicode(text, text.GetLength(), CHARSET_DEFAULT, font);
DrawText(x, y, h, font, ink, h.GetLength(), dx);
}

// --------------------------

Size GetTextSize(const wchar *text, Font font, int n)
{
#ifdef flagWINGL
return GetTextSize(text, resources.GetFont(font), n);
#else
FontInfo fi = font.Info();
if(n < 0)
n = wstrlen(text);
Size sz;
sz.cx = 0;
const wchar *wtext = (const wchar *)text;
while(n > 0) {
sz.cx += fi[*wtext++];
n--;
}
sz.cy = fi.GetHeight();
return sz;
#endif
}

Size GetTextSize(const WString& text, Font font)
{
return GetTextSize(text, font, text.GetLength());
}

Size GetTextSize(const char *text, byte charset, Font font, int n)
{
return GetTextSize(TextUnicode(text, n, charset, font), font);
}

Size GetTextSize(const char *text, Font font, int n)
{
return GetTextSize(text, CHARSET_DEFAULT, font, n);
}

Size GetTextSize(const String& text, Font font)
{
return GetTextSize(text, font, text.GetLength());
}

END_UPP_NAMESPACE

Change log

r4188 by unodgs on Nov 22, 2011   Diff
WinGL: Added automatic atlas textures,
fixed some bugs
Go to: 
Project members, sign in to write a code review

Older revisions

r3711 by unodgs on Jul 24, 2011   Diff
Rainbow: WinGL..
r3673 by unodgs on Jul 18, 2011   Diff
Rainbow: WinGL..
r3417 by cxl on May 13, 2011   Diff
*Draw: fixed CJK glyph issues
All revisions of this file

File info

Size: 5670 bytes, 220 lines
Powered by Google Project Hosting