kordoc 4.22.3 → 4.22.5
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/README.md +9 -7
- package/dist/{-AOWV7MNY.js → -WFRWBH7T.js} +11 -11
- package/dist/{chunk-3ANXRVI2.js → chunk-2L3Q7REU.js} +3 -3
- package/dist/{chunk-FDFXL7VJ.js → chunk-35ZHXEJA.js} +3 -3
- package/dist/{chunk-BS2XWGT5.js → chunk-3BR7VKWL.js} +2 -2
- package/dist/{chunk-KBGNPGVY.js → chunk-3G3TLZDK.js} +2 -2
- package/dist/{chunk-M2X766AY.js → chunk-3YEL7P4L.js} +2 -2
- package/dist/{chunk-NJEMRAIF.cjs → chunk-4SUB43EJ.cjs} +24 -24
- package/dist/{chunk-NJEMRAIF.cjs.map → chunk-4SUB43EJ.cjs.map} +1 -1
- package/dist/{chunk-DKJ2RNDG.js → chunk-4TWN7PWJ.js} +2 -2
- package/dist/{chunk-UCLDUUBX.js → chunk-52HIK4C2.js} +4 -3
- package/dist/chunk-52HIK4C2.js.map +1 -0
- package/dist/{chunk-3H2IEU4V.js → chunk-63N6CEJE.js} +2 -2
- package/dist/{chunk-MEIQ476H.js → chunk-6MCC2XNB.js} +2 -2
- package/dist/{chunk-SKRWKVVW.js → chunk-6MQKNB6K.js} +15 -8
- package/dist/chunk-6MQKNB6K.js.map +1 -0
- package/dist/{chunk-MI655NV5.cjs → chunk-AS25R4EU.cjs} +2 -2
- package/dist/{chunk-MI655NV5.cjs.map → chunk-AS25R4EU.cjs.map} +1 -1
- package/dist/{chunk-4NQ4EZEE.js → chunk-C3REGEQO.js} +2 -2
- package/dist/{chunk-NLGOMLGU.cjs → chunk-C6B5GWN7.cjs} +35 -28
- package/dist/chunk-C6B5GWN7.cjs.map +1 -0
- package/dist/{chunk-6LIBF2ZB.js → chunk-CO7O3ZT6.js} +2 -2
- package/dist/{chunk-IRNWAHHZ.js → chunk-CRSTBATY.js} +2 -2
- package/dist/{chunk-VJCQOSMT.js → chunk-CW67DAAH.js} +2 -2
- package/dist/{chunk-6QBBGZST.js → chunk-DN55FTJP.js} +2 -2
- package/dist/{chunk-OIF5HRVP.js → chunk-HLPMC7L4.js} +16 -9
- package/dist/chunk-HLPMC7L4.js.map +1 -0
- package/dist/{chunk-24YLYR6Q.js → chunk-LE4VHWIT.js} +4 -4
- package/dist/{chunk-2BCQVQO2.cjs → chunk-N6KXGIIN.cjs} +3 -3
- package/dist/{chunk-2BCQVQO2.cjs.map → chunk-N6KXGIIN.cjs.map} +1 -1
- package/dist/{chunk-7XITVUAK.js → chunk-PSORL4PA.js} +11 -11
- package/dist/{chunk-AXX5AQT4.js → chunk-RYKDIUHT.js} +4 -4
- package/dist/{chunk-O5E25RHU.js → chunk-SETAYS6P.js} +2 -2
- package/dist/{chunk-X45Q7EAC.js → chunk-T7OZ7X6A.js} +2 -2
- package/dist/{chunk-J5PYESLX.js → chunk-TOUJCO2P.js} +2 -2
- package/dist/{chunk-YOGMCRM7.js → chunk-U3GUZQ54.js} +1353 -1335
- package/dist/chunk-U3GUZQ54.js.map +1 -0
- package/dist/{chunk-O3OS6FAW.cjs → chunk-UCK6WGHY.cjs} +3 -3
- package/dist/{chunk-O3OS6FAW.cjs.map → chunk-UCK6WGHY.cjs.map} +1 -1
- package/dist/{chunk-SJ5OZXEL.cjs → chunk-YG4GFQB7.cjs} +6 -6
- package/dist/{chunk-SJ5OZXEL.cjs.map → chunk-YG4GFQB7.cjs.map} +1 -1
- package/dist/chunks-NXABWR6G.js +10 -0
- package/dist/cli.js +30 -30
- package/dist/{formula-W4OL33YQ.js → formula-FSVHUQ6Y.js} +4 -4
- package/dist/{formula-C26FMMGO.js → formula-L625ULJP.js} +3 -3
- package/dist/{formula-5V2WG4BH.cjs → formula-QZGTF3DZ.cjs} +9 -9
- package/dist/{formula-5V2WG4BH.cjs.map → formula-QZGTF3DZ.cjs.map} +1 -1
- package/dist/{image-ocr-BELHEWPX.cjs → image-ocr-AELVAU75.cjs} +17 -17
- package/dist/{image-ocr-BELHEWPX.cjs.map → image-ocr-AELVAU75.cjs.map} +1 -1
- package/dist/{image-ocr-T72HMX2W.js → image-ocr-KE3RUS3R.js} +6 -6
- package/dist/{image-ocr-NSQ34Y6T.js → image-ocr-QTZNBP5V.js} +9 -9
- package/dist/index.cjs +859 -840
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +322 -303
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +22 -22
- package/dist/{model-bundle-34T2LJB4.js → model-bundle-F6TU6ZAV.js} +5 -5
- package/dist/{models-TQH5EM6V.js → models-ZHNNVH2W.js} +5 -5
- package/dist/{parse-worker-v2-YEYLILGJ.js → parse-worker-v2-KQRG3NQO.js} +12 -12
- package/dist/{parser-SJHCBL7T.js → parser-RVMH4PUB.js} +183 -21
- package/dist/parser-RVMH4PUB.js.map +1 -0
- package/dist/{parser-E6BG3ECD.js → parser-WBKVRDPV.js} +179 -17
- package/dist/parser-WBKVRDPV.js.map +1 -0
- package/dist/{parser-OAXCXVQ4.cjs → parser-WNDH2X6N.cjs} +442 -280
- package/dist/parser-WNDH2X6N.cjs.map +1 -0
- package/dist/pdf-ocr-IOUZTPPH.cjs +31 -0
- package/dist/{pdf-ocr-RKXDY3ZA.cjs.map → pdf-ocr-IOUZTPPH.cjs.map} +1 -1
- package/dist/{pdf-ocr-LGPSJM22.js → pdf-ocr-X5XLGL5J.js} +6 -6
- package/dist/{pdf-ocr-T5ASSUKK.js → pdf-ocr-ZP2CUWSO.js} +9 -9
- package/dist/{profile-io-KMCAFTMG.js → profile-io-B4VSI4LW.js} +3 -3
- package/dist/{rasterize-M52AKY7R.js → rasterize-Y7NVUVXU.js} +3 -3
- package/dist/{redact-doc-SWJC27LL.js → redact-doc-GIBTFWCO.js} +11 -11
- package/dist/{render-45AB5YZR.js → render-JVCGYRRO.js} +7 -7
- package/dist/seal-WNX2ZJTK.js +10 -0
- package/dist/{setup-5PBMUI6M.js → setup-7L7EQPMG.js} +3 -3
- package/dist/visual-VPWPXIHN.js +21 -0
- package/dist/{watch-QOGKV52T.js → watch-VYMFGX72.js} +12 -12
- package/package.json +1 -1
- package/dist/chunk-NLGOMLGU.cjs.map +0 -1
- package/dist/chunk-OIF5HRVP.js.map +0 -1
- package/dist/chunk-SKRWKVVW.js.map +0 -1
- package/dist/chunk-UCLDUUBX.js.map +0 -1
- package/dist/chunk-YOGMCRM7.js.map +0 -1
- package/dist/chunks-7KXTS7IV.js +0 -10
- package/dist/parser-E6BG3ECD.js.map +0 -1
- package/dist/parser-OAXCXVQ4.cjs.map +0 -1
- package/dist/parser-SJHCBL7T.js.map +0 -1
- package/dist/pdf-ocr-RKXDY3ZA.cjs +0 -31
- package/dist/seal-7KWG6VHS.js +0 -10
- package/dist/visual-OMJNXLNZ.js +0 -21
- /package/dist/{-AOWV7MNY.js.map → -WFRWBH7T.js.map} +0 -0
- /package/dist/{chunk-3ANXRVI2.js.map → chunk-2L3Q7REU.js.map} +0 -0
- /package/dist/{chunk-FDFXL7VJ.js.map → chunk-35ZHXEJA.js.map} +0 -0
- /package/dist/{chunk-BS2XWGT5.js.map → chunk-3BR7VKWL.js.map} +0 -0
- /package/dist/{chunk-KBGNPGVY.js.map → chunk-3G3TLZDK.js.map} +0 -0
- /package/dist/{chunk-M2X766AY.js.map → chunk-3YEL7P4L.js.map} +0 -0
- /package/dist/{chunk-DKJ2RNDG.js.map → chunk-4TWN7PWJ.js.map} +0 -0
- /package/dist/{chunk-3H2IEU4V.js.map → chunk-63N6CEJE.js.map} +0 -0
- /package/dist/{chunk-MEIQ476H.js.map → chunk-6MCC2XNB.js.map} +0 -0
- /package/dist/{chunk-4NQ4EZEE.js.map → chunk-C3REGEQO.js.map} +0 -0
- /package/dist/{chunk-6LIBF2ZB.js.map → chunk-CO7O3ZT6.js.map} +0 -0
- /package/dist/{chunk-IRNWAHHZ.js.map → chunk-CRSTBATY.js.map} +0 -0
- /package/dist/{chunk-VJCQOSMT.js.map → chunk-CW67DAAH.js.map} +0 -0
- /package/dist/{chunk-6QBBGZST.js.map → chunk-DN55FTJP.js.map} +0 -0
- /package/dist/{chunk-24YLYR6Q.js.map → chunk-LE4VHWIT.js.map} +0 -0
- /package/dist/{chunk-7XITVUAK.js.map → chunk-PSORL4PA.js.map} +0 -0
- /package/dist/{chunk-AXX5AQT4.js.map → chunk-RYKDIUHT.js.map} +0 -0
- /package/dist/{chunk-O5E25RHU.js.map → chunk-SETAYS6P.js.map} +0 -0
- /package/dist/{chunk-X45Q7EAC.js.map → chunk-T7OZ7X6A.js.map} +0 -0
- /package/dist/{chunk-J5PYESLX.js.map → chunk-TOUJCO2P.js.map} +0 -0
- /package/dist/{chunks-7KXTS7IV.js.map → chunks-NXABWR6G.js.map} +0 -0
- /package/dist/{formula-W4OL33YQ.js.map → formula-FSVHUQ6Y.js.map} +0 -0
- /package/dist/{formula-C26FMMGO.js.map → formula-L625ULJP.js.map} +0 -0
- /package/dist/{image-ocr-T72HMX2W.js.map → image-ocr-KE3RUS3R.js.map} +0 -0
- /package/dist/{image-ocr-NSQ34Y6T.js.map → image-ocr-QTZNBP5V.js.map} +0 -0
- /package/dist/{model-bundle-34T2LJB4.js.map → model-bundle-F6TU6ZAV.js.map} +0 -0
- /package/dist/{models-TQH5EM6V.js.map → models-ZHNNVH2W.js.map} +0 -0
- /package/dist/{parse-worker-v2-YEYLILGJ.js.map → parse-worker-v2-KQRG3NQO.js.map} +0 -0
- /package/dist/{pdf-ocr-LGPSJM22.js.map → pdf-ocr-X5XLGL5J.js.map} +0 -0
- /package/dist/{pdf-ocr-T5ASSUKK.js.map → pdf-ocr-ZP2CUWSO.js.map} +0 -0
- /package/dist/{profile-io-KMCAFTMG.js.map → profile-io-B4VSI4LW.js.map} +0 -0
- /package/dist/{rasterize-M52AKY7R.js.map → rasterize-Y7NVUVXU.js.map} +0 -0
- /package/dist/{redact-doc-SWJC27LL.js.map → redact-doc-GIBTFWCO.js.map} +0 -0
- /package/dist/{render-45AB5YZR.js.map → render-JVCGYRRO.js.map} +0 -0
- /package/dist/{seal-7KWG6VHS.js.map → seal-WNX2ZJTK.js.map} +0 -0
- /package/dist/{setup-5PBMUI6M.js.map → setup-7L7EQPMG.js.map} +0 -0
- /package/dist/{visual-OMJNXLNZ.js.map → visual-VPWPXIHN.js.map} +0 -0
- /package/dist/{watch-QOGKV52T.js.map → watch-VYMFGX72.js.map} +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
loadSharp,
|
|
4
4
|
rasterizePageSvg
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-DN55FTJP.js";
|
|
6
6
|
import {
|
|
7
7
|
inlineImagesIntoMarkdown
|
|
8
8
|
} from "./chunk-VKVDMH7X.js";
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
HEADING_RATIO_H3,
|
|
17
17
|
tidyScriptTags,
|
|
18
18
|
unframeLayoutTables
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-C3REGEQO.js";
|
|
20
20
|
import {
|
|
21
21
|
MAX_COLS,
|
|
22
22
|
MAX_ROWS,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
flattenLayoutTables,
|
|
28
28
|
mapPuaText,
|
|
29
29
|
markNonLayoutTable
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-3BR7VKWL.js";
|
|
31
31
|
import {
|
|
32
32
|
DEFAULT_CHAR,
|
|
33
33
|
DEFAULT_PARA_GEOM,
|
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
hwpxAppMajor,
|
|
42
42
|
parseRenderStyles,
|
|
43
43
|
readZipEntry
|
|
44
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-52HIK4C2.js";
|
|
45
45
|
import {
|
|
46
46
|
KordocError,
|
|
47
47
|
compareSectionPaths,
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
precheckZipSize,
|
|
50
50
|
sanitizeHref,
|
|
51
51
|
toArrayBuffer
|
|
52
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-4TWN7PWJ.js";
|
|
53
53
|
|
|
54
54
|
// src/render/svg-render.ts
|
|
55
55
|
import JSZip from "jszip";
|
|
@@ -3248,6 +3248,8 @@ var FACE_SPACE = {
|
|
|
3248
3248
|
"KoPubWorld\uB3CB\uC6C0\uCCB4 Light": 290
|
|
3249
3249
|
};
|
|
3250
3250
|
var BEFORE_2024_WIDTH = {
|
|
3251
|
+
// TTF 신명조의 대체 큰따옴표 — 원본 PDF의 Haansoft Batang /W 370. 한양신명조 HFT와 별개다.
|
|
3252
|
+
"\uC2E0\uBA85\uC870": { 8220: 370, 8221: 370 },
|
|
3251
3253
|
"\uD734\uBA3C\uBA85\uC870": {
|
|
3252
3254
|
183: 1e3,
|
|
3253
3255
|
8211: 430,
|
|
@@ -10424,14 +10426,14 @@ function fontHasGlyph(face, cp) {
|
|
|
10424
10426
|
if (!hasFontMetrics(face)) return false;
|
|
10425
10427
|
return cp >= 32 && cp <= 126 || FONTS[face.trim()].ex[cp] !== void 0;
|
|
10426
10428
|
}
|
|
10427
|
-
var HANCOM_FALLBACK_W = { 8228: 173, 8231: 173, 8211: 430, 8680: 1e3, 8728: 500, 8227: 465, 12295: 1e3 };
|
|
10429
|
+
var HANCOM_FALLBACK_W = { 8228: 173, 8231: 173, 8211: 430, 8680: 1e3, 8728: 500, 8227: 465, 12295: 1e3, 61607: 937 / 2048 * 1e3, 61599: 937 / 2048 * 1e3, 61550: 1529 / 2048 * 1e3 };
|
|
10428
10430
|
function isHanja(cp) {
|
|
10429
10431
|
return cp >= 19968 && cp <= 40959 || cp >= 13312 && cp <= 19903 || cp >= 63744 && cp <= 64255;
|
|
10430
10432
|
}
|
|
10431
|
-
function fontWidthFn(face) {
|
|
10433
|
+
function fontWidthFn(face, fallback = true) {
|
|
10432
10434
|
if (!hasFontMetrics(face)) return null;
|
|
10433
10435
|
const m = FONTS[face.trim()];
|
|
10434
|
-
return (cp) => cp >= 32 && cp <= 126 ? m.ascii[cp - 32] : m.ex[cp] ?? (HANCOM_FALLBACK_W[cp] ?? (isHalfwidthForm(cp) ? 500 : m.han !== void 0 && isHanja(cp) ? m.han : m.cjk));
|
|
10436
|
+
return (cp) => cp >= 32 && cp <= 126 ? m.ascii[cp - 32] : m.ex[cp] ?? ((fallback ? HANCOM_FALLBACK_W[cp] : void 0) ?? (isHalfwidthForm(cp) ? 500 : m.han !== void 0 && isHanja(cp) ? m.han : m.cjk));
|
|
10435
10437
|
}
|
|
10436
10438
|
function isHalfwidthForm(cp) {
|
|
10437
10439
|
return cp >= 65377 && cp <= 65500 || cp >= 65512 && cp <= 65518;
|
|
@@ -10655,20 +10657,20 @@ function fixedPitchWidthEm1000(cp) {
|
|
|
10655
10657
|
return cp < 128 || isHalfwidthForm(cp) ? 500 : 1e3;
|
|
10656
10658
|
}
|
|
10657
10659
|
var PUA_FULL = /* @__PURE__ */ new Set([983729, 983730, 983731, 983732, 983733, 983734, 983803]);
|
|
10658
|
-
function widthFnOf(faceClass) {
|
|
10659
|
-
const base = baseWidthFnOf(faceClass);
|
|
10660
|
+
function widthFnOf(faceClass, fallback = true) {
|
|
10661
|
+
const base = baseWidthFnOf(faceClass, fallback);
|
|
10660
10662
|
const hcr = faceClass === "hcr" || faceClass === "font:\uD568\uCD08\uB86C\uB3CB\uC6C0" || faceClass === "font:\uD568\uCD08\uB86C\uBC14\uD0D5";
|
|
10661
10663
|
const f = (cp) => cp >= 983040 ? PUA_FULL.has(cp) ? 1e3 : 500 : cp === 61600 ? base(32) : !hcr && cp >= 10102 && cp <= 10131 ? 1e3 : base(cp);
|
|
10662
|
-
if (faceClass === "fixedPitch" || faceClass === "cjk") return (cp) => isZeroWidthCp(cp) ? 0 : HANCOM_FALLBACK_W[cp] ?? f(cp);
|
|
10664
|
+
if (fallback && (faceClass === "fixedPitch" || faceClass === "cjk")) return (cp) => isZeroWidthCp(cp) ? 0 : HANCOM_FALLBACK_W[cp] ?? f(cp);
|
|
10663
10665
|
return (cp) => isZeroWidthCp(cp) ? 0 : f(cp);
|
|
10664
10666
|
}
|
|
10665
|
-
function baseWidthFnOf(faceClass) {
|
|
10667
|
+
function baseWidthFnOf(faceClass, fallback = true) {
|
|
10666
10668
|
if (faceClass === "fixedPitch") return fixedPitchWidthEm1000;
|
|
10667
10669
|
if (faceClass === "gothic") return (cp) => isHalfwidthForm(cp) ? 500 : gothicWidthEm1000(cp);
|
|
10668
10670
|
if (faceClass === "cjk") return cjkWidthEm1000;
|
|
10669
10671
|
if (faceClass?.startsWith("font:")) {
|
|
10670
10672
|
const face = faceClass.slice(5);
|
|
10671
|
-
return fontWidthFn(face) ?? gothicWidthEm1000;
|
|
10673
|
+
return fontWidthFn(face, fallback) ?? gothicWidthEm1000;
|
|
10672
10674
|
}
|
|
10673
10675
|
return charWidthEm1000;
|
|
10674
10676
|
}
|
|
@@ -10691,7 +10693,7 @@ function mulDiv(a, b, c) {
|
|
|
10691
10693
|
const e = a * b;
|
|
10692
10694
|
return Math.trunc(e < 0 ? (e - c / 2) / c : (e + c / 2) / c);
|
|
10693
10695
|
}
|
|
10694
|
-
function hancomCharWidth(ch, height, ratioPct, spacingPct, faceClass, emAdd = 0) {
|
|
10696
|
+
function hancomCharWidth(ch, height, ratioPct, spacingPct, faceClass, emAdd = 0, fallback = true) {
|
|
10695
10697
|
const cp = ch.codePointAt(0);
|
|
10696
10698
|
let w;
|
|
10697
10699
|
if (cp === 8197) {
|
|
@@ -10700,7 +10702,7 @@ function hancomCharWidth(ch, height, ratioPct, spacingPct, faceClass, emAdd = 0)
|
|
|
10700
10702
|
} else if (isSpaceCp(cp)) {
|
|
10701
10703
|
const s = Math.trunc(height / 8);
|
|
10702
10704
|
w = 4 * (ratioPct === 100 ? s : mulDiv(s, ratioPct, 100));
|
|
10703
|
-
} else return hancomEmWidth(widthFnOf(faceClass)(cp) + emAdd, height, ratioPct, spacingPct);
|
|
10705
|
+
} else return hancomEmWidth(widthFnOf(faceClass, fallback)(cp) + emAdd, height, ratioPct, spacingPct);
|
|
10704
10706
|
if (spacingPct) w += 4 * mulDiv(Math.trunc(w / 4), spacingPct, 100);
|
|
10705
10707
|
return w;
|
|
10706
10708
|
}
|
|
@@ -11167,7 +11169,8 @@ function pushTextSlots(t, chars, prId, depth, del = { deleted: 0 }) {
|
|
|
11167
11169
|
} else if (tag === "tab") {
|
|
11168
11170
|
if (del.deleted) pushFillers(chars, 8, prId);
|
|
11169
11171
|
else {
|
|
11170
|
-
|
|
11172
|
+
const width = num(el, "width", -1);
|
|
11173
|
+
chars.push({ ch: "", prId, tab: true, ...width >= 0 ? { tabW: width } : {}, ...el.getAttribute("type") === "2" ? { tabRight: true } : {} });
|
|
11171
11174
|
pushFillers(chars, 7, prId);
|
|
11172
11175
|
}
|
|
11173
11176
|
} else if (tag === "titleMark") {
|
|
@@ -11306,10 +11309,13 @@ function captionExtra(el) {
|
|
|
11306
11309
|
return c && (c.side === "TOP" || c.side === "BOTTOM") ? c.h + c.gap : 0;
|
|
11307
11310
|
}
|
|
11308
11311
|
var DEFAULT_TAB_HU = 4e3;
|
|
11309
|
-
function
|
|
11312
|
+
function paraHeadAdvance(head, offsetHeight, width) {
|
|
11313
|
+
return width + (head.offsetPct ? Math.trunc(offsetHeight * head.offset / 100) : head.offset);
|
|
11314
|
+
}
|
|
11315
|
+
function tabAdvance(x, firstLine, geom, saved) {
|
|
11310
11316
|
const hang = geom && geom.marginIntent < 0 ? -geom.marginIntent : 0;
|
|
11311
11317
|
if (firstLine && geom?.autoTabLeft && hang > 0 && x < hang - 0.5) return hang - x;
|
|
11312
|
-
if (saved
|
|
11318
|
+
if (saved != null && saved >= 0) return saved;
|
|
11313
11319
|
return (Math.floor(x / DEFAULT_TAB_HU) + 1) * DEFAULT_TAB_HU - x;
|
|
11314
11320
|
}
|
|
11315
11321
|
function cellColumns(sub) {
|
|
@@ -11615,10 +11621,8 @@ function cellRowRemainder(cells, row, avail, from, record, bases, carries, style
|
|
|
11615
11621
|
const end = Math.max(...lines.map((l) => l[1]));
|
|
11616
11622
|
const k = lines.findIndex((l) => c.marginT + l[1] > avail - c.marginB);
|
|
11617
11623
|
if (k < 0) {
|
|
11618
|
-
|
|
11619
|
-
|
|
11620
|
-
rem = Math.max(rem, c.marginT + carry + c.marginB);
|
|
11621
|
-
}
|
|
11624
|
+
placed = true;
|
|
11625
|
+
if (carry > 0) rem = Math.max(rem, c.marginT + carry + c.marginB);
|
|
11622
11626
|
cuts.push([c.el, base + end + 1, base]);
|
|
11623
11627
|
continue;
|
|
11624
11628
|
}
|
|
@@ -11932,18 +11936,36 @@ function appendNarrowLineFragments(parent, seg, free, box, flow) {
|
|
|
11932
11936
|
return true;
|
|
11933
11937
|
}
|
|
11934
11938
|
|
|
11939
|
+
// src/render/reflow-borders.ts
|
|
11940
|
+
function lineBorderBox(model, styles, start, end) {
|
|
11941
|
+
const empty = model.chars.length === 0 && model.objs.length === 0;
|
|
11942
|
+
let top = 0, all = 0;
|
|
11943
|
+
const include = (prId) => {
|
|
11944
|
+
const st = prId != null ? styles.charPr.get(prId) : void 0;
|
|
11945
|
+
const f = st?.borderFill != null ? styles.borderFill.get(st.borderFill) : void 0;
|
|
11946
|
+
if (!f || !f.top && !f.bottom) return;
|
|
11947
|
+
const width = (pt3) => empty ? 2 * Math.trunc(pt3 * 50) : Math.trunc(pt3 * 100);
|
|
11948
|
+
const t = f.top ? width(f.top.widthPt) : 0, b = f.bottom ? width(f.bottom.widthPt) : 0;
|
|
11949
|
+
top = Math.max(top, st.height + t);
|
|
11950
|
+
all = Math.max(all, st.height + t + b);
|
|
11951
|
+
};
|
|
11952
|
+
if (empty) for (const run of model.runs) include(run.prId);
|
|
11953
|
+
else for (let i = start; i < end; i++) if (model.chars[i].ch) include(model.chars[i].prId);
|
|
11954
|
+
return [top, all, empty && all > 0];
|
|
11955
|
+
}
|
|
11956
|
+
|
|
11935
11957
|
// src/render/reflow.ts
|
|
11936
11958
|
var geomMemo = (styles) => ({ cell: /* @__PURE__ */ new WeakMap(), table: /* @__PURE__ */ new WeakMap(), paraGeom: styles.paraGeom });
|
|
11937
11959
|
var LINESEG_FLAGS = "393216";
|
|
11938
11960
|
var BASELINE_RATIO = 0.85;
|
|
11939
11961
|
var FONT_LINE_METRICS = [
|
|
11940
11962
|
[/^맑은 고딕/, 2230 / 2048, 496 / 2048, true],
|
|
11941
|
-
[/^(바탕|돋움|굴림|궁서)(체)
|
|
11963
|
+
[/^(바탕|돋움|굴림|궁서)(체)?$|^한컴바탕$|^HY/, 1758 / 2048, 290 / 2048],
|
|
11942
11964
|
[/^휴먼명조$/, 0.859, 0.195],
|
|
11943
11965
|
[/^KoPub(World)?(돋움|바탕)체 Light$/, 0.85, 0.25]
|
|
11944
11966
|
];
|
|
11945
|
-
function fontLineMetrics(face) {
|
|
11946
|
-
if (!face) return void 0;
|
|
11967
|
+
function fontLineMetrics(face, hft) {
|
|
11968
|
+
if (!face || hft && face.trim() === "\uD55C\uCEF4\uBC14\uD0D5") return void 0;
|
|
11947
11969
|
for (const [re, a, d, up] of FONT_LINE_METRICS) if (re.test(face.trim())) return [a, d, up];
|
|
11948
11970
|
return void 0;
|
|
11949
11971
|
}
|
|
@@ -11983,7 +12005,7 @@ function hancomLangOf(cp) {
|
|
|
11983
12005
|
if (cp >= 57344 && cp < 63744 || cp >= 983040) return "hangul";
|
|
11984
12006
|
return "symbol";
|
|
11985
12007
|
}
|
|
11986
|
-
function glyphWidth(ch, st) {
|
|
12008
|
+
function glyphWidth(ch, st, fallback = true) {
|
|
11987
12009
|
const cp = ch.codePointAt(0);
|
|
11988
12010
|
const space = cp === 32 || cp === 160;
|
|
11989
12011
|
const lang = space ? "hangul" : hancomLangOf(cp);
|
|
@@ -11996,7 +12018,7 @@ function glyphWidth(ch, st) {
|
|
|
11996
12018
|
const face1 = L?.face ?? st.face;
|
|
11997
12019
|
const face0 = face1 === "Batang" ? st.before2024 ? "\uBC14\uD0D5" : "\uD55C\uCEF4\uBC14\uD0D5" : face1;
|
|
11998
12020
|
const boldFace = !space && st.bold && (L ? L.hft : st.hft) && face0 && fontHasGlyph(`${face0} Bold`, cp) ? `${face0} Bold` : void 0;
|
|
11999
|
-
const oldEm = st.halfQuote && face0 === "\uD734\uBA3C\uBA85\uC870" && (cp === 8220 || cp === 8221) ? 500 : st.halfQuote && !st.before2024 && face0 === "\uD734\uBA3C\uBA85\uC870" && (cp === 8216 || cp === 8217) ? 312 : st.before2024 && face0 ? BEFORE_2024_WIDTH[face0]?.[cp] : !st.halfQuote && face0 === "\uD734\uBA3C\uBA85\uC870" && cp === 8231 ? BEFORE_2024_WIDTH[face0]?.[cp] : void 0;
|
|
12021
|
+
const oldEm = st.halfQuote && face0 === "\uD734\uBA3C\uBA85\uC870" && (cp === 8220 || cp === 8221) ? 500 : st.halfQuote && !st.before2024 && face0 === "\uD734\uBA3C\uBA85\uC870" && (cp === 8216 || cp === 8217) ? 312 : st.before2024 && face0 && !(face0 === "\uC2E0\uBA85\uC870" && (st.halfQuote || (L?.face ? L.hft : st.hft))) ? BEFORE_2024_WIDTH[face0]?.[cp] : !st.halfQuote && face0 === "\uD734\uBA3C\uBA85\uC870" && cp === 8231 ? BEFORE_2024_WIDTH[face0]?.[cp] : void 0;
|
|
12000
12022
|
const fc = faceClassForReflow(boldFace ?? face0);
|
|
12001
12023
|
const fsEm = space && st.fontSpace ? fontSpaceEm(st.face) : void 0;
|
|
12002
12024
|
if (fsEm !== void 0) {
|
|
@@ -12009,8 +12031,8 @@ function glyphWidth(ch, st) {
|
|
|
12009
12031
|
const b0 = hancomEmWidth(oldEm + bAdd, h, ratio, 0), w0 = spacing ? hancomEmWidth(oldEm + bAdd, h, ratio, spacing) : b0;
|
|
12010
12032
|
return { w: w0, sp: w0 - b0 };
|
|
12011
12033
|
}
|
|
12012
|
-
const base = hancomCharWidth(ch, h, ratio, 0, fc, bAdd);
|
|
12013
|
-
const w = spacing ? hancomCharWidth(ch, h, ratio, spacing, fc, bAdd) : base;
|
|
12034
|
+
const base = hancomCharWidth(ch, h, ratio, 0, fc, bAdd, fallback);
|
|
12035
|
+
const w = spacing ? hancomCharWidth(ch, h, ratio, spacing, fc, bAdd, fallback) : base;
|
|
12014
12036
|
return { w, sp: w - base };
|
|
12015
12037
|
}
|
|
12016
12038
|
function pitchFor(height, geom) {
|
|
@@ -12139,12 +12161,10 @@ function reflowPara(p, doc, styles, areaW, startV, mode, zones = [], nums = /* @
|
|
|
12139
12161
|
const avail = Math.max(1440, Math.floor(areaW / 4) * 4 - marginL - geom.marginRight);
|
|
12140
12162
|
const firstWidth = avail;
|
|
12141
12163
|
const bu = geom.bullet ?? (numText && geom.number ? { ch: numText, ...geom.number } : void 0);
|
|
12164
|
+
const bst = (bu?.charPrId != null ? styles.charPr.get(bu.charPrId) : void 0) ?? domChar;
|
|
12142
12165
|
let headW = 0;
|
|
12143
|
-
if (bu)
|
|
12144
|
-
|
|
12145
|
-
for (const ch of bu.ch) headW += glyphWidth(ch, bst).w;
|
|
12146
|
-
}
|
|
12147
|
-
const bulletW = bu ? headW + (bu.offsetPct ? Math.trunc(height * bu.offset / 100) : bu.offset) : 0;
|
|
12166
|
+
if (bu) for (const ch of bu.ch) headW += glyphWidth(ch, bst, bu.useInstWidth !== false).w;
|
|
12167
|
+
const bulletW = bu ? paraHeadAdvance(bu, height, headW) : 0;
|
|
12148
12168
|
const contBullet = bu?.autoIndent ? bulletW : 0;
|
|
12149
12169
|
const squeeze = p.parentNode?.getAttribute?.("lineWrap") === "SQUEEZE" || !!geom.squeeze;
|
|
12150
12170
|
const NO_WRAP = 1e9;
|
|
@@ -12216,7 +12236,7 @@ function reflowPara(p, doc, styles, areaW, startV, mode, zones = [], nums = /* @
|
|
|
12216
12236
|
const hRel = pos?.getAttribute("horzRelTo") ?? "COLUMN", hAlign = pos?.getAttribute("horzAlign") ?? "LEFT";
|
|
12217
12237
|
const ho = num2(pos, "horzOffset"), base = hRel === "PARA" ? marginL : 0, span = hRel === "PARA" ? avail : areaW;
|
|
12218
12238
|
const x0 = base + (hAlign === "RIGHT" ? span - ho - o.width : hAlign === "CENTER" ? (span - o.width) / 2 + ho : ho);
|
|
12219
|
-
const top = startV + vo;
|
|
12239
|
+
const top = startV - (bodyFlow && vertRel === "PARA" && wrapAttr === "SQUARE" ? geom.spaceBefore : 0) + vo;
|
|
12220
12240
|
const omLx = num2(om, "left"), omRx = num2(om, "right");
|
|
12221
12241
|
const xs = hAlign === "RIGHT" ? x0 - omRx : hAlign === "CENTER" ? x0 : x0 + omLx;
|
|
12222
12242
|
const nextPage = pageH > 0 && top + effH + outB > pageH;
|
|
@@ -12357,6 +12377,8 @@ function reflowPara(p, doc, styles, areaW, startV, mode, zones = [], nums = /* @
|
|
|
12357
12377
|
lineObjAsc[li] = Math.max(lineObjAsc[li], Math.round(h * (Number.isFinite(bl) ? bl / 100 : BASELINE_RATIO)));
|
|
12358
12378
|
}
|
|
12359
12379
|
const lsa = doc.createElement("hp:linesegarray");
|
|
12380
|
+
const subList = p.parentNode;
|
|
12381
|
+
const verticalCenter = subList?.getAttribute?.("vertAlign") === "CENTER" && ["VERTICAL", "VERTICALALL"].includes(subList.getAttribute("textDirection") ?? "");
|
|
12360
12382
|
let v = textStartV;
|
|
12361
12383
|
let firstAcc = 0;
|
|
12362
12384
|
const textposOf = wrap.starts.map((startReal, li) => li === 0 ? 0 : startReal < realIdx.length ? realIdx[startReal] : realIdx.length ? m.chars.length : 0);
|
|
@@ -12372,40 +12394,27 @@ function reflowPara(p, doc, styles, areaW, startV, mode, zones = [], nums = /* @
|
|
|
12372
12394
|
const fontLineOf = (li) => {
|
|
12373
12395
|
if (!geom.fontLineHeight) return void 0;
|
|
12374
12396
|
const s = textposOf[li], e = li === wrap.starts.length - 1 ? m.chars.length : textposOf[li + 1];
|
|
12397
|
+
if (!m.chars.slice(s, e).some((c) => c.ch && c.ch !== " ")) return void 0;
|
|
12375
12398
|
let h = 0, b = 0, any = false;
|
|
12376
12399
|
for (let k = s; k < e; k++) {
|
|
12377
12400
|
const c = m.chars[k];
|
|
12378
|
-
if (!c.ch
|
|
12401
|
+
if (!c.ch) continue;
|
|
12379
12402
|
const st = c.prId != null ? styles.charPr.get(c.prId) : void 0;
|
|
12380
12403
|
if (!st) continue;
|
|
12381
12404
|
const cp = c.ch.codePointAt(0);
|
|
12382
|
-
const
|
|
12405
|
+
const font = c.ch !== " " && st.latin && isLatinCp(cp) ? st.latin : st;
|
|
12406
|
+
const fm = fontLineMetrics(font.face, font.hft);
|
|
12383
12407
|
any = true;
|
|
12384
12408
|
h = Math.max(h, fm ? Math.round(st.height * fm[0]) + (fm[2] ? Math.round : Math.trunc)(st.height * fm[1]) : st.height);
|
|
12385
12409
|
b = Math.max(b, fm ? Math.round(st.height * fm[0]) : Math.round(st.height * BASELINE_RATIO));
|
|
12386
12410
|
}
|
|
12387
12411
|
return any ? [h, b] : void 0;
|
|
12388
12412
|
};
|
|
12389
|
-
const lineBorderBox = (li) => {
|
|
12390
|
-
const s0 = textposOf[li], e = li === wrap.starts.length - 1 ? m.chars.length : textposOf[li + 1];
|
|
12391
|
-
let top = 0, all = 0;
|
|
12392
|
-
for (let k = s0; k < e; k++) {
|
|
12393
|
-
const c = m.chars[k];
|
|
12394
|
-
if (!c.ch) continue;
|
|
12395
|
-
const st = c.prId != null ? styles.charPr.get(c.prId) : void 0;
|
|
12396
|
-
const f = st?.borderFill != null ? styles.borderFill.get(st.borderFill) : void 0;
|
|
12397
|
-
if (!f || !f.top && !f.bottom) continue;
|
|
12398
|
-
const t = f.top ? Math.trunc(f.top.widthPt * 100) : 0, b = f.bottom ? Math.trunc(f.bottom.widthPt * 100) : 0;
|
|
12399
|
-
top = Math.max(top, st.height + t);
|
|
12400
|
-
all = Math.max(all, st.height + t + b);
|
|
12401
|
-
}
|
|
12402
|
-
return [top, all];
|
|
12403
|
-
};
|
|
12404
12413
|
const natW = widths.reduce((a, w) => a + w, 0) + spacings.reduce((a, w) => a + w, 0);
|
|
12405
12414
|
for (let li = 0; li < wrap.starts.length; li++) {
|
|
12406
12415
|
const textpos = textposOf[li];
|
|
12407
12416
|
const fl = fontLineOf(li);
|
|
12408
|
-
const [boxTop, boxAll] = lineBorderBox(li);
|
|
12417
|
+
const [boxTop, boxAll, emptyBorder] = lineBorderBox(m, styles, textposOf[li], textposOf[li + 1] ?? m.chars.length);
|
|
12409
12418
|
const textH0 = fl ? Math.max(fl[0], lineTextH(li)) : lineTextH(li);
|
|
12410
12419
|
const textH = Math.max(textH0, boxAll);
|
|
12411
12420
|
const objOnly = lineObjH[li] > 0 && lineObjH[li] < textH && (() => {
|
|
@@ -12428,15 +12437,17 @@ function reflowPara(p, doc, styles, areaW, startV, mode, zones = [], nums = /* @
|
|
|
12428
12437
|
}
|
|
12429
12438
|
}
|
|
12430
12439
|
const vertpos = v;
|
|
12431
|
-
const
|
|
12440
|
+
const nextStart = textposOf[li + 1], nextChar = m.chars[nextStart];
|
|
12441
|
+
const boundaryH = !m.objs.length && !geom.fontLineHeight && nextChar?.ch.trim() && m.runs.some((r) => r.at === nextStart && r.prId === nextChar.prId) ? heightOf(nextChar.prId) : 0;
|
|
12442
|
+
const occupiedH = Math.max(lineH, collisionHeights[li] ?? 0, boundaryH);
|
|
12432
12443
|
v += lineH + spacing;
|
|
12433
12444
|
const isFirst = li === 0;
|
|
12434
12445
|
const seg = doc.createElement("hp:lineseg");
|
|
12435
12446
|
seg.setAttribute("textpos", String(textpos));
|
|
12436
12447
|
seg.setAttribute("vertpos", String(vertpos));
|
|
12437
|
-
seg.setAttribute("vertsize", String(occupiedH === textH && boxAll > textH0 ? Math.max(textH0, boxTop) : occupiedH));
|
|
12448
|
+
seg.setAttribute("vertsize", String(emptyBorder ? textH0 : occupiedH === textH && boxAll > textH0 ? Math.max(textH0, boxTop) : occupiedH));
|
|
12438
12449
|
seg.setAttribute("textheight", String(lineH));
|
|
12439
|
-
seg.setAttribute("baseline", String(geom.vertAlign === "TOP" ? 0 : geom.vertAlign === "CENTER" ? Math.floor(lineH / 2) : geom.vertAlign === "BOTTOM" ? lineH : Math.max(fl ? fl[1] : Math.round(textH0 * BASELINE_RATIO), lineObjAsc[li])));
|
|
12450
|
+
seg.setAttribute("baseline", String(geom.vertAlign === "TOP" ? 0 : geom.vertAlign === "CENTER" || verticalCenter && (!geom.vertAlign || geom.vertAlign === "BASELINE") ? Math.floor(lineH / 2) : geom.vertAlign === "BOTTOM" ? lineH : Math.max(fl ? fl[1] : Math.round(textH0 * BASELINE_RATIO), boxTop > textH0 ? Math.round(boxTop * BASELINE_RATIO) : 0, lineObjAsc[li])));
|
|
12440
12451
|
seg.setAttribute("spacing", String(spacing));
|
|
12441
12452
|
let box = boxAt(li);
|
|
12442
12453
|
const fit = wrap.starts.length === 1 && lineObjH[li] === 0 ? lineParts[li]?.filter(([a, b]) => b - a >= 1440) : void 0;
|
|
@@ -12914,1317 +12925,1360 @@ function flowEndNotes(root, bodyH) {
|
|
|
12914
12925
|
});
|
|
12915
12926
|
}
|
|
12916
12927
|
|
|
12917
|
-
// src/render/
|
|
12918
|
-
|
|
12919
|
-
|
|
12920
|
-
|
|
12921
|
-
|
|
12922
|
-
|
|
12923
|
-
|
|
12924
|
-
|
|
12925
|
-
|
|
12926
|
-
|
|
12927
|
-
|
|
12928
|
-
|
|
12929
|
-
|
|
12930
|
-
|
|
12931
|
-
|
|
12932
|
-
|
|
12933
|
-
|
|
12934
|
-
|
|
12935
|
-
|
|
12936
|
-
|
|
12937
|
-
|
|
12938
|
-
|
|
12939
|
-
|
|
12940
|
-
|
|
12941
|
-
|
|
12942
|
-
|
|
12943
|
-
|
|
12944
|
-
|
|
12945
|
-
Gamma: "\u0393",
|
|
12946
|
-
Delta: "\u0394",
|
|
12947
|
-
Theta: "\u0398",
|
|
12948
|
-
Lambda: "\u039B",
|
|
12949
|
-
Xi: "\u039E",
|
|
12950
|
-
Pi: "\u03A0",
|
|
12951
|
-
Sigma: "\u03A3",
|
|
12952
|
-
Phi: "\u03A6",
|
|
12953
|
-
Psi: "\u03A8",
|
|
12954
|
-
Omega: "\u03A9",
|
|
12955
|
-
times: "\xD7",
|
|
12956
|
-
cdot: "\xB7",
|
|
12957
|
-
div: "\xF7",
|
|
12958
|
-
pm: "\xB1",
|
|
12959
|
-
mp: "\u2213",
|
|
12960
|
-
le: "\u2264",
|
|
12961
|
-
leq: "\u2264",
|
|
12962
|
-
ge: "\u2265",
|
|
12963
|
-
geq: "\u2265",
|
|
12964
|
-
ne: "\u2260",
|
|
12965
|
-
neq: "\u2260",
|
|
12966
|
-
approx: "\u2248",
|
|
12967
|
-
equiv: "\u2261",
|
|
12968
|
-
sim: "\u223C",
|
|
12969
|
-
infty: "\u221E",
|
|
12970
|
-
rightarrow: "\u2192",
|
|
12971
|
-
leftarrow: "\u2190",
|
|
12972
|
-
Rightarrow: "\u21D2",
|
|
12973
|
-
Leftarrow: "\u21D0",
|
|
12974
|
-
leftrightarrow: "\u2194",
|
|
12975
|
-
Leftrightarrow: "\u21D4",
|
|
12976
|
-
to: "\u2192",
|
|
12977
|
-
angle: "\u2220",
|
|
12978
|
-
triangle: "\u25B3",
|
|
12979
|
-
perp: "\u22A5",
|
|
12980
|
-
parallel: "\u2225",
|
|
12981
|
-
circ: "\u2218",
|
|
12982
|
-
degree: "\xB0",
|
|
12983
|
-
sum: "\u03A3",
|
|
12984
|
-
prod: "\u03A0",
|
|
12985
|
-
int: "\u222B",
|
|
12986
|
-
oint: "\u222E",
|
|
12987
|
-
partial: "\u2202",
|
|
12988
|
-
nabla: "\u2207",
|
|
12989
|
-
in: "\u2208",
|
|
12990
|
-
notin: "\u2209",
|
|
12991
|
-
subset: "\u2282",
|
|
12992
|
-
supset: "\u2283",
|
|
12993
|
-
subseteq: "\u2286",
|
|
12994
|
-
supseteq: "\u2287",
|
|
12995
|
-
cup: "\u222A",
|
|
12996
|
-
cap: "\u2229",
|
|
12997
|
-
emptyset: "\u2205",
|
|
12998
|
-
forall: "\u2200",
|
|
12999
|
-
exists: "\u2203",
|
|
13000
|
-
therefore: "\u2234",
|
|
13001
|
-
because: "\u2235",
|
|
13002
|
-
prime: "\u2032",
|
|
13003
|
-
cdots: "\u22EF",
|
|
13004
|
-
ldots: "\u2026",
|
|
13005
|
-
dots: "\u2026",
|
|
13006
|
-
vdots: "\u22EE",
|
|
13007
|
-
lim: "lim",
|
|
13008
|
-
log: "log",
|
|
13009
|
-
ln: "ln",
|
|
13010
|
-
sin: "sin",
|
|
13011
|
-
cos: "cos",
|
|
13012
|
-
tan: "tan",
|
|
13013
|
-
sec: "sec",
|
|
13014
|
-
csc: "csc",
|
|
13015
|
-
cot: "cot",
|
|
13016
|
-
exp: "exp",
|
|
13017
|
-
max: "max",
|
|
13018
|
-
min: "min",
|
|
13019
|
-
quad: " ",
|
|
13020
|
-
qquad: " ",
|
|
13021
|
-
",": " ",
|
|
13022
|
-
";": " ",
|
|
13023
|
-
"!": "",
|
|
13024
|
-
"{": "{",
|
|
13025
|
-
"}": "}",
|
|
13026
|
-
"|": "\u2016",
|
|
13027
|
-
backslash: "\\",
|
|
13028
|
-
lbrace: "{",
|
|
13029
|
-
rbrace: "}",
|
|
13030
|
-
langle: "\u27E8",
|
|
13031
|
-
rangle: "\u27E9"
|
|
12928
|
+
// src/render/scene.ts
|
|
12929
|
+
function regionId(type, seq) {
|
|
12930
|
+
return `${type}-${String(seq).padStart(6, "0")}`;
|
|
12931
|
+
}
|
|
12932
|
+
function unionBBox(a, b) {
|
|
12933
|
+
const x = Math.min(a.x, b.x), y = Math.min(a.y, b.y);
|
|
12934
|
+
return { page: a.page, x, y, width: Math.max(a.x + a.width, b.x + b.width) - x, height: Math.max(a.y + a.height, b.y + b.height) - y };
|
|
12935
|
+
}
|
|
12936
|
+
var RegionCollector = class {
|
|
12937
|
+
regions = [];
|
|
12938
|
+
counters = /* @__PURE__ */ new Map();
|
|
12939
|
+
add(type, bbox, extra = {}) {
|
|
12940
|
+
const seq = (this.counters.get(type) ?? 0) + 1;
|
|
12941
|
+
this.counters.set(type, seq);
|
|
12942
|
+
const id = regionId(type, seq);
|
|
12943
|
+
const region = { id, type, page: bbox.page, regions: [bbox] };
|
|
12944
|
+
if (extra.sourceId) region.sourceId = extra.sourceId;
|
|
12945
|
+
if (extra.parentId) region.parentId = extra.parentId;
|
|
12946
|
+
this.regions.push(region);
|
|
12947
|
+
return id;
|
|
12948
|
+
}
|
|
12949
|
+
addFragment(id, bbox) {
|
|
12950
|
+
const r = this.regions.find((x) => x.id === id);
|
|
12951
|
+
if (!r) return;
|
|
12952
|
+
const same = r.regions.find((f) => f.page === bbox.page);
|
|
12953
|
+
if (same) Object.assign(same, unionBBox(same, bbox));
|
|
12954
|
+
else r.regions.push(bbox);
|
|
12955
|
+
}
|
|
13032
12956
|
};
|
|
13033
|
-
|
|
13034
|
-
|
|
13035
|
-
function
|
|
13036
|
-
|
|
13037
|
-
const
|
|
13038
|
-
const
|
|
13039
|
-
|
|
13040
|
-
|
|
13041
|
-
|
|
13042
|
-
|
|
13043
|
-
|
|
13044
|
-
|
|
13045
|
-
|
|
13046
|
-
|
|
13047
|
-
|
|
13048
|
-
|
|
13049
|
-
|
|
13050
|
-
|
|
13051
|
-
|
|
13052
|
-
|
|
13053
|
-
const t = v.trim();
|
|
13054
|
-
return [...t].every((c) => map[c]) ? [...t].map((c) => map[c]).join("") : `${mark}${wrap(t)}`;
|
|
13055
|
-
};
|
|
13056
|
-
const atom = () => {
|
|
13057
|
-
const c = s[i];
|
|
13058
|
-
if (c === void 0) return "";
|
|
13059
|
-
if (c === "\\") {
|
|
13060
|
-
i++;
|
|
13061
|
-
let name = "";
|
|
13062
|
-
if (/[A-Za-z]/.test(s[i] ?? "")) while (/[A-Za-z]/.test(s[i] ?? "")) name += s[i++];
|
|
13063
|
-
else name = s[i++] ?? "";
|
|
13064
|
-
if (name === "frac") {
|
|
13065
|
-
const a = arg(), b = arg();
|
|
13066
|
-
return `${wrap(a.trim())}/${wrap(b.trim())}`;
|
|
13067
|
-
}
|
|
13068
|
-
if (name === "sqrt") {
|
|
13069
|
-
skipWs();
|
|
13070
|
-
let root = "";
|
|
13071
|
-
if (s[i] === "[") {
|
|
13072
|
-
i++;
|
|
13073
|
-
root = seq("]");
|
|
13074
|
-
i++;
|
|
12957
|
+
|
|
12958
|
+
// src/render/page-stories.ts
|
|
12959
|
+
function pageStories(root, masters, paraPages, pageCount, pageBase, geom) {
|
|
12960
|
+
const secPr = findFirst(root, "secPr"), visibility = secPr && findChildByLocalName(secPr, "visibility");
|
|
12961
|
+
const pagePr = secPr && findChildByLocalName(secPr, "pagePr"), margin = pagePr && findChildByLocalName(pagePr, "margin");
|
|
12962
|
+
const declarations = [];
|
|
12963
|
+
const hidden = /* @__PURE__ */ new Map();
|
|
12964
|
+
for (const p of elements(root)) if (ln(p) === "p") {
|
|
12965
|
+
const page = paraPages.get(p)?.[0] ?? 0;
|
|
12966
|
+
for (const run of elements(p)) if (ln(run) === "run") {
|
|
12967
|
+
for (const ctrl of elements(run)) if (ln(ctrl) === "ctrl") {
|
|
12968
|
+
for (const el of elements(ctrl)) {
|
|
12969
|
+
if (isDeletedControl(el)) continue;
|
|
12970
|
+
const kind = ln(el);
|
|
12971
|
+
if (kind === "header" || kind === "footer") declarations.push({ el, page, kind });
|
|
12972
|
+
else if (kind === "pageHiding") {
|
|
12973
|
+
const kinds = hidden.get(page) ?? /* @__PURE__ */ new Set();
|
|
12974
|
+
for (const name of ["Header", "Footer", "MasterPage"]) if (num(el, `hide${name}`)) kinds.add(name);
|
|
12975
|
+
hidden.set(page, kinds);
|
|
12976
|
+
}
|
|
13075
12977
|
}
|
|
13076
|
-
const a = arg();
|
|
13077
|
-
return `${root ? script(root, SUP, "") : ""}\u221A${wrap(a.trim())}`;
|
|
13078
|
-
}
|
|
13079
|
-
if (name === "left" || name === "right" || name === "big" || name === "Big" || name === "bigg" || name === "Bigg") {
|
|
13080
|
-
skipWs();
|
|
13081
|
-
const d = s[i] === "\\" ? atom() : s[i++] ?? "";
|
|
13082
|
-
return d === "." ? "" : d;
|
|
13083
12978
|
}
|
|
13084
|
-
if (name === "overline" || name === "bar" || name === "hat" || name === "vec" || name === "dot" || name === "tilde") {
|
|
13085
|
-
const a = arg().trim(), mark = { overline: "\u0305", bar: "\u0304", hat: "\u0302", vec: "\u20D7", dot: "\u0307", tilde: "\u0303" }[name];
|
|
13086
|
-
return [...a].map((ch) => ch + mark).join("");
|
|
13087
|
-
}
|
|
13088
|
-
if (name === "mathrm" || name === "text" || name === "rm" || name === "mathbf" || name === "it" || name === "mathit" || name === "operatorname") return name === "rm" || name === "it" ? "" : arg();
|
|
13089
|
-
return SYMBOLS[name] ?? name;
|
|
13090
12979
|
}
|
|
13091
|
-
|
|
13092
|
-
|
|
13093
|
-
|
|
13094
|
-
|
|
13095
|
-
|
|
12980
|
+
}
|
|
12981
|
+
const parity = (type, n) => type === "BOTH" || type === "ODD" && n % 2 === 1 || type === "EVEN" && n % 2 === 0;
|
|
12982
|
+
const out = [];
|
|
12983
|
+
for (let page = 0; page < pageCount; page++) {
|
|
12984
|
+
const n = pageBase + page + 1;
|
|
12985
|
+
const hides = (name) => hidden.get(page)?.has(name) === true || page === 0 && num(visibility, `hideFirst${name}`) !== 0;
|
|
12986
|
+
if (!hides("MasterPage")) {
|
|
12987
|
+
const matching = masters.filter((m) => m.getAttribute("type") === (n % 2 ? "ODD" : "EVEN"));
|
|
12988
|
+
const both = masters.filter((m) => (m.getAttribute("type") || "BOTH") === "BOTH");
|
|
12989
|
+
const normal = (matching.length ? matching : both).slice(-1);
|
|
12990
|
+
const specific = masters.filter((m) => m.getAttribute("type") === "LAST_PAGE" ? page === pageCount - 1 : m.getAttribute("type") === "OPTIONAL_PAGE" && num(m, "pageNumber") === page + 1);
|
|
12991
|
+
const special = specific.slice(-1);
|
|
12992
|
+
const selected = special.length && !num(special[0], "pageDuplicate") ? special : [...normal, ...special];
|
|
12993
|
+
for (const master of selected) {
|
|
12994
|
+
const sub = findChildByLocalName(master, "subList");
|
|
12995
|
+
if (sub) out.push({ sub, page, x: geom.ML, y: geom.MT, width: geom.BODY_W, layer: num(master, "pageFront") ? 2 : -2 });
|
|
12996
|
+
}
|
|
13096
12997
|
}
|
|
13097
|
-
|
|
13098
|
-
|
|
13099
|
-
|
|
13100
|
-
|
|
13101
|
-
|
|
13102
|
-
|
|
13103
|
-
|
|
13104
|
-
|
|
13105
|
-
|
|
13106
|
-
|
|
13107
|
-
|
|
12998
|
+
for (const kind of ["header", "footer"]) {
|
|
12999
|
+
if (hides(kind === "header" ? "Header" : "Footer")) continue;
|
|
13000
|
+
const eligible = declarations.filter((d) => d.kind === kind && d.page <= page && parity(d.el.getAttribute("applyPageType") || "BOTH", n));
|
|
13001
|
+
const decl = eligible[eligible.length - 1];
|
|
13002
|
+
const sub = decl && findChildByLocalName(decl.el, "subList");
|
|
13003
|
+
if (sub) out.push({ sub, page, x: geom.ML, y: kind === "header" ? num(margin, "top", 5668) : geom.PH - num(margin, "bottom", 4252) - num(margin, "footer"), width: geom.BODY_W });
|
|
13004
|
+
}
|
|
13005
|
+
}
|
|
13006
|
+
return out;
|
|
13007
|
+
}
|
|
13008
|
+
function footNoteStories(root, paraPages, geom) {
|
|
13009
|
+
const pr = findFirst(root, "footNotePr");
|
|
13010
|
+
const sp = pr ? findChildByLocalName(pr, "noteSpacing") : null, line = pr ? findChildByLocalName(pr, "noteLine") : null;
|
|
13011
|
+
const above = num(sp, "aboveLine", 850), below = num(sp, "belowLine", 567), between = num(sp, "betweenNotes", 283);
|
|
13012
|
+
const byPage = /* @__PURE__ */ new Map();
|
|
13013
|
+
for (const p of elements(root)) if (ln(p) === "p") {
|
|
13014
|
+
const page = paraPages.get(p)?.[0] ?? 0;
|
|
13015
|
+
for (const run of elements(p)) if (ln(run) === "run") {
|
|
13016
|
+
for (const ctrl of elements(run)) if (ln(ctrl) === "ctrl") {
|
|
13017
|
+
const fn = findChildByLocalName(ctrl, "footNote");
|
|
13018
|
+
const sub = fn && !isDeletedControl(fn) ? findChildByLocalName(fn, "subList") : null;
|
|
13019
|
+
if (!sub) continue;
|
|
13020
|
+
let h = 0;
|
|
13021
|
+
for (const q of elements(sub)) if (ln(q) === "p") {
|
|
13022
|
+
const lsa = findChildByLocalName(q, "linesegarray");
|
|
13023
|
+
for (const seg of lsa ? elements(lsa) : []) if (ln(seg) === "lineseg") h = Math.max(h, num(seg, "vertpos") + num(seg, "vertsize"));
|
|
13024
|
+
}
|
|
13025
|
+
const list = byPage.get(page) ?? [];
|
|
13026
|
+
list.push({ sub, h });
|
|
13027
|
+
byPage.set(page, list);
|
|
13108
13028
|
}
|
|
13109
|
-
out += atom();
|
|
13110
13029
|
}
|
|
13111
|
-
|
|
13030
|
+
}
|
|
13031
|
+
const stories = [], rules = [];
|
|
13032
|
+
const lenAttr = num(line, "length", -1), widthMm = Number.parseFloat(line?.getAttribute("width") ?? "0.12") || 0.12;
|
|
13033
|
+
const lineType = line?.getAttribute("type") ?? "SOLID";
|
|
13034
|
+
for (const [page, notes] of byPage) {
|
|
13035
|
+
const area = above + below + notes.reduce((a, n) => a + n.h, 0) + between * (notes.length - 1);
|
|
13036
|
+
const top = geom.MT + geom.BODY_H - area;
|
|
13037
|
+
if (lineType !== "NONE") rules.push({ page, x: geom.ML, y: top + above, length: lenAttr > 0 ? lenAttr : 14173, widthMm, color: line?.getAttribute("color") ?? "#000000" });
|
|
13038
|
+
let y = top + above + below;
|
|
13039
|
+
for (const n of notes) {
|
|
13040
|
+
stories.push({ sub: n.sub, page, x: geom.ML, y, width: geom.BODY_W });
|
|
13041
|
+
y += n.h + between;
|
|
13042
|
+
}
|
|
13043
|
+
}
|
|
13044
|
+
return { stories, rules };
|
|
13045
|
+
}
|
|
13046
|
+
function endNoteLayout(root, paraPages, geom) {
|
|
13047
|
+
const notes = [];
|
|
13048
|
+
let last = null;
|
|
13049
|
+
let endColPr = null;
|
|
13050
|
+
for (const p of elements(root)) if (ln(p) === "p") {
|
|
13051
|
+
const lsa = findChildByLocalName(p, "linesegarray"), segs = lsa ? elements(lsa).filter((e) => ln(e) === "lineseg") : [];
|
|
13052
|
+
const pages = paraPages.get(p) ?? [];
|
|
13053
|
+
if (segs.length) last = { seg: segs[segs.length - 1], page: pages[segs.length - 1] ?? pages[0] ?? 0 };
|
|
13054
|
+
for (const run of elements(p)) if (ln(run) === "run") {
|
|
13055
|
+
for (const ctrl of elements(run)) if (ln(ctrl) === "ctrl") {
|
|
13056
|
+
endColPr = findChildByLocalName(ctrl, "colPr") ?? endColPr;
|
|
13057
|
+
const en = findChildByLocalName(ctrl, "endNote");
|
|
13058
|
+
const sub = en && !isDeletedControl(en) ? findChildByLocalName(en, "subList") : null;
|
|
13059
|
+
if (sub) notes.push(sub);
|
|
13060
|
+
}
|
|
13061
|
+
}
|
|
13062
|
+
}
|
|
13063
|
+
if (!notes.length || !last) return null;
|
|
13064
|
+
const pr = findFirst(root, "endNotePr");
|
|
13065
|
+
const sp = pr ? findChildByLocalName(pr, "noteSpacing") : null, line = pr ? findChildByLocalName(pr, "noteLine") : null;
|
|
13066
|
+
const above = num(sp, "aboveLine", 0), below = num(sp, "belowLine", 567), between = num(sp, "betweenNotes", 283);
|
|
13067
|
+
const colPr = endColPr ?? findFirst(root, "colPr"), nCol = Math.max(1, num(colPr, "colCount", 1)), gap = nCol > 1 ? num(colPr, "sameGap", 0) : 0;
|
|
13068
|
+
const colW = (geom.BODY_W - gap * (nCol - 1)) / nCol;
|
|
13069
|
+
let page = last.page;
|
|
13070
|
+
let col = nCol > 1 ? Math.min(nCol - 1, Math.max(0, Math.round(num(last.seg, "horzpos") / (colW + gap)))) : 0;
|
|
13071
|
+
let y = num(last.seg, "vertpos") + num(last.seg, "vertsize") + above;
|
|
13072
|
+
const rules = [];
|
|
13073
|
+
const lenAttr = num(line, "length", -1), widthMm = Number.parseFloat(line?.getAttribute("width") ?? "0.12") || 0.12;
|
|
13074
|
+
if ((line?.getAttribute("type") ?? "SOLID") !== "NONE") rules.push({ page, x: geom.ML + col * (colW + gap), y: geom.MT + y, length: lenAttr > 0 ? lenAttr : 14173, widthMm, color: line?.getAttribute("color") ?? "#000000" });
|
|
13075
|
+
y += below;
|
|
13076
|
+
const next = () => {
|
|
13077
|
+
if (++col >= nCol) {
|
|
13078
|
+
col = 0;
|
|
13079
|
+
page++;
|
|
13080
|
+
}
|
|
13081
|
+
y = 0;
|
|
13112
13082
|
};
|
|
13113
|
-
|
|
13083
|
+
const out = [];
|
|
13084
|
+
notes.forEach((sub, ni) => {
|
|
13085
|
+
if (ni > 0) y += between;
|
|
13086
|
+
let base = y;
|
|
13087
|
+
let prevRaw = Number.NEGATIVE_INFINITY, flowEnd = y;
|
|
13088
|
+
for (const q of elements(sub)) if (ln(q) === "p") {
|
|
13089
|
+
const lsa = findChildByLocalName(q, "linesegarray"), segs = lsa ? elements(lsa).filter((e) => ln(e) === "lineseg") : [];
|
|
13090
|
+
const pages = [];
|
|
13091
|
+
for (const seg of segs) {
|
|
13092
|
+
const raw = num(seg, "vertpos");
|
|
13093
|
+
if (raw < prevRaw) base = flowEnd - raw;
|
|
13094
|
+
prevRaw = raw;
|
|
13095
|
+
let v = base + raw;
|
|
13096
|
+
const vs = num(seg, "vertsize");
|
|
13097
|
+
if (v + vs > geom.BODY_H && v > 0) {
|
|
13098
|
+
const shift = v;
|
|
13099
|
+
next();
|
|
13100
|
+
base -= shift;
|
|
13101
|
+
v = 0;
|
|
13102
|
+
}
|
|
13103
|
+
seg.setAttribute("vertpos", String(v));
|
|
13104
|
+
seg.setAttribute("horzpos", String(num(seg, "horzpos") + col * (colW + gap)));
|
|
13105
|
+
pages.push(page);
|
|
13106
|
+
y = v + vs;
|
|
13107
|
+
flowEnd = y + num(seg, "spacing");
|
|
13108
|
+
}
|
|
13109
|
+
out.push({ p: q, pages });
|
|
13110
|
+
}
|
|
13111
|
+
});
|
|
13112
|
+
return { paras: out, rules, pageCount: page + 1 };
|
|
13114
13113
|
}
|
|
13115
13114
|
|
|
13116
|
-
// src/
|
|
13117
|
-
|
|
13118
|
-
|
|
13119
|
-
|
|
13120
|
-
|
|
13121
|
-
|
|
13122
|
-
|
|
13123
|
-
|
|
13124
|
-
|
|
13125
|
-
|
|
13126
|
-
|
|
13127
|
-
|
|
13128
|
-
|
|
13129
|
-
OPLUS: "\\oplus",
|
|
13130
|
-
OMINUS: "\\ominus",
|
|
13131
|
-
OTIMES: "\\otimes",
|
|
13132
|
-
ODIV: "\\oslash",
|
|
13133
|
-
ODOT: "\\odot",
|
|
13134
|
-
LOR: "\\lor",
|
|
13135
|
-
LAND: "\\land",
|
|
13136
|
-
SUBSET: "\\subset",
|
|
13137
|
-
SUPERSET: "\\supset",
|
|
13138
|
-
SUBSETEQ: "\\subseteq",
|
|
13139
|
-
SUPSETEQ: "\\supseteq",
|
|
13140
|
-
IN: "\\in",
|
|
13141
|
-
OWNS: "\\owns",
|
|
13142
|
-
NOTIN: "\\notin",
|
|
13143
|
-
LEQ: "\\leq",
|
|
13144
|
-
GEQ: "\\geq",
|
|
13145
|
-
"<<": "\\ll",
|
|
13146
|
-
">>": "\\gg",
|
|
13147
|
-
"<<<": "\\lll",
|
|
13148
|
-
">>>": "\\ggg",
|
|
13149
|
-
PREC: "\\prec",
|
|
13150
|
-
SUCC: "\\succ",
|
|
13151
|
-
UPLUS: "\\uplus",
|
|
13152
|
-
"\xB1": "\\pm",
|
|
13153
|
-
"+-": "\\pm",
|
|
13154
|
-
"-+": "\\mp",
|
|
13155
|
-
"\xF7": "\\div",
|
|
13156
|
-
cdot: "\\cdot",
|
|
13157
|
-
CIRC: "\\circ",
|
|
13158
|
-
BULLET: "\\bullet",
|
|
13159
|
-
DEG: " ^\\circ",
|
|
13160
|
-
AST: "\\ast",
|
|
13161
|
-
STAR: "\\bigstar",
|
|
13162
|
-
BIGCIRC: "\\bigcirc",
|
|
13163
|
-
EMPTYSET: "\\emptyset",
|
|
13164
|
-
THEREFORE: "\\therefore",
|
|
13165
|
-
BECAUSE: "\\because",
|
|
13166
|
-
EXIST: "\\exists",
|
|
13167
|
-
// 한글 수식 편집기는 소문자 therefore·because 도 같은 기호로 그린다(#148) — 생성 쪽 정준형은 대문자(equation-generate COMMAND_MAP)
|
|
13168
|
-
therefore: "\\therefore",
|
|
13169
|
-
because: "\\because",
|
|
13170
|
-
"!=": "\\neq",
|
|
13171
|
-
SMCOPROD: "\\coprod",
|
|
13172
|
-
coprod: "\\coprod",
|
|
13173
|
-
SQCAP: "\\sqcap",
|
|
13174
|
-
SQCUP: "\\sqcup",
|
|
13175
|
-
SQSUBSET: "\\sqsubset",
|
|
13176
|
-
SQSUBSETEQ: "\\sqsubseteq",
|
|
13177
|
-
BIGSQCUP: "\\bigsqcup",
|
|
13178
|
-
BIGOPLUS: "\\bigoplus",
|
|
13179
|
-
BIGOTIMES: "\\bigotimes",
|
|
13180
|
-
BIGODOT: "\\bigodot",
|
|
13181
|
-
BIGUPLUS: "\\biguplus",
|
|
13182
|
-
inter: "\\bigcap",
|
|
13183
|
-
union: "\\bigcup",
|
|
13184
|
-
BIGOMINUS: "{\\Large\\ominus}",
|
|
13185
|
-
BIGODIV: "{\\Large\\oslash}",
|
|
13186
|
-
UNDEROVER: "",
|
|
13187
|
-
SIM: "\\sim",
|
|
13188
|
-
APPROX: "\\approx",
|
|
13189
|
-
SIMEQ: "\\simeq",
|
|
13190
|
-
CONG: "\\cong",
|
|
13191
|
-
"==": "\\equiv",
|
|
13192
|
-
DIAMOND: "\\diamond",
|
|
13193
|
-
FORALL: "\\forall",
|
|
13194
|
-
prime: "'",
|
|
13195
|
-
Partial: "\\partial",
|
|
13196
|
-
INF: "\\infty",
|
|
13197
|
-
PROPTO: "\\propto",
|
|
13198
|
-
lim: "\\lim",
|
|
13199
|
-
Lim: "\\lim",
|
|
13200
|
-
larrow: "\\leftarrow",
|
|
13201
|
-
"->": "\\rightarrow",
|
|
13202
|
-
uparrow: "\\uparrow",
|
|
13203
|
-
downarrow: "\\downarrow",
|
|
13204
|
-
LARROW: "\\Leftarrow",
|
|
13205
|
-
RARROW: "\\Rightarrow",
|
|
13206
|
-
UPARROW: "\\Uparrow",
|
|
13207
|
-
DOWNARROW: "\\Downarrow",
|
|
13208
|
-
udarrow: "\\updownarrow",
|
|
13209
|
-
"<->": "\\leftrightarrow",
|
|
13210
|
-
UDARROW: "\\Updownarrow",
|
|
13211
|
-
LRARROW: "\\Leftrightarrow",
|
|
13212
|
-
NWARROW: "\\nwarrow",
|
|
13213
|
-
SEARROW: "\\searrow",
|
|
13214
|
-
NEARROW: "\\nearrow",
|
|
13215
|
-
SWARROW: "\\swarrow",
|
|
13216
|
-
HOOKLEFT: "\\hookleftarrow",
|
|
13217
|
-
HOOKRIGHT: "\\hookrightarrow",
|
|
13218
|
-
PVER: "\\|",
|
|
13219
|
-
MAPSTO: "\\mapsto",
|
|
13220
|
-
CDOTS: "\\cdots",
|
|
13221
|
-
LDOTS: "\\ldots",
|
|
13222
|
-
VDOTS: "\\vdots",
|
|
13223
|
-
DDOTS: "\\ddots",
|
|
13224
|
-
DAGGER: "\\dagger",
|
|
13225
|
-
DDAGGER: "\\ddagger",
|
|
13226
|
-
DOTEQ: "\\doteq",
|
|
13227
|
-
image: "\\fallingdotseq",
|
|
13228
|
-
REIMAGE: "\\risingdotseq",
|
|
13229
|
-
ASYMP: "\\asymp",
|
|
13230
|
-
ISO: "\\Bumpeq",
|
|
13231
|
-
DSUM: "\\dotplus",
|
|
13232
|
-
XOR: "\\veebar",
|
|
13233
|
-
TRIANGLE: "\\triangle",
|
|
13234
|
-
NABLA: "\\nabla",
|
|
13235
|
-
ANGLE: "\\angle",
|
|
13236
|
-
MSANGLE: "\\measuredangle",
|
|
13237
|
-
SANGLE: "\\sphericalangle",
|
|
13238
|
-
VDASH: "\\vdash",
|
|
13239
|
-
DASHV: "\\dashv",
|
|
13240
|
-
BOT: "\\bot",
|
|
13241
|
-
TOP: "\\top",
|
|
13242
|
-
MODELS: "\\models",
|
|
13243
|
-
LAPLACE: "\\mathcal{L}",
|
|
13244
|
-
CENTIGRADE: "^{\\circ}C",
|
|
13245
|
-
FAHRENHEIT: "^{\\circ}F",
|
|
13246
|
-
LSLANT: "\\diagup",
|
|
13247
|
-
RSLANT: "\\diagdown",
|
|
13248
|
-
sqrt: "\\sqrt",
|
|
13249
|
-
int: "\\int",
|
|
13250
|
-
dint: "\\iint",
|
|
13251
|
-
tint: "\\iiint",
|
|
13252
|
-
oint: "\\oint",
|
|
13253
|
-
alpha: "\\alpha",
|
|
13254
|
-
beta: "\\beta",
|
|
13255
|
-
gamma: "\\gamma",
|
|
13256
|
-
delta: "\\delta",
|
|
13257
|
-
epsilon: "\\epsilon",
|
|
13258
|
-
zeta: "\\zeta",
|
|
13259
|
-
eta: "\\eta",
|
|
13260
|
-
theta: "\\theta",
|
|
13261
|
-
iota: "\\iota",
|
|
13262
|
-
kappa: "\\kappa",
|
|
13263
|
-
lambda: "\\lambda",
|
|
13264
|
-
mu: "\\mu",
|
|
13265
|
-
nu: "\\nu",
|
|
13266
|
-
xi: "\\xi",
|
|
13267
|
-
omicron: "\\omicron",
|
|
13268
|
-
pi: "\\pi",
|
|
13269
|
-
rho: "\\rho",
|
|
13270
|
-
sigma: "\\sigma",
|
|
13271
|
-
tau: "\\tau",
|
|
13272
|
-
upsilon: "\\upsilon",
|
|
13273
|
-
phi: "\\phi",
|
|
13274
|
-
chi: "\\chi",
|
|
13275
|
-
psi: "\\psi",
|
|
13276
|
-
omega: "\\omega",
|
|
13277
|
-
ALPHA: "A",
|
|
13278
|
-
BETA: "B",
|
|
13279
|
-
GAMMA: "\\Gamma",
|
|
13280
|
-
DELTA: "\\Delta",
|
|
13281
|
-
EPSILON: "E",
|
|
13282
|
-
ZETA: "Z",
|
|
13283
|
-
ETA: "H",
|
|
13284
|
-
THETA: "\\Theta",
|
|
13285
|
-
IOTA: "I",
|
|
13286
|
-
KAPPA: "K",
|
|
13287
|
-
LAMBDA: "\\Lambda",
|
|
13288
|
-
MU: "M",
|
|
13289
|
-
NU: "N",
|
|
13290
|
-
XI: "\\Xi",
|
|
13291
|
-
OMICRON: "O",
|
|
13292
|
-
PI: "\\Pi",
|
|
13293
|
-
RHO: "P",
|
|
13294
|
-
SIGMA: "\\Sigma",
|
|
13295
|
-
TAU: "T",
|
|
13296
|
-
UPSILON: "\\Upsilon",
|
|
13297
|
-
PHI: "\\Phi",
|
|
13298
|
-
CHI: "X",
|
|
13299
|
-
PSI: "\\Psi",
|
|
13300
|
-
OMEGA: "\\Omega",
|
|
13301
|
-
"\u2308": "\\lceil",
|
|
13302
|
-
"\u2309": "\\rceil",
|
|
13303
|
-
"\u230A": "\\lfloor",
|
|
13304
|
-
"\u230B": "\\rfloor",
|
|
13305
|
-
"\u2225": "\\|",
|
|
13306
|
-
"\u2290": "\\sqsupset",
|
|
13307
|
-
"\u2292": "\\sqsupseteq",
|
|
13308
|
-
odint: "\\mathop \u222F",
|
|
13309
|
-
otint: "\\mathop \u2230",
|
|
13310
|
-
BIGSQCAP: "\\mathop \u2A05",
|
|
13311
|
-
ATT: "\\mathop \u203B",
|
|
13312
|
-
HUND: "\\mathop \u2030",
|
|
13313
|
-
THOU: "\\mathop \u2031",
|
|
13314
|
-
IDENTICAL: "\\mathop \u2237",
|
|
13315
|
-
RTANGLE: "\\mathop \u22BE",
|
|
13316
|
-
BASE: "\\mathop \u2302",
|
|
13317
|
-
BENZENE: "\\mathop \u232C"
|
|
13318
|
-
};
|
|
13319
|
-
var MIDDLE_CONVERT_MAP = {
|
|
13320
|
-
matrix: "HULKMATRIX",
|
|
13321
|
-
pmatrix: "HULKPMATRIX",
|
|
13322
|
-
bmatrix: "HULKBMATRIX",
|
|
13323
|
-
dmatrix: "HULKDMATRIX",
|
|
13324
|
-
eqalign: "HULKEQALIGN",
|
|
13325
|
-
cases: "HULKCASE",
|
|
13326
|
-
vec: "HULKVEC",
|
|
13327
|
-
dyad: "HULKDYAD",
|
|
13328
|
-
acute: "HULKACUTE",
|
|
13329
|
-
grave: "HULKGRAVE",
|
|
13330
|
-
dot: "HULKDOT",
|
|
13331
|
-
ddot: "HULKDDOT",
|
|
13332
|
-
bar: "HULKBAR",
|
|
13333
|
-
hat: "HULKHAT",
|
|
13334
|
-
check: "HULKCHECK",
|
|
13335
|
-
arch: "HULKARCH",
|
|
13336
|
-
tilde: "HULKTILDE",
|
|
13337
|
-
BOX: "HULKBOX",
|
|
13338
|
-
OVERBRACE: "HULKOVERBRACE",
|
|
13339
|
-
UNDERBRACE: "HULKUNDERBRACE"
|
|
13340
|
-
};
|
|
13341
|
-
var BAR_CONVERT_MAP = {
|
|
13342
|
-
HULKVEC: "\\overrightarrow",
|
|
13343
|
-
HULKDYAD: "\\overleftrightarrow",
|
|
13344
|
-
HULKACUTE: "\\acute",
|
|
13345
|
-
HULKGRAVE: "\\grave",
|
|
13346
|
-
HULKDOT: "\\dot",
|
|
13347
|
-
HULKDDOT: "\\ddot",
|
|
13348
|
-
HULKBAR: "\\overline",
|
|
13349
|
-
HULKHAT: "\\widehat",
|
|
13350
|
-
HULKCHECK: "\\check",
|
|
13351
|
-
HULKARCH: "\\overset{\\frown}",
|
|
13352
|
-
HULKTILDE: "\\widetilde",
|
|
13353
|
-
HULKBOX: "\\boxed"
|
|
13354
|
-
};
|
|
13355
|
-
var MATRIX_CONVERT_MAP = {
|
|
13356
|
-
HULKMATRIX: { begin: "\\begin{matrix}", end: "\\end{matrix}", removeOutterBrackets: true },
|
|
13357
|
-
HULKPMATRIX: { begin: "\\begin{pmatrix}", end: "\\end{pmatrix}", removeOutterBrackets: true },
|
|
13358
|
-
HULKBMATRIX: { begin: "\\begin{bmatrix}", end: "\\end{bmatrix}", removeOutterBrackets: true },
|
|
13359
|
-
HULKDMATRIX: { begin: "\\begin{vmatrix}", end: "\\end{vmatrix}", removeOutterBrackets: true },
|
|
13360
|
-
HULKCASE: { begin: "\\begin{cases}", end: "\\end{cases}", removeOutterBrackets: true },
|
|
13361
|
-
HULKEQALIGN: { begin: "\\eqalign{", end: "}", removeOutterBrackets: false }
|
|
13362
|
-
};
|
|
13363
|
-
var BRACE_CONVERT_MAP = {
|
|
13364
|
-
HULKOVERBRACE: "\\overbrace",
|
|
13365
|
-
HULKUNDERBRACE: "\\underbrace"
|
|
13366
|
-
};
|
|
13367
|
-
function findBrackets(eqString, startIdx) {
|
|
13368
|
-
const startCur = eqString.indexOf("{", startIdx);
|
|
13369
|
-
if (startCur === -1) throw new Error("cannot find bracket");
|
|
13370
|
-
let bracketCount = 1;
|
|
13371
|
-
for (let i = startCur + 1; i < eqString.length; i++) {
|
|
13372
|
-
const ch = eqString[i];
|
|
13373
|
-
if (ch === "{") bracketCount += 1;
|
|
13374
|
-
else if (ch === "}") bracketCount -= 1;
|
|
13375
|
-
if (bracketCount === 0) return [startCur, i + 1];
|
|
13115
|
+
// src/render/table-pages.ts
|
|
13116
|
+
function stackedFloats(c) {
|
|
13117
|
+
const out = [];
|
|
13118
|
+
for (const p of c.sub ? elements(c.sub) : []) if (ln(p) === "p") {
|
|
13119
|
+
for (const run of elements(p)) if (ln(run) === "run") for (const o of elements(run)) {
|
|
13120
|
+
if (ln(o) !== "pic") continue;
|
|
13121
|
+
const pos = findChildByLocalName(o, "pos");
|
|
13122
|
+
if (!pos || pos.getAttribute("treatAsChar") === "1" || (pos.getAttribute("vertRelTo") ?? "PARA") !== "PARA" || pos.getAttribute("allowOverlap") !== "0") continue;
|
|
13123
|
+
const wrap = o.getAttribute("textWrap") ?? "TOP_AND_BOTTOM";
|
|
13124
|
+
if (wrap !== "SQUARE" && wrap !== "TOP_AND_BOTTOM") continue;
|
|
13125
|
+
const om = findChildByLocalName(o, "outMargin"), raw = num(pos, "vertOffset");
|
|
13126
|
+
out.push({ el: o, vo: Math.max(0, raw >= 2 ** 31 ? raw - 2 ** 32 : raw), h: num(findChildByLocalName(o, "sz"), "height") + num(om, "top") + num(om, "bottom"), omT: num(om, "top") });
|
|
13127
|
+
}
|
|
13376
13128
|
}
|
|
13377
|
-
|
|
13129
|
+
return out;
|
|
13378
13130
|
}
|
|
13379
|
-
function
|
|
13380
|
-
|
|
13381
|
-
|
|
13382
|
-
|
|
13383
|
-
|
|
13384
|
-
|
|
13385
|
-
|
|
13386
|
-
|
|
13387
|
-
|
|
13388
|
-
|
|
13389
|
-
|
|
13390
|
-
try {
|
|
13391
|
-
const [start, end] = findBrackets(eqString, idx);
|
|
13392
|
-
if (start === idx && end > startIdx) return [start, end];
|
|
13393
|
-
} catch {
|
|
13394
|
-
return null;
|
|
13131
|
+
function cellLineBoxes(c) {
|
|
13132
|
+
const out = [];
|
|
13133
|
+
let shift = 0, prevV = Number.NEGATIVE_INFINITY, prevEnd = 0, part = 0;
|
|
13134
|
+
const cols = cellColumns(c.sub);
|
|
13135
|
+
for (const p of c.sub ? elements(c.sub) : []) if (ln(p) === "p") {
|
|
13136
|
+
const lsa = findChildByLocalName(p, "linesegarray");
|
|
13137
|
+
for (const sg of lsa ? elements(lsa) : []) if (ln(sg) === "lineseg") {
|
|
13138
|
+
const v = num(sg, "vertpos");
|
|
13139
|
+
if (v < prevV && !cols) {
|
|
13140
|
+
shift = prevEnd - v;
|
|
13141
|
+
part++;
|
|
13395
13142
|
}
|
|
13396
|
-
|
|
13143
|
+
prevV = v;
|
|
13144
|
+
const top = v + shift, bottom = top + num(sg, "vertsize");
|
|
13145
|
+
prevEnd = bottom + num(sg, "spacing");
|
|
13146
|
+
out.push({ seg: sg, top, bottom, part, origin: shift });
|
|
13397
13147
|
}
|
|
13398
13148
|
}
|
|
13399
|
-
return
|
|
13149
|
+
return out;
|
|
13400
13150
|
}
|
|
13401
|
-
function
|
|
13402
|
-
return
|
|
13151
|
+
function cellLines(c) {
|
|
13152
|
+
return cellLineBoxes(c).map((b) => [b.top, b.bottom]);
|
|
13403
13153
|
}
|
|
13404
|
-
function
|
|
13405
|
-
|
|
13406
|
-
|
|
13407
|
-
|
|
13408
|
-
|
|
13409
|
-
|
|
13154
|
+
function planTableRows(tbl, cells, rowH, ty, MT, BODY_H, slack = 0, floatSpan, nested = false) {
|
|
13155
|
+
if (nested) slack = 0;
|
|
13156
|
+
const nRows = rowH.length;
|
|
13157
|
+
const rowY = [0];
|
|
13158
|
+
for (const h of rowH) rowY.push(rowY[rowY.length - 1] + h);
|
|
13159
|
+
const plain = () => rowH.map((h, r) => [{ page: 0, y: ty + rowY[r], h }]);
|
|
13160
|
+
const pageBottom = MT + BODY_H;
|
|
13161
|
+
const stackOver = tbl.getAttribute("pageBreak") === "CELL" && rowH.some((h, r) => {
|
|
13162
|
+
const rc = cells.filter((c) => c.ra === r && c.rs === 1);
|
|
13163
|
+
if (rc.length !== 1) return false;
|
|
13164
|
+
const st = stackedFloats(rc[0]);
|
|
13165
|
+
return st.length >= 2 && st.reduce((a, f) => a + f.h, 0) > h;
|
|
13166
|
+
});
|
|
13167
|
+
if (BODY_H <= 0 || ty + rowY[nRows] <= pageBottom + slack && !stackOver) return plain();
|
|
13168
|
+
if (findChildByLocalName(tbl, "pos")?.getAttribute("treatAsChar") === "1") {
|
|
13169
|
+
const declared = num(findChildByLocalName(tbl, "sz"), "height") || rowY[nRows];
|
|
13170
|
+
if (ty - MT < 2e3 || ty + declared <= pageBottom + slack) return plain();
|
|
13171
|
+
return rowH.map((h, r) => [{ page: 1, y: MT + rowY[r], h }]);
|
|
13410
13172
|
}
|
|
13411
|
-
|
|
13412
|
-
|
|
13413
|
-
|
|
13414
|
-
const
|
|
13415
|
-
const masked = maskLiteralSpans(eqString);
|
|
13173
|
+
let hdrRows = 0;
|
|
13174
|
+
if (tbl.getAttribute("repeatHeader") === "1") while (hdrRows < nRows && cells.some((c) => c.ra === hdrRows) && cells.filter((c) => c.ra === hdrRows).every((c) => c.el.getAttribute("header") === "1")) hdrRows++;
|
|
13175
|
+
const contTop = MT + num(findChildByLocalName(tbl, "outMargin"), "top") + rowY[hdrRows];
|
|
13176
|
+
const cellSplit = tbl.getAttribute("pageBreak") === "CELL";
|
|
13416
13177
|
const out = [];
|
|
13417
|
-
let
|
|
13418
|
-
for (let
|
|
13419
|
-
|
|
13420
|
-
const
|
|
13421
|
-
|
|
13422
|
-
|
|
13423
|
-
|
|
13424
|
-
|
|
13425
|
-
|
|
13426
|
-
|
|
13427
|
-
|
|
13428
|
-
|
|
13429
|
-
|
|
13430
|
-
|
|
13178
|
+
let page = 0, y = ty, first = true;
|
|
13179
|
+
for (let r = 0; r < nRows; r++) {
|
|
13180
|
+
let h = rowH[r];
|
|
13181
|
+
const pieces = [];
|
|
13182
|
+
const rowCells = cells.filter((c) => c.ra === r && c.rs === 1);
|
|
13183
|
+
const splittable = cellSplit && r >= hdrRows && rowCells.length > 0;
|
|
13184
|
+
const stack = splittable && rowCells.length === 1 ? stackedFloats(rowCells[0]) : [];
|
|
13185
|
+
if (stack.length >= 2) {
|
|
13186
|
+
const c = rowCells[0];
|
|
13187
|
+
let top = y, bottom = y + c.marginT, k = 0;
|
|
13188
|
+
const pcs = [];
|
|
13189
|
+
let place = /* @__PURE__ */ new Map();
|
|
13190
|
+
for (const f of stack) {
|
|
13191
|
+
let at = k === 0 ? top + c.marginT + f.vo : bottom;
|
|
13192
|
+
if (k > 0 && at + f.h > pageBottom - c.marginB) {
|
|
13193
|
+
pcs.push({ page, y: top, h: bottom - top + c.marginB, range: /* @__PURE__ */ new Map([[c.el, pcs.length ? [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY] : [0, Number.POSITIVE_INFINITY]]]), place });
|
|
13194
|
+
page++;
|
|
13195
|
+
top = contTop;
|
|
13196
|
+
place = /* @__PURE__ */ new Map();
|
|
13197
|
+
at = top + c.marginT;
|
|
13198
|
+
bottom = at;
|
|
13199
|
+
}
|
|
13200
|
+
place.set(f.el, at + f.omT);
|
|
13201
|
+
bottom = Math.max(bottom, at + f.h);
|
|
13202
|
+
k++;
|
|
13203
|
+
}
|
|
13204
|
+
if (pcs.length) {
|
|
13205
|
+
pcs.push({ page, y: top, h: bottom - top + c.marginB, range: /* @__PURE__ */ new Map([[c.el, [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]]]), place });
|
|
13206
|
+
out.push(pcs);
|
|
13207
|
+
y = bottom + c.marginB;
|
|
13208
|
+
first = false;
|
|
13209
|
+
continue;
|
|
13431
13210
|
}
|
|
13432
|
-
if (numStart < 0) break;
|
|
13433
|
-
out.length = end;
|
|
13434
|
-
out.splice(numStart, 0, "\\frac");
|
|
13435
|
-
} else {
|
|
13436
|
-
while (numStart > 0 && !/\s/.test(out[numStart - 1])) numStart--;
|
|
13437
|
-
if (numStart === end) break;
|
|
13438
|
-
out.length = end;
|
|
13439
|
-
out.splice(numStart, 0, "\\frac", "{");
|
|
13440
|
-
out.push("}");
|
|
13441
13211
|
}
|
|
13442
|
-
|
|
13443
|
-
|
|
13444
|
-
|
|
13445
|
-
|
|
13446
|
-
|
|
13447
|
-
|
|
13448
|
-
|
|
13449
|
-
|
|
13450
|
-
|
|
13451
|
-
|
|
13452
|
-
|
|
13453
|
-
|
|
13454
|
-
|
|
13455
|
-
|
|
13456
|
-
|
|
13457
|
-
|
|
13458
|
-
|
|
13459
|
-
|
|
13212
|
+
const boxes = splittable ? new Map(rowCells.map((c) => [c.el, cellLineBoxes(c)])) : void 0;
|
|
13213
|
+
const hParts = boxes ? Math.max(0, ...[...boxes.values()].flatMap((bs) => bs.map((b) => b.part))) : 0;
|
|
13214
|
+
if (boxes && hParts > 0) {
|
|
13215
|
+
const declared = num(findChildByLocalName(tbl, "sz"), "height");
|
|
13216
|
+
const led = /* @__PURE__ */ new Set();
|
|
13217
|
+
for (let k = 0; k <= hParts; k++) {
|
|
13218
|
+
if (k > 0 && floatSpan) {
|
|
13219
|
+
let lead = 0, place;
|
|
13220
|
+
for (const c of rowCells) {
|
|
13221
|
+
const b = (boxes.get(c.el) ?? []).find((x) => x.part === k);
|
|
13222
|
+
if (!b) continue;
|
|
13223
|
+
const f = floatSpan(b.seg, y + c.marginT);
|
|
13224
|
+
if (f?.el && f.pages > 0 && f.pages > lead && Math.abs(contTop + c.marginT + b.top - b.origin - f.endY) < 3e3) {
|
|
13225
|
+
lead = f.pages;
|
|
13226
|
+
place = /* @__PURE__ */ new Map([[f.el, y + c.marginT]]);
|
|
13227
|
+
led.add(b.seg);
|
|
13228
|
+
}
|
|
13229
|
+
}
|
|
13230
|
+
if (lead > 0) {
|
|
13231
|
+
const none = new Map(rowCells.map((c) => [c.el, [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]]));
|
|
13232
|
+
for (let e = 0; e < lead; e++) pieces.push({ page: page + e, y: contTop, h: pageBottom - contTop, range: none, place: e === 0 ? place : void 0 });
|
|
13233
|
+
page += lead;
|
|
13234
|
+
}
|
|
13235
|
+
}
|
|
13236
|
+
const range = /* @__PURE__ */ new Map();
|
|
13237
|
+
let ext = 0, toNext = 0;
|
|
13238
|
+
for (const c of rowCells) {
|
|
13239
|
+
const bs = boxes.get(c.el) ?? [];
|
|
13240
|
+
const inK = bs.filter((b) => b.part === k), next = bs.find((b) => b.part > k);
|
|
13241
|
+
const from = inK[0]?.origin ?? next?.origin ?? Number.POSITIVE_INFINITY;
|
|
13242
|
+
range.set(c.el, [from, next?.top ?? Number.POSITIVE_INFINITY]);
|
|
13243
|
+
if (inK.length) ext = Math.max(ext, inK[inK.length - 1].bottom - from + c.marginT + c.marginB);
|
|
13244
|
+
if (inK.length && next) toNext = Math.max(toNext, next.top - from + c.marginT + c.marginB);
|
|
13245
|
+
}
|
|
13246
|
+
const last = k === hParts;
|
|
13247
|
+
const firstH = declared > 0 && ty + declared - y >= ext ? Math.min(pageBottom - y, ty + declared - y) : pageBottom - y;
|
|
13248
|
+
const ph = last ? ext : k === 0 ? firstH : toNext > 0 ? Math.min(pageBottom - contTop, toNext) : pageBottom - contTop;
|
|
13249
|
+
pieces.push({ page, y, h: ph, range });
|
|
13250
|
+
if (!last) {
|
|
13251
|
+
let span = 0, spanEnd = 0;
|
|
13252
|
+
if (floatSpan) for (const c of rowCells) {
|
|
13253
|
+
const bs = (boxes.get(c.el) ?? []).filter((b) => b.part === k), from = bs[0]?.origin ?? 0;
|
|
13254
|
+
for (const b of bs) {
|
|
13255
|
+
if (led.has(b.seg)) continue;
|
|
13256
|
+
const f = floatSpan(b.seg, y + c.marginT + b.top - from);
|
|
13257
|
+
if (f && f.pages > span) {
|
|
13258
|
+
span = f.pages;
|
|
13259
|
+
spanEnd = f.endY;
|
|
13260
|
+
}
|
|
13261
|
+
}
|
|
13262
|
+
}
|
|
13263
|
+
if (span > 0) {
|
|
13264
|
+
const nextTop = Math.min(...rowCells.map((c) => {
|
|
13265
|
+
const b = (boxes.get(c.el) ?? []).find((x) => x.part === k + 1);
|
|
13266
|
+
return b ? contTop + c.marginT + b.top - b.origin : Number.POSITIVE_INFINITY;
|
|
13267
|
+
}));
|
|
13268
|
+
const skip = nextTop < spanEnd - 100 ? span + 1 : span;
|
|
13269
|
+
for (let e = 1; e < skip; e++) pieces.push({ page: page + e, y: contTop, h: pageBottom - contTop, range: new Map(rowCells.map((c) => [c.el, [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]])) });
|
|
13270
|
+
page += skip;
|
|
13271
|
+
} else page++;
|
|
13272
|
+
y = contTop;
|
|
13273
|
+
first = true;
|
|
13274
|
+
} else h = ph;
|
|
13275
|
+
}
|
|
13276
|
+
out.push(pieces);
|
|
13277
|
+
y += h;
|
|
13278
|
+
first = false;
|
|
13279
|
+
continue;
|
|
13460
13280
|
}
|
|
13461
|
-
|
|
13462
|
-
|
|
13463
|
-
|
|
13464
|
-
|
|
13465
|
-
|
|
13466
|
-
|
|
13467
|
-
|
|
13468
|
-
|
|
13469
|
-
|
|
13470
|
-
|
|
13471
|
-
|
|
13472
|
-
|
|
13473
|
-
|
|
13474
|
-
|
|
13475
|
-
|
|
13476
|
-
|
|
13477
|
-
|
|
13478
|
-
|
|
13479
|
-
|
|
13480
|
-
|
|
13481
|
-
|
|
13482
|
-
|
|
13483
|
-
|
|
13484
|
-
|
|
13485
|
-
|
|
13486
|
-
beforeMat = input.slice(0, cursor);
|
|
13487
|
-
afterMat = input.slice(eEnd);
|
|
13281
|
+
if (splittable && y + h > pageBottom) {
|
|
13282
|
+
const from = /* @__PURE__ */ new Map();
|
|
13283
|
+
const lines = new Map(rowCells.map((c) => [c.el, cellLines(c)]));
|
|
13284
|
+
while (y + h > pageBottom && BODY_H > rowY[hdrRows]) {
|
|
13285
|
+
const avail = pageBottom - y;
|
|
13286
|
+
let rem = 0, placed = false, allFit = true, blocked = false;
|
|
13287
|
+
const cuts = [];
|
|
13288
|
+
for (const c of rowCells) {
|
|
13289
|
+
const off = from.get(c.el) ?? 0;
|
|
13290
|
+
const ls = (lines.get(c.el) ?? []).filter((l) => l[0] >= off);
|
|
13291
|
+
if (!ls.length) {
|
|
13292
|
+
cuts.push([c.el, off, off]);
|
|
13293
|
+
continue;
|
|
13294
|
+
}
|
|
13295
|
+
const end = Math.max(...ls.map((l) => l[1]));
|
|
13296
|
+
const k = ls.findIndex((l) => c.marginT + (l[1] - off) > avail - c.marginB);
|
|
13297
|
+
if (k < 0) {
|
|
13298
|
+
cuts.push([c.el, off, end + 1]);
|
|
13299
|
+
continue;
|
|
13300
|
+
}
|
|
13301
|
+
allFit = false;
|
|
13302
|
+
if (k > 0) placed = true;
|
|
13303
|
+
else if (off === 0) blocked = true;
|
|
13304
|
+
cuts.push([c.el, off, ls[k][0]]);
|
|
13305
|
+
rem = Math.max(rem, end - ls[k][0] + c.marginT + c.marginB);
|
|
13488
13306
|
}
|
|
13489
|
-
|
|
13490
|
-
|
|
13491
|
-
|
|
13307
|
+
if (allFit) {
|
|
13308
|
+
if (!first && h <= pageBottom - contTop && rowCells.some((c) => cellContentExtent(c) + c.marginT + c.marginB > avail)) {
|
|
13309
|
+
page++;
|
|
13310
|
+
y = contTop;
|
|
13311
|
+
first = true;
|
|
13312
|
+
break;
|
|
13313
|
+
}
|
|
13314
|
+
if (nested && avail > 0) {
|
|
13315
|
+
pieces.push({ page, y, h: avail, range: new Map(rowCells.map((c) => [c.el, [from.get(c.el) ?? 0, Number.POSITIVE_INFINITY]])) });
|
|
13316
|
+
for (const c of rowCells) from.set(c.el, Number.POSITIVE_INFINITY);
|
|
13317
|
+
page++;
|
|
13318
|
+
y = contTop;
|
|
13319
|
+
first = true;
|
|
13320
|
+
h -= avail;
|
|
13321
|
+
continue;
|
|
13322
|
+
}
|
|
13323
|
+
h = avail;
|
|
13324
|
+
break;
|
|
13325
|
+
}
|
|
13326
|
+
if (blocked && !first) {
|
|
13327
|
+
page++;
|
|
13328
|
+
y = contTop;
|
|
13329
|
+
first = true;
|
|
13330
|
+
continue;
|
|
13331
|
+
}
|
|
13332
|
+
if (!placed) {
|
|
13333
|
+
if (first) break;
|
|
13334
|
+
page++;
|
|
13335
|
+
y = contTop;
|
|
13336
|
+
first = true;
|
|
13337
|
+
continue;
|
|
13338
|
+
}
|
|
13339
|
+
pieces.push({ page, y, h: avail, range: new Map(cuts.map(([el, a, b]) => [el, [a, b]])) });
|
|
13340
|
+
for (const [el, , b] of cuts) from.set(el, b);
|
|
13341
|
+
page++;
|
|
13342
|
+
y = contTop;
|
|
13343
|
+
first = true;
|
|
13344
|
+
h = rem;
|
|
13492
13345
|
}
|
|
13346
|
+
pieces.push({ page, y, h, range: new Map(rowCells.map((c) => [c.el, [from.get(c.el) ?? 0, Number.POSITIVE_INFINITY]])) });
|
|
13347
|
+
out.push(pieces);
|
|
13348
|
+
y += h;
|
|
13349
|
+
first = false;
|
|
13350
|
+
continue;
|
|
13493
13351
|
}
|
|
13494
|
-
|
|
13495
|
-
|
|
13496
|
-
|
|
13497
|
-
|
|
13352
|
+
if (!first && y + h > pageBottom && r >= hdrRows) {
|
|
13353
|
+
page++;
|
|
13354
|
+
y = contTop;
|
|
13355
|
+
first = true;
|
|
13356
|
+
}
|
|
13357
|
+
out.push([{ page, y, h }]);
|
|
13358
|
+
y += h;
|
|
13359
|
+
first = false;
|
|
13498
13360
|
}
|
|
13499
|
-
return
|
|
13361
|
+
return out;
|
|
13500
13362
|
}
|
|
13501
|
-
|
|
13502
|
-
|
|
13503
|
-
|
|
13504
|
-
|
|
13505
|
-
|
|
13506
|
-
|
|
13507
|
-
|
|
13508
|
-
|
|
13509
|
-
|
|
13510
|
-
|
|
13511
|
-
|
|
13512
|
-
|
|
13513
|
-
|
|
13514
|
-
} catch {
|
|
13515
|
-
return input;
|
|
13516
|
-
}
|
|
13363
|
+
|
|
13364
|
+
// src/render/shape-geometry.ts
|
|
13365
|
+
var pt = (u) => String(Math.round(u) / 100);
|
|
13366
|
+
var esc = (s) => s.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
13367
|
+
var SHAPE_TAGS = /* @__PURE__ */ new Set(["rect", "ellipse", "line", "polygon", "curv", "curve", "arc"]);
|
|
13368
|
+
function rotatedBounds(box, rotations) {
|
|
13369
|
+
if (!rotations.length) return box;
|
|
13370
|
+
let points = [[box.x, box.y], [box.x + box.w, box.y], [box.x + box.w, box.y + box.h], [box.x, box.y + box.h]];
|
|
13371
|
+
for (let i = rotations.length - 1; i >= 0; i--) {
|
|
13372
|
+
const r = rotations[i];
|
|
13373
|
+
if (Array.isArray(r)) {
|
|
13374
|
+
points = points.map(([x2, y2]) => [r[0] * x2 + r[2] * y2 + r[4], r[1] * x2 + r[3] * y2 + r[5]]);
|
|
13375
|
+
continue;
|
|
13517
13376
|
}
|
|
13518
|
-
|
|
13519
|
-
|
|
13520
|
-
|
|
13521
|
-
eqString = replaceBar(eqString, barKey, barElem);
|
|
13377
|
+
const { angle, cx, cy } = r;
|
|
13378
|
+
const a = angle * Math.PI / 180, c = Math.cos(a), s = Math.sin(a);
|
|
13379
|
+
points = points.map(([x2, y2]) => [cx + c * (x2 - cx) - s * (y2 - cy), cy + s * (x2 - cx) + c * (y2 - cy)]);
|
|
13522
13380
|
}
|
|
13523
|
-
|
|
13381
|
+
const x = Math.min(...points.map((p) => p[0])), y = Math.min(...points.map((p) => p[1]));
|
|
13382
|
+
return { x, y, w: Math.max(...points.map((p) => p[0])) - x, h: Math.max(...points.map((p) => p[1])) - y };
|
|
13524
13383
|
}
|
|
13525
|
-
function
|
|
13526
|
-
|
|
13527
|
-
|
|
13528
|
-
|
|
13529
|
-
|
|
13530
|
-
|
|
13531
|
-
|
|
13532
|
-
|
|
13533
|
-
|
|
13534
|
-
const elem2 = input.slice(eStart2, eEnd2);
|
|
13535
|
-
const beforeBrace = input.slice(0, cursor);
|
|
13536
|
-
const afterBrace = input.slice(eEnd2);
|
|
13537
|
-
input = beforeBrace + braceElem + elem1 + "^" + elem2 + afterBrace;
|
|
13538
|
-
} catch {
|
|
13539
|
-
return input;
|
|
13540
|
-
}
|
|
13541
|
-
}
|
|
13542
|
-
return input;
|
|
13543
|
-
};
|
|
13544
|
-
for (const [braceKey, braceElem] of Object.entries(BRACE_CONVERT_MAP)) {
|
|
13545
|
-
eqString = replaceBrace(eqString, braceKey, braceElem);
|
|
13546
|
-
}
|
|
13547
|
-
return eqString;
|
|
13548
|
-
}
|
|
13549
|
-
function replaceBracket(strList) {
|
|
13550
|
-
for (let i = 0; i < strList.length; i++) {
|
|
13551
|
-
if (strList[i] === "{" && i > 0 && strList[i - 1] === "\\left") strList[i] = "\\{";
|
|
13552
|
-
if (strList[i] === "}" && i > 0 && strList[i - 1] === "\\right") strList[i] = "\\}";
|
|
13553
|
-
}
|
|
13554
|
-
return strList;
|
|
13384
|
+
function mulAffine(m, n) {
|
|
13385
|
+
return [
|
|
13386
|
+
m[0] * n[0] + m[2] * n[1],
|
|
13387
|
+
m[1] * n[0] + m[3] * n[1],
|
|
13388
|
+
m[0] * n[2] + m[2] * n[3],
|
|
13389
|
+
m[1] * n[2] + m[3] * n[3],
|
|
13390
|
+
m[0] * n[4] + m[2] * n[5] + m[4],
|
|
13391
|
+
m[1] * n[4] + m[3] * n[5] + m[5]
|
|
13392
|
+
];
|
|
13555
13393
|
}
|
|
13556
|
-
function
|
|
13557
|
-
|
|
13558
|
-
|
|
13559
|
-
|
|
13560
|
-
|
|
13561
|
-
|
|
13562
|
-
|
|
13563
|
-
|
|
13564
|
-
|
|
13565
|
-
else {
|
|
13566
|
-
const quoted = /^"(.+)"$/.exec(t);
|
|
13567
|
-
if (quoted) tokens[i] = `\\text{${quoted[1]}}`;
|
|
13568
|
-
}
|
|
13394
|
+
function renderingMatrix(el) {
|
|
13395
|
+
const info = findChildByLocalName(el, "renderingInfo");
|
|
13396
|
+
if (!info) return null;
|
|
13397
|
+
let m = null;
|
|
13398
|
+
for (const c of elements(info)) {
|
|
13399
|
+
const tag = ln(c);
|
|
13400
|
+
if (tag !== "transMatrix" && tag !== "scaMatrix" && tag !== "rotMatrix") continue;
|
|
13401
|
+
const n = [num(c, "e1", 1), num(c, "e4"), num(c, "e2"), num(c, "e5", 1), num(c, "e3"), num(c, "e6")];
|
|
13402
|
+
m = m ? mulAffine(m, n) : n;
|
|
13569
13403
|
}
|
|
13570
|
-
|
|
13571
|
-
tokens = replaceBracket(tokens);
|
|
13572
|
-
let out = tokens.join(" ");
|
|
13573
|
-
out = replaceFrac(out);
|
|
13574
|
-
out = replaceRootOf(out);
|
|
13575
|
-
out = replaceAllMatrix(out);
|
|
13576
|
-
out = replaceAllBar(out);
|
|
13577
|
-
out = replaceAllBrace(out);
|
|
13578
|
-
return out;
|
|
13579
|
-
}
|
|
13580
|
-
|
|
13581
|
-
// src/hwp5/equation.ts
|
|
13582
|
-
var WORD_ALIASES = {
|
|
13583
|
-
// 삼각/로그 함수 — 정본 맵 부재
|
|
13584
|
-
sin: "\\sin",
|
|
13585
|
-
cos: "\\cos",
|
|
13586
|
-
tan: "\\tan",
|
|
13587
|
-
sec: "\\sec",
|
|
13588
|
-
csc: "\\csc",
|
|
13589
|
-
cot: "\\cot",
|
|
13590
|
-
log: "\\log",
|
|
13591
|
-
ln: "\\ln",
|
|
13592
|
-
// 연산자·관계 기호 (정본은 대문자 키만 보유)
|
|
13593
|
-
divide: "\\div",
|
|
13594
|
-
div: "\\div",
|
|
13595
|
-
le: "\\leq",
|
|
13596
|
-
ge: "\\geq",
|
|
13597
|
-
geq: "\\geq",
|
|
13598
|
-
deg: "^\\circ",
|
|
13599
|
-
rarrow: "\\rightarrow",
|
|
13600
|
-
lrarrow: "\\leftrightarrow",
|
|
13601
|
-
rightarrow: "\\rightarrow",
|
|
13602
|
-
leftarrow: "\\leftarrow",
|
|
13603
|
-
in: "\\in",
|
|
13604
|
-
notin: "\\notin",
|
|
13605
|
-
emptyset: "\\emptyset",
|
|
13606
|
-
subset: "\\subset",
|
|
13607
|
-
nsubset: "\\nsubseteq",
|
|
13608
|
-
cup: "\\cup",
|
|
13609
|
-
cap: "\\cap",
|
|
13610
|
-
smallinter: "\\cap",
|
|
13611
|
-
smallsum: "\\sum",
|
|
13612
|
-
sim: "\\sim",
|
|
13613
|
-
circ: "\\circ",
|
|
13614
|
-
bot: "\\perp",
|
|
13615
|
-
partial: "\\partial",
|
|
13616
|
-
nabla: "\\nabla",
|
|
13617
|
-
angle: "\\angle",
|
|
13618
|
-
triangle: "\\triangle",
|
|
13619
|
-
inf: "\\infty",
|
|
13620
|
-
left: "\\left",
|
|
13621
|
-
right: "\\right",
|
|
13622
|
-
// 글꼴 지시자 — 제거
|
|
13623
|
-
rm: "",
|
|
13624
|
-
it: ""
|
|
13625
|
-
};
|
|
13626
|
-
var STRUCTURAL_FOLD = /* @__PURE__ */ new Set(["over", "root", "of"]);
|
|
13627
|
-
function normalizeWords(input) {
|
|
13628
|
-
return input.replace(/(?<![\\A-Za-z0-9])([A-Za-z][A-Za-z0-9]*)(?![A-Za-z0-9])/g, (word) => {
|
|
13629
|
-
if (Object.hasOwn(CONVERT_MAP, word) || Object.hasOwn(MIDDLE_CONVERT_MAP, word)) return word;
|
|
13630
|
-
const lower = word.toLowerCase();
|
|
13631
|
-
if (STRUCTURAL_FOLD.has(lower)) return lower;
|
|
13632
|
-
if (Object.hasOwn(WORD_ALIASES, lower)) return WORD_ALIASES[lower];
|
|
13633
|
-
if (lower !== word && (Object.hasOwn(CONVERT_MAP, lower) || Object.hasOwn(MIDDLE_CONVERT_MAP, lower))) return lower;
|
|
13634
|
-
return word;
|
|
13635
|
-
});
|
|
13636
|
-
}
|
|
13637
|
-
function normalizeScripts(input) {
|
|
13638
|
-
return input.replace(/\s*\^\s*/g, "^").replace(/\s*_\s*/g, "_").replace(/\^(?!\{)([^\s{}_^]+)/g, "^{$1}").replace(/_(?!\{)([^\s{}_^]+)/g, "_{$1}").replace(/([_^])/g, " $1 ");
|
|
13639
|
-
}
|
|
13640
|
-
function normalizeOperators(input) {
|
|
13641
|
-
return input.replace(/\+-/g, " \\pm ").replace(/-\+/g, " \\mp ").replace(/\/\//g, " \\parallel ").replace(/!=/g, " \\neq ").replace(/<=/g, " \\leq ").replace(/>=/g, " \\geq ").replace(/==/g, " \\equiv ").replace(/△/g, " \\triangle ").replace(/□/g, " \\square ").replace(/‧/g, " \\cdot ");
|
|
13642
|
-
}
|
|
13643
|
-
function hwpEquationToLatex(equation) {
|
|
13644
|
-
let s = equation.replace(/\0/g, "").replace(/\s+/g, " ").trim();
|
|
13645
|
-
if (!s) return "";
|
|
13646
|
-
s = normalizeScripts(s);
|
|
13647
|
-
s = normalizeOperators(s);
|
|
13648
|
-
s = normalizeWords(s);
|
|
13649
|
-
s = s.replace(/\broot\s+(?!\{)(\S+)\s+of(?![A-Za-z0-9])/gi, "root { $1 } of");
|
|
13650
|
-
return hmlToLatex(s).replace(/\s+/g, " ").trim();
|
|
13651
|
-
}
|
|
13652
|
-
|
|
13653
|
-
// src/render/scene.ts
|
|
13654
|
-
function regionId(type, seq) {
|
|
13655
|
-
return `${type}-${String(seq).padStart(6, "0")}`;
|
|
13404
|
+
return m;
|
|
13656
13405
|
}
|
|
13657
|
-
function
|
|
13658
|
-
const
|
|
13659
|
-
|
|
13406
|
+
function objectGeometry(el, x, y, w, h, boxW = w, boxH = h) {
|
|
13407
|
+
const rot = findChildByLocalName(el, "rotationInfo");
|
|
13408
|
+
const angle = num(rot, "angle") % 360;
|
|
13409
|
+
if (!angle) return { x, y, w, h, bbox: { x, y, w, h }, transform: "" };
|
|
13410
|
+
const cx = x + boxW / 2, cy = y + boxH / 2;
|
|
13411
|
+
const fx = cx - w / 2, fy = cy - h / 2;
|
|
13412
|
+
const rotation = { angle, cx: Math.round(cx), cy: Math.round(cy) };
|
|
13413
|
+
return { x: fx, y: fy, w, h, bbox: rotatedBounds({ x: fx, y: fy, w, h }, [rotation]), rotation, transform: `rotate(${angle} ${pt(cx)} ${pt(cy)})` };
|
|
13660
13414
|
}
|
|
13661
|
-
|
|
13662
|
-
|
|
13663
|
-
|
|
13664
|
-
|
|
13665
|
-
|
|
13666
|
-
|
|
13667
|
-
|
|
13668
|
-
const
|
|
13669
|
-
if (
|
|
13670
|
-
|
|
13671
|
-
|
|
13672
|
-
|
|
13673
|
-
|
|
13674
|
-
|
|
13675
|
-
const
|
|
13676
|
-
|
|
13677
|
-
const
|
|
13678
|
-
if (
|
|
13679
|
-
else
|
|
13680
|
-
|
|
13681
|
-
};
|
|
13682
|
-
|
|
13683
|
-
// src/render/page-stories.ts
|
|
13684
|
-
function pageStories(root, masters, paraPages, pageCount, pageBase, geom) {
|
|
13685
|
-
const secPr = findFirst(root, "secPr"), visibility = secPr && findChildByLocalName(secPr, "visibility");
|
|
13686
|
-
const pagePr = secPr && findChildByLocalName(secPr, "pagePr"), margin = pagePr && findChildByLocalName(pagePr, "margin");
|
|
13687
|
-
const declarations = [];
|
|
13688
|
-
const hidden = /* @__PURE__ */ new Map();
|
|
13689
|
-
for (const p of elements(root)) if (ln(p) === "p") {
|
|
13690
|
-
const page = paraPages.get(p)?.[0] ?? 0;
|
|
13691
|
-
for (const run of elements(p)) if (ln(run) === "run") {
|
|
13692
|
-
for (const ctrl of elements(run)) if (ln(ctrl) === "ctrl") {
|
|
13693
|
-
for (const el of elements(ctrl)) {
|
|
13694
|
-
if (isDeletedControl(el)) continue;
|
|
13695
|
-
const kind = ln(el);
|
|
13696
|
-
if (kind === "header" || kind === "footer") declarations.push({ el, page, kind });
|
|
13697
|
-
else if (kind === "pageHiding") {
|
|
13698
|
-
const kinds = hidden.get(page) ?? /* @__PURE__ */ new Set();
|
|
13699
|
-
for (const name of ["Header", "Footer", "MasterPage"]) if (num(el, `hide${name}`)) kinds.add(name);
|
|
13700
|
-
hidden.set(page, kinds);
|
|
13701
|
-
}
|
|
13702
|
-
}
|
|
13703
|
-
}
|
|
13415
|
+
function shapeFill(el, defs, images, warn) {
|
|
13416
|
+
const brush = findChildByLocalName(el, "fillBrush");
|
|
13417
|
+
const win = brush && findChildByLocalName(brush, "winBrush");
|
|
13418
|
+
const face = win?.getAttribute("faceColor");
|
|
13419
|
+
if (docColor(face)) return esc(face);
|
|
13420
|
+
const grad = brush && findChildByLocalName(brush, "gradation");
|
|
13421
|
+
if (grad) {
|
|
13422
|
+
const colors = elements(grad).filter((c) => ln(c) === "color").map((c) => docColor(c.getAttribute("value"), "#000000"));
|
|
13423
|
+
if (!colors.length) return "none";
|
|
13424
|
+
const type = grad.getAttribute("type") ?? "LINEAR";
|
|
13425
|
+
if (type !== "LINEAR" && type !== "RADIAL") {
|
|
13426
|
+
warn(`gradient:${type}`, `\uADF8\uB77C\uB370\uC774\uC158(${type}) \uBBF8\uC9C0\uC6D0 \u2014 \uCCAB \uC0C9\uC73C\uB85C \uCC44\uC6C0`);
|
|
13427
|
+
return esc(colors[0]);
|
|
13428
|
+
}
|
|
13429
|
+
const id = `paint${defs.length}`;
|
|
13430
|
+
const opacity = Math.max(0, Math.min(1, 1 - num(grad, "alpha") / 255));
|
|
13431
|
+
const stops = colors.map((color, i) => `<stop offset="${colors.length === 1 ? 0 : i / (colors.length - 1)}" stop-color="${esc(color)}" stop-opacity="${opacity}"/>`).join("");
|
|
13432
|
+
if (type === "RADIAL") defs.push(`<radialGradient id="${id}" cx="${num(grad, "centerX", 50)}%" cy="${num(grad, "centerY", 50)}%">${stops}</radialGradient>`);
|
|
13433
|
+
else {
|
|
13434
|
+
const a = num(grad, "angle") * Math.PI / 180, dx = Math.cos(a) / 2, dy = -Math.sin(a) / 2;
|
|
13435
|
+
defs.push(`<linearGradient id="${id}" x1="${0.5 - dx}" y1="${0.5 - dy}" x2="${0.5 + dx}" y2="${0.5 + dy}">${stops}</linearGradient>`);
|
|
13704
13436
|
}
|
|
13437
|
+
return `url(#${id})`;
|
|
13705
13438
|
}
|
|
13706
|
-
const
|
|
13707
|
-
const
|
|
13708
|
-
|
|
13709
|
-
const
|
|
13710
|
-
const
|
|
13711
|
-
if (!
|
|
13712
|
-
|
|
13713
|
-
|
|
13714
|
-
const normal = (matching.length ? matching : both).slice(-1);
|
|
13715
|
-
const specific = masters.filter((m) => m.getAttribute("type") === "LAST_PAGE" ? page === pageCount - 1 : m.getAttribute("type") === "OPTIONAL_PAGE" && num(m, "pageNumber") === page + 1);
|
|
13716
|
-
const special = specific.slice(-1);
|
|
13717
|
-
const selected = special.length && !num(special[0], "pageDuplicate") ? special : [...normal, ...special];
|
|
13718
|
-
for (const master of selected) {
|
|
13719
|
-
const sub = findChildByLocalName(master, "subList");
|
|
13720
|
-
if (sub) out.push({ sub, page, x: geom.ML, y: geom.MT, width: geom.BODY_W, layer: num(master, "pageFront") ? 2 : -2 });
|
|
13721
|
-
}
|
|
13439
|
+
const imgBrush = brush && findChildByLocalName(brush, "imgBrush");
|
|
13440
|
+
const img = imgBrush && findChildByLocalName(imgBrush, "img");
|
|
13441
|
+
if (imgBrush && img) {
|
|
13442
|
+
const ref = img.getAttribute("binaryItemIDRef") ?? "";
|
|
13443
|
+
const loaded = images.get(ref);
|
|
13444
|
+
if (!loaded) {
|
|
13445
|
+
warn(`brush-image:${ref}`, `\uADF8\uB9BC \uCC44\uC6C0 \uC774\uBBF8\uC9C0(${ref}) \uC5C6\uC74C \u2014 \uCC44\uC6C0 \uC0DD\uB7B5`);
|
|
13446
|
+
return "none";
|
|
13722
13447
|
}
|
|
13723
|
-
|
|
13724
|
-
|
|
13725
|
-
|
|
13726
|
-
|
|
13727
|
-
const sub = decl && findChildByLocalName(decl.el, "subList");
|
|
13728
|
-
if (sub) out.push({ sub, page, x: geom.ML, y: kind === "header" ? num(margin, "top", 5668) : geom.PH - num(margin, "bottom", 4252) - num(margin, "footer"), width: geom.BODY_W });
|
|
13448
|
+
const mode = imgBrush.getAttribute("mode") ?? "TOTAL";
|
|
13449
|
+
if (mode !== "TOTAL") {
|
|
13450
|
+
warn(`brush-mode:${mode}`, `\uADF8\uB9BC \uCC44\uC6C0(${mode}) \uBBF8\uC9C0\uC6D0 \u2014 \uCC44\uC6C0 \uC0DD\uB7B5`);
|
|
13451
|
+
return "none";
|
|
13729
13452
|
}
|
|
13453
|
+
if (loaded.paintId) return `url(#${loaded.paintId})`;
|
|
13454
|
+
const id = `paint${defs.length}`;
|
|
13455
|
+
defs.push(`<pattern id="${id}" width="1" height="1" patternContentUnits="objectBoundingBox"><image href="${esc(loaded.dataUri)}" width="1" height="1" preserveAspectRatio="none"/></pattern>`);
|
|
13456
|
+
loaded.paintId = id;
|
|
13457
|
+
return `url(#${id})`;
|
|
13730
13458
|
}
|
|
13731
|
-
return
|
|
13459
|
+
return "none";
|
|
13732
13460
|
}
|
|
13733
|
-
function
|
|
13734
|
-
const
|
|
13735
|
-
const
|
|
13736
|
-
const
|
|
13737
|
-
const
|
|
13738
|
-
|
|
13739
|
-
|
|
13740
|
-
|
|
13741
|
-
|
|
13742
|
-
|
|
13743
|
-
|
|
13744
|
-
|
|
13745
|
-
|
|
13746
|
-
|
|
13747
|
-
|
|
13748
|
-
|
|
13461
|
+
function shapeGeometry(o, boxX, boxY, defs, images, warn, local = false) {
|
|
13462
|
+
const el = o.el, org = findChildByLocalName(el, "orgSz"), cur = findChildByLocalName(el, "curSz");
|
|
13463
|
+
const ow = num(org, "width"), oh = num(org, "height");
|
|
13464
|
+
const w = (local ? ow : num(cur, "width")) || ow || num(cur, "width") || o.width;
|
|
13465
|
+
const h = (local ? oh : num(cur, "height")) || oh || num(cur, "height") || o.height;
|
|
13466
|
+
const geometry = local ? { x: boxX, y: boxY, w, h, bbox: { x: boxX, y: boxY, w, h }, transform: "" } : objectGeometry(el, boxX, boxY, w, h, o.width || w, o.height || h);
|
|
13467
|
+
const { x, y } = geometry;
|
|
13468
|
+
const sx = ow > 0 ? w / ow : 1, sy = oh > 0 ? h / oh : 1;
|
|
13469
|
+
const line = findChildByLocalName(el, "lineShape"), style = line?.getAttribute("style") ?? "SOLID";
|
|
13470
|
+
const color = esc(docColor(line?.getAttribute("color"), "#000000"));
|
|
13471
|
+
const strokeW = style === "NONE" ? 0 : Math.max(0.2, num(line, "width", 33) / 100 * 2.834645);
|
|
13472
|
+
const dash = /DASH|DOT/.test(style) ? ` stroke-dasharray="${style.includes("DOT") ? "1,1.5" : "3,1.5"}"` : "";
|
|
13473
|
+
const keepWidth = local ? ` vector-effect="non-scaling-stroke"` : "";
|
|
13474
|
+
const stroke = strokeW ? ` stroke="${color}" stroke-width="${strokeW.toFixed(2)}"${dash}${keepWidth}` : "";
|
|
13475
|
+
const fill = ` fill="${shapeFill(el, defs, images, warn)}"`;
|
|
13476
|
+
let svg = "";
|
|
13477
|
+
if (o.tag === "rect") svg = `<rect x="${pt(x)}" y="${pt(y)}" width="${pt(w)}" height="${pt(h)}"${fill}${stroke}/>`;
|
|
13478
|
+
else if (o.tag === "ellipse") svg = `<ellipse cx="${pt(x + w / 2)}" cy="${pt(y + h / 2)}" rx="${pt(w / 2)}" ry="${pt(h / 2)}"${fill}${stroke}/>`;
|
|
13479
|
+
else if (o.tag === "line") {
|
|
13480
|
+
const s = findChildByLocalName(el, "startPt"), e = findChildByLocalName(el, "endPt");
|
|
13481
|
+
svg = `<line x1="${pt(x + num(s, "x") * sx)}" y1="${pt(y + num(s, "y") * sy)}" x2="${pt(x + num(e, "x") * sx)}" y2="${pt(y + num(e, "y") * sy)}" stroke="${color}" stroke-width="${(strokeW || 0.3).toFixed(2)}"${dash}${keepWidth}/>`;
|
|
13482
|
+
} else if (o.tag === "polygon" || o.tag === "curv") {
|
|
13483
|
+
const pts = elements(el).filter((c) => ln(c) === "pt").map((c) => `${pt(x + num(c, "x") * sx)},${pt(y + num(c, "y") * sy)}`);
|
|
13484
|
+
if (pts.length >= 2) svg = `<polygon points="${pts.join(" ")}"${fill}${stroke}/>`;
|
|
13485
|
+
} else if (o.tag === "curve") {
|
|
13486
|
+
const segs = elements(el).filter((c) => ln(c) === "seg");
|
|
13487
|
+
if (segs.length) {
|
|
13488
|
+
let path = "", lastX, lastY;
|
|
13489
|
+
for (const s of segs) {
|
|
13490
|
+
const x1 = num(s, "x1"), y1 = num(s, "y1"), x2 = num(s, "x2"), y2 = num(s, "y2");
|
|
13491
|
+
if (x1 !== lastX || y1 !== lastY) path += `M${pt(x + x1 * sx)} ${pt(y + y1 * sy)}`;
|
|
13492
|
+
path += `L${pt(x + x2 * sx)} ${pt(y + y2 * sy)}`;
|
|
13493
|
+
lastX = x2;
|
|
13494
|
+
lastY = y2;
|
|
13495
|
+
}
|
|
13496
|
+
svg = `<path d="${path}"${fill}${stroke}/>`;
|
|
13497
|
+
}
|
|
13498
|
+
} else if (o.tag === "arc") svg = `<ellipse cx="${pt(x + w / 2)}" cy="${pt(y + h / 2)}" rx="${pt(w / 2)}" ry="${pt(h / 2)}" fill="none"${stroke || ` stroke="${color}" stroke-width="0.3"`}/>`;
|
|
13499
|
+
return { ...geometry, svg };
|
|
13500
|
+
}
|
|
13501
|
+
|
|
13502
|
+
// src/render/equation-text.ts
|
|
13503
|
+
var SYMBOLS = {
|
|
13504
|
+
alpha: "\u03B1",
|
|
13505
|
+
beta: "\u03B2",
|
|
13506
|
+
gamma: "\u03B3",
|
|
13507
|
+
delta: "\u03B4",
|
|
13508
|
+
epsilon: "\u03B5",
|
|
13509
|
+
varepsilon: "\u03B5",
|
|
13510
|
+
zeta: "\u03B6",
|
|
13511
|
+
eta: "\u03B7",
|
|
13512
|
+
theta: "\u03B8",
|
|
13513
|
+
vartheta: "\u03D1",
|
|
13514
|
+
iota: "\u03B9",
|
|
13515
|
+
kappa: "\u03BA",
|
|
13516
|
+
lambda: "\u03BB",
|
|
13517
|
+
mu: "\u03BC",
|
|
13518
|
+
nu: "\u03BD",
|
|
13519
|
+
xi: "\u03BE",
|
|
13520
|
+
pi: "\u03C0",
|
|
13521
|
+
rho: "\u03C1",
|
|
13522
|
+
sigma: "\u03C3",
|
|
13523
|
+
tau: "\u03C4",
|
|
13524
|
+
upsilon: "\u03C5",
|
|
13525
|
+
phi: "\u03C6",
|
|
13526
|
+
varphi: "\u03C6",
|
|
13527
|
+
chi: "\u03C7",
|
|
13528
|
+
psi: "\u03C8",
|
|
13529
|
+
omega: "\u03C9",
|
|
13530
|
+
Gamma: "\u0393",
|
|
13531
|
+
Delta: "\u0394",
|
|
13532
|
+
Theta: "\u0398",
|
|
13533
|
+
Lambda: "\u039B",
|
|
13534
|
+
Xi: "\u039E",
|
|
13535
|
+
Pi: "\u03A0",
|
|
13536
|
+
Sigma: "\u03A3",
|
|
13537
|
+
Phi: "\u03A6",
|
|
13538
|
+
Psi: "\u03A8",
|
|
13539
|
+
Omega: "\u03A9",
|
|
13540
|
+
times: "\xD7",
|
|
13541
|
+
cdot: "\xB7",
|
|
13542
|
+
div: "\xF7",
|
|
13543
|
+
pm: "\xB1",
|
|
13544
|
+
mp: "\u2213",
|
|
13545
|
+
le: "\u2264",
|
|
13546
|
+
leq: "\u2264",
|
|
13547
|
+
ge: "\u2265",
|
|
13548
|
+
geq: "\u2265",
|
|
13549
|
+
ne: "\u2260",
|
|
13550
|
+
neq: "\u2260",
|
|
13551
|
+
approx: "\u2248",
|
|
13552
|
+
equiv: "\u2261",
|
|
13553
|
+
sim: "\u223C",
|
|
13554
|
+
infty: "\u221E",
|
|
13555
|
+
rightarrow: "\u2192",
|
|
13556
|
+
leftarrow: "\u2190",
|
|
13557
|
+
Rightarrow: "\u21D2",
|
|
13558
|
+
Leftarrow: "\u21D0",
|
|
13559
|
+
leftrightarrow: "\u2194",
|
|
13560
|
+
Leftrightarrow: "\u21D4",
|
|
13561
|
+
to: "\u2192",
|
|
13562
|
+
angle: "\u2220",
|
|
13563
|
+
triangle: "\u25B3",
|
|
13564
|
+
perp: "\u22A5",
|
|
13565
|
+
parallel: "\u2225",
|
|
13566
|
+
circ: "\u2218",
|
|
13567
|
+
degree: "\xB0",
|
|
13568
|
+
sum: "\u03A3",
|
|
13569
|
+
prod: "\u03A0",
|
|
13570
|
+
int: "\u222B",
|
|
13571
|
+
oint: "\u222E",
|
|
13572
|
+
partial: "\u2202",
|
|
13573
|
+
nabla: "\u2207",
|
|
13574
|
+
in: "\u2208",
|
|
13575
|
+
notin: "\u2209",
|
|
13576
|
+
subset: "\u2282",
|
|
13577
|
+
supset: "\u2283",
|
|
13578
|
+
subseteq: "\u2286",
|
|
13579
|
+
supseteq: "\u2287",
|
|
13580
|
+
cup: "\u222A",
|
|
13581
|
+
cap: "\u2229",
|
|
13582
|
+
emptyset: "\u2205",
|
|
13583
|
+
forall: "\u2200",
|
|
13584
|
+
exists: "\u2203",
|
|
13585
|
+
therefore: "\u2234",
|
|
13586
|
+
because: "\u2235",
|
|
13587
|
+
prime: "\u2032",
|
|
13588
|
+
cdots: "\u22EF",
|
|
13589
|
+
ldots: "\u2026",
|
|
13590
|
+
dots: "\u2026",
|
|
13591
|
+
vdots: "\u22EE",
|
|
13592
|
+
lim: "lim",
|
|
13593
|
+
log: "log",
|
|
13594
|
+
ln: "ln",
|
|
13595
|
+
sin: "sin",
|
|
13596
|
+
cos: "cos",
|
|
13597
|
+
tan: "tan",
|
|
13598
|
+
sec: "sec",
|
|
13599
|
+
csc: "csc",
|
|
13600
|
+
cot: "cot",
|
|
13601
|
+
exp: "exp",
|
|
13602
|
+
max: "max",
|
|
13603
|
+
min: "min",
|
|
13604
|
+
quad: " ",
|
|
13605
|
+
qquad: " ",
|
|
13606
|
+
",": " ",
|
|
13607
|
+
";": " ",
|
|
13608
|
+
"!": "",
|
|
13609
|
+
"{": "{",
|
|
13610
|
+
"}": "}",
|
|
13611
|
+
"|": "\u2016",
|
|
13612
|
+
backslash: "\\",
|
|
13613
|
+
lbrace: "{",
|
|
13614
|
+
rbrace: "}",
|
|
13615
|
+
langle: "\u27E8",
|
|
13616
|
+
rangle: "\u27E9"
|
|
13617
|
+
};
|
|
13618
|
+
var SUP = { "0": "\u2070", "1": "\xB9", "2": "\xB2", "3": "\xB3", "4": "\u2074", "5": "\u2075", "6": "\u2076", "7": "\u2077", "8": "\u2078", "9": "\u2079", "+": "\u207A", "-": "\u207B", "=": "\u207C", "(": "\u207D", ")": "\u207E", n: "\u207F", i: "\u2071", x: "\u02E3", "\u2032": "\u2032" };
|
|
13619
|
+
var SUB = { "0": "\u2080", "1": "\u2081", "2": "\u2082", "3": "\u2083", "4": "\u2084", "5": "\u2085", "6": "\u2086", "7": "\u2087", "8": "\u2088", "9": "\u2089", "+": "\u208A", "-": "\u208B", "=": "\u208C", "(": "\u208D", ")": "\u208E" };
|
|
13620
|
+
function latexToPlain(latex) {
|
|
13621
|
+
let i = 0;
|
|
13622
|
+
const s = latex;
|
|
13623
|
+
const skipWs = () => {
|
|
13624
|
+
while (i < s.length && s[i] === " ") i++;
|
|
13625
|
+
};
|
|
13626
|
+
const arg = () => {
|
|
13627
|
+
skipWs();
|
|
13628
|
+
if (s[i] === "{") {
|
|
13629
|
+
i++;
|
|
13630
|
+
const v = seq("}");
|
|
13631
|
+
i++;
|
|
13632
|
+
return v;
|
|
13633
|
+
}
|
|
13634
|
+
return atom();
|
|
13635
|
+
};
|
|
13636
|
+
const wrap = (v) => v.length > 1 && !/^[\w.′]+$|^\(.*\)$/u.test(v) ? `(${v})` : v;
|
|
13637
|
+
const script = (v, map, mark) => {
|
|
13638
|
+
const t = v.trim();
|
|
13639
|
+
return [...t].every((c) => map[c]) ? [...t].map((c) => map[c]).join("") : `${mark}${wrap(t)}`;
|
|
13640
|
+
};
|
|
13641
|
+
const atom = () => {
|
|
13642
|
+
const c = s[i];
|
|
13643
|
+
if (c === void 0) return "";
|
|
13644
|
+
if (c === "\\") {
|
|
13645
|
+
i++;
|
|
13646
|
+
let name = "";
|
|
13647
|
+
if (/[A-Za-z]/.test(s[i] ?? "")) while (/[A-Za-z]/.test(s[i] ?? "")) name += s[i++];
|
|
13648
|
+
else name = s[i++] ?? "";
|
|
13649
|
+
if (name === "frac") {
|
|
13650
|
+
const a = arg(), b = arg();
|
|
13651
|
+
return `${wrap(a.trim())}/${wrap(b.trim())}`;
|
|
13652
|
+
}
|
|
13653
|
+
if (name === "sqrt") {
|
|
13654
|
+
skipWs();
|
|
13655
|
+
let root = "";
|
|
13656
|
+
if (s[i] === "[") {
|
|
13657
|
+
i++;
|
|
13658
|
+
root = seq("]");
|
|
13659
|
+
i++;
|
|
13749
13660
|
}
|
|
13750
|
-
const
|
|
13751
|
-
|
|
13752
|
-
byPage.set(page, list);
|
|
13661
|
+
const a = arg();
|
|
13662
|
+
return `${root ? script(root, SUP, "") : ""}\u221A${wrap(a.trim())}`;
|
|
13753
13663
|
}
|
|
13664
|
+
if (name === "left" || name === "right" || name === "big" || name === "Big" || name === "bigg" || name === "Bigg") {
|
|
13665
|
+
skipWs();
|
|
13666
|
+
const d = s[i] === "\\" ? atom() : s[i++] ?? "";
|
|
13667
|
+
return d === "." ? "" : d;
|
|
13668
|
+
}
|
|
13669
|
+
if (name === "overline" || name === "bar" || name === "hat" || name === "vec" || name === "dot" || name === "tilde") {
|
|
13670
|
+
const a = arg().trim(), mark = { overline: "\u0305", bar: "\u0304", hat: "\u0302", vec: "\u20D7", dot: "\u0307", tilde: "\u0303" }[name];
|
|
13671
|
+
return [...a].map((ch) => ch + mark).join("");
|
|
13672
|
+
}
|
|
13673
|
+
if (name === "mathrm" || name === "text" || name === "rm" || name === "mathbf" || name === "it" || name === "mathit" || name === "operatorname") return name === "rm" || name === "it" ? "" : arg();
|
|
13674
|
+
return SYMBOLS[name] ?? name;
|
|
13754
13675
|
}
|
|
13755
|
-
|
|
13756
|
-
|
|
13757
|
-
|
|
13758
|
-
|
|
13759
|
-
|
|
13760
|
-
|
|
13761
|
-
|
|
13762
|
-
if (
|
|
13763
|
-
|
|
13764
|
-
|
|
13765
|
-
|
|
13766
|
-
|
|
13676
|
+
i++;
|
|
13677
|
+
if (c === "{") {
|
|
13678
|
+
const v = seq("}");
|
|
13679
|
+
i++;
|
|
13680
|
+
return v;
|
|
13681
|
+
}
|
|
13682
|
+
if (c === "^") return script(arg(), SUP, "^");
|
|
13683
|
+
if (c === "_") return script(arg(), SUB, "_");
|
|
13684
|
+
if (c === "~" || c === "`") return " ";
|
|
13685
|
+
return c;
|
|
13686
|
+
};
|
|
13687
|
+
const seq = (end) => {
|
|
13688
|
+
let out = "";
|
|
13689
|
+
while (i < s.length && s[i] !== end) {
|
|
13690
|
+
if (s[i] === " ") {
|
|
13691
|
+
i++;
|
|
13692
|
+
continue;
|
|
13693
|
+
}
|
|
13694
|
+
out += atom();
|
|
13767
13695
|
}
|
|
13696
|
+
return out;
|
|
13697
|
+
};
|
|
13698
|
+
return seq("\0").replace(/\s+/g, " ").trim();
|
|
13699
|
+
}
|
|
13700
|
+
|
|
13701
|
+
// src/hwpx/equation.ts
|
|
13702
|
+
var CONVERT_MAP = {
|
|
13703
|
+
TIMES: "\\times",
|
|
13704
|
+
times: "\\times",
|
|
13705
|
+
LEFT: "\\left",
|
|
13706
|
+
RIGHT: "\\right",
|
|
13707
|
+
under: "\\underline",
|
|
13708
|
+
SMALLSUM: "\\sum",
|
|
13709
|
+
sum: "\\sum",
|
|
13710
|
+
SMALLPROD: "\\prod",
|
|
13711
|
+
prod: "\\prod",
|
|
13712
|
+
SMALLINTER: "\\cap",
|
|
13713
|
+
CUP: "\\cup",
|
|
13714
|
+
OPLUS: "\\oplus",
|
|
13715
|
+
OMINUS: "\\ominus",
|
|
13716
|
+
OTIMES: "\\otimes",
|
|
13717
|
+
ODIV: "\\oslash",
|
|
13718
|
+
ODOT: "\\odot",
|
|
13719
|
+
LOR: "\\lor",
|
|
13720
|
+
LAND: "\\land",
|
|
13721
|
+
SUBSET: "\\subset",
|
|
13722
|
+
SUPERSET: "\\supset",
|
|
13723
|
+
SUBSETEQ: "\\subseteq",
|
|
13724
|
+
SUPSETEQ: "\\supseteq",
|
|
13725
|
+
IN: "\\in",
|
|
13726
|
+
OWNS: "\\owns",
|
|
13727
|
+
NOTIN: "\\notin",
|
|
13728
|
+
LEQ: "\\leq",
|
|
13729
|
+
GEQ: "\\geq",
|
|
13730
|
+
"<<": "\\ll",
|
|
13731
|
+
">>": "\\gg",
|
|
13732
|
+
"<<<": "\\lll",
|
|
13733
|
+
">>>": "\\ggg",
|
|
13734
|
+
PREC: "\\prec",
|
|
13735
|
+
SUCC: "\\succ",
|
|
13736
|
+
UPLUS: "\\uplus",
|
|
13737
|
+
"\xB1": "\\pm",
|
|
13738
|
+
"+-": "\\pm",
|
|
13739
|
+
"-+": "\\mp",
|
|
13740
|
+
"\xF7": "\\div",
|
|
13741
|
+
cdot: "\\cdot",
|
|
13742
|
+
CIRC: "\\circ",
|
|
13743
|
+
BULLET: "\\bullet",
|
|
13744
|
+
DEG: " ^\\circ",
|
|
13745
|
+
AST: "\\ast",
|
|
13746
|
+
STAR: "\\bigstar",
|
|
13747
|
+
BIGCIRC: "\\bigcirc",
|
|
13748
|
+
EMPTYSET: "\\emptyset",
|
|
13749
|
+
THEREFORE: "\\therefore",
|
|
13750
|
+
BECAUSE: "\\because",
|
|
13751
|
+
EXIST: "\\exists",
|
|
13752
|
+
// 한글 수식 편집기는 소문자 therefore·because 도 같은 기호로 그린다(#148) — 생성 쪽 정준형은 대문자(equation-generate COMMAND_MAP)
|
|
13753
|
+
therefore: "\\therefore",
|
|
13754
|
+
because: "\\because",
|
|
13755
|
+
"!=": "\\neq",
|
|
13756
|
+
SMCOPROD: "\\coprod",
|
|
13757
|
+
coprod: "\\coprod",
|
|
13758
|
+
SQCAP: "\\sqcap",
|
|
13759
|
+
SQCUP: "\\sqcup",
|
|
13760
|
+
SQSUBSET: "\\sqsubset",
|
|
13761
|
+
SQSUBSETEQ: "\\sqsubseteq",
|
|
13762
|
+
BIGSQCUP: "\\bigsqcup",
|
|
13763
|
+
BIGOPLUS: "\\bigoplus",
|
|
13764
|
+
BIGOTIMES: "\\bigotimes",
|
|
13765
|
+
BIGODOT: "\\bigodot",
|
|
13766
|
+
BIGUPLUS: "\\biguplus",
|
|
13767
|
+
inter: "\\bigcap",
|
|
13768
|
+
union: "\\bigcup",
|
|
13769
|
+
BIGOMINUS: "{\\Large\\ominus}",
|
|
13770
|
+
BIGODIV: "{\\Large\\oslash}",
|
|
13771
|
+
UNDEROVER: "",
|
|
13772
|
+
SIM: "\\sim",
|
|
13773
|
+
APPROX: "\\approx",
|
|
13774
|
+
SIMEQ: "\\simeq",
|
|
13775
|
+
CONG: "\\cong",
|
|
13776
|
+
"==": "\\equiv",
|
|
13777
|
+
DIAMOND: "\\diamond",
|
|
13778
|
+
FORALL: "\\forall",
|
|
13779
|
+
prime: "'",
|
|
13780
|
+
Partial: "\\partial",
|
|
13781
|
+
INF: "\\infty",
|
|
13782
|
+
PROPTO: "\\propto",
|
|
13783
|
+
lim: "\\lim",
|
|
13784
|
+
Lim: "\\lim",
|
|
13785
|
+
larrow: "\\leftarrow",
|
|
13786
|
+
"->": "\\rightarrow",
|
|
13787
|
+
uparrow: "\\uparrow",
|
|
13788
|
+
downarrow: "\\downarrow",
|
|
13789
|
+
LARROW: "\\Leftarrow",
|
|
13790
|
+
RARROW: "\\Rightarrow",
|
|
13791
|
+
UPARROW: "\\Uparrow",
|
|
13792
|
+
DOWNARROW: "\\Downarrow",
|
|
13793
|
+
udarrow: "\\updownarrow",
|
|
13794
|
+
"<->": "\\leftrightarrow",
|
|
13795
|
+
UDARROW: "\\Updownarrow",
|
|
13796
|
+
LRARROW: "\\Leftrightarrow",
|
|
13797
|
+
NWARROW: "\\nwarrow",
|
|
13798
|
+
SEARROW: "\\searrow",
|
|
13799
|
+
NEARROW: "\\nearrow",
|
|
13800
|
+
SWARROW: "\\swarrow",
|
|
13801
|
+
HOOKLEFT: "\\hookleftarrow",
|
|
13802
|
+
HOOKRIGHT: "\\hookrightarrow",
|
|
13803
|
+
PVER: "\\|",
|
|
13804
|
+
MAPSTO: "\\mapsto",
|
|
13805
|
+
CDOTS: "\\cdots",
|
|
13806
|
+
LDOTS: "\\ldots",
|
|
13807
|
+
VDOTS: "\\vdots",
|
|
13808
|
+
DDOTS: "\\ddots",
|
|
13809
|
+
DAGGER: "\\dagger",
|
|
13810
|
+
DDAGGER: "\\ddagger",
|
|
13811
|
+
DOTEQ: "\\doteq",
|
|
13812
|
+
image: "\\fallingdotseq",
|
|
13813
|
+
REIMAGE: "\\risingdotseq",
|
|
13814
|
+
ASYMP: "\\asymp",
|
|
13815
|
+
ISO: "\\Bumpeq",
|
|
13816
|
+
DSUM: "\\dotplus",
|
|
13817
|
+
XOR: "\\veebar",
|
|
13818
|
+
TRIANGLE: "\\triangle",
|
|
13819
|
+
NABLA: "\\nabla",
|
|
13820
|
+
ANGLE: "\\angle",
|
|
13821
|
+
MSANGLE: "\\measuredangle",
|
|
13822
|
+
SANGLE: "\\sphericalangle",
|
|
13823
|
+
VDASH: "\\vdash",
|
|
13824
|
+
DASHV: "\\dashv",
|
|
13825
|
+
BOT: "\\bot",
|
|
13826
|
+
TOP: "\\top",
|
|
13827
|
+
MODELS: "\\models",
|
|
13828
|
+
LAPLACE: "\\mathcal{L}",
|
|
13829
|
+
CENTIGRADE: "^{\\circ}C",
|
|
13830
|
+
FAHRENHEIT: "^{\\circ}F",
|
|
13831
|
+
LSLANT: "\\diagup",
|
|
13832
|
+
RSLANT: "\\diagdown",
|
|
13833
|
+
sqrt: "\\sqrt",
|
|
13834
|
+
int: "\\int",
|
|
13835
|
+
dint: "\\iint",
|
|
13836
|
+
tint: "\\iiint",
|
|
13837
|
+
oint: "\\oint",
|
|
13838
|
+
alpha: "\\alpha",
|
|
13839
|
+
beta: "\\beta",
|
|
13840
|
+
gamma: "\\gamma",
|
|
13841
|
+
delta: "\\delta",
|
|
13842
|
+
epsilon: "\\epsilon",
|
|
13843
|
+
zeta: "\\zeta",
|
|
13844
|
+
eta: "\\eta",
|
|
13845
|
+
theta: "\\theta",
|
|
13846
|
+
iota: "\\iota",
|
|
13847
|
+
kappa: "\\kappa",
|
|
13848
|
+
lambda: "\\lambda",
|
|
13849
|
+
mu: "\\mu",
|
|
13850
|
+
nu: "\\nu",
|
|
13851
|
+
xi: "\\xi",
|
|
13852
|
+
omicron: "\\omicron",
|
|
13853
|
+
pi: "\\pi",
|
|
13854
|
+
rho: "\\rho",
|
|
13855
|
+
sigma: "\\sigma",
|
|
13856
|
+
tau: "\\tau",
|
|
13857
|
+
upsilon: "\\upsilon",
|
|
13858
|
+
phi: "\\phi",
|
|
13859
|
+
chi: "\\chi",
|
|
13860
|
+
psi: "\\psi",
|
|
13861
|
+
omega: "\\omega",
|
|
13862
|
+
ALPHA: "A",
|
|
13863
|
+
BETA: "B",
|
|
13864
|
+
GAMMA: "\\Gamma",
|
|
13865
|
+
DELTA: "\\Delta",
|
|
13866
|
+
EPSILON: "E",
|
|
13867
|
+
ZETA: "Z",
|
|
13868
|
+
ETA: "H",
|
|
13869
|
+
THETA: "\\Theta",
|
|
13870
|
+
IOTA: "I",
|
|
13871
|
+
KAPPA: "K",
|
|
13872
|
+
LAMBDA: "\\Lambda",
|
|
13873
|
+
MU: "M",
|
|
13874
|
+
NU: "N",
|
|
13875
|
+
XI: "\\Xi",
|
|
13876
|
+
OMICRON: "O",
|
|
13877
|
+
PI: "\\Pi",
|
|
13878
|
+
RHO: "P",
|
|
13879
|
+
SIGMA: "\\Sigma",
|
|
13880
|
+
TAU: "T",
|
|
13881
|
+
UPSILON: "\\Upsilon",
|
|
13882
|
+
PHI: "\\Phi",
|
|
13883
|
+
CHI: "X",
|
|
13884
|
+
PSI: "\\Psi",
|
|
13885
|
+
OMEGA: "\\Omega",
|
|
13886
|
+
"\u2308": "\\lceil",
|
|
13887
|
+
"\u2309": "\\rceil",
|
|
13888
|
+
"\u230A": "\\lfloor",
|
|
13889
|
+
"\u230B": "\\rfloor",
|
|
13890
|
+
"\u2225": "\\|",
|
|
13891
|
+
"\u2290": "\\sqsupset",
|
|
13892
|
+
"\u2292": "\\sqsupseteq",
|
|
13893
|
+
odint: "\\mathop \u222F",
|
|
13894
|
+
otint: "\\mathop \u2230",
|
|
13895
|
+
BIGSQCAP: "\\mathop \u2A05",
|
|
13896
|
+
ATT: "\\mathop \u203B",
|
|
13897
|
+
HUND: "\\mathop \u2030",
|
|
13898
|
+
THOU: "\\mathop \u2031",
|
|
13899
|
+
IDENTICAL: "\\mathop \u2237",
|
|
13900
|
+
RTANGLE: "\\mathop \u22BE",
|
|
13901
|
+
BASE: "\\mathop \u2302",
|
|
13902
|
+
BENZENE: "\\mathop \u232C"
|
|
13903
|
+
};
|
|
13904
|
+
var MIDDLE_CONVERT_MAP = {
|
|
13905
|
+
matrix: "HULKMATRIX",
|
|
13906
|
+
pmatrix: "HULKPMATRIX",
|
|
13907
|
+
bmatrix: "HULKBMATRIX",
|
|
13908
|
+
dmatrix: "HULKDMATRIX",
|
|
13909
|
+
eqalign: "HULKEQALIGN",
|
|
13910
|
+
cases: "HULKCASE",
|
|
13911
|
+
vec: "HULKVEC",
|
|
13912
|
+
dyad: "HULKDYAD",
|
|
13913
|
+
acute: "HULKACUTE",
|
|
13914
|
+
grave: "HULKGRAVE",
|
|
13915
|
+
dot: "HULKDOT",
|
|
13916
|
+
ddot: "HULKDDOT",
|
|
13917
|
+
bar: "HULKBAR",
|
|
13918
|
+
hat: "HULKHAT",
|
|
13919
|
+
check: "HULKCHECK",
|
|
13920
|
+
arch: "HULKARCH",
|
|
13921
|
+
tilde: "HULKTILDE",
|
|
13922
|
+
BOX: "HULKBOX",
|
|
13923
|
+
OVERBRACE: "HULKOVERBRACE",
|
|
13924
|
+
UNDERBRACE: "HULKUNDERBRACE"
|
|
13925
|
+
};
|
|
13926
|
+
var BAR_CONVERT_MAP = {
|
|
13927
|
+
HULKVEC: "\\overrightarrow",
|
|
13928
|
+
HULKDYAD: "\\overleftrightarrow",
|
|
13929
|
+
HULKACUTE: "\\acute",
|
|
13930
|
+
HULKGRAVE: "\\grave",
|
|
13931
|
+
HULKDOT: "\\dot",
|
|
13932
|
+
HULKDDOT: "\\ddot",
|
|
13933
|
+
HULKBAR: "\\overline",
|
|
13934
|
+
HULKHAT: "\\widehat",
|
|
13935
|
+
HULKCHECK: "\\check",
|
|
13936
|
+
HULKARCH: "\\overset{\\frown}",
|
|
13937
|
+
HULKTILDE: "\\widetilde",
|
|
13938
|
+
HULKBOX: "\\boxed"
|
|
13939
|
+
};
|
|
13940
|
+
var MATRIX_CONVERT_MAP = {
|
|
13941
|
+
HULKMATRIX: { begin: "\\begin{matrix}", end: "\\end{matrix}", removeOutterBrackets: true },
|
|
13942
|
+
HULKPMATRIX: { begin: "\\begin{pmatrix}", end: "\\end{pmatrix}", removeOutterBrackets: true },
|
|
13943
|
+
HULKBMATRIX: { begin: "\\begin{bmatrix}", end: "\\end{bmatrix}", removeOutterBrackets: true },
|
|
13944
|
+
HULKDMATRIX: { begin: "\\begin{vmatrix}", end: "\\end{vmatrix}", removeOutterBrackets: true },
|
|
13945
|
+
HULKCASE: { begin: "\\begin{cases}", end: "\\end{cases}", removeOutterBrackets: true },
|
|
13946
|
+
HULKEQALIGN: { begin: "\\eqalign{", end: "}", removeOutterBrackets: false }
|
|
13947
|
+
};
|
|
13948
|
+
var BRACE_CONVERT_MAP = {
|
|
13949
|
+
HULKOVERBRACE: "\\overbrace",
|
|
13950
|
+
HULKUNDERBRACE: "\\underbrace"
|
|
13951
|
+
};
|
|
13952
|
+
function findBrackets(eqString, startIdx) {
|
|
13953
|
+
const startCur = eqString.indexOf("{", startIdx);
|
|
13954
|
+
if (startCur === -1) throw new Error("cannot find bracket");
|
|
13955
|
+
let bracketCount = 1;
|
|
13956
|
+
for (let i = startCur + 1; i < eqString.length; i++) {
|
|
13957
|
+
const ch = eqString[i];
|
|
13958
|
+
if (ch === "{") bracketCount += 1;
|
|
13959
|
+
else if (ch === "}") bracketCount -= 1;
|
|
13960
|
+
if (bracketCount === 0) return [startCur, i + 1];
|
|
13768
13961
|
}
|
|
13769
|
-
|
|
13962
|
+
throw new Error("cannot find bracket");
|
|
13770
13963
|
}
|
|
13771
|
-
function
|
|
13772
|
-
|
|
13773
|
-
let
|
|
13774
|
-
|
|
13775
|
-
|
|
13776
|
-
|
|
13777
|
-
|
|
13778
|
-
|
|
13779
|
-
|
|
13780
|
-
|
|
13781
|
-
endColPr = findChildByLocalName(ctrl, "colPr") ?? endColPr;
|
|
13782
|
-
const en = findChildByLocalName(ctrl, "endNote");
|
|
13783
|
-
const sub = en && !isDeletedControl(en) ? findChildByLocalName(en, "subList") : null;
|
|
13784
|
-
if (sub) notes.push(sub);
|
|
13964
|
+
function findEnclosingBrackets(eqString, startIdx) {
|
|
13965
|
+
let depth = 0;
|
|
13966
|
+
for (let idx = startIdx - 1; idx >= 0; idx--) {
|
|
13967
|
+
const ch = eqString[idx];
|
|
13968
|
+
if (ch === "}") {
|
|
13969
|
+
depth += 1;
|
|
13970
|
+
} else if (ch === "{") {
|
|
13971
|
+
if (depth > 0) {
|
|
13972
|
+
depth -= 1;
|
|
13973
|
+
continue;
|
|
13785
13974
|
}
|
|
13786
|
-
|
|
13787
|
-
|
|
13788
|
-
|
|
13789
|
-
|
|
13790
|
-
|
|
13791
|
-
const above = num(sp, "aboveLine", 0), below = num(sp, "belowLine", 567), between = num(sp, "betweenNotes", 283);
|
|
13792
|
-
const colPr = endColPr ?? findFirst(root, "colPr"), nCol = Math.max(1, num(colPr, "colCount", 1)), gap = nCol > 1 ? num(colPr, "sameGap", 0) : 0;
|
|
13793
|
-
const colW = (geom.BODY_W - gap * (nCol - 1)) / nCol;
|
|
13794
|
-
let page = last.page;
|
|
13795
|
-
let col = nCol > 1 ? Math.min(nCol - 1, Math.max(0, Math.round(num(last.seg, "horzpos") / (colW + gap)))) : 0;
|
|
13796
|
-
let y = num(last.seg, "vertpos") + num(last.seg, "vertsize") + above;
|
|
13797
|
-
const rules = [];
|
|
13798
|
-
const lenAttr = num(line, "length", -1), widthMm = Number.parseFloat(line?.getAttribute("width") ?? "0.12") || 0.12;
|
|
13799
|
-
if ((line?.getAttribute("type") ?? "SOLID") !== "NONE") rules.push({ page, x: geom.ML + col * (colW + gap), y: geom.MT + y, length: lenAttr > 0 ? lenAttr : 14173, widthMm, color: line?.getAttribute("color") ?? "#000000" });
|
|
13800
|
-
y += below;
|
|
13801
|
-
const next = () => {
|
|
13802
|
-
if (++col >= nCol) {
|
|
13803
|
-
col = 0;
|
|
13804
|
-
page++;
|
|
13805
|
-
}
|
|
13806
|
-
y = 0;
|
|
13807
|
-
};
|
|
13808
|
-
const out = [];
|
|
13809
|
-
notes.forEach((sub, ni) => {
|
|
13810
|
-
if (ni > 0) y += between;
|
|
13811
|
-
let base = y;
|
|
13812
|
-
let prevRaw = Number.NEGATIVE_INFINITY, flowEnd = y;
|
|
13813
|
-
for (const q of elements(sub)) if (ln(q) === "p") {
|
|
13814
|
-
const lsa = findChildByLocalName(q, "linesegarray"), segs = lsa ? elements(lsa).filter((e) => ln(e) === "lineseg") : [];
|
|
13815
|
-
const pages = [];
|
|
13816
|
-
for (const seg of segs) {
|
|
13817
|
-
const raw = num(seg, "vertpos");
|
|
13818
|
-
if (raw < prevRaw) base = flowEnd - raw;
|
|
13819
|
-
prevRaw = raw;
|
|
13820
|
-
let v = base + raw;
|
|
13821
|
-
const vs = num(seg, "vertsize");
|
|
13822
|
-
if (v + vs > geom.BODY_H && v > 0) {
|
|
13823
|
-
const shift = v;
|
|
13824
|
-
next();
|
|
13825
|
-
base -= shift;
|
|
13826
|
-
v = 0;
|
|
13827
|
-
}
|
|
13828
|
-
seg.setAttribute("vertpos", String(v));
|
|
13829
|
-
seg.setAttribute("horzpos", String(num(seg, "horzpos") + col * (colW + gap)));
|
|
13830
|
-
pages.push(page);
|
|
13831
|
-
y = v + vs;
|
|
13832
|
-
flowEnd = y + num(seg, "spacing");
|
|
13975
|
+
try {
|
|
13976
|
+
const [start, end] = findBrackets(eqString, idx);
|
|
13977
|
+
if (start === idx && end > startIdx) return [start, end];
|
|
13978
|
+
} catch {
|
|
13979
|
+
return null;
|
|
13833
13980
|
}
|
|
13834
|
-
|
|
13981
|
+
return null;
|
|
13835
13982
|
}
|
|
13836
|
-
}
|
|
13837
|
-
return
|
|
13983
|
+
}
|
|
13984
|
+
return null;
|
|
13838
13985
|
}
|
|
13839
|
-
|
|
13840
|
-
|
|
13841
|
-
|
|
13842
|
-
|
|
13843
|
-
|
|
13844
|
-
|
|
13845
|
-
|
|
13846
|
-
|
|
13847
|
-
|
|
13848
|
-
const wrap = o.getAttribute("textWrap") ?? "TOP_AND_BOTTOM";
|
|
13849
|
-
if (wrap !== "SQUARE" && wrap !== "TOP_AND_BOTTOM") continue;
|
|
13850
|
-
const om = findChildByLocalName(o, "outMargin"), raw = num(pos, "vertOffset");
|
|
13851
|
-
out.push({ el: o, vo: Math.max(0, raw >= 2 ** 31 ? raw - 2 ** 32 : raw), h: num(findChildByLocalName(o, "sz"), "height") + num(om, "top") + num(om, "bottom"), omT: num(om, "top") });
|
|
13852
|
-
}
|
|
13986
|
+
function maskLiteralSpans(eqString) {
|
|
13987
|
+
return eqString.replace(/"[^"]*"/g, (m) => "\uFFFF".repeat(m.length)).replace(/\\text\{[^}]*\}/g, (m) => "\uFFFF".repeat(m.length));
|
|
13988
|
+
}
|
|
13989
|
+
function findKeywordToken(eqString, word, from = 0) {
|
|
13990
|
+
const masked = maskLiteralSpans(eqString);
|
|
13991
|
+
for (let i = masked.indexOf(word, from); i !== -1; i = masked.indexOf(word, i + 1)) {
|
|
13992
|
+
const okL = i === 0 || /\s/.test(masked[i - 1]);
|
|
13993
|
+
const okR = i + word.length === masked.length || /\s/.test(masked[i + word.length]);
|
|
13994
|
+
if (okL && okR) return i;
|
|
13853
13995
|
}
|
|
13854
|
-
return
|
|
13996
|
+
return -1;
|
|
13855
13997
|
}
|
|
13856
|
-
function
|
|
13998
|
+
function replaceFrac(eqString) {
|
|
13999
|
+
const hmlFrac = "over";
|
|
14000
|
+
const masked = maskLiteralSpans(eqString);
|
|
13857
14001
|
const out = [];
|
|
13858
|
-
let
|
|
13859
|
-
|
|
13860
|
-
|
|
13861
|
-
const
|
|
13862
|
-
|
|
13863
|
-
|
|
13864
|
-
|
|
13865
|
-
|
|
13866
|
-
|
|
14002
|
+
let pos = 0;
|
|
14003
|
+
for (let cursor = masked.indexOf(hmlFrac); cursor !== -1; cursor = masked.indexOf(hmlFrac, cursor + 1)) {
|
|
14004
|
+
const okL = cursor === 0 || /\s/.test(masked[cursor - 1]);
|
|
14005
|
+
const okR = cursor + hmlFrac.length === masked.length || /\s/.test(masked[cursor + hmlFrac.length]);
|
|
14006
|
+
if (!okL || !okR) continue;
|
|
14007
|
+
for (; pos < cursor; pos++) out.push(eqString[pos]);
|
|
14008
|
+
let end = out.length;
|
|
14009
|
+
while (end > 0 && /\s/.test(out[end - 1])) end--;
|
|
14010
|
+
let numStart = end;
|
|
14011
|
+
if (end > 0 && out[end - 1] === "}") {
|
|
14012
|
+
let depth = 0;
|
|
14013
|
+
for (numStart = end - 1; numStart >= 0; numStart--) {
|
|
14014
|
+
if (out[numStart] === "}") depth++;
|
|
14015
|
+
else if (out[numStart] === "{" && --depth === 0) break;
|
|
13867
14016
|
}
|
|
13868
|
-
|
|
13869
|
-
|
|
13870
|
-
|
|
13871
|
-
|
|
14017
|
+
if (numStart < 0) break;
|
|
14018
|
+
out.length = end;
|
|
14019
|
+
out.splice(numStart, 0, "\\frac");
|
|
14020
|
+
} else {
|
|
14021
|
+
while (numStart > 0 && !/\s/.test(out[numStart - 1])) numStart--;
|
|
14022
|
+
if (numStart === end) break;
|
|
14023
|
+
out.length = end;
|
|
14024
|
+
out.splice(numStart, 0, "\\frac", "{");
|
|
14025
|
+
out.push("}");
|
|
13872
14026
|
}
|
|
14027
|
+
pos = cursor + hmlFrac.length;
|
|
13873
14028
|
}
|
|
13874
|
-
return out;
|
|
13875
|
-
}
|
|
13876
|
-
function cellLines(c) {
|
|
13877
|
-
return cellLineBoxes(c).map((b) => [b.top, b.bottom]);
|
|
14029
|
+
return out.join("") + eqString.slice(pos);
|
|
13878
14030
|
}
|
|
13879
|
-
function
|
|
13880
|
-
|
|
13881
|
-
|
|
13882
|
-
|
|
13883
|
-
|
|
13884
|
-
|
|
13885
|
-
|
|
13886
|
-
|
|
13887
|
-
|
|
13888
|
-
|
|
13889
|
-
|
|
13890
|
-
|
|
13891
|
-
|
|
13892
|
-
|
|
13893
|
-
|
|
13894
|
-
const declared = num(findChildByLocalName(tbl, "sz"), "height") || rowY[nRows];
|
|
13895
|
-
if (ty - MT < 2e3 || ty + declared <= pageBottom + slack) return plain();
|
|
13896
|
-
return rowH.map((h, r) => [{ page: 1, y: MT + rowY[r], h }]);
|
|
14031
|
+
function replaceRootOf(eqString) {
|
|
14032
|
+
while (true) {
|
|
14033
|
+
const rootCursor = findKeywordToken(eqString, "root");
|
|
14034
|
+
if (rootCursor === -1) break;
|
|
14035
|
+
try {
|
|
14036
|
+
const elem1 = findBrackets(eqString, rootCursor);
|
|
14037
|
+
const ofCursor = findKeywordToken(eqString, "of", elem1[1]);
|
|
14038
|
+
if (ofCursor === -1) return eqString;
|
|
14039
|
+
const elem2 = findBrackets(eqString, ofCursor);
|
|
14040
|
+
const e1 = eqString.slice(elem1[0] + 1, elem1[1] - 1);
|
|
14041
|
+
const e2 = eqString.slice(elem2[0] + 1, elem2[1] - 1);
|
|
14042
|
+
eqString = eqString.slice(0, rootCursor) + "\\sqrt[" + e1 + "]{" + e2 + "}" + eqString.slice(elem2[1] + 1);
|
|
14043
|
+
} catch {
|
|
14044
|
+
return eqString;
|
|
14045
|
+
}
|
|
13897
14046
|
}
|
|
13898
|
-
|
|
13899
|
-
|
|
13900
|
-
|
|
13901
|
-
const
|
|
13902
|
-
|
|
13903
|
-
|
|
13904
|
-
|
|
13905
|
-
|
|
13906
|
-
|
|
13907
|
-
|
|
13908
|
-
|
|
13909
|
-
|
|
13910
|
-
|
|
13911
|
-
|
|
13912
|
-
|
|
13913
|
-
|
|
13914
|
-
|
|
13915
|
-
|
|
13916
|
-
|
|
13917
|
-
if (
|
|
13918
|
-
|
|
13919
|
-
|
|
13920
|
-
|
|
13921
|
-
|
|
13922
|
-
|
|
13923
|
-
|
|
14047
|
+
return eqString;
|
|
14048
|
+
}
|
|
14049
|
+
function replaceAllMatrix(eqString) {
|
|
14050
|
+
const replaceElements = (bracketStr) => {
|
|
14051
|
+
let inner = bracketStr.slice(1, -1);
|
|
14052
|
+
inner = inner.replace(/#/g, " \\\\ ");
|
|
14053
|
+
inner = inner.replace(/&/g, "&");
|
|
14054
|
+
return inner;
|
|
14055
|
+
};
|
|
14056
|
+
const replaceMatrix = (input, matStr, matElem) => {
|
|
14057
|
+
while (true) {
|
|
14058
|
+
const cursor = input.indexOf(matStr);
|
|
14059
|
+
if (cursor === -1) break;
|
|
14060
|
+
try {
|
|
14061
|
+
const [eStart, eEnd] = findBrackets(input, cursor);
|
|
14062
|
+
const elem = replaceElements(input.slice(eStart, eEnd));
|
|
14063
|
+
let beforeMat;
|
|
14064
|
+
let afterMat;
|
|
14065
|
+
const outer = matElem.removeOutterBrackets ? findEnclosingBrackets(input, cursor) : null;
|
|
14066
|
+
if (outer && outer[1] >= eEnd) {
|
|
14067
|
+
const [bStart, bEnd] = outer;
|
|
14068
|
+
beforeMat = input.slice(0, bStart);
|
|
14069
|
+
afterMat = input.slice(bEnd);
|
|
14070
|
+
} else {
|
|
14071
|
+
beforeMat = input.slice(0, cursor);
|
|
14072
|
+
afterMat = input.slice(eEnd);
|
|
13924
14073
|
}
|
|
13925
|
-
|
|
13926
|
-
|
|
13927
|
-
|
|
13928
|
-
}
|
|
13929
|
-
if (pcs.length) {
|
|
13930
|
-
pcs.push({ page, y: top, h: bottom - top + c.marginB, range: /* @__PURE__ */ new Map([[c.el, [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]]]), place });
|
|
13931
|
-
out.push(pcs);
|
|
13932
|
-
y = bottom + c.marginB;
|
|
13933
|
-
first = false;
|
|
13934
|
-
continue;
|
|
14074
|
+
input = beforeMat + matElem.begin + elem + matElem.end + afterMat;
|
|
14075
|
+
} catch {
|
|
14076
|
+
return input;
|
|
13935
14077
|
}
|
|
13936
14078
|
}
|
|
13937
|
-
|
|
13938
|
-
|
|
13939
|
-
|
|
13940
|
-
|
|
13941
|
-
|
|
13942
|
-
|
|
13943
|
-
|
|
13944
|
-
|
|
13945
|
-
|
|
13946
|
-
|
|
13947
|
-
|
|
13948
|
-
|
|
13949
|
-
|
|
13950
|
-
|
|
13951
|
-
|
|
13952
|
-
|
|
13953
|
-
|
|
13954
|
-
|
|
13955
|
-
|
|
13956
|
-
|
|
13957
|
-
|
|
13958
|
-
|
|
13959
|
-
}
|
|
13960
|
-
}
|
|
13961
|
-
const range = /* @__PURE__ */ new Map();
|
|
13962
|
-
let ext = 0, toNext = 0;
|
|
13963
|
-
for (const c of rowCells) {
|
|
13964
|
-
const bs = boxes.get(c.el) ?? [];
|
|
13965
|
-
const inK = bs.filter((b) => b.part === k), next = bs.find((b) => b.part > k);
|
|
13966
|
-
const from = inK[0]?.origin ?? next?.origin ?? Number.POSITIVE_INFINITY;
|
|
13967
|
-
range.set(c.el, [from, next?.top ?? Number.POSITIVE_INFINITY]);
|
|
13968
|
-
if (inK.length) ext = Math.max(ext, inK[inK.length - 1].bottom - from + c.marginT + c.marginB);
|
|
13969
|
-
if (inK.length && next) toNext = Math.max(toNext, next.top - from + c.marginT + c.marginB);
|
|
13970
|
-
}
|
|
13971
|
-
const last = k === hParts;
|
|
13972
|
-
const firstH = declared > 0 && ty + declared - y >= ext ? Math.min(pageBottom - y, ty + declared - y) : pageBottom - y;
|
|
13973
|
-
const ph = last ? ext : k === 0 ? firstH : toNext > 0 ? Math.min(pageBottom - contTop, toNext) : pageBottom - contTop;
|
|
13974
|
-
pieces.push({ page, y, h: ph, range });
|
|
13975
|
-
if (!last) {
|
|
13976
|
-
let span = 0, spanEnd = 0;
|
|
13977
|
-
if (floatSpan) for (const c of rowCells) {
|
|
13978
|
-
const bs = (boxes.get(c.el) ?? []).filter((b) => b.part === k), from = bs[0]?.origin ?? 0;
|
|
13979
|
-
for (const b of bs) {
|
|
13980
|
-
if (led.has(b.seg)) continue;
|
|
13981
|
-
const f = floatSpan(b.seg, y + c.marginT + b.top - from);
|
|
13982
|
-
if (f && f.pages > span) {
|
|
13983
|
-
span = f.pages;
|
|
13984
|
-
spanEnd = f.endY;
|
|
13985
|
-
}
|
|
13986
|
-
}
|
|
13987
|
-
}
|
|
13988
|
-
if (span > 0) {
|
|
13989
|
-
const nextTop = Math.min(...rowCells.map((c) => {
|
|
13990
|
-
const b = (boxes.get(c.el) ?? []).find((x) => x.part === k + 1);
|
|
13991
|
-
return b ? contTop + c.marginT + b.top - b.origin : Number.POSITIVE_INFINITY;
|
|
13992
|
-
}));
|
|
13993
|
-
const skip = nextTop < spanEnd - 100 ? span + 1 : span;
|
|
13994
|
-
for (let e = 1; e < skip; e++) pieces.push({ page: page + e, y: contTop, h: pageBottom - contTop, range: new Map(rowCells.map((c) => [c.el, [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]])) });
|
|
13995
|
-
page += skip;
|
|
13996
|
-
} else page++;
|
|
13997
|
-
y = contTop;
|
|
13998
|
-
first = true;
|
|
13999
|
-
} else h = ph;
|
|
14079
|
+
return input;
|
|
14080
|
+
};
|
|
14081
|
+
for (const [matKey, matElem] of Object.entries(MATRIX_CONVERT_MAP)) {
|
|
14082
|
+
eqString = replaceMatrix(eqString, matKey, matElem);
|
|
14083
|
+
}
|
|
14084
|
+
return eqString;
|
|
14085
|
+
}
|
|
14086
|
+
function replaceAllBar(eqString) {
|
|
14087
|
+
const replaceBar = (input, barStr, barElem) => {
|
|
14088
|
+
while (true) {
|
|
14089
|
+
const cursor = input.indexOf(barStr);
|
|
14090
|
+
if (cursor === -1) break;
|
|
14091
|
+
try {
|
|
14092
|
+
const [eStart, eEnd] = findBrackets(input, cursor);
|
|
14093
|
+
const elem = input.slice(eStart, eEnd);
|
|
14094
|
+
const outer = findEnclosingBrackets(input, cursor);
|
|
14095
|
+
const [replaceStart, replaceEnd] = outer && outer[1] >= eEnd ? outer : [cursor, eEnd];
|
|
14096
|
+
const beforeBar = input.slice(0, replaceStart);
|
|
14097
|
+
const afterBar = input.slice(replaceEnd);
|
|
14098
|
+
input = beforeBar + barElem + elem + afterBar;
|
|
14099
|
+
} catch {
|
|
14100
|
+
return input;
|
|
14000
14101
|
}
|
|
14001
|
-
out.push(pieces);
|
|
14002
|
-
y += h;
|
|
14003
|
-
first = false;
|
|
14004
|
-
continue;
|
|
14005
14102
|
}
|
|
14006
|
-
|
|
14007
|
-
|
|
14008
|
-
|
|
14009
|
-
|
|
14010
|
-
|
|
14011
|
-
|
|
14012
|
-
|
|
14013
|
-
|
|
14014
|
-
|
|
14015
|
-
|
|
14016
|
-
|
|
14017
|
-
|
|
14018
|
-
|
|
14019
|
-
|
|
14020
|
-
|
|
14021
|
-
|
|
14022
|
-
|
|
14023
|
-
|
|
14024
|
-
|
|
14025
|
-
|
|
14026
|
-
|
|
14027
|
-
|
|
14028
|
-
else if (off === 0) blocked = true;
|
|
14029
|
-
cuts.push([c.el, off, ls[k][0]]);
|
|
14030
|
-
rem = Math.max(rem, end - ls[k][0] + c.marginT + c.marginB);
|
|
14031
|
-
}
|
|
14032
|
-
if (allFit) {
|
|
14033
|
-
if (!first && h <= pageBottom - contTop && rowCells.some((c) => cellContentExtent(c) + c.marginT + c.marginB > avail)) {
|
|
14034
|
-
page++;
|
|
14035
|
-
y = contTop;
|
|
14036
|
-
first = true;
|
|
14037
|
-
break;
|
|
14038
|
-
}
|
|
14039
|
-
if (nested && avail > 0) {
|
|
14040
|
-
pieces.push({ page, y, h: avail, range: new Map(rowCells.map((c) => [c.el, [from.get(c.el) ?? 0, Number.POSITIVE_INFINITY]])) });
|
|
14041
|
-
for (const c of rowCells) from.set(c.el, Number.POSITIVE_INFINITY);
|
|
14042
|
-
page++;
|
|
14043
|
-
y = contTop;
|
|
14044
|
-
first = true;
|
|
14045
|
-
h -= avail;
|
|
14046
|
-
continue;
|
|
14047
|
-
}
|
|
14048
|
-
h = avail;
|
|
14049
|
-
break;
|
|
14050
|
-
}
|
|
14051
|
-
if (blocked && !first) {
|
|
14052
|
-
page++;
|
|
14053
|
-
y = contTop;
|
|
14054
|
-
first = true;
|
|
14055
|
-
continue;
|
|
14056
|
-
}
|
|
14057
|
-
if (!placed) {
|
|
14058
|
-
if (first) break;
|
|
14059
|
-
page++;
|
|
14060
|
-
y = contTop;
|
|
14061
|
-
first = true;
|
|
14062
|
-
continue;
|
|
14063
|
-
}
|
|
14064
|
-
pieces.push({ page, y, h: avail, range: new Map(cuts.map(([el, a, b]) => [el, [a, b]])) });
|
|
14065
|
-
for (const [el, , b] of cuts) from.set(el, b);
|
|
14066
|
-
page++;
|
|
14067
|
-
y = contTop;
|
|
14068
|
-
first = true;
|
|
14069
|
-
h = rem;
|
|
14103
|
+
return input;
|
|
14104
|
+
};
|
|
14105
|
+
for (const [barKey, barElem] of Object.entries(BAR_CONVERT_MAP)) {
|
|
14106
|
+
eqString = replaceBar(eqString, barKey, barElem);
|
|
14107
|
+
}
|
|
14108
|
+
return eqString;
|
|
14109
|
+
}
|
|
14110
|
+
function replaceAllBrace(eqString) {
|
|
14111
|
+
const replaceBrace = (input, braceStr, braceElem) => {
|
|
14112
|
+
while (true) {
|
|
14113
|
+
const cursor = input.indexOf(braceStr);
|
|
14114
|
+
if (cursor === -1) break;
|
|
14115
|
+
try {
|
|
14116
|
+
const [eStart1, eEnd1] = findBrackets(input, cursor);
|
|
14117
|
+
const [eStart2, eEnd2] = findBrackets(input, eEnd1);
|
|
14118
|
+
const elem1 = input.slice(eStart1, eEnd1);
|
|
14119
|
+
const elem2 = input.slice(eStart2, eEnd2);
|
|
14120
|
+
const beforeBrace = input.slice(0, cursor);
|
|
14121
|
+
const afterBrace = input.slice(eEnd2);
|
|
14122
|
+
input = beforeBrace + braceElem + elem1 + "^" + elem2 + afterBrace;
|
|
14123
|
+
} catch {
|
|
14124
|
+
return input;
|
|
14070
14125
|
}
|
|
14071
|
-
pieces.push({ page, y, h, range: new Map(rowCells.map((c) => [c.el, [from.get(c.el) ?? 0, Number.POSITIVE_INFINITY]])) });
|
|
14072
|
-
out.push(pieces);
|
|
14073
|
-
y += h;
|
|
14074
|
-
first = false;
|
|
14075
|
-
continue;
|
|
14076
14126
|
}
|
|
14077
|
-
|
|
14078
|
-
|
|
14079
|
-
|
|
14080
|
-
|
|
14127
|
+
return input;
|
|
14128
|
+
};
|
|
14129
|
+
for (const [braceKey, braceElem] of Object.entries(BRACE_CONVERT_MAP)) {
|
|
14130
|
+
eqString = replaceBrace(eqString, braceKey, braceElem);
|
|
14131
|
+
}
|
|
14132
|
+
return eqString;
|
|
14133
|
+
}
|
|
14134
|
+
function replaceBracket(strList) {
|
|
14135
|
+
for (let i = 0; i < strList.length; i++) {
|
|
14136
|
+
if (strList[i] === "{" && i > 0 && strList[i - 1] === "\\left") strList[i] = "\\{";
|
|
14137
|
+
if (strList[i] === "}" && i > 0 && strList[i - 1] === "\\right") strList[i] = "\\}";
|
|
14138
|
+
}
|
|
14139
|
+
return strList;
|
|
14140
|
+
}
|
|
14141
|
+
function hmlToLatex(hmlEqStr) {
|
|
14142
|
+
if (!hmlEqStr) return "";
|
|
14143
|
+
let s = hmlEqStr.replace(/[\r\n\t]+/g, " ").replace(/`/g, " ");
|
|
14144
|
+
s = s.replace(/\{/g, " { ").replace(/\}/g, " } ").replace(/&/g, " & ");
|
|
14145
|
+
let tokens = s.split(" ");
|
|
14146
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
14147
|
+
const t = tokens[i];
|
|
14148
|
+
if (Object.hasOwn(CONVERT_MAP, t)) tokens[i] = CONVERT_MAP[t];
|
|
14149
|
+
else if (Object.hasOwn(MIDDLE_CONVERT_MAP, t)) tokens[i] = MIDDLE_CONVERT_MAP[t];
|
|
14150
|
+
else {
|
|
14151
|
+
const quoted = /^"(.+)"$/.exec(t);
|
|
14152
|
+
if (quoted) tokens[i] = `\\text{${quoted[1]}}`;
|
|
14081
14153
|
}
|
|
14082
|
-
out.push([{ page, y, h }]);
|
|
14083
|
-
y += h;
|
|
14084
|
-
first = false;
|
|
14085
14154
|
}
|
|
14155
|
+
tokens = tokens.filter((tok) => tok.length !== 0);
|
|
14156
|
+
tokens = replaceBracket(tokens);
|
|
14157
|
+
let out = tokens.join(" ");
|
|
14158
|
+
out = replaceFrac(out);
|
|
14159
|
+
out = replaceRootOf(out);
|
|
14160
|
+
out = replaceAllMatrix(out);
|
|
14161
|
+
out = replaceAllBar(out);
|
|
14162
|
+
out = replaceAllBrace(out);
|
|
14086
14163
|
return out;
|
|
14087
14164
|
}
|
|
14088
14165
|
|
|
14089
|
-
// src/
|
|
14090
|
-
var
|
|
14091
|
-
|
|
14092
|
-
|
|
14093
|
-
|
|
14094
|
-
|
|
14095
|
-
|
|
14096
|
-
|
|
14097
|
-
|
|
14098
|
-
|
|
14099
|
-
|
|
14100
|
-
|
|
14101
|
-
|
|
14102
|
-
|
|
14103
|
-
|
|
14104
|
-
|
|
14105
|
-
|
|
14106
|
-
|
|
14107
|
-
|
|
14166
|
+
// src/hwp5/equation.ts
|
|
14167
|
+
var WORD_ALIASES = {
|
|
14168
|
+
// 삼각/로그 함수 — 정본 맵 부재
|
|
14169
|
+
sin: "\\sin",
|
|
14170
|
+
cos: "\\cos",
|
|
14171
|
+
tan: "\\tan",
|
|
14172
|
+
sec: "\\sec",
|
|
14173
|
+
csc: "\\csc",
|
|
14174
|
+
cot: "\\cot",
|
|
14175
|
+
log: "\\log",
|
|
14176
|
+
ln: "\\ln",
|
|
14177
|
+
// 연산자·관계 기호 (정본은 대문자 키만 보유)
|
|
14178
|
+
divide: "\\div",
|
|
14179
|
+
div: "\\div",
|
|
14180
|
+
le: "\\leq",
|
|
14181
|
+
ge: "\\geq",
|
|
14182
|
+
geq: "\\geq",
|
|
14183
|
+
deg: "^\\circ",
|
|
14184
|
+
rarrow: "\\rightarrow",
|
|
14185
|
+
lrarrow: "\\leftrightarrow",
|
|
14186
|
+
rightarrow: "\\rightarrow",
|
|
14187
|
+
leftarrow: "\\leftarrow",
|
|
14188
|
+
in: "\\in",
|
|
14189
|
+
notin: "\\notin",
|
|
14190
|
+
emptyset: "\\emptyset",
|
|
14191
|
+
subset: "\\subset",
|
|
14192
|
+
nsubset: "\\nsubseteq",
|
|
14193
|
+
cup: "\\cup",
|
|
14194
|
+
cap: "\\cap",
|
|
14195
|
+
smallinter: "\\cap",
|
|
14196
|
+
smallsum: "\\sum",
|
|
14197
|
+
sim: "\\sim",
|
|
14198
|
+
circ: "\\circ",
|
|
14199
|
+
bot: "\\perp",
|
|
14200
|
+
partial: "\\partial",
|
|
14201
|
+
nabla: "\\nabla",
|
|
14202
|
+
angle: "\\angle",
|
|
14203
|
+
triangle: "\\triangle",
|
|
14204
|
+
inf: "\\infty",
|
|
14205
|
+
left: "\\left",
|
|
14206
|
+
right: "\\right",
|
|
14207
|
+
// 글꼴 지시자 — 제거
|
|
14208
|
+
rm: "",
|
|
14209
|
+
it: ""
|
|
14210
|
+
};
|
|
14211
|
+
var STRUCTURAL_FOLD = /* @__PURE__ */ new Set(["over", "root", "of"]);
|
|
14212
|
+
function normalizeWords(input) {
|
|
14213
|
+
return input.replace(/(?<![\\A-Za-z0-9])([A-Za-z][A-Za-z0-9]*)(?![A-Za-z0-9])/g, (word) => {
|
|
14214
|
+
if (Object.hasOwn(CONVERT_MAP, word) || Object.hasOwn(MIDDLE_CONVERT_MAP, word)) return word;
|
|
14215
|
+
const lower = word.toLowerCase();
|
|
14216
|
+
if (STRUCTURAL_FOLD.has(lower)) return lower;
|
|
14217
|
+
if (Object.hasOwn(WORD_ALIASES, lower)) return WORD_ALIASES[lower];
|
|
14218
|
+
if (lower !== word && (Object.hasOwn(CONVERT_MAP, lower) || Object.hasOwn(MIDDLE_CONVERT_MAP, lower))) return lower;
|
|
14219
|
+
return word;
|
|
14220
|
+
});
|
|
14108
14221
|
}
|
|
14109
|
-
function
|
|
14110
|
-
return [
|
|
14111
|
-
m[0] * n[0] + m[2] * n[1],
|
|
14112
|
-
m[1] * n[0] + m[3] * n[1],
|
|
14113
|
-
m[0] * n[2] + m[2] * n[3],
|
|
14114
|
-
m[1] * n[2] + m[3] * n[3],
|
|
14115
|
-
m[0] * n[4] + m[2] * n[5] + m[4],
|
|
14116
|
-
m[1] * n[4] + m[3] * n[5] + m[5]
|
|
14117
|
-
];
|
|
14222
|
+
function normalizeScripts(input) {
|
|
14223
|
+
return input.replace(/\s*\^\s*/g, "^").replace(/\s*_\s*/g, "_").replace(/\^(?!\{)([^\s{}_^]+)/g, "^{$1}").replace(/_(?!\{)([^\s{}_^]+)/g, "_{$1}").replace(/([_^])/g, " $1 ");
|
|
14118
14224
|
}
|
|
14119
|
-
function
|
|
14120
|
-
|
|
14121
|
-
if (!info) return null;
|
|
14122
|
-
let m = null;
|
|
14123
|
-
for (const c of elements(info)) {
|
|
14124
|
-
const tag = ln(c);
|
|
14125
|
-
if (tag !== "transMatrix" && tag !== "scaMatrix" && tag !== "rotMatrix") continue;
|
|
14126
|
-
const n = [num(c, "e1", 1), num(c, "e4"), num(c, "e2"), num(c, "e5", 1), num(c, "e3"), num(c, "e6")];
|
|
14127
|
-
m = m ? mulAffine(m, n) : n;
|
|
14128
|
-
}
|
|
14129
|
-
return m;
|
|
14225
|
+
function normalizeOperators(input) {
|
|
14226
|
+
return input.replace(/\+-/g, " \\pm ").replace(/-\+/g, " \\mp ").replace(/\/\//g, " \\parallel ").replace(/!=/g, " \\neq ").replace(/<=/g, " \\leq ").replace(/>=/g, " \\geq ").replace(/==/g, " \\equiv ").replace(/△/g, " \\triangle ").replace(/□/g, " \\square ").replace(/‧/g, " \\cdot ");
|
|
14130
14227
|
}
|
|
14131
|
-
function
|
|
14132
|
-
|
|
14133
|
-
|
|
14134
|
-
|
|
14135
|
-
|
|
14136
|
-
|
|
14137
|
-
|
|
14138
|
-
return
|
|
14228
|
+
function hwpEquationToLatex(equation) {
|
|
14229
|
+
let s = equation.replace(/\0/g, "").replace(/\s+/g, " ").trim();
|
|
14230
|
+
if (!s) return "";
|
|
14231
|
+
s = normalizeScripts(s);
|
|
14232
|
+
s = normalizeOperators(s);
|
|
14233
|
+
s = normalizeWords(s);
|
|
14234
|
+
s = s.replace(/\broot\s+(?!\{)(\S+)\s+of(?![A-Za-z0-9])/gi, "root { $1 } of");
|
|
14235
|
+
return hmlToLatex(s).replace(/\s+/g, " ").trim();
|
|
14139
14236
|
}
|
|
14140
|
-
|
|
14141
|
-
|
|
14142
|
-
|
|
14143
|
-
const
|
|
14144
|
-
|
|
14145
|
-
const
|
|
14146
|
-
|
|
14147
|
-
|
|
14148
|
-
|
|
14149
|
-
|
|
14150
|
-
|
|
14151
|
-
|
|
14152
|
-
|
|
14153
|
-
|
|
14154
|
-
|
|
14155
|
-
|
|
14156
|
-
|
|
14157
|
-
|
|
14158
|
-
|
|
14159
|
-
|
|
14160
|
-
|
|
14161
|
-
|
|
14162
|
-
|
|
14237
|
+
|
|
14238
|
+
// src/render/object-anchor.ts
|
|
14239
|
+
function anchorObject(o, ox, oy, baseV, areaW, ctx, anchorLineV, stayLine = false, paraStartV, laterLineH) {
|
|
14240
|
+
const { PW, PH, ML, MT, BODY_W, BODY_H } = ctx.geom;
|
|
14241
|
+
const pos = findChildByLocalName(o.el, "pos");
|
|
14242
|
+
const om = findChildByLocalName(o.el, "outMargin");
|
|
14243
|
+
const omT = num(om, "top"), omB = num(om, "bottom");
|
|
14244
|
+
const w = o.width, h = o.tag === "tbl" ? Math.max(o.height, measureTableHeight(o.el, ctx.extentMemo)) : o.height;
|
|
14245
|
+
if (!pos) return { x: ox, y: oy + baseV };
|
|
14246
|
+
const voRaw = num(pos, "vertOffset"), voS = voRaw >= 2 ** 31 ? voRaw - 2 ** 32 : voRaw;
|
|
14247
|
+
const vo = (pos.getAttribute("vertRelTo") ?? "PARA") === "PARA" ? Math.max(0, voS) : voS;
|
|
14248
|
+
const ho = num(pos, "horzOffset");
|
|
14249
|
+
const vrel = pos.getAttribute("vertRelTo") ?? "PARA";
|
|
14250
|
+
const hrel = pos.getAttribute("horzRelTo") ?? "PARA";
|
|
14251
|
+
const va = pos.getAttribute("vertAlign") ?? "TOP";
|
|
14252
|
+
const ha = pos.getAttribute("horzAlign") ?? "LEFT";
|
|
14253
|
+
const wrap = o.el.getAttribute("textWrap") ?? "TOP_AND_BOTTOM";
|
|
14254
|
+
let y;
|
|
14255
|
+
if (vrel === "PAPER") {
|
|
14256
|
+
y = va === "BOTTOM" ? PH - h - vo - omB : va === "CENTER" ? (PH - h) / 2 + vo : vo + omT;
|
|
14257
|
+
} else if (vrel === "PAGE") {
|
|
14258
|
+
y = va === "BOTTOM" ? MT + BODY_H - h - vo : va === "CENTER" ? MT + (BODY_H - h) / 2 + vo : MT + vo;
|
|
14259
|
+
} else if (wrap === "TOP_AND_BOTTOM") {
|
|
14260
|
+
const lineV = anchorLineV ?? baseV;
|
|
14261
|
+
const pushed = lineV - (omT + h + omB);
|
|
14262
|
+
const below = laterLineH !== void 0 && vo + omT >= laterLineH;
|
|
14263
|
+
const anchor = below ? lineV : stayLine !== false ? lineV - stayLine : pushed >= -100 ? pushed : paraStartV !== void 0 ? paraStartV : lineV;
|
|
14264
|
+
y = oy + anchor + omT + vo;
|
|
14265
|
+
} else {
|
|
14266
|
+
const origin = vrel === "PARA" && wrap === "SQUARE" ? paraStartV ?? baseV : baseV;
|
|
14267
|
+
y = oy + Math.max(origin + vo, wrap === "SQUARE" && anchorLineV !== void 0 ? anchorLineV : -Infinity) + omT;
|
|
14163
14268
|
}
|
|
14164
|
-
|
|
14165
|
-
const
|
|
14166
|
-
if (
|
|
14167
|
-
|
|
14168
|
-
|
|
14169
|
-
|
|
14170
|
-
|
|
14171
|
-
|
|
14172
|
-
}
|
|
14173
|
-
const mode = imgBrush.getAttribute("mode") ?? "TOTAL";
|
|
14174
|
-
if (mode !== "TOTAL") {
|
|
14175
|
-
warn(`brush-mode:${mode}`, `\uADF8\uB9BC \uCC44\uC6C0(${mode}) \uBBF8\uC9C0\uC6D0 \u2014 \uCC44\uC6C0 \uC0DD\uB7B5`);
|
|
14176
|
-
return "none";
|
|
14177
|
-
}
|
|
14178
|
-
if (loaded.paintId) return `url(#${loaded.paintId})`;
|
|
14179
|
-
const id = `paint${defs.length}`;
|
|
14180
|
-
defs.push(`<pattern id="${id}" width="1" height="1" patternContentUnits="objectBoundingBox"><image href="${esc(loaded.dataUri)}" width="1" height="1" preserveAspectRatio="none"/></pattern>`);
|
|
14181
|
-
loaded.paintId = id;
|
|
14182
|
-
return `url(#${id})`;
|
|
14269
|
+
let x;
|
|
14270
|
+
const omL = num(om, "left"), omR = num(om, "right");
|
|
14271
|
+
if (hrel === "PAGE") {
|
|
14272
|
+
x = ha === "RIGHT" ? ML + BODY_W - w - ho - omR : ha === "CENTER" ? ML + (BODY_W - w) / 2 + ho : ML + ho + omL;
|
|
14273
|
+
} else if (hrel === "PAPER") {
|
|
14274
|
+
x = (ha === "RIGHT" ? PW - w - ho - omR : ha === "CENTER" ? (PW - w) / 2 + ho : ho + omL) - (ctx.bodyDx?.(ctx.page) ?? 0);
|
|
14275
|
+
} else {
|
|
14276
|
+
x = ha === "RIGHT" ? ox + areaW - w - ho - omR : ha === "CENTER" ? ox + (areaW - w) / 2 + ho : ox + ho + omL;
|
|
14183
14277
|
}
|
|
14184
|
-
return
|
|
14185
|
-
}
|
|
14186
|
-
function shapeGeometry(o, boxX, boxY, defs, images, warn, local = false) {
|
|
14187
|
-
const el = o.el, org = findChildByLocalName(el, "orgSz"), cur = findChildByLocalName(el, "curSz");
|
|
14188
|
-
const ow = num(org, "width"), oh = num(org, "height");
|
|
14189
|
-
const w = (local ? ow : num(cur, "width")) || ow || num(cur, "width") || o.width;
|
|
14190
|
-
const h = (local ? oh : num(cur, "height")) || oh || num(cur, "height") || o.height;
|
|
14191
|
-
const geometry = local ? { x: boxX, y: boxY, w, h, bbox: { x: boxX, y: boxY, w, h }, transform: "" } : objectGeometry(el, boxX, boxY, w, h, o.width || w, o.height || h);
|
|
14192
|
-
const { x, y } = geometry;
|
|
14193
|
-
const sx = ow > 0 ? w / ow : 1, sy = oh > 0 ? h / oh : 1;
|
|
14194
|
-
const line = findChildByLocalName(el, "lineShape"), style = line?.getAttribute("style") ?? "SOLID";
|
|
14195
|
-
const color = esc(docColor(line?.getAttribute("color"), "#000000"));
|
|
14196
|
-
const strokeW = style === "NONE" ? 0 : Math.max(0.2, num(line, "width", 33) / 100 * 2.834645);
|
|
14197
|
-
const dash = /DASH|DOT/.test(style) ? ` stroke-dasharray="${style.includes("DOT") ? "1,1.5" : "3,1.5"}"` : "";
|
|
14198
|
-
const keepWidth = local ? ` vector-effect="non-scaling-stroke"` : "";
|
|
14199
|
-
const stroke = strokeW ? ` stroke="${color}" stroke-width="${strokeW.toFixed(2)}"${dash}${keepWidth}` : "";
|
|
14200
|
-
const fill = ` fill="${shapeFill(el, defs, images, warn)}"`;
|
|
14201
|
-
let svg = "";
|
|
14202
|
-
if (o.tag === "rect") svg = `<rect x="${pt(x)}" y="${pt(y)}" width="${pt(w)}" height="${pt(h)}"${fill}${stroke}/>`;
|
|
14203
|
-
else if (o.tag === "ellipse") svg = `<ellipse cx="${pt(x + w / 2)}" cy="${pt(y + h / 2)}" rx="${pt(w / 2)}" ry="${pt(h / 2)}"${fill}${stroke}/>`;
|
|
14204
|
-
else if (o.tag === "line") {
|
|
14205
|
-
const s = findChildByLocalName(el, "startPt"), e = findChildByLocalName(el, "endPt");
|
|
14206
|
-
svg = `<line x1="${pt(x + num(s, "x") * sx)}" y1="${pt(y + num(s, "y") * sy)}" x2="${pt(x + num(e, "x") * sx)}" y2="${pt(y + num(e, "y") * sy)}" stroke="${color}" stroke-width="${(strokeW || 0.3).toFixed(2)}"${dash}${keepWidth}/>`;
|
|
14207
|
-
} else if (o.tag === "polygon" || o.tag === "curv") {
|
|
14208
|
-
const pts = elements(el).filter((c) => ln(c) === "pt").map((c) => `${pt(x + num(c, "x") * sx)},${pt(y + num(c, "y") * sy)}`);
|
|
14209
|
-
if (pts.length >= 2) svg = `<polygon points="${pts.join(" ")}"${fill}${stroke}/>`;
|
|
14210
|
-
} else if (o.tag === "curve") {
|
|
14211
|
-
const segs = elements(el).filter((c) => ln(c) === "seg");
|
|
14212
|
-
if (segs.length) {
|
|
14213
|
-
let path = "", lastX, lastY;
|
|
14214
|
-
for (const s of segs) {
|
|
14215
|
-
const x1 = num(s, "x1"), y1 = num(s, "y1"), x2 = num(s, "x2"), y2 = num(s, "y2");
|
|
14216
|
-
if (x1 !== lastX || y1 !== lastY) path += `M${pt(x + x1 * sx)} ${pt(y + y1 * sy)}`;
|
|
14217
|
-
path += `L${pt(x + x2 * sx)} ${pt(y + y2 * sy)}`;
|
|
14218
|
-
lastX = x2;
|
|
14219
|
-
lastY = y2;
|
|
14220
|
-
}
|
|
14221
|
-
svg = `<path d="${path}"${fill}${stroke}/>`;
|
|
14222
|
-
}
|
|
14223
|
-
} else if (o.tag === "arc") svg = `<ellipse cx="${pt(x + w / 2)}" cy="${pt(y + h / 2)}" rx="${pt(w / 2)}" ry="${pt(h / 2)}" fill="none"${stroke || ` stroke="${color}" stroke-width="0.3"`}/>`;
|
|
14224
|
-
return { ...geometry, svg };
|
|
14278
|
+
return { x, y };
|
|
14225
14279
|
}
|
|
14226
14280
|
|
|
14227
|
-
// src/render/svg-
|
|
14281
|
+
// src/render/svg-content.ts
|
|
14228
14282
|
function escapeXml(s) {
|
|
14229
14283
|
return s.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
14230
14284
|
}
|
|
@@ -14274,7 +14328,8 @@ function planLines(m, styles, numText = "") {
|
|
|
14274
14328
|
const bu = geom?.bullet ?? (numText && geom?.number ? { ch: numText, ...geom.number } : void 0);
|
|
14275
14329
|
const firstPr = m.chars.find((c) => c.ch !== "")?.prId ?? null;
|
|
14276
14330
|
const bst = (bu?.charPrId != null ? styles.charPr.get(bu.charPrId) : firstPr != null ? styles.charPr.get(firstPr) : void 0) ?? DEFAULT_CHAR;
|
|
14277
|
-
const
|
|
14331
|
+
const headW = bu?.useInstWidth === false ? [...bu.ch].reduce((w, ch) => w + glyphWidth(ch, bst, false).w, 0) : bu ? measureTextWidth(bu.ch, bst.height, bst.ratio, { spacingPct: bst.spacing, faceClass: faceClassOf(bst.face) }) : 0;
|
|
14332
|
+
const bulletW = bu ? paraHeadAdvance(bu, bst.height, headW) : 0;
|
|
14278
14333
|
const plans = [];
|
|
14279
14334
|
for (let i = 0; i < m.segs.length; i++) {
|
|
14280
14335
|
const seg = m.segs[i];
|
|
@@ -14546,7 +14601,7 @@ function drawPara(p, ox, oy, areaW, ctx, depth, segPages) {
|
|
|
14546
14601
|
const stay = tbFloats < 2 && !m.objs.some((q) => q.inline) && !m.chars.some((c) => c.ch !== "" && !c.nb && c.ch.trim() !== "");
|
|
14547
14602
|
const sbA = m.paraPrId != null ? ctx.styles.paraGeom.get(m.paraPrId)?.spaceBefore ?? 0 : 0;
|
|
14548
14603
|
const firstLine = anchorLineV === void 0 || anchorLineV === baseV;
|
|
14549
|
-
let { x, y } = anchorObject(o, ax, oy, objBaseV, aw, ctx, anchorLineV, stay ? sbA : false, firstLine && pTop !== void 0 && pTop < baseV ? pTop : void 0, firstLine ? void 0 : anchorLineH);
|
|
14604
|
+
let { x, y } = anchorObject(o, ax, oy, objBaseV, aw, ctx, anchorLineV, stay ? sbA : false, (firstLine || wrapA === "SQUARE") && pTop !== void 0 && pTop < baseV ? pTop : void 0, firstLine ? void 0 : anchorLineH);
|
|
14550
14605
|
if (depth === 0 && tbFloats >= 2 && wrapA === "TOP_AND_BOTTOM") {
|
|
14551
14606
|
if (!tbStack) {
|
|
14552
14607
|
tbStack = /* @__PURE__ */ new Map();
|
|
@@ -14583,46 +14638,6 @@ function cellParaTop(p, geom) {
|
|
|
14583
14638
|
const last = segs[segs.length - 1];
|
|
14584
14639
|
return num(last, "vertpos") + num(last, "vertsize") + num(last, "spacing") + (geom.get(prev.getAttribute("paraPrIDRef") ?? "")?.spaceAfter ?? 0);
|
|
14585
14640
|
}
|
|
14586
|
-
function anchorObject(o, ox, oy, baseV, areaW, ctx, anchorLineV, stayLine = false, paraStartV, laterLineH) {
|
|
14587
|
-
const { PW, PH, ML, MT, BODY_W, BODY_H } = ctx.geom;
|
|
14588
|
-
const pos = findChildByLocalName(o.el, "pos");
|
|
14589
|
-
const om = findChildByLocalName(o.el, "outMargin");
|
|
14590
|
-
const omT = num(om, "top"), omB = num(om, "bottom");
|
|
14591
|
-
const w = o.width, h = o.tag === "tbl" ? Math.max(o.height, measureTableHeight(o.el, ctx.extentMemo)) : o.height;
|
|
14592
|
-
if (!pos) return { x: ox, y: oy + baseV };
|
|
14593
|
-
const voRaw = num(pos, "vertOffset"), voS = voRaw >= 2 ** 31 ? voRaw - 2 ** 32 : voRaw;
|
|
14594
|
-
const vo = (pos.getAttribute("vertRelTo") ?? "PARA") === "PARA" ? Math.max(0, voS) : voS;
|
|
14595
|
-
const ho = num(pos, "horzOffset");
|
|
14596
|
-
const vrel = pos.getAttribute("vertRelTo") ?? "PARA";
|
|
14597
|
-
const hrel = pos.getAttribute("horzRelTo") ?? "PARA";
|
|
14598
|
-
const va = pos.getAttribute("vertAlign") ?? "TOP";
|
|
14599
|
-
const ha = pos.getAttribute("horzAlign") ?? "LEFT";
|
|
14600
|
-
const wrap = o.el.getAttribute("textWrap") ?? "TOP_AND_BOTTOM";
|
|
14601
|
-
let y;
|
|
14602
|
-
if (vrel === "PAPER") {
|
|
14603
|
-
y = va === "BOTTOM" ? PH - h - vo - omB : va === "CENTER" ? (PH - h) / 2 + vo : vo + omT;
|
|
14604
|
-
} else if (vrel === "PAGE") {
|
|
14605
|
-
y = va === "BOTTOM" ? MT + BODY_H - h - vo : va === "CENTER" ? MT + (BODY_H - h) / 2 + vo : MT + vo;
|
|
14606
|
-
} else if (wrap === "TOP_AND_BOTTOM") {
|
|
14607
|
-
const lineV = anchorLineV ?? baseV;
|
|
14608
|
-
const pushed = lineV - (omT + h + omB);
|
|
14609
|
-
const below = laterLineH !== void 0 && vo + omT >= laterLineH;
|
|
14610
|
-
const anchor = below ? lineV : stayLine !== false ? lineV - stayLine : pushed >= -100 ? pushed : paraStartV !== void 0 ? paraStartV : lineV;
|
|
14611
|
-
y = oy + anchor + omT + vo;
|
|
14612
|
-
} else {
|
|
14613
|
-
y = oy + Math.max(baseV + vo, wrap === "SQUARE" && anchorLineV !== void 0 ? anchorLineV : -Infinity) + omT;
|
|
14614
|
-
}
|
|
14615
|
-
let x;
|
|
14616
|
-
const omL = num(om, "left"), omR = num(om, "right");
|
|
14617
|
-
if (hrel === "PAGE") {
|
|
14618
|
-
x = ha === "RIGHT" ? ML + BODY_W - w - ho - omR : ha === "CENTER" ? ML + (BODY_W - w) / 2 + ho : ML + ho + omL;
|
|
14619
|
-
} else if (hrel === "PAPER") {
|
|
14620
|
-
x = (ha === "RIGHT" ? PW - w - ho - omR : ha === "CENTER" ? (PW - w) / 2 + ho : ho + omL) - (ctx.bodyDx?.(ctx.page) ?? 0);
|
|
14621
|
-
} else {
|
|
14622
|
-
x = ha === "RIGHT" ? ox + areaW - w - ho - omR : ha === "CENTER" ? ox + (areaW - w) / 2 + ho : ox + ho + omL;
|
|
14623
|
-
}
|
|
14624
|
-
return { x, y };
|
|
14625
|
-
}
|
|
14626
14641
|
function drawObject(o, x, y, baseV, areaW, ctx, depth) {
|
|
14627
14642
|
if (!o.inline && depth === 0 && ctx.paintJobs) {
|
|
14628
14643
|
const wrap = o.el.getAttribute("textWrap");
|
|
@@ -14649,8 +14664,8 @@ function drawObject(o, x, y, baseV, areaW, ctx, depth) {
|
|
|
14649
14664
|
x = ox;
|
|
14650
14665
|
y = oy;
|
|
14651
14666
|
}
|
|
14652
|
-
if (o.tag === "tbl")
|
|
14653
|
-
else if (o.tag === "pic")
|
|
14667
|
+
if (o.tag === "tbl") ctx.draw.table(o.el, x, y, ctx, depth + 1);
|
|
14668
|
+
else if (o.tag === "pic") ctx.draw.pic(o.el, x, y, ctx);
|
|
14654
14669
|
else if (o.tag === "container") {
|
|
14655
14670
|
if (drawGroupByMatrix(o, x, y, baseV, areaW, ctx, depth)) return;
|
|
14656
14671
|
for (const ch of elements(o.el)) {
|
|
@@ -14706,7 +14721,7 @@ function drawGroupByMatrix(o, x, y, baseV, areaW, ctx, depth) {
|
|
|
14706
14721
|
ctx.regionRotations.push(m);
|
|
14707
14722
|
emit(ctx, `<g transform="matrix(${m.slice(0, 4).map((v) => Math.round(v * 1e6) / 1e6).join(" ")} ${pt2(m[4])} ${pt2(m[5])})">`);
|
|
14708
14723
|
const sub = { el: leaf, tag, index: 0, inline: true, width: w, height: h, omL: 0, omR: 0 };
|
|
14709
|
-
if (tag === "pic")
|
|
14724
|
+
if (tag === "pic") ctx.draw.picFrame(leaf, 0, 0, w, h, "", ctx);
|
|
14710
14725
|
else if (SHAPE_TAGS.has(tag)) drawShape(sub, 0, 0, ctx, depth + 1, [Math.hypot(m[0], m[1]) || 1, Math.hypot(m[2], m[3]) || 1]);
|
|
14711
14726
|
else drawObject(sub, 0, 0, baseV, areaW, ctx, depth + 1);
|
|
14712
14727
|
emit(ctx, "</g>");
|
|
@@ -14754,6 +14769,8 @@ function drawShape(o, x, y, ctx, depth, groupScale) {
|
|
|
14754
14769
|
ctx.parentStack.pop();
|
|
14755
14770
|
emit(ctx, "</g>");
|
|
14756
14771
|
}
|
|
14772
|
+
|
|
14773
|
+
// src/render/svg-render.ts
|
|
14757
14774
|
function edgeLine(x1, y1, x2, y2, e) {
|
|
14758
14775
|
const dash = /DASH|DOT/.test(e.type) ? ` stroke-dasharray="${e.type.includes("DOT") ? "1,1.5" : "3,1.5"}"` : "";
|
|
14759
14776
|
return `<line x1="${pt2(x1)}" y1="${pt2(y1)}" x2="${pt2(x2)}" y2="${pt2(y2)}" stroke="${escapeXml(e.color)}" stroke-width="${e.widthPt.toFixed(2)}"${dash}/>`;
|
|
@@ -15368,6 +15385,7 @@ function drawPageNumbers(root, paraPages, ctx) {
|
|
|
15368
15385
|
}
|
|
15369
15386
|
function renderSectionRoots(sections, input) {
|
|
15370
15387
|
const ctxBase = {
|
|
15388
|
+
draw: { table: drawTable, pic: drawPic, picFrame: drawPicFrame },
|
|
15371
15389
|
styles: input.styles,
|
|
15372
15390
|
images: input.images,
|
|
15373
15391
|
defs: [],
|
|
@@ -19672,4 +19690,4 @@ export {
|
|
|
19672
19690
|
cropRect,
|
|
19673
19691
|
extractRenderedRegions
|
|
19674
19692
|
};
|
|
19675
|
-
//# sourceMappingURL=chunk-
|
|
19693
|
+
//# sourceMappingURL=chunk-U3GUZQ54.js.map
|