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