emf-converter 4.28.0 → 4.29.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 +1 -1
- package/dist/lite.d.mts +127 -2
- package/dist/lite.d.ts +127 -2
- package/dist/lite.js +50 -1
- package/dist/lite.mjs +50 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -247,7 +247,7 @@ import { convertMetafileToDataUrl } from 'emf-converter/lite';
|
|
|
247
247
|
const png = await convertMetafileToDataUrl(buffer, { fontFamilyMap: { 'MS Mincho': 'Noto Serif JP' } });
|
|
248
248
|
```
|
|
249
249
|
|
|
250
|
-
It is about 425 KB minified (157 KB gzipped), against about 2.4 MB unminified (850 KB gzipped) for the full browser build. It exports `convertMetafileToDataUrl`, `convertMetafileToImageData` and `DEFAULT_DPI_SCALE`, takes the same options except `fonts` and `fontSmoothing`, and replays every record the full build does. It leaves out:
|
|
250
|
+
It is about 425 KB minified (157 KB gzipped), against about 2.4 MB unminified (850 KB gzipped) for the full browser build. It exports `convertMetafileToDataUrl`, `convertMetafileToImageData`, `getMetafileInfo` and `DEFAULT_DPI_SCALE`, takes the same options except `fonts` and `fontSmoothing`, and replays every record the full build does. It leaves out:
|
|
251
251
|
|
|
252
252
|
- JPEG, WebP, SVG and PDF output.
|
|
253
253
|
- The TrueType engine, so text is always drawn with the canvas's `fillText`. Use `fontFamilyMap` to choose installed or web fonts.
|
package/dist/lite.d.mts
CHANGED
|
@@ -181,6 +181,131 @@ interface RgbaImage {
|
|
|
181
181
|
*/
|
|
182
182
|
declare const DEFAULT_DPI_SCALE = 1;
|
|
183
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Metafile inspection: what a file contains, without rendering it.
|
|
186
|
+
*
|
|
187
|
+
* {@link getMetafileInfo} reads the headers and walks the record stream once
|
|
188
|
+
* (plus the EMF+ object records), reusing the converter's own header parsers
|
|
189
|
+
* and size helpers, and reports the format, the pixel size
|
|
190
|
+
* `convertMetafileToDataUrl` would produce at default options, a record
|
|
191
|
+
* histogram, the font faces the drawing names, and the embedded images.
|
|
192
|
+
*
|
|
193
|
+
* The font list is the most useful part: text only matches Windows when the
|
|
194
|
+
* fonts a file names are passed as the `fonts` conversion option.
|
|
195
|
+
*
|
|
196
|
+
* @module metafile-info
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
/** A rectangle as the file's header records it. */
|
|
200
|
+
interface MetafileRect {
|
|
201
|
+
left: number;
|
|
202
|
+
top: number;
|
|
203
|
+
right: number;
|
|
204
|
+
bottom: number;
|
|
205
|
+
}
|
|
206
|
+
/** One font face a metafile names. */
|
|
207
|
+
interface MetafileFont {
|
|
208
|
+
/** The face name as written in the file (the first spelling when several differ only in case). */
|
|
209
|
+
name: string;
|
|
210
|
+
/** `true` when a GDI font record (EMF `EMR_EXTCREATEFONTINDIRECTW`, WMF `META_CREATEFONTINDIRECT`) names it. */
|
|
211
|
+
gdi: boolean;
|
|
212
|
+
/** `true` when an EMF+ font object names it. */
|
|
213
|
+
emfPlus: boolean;
|
|
214
|
+
}
|
|
215
|
+
/** The result of {@link getMetafileInfo}. */
|
|
216
|
+
interface MetafileInfo {
|
|
217
|
+
/**
|
|
218
|
+
* `'emf'` (plain GDI records), `'emf+'` (EMF+ only: the GDI records are a
|
|
219
|
+
* stub), `'emf+dual'` (EMF+ with a GDI fallback) or `'wmf'`.
|
|
220
|
+
*/
|
|
221
|
+
format: 'emf' | 'emf+' | 'emf+dual' | 'wmf';
|
|
222
|
+
/** WMF only: `true` when the file has an Aldus placeable header. */
|
|
223
|
+
placeable?: boolean;
|
|
224
|
+
/** WMF only: `true` when the file carries its original EMF in `META_ESCAPE` comments, which the converter plays instead of the WMF records. */
|
|
225
|
+
playsEmbeddedEmf?: boolean;
|
|
226
|
+
/** EMF: the header's device-pixel bounds (inclusive). WMF: its bounding box in logical units. */
|
|
227
|
+
bounds: MetafileRect;
|
|
228
|
+
/** EMF: the header's picture frame in .01 mm. Placeable WMF: the bounding box converted to .01 mm. Otherwise `null`. */
|
|
229
|
+
frame: MetafileRect | null;
|
|
230
|
+
/** WMF only: logical units per inch from the placeable header (96 when absent). */
|
|
231
|
+
unitsPerInch?: number;
|
|
232
|
+
/** EMF only: the reference device's size in pixels (`szlDevice`), or `null` when the header's is unusable. */
|
|
233
|
+
device: {
|
|
234
|
+
width: number;
|
|
235
|
+
height: number;
|
|
236
|
+
} | null;
|
|
237
|
+
/** EMF only: the reference device's size in millimetres (`szlMillimeters`), or `null`. */
|
|
238
|
+
deviceMm: {
|
|
239
|
+
width: number;
|
|
240
|
+
height: number;
|
|
241
|
+
} | null;
|
|
242
|
+
/** Reference device resolution: EMF `szlDevice` / `szlMillimeters` (96 when unusable), WMF the converter's 96. */
|
|
243
|
+
dpi: {
|
|
244
|
+
x: number;
|
|
245
|
+
y: number;
|
|
246
|
+
};
|
|
247
|
+
/** Pixel width `convertMetafileToDataUrl` produces at default options. */
|
|
248
|
+
width: number;
|
|
249
|
+
/** Pixel height `convertMetafileToDataUrl` produces at default options. */
|
|
250
|
+
height: number;
|
|
251
|
+
/** Records read from the stream (EMF: including the header and EOF; WMF: excluding the header and EOF). */
|
|
252
|
+
recordCount: number;
|
|
253
|
+
/** Records read from the EMF+ streams inside `EMR_COMMENT` records. */
|
|
254
|
+
emfPlusRecordCount: number;
|
|
255
|
+
/** Record count by name (`EMR_*`, `META_*`, `EMFPLUS_*`; `UNKNOWN_0x..` for unnamed types). */
|
|
256
|
+
recordTypes: Record<string, number>;
|
|
257
|
+
/** The distinct font faces the drawing names (declared fonts; not every one is necessarily used). */
|
|
258
|
+
fonts: MetafileFont[];
|
|
259
|
+
/** `true` when any text-drawing record is present. */
|
|
260
|
+
hasText: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Embedded images. `count` includes DIBs (`image/bmp`, or the JPEG/PNG
|
|
263
|
+
* a DIB can carry), EMF+ image objects and nested metafiles
|
|
264
|
+
* (`image/emf`, `image/wmf`); `mimeTypes` lists the distinct types.
|
|
265
|
+
*/
|
|
266
|
+
images: {
|
|
267
|
+
count: number;
|
|
268
|
+
mimeTypes: string[];
|
|
269
|
+
};
|
|
270
|
+
/** Nested metafiles among `images`. */
|
|
271
|
+
embeddedMetafiles: number;
|
|
272
|
+
/** EMF header description (application and document names, NUL separators shown as newlines), or `null`. */
|
|
273
|
+
description: string | null;
|
|
274
|
+
/** `true` when the record limit was hit or the stream ends in a damaged record. */
|
|
275
|
+
truncated: boolean;
|
|
276
|
+
}
|
|
277
|
+
/** Options for {@link getMetafileInfo}. */
|
|
278
|
+
interface MetafileInfoOptions {
|
|
279
|
+
/** Record limit per stream, as for the converters. Defaults as theirs do. */
|
|
280
|
+
maxRecords?: number;
|
|
281
|
+
/** ANSI code page for WMF face names, as `ansiCodePage` for the converters. Default 1252. */
|
|
282
|
+
ansiCodePage?: number;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Inspects an EMF, EMF+ or WMF buffer without rendering it.
|
|
286
|
+
*
|
|
287
|
+
* Returns the format, the header geometry, the pixel size
|
|
288
|
+
* `convertMetafileToDataUrl` produces at default options (computed with the
|
|
289
|
+
* converter's own size helper, so the two agree), a histogram of record
|
|
290
|
+
* names, the font faces the drawing names, whether it draws text, and its
|
|
291
|
+
* embedded images. `fonts` shows which font files to pass to the converters
|
|
292
|
+
* as their `fonts` option: text only matches Windows when they are supplied.
|
|
293
|
+
*
|
|
294
|
+
* Never throws. Returns `null` for a buffer that is not a metafile (or whose
|
|
295
|
+
* bounds the converter would refuse). A truncated or damaged file is
|
|
296
|
+
* reported as far as it can be read, with `truncated: true`.
|
|
297
|
+
*
|
|
298
|
+
* Limits: the font list is what the file declares (a declared font may never
|
|
299
|
+
* be selected); fonts inside nested EMF+ metafiles are included, those in
|
|
300
|
+
* nested WMFs are not; images in a dual-mode file are counted in each
|
|
301
|
+
* record stream that has them.
|
|
302
|
+
*
|
|
303
|
+
* @param input - The metafile bytes (`ArrayBuffer`, typed array / `Buffer` or `Blob`; gzip is inflated).
|
|
304
|
+
* @param options - Optional {@link MetafileInfoOptions}.
|
|
305
|
+
* @returns A {@link MetafileInfo}, or `null` when the buffer is not a metafile.
|
|
306
|
+
*/
|
|
307
|
+
declare function getMetafileInfo(input: MetafileInput, options?: MetafileInfoOptions): Promise<MetafileInfo | null>;
|
|
308
|
+
|
|
184
309
|
/**
|
|
185
310
|
* `emf-converter/lite`: a small browser build that renders EMF/WMF (with
|
|
186
311
|
* EMF+) to PNG through the page's canvas, for apps that only need a raster
|
|
@@ -211,5 +336,5 @@ declare function convertMetafileToDataUrl(input: MetafileInput, options?: LiteCo
|
|
|
211
336
|
/** Renders an EMF or WMF file to straight RGBA pixels, as the full build's `convertMetafileToImageData` does. */
|
|
212
337
|
declare function convertMetafileToImageData(input: MetafileInput, options?: LiteConvertOptions): Promise<RgbaImage | null>;
|
|
213
338
|
|
|
214
|
-
export { DEFAULT_DPI_SCALE, convertMetafileToDataUrl, convertMetafileToImageData };
|
|
215
|
-
export type { LiteConvertOptions, MetafileInput, RgbaImage };
|
|
339
|
+
export { DEFAULT_DPI_SCALE, convertMetafileToDataUrl, convertMetafileToImageData, getMetafileInfo };
|
|
340
|
+
export type { LiteConvertOptions, MetafileFont, MetafileInfo, MetafileInfoOptions, MetafileInput, MetafileRect, RgbaImage };
|
package/dist/lite.d.ts
CHANGED
|
@@ -181,6 +181,131 @@ interface RgbaImage {
|
|
|
181
181
|
*/
|
|
182
182
|
declare const DEFAULT_DPI_SCALE = 1;
|
|
183
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Metafile inspection: what a file contains, without rendering it.
|
|
186
|
+
*
|
|
187
|
+
* {@link getMetafileInfo} reads the headers and walks the record stream once
|
|
188
|
+
* (plus the EMF+ object records), reusing the converter's own header parsers
|
|
189
|
+
* and size helpers, and reports the format, the pixel size
|
|
190
|
+
* `convertMetafileToDataUrl` would produce at default options, a record
|
|
191
|
+
* histogram, the font faces the drawing names, and the embedded images.
|
|
192
|
+
*
|
|
193
|
+
* The font list is the most useful part: text only matches Windows when the
|
|
194
|
+
* fonts a file names are passed as the `fonts` conversion option.
|
|
195
|
+
*
|
|
196
|
+
* @module metafile-info
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
/** A rectangle as the file's header records it. */
|
|
200
|
+
interface MetafileRect {
|
|
201
|
+
left: number;
|
|
202
|
+
top: number;
|
|
203
|
+
right: number;
|
|
204
|
+
bottom: number;
|
|
205
|
+
}
|
|
206
|
+
/** One font face a metafile names. */
|
|
207
|
+
interface MetafileFont {
|
|
208
|
+
/** The face name as written in the file (the first spelling when several differ only in case). */
|
|
209
|
+
name: string;
|
|
210
|
+
/** `true` when a GDI font record (EMF `EMR_EXTCREATEFONTINDIRECTW`, WMF `META_CREATEFONTINDIRECT`) names it. */
|
|
211
|
+
gdi: boolean;
|
|
212
|
+
/** `true` when an EMF+ font object names it. */
|
|
213
|
+
emfPlus: boolean;
|
|
214
|
+
}
|
|
215
|
+
/** The result of {@link getMetafileInfo}. */
|
|
216
|
+
interface MetafileInfo {
|
|
217
|
+
/**
|
|
218
|
+
* `'emf'` (plain GDI records), `'emf+'` (EMF+ only: the GDI records are a
|
|
219
|
+
* stub), `'emf+dual'` (EMF+ with a GDI fallback) or `'wmf'`.
|
|
220
|
+
*/
|
|
221
|
+
format: 'emf' | 'emf+' | 'emf+dual' | 'wmf';
|
|
222
|
+
/** WMF only: `true` when the file has an Aldus placeable header. */
|
|
223
|
+
placeable?: boolean;
|
|
224
|
+
/** WMF only: `true` when the file carries its original EMF in `META_ESCAPE` comments, which the converter plays instead of the WMF records. */
|
|
225
|
+
playsEmbeddedEmf?: boolean;
|
|
226
|
+
/** EMF: the header's device-pixel bounds (inclusive). WMF: its bounding box in logical units. */
|
|
227
|
+
bounds: MetafileRect;
|
|
228
|
+
/** EMF: the header's picture frame in .01 mm. Placeable WMF: the bounding box converted to .01 mm. Otherwise `null`. */
|
|
229
|
+
frame: MetafileRect | null;
|
|
230
|
+
/** WMF only: logical units per inch from the placeable header (96 when absent). */
|
|
231
|
+
unitsPerInch?: number;
|
|
232
|
+
/** EMF only: the reference device's size in pixels (`szlDevice`), or `null` when the header's is unusable. */
|
|
233
|
+
device: {
|
|
234
|
+
width: number;
|
|
235
|
+
height: number;
|
|
236
|
+
} | null;
|
|
237
|
+
/** EMF only: the reference device's size in millimetres (`szlMillimeters`), or `null`. */
|
|
238
|
+
deviceMm: {
|
|
239
|
+
width: number;
|
|
240
|
+
height: number;
|
|
241
|
+
} | null;
|
|
242
|
+
/** Reference device resolution: EMF `szlDevice` / `szlMillimeters` (96 when unusable), WMF the converter's 96. */
|
|
243
|
+
dpi: {
|
|
244
|
+
x: number;
|
|
245
|
+
y: number;
|
|
246
|
+
};
|
|
247
|
+
/** Pixel width `convertMetafileToDataUrl` produces at default options. */
|
|
248
|
+
width: number;
|
|
249
|
+
/** Pixel height `convertMetafileToDataUrl` produces at default options. */
|
|
250
|
+
height: number;
|
|
251
|
+
/** Records read from the stream (EMF: including the header and EOF; WMF: excluding the header and EOF). */
|
|
252
|
+
recordCount: number;
|
|
253
|
+
/** Records read from the EMF+ streams inside `EMR_COMMENT` records. */
|
|
254
|
+
emfPlusRecordCount: number;
|
|
255
|
+
/** Record count by name (`EMR_*`, `META_*`, `EMFPLUS_*`; `UNKNOWN_0x..` for unnamed types). */
|
|
256
|
+
recordTypes: Record<string, number>;
|
|
257
|
+
/** The distinct font faces the drawing names (declared fonts; not every one is necessarily used). */
|
|
258
|
+
fonts: MetafileFont[];
|
|
259
|
+
/** `true` when any text-drawing record is present. */
|
|
260
|
+
hasText: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Embedded images. `count` includes DIBs (`image/bmp`, or the JPEG/PNG
|
|
263
|
+
* a DIB can carry), EMF+ image objects and nested metafiles
|
|
264
|
+
* (`image/emf`, `image/wmf`); `mimeTypes` lists the distinct types.
|
|
265
|
+
*/
|
|
266
|
+
images: {
|
|
267
|
+
count: number;
|
|
268
|
+
mimeTypes: string[];
|
|
269
|
+
};
|
|
270
|
+
/** Nested metafiles among `images`. */
|
|
271
|
+
embeddedMetafiles: number;
|
|
272
|
+
/** EMF header description (application and document names, NUL separators shown as newlines), or `null`. */
|
|
273
|
+
description: string | null;
|
|
274
|
+
/** `true` when the record limit was hit or the stream ends in a damaged record. */
|
|
275
|
+
truncated: boolean;
|
|
276
|
+
}
|
|
277
|
+
/** Options for {@link getMetafileInfo}. */
|
|
278
|
+
interface MetafileInfoOptions {
|
|
279
|
+
/** Record limit per stream, as for the converters. Defaults as theirs do. */
|
|
280
|
+
maxRecords?: number;
|
|
281
|
+
/** ANSI code page for WMF face names, as `ansiCodePage` for the converters. Default 1252. */
|
|
282
|
+
ansiCodePage?: number;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Inspects an EMF, EMF+ or WMF buffer without rendering it.
|
|
286
|
+
*
|
|
287
|
+
* Returns the format, the header geometry, the pixel size
|
|
288
|
+
* `convertMetafileToDataUrl` produces at default options (computed with the
|
|
289
|
+
* converter's own size helper, so the two agree), a histogram of record
|
|
290
|
+
* names, the font faces the drawing names, whether it draws text, and its
|
|
291
|
+
* embedded images. `fonts` shows which font files to pass to the converters
|
|
292
|
+
* as their `fonts` option: text only matches Windows when they are supplied.
|
|
293
|
+
*
|
|
294
|
+
* Never throws. Returns `null` for a buffer that is not a metafile (or whose
|
|
295
|
+
* bounds the converter would refuse). A truncated or damaged file is
|
|
296
|
+
* reported as far as it can be read, with `truncated: true`.
|
|
297
|
+
*
|
|
298
|
+
* Limits: the font list is what the file declares (a declared font may never
|
|
299
|
+
* be selected); fonts inside nested EMF+ metafiles are included, those in
|
|
300
|
+
* nested WMFs are not; images in a dual-mode file are counted in each
|
|
301
|
+
* record stream that has them.
|
|
302
|
+
*
|
|
303
|
+
* @param input - The metafile bytes (`ArrayBuffer`, typed array / `Buffer` or `Blob`; gzip is inflated).
|
|
304
|
+
* @param options - Optional {@link MetafileInfoOptions}.
|
|
305
|
+
* @returns A {@link MetafileInfo}, or `null` when the buffer is not a metafile.
|
|
306
|
+
*/
|
|
307
|
+
declare function getMetafileInfo(input: MetafileInput, options?: MetafileInfoOptions): Promise<MetafileInfo | null>;
|
|
308
|
+
|
|
184
309
|
/**
|
|
185
310
|
* `emf-converter/lite`: a small browser build that renders EMF/WMF (with
|
|
186
311
|
* EMF+) to PNG through the page's canvas, for apps that only need a raster
|
|
@@ -211,5 +336,5 @@ declare function convertMetafileToDataUrl(input: MetafileInput, options?: LiteCo
|
|
|
211
336
|
/** Renders an EMF or WMF file to straight RGBA pixels, as the full build's `convertMetafileToImageData` does. */
|
|
212
337
|
declare function convertMetafileToImageData(input: MetafileInput, options?: LiteConvertOptions): Promise<RgbaImage | null>;
|
|
213
338
|
|
|
214
|
-
export { DEFAULT_DPI_SCALE, convertMetafileToDataUrl, convertMetafileToImageData };
|
|
215
|
-
export type { LiteConvertOptions, MetafileInput, RgbaImage };
|
|
339
|
+
export { DEFAULT_DPI_SCALE, convertMetafileToDataUrl, convertMetafileToImageData, getMetafileInfo };
|
|
340
|
+
export type { LiteConvertOptions, MetafileFont, MetafileInfo, MetafileInfoOptions, MetafileInput, MetafileRect, RgbaImage };
|