Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple text Line Support #22

Open
kpomservices opened this issue Aug 23, 2021 · 6 comments
Open

Multiple text Line Support #22

kpomservices opened this issue Aug 23, 2021 · 6 comments

Comments

@kpomservices
Copy link

Is there is any option or way to generate svg path for multiple text lines?
Please suggest.

@danmarshall
Copy link
Owner

This may also mean that there would need to be a line-height parameter.

@kpomservices
Copy link
Author

kpomservices commented Aug 24, 2021

Yes exactly.

They used opentype-layout
https://maker.js.org/playground/?script=makerjs-wrap-text

Below is the code i used

   App.prototype.wrapText = function(font, text, fontSize, width, align, lineHeight) {
        //sample from https://github.com/Jam3/opentype-layout
        var scale = 1 / font.unitsPerEm * fontSize;
        var layoutOptions = {
            align,
            lineHeight: lineHeight * font.unitsPerEm,
            width: width / scale
        };

        var layout = computeLayout(font, text, layoutOptions);

        layout.glyphs.forEach((glyph, i) => {
            var character = makerjs.models.Text.glyphToModel(glyph.data, fontSize);
            character.origin = makerjs.point.scale(glyph.position, scale);
            makerjs.model.addModel(this, character, i);
        });

        //for seperate paths
        for (var i in this.models) {
            this.models[i].layer = i;
        }

        var svg = makerjs.exporter.toSVG(this);

        this.renderDiv.innerHTML = svg;
        this.outputTextarea.value = svg;
    }; 

@danmarshall
Copy link
Owner

Oh, right, there also is a width parameter. But I wonder if it would be easier to have a mutli-line textbox as input, then use line breaks for newlines?

@kpomservices
Copy link
Author

Width will be main input needed for opentype-layout, if we are providing line break then we need to calculate the width of the text entered (width of longer line in the multi-line) and send that width as input to opentype-layout.

@drone1
Copy link

drone1 commented Nov 2, 2022

Would also love this feature FWIW. Thanks.

@JxxIT
Copy link

JxxIT commented Apr 16, 2024

Hi, Are there any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants