]> git.saurik.com Git - wxWidgets.git/blob - src/html/mod_fonts.cpp
wxHtmlTag::ScanParam now returns value
[wxWidgets.git] / src / html / mod_fonts.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: mod_fonts.cpp
3 // Purpose: wxHtml module for fonts & colors of fonts
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 #ifdef __GNUG__
10 #pragma implementation
11 #endif
12
13 #include <wx/wxprec.h>
14
15 #include "wx/defs.h"
16 #if wxUSE_HTML
17
18 #ifdef __BORDLANDC__
19 #pragma hdrstop
20 #endif
21
22 #ifndef WXPRECOMP
23 #include <wx/wx.h>
24 #endif
25
26 #include <wx/html/forcelink.h>
27 #include <wx/html/mod_templ.h>
28
29 FORCE_LINK_ME(mod_fonts)
30
31
32 TAG_HANDLER_BEGIN(FONT, "FONT")
33
34 TAG_HANDLER_PROC(tag)
35 {
36 wxColour oldclr = m_WParser -> GetActualColor();
37 int oldsize = m_WParser -> GetFontSize();
38
39 if (tag.HasParam("COLOR")) {
40 unsigned long tmp = 0;
41 wxColour clr;
42 if (tag.ScanParam("COLOR", "#%lX", &tmp) == 1) {
43 clr = wxColour((tmp & 0xFF0000) >> 16 , (tmp & 0x00FF00) >> 8, (tmp & 0x0000FF));
44 m_WParser -> SetActualColor(clr);
45 m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(clr));
46 }
47 }
48
49 if (tag.HasParam("SIZE")) {
50 long tmp = 0;
51 if (tag.ScanParam("SIZE", "%li", &tmp) == 1) {
52 m_WParser -> SetFontSize(oldsize+tmp);
53 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
54 }
55 }
56
57 ParseInner(tag);
58
59 if (oldclr != m_WParser -> GetActualColor()) {
60 m_WParser -> SetActualColor(oldclr);
61 m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(oldclr));
62 }
63 if (oldsize != m_WParser -> GetFontSize()) {
64 m_WParser -> SetFontSize(oldsize);
65 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
66 }
67 return TRUE;
68 }
69
70 TAG_HANDLER_END(FONT)
71
72
73 TAG_HANDLER_BEGIN(FACES, "U,I,B,TT")
74
75 TAG_HANDLER_PROC(tag)
76 {
77 int fixed = m_WParser -> GetFontFixed(),
78 italic = m_WParser -> GetFontItalic(),
79 underlined = m_WParser -> GetFontUnderlined(),
80 bold = m_WParser -> GetFontBold();
81
82 if (tag.GetName() == "U")
83 m_WParser -> SetFontUnderlined(TRUE);
84 else if (tag.GetName() == "B")
85 m_WParser -> SetFontBold(TRUE);
86 else if (tag.GetName() == "I")
87 m_WParser -> SetFontItalic(TRUE);
88 else
89 m_WParser -> SetFontFixed(TRUE);
90 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
91
92 ParseInner(tag);
93
94 m_WParser -> SetFontUnderlined(underlined);
95 m_WParser -> SetFontBold(bold);
96 m_WParser -> SetFontItalic(italic);
97 m_WParser -> SetFontFixed(fixed);
98 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
99 return TRUE;
100 }
101
102 TAG_HANDLER_END(FACES)
103
104
105
106
107
108 TAG_HANDLER_BEGIN(Hx, "H1,H2,H3,H4,H5,H6")
109
110 TAG_HANDLER_PROC(tag)
111 {
112 int old_size, old_b, old_i, old_u, old_f, old_al;
113 wxHtmlContainerCell *c;
114
115 old_size = m_WParser -> GetFontSize();
116 old_b = m_WParser -> GetFontBold();
117 old_i = m_WParser -> GetFontItalic();
118 old_u = m_WParser -> GetFontUnderlined();
119 old_f = m_WParser -> GetFontFixed();
120 old_al = m_WParser -> GetAlign();
121
122 m_WParser -> SetFontBold(TRUE);
123 m_WParser -> SetFontItalic(FALSE);
124 m_WParser -> SetFontUnderlined(FALSE);
125 m_WParser -> SetFontFixed(FALSE);
126
127 if (tag.GetName() == "H1")
128 m_WParser -> SetFontSize(+4);
129 else if (tag.GetName() == "H2")
130 m_WParser -> SetFontSize(+3);
131 else if (tag.GetName() == "H3")
132 m_WParser -> SetFontSize(+2);
133 else if (tag.GetName() == "H4") {
134 m_WParser -> SetFontSize(+2);
135 m_WParser -> SetFontItalic(TRUE);
136 m_WParser -> SetFontBold(FALSE);
137 }
138 else if (tag.GetName() == "H5")
139 m_WParser -> SetFontSize(+1);
140 else if (tag.GetName() == "H6") {
141 m_WParser -> SetFontSize(+1);
142 m_WParser -> SetFontItalic(TRUE);
143 m_WParser -> SetFontBold(FALSE);
144 }
145
146 c = m_WParser -> GetContainer();
147 if (c -> GetFirstCell()) {
148 m_WParser -> CloseContainer();
149 m_WParser -> OpenContainer();
150 c = m_WParser -> GetContainer();
151 }
152 c = m_WParser -> GetContainer();
153
154 c -> SetAlign(tag);
155 c -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
156 c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_TOP);
157 m_WParser -> SetAlign(c -> GetAlignHor());
158
159 ParseInner(tag);
160
161 m_WParser -> SetFontSize(old_size);
162 m_WParser -> SetFontBold(old_b);
163 m_WParser -> SetFontItalic(old_i);
164 m_WParser -> SetFontUnderlined(old_u);
165 m_WParser -> SetFontFixed(old_f);
166 m_WParser -> SetAlign(old_al);
167
168 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
169 m_WParser -> CloseContainer();
170 m_WParser -> OpenContainer();
171 c = m_WParser -> GetContainer();
172 c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_TOP);
173
174 return TRUE;
175 }
176
177 TAG_HANDLER_END(Hx)
178
179
180
181
182 TAGS_MODULE_BEGIN(Fonts)
183
184 TAGS_MODULE_ADD(FONT)
185 TAGS_MODULE_ADD(FACES)
186 TAGS_MODULE_ADD(Hx)
187
188 TAGS_MODULE_END(Fonts)
189
190
191 #endif