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
27 #include "wx/html/forcelnk.h"
28 #include "wx/html/m_templ.h"
29 #include "wx/fontenum.h"
30 #include "wx/tokenzr.h"
32 FORCE_LINK_ME(m_fonts
)
35 TAG_HANDLER_BEGIN(FONT
, "FONT")
38 wxSortedArrayString m_Faces
;
42 wxColour oldclr
= m_WParser
->GetActualColor();
43 int oldsize
= m_WParser
->GetFontSize();
44 wxString oldface
= m_WParser
->GetFontFace();
46 if (tag
.HasParam(wxT("COLOR")))
49 if (tag
.GetParamAsColour(wxT("COLOR"), &clr
))
51 m_WParser
->SetActualColor(clr
);
52 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(clr
));
56 if (tag
.HasParam(wxT("SIZE")))
59 wxChar c
= tag
.GetParam(wxT("SIZE")).GetChar(0);
60 if (tag
.GetParamAsInt(wxT("SIZE"), &tmp
))
62 if (c
== wxT('+') || c
== wxT('-'))
63 m_WParser
->SetFontSize(oldsize
+tmp
);
65 m_WParser
->SetFontSize(tmp
);
66 m_WParser
->GetContainer()->InsertCell(
67 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
71 if (tag
.HasParam(wxT("FACE")))
73 if (m_Faces
.GetCount() == 0)
76 enu
.EnumerateFacenames();
77 m_Faces
= *enu
.GetFacenames();
79 wxStringTokenizer
tk(tag
.GetParam(wxT("FACE")), wxT(","));
82 while (tk
.HasMoreTokens())
84 if ((index
= m_Faces
.Index(tk
.GetNextToken())) != wxNOT_FOUND
)
86 m_WParser
->SetFontFace(m_Faces
[index
]);
87 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
95 if (oldface
!= m_WParser
->GetFontFace())
97 m_WParser
->SetFontFace(oldface
);
98 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
100 if (oldsize
!= m_WParser
->GetFontSize())
102 m_WParser
->SetFontSize(oldsize
);
103 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
105 if (oldclr
!= m_WParser
->GetActualColor())
107 m_WParser
->SetActualColor(oldclr
);
108 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr
));
113 TAG_HANDLER_END(FONT
)
116 TAG_HANDLER_BEGIN(FACES_U
, "U,STRIKE")
118 TAG_HANDLER_PROC(tag
)
120 int underlined
= m_WParser
->GetFontUnderlined();
122 m_WParser
->SetFontUnderlined(TRUE
);
123 m_WParser
->GetContainer()->InsertCell(
124 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
128 m_WParser
->SetFontUnderlined(underlined
);
129 m_WParser
->GetContainer()->InsertCell(
130 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
134 TAG_HANDLER_END(FACES_U
)
139 TAG_HANDLER_BEGIN(FACES_B
, "B,STRONG")
141 TAG_HANDLER_PROC(tag
)
143 int bold
= m_WParser
->GetFontBold();
145 m_WParser
->SetFontBold(TRUE
);
146 m_WParser
->GetContainer()->InsertCell(
147 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
151 m_WParser
->SetFontBold(bold
);
152 m_WParser
->GetContainer()->InsertCell(
153 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
157 TAG_HANDLER_END(FACES_B
)
162 TAG_HANDLER_BEGIN(FACES_I
, "I,EM,CITE,ADDRESS")
164 TAG_HANDLER_PROC(tag
)
166 int italic
= m_WParser
->GetFontItalic();
168 m_WParser
->SetFontItalic(TRUE
);
169 m_WParser
->GetContainer()->InsertCell(
170 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
174 m_WParser
->SetFontItalic(italic
);
175 m_WParser
->GetContainer()->InsertCell(
176 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
180 TAG_HANDLER_END(FACES_I
)
185 TAG_HANDLER_BEGIN(FACES_TT
, "TT,CODE,KBD,SAMP")
187 TAG_HANDLER_PROC(tag
)
189 int fixed
= m_WParser
->GetFontFixed();
191 m_WParser
->SetFontFixed(TRUE
);
192 m_WParser
->GetContainer()->InsertCell(
193 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
197 m_WParser
->SetFontFixed(fixed
);
198 m_WParser
->GetContainer()->InsertCell(
199 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
203 TAG_HANDLER_END(FACES_TT
)
209 TAG_HANDLER_BEGIN(Hx
, "H1,H2,H3,H4,H5,H6")
211 TAG_HANDLER_PROC(tag
)
213 int old_size
, old_b
, old_i
, old_u
, old_f
, old_al
;
214 wxHtmlContainerCell
*c
;
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();
223 m_WParser
->SetFontBold(TRUE
);
224 m_WParser
->SetFontItalic(FALSE
);
225 m_WParser
->SetFontUnderlined(FALSE
);
226 m_WParser
->SetFontFixed(FALSE
);
228 if (tag
.GetName() == wxT("H1"))
229 m_WParser
->SetFontSize(7);
230 else if (tag
.GetName() == wxT("H2"))
231 m_WParser
->SetFontSize(6);
232 else if (tag
.GetName() == wxT("H3"))
233 m_WParser
->SetFontSize(5);
234 else if (tag
.GetName() == wxT("H4"))
236 m_WParser
->SetFontSize(5);
237 m_WParser
->SetFontItalic(TRUE
);
238 m_WParser
->SetFontBold(FALSE
);
240 else if (tag
.GetName() == wxT("H5"))
241 m_WParser
->SetFontSize(4);
242 else if (tag
.GetName() == wxT("H6"))
244 m_WParser
->SetFontSize(4);
245 m_WParser
->SetFontItalic(TRUE
);
246 m_WParser
->SetFontBold(FALSE
);
249 c
= m_WParser
->GetContainer();
250 if (c
->GetFirstCell())
252 m_WParser
->CloseContainer();
253 m_WParser
->OpenContainer();
254 c
= m_WParser
->GetContainer();
256 c
= m_WParser
->GetContainer();
259 c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
260 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
261 m_WParser
->SetAlign(c
->GetAlignHor());
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
);
272 m_WParser
->GetContainer()->InsertCell(
273 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
274 m_WParser
->CloseContainer();
275 m_WParser
->OpenContainer();
276 c
= m_WParser
->GetContainer();
277 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
285 TAG_HANDLER_BEGIN(BIGSMALL
, "BIG,SMALL")
287 TAG_HANDLER_PROC(tag
)
289 int oldsize
= m_WParser
->GetFontSize();
290 int sz
= (tag
.GetName() == wxT("BIG")) ? +1 : -1;
292 m_WParser
->SetFontSize(sz
);
293 m_WParser
->GetContainer()->InsertCell(
294 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
298 m_WParser
->SetFontSize(oldsize
);
299 m_WParser
->GetContainer()->InsertCell(
300 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
304 TAG_HANDLER_END(BIGSMALL
)
309 TAGS_MODULE_BEGIN(Fonts
)
311 TAGS_MODULE_ADD(FONT
)
312 TAGS_MODULE_ADD(FACES_U
)
313 TAGS_MODULE_ADD(FACES_I
)
314 TAGS_MODULE_ADD(FACES_B
)
315 TAGS_MODULE_ADD(FACES_TT
)
317 TAGS_MODULE_ADD(BIGSMALL
)
319 TAGS_MODULE_END(Fonts
)