]> git.saurik.com Git - wxWidgets.git/blame - src/html/m_fonts.cpp
*** empty log message ***
[wxWidgets.git] / src / html / m_fonts.cpp
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
ef01b72f 2// Name: m_fonts.cpp
5526e819
VS
3// Purpose: wxHtml module for fonts & colors of fonts
4// Author: Vaclav Slavik
69941f05 5// RCS-ID: $Id$
5526e819
VS
6// Copyright: (c) 1999 Vaclav Slavik
7// Licence: wxWindows Licence
8/////////////////////////////////////////////////////////////////////////////
9
3364ab79
RS
10#ifdef __GNUG__
11#pragma implementation
12#endif
13
3096bd2f 14#include "wx/wxprec.h"
5526e819
VS
15
16#include "wx/defs.h"
17#if wxUSE_HTML
18
3364ab79
RS
19#ifdef __BORDLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WXPRECOMP
3096bd2f 24#include "wx/wx.h"
3364ab79
RS
25#endif
26
69941f05
VS
27#include "wx/html/forcelnk.h"
28#include "wx/html/m_templ.h"
f1ad10f3
VS
29#include "wx/fontenum.h"
30#include "wx/tokenzr.h"
5526e819 31
ef01b72f 32FORCE_LINK_ME(m_fonts)
5526e819
VS
33
34
9b64e798 35TAG_HANDLER_BEGIN(FONT, "FONT")
5526e819 36
f1ad10f3
VS
37 TAG_HANDLER_VARS
38 wxSortedArrayString m_Faces;
39
5526e819
VS
40 TAG_HANDLER_PROC(tag)
41 {
5526e819
VS
42 wxColour oldclr = m_WParser -> GetActualColor();
43 int oldsize = m_WParser -> GetFontSize();
f1ad10f3 44 wxString oldface = m_WParser -> GetFontFace();
5526e819 45
66a77a74 46 if (tag.HasParam(wxT("COLOR"))) {
e7ee65ed 47 unsigned long tmp = 0;
5526e819 48 wxColour clr;
66a77a74 49 if (tag.ScanParam(wxT("COLOR"), wxT("#%lX"), &tmp) == 1) {
72aa4a98
VS
50 clr = wxColour((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF));
51 m_WParser -> SetActualColor(clr);
52 m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(clr));
e7ee65ed 53 }
5526e819
VS
54 }
55
66a77a74 56 if (tag.HasParam(wxT("SIZE"))) {
e7ee65ed 57 long tmp = 0;
84e5f539 58 wxChar c = tag.GetParam(wxT("SIZE"))[(unsigned int) 0];
66a77a74 59 if (tag.ScanParam(wxT("SIZE"), wxT("%li"), &tmp) == 1) {
2463329c
VS
60 if (c == '+' || c == '-')
61 m_WParser -> SetFontSize(oldsize+tmp);
62 else
63 m_WParser -> SetFontSize(tmp);
72aa4a98 64 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
e7ee65ed 65 }
5526e819 66 }
f1ad10f3
VS
67
68 if (tag.HasParam(wxT("FACE"))) {
69 if (m_Faces.GetCount() == 0) {
70 wxFontEnumerator enu;
71 enu.EnumerateFacenames();
72 m_Faces = *enu.GetFacenames();
73 }
74 wxStringTokenizer tk(tag.GetParam(wxT("FACE")), ",");
75 int index;
76
77 while (tk.HasMoreTokens())
78 if ((index = m_Faces.Index(tk.GetNextToken())) != wxNOT_FOUND) {
79 m_WParser -> SetFontFace(m_Faces[index]);
80 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
81 break;
82 }
83 }
5526e819
VS
84
85 ParseInner(tag);
86
f1ad10f3
VS
87 if (oldface != m_WParser -> GetFontFace()) {
88 m_WParser -> SetFontFace(oldface);
89 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
90 }
5526e819
VS
91 if (oldsize != m_WParser -> GetFontSize()) {
92 m_WParser -> SetFontSize(oldsize);
93 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
f1ad10f3
VS
94 }
95 if (oldclr != m_WParser -> GetActualColor()) {
96 m_WParser -> SetActualColor(oldclr);
97 m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(oldclr));
5526e819
VS
98 }
99 return TRUE;
100 }
101
102TAG_HANDLER_END(FONT)
103
104
e7ee65ed 105TAG_HANDLER_BEGIN(FACES_U, "U,STRIKE")
5526e819
VS
106
107 TAG_HANDLER_PROC(tag)
108 {
ef01b72f
VS
109 int underlined = m_WParser -> GetFontUnderlined();
110
111 m_WParser -> SetFontUnderlined(TRUE);
5526e819
VS
112 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
113
114 ParseInner(tag);
115
116 m_WParser -> SetFontUnderlined(underlined);
ef01b72f
VS
117 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
118 return TRUE;
119 }
120
121TAG_HANDLER_END(FACES_U)
122
123
124
125
126TAG_HANDLER_BEGIN(FACES_B, "B,STRONG")
127
128 TAG_HANDLER_PROC(tag)
129 {
130 int bold = m_WParser -> GetFontBold();
131
132 m_WParser -> SetFontBold(TRUE);
133 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
134
135 ParseInner(tag);
136
5526e819 137 m_WParser -> SetFontBold(bold);
ef01b72f
VS
138 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
139 return TRUE;
140 }
141
142TAG_HANDLER_END(FACES_B)
143
144
145
146
e7ee65ed 147TAG_HANDLER_BEGIN(FACES_I, "I,EM,CITE,ADDRESS")
ef01b72f
VS
148
149 TAG_HANDLER_PROC(tag)
150 {
151 int italic = m_WParser -> GetFontItalic();
152
153 m_WParser -> SetFontItalic(TRUE);
154 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
155
156 ParseInner(tag);
157
5526e819 158 m_WParser -> SetFontItalic(italic);
ef01b72f
VS
159 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
160 return TRUE;
161 }
162
163TAG_HANDLER_END(FACES_I)
164
165
166
167
e7ee65ed 168TAG_HANDLER_BEGIN(FACES_TT, "TT,CODE,KBD,SAMP")
ef01b72f
VS
169
170 TAG_HANDLER_PROC(tag)
171 {
172 int fixed = m_WParser -> GetFontFixed();
173
174 m_WParser -> SetFontFixed(TRUE);
175 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
176
177 ParseInner(tag);
178
5526e819
VS
179 m_WParser -> SetFontFixed(fixed);
180 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
181 return TRUE;
182 }
183
ef01b72f 184TAG_HANDLER_END(FACES_TT)
5526e819
VS
185
186
187
188
189
190TAG_HANDLER_BEGIN(Hx, "H1,H2,H3,H4,H5,H6")
191
192 TAG_HANDLER_PROC(tag)
193 {
194 int old_size, old_b, old_i, old_u, old_f, old_al;
195 wxHtmlContainerCell *c;
196
197 old_size = m_WParser -> GetFontSize();
198 old_b = m_WParser -> GetFontBold();
199 old_i = m_WParser -> GetFontItalic();
200 old_u = m_WParser -> GetFontUnderlined();
201 old_f = m_WParser -> GetFontFixed();
202 old_al = m_WParser -> GetAlign();
203
204 m_WParser -> SetFontBold(TRUE);
205 m_WParser -> SetFontItalic(FALSE);
206 m_WParser -> SetFontUnderlined(FALSE);
207 m_WParser -> SetFontFixed(FALSE);
208
e7ee65ed 209 if (tag.GetName() == wxT("H1"))
2463329c 210 m_WParser -> SetFontSize(7);
0413cec5 211 else if (tag.GetName() == wxT("H2"))
2463329c 212 m_WParser -> SetFontSize(6);
0413cec5 213 else if (tag.GetName() == wxT("H3"))
2463329c 214 m_WParser -> SetFontSize(5);
0413cec5 215 else if (tag.GetName() == wxT("H4")) {
2463329c 216 m_WParser -> SetFontSize(5);
5526e819
VS
217 m_WParser -> SetFontItalic(TRUE);
218 m_WParser -> SetFontBold(FALSE);
219 }
0413cec5 220 else if (tag.GetName() == wxT("H5"))
2463329c 221 m_WParser -> SetFontSize(4);
0413cec5 222 else if (tag.GetName() == wxT("H6")) {
2463329c 223 m_WParser -> SetFontSize(4);
5526e819
VS
224 m_WParser -> SetFontItalic(TRUE);
225 m_WParser -> SetFontBold(FALSE);
226 }
227
228 c = m_WParser -> GetContainer();
229 if (c -> GetFirstCell()) {
230 m_WParser -> CloseContainer();
231 m_WParser -> OpenContainer();
232 c = m_WParser -> GetContainer();
233 }
234 c = m_WParser -> GetContainer();
235
236 c -> SetAlign(tag);
237 c -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
efba2b89 238 c -> SetIndent(m_WParser -> GetCharHeight(), wxHTML_INDENT_TOP);
5526e819
VS
239 m_WParser -> SetAlign(c -> GetAlignHor());
240
241 ParseInner(tag);
242
243 m_WParser -> SetFontSize(old_size);
244 m_WParser -> SetFontBold(old_b);
245 m_WParser -> SetFontItalic(old_i);
246 m_WParser -> SetFontUnderlined(old_u);
247 m_WParser -> SetFontFixed(old_f);
248 m_WParser -> SetAlign(old_al);
249
250 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
251 m_WParser -> CloseContainer();
252 m_WParser -> OpenContainer();
253 c = m_WParser -> GetContainer();
efba2b89 254 c -> SetIndent(m_WParser -> GetCharHeight(), wxHTML_INDENT_TOP);
5526e819
VS
255
256 return TRUE;
257 }
258
259TAG_HANDLER_END(Hx)
260
261
e7ee65ed
VS
262TAG_HANDLER_BEGIN(BIGSMALL, "BIG,SMALL")
263
264 TAG_HANDLER_PROC(tag)
265 {
266 int oldsize = m_WParser -> GetFontSize();
267 int sz = (tag.GetName() == wxT("BIG")) ? +1 : -1;
268
269 m_WParser -> SetFontSize(sz);
270 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
271
272 ParseInner(tag);
273
274 m_WParser -> SetFontSize(oldsize);
275 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
276 return TRUE;
277 }
278
279TAG_HANDLER_END(BIGSMALL)
280
281
5526e819
VS
282
283
284TAGS_MODULE_BEGIN(Fonts)
285
286 TAGS_MODULE_ADD(FONT)
ef01b72f
VS
287 TAGS_MODULE_ADD(FACES_U)
288 TAGS_MODULE_ADD(FACES_I)
289 TAGS_MODULE_ADD(FACES_B)
290 TAGS_MODULE_ADD(FACES_TT)
5526e819 291 TAGS_MODULE_ADD(Hx)
e7ee65ed 292 TAGS_MODULE_ADD(BIGSMALL)
5526e819
VS
293
294TAGS_MODULE_END(Fonts)
295
296
3364ab79 297#endif