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

Kerning #17

Closed
lojjic opened this issue May 28, 2020 · 6 comments
Closed

Kerning #17

lojjic opened this issue May 28, 2020 · 6 comments
Labels
feature request New feature or request

Comments

@lojjic
Copy link

lojjic commented May 28, 2020

I've noticed that neither of the text implementations honor kerning offsets for glyph pairs. I'm not sure if the current font encoding carries kerning information, but if it does then honoring that would be a significant improvement.

@felixmariotto felixmariotto added the feature request New feature or request label May 28, 2020
@felixmariotto
Copy link
Owner

Thanks for pointing this out, it should be supported at some point.

@trusktr
Copy link
Contributor

trusktr commented Jun 14, 2020

Troika's TextMesh supports this it seems. Worth looking into. @lojjic Would you be willing to try importing that here and hooking it in?

@felixmariotto
Copy link
Owner

felixmariotto commented Jun 14, 2020

It's not worth creating a dependency just for supporting kerning.

Some hints to add support with the native Text class :

  • This should have 'leftAnchor' and 'rightAnchor' parameters

    return {
    height: dimensions.height,
    width: dimensions.width,
    anchor: dimensions.anchor,
    lineBreak,
    glyph,
    fontSize
    };

  • Somewhere here these two parameters should be looked up for computing inline.offsetX

    this.children.filter( (child)=> {
    return child.isInline ? true : false
    })
    .reduce( (lastInlineOffset, inlineComponent)=> {
    // Abort condition
    if ( !inlineComponent.inlines ) return
    //////////////////////////////////////////////////////////////
    // Compute offset of each children according to its dimensions
    //////////////////////////////////////////////////////////////
    const currentInlineInfo = inlineComponent.inlines.reduce( (lastInlineOffset, inline, i, inlines)=> {
    // Line break
    const nextBreak = distanceToNextBreak( inlines, i );
    if (
    lastInlineOffset + inline.width > INNER_WIDTH ||
    inline.lineBreak === "mandatory" ||
    this.shouldFriendlyBreak( inlines[ i - 1 ], lastInlineOffset, nextBreak, INNER_WIDTH )
    ) {
    lines.push([ inline ]);
    inline.offsetX = 0;
    return inline.width;
    }
    lines[ lines.length - 1 ].push( inline );
    //
    inline.offsetX = lastInlineOffset;
    //
    return lastInlineOffset + inline.width;
    }, lastInlineOffset );
    //
    return currentInlineInfo
    }, 0 );

/!\ There may be issues with the computed lines length, it must be checked.

@swingingtom
Copy link
Collaborator

If noone started it yet, I would like to give a try at this implementation

@felixmariotto
Copy link
Owner

@swingingtom go ahead !

@felixmariotto
Copy link
Owner

adressed by #106

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

No branches or pull requests

4 participants