Skip to content

Commit

Permalink
fix: negative letter spacing (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Apr 17, 2024
1 parent ec40123 commit 11ab7e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Binary file added __test__/snapshots/negative-letter-spacing.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions __test__/text.spec.ts
Expand Up @@ -119,6 +119,19 @@ test('letter-spacing', async (t) => {
await snapshotImage(t, { canvas, ctx })
})

test('negative-letter-spacing', async (t) => {
const canvas = createCanvas(800, 800)
const ctx = canvas.getContext('2d')!
ctx.font = '30px Iosevka Slab'

// Default letter spacing
ctx.fillText(`Hello world (default: ${ctx.letterSpacing})`, 10, 40)

ctx.letterSpacing = '-5px'
ctx.fillText(`Hello world (${ctx.letterSpacing})`, 10, 90)
await snapshotImage(t, { canvas, ctx })
})

test('word-spacing', async (t) => {
const canvas = createCanvas(800, 800)
const ctx = canvas.getContext('2d')!
Expand Down
2 changes: 1 addition & 1 deletion src/ctx.rs
Expand Up @@ -35,7 +35,7 @@ use crate::{
};

static CSS_SIZE_REGEXP: Lazy<Regex> =
Lazy::new(|| Regex::new(r#"([\d\.]+)(%|px|pt|pc|in|cm|mm|%|em|ex|ch|rem|q)?\s*"#).unwrap());
Lazy::new(|| Regex::new(r#"(-?[\d\.]+)(%|px|pt|pc|in|cm|mm|%|em|ex|ch|rem|q)?\s*"#).unwrap());

impl From<SkError> for Error {
fn from(err: SkError) -> Error {
Expand Down

0 comments on commit 11ab7e2

Please sign in to comment.