martensite-text 0.2.0

HarfBuzz shaping, BiDi, font fallback, and sub-pixel IME projection via cosmic-text.
Documentation
//! Typography and IME candidate projection.
#![forbid(unsafe_code)]

/// Re-exported text layout primitives from `cosmic_text`.
pub use cosmic_text::{Attrs, Buffer, FontSystem, Metrics, Shaping};
use winit::dpi::{LogicalPosition, LogicalSize};

/// Computes the IME candidate window bounds from the cursor position and line height.
///
/// Returns a logical position and size describing where the IME candidate window
/// should be anchored relative to the text being composed.
pub fn compute_ime_bounds(x: f64, y: f64, height: f64) -> (LogicalPosition<f64>, LogicalSize<f64>) {
    (LogicalPosition::new(x, y), LogicalSize::new(2.0, height))
}

#[cfg(test)]
mod tests {
    use super::compute_ime_bounds;

    #[test]
    fn returns_correct_position_and_size() {
        let (pos, size) = compute_ime_bounds(10.0, 20.0, 30.0);
        assert_eq!(pos.x, 10.0);
        assert_eq!(pos.y, 20.0);
        assert_eq!(size.width, 2.0);
        assert_eq!(size.height, 30.0);
    }

    #[test]
    fn zero_height() {
        let (pos, size) = compute_ime_bounds(5.0, 5.0, 0.0);
        assert_eq!(pos.x, 5.0);
        assert_eq!(pos.y, 5.0);
        assert_eq!(size.width, 2.0);
        assert_eq!(size.height, 0.0);
    }

    #[test]
    fn negative_coordinates() {
        let (pos, size) = compute_ime_bounds(-10.0, -20.0, 30.0);
        assert_eq!(pos.x, -10.0);
        assert_eq!(pos.y, -20.0);
        assert_eq!(size.width, 2.0);
        assert_eq!(size.height, 30.0);
    }
}