mirror of
https://github.com/servo/servo.git
synced 2025-09-11 15:38:24 +01:00
Rename gfx
to fonts
(#32556)
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>
This commit is contained in:
parent
9f8118abc7
commit
cd2ab36759
159 changed files with 224 additions and 266 deletions
69
components/fonts/tests/font_template.rs
Normal file
69
components/fonts/tests/font_template.rs
Normal file
|
@ -0,0 +1,69 @@
|
|||
/* 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 https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// 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 std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use fonts::platform::font::PlatformFont;
|
||||
use fonts::{FontIdentifier, FontTemplateDescriptor, PlatformFontMethods};
|
||||
use servo_url::ServoUrl;
|
||||
use style::values::computed::font::{FontStretch, FontStyle, 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 identifier = FontIdentifier::Web(ServoUrl::from_file_path(path.clone()).unwrap());
|
||||
let file = File::open(path.clone()).unwrap();
|
||||
let data = file.bytes().map(|b| b.unwrap()).collect();
|
||||
let handle = PlatformFont::new_from_data(identifier, Arc::new(data), 0, None).unwrap();
|
||||
handle.descriptor()
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
descriptor("DejaVuSans"),
|
||||
FontTemplateDescriptor::new(
|
||||
FontWeight::NORMAL,
|
||||
FontStretch::hundred(),
|
||||
FontStyle::NORMAL,
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
descriptor("DejaVuSans-Bold"),
|
||||
FontTemplateDescriptor::new(FontWeight::BOLD, FontStretch::hundred(), FontStyle::NORMAL,)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
descriptor("DejaVuSans-Oblique"),
|
||||
FontTemplateDescriptor::new(
|
||||
FontWeight::NORMAL,
|
||||
FontStretch::hundred(),
|
||||
FontStyle::ITALIC,
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
descriptor("DejaVuSansCondensed-BoldOblique"),
|
||||
FontTemplateDescriptor::new(
|
||||
FontWeight::BOLD,
|
||||
FontStretch::from_percentage(0.875),
|
||||
FontStyle::ITALIC,
|
||||
)
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue