Skip to content

Text on paths#6543

Merged
asturur merged 21 commits into
masterfrom
text-on-a-path-attempts
Oct 26, 2020
Merged

Text on paths#6543
asturur merged 21 commits into
masterfrom
text-on-a-path-attempts

Conversation

@asturur

@asturur asturur commented Aug 24, 2020

Copy link
Copy Markdown
Member

@melchiar This PR contains the progress of text on a path, that i started right now.
i ll push up every time i do a small progress.

closes #729
closes #5900
closes #2544

@asturur

asturur commented Aug 24, 2020

Copy link
Copy Markdown
Member Author

step 1, we are here:

image

that is not bad, if you look at the commit changes.

@melchiar

Copy link
Copy Markdown
Contributor

looking good so far 👍

In having path be a property of text, will the path itself to be styleable (ie. strokes, fills), or will it just be used for text coordinates? (similar to how clipPaths aren't styleable)

@asturur

asturur commented Aug 25, 2020

Copy link
Copy Markdown
Member Author

image

step 2!

@asturur

asturur commented Aug 25, 2020

Copy link
Copy Markdown
Member Author

@melchiar let's see where we get, is all yet to be decided. having the path renderable makes things easier for devs, rather than aligning objects.

@emielmolenaar

Copy link
Copy Markdown

Awesome work! My math skills are a bit meh, but when I see chance to collaborate on this one I will.

@asturur

asturur commented Aug 25, 2020

Copy link
Copy Markdown
Member Author

Another small improvement.
image

Next thing i would look at is the bounding box.

@asturur

asturur commented Aug 26, 2020

Copy link
Copy Markdown
Member Author

image

@andrewzolotukhin

Copy link
Copy Markdown

Looks great!

@stale

stale Bot commented Sep 11, 2020

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale Issue marked as stale by the stale bot label Sep 11, 2020
@stale stale Bot closed this Sep 18, 2020
@melchiar melchiar reopened this Sep 18, 2020
@stale stale Bot removed the stale Issue marked as stale by the stale bot label Sep 18, 2020
@asturur

asturur commented Sep 18, 2020

Copy link
Copy Markdown
Member Author

Yeah i have to get back to this, i m really under a train of work lately

@thobn24h

Copy link
Copy Markdown

Impressive !
@asturur, Have you had any draft document or guideline about this new feature, yet?

@asturur

asturur commented Sep 28, 2020

Copy link
Copy Markdown
Member Author

Isn't working properly yet. the idea is to get underline/striketrough/overline working and the release for text only, meaning that for Itext and textbox will work badly and is on the dev to not update it.

thereisn't match to say about it, you take a fabric.Path, and you do Text.set('path', myPath) that's it.
No options for now about being over or under the path.

@asturur

asturur commented Oct 3, 2020

Copy link
Copy Markdown
Member Author

Ok after long time, here i am back.
I changed the implementation to be a measure time more than at render time.
Added support for text decoration.
Now i will write tests and merge as it is, then improve.
Next step is correct bounding box.
Then multi line.

Editing will come later or maybe not come at all, since is really edgy.

@asturur

asturur commented Oct 3, 2020

Copy link
Copy Markdown
Member Author

This is with underline and overline applied

image

@asturur

asturur commented Feb 19, 2021

Copy link
Copy Markdown
Member Author

no not yet

@vijaygurjar

vijaygurjar commented Feb 24, 2021

Copy link
Copy Markdown

Hello
I want to scale path not textbox. After scale how i will get updated path co-ordinates or (path string) and also i want to align text like right,center,left.
Sample fiddle:
https://jsfiddle.net/vijaygurjar/9mtcuzv4/18/

Require output like below:
sample

@billensley

billensley commented Feb 24, 2021 via email

Copy link
Copy Markdown

@asturur

asturur commented Feb 24, 2021

Copy link
Copy Markdown
Member Author

@vijaygurjar transforming a fabric path to a scaled path is entirely possible with fabric tools is not something i can explain in a message or an email.
You have to look for transformPoint util and transform each point of the path ( including controls point ).

@fran1990Web

Copy link
Copy Markdown

Thanks you @asturur for the work.
This solution. Could be apply on Textbox?
Thanks you very much!

@asturur

asturur commented Mar 4, 2021

Copy link
Copy Markdown
Member Author

Editing still does not work properly.

@fran1990Web

Copy link
Copy Markdown

Thanks you @asturur. Do you think this could be a new feature to add? Meanwhile I can use it in text :)

@asturur

asturur commented Mar 4, 2021

Copy link
Copy Markdown
Member Author

yes it will. My priority is RTL support and fixing something in selections interactions

@fran1990Web

Copy link
Copy Markdown

Thanks! :)

@melchiar

melchiar commented Jun 17, 2021

Copy link
Copy Markdown
Contributor

I've just opened a discussion thread for textAlign and startOffset support if anyone cares to provide feedback.
#7128

edit - side has now been added as well

You're welcome to experiment with my work in progress integration of these features:
https://jsfiddle.net/melchiar/vhgtesoy/

image

@billensley

billensley commented Jun 17, 2021 via email

Copy link
Copy Markdown

@tran-ngoc-phuong-dang

Copy link
Copy Markdown

Has there been any new progress on this? When will this have support for SVG export?

@melchiar

Copy link
Copy Markdown
Contributor

The next release will include additional property support for textAlign, pathStartOffset, and pathSide, along with a util for transforming path data. They're in the current master branch if you want to grab them early, otherwise the next release should be here soon.

No work done yet on svg export though as it hasn't been a priority.

@tran-ngoc-phuong-dang

Copy link
Copy Markdown

hi. Any news on the svg export for this feature? What's the next update for the textpath?

@melchiar

Copy link
Copy Markdown
Contributor

No news on svg yet.

@emielmolenaar

emielmolenaar commented Nov 2, 2021

Copy link
Copy Markdown

We have been experimenting with text on paths and we use this to properly export text on paths to SVG:

fabric.Text.prototype._wrapSVGTextAndBg = function (textAndBg) {
    var noShadow = true, textDecoration = this.getSvgTextDecoration(this);

    const elements = [
        textAndBg.textBgRects.join(''),
        '\t\t<text xml:space="preserve" ',
        (this.fontFamily ? 'font-family="' + this.fontFamily.replace(/"/g, '\'') + '" ' : ''),
        (this.fontSize ? 'font-size="' + this.fontSize + '" ' : ''),
        (this.fontStyle ? 'font-style="' + this.fontStyle + '" ' : ''),
        (this.fontWeight ? 'font-weight="' + this.fontWeight + '" ' : ''),
        (textDecoration ? 'text-decoration="' + textDecoration + '" ' : ''),
        'style="', this.getSvgStyles(noShadow), '"', this.addPaintOrder(), ' >',
    ];

    if (!this.path) {
        elements.push(textAndBg.textSpans.join(''));
    } else {
        /**
         * There is a path, make sure that:
         *
         * 1. A <textpath> surrounds the tspans containing a link to the <path>
         * 2. Every X and Y of every <tspan> is 0
         * 3. The <path> is added
         */
        const id = Date.now() + '-' + Math.random().toString(36).substr(2, 9);

        elements.push('<textPath xlink:href="#path-' + id + '">');
        elements.push(textAndBg.textSpans.join('').replace(/x="[^"]+"/, 'x="0"').replace(/y="[^"]+"/, 'y="0"'));
        elements.push('</textPath>');

        const path = this.path.path
            .map(function (path) {
                return path.join(' ');
            })
            .join(' ');

        elements.push('<path id="path-' + id + '" d="' + path + '" fill="none"></path>');
    }

    elements.push('</text>\n');

    return elements;
}

Although it is a bit hacky (especially the coordinate replacing with regexes), this works for us. Maybe this might be helpful for others.

@mafna-air

Copy link
Copy Markdown

thank you. Hope there will be official support for svg export soon.

@tran-ngoc-phuong-dang

Copy link
Copy Markdown

has there been any more progress on this feature? With the SVG export function?

@egemenerd

Copy link
Copy Markdown

@av01d

av01d commented Jun 19, 2023

Copy link
Copy Markdown

This looks interesting;

https://stackblitz.com/edit/web-platform-n8kzvg?file=script.js

This does indeed look promising. But it isn't finished yet, you can't move/resize the curved text and the toSVG function doesn't yield results (yet). Hopefully the creator of this code will keep working on it...

@umashankar-pardhi-amla

Copy link
Copy Markdown

Any update on SVG export? Text on path

@ShaMan123

Copy link
Copy Markdown
Contributor

If you are using node I can point out a solution

@umashankar-pardhi-amla

Copy link
Copy Markdown

@ShaMan123 : Yes please

@ShaMan123

Copy link
Copy Markdown
Contributor

#9185 is what you need, look at the repro in the description for POC

@ShaMan123

Copy link
Copy Markdown
Contributor

I am not sure about rendering to text though (paths work), you will need to investigate if that is important for you

@umashankar-pardhi-amla

Copy link
Copy Markdown

@emielmolenaar emielmolenaar : The SVG is rendering, but it's not positioned correctly. Could you explain how you've configured the object, including user selection, scaling, and all? I'd appreciate your help with this.

We have been experimenting with text on paths and we use this to properly export text on paths to SVG:

fabric.Text.prototype._wrapSVGTextAndBg = function (textAndBg) {
    var noShadow = true, textDecoration = this.getSvgTextDecoration(this);

    const elements = [
        textAndBg.textBgRects.join(''),
        '\t\t<text xml:space="preserve" ',
        (this.fontFamily ? 'font-family="' + this.fontFamily.replace(/"/g, '\'') + '" ' : ''),
        (this.fontSize ? 'font-size="' + this.fontSize + '" ' : ''),
        (this.fontStyle ? 'font-style="' + this.fontStyle + '" ' : ''),
        (this.fontWeight ? 'font-weight="' + this.fontWeight + '" ' : ''),
        (textDecoration ? 'text-decoration="' + textDecoration + '" ' : ''),
        'style="', this.getSvgStyles(noShadow), '"', this.addPaintOrder(), ' >',
    ];

    if (!this.path) {
        elements.push(textAndBg.textSpans.join(''));
    } else {
        /**
         * There is a path, make sure that:
         *
         * 1. A <textpath> surrounds the tspans containing a link to the <path>
         * 2. Every X and Y of every <tspan> is 0
         * 3. The <path> is added
         */
        const id = Date.now() + '-' + Math.random().toString(36).substr(2, 9);

        elements.push('<textPath xlink:href="#path-' + id + '">');
        elements.push(textAndBg.textSpans.join('').replace(/x="[^"]+"/, 'x="0"').replace(/y="[^"]+"/, 'y="0"'));
        elements.push('</textPath>');

        const path = this.path.path
            .map(function (path) {
                return path.join(' ');
            })
            .join(' ');

        elements.push('<path id="path-' + id + '" d="' + path + '" fill="none"></path>');
    }

    elements.push('</text>\n');

    return elements;
}

Although it is a bit hacky (especially the coordinate replacing with regexes), this works for us. Maybe this might be helpful for others.

@aswanth6000

Copy link
Copy Markdown
Screenshot 2024-04-16 223348 How can i add control points like this, like in the middle of the text.

@00cyberghost

Copy link
Copy Markdown

Screenshot 2024-04-16 223348 How can i add control points like this, like in the middle of the text.

i am also interested in this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to Generate Curved Text ? SVG text on path is not working Curve Text Feature [$200]