]> git.saurik.com Git - wxWidgets.git/blob - src/html/m_fonts.cpp
Build fix for SmartPhoneCE.
[wxWidgets.git] / src / html / m_fonts.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/m_fonts.cpp
3 // Purpose: wxHtml module for fonts & colors of fonts
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #include "wx/wxprec.h"
11
12 #ifdef __BORLANDC__
13 #pragma hdrstop
14 #endif
15
16 #if wxUSE_HTML && wxUSE_STREAMS
17
18 #ifndef WXPRECOMP
19 #endif
20
21 #include "wx/html/forcelnk.h"
22 #include "wx/html/m_templ.h"
23 #include "wx/fontenum.h"
24 #include "wx/tokenzr.h"
25
26 FORCE_LINK_ME(m_fonts)
27
28
29 TAG_HANDLER_BEGIN(FONT, "FONT" )
30
31 TAG_HANDLER_VARS
32 wxArrayString m_Faces;
33
34 TAG_HANDLER_CONSTR(FONT) { }
35
36 TAG_HANDLER_PROC(tag)
37 {
38 wxColour oldclr = m_WParser->GetActualColor();
39 int oldsize = m_WParser->GetFontSize();
40 wxString oldface = m_WParser->GetFontFace();
41
42 if (tag.HasParam(wxT("COLOR")))
43 {
44 wxColour clr;
45 if (tag.GetParamAsColour(wxT("COLOR"), &clr))
46 {
47 m_WParser->SetActualColor(clr);
48 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr));
49 }
50 }
51
52 if (tag.HasParam(wxT("SIZE")))
53 {
54 int tmp = 0;
55 wxChar c = tag.GetParam(wxT("SIZE")).GetChar(0);
56 if (tag.GetParamAsInt(wxT("SIZE"), &tmp))
57 {
58 if (c == wxT('+') || c == wxT('-'))
59 m_WParser->SetFontSize(oldsize+tmp);
60 else
61 m_WParser->SetFontSize(tmp);
62 m_WParser->GetContainer()->InsertCell(
63 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
64 }
65 }
66
67 if (tag.HasParam(wxT("FACE")))
68 {
69 if (m_Faces.GetCount() == 0)
70 {
71 wxFontEnumerator enu;
72 enu.EnumerateFacenames();
73 const wxArrayString *faces = enu.GetFacenames();
74 if ( faces )
75 m_Faces = *faces;
76 }
77 wxStringTokenizer tk(tag.GetParam(wxT("FACE")), wxT(","));
78 int index;
79
80 while (tk.HasMoreTokens())
81 {
82 if ((index = m_Faces.Index(tk.GetNextToken(), false)) != wxNOT_FOUND)
83 {
84 m_WParser->SetFontFace(m_Faces[index]);
85 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
86 break;
87 }
88 }
89 }
90
91 ParseInner(tag);
92
93 if (oldface != m_WParser->GetFontFace())
94 {
95 m_WParser->SetFontFace(oldface);
96 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
97 }
98 if (oldsize != m_WParser->GetFontSize())
99 {
100 m_WParser->SetFontSize(oldsize);
101 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
102 }
103 if (oldclr != m_WParser->GetActualColor())
104 {
105 m_WParser->SetActualColor(oldclr);
106 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr));
107 }
108 return true;
109 }
110
111 TAG_HANDLER_END(FONT)
112
113
114 TAG_HANDLER_BEGIN(FACES_U, "U,STRIKE")
115
116 TAG_HANDLER_CONSTR(FACES_U) { }
117
118 TAG_HANDLER_PROC(tag)
119 {
120 int underlined = m_WParser->GetFontUnderlined();
121
122 m_WParser->SetFontUnderlined(true);
123 m_WParser->GetContainer()->InsertCell(
124 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
125
126 ParseInner(tag);
127
128 m_WParser->SetFontUnderlined(underlined);
129 m_WParser->GetContainer()->InsertCell(
130 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
131 return true;
132 }
133
134 TAG_HANDLER_END(FACES_U)
135
136
137
138
139 TAG_HANDLER_BEGIN(FACES_B, "B,STRONG")
140 TAG_HANDLER_CONSTR(FACES_B) { }
141
142 TAG_HANDLER_PROC(tag)
143 {
144 int bold = m_WParser->GetFontBold();
145
146 m_WParser->SetFontBold(true);
147 m_WParser->GetContainer()->InsertCell(
148 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
149
150 ParseInner(tag);
151
152 m_WParser->SetFontBold(bold);
153 m_WParser->GetContainer()->InsertCell(
154 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
155 return true;
156 }
157
158 TAG_HANDLER_END(FACES_B)
159
160
161
162
163 TAG_HANDLER_BEGIN(FACES_I, "I,EM,CITE,ADDRESS")
164 TAG_HANDLER_CONSTR(FACES_I) { }
165
166 TAG_HANDLER_PROC(tag)
167 {
168 int italic = m_WParser->GetFontItalic();
169
170 m_WParser->SetFontItalic(true);
171 m_WParser->GetContainer()->InsertCell(
172 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
173
174 ParseInner(tag);
175
176 m_WParser->SetFontItalic(italic);
177 m_WParser->GetContainer()->InsertCell(
178 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
179 return true;
180 }
181
182 TAG_HANDLER_END(FACES_I)
183
184
185
186
187 TAG_HANDLER_BEGIN(FACES_TT, "TT,CODE,KBD,SAMP")
188 TAG_HANDLER_CONSTR(FACES_TT) { }
189
190 TAG_HANDLER_PROC(tag)
191 {
192 int fixed = m_WParser->GetFontFixed();
193
194 m_WParser->SetFontFixed(true);
195 m_WParser->GetContainer()->InsertCell(
196 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
197
198 ParseInner(tag);
199
200 m_WParser->SetFontFixed(fixed);
201 m_WParser->GetContainer()->InsertCell(
202 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
203 return true;
204 }
205
206 TAG_HANDLER_END(FACES_TT)
207
208
209
210
211
212 TAG_HANDLER_BEGIN(Hx, "H1,H2,H3,H4,H5,H6")
213 TAG_HANDLER_CONSTR(Hx) { }
214
215 TAG_HANDLER_PROC(tag)
216 {
217 int old_size, old_b, old_i, old_u, old_f, old_al;
218 wxHtmlContainerCell *c;
219
220 old_size = m_WParser->GetFontSize();
221 old_b = m_WParser->GetFontBold();
222 old_i = m_WParser->GetFontItalic();
223 old_u = m_WParser->GetFontUnderlined();
224 old_f = m_WParser->GetFontFixed();
225 old_al = m_WParser->GetAlign();
226
227 m_WParser->SetFontBold(true);
228 m_WParser->SetFontItalic(false);
229 m_WParser->SetFontUnderlined(false);
230 m_WParser->SetFontFixed(false);
231
232 if (tag.GetName() == wxT("H1"))
233 m_WParser->SetFontSize(7);
234 else if (tag.GetName() == wxT("H2"))
235 m_WParser->SetFontSize(6);
236 else if (tag.GetName() == wxT("H3"))
237 m_WParser->SetFontSize(5);
238 else if (tag.GetName() == wxT("H4"))
239 {
240 m_WParser->SetFontSize(5);
241 m_WParser->SetFontItalic(true);
242 m_WParser->SetFontBold(false);
243 }
244 else if (tag.GetName() == wxT("H5"))
245 m_WParser->SetFontSize(4);
246 else if (tag.GetName() == wxT("H6"))
247 {
248 m_WParser->SetFontSize(4);
249 m_WParser->SetFontItalic(true);
250 m_WParser->SetFontBold(false);
251 }
252
253 c = m_WParser->GetContainer();
254 if (c->GetFirstChild())
255 {
256 m_WParser->CloseContainer();
257 m_WParser->OpenContainer();
258 c = m_WParser->GetContainer();
259 }
260 c = m_WParser->GetContainer();
261
262 c->SetAlign(tag);
263 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
264 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
265 m_WParser->SetAlign(c->GetAlignHor());
266
267 ParseInner(tag);
268
269 m_WParser->SetFontSize(old_size);
270 m_WParser->SetFontBold(old_b);
271 m_WParser->SetFontItalic(old_i);
272 m_WParser->SetFontUnderlined(old_u);
273 m_WParser->SetFontFixed(old_f);
274 m_WParser->SetAlign(old_al);
275
276 m_WParser->GetContainer()->InsertCell(
277 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
278 m_WParser->CloseContainer();
279 m_WParser->OpenContainer();
280 c = m_WParser->GetContainer();
281 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
282
283 return true;
284 }
285
286 TAG_HANDLER_END(Hx)
287
288
289 TAG_HANDLER_BEGIN(BIGSMALL, "BIG,SMALL")
290 TAG_HANDLER_CONSTR(BIGSMALL) { }
291
292 TAG_HANDLER_PROC(tag)
293 {
294 int oldsize = m_WParser->GetFontSize();
295 int sz = (tag.GetName() == wxT("BIG")) ? +1 : -1;
296
297 m_WParser->SetFontSize(sz);
298 m_WParser->GetContainer()->InsertCell(
299 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
300
301 ParseInner(tag);
302
303 m_WParser->SetFontSize(oldsize);
304 m_WParser->GetContainer()->InsertCell(
305 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
306 return true;
307 }
308
309 TAG_HANDLER_END(BIGSMALL)
310
311
312
313
314 TAGS_MODULE_BEGIN(Fonts)
315
316 TAGS_MODULE_ADD(FONT)
317 TAGS_MODULE_ADD(FACES_U)
318 TAGS_MODULE_ADD(FACES_I)
319 TAGS_MODULE_ADD(FACES_B)
320 TAGS_MODULE_ADD(FACES_TT)
321 TAGS_MODULE_ADD(Hx)
322 TAGS_MODULE_ADD(BIGSMALL)
323
324 TAGS_MODULE_END(Fonts)
325
326
327 #endif