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:

svg-bug-T65703.png (516×644 px, 129 KB)

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).

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

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.

Fix should be included in librsvg 2.40.13.

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 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.

Please be patient and see T112421 in the meantime.

kaldari claimed this task.

Looks like this is fixed now from my tests.