Skip to content

Commit

Permalink
Add support for subpixel offsets.
Browse files Browse the repository at this point in the history
Closes #11.
  • Loading branch information
pcwalton committed Feb 21, 2017
1 parent e2014cf commit 49408b9
Show file tree
Hide file tree
Showing 15 changed files with 367 additions and 208 deletions.
3 changes: 2 additions & 1 deletion examples/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ fn main() {
let mut atlas_builder = AtlasBuilder::new(device_pixel_width as GLuint,
shelf_height);
for glyph_index in 0..(glyph_count as u16) {
atlas_builder.pack_glyph(&outlines, glyph_index, point_size as f32).unwrap();
atlas_builder.pack_glyph(&outlines, glyph_index, point_size as f32, 0.0)
.unwrap();
}
atlas = atlas_builder.create_atlas().unwrap();
}
Expand Down
37 changes: 17 additions & 20 deletions examples/dump-outlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ extern crate euclid;
extern crate memmap;
extern crate pathfinder;

use euclid::Point2D;
use memmap::{Mmap, Protection};
use pathfinder::charmap::CodepointRange;
use pathfinder::otf::Font;
use pathfinder::otf::{Font, PointKind};
use std::char;
use std::env;

Expand All @@ -25,28 +24,26 @@ fn main() {
codepoint,
char::from_u32(codepoint).unwrap_or('?'));

let mut last_point: Option<Point2D<i16>> = None;
let mut last_point_was_off_curve = false;
let mut last_point_was_on_curve = false;
font.for_each_point(glyph_id, |point| {
if point.index_in_contour == 0 {
println!("M {},{}", point.position.x, point.position.y);
let prefix = if point.index_in_contour == 0 {
"M "
} else {
let last = last_point.unwrap();
if point.on_curve {
if last_point_was_off_curve {
println!("Q {},{} {},{}",
last.x,
last.y,
point.position.x,
point.position.y);
} else {
println!("L {},{}", point.position.x, point.position.y);
}
match point.kind {
PointKind::OnCurve if last_point_was_on_curve => "L ",
PointKind::OnCurve => " ",
PointKind::QuadControl => "Q ",
PointKind::FirstCubicControl => "C ",
PointKind::SecondCubicControl => " ",
}
}
};

print!("{}{},{}", prefix, point.position.x, point.position.y);

last_point_was_off_curve = !point.on_curve;
last_point = Some(point.position);
last_point_was_on_curve = point.kind == PointKind::OnCurve;
if last_point_was_on_curve {
println!("")
}
}).unwrap()
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/generate-atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn main() {

let mut atlas_builder = AtlasBuilder::new(device_pixel_width as GLuint, shelf_height);
for glyph_index in 0..glyph_count {
atlas_builder.pack_glyph(&outlines, glyph_index, point_size).unwrap();
atlas_builder.pack_glyph(&outlines, glyph_index, point_size, 0.0).unwrap();
}
atlas = atlas_builder.create_atlas().unwrap();
}
Expand Down
Loading

0 comments on commit 49408b9

Please sign in to comment.