Page MenuHomePhabricator

Incorrect text positioning in SVG rasterization (any extreme down scale) (fixed in upstream 2.40.13)
Closed, ResolvedPublic

Description

text with only 1 down scaled <rect> element 1:100

Problem version: File:Ikaros_solar_sail_key_plain.svg - with scale(.06) (= matrix(.06 0 ...)

Fixed version: File:Ikaros_solar_sail_key.svg - down scale removed

T36947: Incorrect text positioning in SVG rasterization (scale/transform; font-size; kerning) looks at first glance exactly, but these has other effects and very different cause. I've also analyzed some text problems from T19845: DejaVu Sans font renders incorrectly in SVG thumbnails, which was already fixed but someone has it reopened with other/this examples (DejaVu font) with other different issue, so I open this new general bug, because I found the concrete cause and can differentiate it clear.

I guess every font family is affected, the font-size is also irrelevant (all font related seems irrelevant, thats the main difference to T36947: Incorrect text positioning in SVG rasterization (scale/transform; font-size; kerning))

Every SVG element(regardless of whether text or not) that got a down scale 1 : >5 and lays under the text (in the code only) has a negative effect on the font rendering. The larger the down scaling the greater the effect.

Another example:
File:Glaubensartikel des Islam.svg (19:14, 6. Apr. 2014, that is fixed now) has rendered as
https://upload.wikimedia.org/wikipedia/commons/thumb/archive/b/b4/20140406212617!Glaubensartikel_des_Islam.svg/300px-Glaubensartikel_des_Islam.svg.png


Version: wmf-deployment
Severity: normal
URL: https://commons.wikimedia.org/wiki/File:Ikaros_solar_sail_key_plain.svg
See Also:
T36947: Incorrect text positioning in SVG rasterization (scale/transform; font-size; kerning)
T19845: DejaVu Sans font renders incorrectly in SVG thumbnails

Attached:

Comparison of broken and fixed renderings:

Details

Reference
bz63703

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 3:08 AM
bzimport set Reference to bz63703.
bzimport added a subscriber: Unknown Object (MLST).
Perhelion created this task.Apr 8 2014, 9:30 PM
Menner added a subscriber: Menner.May 7 2015, 10:12 PM

I can clearly reproduce when the reported issue takes place. It like comes from the two path elements between the two text elements containing main body. I suspect a wild pointer problem in the matrix attribute.

This bug at gnome shows also an issue with a matrix element: https://bugzilla.gnome.org/show_bug.cgi?id=634324

Menner added a comment.EditedMay 8 2015, 10:14 PM

The result to text elements is equal to multiplying font-size with scaling of previous path elements which leads to font hinting and upscaling text again to the intended font-size.

I've analyzed the code and circled the error in a function from rsvg-cairo-draw.c of librsvg

rsvg_cairo_render_path

By commenting out condition line at the beginning and end of this function for layer stack it fixes the problem.

if (need_tmpbuf)
    rsvg_cairo_push_discrete_layer (ctx);

Excluding this push-pop operation of context makes things like scaling permanent for path rendering.

Difficult to say if removing the condition has unforeseen consequences. I'll try it next week.

Menner set Security to None.
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJan 19 2016, 3:09 AM

Fix should be included in librsvg 2.40.13.

MvG added a subscriber: MvG.Jan 29 2016, 3:38 PM

I think that extreme scaling in either direction will cause problems. At least that's what I observed when this SVG got rendered like this. The setup here is that for mathematical reasons, the circles there have radius 1, so there is a scale factor of over 100 applied to the whole image via its viewBox. As a consequence, the vertical positioning in rsvg is too low, and within a span of text there apparently is no horizontal advancment between glyphs, so they all buch at the same position. Both of this could be either due to font metric getting rounded inappropriately, or due to some transformation not getting applied to said metrics. I managed to work around the issues in later versions by manually scaling the text part, but that's rather annoying. I have librsvg 2.40.13 installed locally, and at least my issue is not solved by that version.

Aklapper updated the task description. (Show Details)Mar 8 2016, 8:13 PM
Aklapper renamed this task from Incorrect text positioning in SVG rasterization (any extreme down scale) to Incorrect text positioning in SVG rasterization (any extreme down scale) (fixed in upstream 2.40.13).May 21 2016, 5:06 PM
Aklapper removed a subscriber: wikibugs-l-list.

That bug is partly fixed on the new jessie image scaler using 2.40.16 (tested locally, it's not yet pooled into the set of active scalers in production).
I have scaled "Hyperbolic ideal triangle and its incircle.svg" on the new and the present image scalers and put the results at https://people.wikimedia.org/~jmm/svg/ :

hyper-old.png is the result with the current scalers. hyper-new.png now has correct positions of the A,B,C,D points, but the "|AB| ≈ 0.55" etc. is still distorted. That's probably a separate bug to be reported upstream since 2.40.16 is the latest upstream release.

hyper-old.png is the result with the current scalers. hyper-new.png now has correct positions of the A,B,C,D points, but the "|AB| ≈ 0.55" etc. is still distorted. That's probably a separate bug to be reported upstream since 2.40.16 is the latest upstream release.

That is clear bug T36947 because font-size="0.12px" is used.

kaldari updated the task description. (Show Details)Jul 5 2016, 7:45 PM
Menner added a comment.Jul 6 2016, 8:13 PM

Please be patient and see T112421 in the meantime.

kaldari closed this task as Resolved.Aug 10 2016, 6:34 PM
kaldari claimed this task.

Looks like this is fixed now from my tests.