aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/offscreencanvasrenderingcontext2d.rs
diff options
context:
space:
mode:
authorbors-servo <servo-ops@mozilla.com>2020-06-12 13:43:51 -0400
committerGitHub <noreply@github.com>2020-06-12 13:43:51 -0400
commit721271dcd3c20db5ca8cf146e2b5907647afb4d6 (patch)
tree75360f129a6172fd64040d46d88bdc2a8b0f66d0 /components/script/dom/offscreencanvasrenderingcontext2d.rs
parentcb92a15600771a69a796f88975d8100f4be296ae (diff)
parent502f34a9db36202cd89f7a1b48bd138d2ce6f46e (diff)
downloadservo-721271dcd3c20db5ca8cf146e2b5907647afb4d6.tar.gz
servo-721271dcd3c20db5ca8cf146e2b5907647afb4d6.zip
Auto merge of #26697 - utsavoza:ugo/issue-11681/22-05-2020, r=jdm
Implement CanvasRenderingContext2d.fillText The PR consists of broadly two main changes: - Implementation of Canvas2dRenderingContext.font - Basic implementation of Canvas2dRenderingContext.fillText Although I am not fully sure about the long term goals for the canvas backend in Servo, I assumed limited scope for font and text handling (should support simple text drawing with font selection) in the current implementation as I believe a more complete implementation would eventually be brought in as a part of #22957. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #11681 - [x] There are tests for these changes
Diffstat (limited to 'components/script/dom/offscreencanvasrenderingcontext2d.rs')
-rw-r--r--components/script/dom/offscreencanvasrenderingcontext2d.rs57
1 files changed, 51 insertions, 6 deletions
diff --git a/components/script/dom/offscreencanvasrenderingcontext2d.rs b/components/script/dom/offscreencanvasrenderingcontext2d.rs
index a3a873250f1..8c3deb001f4 100644
--- a/components/script/dom/offscreencanvasrenderingcontext2d.rs
+++ b/components/script/dom/offscreencanvasrenderingcontext2d.rs
@@ -3,10 +3,13 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::canvas_state::CanvasState;
+use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasDirection;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasFillRule;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasImageSource;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasLineCap;
use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasLineJoin;
+use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasTextAlign;
+use crate::dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasTextBaseline;
use crate::dom::bindings::codegen::Bindings::OffscreenCanvasRenderingContext2DBinding::OffscreenCanvasRenderingContext2DMethods;
use crate::dom::bindings::codegen::UnionTypes::StringOrCanvasGradientOrCanvasPattern;
use crate::dom::bindings::error::ErrorResult;
@@ -60,11 +63,6 @@ impl OffscreenCanvasRenderingContext2D {
));
reflect_dom_object(boxed, global)
}
- /*
- pub fn get_canvas_state(&self) -> Ref<CanvasState> {
- self.canvas_state.borrow()
- }
- */
pub fn set_canvas_bitmap_dimensions(&self, size: Size2D<u64>) {
self.canvas_state.set_bitmap_dimensions(size);
@@ -249,7 +247,13 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
// https://html.spec.whatwg.org/multipage/#dom-context-2d-filltext
fn FillText(&self, text: DOMString, x: f64, y: f64, max_width: Option<f64>) {
- self.canvas_state.fill_text(text, x, y, max_width)
+ self.canvas_state.fill_text(
+ self.htmlcanvas.as_ref().map(|c| &**c),
+ text,
+ x,
+ y,
+ max_width,
+ )
}
// https://html.spec.whatwg.org/multipage/#textmetrics
@@ -257,6 +261,47 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
self.canvas_state.measure_text(&self.global(), text)
}
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-font
+ fn Font(&self) -> DOMString {
+ self.canvas_state.font()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-font
+ fn SetFont(&self, value: DOMString) {
+ self.canvas_state
+ .set_font(self.htmlcanvas.as_ref().map(|c| &**c), value)
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-textalign
+ fn TextAlign(&self) -> CanvasTextAlign {
+ self.canvas_state.text_align()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-textalign
+ fn SetTextAlign(&self, value: CanvasTextAlign) {
+ self.canvas_state.set_text_align(value)
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-textbaseline
+ fn TextBaseline(&self) -> CanvasTextBaseline {
+ self.canvas_state.text_baseline()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-textbaseline
+ fn SetTextBaseline(&self, value: CanvasTextBaseline) {
+ self.canvas_state.set_text_baseline(value)
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-direction
+ fn Direction(&self) -> CanvasDirection {
+ self.canvas_state.direction()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-context-2d-direction
+ fn SetDirection(&self, value: CanvasDirection) {
+ self.canvas_state.set_direction(value)
+ }
+
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth
fn LineWidth(&self) -> f64 {
self.canvas_state.line_width()