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