Skip to content
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

Removed gfx -> style dependency #19934

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Some generated files are not rendered by default. Learn more.

@@ -39,7 +39,7 @@ servo_atoms = {path = "../atoms"}
servo_geometry = {path = "../geometry"}
servo_url = {path = "../url"}
smallvec = "0.6"
style = {path = "../style"}
style_traits = {path = "../style_traits"}
time = "0.1.12"
unicode-bidi = {version = "0.3", features = ["with_serde"]}
unicode-script = {version = "0.1", features = ["harfbuzz"]}
@@ -37,7 +37,7 @@ use webrender_api::{LayoutPoint, LayoutRect, LayoutSize, LayoutVector2D, LineSty
use webrender_api::{MixBlendMode, NormalBorder, ScrollPolicy, ScrollSensitivity};
use webrender_api::{StickyOffsetBounds, TransformStyle};

pub use style::dom::OpaqueNode;
pub use style_traits::OpaqueNode;

/// The factor that we multiply the blur radius by in order to inflate the boundaries of display
/// items that involve a blur. This ensures that the display item boundaries include all the ink.
@@ -17,7 +17,7 @@ use std::rc::Rc;
use std::str;
use std::sync::Arc;
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};
use style::computed_values::{font_stretch, font_variant_caps, font_weight};
use style_traits::values::font::{FontStretch, FontVariantCaps, FontWeight};
use text::Shaper;
use text::glyph::{ByteIndex, GlyphData, GlyphId, GlyphStore};
use text::shaping::ShaperMethods;
@@ -49,8 +49,8 @@ pub trait FontHandleMethods: Sized {
fn family_name(&self) -> String;
fn face_name(&self) -> Option<String>;
fn is_italic(&self) -> bool;
fn boldness(&self) -> font_weight::T;
fn stretchiness(&self) -> font_stretch::T;
fn boldness(&self) -> FontWeight;
fn stretchiness(&self) -> FontStretch;

fn glyph_index(&self, codepoint: char) -> Option<GlyphId>;
fn glyph_h_advance(&self, GlyphId) -> Option<FractionalPixel>;
@@ -104,7 +104,7 @@ pub struct FontMetrics {
pub struct Font {
pub handle: FontHandle,
pub metrics: FontMetrics,
pub variant: font_variant_caps::T,
pub variant: FontVariantCaps,
pub descriptor: FontTemplateDescriptor,
pub requested_pt_size: Au,
pub actual_pt_size: Au,
@@ -116,7 +116,7 @@ pub struct Font {

impl Font {
pub fn new(handle: FontHandle,
variant: font_variant_caps::T,
variant: FontVariantCaps,
descriptor: FontTemplateDescriptor,
requested_pt_size: Au,
actual_pt_size: Au,
@@ -261,8 +261,8 @@ impl Font {
#[inline]
pub fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
let codepoint = match self.variant {
font_variant_caps::T::SmallCaps => codepoint.to_uppercase().next().unwrap(), //FIXME: #5938
font_variant_caps::T::Normal => codepoint,
FontVariantCaps::SmallCaps => codepoint.to_uppercase().next().unwrap(), //FIXME: #5938
FontVariantCaps::Normal => codepoint,
};
self.handle.glyph_index(codepoint)
}
@@ -25,8 +25,7 @@ use std::ops::Deref;
use std::sync::{Arc, Mutex};
use std::thread;
use std::u32;
use style::font_face::{EffectiveSources, Source};
use style::values::computed::font::{SingleFontFamily, FamilyName};
use style_traits::values::font::{EffectiveSources, Source};
use webrender_api;

/// A list of font templates that make up a given font family.
@@ -105,7 +104,7 @@ impl FontTemplates {
/// Commands that the FontContext sends to the font cache thread.
#[derive(Debug, Deserialize, Serialize)]
pub enum Command {
GetFontTemplate(SingleFontFamily, FontTemplateDescriptor, IpcSender<Reply>),
GetFontTemplate(LowercaseString, FontTemplateDescriptor, IpcSender<Reply>),
GetLastResortFontTemplate(FontTemplateDescriptor, IpcSender<Reply>),
GetFontInstance(webrender_api::FontKey, Au, IpcSender<webrender_api::FontInstanceKey>),
AddWebFont(LowercaseString, EffectiveSources, IpcSender<()>),
@@ -124,7 +123,7 @@ pub enum Reply {
struct FontCache {
port: IpcReceiver<Command>,
channel_to_self: IpcSender<Command>,
generic_fonts: HashMap<SingleFontFamily, LowercaseString>,
generic_fonts: HashMap<LowercaseString, LowercaseString>,
local_families: HashMap<LowercaseString, FontTemplates>,
web_families: HashMap<LowercaseString, FontTemplates>,
font_context: FontContextHandle,
@@ -134,20 +133,20 @@ struct FontCache {
font_instances: HashMap<(webrender_api::FontKey, Au), webrender_api::FontInstanceKey>,
}

fn populate_generic_fonts() -> HashMap<SingleFontFamily, LowercaseString> {
fn populate_generic_fonts() -> HashMap<LowercaseString, LowercaseString> {
let mut generic_fonts = HashMap::with_capacity(5);

append_map(&mut generic_fonts, SingleFontFamily::Generic(atom!("serif")), "Times New Roman");
append_map(&mut generic_fonts, SingleFontFamily::Generic(atom!("sans-serif")), SANS_SERIF_FONT_FAMILY);
append_map(&mut generic_fonts, SingleFontFamily::Generic(atom!("cursive")), "Apple Chancery");
append_map(&mut generic_fonts, SingleFontFamily::Generic(atom!("fantasy")), "Papyrus");
append_map(&mut generic_fonts, SingleFontFamily::Generic(atom!("monospace")), "Menlo");
append_map(&mut generic_fonts, LowercaseString::new("serif"), "Times New Roman");
append_map(&mut generic_fonts, LowercaseString::new("sans-serif"), SANS_SERIF_FONT_FAMILY);
append_map(&mut generic_fonts, LowercaseString::new("cursive"), "Apple Chancery");
append_map(&mut generic_fonts, LowercaseString::new("fantasy"), "Papyrus");
append_map(&mut generic_fonts, LowercaseString::new("monospace"), "Menlo");

fn append_map(generic_fonts: &mut HashMap<SingleFontFamily, LowercaseString>,
font_family: SingleFontFamily,
fn append_map(generic_fonts: &mut HashMap<LowercaseString, LowercaseString>,
font_family: LowercaseString,
mapped_name: &str) {
let family_name = {
let opt_system_default = system_default_family(font_family.name());
let opt_system_default = system_default_family(&font_family);
match opt_system_default {
Some(system_default) => LowercaseString::new(&system_default),
None => LowercaseString::new(mapped_name)
@@ -230,7 +229,7 @@ impl FontCache {
match src {
Source::Url(url_source) => {
// https://drafts.csswg.org/css-fonts/#font-fetching-requirements
let url = match url_source.url.url() {
let url = match url_source {
Some(url) => url.clone(),
None => return,
};
@@ -292,7 +291,7 @@ impl FontCache {
});
}
Source::Local(ref font) => {
let font_face_name = LowercaseString::new(&font.name);
let font_face_name = LowercaseString::new(&font);
let templates = &mut self.web_families.get_mut(&family_name).unwrap();
let mut found = false;
for_each_variation(&font_face_name, |path| {
@@ -320,9 +319,9 @@ impl FontCache {
});
}

fn transform_family(&self, family: &SingleFontFamily) -> LowercaseString {
match self.generic_fonts.get(family) {
None => LowercaseString::new(family.name()),
fn transform_family(&self, family_name: &LowercaseString) -> LowercaseString {
match self.generic_fonts.get(family_name) {
None => LowercaseString::new(family_name),
Some(mapped_family) => (*mapped_family).clone()
}
}
@@ -351,9 +350,9 @@ impl FontCache {
}
}

fn find_font_in_web_family(&mut self, family: &SingleFontFamily, desc: &FontTemplateDescriptor)
fn find_font_in_web_family(&mut self, family_name: &LowercaseString, desc: &FontTemplateDescriptor)
-> Option<Arc<FontTemplateData>> {
let family_name = LowercaseString::new(family.name());
let family_name = LowercaseString::new(family_name);

if self.web_families.contains_key(&family_name) {
let templates = self.web_families.get_mut(&family_name).unwrap();
@@ -385,11 +384,11 @@ impl FontCache {
}
}

fn find_font_template(&mut self, family: &SingleFontFamily, desc: &FontTemplateDescriptor)
fn find_font_template(&mut self, family_name: &LowercaseString, desc: &FontTemplateDescriptor)
-> Option<FontTemplateInfo> {
let template = self.find_font_in_web_family(family, desc)
let template = self.find_font_in_web_family(family_name, desc)
.or_else(|| {
let transformed_family = self.transform_family(family);
let transformed_family = self.transform_family(family_name);
self.find_font_in_local_family(&transformed_family, desc)
});

@@ -453,11 +452,11 @@ impl FontCacheThread {
}
}

pub fn find_font_template(&self, family: SingleFontFamily, desc: FontTemplateDescriptor)
pub fn find_font_template(&self, family_name: &str, desc: FontTemplateDescriptor)
-> Option<FontTemplateInfo> {
let (response_chan, response_port) =
ipc::channel().expect("failed to create IPC channel");
self.chan.send(Command::GetFontTemplate(family, desc, response_chan))
self.chan.send(Command::GetFontTemplate(LowercaseString::new(family_name), desc, response_chan))
.expect("failed to send message to font cache thread");

let reply = response_port.recv()
@@ -487,8 +486,8 @@ impl FontCacheThread {
}
}

pub fn add_web_font(&self, family: FamilyName, sources: EffectiveSources, sender: IpcSender<()>) {
self.chan.send(Command::AddWebFont(LowercaseString::new(&family.name), sources, sender)).unwrap();
pub fn add_web_font(&self, family_name: &str, sources: EffectiveSources, sender: IpcSender<()>) {
self.chan.send(Command::AddWebFont(LowercaseString::new(family_name), sources, sender)).unwrap();
}

pub fn get_font_instance(&self, key: webrender_api::FontKey, size: Au) -> webrender_api::FontInstanceKey {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.