aboutsummaryrefslogtreecommitdiffstats
path: root/components/fonts/font.rs
diff options
context:
space:
mode:
authorChocolate Pie <106949016+chocolate-pie@users.noreply.github.com>2024-07-18 04:20:18 +0900
committerGitHub <noreply@github.com>2024-07-17 19:20:18 +0000
commit122333554768d69789a08df25c0bcde3ddd1aa4c (patch)
tree7fc6eeead1345171f7d62f39ae8cd2f36695ff44 /components/fonts/font.rs
parentd82232d549a880aaa1b5613e22ca4f7ec9593d74 (diff)
downloadservo-122333554768d69789a08df25c0bcde3ddd1aa4c.tar.gz
servo-122333554768d69789a08df25c0bcde3ddd1aa4c.zip
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>
Diffstat (limited to 'components/fonts/font.rs')
-rw-r--r--components/fonts/font.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/components/fonts/font.rs b/components/fonts/font.rs
index 719ec70f144..67236debef1 100644
--- a/components/fonts/font.rs
+++ b/components/fonts/font.rs
@@ -49,6 +49,7 @@ pub const KERN: u32 = ot_tag!('k', 'e', 'r', 'n');
pub const SBIX: u32 = ot_tag!('s', 'b', 'i', 'x');
pub const CBDT: u32 = ot_tag!('C', 'B', 'D', 'T');
pub const COLR: u32 = ot_tag!('C', 'O', 'L', 'R');
+pub const BASE: u32 = ot_tag!('B', 'A', 'S', 'E');
pub const LAST_RESORT_GLYPH_ADVANCE: FractionalPixel = 10.0;
@@ -89,6 +90,7 @@ pub trait PlatformFontMethods: Sized {
fn can_do_fast_shaping(&self) -> bool;
fn metrics(&self) -> FontMetrics;
fn table_for_tag(&self, _: FontTableTag) -> Option<FontTable>;
+ fn typographic_bounds(&self, _: GlyphId) -> Rect<f32>;
/// Get the necessary [`FontInstanceFlags`]` for this font.
fn webrender_font_instance_flags(&self) -> FontInstanceFlags;
@@ -464,6 +466,16 @@ impl Font {
cache.glyph_advances.insert(glyph_id, new_width);
new_width
}
+
+ pub fn typographic_bounds(&self, glyph_id: GlyphId) -> Rect<f32> {
+ self.handle.typographic_bounds(glyph_id)
+ }
+
+ #[allow(unsafe_code)]
+ pub fn get_baseline(&self) -> Option<FontBaseline> {
+ let this = self as *const Font;
+ unsafe { self.shaper.get_or_init(|| Shaper::new(this)).get_baseline() }
+ }
}
pub type FontRef = Arc<Font>;
@@ -805,6 +817,12 @@ impl FontFamilyDescriptor {
}
}
+pub struct FontBaseline {
+ pub ideographic_baseline: f32,
+ pub alphabetic_baseline: f32,
+ pub hanging_baseline: f32,
+}
+
/// Given a mapping array `mapping` and a value, map that value onto
/// the value specified by the array. For instance, for FontConfig
/// values of weights, we would map these onto the CSS [0..1000] range