Skip to content

Commit

Permalink
vertical writing attribute (#9)
Browse files Browse the repository at this point in the history
* add v_advance, v_side_bearing

* update message

* Update changelog

Co-authored-by: Alex Butler <alexheretic@gmail.com>
  • Loading branch information
ekicyou and alexheretic authored Jul 6, 2020
1 parent fcb1ab9 commit 6911bf3
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
3 changes: 3 additions & 0 deletions glyph/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
* Add `v_advance` & `v_side_bearing` methods to `ScaleFont` + `_unscaled` variants to `Font`.

# 0.2.2
* Add `Font::glyph_bounds` method, similar to glyph_brush's `glyph_bounds` but for a single glyph.
* Rename `OutlinedGlyph::bounds` to `OutlinedGlyph::px_bounds` for clarity.
Expand Down
20 changes: 20 additions & 0 deletions glyph/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ pub trait Font {
/// Scaling can be done with [as_scaled](trait.Font.html#method.as_scaled).
fn h_side_bearing_unscaled(&self, id: GlyphId) -> f32;

/// Unscaled vertical advance for a given glyph id.
///
/// Scaling can be done with [as_scaled](trait.Font.html#method.as_scaled).
fn v_advance_unscaled(&self, id: GlyphId) -> f32;

/// Unscaled vertical side bearing for a given glyph id.
///
/// Scaling can be done with [as_scaled](trait.Font.html#method.as_scaled).
fn v_side_bearing_unscaled(&self, id: GlyphId) -> f32;

/// Returns additional unscaled kerning to apply for a particular pair of glyph ids.
///
/// Scaling can be done with [as_scaled](trait.Font.html#method.as_scaled).
Expand Down Expand Up @@ -154,6 +164,16 @@ impl<F: Font> Font for &F {
(*self).h_side_bearing_unscaled(id)
}

#[inline]
fn v_advance_unscaled(&self, id: GlyphId) -> f32 {
(*self).v_advance_unscaled(id)
}

#[inline]
fn v_side_bearing_unscaled(&self, id: GlyphId) -> f32 {
(*self).v_side_bearing_unscaled(id)
}

#[inline]
fn kern_unscaled(&self, first: GlyphId, second: GlyphId) -> f32 {
(*self).kern_unscaled(first, second)
Expand Down
10 changes: 10 additions & 0 deletions glyph/src/font_arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ impl Font for FontArc {
self.0.h_side_bearing_unscaled(id)
}

#[inline]
fn v_advance_unscaled(&self, id: GlyphId) -> f32 {
self.0.v_advance_unscaled(id)
}

#[inline]
fn v_side_bearing_unscaled(&self, id: GlyphId) -> f32 {
self.0.v_side_bearing_unscaled(id)
}

#[inline]
fn kern_unscaled(&self, first: GlyphId, second: GlyphId) -> f32 {
self.0.kern_unscaled(first, second)
Expand Down
12 changes: 12 additions & 0 deletions glyph/src/scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ pub trait ScaleFont<F: Font> {
self.h_scale_factor() * self.font().h_side_bearing_unscaled(id)
}

/// Pixel scaled vertical advance for a given glyph.
#[inline]
fn v_advance(&self, id: GlyphId) -> f32 {
self.v_scale_factor() * self.font().v_advance_unscaled(id)
}

/// Pixel scaled vertical side bearing for a given glyph.
#[inline]
fn v_side_bearing(&self, id: GlyphId) -> f32 {
self.v_scale_factor() * self.font().v_side_bearing_unscaled(id)
}

/// Returns additional pixel scaled kerning to apply for a particular pair of glyphs.
#[inline]
fn kern(&self, first: GlyphId, second: GlyphId) -> f32 {
Expand Down
20 changes: 20 additions & 0 deletions glyph/src/ttfp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,26 @@ macro_rules! impl_font {
f32::from(advance)
}

#[inline]
fn v_advance_unscaled(&self, id: GlyphId) -> f32 {
let advance = self
.0
.as_font()
.glyph_ver_advance(id.into())
.expect("Invalid glyph_ver_advance");
f32::from(advance)
}

#[inline]
fn v_side_bearing_unscaled(&self, id: GlyphId) -> f32 {
let advance = self
.0
.as_font()
.glyph_ver_side_bearing(id.into())
.expect("Invalid glyph_ver_side_bearing");
f32::from(advance)
}

#[inline]
fn kern_unscaled(&self, first: GlyphId, second: GlyphId) -> f32 {
self.0
Expand Down

0 comments on commit 6911bf3

Please sign in to comment.