microsoft / maker.js

πŸ“βš™ 2D vector line drawing and shape modeling for CNC and laser cutters.
http://maker.js.org
Apache License 2.0
1.78k stars 275 forks source link

How to export SVG with right aligned text ? #452

Open amatyat opened 4 years ago

amatyat commented 4 years ago

How to export SVG with right-aligned text (Arabic)? Below code generate left-aligned text :

var makerjs = require('makerjs')
var textModel;

opentype.load('fonts/Roboto-Black.ttf', function(err, font) {
    if (err)
    {
                alert('Could not load font: ' + err);
    }
    else
    {
        var text = 'Hello World! This box should start word-wrapping!';
                textModel = new makerjs.models.Text(font, text, 45, true, true);
        var svg = makerjs.exporter.toSVG(textModel,{stroke: '#000', fill: '#000'});
        document.write(svg);
    }
danmarshall commented 4 years ago

Hello, just to clarify do you mean right-to-left text?

amatyat commented 4 years ago

Right aligned text. Like below :

image

and right-to-left text. Both.

danmarshall commented 4 years ago

First, see this issue comment about using the opentype-layout library for opentype.js

Then, check out the readme for computeLayout which has an align option.

For right-to-left, this should be supported by opentype.js. It’s possible that our copy of opentype.js for the Playground may need to be updated, please let me know or send a PR 😁

amatyat commented 4 years ago

For right-to-left, could you please share an example of how to use it?