diff --git a/docs/changes.txt b/docs/changes.txt index 63874ece34..0658895d6c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -103,6 +103,7 @@ All (GUI): - 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é). +- Fix one pixel gaps between consecutive underlined words in wxHTML. - 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/include/wx/html/htmlcell.h b/include/wx/html/htmlcell.h index 4bc9299934..f4190de427 100644 --- a/include/wx/html/htmlcell.h +++ b/include/wx/html/htmlcell.h @@ -125,7 +125,12 @@ public: class WXDLLIMPEXP_HTML wxHtmlRenderingInfo { public: - wxHtmlRenderingInfo() : m_selection(NULL), m_style(NULL) {} + wxHtmlRenderingInfo() + : m_selection(NULL), + m_style(NULL), + m_prevUnderlined(false) + { + } void SetSelection(wxHtmlSelection *s) { m_selection = s; } wxHtmlSelection *GetSelection() const { return m_selection; } @@ -133,12 +138,16 @@ public: void SetStyle(wxHtmlRenderingStyle *style) { m_style = style; } wxHtmlRenderingStyle& GetStyle() { return *m_style; } + void SetCurrentUnderlined(bool u) { m_prevUnderlined = u; } + bool WasPreviousUnderlined() const { return m_prevUnderlined; } + wxHtmlRenderingState& GetState() { return m_state; } protected: wxHtmlSelection *m_selection; wxHtmlRenderingStyle *m_style; wxHtmlRenderingState m_state; + bool m_prevUnderlined; }; diff --git a/src/html/htmlcell.cpp b/src/html/htmlcell.cpp index ed3b2d8373..6000a004c8 100644 --- a/src/html/htmlcell.cpp +++ b/src/html/htmlcell.cpp @@ -480,6 +480,25 @@ void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, wxHtmlSelectionState selstate = info.GetState().GetSelectionState(); // Not changing selection state, draw the word in single mode: SwitchSelState(dc, info, selstate != wxHTML_SEL_OUT); + + // This is a quite horrible hack but it fixes a nasty user-visible + // problem: when drawing underlined text, which is common in wxHTML as + // all links are underlined, there is a 1 pixel gap between the + // underlines because we draw separate words in separate DrawText() + // calls. The right thing to do would be to draw all of them appearing + // on the same line at once (this would probably be more efficient as + // well), but this doesn't seem simple to do, so instead we just draw + // an extra space at a negative offset to ensure that the underline + // spans the previous pixel and so overlaps the one from the previous + // word, if any. + const bool prevUnderlined = info.WasPreviousUnderlined(); + const bool thisUnderlined = dc.GetFont().GetUnderlined(); + if ( prevUnderlined && thisUnderlined ) + { + dc.DrawText(wxS(" "), x + m_PosX - 1, y + m_PosY); + } + info.SetCurrentUnderlined(thisUnderlined); + dc.DrawText(m_Word, x + m_PosX, y + m_PosY); drawSelectionAfterCell = (selstate != wxHTML_SEL_OUT); }