]>
Commit | Line | Data |
---|---|---|
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 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
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 __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WXPRECOMP | |
24 | #endif | |
25 | ||
26 | #include "wx/html/forcelnk.h" | |
27 | #include "wx/html/m_templ.h" | |
28 | #include "wx/fontenum.h" | |
29 | #include "wx/tokenzr.h" | |
30 | ||
31 | FORCE_LINK_ME(m_fonts) | |
32 | ||
33 | ||
34 | TAG_HANDLER_BEGIN(FONT, "FONT" ) | |
35 | ||
36 | TAG_HANDLER_VARS | |
37 | wxArrayString m_Faces; | |
38 | ||
39 | TAG_HANDLER_CONSTR(FONT) { } | |
40 | ||
41 | TAG_HANDLER_PROC(tag) | |
42 | { | |
43 | wxColour oldclr = m_WParser->GetActualColor(); | |
44 | int oldsize = m_WParser->GetFontSize(); | |
45 | wxString oldface = m_WParser->GetFontFace(); | |
46 | ||
47 | if (tag.HasParam(wxT("COLOR"))) | |
48 | { | |
49 | wxColour clr; | |
50 | if (tag.GetParamAsColour(wxT("COLOR"), &clr)) | |
51 | { | |
52 | m_WParser->SetActualColor(clr); | |
53 | m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr)); | |
54 | } | |
55 | } | |
56 | ||
57 | if (tag.HasParam(wxT("SIZE"))) | |
58 | { | |
59 | int tmp = 0; | |
60 | wxChar c = tag.GetParam(wxT("SIZE")).GetChar(0); | |
61 | if (tag.GetParamAsInt(wxT("SIZE"), &tmp)) | |
62 | { | |
63 | if (c == wxT('+') || c == wxT('-')) | |
64 | m_WParser->SetFontSize(oldsize+tmp); | |
65 | else | |
66 | m_WParser->SetFontSize(tmp); | |
67 | m_WParser->GetContainer()->InsertCell( | |
68 | 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 | const wxArrayString *faces = enu.GetFacenames(); | |
79 | if ( faces ) | |
80 | m_Faces = *faces; | |
81 | } | |
82 | wxStringTokenizer tk(tag.GetParam(wxT("FACE")), wxT(",")); | |
83 | int index; | |
84 | ||
85 | while (tk.HasMoreTokens()) | |
86 | { | |
87 | if ((index = m_Faces.Index(tk.GetNextToken(), FALSE)) != 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_CONSTR(FACES_U) { } | |
122 | ||
123 | TAG_HANDLER_PROC(tag) | |
124 | { | |
125 | int underlined = m_WParser->GetFontUnderlined(); | |
126 | ||
127 | m_WParser->SetFontUnderlined(TRUE); | |
128 | m_WParser->GetContainer()->InsertCell( | |
129 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
130 | ||
131 | ParseInner(tag); | |
132 | ||
133 | m_WParser->SetFontUnderlined(underlined); | |
134 | m_WParser->GetContainer()->InsertCell( | |
135 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
136 | return TRUE; | |
137 | } | |
138 | ||
139 | TAG_HANDLER_END(FACES_U) | |
140 | ||
141 | ||
142 | ||
143 | ||
144 | TAG_HANDLER_BEGIN(FACES_B, "B,STRONG") | |
145 | TAG_HANDLER_CONSTR(FACES_B) { } | |
146 | ||
147 | TAG_HANDLER_PROC(tag) | |
148 | { | |
149 | int bold = m_WParser->GetFontBold(); | |
150 | ||
151 | m_WParser->SetFontBold(TRUE); | |
152 | m_WParser->GetContainer()->InsertCell( | |
153 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
154 | ||
155 | ParseInner(tag); | |
156 | ||
157 | m_WParser->SetFontBold(bold); | |
158 | m_WParser->GetContainer()->InsertCell( | |
159 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
160 | return TRUE; | |
161 | } | |
162 | ||
163 | TAG_HANDLER_END(FACES_B) | |
164 | ||
165 | ||
166 | ||
167 | ||
168 | TAG_HANDLER_BEGIN(FACES_I, "I,EM,CITE,ADDRESS") | |
169 | TAG_HANDLER_CONSTR(FACES_I) { } | |
170 | ||
171 | TAG_HANDLER_PROC(tag) | |
172 | { | |
173 | int italic = m_WParser->GetFontItalic(); | |
174 | ||
175 | m_WParser->SetFontItalic(TRUE); | |
176 | m_WParser->GetContainer()->InsertCell( | |
177 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
178 | ||
179 | ParseInner(tag); | |
180 | ||
181 | m_WParser->SetFontItalic(italic); | |
182 | m_WParser->GetContainer()->InsertCell( | |
183 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
184 | return TRUE; | |
185 | } | |
186 | ||
187 | TAG_HANDLER_END(FACES_I) | |
188 | ||
189 | ||
190 | ||
191 | ||
192 | TAG_HANDLER_BEGIN(FACES_TT, "TT,CODE,KBD,SAMP") | |
193 | TAG_HANDLER_CONSTR(FACES_TT) { } | |
194 | ||
195 | TAG_HANDLER_PROC(tag) | |
196 | { | |
197 | int fixed = m_WParser->GetFontFixed(); | |
198 | ||
199 | m_WParser->SetFontFixed(TRUE); | |
200 | m_WParser->GetContainer()->InsertCell( | |
201 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
202 | ||
203 | ParseInner(tag); | |
204 | ||
205 | m_WParser->SetFontFixed(fixed); | |
206 | m_WParser->GetContainer()->InsertCell( | |
207 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
208 | return TRUE; | |
209 | } | |
210 | ||
211 | TAG_HANDLER_END(FACES_TT) | |
212 | ||
213 | ||
214 | ||
215 | ||
216 | ||
217 | TAG_HANDLER_BEGIN(Hx, "H1,H2,H3,H4,H5,H6") | |
218 | TAG_HANDLER_CONSTR(Hx) { } | |
219 | ||
220 | TAG_HANDLER_PROC(tag) | |
221 | { | |
222 | int old_size, old_b, old_i, old_u, old_f, old_al; | |
223 | wxHtmlContainerCell *c; | |
224 | ||
225 | old_size = m_WParser->GetFontSize(); | |
226 | old_b = m_WParser->GetFontBold(); | |
227 | old_i = m_WParser->GetFontItalic(); | |
228 | old_u = m_WParser->GetFontUnderlined(); | |
229 | old_f = m_WParser->GetFontFixed(); | |
230 | old_al = m_WParser->GetAlign(); | |
231 | ||
232 | m_WParser->SetFontBold(TRUE); | |
233 | m_WParser->SetFontItalic(FALSE); | |
234 | m_WParser->SetFontUnderlined(FALSE); | |
235 | m_WParser->SetFontFixed(FALSE); | |
236 | ||
237 | if (tag.GetName() == wxT("H1")) | |
238 | m_WParser->SetFontSize(7); | |
239 | else if (tag.GetName() == wxT("H2")) | |
240 | m_WParser->SetFontSize(6); | |
241 | else if (tag.GetName() == wxT("H3")) | |
242 | m_WParser->SetFontSize(5); | |
243 | else if (tag.GetName() == wxT("H4")) | |
244 | { | |
245 | m_WParser->SetFontSize(5); | |
246 | m_WParser->SetFontItalic(TRUE); | |
247 | m_WParser->SetFontBold(FALSE); | |
248 | } | |
249 | else if (tag.GetName() == wxT("H5")) | |
250 | m_WParser->SetFontSize(4); | |
251 | else if (tag.GetName() == wxT("H6")) | |
252 | { | |
253 | m_WParser->SetFontSize(4); | |
254 | m_WParser->SetFontItalic(TRUE); | |
255 | m_WParser->SetFontBold(FALSE); | |
256 | } | |
257 | ||
258 | c = m_WParser->GetContainer(); | |
259 | if (c->GetFirstChild()) | |
260 | { | |
261 | m_WParser->CloseContainer(); | |
262 | m_WParser->OpenContainer(); | |
263 | c = m_WParser->GetContainer(); | |
264 | } | |
265 | c = m_WParser->GetContainer(); | |
266 | ||
267 | c->SetAlign(tag); | |
268 | c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
269 | c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP); | |
270 | m_WParser->SetAlign(c->GetAlignHor()); | |
271 | ||
272 | ParseInner(tag); | |
273 | ||
274 | m_WParser->SetFontSize(old_size); | |
275 | m_WParser->SetFontBold(old_b); | |
276 | m_WParser->SetFontItalic(old_i); | |
277 | m_WParser->SetFontUnderlined(old_u); | |
278 | m_WParser->SetFontFixed(old_f); | |
279 | m_WParser->SetAlign(old_al); | |
280 | ||
281 | m_WParser->GetContainer()->InsertCell( | |
282 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
283 | m_WParser->CloseContainer(); | |
284 | m_WParser->OpenContainer(); | |
285 | c = m_WParser->GetContainer(); | |
286 | c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP); | |
287 | ||
288 | return TRUE; | |
289 | } | |
290 | ||
291 | TAG_HANDLER_END(Hx) | |
292 | ||
293 | ||
294 | TAG_HANDLER_BEGIN(BIGSMALL, "BIG,SMALL") | |
295 | TAG_HANDLER_CONSTR(BIGSMALL) { } | |
296 | ||
297 | TAG_HANDLER_PROC(tag) | |
298 | { | |
299 | int oldsize = m_WParser->GetFontSize(); | |
300 | int sz = (tag.GetName() == wxT("BIG")) ? +1 : -1; | |
301 | ||
302 | m_WParser->SetFontSize(sz); | |
303 | m_WParser->GetContainer()->InsertCell( | |
304 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
305 | ||
306 | ParseInner(tag); | |
307 | ||
308 | m_WParser->SetFontSize(oldsize); | |
309 | m_WParser->GetContainer()->InsertCell( | |
310 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
311 | return TRUE; | |
312 | } | |
313 | ||
314 | TAG_HANDLER_END(BIGSMALL) | |
315 | ||
316 | ||
317 | ||
318 | ||
319 | TAGS_MODULE_BEGIN(Fonts) | |
320 | ||
321 | TAGS_MODULE_ADD(FONT) | |
322 | TAGS_MODULE_ADD(FACES_U) | |
323 | TAGS_MODULE_ADD(FACES_I) | |
324 | TAGS_MODULE_ADD(FACES_B) | |
325 | TAGS_MODULE_ADD(FACES_TT) | |
326 | TAGS_MODULE_ADD(Hx) | |
327 | TAGS_MODULE_ADD(BIGSMALL) | |
328 | ||
329 | TAGS_MODULE_END(Fonts) | |
330 | ||
331 | ||
332 | #endif |