]>
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();
43 if (tag
.GetParamAsColour(wxT("COLOR"), &clr
))
45 m_WParser
->SetActualColor(clr
);
46 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(clr
));
53 if (tag
.GetParamAsString(wxT("SIZE"), &sizeStr
) && sizeStr
.ToLong(&tmp
))
55 wxChar c
= sizeStr
[0];
56 if (c
== wxT('+') || c
== wxT('-'))
57 m_WParser
->SetFontSize(oldsize
+tmp
);
59 m_WParser
->SetFontSize(tmp
);
60 m_WParser
->GetContainer()->InsertCell(
61 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
66 if (tag
.GetParamAsString(wxT("FACE"), &faces
))
68 if (m_Faces
.GetCount() == 0)
69 m_Faces
= wxFontEnumerator::GetFacenames();
71 wxStringTokenizer
tk(faces
, wxT(","));
74 while (tk
.HasMoreTokens())
76 if ((index
= m_Faces
.Index(tk
.GetNextToken(), false)) != wxNOT_FOUND
)
78 m_WParser
->SetFontFace(m_Faces
[index
]);
79 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
87 if (oldface
!= m_WParser
->GetFontFace())
89 m_WParser
->SetFontFace(oldface
);
90 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
92 if (oldsize
!= m_WParser
->GetFontSize())
94 m_WParser
->SetFontSize(oldsize
);
95 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
97 if (oldclr
!= m_WParser
->GetActualColor())
99 m_WParser
->SetActualColor(oldclr
);
100 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr
));
105 TAG_HANDLER_END(FONT
)
108 TAG_HANDLER_BEGIN(FACES_U
, "U,STRIKE,DEL")
110 TAG_HANDLER_CONSTR(FACES_U
) { }
112 TAG_HANDLER_PROC(tag
)
114 int underlined
= m_WParser
->GetFontUnderlined();
116 m_WParser
->SetFontUnderlined(true);
117 m_WParser
->GetContainer()->InsertCell(
118 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
122 m_WParser
->SetFontUnderlined(underlined
);
123 m_WParser
->GetContainer()->InsertCell(
124 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
128 TAG_HANDLER_END(FACES_U
)
133 TAG_HANDLER_BEGIN(FACES_B
, "B,STRONG")
134 TAG_HANDLER_CONSTR(FACES_B
) { }
136 TAG_HANDLER_PROC(tag
)
138 int bold
= m_WParser
->GetFontBold();
140 m_WParser
->SetFontBold(true);
141 m_WParser
->GetContainer()->InsertCell(
142 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
146 m_WParser
->SetFontBold(bold
);
147 m_WParser
->GetContainer()->InsertCell(
148 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
152 TAG_HANDLER_END(FACES_B
)
157 TAG_HANDLER_BEGIN(FACES_I
, "I,EM,CITE,ADDRESS")
158 TAG_HANDLER_CONSTR(FACES_I
) { }
160 TAG_HANDLER_PROC(tag
)
162 int italic
= m_WParser
->GetFontItalic();
164 m_WParser
->SetFontItalic(true);
165 m_WParser
->GetContainer()->InsertCell(
166 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
170 m_WParser
->SetFontItalic(italic
);
171 m_WParser
->GetContainer()->InsertCell(
172 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
176 TAG_HANDLER_END(FACES_I
)
181 TAG_HANDLER_BEGIN(FACES_TT
, "TT,CODE,KBD,SAMP")
182 TAG_HANDLER_CONSTR(FACES_TT
) { }
184 TAG_HANDLER_PROC(tag
)
186 int fixed
= m_WParser
->GetFontFixed();
188 m_WParser
->SetFontFixed(true);
189 m_WParser
->GetContainer()->InsertCell(
190 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
194 m_WParser
->SetFontFixed(fixed
);
195 m_WParser
->GetContainer()->InsertCell(
196 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
200 TAG_HANDLER_END(FACES_TT
)
206 TAG_HANDLER_BEGIN(Hx
, "H1,H2,H3,H4,H5,H6")
207 TAG_HANDLER_CONSTR(Hx
) { }
209 TAG_HANDLER_PROC(tag
)
211 int old_size
, old_b
, old_i
, old_u
, old_f
, old_al
;
212 wxHtmlContainerCell
*c
;
214 old_size
= m_WParser
->GetFontSize();
215 old_b
= m_WParser
->GetFontBold();
216 old_i
= m_WParser
->GetFontItalic();
217 old_u
= m_WParser
->GetFontUnderlined();
218 old_f
= m_WParser
->GetFontFixed();
219 old_al
= m_WParser
->GetAlign();
221 m_WParser
->SetFontBold(true);
222 m_WParser
->SetFontItalic(false);
223 m_WParser
->SetFontUnderlined(false);
224 m_WParser
->SetFontFixed(false);
226 if (tag
.GetName() == wxT("H1"))
227 m_WParser
->SetFontSize(7);
228 else if (tag
.GetName() == wxT("H2"))
229 m_WParser
->SetFontSize(6);
230 else if (tag
.GetName() == wxT("H3"))
231 m_WParser
->SetFontSize(5);
232 else if (tag
.GetName() == wxT("H4"))
234 m_WParser
->SetFontSize(5);
235 m_WParser
->SetFontItalic(true);
236 m_WParser
->SetFontBold(false);
238 else if (tag
.GetName() == wxT("H5"))
239 m_WParser
->SetFontSize(4);
240 else if (tag
.GetName() == wxT("H6"))
242 m_WParser
->SetFontSize(4);
243 m_WParser
->SetFontItalic(true);
244 m_WParser
->SetFontBold(false);
247 c
= m_WParser
->GetContainer();
248 if (c
->GetFirstChild())
250 m_WParser
->CloseContainer();
251 m_WParser
->OpenContainer();
252 c
= m_WParser
->GetContainer();
254 c
= m_WParser
->GetContainer();
257 c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
258 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
259 m_WParser
->SetAlign(c
->GetAlignHor());
263 m_WParser
->SetFontSize(old_size
);
264 m_WParser
->SetFontBold(old_b
);
265 m_WParser
->SetFontItalic(old_i
);
266 m_WParser
->SetFontUnderlined(old_u
);
267 m_WParser
->SetFontFixed(old_f
);
268 m_WParser
->SetAlign(old_al
);
270 m_WParser
->GetContainer()->InsertCell(
271 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
272 m_WParser
->CloseContainer();
273 m_WParser
->OpenContainer();
274 c
= m_WParser
->GetContainer();
275 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
283 TAG_HANDLER_BEGIN(BIGSMALL
, "BIG,SMALL")
284 TAG_HANDLER_CONSTR(BIGSMALL
) { }
286 TAG_HANDLER_PROC(tag
)
288 int oldsize
= m_WParser
->GetFontSize();
289 int sz
= (tag
.GetName() == wxT("BIG")) ? +1 : -1;
291 m_WParser
->SetFontSize(sz
);
292 m_WParser
->GetContainer()->InsertCell(
293 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
297 m_WParser
->SetFontSize(oldsize
);
298 m_WParser
->GetContainer()->InsertCell(
299 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
303 TAG_HANDLER_END(BIGSMALL
)
308 TAGS_MODULE_BEGIN(Fonts
)
310 TAGS_MODULE_ADD(FONT
)
311 TAGS_MODULE_ADD(FACES_U
)
312 TAGS_MODULE_ADD(FACES_I
)
313 TAGS_MODULE_ADD(FACES_B
)
314 TAGS_MODULE_ADD(FACES_TT
)
316 TAGS_MODULE_ADD(BIGSMALL
)
318 TAGS_MODULE_END(Fonts
)