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