Added some missing tests; replaced scrolwin.cpp with scrlwng.cpp
[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 #ifdef __GNUG__
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 __BORDLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WXPRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include "wx/html/forcelnk.h"
28 #include "wx/html/m_templ.h"
29 #include "wx/fontenum.h"
30 #include "wx/tokenzr.h"
31
32 FORCE_LINK_ME(m_fonts)
33
34
35 TAG_HANDLER_BEGIN(FONT, "FONT")
36
37 TAG_HANDLER_VARS
38 wxSortedArrayString m_Faces;
39
40 TAG_HANDLER_PROC(tag)
41 {
42 wxColour oldclr = m_WParser->GetActualColor();
43 int oldsize = m_WParser->GetFontSize();
44 wxString oldface = m_WParser->GetFontFace();
45
46 if (tag.HasParam(wxT("COLOR")))
47 {
48 wxColour clr;
49 if (tag.GetParamAsColour(wxT("COLOR"), &clr))
50 {
51 m_WParser->SetActualColor(clr);
52 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr));
53 }
54 }
55
56 if (tag.HasParam(wxT("SIZE")))
57 {
58 int tmp = 0;
59 wxChar c = tag.GetParam(wxT("SIZE")).GetChar(0);
60 if (tag.GetParamAsInt(wxT("SIZE"), &tmp))
61 {
62 if (c == wxT('+') || c == wxT('-'))
63 m_WParser->SetFontSize(oldsize+tmp);
64 else
65 m_WParser->SetFontSize(tmp);
66 m_WParser->GetContainer()->InsertCell(
67 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
68 }
69 }
70
71 if (tag.HasParam(wxT("FACE")))
72 {
73 if (m_Faces.GetCount() == 0)
74 {
75 wxFontEnumerator enu;
76 enu.EnumerateFacenames();
77 m_Faces = *enu.GetFacenames();
78 }
79 wxStringTokenizer tk(tag.GetParam(wxT("FACE")), wxT(","));
80 int index;
81
82 while (tk.HasMoreTokens())
83 {
84 if ((index = m_Faces.Index(tk.GetNextToken())) != wxNOT_FOUND)
85 {
86 m_WParser->SetFontFace(m_Faces[index]);
87 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
88 break;
89 }
90 }
91 }
92
93 ParseInner(tag);
94
95 if (oldface != m_WParser->GetFontFace())
96 {
97 m_WParser->SetFontFace(oldface);
98 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
99 }
100 if (oldsize != m_WParser->GetFontSize())
101 {
102 m_WParser->SetFontSize(oldsize);
103 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
104 }
105 if (oldclr != m_WParser->GetActualColor())
106 {
107 m_WParser->SetActualColor(oldclr);
108 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr));
109 }
110 return TRUE;
111 }
112
113 TAG_HANDLER_END(FONT)
114
115
116 TAG_HANDLER_BEGIN(FACES_U, "U,STRIKE")
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
141 TAG_HANDLER_PROC(tag)
142 {
143 int bold = m_WParser->GetFontBold();
144
145 m_WParser->SetFontBold(TRUE);
146 m_WParser->GetContainer()->InsertCell(
147 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
148
149 ParseInner(tag);
150
151 m_WParser->SetFontBold(bold);
152 m_WParser->GetContainer()->InsertCell(
153 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
154 return TRUE;
155 }
156
157 TAG_HANDLER_END(FACES_B)
158
159
160
161
162 TAG_HANDLER_BEGIN(FACES_I, "I,EM,CITE,ADDRESS")
163
164 TAG_HANDLER_PROC(tag)
165 {
166 int italic = m_WParser->GetFontItalic();
167
168 m_WParser->SetFontItalic(TRUE);
169 m_WParser->GetContainer()->InsertCell(
170 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
171
172 ParseInner(tag);
173
174 m_WParser->SetFontItalic(italic);
175 m_WParser->GetContainer()->InsertCell(
176 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
177 return TRUE;
178 }
179
180 TAG_HANDLER_END(FACES_I)
181
182
183
184
185 TAG_HANDLER_BEGIN(FACES_TT, "TT,CODE,KBD,SAMP")
186
187 TAG_HANDLER_PROC(tag)
188 {
189 int fixed = m_WParser->GetFontFixed();
190
191 m_WParser->SetFontFixed(TRUE);
192 m_WParser->GetContainer()->InsertCell(
193 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
194
195 ParseInner(tag);
196
197 m_WParser->SetFontFixed(fixed);
198 m_WParser->GetContainer()->InsertCell(
199 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
200 return TRUE;
201 }
202
203 TAG_HANDLER_END(FACES_TT)
204
205
206
207
208
209 TAG_HANDLER_BEGIN(Hx, "H1,H2,H3,H4,H5,H6")
210
211 TAG_HANDLER_PROC(tag)
212 {
213 int old_size, old_b, old_i, old_u, old_f, old_al;
214 wxHtmlContainerCell *c;
215
216 old_size = m_WParser->GetFontSize();
217 old_b = m_WParser->GetFontBold();
218 old_i = m_WParser->GetFontItalic();
219 old_u = m_WParser->GetFontUnderlined();
220 old_f = m_WParser->GetFontFixed();
221 old_al = m_WParser->GetAlign();
222
223 m_WParser->SetFontBold(TRUE);
224 m_WParser->SetFontItalic(FALSE);
225 m_WParser->SetFontUnderlined(FALSE);
226 m_WParser->SetFontFixed(FALSE);
227
228 if (tag.GetName() == wxT("H1"))
229 m_WParser->SetFontSize(7);
230 else if (tag.GetName() == wxT("H2"))
231 m_WParser->SetFontSize(6);
232 else if (tag.GetName() == wxT("H3"))
233 m_WParser->SetFontSize(5);
234 else if (tag.GetName() == wxT("H4"))
235 {
236 m_WParser->SetFontSize(5);
237 m_WParser->SetFontItalic(TRUE);
238 m_WParser->SetFontBold(FALSE);
239 }
240 else if (tag.GetName() == wxT("H5"))
241 m_WParser->SetFontSize(4);
242 else if (tag.GetName() == wxT("H6"))
243 {
244 m_WParser->SetFontSize(4);
245 m_WParser->SetFontItalic(TRUE);
246 m_WParser->SetFontBold(FALSE);
247 }
248
249 c = m_WParser->GetContainer();
250 if (c->GetFirstCell())
251 {
252 m_WParser->CloseContainer();
253 m_WParser->OpenContainer();
254 c = m_WParser->GetContainer();
255 }
256 c = m_WParser->GetContainer();
257
258 c->SetAlign(tag);
259 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
260 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
261 m_WParser->SetAlign(c->GetAlignHor());
262
263 ParseInner(tag);
264
265 m_WParser->SetFontSize(old_size);
266 m_WParser->SetFontBold(old_b);
267 m_WParser->SetFontItalic(old_i);
268 m_WParser->SetFontUnderlined(old_u);
269 m_WParser->SetFontFixed(old_f);
270 m_WParser->SetAlign(old_al);
271
272 m_WParser->GetContainer()->InsertCell(
273 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
274 m_WParser->CloseContainer();
275 m_WParser->OpenContainer();
276 c = m_WParser->GetContainer();
277 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
278
279 return TRUE;
280 }
281
282 TAG_HANDLER_END(Hx)
283
284
285 TAG_HANDLER_BEGIN(BIGSMALL, "BIG,SMALL")
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