Set default html font Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Marcus Frenkel
Experienced Solver
Experienced Solver
Posts: 79
Joined: Thu Sep 25, 2008 12:14 am

Set default html font

Post by Marcus Frenkel »

Hi,

I use SetFont to set the font/size of all items in the wxSimpleHtmlListBox but there is no effect and the font/size remains the same. I use the below code with no luck:

Code: Select all

MySimpleHtmlListBox->SetFont( wxFont( 1, 70, 90, 90, false, wxT("Tahoma") ) );
I also tried to change the default font on wxHtmlWindow the same way but no luck either. A bug maybe or I'm doing something wrong?

Marcus
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan »

Hi,
it will not work. I think you couldn't to do it :(
AFAIK it could be made by means of wxHtmlWinParser interface, but unfortunately wxSimpleHtmlListBox (wxHtmlListBox) doesn't provide public interface to it (them have m_htmlParser as private member).
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
Marcus Frenkel
Experienced Solver
Experienced Solver
Posts: 79
Joined: Thu Sep 25, 2008 12:14 am

Post by Marcus Frenkel »

Thank you. Any simple code how can I use wxHtmlWinParser to change the default font for the wxHtmlWindow?

Marcus
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan »

Marcus Frenkel wrote:Thank you. Any simple code how can I use wxHtmlWinParser to change the default font for the wxHtmlWindow?

Code: Select all

...
wxHtmlWindow* html_window;
...
int f_sizes[7] = {6, 8, 10, 12, 14, 16, 18};
html_window->GetParser()->SetFonts(_T("Arial"), _T("Courier New"), f_sizes);
...
http://docs.wxwidgets.org/stable/wx_wxh ... ersetfonts
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
Marcus Frenkel
Experienced Solver
Experienced Solver
Posts: 79
Joined: Thu Sep 25, 2008 12:14 am

Post by Marcus Frenkel »

Thanks. Using your code for wxHtmlWindow it do works but only in between <font></font> tags. If the text is not inside <font> tag or it's in a <td> tag then the GetParser->SetFonts or GetParser->SetFontSize doesn't have any effect. In addition, the array with the font sizes must have the default values (-2 to +4) because it only understands these values when using <FONT SIZE="x">. But the <FONT> tag works without using the GetParser-> functions too. My wxHtmlWindow will have text appended on short time intervals and it will take a lot memory eventually so I would like to shrink the html source code present in the memory by avoiding <font> tags.

In what wx source files can I find the definitions for the standard fonts/sizes for wxHtmlWindow and wxSimpleHtmlListBox? It seems easier at this point to recompile the source code with the standard values changed.

I'm just trying to have the default font inside wxHtmlWindow and wxSimpleHtmlListBox with the same size and face like when I use wxStaticText or other wx Controls.

Marcus
chris_bern
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Mar 05, 2008 3:30 pm

Post by chris_bern »

Code: Select all

HtmlWin->GetParser()->SetStandardFonts(wxNORMAL_FONT->GetPointSize(),wxEmptyString,wxEmptyString)
should do the trick.

Chris
Marcus Frenkel
Experienced Solver
Experienced Solver
Posts: 79
Joined: Thu Sep 25, 2008 12:14 am

Post by Marcus Frenkel »

Chris, that works great for wxHtmlWindow.

What about the wxSimpleHtmlListBox? There is no GetParser accessible function like Tan mentioned.
chris_bern
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Mar 05, 2008 3:30 pm

Post by chris_bern »

In htmllbox.h move this line "wxHtmlWinParser *m_htmlParser;" from private to the public part and rebuild to use the parser in your wxSimpleHtmlListBox. It's not a bad idea to request the designers of this control to make the parser public in the next wxWidgets release.
Last edited by chris_bern on Fri Oct 17, 2008 2:15 am, edited 1 time in total.
Marcus Frenkel
Experienced Solver
Experienced Solver
Posts: 79
Joined: Thu Sep 25, 2008 12:14 am

Post by Marcus Frenkel »

I did that but the application crashes when I use GetParser->.. on wxSimpleHtmlListBox. The debug points the break point at:

Code: Select all

.
.
for (i = 0; i < 7; i++)
m_FontsSizes[i] = sizes[i]; 
.
.
inside

Code: Select all

void wxHtmlWinParser::SetFonts(const wxString& normal_face,
                               const wxString& fixed_face,
                               const int *sizes)
Marcus Frenkel
Experienced Solver
Experienced Solver
Posts: 79
Joined: Thu Sep 25, 2008 12:14 am

Post by Marcus Frenkel »

Sorry to still bother with this. Whatever function I use from the parser (MySimpleHtmlListBox->m_HtmlParser->..) the application crashes. I guess that it can't be forcefully used as a public member without fixing some other stuff.

Marcus
chris_bern
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Mar 05, 2008 3:30 pm

Post by chris_bern »

I tried too and the Private to Public easy hack doesn't work. Sorry. You can use FONT tag for the list, it shouldn't impact the memory much. You can use wxNORMAL_FONT->GetPointSize() and wxNORMAL_FONT->GetPixelSize() and use it in the FONT tag accordingly.

Chris
Marcus Frenkel
Experienced Solver
Experienced Solver
Posts: 79
Joined: Thu Sep 25, 2008 12:14 am

Post by Marcus Frenkel »

Yeah I guess I have to use FONT tag for wxSimpleHtmlListBox as there is no <Default Font> solution for that. wxNORMAL_FONT->GetPixelSize() is helpful I only needed to increase it by two points (x&y) to get the same size like the default one. Thanks to tan I found GetParser function very helpful. There's a solution for wxHtmlWindow anyway - can't get all in your life.
Post Reply