question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PIXI.Text letterSpacing

See original GitHub issue

Using the “letterSpacing”, PIXI.Text draws incorrectly

pixi-text

After viewing the source code and searching Google, I got to make it work correctly

pixi-text

I had to append the canvas in the document, otherwise it does not work. Any ideas on this?

canvas.style.letterSpacing = style.letterSpacing + 'px';
document.body.appendChild(canvas);
Text.prototype.drawLetterSpacing = function drawLetterSpacing(text, x, y) {
    var isStroke = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;

    var style = this._style;

    // letterSpacing of 0 means normal
    var letterSpacing = style.letterSpacing;

    // if (letterSpacing === 0) {
        if (isStroke) {
            this.context.strokeText(text, x, y);
        } else {
            this.context.fillText(text, x, y);
        }

        // return;
    // }

    // var characters = String.prototype.split.call(text, '');
    // var currentPosition = x;
    // var index = 0;
    // var current = '';
    //
    // while (index < text.length) {
    //     current = characters[index++];
    //     if (isStroke) {
    //         this.context.strokeText(current, currentPosition, y);
    //     } else {
    //         this.context.fillText(current, currentPosition, y);
    //     }
    //     currentPosition += this.context.measureText(current).width + letterSpacing;
    // }
};

I would also like to do something like this

canvas.style.mozOsxFontSmoothing = 'grayscale';
canvas.style.webkitFontSmoothing = 'antialiased';

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:22 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
gizmooocommented, Jan 29, 2018

It’s really worked https://jsfiddle.net/hg4pbsne/34/

1reaction
vereschagaicommented, Oct 16, 2018

@gizmooo It would be very helpful if you could make a PR for this problem, as It should help lots of users stop experiencing cutting off letters without workaround padding and improve general text look. It would be pleasant if you at least will share your solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PIXI.Text letterSpacing · Issue #4635 · pixijs/pixijs - GitHub
Using the "letterSpacing", PIXI.Text draws incorrectly After viewing the source code and searching Google, I got to make it work correctly I ...
Read more >
PIXI.TextStyle - PixiJS API Documentation
Documentation for PixiJS library. ... A TextStyle Object contains information to decorate a Text objects. ... letterSpacing, number, 0.
Read more >
PIXI.TextStyle Editor - PixiJS
PixiJS TextStyle ; Font · Font Size. Font Style · Font Variant · Font Weight ; Stroke. Color. Thickness. Line Join · Miter...
Read more >
Letterspacing with BitmapText - Pixi.js
Yea, but in my opionion letter spacing, in opposite to kerning, shouldn't be bound to glyph map, but rather to individual text field....
Read more >
@pixi/text-html - npm
Better support for emojis and other HTML layout features, better compatibility with CSS line-height and letter-spacing. Disadvantages: Unlike PIXI.Text , ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found