From d3931ea6603f0eb653789eda48f8c1ba04468802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kinaou=20Herv=C3=A9?= Date: Wed, 2 Dec 2015 23:53:00 +0100 Subject: [PATCH] Add support for CSS "color", "size" and "font" to wxHTML Simply map them to the existing HTML parameters, just as we already do for a few other styles. Closes #16773. --- docs/changes.txt | 1 + src/html/htmltag.cpp | 7 ++++++ src/html/m_fonts.cpp | 58 ++++++++++++++++++++++++++++++++++++++------ 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 74912e90ce..54528efea6 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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). diff --git a/src/html/htmltag.cpp b/src/html/htmltag.cpp index 7f6febb770..3d17acfee9 100644 --- a/src/html/htmltag.cpp +++ b/src/html/htmltag.cpp @@ -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; diff --git a/src/html/m_fonts.cpp b/src/html/m_fonts.cpp index 117f8faca9..6d039f99ae 100644 --- a/src/html/m_fonts.cpp +++ b/src/html/m_fonts.cpp @@ -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; }