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