]>
Commit | Line | Data |
---|---|---|
5526e819 | 1 | ///////////////////////////////////////////////////////////////////////////// |
93763ad5 | 2 | // Name: src/html/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 | 11 | |
2b5f62a0 | 12 | #ifdef __BORLANDC__ |
93763ad5 | 13 | #pragma hdrstop |
5526e819 VS |
14 | #endif |
15 | ||
93763ad5 WS |
16 | #if wxUSE_HTML && wxUSE_STREAMS |
17 | ||
b4f4d3dd | 18 | #ifndef WX_PRECOMP |
04dbb646 VZ |
19 | #include "wx/intl.h" |
20 | #include "wx/dc.h" | |
e4db172a | 21 | #include "wx/log.h" |
9eddec69 | 22 | #include "wx/settings.h" |
5526e819 VS |
23 | #endif |
24 | ||
69941f05 VS |
25 | #include "wx/html/htmldefs.h" |
26 | #include "wx/html/winpars.h" | |
27 | #include "wx/html/htmlwin.h" | |
b250d384 | 28 | #include "wx/fontmap.h" |
3ec372c8 | 29 | #include "wx/uri.h" |
5526e819 VS |
30 | |
31 | ||
32 | //----------------------------------------------------------------------------- | |
33 | // wxHtmlWinParser | |
34 | //----------------------------------------------------------------------------- | |
35 | ||
4f44ea36 | 36 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinParser, wxHtmlParser) |
5526e819 VS |
37 | |
38 | wxList wxHtmlWinParser::m_Modules; | |
39 | ||
bc55e31b | 40 | wxHtmlWinParser::wxHtmlWinParser(wxHtmlWindowInterface *wndIface) |
5526e819 | 41 | { |
211dfedd VS |
42 | m_tmpStrBuf = NULL; |
43 | m_tmpStrBufSize = 0; | |
bc55e31b | 44 | m_windowInterface = wndIface; |
5526e819 VS |
45 | m_Container = NULL; |
46 | m_DC = NULL; | |
47 | m_CharHeight = m_CharWidth = 0; | |
d1da8872 | 48 | m_UseLink = false; |
2b5f62a0 | 49 | #if !wxUSE_UNICODE |
c7820964 | 50 | m_nbsp = 0; |
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 | ||
ba804ab2 VZ |
114 | // build all HTML font sizes (1..7) from the given base size |
115 | static void wxBuildFontSizes(int *sizes, int size) | |
116 | { | |
117 | // using a fixed factor (1.2, from CSS2) is a bad idea as explained at | |
118 | // http://www.w3.org/TR/CSS21/fonts.html#font-size-props but this is by far | |
119 | // simplest thing to do so still do it like this for now | |
1d203ed8 | 120 | sizes[0] = int(size * 0.75); // exception to 1.2 rule, otherwise too small |
ba804ab2 VZ |
121 | sizes[1] = int(size * 0.83); |
122 | sizes[2] = size; | |
123 | sizes[3] = int(size * 1.2); | |
124 | sizes[4] = int(size * 1.44); | |
125 | sizes[5] = int(size * 1.73); | |
126 | sizes[6] = int(size * 2); | |
127 | } | |
128 | ||
1d203ed8 VZ |
129 | static int wxGetDefaultHTMLFontSize() |
130 | { | |
131 | // base the default font size on the size of the default system font but | |
132 | // also ensure that we have a font of reasonable size, otherwise small HTML | |
133 | // fonts are unreadable | |
134 | int size = wxNORMAL_FONT->GetPointSize(); | |
135 | if ( size < 10 ) | |
136 | size = 10; | |
137 | return size; | |
138 | } | |
139 | ||
ba804ab2 VZ |
140 | void wxHtmlWinParser::SetFonts(const wxString& normal_face, |
141 | const wxString& fixed_face, | |
4eecf115 | 142 | const int *sizes) |
5526e819 | 143 | { |
ba804ab2 VZ |
144 | static int default_sizes[7] = { 0 }; |
145 | if ( !sizes ) | |
146 | { | |
147 | if ( !default_sizes[0] ) | |
1d203ed8 | 148 | wxBuildFontSizes(default_sizes, wxGetDefaultHTMLFontSize()); |
ba804ab2 VZ |
149 | |
150 | sizes = default_sizes; | |
151 | } | |
4eecf115 | 152 | |
c9f56e70 VS |
153 | int i, j, k, l, m; |
154 | ||
ba804ab2 VZ |
155 | for (i = 0; i < 7; i++) |
156 | m_FontsSizes[i] = sizes[i]; | |
157 | ||
5526e819 VS |
158 | m_FontFaceFixed = fixed_face; |
159 | m_FontFaceNormal = normal_face; | |
3c8c8da2 | 160 | |
2b5f62a0 | 161 | #if !wxUSE_UNICODE |
b250d384 | 162 | SetInputEncoding(m_InputEnc); |
2b5f62a0 | 163 | #endif |
c9f56e70 VS |
164 | |
165 | for (i = 0; i < 2; i++) | |
166 | for (j = 0; j < 2; j++) | |
167 | for (k = 0; k < 2; k++) | |
168 | for (l = 0; l < 2; l++) | |
169 | for (m = 0; m < 7; m++) { | |
3c8c8da2 | 170 | if (m_FontsTable[i][j][k][l][m] != NULL) |
e3c7fd79 | 171 | { |
c9f56e70 VS |
172 | delete m_FontsTable[i][j][k][l][m]; |
173 | m_FontsTable[i][j][k][l][m] = NULL; | |
174 | } | |
175 | } | |
5526e819 VS |
176 | } |
177 | ||
10e5c7ea VS |
178 | void wxHtmlWinParser::SetStandardFonts(int size, |
179 | const wxString& normal_face, | |
180 | const wxString& fixed_face) | |
7acd3625 | 181 | { |
ba804ab2 | 182 | if (size == -1) |
1d203ed8 | 183 | size = wxGetDefaultHTMLFontSize(); |
d1da8872 | 184 | |
7acd3625 | 185 | int f_sizes[7]; |
ba804ab2 VZ |
186 | wxBuildFontSizes(f_sizes, size); |
187 | ||
188 | wxString normal = normal_face; | |
189 | if ( normal.empty() ) | |
190 | normal = wxNORMAL_FONT->GetFaceName(); | |
d1da8872 | 191 | |
10e5c7ea | 192 | SetFonts(normal, fixed_face, f_sizes); |
7acd3625 RD |
193 | } |
194 | ||
5526e819 VS |
195 | void wxHtmlWinParser::InitParser(const wxString& source) |
196 | { | |
197 | wxHtmlParser::InitParser(source); | |
2b5f62a0 | 198 | wxASSERT_MSG(m_DC != NULL, wxT("no DC assigned to wxHtmlWinParser!!")); |
5526e819 VS |
199 | |
200 | m_FontBold = m_FontItalic = m_FontUnderlined = m_FontFixed = FALSE; | |
f2c2fa4d | 201 | m_FontSize = 3; //default one |
5526e819 | 202 | CreateCurrentFont(); // we're selecting default font into |
5620726f RR |
203 | |
204 | // we're not using GetCharWidth/Height() because of | |
205 | // differences under X and win | |
206 | wxCoord w,h; | |
207 | m_DC->GetTextExtent( wxT("H"), &w, &h); | |
208 | m_CharWidth = w; | |
209 | m_CharHeight = h; | |
5526e819 | 210 | |
d1da8872 | 211 | m_UseLink = false; |
9548f380 | 212 | m_Link = wxHtmlLinkInfo( wxEmptyString ); |
5526e819 VS |
213 | m_LinkColor.Set(0, 0, 0xFF); |
214 | m_ActualColor.Set(0, 0, 0); | |
efba2b89 | 215 | m_Align = wxHTML_ALIGN_LEFT; |
3c115835 VS |
216 | m_ScriptMode = wxHTML_SCRIPT_NORMAL; |
217 | m_ScriptBaseline = 0; | |
d1da8872 | 218 | m_tmpLastWasSpace = false; |
b6d93b26 | 219 | m_lastWordCell = NULL; |
5526e819 | 220 | |
69328c1a VS |
221 | // open the toplevel container that contains everything else and that |
222 | // is never closed (this makes parser's life easier): | |
5526e819 | 223 | OpenContainer(); |
69328c1a VS |
224 | |
225 | // then open the first container into which page's content will go: | |
5526e819 | 226 | OpenContainer(); |
2b5f62a0 | 227 | |
fa2f5d3b | 228 | #if !wxUSE_UNICODE |
2b5f62a0 VZ |
229 | wxString charset = ExtractCharsetInformation(source); |
230 | if (!charset.empty()) | |
231 | { | |
232 | wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(charset); | |
233 | if (enc != wxFONTENCODING_SYSTEM) | |
234 | SetInputEncoding(enc); | |
235 | } | |
236 | #endif | |
237 | ||
4f9297b0 | 238 | m_Container->InsertCell(new wxHtmlColourCell(m_ActualColor)); |
44d0c580 | 239 | wxColour windowColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ; |
bc55e31b VS |
240 | |
241 | m_Container->InsertCell | |
242 | ( | |
243 | new wxHtmlColourCell | |
244 | ( | |
245 | m_windowInterface | |
246 | ? m_windowInterface->GetHTMLBackgroundColour() | |
247 | : windowColour, | |
248 | wxHTML_CLR_BACKGROUND | |
249 | ) | |
250 | ); | |
251 | ||
4f9297b0 | 252 | m_Container->InsertCell(new wxHtmlFontCell(CreateCurrentFont())); |
5526e819 VS |
253 | } |
254 | ||
5526e819 VS |
255 | void wxHtmlWinParser::DoneParser() |
256 | { | |
257 | m_Container = NULL; | |
2b5f62a0 VZ |
258 | #if !wxUSE_UNICODE |
259 | SetInputEncoding(wxFONTENCODING_ISO8859_1); // for next call | |
260 | #endif | |
5526e819 VS |
261 | wxHtmlParser::DoneParser(); |
262 | } | |
263 | ||
bc55e31b VS |
264 | #if WXWIN_COMPATIBILITY_2_6 |
265 | wxHtmlWindow *wxHtmlWinParser::GetWindow() | |
266 | { | |
267 | if (!m_windowInterface) | |
268 | return NULL; | |
269 | return wxDynamicCast(m_windowInterface->GetHTMLWindow(), wxHtmlWindow); | |
270 | } | |
271 | #endif | |
272 | ||
5526e819 VS |
273 | wxObject* wxHtmlWinParser::GetProduct() |
274 | { | |
275 | wxHtmlContainerCell *top; | |
276 | ||
277 | CloseContainer(); | |
278 | OpenContainer(); | |
67cfebc2 | 279 | |
5526e819 | 280 | top = m_Container; |
4f9297b0 | 281 | while (top->GetParent()) top = top->GetParent(); |
ace0fab4 VS |
282 | top->RemoveExtraSpacing(true, true); |
283 | ||
5526e819 VS |
284 | return top; |
285 | } | |
286 | ||
0423bdc7 | 287 | wxFSFile *wxHtmlWinParser::OpenURL(wxHtmlURLType type, |
6cc4e6b8 | 288 | const wxString& url) const |
04db5c3f | 289 | { |
bc55e31b VS |
290 | if ( !m_windowInterface ) |
291 | return wxHtmlParser::OpenURL(type, url); | |
292 | ||
293 | wxString myurl(url); | |
294 | wxHtmlOpeningStatus status; | |
295 | for (;;) | |
6cc4e6b8 | 296 | { |
bc55e31b | 297 | wxString myfullurl(myurl); |
4bfa3189 | 298 | |
bc55e31b VS |
299 | // consider url as absolute path first |
300 | wxURI current(myurl); | |
301 | myfullurl = current.BuildUnescapedURI(); | |
4bfa3189 | 302 | |
bc55e31b VS |
303 | // if not absolute then ... |
304 | if( current.IsReference() ) | |
305 | { | |
306 | wxString basepath = GetFS()->GetPath(); | |
307 | wxURI base(basepath); | |
4bfa3189 | 308 | |
bc55e31b VS |
309 | // ... try to apply base path if valid ... |
310 | if( !base.IsReference() ) | |
311 | { | |
312 | wxURI path(myfullurl); | |
313 | path.Resolve( base ); | |
314 | myfullurl = path.BuildUnescapedURI(); | |
315 | } | |
316 | else | |
317 | { | |
318 | // ... or force such addition if not included already | |
319 | if( !current.GetPath().Contains(base.GetPath()) ) | |
4bfa3189 | 320 | { |
bc55e31b VS |
321 | basepath += myurl; |
322 | wxURI connected( basepath ); | |
323 | myfullurl = connected.BuildUnescapedURI(); | |
4bfa3189 WS |
324 | } |
325 | } | |
6cc4e6b8 | 326 | } |
0423bdc7 | 327 | |
bc55e31b VS |
328 | wxString redirect; |
329 | status = m_windowInterface->OnHTMLOpeningURL(type, myfullurl, &redirect); | |
330 | if ( status != wxHTML_REDIRECT ) | |
331 | break; | |
2c892c0b | 332 | |
bc55e31b | 333 | myurl = redirect; |
6cc4e6b8 | 334 | } |
2c892c0b | 335 | |
bc55e31b VS |
336 | if ( status == wxHTML_BLOCK ) |
337 | return NULL; | |
338 | ||
5c4035d6 MW |
339 | int flags = wxFS_READ; |
340 | if (type == wxHTML_URL_IMAGE) | |
341 | flags |= wxFS_SEEKABLE; | |
342 | ||
343 | return GetFS()->OpenFile(myurl, flags); | |
04db5c3f | 344 | } |
5526e819 | 345 | |
5bce3e6f | 346 | void wxHtmlWinParser::AddText(const wxString& txt) |
5526e819 | 347 | { |
211dfedd | 348 | register wxChar d; |
5526e819 | 349 | int templen = 0; |
211dfedd | 350 | |
5bce3e6f | 351 | size_t lng = txt.length(); |
211dfedd VS |
352 | if (lng+1 > m_tmpStrBufSize) |
353 | { | |
354 | delete[] m_tmpStrBuf; | |
355 | m_tmpStrBuf = new wxChar[lng+1]; | |
356 | m_tmpStrBufSize = lng+1; | |
357 | } | |
358 | wxChar *temp = m_tmpStrBuf; | |
3c8c8da2 | 359 | |
5bce3e6f VS |
360 | wxString::const_iterator i = txt.begin(); |
361 | wxString::const_iterator end = txt.end(); | |
362 | ||
3c8c8da2 | 363 | if (m_tmpLastWasSpace) |
4f9297b0 | 364 | { |
5bce3e6f VS |
365 | while ( (i < end) && |
366 | (*i == wxT('\n') || *i == wxT('\r') || *i == wxT(' ') || | |
367 | *i == wxT('\t')) ) | |
368 | { | |
369 | ++i; | |
370 | } | |
5526e819 VS |
371 | } |
372 | ||
5bce3e6f | 373 | while (i < end) |
4f9297b0 | 374 | { |
5bce3e6f VS |
375 | size_t x = 0; |
376 | d = temp[templen++] = *i; | |
3c8c8da2 | 377 | if ((d == wxT('\n')) || (d == wxT('\r')) || (d == wxT(' ')) || (d == wxT('\t'))) |
e3c7fd79 | 378 | { |
5bce3e6f VS |
379 | ++i, ++x; |
380 | while ( (i < end) && | |
381 | (*i == wxT('\n') || *i == wxT('\r') || | |
f5595af6 | 382 | *i == wxT(' ') || *i == wxT('\t')) ) |
5bce3e6f VS |
383 | { |
384 | ++i; | |
385 | ++x; | |
386 | } | |
5526e819 | 387 | } |
5bce3e6f VS |
388 | else |
389 | ++i; | |
5526e819 | 390 | |
3c8c8da2 | 391 | if (x) |
e3c7fd79 | 392 | { |
211dfedd | 393 | temp[templen-1] = wxT(' '); |
c7820964 | 394 | DoAddText(temp, templen); |
d1da8872 | 395 | m_tmpLastWasSpace = true; |
5526e819 VS |
396 | } |
397 | } | |
af035b26 VS |
398 | |
399 | if (templen && (templen > 1 || temp[0] != wxT(' '))) | |
4f9297b0 | 400 | { |
c7820964 | 401 | DoAddText(temp, templen); |
97eac136 VS |
402 | m_tmpLastWasSpace = false; |
403 | } | |
404 | } | |
405 | ||
c7820964 | 406 | void wxHtmlWinParser::DoAddText(wxChar *temp, int& templen) |
97eac136 | 407 | { |
c7820964 VS |
408 | #define NBSP_UNICODE_VALUE 160 |
409 | #if !wxUSE_UNICODE | |
410 | if ( m_nbsp == 0 ) | |
411 | m_nbsp = GetEntitiesParser()->GetCharForCode(NBSP_UNICODE_VALUE); | |
412 | #define CUR_NBSP_VALUE m_nbsp | |
413 | #else | |
414 | #define CUR_NBSP_VALUE NBSP_UNICODE_VALUE | |
415 | #endif | |
416 | ||
97eac136 VS |
417 | temp[templen] = 0; |
418 | templen = 0; | |
2b5f62a0 | 419 | #if !wxUSE_UNICODE |
97eac136 VS |
420 | if (m_EncConv) |
421 | m_EncConv->Convert(temp); | |
2b5f62a0 | 422 | #endif |
97eac136 VS |
423 | size_t len = wxStrlen(temp); |
424 | for (size_t j = 0; j < len; j++) | |
425 | { | |
c7820964 | 426 | if (temp[j] == CUR_NBSP_VALUE) |
97eac136 | 427 | temp[j] = wxT(' '); |
5526e819 | 428 | } |
97eac136 | 429 | |
37ed592f | 430 | wxHtmlWordCell *c = new wxHtmlWordCell(temp, *(GetDC())); |
97eac136 | 431 | |
3c115835 VS |
432 | ApplyStateToCell(c); |
433 | ||
97eac136 | 434 | m_Container->InsertCell(c); |
37ed592f VS |
435 | c->SetPreviousWord(m_lastWordCell); |
436 | m_lastWordCell = c; | |
5526e819 VS |
437 | } |
438 | ||
439 | ||
440 | ||
441 | wxHtmlContainerCell* wxHtmlWinParser::OpenContainer() | |
442 | { | |
443 | m_Container = new wxHtmlContainerCell(m_Container); | |
4f9297b0 | 444 | m_Container->SetAlignHor(m_Align); |
d1da8872 | 445 | m_tmpLastWasSpace = true; |
5526e819 VS |
446 | /* to avoid space being first character in paragraph */ |
447 | return m_Container; | |
448 | } | |
449 | ||
450 | ||
451 | ||
452 | wxHtmlContainerCell* wxHtmlWinParser::SetContainer(wxHtmlContainerCell *c) | |
453 | { | |
d1da8872 | 454 | m_tmpLastWasSpace = true; |
5526e819 VS |
455 | /* to avoid space being first character in paragraph */ |
456 | return m_Container = c; | |
457 | } | |
458 | ||
459 | ||
460 | ||
461 | wxHtmlContainerCell* wxHtmlWinParser::CloseContainer() | |
462 | { | |
4f9297b0 | 463 | m_Container = m_Container->GetParent(); |
5526e819 VS |
464 | return m_Container; |
465 | } | |
466 | ||
467 | ||
f2c2fa4d VS |
468 | void wxHtmlWinParser::SetFontSize(int s) |
469 | { | |
8aef90e8 VS |
470 | if (s < 1) |
471 | s = 1; | |
472 | else if (s > 7) | |
473 | s = 7; | |
f2c2fa4d VS |
474 | m_FontSize = s; |
475 | } | |
476 | ||
477 | ||
478 | ||
5526e819 VS |
479 | wxFont* wxHtmlWinParser::CreateCurrentFont() |
480 | { | |
481 | int fb = GetFontBold(), | |
482 | fi = GetFontItalic(), | |
483 | fu = GetFontUnderlined(), | |
484 | ff = GetFontFixed(), | |
f2c2fa4d | 485 | fs = GetFontSize() - 1 /*remap from <1;7> to <0;6>*/ ; |
5526e819 | 486 | |
f1ad10f3 VS |
487 | wxString face = ff ? m_FontFaceFixed : m_FontFaceNormal; |
488 | wxString *faceptr = &(m_FontsFacesTable[fb][fi][fu][ff][fs]); | |
489 | wxFont **fontptr = &(m_FontsTable[fb][fi][fu][ff][fs]); | |
2b5f62a0 | 490 | #if !wxUSE_UNICODE |
b250d384 | 491 | wxFontEncoding *encptr = &(m_FontsEncTable[fb][fi][fu][ff][fs]); |
2b5f62a0 | 492 | #endif |
f1ad10f3 | 493 | |
2b5f62a0 VZ |
494 | if (*fontptr != NULL && (*faceptr != face |
495 | #if !wxUSE_UNICODE | |
496 | || *encptr != m_OutputEnc | |
497 | #endif | |
498 | )) | |
4f9297b0 | 499 | { |
f1ad10f3 VS |
500 | delete *fontptr; |
501 | *fontptr = NULL; | |
502 | } | |
503 | ||
3c8c8da2 | 504 | if (*fontptr == NULL) |
4f9297b0 | 505 | { |
f1ad10f3 VS |
506 | *faceptr = face; |
507 | *fontptr = new wxFont( | |
7a5e6267 | 508 | (int) (m_FontsSizes[fs] * m_PixelScale), |
f1ad10f3 VS |
509 | ff ? wxMODERN : wxSWISS, |
510 | fi ? wxITALIC : wxNORMAL, | |
511 | fb ? wxBOLD : wxNORMAL, | |
d1da8872 | 512 | fu ? true : false, face |
2b5f62a0 VZ |
513 | #if wxUSE_UNICODE |
514 | ); | |
515 | #else | |
516 | , m_OutputEnc); | |
517 | *encptr = m_OutputEnc; | |
518 | #endif | |
5526e819 | 519 | } |
4f9297b0 | 520 | m_DC->SetFont(**fontptr); |
f1ad10f3 | 521 | return (*fontptr); |
5526e819 VS |
522 | } |
523 | ||
524 | ||
525 | ||
f2c2fa4d VS |
526 | void wxHtmlWinParser::SetLink(const wxHtmlLinkInfo& link) |
527 | { | |
3c8c8da2 | 528 | m_Link = link; |
f2c2fa4d VS |
529 | m_UseLink = (link.GetHref() != wxEmptyString); |
530 | } | |
531 | ||
3c8c8da2 | 532 | void wxHtmlWinParser::SetFontFace(const wxString& face) |
b250d384 | 533 | { |
8aef90e8 VS |
534 | if (GetFontFixed()) |
535 | m_FontFaceFixed = face; | |
536 | else | |
537 | m_FontFaceNormal = face; | |
b250d384 | 538 | |
2b5f62a0 | 539 | #if !wxUSE_UNICODE |
b250d384 VS |
540 | if (m_InputEnc != wxFONTENCODING_DEFAULT) |
541 | SetInputEncoding(m_InputEnc); | |
2b5f62a0 | 542 | #endif |
b250d384 VS |
543 | } |
544 | ||
3c115835 VS |
545 | void wxHtmlWinParser::ApplyStateToCell(wxHtmlCell *cell) |
546 | { | |
547 | // set the link: | |
548 | if (m_UseLink) | |
549 | cell->SetLink(GetLink()); | |
550 | ||
551 | // apply current script mode settings: | |
552 | cell->SetScriptMode(GetScriptMode(), GetScriptBaseline()); | |
553 | } | |
b250d384 VS |
554 | |
555 | ||
2b5f62a0 | 556 | #if !wxUSE_UNICODE |
b250d384 VS |
557 | void wxHtmlWinParser::SetInputEncoding(wxFontEncoding enc) |
558 | { | |
c7820964 VS |
559 | // the character used for non-breakable space may change: |
560 | m_nbsp = 0; | |
561 | ||
b250d384 | 562 | m_InputEnc = m_OutputEnc = wxFONTENCODING_DEFAULT; |
3c8c8da2 | 563 | if (m_EncConv) |
daa616fc | 564 | { |
3c8c8da2 | 565 | delete m_EncConv; |
daa616fc VS |
566 | m_EncConv = NULL; |
567 | } | |
b250d384 | 568 | |
8aef90e8 VS |
569 | if (enc == wxFONTENCODING_DEFAULT) |
570 | return; | |
b250d384 VS |
571 | |
572 | wxFontEncoding altfix, altnorm; | |
573 | bool availfix, availnorm; | |
3c8c8da2 | 574 | |
142b3bc2 VS |
575 | availnorm = wxFontMapper::Get()->IsEncodingAvailable(enc, m_FontFaceNormal); |
576 | availfix = wxFontMapper::Get()->IsEncodingAvailable(enc, m_FontFaceFixed); | |
8aef90e8 | 577 | |
3c8c8da2 | 578 | if (availnorm && availfix) |
8aef90e8 VS |
579 | { |
580 | // exact match? | |
b250d384 | 581 | m_OutputEnc = enc; |
8aef90e8 | 582 | } |
3c8c8da2 | 583 | |
d1da8872 WS |
584 | else if (wxFontMapper::Get()->GetAltForEncoding(enc, &altnorm, m_FontFaceNormal, false) && |
585 | wxFontMapper::Get()->GetAltForEncoding(enc, &altfix, m_FontFaceFixed, false) && | |
b250d384 | 586 | altnorm == altfix) |
8aef90e8 VS |
587 | { |
588 | // alternatives? | |
b250d384 | 589 | m_OutputEnc = altnorm; |
8aef90e8 | 590 | } |
b250d384 | 591 | else if (availnorm) |
8aef90e8 VS |
592 | { |
593 | // at least normal face? | |
b250d384 | 594 | m_OutputEnc = enc; |
8aef90e8 | 595 | } |
d1da8872 | 596 | else if (wxFontMapper::Get()->GetAltForEncoding(enc, &altnorm, m_FontFaceNormal, false)) |
8aef90e8 | 597 | { |
b250d384 | 598 | m_OutputEnc = altnorm; |
8aef90e8 | 599 | } |
b250d384 | 600 | else |
c83e1237 SC |
601 | { |
602 | #ifndef __WXMAC__ | |
6a17b868 | 603 | // okay, let's convert to ISO_8859-1, available always |
b250d384 | 604 | m_OutputEnc = wxFONTENCODING_DEFAULT; |
90548138 | 605 | #else |
c83e1237 | 606 | m_OutputEnc = wxLocale::GetSystemEncoding() ; |
90548138 | 607 | #endif |
c83e1237 | 608 | } |
3c8c8da2 | 609 | |
b250d384 | 610 | m_InputEnc = enc; |
daa616fc | 611 | if (m_OutputEnc == wxFONTENCODING_DEFAULT) |
8aef90e8 | 612 | { |
daa616fc | 613 | GetEntitiesParser()->SetEncoding(wxFONTENCODING_SYSTEM); |
8aef90e8 | 614 | } |
daa616fc | 615 | else |
8aef90e8 | 616 | { |
daa616fc | 617 | GetEntitiesParser()->SetEncoding(m_OutputEnc); |
8aef90e8 | 618 | } |
3c8c8da2 | 619 | |
8aef90e8 VS |
620 | if (m_InputEnc == m_OutputEnc) |
621 | return; | |
b250d384 VS |
622 | |
623 | m_EncConv = new wxEncodingConverter(); | |
3c8c8da2 | 624 | if (!m_EncConv->Init(m_InputEnc, |
b250d384 VS |
625 | (m_OutputEnc == wxFONTENCODING_DEFAULT) ? |
626 | wxFONTENCODING_ISO8859_1 : m_OutputEnc, | |
3c8c8da2 | 627 | wxCONVERT_SUBSTITUTE)) |
6a17b868 | 628 | { // total failure :-( |
3c8c8da2 VZ |
629 | wxLogError(_("Failed to display HTML document in %s encoding"), |
630 | wxFontMapper::GetEncodingName(enc).c_str()); | |
b250d384 VS |
631 | m_InputEnc = m_OutputEnc = wxFONTENCODING_DEFAULT; |
632 | delete m_EncConv; | |
633 | m_EncConv = NULL; | |
634 | } | |
635 | } | |
2b5f62a0 | 636 | #endif |
b250d384 VS |
637 | |
638 | ||
f2c2fa4d | 639 | |
5526e819 VS |
640 | |
641 | //----------------------------------------------------------------------------- | |
642 | // wxHtmlWinTagHandler | |
643 | //----------------------------------------------------------------------------- | |
644 | ||
645 | IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinTagHandler, wxHtmlTagHandler) | |
646 | ||
5526e819 VS |
647 | //----------------------------------------------------------------------------- |
648 | // wxHtmlTagsModule | |
649 | //----------------------------------------------------------------------------- | |
650 | ||
d6a6d666 VS |
651 | // NB: This is *NOT* winpars.cpp's initialization and shutdown code!! |
652 | // This module is an ancestor for tag handlers modules defined | |
653 | // in m_*.cpp files with TAGS_MODULE_BEGIN...TAGS_MODULE_END construct. | |
654 | // | |
655 | // Do not add any winpars.cpp shutdown or initialization code to it, | |
656 | // create a new module instead! | |
5526e819 VS |
657 | |
658 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlTagsModule, wxModule) | |
659 | ||
5526e819 VS |
660 | bool wxHtmlTagsModule::OnInit() |
661 | { | |
662 | wxHtmlWinParser::AddModule(this); | |
d1da8872 | 663 | return true; |
5526e819 VS |
664 | } |
665 | ||
5526e819 VS |
666 | void wxHtmlTagsModule::OnExit() |
667 | { | |
f6bcfd97 | 668 | wxHtmlWinParser::RemoveModule(this); |
5526e819 | 669 | } |
d6a6d666 | 670 | |
223d09f6 | 671 | #endif |