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