Improve Freetype font handling and font selection
<!-- Please describe your changes on the following line: -->
This correctly implements the boldness and stretchiness properties for Freetype fonts. This also modifies the metric used to select fonts so that it takes account of stretchiness and italicness instead of just boldness. Finally there is a test of font selection (and thereby that fonts are having their boldness/italicness correctly read).
These were originally part of an old and abandoned pull request. I've rebased the changes and modified them to make them work with some name changes.
---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- 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. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19965)
<!-- Reviewable:end -->
Fix FontTemplateDescriptor under FreeType
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.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19928)
<!-- Reviewable:end -->
style: Tweak font-family serialization so that it is simpler.
In particular, every time that there's at least more than one identifier, switch
to quoted family name, since the reconstruction of the serialization will be
lossy anyway.
This allows us to avoid copies and all that.
What Chrome implements doesn't make much sense in the sense that they always
serialize:
font-family: "foo"; -> font-family: foo;
font-family: foo bar; -> font-family: "foo bar";
font-family: foo\ bar; -> font-family: "foo bar";
This patch makes us match on the second case, but not on the rest, because I
think Gecko's behavior is preferable in those cases.
Bug: 1434802
Reviewed-by: xidorn
MozReview-Commit-ID: JwBECA93lfi
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19983)
<!-- Reviewable:end -->
In particular, every time that there's at least more than one identifier, switch
to quoted family name, since the reconstruction of the serialization will be
lossy anyway.
This allows us to avoid copies and all that.
What Chrome implements doesn't make much sense in the sense that they always
serialize:
font-family: "foo"; -> font-family: foo;
font-family: foo bar; -> font-family: "foo bar";
font-family: foo\ bar; -> font-family: "foo bar";
This patch makes us match on the second case, but not on the rest, because I
think Gecko's behavior is preferable in those cases.
Bug: 1434802
Reviewed-by: xidorn
MozReview-Commit-ID: JwBECA93lfi
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.
style: Derive ToCss for FontFamilyList.
The extra reference in to_css is needed because the family list iterator returns
by value in Gecko.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19981)
<!-- Reviewable:end -->
Much like we optimize to_ascii_lowercase.
This also fixes a bug in Servo where attr() rules with an unknown namespace
prefix are parsed, which is wrong.
This avoids resetting the computed values all the time, and paves the way to
avoid using a StyleSet on XBL bindings / Shadow DOM, which we should really
really do because it's super overkill.
There are some XBL bits that are kind of hacky, in particular the mStylistDirty,
but they'll go away soon, since I want to redo how we store styles in XBL.
The alternative, which was returning an array of indices or something was even
more hacky I think.
Bug: 1435939
Reviewed-by: xidorn
MozReview-Commit-ID: 6tEl5gebXVF
Use LayoutRects for bounds and overflow in display lists
Convert text runs to glyphs in display list builder.
Remove ComplexClippingRegion and use the WebRender type.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19931)
<!-- Reviewable:end -->
Change debug assertions to specific ones
<!-- 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 fix#19962 (github issue number if applicable).
<!-- 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. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19970)
<!-- Reviewable:end -->
style: Move content property out of mako.
<!-- Please describe your changes on the following line: -->
r? emilio
---
<!-- 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 build-geckolib` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix#19936 (github issue number if applicable).
<!-- Either: -->
- [x] These changes do not require tests
<!-- 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. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19957)
<!-- Reviewable:end -->
style: Don't serialize default values of the font shorthand.
This makes us consistent with the old style system and Blink / WebKit.
Not adding a test because shorthands serialization is a mess... :(
Anyway, nothing like fixing bugs by removing code.
Bug: 1436031
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19964)
<!-- Reviewable:end -->
The test picks a font and makes a table asking for that font at every
possible weight/stretch combination. One should expect the table
entries to get bolder from right to left and wider from top to bottom.
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.
The current implementation for boldness assumes that if Freetype
claims a font is not bold then it must have normal weight. However
fonts with lighter-than-normal weight are not claimed to be bold.
Therefore we get rid of this check.
This makes us consistent with the old style system and Blink / WebKit.
Not adding a test because shorthands serialization is a mess... :(
Anyway, nothing like fixing bugs by removing code.
Bug: 1436031