| autohint |
|
|
- |
| cff |
|
|
- |
| error.rs |
Error types associated with outlines. |
3052 |
- |
| glyf |
|
|
- |
| hint.rs |
Support for applying embedded hinting instructions. |
23800 |
- |
| hint_reliant.rs |
Name detection for fonts that require hinting to be run for correct
contours (FreeType calls these "tricky" fonts). |
14731 |
- |
| memory.rs |
Support for temporary memory allocation, making use of the stack for
small sizes. |
1092 |
- |
| metrics.rs |
Helper for loading (possibly variable) horizontal glyph metrics. |
1781 |
- |
| mod.rs |
Loading, scaling and hinting of glyph outlines.
This module provides support for retrieving (optionally scaled and hinted)
glyph outlines in the form of vector paths.
# Drawing a glyph
Generating SVG [path commands](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#path_commands)
for a character (this assumes a local variable `font` of type [`FontRef`]):
```rust
use skrifa::{
instance::{LocationRef, Size},
outline::{DrawSettings, OutlinePen},
FontRef, MetadataProvider,
};
# fn wrapper(font: FontRef) {
// First, grab the set of outline glyphs from the font.
let outlines = font.outline_glyphs();
// Find the glyph identifier for our character.
let glyph_id = font.charmap().map('Q').unwrap();
// Grab the outline glyph.
let glyph = outlines.get(glyph_id).unwrap();
// Define how we want the glyph to be drawn. This creates
// settings for an instance without hinting at a size of
// 16px with no variations applied.
let settings = DrawSettings::unhinted(Size::new(16.0), LocationRef::default());
// Alternatively, we can apply variations like so:
let var_location = font.axes().location(&[("wght", 650.0), ("wdth", 100.0)]);
let settings = DrawSettings::unhinted(Size::new(16.0), &var_location);
// At this point, we need a "sink" to receive the resulting path. This
// is done by creating an implementation of the OutlinePen trait.
// Let's make one that generates SVG path data.
#[derive(Default)]
struct SvgPath(String);
// Implement the OutlinePen trait for this type. This emits the appropriate
// SVG path commands for each element type.
impl OutlinePen for SvgPath {
fn move_to(&mut self, x: f32, y: f32) {
self.0.push_str(&format!("M{x:.1},{y:.1} "));
}
fn line_to(&mut self, x: f32, y: f32) {
self.0.push_str(&format!("L{x:.1},{y:.1} "));
}
fn quad_to(&mut self, cx0: f32, cy0: f32, x: f32, y: f32) {
self.0
.push_str(&format!("Q{cx0:.1},{cy0:.1} {x:.1},{y:.1} "));
}
fn curve_to(&mut self, cx0: f32, cy0: f32, cx1: f32, cy1: f32, x: f32, y: f32) {
self.0.push_str(&format!(
"C{cx0:.1},{cy0:.1} {cx1:.1},{cy1:.1} {x:.1},{y:.1} "
));
}
fn close(&mut self) {
self.0.push_str("Z ");
}
}
// Now, construct an instance of our pen.
let mut svg_path = SvgPath::default();
// And draw the glyph!
glyph.draw(settings, &mut svg_path).unwrap();
// See what we've drawn.
println!("{}", svg_path.0);
# }
``` |
58186 |
- |
| path.rs |
TrueType style outline to path conversion. |
14592 |
- |
| pen.rs |
Types for collecting the output when drawing a glyph outline. |
970 |
- |
| testing.rs |
Helpers for unit testing |
5850 |
- |
| unscaled.rs |
Compact representation of an unscaled, unhinted outline. |
13783 |
- |
| varc |
|
|
- |