Bug 171805 - SVG textLength not working correctly
Summary: SVG textLength not working correctly
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2017-05-08 08:51 PDT by Jason Davies
Modified: 2023-01-14 13:29 PST (History)
20 users (show)

See Also:


Attachments
Minimal demonstration of textLength bug. (264 bytes, image/svg+xml)
2017-05-08 08:51 PDT, Jason Davies
no flags Details
Patch (3.20 KB, patch)
2022-06-02 07:11 PDT, Tom Bigelajzen
tombigel: review?
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Davies 2017-05-08 08:51:20 PDT
Created attachment 309363 [details]
Minimal demonstration of textLength bug.

Open the attached bug.svg file, containing <text textLength="1200">test</text>.

Notice how the right-hand edge of the text does not line up with the red rectangle.

I've reported the same bug for Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=719522

FireFox exhibits the correct behaviour.
Comment 1 Radar WebKit Bug Importer 2017-05-08 19:45:13 PDT
<rdar://problem/32066826>
Comment 2 Tom Bigelajzen 2022-06-02 07:11:17 PDT
Created attachment 459960 [details]
Patch
Comment 3 Tom Bigelajzen 2022-06-02 07:17:27 PDT
I created a minimal patch for this bug without tests etc. just to show that it's fixable by copying the logic from the Chromium bug fix from 5 years ago.

I don't have the time or knowledge to go through all the way with this patch (tests etc.) and will appreciate if someone with the right knowledge could complete the last mile with this fix
Comment 4 Said Abou-Hallawa 2022-09-06 13:46:18 PDT
Comment on attachment 459960 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=459960&action=review

> Source/WebCore/rendering/svg/SVGTextChunk.cpp:147
> +    float textLengthShift = desiredTextLength() - totalLength();
> +    if (totalCharacters() > 1) {
> +        textLengthShift /= totalCharacters() - 1;
> +    }

I think this code should look like this:

float textLengthShift = 0;
if (totalCharacters() > 1)
    textLengthShift = (desiredTextLength() - totalLength()) / (totalCharacters() - 1);

> Source/WebCore/rendering/svg/SVGTextLayoutEngine.cpp:210
> -    if (textContentElement->lengthAdjust() == SVGLengthAdjustSpacing)
> -        m_textPathSpacing = (desiredTextLength - totalLength) / totalCharacters;
> +    if (textContentElement->lengthAdjust() == SVGLengthAdjustSpacing && totalCharacters > 1)
> +        m_textPathSpacing = (desiredTextLength - totalLength) / (totalCharacters - 1);
>      else
>          m_textPathScaling = desiredTextLength / totalLength;

I think this if-statement should be like this:

    if (textContentElement->lengthAdjust() == SVGLengthAdjustSpacing) {
        if (totalCharacters > 1)
            m_textPathSpacing = (desiredTextLength - totalLength) / (totalCharacters - 1);
    } else
        m_textPathScaling = desiredTextLength / totalLength;
Comment 5 Said Abou-Hallawa 2022-09-06 13:48:02 PDT
(In reply to Tom Bigelajzen from comment #3)
> I created a minimal patch for this bug without tests etc. just to show that
> it's fixable by copying the logic from the Chromium bug fix from 5 years ago.
> 
> I don't have the time or knowledge to go through all the way with this patch
> (tests etc.) and will appreciate if someone with the right knowledge could
> complete the last mile with this fix

The failed tests need to be rebaslined since the inter-character spacing width has changed.
Comment 6 Ahmad Saleem 2023-01-14 02:50:41 PST
PR - https://github.com/WebKit/WebKit/pull/8655

Let's try..

@Said - I already took your review of this patch and incorporated it. :-)
Comment 7 EWS 2023-01-14 13:29:22 PST
Committed 258921@main (5c38a23d96c2): <https://commits.webkit.org/258921@main>

Reviewed commits have been landed. Closing PR #8655 and removing active labels.