34 Commits

Author SHA1 Message Date
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
Mitchell Hashimoto
2408d4c6a9 more fixes 2025-03-12 09:59:24 -07: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
3ee6577154 some tweaks 2024-11-09 11:03:02 -08:00
Nadir Fejzic
4def80ce16 refactor: use if expression instead of switch 2024-11-09 13:09:15 +01:00
Nadir Fejzic
67966cb091 refactor: add default value for `freetype_load_flags' 2024-11-09 13:06:36 +01:00
Nadir Fejzic
83c4d0077b refactor: define FreetypeLoadFlags struct and default in font.face 2024-11-09 12:34:39 +01:00
Nadir Fejzic
c0b24ee60d refactor: make freetype flags void for non-freetype backend
This is an attempt to use `void` as type for Freetype Load Flags when
backend does not use these flags.
2024-11-09 01:39:10 +01:00
Nadir Fejzic
945a715b08 refactor: handle freetype load flags in face instead of renderer 2024-11-09 00:42:18 +01:00
Nadir Fejzic
74bda5a6eb feat: implement configurable freetype load flags 2024-11-08 20:38:38 +01:00
Qwerasd
d01db9f793 revert dpi type to u16 2024-05-09 00:03:40 -04:00
Qwerasd
d4a7549222 feat(font): Non-integer point sizes
Allows for high dpi displays to get odd numbered pixel sizes, for
example, 13.5pt @ 2px/pt for 27px font. This implementation performs
all the sizing calculations with f32, rounding to the nearest pixel
size when it comes to rendering. In the future this can be enhanced
by adding fractional scaling to support fractional pixel sizes.
2024-05-09 00:03:40 -04:00
Mitchell Hashimoto
851b1fe2ac font: noop shaper 2024-05-01 20:31:50 -07:00
Mitchell Hashimoto
1072354747 build: add -Dfont-backend=coretext_harfbuzz to force Harfbuzz w/ CT 2024-04-30 14:03:38 -07:00
Mitchell Hashimoto
552c97eea4 font/freetype: avoid overflows with u8 font size 2024-03-27 20:45:55 -07:00
Mitchell Hashimoto
461b16ce34 font sizes are limited to u8 (max size = 255 points)
Fixes #1618

Font sizes in configuration were always a u8, but the keybinding and
internal state was a u16 so it allowed for an ever-growing font size. At
a certain point, there is an integer overflow which causes it to wrap
around. This is all silly, 255 should be large enough for anyone[1]

[1]: Ready to be super wrong about this
2024-03-27 20:36:59 -07:00
Mitchell Hashimoto
7f40881747 font: faces use primary grid metrics to better line up glyphs
Fixes #895

Every loaded font face calculates metrics for itself. One of the
important metrics is the baseline to "sit" the glyph on top of. Prior to
this commit, each rasterized glyph would sit on its own calculated
baseline. However, this leads to off-center rendering when the font
being rasterized isn't the font that defines the terminal grid.

This commit passes in the font metrics for the font defining the
terminal grid to all font rasterization requests. This can then be used
by non-primary fonts to sit the glyph according to the primary grid.
2023-12-02 09:51:15 -08:00
Mitchell Hashimoto
3d8dd0783a font: if VS15/16 not specified, prefer any presentation in explicit font
Fixes #845

Quick background: Emoji codepoints are either default text or default
graphical ("Emoji") presentation. An example of a default text emoji
is ❤. You have to add VS16 to this emoji to get: ❤️. Some font are
default graphical and require VS15 to force text.

A font face can only advertise text vs emoji presentation for the entire
font face. Some font faces (i.e. Cozette) include both text glyphs and
emoji glyphs, but since they can only advertise as one, advertise as
"text".

As a result, if a user types an emoji such as 👽, it will fallback to
another font to try to find a font that satisfies the "graphical"
presentation requirement. But Cozette supports 👽, its just advertised
as "text"!

Normally, this behavior is what you want. However, if a user explicitly
requests their font-family to be a font that contains a mix of test and
emoji, they _probably_ want those emoji to be used regardless of default
presentation. This is similar to a rich text editor (like TextEdit on
Mac): if you explicitly select "Cozette" as your font, the alien emoji
shows up using the text-based Cozette glyph.

This commit changes our presentation handling behavior to do the
following:

  * If no explicit variation selector (VS15/VS16) is specified,
    any matching codepoint in an explicitly loaded font (i.e. via
    `font-family`) will be used.

  * If an explicit variation selector is specified or our explicitly
    loaded fonts don't contain the codepoint, fallback fonts will be
    searched but require an exact match on presentation.

  * If no fallback is found with an exact match, any font with any
    presentation can match the codepoint.

This commit should generally not change the behavior of Emoji or VS15/16
handling for almost all users. The only users impacted by this commit
are specifically users who are using fonts with a mix of emoji and text.
2023-11-08 21:55:20 -08:00
Mitchell Hashimoto
7995d44cfb font: render sprites with a configurable grid cell width
Fixes #666
2023-10-13 14:31:55 -07:00
Mitchell Hashimoto
54b9b45a7f font: rework font init to use a struct with modifiersets everywhere 2023-10-04 17:23:57 -07:00
Mitchell Hashimoto
bac5e20962 font: Metrics.Modifier for applying a percentage/absolute change 2023-10-04 15:28:22 -07:00
Mitchell Hashimoto
9d0729f17c font/coretext: ability to set variation axes 2023-08-28 07:25:09 -07:00
Mitchell Hashimoto
0faf6097d0 Change font metrics to all be integers, not floats.
Font metrics realistically should be integral. Cell widths, cell
heights, etc. do not make sense to be floats, since our grid is
integral. There is no such thing as a "half cell" (or any point).

The reason we historically had these all as f32 is simplicity mixed
with history. OpenGL APIs and shaders all use f32 for their values, we
originally only supported OpenGL, and all the font rendering used to be
directly in the renderer code (like... a year+ ago).

When we refactored the font metrics calculation to its own system and
also added additional renderers like Metal (which use f64, not f32), we
never updated anything. We just kept metrics as f32 and casted
everywhere.

With CoreText and #177 this finally reared its ugly head. By forgetting
a simple rounding on cell metric calculation, our integral renderers
(sprite fonts) were off by 1 pixel compared to the GPU renderers.
Insidious.

Let's represent font metrics with the types that actually make sense: a
cell width/height, etc. is _integral_. When we get to the GPU, we now
cast to floats. We also cast to floats whenever we're doing more precise
math (i.e. mouse offset calculation). In this case, we're only
converting to floats from a integral type which is going to be much
safer and less prone to uncertain rounding than converting to an int
from a float type.

Fixes #177
2023-07-03 11:23:20 -07:00
Mitchell Hashimoto
3795cd6c2d font: turn rasterization options into a struct, add thicken 2023-07-01 09:55:19 -07:00
Mitchell Hashimoto
2a74330911 font: begin making Group work with wasm 2022-12-05 16:08:20 -08:00
Mitchell Hashimoto
37f00ac725 don't export coretext/freetype 2022-12-04 13:19:29 -08:00
Mitchell Hashimoto
940828ed97 font: web canvas creates a canvas element 2022-12-03 22:11:01 -08:00
Mitchell Hashimoto
b858aea124 Start scaffolding web_canvas backend 2022-12-01 13:02:17 -08:00
Mitchell Hashimoto
f393049988 fix compilation 2022-10-08 11:25:54 -07:00
Mitchell Hashimoto
723db8be2f font: coretext face presentation 2022-10-08 09:55:22 -07:00
Mitchell Hashimoto
90f3b9391c font: begin coretext Face 2022-10-08 09:43:54 -07:00
Mitchell Hashimoto
71ec509930 Make font face a compile time interface, stub for coretext 2022-10-08 09:19:21 -07:00