]> git.saurik.com Git - wxWidgets.git/blob - src/html/m_fonts.cpp
Beginning of bitmap updates
[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((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF));
53 m_WParser->SetActualColor(clr);
54 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr));
55 }
56 }
57
58 if (tag.HasParam(wxT("SIZE")))
59 {
60 long tmp = 0;
61 wxChar c = tag.GetParam(wxT("SIZE"))[(unsigned int) 0];
62 if (tag.ScanParam(wxT("SIZE"), wxT("%li"), &tmp) == 1)
63 {
64 if (c == '+' || c == '-')
65 m_WParser->SetFontSize(oldsize+tmp);
66 else
67 m_WParser->SetFontSize(tmp);
68 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
69 }
70 }
71
72 if (tag.HasParam(wxT("FACE")))
73 {
74 if (m_Faces.GetCount() == 0)
75 {
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())
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()));
89 break;
90 }
91 }
92 }
93
94 ParseInner(tag);
95
96 if (oldface != m_WParser->GetFontFace())
97 {
98 m_WParser->SetFontFace(oldface);
99 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
100 }
101 if (oldsize != m_WParser->GetFontSize())
102 {
103 m_WParser->SetFontSize(oldsize);
104 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
105 }
106 if (oldclr != m_WParser->GetActualColor())
107 {
108 m_WParser->SetActualColor(oldclr);
109 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr));
110 }
111 return TRUE;
112 }
113
114 TAG_HANDLER_END(FONT)
115
116
117 TAG_HANDLER_BEGIN(FACES_U, "U,STRIKE")
118
119 TAG_HANDLER_PROC(tag)
120 {
121 int underlined = m_WParser->GetFontUnderlined();
122
123 m_WParser->SetFontUnderlined(TRUE);
124 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
125
126 ParseInner(tag);
127
128 m_WParser->SetFontUnderlined(underlined);
129 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
130 return TRUE;
131 }
132
133 TAG_HANDLER_END(FACES_U)
134
135
136
137
138 TAG_HANDLER_BEGIN(FACES_B, "B,STRONG")
139
140 TAG_HANDLER_PROC(tag)
141 {
142 int bold = m_WParser->GetFontBold();
143
144 m_WParser->SetFontBold(TRUE);
145 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
146
147 ParseInner(tag);
148
149 m_WParser->SetFontBold(bold);
150 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
151 return TRUE;
152 }
153
154 TAG_HANDLER_END(FACES_B)
155
156
157
158
159 TAG_HANDLER_BEGIN(FACES_I, "I,EM,CITE,ADDRESS")
160
161 TAG_HANDLER_PROC(tag)
162 {
163 int italic = m_WParser->GetFontItalic();
164
165 m_WParser->SetFontItalic(TRUE);
166 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
167
168 ParseInner(tag);
169
170 m_WParser->SetFontItalic(italic);
171 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
172 return TRUE;
173 }
174
175 TAG_HANDLER_END(FACES_I)
176
177
178
179
180 TAG_HANDLER_BEGIN(FACES_TT, "TT,CODE,KBD,SAMP")
181
182 TAG_HANDLER_PROC(tag)
183 {
184 int fixed = m_WParser->GetFontFixed();
185
186 m_WParser->SetFontFixed(TRUE);
187 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
188
189 ParseInner(tag);
190
191 m_WParser->SetFontFixed(fixed);
192 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
193 return TRUE;
194 }
195
196 TAG_HANDLER_END(FACES_TT)
197
198
199
200
201
202 TAG_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
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();
215
216 m_WParser->SetFontBold(TRUE);
217 m_WParser->SetFontItalic(FALSE);
218 m_WParser->SetFontUnderlined(FALSE);
219 m_WParser->SetFontFixed(FALSE);
220
221 if (tag.GetName() == wxT("H1"))
222 m_WParser->SetFontSize(7);
223 else if (tag.GetName() == wxT("H2"))
224 m_WParser->SetFontSize(6);
225 else if (tag.GetName() == wxT("H3"))
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);
232 }
233 else if (tag.GetName() == wxT("H5"))
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);
240 }
241
242 c = m_WParser->GetContainer();
243 if (c->GetFirstCell())
244 {
245 m_WParser->CloseContainer();
246 m_WParser->OpenContainer();
247 c = m_WParser->GetContainer();
248 }
249 c = m_WParser->GetContainer();
250
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());
255
256 ParseInner(tag);
257
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);
264
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);
270
271 return TRUE;
272 }
273
274 TAG_HANDLER_END(Hx)
275
276
277 TAG_HANDLER_BEGIN(BIGSMALL, "BIG,SMALL")
278
279 TAG_HANDLER_PROC(tag)
280 {
281 int oldsize = m_WParser->GetFontSize();
282 int sz = (tag.GetName() == wxT("BIG")) ? +1 : -1;
283
284 m_WParser->SetFontSize(sz);
285 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
286
287 ParseInner(tag);
288
289 m_WParser->SetFontSize(oldsize);
290 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
291 return TRUE;
292 }
293
294 TAG_HANDLER_END(BIGSMALL)
295
296
297
298
299 TAGS_MODULE_BEGIN(Fonts)
300
301 TAGS_MODULE_ADD(FONT)
302 TAGS_MODULE_ADD(FACES_U)
303 TAGS_MODULE_ADD(FACES_I)
304 TAGS_MODULE_ADD(FACES_B)
305 TAGS_MODULE_ADD(FACES_TT)
306 TAGS_MODULE_ADD(Hx)
307 TAGS_MODULE_ADD(BIGSMALL)
308
309 TAGS_MODULE_END(Fonts)
310
311
312 #endif