Skip to content

Commit

Permalink
Merge pull request #435 from LiveSplit/dependabot/cargo/rustybuzz-0.4.0
Browse files Browse the repository at this point in the history
Update rustybuzz requirement from 0.3.0 to 0.4.0
  • Loading branch information
CryZe authored Jun 29, 2021
2 parents 47c6b7b + 7c5095a commit bcbff22
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ utf-8 = { version = "0.7.4", optional = true }
# Rendering
ahash = { version = "0.7.0", default-features = false, optional = true }
euclid = { version = "0.22.1", default-features = false, optional = true }
rustybuzz = { version = "0.3.0", optional = true }
rustybuzz = { version = "0.4.0", optional = true }
ttf-parser = { version = "0.12.0", optional = true }

# Font Loading
Expand Down
10 changes: 3 additions & 7 deletions src/component/possible_time_save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,10 @@ impl Component {
state
.key_abbreviations
.push("Total Possible Time Save".into());
state.key_abbreviations.push("Possible Time Save".into());
state.key_abbreviations.push("Poss. Time Save".into());
state.key_abbreviations.push("Time Save".into());
} else {
state.key_abbreviations.push("Possible Time Save".into());
state.key_abbreviations.push("Poss. Time Save".into());
state.key_abbreviations.push("Time Save".into());
}
state.key_abbreviations.push("Possible Time Save".into());
state.key_abbreviations.push("Poss. Time Save".into());
state.key_abbreviations.push("Time Save".into());

state.display_two_rows = self.settings.display_two_rows;
state.updates_frequently = false;
Expand Down
27 changes: 10 additions & 17 deletions src/rendering/font/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::{
};
use crate::settings::{FontStretch, FontStyle, FontWeight};
use rustybuzz::{Face, Feature, GlyphBuffer, Tag, UnicodeBuffer, Variation};
use ttf_parser::{GlyphId, OutlineBuilder, Tag as ParserTag};
use ttf_parser::{GlyphId, OutlineBuilder};

pub use self::{cache::FontCache, glyph_cache::GlyphCache};

Expand All @@ -29,8 +29,7 @@ pub const TEXT_FONT: &[u8] = include_bytes!("assets/FiraSans-Regular.ttf");
pub const TIMER_FONT: &[u8] = include_bytes!("assets/Timer.ttf");

pub struct Font<'fd> {
rb: Face<'fd>,
face: ttf_parser::Face<'fd>,
face: Face<'fd>,
color_tables: Option<ColorTables<'fd>>,
scale_factor: f32,
#[cfg(feature = "font-loading")]
Expand Down Expand Up @@ -83,18 +82,13 @@ impl<'fd> Font<'fd> {
weight: FontWeight,
stretch: FontStretch,
) -> Option<Self> {
let mut face = ttf_parser::Face::from_slice(data, index).ok()?;
let mut rb = Face::from_slice(data, index)?;
let mut face = Face::from_slice(data, index)?;

let italic = style.value_for_italic();
let weight = weight.value();
let stretch = stretch.percentage();

face.set_variation(ParserTag::from_bytes(b"ital"), italic);
face.set_variation(ParserTag::from_bytes(b"wght"), weight);
face.set_variation(ParserTag::from_bytes(b"wdth"), stretch);

rb.set_variations(&[
face.set_variations(&[
Variation {
tag: Tag::from_bytes(b"ital"),
value: italic,
Expand All @@ -111,7 +105,6 @@ impl<'fd> Font<'fd> {

Some(Self {
scale_factor: 1.0 / face.height() as f32,
rb,
color_tables: ColorTables::new(&face),
face,
#[cfg(feature = "font-loading")]
Expand Down Expand Up @@ -150,15 +143,15 @@ impl<'f> ScaledFont<'f> {

pub fn shape(self, buffer: UnicodeBuffer) -> Glyphs<'f> {
Glyphs {
buffer: rustybuzz::shape(&self.font.rb, &[], buffer),
buffer: rustybuzz::shape(&self.font.face, &[], buffer),
font: self,
}
}

pub fn shape_tabular_numbers(self, buffer: UnicodeBuffer) -> Glyphs<'f> {
Glyphs {
buffer: rustybuzz::shape(
&self.font.rb,
&self.font.face,
&[
// If the font has support for tabular numbers, we want to
// use it, so we don't have to fix up much. Though we still
Expand Down Expand Up @@ -248,7 +241,7 @@ impl<'f> Glyphs<'f> {

iter.map(move |(i, p)| {
let g = PositionedGlyph {
id: i.codepoint,
id: i.glyph_id,
x: cursor.x + p.x_offset as f32 * scale,
y: cursor.y + p.y_offset as f32 * scale,
};
Expand All @@ -274,7 +267,7 @@ impl<'f> Glyphs<'f> {
cursor.x -= p.x_advance as f32 * scale;
cursor.y -= p.y_advance as f32 * scale;
PositionedGlyph {
id: i.codepoint,
id: i.glyph_id,
x: cursor.x + p.x_offset as f32 * scale,
y: cursor.y + p.y_offset as f32 * scale,
}
Expand Down Expand Up @@ -354,7 +347,7 @@ impl<'f> Glyphs<'f> {
)
.rev()
.map(move |(i, p)| {
let x = if digits.contains(&i.codepoint) {
let x = if digits.contains(&i.glyph_id) {
cursor.x -= digit_width;
let wider_by = digit_width - (p.x_advance as f32 * scale);
cursor.x + p.x_offset as f32 * scale + 0.5 * wider_by
Expand All @@ -365,7 +358,7 @@ impl<'f> Glyphs<'f> {

cursor.y -= p.y_advance as f32 * scale;
PositionedGlyph {
id: i.codepoint,
id: i.glyph_id,
x,
y: cursor.y + p.y_offset as f32 * scale,
}
Expand Down

0 comments on commit bcbff22

Please sign in to comment.