emf-converter 4.25.1 → 4.25.2

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/dist/browser.js CHANGED
@@ -43628,6 +43628,10 @@ function parseWmfHeader(view) {
43628
43628
  boundsBottom = view.getInt16(12, true);
43629
43629
  unitsPerInch = view.getUint16(14, true) || 96;
43630
43630
  headerOffset = 22;
43631
+ const isType = (at) => [1, 2].includes(view.getUint16(at, true)) && view.getUint16(at + 2, true) === 9;
43632
+ if (view.byteLength >= 24 + 18 && !isType(22) && view.getUint16(22, true) === 0 && isType(24)) {
43633
+ headerOffset = 24;
43634
+ }
43631
43635
  }
43632
43636
  if (headerOffset + 18 > view.byteLength) {
43633
43637
  return null;
@@ -56292,7 +56296,13 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56292
56296
  continue;
56293
56297
  }
56294
56298
  if (emfPlusState.dualMode && !emfPlusState.gdiPassthrough) {
56295
- if (recType !== EMR_SAVEDC && recType !== EMR_RESTOREDC) {
56299
+ if (recType === EMR_SAVEDC) {
56300
+ saveSkippedDc(rCtx);
56301
+ } else if (recType === EMR_RESTOREDC) {
56302
+ if (recSize >= 12) {
56303
+ restoreSkippedDc(rCtx, view.getInt32(dataOff, true));
56304
+ }
56305
+ } else {
56296
56306
  handleEmfGdiStateRecord(rCtx, recType, offset, dataOff, recSize);
56297
56307
  }
56298
56308
  offset += recSize;
@@ -56318,6 +56328,31 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56318
56328
  }
56319
56329
  return allDeferredImages;
56320
56330
  }
56331
+ function saveSkippedDc(rCtx) {
56332
+ rCtx.skippedDcStack ?? (rCtx.skippedDcStack = []);
56333
+ rCtx.skippedDcStack.push({
56334
+ state: cloneState(rCtx.state),
56335
+ mapping: {
56336
+ mapMode: rCtx.mapMode,
56337
+ windowOrg: { ...rCtx.windowOrg },
56338
+ windowExt: { ...rCtx.windowExt },
56339
+ viewportOrg: { ...rCtx.viewportOrg },
56340
+ viewportExt: { ...rCtx.viewportExt },
56341
+ useMappingMode: rCtx.useMappingMode
56342
+ }
56343
+ });
56344
+ }
56345
+ function restoreSkippedDc(rCtx, level) {
56346
+ const stack = rCtx.skippedDcStack ?? [];
56347
+ const at = level < 0 ? stack.length + level : level - 1;
56348
+ if (at < 0 || at >= stack.length) {
56349
+ return;
56350
+ }
56351
+ const saved = stack[at];
56352
+ stack.length = at;
56353
+ Object.assign(rCtx.state, saved.state);
56354
+ Object.assign(rCtx, saved.mapping);
56355
+ }
56321
56356
  function replayNestedEmf(bytes, ctx, canvasW, canvasH, toCanvas, options2) {
56322
56357
  const view = new DataView(bytes);
56323
56358
  const header = parseEmfHeader(view);
package/dist/browser.mjs CHANGED
@@ -43626,6 +43626,10 @@ function parseWmfHeader(view) {
43626
43626
  boundsBottom = view.getInt16(12, true);
43627
43627
  unitsPerInch = view.getUint16(14, true) || 96;
43628
43628
  headerOffset = 22;
43629
+ const isType = (at) => [1, 2].includes(view.getUint16(at, true)) && view.getUint16(at + 2, true) === 9;
43630
+ if (view.byteLength >= 24 + 18 && !isType(22) && view.getUint16(22, true) === 0 && isType(24)) {
43631
+ headerOffset = 24;
43632
+ }
43629
43633
  }
43630
43634
  if (headerOffset + 18 > view.byteLength) {
43631
43635
  return null;
@@ -56290,7 +56294,13 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56290
56294
  continue;
56291
56295
  }
56292
56296
  if (emfPlusState.dualMode && !emfPlusState.gdiPassthrough) {
56293
- if (recType !== EMR_SAVEDC && recType !== EMR_RESTOREDC) {
56297
+ if (recType === EMR_SAVEDC) {
56298
+ saveSkippedDc(rCtx);
56299
+ } else if (recType === EMR_RESTOREDC) {
56300
+ if (recSize >= 12) {
56301
+ restoreSkippedDc(rCtx, view.getInt32(dataOff, true));
56302
+ }
56303
+ } else {
56294
56304
  handleEmfGdiStateRecord(rCtx, recType, offset, dataOff, recSize);
56295
56305
  }
56296
56306
  offset += recSize;
@@ -56316,6 +56326,31 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56316
56326
  }
56317
56327
  return allDeferredImages;
56318
56328
  }
56329
+ function saveSkippedDc(rCtx) {
56330
+ rCtx.skippedDcStack ?? (rCtx.skippedDcStack = []);
56331
+ rCtx.skippedDcStack.push({
56332
+ state: cloneState(rCtx.state),
56333
+ mapping: {
56334
+ mapMode: rCtx.mapMode,
56335
+ windowOrg: { ...rCtx.windowOrg },
56336
+ windowExt: { ...rCtx.windowExt },
56337
+ viewportOrg: { ...rCtx.viewportOrg },
56338
+ viewportExt: { ...rCtx.viewportExt },
56339
+ useMappingMode: rCtx.useMappingMode
56340
+ }
56341
+ });
56342
+ }
56343
+ function restoreSkippedDc(rCtx, level) {
56344
+ const stack = rCtx.skippedDcStack ?? [];
56345
+ const at = level < 0 ? stack.length + level : level - 1;
56346
+ if (at < 0 || at >= stack.length) {
56347
+ return;
56348
+ }
56349
+ const saved = stack[at];
56350
+ stack.length = at;
56351
+ Object.assign(rCtx.state, saved.state);
56352
+ Object.assign(rCtx, saved.mapping);
56353
+ }
56319
56354
  function replayNestedEmf(bytes, ctx, canvasW, canvasH, toCanvas, options2) {
56320
56355
  const view = new DataView(bytes);
56321
56356
  const header = parseEmfHeader(view);
package/dist/index.js CHANGED
@@ -43629,6 +43629,10 @@ function parseWmfHeader(view) {
43629
43629
  boundsBottom = view.getInt16(12, true);
43630
43630
  unitsPerInch = view.getUint16(14, true) || 96;
43631
43631
  headerOffset = 22;
43632
+ const isType = (at) => [1, 2].includes(view.getUint16(at, true)) && view.getUint16(at + 2, true) === 9;
43633
+ if (view.byteLength >= 24 + 18 && !isType(22) && view.getUint16(22, true) === 0 && isType(24)) {
43634
+ headerOffset = 24;
43635
+ }
43632
43636
  }
43633
43637
  if (headerOffset + 18 > view.byteLength) {
43634
43638
  return null;
@@ -56293,7 +56297,13 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56293
56297
  continue;
56294
56298
  }
56295
56299
  if (emfPlusState.dualMode && !emfPlusState.gdiPassthrough) {
56296
- if (recType !== EMR_SAVEDC && recType !== EMR_RESTOREDC) {
56300
+ if (recType === EMR_SAVEDC) {
56301
+ saveSkippedDc(rCtx);
56302
+ } else if (recType === EMR_RESTOREDC) {
56303
+ if (recSize >= 12) {
56304
+ restoreSkippedDc(rCtx, view.getInt32(dataOff, true));
56305
+ }
56306
+ } else {
56297
56307
  handleEmfGdiStateRecord(rCtx, recType, offset, dataOff, recSize);
56298
56308
  }
56299
56309
  offset += recSize;
@@ -56319,6 +56329,31 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56319
56329
  }
56320
56330
  return allDeferredImages;
56321
56331
  }
56332
+ function saveSkippedDc(rCtx) {
56333
+ rCtx.skippedDcStack ?? (rCtx.skippedDcStack = []);
56334
+ rCtx.skippedDcStack.push({
56335
+ state: cloneState(rCtx.state),
56336
+ mapping: {
56337
+ mapMode: rCtx.mapMode,
56338
+ windowOrg: { ...rCtx.windowOrg },
56339
+ windowExt: { ...rCtx.windowExt },
56340
+ viewportOrg: { ...rCtx.viewportOrg },
56341
+ viewportExt: { ...rCtx.viewportExt },
56342
+ useMappingMode: rCtx.useMappingMode
56343
+ }
56344
+ });
56345
+ }
56346
+ function restoreSkippedDc(rCtx, level) {
56347
+ const stack = rCtx.skippedDcStack ?? [];
56348
+ const at = level < 0 ? stack.length + level : level - 1;
56349
+ if (at < 0 || at >= stack.length) {
56350
+ return;
56351
+ }
56352
+ const saved = stack[at];
56353
+ stack.length = at;
56354
+ Object.assign(rCtx.state, saved.state);
56355
+ Object.assign(rCtx, saved.mapping);
56356
+ }
56322
56357
  function replayNestedEmf(bytes, ctx, canvasW, canvasH, toCanvas, options2) {
56323
56358
  const view = new DataView(bytes);
56324
56359
  const header = parseEmfHeader(view);
package/dist/index.mjs CHANGED
@@ -43627,6 +43627,10 @@ function parseWmfHeader(view) {
43627
43627
  boundsBottom = view.getInt16(12, true);
43628
43628
  unitsPerInch = view.getUint16(14, true) || 96;
43629
43629
  headerOffset = 22;
43630
+ const isType = (at) => [1, 2].includes(view.getUint16(at, true)) && view.getUint16(at + 2, true) === 9;
43631
+ if (view.byteLength >= 24 + 18 && !isType(22) && view.getUint16(22, true) === 0 && isType(24)) {
43632
+ headerOffset = 24;
43633
+ }
43630
43634
  }
43631
43635
  if (headerOffset + 18 > view.byteLength) {
43632
43636
  return null;
@@ -56291,7 +56295,13 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56291
56295
  continue;
56292
56296
  }
56293
56297
  if (emfPlusState.dualMode && !emfPlusState.gdiPassthrough) {
56294
- if (recType !== EMR_SAVEDC && recType !== EMR_RESTOREDC) {
56298
+ if (recType === EMR_SAVEDC) {
56299
+ saveSkippedDc(rCtx);
56300
+ } else if (recType === EMR_RESTOREDC) {
56301
+ if (recSize >= 12) {
56302
+ restoreSkippedDc(rCtx, view.getInt32(dataOff, true));
56303
+ }
56304
+ } else {
56295
56305
  handleEmfGdiStateRecord(rCtx, recType, offset, dataOff, recSize);
56296
56306
  }
56297
56307
  offset += recSize;
@@ -56317,6 +56327,31 @@ function* replayEmfRecordsSteps(view, ctx, bounds, canvasW, canvasH, dpiScale =
56317
56327
  }
56318
56328
  return allDeferredImages;
56319
56329
  }
56330
+ function saveSkippedDc(rCtx) {
56331
+ rCtx.skippedDcStack ?? (rCtx.skippedDcStack = []);
56332
+ rCtx.skippedDcStack.push({
56333
+ state: cloneState(rCtx.state),
56334
+ mapping: {
56335
+ mapMode: rCtx.mapMode,
56336
+ windowOrg: { ...rCtx.windowOrg },
56337
+ windowExt: { ...rCtx.windowExt },
56338
+ viewportOrg: { ...rCtx.viewportOrg },
56339
+ viewportExt: { ...rCtx.viewportExt },
56340
+ useMappingMode: rCtx.useMappingMode
56341
+ }
56342
+ });
56343
+ }
56344
+ function restoreSkippedDc(rCtx, level) {
56345
+ const stack = rCtx.skippedDcStack ?? [];
56346
+ const at = level < 0 ? stack.length + level : level - 1;
56347
+ if (at < 0 || at >= stack.length) {
56348
+ return;
56349
+ }
56350
+ const saved = stack[at];
56351
+ stack.length = at;
56352
+ Object.assign(rCtx.state, saved.state);
56353
+ Object.assign(rCtx, saved.mapping);
56354
+ }
56320
56355
  function replayNestedEmf(bytes, ctx, canvasW, canvasH, toCanvas, options2) {
56321
56356
  const view = new DataView(bytes);
56322
56357
  const header = parseEmfHeader(view);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emf-converter",
3
- "version": "4.25.1",
3
+ "version": "4.25.2",
4
4
  "description": "Convert EMF/WMF metafile binaries to PNG, JPEG or WebP data URLs, SVG (markup, data URL, React/JSX) or PDF",
5
5
  "keywords": [
6
6
  "canvas",