enhance: Implement CanvasRenderingContext2D.measureText (#32704)

Signed-off-by: Chocolate Pie <106949016+chocolate-pie@users.noreply.github.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Chocolate Pie 2024-07-18 04:20:18 +09:00 committed by GitHub
parent d82232d549
commit 1223335547
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 325 additions and 51 deletions

View file

@ -17,6 +17,7 @@ use core_text::font::CTFont;
use core_text::font_descriptor::{
kCTFontDefaultOrientation, CTFontTraits, SymbolicTraitAccessors, TraitAccessors,
};
use euclid::default::{Point2D, Rect, Size2D};
use log::debug;
use style::values::computed::font::{FontStretch, FontStyle, FontWeight};
use webrender_api::FontInstanceFlags;
@ -325,6 +326,16 @@ impl PlatformFontMethods for PlatformFont {
}
FontInstanceFlags::empty()
}
fn typographic_bounds(&self, glyph_id: GlyphId) -> Rect<f32> {
let rect = self
.ctfont
.get_bounding_rects_for_glyphs(kCTFontDefaultOrientation, &[glyph_id as u16]);
Rect::new(
Point2D::new(rect.origin.x as f32, rect.origin.y as f32),
Size2D::new(rect.size.width as f32, rect.size.height as f32),
)
}
}
pub(super) trait CoreTextFontTraitsMapping {