Draft metrics hinting support

This commit is contained in:
Héctor Ramón Jiménez 2025-11-23 06:22:24 +01:00 committed by Jeremy Soller
parent 9339446cfa
commit 48eda6bd7d
15 changed files with 41 additions and 22 deletions

View file

@ -216,6 +216,7 @@ pub struct Buffer {
wrap: Wrap,
monospace_width: Option<f32>,
tab_width: u16,
hint: bool,
}
impl Clone for Buffer {
@ -230,6 +231,7 @@ impl Clone for Buffer {
wrap: self.wrap,
monospace_width: self.monospace_width,
tab_width: self.tab_width,
hint: self.hint,
}
}
}
@ -246,7 +248,7 @@ impl Buffer {
/// # Panics
///
/// Will panic if `metrics.line_height` is zero.
pub fn new_empty(metrics: Metrics) -> Self {
pub fn new_empty(metrics: Metrics, hint: bool) -> Self {
assert_ne!(metrics.line_height, 0.0, "line height cannot be 0");
Self {
lines: Vec::new(),
@ -258,6 +260,7 @@ impl Buffer {
wrap: Wrap::WordOrGlyph,
monospace_width: None,
tab_width: 8,
hint,
}
}
@ -266,8 +269,8 @@ impl Buffer {
/// # Panics
///
/// Will panic if `metrics.line_height` is zero.
pub fn new(font_system: &mut FontSystem, metrics: Metrics) -> Self {
let mut buffer = Self::new_empty(metrics);
pub fn new(font_system: &mut FontSystem, metrics: Metrics, hint: bool) -> Self {
let mut buffer = Self::new_empty(metrics, hint);
buffer.set_text(font_system, "", &Attrs::new(), Shaping::Advanced, None);
buffer
}
@ -297,6 +300,7 @@ impl Buffer {
self.wrap,
self.monospace_width,
self.tab_width,
self.hint,
);
}
}
@ -540,6 +544,7 @@ impl Buffer {
self.wrap,
self.monospace_width,
self.tab_width,
self.hint,
))
}
@ -719,7 +724,7 @@ impl Buffer {
/// ```
/// # use cosmic_text::{Attrs, Buffer, Family, FontSystem, Metrics, Shaping};
/// # let mut font_system = FontSystem::new();
/// let mut buffer = Buffer::new_empty(Metrics::new(32.0, 44.0));
/// let mut buffer = Buffer::new_empty(Metrics::new(32.0, 44.0), false);
/// let attrs = Attrs::new().family(Family::Serif);
/// buffer.set_rich_text(
/// &mut font_system,
@ -1448,7 +1453,7 @@ impl BorrowedWithFontSystem<'_, Buffer> {
/// ```
/// # use cosmic_text::{Attrs, Buffer, Family, FontSystem, Metrics, Shaping};
/// # let mut font_system = FontSystem::new();
/// let mut buffer = Buffer::new_empty(Metrics::new(32.0, 44.0));
/// let mut buffer = Buffer::new_empty(Metrics::new(32.0, 44.0), false);
/// let attrs = Attrs::new().family(Family::Serif);
/// buffer.set_rich_text(
/// &mut font_system,