]>
git.saurik.com Git - wxWidgets.git/blob - src/html/m_fonts.cpp
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
26 #include "wx/html/forcelnk.h"
27 #include "wx/html/m_templ.h"
28 #include "wx/fontenum.h"
29 #include "wx/tokenzr.h"
31 FORCE_LINK_ME(m_fonts
)
34 TAG_HANDLER_BEGIN(FONT
, "FONT" )
37 wxArrayString m_Faces
;
39 TAG_HANDLER_CONSTR(FONT
) { }
43 wxColour oldclr
= m_WParser
->GetActualColor();
44 int oldsize
= m_WParser
->GetFontSize();
45 wxString oldface
= m_WParser
->GetFontFace();
47 if (tag
.HasParam(wxT("COLOR")))
50 if (tag
.GetParamAsColour(wxT("COLOR"), &clr
))
52 m_WParser
->SetActualColor(clr
);
53 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(clr
));
57 if (tag
.HasParam(wxT("SIZE")))
60 wxChar c
= tag
.GetParam(wxT("SIZE")).GetChar(0);
61 if (tag
.GetParamAsInt(wxT("SIZE"), &tmp
))
63 if (c
== wxT('+') || c
== wxT('-'))
64 m_WParser
->SetFontSize(oldsize
+tmp
);
66 m_WParser
->SetFontSize(tmp
);
67 m_WParser
->GetContainer()->InsertCell(
68 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")), wxT(","));
83 while (tk
.HasMoreTokens())
85 if ((index
= m_Faces
.Index(tk
.GetNextToken(), FALSE
)) != 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_CONSTR(FACES_U
) { }
121 TAG_HANDLER_PROC(tag
)
123 int underlined
= m_WParser
->GetFontUnderlined();
125 m_WParser
->SetFontUnderlined(TRUE
);
126 m_WParser
->GetContainer()->InsertCell(
127 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
131 m_WParser
->SetFontUnderlined(underlined
);
132 m_WParser
->GetContainer()->InsertCell(
133 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
137 TAG_HANDLER_END(FACES_U
)
142 TAG_HANDLER_BEGIN(FACES_B
, "B,STRONG")
143 TAG_HANDLER_CONSTR(FACES_B
) { }
145 TAG_HANDLER_PROC(tag
)
147 int bold
= m_WParser
->GetFontBold();
149 m_WParser
->SetFontBold(TRUE
);
150 m_WParser
->GetContainer()->InsertCell(
151 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
155 m_WParser
->SetFontBold(bold
);
156 m_WParser
->GetContainer()->InsertCell(
157 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
161 TAG_HANDLER_END(FACES_B
)
166 TAG_HANDLER_BEGIN(FACES_I
, "I,EM,CITE,ADDRESS")
167 TAG_HANDLER_CONSTR(FACES_I
) { }
169 TAG_HANDLER_PROC(tag
)
171 int italic
= m_WParser
->GetFontItalic();
173 m_WParser
->SetFontItalic(TRUE
);
174 m_WParser
->GetContainer()->InsertCell(
175 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
179 m_WParser
->SetFontItalic(italic
);
180 m_WParser
->GetContainer()->InsertCell(
181 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
185 TAG_HANDLER_END(FACES_I
)
190 TAG_HANDLER_BEGIN(FACES_TT
, "TT,CODE,KBD,SAMP")
191 TAG_HANDLER_CONSTR(FACES_TT
) { }
193 TAG_HANDLER_PROC(tag
)
195 int fixed
= m_WParser
->GetFontFixed();
197 m_WParser
->SetFontFixed(TRUE
);
198 m_WParser
->GetContainer()->InsertCell(
199 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
203 m_WParser
->SetFontFixed(fixed
);
204 m_WParser
->GetContainer()->InsertCell(
205 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
209 TAG_HANDLER_END(FACES_TT
)
215 TAG_HANDLER_BEGIN(Hx
, "H1,H2,H3,H4,H5,H6")
216 TAG_HANDLER_CONSTR(Hx
) { }
218 TAG_HANDLER_PROC(tag
)
220 int old_size
, old_b
, old_i
, old_u
, old_f
, old_al
;
221 wxHtmlContainerCell
*c
;
223 old_size
= m_WParser
->GetFontSize();
224 old_b
= m_WParser
->GetFontBold();
225 old_i
= m_WParser
->GetFontItalic();
226 old_u
= m_WParser
->GetFontUnderlined();
227 old_f
= m_WParser
->GetFontFixed();
228 old_al
= m_WParser
->GetAlign();
230 m_WParser
->SetFontBold(TRUE
);
231 m_WParser
->SetFontItalic(FALSE
);
232 m_WParser
->SetFontUnderlined(FALSE
);
233 m_WParser
->SetFontFixed(FALSE
);
235 if (tag
.GetName() == wxT("H1"))
236 m_WParser
->SetFontSize(7);
237 else if (tag
.GetName() == wxT("H2"))
238 m_WParser
->SetFontSize(6);
239 else if (tag
.GetName() == wxT("H3"))
240 m_WParser
->SetFontSize(5);
241 else if (tag
.GetName() == wxT("H4"))
243 m_WParser
->SetFontSize(5);
244 m_WParser
->SetFontItalic(TRUE
);
245 m_WParser
->SetFontBold(FALSE
);
247 else if (tag
.GetName() == wxT("H5"))
248 m_WParser
->SetFontSize(4);
249 else if (tag
.GetName() == wxT("H6"))
251 m_WParser
->SetFontSize(4);
252 m_WParser
->SetFontItalic(TRUE
);
253 m_WParser
->SetFontBold(FALSE
);
256 c
= m_WParser
->GetContainer();
257 if (c
->GetFirstChild())
259 m_WParser
->CloseContainer();
260 m_WParser
->OpenContainer();
261 c
= m_WParser
->GetContainer();
263 c
= m_WParser
->GetContainer();
266 c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
267 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
268 m_WParser
->SetAlign(c
->GetAlignHor());
272 m_WParser
->SetFontSize(old_size
);
273 m_WParser
->SetFontBold(old_b
);
274 m_WParser
->SetFontItalic(old_i
);
275 m_WParser
->SetFontUnderlined(old_u
);
276 m_WParser
->SetFontFixed(old_f
);
277 m_WParser
->SetAlign(old_al
);
279 m_WParser
->GetContainer()->InsertCell(
280 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
281 m_WParser
->CloseContainer();
282 m_WParser
->OpenContainer();
283 c
= m_WParser
->GetContainer();
284 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
292 TAG_HANDLER_BEGIN(BIGSMALL
, "BIG,SMALL")
293 TAG_HANDLER_CONSTR(BIGSMALL
) { }
295 TAG_HANDLER_PROC(tag
)
297 int oldsize
= m_WParser
->GetFontSize();
298 int sz
= (tag
.GetName() == wxT("BIG")) ? +1 : -1;
300 m_WParser
->SetFontSize(sz
);
301 m_WParser
->GetContainer()->InsertCell(
302 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
306 m_WParser
->SetFontSize(oldsize
);
307 m_WParser
->GetContainer()->InsertCell(
308 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
312 TAG_HANDLER_END(BIGSMALL
)
317 TAGS_MODULE_BEGIN(Fonts
)
319 TAGS_MODULE_ADD(FONT
)
320 TAGS_MODULE_ADD(FACES_U
)
321 TAGS_MODULE_ADD(FACES_I
)
322 TAGS_MODULE_ADD(FACES_B
)
323 TAGS_MODULE_ADD(FACES_TT
)
325 TAGS_MODULE_ADD(BIGSMALL
)
327 TAGS_MODULE_END(Fonts
)