]>
git.saurik.com Git - wxWidgets.git/blob - src/html/m_fonts.cpp
1a0aefdd18703c90067bbdd134f0adf69f209662
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 const wxArrayString
*faces
= enu
.GetFacenames();
82 wxStringTokenizer
tk(tag
.GetParam(wxT("FACE")), wxT(","));
85 while (tk
.HasMoreTokens())
87 if ((index
= m_Faces
.Index(tk
.GetNextToken(), FALSE
)) != wxNOT_FOUND
)
89 m_WParser
->SetFontFace(m_Faces
[index
]);
90 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
98 if (oldface
!= m_WParser
->GetFontFace())
100 m_WParser
->SetFontFace(oldface
);
101 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
103 if (oldsize
!= m_WParser
->GetFontSize())
105 m_WParser
->SetFontSize(oldsize
);
106 m_WParser
->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
108 if (oldclr
!= m_WParser
->GetActualColor())
110 m_WParser
->SetActualColor(oldclr
);
111 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr
));
116 TAG_HANDLER_END(FONT
)
119 TAG_HANDLER_BEGIN(FACES_U
, "U,STRIKE")
121 TAG_HANDLER_CONSTR(FACES_U
) { }
123 TAG_HANDLER_PROC(tag
)
125 int underlined
= m_WParser
->GetFontUnderlined();
127 m_WParser
->SetFontUnderlined(TRUE
);
128 m_WParser
->GetContainer()->InsertCell(
129 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
133 m_WParser
->SetFontUnderlined(underlined
);
134 m_WParser
->GetContainer()->InsertCell(
135 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
139 TAG_HANDLER_END(FACES_U
)
144 TAG_HANDLER_BEGIN(FACES_B
, "B,STRONG")
145 TAG_HANDLER_CONSTR(FACES_B
) { }
147 TAG_HANDLER_PROC(tag
)
149 int bold
= m_WParser
->GetFontBold();
151 m_WParser
->SetFontBold(TRUE
);
152 m_WParser
->GetContainer()->InsertCell(
153 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
157 m_WParser
->SetFontBold(bold
);
158 m_WParser
->GetContainer()->InsertCell(
159 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
163 TAG_HANDLER_END(FACES_B
)
168 TAG_HANDLER_BEGIN(FACES_I
, "I,EM,CITE,ADDRESS")
169 TAG_HANDLER_CONSTR(FACES_I
) { }
171 TAG_HANDLER_PROC(tag
)
173 int italic
= m_WParser
->GetFontItalic();
175 m_WParser
->SetFontItalic(TRUE
);
176 m_WParser
->GetContainer()->InsertCell(
177 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
181 m_WParser
->SetFontItalic(italic
);
182 m_WParser
->GetContainer()->InsertCell(
183 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
187 TAG_HANDLER_END(FACES_I
)
192 TAG_HANDLER_BEGIN(FACES_TT
, "TT,CODE,KBD,SAMP")
193 TAG_HANDLER_CONSTR(FACES_TT
) { }
195 TAG_HANDLER_PROC(tag
)
197 int fixed
= m_WParser
->GetFontFixed();
199 m_WParser
->SetFontFixed(TRUE
);
200 m_WParser
->GetContainer()->InsertCell(
201 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
205 m_WParser
->SetFontFixed(fixed
);
206 m_WParser
->GetContainer()->InsertCell(
207 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
211 TAG_HANDLER_END(FACES_TT
)
217 TAG_HANDLER_BEGIN(Hx
, "H1,H2,H3,H4,H5,H6")
218 TAG_HANDLER_CONSTR(Hx
) { }
220 TAG_HANDLER_PROC(tag
)
222 int old_size
, old_b
, old_i
, old_u
, old_f
, old_al
;
223 wxHtmlContainerCell
*c
;
225 old_size
= m_WParser
->GetFontSize();
226 old_b
= m_WParser
->GetFontBold();
227 old_i
= m_WParser
->GetFontItalic();
228 old_u
= m_WParser
->GetFontUnderlined();
229 old_f
= m_WParser
->GetFontFixed();
230 old_al
= m_WParser
->GetAlign();
232 m_WParser
->SetFontBold(TRUE
);
233 m_WParser
->SetFontItalic(FALSE
);
234 m_WParser
->SetFontUnderlined(FALSE
);
235 m_WParser
->SetFontFixed(FALSE
);
237 if (tag
.GetName() == wxT("H1"))
238 m_WParser
->SetFontSize(7);
239 else if (tag
.GetName() == wxT("H2"))
240 m_WParser
->SetFontSize(6);
241 else if (tag
.GetName() == wxT("H3"))
242 m_WParser
->SetFontSize(5);
243 else if (tag
.GetName() == wxT("H4"))
245 m_WParser
->SetFontSize(5);
246 m_WParser
->SetFontItalic(TRUE
);
247 m_WParser
->SetFontBold(FALSE
);
249 else if (tag
.GetName() == wxT("H5"))
250 m_WParser
->SetFontSize(4);
251 else if (tag
.GetName() == wxT("H6"))
253 m_WParser
->SetFontSize(4);
254 m_WParser
->SetFontItalic(TRUE
);
255 m_WParser
->SetFontBold(FALSE
);
258 c
= m_WParser
->GetContainer();
259 if (c
->GetFirstChild())
261 m_WParser
->CloseContainer();
262 m_WParser
->OpenContainer();
263 c
= m_WParser
->GetContainer();
265 c
= m_WParser
->GetContainer();
268 c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
269 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
270 m_WParser
->SetAlign(c
->GetAlignHor());
274 m_WParser
->SetFontSize(old_size
);
275 m_WParser
->SetFontBold(old_b
);
276 m_WParser
->SetFontItalic(old_i
);
277 m_WParser
->SetFontUnderlined(old_u
);
278 m_WParser
->SetFontFixed(old_f
);
279 m_WParser
->SetAlign(old_al
);
281 m_WParser
->GetContainer()->InsertCell(
282 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
283 m_WParser
->CloseContainer();
284 m_WParser
->OpenContainer();
285 c
= m_WParser
->GetContainer();
286 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
294 TAG_HANDLER_BEGIN(BIGSMALL
, "BIG,SMALL")
295 TAG_HANDLER_CONSTR(BIGSMALL
) { }
297 TAG_HANDLER_PROC(tag
)
299 int oldsize
= m_WParser
->GetFontSize();
300 int sz
= (tag
.GetName() == wxT("BIG")) ? +1 : -1;
302 m_WParser
->SetFontSize(sz
);
303 m_WParser
->GetContainer()->InsertCell(
304 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
308 m_WParser
->SetFontSize(oldsize
);
309 m_WParser
->GetContainer()->InsertCell(
310 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
314 TAG_HANDLER_END(BIGSMALL
)
319 TAGS_MODULE_BEGIN(Fonts
)
321 TAGS_MODULE_ADD(FONT
)
322 TAGS_MODULE_ADD(FACES_U
)
323 TAGS_MODULE_ADD(FACES_I
)
324 TAGS_MODULE_ADD(FACES_B
)
325 TAGS_MODULE_ADD(FACES_TT
)
327 TAGS_MODULE_ADD(BIGSMALL
)
329 TAGS_MODULE_END(Fonts
)