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.mjs CHANGED
@@ -44,7 +44,7 @@ var require_encoder = __commonJS({
44
44
  var YAC_HT;
45
45
  var UVAC_HT;
46
46
  var bitcode = new Array(65535);
47
- var category = new Array(65535);
47
+ var category2 = new Array(65535);
48
48
  var outputfDCTQuant = new Array(64);
49
49
  var DU = new Array(64);
50
50
  var byteout = [];
@@ -653,13 +653,13 @@ var require_encoder = __commonJS({
653
653
  var nrupper = 2;
654
654
  for (var cat = 1; cat <= 15; cat++) {
655
655
  for (var nr = nrlower; nr < nrupper; nr++) {
656
- category[32767 + nr] = cat;
656
+ category2[32767 + nr] = cat;
657
657
  bitcode[32767 + nr] = [];
658
658
  bitcode[32767 + nr][1] = cat;
659
659
  bitcode[32767 + nr][0] = nr;
660
660
  }
661
661
  for (var nrneg = -(nrupper - 1); nrneg <= -nrlower; nrneg++) {
662
- category[32767 + nrneg] = cat;
662
+ category2[32767 + nrneg] = cat;
663
663
  bitcode[32767 + nrneg] = [];
664
664
  bitcode[32767 + nrneg][1] = cat;
665
665
  bitcode[32767 + nrneg][0] = nrupper - 1 + nrneg;
@@ -941,7 +941,7 @@ var require_encoder = __commonJS({
941
941
  writeBits(HTDC[0]);
942
942
  } else {
943
943
  pos = 32767 + Diff;
944
- writeBits(HTDC[category[pos]]);
944
+ writeBits(HTDC[category2[pos]]);
945
945
  writeBits(bitcode[pos]);
946
946
  }
947
947
  var end0pos = 63;
@@ -965,7 +965,7 @@ var require_encoder = __commonJS({
965
965
  nrzeroes = nrzeroes & 15;
966
966
  }
967
967
  pos = 32767 + DU[i];
968
- writeBits(HTAC[(nrzeroes << 4) + category[pos]]);
968
+ writeBits(HTAC[(nrzeroes << 4) + category2[pos]]);
969
969
  writeBits(bitcode[pos]);
970
970
  i++;
971
971
  }
@@ -24851,6 +24851,7 @@ function drawNestedMetafile(rCtx, img, cached, source) {
24851
24851
  imageCache: caches?.images,
24852
24852
  fontFamilyMap: rCtx.fontFamilyMap,
24853
24853
  gdiAntialias: rCtx.gdiAntialias,
24854
+ codePages: rCtx.codePages,
24854
24855
  nestingDepth: depth + 1
24855
24856
  });
24856
24857
  } finally {
@@ -24934,6 +24935,752 @@ function drawEmfPlusImageNow(rCtx, img, draw, source, effect = null) {
24934
24935
  return bitmap ? paintBitmapRaster(rCtx.ctx, bitmap, draw) : false;
24935
24936
  }
24936
24937
 
24938
+ // src/jpeg-encoder.ts
24939
+ var DEFAULT_JPEG_QUALITY = 0.92;
24940
+ var ZIGZAG2 = [
24941
+ 0,
24942
+ 1,
24943
+ 8,
24944
+ 16,
24945
+ 9,
24946
+ 2,
24947
+ 3,
24948
+ 10,
24949
+ 17,
24950
+ 24,
24951
+ 32,
24952
+ 25,
24953
+ 18,
24954
+ 11,
24955
+ 4,
24956
+ 5,
24957
+ 12,
24958
+ 19,
24959
+ 26,
24960
+ 33,
24961
+ 40,
24962
+ 48,
24963
+ 41,
24964
+ 34,
24965
+ 27,
24966
+ 20,
24967
+ 13,
24968
+ 6,
24969
+ 7,
24970
+ 14,
24971
+ 21,
24972
+ 28,
24973
+ 35,
24974
+ 42,
24975
+ 49,
24976
+ 56,
24977
+ 57,
24978
+ 50,
24979
+ 43,
24980
+ 36,
24981
+ 29,
24982
+ 22,
24983
+ 15,
24984
+ 23,
24985
+ 30,
24986
+ 37,
24987
+ 44,
24988
+ 51,
24989
+ 58,
24990
+ 59,
24991
+ 52,
24992
+ 45,
24993
+ 38,
24994
+ 31,
24995
+ 39,
24996
+ 46,
24997
+ 53,
24998
+ 60,
24999
+ 61,
25000
+ 54,
25001
+ 47,
25002
+ 55,
25003
+ 62,
25004
+ 63
25005
+ ];
25006
+ var LUMA_QUANT = [
25007
+ 16,
25008
+ 11,
25009
+ 10,
25010
+ 16,
25011
+ 24,
25012
+ 40,
25013
+ 51,
25014
+ 61,
25015
+ 12,
25016
+ 12,
25017
+ 14,
25018
+ 19,
25019
+ 26,
25020
+ 58,
25021
+ 60,
25022
+ 55,
25023
+ 14,
25024
+ 13,
25025
+ 16,
25026
+ 24,
25027
+ 40,
25028
+ 57,
25029
+ 69,
25030
+ 56,
25031
+ 14,
25032
+ 17,
25033
+ 22,
25034
+ 29,
25035
+ 51,
25036
+ 87,
25037
+ 80,
25038
+ 62,
25039
+ 18,
25040
+ 22,
25041
+ 37,
25042
+ 56,
25043
+ 68,
25044
+ 109,
25045
+ 103,
25046
+ 77,
25047
+ 24,
25048
+ 35,
25049
+ 55,
25050
+ 64,
25051
+ 81,
25052
+ 104,
25053
+ 113,
25054
+ 92,
25055
+ 49,
25056
+ 64,
25057
+ 78,
25058
+ 87,
25059
+ 103,
25060
+ 121,
25061
+ 120,
25062
+ 101,
25063
+ 72,
25064
+ 92,
25065
+ 95,
25066
+ 98,
25067
+ 112,
25068
+ 100,
25069
+ 103,
25070
+ 99
25071
+ ];
25072
+ var CHROMA_QUANT = [
25073
+ 17,
25074
+ 18,
25075
+ 24,
25076
+ 47,
25077
+ 99,
25078
+ 99,
25079
+ 99,
25080
+ 99,
25081
+ 18,
25082
+ 21,
25083
+ 26,
25084
+ 66,
25085
+ 99,
25086
+ 99,
25087
+ 99,
25088
+ 99,
25089
+ 24,
25090
+ 26,
25091
+ 56,
25092
+ 99,
25093
+ 99,
25094
+ 99,
25095
+ 99,
25096
+ 99,
25097
+ 47,
25098
+ 66,
25099
+ 99,
25100
+ 99,
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
+ ];
25138
+ 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] };
25139
+ 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] };
25140
+ var AC_LUMA = {
25141
+ bits: [0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125],
25142
+ values: [
25143
+ 1,
25144
+ 2,
25145
+ 3,
25146
+ 0,
25147
+ 4,
25148
+ 17,
25149
+ 5,
25150
+ 18,
25151
+ 33,
25152
+ 49,
25153
+ 65,
25154
+ 6,
25155
+ 19,
25156
+ 81,
25157
+ 97,
25158
+ 7,
25159
+ 34,
25160
+ 113,
25161
+ 20,
25162
+ 50,
25163
+ 129,
25164
+ 145,
25165
+ 161,
25166
+ 8,
25167
+ 35,
25168
+ 66,
25169
+ 177,
25170
+ 193,
25171
+ 21,
25172
+ 82,
25173
+ 209,
25174
+ 240,
25175
+ 36,
25176
+ 51,
25177
+ 98,
25178
+ 114,
25179
+ 130,
25180
+ 9,
25181
+ 10,
25182
+ 22,
25183
+ 23,
25184
+ 24,
25185
+ 25,
25186
+ 26,
25187
+ 37,
25188
+ 38,
25189
+ 39,
25190
+ 40,
25191
+ 41,
25192
+ 42,
25193
+ 52,
25194
+ 53,
25195
+ 54,
25196
+ 55,
25197
+ 56,
25198
+ 57,
25199
+ 58,
25200
+ 67,
25201
+ 68,
25202
+ 69,
25203
+ 70,
25204
+ 71,
25205
+ 72,
25206
+ 73,
25207
+ 74,
25208
+ 83,
25209
+ 84,
25210
+ 85,
25211
+ 86,
25212
+ 87,
25213
+ 88,
25214
+ 89,
25215
+ 90,
25216
+ 99,
25217
+ 100,
25218
+ 101,
25219
+ 102,
25220
+ 103,
25221
+ 104,
25222
+ 105,
25223
+ 106,
25224
+ 115,
25225
+ 116,
25226
+ 117,
25227
+ 118,
25228
+ 119,
25229
+ 120,
25230
+ 121,
25231
+ 122,
25232
+ 131,
25233
+ 132,
25234
+ 133,
25235
+ 134,
25236
+ 135,
25237
+ 136,
25238
+ 137,
25239
+ 138,
25240
+ 146,
25241
+ 147,
25242
+ 148,
25243
+ 149,
25244
+ 150,
25245
+ 151,
25246
+ 152,
25247
+ 153,
25248
+ 154,
25249
+ 162,
25250
+ 163,
25251
+ 164,
25252
+ 165,
25253
+ 166,
25254
+ 167,
25255
+ 168,
25256
+ 169,
25257
+ 170,
25258
+ 178,
25259
+ 179,
25260
+ 180,
25261
+ 181,
25262
+ 182,
25263
+ 183,
25264
+ 184,
25265
+ 185,
25266
+ 186,
25267
+ 194,
25268
+ 195,
25269
+ 196,
25270
+ 197,
25271
+ 198,
25272
+ 199,
25273
+ 200,
25274
+ 201,
25275
+ 202,
25276
+ 210,
25277
+ 211,
25278
+ 212,
25279
+ 213,
25280
+ 214,
25281
+ 215,
25282
+ 216,
25283
+ 217,
25284
+ 218,
25285
+ 225,
25286
+ 226,
25287
+ 227,
25288
+ 228,
25289
+ 229,
25290
+ 230,
25291
+ 231,
25292
+ 232,
25293
+ 233,
25294
+ 234,
25295
+ 241,
25296
+ 242,
25297
+ 243,
25298
+ 244,
25299
+ 245,
25300
+ 246,
25301
+ 247,
25302
+ 248,
25303
+ 249,
25304
+ 250
25305
+ ]
25306
+ };
25307
+ var AC_CHROMA = {
25308
+ bits: [0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119],
25309
+ values: [
25310
+ 0,
25311
+ 1,
25312
+ 2,
25313
+ 3,
25314
+ 17,
25315
+ 4,
25316
+ 5,
25317
+ 33,
25318
+ 49,
25319
+ 6,
25320
+ 18,
25321
+ 65,
25322
+ 81,
25323
+ 7,
25324
+ 97,
25325
+ 113,
25326
+ 19,
25327
+ 34,
25328
+ 50,
25329
+ 129,
25330
+ 8,
25331
+ 20,
25332
+ 66,
25333
+ 145,
25334
+ 161,
25335
+ 177,
25336
+ 193,
25337
+ 9,
25338
+ 35,
25339
+ 51,
25340
+ 82,
25341
+ 240,
25342
+ 21,
25343
+ 98,
25344
+ 114,
25345
+ 209,
25346
+ 10,
25347
+ 22,
25348
+ 36,
25349
+ 52,
25350
+ 225,
25351
+ 37,
25352
+ 241,
25353
+ 23,
25354
+ 24,
25355
+ 25,
25356
+ 26,
25357
+ 38,
25358
+ 39,
25359
+ 40,
25360
+ 41,
25361
+ 42,
25362
+ 53,
25363
+ 54,
25364
+ 55,
25365
+ 56,
25366
+ 57,
25367
+ 58,
25368
+ 67,
25369
+ 68,
25370
+ 69,
25371
+ 70,
25372
+ 71,
25373
+ 72,
25374
+ 73,
25375
+ 74,
25376
+ 83,
25377
+ 84,
25378
+ 85,
25379
+ 86,
25380
+ 87,
25381
+ 88,
25382
+ 89,
25383
+ 90,
25384
+ 99,
25385
+ 100,
25386
+ 101,
25387
+ 102,
25388
+ 103,
25389
+ 104,
25390
+ 105,
25391
+ 106,
25392
+ 115,
25393
+ 116,
25394
+ 117,
25395
+ 118,
25396
+ 119,
25397
+ 120,
25398
+ 121,
25399
+ 122,
25400
+ 130,
25401
+ 131,
25402
+ 132,
25403
+ 133,
25404
+ 134,
25405
+ 135,
25406
+ 136,
25407
+ 137,
25408
+ 138,
25409
+ 146,
25410
+ 147,
25411
+ 148,
25412
+ 149,
25413
+ 150,
25414
+ 151,
25415
+ 152,
25416
+ 153,
25417
+ 154,
25418
+ 162,
25419
+ 163,
25420
+ 164,
25421
+ 165,
25422
+ 166,
25423
+ 167,
25424
+ 168,
25425
+ 169,
25426
+ 170,
25427
+ 178,
25428
+ 179,
25429
+ 180,
25430
+ 181,
25431
+ 182,
25432
+ 183,
25433
+ 184,
25434
+ 185,
25435
+ 186,
25436
+ 194,
25437
+ 195,
25438
+ 196,
25439
+ 197,
25440
+ 198,
25441
+ 199,
25442
+ 200,
25443
+ 201,
25444
+ 202,
25445
+ 210,
25446
+ 211,
25447
+ 212,
25448
+ 213,
25449
+ 214,
25450
+ 215,
25451
+ 216,
25452
+ 217,
25453
+ 218,
25454
+ 226,
25455
+ 227,
25456
+ 228,
25457
+ 229,
25458
+ 230,
25459
+ 231,
25460
+ 232,
25461
+ 233,
25462
+ 234,
25463
+ 242,
25464
+ 243,
25465
+ 244,
25466
+ 245,
25467
+ 246,
25468
+ 247,
25469
+ 248,
25470
+ 249,
25471
+ 250
25472
+ ]
25473
+ };
25474
+ function buildCodes(spec) {
25475
+ const code = new Uint16Array(256);
25476
+ const size = new Uint8Array(256);
25477
+ let next = 0;
25478
+ let k = 0;
25479
+ for (let len = 1; len <= 16; len++) {
25480
+ for (let i = 0; i < spec.bits[len - 1]; i++) {
25481
+ const symbol = spec.values[k++];
25482
+ code[symbol] = next++;
25483
+ size[symbol] = len;
25484
+ }
25485
+ next <<= 1;
25486
+ }
25487
+ return { code, size };
25488
+ }
25489
+ function scaleQuant(base, quality) {
25490
+ const q = Math.min(100, Math.max(1, Math.round(quality * 100)));
25491
+ const scale = q < 50 ? Math.floor(5e3 / q) : 200 - q * 2;
25492
+ return Uint8Array.from(base, (v) => Math.min(255, Math.max(1, Math.floor((v * scale + 50) / 100))));
25493
+ }
25494
+ var COS = (() => {
25495
+ const t = new Float64Array(64);
25496
+ for (let u = 0; u < 8; u++) {
25497
+ const c = u === 0 ? Math.SQRT1_2 : 1;
25498
+ for (let x = 0; x < 8; x++) {
25499
+ t[u * 8 + x] = c / 2 * Math.cos((2 * x + 1) * u * Math.PI / 16);
25500
+ }
25501
+ }
25502
+ return t;
25503
+ })();
25504
+ function fdctQuantize(block, quant, out, tmp) {
25505
+ for (let y = 0; y < 8; y++) {
25506
+ for (let u = 0; u < 8; u++) {
25507
+ let s = 0;
25508
+ for (let x = 0; x < 8; x++) s += COS[u * 8 + x] * block[y * 8 + x];
25509
+ tmp[y * 8 + u] = s;
25510
+ }
25511
+ }
25512
+ for (let k = 0; k < 64; k++) {
25513
+ const n = ZIGZAG2[k];
25514
+ const v = n >> 3;
25515
+ const u = n & 7;
25516
+ let s = 0;
25517
+ for (let y = 0; y < 8; y++) s += COS[v * 8 + y] * tmp[y * 8 + u];
25518
+ out[k] = Math.round(s / quant[n]);
25519
+ }
25520
+ }
25521
+ var BitWriter = class {
25522
+ constructor() {
25523
+ this.buf = new Uint8Array(4096);
25524
+ this.length = 0;
25525
+ this.acc = 0;
25526
+ this.count = 0;
25527
+ }
25528
+ byte(b) {
25529
+ if (this.length === this.buf.length) {
25530
+ const grown = new Uint8Array(this.buf.length * 2);
25531
+ grown.set(this.buf);
25532
+ this.buf = grown;
25533
+ }
25534
+ this.buf[this.length++] = b;
25535
+ }
25536
+ bits(value, size) {
25537
+ for (let i = size - 1; i >= 0; i--) {
25538
+ this.acc = this.acc << 1 | value >> i & 1;
25539
+ if (++this.count === 8) {
25540
+ this.byte(this.acc);
25541
+ if (this.acc === 255) this.byte(0);
25542
+ this.acc = 0;
25543
+ this.count = 0;
25544
+ }
25545
+ }
25546
+ }
25547
+ /** Pads the last byte with 1 bits and returns the segment. */
25548
+ finish() {
25549
+ if (this.count > 0) this.bits((1 << 8 - this.count) - 1, 8 - this.count);
25550
+ return this.buf.subarray(0, this.length);
25551
+ }
25552
+ };
25553
+ function category(v) {
25554
+ let a = v < 0 ? -v : v;
25555
+ let n = 0;
25556
+ while (a) {
25557
+ n++;
25558
+ a >>= 1;
25559
+ }
25560
+ return n;
25561
+ }
25562
+ function writeBlock(w, coef, prevDc, dc, ac) {
25563
+ const diff = coef[0] - prevDc;
25564
+ const dcSize = category(diff);
25565
+ w.bits(dc.code[dcSize], dc.size[dcSize]);
25566
+ if (dcSize) w.bits(diff < 0 ? diff - 1 : diff, dcSize);
25567
+ let run = 0;
25568
+ for (let k = 1; k < 64; k++) {
25569
+ const v = coef[k];
25570
+ if (v === 0) {
25571
+ run++;
25572
+ continue;
25573
+ }
25574
+ while (run > 15) {
25575
+ w.bits(ac.code[240], ac.size[240]);
25576
+ run -= 16;
25577
+ }
25578
+ const size = category(v);
25579
+ const symbol = run << 4 | size;
25580
+ w.bits(ac.code[symbol], ac.size[symbol]);
25581
+ w.bits(v < 0 ? v - 1 : v, size);
25582
+ run = 0;
25583
+ }
25584
+ if (run > 0) w.bits(ac.code[0], ac.size[0]);
25585
+ return coef[0];
25586
+ }
25587
+ function segment(marker, payload) {
25588
+ const len = payload.length + 2;
25589
+ return [255, marker, len >> 8, len & 255, ...payload];
25590
+ }
25591
+ function dhtPayload(tableClass, id, spec) {
25592
+ return [tableClass << 4 | id, ...spec.bits, ...spec.values];
25593
+ }
25594
+ function encodeJpeg(data, width, height, options2 = {}) {
25595
+ if (!(width >= 1 && height >= 1 && width <= 65535 && height <= 65535)) {
25596
+ throw new RangeError(`JPEG dimensions out of range: ${width}x${height}`);
25597
+ }
25598
+ const quality = Number.isFinite(options2.quality) ? Math.min(1, Math.max(0, options2.quality)) : DEFAULT_JPEG_QUALITY;
25599
+ const [bgR, bgG, bgB] = options2.background ?? [255, 255, 255];
25600
+ const sub = options2.chromaSubsampling ?? false;
25601
+ const lumaQuant = scaleQuant(LUMA_QUANT, quality);
25602
+ const chromaQuant = scaleQuant(CHROMA_QUANT, quality);
25603
+ const n = width * height;
25604
+ const Y = new Float64Array(n);
25605
+ const Cb = new Float64Array(n);
25606
+ const Cr = new Float64Array(n);
25607
+ for (let i = 0; i < n; i++) {
25608
+ const a = data[i * 4 + 3] / 255;
25609
+ const r = data[i * 4] * a + bgR * (1 - a);
25610
+ const g = data[i * 4 + 1] * a + bgG * (1 - a);
25611
+ const b = data[i * 4 + 2] * a + bgB * (1 - a);
25612
+ Y[i] = 0.299 * r + 0.587 * g + 0.114 * b;
25613
+ Cb[i] = -0.168736 * r - 0.331264 * g + 0.5 * b + 128;
25614
+ Cr[i] = 0.5 * r - 0.418688 * g - 0.081312 * b + 128;
25615
+ }
25616
+ const dcL = buildCodes(DC_LUMA);
25617
+ const acL = buildCodes(AC_LUMA);
25618
+ const dcC = buildCodes(DC_CHROMA);
25619
+ const acC = buildCodes(AC_CHROMA);
25620
+ const factor = sub ? 2 : 1;
25621
+ const mcu = 8 * factor;
25622
+ const block = new Float64Array(64);
25623
+ const tmp = new Float64Array(64);
25624
+ const coef = new Int32Array(64);
25625
+ const w = new BitWriter();
25626
+ let dcY = 0;
25627
+ let dcCb = 0;
25628
+ let dcCr = 0;
25629
+ const lumaBlock = (x0, y0) => {
25630
+ for (let y = 0; y < 8; y++) {
25631
+ const row2 = Math.min(height - 1, y0 + y) * width;
25632
+ for (let x = 0; x < 8; x++) block[y * 8 + x] = Y[row2 + Math.min(width - 1, x0 + x)] - 128;
25633
+ }
25634
+ };
25635
+ const chromaBlock = (plane, x0, y0) => {
25636
+ for (let y = 0; y < 8; y++) {
25637
+ for (let x = 0; x < 8; x++) {
25638
+ let s = 0;
25639
+ for (let dy = 0; dy < factor; dy++) {
25640
+ const row2 = Math.min(height - 1, y0 + y * factor + dy) * width;
25641
+ for (let dx = 0; dx < factor; dx++) s += plane[row2 + Math.min(width - 1, x0 + x * factor + dx)];
25642
+ }
25643
+ block[y * 8 + x] = s / (factor * factor) - 128;
25644
+ }
25645
+ }
25646
+ };
25647
+ for (let my = 0; my < height; my += mcu) {
25648
+ for (let mx = 0; mx < width; mx += mcu) {
25649
+ for (let by = 0; by < factor; by++) {
25650
+ for (let bx = 0; bx < factor; bx++) {
25651
+ lumaBlock(mx + bx * 8, my + by * 8);
25652
+ fdctQuantize(block, lumaQuant, coef, tmp);
25653
+ dcY = writeBlock(w, coef, dcY, dcL, acL);
25654
+ }
25655
+ }
25656
+ chromaBlock(Cb, mx, my);
25657
+ fdctQuantize(block, chromaQuant, coef, tmp);
25658
+ dcCb = writeBlock(w, coef, dcCb, dcC, acC);
25659
+ chromaBlock(Cr, mx, my);
25660
+ fdctQuantize(block, chromaQuant, coef, tmp);
25661
+ dcCr = writeBlock(w, coef, dcCr, dcC, acC);
25662
+ }
25663
+ }
25664
+ const scan = w.finish();
25665
+ const sampling = factor << 4 | factor;
25666
+ const header = [
25667
+ 255,
25668
+ 216,
25669
+ // APP0 JFIF 1.01, no density (aspect ratio 1:1), no thumbnail.
25670
+ ...segment(224, [74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0]),
25671
+ ...segment(219, [0, ...ZIGZAG2.map((i) => lumaQuant[i]), 1, ...ZIGZAG2.map((i) => chromaQuant[i])]),
25672
+ ...segment(192, [8, height >> 8, height & 255, width >> 8, width & 255, 3, 1, sampling, 0, 2, 17, 1, 3, 17, 1]),
25673
+ ...segment(196, [...dhtPayload(0, 0, DC_LUMA), ...dhtPayload(1, 0, AC_LUMA), ...dhtPayload(0, 1, DC_CHROMA), ...dhtPayload(1, 1, AC_CHROMA)]),
25674
+ ...segment(218, [3, 1, 0, 2, 17, 3, 17, 0, 63, 0])
25675
+ ];
25676
+ const out = new Uint8Array(header.length + scan.length + 2);
25677
+ out.set(header, 0);
25678
+ out.set(scan, header.length);
25679
+ out[out.length - 2] = 255;
25680
+ out[out.length - 1] = 217;
25681
+ return out;
25682
+ }
25683
+
24937
25684
  // src/fnt-font.ts
24938
25685
  function parseFnt(view, base, end) {
24939
25686
  if (base + 118 > end) {
@@ -36048,6 +36795,20 @@ function handleEmfGdiBlendBlitRecord(rCtx, recType, offset, dataOff, recSize) {
36048
36795
 
36049
36796
  // src/emf-ansi-tables.ts
36050
36797
  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";
36798
+ var OEM_HIGH = {
36799
+ 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",
36800
+ 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",
36801
+ 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",
36802
+ 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",
36803
+ 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",
36804
+ 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",
36805
+ 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",
36806
+ 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",
36807
+ 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",
36808
+ 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",
36809
+ 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",
36810
+ 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"
36811
+ };
36051
36812
  var JOHAB_ROWS = {
36052
36813
  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",
36053
36814
  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",
@@ -36240,12 +37001,23 @@ var ANSI_CODE_PAGE_ENCODING = {
36240
37001
  54936: "gb18030",
36241
37002
  65001: "utf-8"
36242
37003
  };
36243
- function decodeAnsiRecord(bytes, charSet, ansiCodePage) {
37004
+ var OEM_CODE_PAGE_ENCODING = {
37005
+ 874: "windows-874",
37006
+ 932: "shift_jis",
37007
+ 936: "gbk",
37008
+ 949: "euc-kr",
37009
+ 950: "big5"
37010
+ };
37011
+ function decodeOemTable(bytes, high) {
37012
+ return { codes: bytes.map((b) => b < 128 ? b : high.charCodeAt(b - 128)), byteLengths: bytes.map(() => 1) };
37013
+ }
37014
+ function decodeAnsiRecord(bytes, charSet, codePages) {
36244
37015
  if (charSet === 2) {
36245
37016
  return { codes: [...bytes], byteLengths: bytes.map(() => 1) };
36246
37017
  }
36247
- if (charSet === 255) {
36248
- return { codes: bytes.map((b) => b < 128 ? b : OEM437_HIGH.charCodeAt(b - 128)), byteLengths: bytes.map(() => 1) };
37018
+ const oemCodePage = codePages?.oem;
37019
+ if (charSet === 255 && (oemCodePage === void 0 || !(oemCodePage in OEM_CODE_PAGE_ENCODING))) {
37020
+ return decodeOemTable(bytes, (oemCodePage !== void 0 ? OEM_HIGH[oemCodePage] : void 0) ?? OEM437_HIGH);
36249
37021
  }
36250
37022
  if (charSet === 130) {
36251
37023
  const codes = [];
@@ -36261,7 +37033,8 @@ function decodeAnsiRecord(bytes, charSet, ansiCodePage) {
36261
37033
  }
36262
37034
  return { codes, byteLengths };
36263
37035
  }
36264
- const label = (charSet === 0 || charSet === 1) && ansiCodePage !== void 0 ? ANSI_CODE_PAGE_ENCODING[ansiCodePage] ?? "windows-1252" : CHARSET_ENCODING[charSet] ?? "windows-1252";
37036
+ const ansiCodePage = codePages?.ansi;
37037
+ 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";
36265
37038
  if (label === "windows-1252") {
36266
37039
  return { codes: bytes.map((b) => ansiToCode(b, charSet)), byteLengths: bytes.map(() => 1) };
36267
37040
  }
@@ -37081,8 +37854,9 @@ function drawTextCall(rCtx, x, y, codes, options2, rect, dx) {
37081
37854
  const child = { ...rCtx, view };
37082
37855
  handleExtTextOutW(child, 0, 8, size);
37083
37856
  }
37084
- function readAnsiRecord(view, start, count, charSet) {
37085
- return decodeAnsiRecord(Array.from({ length: count }, (_, i) => view.getUint8(start + i)), charSet);
37857
+ function readAnsiRecord(rCtx, start, count, charSet) {
37858
+ const { view } = rCtx;
37859
+ return decodeAnsiRecord(Array.from({ length: count }, (_, i) => view.getUint8(start + i)), charSet, rCtx.codePages);
37086
37860
  }
37087
37861
  function collapseAnsiDx(dx, byteLengths, pdy) {
37088
37862
  if (!dx) return null;
@@ -37117,7 +37891,7 @@ function handlePolyText(rCtx, offset, dataOff, recSize, wide) {
37117
37891
  const offDx = view.getUint32(e + 36, true);
37118
37892
  const unit = wide ? 2 : 1;
37119
37893
  if (!offString || offString > end - offset || n > Math.floor((end - (offset + offString)) / unit)) continue;
37120
- const ansi = wide ? null : readAnsiRecord(view, offset + offString, n, charSet);
37894
+ const ansi = wide ? null : readAnsiRecord(rCtx, offset + offString, n, charSet);
37121
37895
  const codes = wide ? Array.from({ length: n }, (_, j) => view.getUint16(offset + offString + j * 2, true)) : ansi.codes;
37122
37896
  let dx = null;
37123
37897
  const pdy = (options2 & ETO_PDY) !== 0;
@@ -37158,7 +37932,7 @@ function handleEmfGdiDrawTextRecord(rCtx, recType, offset, dataOff, recSize) {
37158
37932
  const n = view.getUint32(dataOff + 36, true), strOff = view.getUint32(dataOff + 40, true), options2 = view.getUint32(dataOff + 44, true);
37159
37933
  if (!strOff || strOff > end - offset) return true;
37160
37934
  if (n > end - (offset + strOff)) return true;
37161
- const ansi = readAnsiRecord(view, offset + strOff, n, state.fontDetails?.charSet ?? 1);
37935
+ const ansi = readAnsiRecord(rCtx, offset + strOff, n, state.fontDetails?.charSet ?? 1);
37162
37936
  const rect = [view.getInt32(dataOff + 48, true), view.getInt32(dataOff + 52, true), view.getInt32(dataOff + 56, true), view.getInt32(dataOff + 60, true)];
37163
37937
  const offDx = view.getUint32(dataOff + 64, true);
37164
37938
  let dx = null;
@@ -40913,6 +41687,7 @@ function replayEmfPlusRecords(view, offset, length, ctx, canvasW, canvasH, state
40913
41687
  imageCache: s.imageCache,
40914
41688
  nestingDepth: s.nestingDepth,
40915
41689
  gdiAntialias: s.gdiAntialias,
41690
+ codePages: s.codePages,
40916
41691
  antiAlias: s.antiAlias,
40917
41692
  ext: s.ext ?? (s.ext = {})
40918
41693
  };
@@ -41090,6 +41865,7 @@ function replayEmfRecords(view, ctx, bounds, canvasW, canvasH, dpiScale = 1, rep
41090
41865
  const plusScale = dpiScale > 0 ? dpiScale : 1;
41091
41866
  emfPlusState.imageCache = replayOptions.imageCache;
41092
41867
  emfPlusState.gdiAntialias = replayOptions.gdiAntialias;
41868
+ emfPlusState.codePages = replayOptions.codePages;
41093
41869
  emfPlusState.baseTransform = replayOptions.plusBaseTransform ?? [
41094
41870
  sx / plusScale,
41095
41871
  0,
@@ -41129,7 +41905,8 @@ function replayEmfRecords(view, ctx, bounds, canvasW, canvasH, dpiScale = 1, rep
41129
41905
  sy,
41130
41906
  pathCmds: [],
41131
41907
  gdiAntialias: replayOptions.gdiAntialias,
41132
- fonts: replayOptions.fonts
41908
+ fonts: replayOptions.fonts,
41909
+ codePages: replayOptions.codePages
41133
41910
  };
41134
41911
  let offset = 0;
41135
41912
  const maxOffset = view.byteLength;
@@ -41534,7 +42311,7 @@ function createFont(p, dataOff, recSize, recEnd) {
41534
42311
  }
41535
42312
  faceBytes.push(ch);
41536
42313
  }
41537
- const family = String.fromCharCode(...decodeAnsiRecord(faceBytes, 1, p.ansiCodePage).codes);
42314
+ const family = String.fromCharCode(...decodeAnsiRecord(faceBytes, 1, { ansi: p.ansiCodePage }).codes);
41538
42315
  const font = {
41539
42316
  kind: "font",
41540
42317
  // Sign kept: resolveFontPixelHeight() tells cell from character height by it.
@@ -42561,7 +43338,7 @@ function drawWithFontEngine2(p, call, codes, dx) {
42561
43338
  }
42562
43339
  function playText(p, call) {
42563
43340
  const charSet = p.rCtx.state.fontDetails?.charSet ?? 1;
42564
- const { codes, byteLengths } = decodeAnsiRecord(call.bytes, charSet, p.ansiCodePage);
43341
+ const { codes, byteLengths } = decodeAnsiRecord(call.bytes, charSet, { ansi: p.ansiCodePage, oem: p.oemCodePage });
42565
43342
  const n = codes.length;
42566
43343
  if (n === 0) {
42567
43344
  return;
@@ -42693,7 +43470,8 @@ function createWmfPlayer(view, ctx, header, canvasW, canvasH, replayOptions = {}
42693
43470
  };
42694
43471
  const p = {
42695
43472
  rCtx,
42696
- ansiCodePage: replayOptions.wmfAnsiCodePage,
43473
+ ansiCodePage: replayOptions.wmfAnsiCodePage ?? replayOptions.codePages?.ansi,
43474
+ oemCodePage: replayOptions.codePages?.oem,
42697
43475
  view,
42698
43476
  kx,
42699
43477
  ky,
@@ -43192,6 +43970,7 @@ async function replayMetafile(buffer, options2, createSurface) {
43192
43970
  maxRecords: opts.maxRecords,
43193
43971
  maxRecordsEmfPlus: opts.maxRecords,
43194
43972
  fontFamilyMap: opts.fontFamilyMap,
43973
+ codePages: { ansi: opts.ansiCodePage, oem: opts.oemCodePage },
43195
43974
  textureCache,
43196
43975
  imageCache,
43197
43976
  gdiAntialias: opts.gdiAntialias,
@@ -43226,6 +44005,7 @@ async function replayMetafile(buffer, options2, createSurface) {
43226
44005
  replayWmfRecords(view, surface.ctx, header, surface.width, surface.height, {
43227
44006
  wmfReferenceDpi: opts.wmfReferenceDpi,
43228
44007
  wmfAnsiCodePage: opts.wmfAnsiCodePage,
44008
+ codePages: { ansi: opts.ansiCodePage, oem: opts.oemCodePage },
43229
44009
  maxRecords: opts.maxRecords,
43230
44010
  fontFamilyMap: opts.fontFamilyMap,
43231
44011
  gdiAntialias: opts.gdiAntialias,
@@ -43346,6 +44126,54 @@ async function processDeferredImages(ctx, deferredImages, recursionDepth) {
43346
44126
  return complete;
43347
44127
  }
43348
44128
  async function convertMetafileToDataUrl(buffer, options2, recursionDepth = 0) {
44129
+ const raster = await renderRaster(buffer, options2, recursionDepth, "convertMetafileToDataUrl");
44130
+ if (!raster) {
44131
+ return null;
44132
+ }
44133
+ try {
44134
+ const url = await exportCanvasToPngDataUrl(raster.canvas);
44135
+ if (!url) {
44136
+ emfWarn("convertMetafileToDataUrl: exportCanvasToPngDataUrl returned null");
44137
+ }
44138
+ return url;
44139
+ } catch (err) {
44140
+ emfWarn("convertMetafileToDataUrl: EXCEPTION:", err instanceof Error ? err.message : err);
44141
+ console.warn("[emf-converter] Conversion failed:", err instanceof Error ? err.message : err);
44142
+ return null;
44143
+ }
44144
+ }
44145
+ async function convertMetafileToJpegDataUrl(buffer, options2) {
44146
+ const raster = await renderRaster(buffer, options2, 0, "convertMetafileToJpegDataUrl");
44147
+ if (!raster) {
44148
+ return null;
44149
+ }
44150
+ try {
44151
+ const { canvas, ctx } = raster;
44152
+ const pixels = canvas instanceof SoftwareRasterCanvas ? canvas.pixels : canvasGetImageData(ctx, 0, 0, canvas.width, canvas.height).data;
44153
+ const jpeg = encodeJpeg(pixels, canvas.width, canvas.height, {
44154
+ quality: options2?.quality,
44155
+ background: parseBackground(options2?.background),
44156
+ chromaSubsampling: options2?.chromaSubsampling
44157
+ });
44158
+ return `data:image/jpeg;base64,${bytesToBase64(jpeg)}`;
44159
+ } catch (err) {
44160
+ emfWarn("convertMetafileToJpegDataUrl: EXCEPTION:", err instanceof Error ? err.message : err);
44161
+ console.warn("[emf-converter] Conversion failed:", err instanceof Error ? err.message : err);
44162
+ return null;
44163
+ }
44164
+ }
44165
+ function parseBackground(color) {
44166
+ if (color === void 0) {
44167
+ return [255, 255, 255];
44168
+ }
44169
+ const hex5 = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(color.trim())?.[1];
44170
+ if (!hex5) {
44171
+ return [255, 255, 255];
44172
+ }
44173
+ const full = hex5.length === 3 ? [...hex5].map((c) => c + c).join("") : hex5;
44174
+ return [0, 2, 4].map((i) => parseInt(full.slice(i, i + 2), 16));
44175
+ }
44176
+ async function renderRaster(buffer, options2, recursionDepth, caller) {
43349
44177
  await ensureNodeCanvasModule();
43350
44178
  if (recursionDepth > MAX_METAFILE_RECURSION) {
43351
44179
  return null;
@@ -43375,17 +44203,13 @@ async function convertMetafileToDataUrl(buffer, options2, recursionDepth = 0) {
43375
44203
  const soft = canvas instanceof SoftwareRasterCanvas ? canvas : null;
43376
44204
  if (soft && (soft.textDraws > 0 || !complete)) {
43377
44205
  emfWarn(
43378
- `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`
44206
+ `${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`
43379
44207
  );
43380
44208
  return null;
43381
44209
  }
43382
- const url = await exportCanvasToPngDataUrl(canvas);
43383
- if (!url) {
43384
- emfWarn("convertMetafileToDataUrl: exportCanvasToPngDataUrl returned null");
43385
- }
43386
- return url;
44210
+ return { canvas, ctx: result.surface.ctx };
43387
44211
  } catch (err) {
43388
- emfWarn("convertMetafileToDataUrl: EXCEPTION:", err instanceof Error ? err.message : err);
44212
+ emfWarn(`${caller}: EXCEPTION:`, err instanceof Error ? err.message : err);
43389
44213
  console.warn("[emf-converter] Conversion failed:", err instanceof Error ? err.message : err);
43390
44214
  return null;
43391
44215
  }
@@ -43616,4 +44440,4 @@ function defaultFontDirs(path, os) {
43616
44440
  return ["/usr/share/fonts", "/usr/local/share/fonts", path.join(home, ".fonts"), path.join(home, ".local", "share", "fonts")];
43617
44441
  }
43618
44442
 
43619
- export { DEFAULT_DPI_SCALE, convertMetafileToDataUrl, convertMetafileToSvg, convertMetafileToSvgDataUrl, convertMetafileToSvgTree, loadSystemFonts, svgTreeToDataUrl, svgTreeToJsx, svgTreeToReact, svgTreeToString };
44443
+ export { DEFAULT_DPI_SCALE, convertMetafileToDataUrl, convertMetafileToJpegDataUrl, convertMetafileToSvg, convertMetafileToSvgDataUrl, convertMetafileToSvgTree, loadSystemFonts, svgTreeToDataUrl, svgTreeToJsx, svgTreeToReact, svgTreeToString };