@file-viewer/docx 0.3.41 → 0.3.43

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.
@@ -2775,6 +2775,192 @@
2775
2775
  return `<svg xmlns="http://www.w3.org/2000/svg" width="${fmt$1(physicalWidth)}mm" height="${fmt$1(physicalHeight)}mm" viewBox="${fmt$1(bounds.left)} ${fmt$1(bounds.top)} ${fmt$1(width)} ${fmt$1(height)}" preserveAspectRatio="xMidYMid meet" data-docx-metafile="emf"><rect x="${fmt$1(bounds.left)}" y="${fmt$1(bounds.top)}" width="${fmt$1(width)}" height="${fmt$1(height)}" fill="none" stroke="#999" stroke-width="1"/><text x="${fmt$1(bounds.left + width / 2)}" y="${fmt$1(bounds.top + height / 2)}" text-anchor="middle" font-size="12" fill="#666">${esc$1(message)}</text></svg>`;
2776
2776
  }
2777
2777
 
2778
+ /*! @license Adobe Symbol Encoding to Unicode
2779
+ * Copyright (c) 1991-2011 Unicode, Inc. All Rights reserved.
2780
+ *
2781
+ * This file is provided as-is by Unicode, Inc. (The Unicode Consortium). No
2782
+ * claims are made as to fitness for any particular purpose. No warranties of
2783
+ * any kind are expressed or implied. The recipient agrees to determine
2784
+ * applicability of information provided. If this file has been provided on
2785
+ * magnetic media by Unicode, Inc., the sole remedy for any claim will be
2786
+ * exchange of defective media within 90 days of receipt.
2787
+ *
2788
+ * Unicode, Inc. hereby grants the right to freely use the information
2789
+ * supplied in this file in the creation of products supporting the
2790
+ * Unicode Standard, and to make copies of this file in any form for
2791
+ * internal or external distribution as long as this notice remains
2792
+ * attached.
2793
+ *
2794
+ * Source: https://www.unicode.org/Public/MAPPINGS/VENDORS/ADOBE/symbol.txt
2795
+ */
2796
+ const symbolEncoding = {
2797
+ 0x21: 0x21,
2798
+ 0x22: 0x2200,
2799
+ 0x23: 0x23,
2800
+ 0x24: 0x2203,
2801
+ 0x25: 0x25,
2802
+ 0x26: 0x26,
2803
+ 0x27: 0x220b,
2804
+ 0x28: 0x28,
2805
+ 0x29: 0x29,
2806
+ 0x2a: 0x2217,
2807
+ 0x2b: 0x2b,
2808
+ 0x2c: 0x2c,
2809
+ 0x2d: 0x2212,
2810
+ 0x2e: 0x2e,
2811
+ 0x2f: 0x2f,
2812
+ 0x30: 0x30,
2813
+ 0x31: 0x31,
2814
+ 0x32: 0x32,
2815
+ 0x33: 0x33,
2816
+ 0x34: 0x34,
2817
+ 0x35: 0x35,
2818
+ 0x36: 0x36,
2819
+ 0x37: 0x37,
2820
+ 0x38: 0x38,
2821
+ 0x39: 0x39,
2822
+ 0x3a: 0x3a,
2823
+ 0x3b: 0x3b,
2824
+ 0x3c: 0x3c,
2825
+ 0x3d: 0x3d,
2826
+ 0x3e: 0x3e,
2827
+ 0x3f: 0x3f,
2828
+ 0x40: 0x2245,
2829
+ 0x41: 0x391,
2830
+ 0x42: 0x392,
2831
+ 0x43: 0x3a7,
2832
+ 0x45: 0x395,
2833
+ 0x46: 0x3a6,
2834
+ 0x47: 0x393,
2835
+ 0x48: 0x397,
2836
+ 0x49: 0x399,
2837
+ 0x4a: 0x3d1,
2838
+ 0x4b: 0x39a,
2839
+ 0x4c: 0x39b,
2840
+ 0x4d: 0x39c,
2841
+ 0x4e: 0x39d,
2842
+ 0x4f: 0x39f,
2843
+ 0x50: 0x3a0,
2844
+ 0x51: 0x398,
2845
+ 0x52: 0x3a1,
2846
+ 0x53: 0x3a3,
2847
+ 0x54: 0x3a4,
2848
+ 0x55: 0x3a5,
2849
+ 0x56: 0x3c2,
2850
+ 0x58: 0x39e,
2851
+ 0x59: 0x3a8,
2852
+ 0x5a: 0x396,
2853
+ 0x5b: 0x5b,
2854
+ 0x5c: 0x2234,
2855
+ 0x5d: 0x5d,
2856
+ 0x5e: 0x22a5,
2857
+ 0x5f: 0x5f,
2858
+ 0x61: 0x3b1,
2859
+ 0x62: 0x3b2,
2860
+ 0x63: 0x3c7,
2861
+ 0x64: 0x3b4,
2862
+ 0x65: 0x3b5,
2863
+ 0x66: 0x3c6,
2864
+ 0x67: 0x3b3,
2865
+ 0x68: 0x3b7,
2866
+ 0x69: 0x3b9,
2867
+ 0x6a: 0x3d5,
2868
+ 0x6b: 0x3ba,
2869
+ 0x6c: 0x3bb,
2870
+ 0x6e: 0x3bd,
2871
+ 0x6f: 0x3bf,
2872
+ 0x70: 0x3c0,
2873
+ 0x71: 0x3b8,
2874
+ 0x72: 0x3c1,
2875
+ 0x73: 0x3c3,
2876
+ 0x74: 0x3c4,
2877
+ 0x75: 0x3c5,
2878
+ 0x76: 0x3d6,
2879
+ 0x77: 0x3c9,
2880
+ 0x78: 0x3be,
2881
+ 0x79: 0x3c8,
2882
+ 0x7a: 0x3b6,
2883
+ 0x7b: 0x7b,
2884
+ 0x7c: 0x7c,
2885
+ 0x7d: 0x7d,
2886
+ 0x7e: 0x223c,
2887
+ 0xa0: 0x20ac,
2888
+ 0xa1: 0x3d2,
2889
+ 0xa2: 0x2032,
2890
+ 0xa3: 0x2264,
2891
+ 0xa5: 0x221e,
2892
+ 0xa6: 0x192,
2893
+ 0xa7: 0x2663,
2894
+ 0xa8: 0x2666,
2895
+ 0xa9: 0x2665,
2896
+ 0xaa: 0x2660,
2897
+ 0xab: 0x2194,
2898
+ 0xac: 0x2190,
2899
+ 0xad: 0x2191,
2900
+ 0xae: 0x2192,
2901
+ 0xaf: 0x2193,
2902
+ 0xb0: 0xb0,
2903
+ 0xb1: 0xb1,
2904
+ 0xb2: 0x2033,
2905
+ 0xb3: 0x2265,
2906
+ 0xb4: 0xd7,
2907
+ 0xb5: 0x221d,
2908
+ 0xb6: 0x2202,
2909
+ 0xb7: 0x2022,
2910
+ 0xb8: 0xf7,
2911
+ 0xb9: 0x2260,
2912
+ 0xba: 0x2261,
2913
+ 0xbb: 0x2248,
2914
+ 0xbc: 0x2026,
2915
+ 0xbf: 0x21b5,
2916
+ 0xc0: 0x2135,
2917
+ 0xc1: 0x2111,
2918
+ 0xc2: 0x211c,
2919
+ 0xc3: 0x2118,
2920
+ 0xc4: 0x2297,
2921
+ 0xc5: 0x2295,
2922
+ 0xc6: 0x2205,
2923
+ 0xc7: 0x2229,
2924
+ 0xc8: 0x222a,
2925
+ 0xc9: 0x2283,
2926
+ 0xca: 0x2287,
2927
+ 0xcb: 0x2284,
2928
+ 0xcc: 0x2282,
2929
+ 0xcd: 0x2286,
2930
+ 0xce: 0x2208,
2931
+ 0xcf: 0x2209,
2932
+ 0xd0: 0x2220,
2933
+ 0xd1: 0x2207,
2934
+ 0xd5: 0x220f,
2935
+ 0xd6: 0x221a,
2936
+ 0xd7: 0x22c5,
2937
+ 0xd8: 0xac,
2938
+ 0xd9: 0x2227,
2939
+ 0xda: 0x2228,
2940
+ 0xdb: 0x21d4,
2941
+ 0xdc: 0x21d0,
2942
+ 0xdd: 0x21d1,
2943
+ 0xde: 0x21d2,
2944
+ 0xdf: 0x21d3,
2945
+ 0xe0: 0x25ca,
2946
+ 0xe1: 0x2329,
2947
+ 0xe5: 0x2211,
2948
+ 0xf1: 0x232a,
2949
+ 0xf2: 0x222b,
2950
+ 0xf3: 0x2320,
2951
+ 0xf5: 0x2321,
2952
+ };
2953
+ function decodeWordSymbol(font, code) {
2954
+ const original = String.fromCharCode(code);
2955
+ const family = (font ?? "").trim().replace(/^(["'])(.*)\1$/, "$2").trim().toLowerCase();
2956
+ if (family !== "symbol")
2957
+ return { text: original, normalized: false };
2958
+ const slot = code >= 0xf000 && code <= 0xf0ff ? code - 0xf000 : code;
2959
+ const unicode = slot >= 0 && slot <= 0xff ? symbolEncoding[slot] : undefined;
2960
+ const text = unicode === undefined ? original : String.fromCharCode(unicode);
2961
+ return { text, normalized: text !== original };
2962
+ }
2963
+
2778
2964
  const PLACEABLE_KEY = 0x9ac6cdd7;
2779
2965
  const META = {
2780
2966
  EOF: 0x0000,
@@ -2849,7 +3035,7 @@
2849
3035
  return null;
2850
3036
  const fileSizeWords = view.getUint32(offset + 6, true);
2851
3037
  const objectCount = Math.max(1, view.getUint16(offset + 10, true) || 16);
2852
- const declaredBytes = fileSizeWords > 0 ? fileSizeWords * 2 : view.byteLength;
3038
+ const declaredEnd = fileSizeWords > 0 ? offset + fileSizeWords * 2 : view.byteLength;
2853
3039
  offset += 18;
2854
3040
  const width = Math.max(1, bounds.right - bounds.left);
2855
3041
  const height = Math.max(1, bounds.bottom - bounds.top);
@@ -2860,7 +3046,7 @@
2860
3046
  let records = 0;
2861
3047
  const maxRecords = options.maxRecords ?? 10000;
2862
3048
  const maxShapes = options.maxShapes ?? 50000;
2863
- const endLimit = Math.min(view.byteLength, declaredBytes);
3049
+ const endLimit = Math.min(view.byteLength, declaredEnd);
2864
3050
  const emit = (markup) => {
2865
3051
  if (!markup || shapeCount >= maxShapes)
2866
3052
  return;
@@ -2871,13 +3057,10 @@
2871
3057
  const sizeWords = view.getUint32(offset, true);
2872
3058
  const fn = view.getUint16(offset + 4, true);
2873
3059
  const end = offset + sizeWords * 2;
2874
- if (sizeWords < 3 || end > view.byteLength)
3060
+ if (fn == META.EOF || sizeWords < 3 || end > endLimit)
2875
3061
  break;
2876
3062
  const params = offset + 6;
2877
3063
  switch (fn) {
2878
- case META.EOF:
2879
- offset = endLimit;
2880
- break;
2881
3064
  case META.SETBKMODE:
2882
3065
  state.bkMode = readInt16(view, params);
2883
3066
  break;
@@ -2990,8 +3173,11 @@
2990
3173
  };
2991
3174
  }
2992
3175
  function transformScalarX(state, value) {
3176
+ return Math.abs(transformDeltaX(state, value));
3177
+ }
3178
+ function transformDeltaX(state, value) {
2993
3179
  const viewportExt = state.viewportExt ?? state.windowExt;
2994
- return Math.abs(value * safeRatio(viewportExt.x, state.windowExt.x));
3180
+ return value * safeRatio(viewportExt.x, state.windowExt.x);
2995
3181
  }
2996
3182
  function transformScalarY(state, value) {
2997
3183
  const viewportExt = state.viewportExt ?? state.windowExt;
@@ -3064,7 +3250,7 @@
3064
3250
  const alignedStringEnd = stringOffset + count + (count % 2);
3065
3251
  if (alignedStringEnd + 4 > end)
3066
3252
  return;
3067
- const text = decodeText(view, stringOffset, count, state.font.charset);
3253
+ const text = decodeText(readTextBytes(view, stringOffset, count), state.font);
3068
3254
  const y = readInt16(view, alignedStringEnd);
3069
3255
  const x = readInt16(view, alignedStringEnd + 2);
3070
3256
  emitText(text, resolveTextPoint(state, { x, y }), null, state, emit);
@@ -3078,17 +3264,16 @@
3078
3264
  let pos = offset + 8;
3079
3265
  if (options & 0x0006)
3080
3266
  pos += 8;
3081
- if (pos + count > end)
3267
+ if (pos + count + (count % 2) > end)
3082
3268
  return;
3083
- const text = decodeText(view, pos, count, state.font.charset);
3269
+ const bytes = readTextBytes(view, pos, count);
3270
+ const text = decodeText(bytes, state.font);
3084
3271
  pos += count + (count % 2);
3085
- const dx = [];
3086
- while (pos + 2 <= end && dx.length < count) {
3087
- dx.push(readInt16(view, pos));
3088
- pos += 2;
3089
- }
3090
- emitText(text, resolveTextPoint(state, { x, y }), dx.length ? dx : null, state, emit);
3091
- advanceCurrentPoint(text, dx.length ? dx : null, state);
3272
+ const dx = count > 0 && pos + count * 2 <= end
3273
+ ? Array.from({ length: count }, (_, i) => readInt16(view, pos + i * 2))
3274
+ : null;
3275
+ emitText(text, resolveTextPoint(state, { x, y }), groupGlyphAdvances(bytes, text, dx, state.font), state, emit);
3276
+ advanceCurrentPoint(text, dx, state);
3092
3277
  }
3093
3278
  function resolveTextPoint(state, declared) {
3094
3279
  if (state.textAlign & 0x0001)
@@ -3102,7 +3287,7 @@
3102
3287
  ? dx.reduce((sum, value) => sum + value, 0)
3103
3288
  : text.length * state.font.size * 0.5;
3104
3289
  state.currentPoint = {
3105
- x: state.currentPoint.x + transformScalarX(state, logicalAdvance),
3290
+ x: state.currentPoint.x + transformDeltaX(state, logicalAdvance),
3106
3291
  y: state.currentPoint.y
3107
3292
  };
3108
3293
  }
@@ -3111,8 +3296,11 @@
3111
3296
  return;
3112
3297
  const font = state.font;
3113
3298
  const size = Math.max(1, transformScalarY(state, font.size));
3299
+ const symbol = isSymbolFont(font);
3300
+ const family = symbol ? "Cambria Math, Times New Roman, serif" : quoteFont(font.family);
3301
+ const symbolAttr = symbol ? ` font-family="${escAttr(font.family)}"` : "";
3114
3302
  const style = [
3115
- `font-family:${quoteFont(font.family)}`,
3303
+ `font-family:${family}`,
3116
3304
  `font-size:${fmt(size)}px`,
3117
3305
  `font-weight:${font.weight >= 600 ? "700" : font.weight}`,
3118
3306
  `font-style:${font.italic ? "italic" : "normal"}`,
@@ -3133,14 +3321,17 @@
3133
3321
  textAnchorAttr(state.textAlign),
3134
3322
  ].filter(Boolean).join(" ");
3135
3323
  if (!dx || dx.length == 0) {
3136
- emit(`<text ${attrs}>${esc(text)}</text>`);
3324
+ const escaped = esc(text);
3325
+ const content = symbol ? escaped.replace(/[\uf000-\uf0ff]+/g, glyphs => `<tspan${symbolAttr}>${glyphs}</tspan>`) : escaped;
3326
+ emit(`<text ${attrs}>${content}</text>`);
3137
3327
  return;
3138
3328
  }
3139
3329
  let x = point.x;
3140
3330
  const chars = Array.from(text);
3141
3331
  const tspans = chars.map((ch, i) => {
3142
- const t = `<tspan x="${fmt(x)}">${esc(ch)}</tspan>`;
3143
- x += transformScalarX(state, dx[i] ?? 0);
3332
+ const fontAttr = symbol && /[\uf000-\uf0ff]/.test(ch) ? symbolAttr : "";
3333
+ const t = `<tspan x="${fmt(x)}"${fontAttr}>${esc(ch)}</tspan>`;
3334
+ x += transformDeltaX(state, dx[i] ?? 0);
3144
3335
  return t;
3145
3336
  }).join("");
3146
3337
  emit(`<text ${attrs}>${tspans}</text>`);
@@ -3173,8 +3364,19 @@
3173
3364
  return `text-anchor="middle"`;
3174
3365
  return "";
3175
3366
  }
3176
- function decodeText(view, offset, count, charset) {
3177
- const bytes = new Uint8Array(view.buffer, view.byteOffset + offset, Math.max(0, Math.min(count, view.byteLength - offset)));
3367
+ function readTextBytes(view, offset, count) {
3368
+ return new Uint8Array(view.buffer, view.byteOffset + offset, count);
3369
+ }
3370
+ function isSymbolFont(font) {
3371
+ return font.family.toLowerCase() === "symbol";
3372
+ }
3373
+ function decodeText(bytes, font) {
3374
+ if (isSymbolFont(font)) {
3375
+ return Array.from(bytes, byte => byte == 0 || byte == 0x20
3376
+ ? String.fromCharCode(byte)
3377
+ : decodeWordSymbol(font.family, 0xf000 + byte).text).join("").replace(/\0+$/g, "");
3378
+ }
3379
+ const charset = font.charset;
3178
3380
  const preferred = charset == 2 ? "symbol" : charset == 134 ? "gb18030" : "windows-1252";
3179
3381
  try {
3180
3382
  return new TextDecoder(preferred).decode(bytes).replace(/\0+$/g, "");
@@ -3186,6 +3388,29 @@
3186
3388
  return result.replace(/\0+$/g, "");
3187
3389
  }
3188
3390
  }
3391
+ function groupGlyphAdvances(bytes, text, dx, font) {
3392
+ if (!dx || font.charset != 134 || isSymbolFont(font))
3393
+ return dx;
3394
+ const glyphCount = Array.from(text).length;
3395
+ if (glyphCount == bytes.length)
3396
+ return dx;
3397
+ const decoder = new TextDecoder("gb18030");
3398
+ const advances = [];
3399
+ let advance = 0;
3400
+ for (let i = 0; i < bytes.length; i++) {
3401
+ advance += dx[i];
3402
+ const glyph = decoder.decode(bytes.subarray(i, i + 1), { stream: true });
3403
+ if (!glyph)
3404
+ continue;
3405
+ if (Array.from(glyph).length != 1)
3406
+ return null;
3407
+ advances.push(advance);
3408
+ advance = 0;
3409
+ }
3410
+ if (decoder.decode())
3411
+ advances.push(advance);
3412
+ return advances.length >= glyphCount ? advances : null;
3413
+ }
3189
3414
  function readPointYX(view, offset) {
3190
3415
  return { y: readInt16(view, offset), x: readInt16(view, offset + 2) };
3191
3416
  }
@@ -5056,7 +5281,11 @@
5056
5281
  const result = { type: DomType.VmlPicture, children: [] };
5057
5282
  for (const el of globalXmlParser.elements(elem)) {
5058
5283
  const child = parseVmlElement(el, this);
5059
- child && result.children.push(child);
5284
+ if (!child)
5285
+ continue;
5286
+ if (elem.localName === "object" && child.tagName === "image" && child.cssStyle?.position !== "absolute")
5287
+ child.props = { ...child.props, inlineObjectPreview: true };
5288
+ result.children.push(child);
5060
5289
  }
5061
5290
  return result;
5062
5291
  }
@@ -6897,190 +7126,20 @@
6897
7126
  }
6898
7127
  }
6899
7128
 
6900
- /*! @license Adobe Symbol Encoding to Unicode
6901
- * Copyright (c) 1991-2011 Unicode, Inc. All Rights reserved.
6902
- *
6903
- * This file is provided as-is by Unicode, Inc. (The Unicode Consortium). No
6904
- * claims are made as to fitness for any particular purpose. No warranties of
6905
- * any kind are expressed or implied. The recipient agrees to determine
6906
- * applicability of information provided. If this file has been provided on
6907
- * magnetic media by Unicode, Inc., the sole remedy for any claim will be
6908
- * exchange of defective media within 90 days of receipt.
6909
- *
6910
- * Unicode, Inc. hereby grants the right to freely use the information
6911
- * supplied in this file in the creation of products supporting the
6912
- * Unicode Standard, and to make copies of this file in any form for
6913
- * internal or external distribution as long as this notice remains
6914
- * attached.
6915
- *
6916
- * Source: https://www.unicode.org/Public/MAPPINGS/VENDORS/ADOBE/symbol.txt
6917
- */
6918
- const symbolEncoding = {
6919
- 0x21: 0x21,
6920
- 0x22: 0x2200,
6921
- 0x23: 0x23,
6922
- 0x24: 0x2203,
6923
- 0x25: 0x25,
6924
- 0x26: 0x26,
6925
- 0x27: 0x220b,
6926
- 0x28: 0x28,
6927
- 0x29: 0x29,
6928
- 0x2a: 0x2217,
6929
- 0x2b: 0x2b,
6930
- 0x2c: 0x2c,
6931
- 0x2d: 0x2212,
6932
- 0x2e: 0x2e,
6933
- 0x2f: 0x2f,
6934
- 0x30: 0x30,
6935
- 0x31: 0x31,
6936
- 0x32: 0x32,
6937
- 0x33: 0x33,
6938
- 0x34: 0x34,
6939
- 0x35: 0x35,
6940
- 0x36: 0x36,
6941
- 0x37: 0x37,
6942
- 0x38: 0x38,
6943
- 0x39: 0x39,
6944
- 0x3a: 0x3a,
6945
- 0x3b: 0x3b,
6946
- 0x3c: 0x3c,
6947
- 0x3d: 0x3d,
6948
- 0x3e: 0x3e,
6949
- 0x3f: 0x3f,
6950
- 0x40: 0x2245,
6951
- 0x41: 0x391,
6952
- 0x42: 0x392,
6953
- 0x43: 0x3a7,
6954
- 0x45: 0x395,
6955
- 0x46: 0x3a6,
6956
- 0x47: 0x393,
6957
- 0x48: 0x397,
6958
- 0x49: 0x399,
6959
- 0x4a: 0x3d1,
6960
- 0x4b: 0x39a,
6961
- 0x4c: 0x39b,
6962
- 0x4d: 0x39c,
6963
- 0x4e: 0x39d,
6964
- 0x4f: 0x39f,
6965
- 0x50: 0x3a0,
6966
- 0x51: 0x398,
6967
- 0x52: 0x3a1,
6968
- 0x53: 0x3a3,
6969
- 0x54: 0x3a4,
6970
- 0x55: 0x3a5,
6971
- 0x56: 0x3c2,
6972
- 0x58: 0x39e,
6973
- 0x59: 0x3a8,
6974
- 0x5a: 0x396,
6975
- 0x5b: 0x5b,
6976
- 0x5c: 0x2234,
6977
- 0x5d: 0x5d,
6978
- 0x5e: 0x22a5,
6979
- 0x5f: 0x5f,
6980
- 0x61: 0x3b1,
6981
- 0x62: 0x3b2,
6982
- 0x63: 0x3c7,
6983
- 0x64: 0x3b4,
6984
- 0x65: 0x3b5,
6985
- 0x66: 0x3c6,
6986
- 0x67: 0x3b3,
6987
- 0x68: 0x3b7,
6988
- 0x69: 0x3b9,
6989
- 0x6a: 0x3d5,
6990
- 0x6b: 0x3ba,
6991
- 0x6c: 0x3bb,
6992
- 0x6e: 0x3bd,
6993
- 0x6f: 0x3bf,
6994
- 0x70: 0x3c0,
6995
- 0x71: 0x3b8,
6996
- 0x72: 0x3c1,
6997
- 0x73: 0x3c3,
6998
- 0x74: 0x3c4,
6999
- 0x75: 0x3c5,
7000
- 0x76: 0x3d6,
7001
- 0x77: 0x3c9,
7002
- 0x78: 0x3be,
7003
- 0x79: 0x3c8,
7004
- 0x7a: 0x3b6,
7005
- 0x7b: 0x7b,
7006
- 0x7c: 0x7c,
7007
- 0x7d: 0x7d,
7008
- 0x7e: 0x223c,
7009
- 0xa0: 0x20ac,
7010
- 0xa1: 0x3d2,
7011
- 0xa2: 0x2032,
7012
- 0xa3: 0x2264,
7013
- 0xa5: 0x221e,
7014
- 0xa6: 0x192,
7015
- 0xa7: 0x2663,
7016
- 0xa8: 0x2666,
7017
- 0xa9: 0x2665,
7018
- 0xaa: 0x2660,
7019
- 0xab: 0x2194,
7020
- 0xac: 0x2190,
7021
- 0xad: 0x2191,
7022
- 0xae: 0x2192,
7023
- 0xaf: 0x2193,
7024
- 0xb0: 0xb0,
7025
- 0xb1: 0xb1,
7026
- 0xb2: 0x2033,
7027
- 0xb3: 0x2265,
7028
- 0xb4: 0xd7,
7029
- 0xb5: 0x221d,
7030
- 0xb6: 0x2202,
7031
- 0xb7: 0x2022,
7032
- 0xb8: 0xf7,
7033
- 0xb9: 0x2260,
7034
- 0xba: 0x2261,
7035
- 0xbb: 0x2248,
7036
- 0xbc: 0x2026,
7037
- 0xbf: 0x21b5,
7038
- 0xc0: 0x2135,
7039
- 0xc1: 0x2111,
7040
- 0xc2: 0x211c,
7041
- 0xc3: 0x2118,
7042
- 0xc4: 0x2297,
7043
- 0xc5: 0x2295,
7044
- 0xc6: 0x2205,
7045
- 0xc7: 0x2229,
7046
- 0xc8: 0x222a,
7047
- 0xc9: 0x2283,
7048
- 0xca: 0x2287,
7049
- 0xcb: 0x2284,
7050
- 0xcc: 0x2282,
7051
- 0xcd: 0x2286,
7052
- 0xce: 0x2208,
7053
- 0xcf: 0x2209,
7054
- 0xd0: 0x2220,
7055
- 0xd1: 0x2207,
7056
- 0xd5: 0x220f,
7057
- 0xd6: 0x221a,
7058
- 0xd7: 0x22c5,
7059
- 0xd8: 0xac,
7060
- 0xd9: 0x2227,
7061
- 0xda: 0x2228,
7062
- 0xdb: 0x21d4,
7063
- 0xdc: 0x21d0,
7064
- 0xdd: 0x21d1,
7065
- 0xde: 0x21d2,
7066
- 0xdf: 0x21d3,
7067
- 0xe0: 0x25ca,
7068
- 0xe1: 0x2329,
7069
- 0xe5: 0x2211,
7070
- 0xf1: 0x232a,
7071
- 0xf2: 0x222b,
7072
- 0xf3: 0x2320,
7073
- 0xf5: 0x2321,
7074
- };
7075
- function decodeWordSymbol(font, code) {
7076
- const original = String.fromCharCode(code);
7077
- const family = (font ?? "").trim().replace(/^(["'])(.*)\1$/, "$2").trim().toLowerCase();
7078
- if (family !== "symbol")
7079
- return { text: original, normalized: false };
7080
- const slot = code >= 0xf000 && code <= 0xf0ff ? code - 0xf000 : code;
7081
- const unicode = slot >= 0 && slot <= 0xff ? symbolEncoding[slot] : undefined;
7082
- const text = unicode === undefined ? original : String.fromCharCode(unicode);
7083
- return { text, normalized: text !== original };
7129
+ const eastAsianCharacter = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Bopomofo}\p{Script=Yi}\u2e80-\u2fff\u3000-\u303f\u31c0-\u31ef\u3200-\u33ff\ufe10-\ufe1f\ufe30-\ufe6f\uff00-\uffef]/u;
7130
+ const precedingFont = /[\p{Mark}\u200c\u200d\u2060]/u;
7131
+ function fontScriptRuns(text, previousEastAsian = false) {
7132
+ const runs = [];
7133
+ for (const character of text) {
7134
+ const previous = runs[runs.length - 1];
7135
+ const eastAsian = precedingFont.test(character)
7136
+ ? previous?.eastAsian ?? previousEastAsian : eastAsianCharacter.test(character);
7137
+ if (previous?.eastAsian === eastAsian)
7138
+ previous.text += character;
7139
+ else
7140
+ runs.push({ text: character, eastAsian });
7141
+ }
7142
+ return runs;
7084
7143
  }
7085
7144
 
7086
7145
  class CommentLayer {
@@ -8858,6 +8917,7 @@
8858
8917
  this.currentTabs = [];
8859
8918
  this.anchorLayouts = new Map();
8860
8919
  this.currentParagraph = null;
8920
+ this.currentRunFont = null;
8861
8921
  this.currentParagraphTabIndex = 0;
8862
8922
  this.currentParagraphTabCount = 0;
8863
8923
  this.commentMap = {};
@@ -9914,7 +9974,7 @@
9914
9974
  this.setCssStyle(result, "--docx-latin-font-family", latin);
9915
9975
  this.setCssStyle(result, "font-family", `var(--docx-latin-font-family), ${family}`);
9916
9976
  }
9917
- applyRunFontSlots(elem, style, result) {
9977
+ resolveRunFontSlots(elem, style) {
9918
9978
  const paragraph = elem.type == DomType.Paragraph ? elem : this.currentParagraph;
9919
9979
  const paragraphStyle = this.findStyle(paragraph?.styleName) ?? this.defaultParagraphStyle;
9920
9980
  const levels = [elem.cssStyle, ...this.styleValueLevels(style, "span"),
@@ -9940,18 +10000,29 @@
9940
10000
  && !/[\p{Script=Latin}\p{Script=Cyrillic}\p{Script=Han}]/u.test(text))
9941
10001
  || isAdditionalComplexScriptRun(text)));
9942
10002
  const highAnsi = /[\p{Script=Cyrillic}\p{Script=Greek}]/u.test(text);
10003
+ const scriptRuns = fontScriptRuns(text);
10004
+ const eastAsianOnly = scriptRuns.length && scriptRuns.every(run => run.eastAsian);
9943
10005
  const slots = complex ? ["complex", "ascii", "hansi", "eastasia"]
9944
- : highAnsi ? ["hansi", "ascii", "eastasia", "complex"] : ["ascii", "hansi", "eastasia", "complex"];
9945
- const fonts = slots.map(slot => {
10006
+ : eastAsianOnly ? ["eastasia", "ascii", "hansi", "complex"]
10007
+ : highAnsi ? ["hansi", "ascii", "eastasia", "complex"] : ["ascii", "hansi", "eastasia", "complex"];
10008
+ const resolveFonts = (slots) => slots.map(slot => {
9946
10009
  const font = value(`--docx-font-${slot}`);
9947
10010
  return slot == "eastasia" ? themedFont(font, language("$lang-eastAsia"))
9948
10011
  : slot == "complex" ? themedFont(font, language("$lang-bidi")) : font;
9949
10012
  }).filter(Boolean);
9950
- if (fonts.length)
9951
- this.setCssStyle(result, "font-family", [...new Set(fonts)].join(', '));
9952
- if (complex && value("--docx-complex-font-size")) {
9953
- this.setCssStyle(result, "font-size", value("--docx-complex-font-size"));
9954
- this.setCssStyle(result, "min-height", value("--docx-complex-font-size"));
10013
+ const fontFamily = [...new Set(resolveFonts(slots))].join(', ');
10014
+ const eastAsianFontFamily = !complex && value("--docx-font-eastasia")
10015
+ ? [...new Set(resolveFonts(["eastasia", ...slots.filter(slot => slot !== "eastasia")]))].join(', ') : null;
10016
+ return { fontFamily, eastAsianFontFamily,
10017
+ splitEastAsia: !!eastAsianFontFamily && eastAsianFontFamily !== fontFamily && scriptRuns.some(run => run.eastAsian),
10018
+ complexFontSize: complex ? value("--docx-complex-font-size") : null, previousEastAsian: false };
10019
+ }
10020
+ applyRunFontSlots(elem, style, result, font = this.resolveRunFontSlots(elem, style)) {
10021
+ if (font.fontFamily)
10022
+ this.setCssStyle(result, "font-family", font.fontFamily);
10023
+ if (font.complexFontSize) {
10024
+ this.setCssStyle(result, "font-size", font.complexFontSize);
10025
+ this.setCssStyle(result, "min-height", font.complexFontSize);
9955
10026
  }
9956
10027
  }
9957
10028
  isInsideTableCell(elem) {
@@ -14365,7 +14436,14 @@ section.${c}>footer { z-index: 1; }
14365
14436
  return false;
14366
14437
  }
14367
14438
  renderText(elem) {
14368
- return this.h(this.applyCjkLineBreakGuards(elem.text));
14439
+ const text = this.applyCjkLineBreakGuards(elem.text);
14440
+ if (!this.currentRunFont?.splitEastAsia)
14441
+ return this.h(text);
14442
+ const fragments = fontScriptRuns(text, this.currentRunFont.previousEastAsian);
14443
+ this.currentRunFont.previousEastAsian = fragments[fragments.length - 1]?.eastAsian ?? this.currentRunFont.previousEastAsian;
14444
+ return this.h({ tagName: "#fragment", children: fragments.map(run => run.eastAsian
14445
+ ? this.h({ tagName: "span", className: `${this.className}-font-eastasia`, style: { fontFamily: this.currentRunFont.eastAsianFontFamily }, children: [run.text] })
14446
+ : this.h(run.text)) });
14369
14447
  }
14370
14448
  applyCjkLineBreakGuards(text) {
14371
14449
  if (!text || !this.document.settingsPart?.settings?.kinsoku)
@@ -14547,7 +14625,17 @@ section.${c}>footer { z-index: 1; }
14547
14625
  : elem.children;
14548
14626
  if (elem.fieldRun && (!runChildren || runChildren.length == 0))
14549
14627
  return null;
14550
- let children = this.renderElements(runChildren);
14628
+ const previousFont = this.currentRunFont;
14629
+ const style = this.findStyle(elem.styleName);
14630
+ const font = this.resolveRunFontSlots(elem, style);
14631
+ this.currentRunFont = font;
14632
+ let children;
14633
+ try {
14634
+ children = this.renderElements(runChildren);
14635
+ }
14636
+ finally {
14637
+ this.currentRunFont = previousFont;
14638
+ }
14551
14639
  if (elem.verticalAlign) {
14552
14640
  children = [this.h({ tagName: elem.verticalAlign, children })];
14553
14641
  }
@@ -14564,9 +14652,8 @@ section.${c}>footer { z-index: 1; }
14564
14652
  return tab;
14565
14653
  }
14566
14654
  const result = this.toHTML(elem, ns.html, "span", children);
14567
- const style = this.findStyle(elem.styleName);
14568
14655
  this.applyTextBoxFontInheritance(elem, style, result);
14569
- this.applyRunFontSlots(elem, style, result);
14656
+ this.applyRunFontSlots(elem, style, result, font);
14570
14657
  const snapToGrid = elem.cssStyle?.["--docx-snap-to-grid"] ?? this.styleValue(style, "span", "--docx-snap-to-grid");
14571
14658
  if (/^(0|false|off)$/i.test(snapToGrid ?? ""))
14572
14659
  result.style.letterSpacing = "normal";
@@ -14667,7 +14754,9 @@ section.${c}>footer { z-index: 1; }
14667
14754
  }
14668
14755
  renderVmlPicture(elem) {
14669
14756
  const result = this.renderContainer(elem, this.currentParagraph ? "span" : "div");
14670
- result.style.display = "block";
14757
+ const shape = elem.children?.length === 1 ? elem.children[0] : null;
14758
+ const inlinePreview = !!this.currentParagraph && shape?.props?.inlineObjectPreview;
14759
+ result.style.display = inlinePreview ? "inline-block" : "block";
14671
14760
  return result;
14672
14761
  }
14673
14762
  vmlLengthInPoints(value) {
@@ -14844,7 +14933,10 @@ section.${c}>footer { z-index: 1; }
14844
14933
  viewport.setAttribute("y", `${bounds.y}`);
14845
14934
  viewport.setAttribute("width", `${bounds.width}`);
14846
14935
  viewport.setAttribute("height", `${bounds.height}`);
14847
- viewport.setAttribute("viewBox", "0 0 100 100");
14936
+ const imageViewBox = elem.props?.inlineObjectPreview && bounds.width > 0 && bounds.height > 0
14937
+ ? `0 0 ${bounds.width} ${bounds.height}`
14938
+ : "0 0 100 100";
14939
+ viewport.setAttribute("viewBox", imageViewBox);
14848
14940
  viewport.setAttribute("preserveAspectRatio", "none");
14849
14941
  viewport.setAttribute("overflow", "hidden");
14850
14942
  const image = this.createSvgElement("image");