aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx/font_template.rs
Commit message (Collapse)AuthorAgeFilesLines
* Rename `gfx` to `fonts` (#32556)Martin Robinson2024-06-191-573/+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: Respect emoji variation selector when selecting fonts (#32493)Martin Robinson2024-06-181-2/+2
| | | | | | | | | | | | | | 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>
* font_template.rs: apply clippy lints (#32391)Farid2024-05-301-7/+7
| | | Signed-off-by: Jujumba <far77578@gmail.com>
* fonts: Add support for the CSS font matching algorithm (#32366)Martin Robinson2024-05-241-24/+309
| | | | | | | | | | | | | | | | | | | | | | * 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-231-2/+10
| | | | | | | | | | | | | 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: Store web fonts in the per-Layout `FontContext` (#32303)Martin Robinson2024-05-201-6/+27
| | | | | | | | | 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>
* fonts: Add `MallocSizeOf` implementation for `FontContext` (#32206)Martin Robinson2024-05-031-1/+11
| | | | | | | | | | | | | | | | * 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>
* fonts: Make `FontContext` thread-safe and share it per-Layout (#32205)Martin Robinson2024-05-021-3/+2
| | | | | | | | | | | | 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>
* fonts: Add support for more @font-face features (#32164)Martin Robinson2024-04-291-38/+95
| | | | | | | | | | | | | | | | | | | | | | | 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-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: Rework platform font initialization (#32127)Mukilan Thiyagarajan2024-04-221-71/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-4/+4
| | | | | | | | | | | | | | | | * 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-93/+94
| | | | | | | | | | | | | | | | | | | 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-12/+6
| | | | | | | | | | | | | | | | | | | | | | | 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.
* clippy: Fix remaining warnings in `gfx` for MacOS (#31669)Martin Robinson2024-03-151-6/+5
|
* fonts: Add `FontIdentifier` and `LocalFontIdentifier` (#31658)Martin Robinson2024-03-141-4/+7
| | | | | | | | | | | | | | | | | | | 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.
* clippy: fix warnings in components/gfx (#31560)eri2024-03-081-11/+5
| | | | | | | * clippy: fix warnings in components/gfx * refactor: switched the order of impl so that its intent is clearer * fix: add font context default in other platforms
* Further changes required by ServoOriol Brufau2023-10-021-7/+5
|
* Strict import formatting (grouping and granularity) (#30325)Samson2023-09-111-6/+8
| | | | | * 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>
* Update MPL license to https (part 4)Jan Andre Ikenmeyer2018-11-191-1/+1
|
* `cargo fix --edition`Simon Sapin2018-11-061-4/+4
|
* Format the rest of gfx #21373kingdido9992018-09-081-22/+22
|
* Implement font fallbackJon Leighton2018-05-191-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-41/+33
|
* style: Fixups for css-fonts-4 font-weight.Emilio Cobos Álvarez2018-04-281-7/+10
|
* Lazy load fonts in a FontGroupJon Leighton2018-02-221-13/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Merge branch 'master' into freetype2dan-robertson2018-02-081-39/+28
|\
| * Fix FontTemplateDescriptor under FreeTypeJon Leighton2018-02-071-39/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Issue #17321. Under Linux, using "font-family: sans-serif" previously caused Servo to select the "UltraLight" face (of DejaVu Sans). There were two reasons for this: 1. Font weight was only retrieved from the OS/2 table for bold faces. This neglected to retrieve the weight information for "lighter than normal" weight faces. This meant that the UltraLight face appeared as normal weight, and was selected. 2. Retrieval of font stretch information from the OS/2 table was not implemented at all.
* | Change selection of the best font for a styleDan Robertson2018-02-061-4/+24
|/ | | | | | | Previously anything with the wrong stretch/italicness was considered equally bad. Now we consider the wrong weight to be least bad, wrong boldness of intermediate badness, and wrong itallicness to be most bad.
* order derivable traits listsClément DAVID2017-08-231-1/+1
| | | | | | Ignoring : - **generated**.rs - python/tidy/servo_tidy_tests/rust_tidy.rs
* Use integer for specified and computed font-weightXidorn Quan2017-07-061-1/+1
|
* UntrySimon Sapin2017-06-181-4/+4
|
* Update to string-cache 0.3Simon Sapin2016-11-031-1/+1
|
* Make font template data load fallible. Fixes #12037.Josh Matthews2016-07-051-14/+17
|
* gfx: Implement `Debug` for `FontTemplate` instances.Patrick Walton2016-05-101-0/+7
|
* gfx: Perform fuzzy matching on font weights if an exact match wasn'tPatrick Walton2016-05-101-34/+69
| | | | | | | found. Partially addresses #190. Partially addresses #9487.
* Derive Debug on FontGroup and its componentsOlaf Buddenhagen2015-12-121-1/+1
|
* compositing: Split Servo up into multiple sandboxed processes.Patrick Walton2015-11-191-1/+1
| | | | | Multiprocess mode is enabled with the `-M` switch, and sandboxing is enabled with the `-S` switch.
* Fix reported test-tidy errors for unmerged import blocksBrandon Fairchild2015-09-191-2/+1
| | | | This merges import blocks that were reported by tidy as unmerged.
* Remove 'get_*' on getters as per RFC 0344 on various componentsMathieu Rheaume2015-09-121-5/+5
|
* Upgrade to rustc 1.4.0-dev (cb9323ec0 2015-09-01)Simon Sapin2015-09-021-2/+2
|
* sort all usesJohann Tuffe2015-08-201-1/+1
|
* Use atoms for font template structures.Glenn Watson2015-07-131-8/+8
|
* Remove some as_slice calls.Ms2ger2015-04-241-1/+1
|
* gfx: Perform more aggressive caching inPatrick Walton2015-04-011-5/+5
| | | | | | | | | | | | | | | | | | | `FontContext::get_layout_font_group_for_style()`. There are several optimizations here: * We make font families atoms, to allow for quicker comparisons. * We precalculate an FNV hash of the relevant fields of the font style structure. * When obtaining a platform font group, we first check pointer equality for the font style. If there's no match, we go to the FNV hash. Only if both caches miss do we construct and cache a font group. Note that individual fonts are *also* cached; thus there are two layers of caching here. 15% improvement in total layout thread time for Facebook Timeline.
* Update some code that's feature-gated under core.Ms2ger2015-03-211-1/+1
|
* gfx: Implement `font-stretch` per CSS3-FONTS § 3.3 in the Core TextPatrick Walton2015-01-281-41/+48
| | | | font backend.
* Update rustc to 00b112c45a604fa6f4b59af2a40c9deeadfdb7c6/rustc-1.0.0-dev.Josh Matthews2015-01-281-1/+1
|
* Move to to_owned rather than into_string.Ms2ger2015-01-201-1/+2
| | | | into_string has been removed from Rust.