mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Implement CanvasRenderingContext2d.fillText's "unimplemented" message
This commit is contained in:
parent
1c9c0334ba
commit
2af828485f
6 changed files with 35 additions and 3 deletions
|
@ -133,6 +133,7 @@ impl<'a> CanvasPaintThread<'a> {
|
||||||
match msg.unwrap() {
|
match msg.unwrap() {
|
||||||
CanvasMsg::Canvas2d(message) => {
|
CanvasMsg::Canvas2d(message) => {
|
||||||
match message {
|
match message {
|
||||||
|
Canvas2dMsg::FillText(text, x, y, max_width) => painter.fill_text(text, x, y, max_width),
|
||||||
Canvas2dMsg::FillRect(ref rect) => painter.fill_rect(rect),
|
Canvas2dMsg::FillRect(ref rect) => painter.fill_rect(rect),
|
||||||
Canvas2dMsg::StrokeRect(ref rect) => painter.stroke_rect(rect),
|
Canvas2dMsg::StrokeRect(ref rect) => painter.stroke_rect(rect),
|
||||||
Canvas2dMsg::ClearRect(ref rect) => painter.clear_rect(rect),
|
Canvas2dMsg::ClearRect(ref rect) => painter.clear_rect(rect),
|
||||||
|
@ -228,6 +229,10 @@ impl<'a> CanvasPaintThread<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
fn fill_rect(&self, rect: &Rect<f32>) {
|
fn fill_rect(&self, rect: &Rect<f32>) {
|
||||||
if is_zero_size_gradient(&self.state.fill_style) {
|
if is_zero_size_gradient(&self.state.fill_style) {
|
||||||
return; // Paint nothing if gradient size is zero.
|
return; // Paint nothing if gradient size is zero.
|
||||||
|
|
|
@ -43,6 +43,7 @@ pub enum Canvas2dMsg {
|
||||||
Clip,
|
Clip,
|
||||||
ClosePath,
|
ClosePath,
|
||||||
Fill,
|
Fill,
|
||||||
|
FillText(String, f64, f64, Option<f64>),
|
||||||
FillRect(Rect<f32>),
|
FillRect(Rect<f32>),
|
||||||
GetImageData(Rect<i32>, Size2D<f64>, IpcSender<Vec<u8>>),
|
GetImageData(Rect<i32>, Size2D<f64>, IpcSender<Vec<u8>>),
|
||||||
IsPointInPath(f64, f64, FillRule, IpcSender<bool>),
|
IsPointInPath(f64, f64, FillRule, IpcSender<bool>),
|
||||||
|
|
|
@ -800,6 +800,13 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
receiver.recv().unwrap()
|
receiver.recv().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-filltext
|
||||||
|
fn FillText(&self, text: DOMString, x: f64, y: f64, max_width: Option<f64>) {
|
||||||
|
let parsed_text: String = text.into();
|
||||||
|
self.ipc_renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::FillText(parsed_text, x, y, max_width))).unwrap();
|
||||||
|
self.mark_as_dirty();
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-drawimage
|
||||||
fn DrawImage(&self,
|
fn DrawImage(&self,
|
||||||
image: CanvasImageSource,
|
image: CanvasImageSource,
|
||||||
|
|
|
@ -153,8 +153,9 @@ interface CanvasUserInterface {
|
||||||
[NoInterfaceObject]
|
[NoInterfaceObject]
|
||||||
interface CanvasText {
|
interface CanvasText {
|
||||||
// text (see also the CanvasDrawingStyles interface)
|
// text (see also the CanvasDrawingStyles interface)
|
||||||
//void fillText(DOMString text, unrestricted double x, unrestricted double y,
|
[Pref="dom.canvas-text.enabled"]
|
||||||
// optional unrestricted double maxWidth);
|
void fillText(DOMString text, unrestricted double x, unrestricted double y,
|
||||||
|
optional unrestricted double maxWidth);
|
||||||
//void strokeText(DOMString text, unrestricted double x, unrestricted double y,
|
//void strokeText(DOMString text, unrestricted double x, unrestricted double y,
|
||||||
// optional unrestricted double maxWidth);
|
// optional unrestricted double maxWidth);
|
||||||
//TextMetrics measureText(DOMString text);
|
//TextMetrics measureText(DOMString text);
|
||||||
|
@ -264,4 +265,3 @@ interface CanvasPath {
|
||||||
// double rotation, double startAngle, double endAngle,
|
// double rotation, double startAngle, double endAngle,
|
||||||
// boolean anticlockwise);
|
// boolean anticlockwise);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"dom.bluetooth.enabled": false,
|
"dom.bluetooth.enabled": false,
|
||||||
"dom.bluetooth.testing.enabled": false,
|
"dom.bluetooth.testing.enabled": false,
|
||||||
|
"dom.canvas-text.enabled": false,
|
||||||
"dom.compositionevent.enabled": false,
|
"dom.compositionevent.enabled": false,
|
||||||
"dom.customelements.enabled": false,
|
"dom.customelements.enabled": false,
|
||||||
"dom.forcetouch.enabled": false,
|
"dom.forcetouch.enabled": false,
|
||||||
|
|
18
tests/html/test_canvas_filltext.html
Normal file
18
tests/html/test_canvas_filltext.html
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<canvas id="tutorial" style="border:1px solid #d3d3d3"></canvas>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
canvas = document.getElementById('tutorial');
|
||||||
|
canvas.width = 200;
|
||||||
|
canvas.height = 200;
|
||||||
|
|
||||||
|
var ctx = canvas.getContext('2d');
|
||||||
|
ctx.fillText('Test', 10.0, 10.0);
|
||||||
|
|
||||||
|
ctx.fillText('Test truncated', 30.0, 20.0, 5.0);
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue