2017-01-07 14:52:45 -05:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2017-01-09 21:29:41 -05:00
|
|
|
extern crate euclid;
|
2017-01-07 02:49:45 -05:00
|
|
|
extern crate memmap;
|
|
|
|
extern crate pathfinder;
|
|
|
|
|
2017-01-09 21:29:41 -05:00
|
|
|
use euclid::Point2D;
|
2017-01-07 02:49:45 -05:00
|
|
|
use memmap::{Mmap, Protection};
|
2017-01-09 21:29:41 -05:00
|
|
|
use pathfinder::charmap::CodepointRange;
|
2017-01-26 13:27:38 -05:00
|
|
|
use pathfinder::otf::Font;
|
2017-01-09 21:29:41 -05:00
|
|
|
use std::char;
|
2017-01-07 02:49:45 -05:00
|
|
|
use std::env;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let file = Mmap::open_path(env::args().nth(1).unwrap(), Protection::Read).unwrap();
|
|
|
|
unsafe {
|
2017-01-26 13:27:38 -05:00
|
|
|
let font = Font::new(file.as_slice()).unwrap();
|
2017-01-09 22:49:00 -05:00
|
|
|
let codepoint_ranges = [CodepointRange::new('!' as u32, '~' as u32)];
|
2017-02-07 23:02:10 -05:00
|
|
|
let glyph_mapping = font.glyph_mapping_for_codepoint_ranges(&codepoint_ranges).unwrap();
|
|
|
|
for (glyph_index, (_, glyph_id)) in glyph_mapping.iter().enumerate() {
|
2017-02-02 19:40:46 -05:00
|
|
|
let codepoint = '!' as u32 + glyph_index as u32;
|
2017-01-09 21:29:41 -05:00
|
|
|
println!("Glyph {}: codepoint {} '{}':",
|
|
|
|
glyph_id,
|
|
|
|
codepoint,
|
|
|
|
char::from_u32(codepoint).unwrap_or('?'));
|
|
|
|
|
|
|
|
let mut last_point: Option<Point2D<i16>> = None;
|
|
|
|
let mut last_point_was_off_curve = false;
|
2017-02-02 20:00:37 -05:00
|
|
|
font.for_each_point(glyph_id, |point| {
|
2017-02-03 20:04:57 -05:00
|
|
|
if point.index_in_contour == 0 {
|
2017-01-09 21:29:41 -05:00
|
|
|
println!("M {},{}", point.position.x, point.position.y);
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
last_point_was_off_curve = !point.on_curve;
|
|
|
|
last_point = Some(point.position);
|
|
|
|
}).unwrap()
|
|
|
|
}
|
2017-01-07 02:49:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|