mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Implement CanvasRenderingContext2D.font property
This commit is contained in:
parent
15fd256302
commit
c21fde3751
11 changed files with 68 additions and 6 deletions
|
@ -34,6 +34,7 @@ pixels = { path = "../pixels" }
|
|||
raqote = { version = "0.8", features = ["text"] }
|
||||
servo_config = { path = "../config" }
|
||||
sparkle = "0.1.24"
|
||||
style = { path = "../style" }
|
||||
# NOTE: the sm-angle feature only enables ANGLE on Windows, not other platforms!
|
||||
surfman = { version = "0.2", features = ["sm-angle", "sm-angle-default"] }
|
||||
surfman-chains = "0.3"
|
||||
|
|
|
@ -13,6 +13,7 @@ use num_traits::ToPrimitive;
|
|||
use std::marker::PhantomData;
|
||||
use std::mem;
|
||||
use std::sync::Arc;
|
||||
use style::properties::style_structs::Font as FontStyleStruct;
|
||||
use webrender_api::units::RectExt as RectExt_;
|
||||
|
||||
/// The canvas data stores a state machine for the current status of
|
||||
|
@ -1067,6 +1068,10 @@ impl<'a> CanvasData<'a> {
|
|||
self.backend.set_shadow_color(value, &mut self.state);
|
||||
}
|
||||
|
||||
pub fn set_font(&mut self, font_style: FontStyleStruct) {
|
||||
self.state.font_style = Some(font_style)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#when-shadows-are-drawn
|
||||
fn need_to_draw_shadow(&self) -> bool {
|
||||
self.backend.need_to_draw_shadow(&self.state.shadow_color) &&
|
||||
|
@ -1158,6 +1163,7 @@ pub struct CanvasPaintState<'a> {
|
|||
pub shadow_offset_y: f64,
|
||||
pub shadow_blur: f64,
|
||||
pub shadow_color: Color,
|
||||
pub font_style: Option<FontStyleStruct>,
|
||||
}
|
||||
|
||||
/// It writes an image to the destination target
|
||||
|
|
|
@ -247,6 +247,7 @@ impl<'a> CanvasPaintThread<'a> {
|
|||
},
|
||||
Canvas2dMsg::SetShadowBlur(value) => self.canvas(canvas_id).set_shadow_blur(value),
|
||||
Canvas2dMsg::SetShadowColor(color) => self.canvas(canvas_id).set_shadow_color(color),
|
||||
Canvas2dMsg::SetFont(font_style) => self.canvas(canvas_id).set_font(font_style),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,6 +90,7 @@ impl<'a> CanvasPaintState<'a> {
|
|||
shadow_offset_y: 0.0,
|
||||
shadow_blur: 0.0,
|
||||
shadow_color: Color::Raqote(raqote::SolidSource::from_unpremultiplied_argb(0, 0, 0, 0)),
|
||||
font_style: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue