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