Skip to content

Commit

Permalink
Add name to FontConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
aloucks committed Jul 27, 2019
1 parent f476c3d commit 1c2d6d9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/fonts/atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ pub struct FontConfig {
pub glyph_max_advance_x: f32,
pub rasterizer_flags: u32,
pub rasterizer_multiply: f32,
pub name: Option<String>,
}

impl Default for FontConfig {
Expand All @@ -296,6 +297,7 @@ impl Default for FontConfig {
glyph_max_advance_x: f32::MAX,
rasterizer_flags: 0,
rasterizer_multiply: 1.0,
name: None,
}
}
}
Expand All @@ -313,6 +315,17 @@ impl FontConfig {
raw.GlyphMaxAdvanceX = self.glyph_max_advance_x;
raw.RasterizerFlags = self.rasterizer_flags;
raw.RasterizerMultiply = self.rasterizer_multiply;
if let Some(name) = self.name.as_ref() {
let bytes = name.as_bytes();
let mut len = bytes.len().max(raw.Name.len() - 1);
while !name.is_char_boundary(len) {
len -= 1;
}
unsafe {
bytes.as_ptr().copy_to(raw.Name.as_mut_ptr() as _, len);
raw.Name[len] = 0;
}
}
}
}

Expand Down

0 comments on commit 1c2d6d9

Please sign in to comment.