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

Also select font via unprettified family name #2098

Open
laurmaedje opened this issue Sep 9, 2023 · 17 comments
Open

Also select font via unprettified family name #2098

laurmaedje opened this issue Sep 9, 2023 · 17 comments
Labels
feature request New feature or request text Text layout, shaping, internationalization, etc.

Comments

@laurmaedje
Copy link
Member

Description

Typst prettifies some font names, but ideally the true name should also work, that is, in the example below both line 2 and 3 should render in New CM.

Hello \
#text(font: "NewComputerModern10")[Hello] \
#text(font: "New Computer Modern")[Hello]

Moreover, conceivably a font could be selectable via full name or perhaps also PostScript name:

_Hello_ \
#text(font: "Linux Libertine Italic")[Hello]

Use Case

More compatibility.

@Leedehai
Copy link
Contributor

Leedehai commented Dec 12, 2023

I can take a look at this. I kinda familiarized myself with the fonts while investigating #2917. If the maintainers are willing, let's open a Forge thread?

@laurmaedje
Copy link
Member Author

I'll open one.

@tornaria
Copy link

Maybe related: there seems to be no way to select font by size. For example,

#set text(font: "Latin Modern Sans", size: 17pt)

Hello, world!

uses an 8pt font:

$ pdffonts LM17.pdf 
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
AKPPLH+LMSans8-Regular-Identity-H    CID Type 0C       Identity-H       yes yes yes      4  0

but I do have a "Latin Modern Sans" in 17pt installed:

$ fc-scan --format="%{file} / %{family} / %{style}\n" /usr/share/fonts/latinmodern/lmsans[0-9]*.otf
/usr/share/fonts/latinmodern/lmsans10-bold.otf / Latin Modern Sans,LM Sans 10 / 10 Bold,Bold
/usr/share/fonts/latinmodern/lmsans10-boldoblique.otf / Latin Modern Sans,LM Sans 10 / 10 Bold Oblique,Bold Italic
/usr/share/fonts/latinmodern/lmsans10-oblique.otf / Latin Modern Sans,LM Sans 10 / 10 Oblique,Italic
/usr/share/fonts/latinmodern/lmsans10-regular.otf / Latin Modern Sans,LM Sans 10 / 10 Regular,Regular
/usr/share/fonts/latinmodern/lmsans12-oblique.otf / Latin Modern Sans,LM Sans 12 / 12 Oblique,Italic
/usr/share/fonts/latinmodern/lmsans12-regular.otf / Latin Modern Sans,LM Sans 12 / 12 Regular,Regular
/usr/share/fonts/latinmodern/lmsans17-oblique.otf / Latin Modern Sans,LM Sans 17 / 17 Oblique,Italic
/usr/share/fonts/latinmodern/lmsans17-regular.otf / Latin Modern Sans,LM Sans 17 / 17 Regular,Regular
/usr/share/fonts/latinmodern/lmsans8-oblique.otf / Latin Modern Sans,LM Sans 8 / 8 Oblique,Italic
/usr/share/fonts/latinmodern/lmsans8-regular.otf / Latin Modern Sans,LM Sans 8 / 8 Regular,Regular
/usr/share/fonts/latinmodern/lmsans9-oblique.otf / Latin Modern Sans,LM Sans 9 / 9 Oblique,Italic
/usr/share/fonts/latinmodern/lmsans9-regular.otf / Latin Modern Sans,LM Sans 9 / 9 Regular,Regular


In fact, it seems typst finds all of these fonts:

$ typst fonts --variants
[...]
Latin Modern Sans
- Style: Normal, Weight: 700, Stretch: FontStretch(1000)
- Style: Italic, Weight: 400, Stretch: FontStretch(1000)
- Style: Italic, Weight: 400, Stretch: FontStretch(1000)
- Style: Normal, Weight: 400, Stretch: FontStretch(1000)
- Style: Italic, Weight: 400, Stretch: FontStretch(1000)
- Style: Normal, Weight: 400, Stretch: FontStretch(1000)
- Style: Italic, Weight: 400, Stretch: FontStretch(1000)
- Style: Italic, Weight: 600, Stretch: FontStretch(1000)
- Style: Italic, Weight: 400, Stretch: FontStretch(1000)
- Style: Normal, Weight: 400, Stretch: FontStretch(1000)
- Style: Italic, Weight: 700, Stretch: FontStretch(1000)
- Style: Normal, Weight: 400, Stretch: FontStretch(1000)
- Style: Normal, Weight: 400, Stretch: FontStretch(1000)
- Style: Normal, Weight: 600, Stretch: FontStretch(1000)
[...]

But it will only use the 8pt font lmsans8-regular.otf. If I move away this file, it will then choose the 17pt one lmsans17-regular.otf.

Note that the 17pt font is not the same as the 8pt scaled to 17pt (which is what typst produces).

@inferiorhumanorgans
Copy link
Contributor

With Roboto and Roboto Condensed installed there's no way to select a specific variant.

https://fonts.google.com/specimen/Roboto

https://fonts.google.com/specimen/Roboto+Condensed

$ typst fonts --variants
…
Roboto
- Style: Normal, Weight: 500, Stretch: FontStretch(1000)
- Style: Normal, Weight: 300, Stretch: FontStretch(1000)
- Style: Normal, Weight: 400, Stretch: FontStretch(1000)
- Style: Normal, Weight: 400, Stretch: FontStretch(1000)
- Style: Italic, Weight: 500, Stretch: FontStretch(1000)
- Style: Italic, Weight: 250, Stretch: FontStretch(1000)
- Style: Italic, Weight: 700, Stretch: FontStretch(1000)
- Style: Italic, Weight: 300, Stretch: FontStretch(1000)
- Style: Italic, Weight: 400, Stretch: FontStretch(1000)
- Style: Italic, Weight: 900, Stretch: FontStretch(1000)
- Style: Normal, Weight: 700, Stretch: FontStretch(1000)
- Style: Normal, Weight: 250, Stretch: FontStretch(1000)
- Style: Normal, Weight: 900, Stretch: FontStretch(1000)

Note that Roboto Condensed is a variable font so even though it's only showing up at weight=400, it's valid for any weight.

Being able to select a weight by name is also be a nice to have and that would be captured by the PostScript name. Fonts like e.g. Bell Centennial have non-standard names (Address, Name & Number, Sub-Caption, Bold Listing) for their weights and it would be nice to not have to manually map them to numeric values. Others like FF Meta have two variants at the same weight with different names.

@TechnicJelle
Copy link

TechnicJelle commented Nov 10, 2024

I just installed Typst for the first time today, as well, to try and re-make my resume in it.
But my preferred font is Roboto, so I have also run into this issue now.
I do not know what to do to properly fix it.

My old resume, in LibreOffice:
image

What Typst makes of it:
image

The normal body text is fine, but any bold or heading text is condensed against my wishes.

My "code" is super simple for now, as I have not got further than this:

#set page(
	paper: "a4",
	margin: (x: 0.5cm, y: 0.7cm),
)
#set text(
	font: "Roboto",
	size: 11pt,
)

// *snip*

== Education

=== Bachelor of Creative Media and Game Technologies Sept 2021 - Present
At *Saxion University of Applied Sciences*

I would love a fix for this issue. In my opinion font: "Roboto" should use the Roboto font, and not Roboto Condensed.

@terefang
Copy link

you might want also to look at my ticket #5455

@TechnicJelle
Copy link

Currently, I worked around this issue by ignoring the system fonts, and supplying my own specific font files.
Like this:

typst compile resume.typ --font-path ./Fonts/ --ignore-system-fonts
My specific file structure
.
├── compile.sh
├── Fonts
│   ├── fontawesome-free-6.6.0-desktop
│   │   ├── Font Awesome 6 Brands-Regular-400.otf
│   │   ├── Font Awesome 6 Free-Regular-400.otf
│   │   └── LICENSE.txt
│   ├── JetBrainsMono-2.304
│   │   ├── AUTHORS.txt
│   │   ├── JetBrainsMono-Regular.ttf
│   │   └── OFL.txt
│   ├── Noto Color Emoji
│   │   ├── NotoColorEmoji-Regular.ttf
│   │   └── OFL.txt
│   ├── Roboto
│   │   ├── LICENSE.txt
│   │   ├── Roboto-BlackItalic.ttf
│   │   ├── Roboto-Black.ttf
│   │   ├── Roboto-BoldItalic.ttf
│   │   ├── Roboto-Bold.ttf
│   │   ├── Roboto-Italic.ttf
│   │   ├── Roboto-LightItalic.ttf
│   │   ├── Roboto-Light.ttf
│   │   ├── Roboto-MediumItalic.ttf
│   │   ├── Roboto-Medium.ttf
│   │   ├── Roboto-Regular.ttf
│   │   ├── Roboto-ThinItalic.ttf
│   │   └── Roboto-Thin.ttf
│   └── simple-icons-font-9.19.0
│       ├── DISCLAIMER.md
│       ├── LICENSE.md
│       ├── SimpleIcons.otf
│       └── SimpleIcons.otf.7z
├── resume.pdf
└── resume.typ

Yes, there is font duplication now, but the additional advantage of this (aside from it working) is that other devices can compile it as well, without having to have those fonts installed.

@terefang
Copy link

Note that Roboto Condensed is a variable font so even though it's only showing up at weight=400, it's valid for any weight.

if i remember correctly, variable font files are not valid for pdf embedding.

@inferiorhumanorgans
Copy link
Contributor

inferiorhumanorgans commented Nov 25, 2024

Roboto should be available in a non variable version and I would use that instead as variable fonts have limited support for now. Roboto vs Roboto Condensed comes down to ttf-parser not looking in every last location where a font can specify its stretch.

As of ttf-parser 0.25.0 the STAT table is parsed and can be checked. This should allow typst to get condensed versions of Roboto identified properly as condensed. This allows typst to check for correct information but has not (yet) been included in ttf-parser's is_bold and is_italic functions. See also #576. Unfortunately, I believe there are some breaking changes going from ttf-parser 0.24 to 0.25.

Related, I've not had the bandwidth recently to finish up the PANOSE support (harfbuzz/ttf-parser#172), so some older fonts are still out of luck if their OS/2 table only has correct information in the PANOSE field.

Short term the more more correct end-user fix is to use the static version of Roboto and add an exception to typst here for your local builds:

https://github.com/typst/typst/blob/main/crates/typst-library/src/text/font/exceptions.rs

@terefang
Copy link

terefang commented Nov 27, 2024

As of ttf-parser 0.25.0 the STAT table is also checked and this should get condensed versions of Roboto identified properly as condensed.

let me add a reality check here – i recently bought a commercial grade font-bundle from a german manufacturer targetted at the SMB/KMU market.

1 - non of the files contains a STAT table.

2 - using (version 0.12.0) typst fonts --ignore-system-fonts --font-path ./ --variants i get

Limerick Antique
- Style: Italic, Weight: 800, Stretch: FontStretch(1000)
- Style: Italic, Weight: 900, Stretch: FontStretch(1000)
- Style: Normal, Weight: 250, Stretch: FontStretch(1000)
- Style: Italic, Weight: 500, Stretch: FontStretch(1000)
- Style: Italic, Weight: 300, Stretch: FontStretch(1000)
- Style: Normal, Weight: 400, Stretch: FontStretch(1000)
- Style: Normal, Weight: 700, Stretch: FontStretch(1000)
- Style: Italic, Weight: 700, Stretch: FontStretch(1000)
- Style: Italic, Weight: 400, Stretch: FontStretch(1000)
- Style: Italic, Weight: 250, Stretch: FontStretch(1000)
- Style: Normal, Weight: 300, Stretch: FontStretch(1000)
- Style: Normal, Weight: 800, Stretch: FontStretch(1000)
- Style: Normal, Weight: 900, Stretch: FontStretch(1000)
- Style: Normal, Weight: 500, Stretch: FontStretch(1000)
Limerick Cd Antique
- Style: Normal, Weight: 900, Stretch: FontStretch(1000)
- Style: Italic, Weight: 250, Stretch: FontStretch(1000)
- Style: Normal, Weight: 800, Stretch: FontStretch(1000)
- Style: Italic, Weight: 900, Stretch: FontStretch(1000)
- Style: Italic, Weight: 400, Stretch: FontStretch(1000)
- Style: Italic, Weight: 700, Stretch: FontStretch(1000)
- Style: Normal, Weight: 500, Stretch: FontStretch(1000)
- Style: Italic, Weight: 500, Stretch: FontStretch(1000)
- Style: Normal, Weight: 250, Stretch: FontStretch(1000)
- Style: Italic, Weight: 300, Stretch: FontStretch(1000)
- Style: Italic, Weight: 800, Stretch: FontStretch(1000)
- Style: Normal, Weight: 400, Stretch: FontStretch(1000)
- Style: Normal, Weight: 300, Stretch: FontStretch(1000)
- Style: Normal, Weight: 700, Stretch: FontStretch(1000)

for

Limerick-Antique-BoldItalic.ttf
Limerick-Antique-Bold.ttf
Limerick-Antique-HeavyItalic.ttf
Limerick-Antique-Heavy.ttf
Limerick-Antique-Italic.ttf
Limerick-Antique-LightItalic.ttf
Limerick-Antique-Light.ttf
Limerick-Antique-MediumItalic.ttf
Limerick-Antique-Medium.ttf
Limerick-Antique-Regular.ttf
Limerick-Antique-XboldItalic.ttf
Limerick-Antique-Xbold.ttf
Limerick-Antique-XlightItalic.ttf
Limerick-Antique-Xlight.ttf
Limerick-Cd-Antique-BoldItalic.ttf
Limerick-Cd-Antique-Bold.ttf
Limerick-Cd-Antique-HeavyItalic.ttf
Limerick-Cd-Antique-Heavy.ttf
Limerick-Cd-Antique-Italic.ttf
Limerick-Cd-Antique-LightItalic.ttf
Limerick-Cd-Antique-Light.ttf
Limerick-Cd-Antique-MediumItalic.ttf
Limerick-Cd-Antique-Medium.ttf
Limerick-Cd-Antique-Regular.ttf
Limerick-Cd-Antique-XboldItalic.ttf
Limerick-Cd-Antique-Xbold.ttf
Limerick-Cd-Antique-XlightItalic.ttf
Limerick-Cd-Antique-Xlight.ttf

3 - i also took a "Pro" version font family to the test:

Bodoni Antiqua Pro
- Style: Italic, Weight: 700, Stretch: FontStretch(1000)
- Style: Italic, Weight: 400, Stretch: FontStretch(1000)
- Style: Normal, Weight: 600, Stretch: FontStretch(1000)
- Style: Normal, Weight: 300, Stretch: FontStretch(1000)
- Style: Italic, Weight: 400, Stretch: FontStretch(1000)
- Style: Italic, Weight: 600, Stretch: FontStretch(1000)
- Style: Normal, Weight: 400, Stretch: FontStretch(1000)
- Style: Italic, Weight: 700, Stretch: FontStretch(1000)
- Style: Normal, Weight: 400, Stretch: FontStretch(1000)
- Style: Italic, Weight: 600, Stretch: FontStretch(1000)
- Style: Normal, Weight: 700, Stretch: FontStretch(1000)
- Style: Normal, Weight: 600, Stretch: FontStretch(1000)
- Style: Italic, Weight: 300, Stretch: FontStretch(1000)
- Style: Normal, Weight: 700, Stretch: FontStretch(1000)
Bodoni Antiqua Pro Caps
- Style: Normal, Weight: 400, Stretch: FontStretch(1000)
- Style: Normal, Weight: 300, Stretch: FontStretch(1000)
Bodoni Antiqua Pro Compress
- Style: Normal, Weight: 400, Stretch: FontStretch(1000)
- Style: Normal, Weight: 700, Stretch: FontStretch(1000)

for

Bodoni-Antiqua-Pro-BoldItalic.ttf
Bodoni-Antiqua-Pro-Bold.ttf
Bodoni-Antiqua-Pro-Caps-Light.ttf
Bodoni-Antiqua-Pro-Caps-Regular.ttf
Bodoni-Antiqua-Pro-Cd-BoldItalic.ttf
Bodoni-Antiqua-Pro-Cd-Bold.ttf
Bodoni-Antiqua-Pro-Cd-DemiItalic.ttf
Bodoni-Antiqua-Pro-Cd-Demi.ttf
Bodoni-Antiqua-Pro-Cd-Italic.ttf
Bodoni-Antiqua-Pro-Cd-Regular.ttf
Bodoni-Antiqua-Pro-Compress-Bold.ttf
Bodoni-Antiqua-Pro-Compress-Regular.ttf
Bodoni-Antiqua-Pro-DemiItalic.ttf
Bodoni-Antiqua-Pro-Demi.ttf
Bodoni-Antiqua-Pro-Italic.ttf
Bodoni-Antiqua-Pro-LightItalic.ttf
Bodoni-Antiqua-Pro-Light.ttf
Bodoni-Antiqua-Pro-Regular.ttf

i am willing to work with the manufacturer to fix their fonts – what should i tell them exactly ?

@inferiorhumanorgans
Copy link
Contributor

@terefang Whoever sold you those fonts should fix them. typst is getting the weight and/or slant wrong because ttf-parser is being fed incorrect information and not (as of 0.24) checking the additional places where correct information may (or may not) exist. typst currently uses ttf-parser 0.24.

As of 0.25 ttf-parser provides primitives to mitigate some of this, however looking at harfbuzz/ttf-parser#166, the changes to check STAT for weight and slant in the higher level functions didn't get included.

For diagnostic information start here:

#576 (comment)

@inferiorhumanorgans
Copy link
Contributor

That said I think a mechanism to select a font by its Postscript name would be a big win.

@terefang
Copy link

terefang commented Nov 27, 2024

let me add:

$ fc-scan --format="%{file} | %{family} | %{style} | %{width} | %{postscriptname}\n" *.ttf|sort
Bodoni-Antiqua-Pro-BoldItalic.ttf | Bodoni Antiqua Pro | Bold Italic | 100 | BodoniAntiquaPro-BoldItalic
Bodoni-Antiqua-Pro-Bold.ttf | Bodoni Antiqua Pro | Bold | 100 | BodoniAntiquaPro-Bold
Bodoni-Antiqua-Pro-Caps-Light.ttf | Bodoni Antiqua Pro Caps,Bodoni Antiqua Pro Caps Light | Light,Regular | 100 | BodoniAntiquaProCaps-Light
Bodoni-Antiqua-Pro-Caps-Regular.ttf | Bodoni Antiqua Pro Caps | Regular | 100 | BodoniAntiquaProCaps
Bodoni-Antiqua-Pro-Cd-BoldItalic.ttf | Bodoni Antiqua Pro Cd | Bold Italic | 100 | BodoniAntiquaProCd-BoldItalic
Bodoni-Antiqua-Pro-Cd-Bold.ttf | Bodoni Antiqua Pro Cd | Bold | 100 | BodoniAntiquaProCd-Bold
Bodoni-Antiqua-Pro-Cd-DemiItalic.ttf | Bodoni Antiqua Pro Cd,Bodoni Antiqua Pro Cd Demi | Demi Italic,Italic | 100 | BodoniAntiquaProCd-DemiItalic
Bodoni-Antiqua-Pro-Cd-Demi.ttf | Bodoni Antiqua Pro Cd,Bodoni Antiqua Pro Cd Demi | Demi,Regular | 100 | BodoniAntiquaProCd-Demi
Bodoni-Antiqua-Pro-Cd-Italic.ttf | Bodoni Antiqua Pro Cd | Italic | 100 | BodoniAntiquaProCd-Italic
Bodoni-Antiqua-Pro-Cd-Regular.ttf | Bodoni Antiqua Pro Cd | Regular | 100 | BodoniAntiquaProCd
Bodoni-Antiqua-Pro-Compress-Bold.ttf | Bodoni Antiqua Pro Compress | Bold | 100 | BodoniAntiquaProCompress-Bold
Bodoni-Antiqua-Pro-Compress-Regular.ttf | Bodoni Antiqua Pro Compress | Regular | 100 | BodoniAntiquaProCompress
Bodoni-Antiqua-Pro-DemiItalic.ttf | Bodoni Antiqua Pro,Bodoni Antiqua Pro Demi | Demi Italic,Italic | 100 | BodoniAntiquaPro-DemiItalic
Bodoni-Antiqua-Pro-Demi.ttf | Bodoni Antiqua Pro,Bodoni Antiqua Pro Demi | Demi,Regular | 100 | BodoniAntiquaPro-Demi
Bodoni-Antiqua-Pro-Italic.ttf | Bodoni Antiqua Pro | Italic | 100 | BodoniAntiquaPro-Italic
Bodoni-Antiqua-Pro-LightItalic.ttf | Bodoni Antiqua Pro,Bodoni Antiqua Pro Light | Light Italic,Italic | 100 | BodoniAntiquaPro-LightItalic
Bodoni-Antiqua-Pro-Light.ttf | Bodoni Antiqua Pro,Bodoni Antiqua Pro Light | Light,Regular | 100 | BodoniAntiquaPro-Light
Bodoni-Antiqua-Pro-Regular.ttf | Bodoni Antiqua Pro | Regular | 100 | BodoniAntiquaPro

@inferiorhumanorgans
Copy link
Contributor

Right, see my comment above for information on how to get more detailed information from your fonts.

@terefang
Copy link

yeah ... but what about if the fonts cannot be fixed because of complex licensing issues ?

then it would make sense to have something in place like i proposed in #5455

@terefang
Copy link

terefang commented Nov 27, 2024

Right, see my comment above for information on how to get more detailed information from your fonts.

do you suggest that i need to install a complete rust dev environment just to get the debugging utility ?

which has build errors btw

@terefang
Copy link

terefang commented Nov 27, 2024

maybe a more common tool could be used like ttfdump ?

$ ttfdump Bodoni-Antiqua-Pro-Cd-Regular.ttf -t 'OS/2'
.....
'OS/2' Table - OS/2 and Windows Metrics
---------------------------------------
	 'OS/2' version:	 3
	 xAvgCharWidth:		 432
	 usWeightClass:		 400 	 'Normal'
	 usWidthClass:		 5 	 'Medium'
	 fsType:		 4
	 ySubscriptXSize:	 700
	 ySubscriptYSize:	 650
	 ySubscriptXOffset:	 0
	 ySubscriptYOffset:	 140
	 ySuperscriptXSize:	 700
	 ySuperscriptYSize:	 650
	 ySuperscriptXOffset:	 0
	 ySuperscriptYOffset:	 477
	 yStrikeoutSize:	 50
	 yStrikeoutPosition	 250
	 sFamilyClass:	 0 	 subclass = 0
	 PANOSE:
		 Family Kind:	 2 	 'Text and Display'
		 Serif Style:	 0 	 'Any'
		 Weight:	 5 	 'Book'
		 Proportion:	 6 	 'Condensed'
		 Contrast:	 8 	 'High'
		 Stroke:	 0 	 'Any'
		 Arm Style:	 0 	 'Any'
		 Lettreform:	 2 	 'Normal/Contact'
		 Midline:	 0 	 'Any'
		 X-height:	 3 	 'Constant/Standard'
	 Unicode Range 1( Bits 0 - 31 ): 	 0xa000006f
	 Unicode Range 2( Bits 32 - 63 ): 	 0x500078bb
	 Unicode Range 3( Bits 64 - 95 ): 	 0x00000000
	 Unicode Range 4( Bits 96 - 128 ): 	 0x00000000
	 achVendID:		 'smak'
	 fsSelection:		 0x0040 	 'Regular '
	 usFirstCharIndex:	 0x0020
 	 usLastCharIndex:	 0xfb04
	 sTypoAscender:		 667
	 sTypoDescender:	 -200
	 sTypoLineGap:		 44
	 usWinAscent:		 859
	 usWinDescent:		 267
	 CodePage Range 1( Bits 0 - 31 ):	 0x20000093
	 CodePage Range 2( Bits 32- 63 ):	 0x4d000000
	 sxHeight:		 427
	 sCapHeight:		 667
	 usDefaultChar:		 0x0000
	 usBreakChar:		 0x0020
	 usMaxContext:		 5

looks like the usWidthClass is wrong.

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 text Text layout, shaping, internationalization, etc.
Projects
None yet
Development

No branches or pull requests

6 participants