Add support for CSS "color", "size" and "font" to wxHTML <font>

Simply map them to the existing HTML parameters, just as we already do for a
few other styles.

Closes #16773.
This commit is contained in:
Kinaou Hervé 2015-12-02 23:53:00 +01:00 committed by Vadim Zeitlin
parent 0ed580f451
commit d3931ea660
3 changed files with 59 additions and 7 deletions

View File

@ -98,6 +98,7 @@ All (GUI):
- Make results of wxDC::DrawEllipticArc() consistent across all platforms.
- XRC handler for wxAuiToolBar added (Kinaou Hervé, David Hart).
- Improve wxLIST_AUTOSIZE_XXX support in generic wxListCtrl (Kinaou Hervé).
- Support "color", "size" and "font" CSS for fonts in wxHTML (Kinaou Hervé).
- Add wxCursor::GetHotSpot().
- Add wxFD_NO_FOLLOW style for wxFileDialog (Luca Bacci).
- Add support for embedding bitmaps in generated SVG in wxSVGFileDC (iwbnwif).

View File

@ -464,6 +464,9 @@ wxHtmlTag::wxHtmlTag(wxHtmlTag *parent,
{ "vertical-align", "VALIGN" },
{ "background", "BGCOLOR" },
{ "background-color", "BGCOLOR" },
{ "color", "COLOR" },
{ "size", "SIZE" },
{ "face", "FACE" },
};
wxHtmlStyleParams styleParams(*this);
@ -613,6 +616,10 @@ wxHtmlTag::GetParamAsIntOrPercent(const wxString& par,
{
isPercent = true;
}
else if ( param.EndsWith("px", &num) )
{
isPercent = false;
}
else
{
isPercent = false;

View File

@ -21,6 +21,7 @@
#include "wx/html/m_templ.h"
#include "wx/fontenum.h"
#include "wx/tokenzr.h"
#include "wx/html/styleparams.h"
FORCE_LINK_ME(m_fonts)
@ -35,9 +36,19 @@ TAG_HANDLER_BEGIN(FONT, "FONT" )
TAG_HANDLER_PROC(tag)
{
wxColour oldclr = m_WParser->GetActualColor();
wxColour oldbackclr = m_WParser->GetActualBackgroundColor();
int oldbackmode = m_WParser->GetActualBackgroundMode();
int oldsize = m_WParser->GetFontSize();
int oldbold = m_WParser->GetFontBold();
int olditalic = m_WParser->GetFontItalic();
int oldunderlined = m_WParser->GetFontUnderlined();
wxString oldface = m_WParser->GetFontFace();
// Load any style parameters
wxHtmlStyleParams styleParams(tag);
ApplyStyle(styleParams);
{
wxColour clr;
if (tag.GetParamAsColour(wxT("COLOR"), &clr))
@ -45,6 +56,11 @@ TAG_HANDLER_BEGIN(FONT, "FONT" )
m_WParser->SetActualColor(clr);
m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr));
}
if (tag.GetParamAsColour(wxT("BGCOLOR"), &clr))
{
m_WParser->SetActualBackgroundColor(clr);
m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr, wxHTML_CLR_BACKGROUND));
}
}
{
@ -84,14 +100,33 @@ TAG_HANDLER_BEGIN(FONT, "FONT" )
ParseInner(tag);
if (oldface != m_WParser->GetFontFace())
if ((oldface != m_WParser->GetFontFace()) ||
(oldunderlined != m_WParser->GetFontUnderlined()) ||
(olditalic != m_WParser->GetFontItalic()) ||
(oldbold != m_WParser->GetFontBold()) ||
(oldsize != m_WParser->GetFontSize()))
{
m_WParser->SetFontFace(oldface);
m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
}
if (oldsize != m_WParser->GetFontSize())
{
m_WParser->SetFontSize(oldsize);
if (oldface != m_WParser->GetFontFace())
{
m_WParser->SetFontFace(oldface);
}
if (oldunderlined != m_WParser->GetFontUnderlined())
{
m_WParser->SetFontUnderlined(oldunderlined);
}
if (olditalic != m_WParser->GetFontItalic())
{
m_WParser->SetFontItalic(olditalic);
}
if (oldbold != m_WParser->GetFontBold())
{
m_WParser->SetFontBold(oldbold);
}
if (oldsize != m_WParser->GetFontSize())
{
m_WParser->SetFontSize(oldsize);
}
m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
}
if (oldclr != m_WParser->GetActualColor())
@ -99,6 +134,15 @@ TAG_HANDLER_BEGIN(FONT, "FONT" )
m_WParser->SetActualColor(oldclr);
m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr));
}
if (oldbackmode != m_WParser->GetActualBackgroundMode() ||
oldbackclr != m_WParser->GetActualBackgroundColor())
{
m_WParser->SetActualBackgroundMode(oldbackmode);
m_WParser->SetActualBackgroundColor(oldbackclr);
m_WParser->GetContainer()->InsertCell(
new wxHtmlColourCell(oldbackclr, oldbackmode == wxTRANSPARENT ? wxHTML_CLR_TRANSPARENT_BACKGROUND : wxHTML_CLR_BACKGROUND));
}
return true;
}