]> git.saurik.com Git - wxWidgets.git/blame - src/html/m_fonts.cpp
complain about nonexistent directory in wxDir
[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
VS
6// Copyright: (c) 1999 Vaclav Slavik
7// Licence: wxWindows Licence
8/////////////////////////////////////////////////////////////////////////////
9
3364ab79
RS
10#ifdef __GNUG__
11#pragma implementation
12#endif
13
3096bd2f 14#include "wx/wxprec.h"
5526e819
VS
15
16#include "wx/defs.h"
f6bcfd97 17#if wxUSE_HTML && wxUSE_STREAMS
5526e819 18
3364ab79
RS
19#ifdef __BORDLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WXPRECOMP
3364ab79
RS
24#endif
25
69941f05
VS
26#include "wx/html/forcelnk.h"
27#include "wx/html/m_templ.h"
f1ad10f3
VS
28#include "wx/fontenum.h"
29#include "wx/tokenzr.h"
5526e819 30
ef01b72f 31FORCE_LINK_ME(m_fonts)
5526e819
VS
32
33
9b64e798 34TAG_HANDLER_BEGIN(FONT, "FONT")
5526e819 35
f1ad10f3
VS
36 TAG_HANDLER_VARS
37 wxSortedArrayString m_Faces;
38
5526e819
VS
39 TAG_HANDLER_PROC(tag)
40 {
4f9297b0
VS
41 wxColour oldclr = m_WParser->GetActualColor();
42 int oldsize = m_WParser->GetFontSize();
43 wxString oldface = m_WParser->GetFontFace();
5526e819 44
33ac7e6f 45 if (tag.HasParam(wxT("COLOR")))
04dbb646 46 {
5526e819 47 wxColour clr;
8bd72d90 48 if (tag.GetParamAsColour(wxT("COLOR"), &clr))
04dbb646 49 {
4f9297b0
VS
50 m_WParser->SetActualColor(clr);
51 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr));
e7ee65ed 52 }
5526e819
VS
53 }
54
33ac7e6f 55 if (tag.HasParam(wxT("SIZE")))
04dbb646 56 {
8bd72d90
VS
57 int tmp = 0;
58 wxChar c = tag.GetParam(wxT("SIZE")).GetChar(0);
59 if (tag.GetParamAsInt(wxT("SIZE"), &tmp))
04dbb646 60 {
8bd72d90 61 if (c == wxT('+') || c == wxT('-'))
4f9297b0 62 m_WParser->SetFontSize(oldsize+tmp);
2463329c 63 else
4f9297b0 64 m_WParser->SetFontSize(tmp);
8bd72d90
VS
65 m_WParser->GetContainer()->InsertCell(
66 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
e7ee65ed 67 }
5526e819 68 }
33ac7e6f
KB
69
70 if (tag.HasParam(wxT("FACE")))
04dbb646 71 {
33ac7e6f 72 if (m_Faces.GetCount() == 0)
04dbb646 73 {
f1ad10f3
VS
74 wxFontEnumerator enu;
75 enu.EnumerateFacenames();
76 m_Faces = *enu.GetFacenames();
77 }
8bd72d90 78 wxStringTokenizer tk(tag.GetParam(wxT("FACE")), wxT(","));
f1ad10f3 79 int index;
33ac7e6f
KB
80
81 while (tk.HasMoreTokens())
04dbb646 82 {
33ac7e6f 83 if ((index = m_Faces.Index(tk.GetNextToken())) != 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
VS
108 }
109 return TRUE;
110 }
111
112TAG_HANDLER_END(FONT)
113
114
e7ee65ed 115TAG_HANDLER_BEGIN(FACES_U, "U,STRIKE")
5526e819
VS
116
117 TAG_HANDLER_PROC(tag)
118 {
4f9297b0 119 int underlined = m_WParser->GetFontUnderlined();
ef01b72f 120
4f9297b0 121 m_WParser->SetFontUnderlined(TRUE);
8bd72d90
VS
122 m_WParser->GetContainer()->InsertCell(
123 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
5526e819
VS
124
125 ParseInner(tag);
126
4f9297b0 127 m_WParser->SetFontUnderlined(underlined);
8bd72d90
VS
128 m_WParser->GetContainer()->InsertCell(
129 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ef01b72f
VS
130 return TRUE;
131 }
132
133TAG_HANDLER_END(FACES_U)
134
135
136
137
138TAG_HANDLER_BEGIN(FACES_B, "B,STRONG")
139
140 TAG_HANDLER_PROC(tag)
141 {
4f9297b0 142 int bold = m_WParser->GetFontBold();
ef01b72f 143
4f9297b0 144 m_WParser->SetFontBold(TRUE);
8bd72d90
VS
145 m_WParser->GetContainer()->InsertCell(
146 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ef01b72f
VS
147
148 ParseInner(tag);
149
4f9297b0 150 m_WParser->SetFontBold(bold);
8bd72d90
VS
151 m_WParser->GetContainer()->InsertCell(
152 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ef01b72f
VS
153 return TRUE;
154 }
155
156TAG_HANDLER_END(FACES_B)
157
158
159
160
e7ee65ed 161TAG_HANDLER_BEGIN(FACES_I, "I,EM,CITE,ADDRESS")
ef01b72f
VS
162
163 TAG_HANDLER_PROC(tag)
164 {
4f9297b0 165 int italic = m_WParser->GetFontItalic();
ef01b72f 166
4f9297b0 167 m_WParser->SetFontItalic(TRUE);
8bd72d90
VS
168 m_WParser->GetContainer()->InsertCell(
169 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ef01b72f
VS
170
171 ParseInner(tag);
172
4f9297b0 173 m_WParser->SetFontItalic(italic);
8bd72d90
VS
174 m_WParser->GetContainer()->InsertCell(
175 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ef01b72f
VS
176 return TRUE;
177 }
178
179TAG_HANDLER_END(FACES_I)
180
181
182
183
e7ee65ed 184TAG_HANDLER_BEGIN(FACES_TT, "TT,CODE,KBD,SAMP")
ef01b72f
VS
185
186 TAG_HANDLER_PROC(tag)
187 {
4f9297b0 188 int fixed = m_WParser->GetFontFixed();
ef01b72f 189
4f9297b0 190 m_WParser->SetFontFixed(TRUE);
8bd72d90
VS
191 m_WParser->GetContainer()->InsertCell(
192 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ef01b72f
VS
193
194 ParseInner(tag);
195
4f9297b0 196 m_WParser->SetFontFixed(fixed);
8bd72d90
VS
197 m_WParser->GetContainer()->InsertCell(
198 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
5526e819
VS
199 return TRUE;
200 }
201
ef01b72f 202TAG_HANDLER_END(FACES_TT)
5526e819
VS
203
204
205
206
207
208TAG_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
4f9297b0
VS
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();
5526e819 221
4f9297b0
VS
222 m_WParser->SetFontBold(TRUE);
223 m_WParser->SetFontItalic(FALSE);
224 m_WParser->SetFontUnderlined(FALSE);
225 m_WParser->SetFontFixed(FALSE);
5526e819 226
e7ee65ed 227 if (tag.GetName() == wxT("H1"))
4f9297b0 228 m_WParser->SetFontSize(7);
0413cec5 229 else if (tag.GetName() == wxT("H2"))
4f9297b0 230 m_WParser->SetFontSize(6);
0413cec5 231 else if (tag.GetName() == wxT("H3"))
4f9297b0 232 m_WParser->SetFontSize(5);
33ac7e6f 233 else if (tag.GetName() == wxT("H4"))
04dbb646 234 {
4f9297b0
VS
235 m_WParser->SetFontSize(5);
236 m_WParser->SetFontItalic(TRUE);
237 m_WParser->SetFontBold(FALSE);
5526e819 238 }
0413cec5 239 else if (tag.GetName() == wxT("H5"))
4f9297b0 240 m_WParser->SetFontSize(4);
33ac7e6f 241 else if (tag.GetName() == wxT("H6"))
04dbb646 242 {
4f9297b0
VS
243 m_WParser->SetFontSize(4);
244 m_WParser->SetFontItalic(TRUE);
245 m_WParser->SetFontBold(FALSE);
5526e819
VS
246 }
247
4f9297b0 248 c = m_WParser->GetContainer();
33ac7e6f 249 if (c->GetFirstCell())
04dbb646 250 {
4f9297b0
VS
251 m_WParser->CloseContainer();
252 m_WParser->OpenContainer();
253 c = m_WParser->GetContainer();
5526e819 254 }
4f9297b0 255 c = m_WParser->GetContainer();
5526e819 256
4f9297b0
VS
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());
5526e819
VS
261
262 ParseInner(tag);
263
4f9297b0
VS
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);
5526e819 270
8bd72d90
VS
271 m_WParser->GetContainer()->InsertCell(
272 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
4f9297b0
VS
273 m_WParser->CloseContainer();
274 m_WParser->OpenContainer();
275 c = m_WParser->GetContainer();
276 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
5526e819
VS
277
278 return TRUE;
279 }
280
281TAG_HANDLER_END(Hx)
282
283
e7ee65ed
VS
284TAG_HANDLER_BEGIN(BIGSMALL, "BIG,SMALL")
285
286 TAG_HANDLER_PROC(tag)
287 {
4f9297b0 288 int oldsize = m_WParser->GetFontSize();
e7ee65ed
VS
289 int sz = (tag.GetName() == wxT("BIG")) ? +1 : -1;
290
4f9297b0 291 m_WParser->SetFontSize(sz);
8bd72d90
VS
292 m_WParser->GetContainer()->InsertCell(
293 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
e7ee65ed
VS
294
295 ParseInner(tag);
296
4f9297b0 297 m_WParser->SetFontSize(oldsize);
8bd72d90
VS
298 m_WParser->GetContainer()->InsertCell(
299 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
e7ee65ed
VS
300 return TRUE;
301 }
302
303TAG_HANDLER_END(BIGSMALL)
304
305
5526e819
VS
306
307
308TAGS_MODULE_BEGIN(Fonts)
309
310 TAGS_MODULE_ADD(FONT)
ef01b72f
VS
311 TAGS_MODULE_ADD(FACES_U)
312 TAGS_MODULE_ADD(FACES_I)
313 TAGS_MODULE_ADD(FACES_B)
314 TAGS_MODULE_ADD(FACES_TT)
5526e819 315 TAGS_MODULE_ADD(Hx)
e7ee65ed 316 TAGS_MODULE_ADD(BIGSMALL)
5526e819
VS
317
318TAGS_MODULE_END(Fonts)
319
320
3364ab79 321#endif