Skip to content

Commit 687db86

Browse files
jrmuizel38
authored andcommitted
Update to rusttype 0.9
This adds support for fonts with CFF glyph outlines.
1 parent c0ab597 commit 687db86

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ optional = true
2424
default_features = false
2525

2626
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
27-
rusttype = { version = "0.8.2", optional = true }
27+
rusttype = { version = "0.9", optional = true }
2828
lazy_static = { version = "1.4.0", optional = true }
2929
font-kit = { version = "0.7.0", optional = true }
3030

src/style/font/ttf.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use std::borrow::{Borrow, Cow};
22
use std::collections::HashMap;
33
use std::i32;
44
use std::io::Read;
5-
use std::sync::{Arc, RwLock};
5+
use std::sync::RwLock;
66

77
use lazy_static::lazy_static;
8-
use rusttype::{point, Error, Font, FontCollection, Scale, SharedBytes};
8+
use rusttype::{point, Font, Scale};
99

1010
use font_kit::family_name::FamilyName;
1111
use font_kit::handle::Handle;
@@ -20,7 +20,7 @@ type FontResult<T> = Result<T, FontError>;
2020
pub enum FontError {
2121
LockError,
2222
NoSuchFont(String, String),
23-
FontLoadError(Arc<Error>),
23+
FontLoadError,
2424
}
2525

2626
impl std::fmt::Display for FontError {
@@ -30,7 +30,7 @@ impl std::fmt::Display for FontError {
3030
FontError::NoSuchFont(family, style) => {
3131
write!(fmt, "No such font: {} {}", family, style)
3232
}
33-
FontError::FontLoadError(e) => write!(fmt, "Font loading error: {}", e),
33+
FontError::FontLoadError => write!(fmt, "Font loading error"),
3434
}
3535
}
3636
}
@@ -100,10 +100,8 @@ fn load_font_data(face: FontFamily, style: FontStyle) -> FontResult<Font<'static
100100
};
101101
// TODO: font-kit actually have rasterizer, so consider remove dependency for rusttype as
102102
// well
103-
let result = FontCollection::from_bytes(Into::<SharedBytes>::into(data))
104-
.map_err(|err| FontError::FontLoadError(Arc::new(err)))?
105-
.font_at(id.max(0) as usize)
106-
.map_err(|err| FontError::FontLoadError(Arc::new(err)));
103+
let result = Font::try_from_vec_and_index(data, id.max(0))
104+
.ok_or(FontError::FontLoadError);
107105

108106
CACHE
109107
.write()

0 commit comments

Comments
 (0)