Skip to content

Commit b2ce923

Browse files
author
zhangjipeng
committed
fix text and tspan redraw missing path bug.
1 parent ce7aefa commit b2ce923

3 files changed

Lines changed: 31 additions & 13 deletions

File tree

ext/svg/psx_svg_render.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ class svg_render_use : public render_obj_base
10941094

10951095
void get_xlink(void) const
10961096
{
1097-
if (!m_linked) {
1097+
if (!m_linked && m_xlink) {
10981098
render_obj_base* head = m_head;
10991099
while (head) {
11001100
if (head->id() && strcmp(m_xlink, head->id()) == 0) {
@@ -1264,8 +1264,12 @@ class svg_render_content : public render_obj_base
12641264
{
12651265
}
12661266

1267-
virtual void render_content(ps_context* ctx, ps_path* contents, ps_matrix* offset_matrix, float yoffset)
1267+
virtual void render_content(ps_context* ctx, ps_path* contents, ps_matrix* offset_matrix, float yoffset, bool rebuild_path)
12681268
{
1269+
if (!rebuild_path) {
1270+
return;
1271+
}
1272+
12691273
ps_path* glyph_path = ps_path_create();
12701274

12711275
ps_matrix* mtx = ps_matrix_create_copy(offset_matrix);
@@ -1348,19 +1352,21 @@ class svg_render_text : public render_obj_base
13481352
ps_font_info info;
13491353
ps_get_font_info(ctx, &info);
13501354

1355+
bool build_path = false;
13511356
if (ps_path_is_empty(m_path)) {
1352-
// FIXME: text and span redraw !!!!!!!!!!!!!!!!!
1353-
ps_matrix* mtx = ps_matrix_create();
1354-
ps_matrix_translate(mtx, m_x, m_y);
1355-
1356-
// draw text contents and spans
1357-
for (uint32_t i = 0; i < psx_array_size(&m_contents); i++) {
1358-
svg_render_content* content = *(psx_array_get(&m_contents, i, svg_render_content*));
1359-
content->render_content(ctx, m_path, mtx, -info.ascent);
1360-
}
1361-
ps_matrix_unref(mtx);
1357+
build_path = true;
13621358
}
13631359

1360+
ps_matrix* mtx = ps_matrix_create();
1361+
ps_matrix_translate(mtx, m_x, m_y);
1362+
1363+
// draw text contents and spans
1364+
for (uint32_t i = 0; i < psx_array_size(&m_contents); i++) {
1365+
svg_render_content* content = *(psx_array_get(&m_contents, i, svg_render_content*));
1366+
content->render_content(ctx, m_path, mtx, -info.ascent, build_path);
1367+
}
1368+
ps_matrix_unref(mtx);
1369+
13641370
ps_set_font(ctx, old_font);
13651371

13661372
ps_set_path(ctx, m_path);
@@ -1454,7 +1460,7 @@ class svg_render_tspan : public svg_render_content
14541460
this->svg_render_tspan::~svg_render_tspan();
14551461
}
14561462

1457-
virtual void render_content(ps_context* ctx, ps_path*, ps_matrix* offset_matrix, float)
1463+
virtual void render_content(ps_context* ctx, ps_path*, ps_matrix* offset_matrix, float, bool)
14581464
{
14591465
ps_save(ctx);
14601466
prepare(ctx);

unit_tests/ext_svg_render.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,18 @@ TEST_F(SVGRenderTest, TextTest)
414414
"</text></svg>";
415415
draw_svg(svg_text_gradient);
416416
EXPECT_SYS_SNAPSHOT_EQ(svg_text_gradient);
417+
418+
const char* svg_text_use_gradient = "<svg><defs><linearGradient id=\"g1\">"
419+
"<stop offset=\"0.1\" stop-color=\"blue\"/>"
420+
"<stop offset =\"0.8\" stop-color=\"red\"/>"
421+
"</linearGradient></defs>"
422+
"<text id=\"text1\" fill=\"url(#g1)\" x=20 y=60"
423+
" font-family=\"sans-serif\" font-size=\"48px\" font-weight=\"bold\">"
424+
"hello <tspan fill=\"green\" font-size=\"24px\">all</tspan> world"
425+
"</text><use x=\"20\" y=\"100\" xlink:href=\"#text1\"/></svg>";
426+
draw_svg(svg_text_use_gradient);
427+
EXPECT_SYS_SNAPSHOT_EQ(svg_text_use_gradient);
428+
417429
}
418430

419431
TEST_F(SVGRenderTest, ImageTest)
12.8 KB
Loading

0 commit comments

Comments
 (0)