mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-09-28 03:21:28 +08:00
Fix wxHTML line breaks around NBSP-only segments
Preserve non-breaking spaces in wxHtmlWinParser instead of converting them to normal spaces, and prevent wxHtmlWordCell from allowing a line break before NBSP-only text segments. Add a parser regression test covering an -only segment between words. Fixes #20399. Closes #26678.
This commit is contained in:
@@ -25,6 +25,29 @@
|
||||
#include "wx/html/winpars.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void AddTextCells(const wxHtmlCell *cell,
|
||||
std::vector<const wxHtmlCell *>& cells)
|
||||
{
|
||||
if ( !cell )
|
||||
return;
|
||||
|
||||
const wxString text = cell->ConvertToText(nullptr);
|
||||
if ( !text.empty() )
|
||||
cells.push_back(cell);
|
||||
|
||||
for ( const wxHtmlCell *child = cell->GetFirstChild(); child;
|
||||
child = child->GetNext() )
|
||||
{
|
||||
AddTextCells(child, cells);
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -89,6 +112,32 @@ TEST_CASE("wxHtmlParser::ImageAlignCenter", "[html][parser]")
|
||||
image->GetPosY() + image->GetHeight() / 2 );
|
||||
}
|
||||
|
||||
TEST_CASE("wxHtmlParser::NBSPLineBreak", "[html][parser]")
|
||||
{
|
||||
wxBitmap bmp(100, 100);
|
||||
wxMemoryDC dc(bmp);
|
||||
wxHtmlWinParser p;
|
||||
p.SetDC(&dc);
|
||||
|
||||
const wxString html = "aaa <font color=\"#ff0000\">"
|
||||
" </font>bbb";
|
||||
std::unique_ptr<wxHtmlContainerCell> const top(
|
||||
static_cast<wxHtmlContainerCell *>(p.Parse(html)));
|
||||
REQUIRE(top);
|
||||
|
||||
top->Layout(1);
|
||||
|
||||
std::vector<const wxHtmlCell *> cells;
|
||||
AddTextCells(top.get(), cells);
|
||||
|
||||
REQUIRE(cells.size() >= 3);
|
||||
CHECK(cells[0]->ConvertToText(nullptr) == "aaa ");
|
||||
CHECK(cells[1]->ConvertToText(nullptr) == wxString(L'\xa0', 2));
|
||||
CHECK(cells[2]->ConvertToText(nullptr) == "bbb");
|
||||
CHECK(cells[0]->GetAbsPos().y == cells[1]->GetAbsPos().y);
|
||||
CHECK(cells[1]->GetAbsPos().y == cells[2]->GetAbsPos().y);
|
||||
}
|
||||
|
||||
TEST_CASE("wxHtmlCell::Detach", "[html][cell]")
|
||||
{
|
||||
wxMemoryDC dc;
|
||||
|
||||
Reference in New Issue
Block a user