]> git.saurik.com Git - wxWidgets.git/blob - src/html/mod_fonts.cpp
started adding swigged sources
[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 unsigned long tmp;
37 wxColour oldclr = m_WParser -> GetActualColor();
38 int oldsize = m_WParser -> GetFontSize();
39
40 if (tag.HasParam("COLOR")) {
41 wxColour clr;
42 tag.ScanParam("COLOR", "#%lX", &tmp);
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 if (tag.HasParam("SIZE")) {
49 tag.ScanParam("SIZE", "%li", &tmp);
50 m_WParser -> SetFontSize(tmp);
51 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
52 }
53
54 ParseInner(tag);
55
56 if (oldclr != m_WParser -> GetActualColor()) {
57 m_WParser -> SetActualColor(oldclr);
58 m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(oldclr));
59 }
60 if (oldsize != m_WParser -> GetFontSize()) {
61 m_WParser -> SetFontSize(oldsize);
62 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
63 }
64 return TRUE;
65 }
66
67 TAG_HANDLER_END(FONT)
68
69
70 TAG_HANDLER_BEGIN(FACES, "U,I,B,TT")
71
72 TAG_HANDLER_PROC(tag)
73 {
74 int fixed = m_WParser -> GetFontFixed(),
75 italic = m_WParser -> GetFontItalic(),
76 underlined = m_WParser -> GetFontUnderlined(),
77 bold = m_WParser -> GetFontBold();
78
79 if (tag.GetName() == "U")
80 m_WParser -> SetFontUnderlined(TRUE);
81 else if (tag.GetName() == "B")
82 m_WParser -> SetFontBold(TRUE);
83 else if (tag.GetName() == "I")
84 m_WParser -> SetFontItalic(TRUE);
85 else
86 m_WParser -> SetFontFixed(TRUE);
87 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
88
89 ParseInner(tag);
90
91 m_WParser -> SetFontUnderlined(underlined);
92 m_WParser -> SetFontBold(bold);
93 m_WParser -> SetFontItalic(italic);
94 m_WParser -> SetFontFixed(fixed);
95 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
96 return TRUE;
97 }
98
99 TAG_HANDLER_END(FACES)
100
101
102
103
104
105 TAG_HANDLER_BEGIN(Hx, "H1,H2,H3,H4,H5,H6")
106
107 TAG_HANDLER_PROC(tag)
108 {
109 int old_size, old_b, old_i, old_u, old_f, old_al;
110 wxHtmlContainerCell *c;
111
112 old_size = m_WParser -> GetFontSize();
113 old_b = m_WParser -> GetFontBold();
114 old_i = m_WParser -> GetFontItalic();
115 old_u = m_WParser -> GetFontUnderlined();
116 old_f = m_WParser -> GetFontFixed();
117 old_al = m_WParser -> GetAlign();
118
119 m_WParser -> SetFontBold(TRUE);
120 m_WParser -> SetFontItalic(FALSE);
121 m_WParser -> SetFontUnderlined(FALSE);
122 m_WParser -> SetFontFixed(FALSE);
123
124 if (tag.GetName() == "H1")
125 m_WParser -> SetFontSize(+4);
126 else if (tag.GetName() == "H2")
127 m_WParser -> SetFontSize(+3);
128 else if (tag.GetName() == "H3")
129 m_WParser -> SetFontSize(+2);
130 else if (tag.GetName() == "H4") {
131 m_WParser -> SetFontSize(+2);
132 m_WParser -> SetFontItalic(TRUE);
133 m_WParser -> SetFontBold(FALSE);
134 }
135 else if (tag.GetName() == "H5")
136 m_WParser -> SetFontSize(+1);
137 else if (tag.GetName() == "H6") {
138 m_WParser -> SetFontSize(+1);
139 m_WParser -> SetFontItalic(TRUE);
140 m_WParser -> SetFontBold(FALSE);
141 }
142
143 c = m_WParser -> GetContainer();
144 if (c -> GetFirstCell()) {
145 m_WParser -> CloseContainer();
146 m_WParser -> OpenContainer();
147 c = m_WParser -> GetContainer();
148 }
149 c = m_WParser -> GetContainer();
150
151 c -> SetAlign(tag);
152 c -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
153 c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_TOP);
154 m_WParser -> SetAlign(c -> GetAlignHor());
155
156 ParseInner(tag);
157
158 m_WParser -> SetFontSize(old_size);
159 m_WParser -> SetFontBold(old_b);
160 m_WParser -> SetFontItalic(old_i);
161 m_WParser -> SetFontUnderlined(old_u);
162 m_WParser -> SetFontFixed(old_f);
163 m_WParser -> SetAlign(old_al);
164
165 m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
166 m_WParser -> CloseContainer();
167 m_WParser -> OpenContainer();
168 c = m_WParser -> GetContainer();
169 c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_TOP);
170
171 return TRUE;
172 }
173
174 TAG_HANDLER_END(Hx)
175
176
177
178
179 TAGS_MODULE_BEGIN(Fonts)
180
181 TAGS_MODULE_ADD(FONT)
182 TAGS_MODULE_ADD(FACES)
183 TAGS_MODULE_ADD(Hx)
184
185 TAGS_MODULE_END(Fonts)
186
187
188 #endif