aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx/tests
Commit message (Collapse)AuthorAgeFilesLines
* base: Remove `ucd` dependency (#32424)Martin Robinson2024-06-031-24/+0
| | | | | | | | | | | | | | 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 support for `white-space-collapse: break-spaces` (#32388)Martin Robinson2024-05-301-102/+1
| | | | | | | | | | | | | | 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>
* fonts: Improve font fallback (#32286)Martin Robinson2024-05-271-6/+25
| | | | | | | | | | | | | | | | | | - 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: Remove web fonts when their stylsheet is removed (#32346)Martin Robinson2024-05-231-0/+2
| | | | | | | | | | | | | 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-39/+63
| | | | | | | | | 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: Make `FontContext` thread-safe and share it per-Layout (#32205)Martin Robinson2024-05-021-35/+23
| | | | | | | | | | | | 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: Use `FontInstanceFlags::EMBEDDED_BITMAPS` for color fonts on MacOS ↵Martin Robinson2024-05-021-1/+2
| | | | | | (#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-292-59/+53
| | | | | | | | | | | | | | | | | | | | | | | 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-232-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-222-15/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-7/+6
| | | | | | | | | | | | | | | | * 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-171-3/+3
| | | | This clarifies what this type does a bit. Based on a suggestion by @mukilan.
* gfx: Remove `FontTemplateData` (#32034)Martin Robinson2024-04-162-8/+12
| | | | | | | | | | | | | | | | | | | 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-122-10/+3
| | | | | | | | | | | | | | | | | | | | | | | 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.
* 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
* 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>
* fonts: Consider Tertiary Ideographic Plane to be CJK (#31670)sandeep2024-03-181-1/+20
| | | | | | | | | | | | | | | | | | | | * 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>
* fonts: Add `FontIdentifier` and `LocalFontIdentifier` (#31658)Martin Robinson2024-03-142-19/+38
| | | | | | | | | | | | | | | | | | | 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.
* font_cache: Handle filtering `@font-face` rules in Servo (#31601)Martin Robinson2024-03-111-0/+2
| | | | | | | | | | | Instead of letting Stylo filter `@font-face` rules, handle this filtering in Servo. It doesn't make sense that Stylo knows about what fonts Servo supports. This also cleans up a bit the way that this is handled, giving an entire stylesheet of rules to the font cache to process instead of letting each layout thread walk the rules. This brings more of the font-related code into the FontCacheThread itself. This is the first step toward adding WOFF2 support and fixing various web font related bugs.
* clippy: fix warnings in components/gfx (#31560)eri2024-03-082-5/+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
* layout: Turn on synthetic small-caps for layout 2020 (#31435)Martin Robinson2024-02-281-2/+2
| | | | | | | | | | | | Synthetic small caps is supported by the font subsystem, but this is disabled in Layout 2020. We can turn this on to bring support to parity with the old layout system. In addition to turning on synthetic small-caps this change also improves the way that they work. Before, synthetic small caps meant that every character was a small version of capitalized character. After this change, capital letters are larger than small caps versions of small letters -- matching other browsers and the common expectation of how small caps works.
* Further changes required by ServoOriol Brufau2023-10-022-18/+14
|
* Strict import formatting (grouping and granularity) (#30325)Samson2023-09-112-11/+13
| | | | | * strict imports formatting * Reformat all imports
* Try to `use` WebRender types moreMartin Robinson2023-07-101-7/+4
| | | | | The newer versions of WebRender move types around between `webrender` and `webrender_api` and this will reduce the churn during the upgrade.
* Further changes required by ServoOriol Brufau2023-06-091-0/+1
|
* Further changes required by ServoOriol Brufau2023-05-241-1/+3
|
* Fix gfx unit tests.Emilio Cobos Álvarez2019-04-121-2/+2
|
* gfx: Fix unit tests.Emilio Cobos Álvarez2019-03-271-1/+4
|
* Rustfmt has changed its default style :/Simon Sapin2018-12-281-2/+2
|
* Update MPL license to https (part 4)Jan Andre Ikenmeyer2018-11-193-3/+3
|
* Remove useless `use crate_name;` imports.Simon Sapin2018-11-081-1/+0
| | | | A `crate_name::foo` path always works in 2018
* `cargo fix --edition-idioms`Simon Sapin2018-11-083-16/+1
|
* Reorder importsPyfisch2018-11-063-6/+10
|
* Format remaining filesPyfisch2018-11-062-2/+4
|
* Format the rest of gfx #21373kingdido9992018-09-083-146/+134
|
* FontContext: Cache data fetched from the cache threadJon Leighton2018-05-191-1/+36
| | | | | | | Before this change, if we needed to create a Font which we've already created, but at a new size, then we'd fetch the FontTemplateInfo again. If the bytes of the font are held in memory, then this could be expensive as we need to pass those bytes over IPC.
* Implement font fallbackJon Leighton2018-05-192-29/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-282-12/+15
|
* Add test for FontContext/FontGroup functionalityJon Leighton2018-02-2255-0/+293
| | | | | | | | | | | | | | | | | | | | | | Unfortunately, this required quite a bit of changes to the non-test code. That's because FontContext depends on a FontCacheThread, which in turn depends on a CoreResourceThread and therefore lots of other data structures. It seemed like it would be very difficult to instantiate a FontContext as it was, and even if we could it seems like overkill to have all these data structures present for a relatively focused test. Therefore, I created a FontSource trait which represents the interface which FontContext uses to talk to FontCacheThread. FontCacheThread then implements FontSource. Then, in the test, we can create a dummy implementation of FontSource rather than using FontCacheThread. This actually has the advantage that we can make our dummy implementation behave in certain specific way which are useful for testing, for example it can count the number of times find_font_template() is called, which helps us verify that caching/lazy-loading is working as intended.
* Fix FontTemplateDescriptor under FreeTypeJon Leighton2018-02-0737-0/+9804
| | | | | | | | | | | | | | 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.
* Merge gfx and gfx_testsAnthony Ramine2018-01-201-0/+162