]> git.saurik.com Git - wxWidgets.git/blame - src/html/m_fonts.cpp
Extend history api using the ie backend to include loading history items, and getting...
[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
b4f4d3dd 18#ifndef WX_PRECOMP
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 {
2e49a807
VZ
54 long tmp = 0;
55 const wxString sizeStr = tag.GetParam(wxT("SIZE"));
56 if (sizeStr.ToLong(&tmp))
04dbb646 57 {
2e49a807 58 wxChar c = sizeStr[0];
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)
6540132f
VZ
71 m_Faces = wxFontEnumerator::GetFacenames();
72
8bd72d90 73 wxStringTokenizer tk(tag.GetParam(wxT("FACE")), wxT(","));
f1ad10f3 74 int index;
33ac7e6f
KB
75
76 while (tk.HasMoreTokens())
04dbb646 77 {
d1da8872 78 if ((index = m_Faces.Index(tk.GetNextToken(), false)) != wxNOT_FOUND)
04dbb646 79 {
4f9297b0
VS
80 m_WParser->SetFontFace(m_Faces[index]);
81 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
f1ad10f3
VS
82 break;
83 }
04dbb646 84 }
f1ad10f3 85 }
5526e819
VS
86
87 ParseInner(tag);
88
33ac7e6f 89 if (oldface != m_WParser->GetFontFace())
04dbb646 90 {
4f9297b0
VS
91 m_WParser->SetFontFace(oldface);
92 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
33ac7e6f
KB
93 }
94 if (oldsize != m_WParser->GetFontSize())
04dbb646 95 {
4f9297b0
VS
96 m_WParser->SetFontSize(oldsize);
97 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
33ac7e6f
KB
98 }
99 if (oldclr != m_WParser->GetActualColor())
04dbb646 100 {
4f9297b0
VS
101 m_WParser->SetActualColor(oldclr);
102 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr));
5526e819 103 }
d1da8872 104 return true;
5526e819
VS
105 }
106
107TAG_HANDLER_END(FONT)
108
109
e7ee65ed 110TAG_HANDLER_BEGIN(FACES_U, "U,STRIKE")
5526e819 111
fc7a2a60
VZ
112 TAG_HANDLER_CONSTR(FACES_U) { }
113
5526e819
VS
114 TAG_HANDLER_PROC(tag)
115 {
4f9297b0 116 int underlined = m_WParser->GetFontUnderlined();
ef01b72f 117
d1da8872 118 m_WParser->SetFontUnderlined(true);
8bd72d90
VS
119 m_WParser->GetContainer()->InsertCell(
120 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
5526e819
VS
121
122 ParseInner(tag);
123
4f9297b0 124 m_WParser->SetFontUnderlined(underlined);
8bd72d90
VS
125 m_WParser->GetContainer()->InsertCell(
126 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
d1da8872 127 return true;
ef01b72f
VS
128 }
129
130TAG_HANDLER_END(FACES_U)
131
132
133
134
135TAG_HANDLER_BEGIN(FACES_B, "B,STRONG")
fc7a2a60 136 TAG_HANDLER_CONSTR(FACES_B) { }
ef01b72f
VS
137
138 TAG_HANDLER_PROC(tag)
139 {
4f9297b0 140 int bold = m_WParser->GetFontBold();
ef01b72f 141
d1da8872 142 m_WParser->SetFontBold(true);
8bd72d90
VS
143 m_WParser->GetContainer()->InsertCell(
144 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ef01b72f
VS
145
146 ParseInner(tag);
147
4f9297b0 148 m_WParser->SetFontBold(bold);
8bd72d90
VS
149 m_WParser->GetContainer()->InsertCell(
150 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
d1da8872 151 return true;
ef01b72f
VS
152 }
153
154TAG_HANDLER_END(FACES_B)
155
156
157
158
e7ee65ed 159TAG_HANDLER_BEGIN(FACES_I, "I,EM,CITE,ADDRESS")
fc7a2a60 160 TAG_HANDLER_CONSTR(FACES_I) { }
ef01b72f
VS
161
162 TAG_HANDLER_PROC(tag)
163 {
4f9297b0 164 int italic = m_WParser->GetFontItalic();
ef01b72f 165
d1da8872 166 m_WParser->SetFontItalic(true);
8bd72d90
VS
167 m_WParser->GetContainer()->InsertCell(
168 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ef01b72f
VS
169
170 ParseInner(tag);
171
4f9297b0 172 m_WParser->SetFontItalic(italic);
8bd72d90
VS
173 m_WParser->GetContainer()->InsertCell(
174 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
d1da8872 175 return true;
ef01b72f
VS
176 }
177
178TAG_HANDLER_END(FACES_I)
179
180
181
182
e7ee65ed 183TAG_HANDLER_BEGIN(FACES_TT, "TT,CODE,KBD,SAMP")
fc7a2a60 184 TAG_HANDLER_CONSTR(FACES_TT) { }
ef01b72f
VS
185
186 TAG_HANDLER_PROC(tag)
187 {
4f9297b0 188 int fixed = m_WParser->GetFontFixed();
ef01b72f 189
d1da8872 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()));
d1da8872 199 return true;
5526e819
VS
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")
fc7a2a60 209 TAG_HANDLER_CONSTR(Hx) { }
5526e819
VS
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
4f9297b0
VS
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();
5526e819 222
d1da8872
WS
223 m_WParser->SetFontBold(true);
224 m_WParser->SetFontItalic(false);
225 m_WParser->SetFontUnderlined(false);
226 m_WParser->SetFontFixed(false);
5526e819 227
e7ee65ed 228 if (tag.GetName() == wxT("H1"))
4f9297b0 229 m_WParser->SetFontSize(7);
0413cec5 230 else if (tag.GetName() == wxT("H2"))
4f9297b0 231 m_WParser->SetFontSize(6);
0413cec5 232 else if (tag.GetName() == wxT("H3"))
4f9297b0 233 m_WParser->SetFontSize(5);
33ac7e6f 234 else if (tag.GetName() == wxT("H4"))
04dbb646 235 {
4f9297b0 236 m_WParser->SetFontSize(5);
d1da8872
WS
237 m_WParser->SetFontItalic(true);
238 m_WParser->SetFontBold(false);
5526e819 239 }
0413cec5 240 else if (tag.GetName() == wxT("H5"))
4f9297b0 241 m_WParser->SetFontSize(4);
33ac7e6f 242 else if (tag.GetName() == wxT("H6"))
04dbb646 243 {
4f9297b0 244 m_WParser->SetFontSize(4);
d1da8872
WS
245 m_WParser->SetFontItalic(true);
246 m_WParser->SetFontBold(false);
5526e819
VS
247 }
248
4f9297b0 249 c = m_WParser->GetContainer();
e3774124 250 if (c->GetFirstChild())
04dbb646 251 {
4f9297b0
VS
252 m_WParser->CloseContainer();
253 m_WParser->OpenContainer();
254 c = m_WParser->GetContainer();
5526e819 255 }
4f9297b0 256 c = m_WParser->GetContainer();
5526e819 257
4f9297b0
VS
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());
5526e819
VS
262
263 ParseInner(tag);
264
4f9297b0
VS
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);
5526e819 271
8bd72d90
VS
272 m_WParser->GetContainer()->InsertCell(
273 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
4f9297b0
VS
274 m_WParser->CloseContainer();
275 m_WParser->OpenContainer();
276 c = m_WParser->GetContainer();
277 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
5526e819 278
d1da8872 279 return true;
5526e819
VS
280 }
281
282TAG_HANDLER_END(Hx)
283
284
e7ee65ed 285TAG_HANDLER_BEGIN(BIGSMALL, "BIG,SMALL")
fc7a2a60 286 TAG_HANDLER_CONSTR(BIGSMALL) { }
e7ee65ed
VS
287
288 TAG_HANDLER_PROC(tag)
289 {
4f9297b0 290 int oldsize = m_WParser->GetFontSize();
e7ee65ed
VS
291 int sz = (tag.GetName() == wxT("BIG")) ? +1 : -1;
292
4f9297b0 293 m_WParser->SetFontSize(sz);
8bd72d90
VS
294 m_WParser->GetContainer()->InsertCell(
295 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
e7ee65ed
VS
296
297 ParseInner(tag);
298
4f9297b0 299 m_WParser->SetFontSize(oldsize);
8bd72d90
VS
300 m_WParser->GetContainer()->InsertCell(
301 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
d1da8872 302 return true;
e7ee65ed
VS
303 }
304
305TAG_HANDLER_END(BIGSMALL)
306
307
5526e819
VS
308
309
310TAGS_MODULE_BEGIN(Fonts)
311
312 TAGS_MODULE_ADD(FONT)
ef01b72f
VS
313 TAGS_MODULE_ADD(FACES_U)
314 TAGS_MODULE_ADD(FACES_I)
315 TAGS_MODULE_ADD(FACES_B)
316 TAGS_MODULE_ADD(FACES_TT)
5526e819 317 TAGS_MODULE_ADD(Hx)
e7ee65ed 318 TAGS_MODULE_ADD(BIGSMALL)
5526e819
VS
319
320TAGS_MODULE_END(Fonts)
321
322
3364ab79 323#endif