]>
Commit | Line | Data |
---|---|---|
5526e819 | 1 | ///////////////////////////////////////////////////////////////////////////// |
69941f05 | 2 | // Name: winpars.cpp |
5526e819 VS |
3 | // Purpose: wxHtmlParser class (generic parser) |
4 | // Author: Vaclav Slavik | |
69941f05 | 5 | // RCS-ID: $Id$ |
5526e819 | 6 | // Copyright: (c) 1999 Vaclav Slavik |
65571936 | 7 | // Licence: wxWindows licence |
5526e819 VS |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
3096bd2f | 10 | #include "wx/wxprec.h" |
5526e819 VS |
11 | |
12 | #include "wx/defs.h" | |
f6bcfd97 | 13 | #if wxUSE_HTML && wxUSE_STREAMS |
5526e819 | 14 | |
2b5f62a0 | 15 | #ifdef __BORLANDC__ |
5526e819 VS |
16 | #pragma hdrstop |
17 | #endif | |
18 | ||
19 | #ifndef WXPRECOMP | |
04dbb646 VZ |
20 | #include "wx/intl.h" |
21 | #include "wx/dc.h" | |
5526e819 VS |
22 | #endif |
23 | ||
69941f05 VS |
24 | #include "wx/html/htmldefs.h" |
25 | #include "wx/html/winpars.h" | |
26 | #include "wx/html/htmlwin.h" | |
b250d384 | 27 | #include "wx/fontmap.h" |
f3c82859 | 28 | #include "wx/log.h" |
3403ccd5 | 29 | #include "wx/settings.h" |
3ec372c8 | 30 | #include "wx/uri.h" |
5526e819 VS |
31 | |
32 | ||
33 | //----------------------------------------------------------------------------- | |
34 | // wxHtmlWinParser | |
35 | //----------------------------------------------------------------------------- | |
36 | ||
4f44ea36 | 37 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinParser, wxHtmlParser) |
5526e819 VS |
38 | |
39 | wxList wxHtmlWinParser::m_Modules; | |
40 | ||
04db5c3f | 41 | wxHtmlWinParser::wxHtmlWinParser(wxHtmlWindow *wnd) : wxHtmlParser() |
5526e819 | 42 | { |
211dfedd VS |
43 | m_tmpStrBuf = NULL; |
44 | m_tmpStrBufSize = 0; | |
5526e819 VS |
45 | m_Window = wnd; |
46 | m_Container = NULL; | |
47 | m_DC = NULL; | |
48 | m_CharHeight = m_CharWidth = 0; | |
d1da8872 | 49 | m_UseLink = false; |
2b5f62a0 | 50 | #if !wxUSE_UNICODE |
b250d384 | 51 | m_EncConv = NULL; |
2b5f62a0 VZ |
52 | m_InputEnc = wxFONTENCODING_ISO8859_1; |
53 | m_OutputEnc = wxFONTENCODING_DEFAULT; | |
54 | #endif | |
b6d93b26 | 55 | m_lastWordCell = NULL; |
5526e819 VS |
56 | |
57 | { | |
58 | int i, j, k, l, m; | |
59 | for (i = 0; i < 2; i++) | |
60 | for (j = 0; j < 2; j++) | |
61 | for (k = 0; k < 2; k++) | |
62 | for (l = 0; l < 2; l++) | |
3c8c8da2 | 63 | for (m = 0; m < 7; m++) |
e3c7fd79 | 64 | { |
5526e819 | 65 | m_FontsTable[i][j][k][l][m] = NULL; |
f1ad10f3 | 66 | m_FontsFacesTable[i][j][k][l][m] = wxEmptyString; |
2b5f62a0 | 67 | #if !wxUSE_UNICODE |
b250d384 | 68 | m_FontsEncTable[i][j][k][l][m] = wxFONTENCODING_DEFAULT; |
2b5f62a0 | 69 | #endif |
f1ad10f3 | 70 | } |
4eecf115 VS |
71 | |
72 | SetFonts(wxEmptyString, wxEmptyString, NULL); | |
5526e819 VS |
73 | } |
74 | ||
75 | // fill in wxHtmlParser's tables: | |
222ed1d6 | 76 | wxList::compatibility_iterator node = m_Modules.GetFirst(); |
3c8c8da2 | 77 | while (node) |
4f9297b0 VS |
78 | { |
79 | wxHtmlTagsModule *mod = (wxHtmlTagsModule*) node->GetData(); | |
80 | mod->FillHandlersTable(this); | |
81 | node = node->GetNext(); | |
5526e819 VS |
82 | } |
83 | } | |
84 | ||
b250d384 VS |
85 | wxHtmlWinParser::~wxHtmlWinParser() |
86 | { | |
87 | int i, j, k, l, m; | |
88 | ||
89 | for (i = 0; i < 2; i++) | |
90 | for (j = 0; j < 2; j++) | |
91 | for (k = 0; k < 2; k++) | |
92 | for (l = 0; l < 2; l++) | |
3c8c8da2 | 93 | for (m = 0; m < 7; m++) |
e3c7fd79 | 94 | { |
3c8c8da2 | 95 | if (m_FontsTable[i][j][k][l][m] != NULL) |
b250d384 VS |
96 | delete m_FontsTable[i][j][k][l][m]; |
97 | } | |
2b5f62a0 | 98 | #if !wxUSE_UNICODE |
211dfedd | 99 | delete m_EncConv; |
2b5f62a0 | 100 | #endif |
211dfedd | 101 | delete[] m_tmpStrBuf; |
b250d384 VS |
102 | } |
103 | ||
5526e819 VS |
104 | void wxHtmlWinParser::AddModule(wxHtmlTagsModule *module) |
105 | { | |
106 | m_Modules.Append(module); | |
107 | } | |
108 | ||
f6bcfd97 BP |
109 | void wxHtmlWinParser::RemoveModule(wxHtmlTagsModule *module) |
110 | { | |
111 | m_Modules.DeleteObject(module); | |
112 | } | |
113 | ||
fbfb8bcc | 114 | void wxHtmlWinParser::SetFonts(const wxString& normal_face, const wxString& fixed_face, |
4eecf115 | 115 | const int *sizes) |
5526e819 | 116 | { |
4eecf115 VS |
117 | static int default_sizes[7] = |
118 | { | |
119 | wxHTML_FONT_SIZE_1, | |
d1da8872 WS |
120 | wxHTML_FONT_SIZE_2, |
121 | wxHTML_FONT_SIZE_3, | |
122 | wxHTML_FONT_SIZE_4, | |
123 | wxHTML_FONT_SIZE_5, | |
124 | wxHTML_FONT_SIZE_6, | |
125 | wxHTML_FONT_SIZE_7 | |
4eecf115 | 126 | }; |
d1da8872 | 127 | |
4eecf115 VS |
128 | if (sizes == NULL) sizes = default_sizes; |
129 | ||
c9f56e70 VS |
130 | int i, j, k, l, m; |
131 | ||
132 | for (i = 0; i < 7; i++) m_FontsSizes[i] = sizes[i]; | |
5526e819 VS |
133 | m_FontFaceFixed = fixed_face; |
134 | m_FontFaceNormal = normal_face; | |
3c8c8da2 | 135 | |
2b5f62a0 | 136 | #if !wxUSE_UNICODE |
b250d384 | 137 | SetInputEncoding(m_InputEnc); |
2b5f62a0 | 138 | #endif |
c9f56e70 VS |
139 | |
140 | for (i = 0; i < 2; i++) | |
141 | for (j = 0; j < 2; j++) | |
142 | for (k = 0; k < 2; k++) | |
143 | for (l = 0; l < 2; l++) | |
144 | for (m = 0; m < 7; m++) { | |
3c8c8da2 | 145 | if (m_FontsTable[i][j][k][l][m] != NULL) |
e3c7fd79 | 146 | { |
c9f56e70 VS |
147 | delete m_FontsTable[i][j][k][l][m]; |
148 | m_FontsTable[i][j][k][l][m] = NULL; | |
149 | } | |
150 | } | |
5526e819 VS |
151 | } |
152 | ||
10e5c7ea VS |
153 | void wxHtmlWinParser::SetStandardFonts(int size, |
154 | const wxString& normal_face, | |
155 | const wxString& fixed_face) | |
7acd3625 | 156 | { |
10e5c7ea | 157 | wxFont defaultFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); |
d1da8872 | 158 | |
7acd3625 RD |
159 | int f_sizes[7]; |
160 | if (size == -1) | |
10e5c7ea | 161 | size = defaultFont.GetPointSize(); |
7acd3625 RD |
162 | |
163 | f_sizes[0] = int(size * 0.6); | |
164 | f_sizes[1] = int(size * 0.8); | |
165 | f_sizes[2] = size; | |
166 | f_sizes[3] = int(size * 1.2); | |
167 | f_sizes[4] = int(size * 1.4); | |
168 | f_sizes[5] = int(size * 1.6); | |
169 | f_sizes[6] = int(size * 1.8); | |
10e5c7ea | 170 | |
d1da8872 | 171 | wxString normal = normal_face.empty() ? |
10e5c7ea | 172 | defaultFont.GetFaceName() : normal_face; |
d1da8872 | 173 | |
10e5c7ea | 174 | SetFonts(normal, fixed_face, f_sizes); |
7acd3625 RD |
175 | } |
176 | ||
5526e819 VS |
177 | void wxHtmlWinParser::InitParser(const wxString& source) |
178 | { | |
179 | wxHtmlParser::InitParser(source); | |
2b5f62a0 | 180 | wxASSERT_MSG(m_DC != NULL, wxT("no DC assigned to wxHtmlWinParser!!")); |
5526e819 VS |
181 | |
182 | m_FontBold = m_FontItalic = m_FontUnderlined = m_FontFixed = FALSE; | |
f2c2fa4d | 183 | m_FontSize = 3; //default one |
5526e819 | 184 | CreateCurrentFont(); // we're selecting default font into |
2b5f62a0 | 185 | m_DC->GetTextExtent( wxT("H"), &m_CharWidth, &m_CharHeight); |
5526e819 | 186 | /* NOTE : we're not using GetCharWidth/Height() because |
0e8c8233 | 187 | of differences under X and win |
5526e819 VS |
188 | */ |
189 | ||
d1da8872 | 190 | m_UseLink = false; |
9548f380 | 191 | m_Link = wxHtmlLinkInfo( wxEmptyString ); |
5526e819 VS |
192 | m_LinkColor.Set(0, 0, 0xFF); |
193 | m_ActualColor.Set(0, 0, 0); | |
efba2b89 | 194 | m_Align = wxHTML_ALIGN_LEFT; |
d1da8872 | 195 | m_tmpLastWasSpace = false; |
b6d93b26 | 196 | m_lastWordCell = NULL; |
5526e819 VS |
197 | |
198 | OpenContainer(); | |
5526e819 | 199 | OpenContainer(); |
2b5f62a0 | 200 | |
fa2f5d3b | 201 | #if !wxUSE_UNICODE |
2b5f62a0 VZ |
202 | wxString charset = ExtractCharsetInformation(source); |
203 | if (!charset.empty()) | |
204 | { | |
205 | wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(charset); | |
206 | if (enc != wxFONTENCODING_SYSTEM) | |
207 | SetInputEncoding(enc); | |
208 | } | |
209 | #endif | |
210 | ||
4f9297b0 | 211 | m_Container->InsertCell(new wxHtmlColourCell(m_ActualColor)); |
44d0c580 | 212 | wxColour windowColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ; |
eb6a4098 | 213 | m_Container->InsertCell( |
3403ccd5 RD |
214 | new wxHtmlColourCell(GetWindow() ? |
215 | GetWindow()->GetBackgroundColour() : | |
44d0c580 | 216 | windowColour, |
eb6a4098 | 217 | wxHTML_CLR_BACKGROUND)); |
4f9297b0 | 218 | m_Container->InsertCell(new wxHtmlFontCell(CreateCurrentFont())); |
5526e819 VS |
219 | } |
220 | ||
5526e819 VS |
221 | void wxHtmlWinParser::DoneParser() |
222 | { | |
223 | m_Container = NULL; | |
2b5f62a0 VZ |
224 | #if !wxUSE_UNICODE |
225 | SetInputEncoding(wxFONTENCODING_ISO8859_1); // for next call | |
226 | #endif | |
5526e819 VS |
227 | wxHtmlParser::DoneParser(); |
228 | } | |
229 | ||
5526e819 VS |
230 | wxObject* wxHtmlWinParser::GetProduct() |
231 | { | |
232 | wxHtmlContainerCell *top; | |
233 | ||
234 | CloseContainer(); | |
235 | OpenContainer(); | |
67cfebc2 | 236 | |
5526e819 | 237 | top = m_Container; |
4f9297b0 | 238 | while (top->GetParent()) top = top->GetParent(); |
ace0fab4 VS |
239 | top->RemoveExtraSpacing(true, true); |
240 | ||
5526e819 VS |
241 | return top; |
242 | } | |
243 | ||
0423bdc7 | 244 | wxFSFile *wxHtmlWinParser::OpenURL(wxHtmlURLType type, |
6cc4e6b8 | 245 | const wxString& url) const |
04db5c3f | 246 | { |
04db5c3f | 247 | if ( m_Window ) |
6cc4e6b8 | 248 | { |
6cc4e6b8 VS |
249 | wxString myurl(url); |
250 | wxHtmlOpeningStatus status; | |
251 | for (;;) | |
252 | { | |
4bfa3189 WS |
253 | wxString myfullurl(myurl); |
254 | ||
4bfa3189 | 255 | // consider url as absolute path first |
7e496014 WS |
256 | wxURI current(myurl); |
257 | myfullurl = current.BuildUnescapedURI(); | |
4bfa3189 WS |
258 | |
259 | // if not absolute then ... | |
260 | if( current.IsReference() ) | |
261 | { | |
262 | wxString basepath = GetFS()->GetPath(); | |
7e496014 | 263 | wxURI base(basepath); |
4bfa3189 | 264 | |
7e496014 | 265 | // ... try to apply base path if valid ... |
4bfa3189 WS |
266 | if( !base.IsReference() ) |
267 | { | |
268 | wxURI path(myfullurl); | |
269 | path.Resolve( base ); | |
7e496014 | 270 | myfullurl = path.BuildUnescapedURI(); |
4bfa3189 WS |
271 | } |
272 | else | |
273 | { | |
274 | // ... or force such addition if not included already | |
7e496014 | 275 | if( !current.GetPath().Contains(base.GetPath()) ) |
4bfa3189 WS |
276 | { |
277 | basepath += myurl; | |
7e496014 WS |
278 | wxURI connected( basepath ); |
279 | myfullurl = connected.BuildUnescapedURI(); | |
4bfa3189 WS |
280 | } |
281 | } | |
282 | } | |
4bfa3189 | 283 | |
0423bdc7 | 284 | wxString redirect; |
4bfa3189 | 285 | status = m_Window->OnOpeningURL(type, myfullurl, &redirect); |
0423bdc7 | 286 | if ( status != wxHTML_REDIRECT ) |
6cc4e6b8 | 287 | break; |
0423bdc7 VZ |
288 | |
289 | myurl = redirect; | |
6cc4e6b8 | 290 | } |
0423bdc7 | 291 | |
6cc4e6b8 VS |
292 | if ( status == wxHTML_BLOCK ) |
293 | return NULL; | |
2c892c0b VZ |
294 | |
295 | return GetFS()->OpenFile(myurl); | |
6cc4e6b8 | 296 | } |
2c892c0b VZ |
297 | |
298 | return wxHtmlParser::OpenURL(type, url); | |
04db5c3f | 299 | } |
5526e819 | 300 | |
211dfedd | 301 | void wxHtmlWinParser::AddText(const wxChar* txt) |
5526e819 | 302 | { |
e3c7fd79 VZ |
303 | size_t i = 0, |
304 | x, | |
305 | lng = wxStrlen(txt); | |
211dfedd | 306 | register wxChar d; |
5526e819 | 307 | int templen = 0; |
f23e92e7 | 308 | wxChar nbsp = GetEntitiesParser()->GetCharForCode(160 /* nbsp */); |
211dfedd VS |
309 | |
310 | if (lng+1 > m_tmpStrBufSize) | |
311 | { | |
312 | delete[] m_tmpStrBuf; | |
313 | m_tmpStrBuf = new wxChar[lng+1]; | |
314 | m_tmpStrBufSize = lng+1; | |
315 | } | |
316 | wxChar *temp = m_tmpStrBuf; | |
3c8c8da2 VZ |
317 | |
318 | if (m_tmpLastWasSpace) | |
4f9297b0 | 319 | { |
3c8c8da2 VZ |
320 | while ((i < lng) && |
321 | ((txt[i] == wxT('\n')) || (txt[i] == wxT('\r')) || (txt[i] == wxT(' ')) || | |
211dfedd | 322 | (txt[i] == wxT('\t')))) i++; |
5526e819 VS |
323 | } |
324 | ||
3c8c8da2 | 325 | while (i < lng) |
4f9297b0 | 326 | { |
5526e819 VS |
327 | x = 0; |
328 | d = temp[templen++] = txt[i]; | |
3c8c8da2 | 329 | if ((d == wxT('\n')) || (d == wxT('\r')) || (d == wxT(' ')) || (d == wxT('\t'))) |
e3c7fd79 | 330 | { |
5526e819 | 331 | i++, x++; |
3c8c8da2 | 332 | while ((i < lng) && ((txt[i] == wxT('\n')) || (txt[i] == wxT('\r')) || |
211dfedd | 333 | (txt[i] == wxT(' ')) || (txt[i] == wxT('\t')))) i++, x++; |
5526e819 VS |
334 | } |
335 | else i++; | |
336 | ||
3c8c8da2 | 337 | if (x) |
e3c7fd79 | 338 | { |
211dfedd | 339 | temp[templen-1] = wxT(' '); |
97eac136 | 340 | DoAddText(temp, templen, nbsp); |
d1da8872 | 341 | m_tmpLastWasSpace = true; |
5526e819 VS |
342 | } |
343 | } | |
af035b26 VS |
344 | |
345 | if (templen && (templen > 1 || temp[0] != wxT(' '))) | |
4f9297b0 | 346 | { |
97eac136 VS |
347 | DoAddText(temp, templen, nbsp); |
348 | m_tmpLastWasSpace = false; | |
349 | } | |
350 | } | |
351 | ||
352 | void wxHtmlWinParser::DoAddText(wxChar *temp, int& templen, wxChar nbsp) | |
353 | { | |
354 | temp[templen] = 0; | |
355 | templen = 0; | |
2b5f62a0 | 356 | #if !wxUSE_UNICODE |
97eac136 VS |
357 | if (m_EncConv) |
358 | m_EncConv->Convert(temp); | |
2b5f62a0 | 359 | #endif |
97eac136 VS |
360 | size_t len = wxStrlen(temp); |
361 | for (size_t j = 0; j < len; j++) | |
362 | { | |
363 | if (temp[j] == nbsp) | |
364 | temp[j] = wxT(' '); | |
5526e819 | 365 | } |
97eac136 VS |
366 | |
367 | wxHtmlCell *c = new wxHtmlWordCell(temp, *(GetDC())); | |
368 | ||
369 | if (m_UseLink) | |
370 | c->SetLink(m_Link); | |
371 | m_Container->InsertCell(c); | |
372 | ((wxHtmlWordCell*)c)->SetPreviousWord(m_lastWordCell); | |
373 | m_lastWordCell = (wxHtmlWordCell*)c; | |
5526e819 VS |
374 | } |
375 | ||
376 | ||
377 | ||
378 | wxHtmlContainerCell* wxHtmlWinParser::OpenContainer() | |
379 | { | |
380 | m_Container = new wxHtmlContainerCell(m_Container); | |
4f9297b0 | 381 | m_Container->SetAlignHor(m_Align); |
d1da8872 | 382 | m_tmpLastWasSpace = true; |
5526e819 VS |
383 | /* to avoid space being first character in paragraph */ |
384 | return m_Container; | |
385 | } | |
386 | ||
387 | ||
388 | ||
389 | wxHtmlContainerCell* wxHtmlWinParser::SetContainer(wxHtmlContainerCell *c) | |
390 | { | |
d1da8872 | 391 | m_tmpLastWasSpace = true; |
5526e819 VS |
392 | /* to avoid space being first character in paragraph */ |
393 | return m_Container = c; | |
394 | } | |
395 | ||
396 | ||
397 | ||
398 | wxHtmlContainerCell* wxHtmlWinParser::CloseContainer() | |
399 | { | |
4f9297b0 | 400 | m_Container = m_Container->GetParent(); |
5526e819 VS |
401 | return m_Container; |
402 | } | |
403 | ||
404 | ||
f2c2fa4d VS |
405 | void wxHtmlWinParser::SetFontSize(int s) |
406 | { | |
407 | if (s < 1) s = 1; | |
408 | else if (s > 7) s = 7; | |
409 | m_FontSize = s; | |
410 | } | |
411 | ||
412 | ||
413 | ||
5526e819 VS |
414 | wxFont* wxHtmlWinParser::CreateCurrentFont() |
415 | { | |
416 | int fb = GetFontBold(), | |
417 | fi = GetFontItalic(), | |
418 | fu = GetFontUnderlined(), | |
419 | ff = GetFontFixed(), | |
f2c2fa4d | 420 | fs = GetFontSize() - 1 /*remap from <1;7> to <0;6>*/ ; |
5526e819 | 421 | |
f1ad10f3 VS |
422 | wxString face = ff ? m_FontFaceFixed : m_FontFaceNormal; |
423 | wxString *faceptr = &(m_FontsFacesTable[fb][fi][fu][ff][fs]); | |
424 | wxFont **fontptr = &(m_FontsTable[fb][fi][fu][ff][fs]); | |
2b5f62a0 | 425 | #if !wxUSE_UNICODE |
b250d384 | 426 | wxFontEncoding *encptr = &(m_FontsEncTable[fb][fi][fu][ff][fs]); |
2b5f62a0 | 427 | #endif |
f1ad10f3 | 428 | |
2b5f62a0 VZ |
429 | if (*fontptr != NULL && (*faceptr != face |
430 | #if !wxUSE_UNICODE | |
431 | || *encptr != m_OutputEnc | |
432 | #endif | |
433 | )) | |
4f9297b0 | 434 | { |
f1ad10f3 VS |
435 | delete *fontptr; |
436 | *fontptr = NULL; | |
437 | } | |
438 | ||
3c8c8da2 | 439 | if (*fontptr == NULL) |
4f9297b0 | 440 | { |
f1ad10f3 VS |
441 | *faceptr = face; |
442 | *fontptr = new wxFont( | |
7a5e6267 | 443 | (int) (m_FontsSizes[fs] * m_PixelScale), |
f1ad10f3 VS |
444 | ff ? wxMODERN : wxSWISS, |
445 | fi ? wxITALIC : wxNORMAL, | |
446 | fb ? wxBOLD : wxNORMAL, | |
d1da8872 | 447 | fu ? true : false, face |
2b5f62a0 VZ |
448 | #if wxUSE_UNICODE |
449 | ); | |
450 | #else | |
451 | , m_OutputEnc); | |
452 | *encptr = m_OutputEnc; | |
453 | #endif | |
5526e819 | 454 | } |
4f9297b0 | 455 | m_DC->SetFont(**fontptr); |
f1ad10f3 | 456 | return (*fontptr); |
5526e819 VS |
457 | } |
458 | ||
459 | ||
460 | ||
f2c2fa4d VS |
461 | void wxHtmlWinParser::SetLink(const wxHtmlLinkInfo& link) |
462 | { | |
3c8c8da2 | 463 | m_Link = link; |
f2c2fa4d VS |
464 | m_UseLink = (link.GetHref() != wxEmptyString); |
465 | } | |
466 | ||
467 | ||
3c8c8da2 | 468 | void wxHtmlWinParser::SetFontFace(const wxString& face) |
b250d384 | 469 | { |
3c8c8da2 | 470 | if (GetFontFixed()) m_FontFaceFixed = face; |
b250d384 VS |
471 | else m_FontFaceNormal = face; |
472 | ||
2b5f62a0 | 473 | #if !wxUSE_UNICODE |
b250d384 VS |
474 | if (m_InputEnc != wxFONTENCODING_DEFAULT) |
475 | SetInputEncoding(m_InputEnc); | |
2b5f62a0 | 476 | #endif |
b250d384 VS |
477 | } |
478 | ||
479 | ||
480 | ||
2b5f62a0 | 481 | #if !wxUSE_UNICODE |
b250d384 VS |
482 | void wxHtmlWinParser::SetInputEncoding(wxFontEncoding enc) |
483 | { | |
484 | m_InputEnc = m_OutputEnc = wxFONTENCODING_DEFAULT; | |
3c8c8da2 | 485 | if (m_EncConv) |
daa616fc | 486 | { |
3c8c8da2 | 487 | delete m_EncConv; |
daa616fc VS |
488 | m_EncConv = NULL; |
489 | } | |
b250d384 VS |
490 | |
491 | if (enc == wxFONTENCODING_DEFAULT) return; | |
492 | ||
493 | wxFontEncoding altfix, altnorm; | |
494 | bool availfix, availnorm; | |
3c8c8da2 VZ |
495 | |
496 | // exact match? | |
142b3bc2 VS |
497 | availnorm = wxFontMapper::Get()->IsEncodingAvailable(enc, m_FontFaceNormal); |
498 | availfix = wxFontMapper::Get()->IsEncodingAvailable(enc, m_FontFaceFixed); | |
3c8c8da2 | 499 | if (availnorm && availfix) |
b250d384 | 500 | m_OutputEnc = enc; |
3c8c8da2 | 501 | |
b250d384 | 502 | // alternatives? |
d1da8872 WS |
503 | else if (wxFontMapper::Get()->GetAltForEncoding(enc, &altnorm, m_FontFaceNormal, false) && |
504 | wxFontMapper::Get()->GetAltForEncoding(enc, &altfix, m_FontFaceFixed, false) && | |
b250d384 VS |
505 | altnorm == altfix) |
506 | m_OutputEnc = altnorm; | |
3c8c8da2 | 507 | |
b250d384 VS |
508 | // at least normal face? |
509 | else if (availnorm) | |
510 | m_OutputEnc = enc; | |
d1da8872 | 511 | else if (wxFontMapper::Get()->GetAltForEncoding(enc, &altnorm, m_FontFaceNormal, false)) |
b250d384 | 512 | m_OutputEnc = altnorm; |
3c8c8da2 | 513 | |
b250d384 | 514 | else |
c83e1237 SC |
515 | { |
516 | #ifndef __WXMAC__ | |
517 | // okay, let convert to ISO_8859-1, available always | |
b250d384 | 518 | m_OutputEnc = wxFONTENCODING_DEFAULT; |
90548138 | 519 | #else |
c83e1237 | 520 | m_OutputEnc = wxLocale::GetSystemEncoding() ; |
90548138 | 521 | #endif |
c83e1237 | 522 | } |
3c8c8da2 | 523 | |
b250d384 | 524 | m_InputEnc = enc; |
daa616fc VS |
525 | if (m_OutputEnc == wxFONTENCODING_DEFAULT) |
526 | GetEntitiesParser()->SetEncoding(wxFONTENCODING_SYSTEM); | |
527 | else | |
528 | GetEntitiesParser()->SetEncoding(m_OutputEnc); | |
3c8c8da2 | 529 | |
b250d384 VS |
530 | if (m_InputEnc == m_OutputEnc) return; |
531 | ||
532 | m_EncConv = new wxEncodingConverter(); | |
3c8c8da2 | 533 | if (!m_EncConv->Init(m_InputEnc, |
b250d384 VS |
534 | (m_OutputEnc == wxFONTENCODING_DEFAULT) ? |
535 | wxFONTENCODING_ISO8859_1 : m_OutputEnc, | |
3c8c8da2 | 536 | wxCONVERT_SUBSTITUTE)) |
b250d384 | 537 | { // total failture :-( |
3c8c8da2 VZ |
538 | wxLogError(_("Failed to display HTML document in %s encoding"), |
539 | wxFontMapper::GetEncodingName(enc).c_str()); | |
b250d384 VS |
540 | m_InputEnc = m_OutputEnc = wxFONTENCODING_DEFAULT; |
541 | delete m_EncConv; | |
542 | m_EncConv = NULL; | |
543 | } | |
544 | } | |
2b5f62a0 | 545 | #endif |
b250d384 VS |
546 | |
547 | ||
f2c2fa4d | 548 | |
5526e819 VS |
549 | |
550 | //----------------------------------------------------------------------------- | |
551 | // wxHtmlWinTagHandler | |
552 | //----------------------------------------------------------------------------- | |
553 | ||
554 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinTagHandler, wxHtmlTagHandler) | |
555 | ||
5526e819 VS |
556 | //----------------------------------------------------------------------------- |
557 | // wxHtmlTagsModule | |
558 | //----------------------------------------------------------------------------- | |
559 | ||
d6a6d666 VS |
560 | // NB: This is *NOT* winpars.cpp's initialization and shutdown code!! |
561 | // This module is an ancestor for tag handlers modules defined | |
562 | // in m_*.cpp files with TAGS_MODULE_BEGIN...TAGS_MODULE_END construct. | |
563 | // | |
564 | // Do not add any winpars.cpp shutdown or initialization code to it, | |
565 | // create a new module instead! | |
5526e819 VS |
566 | |
567 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlTagsModule, wxModule) | |
568 | ||
5526e819 VS |
569 | bool wxHtmlTagsModule::OnInit() |
570 | { | |
571 | wxHtmlWinParser::AddModule(this); | |
d1da8872 | 572 | return true; |
5526e819 VS |
573 | } |
574 | ||
5526e819 VS |
575 | void wxHtmlTagsModule::OnExit() |
576 | { | |
f6bcfd97 | 577 | wxHtmlWinParser::RemoveModule(this); |
5526e819 | 578 | } |
d6a6d666 | 579 | |
223d09f6 | 580 | #endif |
5526e819 | 581 |