New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix FontTemplateDescriptor under FreeType #19928
Merged
+9,902
−70
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Loading status checks…
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.
- Loading branch information
commit 446b0e47a673b133deb7927c02ea5bad983783cf
| @@ -0,0 +1,67 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| #[cfg(not(target_os = "macos"))] extern crate gfx; | ||
| #[cfg(not(target_os = "macos"))] extern crate servo_atoms; | ||
| #[cfg(not(target_os = "macos"))] extern crate style; | ||
|
|
||
| // Test doesn't yet run on Mac, see https://github.com/servo/servo/pull/19928 for explanation. | ||
| #[cfg(not(target_os = "macos"))] | ||
| #[test] | ||
| fn test_font_template_descriptor() { | ||
| use gfx::font_context::FontContextHandle; | ||
| use gfx::font_template::{FontTemplate, FontTemplateDescriptor}; | ||
| use servo_atoms::Atom; | ||
| use std::fs::File; | ||
| use std::io::prelude::*; | ||
| use std::path::PathBuf; | ||
| use style::computed_values::font_stretch::T as FontStretch; | ||
| use style::values::computed::font::FontWeight; | ||
|
|
||
| fn descriptor(filename: &str) -> FontTemplateDescriptor { | ||
| let mut path: PathBuf = [ | ||
| env!("CARGO_MANIFEST_DIR"), | ||
| "tests", | ||
| "support", | ||
| "dejavu-fonts-ttf-2.37", | ||
| "ttf", | ||
| ].iter().collect(); | ||
| path.push(format!("{}.ttf", filename)); | ||
|
|
||
| let file = File::open(path).unwrap(); | ||
|
|
||
| let mut template = FontTemplate::new( | ||
| Atom::from(filename), | ||
| Some(file.bytes().map(|b| b.unwrap()).collect()) | ||
| ).unwrap(); | ||
|
|
||
| let context = FontContextHandle::new(); | ||
|
|
||
| template.descriptor(&context).unwrap() | ||
| } | ||
|
|
||
| assert_eq!(descriptor("DejaVuSans"), FontTemplateDescriptor { | ||
| weight: FontWeight::normal(), | ||
| stretch: FontStretch::Normal, | ||
| italic: false, | ||
| }); | ||
|
|
||
| assert_eq!(descriptor("DejaVuSans-Bold"), FontTemplateDescriptor { | ||
| weight: FontWeight::bold(), | ||
| stretch: FontStretch::Normal, | ||
| italic: false, | ||
| }); | ||
|
|
||
| assert_eq!(descriptor("DejaVuSans-Oblique"), FontTemplateDescriptor { | ||
| weight: FontWeight::normal(), | ||
| stretch: FontStretch::Normal, | ||
| italic: true, | ||
| }); | ||
|
|
||
| assert_eq!(descriptor("DejaVuSansCondensed-BoldOblique"), FontTemplateDescriptor { | ||
| weight: FontWeight::bold(), | ||
| stretch: FontStretch::SemiCondensed, | ||
| italic: true, | ||
| }); | ||
| } |
| @@ -0,0 +1,57 @@ | ||
| abysta at yandex.ru | ||
| Adrian Schroeter | ||
| Aleksey Chalabyan | ||
| Andrey Valentinovich Panov | ||
| Ben Laenen | ||
| Besarion Gugushvili | ||
| Bhikkhu Pesala | ||
| Clayborne Arevalo | ||
| Dafydd Harries | ||
| Danilo Segan | ||
| Davide Viti | ||
| David Jez | ||
| David Lawrence Ramsey | ||
| Denis Jacquerye | ||
| Dwayne Bailey | ||
| Eugeniy Meshcheryakov | ||
| Frédéric Wang | ||
| Gee Fung Sit | ||
| Heikki Lindroos | ||
| James Cloos | ||
| James Crippen | ||
| John Karp | ||
| Keenan Pepper | ||
| Lars Næsbye Christensen | ||
| Lior Halphon | ||
| MaEr | ||
| Mashrab Kuvatov | ||
| Max Berger | ||
| Mederic Boquien | ||
| Michael Everson | ||
| MihailJP | ||
| Misu Moldovan | ||
| Nguyen Thai Ngoc Duy | ||
| Nicolas Mailhot | ||
| Norayr Chilingarian | ||
| Olleg Samoylov | ||
| Ognyan Kulev | ||
| Ondrej Koala Vacha | ||
| Peter Cernak | ||
| Remy Oudompheng | ||
| Roozbeh Pournader | ||
| Rouben Hakobian | ||
| Sahak Petrosyan | ||
| Sami Tarazi | ||
| Sander Vesik | ||
| Stepan Roh | ||
| Stephen Hartke | ||
| Steve Tinney | ||
| Tavmjong Bah | ||
| Thomas Henlich | ||
| Tim May | ||
| Valentin Stoykov | ||
| Vasek Stodulka | ||
| Wesley Transue | ||
| Yoshiki Ohshima | ||
|
|
||
| $Id$ |
| @@ -0,0 +1,3 @@ | ||
| See http://dejavu.sourceforge.net/wiki/index.php/Bugs | ||
|
|
||
| $Id$ |
Oops, something went wrong.
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
I had to do this for the test, which doesn't seem ideal but I struggled to find an alternative. In the existing code, a
FontContextinstantiates aFontContextHandle, but instantiating aFontContextrequires lots of dependencies (some of them external to this crate too).