Skip to content

Commit 0b8a7e9

Browse files
committed
Remove rusttype, use font-kit handle font
1 parent 687db86 commit 0b8a7e9

File tree

8 files changed

+212
-90
lines changed

8 files changed

+212
-90
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ optional = true
2424
default_features = false
2525

2626
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
27-
rusttype = { version = "0.9", optional = true }
27+
ttf-parser = { version = "0.8.2", optional = true }
2828
lazy_static = { version = "1.4.0", optional = true }
29+
pathfinder_geometry = { version = "0.5.1", optional = true }
2930
font-kit = { version = "0.7.0", optional = true }
3031

3132
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.image]
@@ -81,7 +82,7 @@ point_series = []
8182
surface_series = []
8283

8384
# Font implemnetation
84-
ttf = ["font-kit", "rusttype", "lazy_static"]
85+
ttf = ["font-kit", "ttf-parser", "lazy_static", "pathfinder_geometry"]
8586

8687
# Misc
8788
datetime = ["chrono"]

examples/3d-plot.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4747
.draw()?;
4848
Ok(())
4949
}
50+
#[test]
51+
fn entry_point() {
52+
main().unwrap()
53+
}

examples/3d-plot2.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4242

4343
Ok(())
4444
}
45+
#[test]
46+
fn entry_point() {
47+
main().unwrap()
48+
}

examples/tick_control.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
8080

8181
Ok(())
8282
}
83-
8483
#[test]
8584
fn entry_point() {
86-
main().unwrap();
85+
main().unwrap()
8786
}

src/chart/context.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,10 @@ impl<'a, DB: DrawingBackend, X: Ranged, Y: Ranged> ChartContext<'a, DB, Cartesia
302302
.iter()
303303
.map(|(_, text)| {
304304
if orientation.0 > 0 && orientation.1 == 0 && tick_size >= 0 {
305-
let ((x0, _), (x1, _)) = label_style
306-
.font
307-
.layout_box(text)
308-
.unwrap_or(((0, 0), (0, 0)));
309-
x1 - x0
305+
self.drawing_area
306+
.estimate_text_size(text, &label_style)
307+
.map(|(w, _)| w)
308+
.unwrap_or(0) as i32
310309
} else {
311310
// Don't ever do the layout estimationfor the drawing area that is either not
312311
// the right one or the tick mark is inward.

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,8 @@ pub mod prelude {
789789

790790
// Elements
791791
pub use crate::element::{
792-
Circle, Cross, DynElement, EmptyElement, IntoDynElement, MultiLineText, PathElement, Pixel,
793-
Polygon, Rectangle, Text, TriangleMarker, Cubiod,
792+
Circle, Cross, Cubiod, DynElement, EmptyElement, IntoDynElement, MultiLineText,
793+
PathElement, Pixel, Polygon, Rectangle, Text, TriangleMarker,
794794
};
795795

796796
#[cfg(feature = "boxplot")]

src/series/surface.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ where
9696
self.style = StyleConfig::Fixed(s.into());
9797
self
9898
}
99-
10099
}
101100

102101
macro_rules! impl_constructor {
@@ -131,7 +130,10 @@ where
131130
{
132131
type Item = Polygon<(X, Y, Z)>;
133132
fn next(&mut self) -> Option<Self::Item> {
134-
let (b0, b1) = if let (Some(b0), Some(b1)) = (self.free_var_2.get(self.vidx_2), self.free_var_2.get(self.vidx_2 + 1)) {
133+
let (b0, b1) = if let (Some(b0), Some(b1)) = (
134+
self.free_var_2.get(self.vidx_2),
135+
self.free_var_2.get(self.vidx_2 + 1),
136+
) {
135137
self.vidx_2 += 1;
136138
(b0, b1)
137139
} else {
@@ -143,7 +145,7 @@ where
143145
return None;
144146
}
145147
};
146-
148+
147149
match (
148150
self.free_var_1.get(self.vidx_1),
149151
self.free_var_1.get(self.vidx_1 + 1),

0 commit comments

Comments
 (0)