Skip to content

Commit

Permalink
fix: stroke/fill text should treat \n as space
Browse files Browse the repository at this point in the history
Close #434
  • Loading branch information
Brooooooklyn committed Mar 10, 2022
1 parent 0d12337 commit 4c9ac1e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions __test__/text.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,19 @@ for (const align of ['center', 'end', 'left', 'right', 'start'] as CanvasTextAli
await snapshotImage(t)
})
}

test(`fillText-line-break-as-space`, async (t) => {
const { ctx, canvas } = t.context
const x = canvas.width / 2
ctx.font = '16px Iosevka Slab'
ctx.fillText('Hello\nCanvas', x, 200)
await snapshotImage(t)
})

test(`strokeText-line-break-as-space`, async (t) => {
const { ctx, canvas } = t.context
const x = canvas.width / 2
ctx.font = '32px Iosevka Slab'
ctx.strokeText('Hello\nCanvas', x, 200)
await snapshotImage(t)
})
16 changes: 14 additions & 2 deletions src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,13 @@ impl Context {
max_width: f32,
) -> result::Result<(), SkError> {
let stroke_paint = self.stroke_paint()?;
self.draw_text(text, x, y, max_width, &stroke_paint)?;
self.draw_text(
text.replace('\n', " ").as_str(),
x,
y,
max_width,
&stroke_paint,
)?;
Ok(())
}

Expand Down Expand Up @@ -469,7 +475,13 @@ impl Context {
max_width: f32,
) -> result::Result<(), SkError> {
let fill_paint = self.fill_paint()?;
self.draw_text(text, x, y, max_width, &fill_paint)?;
self.draw_text(
text.replace('\n', " ").as_str(),
x,
y,
max_width,
&fill_paint,
)?;
Ok(())
}

Expand Down

0 comments on commit 4c9ac1e

Please sign in to comment.