]> git.saurik.com Git - wxWidgets.git/blob - src/html/m_fonts.cpp
6ad8550e1b527e8765d0d3f62e1a91a182c96536
[wxWidgets.git] / src / html / m_fonts.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: m_fonts.cpp
3 // Purpose: wxHtml module for fonts & colors of fonts
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation
12 #endif
13
14 #include "wx/wxprec.h"
15
16 #include "wx/defs.h"
17 #if wxUSE_HTML
18
19 #ifdef __BORDLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WXPRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include "wx/html/forcelnk.h"
28 #include "wx/html/m_templ.h"
29
30 FORCE_LINK_ME(m_fonts)
31
32
33 TAG_HANDLER_BEGIN(FONT, "FONT")
34
35 TAG_HANDLER_PROC(tag)
36 {
37 wxColour oldclr = m_WParser -> GetActualColor();
38 int oldsize = m_WParser -> GetFontSize();
39
40 if (tag.HasParam(wxT("COLOR"))) {
41 unsigned long tmp = 0;
42 wxColour clr;
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));
47 }
48 }
49
50 if (tag.HasParam(wxT("SIZE"))) {
51 long tmp = 0;
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);
56 else
57 m_WParser -> SetFontSize(tmp);
58 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
59 }
60 }
61
62 ParseInner(tag);
63
64 if (oldclr != m_WParser -> GetActualColor()) {
65 m_WParser -> SetActualColor(oldclr);
66 m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(oldclr));
67 }
68 if (oldsize != m_WParser -> GetFontSize()) {
69 m_WParser -> SetFontSize(oldsize);
70 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
71 }
72 return TRUE;
73 }
74
75 TAG_HANDLER_END(FONT)
76
77
78 TAG_HANDLER_BEGIN(FACES_U, "U")
79
80 TAG_HANDLER_PROC(tag)
81 {
82 int underlined = m_WParser -> GetFontUnderlined();
83
84 m_WParser -> SetFontUnderlined(TRUE);
85 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
86
87 ParseInner(tag);
88
89 m_WParser -> SetFontUnderlined(underlined);
90 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
91 return TRUE;
92 }
93
94 TAG_HANDLER_END(FACES_U)
95
96
97
98
99 TAG_HANDLER_BEGIN(FACES_B, "B,STRONG")
100
101 TAG_HANDLER_PROC(tag)
102 {
103 int bold = m_WParser -> GetFontBold();
104
105 m_WParser -> SetFontBold(TRUE);
106 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
107
108 ParseInner(tag);
109
110 m_WParser -> SetFontBold(bold);
111 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
112 return TRUE;
113 }
114
115 TAG_HANDLER_END(FACES_B)
116
117
118
119
120 TAG_HANDLER_BEGIN(FACES_I, "I,EM,CITE")
121
122 TAG_HANDLER_PROC(tag)
123 {
124 int italic = m_WParser -> GetFontItalic();
125
126 m_WParser -> SetFontItalic(TRUE);
127 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
128
129 ParseInner(tag);
130
131 m_WParser -> SetFontItalic(italic);
132 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
133 return TRUE;
134 }
135
136 TAG_HANDLER_END(FACES_I)
137
138
139
140
141 TAG_HANDLER_BEGIN(FACES_TT, "TT")
142
143 TAG_HANDLER_PROC(tag)
144 {
145 int fixed = m_WParser -> GetFontFixed();
146
147 m_WParser -> SetFontFixed(TRUE);
148 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
149
150 ParseInner(tag);
151
152 m_WParser -> SetFontFixed(fixed);
153 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
154 return TRUE;
155 }
156
157 TAG_HANDLER_END(FACES_TT)
158
159
160
161
162
163 TAG_HANDLER_BEGIN(Hx, "H1,H2,H3,H4,H5,H6")
164
165 TAG_HANDLER_PROC(tag)
166 {
167 int old_size, old_b, old_i, old_u, old_f, old_al;
168 wxHtmlContainerCell *c;
169
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();
176
177 m_WParser -> SetFontBold(TRUE);
178 m_WParser -> SetFontItalic(FALSE);
179 m_WParser -> SetFontUnderlined(FALSE);
180 m_WParser -> SetFontFixed(FALSE);
181
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);
192 }
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);
199 }
200
201 c = m_WParser -> GetContainer();
202 if (c -> GetFirstCell()) {
203 m_WParser -> CloseContainer();
204 m_WParser -> OpenContainer();
205 c = m_WParser -> GetContainer();
206 }
207 c = m_WParser -> GetContainer();
208
209 c -> SetAlign(tag);
210 c -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
211 c -> SetIndent(m_WParser -> GetCharHeight(), wxHTML_INDENT_TOP);
212 m_WParser -> SetAlign(c -> GetAlignHor());
213
214 ParseInner(tag);
215
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);
222
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);
228
229 return TRUE;
230 }
231
232 TAG_HANDLER_END(Hx)
233
234
235
236
237 TAGS_MODULE_BEGIN(Fonts)
238
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)
244 TAGS_MODULE_ADD(Hx)
245
246 TAGS_MODULE_END(Fonts)
247
248
249 #endif