Discussion:
How can I get the font information for a wxHtmlWindow?
'Ray Satiro' via wx-users
2014-08-26 18:48:35 UTC
Permalink
Is there a way to get the font information for a wxHtmlWindow? I'm using wxWidgets built from master branch commit a307120 20140818. I'm adding a font picker to the app I'm working on allow the user to change the font face and size for an wxHtmlWindow. I would like to get whatever font the wxHtmlWindow is set to and then set the font picker to that font face and size so that when the picker is opened it shows the currently applied font. I tried GetFont() but it always returns the same thing and not what is actually set. To workaround what I am going to do is after the first time the user uses the font picker I'll record what they selected and save that information so the next time it is opened I can set it to what they last selected. But I don't have the information for the initial opening.

I set the selected face and size using SetStandardFonts(). Another thing I've noticed is the size I set appears much smaller in the wxHtmlWindow. To workaround that I can add a some points to the point size, but I'm curious why that is or if anyone has encountered something similar. A lot of the html has a relative font tag size -1 but still it seems quite a few points small.

Does anyone have a link to documentation of SetFonts()? I've read wxHtmlDCRenderer::SetFonts() [1] and it says the sizes are set using wxHTML_FONT_SIZE_1, etc. but I can't find those defined anywhere. It also doesn't say whether it needs point size or pixel size. I'm not using SetFonts() yet but I am looking into it to see if something in the array of sizes is why when I set a font size it appears much smaller. I was thinking if someone set a font like 14 for example I could do an array of {12,13,14,15,16,17,18} to represent the HTML relative sizes of {-2,-1,0,1,2,3,4} unless that isn't advised maybe because there is more distance needed between sizes or wxWidgets auto adjusts that array automatically when SetStandardFonts() is called? Can I get the current settings for that array and should I adjust it manually?

Thanks


[1]: http://docs.wxwidgets.org/trunk/classwx_html_d_c_renderer.html#a70cfd1cd9f25f91afe40694466b70f7a
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2014-08-28 11:43:32 UTC
Permalink
On Tue, 26 Aug 2014 11:48:35 -0700 Ray Satiro wrote:

RS> Is there a way to get the font information for a wxHtmlWindow?

No, this doesn't really make sense.

RS> I set the selected face and size using SetStandardFonts(). Another
RS> thing I've noticed is the size I set appears much smaller in the
RS> wxHtmlWindow.

Much smaller compared to what?

RS> Does anyone have a link to documentation of SetFonts()? I've read
RS> wxHtmlDCRenderer::SetFonts()

The documentation really needs to be improved here, it doesn't correspond
to how the code works (any more).

RS> [1] and it says the sizes are set using
RS> wxHTML_FONT_SIZE_1, etc. but I can't find those defined anywhere.

They can be found in src/html/winpars.cpp but I'm not sure we really want
to document, or even make public, their exact values, they may change.

RS> It also doesn't say whether it needs point size or pixel size.

Points (always by default).

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
'Ray Satiro' via wx-users
2014-08-29 07:14:06 UTC
Permalink
Post by Vadim Zeitlin
RS> Is there a way to get the font information for a wxHtmlWindow?
No, this doesn't really make sense.
Why not?
Post by Vadim Zeitlin
RS> I set the selected face and size using SetStandardFonts(). Another
RS> thing I've noticed is the size I set appears much smaller in the
RS> wxHtmlWindow.
Much smaller compared to what?
I think what I observed was because the HTML font size was set to a
relative -1 which I've learned after reading the source code you
referenced is like 83% of the normal size so it's more than just a point
down.
Post by Vadim Zeitlin
They can be found in src/html/winpars.cpp but I'm not sure we really want
to document, or even make public, their exact values, they may change.
Thanks for that. After reviewing that code, wxHtmlWinParser and
wxHtmlWindow I've established that I can get the wxHtmlWinParser by
using wxHtmlWindow::GetParser(). That doesn't appear to be documented [1].

// Returns a pointer to the parser.
wxHtmlWinParser *GetParser() const { return m_Parser; }

I can get the faces by calling wxHtmlWinParser::GetFontFace() which will
return either the normal font face or the fixed font face depending on
what's in use if I understand correctly. That also doesn't appear to be
documented [2].

wxString GetFontFace() const {return GetFontFixed() ?
m_FontFaceFixed : m_FontFaceNormal;}

So in order to retrieve both faces I can do something like this:

wxString fixed, normal;
wxHtmlWinParser &parser = *html->GetParser();
int is_fixed = parser.GetFontFixed();

(is_fixed ? fixed : normal) = parser.GetFontFace();
parser.SetFontFixed(!is_fixed);
(!is_fixed ? fixed : normal) = parser.GetFontFace();
parser.SetFontFixed(is_fixed);

I've attached a minimal example that shows this. Getting the point size
is a little more difficult, there doesn't seem to be a way to do that
without first setting the HTML relative font size to 0 and then calling
CreateCurrentFont() and I had a problem with a dangling device context
pointer when I tried that [3].

I'm thinking I will probably initialize my font picker using
wxNORMAL_FONT (since I now know that is what the HTML parser uses by
default), and then I will save the information from the font picker and
restore it if the picker is reopened rather than mess with the parser.
Thanks for your help.


[1]: http://docs.wxwidgets.org/trunk/classwx_html_window.html
[2]:
http://docs.wxwidgets.org/trunk/classwx_html_win_parser.html#ad22d30ddb714b8421daed468661d63b9
[3]: http://trac.wxwidgets.org/ticket/16501
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2014-08-29 11:58:51 UTC
Permalink
On Fri, 29 Aug 2014 03:14:06 -0400 Ray Satiro wrote:

RS> On 8/28/2014 7:43 AM, Vadim Zeitlin wrote:
RS> > RS> Is there a way to get the font information for a wxHtmlWindow?
RS> >
RS> > No, this doesn't really make sense.
RS>
RS> Why not?

Because wxHtmlWindow doesn't have a single font, so using GetFont() can't
return anything useful. In fact, just about any font can be used inside
wxHtmlWindow...

RS> Thanks for that. After reviewing that code, wxHtmlWinParser and
RS> wxHtmlWindow I've established that I can get the wxHtmlWinParser by
RS> using wxHtmlWindow::GetParser(). That doesn't appear to be documented [1].
RS>
RS> // Returns a pointer to the parser.
RS> wxHtmlWinParser *GetParser() const { return m_Parser; }
RS>
RS> I can get the faces by calling wxHtmlWinParser::GetFontFace() which will
RS> return either the normal font face or the fixed font face depending on
RS> what's in use if I understand correctly. That also doesn't appear to be
RS> documented [2].

I am not sure if it's not intentional. I.e. I don't think this stuff is
really meant to be public in the first place.

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Loading...