mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
🐛 Fix texts with empty fills and strokes
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -367,6 +367,22 @@ test("Renders a file with texts with tabs", async ({
|
||||
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 }) => {
|
||||
const workspace = new WasmWorkspacePage(page);
|
||||
await workspace.setupEmptyFile();
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 77 KiB |
@@ -28,13 +28,15 @@ pub fn stroke_paragraph_builder_group_from_text(
|
||||
let fonts = get_font_collection();
|
||||
let mut paragraph_group = Vec::new();
|
||||
let remove_stroke_alpha = use_shadow.unwrap_or(false) && !stroke.is_transparent();
|
||||
let is_stroke_render = true;
|
||||
|
||||
for paragraph in text_content.paragraphs() {
|
||||
let mut stroke_paragraphs_map: std::collections::HashMap<usize, ParagraphBuilder> =
|
||||
std::collections::HashMap::new();
|
||||
|
||||
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(
|
||||
stroke,
|
||||
bounds,
|
||||
|
||||
@@ -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 fills_paint = skia::Paint::default();
|
||||
|
||||
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);
|
||||
return fills_paint;
|
||||
}
|
||||
|
||||
@@ -351,6 +351,7 @@ impl TextContent {
|
||||
) -> Vec<ParagraphBuilderGroup> {
|
||||
let fonts = get_font_collection();
|
||||
let fallback_fonts = get_fallback_fonts();
|
||||
let is_stroke_render = false;
|
||||
let mut paragraph_group = Vec::new();
|
||||
|
||||
for paragraph in self.paragraphs() {
|
||||
@@ -363,6 +364,7 @@ impl TextContent {
|
||||
fallback_fonts,
|
||||
remove_alpha,
|
||||
paragraph.line_height(),
|
||||
is_stroke_render,
|
||||
);
|
||||
let text: String = span.apply_text_transform();
|
||||
builder.push_style(&text_style);
|
||||
@@ -678,6 +680,7 @@ impl TextSpan {
|
||||
fallback_fonts: &HashSet<String>,
|
||||
remove_alpha: bool,
|
||||
paragraph_line_height: f32,
|
||||
is_stroke_render: bool,
|
||||
) -> skia::textlayout::TextStyle {
|
||||
let mut style = skia::textlayout::TextStyle::default();
|
||||
let mut paint = paint::Paint::default();
|
||||
@@ -686,7 +689,7 @@ impl TextSpan {
|
||||
paint.set_color(skia::Color::BLACK);
|
||||
paint.set_alpha(255);
|
||||
} 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);
|
||||
@@ -723,11 +726,13 @@ impl TextSpan {
|
||||
remove_alpha: bool,
|
||||
paragraph_line_height: f32,
|
||||
) -> skia::textlayout::TextStyle {
|
||||
let is_stroke_render = true;
|
||||
let mut style = self.to_style(
|
||||
&Rect::default(),
|
||||
fallback_fonts,
|
||||
remove_alpha,
|
||||
paragraph_line_height,
|
||||
is_stroke_render,
|
||||
);
|
||||
if remove_alpha {
|
||||
let mut paint = skia::Paint::default();
|
||||
|
||||
Reference in New Issue
Block a user