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