]> git.saurik.com Git - wxWidgets.git/blob - src/html/m_fonts.cpp
changed version number
[wxWidgets.git] / src / html / m_fonts.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: m_fonts.cpp
3 // Purpose: wxHtml module for fonts & colors of fonts
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation
12 #endif
13
14 #include "wx/wxprec.h"
15
16 #include "wx/defs.h"
17 #if wxUSE_HTML && wxUSE_STREAMS
18
19 #ifdef __BORDLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WXPRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include "wx/html/forcelnk.h"
28 #include "wx/html/m_templ.h"
29 #include "wx/fontenum.h"
30 #include "wx/tokenzr.h"
31
32 FORCE_LINK_ME(m_fonts)
33
34
35 TAG_HANDLER_BEGIN(FONT, "FONT")
36
37 TAG_HANDLER_VARS
38 wxSortedArrayString m_Faces;
39
40 TAG_HANDLER_PROC(tag)
41 {
42 wxColour oldclr = m_WParser->GetActualColor();
43 int oldsize = m_WParser->GetFontSize();
44 wxString oldface = m_WParser->GetFontFace();
45
46 if (tag.HasParam(wxT("COLOR")))
47 {
48 unsigned long tmp = 0;
49 wxColour clr;
50 if (tag.ScanParam(wxT("COLOR"), wxT("#%lX"), &tmp) == 1)
51 {
52 clr = wxColour((unsigned char)((tmp & 0xFF0000) >> 16),
53 (unsigned char)((tmp & 0x00FF00) >> 8),
54 (unsigned char)(tmp & 0x0000FF));
55 m_WParser->SetActualColor(clr);
56 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr));
57 }
58 }
59
60 if (tag.HasParam(wxT("SIZE")))
61 {
62 long tmp = 0;
63 wxChar c = tag.GetParam(wxT("SIZE"))[(unsigned int) 0];
64 if (tag.ScanParam(wxT("SIZE"), wxT("%li"), &tmp) == 1)
65 {
66 if (c == '+' || c == '-')
67 m_WParser->SetFontSize(oldsize+tmp);
68 else
69 m_WParser->SetFontSize(tmp);
70 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
71 }
72 }
73
74 if (tag.HasParam(wxT("FACE")))
75 {
76 if (m_Faces.GetCount() == 0)
77 {
78 wxFontEnumerator enu;
79 enu.EnumerateFacenames();
80 m_Faces = *enu.GetFacenames();
81 }
82 wxStringTokenizer tk(tag.GetParam(wxT("FACE")), ",");
83 int index;
84
85 while (tk.HasMoreTokens())
86 {
87 if ((index = m_Faces.Index(tk.GetNextToken())) != wxNOT_FOUND)
88 {
89 m_WParser->SetFontFace(m_Faces[index]);
90 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
91 break;
92 }
93 }
94 }
95
96 ParseInner(tag);
97
98 if (oldface != m_WParser->GetFontFace())
99 {
100 m_WParser->SetFontFace(oldface);
101 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
102 }
103 if (oldsize != m_WParser->GetFontSize())
104 {
105 m_WParser->SetFontSize(oldsize);
106 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
107 }
108 if (oldclr != m_WParser->GetActualColor())
109 {
110 m_WParser->SetActualColor(oldclr);
111 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr));
112 }
113 return TRUE;
114 }
115
116 TAG_HANDLER_END(FONT)
117
118
119 TAG_HANDLER_BEGIN(FACES_U, "U,STRIKE")
120
121 TAG_HANDLER_PROC(tag)
122 {
123 int underlined = m_WParser->GetFontUnderlined();
124
125 m_WParser->SetFontUnderlined(TRUE);
126 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
127
128 ParseInner(tag);
129
130 m_WParser->SetFontUnderlined(underlined);
131 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
132 return TRUE;
133 }
134
135 TAG_HANDLER_END(FACES_U)
136
137
138
139
140 TAG_HANDLER_BEGIN(FACES_B, "B,STRONG")
141
142 TAG_HANDLER_PROC(tag)
143 {
144 int bold = m_WParser->GetFontBold();
145
146 m_WParser->SetFontBold(TRUE);
147 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
148
149 ParseInner(tag);
150
151 m_WParser->SetFontBold(bold);
152 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
153 return TRUE;
154 }
155
156 TAG_HANDLER_END(FACES_B)
157
158
159
160
161 TAG_HANDLER_BEGIN(FACES_I, "I,EM,CITE,ADDRESS")
162
163 TAG_HANDLER_PROC(tag)
164 {
165 int italic = m_WParser->GetFontItalic();
166
167 m_WParser->SetFontItalic(TRUE);
168 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
169
170 ParseInner(tag);
171
172 m_WParser->SetFontItalic(italic);
173 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
174 return TRUE;
175 }
176
177 TAG_HANDLER_END(FACES_I)
178
179
180
181
182 TAG_HANDLER_BEGIN(FACES_TT, "TT,CODE,KBD,SAMP")
183
184 TAG_HANDLER_PROC(tag)
185 {
186 int fixed = m_WParser->GetFontFixed();
187
188 m_WParser->SetFontFixed(TRUE);
189 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
190
191 ParseInner(tag);
192
193 m_WParser->SetFontFixed(fixed);
194 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
195 return TRUE;
196 }
197
198 TAG_HANDLER_END(FACES_TT)
199
200
201
202
203
204 TAG_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
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();
217
218 m_WParser->SetFontBold(TRUE);
219 m_WParser->SetFontItalic(FALSE);
220 m_WParser->SetFontUnderlined(FALSE);
221 m_WParser->SetFontFixed(FALSE);
222
223 if (tag.GetName() == wxT("H1"))
224 m_WParser->SetFontSize(7);
225 else if (tag.GetName() == wxT("H2"))
226 m_WParser->SetFontSize(6);
227 else if (tag.GetName() == wxT("H3"))
228 m_WParser->SetFontSize(5);
229 else if (tag.GetName() == wxT("H4"))
230 {
231 m_WParser->SetFontSize(5);
232 m_WParser->SetFontItalic(TRUE);
233 m_WParser->SetFontBold(FALSE);
234 }
235 else if (tag.GetName() == wxT("H5"))
236 m_WParser->SetFontSize(4);
237 else if (tag.GetName() == wxT("H6"))
238 {
239 m_WParser->SetFontSize(4);
240 m_WParser->SetFontItalic(TRUE);
241 m_WParser->SetFontBold(FALSE);
242 }
243
244 c = m_WParser->GetContainer();
245 if (c->GetFirstCell())
246 {
247 m_WParser->CloseContainer();
248 m_WParser->OpenContainer();
249 c = m_WParser->GetContainer();
250 }
251 c = m_WParser->GetContainer();
252
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());
257
258 ParseInner(tag);
259
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);
266
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);
272
273 return TRUE;
274 }
275
276 TAG_HANDLER_END(Hx)
277
278
279 TAG_HANDLER_BEGIN(BIGSMALL, "BIG,SMALL")
280
281 TAG_HANDLER_PROC(tag)
282 {
283 int oldsize = m_WParser->GetFontSize();
284 int sz = (tag.GetName() == wxT("BIG")) ? +1 : -1;
285
286 m_WParser->SetFontSize(sz);
287 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
288
289 ParseInner(tag);
290
291 m_WParser->SetFontSize(oldsize);
292 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
293 return TRUE;
294 }
295
296 TAG_HANDLER_END(BIGSMALL)
297
298
299
300
301 TAGS_MODULE_BEGIN(Fonts)
302
303 TAGS_MODULE_ADD(FONT)
304 TAGS_MODULE_ADD(FACES_U)
305 TAGS_MODULE_ADD(FACES_I)
306 TAGS_MODULE_ADD(FACES_B)
307 TAGS_MODULE_ADD(FACES_TT)
308 TAGS_MODULE_ADD(Hx)
309 TAGS_MODULE_ADD(BIGSMALL)
310
311 TAGS_MODULE_END(Fonts)
312
313
314 #endif