diff options
author | kaiakz <kaiakx@yandex.com> | 2020-02-15 20:52:51 +0800 |
---|---|---|
committer | kaiakz <kaiakx@yandex.com> | 2020-03-19 15:40:14 +0800 |
commit | 0d0ac986b7637185c22920b2f9c14afdb09aa940 (patch) | |
tree | be2b95883de91b17bdef57c0c325457ac597917d /components/canvas/canvas_data.rs | |
parent | 2b0a48f291bf6968ce9d13822fd242d46f4f0412 (diff) | |
download | servo-0d0ac986b7637185c22920b2f9c14afdb09aa940.tar.gz servo-0d0ac986b7637185c22920b2f9c14afdb09aa940.zip |
Add a simple implementation of CanvasRenderingContext2d.fillText
Diffstat (limited to 'components/canvas/canvas_data.rs')
-rw-r--r-- | components/canvas/canvas_data.rs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index f291ce416e9..fa77b016dd0 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -266,6 +266,15 @@ pub trait GenericDrawTarget { ); fn fill(&mut self, path: &Path, pattern: Pattern, draw_options: &DrawOptions); fn fill_rect(&mut self, rect: &Rect<f32>, pattern: Pattern, draw_options: Option<&DrawOptions>); + fn fill_text( + &mut self, + text: String, + x: f32, + y: f32, + max_width: Option<f64>, + pattern: Pattern, + draw_options: &DrawOptions, + ); fn get_format(&self) -> SurfaceFormat; fn get_size(&self) -> Size2D<i32>; fn get_transform(&self) -> Transform2D<f32>; @@ -458,10 +467,19 @@ impl<'a> CanvasData<'a> { } } - pub fn fill_text(&self, text: String, x: f64, y: f64, max_width: Option<f64>) { - error!( - "Unimplemented canvas2d.fillText. Values received: {}, {}, {}, {:?}.", - text, x, y, max_width + pub fn fill_text(&mut self, text: String, x: f64, y: f64, max_width: Option<f64>) { + // If any of the arguments are infinite or NaN, then return. + if !x.is_finite() || !y.is_finite() { + return; + } + + self.drawtarget.fill_text( + text, + x as f32, + y as f32, + max_width, + self.state.fill_style.clone(), + &self.state.draw_options, ); } |