]>
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
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
16 #if wxUSE_HTML && wxUSE_STREAMS
21 #include "wx/html/forcelnk.h"
22 #include "wx/html/m_templ.h"
23 #include "wx/fontenum.h"
24 #include "wx/tokenzr.h"
26 FORCE_LINK_ME(m_fonts
)
29 TAG_HANDLER_BEGIN(FONT
, "FONT" )
32 wxArrayString m_Faces
;
34 TAG_HANDLER_CONSTR(FONT
) { }
38 wxColour oldclr
= m_WParser
->GetActualColor();
39 int oldsize
= m_WParser
->GetFontSize();
40 wxString oldface
= m_WParser
->GetFontFace();
42 if (tag
.HasParam(wxT("COLOR")))
45 if (tag
.GetParamAsColour(wxT("COLOR"), &clr
))
47 m_WParser
->SetActualColor(clr
);
48 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(clr
));
52 if (tag
.HasParam(wxT("SIZE")))
55 wxChar c
= tag
.GetParam(wxT("SIZE")).GetChar(0);
56 if (tag
.GetParamAsInt(wxT("SIZE"), &tmp
))
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)
72 enu
.EnumerateFacenames();
73 const wxArrayString
*faces
= enu
.GetFacenames();
77 wxStringTokenizer
tk(tag
.GetParam(wxT("FACE")), wxT(","));
80 while (tk
.HasMoreTokens())
82 if ((index
= m_Faces
.Index(tk
.GetNextToken(), false)) != wxNOT_FOUND
)
84 m_WParser
->SetFontFace(m_Faces
[index
]);
85 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
93 if (oldface
!= m_WParser
->GetFontFace())
95 m_WParser
->SetFontFace(oldface
);
96 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
98 if (oldsize
!= m_WParser
->GetFontSize())
100 m_WParser
->SetFontSize(oldsize
);
101 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
103 if (oldclr
!= m_WParser
->GetActualColor())
105 m_WParser
->SetActualColor(oldclr
);
106 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr
));
111 TAG_HANDLER_END(FONT
)
114 TAG_HANDLER_BEGIN(FACES_U
, "U,STRIKE")
116 TAG_HANDLER_CONSTR(FACES_U
) { }
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")
140 TAG_HANDLER_CONSTR(FACES_B
) { }
142 TAG_HANDLER_PROC(tag
)
144 int bold
= m_WParser
->GetFontBold();
146 m_WParser
->SetFontBold(true);
147 m_WParser
->GetContainer()->InsertCell(
148 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
152 m_WParser
->SetFontBold(bold
);
153 m_WParser
->GetContainer()->InsertCell(
154 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
158 TAG_HANDLER_END(FACES_B
)
163 TAG_HANDLER_BEGIN(FACES_I
, "I,EM,CITE,ADDRESS")
164 TAG_HANDLER_CONSTR(FACES_I
) { }
166 TAG_HANDLER_PROC(tag
)
168 int italic
= m_WParser
->GetFontItalic();
170 m_WParser
->SetFontItalic(true);
171 m_WParser
->GetContainer()->InsertCell(
172 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
176 m_WParser
->SetFontItalic(italic
);
177 m_WParser
->GetContainer()->InsertCell(
178 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
182 TAG_HANDLER_END(FACES_I
)
187 TAG_HANDLER_BEGIN(FACES_TT
, "TT,CODE,KBD,SAMP")
188 TAG_HANDLER_CONSTR(FACES_TT
) { }
190 TAG_HANDLER_PROC(tag
)
192 int fixed
= m_WParser
->GetFontFixed();
194 m_WParser
->SetFontFixed(true);
195 m_WParser
->GetContainer()->InsertCell(
196 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
200 m_WParser
->SetFontFixed(fixed
);
201 m_WParser
->GetContainer()->InsertCell(
202 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
206 TAG_HANDLER_END(FACES_TT
)
212 TAG_HANDLER_BEGIN(Hx
, "H1,H2,H3,H4,H5,H6")
213 TAG_HANDLER_CONSTR(Hx
) { }
215 TAG_HANDLER_PROC(tag
)
217 int old_size
, old_b
, old_i
, old_u
, old_f
, old_al
;
218 wxHtmlContainerCell
*c
;
220 old_size
= m_WParser
->GetFontSize();
221 old_b
= m_WParser
->GetFontBold();
222 old_i
= m_WParser
->GetFontItalic();
223 old_u
= m_WParser
->GetFontUnderlined();
224 old_f
= m_WParser
->GetFontFixed();
225 old_al
= m_WParser
->GetAlign();
227 m_WParser
->SetFontBold(true);
228 m_WParser
->SetFontItalic(false);
229 m_WParser
->SetFontUnderlined(false);
230 m_WParser
->SetFontFixed(false);
232 if (tag
.GetName() == wxT("H1"))
233 m_WParser
->SetFontSize(7);
234 else if (tag
.GetName() == wxT("H2"))
235 m_WParser
->SetFontSize(6);
236 else if (tag
.GetName() == wxT("H3"))
237 m_WParser
->SetFontSize(5);
238 else if (tag
.GetName() == wxT("H4"))
240 m_WParser
->SetFontSize(5);
241 m_WParser
->SetFontItalic(true);
242 m_WParser
->SetFontBold(false);
244 else if (tag
.GetName() == wxT("H5"))
245 m_WParser
->SetFontSize(4);
246 else if (tag
.GetName() == wxT("H6"))
248 m_WParser
->SetFontSize(4);
249 m_WParser
->SetFontItalic(true);
250 m_WParser
->SetFontBold(false);
253 c
= m_WParser
->GetContainer();
254 if (c
->GetFirstChild())
256 m_WParser
->CloseContainer();
257 m_WParser
->OpenContainer();
258 c
= m_WParser
->GetContainer();
260 c
= m_WParser
->GetContainer();
263 c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
264 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
265 m_WParser
->SetAlign(c
->GetAlignHor());
269 m_WParser
->SetFontSize(old_size
);
270 m_WParser
->SetFontBold(old_b
);
271 m_WParser
->SetFontItalic(old_i
);
272 m_WParser
->SetFontUnderlined(old_u
);
273 m_WParser
->SetFontFixed(old_f
);
274 m_WParser
->SetAlign(old_al
);
276 m_WParser
->GetContainer()->InsertCell(
277 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
278 m_WParser
->CloseContainer();
279 m_WParser
->OpenContainer();
280 c
= m_WParser
->GetContainer();
281 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
289 TAG_HANDLER_BEGIN(BIGSMALL
, "BIG,SMALL")
290 TAG_HANDLER_CONSTR(BIGSMALL
) { }
292 TAG_HANDLER_PROC(tag
)
294 int oldsize
= m_WParser
->GetFontSize();
295 int sz
= (tag
.GetName() == wxT("BIG")) ? +1 : -1;
297 m_WParser
->SetFontSize(sz
);
298 m_WParser
->GetContainer()->InsertCell(
299 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
303 m_WParser
->SetFontSize(oldsize
);
304 m_WParser
->GetContainer()->InsertCell(
305 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
309 TAG_HANDLER_END(BIGSMALL
)
314 TAGS_MODULE_BEGIN(Fonts
)
316 TAGS_MODULE_ADD(FONT
)
317 TAGS_MODULE_ADD(FACES_U
)
318 TAGS_MODULE_ADD(FACES_I
)
319 TAGS_MODULE_ADD(FACES_B
)
320 TAGS_MODULE_ADD(FACES_TT
)
322 TAGS_MODULE_ADD(BIGSMALL
)
324 TAGS_MODULE_END(Fonts
)