62 Commits

Author SHA1 Message Date
Mitchell Hashimoto
5ad8ea6b22 pkg/macos: clean up for Zig 0.14, consolidate C imports into one decl
Fixes #6727

The major change in this commit is to consolidate all the C imports in
a single decl in main.zig. This is required for Zig 0.14. Without it,
the problem in #6727 will happen. I was never able to minimize why this
happens in order to open a Zig bug.

Beyond this, I fixed the build.zig and build.zig.zon to work with Zig
0.14 so that we can test building `pkg/macos` in isolation. There are no
downstream impacting changes in the build.zig files.
2025-03-15 07:02:53 -07: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
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
Mitchell Hashimoto
1aa932f810 font/coretext: use CTFontCreateForString for final codepoint fallback
Fixes #2499

We rely on CoreText's font discovery to find the best font for a
fallback by using the character set attribute. It appears that for some
codepoints, the character set attribute is not enough to find a font
that supports the codepoint.

In this case, we use CTFontCreateForString to find the font that
CoreText would use. The one subtlety here is we need to ignore the
last resort font, which just has replacement glyphs for all codepoints.

We already had a function to do this for CJK characters (#1637)
thankfully so we can just reuse that!

This also fixes a bug where CTFontCreateForString range param expects
the range length to be utf16 code units, not utf32.
2024-10-25 21:29:45 -07:00
Qwerasd
3ec36e4d23 coretext: improve strikethrough position calculation 2024-09-23 19:01:15 -06:00
Mitchell Hashimoto
f5234e286a pkg/macos: copyAttribute should return optional 2024-08-24 20:35:41 -07:00
Mitchell Hashimoto
318dc85c02 pkg/macos: yeet more usingns 2024-08-16 16:50:41 -07:00
Mitchell Hashimoto
1a7cde9e3e font/coretext: can read font tables 2024-05-27 20:23:10 -07:00
Mitchell Hashimoto
9f4d4d3c61 font: treated fonts with mixed color/non-color glyphs as text
Related to #1768 but doesn't fix it properly.

This is a temporary hack to avoid some issues with fonts that have mixed
color/non-color glyphs. If there are mixed presentations and the font
does not have emoji codepoints, then we assume it is text. This fixes
the typical scenarios.

This is not a long term solution. A proper long term solution is to
detect this scenario and on a per-glyph basis handle colorization (or
the lack thereof) correctly. It looks like to do this we'll have to
parse some font tables which is considerably more work so I wanted to do
this first.
2024-05-26 10:17:20 -07:00
Mitchell Hashimoto
1cb70d6e40 font/coretext: force LTR shaping 2024-05-08 10:11:57 -07:00
Mitchell Hashimoto
eeb7f7aa02 pkg/macos: add more text APIs 2024-05-08 09:49:16 -07:00
Mitchell Hashimoto
1189817dd8 pkg/macos: CTFontCreateForString 2024-05-05 21:38:19 -07:00
Mitchell Hashimoto
a29a0a1e5c pkg/macos: add more CoreText APIs 2024-05-05 21:01:44 -07:00
Gordon Cassie
abd782a7aa Fix typo. 2024-04-30 10:20:31 -07:00
Kyaw
22d631942c font/coretext: use CTFontCopyFamilyName
Use `CTFontCopyFamilyName` instead of `CTFontCopyDisplayName` to get
the font name to match the behavior of how it's done on freetype
backend.
2023-12-15 02:26:47 +06:30
Mitchell Hashimoto
cc0b615552 pkg/macos: more APIs 2023-12-11 20:48:45 -08:00
Mitchell Hashimoto
0137f5b0d3 pkg/macos: add many more text APIs 2023-12-11 11:12:29 -08:00
Mitchell Hashimoto
ff68c56268 pkg/macos: implement CTRun 2023-12-11 11:12:28 -08:00
Mitchell Hashimoto
cb684e35cc font/coretext: discovery scoring should take into account symb. traits
Fixes #707

Our scoring algorithm previously did not take into account symbolic
traits, so when `bold = false and italic = false`, regular, bold, italic
would all be equally likely to appear first.

This modifies our scoring algorithm to prioritize matching symbolic
traits. Further, we have a special case for no symbolic traits to
prioritize "Regular" named styles. We can expand this to other styles
too but we do not do this here.

We also modified the algorithm to always prefer fonts with more glyphs
over fonts with less, hopeful that we can load fewer fonts for other
glyphs later.
2023-11-03 22:21:34 -07:00
Mitchell Hashimoto
1411015038 font: fallback search should search full discovery chain
Fixes #668

We were previously only checking the first font result in the search.
This also fixes our CoreText scoring algorithm to prioritize faces that
have the codepoint we're searching for.
2023-10-13 12:25:27 -07:00
Mitchell Hashimoto
1127330b3a font/coretext: score discovered fonts 2023-10-03 09:17:41 -07:00
Mitchell Hashimoto
9d0729f17c font/coretext: ability to set variation axes 2023-08-28 07:25:09 -07:00
Mitchell Hashimoto
fb0f80f9ca macos: add necessary functions for variation axes querying 2023-08-28 07:25:09 -07:00
Mitchell Hashimoto
4bf8a0d149 font: support skew transform for auto-italics 2023-07-03 15:54:50 -07:00
Mitchell Hashimoto
0a718ec3eb pkg/macos: do not use bitCast through a function
workaround Zig issue: https://github.com/ziglang/zig/issues/16290
2023-07-01 13:38:10 -07:00
Mitchell Hashimoto
d39e3f5428 coretext: improved baseline calculation 2023-07-01 09:23:40 -07:00
Mitchell Hashimoto
45da58188c fix up for new zig 2023-07-01 09:23:39 -07:00
Mitchell Hashimoto
2a1cbb4f21 coretext: calculate units per em/point 2023-07-01 09:23:39 -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
b196e43ee4 fix some issues for future Zig update 2023-05-19 08:34:07 -07:00
Mitchell Hashimoto
da2942e083 font: specific codepoint lookup in internals 2022-11-17 15:49:14 -08:00
Mitchell Hashimoto
6c84199b84 fix more stage2 build errors 2022-10-14 10:01:41 -07:00
Mitchell Hashimoto
a6c3ee3bc2 pkg/macos: fix zig C ABI issue 2022-10-10 09:18:57 -07:00
Mitchell Hashimoto
1cf390729e pkg/macos: bitmap info arg 2022-10-09 16:29:19 -07:00
Mitchell Hashimoto
1b7bc052d4 font: coretext calculate cell metrics 2022-10-09 10:57:19 -07:00
Mitchell Hashimoto
8b3959dceb macos: frames, attributed strings, stylized strings 2022-10-09 08:07:56 -07:00
Mitchell Hashimoto
1e2e4169a5 pkg/macos: starting frames 2022-10-08 17:52:01 -07:00
Mitchell Hashimoto
061f7f6a30 pkg/macos: text framesetter 2022-10-08 17:29:50 -07:00
Mitchell Hashimoto
a97f997f9a font: start working on core text cell height calcs 2022-10-08 17:03:09 -07:00
Mitchell Hashimoto
c9a335646e pkg/macos: some font metrics functions 2022-10-08 11:34:45 -07:00
Mitchell Hashimoto
26629bcb6e pkg/macos: create fonts from data 2022-10-08 10:21:33 -07:00
Mitchell Hashimoto
240c560720 macos: create descriptors from URL 2022-10-08 10:16:35 -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
833fd0e49a pkg/macos: bounding rects for text 2022-10-07 21:23:34 -07:00
Mitchell Hashimoto
c48ddcecd7 pkg/macos: font draw glyphs 2022-10-07 21:04:30 -07:00
Mitchell Hashimoto
c565c561fd Use Apple Emoji font on Mac 2022-10-02 11:20:55 -07:00
Mitchell Hashimoto
12c9482d48 Mac Font Discovery with CoreText (#17)
This implements font discovery so the `--font-family` flag works for macOS. Fonts are looked up using the Core Text API so any installed font on the Mac system can be used. 

We still use FreeType for rendering, and CoreText doesn't _quite_ give us all the information we need to build the exact face in FreeType. So a TODO after this is to now implement glyph _rendering_ using Core Text and Core Graphics. Until then, a couple fonts don't quite work (i.e. Monaco, a big one!) but many do!
2022-10-01 22:21:30 -07:00
Mitchell Hashimoto
791739de9c pkg/macos: font initializes, get glyphs 2022-10-01 21:49:02 -07:00