1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
use crate::prelude::*; use crate::scalar; use skia_bindings as sb; use skia_bindings::SkFontMetrics; bitflags! { #[derive(Default)] pub struct Flags: u32 { const UNDERLINE_THICKNESS_IS_VALID = sb::SkFontMetrics_FontMetricsFlags_kUnderlineThicknessIsValid_Flag as _; const UNDERLINE_POSITION_IS_VALID = sb::SkFontMetrics_FontMetricsFlags_kUnderlinePositionIsValid_Flag as _; const STRIKEOUT_THICKNESS_IS_VALID = sb::SkFontMetrics_FontMetricsFlags_kStrikeoutThicknessIsValid_Flag as _; const STRIKEOUT_POSITION_IS_VALID = sb::SkFontMetrics_FontMetricsFlags_kStrikeoutPositionIsValid_Flag as _; } } #[repr(C)] #[derive(Copy, Clone, PartialEq, Default, Debug)] pub struct FontMetrics { flags: self::Flags, pub top: scalar, pub ascent: scalar, pub descent: scalar, pub bottom: scalar, pub leading: scalar, pub avg_char_width: scalar, pub max_char_width: scalar, pub x_min: scalar, pub x_max: scalar, pub x_height: scalar, pub cap_height: scalar, underline_thickness: scalar, underline_position: scalar, strikeout_thickness: scalar, strikeout_position: scalar, } impl NativeTransmutable<SkFontMetrics> for FontMetrics {} #[test] fn test_font_metrics_layout() { FontMetrics::test_layout(); } impl FontMetrics { pub fn underline_thickness(&self) -> Option<scalar> { self.if_valid( Flags::UNDERLINE_THICKNESS_IS_VALID, self.underline_thickness, ) } pub fn underline_position(&self) -> Option<scalar> { self.if_valid(Flags::UNDERLINE_POSITION_IS_VALID, self.underline_position) } pub fn strikeout_thickness(&self) -> Option<scalar> { self.if_valid( Flags::STRIKEOUT_THICKNESS_IS_VALID, self.strikeout_thickness, ) } pub fn strikeout_position(&self) -> Option<scalar> { self.if_valid(Flags::STRIKEOUT_POSITION_IS_VALID, self.strikeout_position) } fn if_valid(&self, flag: self::Flags, value: scalar) -> Option<scalar> { self.flags.contains(flag).if_true_some(value) } }