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