aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx/platform/macos/font.rs
Commit message (Collapse)AuthorAgeFilesLines
* Rename `gfx` to `fonts` (#32556)Martin Robinson2024-06-191-377/+0
| | | | | | | | | This crate only takes care of fonts now as graphics related things are split into other crates. In addition, this exposes data structures at the top of the crate, hiding the implementation details and making it simpler to import them. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* fonts: Improve font fallback (#32286)Martin Robinson2024-05-271-1/+0
| | | | | | | | | | | | | | | | | | - Better detect situations where emoji is necessary by looking ahead one character while laying out. This allow processing Unicode presentation selectors. When detecting emoji, put emoji fonts at the front of fallback lists for all platforms. This enables monochrome emoji on Windows. Full-color emoji on Windows probably needs full support for processing the COLR table and drawing separate glyph color layers. - Improve the font fallback list on FreeType platforms. Ideally, Servo would be able to look through the entire font list to find the best font for a certain character, but until that time we can make sure the font list contains the "Noto Sans" fonts which cover most situations. Fixes #31664. Fixes #12944.
* fonts: Make `FontContext` thread-safe and share it per-Layout (#32205)Martin Robinson2024-05-021-0/+11
| | | | | | | | | | | | This allows sharing font templates, fonts, and platform fonts across layout threads. It's the first step toward storing web fonts in the layout versus the shared `FontCacheThread`. Now fonts and font groups have some locking (especially on FreeType), which will probably affect performance. On the other hand, we measured memory usage and this saves roughly 40 megabytes of memory when loading servo.org based on data from the memory profiler. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* feat: Support font-relative `ch` and `ic` units (#32171)Andreu Botella2024-05-021-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * feat: Support font-relative `ch` and `ic` units After #31966, which made it possible for the first time to resolve font-relative CSS units, this change adds support for the `ch` and `ic` units. One difference with the `ex` unit that was added in that PR is that these units must reflect the advance width of a character (the zero digit in the case of `ch`, and the CJK water radical for `ic`) as it would be rendered by the current font group. This means that the size of these units don't only depend on the first available font, in the case where that font does not contain a glyph for that character. This is implemented by adding the advance width for these two characters as optional fields of `FontMetrics`, so the advance width computation happens in advance. Then, when the font metrics are queried as part of unit resolution, the font group is searched for the first font containing that character. This change only implements support for these units in upright typesetting modes, since Servo does not yet have support for vertical writing modes. This means that many of the WPT tests that test for the behavior of these units with vertical writing modes do not pass. This change also makes a number of WPT tests pass, which relied on the `ch` and `ic` units. It, however, also makes the test `/css/css-text/white-space/text-wrap-balance-overflow-002.html` fail, since it tests `text-wrap: balance`, which Servo does not yet implement, and it was only previously passing by chance due to the previous behavior of these units. * Revert Python 3.10-related changes to wss * Fix formatting * Remove test expectation
* fonts: Use `FontInstanceFlags::EMBEDDED_BITMAPS` for color fonts on MacOS ↵Martin Robinson2024-05-021-1/+14
| | | | | | (#32203) This flag ensures that these fonts are rendered full color in WebRender, allowing for full color emoji.
* fonts: Add support for more @font-face features (#32164)Martin Robinson2024-04-291-5/+1
| | | | | | | | | | | | | | | | | | | | | | | There are a couple major changes here: 1. Support is added for the `weight`, `style`, `stretch` and `unicode-range` declarations in `@font-face`. 2. Font matching in the font cache can return templates and `FontGroupFamily` can own mulitple templates. This is due to needing support for "composite fonts". These are `@font-face` declarations that only differ in their `unicode-range` definition. This fixes a lot of non-determinism in font selection especially when dealing with pages that define "composite faces." A notable example of such a page is servo.org, which now consistently displays the correct web font. One test starts to fail due to an uncovered bug, but this will be fixed in a followup change. Fixes #20686. Fixes #20684. Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* fonts: Merge multiple methods into `PlatformFont::descriptor()` (#32115)Martin Robinson2024-04-231-18/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This combines `style()`, `boldness()`, `stretchiness()` into a `descriptor()` method which is used when creating `FontTemplate`s for web fonts. Eventually this method will simply read font tables using skrifa. This is the first step. In addition, `family_name()` and `face_name()` are removed. They were only used for debugging and the `FontIdentifier` serves for that. On Windows, this was adding another way in which font loading could fail, without buying us very much. The path or URL to the font is more important when debugging than the names in the font tables. Closes #15103. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes do not require tests because they should not change observable behavior. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
* fonts: Fix emoji font selection on macOS (#32122)Martin Robinson2024-04-221-7/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes two issues that were preventing emojis from being properly selected from fonts on macOS. 1. `CTFont::get_glyphs_for_characters` takes the input characters as UniChar which are UTF-16 encoded characters. We need to encode the input `char` as UTF-16 before passing it to CoreText. 2. The font fallback list is updated with the latest logic from Gecko, which importantly adds "Apple Color Emoji" to the list of fallback fonts. Sorry for the big change, but this is just a direct port of the code from Gecko. With these two changes, emojis display but in grayscale. 😅 To fix this, another part of the font stack will need to detect when the font supports color and pass that information to WebRender when creating the font instance. We will likely do this in platform independent way later that will depend on some more preliminary changes. <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes are part of #17267. - [x] There are tests for these changes, but the macOS CI does not currently run WPT so we cannot observe the updated results. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
* fonts: Rework platform font initialization (#32127)Mukilan Thiyagarajan2024-04-221-27/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change reworks the way that platform fonts are created and descriptor data is on `FontTemplate` is initialized. The main change here is that platform fonts for local font faces are always initialized using the font data loaded into memory from disk. This means that there is now only a single path for creating platform fonts. In addition, the font list is now responsible for getting the `FontTemplateDescriptor` for local `FontTemplate`s. Before the font had to be loaded into memory to get the weight, style, and width used for the descriptor. This is what fonts lists are for though, so for every platform we have that information before needing to load the font. In the future, hopefully this will allow discarding fonts before needing to load them into memory. Web fonts still get the descriptor from the platform handle, but hopefully that can be done with skrifa in the future. Thsese two fixes together allow properly loading indexed font variations on Linux machines. Before only the first variation could be instantiated. Fixes https://github.com/servo/servo/issues/13317. Fixes https://github.com/servo/servo/issues/24554. Co-authored-by: Martin Robinson <mrobinson@igalia.com> ---- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #13317 and #24554 - [x] There are tests for these changes --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* Simplify `FontHandle` and rename it to `PlatformFont` (#32101)Martin Robinson2024-04-171-12/+11
| | | | | | | | | | | | | | | | * Simplify `FontHandle` and rename it to `PlatformFont` Rename it to `PlatformFont` and move the `FontTemplate` member to `Font`, because it's shared by all platforms. * Update components/gfx/platform/freetype/font.rs Co-authored-by: Mukilan Thiyagarajan <mukilanthiagarajan@gmail.com> * Fix build for MacOS and Windows --------- Co-authored-by: Mukilan Thiyagarajan <mukilanthiagarajan@gmail.com>
* gfx: Remove `FontTemplateData` (#32034)Martin Robinson2024-04-161-28/+22
| | | | | | | | | | | | | | | | | | | Now that `FontTemplateData` is more or less the same on all platforms, it can be removed. This is a preparatory change for a full refactor of the font system on Servo. The major changes here are: - Remove `FontTemplateData` and move its members into `FontTemplate` - Make `FontTemplate` have full interior mutability instead of only the `FontTemplateData` member. This is preparation for having these data types `Send` and `Sync` with locking. - Remove the strong/weak reference concept for font data. In practice, all font data references were strong, so this was never fully complete. Instead of using this approach, the new font system will use a central font data cache with references associated to layouts. - The `CTFont` cache is now a global cache, so `CTFont`s can be shared between threads. The cache is cleared when clearing font caches. A benefit of this change (apart from `CTFont` sharing) is that font data loading is platform-independent now.
* Remove `FontContextHandle` (#32038)Martin Robinson2024-04-121-2/+0
| | | | | | | | | | | | | | | | | | | | | | | The `FontContextHandle` was really only used on FreeType platforms to store the `FT_Library` handle to use for creating faces. Each `FontContext` and `FontCacheThread` would create its own `FontContextHandle`. This change removes this data structure in favor of a mutex-protected shared `FontContextHandle` for an entire Servo process. The handle is initialized using a `OnceLock` to ensure that it only happens once and also that it stays alive for the entire process lifetime. In addition to greatly simplifying the code, this will make it possible for different threads to share platform-specific `FontHandle`s, avoiding multiple allocations for a single font. The only downside to all of this is that memory usage of FreeType fonts isn't measured (though the mechanism is still there). This is because the `FontCacheThread` currently doesn't do any memory measurement. Eventually this *will* happen though, during the font system redesign. In exchange, this should reduce the memory usage since there is only a single FreeType library loaded into memory now. This is part of #32033.
* gfx: Do not apply scale to `CoreText` font metrics (#31996)Martin Robinson2024-04-051-27/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | Since the original version of the CoreText font code, it has scaled the metrics from CoreText by an unusual scale: ``` let scale = px_to_pt(self.ctfont.pt_size()) / (ascent + descent); ``` It's unclear what this scale was trying to accomplish. Note that it's passing the return value of `pt_size()` to `px_to_pt` which seems backward. This scale seems bogus, but perhaps it's based on a misconception about what its returned from CoreText. Unlike the return values of `CGFont` methods, which are returned in font units, the ones from `CTFont` are "scaled according to the point size and matrix of the font reference." Indeed, when just interpreting these values as pixel values, the results more or less match Firefox and Chrome. This becomes much more obvious now that we have support for `ex` units. Even when not using `ex`, you can sometimes see the top parts of glyphs cut off due to this scaling. This change removes the scaling and simply interpets the return values of `CTFont` methods as pixels. It addresses all of the issues mentioned above. Note that this path will eventually just be a fallback path and metrics will come from sfnt tables in the future.
* gfx: Derive `line-through` metrics for fonts on MacOS (#31756)Martin Robinson2024-03-191-4/+13
| | | | | | | | | | | | | There is now platform-specific way to get metrics for `line-through` on MacOS and currently striking through simply does not work. The correct approach here is likely to first search for these metrics in font tables and then falling back to deriving them. Searching the font tables is a larger change, so this change adds the fallback mechanism first. This at least makes sure that strike through renders at all on Mac. In a followup change we can add support for getting metrics via HarfBuzz in a platform-independent way, which is what Gecko does. Fixes #942.
* clippy: Fix remaining warnings in `gfx` for MacOS (#31669)Martin Robinson2024-03-151-29/+30
|
* fonts: Add `FontIdentifier` and `LocalFontIdentifier` (#31658)Martin Robinson2024-03-141-3/+3
| | | | | | | | | | | | | | | | | | | Instead of using a simple `Atom` to identify a local font, use a data structure. This allows us to carry more information necessary to identify a local font (such as a path on MacOS). We need this for the new version of WebRender, as fonts on MacOS now require a path. This has a lot of benefits: 1. We can avoid loading fonts without paths on MacOS, which should avoid a lot of problems with flakiness and ensure we always load the same font for a given identifier. 2. This clarifies the difference between web fonts and local fonts, though there is more work to do here. 3. This avoid a *lot* of font shenanigans, such as trying to work backwards from the name of the font to the path of the font we actually matched. In general, we can remove a lot of code trying to accomplish these shenanigans. 4. Getting the font bytes always returns an `Arc` now avoiding an extra full font copy in the case of Canvas.
* Further changes required by ServoOriol Brufau2023-10-021-8/+4
|
* Strict import formatting (grouping and granularity) (#30325)Samson2023-09-111-12/+15
| | | | | * strict imports formatting * Reformat all imports
* remove `extern crate` (#30311)Samson2023-09-081-0/+1
| | | | | | | | | | | * remove extern crate * Update components/script_plugins/lib.rs Co-authored-by: Martin Robinson <mrobinson@igalia.com> --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* Rustfmt has changed its default style :/Simon Sapin2018-12-281-7/+7
|
* mac: Treat CT returning 0 glyph indexes as failing to find indexes.Josh Matthews2018-12-141-3/+2
|
* Update MPL license to https (part 4)Jan Andre Ikenmeyer2018-11-191-1/+1
|
* Reorder importsPyfisch2018-11-061-3/+5
|
* Format remaining filesPyfisch2018-11-061-2/+1
|
* Sort `use` statementsSimon Sapin2018-11-061-1/+1
|
* `cargo fix --edition`Simon Sapin2018-11-061-5/+5
|
* Update webrender to 923ee495bd9b0fda8a4a94c5a6cf42e2f0548731.Josh Matthews2018-10-091-9/+13
|
* Fix comments indentation issue in gfx platformkingdido9992018-09-051-2/+3
|
* Format gfx platform #21373kingdido9992018-09-051-46/+48
|
* gfx: Make FontHandleMethods::family_name return an optional value.Josh Matthews2018-08-081-2/+2
|
* Implement font fallbackJon Leighton2018-05-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Prior to this change, if none of the fonts specified in CSS contained a glyph for a codepoint, we tried only one fallback font. If that font didn't contain the glyph, we'd give up. With this change, we try multiple fonts in turn. The font names we try differ across each platform, and based on the codepoint we're trying to match. The current implementation is heavily inspired by the analogous code in Gecko, but I've used to ucd lib to make it more readable, whereas Gecko matches raw unicode ranges. This fixes some of the issues reported in #17267, although colour emoji support is not implemented. == Notes on changes to WPT metadata == === css/css-text/i18n/css3-text-line-break-opclns-* === A bunch of these have started failing on macos when they previously passed. These tests check that the browser automatically inserts line breaks near certain characters that are classified as "opening and closing punctuation". The idea is that if we have e.g. an opening parenthesis, it does not make sense for it to appear at the end of a line box; it should "stick" to the next character and go into the next line box. Before this change, a lot of these codepoints rendered as a missing glyph on Mac and Linux. In some cases, that meant that the test was passing. After this change, a bunch of these codepoints are now rendering glyphs on Mac (but not Linux). In some cases, the test should continue to pass where it previously did when rendering with the missing glyph. However, it seems this has also exposed a layout bug. The "ref" div in these tests contains a <br> element, and it seems that this, combined with these punctuation characters, makes the spacing between glyphs ever so slightly different to the "test" div. (Speculation: might be something to do with shaping?) Therefore I've had to mark a bunch of these tests failing on mac. === css/css-text/i18n/css3-text-line-break-baspglwj-* === Some of these previously passed on Mac due to a missing glyph. Now that we're rendering the correct glyph, they are failing. === css/css-text/word-break/word-break-normal-bo-000.html === The characters now render correctly on Mac, and the test is passing. But we do not find a suitable fallback font on Linux, so it is still failing on that platform. === css/css-text/word-break/word-break-break-all-007.html === This was previously passing on Mac, but only because missing character glyphs were rendered. Now that a fallback font is able to be found, it (correctly) fails. === mozilla/tests/css/font_fallback_* === These are new tests added in this commit. 01 and 02 are marked failing on Linux because the builders don't have the appropriate fonts installed (that will be a follow-up). Fix build errors from rebase FontTemplateDescriptor can no longer just derive(Hash). We need to implement it on each component part, because the components now generally wrap floats, which do not impl Hash because of NaN. However in this case we know that we won't have a NaN, so it is safe to manually impl Hash.
* Fix servo build.Emilio Cobos Álvarez2018-04-281-16/+12
|
* style: Fixups for css-fonts-4 font-weight.Emilio Cobos Álvarez2018-04-281-1/+3
|
* Lazy load fonts in a FontGroupJon Leighton2018-02-221-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | This is a step towards fixing #17267. To fix that, we need to be able to try various different fallback fonts in turn, which would become unweildy with the prior eager-loading strategy. Prior to this change, FontGroup loaded up all Font instances, including the fallback font, before any of them were checked for the presence of the glyphs we're trying to render. So for the following CSS: font-family: Helvetica, Arial; The FontGroup would contain a Font instance for Helvetica, and a Font instance for Arial, and a Font instance for the fallback font. It may be that Helvetica contains glyphs for every character in the document, and therefore Arial and the fallback font are not needed at all. This change makes the strategy lazy, so that we'll only create a Font for Arial if we cannot find a glyph within Helvetica. I've also substantially refactored the existing code in the process and added some documentation along the way.
* Use specific negative assertion for gfx platform macos fontCYBAI2018-01-261-1/+1
|
* gfx: Use ? on Option more often.Emilio Cobos Álvarez2017-12-091-5/+1
|
* style: Make all keywords CamelCase for consistency.Emilio Cobos Álvarez2017-12-061-13/+14
| | | | This prevents confusion and paves the ground for derive(Parse) of them.
* Use integer for specified and computed font-weightXidorn Quan2017-07-061-11/+1
|
* Fix panic when font face name is not availableDominik Boehi2017-04-121-2/+2
|
* Update rustc to 1.16.0-nightly (7821a9b99 2017-01-23).Ms2ger2017-01-241-4/+0
|
* gfx: On the Mac, take the scale into account when determining thePatrick Walton2016-10-111-2/+2
| | | | x-height of a font.
* Reorder `use` statementsUK9922016-09-091-3/+3
|
* Bail out gracefully on malformed kern table headers.Matt Brubeck2016-07-061-2/+5
| | | | Fixes #12081.
* Report use statements that use {} with only one entryCullen Rhodes2016-05-271-1/+1
|
* Add a fast path for shaping ASCII textMatt Brubeck2016-05-201-9/+126
|
* Make FontHandle fields privateMatt Brubeck2016-05-191-2/+2
|
* Allow creation of unboxed FontTablesMatt Brubeck2016-05-191-2/+2
|
* Simplify FontTableMethods::with_bufferMatt Brubeck2016-05-191-2/+2
|
* gfx: Change the mapping from Mac weights to CSS weights so that 0.0 mapsPatrick Walton2016-05-101-10/+14
| | | | | | | | | | | | | to 400, not 500. CSS `normal` font-weight is specified as 400, while Mac "Regular" font weight is reported as 0.0. On the Mac, we need to center the two ranges on the same value to avoid choosing "Light" fonts where "Regular" would have been more appropriate. Closes #9487. fix for mac
* gfx: Clamp the font size we supply to Core Text to 0.01pt.Patrick Walton2016-04-111-1/+1
| | | | | | | | | | Core Text treats a font size of 0.0 as 12.0, which is obviously not what we want. Improves Twitter. Improves Reddit /r/rust. Closes #10492.