diff --git a/__test__/index.spec.ts b/__test__/index.spec.ts index 790c2e30..8a342c98 100755 --- a/__test__/index.spec.ts +++ b/__test__/index.spec.ts @@ -501,7 +501,7 @@ test('should render `` to an `` element', async (t) => { t.is(result.getHeight(), 900) }) -test('should get svg bbox', (t) => { +test('should get svg innerBBox', (t) => { const svg = ` @@ -524,7 +524,35 @@ test('should get svg bbox', (t) => { } }) -test('should get svg bbox(rect)', async (t) => { +test('should get svg bbox with stroke', (t) => { + const svg = ` + + + + +` + + const resvg = new Resvg(svg) + const bbox = resvg.getBBox() + t.not(bbox, undefined) + if (bbox) { + t.is(bbox.width, 116.70712280273438) + t.is(bbox.height, 90) + t.is(bbox.x, -21.707120895385742) + t.is(bbox.y, 5) + } + + const innerBBox = resvg.innerBBox() + t.not(innerBBox, undefined) + if (innerBBox) { + t.is(innerBBox.width, 125) + t.is(innerBBox.height, 93) + t.is(innerBBox.x, -30) + t.is(innerBBox.y, 5) + } +}) + +test('should get svg bbox(rect) and cropByBBox', async (t) => { const svg = ` ` diff --git a/__test__/wasm.spec.ts b/__test__/wasm.spec.ts index c02d4211..de10b0eb 100755 --- a/__test__/wasm.spec.ts +++ b/__test__/wasm.spec.ts @@ -419,7 +419,35 @@ test('should render `` to an `` element', async (t) => { t.is(result.getHeight(), 900) }) -test('should get svg bbox(rect)', async (t) => { +test('should get svg bbox with stroke', (t) => { + const svg = ` + + + + +` + + const resvg = new Resvg(svg) + const bbox = resvg.getBBox() + t.not(bbox, undefined) + if (bbox) { + t.is(bbox.width, 116.70712280273438) + t.is(bbox.height, 90) + t.is(bbox.x, -21.707120895385742) + t.is(bbox.y, 5) + } + + const innerBBox = resvg.innerBBox() + t.not(innerBBox, undefined) + if (innerBBox) { + t.is(innerBBox.width, 125) + t.is(innerBBox.height, 93) + t.is(innerBBox.x, -30) + t.is(innerBBox.y, 5) + } +}) + +test('should get svg bbox(rect) and cropByBBox', async (t) => { const svg = ` ` diff --git a/example/bbox-out.png b/example/bbox-out.png index 095da1f9..54e6d0f5 100644 Binary files a/example/bbox-out.png and b/example/bbox-out.png differ diff --git a/example/bbox.svg b/example/bbox.svg index 0e044983..e81bb563 100644 --- a/example/bbox.svg +++ b/example/bbox.svg @@ -3,5 +3,5 @@ - + diff --git a/wasm/index_bg.wasm b/wasm/index_bg.wasm index 4d07cde2..adbeb7cc 100644 Binary files a/wasm/index_bg.wasm and b/wasm/index_bg.wasm differ