-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,088 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { promises as fs } from 'fs' | ||
import { join } from 'path' | ||
|
||
import b from 'benny' | ||
|
||
const wasm = require(`../wasm`) | ||
const simd = require(`../wasm-simd`) | ||
|
||
async function run() { | ||
await wasm.initWasm(fs.readFile(join(__dirname, '../wasm/index_bg.wasm'))) | ||
await simd.initWasm(fs.readFile(join(__dirname, '../wasm-simd/index_bg.wasm'))) | ||
|
||
const svg1 = await fs.readFile(join(__dirname, '../example/text.svg')) | ||
const tiger = await fs.readFile(join(__dirname, '../__test__/tiger.svg')) | ||
const icon = await fs.readFile(join(__dirname, '../__test__/icon-alarm.svg')) | ||
|
||
await b.suite( | ||
'resize width', | ||
b.add('resvg-js(Wasm)', () => { | ||
const opts = { | ||
background: '#eeebe6', | ||
fitTo: { | ||
mode: 'width', | ||
value: 1200, | ||
}, | ||
logLevel: 'off', | ||
} | ||
const resvg = new wasm.Resvg(svg1, opts) | ||
const pngData = resvg.render() | ||
pngData.asPng() | ||
}), | ||
|
||
b.add('resvg-js(Wasm SIMD)', () => { | ||
const opts = { | ||
background: '#eeebe6', | ||
fitTo: { | ||
mode: 'width', | ||
value: 1200, | ||
}, | ||
logLevel: 'off', | ||
} | ||
const resvg = new simd.Resvg(svg1, opts) | ||
const pngData = resvg.render() | ||
pngData.asPng() | ||
}), | ||
|
||
b.cycle(), | ||
b.complete(), | ||
) | ||
|
||
await b.suite( | ||
'resize icon width', | ||
b.add('resvg-js(Wasm)', () => { | ||
const opts = { | ||
fitTo: { | ||
mode: 'width', | ||
value: 386, | ||
}, | ||
logLevel: 'off', | ||
} | ||
const resvg = new wasm.Resvg(icon, opts) | ||
const pngData = resvg.render() | ||
pngData.asPng() | ||
}), | ||
|
||
b.add('resvg-js(Wasm SIMD)', () => { | ||
const opts = { | ||
fitTo: { | ||
mode: 'width', | ||
value: 386, | ||
}, | ||
logLevel: 'off', | ||
} | ||
const resvg = new simd.Resvg(icon, opts) | ||
const pngData = resvg.render() | ||
pngData.asPng() | ||
}), | ||
|
||
b.cycle(), | ||
b.complete(), | ||
) | ||
|
||
await b.suite( | ||
'default options and no text', | ||
b.add('resvg-js(Wasm)', () => { | ||
const opts = { | ||
logLevel: 'off', | ||
} | ||
const resvg = new wasm.Resvg(tiger, opts) | ||
const pngData = resvg.render() | ||
pngData.asPng() | ||
}), | ||
|
||
b.add('resvg-js(Wasm SIMD)', () => { | ||
const opts = { | ||
logLevel: 'off', | ||
} | ||
const resvg = new simd.Resvg(tiger, opts) | ||
const pngData = resvg.render() | ||
pngData.asPng() | ||
}), | ||
|
||
b.cycle(), | ||
b.complete(), | ||
) | ||
} | ||
|
||
run().catch((e) => { | ||
console.error(e) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Generated by dts-bundle-generator v6.12.0 | ||
|
||
declare class BBox { | ||
free(): void; | ||
/** | ||
*/ | ||
height: number; | ||
/** | ||
*/ | ||
width: number; | ||
/** | ||
*/ | ||
x: number; | ||
/** | ||
*/ | ||
y: number; | ||
} | ||
declare class RenderedImage { | ||
free(): void; | ||
/** | ||
* Write the image data to Uint8Array | ||
* @returns {Uint8Array} | ||
*/ | ||
asPng(): Uint8Array; | ||
/** | ||
* Get the PNG height | ||
*/ | ||
readonly height: number; | ||
/** | ||
* Get the PNG width | ||
*/ | ||
readonly width: number; | ||
} | ||
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; | ||
export type ResvgRenderOptions = { | ||
font?: { | ||
loadSystemFonts?: boolean; | ||
fontFiles?: string[]; | ||
fontDirs?: string[]; | ||
defaultFontFamily?: string; | ||
defaultFontSize?: number; | ||
serifFamily?: string; | ||
sansSerifFamily?: string; | ||
cursiveFamily?: string; | ||
fantasyFamily?: string; | ||
monospaceFamily?: string; | ||
}; | ||
dpi?: number; | ||
languages?: string[]; | ||
shapeRendering?: 0 // optimizeSpeed | ||
| 1 // crispEdges | ||
| 2; // geometricPrecision | ||
textRendering?: 0 // optimizeSpeed | ||
| 1 // optimizeLegibility | ||
| 2; // geometricPrecision' | ||
imageRendering?: 0 // optimizeQuality | ||
| 1; // optimizeSpeed | ||
fitTo?: { | ||
mode: "original"; | ||
} | { | ||
mode: "width"; | ||
value: number; | ||
} | { | ||
mode: "height"; | ||
value: number; | ||
} | { | ||
mode: "zoom"; | ||
value: number; | ||
}; | ||
background?: string; // Support CSS3 color, e.g. rgba(255, 255, 255, .8) | ||
crop?: { | ||
left: number; | ||
top: number; | ||
right?: number; | ||
bottom?: number; | ||
}; | ||
logLevel?: "off" | "error" | "warn" | "info" | "debug" | "trace"; | ||
}; | ||
/** | ||
* Initialize Wasm module | ||
* @param module_or_path WebAssembly Module or .wasm url | ||
* | ||
*/ | ||
export declare const initWasm: (module_or_path: Promise<InitInput> | InitInput) => Promise<void>; | ||
export declare const Resvg: { | ||
new (svg: Uint8Array | string, options?: ResvgRenderOptions): { | ||
free(): void; | ||
render(): RenderedImage; | ||
toString(): string; | ||
innerBBox(): BBox | undefined; | ||
getBBox(): BBox | undefined; | ||
cropByBBox(bbox: BBox): void; | ||
imagesToResolve(): any[]; | ||
resolveImage(href: string, buffer: Uint8Array): void; | ||
readonly height: number; | ||
readonly width: number; | ||
}; | ||
}; | ||
|
||
export {}; |
Oops, something went wrong.