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

Unwanted ligatures #490

Closed
zimt28 opened this issue Jun 15, 2020 · 9 comments
Closed

Unwanted ligatures #490

zimt28 opened this issue Jun 15, 2020 · 9 comments

Comments

@zimt28
Copy link

zimt28 commented Jun 15, 2020

I want to use a font from fonts.google.com and am running into an issue.

I've included the font (Nunito) like so:

const nunitoBoldUrl =
  "https://fonts.gstatic.com/s/nunito/v12/XRXW3I6Li01BKofA6sKUYevIWzgPDA.woff2";
const nunitoBoldFontBytes = await fetch(nunitoBoldUrl).then((res) => res.arrayBuffer());

const nunitoBold = await pdfDoc.embedFont(nunitoBoldFontBytes);

This works, with one exception (there might be more, but this is what I could find):

Printing fi adds unwanted spacing after it which shouldn't be there, the Google preview also doesn't show it.

fi ir fir:
Screenshot 2020-06-15 at 21 05 12

I think the font has a special ligature for fi, if I install the font on my system I get the same connected f and i letters, but without the spacing. Is this an issue with pdf-kit or fontkit?

@fobdy
Copy link

fobdy commented Jun 22, 2020

The same problem for me with "Source Sans Pro" font and "ft"

@fobdy
Copy link

fobdy commented Jun 22, 2020

We could try to turn off the ligatures if there was access to the low-level fontkit api

font.layout(lineTxt, { liga:false })

Related foliojs/fontkit#170

@zimt28
Copy link
Author

zimt28 commented Jun 22, 2020

@fobdy Which file format are you trying to use?

@fobdy
Copy link

fobdy commented Jul 31, 2020

@fobdy Which file format are you trying to use?

I'm using .ttf.
Update: the same with .otf
Fonts that are used: https://github.com/adobe-fonts/source-sans-pro/releases/tag/3.006R

@Hopding
Copy link
Owner

Hopding commented Sep 26, 2020

Hello @zimt28 @fobdy! As far as I'm aware this is an issue with fontkit, though I haven't been able to confirm this. If anybody is interested, it is possible to disable ligatures when performing text layout with fontkit (as @fobdy mentioned). You would just need to update the API to pass options here:

/**
* Encode the JavaScript string into this font. (JavaScript encodes strings in
* Unicode, but embedded fonts use their own custom encodings)
*/
encodeText(text: string): PDFHexString {
const { glyphs } = this.font.layout(text);

I'd be happy to accept a PR if anybody is interested in working on this.

hefler added a commit to hefler/pdf-lib that referenced this issue Oct 21, 2020
@hefler hefler mentioned this issue Oct 21, 2020
Hopding pushed a commit that referenced this issue Dec 12, 2020
* Font features option for embedded fonts (#490)

* Updated downlevel-dts

* Typing `fontFeatures` to TypeFeatures

* Reverting to `downlevel-dts@^0.5.0`

* Updated EmbedFont Options with TypeFeatures

* Add a test for TypeFeatures option
Hopding added a commit that referenced this issue Dec 13, 2020
* Font features (#642)

* Font features option for embedded fonts (#490)

* Updated downlevel-dts

* Typing `fontFeatures` to TypeFeatures

* Reverting to `downlevel-dts@^0.5.0`

* Updated EmbedFont Options with TypeFeatures

* Add a test for TypeFeatures option

* Update yarn.lock

* Cleanup font features implementation

* Cleanup

Co-authored-by: Felipe Hefler <[email protected]>
@Hopding
Copy link
Owner

Hopding commented Dec 21, 2020

Version 1.14.0 includes an API that can disable font ligatures (thanks to @hefler!):

const nunitoNoLigaFont = await pdfDoc.embedFont(fonts.ttf.nunito, {
subset: true,
features: { liga: false },
});

@Hopding Hopding closed this as completed Dec 21, 2020
Hopding added a commit that referenced this issue Aug 30, 2021
* Font features (#642)

* Font features option for embedded fonts (#490)

* Updated downlevel-dts

* Typing `fontFeatures` to TypeFeatures

* Reverting to `downlevel-dts@^0.5.0`

* Updated EmbedFont Options with TypeFeatures

* Add a test for TypeFeatures option

* Update yarn.lock

* Cleanup font features implementation

* Cleanup

Co-authored-by: Felipe Hefler <[email protected]>
@direnc
Copy link

direnc commented Jul 30, 2023

Same problem with Garamond. features: { liga: false } solution is not working, still with spacing .

@ephraimduncan
Copy link

Same problem with Caveat, disabling ligatures is not working

@r4dulf
Copy link

r4dulf commented Jun 20, 2024

@ephraimduncan For the Caveat font, setting calt: false solved the problem

 const caveatRegular = await documentProxy.embedFont(caveatFontData, {
    features: { calt: false },
  });

image

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

No branches or pull requests

6 participants