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((tmp
& 0xFF0000) >> 16 , (tmp
& 0x00FF00) >> 8, (tmp
& 0x0000FF));
53 m_WParser
->SetActualColor(clr
);
54 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(clr
));
58 if (tag
.HasParam(wxT("SIZE")))
61 wxChar c
= tag
.GetParam(wxT("SIZE"))[(unsigned int) 0];
62 if (tag
.ScanParam(wxT("SIZE"), wxT("%li"), &tmp
) == 1)
64 if (c
== '+' || c
== '-')
65 m_WParser
->SetFontSize(oldsize
+tmp
);
67 m_WParser
->SetFontSize(tmp
);
68 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
72 if (tag
.HasParam(wxT("FACE")))
74 if (m_Faces
.GetCount() == 0)
77 enu
.EnumerateFacenames();
78 m_Faces
= *enu
.GetFacenames();
80 wxStringTokenizer
tk(tag
.GetParam(wxT("FACE")), ",");
83 while (tk
.HasMoreTokens())
85 if ((index
= m_Faces
.Index(tk
.GetNextToken())) != wxNOT_FOUND
)
87 m_WParser
->SetFontFace(m_Faces
[index
]);
88 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
96 if (oldface
!= m_WParser
->GetFontFace())
98 m_WParser
->SetFontFace(oldface
);
99 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
101 if (oldsize
!= m_WParser
->GetFontSize())
103 m_WParser
->SetFontSize(oldsize
);
104 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
106 if (oldclr
!= m_WParser
->GetActualColor())
108 m_WParser
->SetActualColor(oldclr
);
109 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr
));
114 TAG_HANDLER_END(FONT
)
117 TAG_HANDLER_BEGIN(FACES_U
, "U,STRIKE")
119 TAG_HANDLER_PROC(tag
)
121 int underlined
= m_WParser
->GetFontUnderlined();
123 m_WParser
->SetFontUnderlined(TRUE
);
124 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
128 m_WParser
->SetFontUnderlined(underlined
);
129 m_WParser
->GetContainer()->InsertCell(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(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
149 m_WParser
->SetFontBold(bold
);
150 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
154 TAG_HANDLER_END(FACES_B
)
159 TAG_HANDLER_BEGIN(FACES_I
, "I,EM,CITE,ADDRESS")
161 TAG_HANDLER_PROC(tag
)
163 int italic
= m_WParser
->GetFontItalic();
165 m_WParser
->SetFontItalic(TRUE
);
166 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
170 m_WParser
->SetFontItalic(italic
);
171 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
175 TAG_HANDLER_END(FACES_I
)
180 TAG_HANDLER_BEGIN(FACES_TT
, "TT,CODE,KBD,SAMP")
182 TAG_HANDLER_PROC(tag
)
184 int fixed
= m_WParser
->GetFontFixed();
186 m_WParser
->SetFontFixed(TRUE
);
187 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
191 m_WParser
->SetFontFixed(fixed
);
192 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
196 TAG_HANDLER_END(FACES_TT
)
202 TAG_HANDLER_BEGIN(Hx
, "H1,H2,H3,H4,H5,H6")
204 TAG_HANDLER_PROC(tag
)
206 int old_size
, old_b
, old_i
, old_u
, old_f
, old_al
;
207 wxHtmlContainerCell
*c
;
209 old_size
= m_WParser
->GetFontSize();
210 old_b
= m_WParser
->GetFontBold();
211 old_i
= m_WParser
->GetFontItalic();
212 old_u
= m_WParser
->GetFontUnderlined();
213 old_f
= m_WParser
->GetFontFixed();
214 old_al
= m_WParser
->GetAlign();
216 m_WParser
->SetFontBold(TRUE
);
217 m_WParser
->SetFontItalic(FALSE
);
218 m_WParser
->SetFontUnderlined(FALSE
);
219 m_WParser
->SetFontFixed(FALSE
);
221 if (tag
.GetName() == wxT("H1"))
222 m_WParser
->SetFontSize(7);
223 else if (tag
.GetName() == wxT("H2"))
224 m_WParser
->SetFontSize(6);
225 else if (tag
.GetName() == wxT("H3"))
226 m_WParser
->SetFontSize(5);
227 else if (tag
.GetName() == wxT("H4"))
229 m_WParser
->SetFontSize(5);
230 m_WParser
->SetFontItalic(TRUE
);
231 m_WParser
->SetFontBold(FALSE
);
233 else if (tag
.GetName() == wxT("H5"))
234 m_WParser
->SetFontSize(4);
235 else if (tag
.GetName() == wxT("H6"))
237 m_WParser
->SetFontSize(4);
238 m_WParser
->SetFontItalic(TRUE
);
239 m_WParser
->SetFontBold(FALSE
);
242 c
= m_WParser
->GetContainer();
243 if (c
->GetFirstCell())
245 m_WParser
->CloseContainer();
246 m_WParser
->OpenContainer();
247 c
= m_WParser
->GetContainer();
249 c
= m_WParser
->GetContainer();
252 c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
253 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
254 m_WParser
->SetAlign(c
->GetAlignHor());
258 m_WParser
->SetFontSize(old_size
);
259 m_WParser
->SetFontBold(old_b
);
260 m_WParser
->SetFontItalic(old_i
);
261 m_WParser
->SetFontUnderlined(old_u
);
262 m_WParser
->SetFontFixed(old_f
);
263 m_WParser
->SetAlign(old_al
);
265 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
266 m_WParser
->CloseContainer();
267 m_WParser
->OpenContainer();
268 c
= m_WParser
->GetContainer();
269 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
277 TAG_HANDLER_BEGIN(BIGSMALL
, "BIG,SMALL")
279 TAG_HANDLER_PROC(tag
)
281 int oldsize
= m_WParser
->GetFontSize();
282 int sz
= (tag
.GetName() == wxT("BIG")) ? +1 : -1;
284 m_WParser
->SetFontSize(sz
);
285 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
289 m_WParser
->SetFontSize(oldsize
);
290 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
294 TAG_HANDLER_END(BIGSMALL
)
299 TAGS_MODULE_BEGIN(Fonts
)
301 TAGS_MODULE_ADD(FONT
)
302 TAGS_MODULE_ADD(FACES_U
)
303 TAGS_MODULE_ADD(FACES_I
)
304 TAGS_MODULE_ADD(FACES_B
)
305 TAGS_MODULE_ADD(FACES_TT
)
307 TAGS_MODULE_ADD(BIGSMALL
)
309 TAGS_MODULE_END(Fonts
)