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