608 Commits

Author SHA1 Message Date
Qwerasd
fca336c32d Metal: blend in Display P3 color space, add option for linear blending
This commit is quite large because it's fairly interconnected and can't
be split up in a logical way. The main part of this commit is that alpha
blending is now always done in the Display P3 color space, and depending
on the configured `window-colorspace` colors will be converted from sRGB
or assumed to already be Display P3 colors. In addition, a config option
`text-blending` has been added which allows the user to configure linear
blending (AKA "gamma correction"). Linear alpha blending also applies to
images and makes custom shaders receive linear colors rather than sRGB.

In addition, an experimental option has been added which corrects linear
blending's tendency to make dark text look too thin and bright text look
too thick. Essentially it's a correction curve on the alpha channel that
depends on the luminance of the glyph being drawn.
2025-01-13 13:50:29 -08:00
Qwerasd
298aeb7536 refactor(font): move ownership of Metrics to Collection
This sets the stage for dynamically adjusting the sizes of fallback
fonts based on the primary font's face metrics. It also removes a lot of
unnecessary work when loading fallback fonts, since we only actually use
the metrics based on the parimary font.
2025-01-06 20:13:45 -05:00
Qwerasd
540fcc0b69 refactor(font): move Metrics out of face
in preparation to move ownership of metrics from faces to collections
2025-01-06 20:13:45 -05:00
Qwerasd
25a112469c font(coretext): add config to adjust strength of font-thicken.
This is achieved by rendering to an alpha-only context rather than a
normal single-channel context, and adjusting the brightness at which
coretext thinks it's drawing the glyph, which affects how it applies
font smoothing (which is what `font-thicken` enables).
2025-01-03 14:19:19 -05:00
Mitchell Hashimoto
18001c3251 font: allow non-boolean font feature settings (#4139)
\+ much more flexible syntax and lenient parser
\+ allows comma-separated list as a single config value

This allows, e.g. `cv01 = 2` to select the second variant of `cv01`.

Resolves #3128 

Parser could probably be a little smaller than it is- would be a lot
cleaner with the labeled switch continue pattern from Zig 0.14. Maybe
should've put it in its own file too...

I spent *much* too long trying to test this with `cv01` with
[monaspace](https://github.com/githubnext/monaspace) before realizing
that the README refers to v1.2 but the latest released version (and
hence the one I had installed) was v1.101 -- I installed the v1.2
version and tested with both CoreText and HarfBuzz and successfully set
`cv01 = 2` and got the expected result.

Feel free to make any stylistic changes you feel necessary before
merging.
2025-01-02 14:04:20 -08:00
moritz-john
b1a197ef57 Fix: typo in comment
Fix: 'becauseonce' -> 'because once'
2025-01-01 09:46:06 +01:00
Qwerasd
2d174f9bff font: allow non-boolean font feature settings
+ much more flexible syntax and lenient parser
+ allows comma-separated list as a single config value

This allows, e.g. `cv01 = 2` to select the second variant of `cv01`.
2024-12-30 21:15:25 -05:00
Mitchell Hashimoto
ef542c6e63 Enable bitmap font usage under CoreText (#4115)
macOS bitmap-only fonts are a poorly documented format, which are often
distributed as `.dfont` or `.dfon` files. They use a 'bhed' table in
place of the usual 'head', but the table format is byte-identical, so
enabling the use of bitmap-only fonts only requires us to properly fetch
this table while calculating metrics.

ref: https://fontforge.org/docs/techref/bitmaponlysfnt.html

Reverts #3550 for obvious reasons, and may close issue #2168 because
this should now mean that bitmap fonts are properly supported under both
font backends due to #3837 - unless `otb` fonts are still not properly
supported under FreeType (they are not supported under CoreText because
CoreText does not know how to handle them).

I tested this change with the `.dfont` distribution of
[Cozette](https://github.com/slavfox/Cozette) v1.25.2 and saw no visual
issues.
2024-12-30 12:05:57 -08:00
Mitchell Hashimoto
41df2d9805 font/freetype: hardcode DPI in test to avoid variation between OS 2024-12-30 12:01:46 -08:00
Qwerasd
7a4215abd7 font/coretext: properly resolve metrics for bitmap-only fonts
macOS bitmap-only fonts are a poorly documented format, which are often
distributed as `.dfont` or `.dfon` files. They use a 'bhed' table in
place of the usual 'head', but the table format is byte-identical, so
enabling the use of bitmap-only fonts only requires us to properly fetch
this table while calculating metrics.

ref: https://fontforge.org/docs/techref/bitmaponlysfnt.html
2024-12-30 14:44:46 -05:00
Qwerasd
31f101c970 Revert "coretext: exclude bitmap fonts from discovery"
This reverts commit 322f166ca50eb495aba3e49d24fda280e2b0a759.
2024-12-30 14:39:07 -05:00
sin-ack
5e14b8e501 font/freetype: Downgrade pixfmt conversion log to debug
This is an expected occurrence with bitmap glyphs and causes unnecessary
spam when using the terminal with one.
2024-12-29 04:56:17 +00:00
sin-ack
1a6d9590a2 font/freetype: Add test for crisp bitmap font rendering
Now we can be certain that bitmap fonts stay crisp. :^)
2024-12-29 04:55:29 +00:00
sin-ack
ea8fe9a4b0 font/freetype: Enable bitmap glyphs for non-color faces
This allows for crisp bitmap font rendering once again.
2024-12-29 02:27:56 +00:00
sin-ack
bfde326bcb font/freetype: Rewrite monoToGrayscale algorithm
The original version had issues converting properly and caused broken
glyphs. This version tries to be as simple as possible in order to make
it easy to understand. I haven't measured the performance but in
practice this will only happen during the first render of the glyph
after a face change (i.e. during launch or when changing font size).
2024-12-29 02:27:52 +00:00
Qwerasd
322f166ca5 coretext: exclude bitmap fonts from discovery
We do not currently support bitmap fonts in a real capacity, and they
often are missing some tables which we currently rely on for metrics,
and we don't handle the metrics calculations failing gracefully right
now.
2024-12-27 14:06:46 -05:00
Qwerasd
9f4d9dc36e font/sprite: fix z2d StaticPath accounting + undefined use
Annotate the node count of all uses of z2d `StaticPath` to verify
correctness, adjusted the size of a couple which were oversized, and
changed all painter calls that take node slices from `StaticPath`s to
use the slice from the wrapped `ArrayList` so that we don't include any
potentially `undefined` nodes at the end of the list, which I think was
causing a crash before.
2024-12-23 04:21:33 -05:00
Qwerasd
98651ab0e5 fmt 2024-12-23 04:18:48 -05:00
Qwerasd
b920352c39 deps: update z2d to v0.4.0
Introduces static path methods and a reworked context API that makes
things generally cleaner.

This update incidentally fixed a bug we had before where the corner
triangle shade characters were drawn solid rather than medium shade.
2024-12-22 16:07:05 -05:00
Mitchell Hashimoto
28c40f9bae font: add cursor-height metric, and adjust- config for it. (#3062)
Subsumes #2580 (which has multiple conflicts with main due to recent
changes to metrics); I figured it'd be easier to just implement it this
way.

#2580 claimed to solve #2487 but I don't think it really does- ideally
we can think of a good way to configure each individual cursor type, but
I don't wanna just do something ad hoc and add a bunch of config keys
blindly so I limited the scope of this.
2024-12-22 10:46:52 -08:00
Qwerasd
3b6d8f3175 fix tests for coretext to include cursor_height 2024-12-22 12:52:04 -05:00
Qwerasd
d624db30c6 test(metrics): fix to initialize cursor height + add comment 2024-12-22 12:38:17 -05:00
Qwerasd
08ebb6b64d fix tests for freetype to include cursor_height metric 2024-12-22 12:34:43 -05:00
Mitchell Hashimoto
eb7b056fba font: add sprites for the separated block quadrants (#2975)
Unicode 16 added "Separated Block Quadrants" from CP 0x0x1CC21 through
0x1CC2F:

𜰡 𜰢 𜰣 𜰤 𜰥 𜰦 𜰧 𜰨 𜰩 𜰪 𜰫 𜰬 𜰭 𜰮 𜰯

To test, use the following command:

```
printf "\U0001CC21\U0001CC22\U0001CC23\U0001CC24\U0001CC25\U0001CC26\U0001CC27\U0001CC28\U0001CC29\U0001CC2A\U0001CC2B\U0001CC2C\U0001CC2D\U0001CC2E\U0001CC2F\n"
```

Which should look like this:

![Screenshot From 2024-12-15
13-15-31](https://github.com/user-attachments/assets/fcf825e1-c824-4f56-8c7d-b4e126401c2b)

cc @qwerasd205 @rockorager
2024-12-22 07:25:27 -08:00
Qwerasd
077dad11b4 font: add cursor-height metric, and adjust- config for it. 2024-12-21 20:15:53 -05:00
Qwerasd
0e21293d43 font(coretext): improve atlas padding calculations
- Simplifies and clarifies the math for how the bounding box for
rendered glyphs is computed
- Reduces margin from 2px between glyphs to 1px by only padding the
bottom and right side of each glyph
- Avoids excessive padding to glyph box when font thicken is enabled or
when using a synthetic bold (it was previously 4x as much padding as
necessary in some cases)
2024-12-19 13:30:52 -08:00
Mitchell Hashimoto
2b78ac4382 font: style edits for #2985 2024-12-16 12:30:34 -08:00
Qwerasd
a06388869d fix: sCapHeight and sxHeight only exist when OS/2 version >= 2 2024-12-16 15:20:26 -05:00
Qwerasd
13e4861dff font(freetype): tolerate fonts without OS/2 tables
This is more common than anticipated, so proper fallback logic has been
added. Why must fonts be like this? -.-
2024-12-16 14:53:29 -05:00
Qwerasd
5cd214066d font(coretext): tolerate fonts without OS/2 tables
This creates big problems if we don't, since a lot of symbols end up
falling back to Apple Gothic, which doesn't have an OS/2 table.
2024-12-16 14:52:07 -05:00
Jeffrey C. Ollie
0c6f4afb34 fix sprite drawing test 2024-12-15 18:00:50 -06:00
Jeffrey C. Ollie
3588d81dcb simplify the code for separated block quadrants 2024-12-15 17:59:04 -06:00
Jeffrey C. Ollie
d0677928af font: add sprites for the separated block quadrants
Unicode 16 added "Separated Block Quadrants" from CP 0x0x1CC21 through 0x1CC2F:

𜰡 𜰢 𜰣 𜰤 𜰥 𜰦 𜰧 𜰨 𜰩 𜰪 𜰫 𜰬 𜰭 𜰮 𜰯

To test, use the following command:

```
printf "\U0001CC21\U0001CC22\U0001CC23\U0001CC24\U0001CC25\U0001CC26\U0001CC27\U0001CC28\U0001CC29\U0001CC2A\U0001CC2B\U0001CC2C\U0001CC2D\U0001CC2E\U0001CC2F\n"
```
2024-12-15 14:33:09 -06:00
Qwerasd
d48c6fc885 config: add adjust keys for new font metrics 2024-12-13 15:36:13 -05:00
Qwerasd
4573890f22 font: fix sign of usWinDescent interpretation 2024-12-13 13:14:49 -05:00
Qwerasd
8a5d484729 font: more robust extraction of vertical metrics from tables
Previously always assuming the typo metrics were good caused some fonts
to have abnormally short cell heights.
2024-12-13 13:00:03 -05:00
Qwerasd
13dd4bd897 font/sprite: separate out cursor rendering from Box
(Fixes width handling when hovering wide chars)
2024-12-13 12:16:15 -05:00
Mitchell Hashimoto
b7dc767237 face: add more RLS types and explicit error sets 2024-12-12 19:47:58 -08:00
Qwerasd
586a7e517e font(freetype): actually take max ascii width instead of first 2024-12-12 21:30:01 -05:00
Qwerasd
f54379aacd font(Box/cursors): properly account for un-adjusted height 2024-12-12 21:04:30 -05:00
Qwerasd
0a29b78a6c clarify naming convention 2024-12-12 20:38:26 -05:00
Qwerasd
0557bf8301 font(metrics): always apply minimum values after calculating 2024-12-12 13:47:13 -05:00
Qwerasd
fb50143cec font(coretext): add metrics test case for CT, fix variable font init
Variable font init used to just select the first available predefined
instance, if there were any, which is often not desirable- using
createFontDescriptorFromData instead of createFontDescritorsFromData
ensures that the default variation config is selected. In the future we
should probably allow selection of predefined instances, but for now
this is the correct behavior.

I found this bug when adding the metrics calculation test case for
CoreText, hence why fixing it is part of the same commit.
2024-12-11 21:14:21 -05:00
Qwerasd
bd18452310 font: unify metrics calculations & separate sprite metrics
Unify grid metrics calculations by relying on shared logic mostly based
on values directly from the font tables, this deduplicates a lot of code
and gives us more control over how we interpret various metrics.

Also separate metrics for underlined, strikethrough, and overline
thickness and position, and box drawing thickness, so that they can
individually be adjusted as the user desires.
2024-12-11 16:55:52 -05:00
Qwerasd
7e5a164be8 font/opentype: add table parsing for head, hhea, post, and OS/2
(and a utility for parsing SFNT font files and fetching table data from
them)
2024-12-10 16:35:51 -05:00
Mike Hartington
df4a6f2161 font/sprite: add missing chevron powerline fonts 2024-11-29 14:26:22 -05:00
Mark Peek
ea3d997f3e Include font copyright information into OFL.txt and add MIT license 2024-11-15 12:35:29 -08:00
Kevin
900f0efb75 add accompanying README with license details 2024-11-15 13:29:50 -05:00
Kevin
9cce09a36b add OFL.txt 2024-11-15 12:45:42 -05:00
Mitchell Hashimoto
3ee6577154 some tweaks 2024-11-09 11:03:02 -08:00