684 Commits

Author SHA1 Message Date
Qwerasd
8b8e0bedad font: add scale groups to nerd font constraints
We do this by characterizing the shared bounding boxes in a static copy
of the symbols only nerd font when we're doing the codegen. This allows
us to get results of our scaling that are just as good as in a patched
font, since related glyphs can now be sized and positioned relative to
each other.
2025-07-08 12:00:22 -06:00
Qwerasd
1430660933 font: constrain width of two-cell icon-height icons
This stops things like folder icons from becoming over-wide. The patcher
typically makes these glyphs always 1 cell wide, but since we know how
it will be displayed we have the benefit of being able to make it more
than 1 cell when there's room. This makes our dynamic scaling *better*
than a static patched font :D
2025-07-08 11:56:49 -06:00
Qwerasd
a67b8b35f6 font/coretext: disable Apple's quantization, do it ourselves
Using the "subpixel quantization" option for rendering our glyph was
creating bad edge cases where we'd lose the bottom or left row / column
of pixels in a glyph sometimes. I investigated the exact effect of this
option and it seems like beyond quantizing the position and scale it's
also doing some rudimentary auto-hinting. That said, the auto-hinting
doesn't do that much for us, and the fact that it horizontally snaps
coordinates to thirds of a pixel instead of whole pixels makes things
worse in terms of legibility at small pixel sizes, so ultimately it's
better with our own handling anyway.

I extensively compared the result of Apple's option with our own manual
quantization here and I'm pretty sure this will always match the whole
pixel sizes, and where it differs (other than things like crossbars) it
seems to make glyphs generally more legible not less.
2025-07-07 21:26:23 -06:00
Qwerasd
5bc41dc694 Nerd Font Icon Height Constraint (#7850)
Nerd font icons were ***WAY*** too big depending on your font setup,
this is because we were always using the full cell height when the nerd
font patcher instead uses an "icon height" for most things. The patcher
calculates the icon height as two thirds of the font's cap height and
one third of the line height, but I've chosen to instead use 1.2 times
the cap height for more consistent results across fonts-- if the user
wants their icons bigger, they can use the `adjust-icon-height` metric
modifier (and they can also use it to make them smaller if they want
that for some reason).

I also adjusted the attributes to user horizontal cover + vertical fit
for `^` stretch modes (proportional scaling but scale up), which makes
it so that it never exceeds the cell size, since first it covers
horizontally and then scales down to fit vertically if necessary;
previously, if there were a particularly wide glyph that was scaled with
cover/cover it would exceed the available width and overflow in to
neighboring cells which wasn't good.
2025-07-07 10:25:53 -06:00
Qwerasd
bcb6ee6db6 config: add adjust-icon-height option
Metric modifier for the `icon_height` metric.
2025-07-07 10:04:11 -06:00
Qwerasd
c47459b4a2 font: add icon height to nerd font constraints
Icons were often WAY too big before because they were filling the whole
cell in height, which isn't great lol. This commit adds an `icon_height`
metric which is used to constrain glyphs that shouldn't be the size of
the entire cell.
2025-07-07 10:04:11 -06:00
Qwerasd
23cc50b12c font/Metrics: remove original_cell_width, no longer needed 2025-07-07 09:09:37 -06:00
Qwerasd
e1e2f823ba font/coretext: fix horizontal bearing calculation
This was subtly wrong in a way that was most obvious when text switched
from regular to bold, where it would seem to wiggle since the bearings
of each letter would shift by a pixel in either direction. This affected
applications like fzf which uses bold to dynamically highlight the line
you have selected.
2025-07-07 08:57:20 -06:00
Qwerasd
00d1e34957 Fallback Font Size Adjustment (#7840)
This PR changes `font.Collection` to automagically adjust the sizes of
added fonts so that their metrics (specifically their ex height, or
their ideograph character width if they have one) match the primary
font. This is like
[`font-size-adjust`](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size-adjust)
from CSS.

This is a big win for users who use mixed writing systems and rely
heavily on fallback fonts. For example, in #7774 it's pointed out that
CJK characters are not very well harmonized with existing Latin glyphs,
well:
|Before (`main`)|After (this PR)|
|-|-|
|<img width="326" alt="image"
src="https://github.com/user-attachments/assets/c11d372d-ec69-426d-b008-1f56a7430f23"
/>|<img width="326" alt="image"
src="https://github.com/user-attachments/assets/efcb56ea-0572-481a-b632-a0b5cd170fa9"
/>|

This also improves our handling of the horizontal alignment of fallback
glyphs. It's not an ideal solution; it only works for glyphs narrower
than the cell width because it messes with ligatures if we include
glyphs wider than the cell width; and most things would look better if
the center were proportionally remapped based on the ratio from the
glyph advance to the cell width, but that messes with glyphs designed to
align vertically so it can't be done, instead the original advance width
is centered in the cell width.
2025-07-06 23:01:55 -06:00
Qwerasd
08fd1688ff font: add test for size adjustment, fix small bug in resize
Previously produced very wrong values when calling Collection.setSize,
since it was assuming that the provided face had the same point size as
the primary face, which isn't true during resize-- so instead we just
have faces keep track of their set size, this is generally useful.
2025-07-06 22:45:13 -06:00
Qwerasd
d33161ad66 fix(font): include line gap in lineHeight helper 2025-07-06 22:40:43 -06:00
Qwerasd
327caf903c font: fix nerd font patcher ypadding twice what it should be
The nerd font patcher uses `ypadding` as a single subtraction from the
cell height, which means that half of it should go to the top padding
and the other half to the bottom, this was making the heavy brackets way
too small lol (0.4 of the cell height instead of 0.7)
2025-07-06 17:20:39 -06:00
Qwerasd
db08bf1655 font: adjust fallback font sizes to match primary metrics
This better harmonizes fallback fonts with the primary font by matching
the heights of lowercase letters. This should be a big improvement for
users who use mixed scripts and so rely heavily on fallback fonts.
2025-07-06 16:55:50 -06:00
Qwerasd
d3aece21d8 font: more generic bearing adjustments
This generally adjusts the bearings of any glyph whose original advance
was narrower than the cell, which helps a lot with proportional fallback
glyphs so they aren't just left-aligned. This only applies to situations
where the glyph was originally narrower than the cell, so that we don't
mess up ligatures, and this centers the old advance width in the new one
rather than adjusting proportionally, because otherwise we can mess up
glyphs that are meant to align with others when placed vertically.
2025-07-06 16:34:31 -06:00
Qwerasd
b10b0f06c3 font: remove unused fields from Glyph
We can reintroduce `advance` if we ever want to do proportional string
drawing, but we don't use it anywhere right now. And we also don't need
`sprite` anymore since that was just there to disable constraints for
sprites back when we did them on the GPU.
2025-07-06 15:53:59 -06:00
Qwerasd
c7e65b0c1c font: respect cell width attributes in nerd font constraints
This mostly applies to powerline glyphs, but is also relevant for heavy
bracket characters, which need to always be 1 wide otherwise they look
silly because they misalign depending on if there's a space after them
or not.
2025-07-06 11:23:49 -06:00
Qwerasd
8f989f6bfd font: fix nerd font codegen to handle ypadding properly
Previously `ypadding` was effectively ignored, since it's mutually
exclusive with `overlap`. This had a noticeable effect on the heavy
bracket characters U+276C...U+2771, which were much taller than they
should have been.

I also fixed the vertical overlap limit, since negative `overlap` values
are used in the nerd font attributes to create padding on all sides of
the cell, so we don't want to limit the magnitude of the overlap for
vertical padding, we only want to limit it if the value is positive.

That change fixed the vertical padding for a handful of ranges, which
should give more consistent results.
2025-07-06 11:02:00 -06:00
Qwerasd
7de4d569b0 Revert "rely on stdin/stdout instead of hardcoded paths"
This reverts commit 2fca0477bc7f3c955daf40a0d4663d63ef3d76a1.

The idea of using stdin and stdout was the integrate it in to the build
script, but since we don't want to do that because it contains an eval,
it just makes it more annoying to use.
2025-07-06 10:49:49 -06:00
Qwerasd
dc18f1a2b9 "Better Glyph Constraint Logic" follow-up (#7822)
Follow-up to #7809, a handful of small fixes/improvements, explained
individually in each commit message.

> [!NOTE]
> Similar to the inverted "monochrome" ft flag fix from #7809, it was
pointed out that "force-autohint" was also inverted, so I did invert
that too, this has the same result of no impact on users who haven't
explicitly set it, but a breaking behavior change for users who have set
it. *These changes definitely need to be pointed out in the 1.2 release
notes!*
2025-07-05 23:04:09 -06:00
Qwerasd
8f50c7f269 font/sprite: no more margin in atlas region
We no longer need a margin in the atlas because we always sample with
nearest neighbor and our glyphs are always pixel perfect, no worry about
interpolation between adjacent glyphs anymore!
2025-07-05 22:13:26 -06:00
Qwerasd
02d82720d2 font/freetype: fix negated force-autohint flag
The behavior of this flag was the opposite of its description in the
docs- luckily, at the same time, the default (true) was the opposite
from what the default actually is in freetype, so users who haven't
explicitly set this flag won't see a behavior difference from this.
2025-07-05 20:40:12 -06:00
Qwerasd
fff16bff69 font/coretext: fix bitmap size calculation, prevent clipping
Previously, many glyphs were having their top and right row/column of
pixels clipped off due to not accounting for the slight bearing in the
width and height calculation here.
2025-07-05 20:36:35 -06:00
trag1c
2fca0477bc rely on stdin/stdout instead of hardcoded paths 2025-07-06 02:28:28 +02:00
trag1c
4b6c461d6f refactor nerd font codegen script 2025-07-06 02:08:46 +02:00
Qwerasd
1ab2603e0f font/freetype: remove freetype_convert.zig
This is no longer needed since we're now using the FT_Bitmap_Convert
function from FreeType to do any conversions we need instead.
2025-07-04 15:47:35 -06:00
Qwerasd
f292132762 font: add constraint width to glyph cache key 2025-07-04 15:47:28 -06:00
Qwerasd
1a8a048136 font/sfnt: simpler and more efficient FixedType conversions 2025-07-04 15:47:28 -06:00
Qwerasd
5553f7bf68 font: always maximize size of emoji and center them 2025-07-04 15:47:28 -06:00
Qwerasd
1775b75f2c font: generate glyph constraints based on nerd font patcher 2025-07-04 15:47:28 -06:00
Qwerasd
e441094af0 font: add constraint logic to rasterizers
This is in preparation to move constraint off the GPU to simplify our
shaders, instead we only need to constrain once at raster time and never
again.

This also significantly reworks the freetype renderGlyph function to be
generally much cleaner and more straightforward.

This commit doesn't actually apply the constraints to anything yet, that
will be in following commits.
2025-07-04 15:47:28 -06:00
Qwerasd
d751a93ecf font: use variable JetBrains Mono for embedded font
This cuts down our file size significantly.
2025-07-03 16:27:59 -06:00
Qwerasd
c2484f48ef font: add jb mono and symbols-only nerd font as dependencies
Rather than using binaries statically in our source tree; this makes
them easier to update. This also makes it so that they are separated
from each other rather than using a patched JB mono as our fallback.
2025-07-03 15:59:04 -06:00
Qwerasd
a91f9ed0e2 font/coretext: fix small memory leak 2025-07-02 11:38:26 -06:00
Qwerasd
2a836b0ab7 font/coretext: fix small memory leak 2025-07-02 11:02:33 -06:00
Qwerasd
cff6860fd9 font/sprite: update reference images 2025-07-01 17:03:10 -06:00
Qwerasd
0cd95a791f font/sprite: add sflc supplement circle/ellipse glyphs 2025-07-01 16:52:17 -06:00
Qwerasd
ffe06f1ccd font/sprite: add sixteenth blocks from slfc supplement 2025-07-01 16:26:57 -06:00
Qwerasd
c838d3d7d2 font/sprite: remove yHalfs and friends, use Fraction
Introduces `fill`, which fills between two `Fraction`s, use this instead
of `yHalfs` and friends wherever they're used, which also means we can
remove `rect`.

This commit does change alignment of the vertical/horizontal eighths in
certain cell sizes, but the change is for the better IMO. Also changes
the center-point alignment of smooth mosaics for odd cell widths, but
the change is no more than half a pixel at worst and is probably an
improvement ultimately.
2025-07-01 16:00:45 -06:00
Qwerasd
ac87154362 font/sprite: introduce Fraction enum for cell fractions
I've included a compatibility test here to make sure that the numbers
from this are in line with the numbers produced by xHalfs, yThirds, etc.

After this commit I'll introduce a helper function that fills based on a
span specified with this enum to replace any uses of xHalfs and friends.

Once I do that I'll remove them and the compatibility test, this should
be a much cleaner interface for this and make it easier to consistently
align block elements with each other.
2025-07-01 15:04:21 -06:00
Qwerasd
adace942d0 font/sprite: update reference images 2025-07-01 13:20:10 -06:00
Qwerasd
b4d83e6349 font/sprite: align quadrants better with other glyphs
Use `xHalfs` and `yHalfs` so that the dimensions of each quadrant are
appropriately aligned with block elements like the one half block, which
could be 1px taller than the bottom quadrants before this change.

This is in line with what we do for sextants, the fact that on odd-sized
cells there's a 1px overlap is considered acceptable there so I assume
it's acceptable here too.
2025-07-01 13:15:54 -06:00
Qwerasd
0414e9e281 font/sprite: add (some) sflc supplement box drawing chars 2025-07-01 13:15:54 -06:00
Qwerasd
dd9ca556f9 font/sprite: add sflc supplement circle pieces 2025-07-01 13:15:54 -06:00
Qwerasd
95fbeb5b82 style(font/sprite): annotate type for value 2025-06-30 16:44:21 -06:00
Qwerasd
a00a727e77 test(font/Atlas): add test case for setFromLarger 2025-06-30 16:37:26 -06:00
Qwerasd
8b6e1fe5b1 font/sprite: update reference PNGs to match new z2d export 2025-06-30 11:16:47 -06:00
Qwerasd
2084d5f256 font/sprite+renderer: never constrain sprite glyphs
This was creating problems with the branch drawing glyphs at some sizes.

In the future the whole "foreground modes" thing needs to be reworked,
so this is just a stopgap until that gets turned in to something nicer.
2025-06-30 11:16:47 -06:00
Qwerasd
e691404a57 prettier format 2025-06-30 11:16:47 -06:00
Qwerasd
4f9d7c565a font/sprite: add explicit underline cursor
Resolves #7651 - uses cursor thickness rather than underline thickness.
2025-06-30 11:16:47 -06:00
Qwerasd
c96af1b3b1 font/sprite: add separated sextants from sflc supplement 2025-06-30 11:16:47 -06:00