]>
git.saurik.com Git - wxWidgets.git/blob - src/html/m_fonts.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/m_fonts.cpp
3 // Purpose: wxHtml module for fonts & colors of fonts
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
15 #if wxUSE_HTML && wxUSE_STREAMS
20 #include "wx/html/forcelnk.h"
21 #include "wx/html/m_templ.h"
22 #include "wx/fontenum.h"
23 #include "wx/tokenzr.h"
25 FORCE_LINK_ME(m_fonts
)
28 TAG_HANDLER_BEGIN(FONT
, "FONT" )
31 wxArrayString m_Faces
;
33 TAG_HANDLER_CONSTR(FONT
) { }
37 wxColour oldclr
= m_WParser
->GetActualColor();
38 int oldsize
= m_WParser
->GetFontSize();
39 wxString oldface
= m_WParser
->GetFontFace();
41 if (tag
.HasParam(wxT("COLOR")))
44 if (tag
.GetParamAsColour(wxT("COLOR"), &clr
))
46 m_WParser
->SetActualColor(clr
);
47 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(clr
));
51 if (tag
.HasParam(wxT("SIZE")))
54 const wxString sizeStr
= tag
.GetParam(wxT("SIZE"));
55 if (sizeStr
.ToLong(&tmp
))
57 wxChar c
= sizeStr
[0];
58 if (c
== wxT('+') || c
== wxT('-'))
59 m_WParser
->SetFontSize(oldsize
+tmp
);
61 m_WParser
->SetFontSize(tmp
);
62 m_WParser
->GetContainer()->InsertCell(
63 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
67 if (tag
.HasParam(wxT("FACE")))
69 if (m_Faces
.GetCount() == 0)
70 m_Faces
= wxFontEnumerator::GetFacenames();
72 wxStringTokenizer
tk(tag
.GetParam(wxT("FACE")), wxT(","));
75 while (tk
.HasMoreTokens())
77 if ((index
= m_Faces
.Index(tk
.GetNextToken(), false)) != wxNOT_FOUND
)
79 m_WParser
->SetFontFace(m_Faces
[index
]);
80 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
88 if (oldface
!= m_WParser
->GetFontFace())
90 m_WParser
->SetFontFace(oldface
);
91 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
93 if (oldsize
!= m_WParser
->GetFontSize())
95 m_WParser
->SetFontSize(oldsize
);
96 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
98 if (oldclr
!= m_WParser
->GetActualColor())
100 m_WParser
->SetActualColor(oldclr
);
101 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr
));
106 TAG_HANDLER_END(FONT
)
109 TAG_HANDLER_BEGIN(FACES_U
, "U,STRIKE,DEL")
111 TAG_HANDLER_CONSTR(FACES_U
) { }
113 TAG_HANDLER_PROC(tag
)
115 int underlined
= m_WParser
->GetFontUnderlined();
117 m_WParser
->SetFontUnderlined(true);
118 m_WParser
->GetContainer()->InsertCell(
119 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
123 m_WParser
->SetFontUnderlined(underlined
);
124 m_WParser
->GetContainer()->InsertCell(
125 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
129 TAG_HANDLER_END(FACES_U
)
134 TAG_HANDLER_BEGIN(FACES_B
, "B,STRONG")
135 TAG_HANDLER_CONSTR(FACES_B
) { }
137 TAG_HANDLER_PROC(tag
)
139 int bold
= m_WParser
->GetFontBold();
141 m_WParser
->SetFontBold(true);
142 m_WParser
->GetContainer()->InsertCell(
143 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
147 m_WParser
->SetFontBold(bold
);
148 m_WParser
->GetContainer()->InsertCell(
149 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
153 TAG_HANDLER_END(FACES_B
)
158 TAG_HANDLER_BEGIN(FACES_I
, "I,EM,CITE,ADDRESS")
159 TAG_HANDLER_CONSTR(FACES_I
) { }
161 TAG_HANDLER_PROC(tag
)
163 int italic
= m_WParser
->GetFontItalic();
165 m_WParser
->SetFontItalic(true);
166 m_WParser
->GetContainer()->InsertCell(
167 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
171 m_WParser
->SetFontItalic(italic
);
172 m_WParser
->GetContainer()->InsertCell(
173 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
177 TAG_HANDLER_END(FACES_I
)
182 TAG_HANDLER_BEGIN(FACES_TT
, "TT,CODE,KBD,SAMP")
183 TAG_HANDLER_CONSTR(FACES_TT
) { }
185 TAG_HANDLER_PROC(tag
)
187 int fixed
= m_WParser
->GetFontFixed();
189 m_WParser
->SetFontFixed(true);
190 m_WParser
->GetContainer()->InsertCell(
191 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
195 m_WParser
->SetFontFixed(fixed
);
196 m_WParser
->GetContainer()->InsertCell(
197 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
201 TAG_HANDLER_END(FACES_TT
)
207 TAG_HANDLER_BEGIN(Hx
, "H1,H2,H3,H4,H5,H6")
208 TAG_HANDLER_CONSTR(Hx
) { }
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
->GetFirstChild())
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")
285 TAG_HANDLER_CONSTR(BIGSMALL
) { }
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
)