Skip to content

Commit

Permalink
Update to latest font-kit changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm committed Apr 7, 2020
1 parent ca35017 commit 9a74efb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ categories = ["graphics"]
euclid = "0.20"
font-kit = { version = "0.5", optional = true }
lyon_geom = "0.15"
pathfinder_geometry = "0.4"
png = "0.15"
typed-arena = "2.0"
sw-composite = "0.7.7"
Expand Down
19 changes: 11 additions & 8 deletions src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ 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;
}

use std::fs::*;
Expand All @@ -26,6 +25,8 @@ use crate::stroke::*;
use crate::{IntRect, IntPoint, Point, Transform, Vector};

use euclid::vec2;
use pathfinder_geometry::transform2d::Transform2F;
use pathfinder_geometry::vector::{Vector2F, Vector2I};

#[derive(Clone)]
pub struct Mask {
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 = Vector2F::new(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,15 @@ 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)),
Transform2F::row_major(self.transform.m11, self.transform.m12, self.transform.m21, self.transform.m22, 0., 0.).translate(Vector2F::new(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 +791,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),
Vector2I::new(combined_bounds.size.width, combined_bounds.size.height),
fk::Format::A8,
);
for (id, position) in ids.iter().zip(positions.iter()) {
Expand All @@ -798,8 +802,7 @@ impl DrawTarget {
&mut canvas,
*id,
point_size,
&fk::FontTransform::new(self.transform.m11, self.transform.m21, self.transform.m12, self.transform.m22),
&position,
Transform2F::row_major(self.transform.m11, self.transform.m12, self.transform.m21, self.transform.m22, 0., 0.).translate(Vector2F::new(position.x, position.y)),
fk::HintingOptions::None,
fk::RasterizationOptions::GrayscaleAa,
).unwrap();
Expand Down

0 comments on commit 9a74efb

Please sign in to comment.