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