aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx
Commit message (Collapse)AuthorAgeFilesLines
* Rename `gfx` to `fonts` (#32556)Martin Robinson2024-06-19116-18636/+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: Clean up WebRender web fonts when they are no longer used (#32545)Martin Robinson2024-06-182-2/+111
| | | | | | | | | | | This is the first part of cleaning up unused WebRender resources. Currently this only cleans up web font resources, but a more full-featured implementation in the future could also clean up unused system fonts. Fixes #32345. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* Use workspace definitions for all crates and update to the 2021 edition (#32544)Martin Robinson2024-06-181-6/+5
|
* fonts: Respect emoji variation selector when selecting fonts (#32493)Martin Robinson2024-06-186-24/+85
| | | | | | | | | | | | | | This uses a pretty simple heuristic to select a font likely to contain color emoji. In the future Servo should actually check if the font also contains a color representation of the character in question. For now the code assumes that when a font supports color glyphs of some kind and supports the character in question at all, it supports the color version. This fixes support for rendering keycap emoji clusters such as 1️⃣ . Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* fonts: Fix loading SFNT tables on Windows (#32499)Martin Robinson2024-06-171-12/+11
| | | | | | | DirectWrite APIs expect the bytes of table tags to be reversed when reading them. Servo was doing this when loading font tables, but not all of them. This led to shaping being broken on Windows. This fixes that issue in a more comprehensive way and adds a comment to avoid this failing in the future.
* build: Fix build warnings on Windows (#32500)Martin Robinson2024-06-152-0/+4
| | | | | Disable some code for Windows, which is causing build warnings. When it cannot be easily disabled (mainly for the incomplete BHM and sandbox feature), allow dead code.
* fonts: Merge Noto fallback lists (#32463)Martin Robinson2024-06-133-327/+247
| | | | | On platforms that ship Noto, the list of fallback fonts can be shared. This reduces code duplcation and makes it easier to keep up to date with changes in Noto.
* gfx: font_list: Fix OpenHarmony build (#32466)Jonathan Schwender2024-06-101-8/+4
| | | | Adapt changes from 1c9120c293cc16c11637feb6003117d4093642b5 to the OpenHarmony font_list.rs.
* Remove unused items in gfx (#32423)Ngo Iok Ui (Wu Yu Wei)2024-06-052-7/+0
|
* base: Remove `ucd` dependency (#32424)Martin Robinson2024-06-039-78/+8
| | | | | | | | | | | | | | Remove the `ucd` dependency which has not been updated in 8 years. In addition, replace it with a generated UnicodeBlock enum which reflects the modern Unicode standard. This is generated via a Python script which is included in the repository. The generation is not part of the build process, because the Unicode database is hosted on the web and it does not change the frequently. This is done instead of bringing in the more up-to-date `unicode_blocks` dependency. `unicode_blocks` defines each block as constant, which means that they cannot be used in match statements -- which we do in Servo. Co-authored-by: Lauryn Menard <lauryn.menard@gmail.com>
* layout: Add a `InlineFormattingContextBuilder` (#32415)Martin Robinson2024-06-032-1/+22
| | | | | | | | | | | | | | | | The main change here is that collapsed and `text-transform`'d text is computed as it's processed by DOM traversal. This single transformed text is stored in the root of the `InlineFormattingContext`. This will eventually allow performing linebreaking and shaping of the entire inline formatting context at once. Allowing for intelligent processing of linebreaking and also shaping across elements. This matches more closely what LayoutNG does. This shouldn't have any (or negligable) behavioral changes, but will allow us to prevent linebreaking inside of clusters in a followup change. Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
* font_template.rs: apply clippy lints (#32391)Farid2024-05-301-7/+7
| | | Signed-off-by: Jujumba <far77578@gmail.com>
* layout: Add support for `white-space-collapse: break-spaces` (#32388)Martin Robinson2024-05-305-668/+23
| | | | | | | | | | | | | | This change adds support for `white-space-collapse: break-spaces` and adds initial parsing support for `overflow-wrap` and `word-break`. The later two properties are not fully supported, only in their interaction with `break-spaces`. This is a preliminary change preparing to implement them. In addition, `break_and_shape` is now forked and added to Layout 2020. This function is going to change a lot soon and forking is preparation for this. More code that is only used by Layout 2013 is moved from `gfx` to that crate. Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
* Move `RenderingContext` to `webrender_traits` (#32386)Martin Robinson2024-05-282-245/+0
| | | | | | The `gfx_traits` crate is gradually become just about text and fonts and this is one of the few things there that is standing in the way of this. Eventually `webrender_traits` will be the general cross-process compositor API, so this sort of makes sense as well.
* fonts: Improve font fallback (#32286)Martin Robinson2024-05-279-316/+594
| | | | | | | | | | | | | | | | | | - 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: Add support for the CSS font matching algorithm (#32366)Martin Robinson2024-05-242-41/+443
| | | | | | | | | | | | | | | | | | | | | | * fonts: Add support for the CSS font matching algorithm This is a port from Gecko of the CSS font matching algorithm distance functions as well as the "simple family" concept for optimizing matching when dealing with simple fonts. Fixes #189. Fixes #190. Fixes #20686. Fixes #20684. Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com> Signed-off-by: Martin Robinson <mrobinson@igalia.com> * Ensure that simple faces are removed for removed stylesheets --------- Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* fonts: Remove web fonts when their stylsheet is removed (#32346)Martin Robinson2024-05-235-28/+166
| | | | | | | | | | | | | This is the first part of ensuring that unused fonts do not leak. This change makes it so that when a stylesheet is removed, the corresponding web fonts are removed from the `FontContext`. Note: WebRender assets are still leaked, which was the situation before for all fonts. A followup change will fix this issue. Fixes #15139. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* fonts: Clean up messaging during web fonts loads (#32332)Martin Robinson2024-05-222-27/+46
| | | | | | | | | | | | Instead of sending a message to the script thread via IPC when a web font loads and then sending another, just give the `FontContext` a callback that send a single message to the script thread. This moves all the cache invalidation internally into `FontContext` as well. Additionally, the unused LayoutControlMessage::ExitNow enum variant is removed. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* fonts: Depend directly on `freetype-sys` (#32318)Martin Robinson2024-05-213-46/+38
| | | | | | Instead of depending on `rust-freetype`, depend directly on `freetype-sys` which is a transitive dependency. This provides almost everything we need (apart from one function call). This will help us eliminate one crate in the dependency chain.
* fonts: Store web fonts in the per-Layout `FontContext` (#32303)Martin Robinson2024-05-2013-515/+822
| | | | | | | | | This moves mangement of web fonts to the per-Layout `FontContext`, preventing web fonts from being available in different Documents. Fixes #12920. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* clippy: Fix warnings in `components/gfx` (#32311)aBit192024-05-181-5/+5
| | | Co-authored-by: antreas <andreas.bitzilis@redpill-linpro.com>
* Move non-gfx things out of `gfx_traits` and create a `base` crate (#32296)Martin Robinson2024-05-172-3/+4
| | | | | | | | | | | | | | | | | | | | | | | For a long time, `gfx_traits` has held a lot of things unrelated to graphics and also unrelated to the `gfx` crate (which is mostly about fonts). This is a cleanup which does a few things: 1. Move non `gfx` crate things out of `gfx_traits`. This is important in order to prevent dependency cycles with a different integration between layout, script, and fonts. 2. Rename the `msg` crate to `base`. It didn't really contain anything to do with messages and instead mostly holds ids, which are used across many different crates in Servo. This new crate will hold the *rare* data types that are widely used. Details: - All BackgroundHangMonitor-related things from base to a new `background_hang_monitor_api` crate. - Moved `TraversalDirection` to `script_traits` - Moved `Epoch`-related things from `gfx_traits` to `base`. - Moved `PrintTree` to base. This should be widely useful in Servo. - Moved `WebrenderApi` from `base` to `webrender_traits` and renamed it to `WebRenderFontApi`.
* fonts: Add color emoji support for FreeType (#32278)Martin Robinson2024-05-173-128/+286
| | | | | | | | | | | Color emoji support with "Noto Color Emoji" requires two things: 1. Support for bitmap fonts in the FreeType backend. This requires specially handling bitmap fonts which have different characteristics in the FreeType API (such as requiring metrics scaling). This support is generally ported from Gecko's implementation. 2. When a character is an emoji it "Noto Color Emoji" needs to be in the fallback list. Ensure that this is high on the list -- this will be improved in a later PR.
* android: Trim whitespace around font filenames. (#32298)Mukilan Thiyagarajan2024-05-171-1/+1
| | | | | | | | | This is a speculative fix for #32161. A similar failure is reproducible on the Android x86_64 emulator with API 35 system image. The fix has not been validated on the actual device so potentially there might be other issues that need to be fixed to complete #32161. Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* fonts: Add `MallocSizeOf` implementation for `FontContext` (#32206)Martin Robinson2024-05-0310-24/+105
| | | | | | | | | | | | | | | | * fonts: Add `MallocSizeOf` implementation for `FontContext` Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com> Signed-off-by: Martin Robinson <mrobinson@igalia.com> * android: remove unused imports in font_list.rs Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com> --------- Signed-off-by: Martin Robinson <mrobinson@igalia.com> Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com> Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
* Fix some clippy warnings in `components/gfx` and `components/script` (#32215)Pi-Cla2024-05-024-19/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * clippy: Squish warnings and errors in gfx warning: redundant closure (gfx/font.rs:415:18) warning: useless conversion to the same type (gfx/font.rs:534:9) warning: the following explicit lifetimes could be elided: 'a (gfx/font.rs:619:16) error: this loop never actually loops (gfx/font_cache_thread.rs:112:9) warning: this expression creates a reference which is immediately dereferenced by the compiler (gfx/font_cache_thread.rs:229:51) warning: redundant closure (gfx/font_cache_thread.rs:551:18) 3 instances of: warning: casting integer literal to `f64` is unnecessary (gfx/platform/freetype/font_list.rs:271-273) * clippy: methods called `from_*` usually take no `self` It reports that by standard convention, from_* methods should not take any `&self` parameter * clippy: you should consider adding a `Default` implementation It reports that public types with a pub fn new() -> Self should have a Default implementation since they can be constructed without arguments * clippy: casting to the same type is unnecessary (`f32` -> `f32`) * clippy: use of `unwrap_or_else` to construct default value * clippy: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self` * clippy: manual `!RangeInclusive::contains` implementation contains expresses the intent better and has less failure modes (such as fencepost errors or using || instead of &&) * clippy: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` * clippy: Fix some new warnings warning: this `if` statement can be collapsed (gfx/font.rs:468:130) warning: this lifetime isn't used in the impl (gfx/platform/freetype/font.rs:341:6) warning: field assignment outside of initializer for an instance created with Default::default() (compositor.rs:881:17)
* Add font-fallback on OpenHarmony and fix several compilation issues (#32141)Jonathan Schwender2024-05-023-3/+254
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add OpenHarmony support for allocator / profile Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com> * gfx: Build harfbuzz from source on OHOS Updates `freetype-sys` to v0.20.1, which includes a build fix for OpenHarmony. Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com> * gfx: Don't depend on fontconfig on OpenHarmony Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com> * gfx: Add ohos font fallback Hardcode HarmonyOS_Sans_SC_Regular for Chinese Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com> * libservo: OHOS useragent, and explicitly opt out of sandboxing Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com> * libservo: Disable get_native_media_display_and_gl_context on ohos Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com> --------- Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
* servoshell: Upgrade `egui` and many other dependencies (#31278)Magnus Larsen2024-05-021-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | * servoshell: Upgrade `egui` and many other dependencies This upgrades: - `core-graphics` - `core-text` - `egui` and friends - `font-kit` - `glow` and friends - `harfbuzz-sys` - `jni` - `nix` - `raqote` - `raw-window-handle` - `winit` * Downgrade jni until we can properly upgrade * Update some test results It's unclear why these are now passing, but they are. --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* fonts: Make `FontContext` thread-safe and share it per-Layout (#32205)Martin Robinson2024-05-0211-237/+266
| | | | | | | | | | | | 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-024-5/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-027-24/+87
| | | | | | (#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-2913-414/+598
| | | | | | | | | | | | | | | | | | | | | | | 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-238-226/+126
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-222-149/+231
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-2217-408/+602
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* clippy: Fix clone_on_copy warnings (#32108)Oluwatobi Sofela2024-04-181-2/+2
|
* Simplify `FontHandle` and rename it to `PlatformFont` (#32101)Martin Robinson2024-04-178-78/+70
| | | | | | | | | | | | | | | | * 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>
* Rename `FontTemplateInfo` to `FontTemplateAndWebRenderFontKey` (#32100)Martin Robinson2024-04-173-16/+16
| | | | This clarifies what this type does a bit. Based on a suggestion by @mukilan.
* gfx: Remove `FontTemplateData` (#32034)Martin Robinson2024-04-1618-597/+390
| | | | | | | | | | | | | | | | | | | 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-1215-247/+151
| | | | | | | | | | | | | | | | | | | | | | | 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.
* layout: Add a `FontMetricsProvider` for resolving font-relative units (#31966)Martin Robinson2024-04-041-4/+12
| | | | | | | | | | | | | | | | | | | The only font relative unit that Servo knows how to resolve currently is `rem` (relative to the root font size). This is because Stylo cannot do any font queries. This adds a mechanism to allow this, exposing the ability to properly render `ex` units in Servo. This change only allows resolving some font size relative units thoug, as Servo doesn't collect all the FontMetrics it needs to resolve them all. This capability will be added in followup changes. Some new tests fail: - ex-unit-001.html: This test fails because Servo does not yet have support for setting the weight using @font-face rules on web fonts. - ex-unit-004.html: This test fails because Servo does not yet have support for setting the Unicode range of a web font using @font-face rules. - first-available-font-001.html: This test fails because the above two feature are missing.
* Update Stylo to 2023-10-16 (#31932)Oriol Brufau2024-03-301-0/+2
| | | | | | | | | | | | | | | | | | | | | | | * Update Stylo to 2023-10-16 * Fixup for https://phabricator.services.mozilla.com/D185154 * Fixup for https://phabricator.services.mozilla.com/D188216 * Fixup for https://phabricator.services.mozilla.com/D185677 * Fixup for https://phabricator.services.mozilla.com/D188566 * Fixup for https://phabricator.services.mozilla.com/D188727 * Fixup for https://phabricator.services.mozilla.com/D189475 * Fixup for https://phabricator.services.mozilla.com/D189521 * Fixup for https://phabricator.services.mozilla.com/D188812 * Fixup for https://phabricator.services.mozilla.com/D189484 * Update test expectations
* clippy: Fix unnecessary_lazy_evaluations warnings (#31898)Oluwatobi Sofela2024-03-271-1/+1
|
* fonts: Add support for WOFF2 and properly load web fonts from @imports (#31879)Martin Robinson2024-03-261-4/+7
| | | | | | | | | | | | This change also makes two fixes that are necessary to get WOFF2 fonts working: 1. It adds support for loading web fonts from stylesheets included via @import rules. 2. It ensure that when web fonts are loaded synchronusly they invalidate the font cache. This led to incorrect font rendering when running tests before. Fixes #31598.
* clippy: Fix `default_constructed_unit_structs` warnings in `components` (#31827)Oluwatobi Sofela2024-03-242-0/+2
| | | | | * clippy: Fix default constructed unit structs warnings * refactor: Allow default constructed unit structs to avoid gfx build error
* Attempt using version of Stylo with -x-lang enabled (#31737)Rhea-Eve2024-03-201-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | * Attempt using version of Stylo with -x-lang enabled Signed-off-by: Rhea Karty <rheakarty@gmail.com> * Added x-lang to initializer list to address failing tests. Signed-off-by: Rhea Karty <rheakarty@gmail.com> * Fix formatting (sorry) Signed-off-by: Rhea Karty <rheakarty@gmail.com> * Revert changes in Cargo.toml, update Cargo.lock. Signed-off-by: Rhea Karty <rheakarty@gmail.com> * Removed .git suffix from Stylo Signed-off-by: Rhea Karty <rheakarty@gmail.com> --------- Signed-off-by: Rhea Karty <rheakarty@gmail.com>
* 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.
* rustdoc: Fix broken link to `FontFace` in `components/gfx` (#31745)Oluwatobi Sofela2024-03-191-1/+1
| | | | | | | | | | | * rustdoc: Fix fontface broken link error * Correct link to `Font` * Reduce the diff a bit --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
* fonts: Consider Tertiary Ideographic Plane to be CJK (#31670)sandeep2024-03-182-2/+22
| | | | | | | | | | | | | | | | | | | | * added check for Tertiary Ideographic Plane * added unit test for is_cjk function Signed-off-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local> * fixed formatting Signed-off-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local> * removed for loop assertions & added TIP chars Signed-off-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local> --------- Signed-off-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local> Co-authored-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local>