Skip to content

Commit

Permalink
Bump crossfont to 0.6.0 (PolyMeilex#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
kchibisov authored Dec 8, 2023
1 parent c8a984e commit a2289e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tiny-skia = { version = "0.11", default-features = false, features = [
smithay-client-toolkit = { version = "0.18.0", default_features = false }

# Draw title text using crossfont `--features crossfont`
crossfont = { version = "0.5.0", features = [
crossfont = { version = "0.6.0", features = [
"force_system_fontconfig",
], optional = true }
# Draw title text using ab_glyph `--features ab_glyph`
Expand Down
26 changes: 13 additions & 13 deletions src/title/crossfont_renderer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::title::config;
use std::mem;

use crossfont::{GlyphKey, Rasterize, RasterizedGlyph};
use tiny_skia::{Color, Pixmap, PixmapPaint, PixmapRef, Transform};

use crate::title::config;

pub struct CrossfontTitleText {
title: String,

Expand Down Expand Up @@ -32,7 +35,6 @@ impl std::fmt::Debug for CrossfontTitleText {
impl CrossfontTitleText {
pub fn new(color: Color) -> Result<Self, crossfont::Error> {
let title = "".into();
let scale = 1;

let font_pref = config::titlebar_font().unwrap_or_default();
let font_style = font_pref
Expand All @@ -44,7 +46,7 @@ impl CrossfontTitleText {
});
let font_desc = crossfont::FontDesc::new(&font_pref.name, font_style);

let mut rasterizer = crossfont::Rasterizer::new(scale as f32)?;
let mut rasterizer = crossfont::Rasterizer::new()?;
let size = crossfont::Size::new(font_pref.pt_size);
let font_key = rasterizer.load_font(&font_desc, size)?;

Expand All @@ -60,15 +62,15 @@ impl CrossfontTitleText {
let metrics = rasterizer.metrics(font_key, size)?;

let mut this = Self {
title,
pixmap: None,
rasterizer,
font_desc,
font_key,
size,
scale,
scale: 1,
metrics,
rasterizer,
title,
color,
pixmap: None,
size,
};

this.rerender();
Expand All @@ -87,12 +89,10 @@ impl CrossfontTitleText {
}

pub fn update_scale(&mut self, scale: u32) {
if self.scale != scale {
self.rasterizer.update_dpr(scale as f32);
self.scale = scale;

let old_scale = mem::replace(&mut self.scale, scale);
if old_scale != self.scale {
self.size = self.size.scale(self.scale as f32 / old_scale as f32);
self.update_metrics().ok();

self.rerender();
}
}
Expand Down

0 comments on commit a2289e5

Please sign in to comment.