1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml module for fonts & colors of fonts
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation
14 #include "wx/wxprec.h"
17 #if wxUSE_HTML && wxUSE_STREAMS
26 #include "wx/html/forcelnk.h"
27 #include "wx/html/m_templ.h"
28 #include "wx/fontenum.h"
29 #include "wx/tokenzr.h"
31 FORCE_LINK_ME(m_fonts
)
34 TAG_HANDLER_BEGIN(FONT
, "FONT")
37 wxSortedArrayString m_Faces
;
41 wxColour oldclr
= m_WParser
->GetActualColor();
42 int oldsize
= m_WParser
->GetFontSize();
43 wxString oldface
= m_WParser
->GetFontFace();
45 if (tag
.HasParam(wxT("COLOR")))
48 if (tag
.GetParamAsColour(wxT("COLOR"), &clr
))
50 m_WParser
->SetActualColor(clr
);
51 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(clr
));
55 if (tag
.HasParam(wxT("SIZE")))
58 wxChar c
= tag
.GetParam(wxT("SIZE")).GetChar(0);
59 if (tag
.GetParamAsInt(wxT("SIZE"), &tmp
))
61 if (c
== wxT('+') || c
== wxT('-'))
62 m_WParser
->SetFontSize(oldsize
+tmp
);
64 m_WParser
->SetFontSize(tmp
);
65 m_WParser
->GetContainer()->InsertCell(
66 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
70 if (tag
.HasParam(wxT("FACE")))
72 if (m_Faces
.GetCount() == 0)
75 enu
.EnumerateFacenames();
76 m_Faces
= *enu
.GetFacenames();
78 wxStringTokenizer
tk(tag
.GetParam(wxT("FACE")), wxT(","));
81 while (tk
.HasMoreTokens())
83 if ((index
= m_Faces
.Index(tk
.GetNextToken())) != wxNOT_FOUND
)
85 m_WParser
->SetFontFace(m_Faces
[index
]);
86 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
94 if (oldface
!= m_WParser
->GetFontFace())
96 m_WParser
->SetFontFace(oldface
);
97 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
99 if (oldsize
!= m_WParser
->GetFontSize())
101 m_WParser
->SetFontSize(oldsize
);
102 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
104 if (oldclr
!= m_WParser
->GetActualColor())
106 m_WParser
->SetActualColor(oldclr
);
107 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr
));
112 TAG_HANDLER_END(FONT
)
115 TAG_HANDLER_BEGIN(FACES_U
, "U,STRIKE")
117 TAG_HANDLER_PROC(tag
)
119 int underlined
= m_WParser
->GetFontUnderlined();
121 m_WParser
->SetFontUnderlined(TRUE
);
122 m_WParser
->GetContainer()->InsertCell(
123 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
127 m_WParser
->SetFontUnderlined(underlined
);
128 m_WParser
->GetContainer()->InsertCell(
129 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
133 TAG_HANDLER_END(FACES_U
)
138 TAG_HANDLER_BEGIN(FACES_B
, "B,STRONG")
140 TAG_HANDLER_PROC(tag
)
142 int bold
= m_WParser
->GetFontBold();
144 m_WParser
->SetFontBold(TRUE
);
145 m_WParser
->GetContainer()->InsertCell(
146 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
150 m_WParser
->SetFontBold(bold
);
151 m_WParser
->GetContainer()->InsertCell(
152 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
156 TAG_HANDLER_END(FACES_B
)
161 TAG_HANDLER_BEGIN(FACES_I
, "I,EM,CITE,ADDRESS")
163 TAG_HANDLER_PROC(tag
)
165 int italic
= m_WParser
->GetFontItalic();
167 m_WParser
->SetFontItalic(TRUE
);
168 m_WParser
->GetContainer()->InsertCell(
169 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
173 m_WParser
->SetFontItalic(italic
);
174 m_WParser
->GetContainer()->InsertCell(
175 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
179 TAG_HANDLER_END(FACES_I
)
184 TAG_HANDLER_BEGIN(FACES_TT
, "TT,CODE,KBD,SAMP")
186 TAG_HANDLER_PROC(tag
)
188 int fixed
= m_WParser
->GetFontFixed();
190 m_WParser
->SetFontFixed(TRUE
);
191 m_WParser
->GetContainer()->InsertCell(
192 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
196 m_WParser
->SetFontFixed(fixed
);
197 m_WParser
->GetContainer()->InsertCell(
198 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
202 TAG_HANDLER_END(FACES_TT
)
208 TAG_HANDLER_BEGIN(Hx
, "H1,H2,H3,H4,H5,H6")
210 TAG_HANDLER_PROC(tag
)
212 int old_size
, old_b
, old_i
, old_u
, old_f
, old_al
;
213 wxHtmlContainerCell
*c
;
215 old_size
= m_WParser
->GetFontSize();
216 old_b
= m_WParser
->GetFontBold();
217 old_i
= m_WParser
->GetFontItalic();
218 old_u
= m_WParser
->GetFontUnderlined();
219 old_f
= m_WParser
->GetFontFixed();
220 old_al
= m_WParser
->GetAlign();
222 m_WParser
->SetFontBold(TRUE
);
223 m_WParser
->SetFontItalic(FALSE
);
224 m_WParser
->SetFontUnderlined(FALSE
);
225 m_WParser
->SetFontFixed(FALSE
);
227 if (tag
.GetName() == wxT("H1"))
228 m_WParser
->SetFontSize(7);
229 else if (tag
.GetName() == wxT("H2"))
230 m_WParser
->SetFontSize(6);
231 else if (tag
.GetName() == wxT("H3"))
232 m_WParser
->SetFontSize(5);
233 else if (tag
.GetName() == wxT("H4"))
235 m_WParser
->SetFontSize(5);
236 m_WParser
->SetFontItalic(TRUE
);
237 m_WParser
->SetFontBold(FALSE
);
239 else if (tag
.GetName() == wxT("H5"))
240 m_WParser
->SetFontSize(4);
241 else if (tag
.GetName() == wxT("H6"))
243 m_WParser
->SetFontSize(4);
244 m_WParser
->SetFontItalic(TRUE
);
245 m_WParser
->SetFontBold(FALSE
);
248 c
= m_WParser
->GetContainer();
249 if (c
->GetFirstCell())
251 m_WParser
->CloseContainer();
252 m_WParser
->OpenContainer();
253 c
= m_WParser
->GetContainer();
255 c
= m_WParser
->GetContainer();
258 c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
259 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
260 m_WParser
->SetAlign(c
->GetAlignHor());
264 m_WParser
->SetFontSize(old_size
);
265 m_WParser
->SetFontBold(old_b
);
266 m_WParser
->SetFontItalic(old_i
);
267 m_WParser
->SetFontUnderlined(old_u
);
268 m_WParser
->SetFontFixed(old_f
);
269 m_WParser
->SetAlign(old_al
);
271 m_WParser
->GetContainer()->InsertCell(
272 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
273 m_WParser
->CloseContainer();
274 m_WParser
->OpenContainer();
275 c
= m_WParser
->GetContainer();
276 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
284 TAG_HANDLER_BEGIN(BIGSMALL
, "BIG,SMALL")
286 TAG_HANDLER_PROC(tag
)
288 int oldsize
= m_WParser
->GetFontSize();
289 int sz
= (tag
.GetName() == wxT("BIG")) ? +1 : -1;
291 m_WParser
->SetFontSize(sz
);
292 m_WParser
->GetContainer()->InsertCell(
293 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
297 m_WParser
->SetFontSize(oldsize
);
298 m_WParser
->GetContainer()->InsertCell(
299 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
303 TAG_HANDLER_END(BIGSMALL
)
308 TAGS_MODULE_BEGIN(Fonts
)
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
)
316 TAGS_MODULE_ADD(BIGSMALL
)
318 TAGS_MODULE_END(Fonts
)