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