]> git.saurik.com Git - wxWidgets.git/blob - src/html/m_fonts.cpp
wxCLOSE->wxCLOSE_BOX
[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 __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_PROC(tag)
40 {
41 wxColour oldclr = m_WParser->GetActualColor();
42 int oldsize = m_WParser->GetFontSize();
43 wxString oldface = m_WParser->GetFontFace();
44
45 if (tag.HasParam(wxT("COLOR")))
46 {
47 wxColour clr;
48 if (tag.GetParamAsColour(wxT("COLOR"), &clr))
49 {
50 m_WParser->SetActualColor(clr);
51 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr));
52 }
53 }
54
55 if (tag.HasParam(wxT("SIZE")))
56 {
57 int tmp = 0;
58 wxChar c = tag.GetParam(wxT("SIZE")).GetChar(0);
59 if (tag.GetParamAsInt(wxT("SIZE"), &tmp))
60 {
61 if (c == wxT('+') || c == wxT('-'))
62 m_WParser->SetFontSize(oldsize+tmp);
63 else
64 m_WParser->SetFontSize(tmp);
65 m_WParser->GetContainer()->InsertCell(
66 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
67 }
68 }
69
70 if (tag.HasParam(wxT("FACE")))
71 {
72 if (m_Faces.GetCount() == 0)
73 {
74 wxFontEnumerator enu;
75 enu.EnumerateFacenames();
76 m_Faces = *enu.GetFacenames();
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_PROC(tag)
118 {
119 int underlined = m_WParser->GetFontUnderlined();
120
121 m_WParser->SetFontUnderlined(TRUE);
122 m_WParser->GetContainer()->InsertCell(
123 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
124
125 ParseInner(tag);
126
127 m_WParser->SetFontUnderlined(underlined);
128 m_WParser->GetContainer()->InsertCell(
129 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
130 return TRUE;
131 }
132
133 TAG_HANDLER_END(FACES_U)
134
135
136
137
138 TAG_HANDLER_BEGIN(FACES_B, "B,STRONG")
139
140 TAG_HANDLER_PROC(tag)
141 {
142 int bold = m_WParser->GetFontBold();
143
144 m_WParser->SetFontBold(TRUE);
145 m_WParser->GetContainer()->InsertCell(
146 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
147
148 ParseInner(tag);
149
150 m_WParser->SetFontBold(bold);
151 m_WParser->GetContainer()->InsertCell(
152 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
153 return TRUE;
154 }
155
156 TAG_HANDLER_END(FACES_B)
157
158
159
160
161 TAG_HANDLER_BEGIN(FACES_I, "I,EM,CITE,ADDRESS")
162
163 TAG_HANDLER_PROC(tag)
164 {
165 int italic = m_WParser->GetFontItalic();
166
167 m_WParser->SetFontItalic(TRUE);
168 m_WParser->GetContainer()->InsertCell(
169 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
170
171 ParseInner(tag);
172
173 m_WParser->SetFontItalic(italic);
174 m_WParser->GetContainer()->InsertCell(
175 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
176 return TRUE;
177 }
178
179 TAG_HANDLER_END(FACES_I)
180
181
182
183
184 TAG_HANDLER_BEGIN(FACES_TT, "TT,CODE,KBD,SAMP")
185
186 TAG_HANDLER_PROC(tag)
187 {
188 int fixed = m_WParser->GetFontFixed();
189
190 m_WParser->SetFontFixed(TRUE);
191 m_WParser->GetContainer()->InsertCell(
192 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
193
194 ParseInner(tag);
195
196 m_WParser->SetFontFixed(fixed);
197 m_WParser->GetContainer()->InsertCell(
198 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
199 return TRUE;
200 }
201
202 TAG_HANDLER_END(FACES_TT)
203
204
205
206
207
208 TAG_HANDLER_BEGIN(Hx, "H1,H2,H3,H4,H5,H6")
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->GetFirstCell())
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
286 TAG_HANDLER_PROC(tag)
287 {
288 int oldsize = m_WParser->GetFontSize();
289 int sz = (tag.GetName() == wxT("BIG")) ? +1 : -1;
290
291 m_WParser->SetFontSize(sz);
292 m_WParser->GetContainer()->InsertCell(
293 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
294
295 ParseInner(tag);
296
297 m_WParser->SetFontSize(oldsize);
298 m_WParser->GetContainer()->InsertCell(
299 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
300 return TRUE;
301 }
302
303 TAG_HANDLER_END(BIGSMALL)
304
305
306
307
308 TAGS_MODULE_BEGIN(Fonts)
309
310 TAGS_MODULE_ADD(FONT)
311 TAGS_MODULE_ADD(FACES_U)
312 TAGS_MODULE_ADD(FACES_I)
313 TAGS_MODULE_ADD(FACES_B)
314 TAGS_MODULE_ADD(FACES_TT)
315 TAGS_MODULE_ADD(Hx)
316 TAGS_MODULE_ADD(BIGSMALL)
317
318 TAGS_MODULE_END(Fonts)
319
320
321 #endif