emf-converter 4.18.2 → 4.20.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/dist/index.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
  }
@@ -24853,6 +24853,7 @@ function drawNestedMetafile(rCtx, img, cached, source) {
24853
24853
  imageCache: caches?.images,
24854
24854
  fontFamilyMap: rCtx.fontFamilyMap,
24855
24855
  gdiAntialias: rCtx.gdiAntialias,
24856
+ codePages: rCtx.codePages,
24856
24857
  nestingDepth: depth + 1
24857
24858
  });
24858
24859
  } finally {
@@ -24936,6 +24937,752 @@ function drawEmfPlusImageNow(rCtx, img, draw, source, effect = null) {
24936
24937
  return bitmap ? paintBitmapRaster(rCtx.ctx, bitmap, draw) : false;
24937
24938
  }
24938
24939
 
24940
+ // src/jpeg-encoder.ts
24941
+ var DEFAULT_JPEG_QUALITY = 0.92;
24942
+ var ZIGZAG2 = [
24943
+ 0,
24944
+ 1,
24945
+ 8,
24946
+ 16,
24947
+ 9,
24948
+ 2,
24949
+ 3,
24950
+ 10,
24951
+ 17,
24952
+ 24,
24953
+ 32,
24954
+ 25,
24955
+ 18,
24956
+ 11,
24957
+ 4,
24958
+ 5,
24959
+ 12,
24960
+ 19,
24961
+ 26,
24962
+ 33,
24963
+ 40,
24964
+ 48,
24965
+ 41,
24966
+ 34,
24967
+ 27,
24968
+ 20,
24969
+ 13,
24970
+ 6,
24971
+ 7,
24972
+ 14,
24973
+ 21,
24974
+ 28,
24975
+ 35,
24976
+ 42,
24977
+ 49,
24978
+ 56,
24979
+ 57,
24980
+ 50,
24981
+ 43,
24982
+ 36,
24983
+ 29,
24984
+ 22,
24985
+ 15,
24986
+ 23,
24987
+ 30,
24988
+ 37,
24989
+ 44,
24990
+ 51,
24991
+ 58,
24992
+ 59,
24993
+ 52,
24994
+ 45,
24995
+ 38,
24996
+ 31,
24997
+ 39,
24998
+ 46,
24999
+ 53,
25000
+ 60,
25001
+ 61,
25002
+ 54,
25003
+ 47,
25004
+ 55,
25005
+ 62,
25006
+ 63
25007
+ ];
25008
+ var LUMA_QUANT = [
25009
+ 16,
25010
+ 11,
25011
+ 10,
25012
+ 16,
25013
+ 24,
25014
+ 40,
25015
+ 51,
25016
+ 61,
25017
+ 12,
25018
+ 12,
25019
+ 14,
25020
+ 19,
25021
+ 26,
25022
+ 58,
25023
+ 60,
25024
+ 55,
25025
+ 14,
25026
+ 13,
25027
+ 16,
25028
+ 24,
25029
+ 40,
25030
+ 57,
25031
+ 69,
25032
+ 56,
25033
+ 14,
25034
+ 17,
25035
+ 22,
25036
+ 29,
25037
+ 51,
25038
+ 87,
25039
+ 80,
25040
+ 62,
25041
+ 18,
25042
+ 22,
25043
+ 37,
25044
+ 56,
25045
+ 68,
25046
+ 109,
25047
+ 103,
25048
+ 77,
25049
+ 24,
25050
+ 35,
25051
+ 55,
25052
+ 64,
25053
+ 81,
25054
+ 104,
25055
+ 113,
25056
+ 92,
25057
+ 49,
25058
+ 64,
25059
+ 78,
25060
+ 87,
25061
+ 103,
25062
+ 121,
25063
+ 120,
25064
+ 101,
25065
+ 72,
25066
+ 92,
25067
+ 95,
25068
+ 98,
25069
+ 112,
25070
+ 100,
25071
+ 103,
25072
+ 99
25073
+ ];
25074
+ var CHROMA_QUANT = [
25075
+ 17,
25076
+ 18,
25077
+ 24,
25078
+ 47,
25079
+ 99,
25080
+ 99,
25081
+ 99,
25082
+ 99,
25083
+ 18,
25084
+ 21,
25085
+ 26,
25086
+ 66,
25087
+ 99,
25088
+ 99,
25089
+ 99,
25090
+ 99,
25091
+ 24,
25092
+ 26,
25093
+ 56,
25094
+ 99,
25095
+ 99,
25096
+ 99,
25097
+ 99,
25098
+ 99,
25099
+ 47,
25100
+ 66,
25101
+ 99,
25102
+ 99,
25103
+ 99,
25104
+ 99,
25105
+ 99,
25106
+ 99,
25107
+ 99,
25108
+ 99,
25109
+ 99,
25110
+ 99,
25111
+ 99,
25112
+ 99,
25113
+ 99,
25114
+ 99,
25115
+ 99,
25116
+ 99,
25117
+ 99,
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
+ ];
25140
+ 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] };
25141
+ 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] };
25142
+ var AC_LUMA = {
25143
+ bits: [0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125],
25144
+ values: [
25145
+ 1,
25146
+ 2,
25147
+ 3,
25148
+ 0,
25149
+ 4,
25150
+ 17,
25151
+ 5,
25152
+ 18,
25153
+ 33,
25154
+ 49,
25155
+ 65,
25156
+ 6,
25157
+ 19,
25158
+ 81,
25159
+ 97,
25160
+ 7,
25161
+ 34,
25162
+ 113,
25163
+ 20,
25164
+ 50,
25165
+ 129,
25166
+ 145,
25167
+ 161,
25168
+ 8,
25169
+ 35,
25170
+ 66,
25171
+ 177,
25172
+ 193,
25173
+ 21,
25174
+ 82,
25175
+ 209,
25176
+ 240,
25177
+ 36,
25178
+ 51,
25179
+ 98,
25180
+ 114,
25181
+ 130,
25182
+ 9,
25183
+ 10,
25184
+ 22,
25185
+ 23,
25186
+ 24,
25187
+ 25,
25188
+ 26,
25189
+ 37,
25190
+ 38,
25191
+ 39,
25192
+ 40,
25193
+ 41,
25194
+ 42,
25195
+ 52,
25196
+ 53,
25197
+ 54,
25198
+ 55,
25199
+ 56,
25200
+ 57,
25201
+ 58,
25202
+ 67,
25203
+ 68,
25204
+ 69,
25205
+ 70,
25206
+ 71,
25207
+ 72,
25208
+ 73,
25209
+ 74,
25210
+ 83,
25211
+ 84,
25212
+ 85,
25213
+ 86,
25214
+ 87,
25215
+ 88,
25216
+ 89,
25217
+ 90,
25218
+ 99,
25219
+ 100,
25220
+ 101,
25221
+ 102,
25222
+ 103,
25223
+ 104,
25224
+ 105,
25225
+ 106,
25226
+ 115,
25227
+ 116,
25228
+ 117,
25229
+ 118,
25230
+ 119,
25231
+ 120,
25232
+ 121,
25233
+ 122,
25234
+ 131,
25235
+ 132,
25236
+ 133,
25237
+ 134,
25238
+ 135,
25239
+ 136,
25240
+ 137,
25241
+ 138,
25242
+ 146,
25243
+ 147,
25244
+ 148,
25245
+ 149,
25246
+ 150,
25247
+ 151,
25248
+ 152,
25249
+ 153,
25250
+ 154,
25251
+ 162,
25252
+ 163,
25253
+ 164,
25254
+ 165,
25255
+ 166,
25256
+ 167,
25257
+ 168,
25258
+ 169,
25259
+ 170,
25260
+ 178,
25261
+ 179,
25262
+ 180,
25263
+ 181,
25264
+ 182,
25265
+ 183,
25266
+ 184,
25267
+ 185,
25268
+ 186,
25269
+ 194,
25270
+ 195,
25271
+ 196,
25272
+ 197,
25273
+ 198,
25274
+ 199,
25275
+ 200,
25276
+ 201,
25277
+ 202,
25278
+ 210,
25279
+ 211,
25280
+ 212,
25281
+ 213,
25282
+ 214,
25283
+ 215,
25284
+ 216,
25285
+ 217,
25286
+ 218,
25287
+ 225,
25288
+ 226,
25289
+ 227,
25290
+ 228,
25291
+ 229,
25292
+ 230,
25293
+ 231,
25294
+ 232,
25295
+ 233,
25296
+ 234,
25297
+ 241,
25298
+ 242,
25299
+ 243,
25300
+ 244,
25301
+ 245,
25302
+ 246,
25303
+ 247,
25304
+ 248,
25305
+ 249,
25306
+ 250
25307
+ ]
25308
+ };
25309
+ var AC_CHROMA = {
25310
+ bits: [0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119],
25311
+ values: [
25312
+ 0,
25313
+ 1,
25314
+ 2,
25315
+ 3,
25316
+ 17,
25317
+ 4,
25318
+ 5,
25319
+ 33,
25320
+ 49,
25321
+ 6,
25322
+ 18,
25323
+ 65,
25324
+ 81,
25325
+ 7,
25326
+ 97,
25327
+ 113,
25328
+ 19,
25329
+ 34,
25330
+ 50,
25331
+ 129,
25332
+ 8,
25333
+ 20,
25334
+ 66,
25335
+ 145,
25336
+ 161,
25337
+ 177,
25338
+ 193,
25339
+ 9,
25340
+ 35,
25341
+ 51,
25342
+ 82,
25343
+ 240,
25344
+ 21,
25345
+ 98,
25346
+ 114,
25347
+ 209,
25348
+ 10,
25349
+ 22,
25350
+ 36,
25351
+ 52,
25352
+ 225,
25353
+ 37,
25354
+ 241,
25355
+ 23,
25356
+ 24,
25357
+ 25,
25358
+ 26,
25359
+ 38,
25360
+ 39,
25361
+ 40,
25362
+ 41,
25363
+ 42,
25364
+ 53,
25365
+ 54,
25366
+ 55,
25367
+ 56,
25368
+ 57,
25369
+ 58,
25370
+ 67,
25371
+ 68,
25372
+ 69,
25373
+ 70,
25374
+ 71,
25375
+ 72,
25376
+ 73,
25377
+ 74,
25378
+ 83,
25379
+ 84,
25380
+ 85,
25381
+ 86,
25382
+ 87,
25383
+ 88,
25384
+ 89,
25385
+ 90,
25386
+ 99,
25387
+ 100,
25388
+ 101,
25389
+ 102,
25390
+ 103,
25391
+ 104,
25392
+ 105,
25393
+ 106,
25394
+ 115,
25395
+ 116,
25396
+ 117,
25397
+ 118,
25398
+ 119,
25399
+ 120,
25400
+ 121,
25401
+ 122,
25402
+ 130,
25403
+ 131,
25404
+ 132,
25405
+ 133,
25406
+ 134,
25407
+ 135,
25408
+ 136,
25409
+ 137,
25410
+ 138,
25411
+ 146,
25412
+ 147,
25413
+ 148,
25414
+ 149,
25415
+ 150,
25416
+ 151,
25417
+ 152,
25418
+ 153,
25419
+ 154,
25420
+ 162,
25421
+ 163,
25422
+ 164,
25423
+ 165,
25424
+ 166,
25425
+ 167,
25426
+ 168,
25427
+ 169,
25428
+ 170,
25429
+ 178,
25430
+ 179,
25431
+ 180,
25432
+ 181,
25433
+ 182,
25434
+ 183,
25435
+ 184,
25436
+ 185,
25437
+ 186,
25438
+ 194,
25439
+ 195,
25440
+ 196,
25441
+ 197,
25442
+ 198,
25443
+ 199,
25444
+ 200,
25445
+ 201,
25446
+ 202,
25447
+ 210,
25448
+ 211,
25449
+ 212,
25450
+ 213,
25451
+ 214,
25452
+ 215,
25453
+ 216,
25454
+ 217,
25455
+ 218,
25456
+ 226,
25457
+ 227,
25458
+ 228,
25459
+ 229,
25460
+ 230,
25461
+ 231,
25462
+ 232,
25463
+ 233,
25464
+ 234,
25465
+ 242,
25466
+ 243,
25467
+ 244,
25468
+ 245,
25469
+ 246,
25470
+ 247,
25471
+ 248,
25472
+ 249,
25473
+ 250
25474
+ ]
25475
+ };
25476
+ function buildCodes(spec) {
25477
+ const code = new Uint16Array(256);
25478
+ const size = new Uint8Array(256);
25479
+ let next = 0;
25480
+ let k = 0;
25481
+ for (let len = 1; len <= 16; len++) {
25482
+ for (let i = 0; i < spec.bits[len - 1]; i++) {
25483
+ const symbol = spec.values[k++];
25484
+ code[symbol] = next++;
25485
+ size[symbol] = len;
25486
+ }
25487
+ next <<= 1;
25488
+ }
25489
+ return { code, size };
25490
+ }
25491
+ function scaleQuant(base, quality) {
25492
+ const q = Math.min(100, Math.max(1, Math.round(quality * 100)));
25493
+ const scale = q < 50 ? Math.floor(5e3 / q) : 200 - q * 2;
25494
+ return Uint8Array.from(base, (v) => Math.min(255, Math.max(1, Math.floor((v * scale + 50) / 100))));
25495
+ }
25496
+ var COS = (() => {
25497
+ const t = new Float64Array(64);
25498
+ for (let u = 0; u < 8; u++) {
25499
+ const c = u === 0 ? Math.SQRT1_2 : 1;
25500
+ for (let x = 0; x < 8; x++) {
25501
+ t[u * 8 + x] = c / 2 * Math.cos((2 * x + 1) * u * Math.PI / 16);
25502
+ }
25503
+ }
25504
+ return t;
25505
+ })();
25506
+ function fdctQuantize(block, quant, out, tmp) {
25507
+ for (let y = 0; y < 8; y++) {
25508
+ for (let u = 0; u < 8; u++) {
25509
+ let s = 0;
25510
+ for (let x = 0; x < 8; x++) s += COS[u * 8 + x] * block[y * 8 + x];
25511
+ tmp[y * 8 + u] = s;
25512
+ }
25513
+ }
25514
+ for (let k = 0; k < 64; k++) {
25515
+ const n = ZIGZAG2[k];
25516
+ const v = n >> 3;
25517
+ const u = n & 7;
25518
+ let s = 0;
25519
+ for (let y = 0; y < 8; y++) s += COS[v * 8 + y] * tmp[y * 8 + u];
25520
+ out[k] = Math.round(s / quant[n]);
25521
+ }
25522
+ }
25523
+ var BitWriter = class {
25524
+ constructor() {
25525
+ this.buf = new Uint8Array(4096);
25526
+ this.length = 0;
25527
+ this.acc = 0;
25528
+ this.count = 0;
25529
+ }
25530
+ byte(b) {
25531
+ if (this.length === this.buf.length) {
25532
+ const grown = new Uint8Array(this.buf.length * 2);
25533
+ grown.set(this.buf);
25534
+ this.buf = grown;
25535
+ }
25536
+ this.buf[this.length++] = b;
25537
+ }
25538
+ bits(value, size) {
25539
+ for (let i = size - 1; i >= 0; i--) {
25540
+ this.acc = this.acc << 1 | value >> i & 1;
25541
+ if (++this.count === 8) {
25542
+ this.byte(this.acc);
25543
+ if (this.acc === 255) this.byte(0);
25544
+ this.acc = 0;
25545
+ this.count = 0;
25546
+ }
25547
+ }
25548
+ }
25549
+ /** Pads the last byte with 1 bits and returns the segment. */
25550
+ finish() {
25551
+ if (this.count > 0) this.bits((1 << 8 - this.count) - 1, 8 - this.count);
25552
+ return this.buf.subarray(0, this.length);
25553
+ }
25554
+ };
25555
+ function category(v) {
25556
+ let a = v < 0 ? -v : v;
25557
+ let n = 0;
25558
+ while (a) {
25559
+ n++;
25560
+ a >>= 1;
25561
+ }
25562
+ return n;
25563
+ }
25564
+ function writeBlock(w, coef, prevDc, dc, ac) {
25565
+ const diff = coef[0] - prevDc;
25566
+ const dcSize = category(diff);
25567
+ w.bits(dc.code[dcSize], dc.size[dcSize]);
25568
+ if (dcSize) w.bits(diff < 0 ? diff - 1 : diff, dcSize);
25569
+ let run = 0;
25570
+ for (let k = 1; k < 64; k++) {
25571
+ const v = coef[k];
25572
+ if (v === 0) {
25573
+ run++;
25574
+ continue;
25575
+ }
25576
+ while (run > 15) {
25577
+ w.bits(ac.code[240], ac.size[240]);
25578
+ run -= 16;
25579
+ }
25580
+ const size = category(v);
25581
+ const symbol = run << 4 | size;
25582
+ w.bits(ac.code[symbol], ac.size[symbol]);
25583
+ w.bits(v < 0 ? v - 1 : v, size);
25584
+ run = 0;
25585
+ }
25586
+ if (run > 0) w.bits(ac.code[0], ac.size[0]);
25587
+ return coef[0];
25588
+ }
25589
+ function segment(marker, payload) {
25590
+ const len = payload.length + 2;
25591
+ return [255, marker, len >> 8, len & 255, ...payload];
25592
+ }
25593
+ function dhtPayload(tableClass, id, spec) {
25594
+ return [tableClass << 4 | id, ...spec.bits, ...spec.values];
25595
+ }
25596
+ function encodeJpeg(data, width, height, options2 = {}) {
25597
+ if (!(width >= 1 && height >= 1 && width <= 65535 && height <= 65535)) {
25598
+ throw new RangeError(`JPEG dimensions out of range: ${width}x${height}`);
25599
+ }
25600
+ const quality = Number.isFinite(options2.quality) ? Math.min(1, Math.max(0, options2.quality)) : DEFAULT_JPEG_QUALITY;
25601
+ const [bgR, bgG, bgB] = options2.background ?? [255, 255, 255];
25602
+ const sub = options2.chromaSubsampling ?? false;
25603
+ const lumaQuant = scaleQuant(LUMA_QUANT, quality);
25604
+ const chromaQuant = scaleQuant(CHROMA_QUANT, quality);
25605
+ const n = width * height;
25606
+ const Y = new Float64Array(n);
25607
+ const Cb = new Float64Array(n);
25608
+ const Cr = new Float64Array(n);
25609
+ for (let i = 0; i < n; i++) {
25610
+ const a = data[i * 4 + 3] / 255;
25611
+ const r = data[i * 4] * a + bgR * (1 - a);
25612
+ const g = data[i * 4 + 1] * a + bgG * (1 - a);
25613
+ const b = data[i * 4 + 2] * a + bgB * (1 - a);
25614
+ Y[i] = 0.299 * r + 0.587 * g + 0.114 * b;
25615
+ Cb[i] = -0.168736 * r - 0.331264 * g + 0.5 * b + 128;
25616
+ Cr[i] = 0.5 * r - 0.418688 * g - 0.081312 * b + 128;
25617
+ }
25618
+ const dcL = buildCodes(DC_LUMA);
25619
+ const acL = buildCodes(AC_LUMA);
25620
+ const dcC = buildCodes(DC_CHROMA);
25621
+ const acC = buildCodes(AC_CHROMA);
25622
+ const factor = sub ? 2 : 1;
25623
+ const mcu = 8 * factor;
25624
+ const block = new Float64Array(64);
25625
+ const tmp = new Float64Array(64);
25626
+ const coef = new Int32Array(64);
25627
+ const w = new BitWriter();
25628
+ let dcY = 0;
25629
+ let dcCb = 0;
25630
+ let dcCr = 0;
25631
+ const lumaBlock = (x0, y0) => {
25632
+ for (let y = 0; y < 8; y++) {
25633
+ const row2 = Math.min(height - 1, y0 + y) * width;
25634
+ for (let x = 0; x < 8; x++) block[y * 8 + x] = Y[row2 + Math.min(width - 1, x0 + x)] - 128;
25635
+ }
25636
+ };
25637
+ const chromaBlock = (plane, x0, y0) => {
25638
+ for (let y = 0; y < 8; y++) {
25639
+ for (let x = 0; x < 8; x++) {
25640
+ let s = 0;
25641
+ for (let dy = 0; dy < factor; dy++) {
25642
+ const row2 = Math.min(height - 1, y0 + y * factor + dy) * width;
25643
+ for (let dx = 0; dx < factor; dx++) s += plane[row2 + Math.min(width - 1, x0 + x * factor + dx)];
25644
+ }
25645
+ block[y * 8 + x] = s / (factor * factor) - 128;
25646
+ }
25647
+ }
25648
+ };
25649
+ for (let my = 0; my < height; my += mcu) {
25650
+ for (let mx = 0; mx < width; mx += mcu) {
25651
+ for (let by = 0; by < factor; by++) {
25652
+ for (let bx = 0; bx < factor; bx++) {
25653
+ lumaBlock(mx + bx * 8, my + by * 8);
25654
+ fdctQuantize(block, lumaQuant, coef, tmp);
25655
+ dcY = writeBlock(w, coef, dcY, dcL, acL);
25656
+ }
25657
+ }
25658
+ chromaBlock(Cb, mx, my);
25659
+ fdctQuantize(block, chromaQuant, coef, tmp);
25660
+ dcCb = writeBlock(w, coef, dcCb, dcC, acC);
25661
+ chromaBlock(Cr, mx, my);
25662
+ fdctQuantize(block, chromaQuant, coef, tmp);
25663
+ dcCr = writeBlock(w, coef, dcCr, dcC, acC);
25664
+ }
25665
+ }
25666
+ const scan = w.finish();
25667
+ const sampling = factor << 4 | factor;
25668
+ const header = [
25669
+ 255,
25670
+ 216,
25671
+ // APP0 JFIF 1.01, no density (aspect ratio 1:1), no thumbnail.
25672
+ ...segment(224, [74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0]),
25673
+ ...segment(219, [0, ...ZIGZAG2.map((i) => lumaQuant[i]), 1, ...ZIGZAG2.map((i) => chromaQuant[i])]),
25674
+ ...segment(192, [8, height >> 8, height & 255, width >> 8, width & 255, 3, 1, sampling, 0, 2, 17, 1, 3, 17, 1]),
25675
+ ...segment(196, [...dhtPayload(0, 0, DC_LUMA), ...dhtPayload(1, 0, AC_LUMA), ...dhtPayload(0, 1, DC_CHROMA), ...dhtPayload(1, 1, AC_CHROMA)]),
25676
+ ...segment(218, [3, 1, 0, 2, 17, 3, 17, 0, 63, 0])
25677
+ ];
25678
+ const out = new Uint8Array(header.length + scan.length + 2);
25679
+ out.set(header, 0);
25680
+ out.set(scan, header.length);
25681
+ out[out.length - 2] = 255;
25682
+ out[out.length - 1] = 217;
25683
+ return out;
25684
+ }
25685
+
24939
25686
  // src/fnt-font.ts
24940
25687
  function parseFnt(view, base, end) {
24941
25688
  if (base + 118 > end) {
@@ -36050,6 +36797,20 @@ function handleEmfGdiBlendBlitRecord(rCtx, recType, offset, dataOff, recSize) {
36050
36797
 
36051
36798
  // src/emf-ansi-tables.ts
36052
36799
  var OEM437_HIGH = "\xC7\xFC\xE9\xE2\xE4\xE0\xE5\xE7\xEA\xEB\xE8\xEF\xEE\xEC\xC4\xC5\xC9\xE6\xC6\xF4\xF6\xF2\xFB\xF9\xFF\xD6\xDC\xA2\xA3\xA5\u20A7\u0192\xE1\xED\xF3\xFA\xF1\xD1\xAA\xBA\xBF\u2310\xAC\xBD\xBC\xA1\xAB\xBB\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\xDF\u0393\u03C0\u03A3\u03C3\xB5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\xB1\u2265\u2264\u2320\u2321\xF7\u2248\xB0\u2219\xB7\u221A\u207F\xB2\u25A0\xA0";
36800
+ var OEM_HIGH = {
36801
+ 737: "\u0391\u0392\u0393\u0394\u0395\u0396\u0397\u0398\u0399\u039A\u039B\u039C\u039D\u039E\u039F\u03A0\u03A1\u03A3\u03A4\u03A5\u03A6\u03A7\u03A8\u03A9\u03B1\u03B2\u03B3\u03B4\u03B5\u03B6\u03B7\u03B8\u03B9\u03BA\u03BB\u03BC\u03BD\u03BE\u03BF\u03C0\u03C1\u03C3\u03C2\u03C4\u03C5\u03C6\u03C7\u03C8\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03C9\u03AC\u03AD\u03AE\u03CA\u03AF\u03CC\u03CD\u03CB\u03CE\u0386\u0388\u0389\u038A\u038C\u038E\u038F\xB1\u2265\u2264\u03AA\u03AB\xF7\u2248\xB0\u2219\xB7\u221A\u207F\xB2\u25A0\xA0",
36802
+ 775: "\u0106\xFC\xE9\u0101\xE4\u0123\xE5\u0107\u0142\u0113\u0156\u0157\u012B\u0179\xC4\xC5\xC9\xE6\xC6\u014D\xF6\u0122\xA2\u015A\u015B\xD6\xDC\xF8\xA3\xD8\xD7\xA4\u0100\u012A\xF3\u017B\u017C\u017A\u201D\xA6\xA9\xAE\xAC\xBD\xBC\u0141\xAB\xBB\u2591\u2592\u2593\u2502\u2524\u0104\u010C\u0118\u0116\u2563\u2551\u2557\u255D\u012E\u0160\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u0172\u016A\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u017D\u0105\u010D\u0119\u0117\u012F\u0161\u0173\u016B\u017E\u2518\u250C\u2588\u2584\u258C\u2590\u2580\xD3\xDF\u014C\u0143\xF5\xD5\xB5\u0144\u0136\u0137\u013B\u013C\u0146\u0112\u0145\u2019\xAD\xB1\u201C\xBE\xB6\xA7\xF7\u201E\xB0\u2219\xB7\xB9\xB3\xB2\u25A0\xA0",
36803
+ 850: "\xC7\xFC\xE9\xE2\xE4\xE0\xE5\xE7\xEA\xEB\xE8\xEF\xEE\xEC\xC4\xC5\xC9\xE6\xC6\xF4\xF6\xF2\xFB\xF9\xFF\xD6\xDC\xF8\xA3\xD8\xD7\u0192\xE1\xED\xF3\xFA\xF1\xD1\xAA\xBA\xBF\xAE\xAC\xBD\xBC\xA1\xAB\xBB\u2591\u2592\u2593\u2502\u2524\xC1\xC2\xC0\xA9\u2563\u2551\u2557\u255D\xA2\xA5\u2510\u2514\u2534\u252C\u251C\u2500\u253C\xE3\xC3\u255A\u2554\u2569\u2566\u2560\u2550\u256C\xA4\xF0\xD0\xCA\xCB\xC8\u0131\xCD\xCE\xCF\u2518\u250C\u2588\u2584\xA6\xCC\u2580\xD3\xDF\xD4\xD2\xF5\xD5\xB5\xFE\xDE\xDA\xDB\xD9\xFD\xDD\xAF\xB4\xAD\xB1\u2017\xBE\xB6\xA7\xF7\xB8\xB0\xA8\xB7\xB9\xB3\xB2\u25A0\xA0",
36804
+ 852: "\xC7\xFC\xE9\xE2\xE4\u016F\u0107\xE7\u0142\xEB\u0150\u0151\xEE\u0179\xC4\u0106\xC9\u0139\u013A\xF4\xF6\u013D\u013E\u015A\u015B\xD6\xDC\u0164\u0165\u0141\xD7\u010D\xE1\xED\xF3\xFA\u0104\u0105\u017D\u017E\u0118\u0119\xAC\u017A\u010C\u015F\xAB\xBB\u2591\u2592\u2593\u2502\u2524\xC1\xC2\u011A\u015E\u2563\u2551\u2557\u255D\u017B\u017C\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u0102\u0103\u255A\u2554\u2569\u2566\u2560\u2550\u256C\xA4\u0111\u0110\u010E\xCB\u010F\u0147\xCD\xCE\u011B\u2518\u250C\u2588\u2584\u0162\u016E\u2580\xD3\xDF\xD4\u0143\u0144\u0148\u0160\u0161\u0154\xDA\u0155\u0170\xFD\xDD\u0163\xB4\xAD\u02DD\u02DB\u02C7\u02D8\xA7\xF7\xB8\xB0\xA8\u02D9\u0171\u0158\u0159\u25A0\xA0",
36805
+ 855: "\u0452\u0402\u0453\u0403\u0451\u0401\u0454\u0404\u0455\u0405\u0456\u0406\u0457\u0407\u0458\u0408\u0459\u0409\u045A\u040A\u045B\u040B\u045C\u040C\u045E\u040E\u045F\u040F\u044E\u042E\u044A\u042A\u0430\u0410\u0431\u0411\u0446\u0426\u0434\u0414\u0435\u0415\u0444\u0424\u0433\u0413\xAB\xBB\u2591\u2592\u2593\u2502\u2524\u0445\u0425\u0438\u0418\u2563\u2551\u2557\u255D\u0439\u0419\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u043A\u041A\u255A\u2554\u2569\u2566\u2560\u2550\u256C\xA4\u043B\u041B\u043C\u041C\u043D\u041D\u043E\u041E\u043F\u2518\u250C\u2588\u2584\u041F\u044F\u2580\u042F\u0440\u0420\u0441\u0421\u0442\u0422\u0443\u0423\u0436\u0416\u0432\u0412\u044C\u042C\u2116\xAD\u044B\u042B\u0437\u0417\u0448\u0428\u044D\u042D\u0449\u0429\u0447\u0427\xA7\u25A0\xA0",
36806
+ 858: "\xC7\xFC\xE9\xE2\xE4\xE0\xE5\xE7\xEA\xEB\xE8\xEF\xEE\xEC\xC4\xC5\xC9\xE6\xC6\xF4\xF6\xF2\xFB\xF9\xFF\xD6\xDC\xF8\xA3\xD8\xD7\u0192\xE1\xED\xF3\xFA\xF1\xD1\xAA\xBA\xBF\xAE\xAC\xBD\xBC\xA1\xAB\xBB\u2591\u2592\u2593\u2502\u2524\xC1\xC2\xC0\xA9\u2563\u2551\u2557\u255D\xA2\xA5\u2510\u2514\u2534\u252C\u251C\u2500\u253C\xE3\xC3\u255A\u2554\u2569\u2566\u2560\u2550\u256C\xA4\xF0\xD0\xCA\xCB\xC8\u20AC\xCD\xCE\xCF\u2518\u250C\u2588\u2584\xA6\xCC\u2580\xD3\xDF\xD4\xD2\xF5\xD5\xB5\xFE\xDE\xDA\xDB\xD9\xFD\xDD\xAF\xB4\xAD\xB1\u2017\xBE\xB6\xA7\xF7\xB8\xB0\xA8\xB7\xB9\xB3\xB2\u25A0\xA0",
36807
+ 860: "\xC7\xFC\xE9\xE2\xE3\xE0\xC1\xE7\xEA\xCA\xE8\xCD\xD4\xEC\xC3\xC2\xC9\xC0\xC8\xF4\xF5\xF2\xDA\xF9\xCC\xD5\xDC\xA2\xA3\xD9\u20A7\xD3\xE1\xED\xF3\xFA\xF1\xD1\xAA\xBA\xBF\xD2\xAC\xBD\xBC\xA1\xAB\xBB\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\xDF\u0393\u03C0\u03A3\u03C3\xB5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\xB1\u2265\u2264\u2320\u2321\xF7\u2248\xB0\u2219\xB7\u221A\u207F\xB2\u25A0\xA0",
36808
+ 861: "\xC7\xFC\xE9\xE2\xE4\xE0\xE5\xE7\xEA\xEB\xE8\xD0\xF0\xDE\xC4\xC5\xC9\xE6\xC6\xF4\xF6\xFE\xFB\xDD\xFD\xD6\xDC\xF8\xA3\xD8\u20A7\u0192\xE1\xED\xF3\xFA\xC1\xCD\xD3\xDA\xBF\u2310\xAC\xBD\xBC\xA1\xAB\xBB\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\xDF\u0393\u03C0\u03A3\u03C3\xB5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\xB1\u2265\u2264\u2320\u2321\xF7\u2248\xB0\u2219\xB7\u221A\u207F\xB2\u25A0\xA0",
36809
+ 862: "\u05D0\u05D1\u05D2\u05D3\u05D4\u05D5\u05D6\u05D7\u05D8\u05D9\u05DA\u05DB\u05DC\u05DD\u05DE\u05DF\u05E0\u05E1\u05E2\u05E3\u05E4\u05E5\u05E6\u05E7\u05E8\u05E9\u05EA\xA2\xA3\xA5\u20A7\u0192\xE1\xED\xF3\xFA\xF1\xD1\xAA\xBA\xBF\u2310\xAC\xBD\xBC\xA1\xAB\xBB\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\xDF\u0393\u03C0\u03A3\u03C3\xB5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\xB1\u2265\u2264\u2320\u2321\xF7\u2248\xB0\u2219\xB7\u221A\u207F\xB2\u25A0\xA0",
36810
+ 863: "\xC7\xFC\xE9\xE2\xC2\xE0\xB6\xE7\xEA\xEB\xE8\xEF\xEE\u2017\xC0\xA7\xC9\xC8\xCA\xF4\xCB\xCF\xFB\xF9\xA4\xD4\xDC\xA2\xA3\xD9\xDB\u0192\xA6\xB4\xF3\xFA\xA8\xB8\xB3\xAF\xCE\u2310\xAC\xBD\xBC\xBE\xAB\xBB\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\xDF\u0393\u03C0\u03A3\u03C3\xB5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\xB1\u2265\u2264\u2320\u2321\xF7\u2248\xB0\u2219\xB7\u221A\u207F\xB2\u25A0\xA0",
36811
+ 865: "\xC7\xFC\xE9\xE2\xE4\xE0\xE5\xE7\xEA\xEB\xE8\xEF\xEE\xEC\xC4\xC5\xC9\xE6\xC6\xF4\xF6\xF2\xFB\xF9\xFF\xD6\xDC\xF8\xA3\xD8\u20A7\u0192\xE1\xED\xF3\xFA\xF1\xD1\xAA\xBA\xBF\u2310\xAC\xBD\xBC\xA1\xAB\xA4\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\xDF\u0393\u03C0\u03A3\u03C3\xB5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\xB1\u2265\u2264\u2320\u2321\xF7\u2248\xB0\u2219\xB7\u221A\u207F\xB2\u25A0\xA0",
36812
+ 866: "\u0410\u0411\u0412\u0413\u0414\u0415\u0416\u0417\u0418\u0419\u041A\u041B\u041C\u041D\u041E\u041F\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042A\u042B\u042C\u042D\u042E\u042F\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043A\u043B\u043C\u043D\u043E\u043F\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044A\u044B\u044C\u044D\u044E\u044F\u0401\u0451\u0404\u0454\u0407\u0457\u040E\u045E\xB0\u2219\xB7\u221A\u2116\xA4\u25A0\xA0"
36813
+ };
36053
36814
  var JOHAB_ROWS = {
36054
36815
  132: "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u11A8\u11A9\u11AA\u11AB\u11AC\u11AD\u11AE\u11AF\u11B0\u11B1\u11B2\u11B3\u11B4\u11B5\u11B6\u11B7\uFFFD\u11B8\u11B9\u11BA\u11BB\u11BC\u11BD\u11BE\u11BF\u11C0\u11C1\u11C2\uFFFD\uFFFD\uFFFD\u1161\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u1162\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u1163\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u1164\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u1165\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD",
36055
36816
  133: "\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u1166\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u1167\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u1168\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u1169\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u116A\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u116B\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD",
@@ -36242,12 +37003,23 @@ var ANSI_CODE_PAGE_ENCODING = {
36242
37003
  54936: "gb18030",
36243
37004
  65001: "utf-8"
36244
37005
  };
36245
- function decodeAnsiRecord(bytes, charSet, ansiCodePage) {
37006
+ var OEM_CODE_PAGE_ENCODING = {
37007
+ 874: "windows-874",
37008
+ 932: "shift_jis",
37009
+ 936: "gbk",
37010
+ 949: "euc-kr",
37011
+ 950: "big5"
37012
+ };
37013
+ function decodeOemTable(bytes, high) {
37014
+ return { codes: bytes.map((b) => b < 128 ? b : high.charCodeAt(b - 128)), byteLengths: bytes.map(() => 1) };
37015
+ }
37016
+ function decodeAnsiRecord(bytes, charSet, codePages) {
36246
37017
  if (charSet === 2) {
36247
37018
  return { codes: [...bytes], byteLengths: bytes.map(() => 1) };
36248
37019
  }
36249
- if (charSet === 255) {
36250
- return { codes: bytes.map((b) => b < 128 ? b : OEM437_HIGH.charCodeAt(b - 128)), byteLengths: bytes.map(() => 1) };
37020
+ const oemCodePage = codePages?.oem;
37021
+ if (charSet === 255 && (oemCodePage === void 0 || !(oemCodePage in OEM_CODE_PAGE_ENCODING))) {
37022
+ return decodeOemTable(bytes, (oemCodePage !== void 0 ? OEM_HIGH[oemCodePage] : void 0) ?? OEM437_HIGH);
36251
37023
  }
36252
37024
  if (charSet === 130) {
36253
37025
  const codes = [];
@@ -36263,7 +37035,8 @@ function decodeAnsiRecord(bytes, charSet, ansiCodePage) {
36263
37035
  }
36264
37036
  return { codes, byteLengths };
36265
37037
  }
36266
- const label = (charSet === 0 || charSet === 1) && ansiCodePage !== void 0 ? ANSI_CODE_PAGE_ENCODING[ansiCodePage] ?? "windows-1252" : CHARSET_ENCODING[charSet] ?? "windows-1252";
37038
+ const ansiCodePage = codePages?.ansi;
37039
+ const label = charSet === 255 && oemCodePage !== void 0 ? OEM_CODE_PAGE_ENCODING[oemCodePage] : (charSet === 0 || charSet === 1) && ansiCodePage !== void 0 ? ANSI_CODE_PAGE_ENCODING[ansiCodePage] ?? "windows-1252" : CHARSET_ENCODING[charSet] ?? "windows-1252";
36267
37040
  if (label === "windows-1252") {
36268
37041
  return { codes: bytes.map((b) => ansiToCode(b, charSet)), byteLengths: bytes.map(() => 1) };
36269
37042
  }
@@ -37083,8 +37856,9 @@ function drawTextCall(rCtx, x, y, codes, options2, rect, dx) {
37083
37856
  const child = { ...rCtx, view };
37084
37857
  handleExtTextOutW(child, 0, 8, size);
37085
37858
  }
37086
- function readAnsiRecord(view, start, count, charSet) {
37087
- return decodeAnsiRecord(Array.from({ length: count }, (_, i) => view.getUint8(start + i)), charSet);
37859
+ function readAnsiRecord(rCtx, start, count, charSet) {
37860
+ const { view } = rCtx;
37861
+ return decodeAnsiRecord(Array.from({ length: count }, (_, i) => view.getUint8(start + i)), charSet, rCtx.codePages);
37088
37862
  }
37089
37863
  function collapseAnsiDx(dx, byteLengths, pdy) {
37090
37864
  if (!dx) return null;
@@ -37119,7 +37893,7 @@ function handlePolyText(rCtx, offset, dataOff, recSize, wide) {
37119
37893
  const offDx = view.getUint32(e + 36, true);
37120
37894
  const unit = wide ? 2 : 1;
37121
37895
  if (!offString || offString > end - offset || n > Math.floor((end - (offset + offString)) / unit)) continue;
37122
- const ansi = wide ? null : readAnsiRecord(view, offset + offString, n, charSet);
37896
+ const ansi = wide ? null : readAnsiRecord(rCtx, offset + offString, n, charSet);
37123
37897
  const codes = wide ? Array.from({ length: n }, (_, j) => view.getUint16(offset + offString + j * 2, true)) : ansi.codes;
37124
37898
  let dx = null;
37125
37899
  const pdy = (options2 & ETO_PDY) !== 0;
@@ -37160,7 +37934,7 @@ function handleEmfGdiDrawTextRecord(rCtx, recType, offset, dataOff, recSize) {
37160
37934
  const n = view.getUint32(dataOff + 36, true), strOff = view.getUint32(dataOff + 40, true), options2 = view.getUint32(dataOff + 44, true);
37161
37935
  if (!strOff || strOff > end - offset) return true;
37162
37936
  if (n > end - (offset + strOff)) return true;
37163
- const ansi = readAnsiRecord(view, offset + strOff, n, state.fontDetails?.charSet ?? 1);
37937
+ const ansi = readAnsiRecord(rCtx, offset + strOff, n, state.fontDetails?.charSet ?? 1);
37164
37938
  const rect = [view.getInt32(dataOff + 48, true), view.getInt32(dataOff + 52, true), view.getInt32(dataOff + 56, true), view.getInt32(dataOff + 60, true)];
37165
37939
  const offDx = view.getUint32(dataOff + 64, true);
37166
37940
  let dx = null;
@@ -40915,6 +41689,7 @@ function replayEmfPlusRecords(view, offset, length, ctx, canvasW, canvasH, state
40915
41689
  imageCache: s.imageCache,
40916
41690
  nestingDepth: s.nestingDepth,
40917
41691
  gdiAntialias: s.gdiAntialias,
41692
+ codePages: s.codePages,
40918
41693
  antiAlias: s.antiAlias,
40919
41694
  ext: s.ext ?? (s.ext = {})
40920
41695
  };
@@ -41092,6 +41867,7 @@ function replayEmfRecords(view, ctx, bounds, canvasW, canvasH, dpiScale = 1, rep
41092
41867
  const plusScale = dpiScale > 0 ? dpiScale : 1;
41093
41868
  emfPlusState.imageCache = replayOptions.imageCache;
41094
41869
  emfPlusState.gdiAntialias = replayOptions.gdiAntialias;
41870
+ emfPlusState.codePages = replayOptions.codePages;
41095
41871
  emfPlusState.baseTransform = replayOptions.plusBaseTransform ?? [
41096
41872
  sx / plusScale,
41097
41873
  0,
@@ -41131,7 +41907,8 @@ function replayEmfRecords(view, ctx, bounds, canvasW, canvasH, dpiScale = 1, rep
41131
41907
  sy,
41132
41908
  pathCmds: [],
41133
41909
  gdiAntialias: replayOptions.gdiAntialias,
41134
- fonts: replayOptions.fonts
41910
+ fonts: replayOptions.fonts,
41911
+ codePages: replayOptions.codePages
41135
41912
  };
41136
41913
  let offset = 0;
41137
41914
  const maxOffset = view.byteLength;
@@ -41536,7 +42313,7 @@ function createFont(p, dataOff, recSize, recEnd) {
41536
42313
  }
41537
42314
  faceBytes.push(ch);
41538
42315
  }
41539
- const family = String.fromCharCode(...decodeAnsiRecord(faceBytes, 1, p.ansiCodePage).codes);
42316
+ const family = String.fromCharCode(...decodeAnsiRecord(faceBytes, 1, { ansi: p.ansiCodePage }).codes);
41540
42317
  const font = {
41541
42318
  kind: "font",
41542
42319
  // Sign kept: resolveFontPixelHeight() tells cell from character height by it.
@@ -42563,7 +43340,7 @@ function drawWithFontEngine2(p, call, codes, dx) {
42563
43340
  }
42564
43341
  function playText(p, call) {
42565
43342
  const charSet = p.rCtx.state.fontDetails?.charSet ?? 1;
42566
- const { codes, byteLengths } = decodeAnsiRecord(call.bytes, charSet, p.ansiCodePage);
43343
+ const { codes, byteLengths } = decodeAnsiRecord(call.bytes, charSet, { ansi: p.ansiCodePage, oem: p.oemCodePage });
42567
43344
  const n = codes.length;
42568
43345
  if (n === 0) {
42569
43346
  return;
@@ -42695,7 +43472,8 @@ function createWmfPlayer(view, ctx, header, canvasW, canvasH, replayOptions = {}
42695
43472
  };
42696
43473
  const p = {
42697
43474
  rCtx,
42698
- ansiCodePage: replayOptions.wmfAnsiCodePage,
43475
+ ansiCodePage: replayOptions.wmfAnsiCodePage ?? replayOptions.codePages?.ansi,
43476
+ oemCodePage: replayOptions.codePages?.oem,
42699
43477
  view,
42700
43478
  kx,
42701
43479
  ky,
@@ -43194,6 +43972,7 @@ async function replayMetafile(buffer, options2, createSurface) {
43194
43972
  maxRecords: opts.maxRecords,
43195
43973
  maxRecordsEmfPlus: opts.maxRecords,
43196
43974
  fontFamilyMap: opts.fontFamilyMap,
43975
+ codePages: { ansi: opts.ansiCodePage, oem: opts.oemCodePage },
43197
43976
  textureCache,
43198
43977
  imageCache,
43199
43978
  gdiAntialias: opts.gdiAntialias,
@@ -43228,6 +44007,7 @@ async function replayMetafile(buffer, options2, createSurface) {
43228
44007
  replayWmfRecords(view, surface.ctx, header, surface.width, surface.height, {
43229
44008
  wmfReferenceDpi: opts.wmfReferenceDpi,
43230
44009
  wmfAnsiCodePage: opts.wmfAnsiCodePage,
44010
+ codePages: { ansi: opts.ansiCodePage, oem: opts.oemCodePage },
43231
44011
  maxRecords: opts.maxRecords,
43232
44012
  fontFamilyMap: opts.fontFamilyMap,
43233
44013
  gdiAntialias: opts.gdiAntialias,
@@ -43348,6 +44128,54 @@ async function processDeferredImages(ctx, deferredImages, recursionDepth) {
43348
44128
  return complete;
43349
44129
  }
43350
44130
  async function convertMetafileToDataUrl(buffer, options2, recursionDepth = 0) {
44131
+ const raster = await renderRaster(buffer, options2, recursionDepth, "convertMetafileToDataUrl");
44132
+ if (!raster) {
44133
+ return null;
44134
+ }
44135
+ try {
44136
+ const url = await exportCanvasToPngDataUrl(raster.canvas);
44137
+ if (!url) {
44138
+ emfWarn("convertMetafileToDataUrl: exportCanvasToPngDataUrl returned null");
44139
+ }
44140
+ return url;
44141
+ } catch (err) {
44142
+ emfWarn("convertMetafileToDataUrl: EXCEPTION:", err instanceof Error ? err.message : err);
44143
+ console.warn("[emf-converter] Conversion failed:", err instanceof Error ? err.message : err);
44144
+ return null;
44145
+ }
44146
+ }
44147
+ async function convertMetafileToJpegDataUrl(buffer, options2) {
44148
+ const raster = await renderRaster(buffer, options2, 0, "convertMetafileToJpegDataUrl");
44149
+ if (!raster) {
44150
+ return null;
44151
+ }
44152
+ try {
44153
+ const { canvas, ctx } = raster;
44154
+ const pixels = canvas instanceof SoftwareRasterCanvas ? canvas.pixels : canvasGetImageData(ctx, 0, 0, canvas.width, canvas.height).data;
44155
+ const jpeg = encodeJpeg(pixels, canvas.width, canvas.height, {
44156
+ quality: options2?.quality,
44157
+ background: parseBackground(options2?.background),
44158
+ chromaSubsampling: options2?.chromaSubsampling
44159
+ });
44160
+ return `data:image/jpeg;base64,${bytesToBase64(jpeg)}`;
44161
+ } catch (err) {
44162
+ emfWarn("convertMetafileToJpegDataUrl: EXCEPTION:", err instanceof Error ? err.message : err);
44163
+ console.warn("[emf-converter] Conversion failed:", err instanceof Error ? err.message : err);
44164
+ return null;
44165
+ }
44166
+ }
44167
+ function parseBackground(color) {
44168
+ if (color === void 0) {
44169
+ return [255, 255, 255];
44170
+ }
44171
+ const hex5 = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(color.trim())?.[1];
44172
+ if (!hex5) {
44173
+ return [255, 255, 255];
44174
+ }
44175
+ const full = hex5.length === 3 ? [...hex5].map((c) => c + c).join("") : hex5;
44176
+ return [0, 2, 4].map((i) => parseInt(full.slice(i, i + 2), 16));
44177
+ }
44178
+ async function renderRaster(buffer, options2, recursionDepth, caller) {
43351
44179
  await ensureNodeCanvasModule();
43352
44180
  if (recursionDepth > MAX_METAFILE_RECURSION) {
43353
44181
  return null;
@@ -43377,17 +44205,13 @@ async function convertMetafileToDataUrl(buffer, options2, recursionDepth = 0) {
43377
44205
  const soft = canvas instanceof SoftwareRasterCanvas ? canvas : null;
43378
44206
  if (soft && (soft.textDraws > 0 || !complete)) {
43379
44207
  emfWarn(
43380
- `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`
44208
+ `${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`
43381
44209
  );
43382
44210
  return null;
43383
44211
  }
43384
- const url = await exportCanvasToPngDataUrl(canvas);
43385
- if (!url) {
43386
- emfWarn("convertMetafileToDataUrl: exportCanvasToPngDataUrl returned null");
43387
- }
43388
- return url;
44212
+ return { canvas, ctx: result.surface.ctx };
43389
44213
  } catch (err) {
43390
- emfWarn("convertMetafileToDataUrl: EXCEPTION:", err instanceof Error ? err.message : err);
44214
+ emfWarn(`${caller}: EXCEPTION:`, err instanceof Error ? err.message : err);
43391
44215
  console.warn("[emf-converter] Conversion failed:", err instanceof Error ? err.message : err);
43392
44216
  return null;
43393
44217
  }
@@ -43620,6 +44444,7 @@ function defaultFontDirs(path, os) {
43620
44444
 
43621
44445
  exports.DEFAULT_DPI_SCALE = DEFAULT_DPI_SCALE;
43622
44446
  exports.convertMetafileToDataUrl = convertMetafileToDataUrl;
44447
+ exports.convertMetafileToJpegDataUrl = convertMetafileToJpegDataUrl;
43623
44448
  exports.convertMetafileToSvg = convertMetafileToSvg;
43624
44449
  exports.convertMetafileToSvgDataUrl = convertMetafileToSvgDataUrl;
43625
44450
  exports.convertMetafileToSvgTree = convertMetafileToSvgTree;