26 Commits

Author SHA1 Message Date
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
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
10b8ca3c69 spelling: normalize grey -> gray 2024-08-11 18:31:01 -04:00
Qwerasd
fa45c18a6a fix point size type 2024-05-09 00:03:40 -04:00
Krzysztof Wolicki
44a48f62f1 change unmodified vars to consts in anticipation of zig changes 2023-11-17 15:46:46 +01:00
Kevin Hovsäter
22b8173164 Fix typos 2023-08-08 14:27:34 +02: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
314f9287b1 Update Zig (#164)
* update zig

* pkg/fontconfig: clean up @as

* pkg/freetype,harfbuzz: clean up @as

* pkg/imgui: clean up @as

* pkg/macos: clean up @as

* pkg/pixman,utf8proc: clean up @as

* clean up @as

* lots more @as cleanup

* undo flatpak changes

* clean up @as
2023-06-30 12:15:31 -07:00
Mitchell Hashimoto
56f8e39e5b Update zig, mach, fmt 2023-06-25 11:08:20 -07:00
Mitchell Hashimoto
bc74033ad6 face: web canvas can render grapheme clusters 2022-12-12 21:40:54 -08:00
Mitchell Hashimoto
c06ca04a1a font: web canvas tracks glyph indexes for grapheme clusters 2022-12-12 11:31:30 -08:00
Mitchell Hashimoto
0c9a9b1f91 font: web canvas face has to render to check presentation for cp
Since we have no way to detect our presentation (text/emoji), we need to
actually render the glyph that is being requested to double-check that
the glyph matches our supported presentation.

We do this because the browser will render fallback fonts for a glyph if
it can't find one in the named font.
2022-12-07 19:20:04 -08:00
Mitchell Hashimoto
6aa212707e font: web canvas can render emoji 2022-12-06 10:55:42 -08:00
Mitchell Hashimoto
d2afddb7e2 font: fix some JS memory leaks 2022-12-05 15:45:31 -08:00
Mitchell Hashimoto
ed4e8c36b0 font: add 1 to the canvas glyph to avoid clipping 2022-12-05 15:37:55 -08:00
Mitchell Hashimoto
25f2f1a652 font: fix glyph offset calculations for render 2022-12-05 15:25:09 -08:00
Mitchell Hashimoto
5e9dd02eab font: add method for drawing atlas to canvas 2022-12-05 15:01:34 -08:00
Mitchell Hashimoto
84f6f37450 face: web canvas glyph rendering appears to work! 2022-12-05 14:28:10 -08:00
Mitchell Hashimoto
19e326dab6 font: working on rendering glyphs in canvas 2022-12-05 10:54:40 -08:00
Mitchell Hashimoto
df302fc2b6 calculate font metrics via canvas 2022-12-04 22:01:58 -08:00
Mitchell Hashimoto
c48d8cd151 hook up logging to wasm, example uses new zig-js package 2022-12-04 13:16:54 -08:00
Mitchell Hashimoto
437f1772f1 logging works for wasm 2022-12-04 12:29:11 -08:00
Mitchell Hashimoto
940828ed97 font: web canvas creates a canvas element 2022-12-03 22:11:01 -08:00
Mitchell Hashimoto
c32219554a blank out web canvas impl 2022-12-01 13:02:17 -08:00
Mitchell Hashimoto
b858aea124 Start scaffolding web_canvas backend 2022-12-01 13:02:17 -08:00