]>
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 /////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
13 #if wxUSE_HTML && wxUSE_STREAMS
22 #include "wx/html/forcelnk.h"
23 #include "wx/html/m_templ.h"
24 #include "wx/fontenum.h"
25 #include "wx/tokenzr.h"
27 FORCE_LINK_ME(m_fonts
)
30 TAG_HANDLER_BEGIN(FONT
, "FONT" )
33 wxArrayString m_Faces
;
35 TAG_HANDLER_CONSTR(FONT
) { }
39 wxColour oldclr
= m_WParser
->GetActualColor();
40 int oldsize
= m_WParser
->GetFontSize();
41 wxString oldface
= m_WParser
->GetFontFace();
43 if (tag
.HasParam(wxT("COLOR")))
46 if (tag
.GetParamAsColour(wxT("COLOR"), &clr
))
48 m_WParser
->SetActualColor(clr
);
49 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(clr
));
53 if (tag
.HasParam(wxT("SIZE")))
56 wxChar c
= tag
.GetParam(wxT("SIZE")).GetChar(0);
57 if (tag
.GetParamAsInt(wxT("SIZE"), &tmp
))
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)
73 enu
.EnumerateFacenames();
74 const wxArrayString
*faces
= enu
.GetFacenames();
78 wxStringTokenizer
tk(tag
.GetParam(wxT("FACE")), wxT(","));
81 while (tk
.HasMoreTokens())
83 if ((index
= m_Faces
.Index(tk
.GetNextToken(), false)) != wxNOT_FOUND
)
85 m_WParser
->SetFontFace(m_Faces
[index
]);
86 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
94 if (oldface
!= m_WParser
->GetFontFace())
96 m_WParser
->SetFontFace(oldface
);
97 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
99 if (oldsize
!= m_WParser
->GetFontSize())
101 m_WParser
->SetFontSize(oldsize
);
102 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
104 if (oldclr
!= m_WParser
->GetActualColor())
106 m_WParser
->SetActualColor(oldclr
);
107 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr
));
112 TAG_HANDLER_END(FONT
)
115 TAG_HANDLER_BEGIN(FACES_U
, "U,STRIKE")
117 TAG_HANDLER_CONSTR(FACES_U
) { }
119 TAG_HANDLER_PROC(tag
)
121 int underlined
= m_WParser
->GetFontUnderlined();
123 m_WParser
->SetFontUnderlined(true);
124 m_WParser
->GetContainer()->InsertCell(
125 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
129 m_WParser
->SetFontUnderlined(underlined
);
130 m_WParser
->GetContainer()->InsertCell(
131 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
135 TAG_HANDLER_END(FACES_U
)
140 TAG_HANDLER_BEGIN(FACES_B
, "B,STRONG")
141 TAG_HANDLER_CONSTR(FACES_B
) { }
143 TAG_HANDLER_PROC(tag
)
145 int bold
= m_WParser
->GetFontBold();
147 m_WParser
->SetFontBold(true);
148 m_WParser
->GetContainer()->InsertCell(
149 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
153 m_WParser
->SetFontBold(bold
);
154 m_WParser
->GetContainer()->InsertCell(
155 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
159 TAG_HANDLER_END(FACES_B
)
164 TAG_HANDLER_BEGIN(FACES_I
, "I,EM,CITE,ADDRESS")
165 TAG_HANDLER_CONSTR(FACES_I
) { }
167 TAG_HANDLER_PROC(tag
)
169 int italic
= m_WParser
->GetFontItalic();
171 m_WParser
->SetFontItalic(true);
172 m_WParser
->GetContainer()->InsertCell(
173 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
177 m_WParser
->SetFontItalic(italic
);
178 m_WParser
->GetContainer()->InsertCell(
179 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
183 TAG_HANDLER_END(FACES_I
)
188 TAG_HANDLER_BEGIN(FACES_TT
, "TT,CODE,KBD,SAMP")
189 TAG_HANDLER_CONSTR(FACES_TT
) { }
191 TAG_HANDLER_PROC(tag
)
193 int fixed
= m_WParser
->GetFontFixed();
195 m_WParser
->SetFontFixed(true);
196 m_WParser
->GetContainer()->InsertCell(
197 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
201 m_WParser
->SetFontFixed(fixed
);
202 m_WParser
->GetContainer()->InsertCell(
203 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
207 TAG_HANDLER_END(FACES_TT
)
213 TAG_HANDLER_BEGIN(Hx
, "H1,H2,H3,H4,H5,H6")
214 TAG_HANDLER_CONSTR(Hx
) { }
216 TAG_HANDLER_PROC(tag
)
218 int old_size
, old_b
, old_i
, old_u
, old_f
, old_al
;
219 wxHtmlContainerCell
*c
;
221 old_size
= m_WParser
->GetFontSize();
222 old_b
= m_WParser
->GetFontBold();
223 old_i
= m_WParser
->GetFontItalic();
224 old_u
= m_WParser
->GetFontUnderlined();
225 old_f
= m_WParser
->GetFontFixed();
226 old_al
= m_WParser
->GetAlign();
228 m_WParser
->SetFontBold(true);
229 m_WParser
->SetFontItalic(false);
230 m_WParser
->SetFontUnderlined(false);
231 m_WParser
->SetFontFixed(false);
233 if (tag
.GetName() == wxT("H1"))
234 m_WParser
->SetFontSize(7);
235 else if (tag
.GetName() == wxT("H2"))
236 m_WParser
->SetFontSize(6);
237 else if (tag
.GetName() == wxT("H3"))
238 m_WParser
->SetFontSize(5);
239 else if (tag
.GetName() == wxT("H4"))
241 m_WParser
->SetFontSize(5);
242 m_WParser
->SetFontItalic(true);
243 m_WParser
->SetFontBold(false);
245 else if (tag
.GetName() == wxT("H5"))
246 m_WParser
->SetFontSize(4);
247 else if (tag
.GetName() == wxT("H6"))
249 m_WParser
->SetFontSize(4);
250 m_WParser
->SetFontItalic(true);
251 m_WParser
->SetFontBold(false);
254 c
= m_WParser
->GetContainer();
255 if (c
->GetFirstChild())
257 m_WParser
->CloseContainer();
258 m_WParser
->OpenContainer();
259 c
= m_WParser
->GetContainer();
261 c
= m_WParser
->GetContainer();
264 c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
265 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
266 m_WParser
->SetAlign(c
->GetAlignHor());
270 m_WParser
->SetFontSize(old_size
);
271 m_WParser
->SetFontBold(old_b
);
272 m_WParser
->SetFontItalic(old_i
);
273 m_WParser
->SetFontUnderlined(old_u
);
274 m_WParser
->SetFontFixed(old_f
);
275 m_WParser
->SetAlign(old_al
);
277 m_WParser
->GetContainer()->InsertCell(
278 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
279 m_WParser
->CloseContainer();
280 m_WParser
->OpenContainer();
281 c
= m_WParser
->GetContainer();
282 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
290 TAG_HANDLER_BEGIN(BIGSMALL
, "BIG,SMALL")
291 TAG_HANDLER_CONSTR(BIGSMALL
) { }
293 TAG_HANDLER_PROC(tag
)
295 int oldsize
= m_WParser
->GetFontSize();
296 int sz
= (tag
.GetName() == wxT("BIG")) ? +1 : -1;
298 m_WParser
->SetFontSize(sz
);
299 m_WParser
->GetContainer()->InsertCell(
300 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
304 m_WParser
->SetFontSize(oldsize
);
305 m_WParser
->GetContainer()->InsertCell(
306 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
310 TAG_HANDLER_END(BIGSMALL
)
315 TAGS_MODULE_BEGIN(Fonts
)
317 TAGS_MODULE_ADD(FONT
)
318 TAGS_MODULE_ADD(FACES_U
)
319 TAGS_MODULE_ADD(FACES_I
)
320 TAGS_MODULE_ADD(FACES_B
)
321 TAGS_MODULE_ADD(FACES_TT
)
323 TAGS_MODULE_ADD(BIGSMALL
)
325 TAGS_MODULE_END(Fonts
)