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