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