Translate HTML Font size to pt 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
Natulux
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 242
Joined: Thu Aug 03, 2017 12:20 pm

Translate HTML Font size to pt

Post by Natulux »

Hey guys

Im playing with the wxRTC sample, which is able to save richtext into html by standard (I think it comes from wxFile or Dialog class).
I am trying to reverse that process and atm I am stuck at translating HTML font size (1-7) into point (pt) for setting correct sizes for the wxRTC.

Do you know any helping function or code to translate html font size into pt?
Or do you know where I get the source code of the saving function, so I can get an idea how the pt size of wxRTC is translated into html size, so I can reverse ingeneer it?
Or any hint in general?

Since there is a bunch of data to be considered (like screen resolution, monitor size, used font...) to do this manually, Im really hoping I don't need to.

Have my thanks.
Natu
User avatar
doublemax
Moderator
Moderator
Posts: 19161
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Translate HTML Font size to pt

Post by doublemax »

From the wxRTC sources:

Code: Select all

wxRichTextHTMLHandler::wxRichTextHTMLHandler(const wxString& name, const wxString& ext, int type)
    : wxRichTextFileHandler(name, ext, type), m_buffer(NULL), m_font(false), m_inTable(false)
{
    m_fontSizeMapping.Add(8);
    m_fontSizeMapping.Add(10);
    m_fontSizeMapping.Add(13);
    m_fontSizeMapping.Add(17);
    m_fontSizeMapping.Add(22);
    m_fontSizeMapping.Add(30);
    m_fontSizeMapping.Add(100);
}

Code: Select all

long wxRichTextHTMLHandler::PtToSize(long size)
{
    int i;
    int len = m_fontSizeMapping.GetCount();
    for (i = 0; i < len; i++)
        if (size <= m_fontSizeMapping[i])
            return i+1;
    return 7;
}
Use the source, Luke!
Natulux
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 242
Joined: Thu Aug 03, 2017 12:20 pm

Re: Translate HTML Font size to pt

Post by Natulux »

That's a nice one, have my thanks, doublemax.
Natulux
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 242
Joined: Thu Aug 03, 2017 12:20 pm

Re: Translate HTML Font size to pt

Post by Natulux »

For completeness sake, this seems to be what browser tools advise or take for you:

1: 8pt
2: 10pt
3: 12pt
4: 14pt
5: 18pt
6: 24pt
7: 36pt

I guess this will change from time to time, but for now it suits our needs.

Have a good one
Natu
Post Reply