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