mirror of
https://github.com/servo/servo.git
synced 2025-08-08 15:05:35 +01:00
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:
parent
d82232d549
commit
1223335547
14 changed files with 325 additions and 51 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue