emf-converter 4.19.0 → 4.20.1

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
@@ -46,7 +46,7 @@ var require_encoder = __commonJS({
46
46
  var YAC_HT;
47
47
  var UVAC_HT;
48
48
  var bitcode = new Array(65535);
49
- var category = new Array(65535);
49
+ var category2 = new Array(65535);
50
50
  var outputfDCTQuant = new Array(64);
51
51
  var DU = new Array(64);
52
52
  var byteout = [];
@@ -655,13 +655,13 @@ var require_encoder = __commonJS({
655
655
  var nrupper = 2;
656
656
  for (var cat = 1; cat <= 15; cat++) {
657
657
  for (var nr = nrlower; nr < nrupper; nr++) {
658
- category[32767 + nr] = cat;
658
+ category2[32767 + nr] = cat;
659
659
  bitcode[32767 + nr] = [];
660
660
  bitcode[32767 + nr][1] = cat;
661
661
  bitcode[32767 + nr][0] = nr;
662
662
  }
663
663
  for (var nrneg = -(nrupper - 1); nrneg <= -nrlower; nrneg++) {
664
- category[32767 + nrneg] = cat;
664
+ category2[32767 + nrneg] = cat;
665
665
  bitcode[32767 + nrneg] = [];
666
666
  bitcode[32767 + nrneg][1] = cat;
667
667
  bitcode[32767 + nrneg][0] = nrupper - 1 + nrneg;
@@ -943,7 +943,7 @@ var require_encoder = __commonJS({
943
943
  writeBits(HTDC[0]);
944
944
  } else {
945
945
  pos = 32767 + Diff;
946
- writeBits(HTDC[category[pos]]);
946
+ writeBits(HTDC[category2[pos]]);
947
947
  writeBits(bitcode[pos]);
948
948
  }
949
949
  var end0pos = 63;
@@ -967,7 +967,7 @@ var require_encoder = __commonJS({
967
967
  nrzeroes = nrzeroes & 15;
968
968
  }
969
969
  pos = 32767 + DU[i];
970
- writeBits(HTAC[(nrzeroes << 4) + category[pos]]);
970
+ writeBits(HTAC[(nrzeroes << 4) + category2[pos]]);
971
971
  writeBits(bitcode[pos]);
972
972
  i++;
973
973
  }
@@ -21484,7 +21484,7 @@ function axisFilter(kernel, scale, copy) {
21484
21484
  return { radius: 0.5, weight: (i, c) => Math.floor(c + 0.5) === i ? 1 : 0 };
21485
21485
  }
21486
21486
  }
21487
- function blendSeparable(rgba, width, box, iu0, wu, iv0, wv, verticalFirst, edge = { wrap: void 0, clamp: null }, integerBicubic = false, premult = false) {
21487
+ function blendSeparable(rgba, width, box, iu0, wu, iv0, wv, verticalFirst, edge = { wrap: void 0, clamp: null }, integerBicubic = false, premult = false, integerPremult = false) {
21488
21488
  const [outer0, outerW, inner0, innerW] = verticalFirst ? [iu0, wu, iv0, wv] : [iv0, wv, iu0, wu];
21489
21489
  const [oMin, oMax, iMin, iMax] = verticalFirst ? [box.x0, box.x1, box.y0, box.y1] : [box.y0, box.y1, box.x0, box.x1];
21490
21490
  let r = 0;
@@ -21525,9 +21525,9 @@ function blendSeparable(rgba, width, box, iu0, wu, iv0, wv, verticalFirst, edge
21525
21525
  }
21526
21526
  const alpha = px[s + 3];
21527
21527
  const wa = wi * alpha / 255;
21528
- lr += premult ? wi * px[s] : integerBicubic ? wi * Math.round(alpha * px[s] / 255) : wa * px[s];
21529
- lg += premult ? wi * px[s + 1] : integerBicubic ? wi * Math.round(alpha * px[s + 1] / 255) : wa * px[s + 1];
21530
- lb += premult ? wi * px[s + 2] : integerBicubic ? wi * Math.round(alpha * px[s + 2] / 255) : wa * px[s + 2];
21528
+ lr += premult ? wi * px[s] : integerBicubic || integerPremult ? wi * Math.round(alpha * px[s] / 255) : wa * px[s];
21529
+ lg += premult ? wi * px[s + 1] : integerBicubic || integerPremult ? wi * Math.round(alpha * px[s + 1] / 255) : wa * px[s + 1];
21530
+ lb += premult ? wi * px[s + 2] : integerBicubic || integerPremult ? wi * Math.round(alpha * px[s + 2] / 255) : wa * px[s + 2];
21531
21531
  la += wi * alpha;
21532
21532
  }
21533
21533
  if (integerBicubic) {
@@ -21719,8 +21719,25 @@ function resampleImage(rgba, width, height, spec, surface, options2 = {}) {
21719
21719
  for (let t = iv0; t <= iv1; t++) {
21720
21720
  wv.push(integerBicubic ? Math.round(fv.weight(t, cv) * 65536) / 65536 : fv.weight(t, cv));
21721
21721
  }
21722
- return blendSeparable(rgba, width, box, iu0, wu, iv0, wv, kernel === "bicubic", edge, integerBicubic, premultSource);
21722
+ return blendSeparable(
21723
+ rgba,
21724
+ width,
21725
+ box,
21726
+ iu0,
21727
+ wu,
21728
+ iv0,
21729
+ wv,
21730
+ kernel === "bicubic",
21731
+ edge,
21732
+ integerBicubic,
21733
+ premultSource,
21734
+ kernel === "bilinear"
21735
+ );
21723
21736
  };
21737
+ if (kernel === "bilinear") {
21738
+ u = Math.floor(u) + Math.round((u - Math.floor(u)) * 2048) / 2048;
21739
+ v = Math.floor(v) + Math.round((v - Math.floor(v)) * 2048) / 2048;
21740
+ }
21724
21741
  let [r, g, b, a] = sampleAt(u, v);
21725
21742
  if (a <= 0) {
21726
21743
  continue;
@@ -21731,7 +21748,7 @@ function resampleImage(rgba, width, height, spec, surface, options2 = {}) {
21731
21748
  b = Math.trunc(b);
21732
21749
  a = Math.trunc(a);
21733
21750
  if (a <= 0) continue;
21734
- } else if (premultSource) {
21751
+ } else if (premultSource || kernel === "bilinear") {
21735
21752
  r = Math.round(r);
21736
21753
  g = Math.round(g);
21737
21754
  b = Math.round(b);
@@ -22629,8 +22646,8 @@ function writeTextureColor(inv2, width, height, rgba, wrap, halfPixel2, dx, dy,
22629
22646
  const cv = inv2[1] * px + inv2[3] * py + inv2[5] - off;
22630
22647
  const iu = Math.floor(cu + 1e-9);
22631
22648
  const iv = Math.floor(cv + 1e-9);
22632
- const fu = Math.max(0, cu - iu);
22633
- const fv = Math.max(0, cv - iv);
22649
+ const fu = Math.round(Math.max(0, cu - iu) * 2048) / 2048;
22650
+ const fv = Math.round(Math.max(0, cv - iv) * 2048) / 2048;
22634
22651
  const clamp2 = wrap === "clamp";
22635
22652
  const mirrorX = wrap === "tile-flip-x" || wrap === "tile-flip-xy";
22636
22653
  const mirrorY = wrap === "tile-flip-y" || wrap === "tile-flip-xy";
@@ -22658,18 +22675,19 @@ function writeTextureColor(inv2, width, height, rgba, wrap, halfPixel2, dx, dy,
22658
22675
  y = wrapTexel(tv, height, mirrorY);
22659
22676
  }
22660
22677
  const s = (y * width + x) * 4;
22661
- const wa = w * rgba[s + 3];
22662
- r += wa * rgba[s];
22663
- g += wa * rgba[s + 1];
22664
- b += wa * rgba[s + 2];
22665
- a += wa;
22678
+ const alpha = rgba[s + 3];
22679
+ r += w * Math.round(rgba[s] * alpha / 255);
22680
+ g += w * Math.round(rgba[s + 1] * alpha / 255);
22681
+ b += w * Math.round(rgba[s + 2] * alpha / 255);
22682
+ a += w * alpha;
22666
22683
  }
22684
+ a = Math.round(a);
22667
22685
  if (a <= 0) {
22668
22686
  return;
22669
22687
  }
22670
- out[o] = r / a;
22671
- out[o + 1] = g / a;
22672
- out[o + 2] = b / a;
22688
+ out[o] = Math.round(Math.round(r) * 255 / a);
22689
+ out[o + 1] = Math.round(Math.round(g) * 255 / a);
22690
+ out[o + 2] = Math.round(Math.round(b) * 255 / a);
22673
22691
  out[o + 3] = a;
22674
22692
  }
22675
22693
  var IDENTITY2 = [1, 0, 0, 1, 0, 0];
@@ -24936,6 +24954,752 @@ function drawEmfPlusImageNow(rCtx, img, draw, source, effect = null) {
24936
24954
  return bitmap ? paintBitmapRaster(rCtx.ctx, bitmap, draw) : false;
24937
24955
  }
24938
24956
 
24957
+ // src/jpeg-encoder.ts
24958
+ var DEFAULT_JPEG_QUALITY = 0.92;
24959
+ var ZIGZAG2 = [
24960
+ 0,
24961
+ 1,
24962
+ 8,
24963
+ 16,
24964
+ 9,
24965
+ 2,
24966
+ 3,
24967
+ 10,
24968
+ 17,
24969
+ 24,
24970
+ 32,
24971
+ 25,
24972
+ 18,
24973
+ 11,
24974
+ 4,
24975
+ 5,
24976
+ 12,
24977
+ 19,
24978
+ 26,
24979
+ 33,
24980
+ 40,
24981
+ 48,
24982
+ 41,
24983
+ 34,
24984
+ 27,
24985
+ 20,
24986
+ 13,
24987
+ 6,
24988
+ 7,
24989
+ 14,
24990
+ 21,
24991
+ 28,
24992
+ 35,
24993
+ 42,
24994
+ 49,
24995
+ 56,
24996
+ 57,
24997
+ 50,
24998
+ 43,
24999
+ 36,
25000
+ 29,
25001
+ 22,
25002
+ 15,
25003
+ 23,
25004
+ 30,
25005
+ 37,
25006
+ 44,
25007
+ 51,
25008
+ 58,
25009
+ 59,
25010
+ 52,
25011
+ 45,
25012
+ 38,
25013
+ 31,
25014
+ 39,
25015
+ 46,
25016
+ 53,
25017
+ 60,
25018
+ 61,
25019
+ 54,
25020
+ 47,
25021
+ 55,
25022
+ 62,
25023
+ 63
25024
+ ];
25025
+ var LUMA_QUANT = [
25026
+ 16,
25027
+ 11,
25028
+ 10,
25029
+ 16,
25030
+ 24,
25031
+ 40,
25032
+ 51,
25033
+ 61,
25034
+ 12,
25035
+ 12,
25036
+ 14,
25037
+ 19,
25038
+ 26,
25039
+ 58,
25040
+ 60,
25041
+ 55,
25042
+ 14,
25043
+ 13,
25044
+ 16,
25045
+ 24,
25046
+ 40,
25047
+ 57,
25048
+ 69,
25049
+ 56,
25050
+ 14,
25051
+ 17,
25052
+ 22,
25053
+ 29,
25054
+ 51,
25055
+ 87,
25056
+ 80,
25057
+ 62,
25058
+ 18,
25059
+ 22,
25060
+ 37,
25061
+ 56,
25062
+ 68,
25063
+ 109,
25064
+ 103,
25065
+ 77,
25066
+ 24,
25067
+ 35,
25068
+ 55,
25069
+ 64,
25070
+ 81,
25071
+ 104,
25072
+ 113,
25073
+ 92,
25074
+ 49,
25075
+ 64,
25076
+ 78,
25077
+ 87,
25078
+ 103,
25079
+ 121,
25080
+ 120,
25081
+ 101,
25082
+ 72,
25083
+ 92,
25084
+ 95,
25085
+ 98,
25086
+ 112,
25087
+ 100,
25088
+ 103,
25089
+ 99
25090
+ ];
25091
+ var CHROMA_QUANT = [
25092
+ 17,
25093
+ 18,
25094
+ 24,
25095
+ 47,
25096
+ 99,
25097
+ 99,
25098
+ 99,
25099
+ 99,
25100
+ 18,
25101
+ 21,
25102
+ 26,
25103
+ 66,
25104
+ 99,
25105
+ 99,
25106
+ 99,
25107
+ 99,
25108
+ 24,
25109
+ 26,
25110
+ 56,
25111
+ 99,
25112
+ 99,
25113
+ 99,
25114
+ 99,
25115
+ 99,
25116
+ 47,
25117
+ 66,
25118
+ 99,
25119
+ 99,
25120
+ 99,
25121
+ 99,
25122
+ 99,
25123
+ 99,
25124
+ 99,
25125
+ 99,
25126
+ 99,
25127
+ 99,
25128
+ 99,
25129
+ 99,
25130
+ 99,
25131
+ 99,
25132
+ 99,
25133
+ 99,
25134
+ 99,
25135
+ 99,
25136
+ 99,
25137
+ 99,
25138
+ 99,
25139
+ 99,
25140
+ 99,
25141
+ 99,
25142
+ 99,
25143
+ 99,
25144
+ 99,
25145
+ 99,
25146
+ 99,
25147
+ 99,
25148
+ 99,
25149
+ 99,
25150
+ 99,
25151
+ 99,
25152
+ 99,
25153
+ 99,
25154
+ 99,
25155
+ 99
25156
+ ];
25157
+ var DC_LUMA = { bits: [0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], values: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] };
25158
+ var DC_CHROMA = { bits: [0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], values: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] };
25159
+ var AC_LUMA = {
25160
+ bits: [0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125],
25161
+ values: [
25162
+ 1,
25163
+ 2,
25164
+ 3,
25165
+ 0,
25166
+ 4,
25167
+ 17,
25168
+ 5,
25169
+ 18,
25170
+ 33,
25171
+ 49,
25172
+ 65,
25173
+ 6,
25174
+ 19,
25175
+ 81,
25176
+ 97,
25177
+ 7,
25178
+ 34,
25179
+ 113,
25180
+ 20,
25181
+ 50,
25182
+ 129,
25183
+ 145,
25184
+ 161,
25185
+ 8,
25186
+ 35,
25187
+ 66,
25188
+ 177,
25189
+ 193,
25190
+ 21,
25191
+ 82,
25192
+ 209,
25193
+ 240,
25194
+ 36,
25195
+ 51,
25196
+ 98,
25197
+ 114,
25198
+ 130,
25199
+ 9,
25200
+ 10,
25201
+ 22,
25202
+ 23,
25203
+ 24,
25204
+ 25,
25205
+ 26,
25206
+ 37,
25207
+ 38,
25208
+ 39,
25209
+ 40,
25210
+ 41,
25211
+ 42,
25212
+ 52,
25213
+ 53,
25214
+ 54,
25215
+ 55,
25216
+ 56,
25217
+ 57,
25218
+ 58,
25219
+ 67,
25220
+ 68,
25221
+ 69,
25222
+ 70,
25223
+ 71,
25224
+ 72,
25225
+ 73,
25226
+ 74,
25227
+ 83,
25228
+ 84,
25229
+ 85,
25230
+ 86,
25231
+ 87,
25232
+ 88,
25233
+ 89,
25234
+ 90,
25235
+ 99,
25236
+ 100,
25237
+ 101,
25238
+ 102,
25239
+ 103,
25240
+ 104,
25241
+ 105,
25242
+ 106,
25243
+ 115,
25244
+ 116,
25245
+ 117,
25246
+ 118,
25247
+ 119,
25248
+ 120,
25249
+ 121,
25250
+ 122,
25251
+ 131,
25252
+ 132,
25253
+ 133,
25254
+ 134,
25255
+ 135,
25256
+ 136,
25257
+ 137,
25258
+ 138,
25259
+ 146,
25260
+ 147,
25261
+ 148,
25262
+ 149,
25263
+ 150,
25264
+ 151,
25265
+ 152,
25266
+ 153,
25267
+ 154,
25268
+ 162,
25269
+ 163,
25270
+ 164,
25271
+ 165,
25272
+ 166,
25273
+ 167,
25274
+ 168,
25275
+ 169,
25276
+ 170,
25277
+ 178,
25278
+ 179,
25279
+ 180,
25280
+ 181,
25281
+ 182,
25282
+ 183,
25283
+ 184,
25284
+ 185,
25285
+ 186,
25286
+ 194,
25287
+ 195,
25288
+ 196,
25289
+ 197,
25290
+ 198,
25291
+ 199,
25292
+ 200,
25293
+ 201,
25294
+ 202,
25295
+ 210,
25296
+ 211,
25297
+ 212,
25298
+ 213,
25299
+ 214,
25300
+ 215,
25301
+ 216,
25302
+ 217,
25303
+ 218,
25304
+ 225,
25305
+ 226,
25306
+ 227,
25307
+ 228,
25308
+ 229,
25309
+ 230,
25310
+ 231,
25311
+ 232,
25312
+ 233,
25313
+ 234,
25314
+ 241,
25315
+ 242,
25316
+ 243,
25317
+ 244,
25318
+ 245,
25319
+ 246,
25320
+ 247,
25321
+ 248,
25322
+ 249,
25323
+ 250
25324
+ ]
25325
+ };
25326
+ var AC_CHROMA = {
25327
+ bits: [0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119],
25328
+ values: [
25329
+ 0,
25330
+ 1,
25331
+ 2,
25332
+ 3,
25333
+ 17,
25334
+ 4,
25335
+ 5,
25336
+ 33,
25337
+ 49,
25338
+ 6,
25339
+ 18,
25340
+ 65,
25341
+ 81,
25342
+ 7,
25343
+ 97,
25344
+ 113,
25345
+ 19,
25346
+ 34,
25347
+ 50,
25348
+ 129,
25349
+ 8,
25350
+ 20,
25351
+ 66,
25352
+ 145,
25353
+ 161,
25354
+ 177,
25355
+ 193,
25356
+ 9,
25357
+ 35,
25358
+ 51,
25359
+ 82,
25360
+ 240,
25361
+ 21,
25362
+ 98,
25363
+ 114,
25364
+ 209,
25365
+ 10,
25366
+ 22,
25367
+ 36,
25368
+ 52,
25369
+ 225,
25370
+ 37,
25371
+ 241,
25372
+ 23,
25373
+ 24,
25374
+ 25,
25375
+ 26,
25376
+ 38,
25377
+ 39,
25378
+ 40,
25379
+ 41,
25380
+ 42,
25381
+ 53,
25382
+ 54,
25383
+ 55,
25384
+ 56,
25385
+ 57,
25386
+ 58,
25387
+ 67,
25388
+ 68,
25389
+ 69,
25390
+ 70,
25391
+ 71,
25392
+ 72,
25393
+ 73,
25394
+ 74,
25395
+ 83,
25396
+ 84,
25397
+ 85,
25398
+ 86,
25399
+ 87,
25400
+ 88,
25401
+ 89,
25402
+ 90,
25403
+ 99,
25404
+ 100,
25405
+ 101,
25406
+ 102,
25407
+ 103,
25408
+ 104,
25409
+ 105,
25410
+ 106,
25411
+ 115,
25412
+ 116,
25413
+ 117,
25414
+ 118,
25415
+ 119,
25416
+ 120,
25417
+ 121,
25418
+ 122,
25419
+ 130,
25420
+ 131,
25421
+ 132,
25422
+ 133,
25423
+ 134,
25424
+ 135,
25425
+ 136,
25426
+ 137,
25427
+ 138,
25428
+ 146,
25429
+ 147,
25430
+ 148,
25431
+ 149,
25432
+ 150,
25433
+ 151,
25434
+ 152,
25435
+ 153,
25436
+ 154,
25437
+ 162,
25438
+ 163,
25439
+ 164,
25440
+ 165,
25441
+ 166,
25442
+ 167,
25443
+ 168,
25444
+ 169,
25445
+ 170,
25446
+ 178,
25447
+ 179,
25448
+ 180,
25449
+ 181,
25450
+ 182,
25451
+ 183,
25452
+ 184,
25453
+ 185,
25454
+ 186,
25455
+ 194,
25456
+ 195,
25457
+ 196,
25458
+ 197,
25459
+ 198,
25460
+ 199,
25461
+ 200,
25462
+ 201,
25463
+ 202,
25464
+ 210,
25465
+ 211,
25466
+ 212,
25467
+ 213,
25468
+ 214,
25469
+ 215,
25470
+ 216,
25471
+ 217,
25472
+ 218,
25473
+ 226,
25474
+ 227,
25475
+ 228,
25476
+ 229,
25477
+ 230,
25478
+ 231,
25479
+ 232,
25480
+ 233,
25481
+ 234,
25482
+ 242,
25483
+ 243,
25484
+ 244,
25485
+ 245,
25486
+ 246,
25487
+ 247,
25488
+ 248,
25489
+ 249,
25490
+ 250
25491
+ ]
25492
+ };
25493
+ function buildCodes(spec) {
25494
+ const code = new Uint16Array(256);
25495
+ const size = new Uint8Array(256);
25496
+ let next = 0;
25497
+ let k = 0;
25498
+ for (let len = 1; len <= 16; len++) {
25499
+ for (let i = 0; i < spec.bits[len - 1]; i++) {
25500
+ const symbol = spec.values[k++];
25501
+ code[symbol] = next++;
25502
+ size[symbol] = len;
25503
+ }
25504
+ next <<= 1;
25505
+ }
25506
+ return { code, size };
25507
+ }
25508
+ function scaleQuant(base, quality) {
25509
+ const q = Math.min(100, Math.max(1, Math.round(quality * 100)));
25510
+ const scale = q < 50 ? Math.floor(5e3 / q) : 200 - q * 2;
25511
+ return Uint8Array.from(base, (v) => Math.min(255, Math.max(1, Math.floor((v * scale + 50) / 100))));
25512
+ }
25513
+ var COS = (() => {
25514
+ const t = new Float64Array(64);
25515
+ for (let u = 0; u < 8; u++) {
25516
+ const c = u === 0 ? Math.SQRT1_2 : 1;
25517
+ for (let x = 0; x < 8; x++) {
25518
+ t[u * 8 + x] = c / 2 * Math.cos((2 * x + 1) * u * Math.PI / 16);
25519
+ }
25520
+ }
25521
+ return t;
25522
+ })();
25523
+ function fdctQuantize(block, quant, out, tmp) {
25524
+ for (let y = 0; y < 8; y++) {
25525
+ for (let u = 0; u < 8; u++) {
25526
+ let s = 0;
25527
+ for (let x = 0; x < 8; x++) s += COS[u * 8 + x] * block[y * 8 + x];
25528
+ tmp[y * 8 + u] = s;
25529
+ }
25530
+ }
25531
+ for (let k = 0; k < 64; k++) {
25532
+ const n = ZIGZAG2[k];
25533
+ const v = n >> 3;
25534
+ const u = n & 7;
25535
+ let s = 0;
25536
+ for (let y = 0; y < 8; y++) s += COS[v * 8 + y] * tmp[y * 8 + u];
25537
+ out[k] = Math.round(s / quant[n]);
25538
+ }
25539
+ }
25540
+ var BitWriter = class {
25541
+ constructor() {
25542
+ this.buf = new Uint8Array(4096);
25543
+ this.length = 0;
25544
+ this.acc = 0;
25545
+ this.count = 0;
25546
+ }
25547
+ byte(b) {
25548
+ if (this.length === this.buf.length) {
25549
+ const grown = new Uint8Array(this.buf.length * 2);
25550
+ grown.set(this.buf);
25551
+ this.buf = grown;
25552
+ }
25553
+ this.buf[this.length++] = b;
25554
+ }
25555
+ bits(value, size) {
25556
+ for (let i = size - 1; i >= 0; i--) {
25557
+ this.acc = this.acc << 1 | value >> i & 1;
25558
+ if (++this.count === 8) {
25559
+ this.byte(this.acc);
25560
+ if (this.acc === 255) this.byte(0);
25561
+ this.acc = 0;
25562
+ this.count = 0;
25563
+ }
25564
+ }
25565
+ }
25566
+ /** Pads the last byte with 1 bits and returns the segment. */
25567
+ finish() {
25568
+ if (this.count > 0) this.bits((1 << 8 - this.count) - 1, 8 - this.count);
25569
+ return this.buf.subarray(0, this.length);
25570
+ }
25571
+ };
25572
+ function category(v) {
25573
+ let a = v < 0 ? -v : v;
25574
+ let n = 0;
25575
+ while (a) {
25576
+ n++;
25577
+ a >>= 1;
25578
+ }
25579
+ return n;
25580
+ }
25581
+ function writeBlock(w, coef, prevDc, dc, ac) {
25582
+ const diff = coef[0] - prevDc;
25583
+ const dcSize = category(diff);
25584
+ w.bits(dc.code[dcSize], dc.size[dcSize]);
25585
+ if (dcSize) w.bits(diff < 0 ? diff - 1 : diff, dcSize);
25586
+ let run = 0;
25587
+ for (let k = 1; k < 64; k++) {
25588
+ const v = coef[k];
25589
+ if (v === 0) {
25590
+ run++;
25591
+ continue;
25592
+ }
25593
+ while (run > 15) {
25594
+ w.bits(ac.code[240], ac.size[240]);
25595
+ run -= 16;
25596
+ }
25597
+ const size = category(v);
25598
+ const symbol = run << 4 | size;
25599
+ w.bits(ac.code[symbol], ac.size[symbol]);
25600
+ w.bits(v < 0 ? v - 1 : v, size);
25601
+ run = 0;
25602
+ }
25603
+ if (run > 0) w.bits(ac.code[0], ac.size[0]);
25604
+ return coef[0];
25605
+ }
25606
+ function segment(marker, payload) {
25607
+ const len = payload.length + 2;
25608
+ return [255, marker, len >> 8, len & 255, ...payload];
25609
+ }
25610
+ function dhtPayload(tableClass, id, spec) {
25611
+ return [tableClass << 4 | id, ...spec.bits, ...spec.values];
25612
+ }
25613
+ function encodeJpeg(data, width, height, options2 = {}) {
25614
+ if (!(width >= 1 && height >= 1 && width <= 65535 && height <= 65535)) {
25615
+ throw new RangeError(`JPEG dimensions out of range: ${width}x${height}`);
25616
+ }
25617
+ const quality = Number.isFinite(options2.quality) ? Math.min(1, Math.max(0, options2.quality)) : DEFAULT_JPEG_QUALITY;
25618
+ const [bgR, bgG, bgB] = options2.background ?? [255, 255, 255];
25619
+ const sub = options2.chromaSubsampling ?? false;
25620
+ const lumaQuant = scaleQuant(LUMA_QUANT, quality);
25621
+ const chromaQuant = scaleQuant(CHROMA_QUANT, quality);
25622
+ const n = width * height;
25623
+ const Y = new Float64Array(n);
25624
+ const Cb = new Float64Array(n);
25625
+ const Cr = new Float64Array(n);
25626
+ for (let i = 0; i < n; i++) {
25627
+ const a = data[i * 4 + 3] / 255;
25628
+ const r = data[i * 4] * a + bgR * (1 - a);
25629
+ const g = data[i * 4 + 1] * a + bgG * (1 - a);
25630
+ const b = data[i * 4 + 2] * a + bgB * (1 - a);
25631
+ Y[i] = 0.299 * r + 0.587 * g + 0.114 * b;
25632
+ Cb[i] = -0.168736 * r - 0.331264 * g + 0.5 * b + 128;
25633
+ Cr[i] = 0.5 * r - 0.418688 * g - 0.081312 * b + 128;
25634
+ }
25635
+ const dcL = buildCodes(DC_LUMA);
25636
+ const acL = buildCodes(AC_LUMA);
25637
+ const dcC = buildCodes(DC_CHROMA);
25638
+ const acC = buildCodes(AC_CHROMA);
25639
+ const factor = sub ? 2 : 1;
25640
+ const mcu = 8 * factor;
25641
+ const block = new Float64Array(64);
25642
+ const tmp = new Float64Array(64);
25643
+ const coef = new Int32Array(64);
25644
+ const w = new BitWriter();
25645
+ let dcY = 0;
25646
+ let dcCb = 0;
25647
+ let dcCr = 0;
25648
+ const lumaBlock = (x0, y0) => {
25649
+ for (let y = 0; y < 8; y++) {
25650
+ const row2 = Math.min(height - 1, y0 + y) * width;
25651
+ for (let x = 0; x < 8; x++) block[y * 8 + x] = Y[row2 + Math.min(width - 1, x0 + x)] - 128;
25652
+ }
25653
+ };
25654
+ const chromaBlock = (plane, x0, y0) => {
25655
+ for (let y = 0; y < 8; y++) {
25656
+ for (let x = 0; x < 8; x++) {
25657
+ let s = 0;
25658
+ for (let dy = 0; dy < factor; dy++) {
25659
+ const row2 = Math.min(height - 1, y0 + y * factor + dy) * width;
25660
+ for (let dx = 0; dx < factor; dx++) s += plane[row2 + Math.min(width - 1, x0 + x * factor + dx)];
25661
+ }
25662
+ block[y * 8 + x] = s / (factor * factor) - 128;
25663
+ }
25664
+ }
25665
+ };
25666
+ for (let my = 0; my < height; my += mcu) {
25667
+ for (let mx = 0; mx < width; mx += mcu) {
25668
+ for (let by = 0; by < factor; by++) {
25669
+ for (let bx = 0; bx < factor; bx++) {
25670
+ lumaBlock(mx + bx * 8, my + by * 8);
25671
+ fdctQuantize(block, lumaQuant, coef, tmp);
25672
+ dcY = writeBlock(w, coef, dcY, dcL, acL);
25673
+ }
25674
+ }
25675
+ chromaBlock(Cb, mx, my);
25676
+ fdctQuantize(block, chromaQuant, coef, tmp);
25677
+ dcCb = writeBlock(w, coef, dcCb, dcC, acC);
25678
+ chromaBlock(Cr, mx, my);
25679
+ fdctQuantize(block, chromaQuant, coef, tmp);
25680
+ dcCr = writeBlock(w, coef, dcCr, dcC, acC);
25681
+ }
25682
+ }
25683
+ const scan = w.finish();
25684
+ const sampling = factor << 4 | factor;
25685
+ const header = [
25686
+ 255,
25687
+ 216,
25688
+ // APP0 JFIF 1.01, no density (aspect ratio 1:1), no thumbnail.
25689
+ ...segment(224, [74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0]),
25690
+ ...segment(219, [0, ...ZIGZAG2.map((i) => lumaQuant[i]), 1, ...ZIGZAG2.map((i) => chromaQuant[i])]),
25691
+ ...segment(192, [8, height >> 8, height & 255, width >> 8, width & 255, 3, 1, sampling, 0, 2, 17, 1, 3, 17, 1]),
25692
+ ...segment(196, [...dhtPayload(0, 0, DC_LUMA), ...dhtPayload(1, 0, AC_LUMA), ...dhtPayload(0, 1, DC_CHROMA), ...dhtPayload(1, 1, AC_CHROMA)]),
25693
+ ...segment(218, [3, 1, 0, 2, 17, 3, 17, 0, 63, 0])
25694
+ ];
25695
+ const out = new Uint8Array(header.length + scan.length + 2);
25696
+ out.set(header, 0);
25697
+ out.set(scan, header.length);
25698
+ out[out.length - 2] = 255;
25699
+ out[out.length - 1] = 217;
25700
+ return out;
25701
+ }
25702
+
24939
25703
  // src/fnt-font.ts
24940
25704
  function parseFnt(view, base, end) {
24941
25705
  if (base + 118 > end) {
@@ -28251,6 +29015,46 @@ function mulDivRound(a, b, c) {
28251
29015
  const d = c > 0 ? Math.floor((a * b + Math.floor(c / 2)) / c) : 2147483647;
28252
29016
  return s < 0 ? -d : d;
28253
29017
  }
29018
+ var MonoStubContour = class {
29019
+ constructor(o) {
29020
+ this.points = Array.from(o.xs, (x, i) => [x / 64 - 0.5, o.ys[i] / 64 - 0.5]);
29021
+ }
29022
+ isStub(flipped, scan, crossing, lo, hi, precision) {
29023
+ const points = this.points;
29024
+ const n = points.length;
29025
+ const point = (i) => flipped ? [points[i][1], points[i][0]] : points[i];
29026
+ let edge = -1;
29027
+ let distance = Infinity;
29028
+ for (let i = 0; i < n; i++) {
29029
+ const a2 = point(i), b2 = point((i + 1) % n);
29030
+ if (a2[1] === b2[1] || scan < Math.min(a2[1], b2[1]) || scan > Math.max(a2[1], b2[1])) continue;
29031
+ const x = a2[0] + (b2[0] - a2[0]) * (scan - a2[1]) / (b2[1] - a2[1]);
29032
+ if (Math.abs(x - crossing) < distance) {
29033
+ distance = Math.abs(x - crossing);
29034
+ edge = i;
29035
+ }
29036
+ }
29037
+ if (edge < 0 || distance > 2 / precision) return null;
29038
+ const trace = (step) => {
29039
+ let i = step === 1 ? (edge + 1) % n : edge;
29040
+ let previous = [crossing, scan];
29041
+ let side = 0;
29042
+ for (let k = 0; k < n; k++, i = (i + step + n) % n) {
29043
+ const p = point(i), dy = p[1] - scan;
29044
+ if (!side && dy) side = Math.sign(dy);
29045
+ if (side && dy * side < 0) {
29046
+ const x = previous[0] + (p[0] - previous[0]) * (scan - previous[1]) / (p[1] - previous[1]);
29047
+ return { side, continues: x <= lo || x >= hi };
29048
+ }
29049
+ if (p[0] <= lo || p[0] >= hi || dy * side >= 1) return { side, continues: true };
29050
+ previous = p;
29051
+ }
29052
+ return { side, continues: false };
29053
+ };
29054
+ const a = trace(1), b = trace(-1);
29055
+ return !(a.side * b.side < 0 && a.continues && b.continues);
29056
+ }
29057
+ };
28254
29058
  function monoBox(o) {
28255
29059
  const n = o.xs.length;
28256
29060
  if (n === 0) {
@@ -28283,7 +29087,7 @@ function monoBox(o) {
28283
29087
  }
28284
29088
  return { xMin, xMax, yMin, yMax };
28285
29089
  }
28286
- function rasterizeMono(o, dropout, fixedBox, stubOvershoot = true) {
29090
+ function rasterizeMono(o, dropout, fixedBox, stubOvershoot = true, smartCrossings26Dot6 = false) {
28287
29091
  const box = fixedBox ?? monoBox(o);
28288
29092
  if (!box) {
28289
29093
  return null;
@@ -28305,6 +29109,15 @@ function rasterizeMono(o, dropout, fixedBox, stubOvershoot = true) {
28305
29109
  const at = (col, row2) => (height - 1 - row2) * width + col;
28306
29110
  const r = new Raster(dropout);
28307
29111
  const P = r.precision;
29112
+ const monoContour = stubOvershoot && (dropout === 1 || dropout === 4 || dropout === 5) && local.endPts.length === 1 && Array.from(local.onCurve).every(Boolean) ? new MonoStubContour(local) : null;
29113
+ const smartPixel = (raster, x1, x2) => {
29114
+ if (monoContour && smartCrossings26Dot6) {
29115
+ const step = P / 64;
29116
+ x1 = Math.round(x1 / step) * step;
29117
+ x2 = Math.round(x2 / step) * step;
29118
+ }
29119
+ return raster.floorPub(Math.floor((x1 + x2 + Math.floor(P * 63 / 64)) / 2));
29120
+ };
28308
29121
  if (r.convert(local, false, 0, (height - 1) * P)) {
28309
29122
  r.sweep(
28310
29123
  (y, x1, x2) => {
@@ -28335,17 +29148,19 @@ function rasterizeMono(o, dropout, fixedBox, stubOvershoot = true) {
28335
29148
  pxl = e2;
28336
29149
  break;
28337
29150
  case 4:
28338
- pxl = r.floorPub(Math.floor((x1 + x2 + Math.floor(P * 63 / 64)) / 2));
29151
+ pxl = smartPixel(r, x1, x2);
28339
29152
  break;
28340
29153
  case 1:
28341
29154
  case 5:
28342
- if (left.next === right && left.height <= 0 && !(stubOvershoot && left.flags & OVERSHOOT_TOP && x2 - x1 >= r.half)) {
29155
+ const stub = monoContour?.isStub(false, y, x1 / P, e2 / P, e1 / P, P);
29156
+ if (stub === true) return;
29157
+ if (stub == null && left.next === right && left.height <= 0 && !(stubOvershoot && left.flags & OVERSHOOT_TOP && x2 - x1 >= r.half)) {
28343
29158
  return;
28344
29159
  }
28345
- if (right.next === left && left.start === y && !(stubOvershoot && left.flags & OVERSHOOT_BOTTOM && x2 - x1 >= r.half)) {
29160
+ if (stub == null && right.next === left && left.start === y && !(stubOvershoot && left.flags & OVERSHOOT_BOTTOM && x2 - x1 >= r.half)) {
28346
29161
  return;
28347
29162
  }
28348
- pxl = mode === 1 ? e2 : r.floorPub(Math.floor((x1 + x2 + Math.floor(P * 63 / 64)) / 2));
29163
+ pxl = mode === 1 ? e2 : smartPixel(r, x1, x2);
28349
29164
  break;
28350
29165
  default:
28351
29166
  return;
@@ -28394,17 +29209,19 @@ function rasterizeMono(o, dropout, fixedBox, stubOvershoot = true) {
28394
29209
  pxl = e2;
28395
29210
  break;
28396
29211
  case 4:
28397
- pxl = h.floorPub(Math.floor((x1 + x2 + Math.floor(P * 63 / 64)) / 2));
29212
+ pxl = smartPixel(h, x1, x2);
28398
29213
  break;
28399
29214
  case 1:
28400
29215
  case 5:
28401
- if (left.next === right && left.height <= 0 && !(stubOvershoot && left.flags & OVERSHOOT_TOP && x2 - x1 >= h.half)) {
29216
+ const stub = monoContour?.isStub(true, col, x1 / P, e2 / P, e1 / P, P);
29217
+ if (stub === true) return;
29218
+ if (stub == null && left.next === right && left.height <= 0 && !(stubOvershoot && left.flags & OVERSHOOT_TOP && x2 - x1 >= h.half)) {
28402
29219
  return;
28403
29220
  }
28404
- if (right.next === left && left.start === col && !(stubOvershoot && left.flags & OVERSHOOT_BOTTOM && x2 - x1 >= h.half)) {
29221
+ if (stub == null && right.next === left && left.start === col && !(stubOvershoot && left.flags & OVERSHOOT_BOTTOM && x2 - x1 >= h.half)) {
28405
29222
  return;
28406
29223
  }
28407
- pxl = mode === 1 ? e2 : h.floorPub(Math.floor((x1 + x2 + Math.floor(P * 63 / 64)) / 2));
29224
+ pxl = mode === 1 ? e2 : smartPixel(h, x1, x2);
28408
29225
  break;
28409
29226
  default:
28410
29227
  return;
@@ -28997,12 +29814,14 @@ var RealizedFont = class {
28997
29814
  }
28998
29815
  let bitmap;
28999
29816
  if (this.mode === "mono") {
29000
- bitmap = rasterizeMono(o, dropoutMode(src.scanSet ? src.scanControl : this.ppem <= DEFAULT_DROPOUT_PPEM, src.scanType));
29817
+ const smartGrid = this.ppemX === this.ppem && !m && !this.syntheticItalic && !subX && !subY;
29818
+ bitmap = rasterizeMono(o, dropoutMode(src.scanSet ? src.scanControl : this.ppem <= DEFAULT_DROPOUT_PPEM, src.scanType), void 0, true, smartGrid);
29001
29819
  } else if (this.mode === "cleartype") {
29002
29820
  const dropout = src.scanSet ? dropoutMode(src.scanControl, src.scanType) : 2;
29003
29821
  bitmap = rasterizeClearType(o, this.gdiPlus, this.gdiPlus ? clearTypeSpread(this.ttf) : void 0, dropout);
29004
29822
  } else {
29005
- bitmap = rasterizeGray(o, src.scanSet ? dropoutMode(src.scanControl, src.scanType) : 2);
29823
+ const dropout = src.scanSet ? dropoutMode(src.scanControl, src.scanType) : 2;
29824
+ bitmap = this.gdiPlus && !this.gridFit && !m && !this.syntheticBold && !this.syntheticItalic && this.ttf.weightClass < 600 && this.ttf.family.toLowerCase() === "courier new" ? rasterizeCourierGray(o, dropout) : rasterizeGray(o, dropout);
29006
29825
  }
29007
29826
  if (bitmap && this.syntheticBold) {
29008
29827
  bitmap = embolden(bitmap, this.mode === "mono" ? 1 : 16);
@@ -29314,6 +30133,23 @@ function resolvePpem(font, height) {
29314
30133
  return ppem;
29315
30134
  }
29316
30135
  var CLEARTYPE_OVERSAMPLE = 6;
30136
+ function rasterizeCourierGray(o, dropout) {
30137
+ const samples = rasterizeSamples(o, 4, 4, 1, dropout, false);
30138
+ if (!samples) return null;
30139
+ const { box, hi } = samples;
30140
+ const width = box.xMax - box.xMin;
30141
+ const height = box.yMax - box.yMin;
30142
+ const data = new Uint8Array(width * height);
30143
+ for (let y = 0; y < hi.height; y++) {
30144
+ const row2 = y * hi.width;
30145
+ for (let x = 0; x < hi.width; x++) {
30146
+ if (hi.data[row2 + x] || x > 0 && hi.data[row2 + x - 1]) {
30147
+ data[Math.floor(y / 4) * width + Math.floor(x / 4)]++;
30148
+ }
30149
+ }
30150
+ }
30151
+ return { width, height, left: box.xMin, top: box.yMax, data };
30152
+ }
29317
30153
  function clearTypeSpread(ttf) {
29318
30154
  if (ttf.family.toLowerCase() !== "courier new") {
29319
30155
  return void 0;
@@ -36569,7 +37405,7 @@ function emitSvgRun(ctx, font, run, glyphs, origins, fontFamilyMap) {
36569
37405
  for (let i = 0; i < origins.length; i++) {
36570
37406
  const code = run.glyphIndices ? font.charForGlyph(glyphs[i]) : run.codes[i];
36571
37407
  if (!run.glyphIndices && !(run.options & ETO_IGNORELANGUAGE) && isC1Control(code)) continue;
36572
- text += String.fromCharCode(code);
37408
+ text += String.fromCodePoint(code);
36573
37409
  visibleOrigins.push(origins[i]);
36574
37410
  }
36575
37411
  if (text.length === 0) return;
@@ -38585,7 +39421,11 @@ function setViewportExt(m, cx, cy) {
38585
39421
  fixIsotropic(m);
38586
39422
  }
38587
39423
  function scaled(v, num, den) {
38588
- return Math.trunc(v * num / den);
39424
+ const product = Math.imul(v, num);
39425
+ if (product === -2147483648 && den === -1) {
39426
+ return 0;
39427
+ }
39428
+ return Math.trunc(product / den);
38589
39429
  }
38590
39430
  function scaleWindowExt(m, xNum, xDen, yNum, yDen) {
38591
39431
  if (!extentsSettable(m) || !xDen || !yDen) {
@@ -38738,10 +39578,16 @@ function setExtent(r, viewport, cx, cy) {
38738
39578
  activateGdiMappingMode(r);
38739
39579
  }
38740
39580
  function scaleExtent(r, viewport, xNum, xDenom, yNum, yDenom) {
38741
- const ext = viewport ? r.viewportExt : r.windowExt;
38742
- const cx = xDenom !== 0 ? Math.round(ext.cx * xNum / xDenom) : ext.cx;
38743
- const cy = yDenom !== 0 ? Math.round(ext.cy * yNum / yDenom) : ext.cy;
38744
- setExtent(r, viewport, cx, cy);
39581
+ const m = emfMapping(r);
39582
+ if (!extentsSettable(m) || !xDenom || !yDenom) {
39583
+ return;
39584
+ }
39585
+ (viewport ? scaleViewportExt : scaleWindowExt)(m, xNum, xDenom, yNum, yDenom);
39586
+ if (r.windowExt.cx === m.winExt.cx && r.windowExt.cy === m.winExt.cy && r.viewportExt.cx === m.vpExt.cx && r.viewportExt.cy === m.vpExt.cy) {
39587
+ return;
39588
+ }
39589
+ storeMapping(r, m);
39590
+ activateGdiMappingMode(r);
38745
39591
  }
38746
39592
  function handleCoordinateRecord(rCtx, recType, dataOff, recSize) {
38747
39593
  const { view } = rCtx;
@@ -39889,8 +40735,8 @@ function drawPlusStringWithEngine(rCtx, font, text, layoutX, layoutY, paint, ali
39889
40735
  if (!unhinted) x = Math.round(x);
39890
40736
  const y = m[3] * layoutY + m[5] + ascent;
39891
40737
  const codes = [];
39892
- for (let i = 0; i < text.length; i++) {
39893
- codes.push(text.charCodeAt(i));
40738
+ for (const character of text) {
40739
+ codes.push(character.codePointAt(0));
39894
40740
  }
39895
40741
  const tracking = format?.tracking ?? PLUS_DEFAULT_TRACKING;
39896
40742
  const dx = unhinted ? codes.map((c) => realized.advance(realized.glyphIndex(c)) * tracking) : null;
@@ -43381,6 +44227,54 @@ async function processDeferredImages(ctx, deferredImages, recursionDepth) {
43381
44227
  return complete;
43382
44228
  }
43383
44229
  async function convertMetafileToDataUrl(buffer, options2, recursionDepth = 0) {
44230
+ const raster = await renderRaster(buffer, options2, recursionDepth, "convertMetafileToDataUrl");
44231
+ if (!raster) {
44232
+ return null;
44233
+ }
44234
+ try {
44235
+ const url = await exportCanvasToPngDataUrl(raster.canvas);
44236
+ if (!url) {
44237
+ emfWarn("convertMetafileToDataUrl: exportCanvasToPngDataUrl returned null");
44238
+ }
44239
+ return url;
44240
+ } catch (err) {
44241
+ emfWarn("convertMetafileToDataUrl: EXCEPTION:", err instanceof Error ? err.message : err);
44242
+ console.warn("[emf-converter] Conversion failed:", err instanceof Error ? err.message : err);
44243
+ return null;
44244
+ }
44245
+ }
44246
+ async function convertMetafileToJpegDataUrl(buffer, options2) {
44247
+ const raster = await renderRaster(buffer, options2, 0, "convertMetafileToJpegDataUrl");
44248
+ if (!raster) {
44249
+ return null;
44250
+ }
44251
+ try {
44252
+ const { canvas, ctx } = raster;
44253
+ const pixels = canvas instanceof SoftwareRasterCanvas ? canvas.pixels : canvasGetImageData(ctx, 0, 0, canvas.width, canvas.height).data;
44254
+ const jpeg = encodeJpeg(pixels, canvas.width, canvas.height, {
44255
+ quality: options2?.quality,
44256
+ background: parseBackground(options2?.background),
44257
+ chromaSubsampling: options2?.chromaSubsampling
44258
+ });
44259
+ return `data:image/jpeg;base64,${bytesToBase64(jpeg)}`;
44260
+ } catch (err) {
44261
+ emfWarn("convertMetafileToJpegDataUrl: EXCEPTION:", err instanceof Error ? err.message : err);
44262
+ console.warn("[emf-converter] Conversion failed:", err instanceof Error ? err.message : err);
44263
+ return null;
44264
+ }
44265
+ }
44266
+ function parseBackground(color) {
44267
+ if (color === void 0) {
44268
+ return [255, 255, 255];
44269
+ }
44270
+ const hex5 = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(color.trim())?.[1];
44271
+ if (!hex5) {
44272
+ return [255, 255, 255];
44273
+ }
44274
+ const full = hex5.length === 3 ? [...hex5].map((c) => c + c).join("") : hex5;
44275
+ return [0, 2, 4].map((i) => parseInt(full.slice(i, i + 2), 16));
44276
+ }
44277
+ async function renderRaster(buffer, options2, recursionDepth, caller) {
43384
44278
  await ensureNodeCanvasModule();
43385
44279
  if (recursionDepth > MAX_METAFILE_RECURSION) {
43386
44280
  return null;
@@ -43410,17 +44304,13 @@ async function convertMetafileToDataUrl(buffer, options2, recursionDepth = 0) {
43410
44304
  const soft = canvas instanceof SoftwareRasterCanvas ? canvas : null;
43411
44305
  if (soft && (soft.textDraws > 0 || !complete)) {
43412
44306
  emfWarn(
43413
- `convertMetafileToDataUrl: no canvas backend and the drawing ${soft.textDraws > 0 ? `contains text (${soft.textDraws} runs)` : "contains an image only a canvas can decode"}; install @napi-rs/canvas for PNG output, or use SVG output`
44307
+ `${caller}: no canvas backend and the drawing ${soft.textDraws > 0 ? `contains text (${soft.textDraws} runs)` : "contains an image only a canvas can decode"}; install @napi-rs/canvas for raster output, or use SVG output`
43414
44308
  );
43415
44309
  return null;
43416
44310
  }
43417
- const url = await exportCanvasToPngDataUrl(canvas);
43418
- if (!url) {
43419
- emfWarn("convertMetafileToDataUrl: exportCanvasToPngDataUrl returned null");
43420
- }
43421
- return url;
44311
+ return { canvas, ctx: result.surface.ctx };
43422
44312
  } catch (err) {
43423
- emfWarn("convertMetafileToDataUrl: EXCEPTION:", err instanceof Error ? err.message : err);
44313
+ emfWarn(`${caller}: EXCEPTION:`, err instanceof Error ? err.message : err);
43424
44314
  console.warn("[emf-converter] Conversion failed:", err instanceof Error ? err.message : err);
43425
44315
  return null;
43426
44316
  }
@@ -43571,6 +44461,7 @@ async function convertMetafileToSvgDataUrl(buffer, options2) {
43571
44461
 
43572
44462
  exports.DEFAULT_DPI_SCALE = DEFAULT_DPI_SCALE;
43573
44463
  exports.convertMetafileToDataUrl = convertMetafileToDataUrl;
44464
+ exports.convertMetafileToJpegDataUrl = convertMetafileToJpegDataUrl;
43574
44465
  exports.convertMetafileToSvg = convertMetafileToSvg;
43575
44466
  exports.convertMetafileToSvgDataUrl = convertMetafileToSvgDataUrl;
43576
44467
  exports.convertMetafileToSvgTree = convertMetafileToSvgTree;