🎉 Add text shadows (#6335)

This commit is contained in:
Elena Torró 2025-04-24 12:19:41 +02:00 committed by GitHub
parent 14e8026e30
commit c2ae58bf08
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 93 additions and 7 deletions

View file

@ -1,13 +1,25 @@
use super::{RenderState, Shape, SurfaceId};
use crate::shapes::TextContent;
use skia_safe::{self as skia, canvas::SaveLayerRec, paint, textlayout::Paragraph};
pub fn render(render_state: &mut RenderState, shape: &Shape, text: &TextContent) {
pub fn render(
render_state: &mut RenderState,
shape: &Shape,
paragraphs: &[Paragraph],
surface_id: Option<SurfaceId>,
paint: Option<&paint::Paint>,
) {
let mut offset_y = 0.0;
for mut skia_paragraph in text.to_paragraphs(&render_state.fonts().font_collection()) {
skia_paragraph.layout(shape.width());
let default_paint = skia::Paint::default();
let mask = SaveLayerRec::default().paint(&paint.unwrap_or(&default_paint));
let canvas = render_state
.surfaces
.canvas(surface_id.unwrap_or(SurfaceId::Fills));
canvas.save_layer(&mask);
for skia_paragraph in paragraphs {
let xy = (shape.selrect().x(), shape.selrect.y() + offset_y);
skia_paragraph.paint(render_state.surfaces.canvas(SurfaceId::Fills), xy);
skia_paragraph.paint(canvas, xy);
offset_y += skia_paragraph.height();
}
canvas.restore();
}