diff options
Diffstat (limited to 'components/script/dom/canvasrenderingcontext2d.rs')
-rw-r--r-- | components/script/dom/canvasrenderingcontext2d.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index 2a8f14295c0..1faf9878b53 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -24,6 +24,7 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::htmlcanvaselement::{CanvasContext, HTMLCanvasElement}; use crate::dom::imagedata::ImageData; use crate::dom::node::{Node, NodeDamage}; +use crate::dom::textmetrics::TextMetrics; use crate::unpremultiplytable::UNPREMULTIPLY_TABLE; use canvas_traits::canvas::{Canvas2dMsg, CanvasId, CanvasMsg}; use canvas_traits::canvas::{CompositionOrBlending, FillOrStrokeStyle, FillRule}; @@ -873,6 +874,15 @@ impl CanvasState { self.send_canvas_2d_msg(Canvas2dMsg::FillText(parsed_text, x, y, max_width)); } + // https://html.spec.whatwg.org/multipage/#textmetrics + pub fn MeasureText(&self, global: &GlobalScope, _text: DOMString) -> DomRoot<TextMetrics> { + // FIXME: for now faking the implementation of MeasureText(). + // See https://github.com/servo/servo/issues/5411#issuecomment-533776291 + TextMetrics::new( + global, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + ) + } + // https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth pub fn LineWidth(&self) -> f64 { self.state.borrow().line_width @@ -1671,6 +1681,11 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D { self.mark_as_dirty(); } + // https://html.spec.whatwg.org/multipage/#textmetrics + fn MeasureText(&self, text: DOMString) -> DomRoot<TextMetrics> { + self.canvas_state.borrow().MeasureText(&self.global(), text) + } + // https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage fn DrawImage(&self, image: CanvasImageSource, dx: f64, dy: f64) -> ErrorResult { self.canvas_state |