🐛 Fix texts with empty fills and strokes

This commit is contained in:
Elena Torro
2025-11-04 16:00:49 +01:00
parent c850f101d3
commit f104dd0d40
6 changed files with 164 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@@ -367,6 +367,22 @@ test("Renders a file with texts with tabs", async ({
await expect(workspace.canvas).toHaveScreenshot(); await expect(workspace.canvas).toHaveScreenshot();
}); });
test("Renders a file with empty text fills and strokes", async ({
page,
}) => {
const workspace = new WasmWorkspacePage(page);
await workspace.setupEmptyFile();
await workspace.mockGetFile("render-wasm/get-file-text-empty-fills.json");
await workspace.goToWorkspace({
id: "58c5cc60-d124-81bd-8007-0f19b52444eb",
pageId: "58c5cc60-d124-81bd-8007-0f19b52444ec",
});
await workspace.waitForFirstRender();
await expect(workspace.canvas).toHaveScreenshot();
});
test.skip("Updates text alignment edition - part 1", async ({ page }) => { test.skip("Updates text alignment edition - part 1", async ({ page }) => {
const workspace = new WasmWorkspacePage(page); const workspace = new WasmWorkspacePage(page);
await workspace.setupEmptyFile(); await workspace.setupEmptyFile();

View File

@@ -28,13 +28,15 @@ pub fn stroke_paragraph_builder_group_from_text(
let fonts = get_font_collection(); let fonts = get_font_collection();
let mut paragraph_group = Vec::new(); let mut paragraph_group = Vec::new();
let remove_stroke_alpha = use_shadow.unwrap_or(false) && !stroke.is_transparent(); let remove_stroke_alpha = use_shadow.unwrap_or(false) && !stroke.is_transparent();
let is_stroke_render = true;
for paragraph in text_content.paragraphs() { for paragraph in text_content.paragraphs() {
let mut stroke_paragraphs_map: std::collections::HashMap<usize, ParagraphBuilder> = let mut stroke_paragraphs_map: std::collections::HashMap<usize, ParagraphBuilder> =
std::collections::HashMap::new(); std::collections::HashMap::new();
for span in paragraph.children().iter() { for span in paragraph.children().iter() {
let text_paint: skia_safe::Handle<_> = merge_fills(span.fills(), *bounds); let text_paint: skia_safe::Handle<_> =
merge_fills(span.fills(), *bounds, is_stroke_render);
let stroke_paints = get_text_stroke_paints( let stroke_paints = get_text_stroke_paints(
stroke, stroke,
bounds, bounds,

View File

@@ -226,12 +226,16 @@ pub fn get_fill_shader(fill: &Fill, bounding_box: &Rect) -> Option<skia::Shader>
} }
} }
pub fn merge_fills(fills: &[Fill], bounding_box: Rect) -> skia::Paint { pub fn merge_fills(fills: &[Fill], bounding_box: Rect, is_stroke_render: bool) -> skia::Paint {
let mut combined_shader: Option<skia::Shader> = None; let mut combined_shader: Option<skia::Shader> = None;
let mut fills_paint = skia::Paint::default(); let mut fills_paint = skia::Paint::default();
if fills.is_empty() { if fills.is_empty() {
combined_shader = Some(skia::shaders::color(skia::Color::TRANSPARENT)); combined_shader = if is_stroke_render {
Some(skia::shaders::color(skia::Color::TRANSPARENT))
} else {
Some(skia::shaders::color(skia::Color::BLACK))
};
fills_paint.set_shader(combined_shader); fills_paint.set_shader(combined_shader);
return fills_paint; return fills_paint;
} }

View File

@@ -351,6 +351,7 @@ impl TextContent {
) -> Vec<ParagraphBuilderGroup> { ) -> Vec<ParagraphBuilderGroup> {
let fonts = get_font_collection(); let fonts = get_font_collection();
let fallback_fonts = get_fallback_fonts(); let fallback_fonts = get_fallback_fonts();
let is_stroke_render = false;
let mut paragraph_group = Vec::new(); let mut paragraph_group = Vec::new();
for paragraph in self.paragraphs() { for paragraph in self.paragraphs() {
@@ -363,6 +364,7 @@ impl TextContent {
fallback_fonts, fallback_fonts,
remove_alpha, remove_alpha,
paragraph.line_height(), paragraph.line_height(),
is_stroke_render,
); );
let text: String = span.apply_text_transform(); let text: String = span.apply_text_transform();
builder.push_style(&text_style); builder.push_style(&text_style);
@@ -678,6 +680,7 @@ impl TextSpan {
fallback_fonts: &HashSet<String>, fallback_fonts: &HashSet<String>,
remove_alpha: bool, remove_alpha: bool,
paragraph_line_height: f32, paragraph_line_height: f32,
is_stroke_render: bool,
) -> skia::textlayout::TextStyle { ) -> skia::textlayout::TextStyle {
let mut style = skia::textlayout::TextStyle::default(); let mut style = skia::textlayout::TextStyle::default();
let mut paint = paint::Paint::default(); let mut paint = paint::Paint::default();
@@ -686,7 +689,7 @@ impl TextSpan {
paint.set_color(skia::Color::BLACK); paint.set_color(skia::Color::BLACK);
paint.set_alpha(255); paint.set_alpha(255);
} else { } else {
paint = merge_fills(&self.fills, *content_bounds); paint = merge_fills(&self.fills, *content_bounds, is_stroke_render);
} }
let max_line_height = f32::max(paragraph_line_height, self.line_height); let max_line_height = f32::max(paragraph_line_height, self.line_height);
@@ -723,11 +726,13 @@ impl TextSpan {
remove_alpha: bool, remove_alpha: bool,
paragraph_line_height: f32, paragraph_line_height: f32,
) -> skia::textlayout::TextStyle { ) -> skia::textlayout::TextStyle {
let is_stroke_render = true;
let mut style = self.to_style( let mut style = self.to_style(
&Rect::default(), &Rect::default(),
fallback_fonts, fallback_fonts,
remove_alpha, remove_alpha,
paragraph_line_height, paragraph_line_height,
is_stroke_render,
); );
if remove_alpha { if remove_alpha {
let mut paint = skia::Paint::default(); let mut paint = skia::Paint::default();