duskmoon314 / typst-fontawesome

A Typst library for Font Awesome icons through the desktop fonts.
https://typst.app/universe/package/fontawesome
MIT License
10 stars 0 forks source link

Some icons appear to not be found (FontAwesome Pro) #10

Open adrfantini opened 5 days ago

adrfantini commented 5 days ago

Hi, I am struggling with Pro icons. The following code works for all icons, except integral:

#import "@preview/fontawesome:0.2.1": *

#set text(size: 2em)

#fa-icon("ban", font: "Font Awesome 6 Pro")
#fa-ban(font: "Font Awesome 6 Pro")

#fa-icon("chess-queen", font: "Font Awesome 6 Pro")
#fa-chess-queen(font: "Font Awesome 6 Pro")

#fa-icon("integral", font: "Font Awesome 6 Pro") // DOES NOT WORK
// #fa-integral(font: "Font Awesome 6 Pro") // not exported/not present

#fa-icon("github", font: "Font Awesome 6 Pro")
#fa-github(font: "Font Awesome 6 Pro")

Result: image

This happens for all Pro icons that I tested.

The output of typst fonts --font-path . includes Font Awesome 6 Pro, so that should be good. I have no other FA fonts installed, so it clearly is getting some fonts.

I have converted the FA .ttf file to .ttx to extract the glyphs, and the file contains a <GlyphID id="2616" name="integral"/>. Additionally it has the following:

    <TTGlyph name="integral" xMin="24" yMin="-64" xMax="296" yMax="448">
      <contour>
        <pt x="216" y="400" on="1"/>
        <pt x="202" y="400" on="0"/>
        <pt x="193" y="391" on="1"/>
        <pt x="193" y="391" on="1"/>
        <pt x="184" y="382" on="0"/>
        <pt x="184" y="368" on="1"/>
        <pt x="184" y="16" on="1"/>
        <pt x="183" y="-18" on="0"/>
        <pt x="161" y="-41" on="1"/>
        <pt x="138" y="-63" on="0"/>
        <pt x="104" y="-64" on="1"/>
        <pt x="70" y="-63" on="0"/>
        <pt x="47" y="-41" on="1"/>
        <pt x="25" y="-18" on="0"/>
        <pt x="24" y="16" on="1"/>
        <pt x="24" y="32" on="1"/>
        <pt x="26" y="54" on="0"/>
        <pt x="48" y="56" on="1"/>
        <pt x="70" y="54" on="0"/>
        <pt x="72" y="32" on="1"/>
        <pt x="72" y="16" on="1"/>
        <pt x="72" y="2" on="0"/>
        <pt x="81" y="-7" on="1"/>
        <pt x="90" y="-16" on="0"/>
        <pt x="104" y="-16" on="1"/>
        <pt x="118" y="-16" on="0"/>
        <pt x="127" y="-7" on="1"/>
        <pt x="136" y="2" on="0"/>
        <pt x="136" y="16" on="1"/>
        <pt x="136" y="368" on="1"/>
        <pt x="137" y="402" on="0"/>
        <pt x="159" y="425" on="1"/>
        <pt x="182" y="447" on="0"/>
        <pt x="216" y="448" on="1"/>
        <pt x="250" y="447" on="0"/>
        <pt x="273" y="425" on="1"/>
        <pt x="295" y="402" on="0"/>
        <pt x="296" y="368" on="1"/>
        <pt x="296" y="352" on="1"/>
        <pt x="294" y="330" on="0"/>
        <pt x="272" y="328" on="1"/>
        <pt x="250" y="330" on="0"/>
        <pt x="248" y="352" on="1"/>
        <pt x="248" y="368" on="1"/>
        <pt x="248" y="382" on="0"/>
        <pt x="239" y="391" on="1"/>
        <pt x="230" y="400" on="0"/>
        <pt x="216" y="400" on="1"/>
      </contour>
      <instructions/>
    </TTGlyph>

so I think the glyph is correctly present.

duskmoon314 commented 5 days ago

#fa-intergral should not work since I haven't paid for the Pro set and only generated functions for icons in the Free set.

Could you please try using the font directly like this:

// `text` enables ligature by default, and I think if this works, then `fa-icon` should work
#text("integral", font: "Font Awesome 6 Pro")

// Use Unicode instead of ligature. I found the Unicode on Font Awesome's website.
#text("\u{f667}", font: "Font Awesome 6 Pro")

If the second one works but the first one does not, maybe we need to check the other two options for ligatures: https://typst.app/docs/reference/text/text/#parameters-discretionary-ligatures

If the second one doesn't work either, maybe Font Awesome Pro needs some settings I need to know. 😢

adrfantini commented 5 days ago

#fa-intergral should not work since I haven't paid for the Pro set and only generated functions for icons in the Free set.

Could you please try using the font directly like this:

// `text` enables ligature by default, and I think if this works, then `fa-icon` should work
#text("integral", font: "Font Awesome 6 Pro")

// Use Unicode instead of ligature. I found the Unicode on Font Awesome's website.
#text("\u{f667}", font: "Font Awesome 6 Pro")

If the second one works but the first one does not, maybe we need to check the other two options for ligatures: https://typst.app/docs/reference/text/text/#parameters-discretionary-ligatures

If the second one doesn't work either, maybe Font Awesome Pro needs some settings I need to know. 😢

using text("integral"... does not work
using text("\u{f667}"... works! (however this is not acceptable in my case since I need icon name-based automation)

However, setting either discretionary or historical ligatures to true does not change the outcome 😢

Is there anything I can do to test this more or to help you test this?

duskmoon314 commented 5 days ago

However, setting either discretionary or historical ligatures to true does not change the outcome

This sounds weird since Font Awesome, as its docs say, supports ligatures for the Free and Brands set. I think there might be some issues between how Typst handles ligatures and what Font Awesome expects.

To solve this issue, I have two ideas:

  1. If the icons you want to use have limited numbers, you can create a fa-icon-map by hand and pass it to fa-icon (A lot of dirty work)
  2. Try using icons in Word, Photoshop, and other design tools and see whether ligature works. If the ligature works, let's open an issue at Typst's original repo.
adrfantini commented 5 days ago

However, setting either discretionary or historical ligatures to true does not change the outcome

This sounds weird since Font Awesome, as its docs say, supports ligatures for the Free and Brands set. I think there might be some issues between how Typst handles ligatures and what Font Awesome expects.

To solve this issue, I have two ideas:

  1. If the icons you want to use have limited numbers, you can create a fa-icon-map by hand and pass it to fa-icon (A lot of dirty work)
  2. Try using icons in Word, Photoshop, and other design tools and see whether ligature works. If the ligature works, let's open an issue at Typst's original repo.

I added the icons to my system, then in Libreoffice Writer copied the glyph from the FA website, and pasted. This is the result: image

duskmoon314 commented 5 days ago

Have you tried ligature? I mean, type in integral in LibreOffice.

duskmoon314 commented 3 days ago

using text("integral"... does not work using text("\u{f667}"... works!

Your environment may have something weird.

I downloaded an OTF of Font Awesome 6 Pro Regular 6.0.0 from the network (though this is not legal) and used it for a simple test. Everything is working fine.

image

My environment

typst 0.11.1 Using typst --font-path . c example.typ to compile

I'd like to know which version of typst you are using and how your files are organized.

adrfantini commented 3 days ago

Sorry for the delay and thank you for your help!

Here's my code with details in comments:

#import "@preview/fontawesome:0.2.1": *

// Using typst 0.11.1 (50115102) on ArchLinux

// Compile command:
// typst compile --font-path . test.typ

// Dir tree
// .
// ├── fa-regular-400.ttf
// ├── test.pdf
// └── test.typ

// Fonts:
// typst fonts --font-path . | grep --color=auto 'wesome'
// Font Awesome 6 Pro

#set text(size: 2em)

OK:
#fa-icon("ban", font: "Font Awesome 6 Pro")
#fa-ban(font: "Font Awesome 6 Pro")

OK:
#fa-icon("chess-queen", font: "Font Awesome 6 Pro")
#fa-chess-queen(font: "Font Awesome 6 Pro")

OK:
#fa-icon("github", font: "Font Awesome 6 Pro")
#fa-github(font: "Font Awesome 6 Pro")

// Use Unicode instead of ligature. I found the Unicode on Font Awesome's website.
OK:
#text("\u{f667}", font: "Font Awesome 6 Pro")
#text("\u{f667}", font: "Font Awesome 6 Pro", discretionary-ligatures: true)
#text("\u{f667}", font: "Font Awesome 6 Pro", historical-ligatures: true)

NOT OK:
#fa-icon("integral", font: "Font Awesome 6 Pro")

// `text` enables ligature by default, and I think if this works, then `fa-icon` should work
NOT OK:
#text("integral", font: "Font Awesome 6 Pro")
#text("integral", font: "Font Awesome 6 Pro", discretionary-ligatures: true)
#text("integral", font: "Font Awesome 6 Pro", historical-ligatures: true)

And here is the output: image

As for ligatures in Libreoffice, they also do not work: image

duskmoon314 commented 2 days ago
// Dir tree
// .
// ├── fa-regular-400.ttf

I notice that you are using a ttf version. I don't know whether this is the cause.

As far as I know, Font Awesome's guide only mentions otf. Maybe the support of otf in Typst and LibreOffice is a little different from ttf?

A discussion on Figma's forum says that ttf doesn't support ligature. If so, I recommend trying the otf version of Font Awesome.