mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
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
This commit is contained in:
commit
721271dcd3
57 changed files with 928 additions and 183 deletions
|
@ -7,6 +7,7 @@ use canvas_traits::canvas::*;
|
|||
use canvas_traits::ConstellationCanvasMsg;
|
||||
use crossbeam_channel::{select, unbounded, Sender};
|
||||
use euclid::default::Size2D;
|
||||
use gfx::font_cache_thread::FontCacheThread;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use ipc_channel::router::ROUTER;
|
||||
use std::borrow::ToOwned;
|
||||
|
@ -35,14 +36,19 @@ pub struct CanvasPaintThread<'a> {
|
|||
canvases: HashMap<CanvasId, CanvasData<'a>>,
|
||||
next_canvas_id: CanvasId,
|
||||
webrender_api: Box<dyn WebrenderApi>,
|
||||
font_cache_thread: FontCacheThread,
|
||||
}
|
||||
|
||||
impl<'a> CanvasPaintThread<'a> {
|
||||
fn new(webrender_api: Box<dyn WebrenderApi>) -> CanvasPaintThread<'a> {
|
||||
fn new(
|
||||
webrender_api: Box<dyn WebrenderApi>,
|
||||
font_cache_thread: FontCacheThread,
|
||||
) -> CanvasPaintThread<'a> {
|
||||
CanvasPaintThread {
|
||||
canvases: HashMap::new(),
|
||||
next_canvas_id: CanvasId(0),
|
||||
webrender_api,
|
||||
font_cache_thread,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,6 +56,7 @@ impl<'a> CanvasPaintThread<'a> {
|
|||
/// communicate with it.
|
||||
pub fn start(
|
||||
webrender_api: Box<dyn WebrenderApi + Send>,
|
||||
font_cache_thread: FontCacheThread,
|
||||
) -> (Sender<ConstellationCanvasMsg>, IpcSender<CanvasMsg>) {
|
||||
let (ipc_sender, ipc_receiver) = ipc::channel::<CanvasMsg>().unwrap();
|
||||
let msg_receiver = ROUTER.route_ipc_receiver_to_new_crossbeam_receiver(ipc_receiver);
|
||||
|
@ -57,7 +64,7 @@ impl<'a> CanvasPaintThread<'a> {
|
|||
thread::Builder::new()
|
||||
.name("CanvasThread".to_owned())
|
||||
.spawn(move || {
|
||||
let mut canvas_paint_thread = CanvasPaintThread::new(webrender_api);
|
||||
let mut canvas_paint_thread = CanvasPaintThread::new(webrender_api, font_cache_thread);
|
||||
loop {
|
||||
select! {
|
||||
recv(msg_receiver) -> msg => {
|
||||
|
@ -118,6 +125,8 @@ impl<'a> CanvasPaintThread<'a> {
|
|||
AntialiasMode::None
|
||||
};
|
||||
|
||||
let font_cache_thread = self.font_cache_thread.clone();
|
||||
|
||||
let canvas_id = self.next_canvas_id.clone();
|
||||
self.next_canvas_id.0 += 1;
|
||||
|
||||
|
@ -125,7 +134,7 @@ impl<'a> CanvasPaintThread<'a> {
|
|||
size,
|
||||
self.webrender_api.clone(),
|
||||
antialias,
|
||||
canvas_id.clone(),
|
||||
font_cache_thread,
|
||||
);
|
||||
self.canvases.insert(canvas_id.clone(), canvas_data);
|
||||
|
||||
|
@ -134,9 +143,10 @@ impl<'a> CanvasPaintThread<'a> {
|
|||
|
||||
fn process_canvas_2d_message(&mut self, message: Canvas2dMsg, canvas_id: CanvasId) {
|
||||
match message {
|
||||
Canvas2dMsg::FillText(text, x, y, max_width, style) => {
|
||||
Canvas2dMsg::FillText(text, x, y, max_width, style, is_rtl) => {
|
||||
self.canvas(canvas_id).set_fill_style(style);
|
||||
self.canvas(canvas_id).fill_text(text, x, y, max_width);
|
||||
self.canvas(canvas_id)
|
||||
.fill_text(text, x, y, max_width, is_rtl);
|
||||
},
|
||||
Canvas2dMsg::FillRect(rect, style) => {
|
||||
self.canvas(canvas_id).set_fill_style(style);
|
||||
|
@ -247,6 +257,13 @@ 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),
|
||||
Canvas2dMsg::SetTextAlign(text_align) => {
|
||||
self.canvas(canvas_id).set_text_align(text_align)
|
||||
},
|
||||
Canvas2dMsg::SetTextBaseline(text_baseline) => {
|
||||
self.canvas(canvas_id).set_text_baseline(text_baseline)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue