emf-converter 3.4.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -77
- package/dist/index.d.mts +134 -19
- package/dist/index.d.ts +134 -19
- package/dist/index.js +25732 -8350
- package/dist/index.mjs +25732 -8351
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -136,15 +136,53 @@ interface EmfConvertOptions {
|
|
|
136
136
|
*/
|
|
137
137
|
fontFamilyMap?: Record<string, string>;
|
|
138
138
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
139
|
+
* Smooth shape edges instead of reproducing Windows' own rasterisation.
|
|
140
|
+
*
|
|
141
|
+
* PNG output defaults to `false`: plain-GDI vector shapes (Rectangle,
|
|
142
|
+
* Ellipse, RoundRect, Polygon, Polyline, arcs, bracketed paths, wide
|
|
143
|
+
* pens) are rasterised the way Windows GDI does, with its 28.4
|
|
144
|
+
* fixed-point geometry, fill rule, line algorithm and Bezier flattening,
|
|
145
|
+
* and EMF+ fills, strokes and clips follow the GDI+ `SmoothingMode` the
|
|
146
|
+
* file records (None, Default and HighSpeed aliased on GDI+'s pixel grid,
|
|
147
|
+
* AntiAlias and HighQuality with GDI+'s 8 x 4-sample antialiasing), so the
|
|
148
|
+
* PNG matches what Windows paints pixel for pixel.
|
|
149
|
+
*
|
|
150
|
+
* `true` draws every edge with Canvas's own antialiasing instead (still
|
|
151
|
+
* with GDI's geometry, pen widths, caps, joins and dash patterns), which
|
|
152
|
+
* looks smoother than Windows, especially for files recorded without
|
|
153
|
+
* GDI+ antialiasing.
|
|
154
|
+
*
|
|
155
|
+
* SVG output defaults to smooth vector edges (an SVG is meant to scale);
|
|
156
|
+
* `false` there embeds Windows' aliased shape pixels as image patches.
|
|
146
157
|
*/
|
|
147
158
|
gdiAntialias?: boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Font files to render GDI and WMF text with, exactly as Windows GDI
|
|
161
|
+
* does: TrueType `.ttf` / `.ttc` and raster `.fon` / `.fnt` bytes
|
|
162
|
+
* (`loadSystemFonts()` reads the installed ones in Node.js). The
|
|
163
|
+
* LOGFONT is realised against these files (face, weight, slant,
|
|
164
|
+
* `lfHeight`/`lfWidth`, charset fallback), each TrueType glyph is grid-fitted by the font's own TrueType
|
|
165
|
+
* instructions and scan-converted with TrueType dropout control
|
|
166
|
+
* (non-antialiased, 4x4 grayscale or ClearType per the LOGFONT's
|
|
167
|
+
* `lfQuality`), and glyphs are placed on GDI's integer device grid with
|
|
168
|
+
* GDI's own advance widths, cell metrics, underline and strike-out.
|
|
169
|
+
* Raster faces (MS Sans Serif, Helv, System, Terminal, ...) are drawn
|
|
170
|
+
* from their bitmaps at the size and whole-number stretch GDI picks.
|
|
171
|
+
* Supply the fonts the metafile names (for Windows-authored files, the
|
|
172
|
+
* matching files from `C:\Windows\Fonts`); a face that is missing is
|
|
173
|
+
* substituted the way GDI's font mapper would (by pitch and family),
|
|
174
|
+
* and without this option text is drawn with the canvas font engine.
|
|
175
|
+
* Ignored by SVG output, which keeps text as `<text>` but takes its
|
|
176
|
+
* per-glyph positions and metrics from these fonts.
|
|
177
|
+
*/
|
|
178
|
+
fonts?: Array<ArrayBuffer | ArrayBufferView>;
|
|
179
|
+
/**
|
|
180
|
+
* Windows' system-wide font smoothing, which GDI applies to fonts that
|
|
181
|
+
* ask for `DEFAULT_QUALITY`, `DRAFT_QUALITY` or `PROOF_QUALITY` (most
|
|
182
|
+
* metafiles): `'cleartype'` (Windows' default), `'gray'` (standard
|
|
183
|
+
* antialiasing) or `'mono'` (smoothing off). Only used with `fonts`.
|
|
184
|
+
*/
|
|
185
|
+
fontSmoothing?: 'cleartype' | 'gray' | 'mono';
|
|
148
186
|
}
|
|
149
187
|
/**
|
|
150
188
|
* Options for the SVG outputs ({@link convertMetafileToSvg} and friends).
|
|
@@ -156,14 +194,34 @@ interface EmfConvertOptions {
|
|
|
156
194
|
interface SvgConvertOptions extends EmfConvertOptions {
|
|
157
195
|
/**
|
|
158
196
|
* Evaluate raster operations that read the destination (exact ROP3 blits,
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
197
|
+
* bitwise ROP2, pattern-brush fills combined through ROP2, and
|
|
198
|
+
* `gdiAntialias: false` shapes) against a hidden raster mirror of the
|
|
199
|
+
* drawing, and embed the pixels they change as image patches. The mirror
|
|
200
|
+
* is the canvas backend when one exists (browser/worker canvas, or
|
|
201
|
+
* `@napi-rs/canvas` in Node.js) and the built-in pure-JavaScript
|
|
202
|
+
* rasteriser otherwise, so this needs no canvas. The built-in mirror
|
|
203
|
+
* cannot draw glyphs: where a raster operation reads pixels under text,
|
|
204
|
+
* every pixel whose result does not depend on the glyphs stays exact and
|
|
205
|
+
* the rest is handed to the SVG renderer as a blend-mode layer (exact for
|
|
206
|
+
* inversion and for masks whose channels are all 0 or 255). With `false`,
|
|
207
|
+
* no mirror is kept and those operations fall back to SVG blend modes
|
|
163
208
|
* (`mix-blend-mode`), which are exact for the common mask ROPs on
|
|
164
209
|
* black/white masks and approximate otherwise. Default `true`.
|
|
165
210
|
*/
|
|
166
211
|
exactRasterOps?: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* How EMF+ `DrawImage` bitmaps are scaled. `'renderer'` (the default)
|
|
214
|
+
* embeds the original image and lets the SVG renderer scale it with its
|
|
215
|
+
* own smoothing, which stays sharp at any display size. `'exact'` bakes
|
|
216
|
+
* each draw at device resolution with the GDI+-matching resampler (the
|
|
217
|
+
* PNG output's `InterpolationMode`/`PixelOffsetMode` model), so the SVG
|
|
218
|
+
* shows what GDI+ painted pixel for pixel at its nominal size. PNG and
|
|
219
|
+
* BMP images are decoded in pure JavaScript; JPEG, GIF and other formats
|
|
220
|
+
* need a canvas backend to decode and otherwise keep `'renderer'`
|
|
221
|
+
* scaling, as do draws GDI+ scales with a filter the resampler does not
|
|
222
|
+
* model (bicubic, high-quality).
|
|
223
|
+
*/
|
|
224
|
+
imageResampling?: 'renderer' | 'exact';
|
|
167
225
|
/**
|
|
168
226
|
* Emit `width`/`height` attributes on the root `<svg>` (the `viewBox` is
|
|
169
227
|
* always emitted). Set `false` for a fluid SVG that fills its container.
|
|
@@ -191,8 +249,13 @@ interface SvgConvertOptions extends EmfConvertOptions {
|
|
|
191
249
|
* - The buffer matches neither a valid EMF header nor a valid WMF header.
|
|
192
250
|
* - The logical bounds are zero-sized or negative.
|
|
193
251
|
* - No canvas API is available (browser/worker canvas, or the optional
|
|
194
|
-
* `@napi-rs/canvas` package in plain Node.js)
|
|
195
|
-
*
|
|
252
|
+
* `@napi-rs/canvas` package in plain Node.js) AND the drawing contains
|
|
253
|
+
* text or an image format only a canvas can decode (JPEG, GIF, ...).
|
|
254
|
+
* Without a canvas the built-in pure-JavaScript rasteriser renders
|
|
255
|
+
* everything else (vectors, clipping, gradients, bitmaps, PNG/BMP
|
|
256
|
+
* images, every raster operation), but it has no font engine, so rather
|
|
257
|
+
* than return an image silently missing its text it returns `null`. SVG
|
|
258
|
+
* output ({@link convertMetafileToSvg}) needs no canvas at all.
|
|
196
259
|
*
|
|
197
260
|
* @param buffer - The raw EMF or WMF file bytes.
|
|
198
261
|
* @param options - Optional {@link EmfConvertOptions} controlling output size,
|
|
@@ -201,6 +264,7 @@ interface SvgConvertOptions extends EmfConvertOptions {
|
|
|
201
264
|
* @returns A `data:image/png;base64,...` string, or `null` on failure.
|
|
202
265
|
*/
|
|
203
266
|
declare function convertMetafileToDataUrl(buffer: ArrayBuffer, options?: EmfConvertOptions, recursionDepth?: number): Promise<string | null>;
|
|
267
|
+
|
|
204
268
|
/**
|
|
205
269
|
* Converts an EMF or WMF buffer (format auto-detected) into an SVG document
|
|
206
270
|
* tree, the common source for every SVG output form: serialise it with
|
|
@@ -208,11 +272,12 @@ declare function convertMetafileToDataUrl(buffer: ArrayBuffer, options?: EmfConv
|
|
|
208
272
|
* with {@link svgTreeToReact}, or generate component source with
|
|
209
273
|
* {@link svgTreeToJsx}.
|
|
210
274
|
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
275
|
+
* This needs no canvas implementation: vectors, text, gradients, clipping,
|
|
276
|
+
* and bitmaps are all recorded in pure JavaScript, and destination-reading
|
|
277
|
+
* raster operations are evaluated exactly against a raster mirror of the
|
|
278
|
+
* drawing (see {@link SvgConvertOptions.exactRasterOps}), which is the
|
|
279
|
+
* canvas backend when one exists (it also measures text) and the built-in
|
|
280
|
+
* pure-JavaScript rasteriser otherwise.
|
|
216
281
|
*
|
|
217
282
|
* @returns The root `<svg>` node, or `null` for an invalid/empty metafile.
|
|
218
283
|
*/
|
|
@@ -239,4 +304,54 @@ declare function convertMetafileToSvgDataUrl(buffer: ArrayBuffer, options?: SvgC
|
|
|
239
304
|
*/
|
|
240
305
|
declare const DEFAULT_DPI_SCALE = 1;
|
|
241
306
|
|
|
242
|
-
|
|
307
|
+
/**
|
|
308
|
+
* `loadSystemFonts()`: reads the operating system's installed font files
|
|
309
|
+
* (Node.js only) into buffers for the converter's `fonts` option.
|
|
310
|
+
*
|
|
311
|
+
* The Node.js modules are loaded with dynamic `import()` (and bundler
|
|
312
|
+
* ignore comments) only when the function is called, so the package stays
|
|
313
|
+
* browser-safe: nothing here is resolved or bundled for a browser build.
|
|
314
|
+
*
|
|
315
|
+
* @module load-system-fonts
|
|
316
|
+
*/
|
|
317
|
+
/** Options for {@link loadSystemFonts}. */
|
|
318
|
+
interface LoadSystemFontsOptions {
|
|
319
|
+
/**
|
|
320
|
+
* Directories to scan instead of the platform defaults (Windows:
|
|
321
|
+
* `%WINDIR%\Fonts` and the per-user `%LOCALAPPDATA%\Microsoft\Windows\Fonts`;
|
|
322
|
+
* Linux: `/usr/share/fonts`, `/usr/local/share/fonts`, `~/.fonts`,
|
|
323
|
+
* `~/.local/share/fonts`; macOS: `/Library/Fonts`,
|
|
324
|
+
* `/System/Library/Fonts`, `~/Library/Fonts`). Missing directories are
|
|
325
|
+
* skipped.
|
|
326
|
+
*/
|
|
327
|
+
dirs?: string[];
|
|
328
|
+
/**
|
|
329
|
+
* Keeps only the files this returns true for, given the full path and
|
|
330
|
+
* the lower-case file name (for example to load just the faces a
|
|
331
|
+
* metafile names: `(p, n) => /^(arial|times|cour)/.test(n)`).
|
|
332
|
+
*/
|
|
333
|
+
filter?: (path: string, name: string) => boolean;
|
|
334
|
+
/** Subdirectory depth to descend (default 4; 0 scans only the directories themselves). */
|
|
335
|
+
maxDepth?: number;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Reads the installed TrueType (`.ttf`, `.ttc`) and raster (`.fon`,
|
|
339
|
+
* `.fnt`) font files, for `convertMetafileToDataUrl(data, { fonts })`
|
|
340
|
+
* and the SVG converters. Node.js only: in a browser (or any runtime
|
|
341
|
+
* without `process.versions.node`) it resolves to an empty array.
|
|
342
|
+
*
|
|
343
|
+
* Reading every installed font can take a few hundred megabytes on
|
|
344
|
+
* Windows; pass `filter` to load only what your metafiles use. Load once
|
|
345
|
+
* and reuse the array across conversions.
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```ts
|
|
349
|
+
* import { convertMetafileToDataUrl, loadSystemFonts } from 'emf-converter';
|
|
350
|
+
*
|
|
351
|
+
* const fonts = await loadSystemFonts();
|
|
352
|
+
* const png = await convertMetafileToDataUrl(emfBytes, { fonts });
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
declare function loadSystemFonts(options?: LoadSystemFontsOptions): Promise<Uint8Array[]>;
|
|
356
|
+
|
|
357
|
+
export { type CreateElement, DEFAULT_DPI_SCALE, type EmfConvertOptions, type LoadSystemFontsOptions, type SvgConvertOptions, type SvgJsxOptions, type SvgNode, convertMetafileToDataUrl, convertMetafileToSvg, convertMetafileToSvgDataUrl, convertMetafileToSvgTree, loadSystemFonts, svgTreeToDataUrl, svgTreeToJsx, svgTreeToReact, svgTreeToString };
|