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