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

Full script font support. #61

Open
achrist opened this issue Dec 16, 2016 · 4 comments
Open

Full script font support. #61

achrist opened this issue Dec 16, 2016 · 4 comments

Comments

@achrist
Copy link
Contributor

achrist commented Dec 16, 2016

Some script fonts draw different glyphs depending on the previous or next glyph and it appears that this library doesn't take that into account. Here's an example using the font Pacifico.

Rendered using Fontkit:
image

Same font in Sketch:
image

Notice how the Fontkit rendering is just drawing individual glyphs without "tails" to connect to the next glyph while in Sketch everything connects. Are there any plans to/is it possible to add support for this?

@devongovett
Copy link
Member

Fontkit does support OpenType and AAT layout. It may be that you just need to enable the right feature, or it could be a bug. Can you send over a link to the font you're using and the code you're using to render? Thanks!

@achrist
Copy link
Contributor Author

achrist commented Dec 16, 2016

I'm using Pacifico Regular as my test font. It can be downloaded from Google Fonts. Some example code is below:

  const font = scene.renderer.fonts.fonts['Pacifico-Regular'];
  const size = 40;
  const gridToPx = size / font.unitsPerEm;
  const ascent = font.ascent * gridToPx;
  const glyphRun = font.layout('This is a test.');
  const { glyphs, positions } = glyphRun;

  context.save();
  context.scale(1, -1);

  let xOffset = 0;

  for (let i = 0; i < glyphs.length; i++) {
    const glyph = glyphs[i];
    const position = positions[i];

    context.save();
    context.fillStyle = 'black';
    context.translate(xOffset, -ascent);
    context.beginPath();
    glyph.render(context, size);
    context.restore();

    xOffset += position.xAdvance * gridToPx;
  }

  context.restore();

I've tried to enable all of the available features for the font but none of them seem to do the trick. The available features according to the font file are:

'aalt',
'calt',
'case',
'dlig',
'fina',
'frac',
'liga',
'ordn',
'salt',
'ss01',
'ss02',
'sups',
'kern',
'mark',
'mkmk'

@Pomax
Copy link
Contributor

Pomax commented Dec 16, 2016

Based on previous work with a different library that had the same issue: if the features toggling is not doing the trick, this might be a left-side bearing issue, with the glyphs placed at (0,0) rather than at (-glyph.lsb,0)

@andersmelander
Copy link

andersmelander commented Sep 11, 2023

I just reproduced this exact problem in my own shaper. My shaper is independent from FontKit but as far as I can tell the cause of the problem is the same.

The problem in my shaper was the GSUB 'calt' feature in the Pacifico font. The 'calt' feature contains two type 6 (chaining contextual substitution) lookups:

  1. The first lookup matches a glyph followed by a glyph. There is no substitution for this lookup (i.e. do nothing).
  2. The second lookup matches a glyph followed by nothing. The substitution is the .fina form of the glyph.

The problem is that the shaper considers a lookup match with no substitution records (case 1 above) a non-match and because of this case 2 above is executed for all glyphs.

The problem can be emulated in the Crowbar OpenType debugger by disabling the 'calt' feature and enabling the 'fina' feature.

Edit: I've now looked at the relevant FontKit code and I can not see that it has the problem my code had.

applyLookupList(lookupRecords) {

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