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"
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"))) {
47 unsigned long tmp
= 0;
49 if (tag
.ScanParam(wxT("COLOR"), wxT("#%lX"), &tmp
) == 1) {
50 clr
= wxColour((tmp
& 0xFF0000) >> 16 , (tmp
& 0x00FF00) >> 8, (tmp
& 0x0000FF));
51 m_WParser
-> SetActualColor(clr
);
52 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlColourCell(clr
));
56 if (tag
.HasParam(wxT("SIZE"))) {
58 wxChar c
= tag
.GetParam(wxT("SIZE"))[(unsigned int) 0];
59 if (tag
.ScanParam(wxT("SIZE"), wxT("%li"), &tmp
) == 1) {
60 if (c
== '+' || c
== '-')
61 m_WParser
-> SetFontSize(oldsize
+tmp
);
63 m_WParser
-> SetFontSize(tmp
);
64 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
68 if (tag
.HasParam(wxT("FACE"))) {
69 if (m_Faces
.GetCount() == 0) {
71 enu
.EnumerateFacenames();
72 m_Faces
= *enu
.GetFacenames();
74 wxStringTokenizer
tk(tag
.GetParam(wxT("FACE")), ",");
77 while (tk
.HasMoreTokens())
78 if ((index
= m_Faces
.Index(tk
.GetNextToken())) != wxNOT_FOUND
) {
79 m_WParser
-> SetFontFace(m_Faces
[index
]);
80 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
87 if (oldface
!= m_WParser
-> GetFontFace()) {
88 m_WParser
-> SetFontFace(oldface
);
89 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
91 if (oldsize
!= m_WParser
-> GetFontSize()) {
92 m_WParser
-> SetFontSize(oldsize
);
93 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
95 if (oldclr
!= m_WParser
-> GetActualColor()) {
96 m_WParser
-> SetActualColor(oldclr
);
97 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlColourCell(oldclr
));
102 TAG_HANDLER_END(FONT
)
105 TAG_HANDLER_BEGIN(FACES_U
, "U,STRIKE")
107 TAG_HANDLER_PROC(tag
)
109 int underlined
= m_WParser
-> GetFontUnderlined();
111 m_WParser
-> SetFontUnderlined(TRUE
);
112 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
116 m_WParser
-> SetFontUnderlined(underlined
);
117 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
121 TAG_HANDLER_END(FACES_U
)
126 TAG_HANDLER_BEGIN(FACES_B
, "B,STRONG")
128 TAG_HANDLER_PROC(tag
)
130 int bold
= m_WParser
-> GetFontBold();
132 m_WParser
-> SetFontBold(TRUE
);
133 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
137 m_WParser
-> SetFontBold(bold
);
138 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
142 TAG_HANDLER_END(FACES_B
)
147 TAG_HANDLER_BEGIN(FACES_I
, "I,EM,CITE,ADDRESS")
149 TAG_HANDLER_PROC(tag
)
151 int italic
= m_WParser
-> GetFontItalic();
153 m_WParser
-> SetFontItalic(TRUE
);
154 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
158 m_WParser
-> SetFontItalic(italic
);
159 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
163 TAG_HANDLER_END(FACES_I
)
168 TAG_HANDLER_BEGIN(FACES_TT
, "TT,CODE,KBD,SAMP")
170 TAG_HANDLER_PROC(tag
)
172 int fixed
= m_WParser
-> GetFontFixed();
174 m_WParser
-> SetFontFixed(TRUE
);
175 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
179 m_WParser
-> SetFontFixed(fixed
);
180 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
184 TAG_HANDLER_END(FACES_TT
)
190 TAG_HANDLER_BEGIN(Hx
, "H1,H2,H3,H4,H5,H6")
192 TAG_HANDLER_PROC(tag
)
194 int old_size
, old_b
, old_i
, old_u
, old_f
, old_al
;
195 wxHtmlContainerCell
*c
;
197 old_size
= m_WParser
-> GetFontSize();
198 old_b
= m_WParser
-> GetFontBold();
199 old_i
= m_WParser
-> GetFontItalic();
200 old_u
= m_WParser
-> GetFontUnderlined();
201 old_f
= m_WParser
-> GetFontFixed();
202 old_al
= m_WParser
-> GetAlign();
204 m_WParser
-> SetFontBold(TRUE
);
205 m_WParser
-> SetFontItalic(FALSE
);
206 m_WParser
-> SetFontUnderlined(FALSE
);
207 m_WParser
-> SetFontFixed(FALSE
);
209 if (tag
.GetName() == wxT("H1"))
210 m_WParser
-> SetFontSize(7);
211 else if (tag
.GetName() == wxT("H2"))
212 m_WParser
-> SetFontSize(6);
213 else if (tag
.GetName() == wxT("H3"))
214 m_WParser
-> SetFontSize(5);
215 else if (tag
.GetName() == wxT("H4")) {
216 m_WParser
-> SetFontSize(5);
217 m_WParser
-> SetFontItalic(TRUE
);
218 m_WParser
-> SetFontBold(FALSE
);
220 else if (tag
.GetName() == wxT("H5"))
221 m_WParser
-> SetFontSize(4);
222 else if (tag
.GetName() == wxT("H6")) {
223 m_WParser
-> SetFontSize(4);
224 m_WParser
-> SetFontItalic(TRUE
);
225 m_WParser
-> SetFontBold(FALSE
);
228 c
= m_WParser
-> GetContainer();
229 if (c
-> GetFirstCell()) {
230 m_WParser
-> CloseContainer();
231 m_WParser
-> OpenContainer();
232 c
= m_WParser
-> GetContainer();
234 c
= m_WParser
-> GetContainer();
237 c
-> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
238 c
-> SetIndent(m_WParser
-> GetCharHeight(), wxHTML_INDENT_TOP
);
239 m_WParser
-> SetAlign(c
-> GetAlignHor());
243 m_WParser
-> SetFontSize(old_size
);
244 m_WParser
-> SetFontBold(old_b
);
245 m_WParser
-> SetFontItalic(old_i
);
246 m_WParser
-> SetFontUnderlined(old_u
);
247 m_WParser
-> SetFontFixed(old_f
);
248 m_WParser
-> SetAlign(old_al
);
250 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
251 m_WParser
-> CloseContainer();
252 m_WParser
-> OpenContainer();
253 c
= m_WParser
-> GetContainer();
254 c
-> SetIndent(m_WParser
-> GetCharHeight(), wxHTML_INDENT_TOP
);
262 TAG_HANDLER_BEGIN(BIGSMALL
, "BIG,SMALL")
264 TAG_HANDLER_PROC(tag
)
266 int oldsize
= m_WParser
-> GetFontSize();
267 int sz
= (tag
.GetName() == wxT("BIG")) ? +1 : -1;
269 m_WParser
-> SetFontSize(sz
);
270 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
274 m_WParser
-> SetFontSize(oldsize
);
275 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
279 TAG_HANDLER_END(BIGSMALL
)
284 TAGS_MODULE_BEGIN(Fonts
)
286 TAGS_MODULE_ADD(FONT
)
287 TAGS_MODULE_ADD(FACES_U
)
288 TAGS_MODULE_ADD(FACES_I
)
289 TAGS_MODULE_ADD(FACES_B
)
290 TAGS_MODULE_ADD(FACES_TT
)
292 TAGS_MODULE_ADD(BIGSMALL
)
294 TAGS_MODULE_END(Fonts
)