]>
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 const wxString sizeStr
= tag
.GetParam(wxT("SIZE"));
56 if (sizeStr
.ToLong(&tmp
))
58 wxChar c
= sizeStr
[0];
59 if (c
== wxT('+') || c
== wxT('-'))
60 m_WParser
->SetFontSize(oldsize
+tmp
);
62 m_WParser
->SetFontSize(tmp
);
63 m_WParser
->GetContainer()->InsertCell(
64 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
68 if (tag
.HasParam(wxT("FACE")))
70 if (m_Faces
.GetCount() == 0)
71 m_Faces
= wxFontEnumerator::GetFacenames();
73 wxStringTokenizer
tk(tag
.GetParam(wxT("FACE")), wxT(","));
76 while (tk
.HasMoreTokens())
78 if ((index
= m_Faces
.Index(tk
.GetNextToken(), false)) != wxNOT_FOUND
)
80 m_WParser
->SetFontFace(m_Faces
[index
]);
81 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
89 if (oldface
!= m_WParser
->GetFontFace())
91 m_WParser
->SetFontFace(oldface
);
92 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
94 if (oldsize
!= m_WParser
->GetFontSize())
96 m_WParser
->SetFontSize(oldsize
);
97 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
99 if (oldclr
!= m_WParser
->GetActualColor())
101 m_WParser
->SetActualColor(oldclr
);
102 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr
));
107 TAG_HANDLER_END(FONT
)
110 TAG_HANDLER_BEGIN(FACES_U
, "U,STRIKE,DEL")
112 TAG_HANDLER_CONSTR(FACES_U
) { }
114 TAG_HANDLER_PROC(tag
)
116 int underlined
= m_WParser
->GetFontUnderlined();
118 m_WParser
->SetFontUnderlined(true);
119 m_WParser
->GetContainer()->InsertCell(
120 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
124 m_WParser
->SetFontUnderlined(underlined
);
125 m_WParser
->GetContainer()->InsertCell(
126 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
130 TAG_HANDLER_END(FACES_U
)
135 TAG_HANDLER_BEGIN(FACES_B
, "B,STRONG")
136 TAG_HANDLER_CONSTR(FACES_B
) { }
138 TAG_HANDLER_PROC(tag
)
140 int bold
= m_WParser
->GetFontBold();
142 m_WParser
->SetFontBold(true);
143 m_WParser
->GetContainer()->InsertCell(
144 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
148 m_WParser
->SetFontBold(bold
);
149 m_WParser
->GetContainer()->InsertCell(
150 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
154 TAG_HANDLER_END(FACES_B
)
159 TAG_HANDLER_BEGIN(FACES_I
, "I,EM,CITE,ADDRESS")
160 TAG_HANDLER_CONSTR(FACES_I
) { }
162 TAG_HANDLER_PROC(tag
)
164 int italic
= m_WParser
->GetFontItalic();
166 m_WParser
->SetFontItalic(true);
167 m_WParser
->GetContainer()->InsertCell(
168 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
172 m_WParser
->SetFontItalic(italic
);
173 m_WParser
->GetContainer()->InsertCell(
174 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
178 TAG_HANDLER_END(FACES_I
)
183 TAG_HANDLER_BEGIN(FACES_TT
, "TT,CODE,KBD,SAMP")
184 TAG_HANDLER_CONSTR(FACES_TT
) { }
186 TAG_HANDLER_PROC(tag
)
188 int fixed
= m_WParser
->GetFontFixed();
190 m_WParser
->SetFontFixed(true);
191 m_WParser
->GetContainer()->InsertCell(
192 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
196 m_WParser
->SetFontFixed(fixed
);
197 m_WParser
->GetContainer()->InsertCell(
198 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
202 TAG_HANDLER_END(FACES_TT
)
208 TAG_HANDLER_BEGIN(Hx
, "H1,H2,H3,H4,H5,H6")
209 TAG_HANDLER_CONSTR(Hx
) { }
211 TAG_HANDLER_PROC(tag
)
213 int old_size
, old_b
, old_i
, old_u
, old_f
, old_al
;
214 wxHtmlContainerCell
*c
;
216 old_size
= m_WParser
->GetFontSize();
217 old_b
= m_WParser
->GetFontBold();
218 old_i
= m_WParser
->GetFontItalic();
219 old_u
= m_WParser
->GetFontUnderlined();
220 old_f
= m_WParser
->GetFontFixed();
221 old_al
= m_WParser
->GetAlign();
223 m_WParser
->SetFontBold(true);
224 m_WParser
->SetFontItalic(false);
225 m_WParser
->SetFontUnderlined(false);
226 m_WParser
->SetFontFixed(false);
228 if (tag
.GetName() == wxT("H1"))
229 m_WParser
->SetFontSize(7);
230 else if (tag
.GetName() == wxT("H2"))
231 m_WParser
->SetFontSize(6);
232 else if (tag
.GetName() == wxT("H3"))
233 m_WParser
->SetFontSize(5);
234 else if (tag
.GetName() == wxT("H4"))
236 m_WParser
->SetFontSize(5);
237 m_WParser
->SetFontItalic(true);
238 m_WParser
->SetFontBold(false);
240 else if (tag
.GetName() == wxT("H5"))
241 m_WParser
->SetFontSize(4);
242 else if (tag
.GetName() == wxT("H6"))
244 m_WParser
->SetFontSize(4);
245 m_WParser
->SetFontItalic(true);
246 m_WParser
->SetFontBold(false);
249 c
= m_WParser
->GetContainer();
250 if (c
->GetFirstChild())
252 m_WParser
->CloseContainer();
253 m_WParser
->OpenContainer();
254 c
= m_WParser
->GetContainer();
256 c
= m_WParser
->GetContainer();
259 c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
260 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
261 m_WParser
->SetAlign(c
->GetAlignHor());
265 m_WParser
->SetFontSize(old_size
);
266 m_WParser
->SetFontBold(old_b
);
267 m_WParser
->SetFontItalic(old_i
);
268 m_WParser
->SetFontUnderlined(old_u
);
269 m_WParser
->SetFontFixed(old_f
);
270 m_WParser
->SetAlign(old_al
);
272 m_WParser
->GetContainer()->InsertCell(
273 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
274 m_WParser
->CloseContainer();
275 m_WParser
->OpenContainer();
276 c
= m_WParser
->GetContainer();
277 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
285 TAG_HANDLER_BEGIN(BIGSMALL
, "BIG,SMALL")
286 TAG_HANDLER_CONSTR(BIGSMALL
) { }
288 TAG_HANDLER_PROC(tag
)
290 int oldsize
= m_WParser
->GetFontSize();
291 int sz
= (tag
.GetName() == wxT("BIG")) ? +1 : -1;
293 m_WParser
->SetFontSize(sz
);
294 m_WParser
->GetContainer()->InsertCell(
295 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
299 m_WParser
->SetFontSize(oldsize
);
300 m_WParser
->GetContainer()->InsertCell(
301 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
305 TAG_HANDLER_END(BIGSMALL
)
310 TAGS_MODULE_BEGIN(Fonts
)
312 TAGS_MODULE_ADD(FONT
)
313 TAGS_MODULE_ADD(FACES_U
)
314 TAGS_MODULE_ADD(FACES_I
)
315 TAGS_MODULE_ADD(FACES_B
)
316 TAGS_MODULE_ADD(FACES_TT
)
318 TAGS_MODULE_ADD(BIGSMALL
)
320 TAGS_MODULE_END(Fonts
)