Skip to content

Commit

Permalink
Auto merge of #24523 - servo:rand, r=jdm,nox
Browse files Browse the repository at this point in the history
Update rand to 0.7 (fixes #24448)
  • Loading branch information
bors-servo committed Oct 23, 2019
2 parents e265303 + 785a344 commit 74d2560
Show file tree
Hide file tree
Showing 46 changed files with 324 additions and 381 deletions.
266 changes: 110 additions & 156 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions Cargo.toml
Expand Up @@ -27,9 +27,5 @@ opt-level = 3

# Those are here to dedupe winapi since mio is still using winapi 0.2.
mio = { git = "https://github.com/servo/mio.git", branch = "servo" }
rand_os = { git = "https://github.com/servo/rand", branch = "servo-rand_os-0.1.3-uwp" }
rand_core = { git = "https://github.com/servo/rand", branch = "servo-rand_os-0.1.3-uwp" }
# https://github.com/cuviper/autocfg/pull/10
autocfg = { git = "https://github.com/servo/autocfg", branch = "rustflags2" }
# https://github.com/retep998/winapi-rs/pull/816
winapi = { git = "https://github.com/servo/winapi-rs", branch = "patch-1" }
4 changes: 2 additions & 2 deletions components/atoms/Cargo.toml
Expand Up @@ -11,7 +11,7 @@ build = "build.rs"
path = "lib.rs"

[dependencies]
string_cache = {version = "0.7"}
string_cache = "0.8"

[build-dependencies]
string_cache_codegen = "0.4"
string_cache_codegen = "0.5"
2 changes: 1 addition & 1 deletion components/bluetooth/Cargo.toml
Expand Up @@ -19,7 +19,7 @@ ipc-channel = "0.12"
log = "0.4"
servo_config = {path = "../config"}
servo_rand = {path = "../rand"}
uuid = {version = "0.7", features = ["v4"]}
uuid = {version = "0.8", features = ["v4"]}

[features]
native-bluetooth = ["device/bluetooth"]
2 changes: 1 addition & 1 deletion components/canvas/Cargo.toml
Expand Up @@ -20,7 +20,7 @@ no_wgl = ["offscreen_gl_context/no_wgl"]
azure = {git = "https://github.com/servo/rust-azure", optional = true}
byteorder = "1"
canvas_traits = {path = "../canvas_traits"}
cssparser = "0.25"
cssparser = "0.27.1"
embedder_traits = {path = "../embedder_traits"}
euclid = "0.20"
fnv = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion components/canvas_traits/Cargo.toml
Expand Up @@ -14,7 +14,7 @@ path = "lib.rs"
webgl_backtrace = []

[dependencies]
cssparser = "0.25"
cssparser = "0.27.1"
euclid = "0.20"
ipc-channel = "0.12"
lazy_static = "1"
Expand Down
2 changes: 1 addition & 1 deletion components/constellation/Cargo.toml
Expand Up @@ -53,4 +53,4 @@ webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
webxr-api = {git = "https://github.com/servo/webxr", features = ["ipc"]}

[target.'cfg(all(not(target_os = "windows"), not(target_os = "ios"), not(target_os="android"), not(target_arch="arm"), not(target_arch="aarch64")))'.dependencies]
gaol = {git = "https://github.com/servo/gaol"}
gaol = "0.2.1"
2 changes: 1 addition & 1 deletion components/devtools/Cargo.toml
Expand Up @@ -22,4 +22,4 @@ msg = {path = "../msg"}
serde = "1.0"
serde_json = "1.0"
time = "0.1"
uuid = {version = "0.7", features = ["v4"]}
uuid = {version = "0.8", features = ["v4"]}
2 changes: 1 addition & 1 deletion components/gfx/Cargo.toml
Expand Up @@ -56,7 +56,7 @@ servo_allocator = {path = "../allocator"}
servo-fontconfig = "0.4"

[target.'cfg(target_os = "android")'.dependencies]
xml5ever = {version = "0.15"}
xml-rs = "0.8"

[target.'cfg(target_os = "windows")'.dependencies]
dwrote = "0.9"
Expand Down
198 changes: 72 additions & 126 deletions components/gfx/platform/freetype/android/font_list.rs
Expand Up @@ -2,17 +2,10 @@
* 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/. */

use super::xml::{Attribute, Node};
use crate::text::util::is_cjk;
use std::cell::RefCell;
use std::fs::File;
use std::io::{self, Read};
use std::path::Path;
use ucd::{Codepoint, UnicodeBlock};
use xml5ever::driver::parse_document;
use xml5ever::rcdom::*;
use xml5ever::rcdom::{Node, RcDom};
use xml5ever::tendril::TendrilSink;
use xml5ever::Attribute;

lazy_static! {
static ref FONT_LIST: FontList = FontList::new();
Expand Down Expand Up @@ -157,51 +150,36 @@ impl FontList {

// Creates a new FontList from a path to the font mapping xml file.
fn from_path(path: &str) -> Option<FontList> {
let xml = match Self::load_file(path) {
Ok(xml) => xml,
_ => {
return None;
},
};

let dom: RcDom = parse_document(RcDom::default(), Default::default()).one(xml);
let doc = &dom.document;
let bytes = std::fs::read(path).ok()?;
let nodes = super::xml::parse(&bytes).ok()?;

// find familyset root node
let children = doc.children.borrow();
let familyset = children.iter().find(|child| match child.data {
NodeData::Element { ref name, .. } => &*name.local == "familyset",
_ => false,
});

let familyset = match familyset {
Some(node) => node,
_ => {
return None;
let familyset = nodes.iter().find_map(|e| match e {
Node::Element { name, children, .. } if name.local_name == "familyset" => {
Some(children)
},
};
_ => None,
})?;

// Parse familyset node
let mut families = Vec::new();
let mut aliases = Vec::new();

for node in familyset.children.borrow().iter() {
match node.data {
NodeData::Element {
ref name,
ref attrs,
..
} => {
if &*name.local == "family" {
Self::parse_family(&node, attrs, &mut families);
} else if &*name.local == "alias" {
// aliases come after the fonts they reference. -->
if !families.is_empty() {
Self::parse_alias(attrs, &mut aliases);
}
for node in familyset {
if let Node::Element {
name,
attributes,
children,
} = node
{
if name.local_name == "family" {
Self::parse_family(children, attributes, &mut families);
} else if name.local_name == "alias" {
// aliases come after the fonts they reference. -->
if !families.is_empty() {
Self::parse_alias(attributes, &mut aliases);
}
},
_ => {},
}
}
}

Expand Down Expand Up @@ -253,14 +231,6 @@ impl FontList {
self.aliases.iter().find(|f| f.from == name)
}

fn load_file(path: &str) -> Result<String, io::Error> {
let mut file = File::open(path)?;
let mut content = String::new();
file.read_to_string(&mut content)?;

Ok(content)
}

// Parse family and font file names
// Example:
// <family name="sans-serif">
Expand All @@ -270,40 +240,35 @@ impl FontList {
// <font weight="300" style="italic">Roboto-LightItalic.ttf</font>
// <font weight="400" style="normal">Roboto-Regular.ttf</font>
// </family>
fn parse_family(familyset: &Node, attrs: &RefCell<Vec<Attribute>>, out: &mut Vec<FontFamily>) {
fn parse_family(familyset: &[Node], attrs: &[Attribute], out: &mut Vec<FontFamily>) {
// Fallback to old Android API v17 xml format if required
let using_api_17 = familyset
.children
.borrow()
.iter()
.any(|node| match node.data {
NodeData::Element { ref name, .. } => &*name.local == "nameset",
_ => false,
});
let using_api_17 = familyset.iter().any(|node| match node {
Node::Element { name, .. } => name.local_name == "nameset",
_ => false,
});
if using_api_17 {
Self::parse_family_v17(familyset, out);
return;
}

// Parse family name
let name = match Self::find_attrib("name", attrs) {
Some(name) => name,
_ => {
return;
},
let name = if let Some(name) = Self::find_attrib("name", attrs) {
name
} else {
return;
};

let mut fonts = Vec::new();
// Parse font variants
for node in familyset.children.borrow().iter() {
match node.data {
NodeData::Element {
ref name,
ref attrs,
..
for node in familyset {
match node {
Node::Element {
name,
attributes,
children,
} => {
if &*name.local == "font" {
FontList::parse_font(&node, attrs, &mut fonts);
if name.local_name == "font" {
FontList::parse_font(&children, attributes, &mut fonts);
}
},
_ => {},
Expand Down Expand Up @@ -333,19 +298,16 @@ impl FontList {
// <file>Roboto-BoldItalic.ttf</file>
// </fileset>
// </family>
fn parse_family_v17(familyset: &Node, out: &mut Vec<FontFamily>) {
fn parse_family_v17(familyset: &[Node], out: &mut Vec<FontFamily>) {
let mut nameset = Vec::new();
let mut fileset = Vec::new();
for node in familyset.children.borrow().iter() {
match node.data {
NodeData::Element { ref name, .. } => {
if &*name.local == "nameset" {
Self::collect_contents_with_tag(node, "name", &mut nameset);
} else if &*name.local == "fileset" {
Self::collect_contents_with_tag(node, "file", &mut fileset);
}
},
_ => {},
for node in familyset {
if let Node::Element { name, children, .. } = node {
if name.local_name == "nameset" {
Self::collect_contents_with_tag(children, "name", &mut nameset);
} else if name.local_name == "fileset" {
Self::collect_contents_with_tag(children, "file", &mut fileset);
}
}
}

Expand All @@ -370,22 +332,17 @@ impl FontList {

// Example:
// <font weight="100" style="normal">Roboto-Thin.ttf</font>
fn parse_font(node: &Node, attrs: &RefCell<Vec<Attribute>>, out: &mut Vec<Font>) {
fn parse_font(nodes: &[Node], attrs: &[Attribute], out: &mut Vec<Font>) {
// Parse font filename
let filename = match Self::text_content(node) {
Some(filename) => filename,
_ => {
return;
},
};

// Parse font weight
let weight = Self::find_attrib("weight", attrs).and_then(|w| w.parse().ok());
if let Some(filename) = Self::text_content(nodes) {
// Parse font weight
let weight = Self::find_attrib("weight", attrs).and_then(|w| w.parse().ok());

out.push(Font {
filename: filename,
weight: weight,
})
out.push(Font {
filename: filename,
weight: weight,
})
}
}

// Example:
Expand All @@ -397,7 +354,7 @@ impl FontList {
// <alias name="helvetica" to="sans-serif" />
// <alias name="tahoma" to="sans-serif" />
// <alias name="verdana" to="sans-serif" />
fn parse_alias(attrs: &RefCell<Vec<Attribute>>, out: &mut Vec<FontAlias>) {
fn parse_alias(attrs: &[Attribute], out: &mut Vec<FontAlias>) {
// Parse alias name and referenced font
let from = match Self::find_attrib("name", attrs) {
Some(from) => from,
Expand All @@ -424,39 +381,28 @@ impl FontList {
})
}

fn find_attrib(name: &str, attrs: &RefCell<Vec<Attribute>>) -> Option<String> {
fn find_attrib(name: &str, attrs: &[Attribute]) -> Option<String> {
attrs
.borrow()
.iter()
.find(|attr| &*attr.name.local == name)
.map(|s| String::from(&s.value))
.find(|attr| attr.name.local_name == name)
.map(|attr| attr.value.clone())
}

fn text_content(node: &Node) -> Option<String> {
node.children
.borrow()
.get(0)
.and_then(|child| match child.data {
NodeData::Text { ref contents } => {
let mut result = String::new();
result.push_str(&contents.borrow());
Some(result)
},
_ => None,
})
fn text_content(nodes: &[Node]) -> Option<String> {
nodes.get(0).and_then(|child| match child {
Node::Text(contents) => Some(contents.clone()),
Node::Element { .. } => None,
})
}

fn collect_contents_with_tag(node: &Node, tag: &str, out: &mut Vec<String>) {
for child in node.children.borrow().iter() {
match child.data {
NodeData::Element { ref name, .. } => {
if &*name.local == tag {
if let Some(content) = Self::text_content(child) {
out.push(content);
}
fn collect_contents_with_tag(nodes: &[Node], tag: &str, out: &mut Vec<String>) {
for node in nodes {
if let Node::Element { name, children, .. } = node {
if name.local_name == tag {
if let Some(content) = Self::text_content(children) {
out.push(content);
}
},
_ => {},
}
}
}
}
Expand Down

0 comments on commit 74d2560

Please sign in to comment.