From b6d93b260ee0e8a145b8965da7e8eef1fed17670 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Tue, 15 Jul 2003 18:39:09 +0000 Subject: [PATCH] don't break lines in the middle of word git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22002 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/html/htmlcell.cpp | 30 +++++++++++++++++++++++++++--- src/html/winpars.cpp | 9 ++++++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/html/htmlcell.cpp b/src/html/htmlcell.cpp index bf9750d649..7a4ff817a3 100644 --- a/src/html/htmlcell.cpp +++ b/src/html/htmlcell.cpp @@ -264,8 +264,17 @@ wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell() m_Word = word; dc.GetTextExtent(m_Word, &m_Width, &m_Height, &m_Descent); SetCanLiveOnPagebreak(FALSE); + m_allowLinebreak = true; } +void wxHtmlWordCell::SetPreviousWord(wxHtmlWordCell *cell) +{ + if ( cell && m_Parent == cell->m_Parent && + !wxIsspace(cell->m_Word.Last()) && !wxIsspace(m_Word[0u]) ) + { + m_allowLinebreak = false; + } +} // Splits m_Word into up to three parts according to selection, returns // substring before, in and after selection and the points (in relative coords) @@ -629,9 +638,10 @@ void wxHtmlContainerCell::Layout(int w) } wxHtmlCell *cell = m_Cells, *line = m_Cells; + wxHtmlCell *nextCell; long xpos = 0, ypos = m_IndentTop; int xdelta = 0, ybasicpos = 0, ydiff; - int s_width, s_indent; + int s_width, nextWordWidth, s_indent; int ysizeup = 0, ysizedown = 0; int MaxLineWidth = 0; int xcnt = 0; @@ -686,13 +696,27 @@ void wxHtmlContainerCell::Layout(int w) if (cell->GetDescent() + ydiff > ysizedown) ysizedown = cell->GetDescent() + ydiff; if (ybasicpos + cell->GetDescent() < -ysizeup) ysizeup = - (ybasicpos + cell->GetDescent()); + // layout nonbreakable run of cells: cell->SetPos(xpos, ybasicpos + cell->GetDescent()); xpos += cell->GetWidth(); cell = cell->GetNext(); xcnt++; - + + // compute length of the next word that would be added: + nextWordWidth = 0; + if (cell) + { + nextCell = cell; + do + { + nextWordWidth += nextCell->GetWidth(); + nextCell = nextCell->GetNext(); + } while (nextCell && !nextCell->IsLinebreakAllowed()); + } + // force new line if occured: - if ((cell == NULL) || (xpos + cell->GetWidth() > s_width)) + if ((cell == NULL) || + (xpos + nextWordWidth > s_width && cell->IsLinebreakAllowed())) { if (xpos > MaxLineWidth) MaxLineWidth = xpos; if (ysizeup < 0) ysizeup = 0; diff --git a/src/html/winpars.cpp b/src/html/winpars.cpp index 8410b01988..ce73fbcfd4 100644 --- a/src/html/winpars.cpp +++ b/src/html/winpars.cpp @@ -54,6 +54,7 @@ wxHtmlWinParser::wxHtmlWinParser(wxHtmlWindow *wnd) : wxHtmlParser() m_InputEnc = wxFONTENCODING_ISO8859_1; m_OutputEnc = wxFONTENCODING_DEFAULT; #endif + m_lastWordCell = NULL; { int i, j, k, l, m; @@ -170,6 +171,7 @@ void wxHtmlWinParser::InitParser(const wxString& source) m_ActualColor.Set(0, 0, 0); m_Align = wxHTML_ALIGN_LEFT; m_tmpLastWasSpace = FALSE; + m_lastWordCell = NULL; OpenContainer(); OpenContainer(); @@ -278,9 +280,6 @@ void wxHtmlWinParser::AddText(const wxChar* txt) { temp[templen-1] = wxT(' '); temp[templen] = 0; -#if 0 // VS - WHY was this here?! - if (templen == 1) continue; -#endif templen = 0; #if !wxUSE_UNICODE if (m_EncConv) @@ -294,6 +293,8 @@ void wxHtmlWinParser::AddText(const wxChar* txt) if (m_UseLink) c->SetLink(m_Link); m_Container->InsertCell(c); + ((wxHtmlWordCell*)c)->SetPreviousWord(m_lastWordCell); + m_lastWordCell = (wxHtmlWordCell*)c; m_tmpLastWasSpace = TRUE; } } @@ -313,6 +314,8 @@ void wxHtmlWinParser::AddText(const wxChar* txt) if (m_UseLink) c->SetLink(m_Link); m_Container->InsertCell(c); + ((wxHtmlWordCell*)c)->SetPreviousWord(m_lastWordCell); + m_lastWordCell = (wxHtmlWordCell*)c; m_tmpLastWasSpace = FALSE; } } -- 2.47.2