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")))
48 unsigned long tmp
= 0;
50 if (tag
.ScanParam(wxT("COLOR"), wxT("#%lX"), &tmp
) == 1)
52 clr
= wxColour((unsigned char)((tmp
& 0xFF0000) >> 16),
53 (unsigned char)((tmp
& 0x00FF00) >> 8),
54 (unsigned char)(tmp
& 0x0000FF));
55 m_WParser
->SetActualColor(clr
);
56 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(clr
));
60 if (tag
.HasParam(wxT("SIZE")))
63 wxChar c
= tag
.GetParam(wxT("SIZE"))[(unsigned int) 0];
64 if (tag
.ScanParam(wxT("SIZE"), wxT("%li"), &tmp
) == 1)
66 if (c
== '+' || c
== '-')
67 m_WParser
->SetFontSize(oldsize
+tmp
);
69 m_WParser
->SetFontSize(tmp
);
70 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
74 if (tag
.HasParam(wxT("FACE")))
76 if (m_Faces
.GetCount() == 0)
79 enu
.EnumerateFacenames();
80 m_Faces
= *enu
.GetFacenames();
82 wxStringTokenizer
tk(tag
.GetParam(wxT("FACE")), ",");
85 while (tk
.HasMoreTokens())
87 if ((index
= m_Faces
.Index(tk
.GetNextToken())) != wxNOT_FOUND
)
89 m_WParser
->SetFontFace(m_Faces
[index
]);
90 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
98 if (oldface
!= m_WParser
->GetFontFace())
100 m_WParser
->SetFontFace(oldface
);
101 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
103 if (oldsize
!= m_WParser
->GetFontSize())
105 m_WParser
->SetFontSize(oldsize
);
106 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
108 if (oldclr
!= m_WParser
->GetActualColor())
110 m_WParser
->SetActualColor(oldclr
);
111 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr
));
116 TAG_HANDLER_END(FONT
)
119 TAG_HANDLER_BEGIN(FACES_U
, "U,STRIKE")
121 TAG_HANDLER_PROC(tag
)
123 int underlined
= m_WParser
->GetFontUnderlined();
125 m_WParser
->SetFontUnderlined(TRUE
);
126 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
130 m_WParser
->SetFontUnderlined(underlined
);
131 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
135 TAG_HANDLER_END(FACES_U
)
140 TAG_HANDLER_BEGIN(FACES_B
, "B,STRONG")
142 TAG_HANDLER_PROC(tag
)
144 int bold
= m_WParser
->GetFontBold();
146 m_WParser
->SetFontBold(TRUE
);
147 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
151 m_WParser
->SetFontBold(bold
);
152 m_WParser
->GetContainer()->InsertCell(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(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
172 m_WParser
->SetFontItalic(italic
);
173 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
177 TAG_HANDLER_END(FACES_I
)
182 TAG_HANDLER_BEGIN(FACES_TT
, "TT,CODE,KBD,SAMP")
184 TAG_HANDLER_PROC(tag
)
186 int fixed
= m_WParser
->GetFontFixed();
188 m_WParser
->SetFontFixed(TRUE
);
189 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
193 m_WParser
->SetFontFixed(fixed
);
194 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
198 TAG_HANDLER_END(FACES_TT
)
204 TAG_HANDLER_BEGIN(Hx
, "H1,H2,H3,H4,H5,H6")
206 TAG_HANDLER_PROC(tag
)
208 int old_size
, old_b
, old_i
, old_u
, old_f
, old_al
;
209 wxHtmlContainerCell
*c
;
211 old_size
= m_WParser
->GetFontSize();
212 old_b
= m_WParser
->GetFontBold();
213 old_i
= m_WParser
->GetFontItalic();
214 old_u
= m_WParser
->GetFontUnderlined();
215 old_f
= m_WParser
->GetFontFixed();
216 old_al
= m_WParser
->GetAlign();
218 m_WParser
->SetFontBold(TRUE
);
219 m_WParser
->SetFontItalic(FALSE
);
220 m_WParser
->SetFontUnderlined(FALSE
);
221 m_WParser
->SetFontFixed(FALSE
);
223 if (tag
.GetName() == wxT("H1"))
224 m_WParser
->SetFontSize(7);
225 else if (tag
.GetName() == wxT("H2"))
226 m_WParser
->SetFontSize(6);
227 else if (tag
.GetName() == wxT("H3"))
228 m_WParser
->SetFontSize(5);
229 else if (tag
.GetName() == wxT("H4"))
231 m_WParser
->SetFontSize(5);
232 m_WParser
->SetFontItalic(TRUE
);
233 m_WParser
->SetFontBold(FALSE
);
235 else if (tag
.GetName() == wxT("H5"))
236 m_WParser
->SetFontSize(4);
237 else if (tag
.GetName() == wxT("H6"))
239 m_WParser
->SetFontSize(4);
240 m_WParser
->SetFontItalic(TRUE
);
241 m_WParser
->SetFontBold(FALSE
);
244 c
= m_WParser
->GetContainer();
245 if (c
->GetFirstCell())
247 m_WParser
->CloseContainer();
248 m_WParser
->OpenContainer();
249 c
= m_WParser
->GetContainer();
251 c
= m_WParser
->GetContainer();
254 c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
255 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
256 m_WParser
->SetAlign(c
->GetAlignHor());
260 m_WParser
->SetFontSize(old_size
);
261 m_WParser
->SetFontBold(old_b
);
262 m_WParser
->SetFontItalic(old_i
);
263 m_WParser
->SetFontUnderlined(old_u
);
264 m_WParser
->SetFontFixed(old_f
);
265 m_WParser
->SetAlign(old_al
);
267 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
268 m_WParser
->CloseContainer();
269 m_WParser
->OpenContainer();
270 c
= m_WParser
->GetContainer();
271 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
279 TAG_HANDLER_BEGIN(BIGSMALL
, "BIG,SMALL")
281 TAG_HANDLER_PROC(tag
)
283 int oldsize
= m_WParser
->GetFontSize();
284 int sz
= (tag
.GetName() == wxT("BIG")) ? +1 : -1;
286 m_WParser
->SetFontSize(sz
);
287 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
291 m_WParser
->SetFontSize(oldsize
);
292 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
296 TAG_HANDLER_END(BIGSMALL
)
301 TAGS_MODULE_BEGIN(Fonts
)
303 TAGS_MODULE_ADD(FONT
)
304 TAGS_MODULE_ADD(FACES_U
)
305 TAGS_MODULE_ADD(FACES_I
)
306 TAGS_MODULE_ADD(FACES_B
)
307 TAGS_MODULE_ADD(FACES_TT
)
309 TAGS_MODULE_ADD(BIGSMALL
)
311 TAGS_MODULE_END(Fonts
)