Skip to content

Commit 92722ff

Browse files
declantsiennicoburns
authored andcommitted
Add font backend swash
1 parent 428d64d commit 92722ff

File tree

10 files changed

+622
-29
lines changed

10 files changed

+622
-29
lines changed

Cargo.lock

Lines changed: 231 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webrender/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ build = "build.rs"
99
edition = "2018"
1010

1111
[features]
12-
default = ["static_freetype"]
12+
default = ["font_backend_swash"]
1313
profiler = ["tracy-rs/enable_profiler"]
1414
capture = ["api/serialize", "ron", "serde", "smallvec/serde", "etagere/serialization", "glyph_rasterizer/capture"]
1515
replay = ["api/deserialize", "ron", "serde", "smallvec/serde", "etagere/serialization", "glyph_rasterizer/replay"]
1616
display_list_stats = ["api/display_list_stats"]
1717
serialize_program = ["serde", "webrender_build/serialize_program"]
1818
dynamic_freetype = ["glyph_rasterizer/dynamic_freetype"]
1919
static_freetype = ["glyph_rasterizer/static_freetype"]
20+
font_backend_swash = ["glyph_rasterizer/backend_swash", "api/font_backend_swash"]
21+
font_backend_native = ["glyph_rasterizer/backend_native"]
2022
leak_checks = []
2123
gecko = ["firefox-on-glean", "glean", "glyph_rasterizer/gecko"]
2224
sw_compositor = ["swgl"]

webrender/src/resource_cache.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,14 +2301,21 @@ impl ResourceCache {
23012301
index,
23022302
}
23032303
}
2304-
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
2304+
#[cfg(feature = "font_backend_swash")]
2305+
FontTemplate::Native(native) => {
2306+
PlainFontTemplate {
2307+
data: native.0.to_string(),
2308+
index: 0,
2309+
}
2310+
}
2311+
#[cfg(not(any(feature = "font_backend_swash", target_os = "macos", target_os = "ios")))]
23052312
FontTemplate::Native(native) => {
23062313
PlainFontTemplate {
23072314
data: native.path.to_string_lossy().to_string(),
23082315
index: native.index,
23092316
}
23102317
}
2311-
#[cfg(any(target_os = "macos", target_os = "ios"))]
2318+
#[cfg(all(not(feature = "font_backend_swash"), any(target_os = "macos", target_os = "ios")))]
23122319
FontTemplate::Native(native) => {
23132320
PlainFontTemplate {
23142321
data: native.name,

webrender_api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ nightly = ["euclid/unstable", "serde/unstable"]
1212
serialize = []
1313
deserialize = []
1414
display_list_stats = []
15+
font_backend_swash = []
1516

1617
[dependencies]
1718
app_units = "0.7.3"

webrender_api/src/font.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
use peek_poke::PeekPoke;
66
use std::cmp::Ordering;
77
use std::hash::{Hash, Hasher};
8-
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
9-
use std::path::PathBuf;
108
use std::sync::Arc;
119
// local imports
1210
use crate::IdNamespace;
@@ -52,14 +50,19 @@ impl FontSize {
5250
pub fn to_f64_px(&self) -> f64 { self.0 as f64 }
5351
}
5452

55-
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
53+
/// Using Rust crate swash and font-index over native fonts
54+
#[cfg(feature = "font_backend_swash")]
55+
#[derive(Clone, Debug, Hash, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
56+
pub struct NativeFontHandle(pub u32);
57+
58+
#[cfg(not(any(feature = "font_backend_swash", target_os = "macos", target_os = "ios")))]
5659
#[derive(Clone, Debug, Hash, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
5760
pub struct NativeFontHandle {
58-
pub path: PathBuf,
61+
pub path: std::path::PathBuf,
5962
pub index: u32,
6063
}
6164

62-
#[cfg(any(target_os = "macos", target_os = "ios"))]
65+
#[cfg(all(not(feature = "font_backend_swash"), any(target_os = "macos", target_os = "ios")))]
6366
#[derive(Clone, Debug, Hash, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
6467
pub struct NativeFontHandle {
6568
pub name: String,

wr_glyph_rasterizer/Cargo.toml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ license = "MPL-2.0"
77
edition = "2018"
88

99
[features]
10-
default = ["static_freetype"]
10+
default = ["backend_swash"]
1111
dynamic_freetype = []
1212
static_freetype = ["freetype/freetype-sys"]
1313
capture = ["api/serialize", "serde", "smallvec/serde"]
1414
replay = ["api/deserialize", "serde", "smallvec/serde"]
1515
gecko = ["firefox-on-glean", "glean"]
16+
backend_swash = ["swash", "zeno", "font-index", "api/font_backend_swash"]
17+
backend_native = [
18+
"freetype", "libc",
19+
"dwrote",
20+
"core-foundation", "core-graphics", "core-text", "objc"]
1621

1722
[dependencies]
1823
api = { version = "0.66.0", path = "../webrender_api", package = "webrender_api" }
@@ -28,6 +33,17 @@ fxhash = "0.2.1"
2833
glean = { workspace = true, optional = true }
2934
firefox-on-glean = { version = "0.1.0", optional = true }
3035
serde = { optional = true, version = "1.0", features = ["serde_derive"] }
36+
parking_lot = { version = "0.12", optional = true }
37+
zeno = { version = "0.2.2", optional = true }
38+
39+
[dependencies.swash]
40+
git = "https://github.com/declantsien/swash.git"
41+
branch = "webrender-fix"
42+
optional = true
43+
44+
[dependencies.font-index]
45+
git = "https://github.com/declantsien/font-index.git"
46+
optional = true
3147

3248
[dev-dependencies]
3349
env_logger = { version = "0.10", default-features = false }
@@ -38,14 +54,14 @@ rayon = "1"
3854
winit = "0.26"
3955

4056
[target.'cfg(any(target_os = "android", all(unix, not(any(target_os = "macos", target_os = "ios")))))'.dependencies]
41-
freetype = { version = "0.7", default-features = false }
42-
libc = "0.2"
57+
freetype = { version = "0.7", default-features = false, optional = true }
58+
libc = {version = "0.2", optional = true}
4359

4460
[target.'cfg(target_os = "windows")'.dependencies]
45-
dwrote = "0.11"
61+
dwrote = { version = "0.11", optional = true }
4662

4763
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
48-
core-foundation = "0.9.2"
49-
core-graphics = "0.23"
50-
core-text = { version = "20.1", default-features = false }
51-
objc = "0.2"
64+
core-foundation = {version = "0.9.2", optional = true }
65+
core-graphics = {version = "0.23", optional = true }
66+
core-text = { version = "20.1", default-features = false, optional = true }
67+
objc = { version = "0.2", optional = true }

0 commit comments

Comments
 (0)