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