Merge pull request #7170 from penpot/elenatorro-fix-text-tests
🔧 Update and fix text tests
@@ -68,10 +68,7 @@ test("Updates a text font", async ({ page }) => {
|
||||
await workspace.waitForFirstRender({ hideUI: false });
|
||||
|
||||
await workspace.clickLeafLayer("this is a text");
|
||||
const fontStyle = workspace.page.getByTitle("Font Style");
|
||||
await fontStyle.click();
|
||||
const boldOption = fontStyle.getByText("bold").first();
|
||||
await boldOption.click();
|
||||
await page.keyboard.press("Control+b");
|
||||
|
||||
await workspace.hideUI();
|
||||
|
||||
@@ -197,6 +194,21 @@ test("Renders a file with text decoration", async ({ page }) => {
|
||||
await expect(workspace.canvas).toHaveScreenshot();
|
||||
});
|
||||
|
||||
test("Renders a file with emoji and text decoration", async ({ page }) => {
|
||||
const workspace = new WasmWorkspacePage(page);
|
||||
await workspace.setupEmptyFile();
|
||||
await mockGetEmojiFont(workspace);
|
||||
|
||||
await workspace.mockGetFile("render-wasm/get-file-emoji-and-text-decoration.json");
|
||||
|
||||
await workspace.goToWorkspace({
|
||||
id: "82d128e1-d3b1-80a5-8006-ae60fedcd5e7",
|
||||
pageId: "82d128e1-d3b1-80a5-8006-ae60fedcd5e8",
|
||||
});
|
||||
await workspace.waitForFirstRender();
|
||||
await expect(workspace.canvas).toHaveScreenshot();
|
||||
});
|
||||
|
||||
test("Renders a file with multiple emoji", async ({ page }) => {
|
||||
const workspace = new WasmWorkspacePage(page);
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 160 KiB |
|
Before Width: | Height: | Size: 508 KiB After Width: | Height: | Size: 523 KiB |
|
Before Width: | Height: | Size: 167 KiB After Width: | Height: | Size: 146 KiB |
|
Before Width: | Height: | Size: 123 KiB After Width: | Height: | Size: 119 KiB |
@@ -161,7 +161,8 @@
|
||||
|
||||
(h/call wasm/internal-module "_set_shape_text_content")))
|
||||
|
||||
(def ^:private emoji-pattern #"[\uD83C-\uDBFF][\uDC00-\uDFFF]|[\u2600-\u27BF]")
|
||||
(def ^:private emoji-pattern
|
||||
#"(?:\uD83C[\uDDE6-\uDDFF]\uD83C[\uDDE6-\uDDFF])|(?:\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDEFF])|(?:\uD83E[\uDD00-\uDDFF])|(?:\uD83D[\uDE80-\uDEFF]|\uD83E[\uDC00-\uDCFF])|(?:\uD83E[\uDE70-\uDEFF])|[\u2600-\u26FF\u2700-\u27BF\u2300-\u23FF\u2B00-\u2BFF]")
|
||||
|
||||
(def ^:private unicode-ranges
|
||||
{:japanese #"[\u3040-\u30FF\u31F0-\u31FF\uFF66-\uFF9F]"
|
||||
@@ -215,7 +216,8 @@
|
||||
:music #"[\u2669-\u267B\u1D100-\u1D1FF]"})
|
||||
|
||||
(defn contains-emoji? [text]
|
||||
(boolean (some #(re-find emoji-pattern %) (seq text))))
|
||||
(let [result (re-find emoji-pattern text)]
|
||||
(boolean result)))
|
||||
|
||||
(defn collect-used-languages
|
||||
[used text]
|
||||
|
||||
@@ -520,6 +520,7 @@ impl RenderState {
|
||||
shadows::render_text_drop_shadows(self, &shape, &mut paragraphs, antialias);
|
||||
}
|
||||
|
||||
let count_inner_strokes = shape.count_visible_inner_strokes();
|
||||
text::render(self, &shape, &mut paragraphs, None, None);
|
||||
|
||||
for stroke in shape.visible_strokes().rev() {
|
||||
@@ -528,6 +529,7 @@ impl RenderState {
|
||||
&shape.selrect(),
|
||||
shape.image_filter(1.).as_ref(),
|
||||
shape.mask_filter(1.).as_ref(),
|
||||
count_inner_strokes,
|
||||
);
|
||||
shadows::render_text_drop_shadows(
|
||||
self,
|
||||
|
||||
@@ -1109,6 +1109,13 @@ impl Shape {
|
||||
pub fn has_visible_inner_strokes(&self) -> bool {
|
||||
self.visible_strokes().any(|s| s.kind == StrokeKind::Inner)
|
||||
}
|
||||
|
||||
pub fn count_visible_inner_strokes(&self) -> usize {
|
||||
self.visible_strokes()
|
||||
.filter(|s| s.kind == StrokeKind::Inner)
|
||||
.count()
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the list of children taking into account the structure modifiers
|
||||
*/
|
||||
|
||||
@@ -124,6 +124,7 @@ impl TextContent {
|
||||
bounds: &Rect,
|
||||
blur: Option<&ImageFilter>,
|
||||
blur_mask: Option<&MaskFilter>,
|
||||
count_inner_strokes: usize,
|
||||
) -> Vec<Vec<ParagraphBuilder>> {
|
||||
let fallback_fonts = get_fallback_fonts();
|
||||
let fonts = get_font_collection();
|
||||
@@ -138,8 +139,14 @@ impl TextContent {
|
||||
if let Some(blur_mask) = blur_mask {
|
||||
text_paint.set_mask_filter(blur_mask.clone());
|
||||
}
|
||||
let stroke_paints =
|
||||
get_text_stroke_paints(stroke, bounds, &text_paint, blur, blur_mask);
|
||||
let stroke_paints = get_text_stroke_paints(
|
||||
stroke,
|
||||
bounds,
|
||||
&text_paint,
|
||||
blur,
|
||||
blur_mask,
|
||||
count_inner_strokes,
|
||||
);
|
||||
let text: String = leaf.apply_text_transform();
|
||||
|
||||
for (paint_idx, stroke_paint) in stroke_paints.iter().enumerate() {
|
||||
@@ -198,8 +205,15 @@ impl TextContent {
|
||||
bounds: &Rect,
|
||||
blur: Option<&ImageFilter>,
|
||||
blur_mask: Option<&MaskFilter>,
|
||||
count_inner_strokes: usize,
|
||||
) -> Vec<Vec<ParagraphBuilder>> {
|
||||
self.collect_paragraphs(self.to_stroke_paragraphs(stroke, bounds, blur, blur_mask))
|
||||
self.collect_paragraphs(self.to_stroke_paragraphs(
|
||||
stroke,
|
||||
bounds,
|
||||
blur,
|
||||
blur_mask,
|
||||
count_inner_strokes,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn grow_type(&self) -> GrowType {
|
||||
@@ -765,6 +779,7 @@ fn get_text_stroke_paints(
|
||||
text_paint: &Paint,
|
||||
blur: Option<&ImageFilter>,
|
||||
blur_mask: Option<&MaskFilter>,
|
||||
count_inner_strokes: usize,
|
||||
) -> Vec<Paint> {
|
||||
let mut paints = Vec::new();
|
||||
|
||||
@@ -777,7 +792,7 @@ fn get_text_stroke_paints(
|
||||
is_opaque = shader.unwrap().is_opaque();
|
||||
}
|
||||
|
||||
if is_opaque {
|
||||
if is_opaque && count_inner_strokes == 1 {
|
||||
let mut paint = text_paint.clone();
|
||||
paint.set_style(skia::PaintStyle::Fill);
|
||||
paint.set_anti_alias(true);
|
||||
@@ -785,7 +800,6 @@ fn get_text_stroke_paints(
|
||||
paint.set_image_filter(blur.clone());
|
||||
}
|
||||
paints.push(paint);
|
||||
|
||||
let mut paint = skia::Paint::default();
|
||||
paint.set_style(skia::PaintStyle::Stroke);
|
||||
paint.set_blend_mode(skia::BlendMode::SrcIn);
|
||||
|
||||