Skip to content

Commit

Permalink
Update to font-kit 0.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm committed May 12, 2020
1 parent ca35017 commit 1accb46
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ categories = ["graphics"]

[dependencies]
euclid = "0.20"
font-kit = { version = "0.5", optional = true }
font-kit = { version = "0.6", optional = true }
lyon_geom = "0.15"
pathfinder_geometry = { version = "0.5", optional = true }
png = "0.15"
typed-arena = "2.0"
sw-composite = "0.7.7"

[features]
default = ["text"]
text = ["font-kit"]
text = ["font-kit", "pathfinder_geometry"]
21 changes: 13 additions & 8 deletions src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ mod fk {
pub use font_kit::canvas::{Canvas, Format, RasterizationOptions};
pub use font_kit::font::Font;
pub use font_kit::hinting::HintingOptions;
pub use font_kit::loader::FontTransform;
pub use pathfinder_geometry::transform2d::Transform2F;
pub use pathfinder_geometry::vector::{vec2f, vec2i};
}

use std::fs::*;
Expand Down Expand Up @@ -741,16 +742,17 @@ impl DrawTarget {
font: &fk::Font,
point_size: f32,
text: &str,
mut start: Point,
start: Point,
src: &Source,
options: &DrawOptions,
) {
let mut start = fk::vec2f(start.x, start.y);
let mut ids = Vec::new();
let mut positions = Vec::new();
for c in text.chars() {
let id = font.glyph_for_char(c).unwrap();
ids.push(id);
positions.push(start);
positions.push(Point::new(start.x(), start.y()));
start += font.advance(id).unwrap() * point_size / 24. / 96.;
}
self.draw_glyphs(font, point_size, &ids, &positions, src, options);
Expand All @@ -771,13 +773,16 @@ impl DrawTarget {
let bounds = font.raster_bounds(
*id,
point_size,
&fk::FontTransform::new(self.transform.m11, self.transform.m21, self.transform.m12, self.transform.m22),
&(self.transform.transform_point(*position)),
fk::Transform2F::row_major(self.transform.m11, self.transform.m12, self.transform.m21, self.transform.m22, 0., 0.)
.translate(fk::vec2f(position.x, position.y)),
fk::HintingOptions::None,
fk::RasterizationOptions::GrayscaleAa,
);
combined_bounds = match bounds {
Ok(bounds) => {
let origin = bounds.origin();
let size = bounds.size();
let bounds = euclid::Rect::new(IntPoint::new(origin.x(), origin.y()), euclid::Size2D::new(size.x(), size.y()));
combined_bounds.union(&bounds)
}
_ => panic!(),
Expand All @@ -787,7 +792,7 @@ impl DrawTarget {
/*let mut canvas = Canvas::new(&euclid::Size2D::new(combined_bounds.size.width as u32,
combined_bounds.size.height as u32), Format::A8);*/
let mut canvas = fk::Canvas::new(
&euclid::Size2D::new(combined_bounds.size.width as u32, combined_bounds.size.height as u32),
fk::vec2i(combined_bounds.size.width, combined_bounds.size.height),
fk::Format::A8,
);
for (id, position) in ids.iter().zip(positions.iter()) {
Expand All @@ -798,8 +803,8 @@ impl DrawTarget {
&mut canvas,
*id,
point_size,
&fk::FontTransform::new(self.transform.m11, self.transform.m21, self.transform.m12, self.transform.m22),
&position,
fk::Transform2F::row_major(self.transform.m11, self.transform.m12, self.transform.m21, self.transform.m22, 0., 0.)
.translate(fk::vec2f(position.x, position.y)),
fk::HintingOptions::None,
fk::RasterizationOptions::GrayscaleAa,
).unwrap();
Expand Down

0 comments on commit 1accb46

Please sign in to comment.