]>
git.saurik.com Git - wxWidgets.git/blob - src/html/m_fonts.cpp
6ad8550e1b527e8765d0d3f62e1a91a182c96536
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"
27 #include "wx/html/forcelnk.h"
28 #include "wx/html/m_templ.h"
30 FORCE_LINK_ME(m_fonts
)
33 TAG_HANDLER_BEGIN(FONT
, "FONT")
37 wxColour oldclr
= m_WParser
-> GetActualColor();
38 int oldsize
= m_WParser
-> GetFontSize();
40 if (tag
.HasParam(wxT("COLOR"))) {
41 unsigned long tmp
= 0;
43 if (tag
.ScanParam(wxT("COLOR"), wxT("#%lX"), &tmp
) == 1) {
44 clr
= wxColour((tmp
& 0xFF0000) >> 16 , (tmp
& 0x00FF00) >> 8, (tmp
& 0x0000FF));
45 m_WParser
-> SetActualColor(clr
);
46 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlColourCell(clr
));
50 if (tag
.HasParam(wxT("SIZE"))) {
52 wxChar c
= tag
.GetParam(wxT("SIZE"))[0];
53 if (tag
.ScanParam(wxT("SIZE"), wxT("%li"), &tmp
) == 1) {
54 if (c
== '+' || c
== '-')
55 m_WParser
-> SetFontSize(oldsize
+tmp
);
57 m_WParser
-> SetFontSize(tmp
);
58 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
64 if (oldclr
!= m_WParser
-> GetActualColor()) {
65 m_WParser
-> SetActualColor(oldclr
);
66 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlColourCell(oldclr
));
68 if (oldsize
!= m_WParser
-> GetFontSize()) {
69 m_WParser
-> SetFontSize(oldsize
);
70 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
78 TAG_HANDLER_BEGIN(FACES_U
, "U")
82 int underlined
= m_WParser
-> GetFontUnderlined();
84 m_WParser
-> SetFontUnderlined(TRUE
);
85 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
89 m_WParser
-> SetFontUnderlined(underlined
);
90 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
94 TAG_HANDLER_END(FACES_U
)
99 TAG_HANDLER_BEGIN(FACES_B
, "B,STRONG")
101 TAG_HANDLER_PROC(tag
)
103 int bold
= m_WParser
-> GetFontBold();
105 m_WParser
-> SetFontBold(TRUE
);
106 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
110 m_WParser
-> SetFontBold(bold
);
111 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
115 TAG_HANDLER_END(FACES_B
)
120 TAG_HANDLER_BEGIN(FACES_I
, "I,EM,CITE")
122 TAG_HANDLER_PROC(tag
)
124 int italic
= m_WParser
-> GetFontItalic();
126 m_WParser
-> SetFontItalic(TRUE
);
127 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
131 m_WParser
-> SetFontItalic(italic
);
132 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
136 TAG_HANDLER_END(FACES_I
)
141 TAG_HANDLER_BEGIN(FACES_TT
, "TT")
143 TAG_HANDLER_PROC(tag
)
145 int fixed
= m_WParser
-> GetFontFixed();
147 m_WParser
-> SetFontFixed(TRUE
);
148 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
152 m_WParser
-> SetFontFixed(fixed
);
153 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
157 TAG_HANDLER_END(FACES_TT
)
163 TAG_HANDLER_BEGIN(Hx
, "H1,H2,H3,H4,H5,H6")
165 TAG_HANDLER_PROC(tag
)
167 int old_size
, old_b
, old_i
, old_u
, old_f
, old_al
;
168 wxHtmlContainerCell
*c
;
170 old_size
= m_WParser
-> GetFontSize();
171 old_b
= m_WParser
-> GetFontBold();
172 old_i
= m_WParser
-> GetFontItalic();
173 old_u
= m_WParser
-> GetFontUnderlined();
174 old_f
= m_WParser
-> GetFontFixed();
175 old_al
= m_WParser
-> GetAlign();
177 m_WParser
-> SetFontBold(TRUE
);
178 m_WParser
-> SetFontItalic(FALSE
);
179 m_WParser
-> SetFontUnderlined(FALSE
);
180 m_WParser
-> SetFontFixed(FALSE
);
182 if (tag
.GetName() == "H1")
183 m_WParser
-> SetFontSize(7);
184 else if (tag
.GetName() == "H2")
185 m_WParser
-> SetFontSize(6);
186 else if (tag
.GetName() == "H3")
187 m_WParser
-> SetFontSize(5);
188 else if (tag
.GetName() == "H4") {
189 m_WParser
-> SetFontSize(5);
190 m_WParser
-> SetFontItalic(TRUE
);
191 m_WParser
-> SetFontBold(FALSE
);
193 else if (tag
.GetName() == "H5")
194 m_WParser
-> SetFontSize(4);
195 else if (tag
.GetName() == "H6") {
196 m_WParser
-> SetFontSize(4);
197 m_WParser
-> SetFontItalic(TRUE
);
198 m_WParser
-> SetFontBold(FALSE
);
201 c
= m_WParser
-> GetContainer();
202 if (c
-> GetFirstCell()) {
203 m_WParser
-> CloseContainer();
204 m_WParser
-> OpenContainer();
205 c
= m_WParser
-> GetContainer();
207 c
= m_WParser
-> GetContainer();
210 c
-> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
211 c
-> SetIndent(m_WParser
-> GetCharHeight(), wxHTML_INDENT_TOP
);
212 m_WParser
-> SetAlign(c
-> GetAlignHor());
216 m_WParser
-> SetFontSize(old_size
);
217 m_WParser
-> SetFontBold(old_b
);
218 m_WParser
-> SetFontItalic(old_i
);
219 m_WParser
-> SetFontUnderlined(old_u
);
220 m_WParser
-> SetFontFixed(old_f
);
221 m_WParser
-> SetAlign(old_al
);
223 m_WParser
-> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
224 m_WParser
-> CloseContainer();
225 m_WParser
-> OpenContainer();
226 c
= m_WParser
-> GetContainer();
227 c
-> SetIndent(m_WParser
-> GetCharHeight(), wxHTML_INDENT_TOP
);
237 TAGS_MODULE_BEGIN(Fonts
)
239 TAGS_MODULE_ADD(FONT
)
240 TAGS_MODULE_ADD(FACES_U
)
241 TAGS_MODULE_ADD(FACES_I
)
242 TAGS_MODULE_ADD(FACES_B
)
243 TAGS_MODULE_ADD(FACES_TT
)
246 TAGS_MODULE_END(Fonts
)