@hirokisakabe/pom 0.1.2 → 0.1.4
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"measureText.d.ts","sourceRoot":"","sources":["../../src/calcYogaLayout/measureText.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,GAAG;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAKF;;GAEG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,cAAc,GACnB;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,
|
|
1
|
+
{"version":3,"file":"measureText.d.ts","sourceRoot":"","sources":["../../src/calcYogaLayout/measureText.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,GAAG;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAKF;;GAEG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,cAAc,GACnB;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CA+CA"}
|
|
@@ -6,28 +6,37 @@ const ctx = canvas.getContext("2d");
|
|
|
6
6
|
*/
|
|
7
7
|
export function measureText(text, maxWidthPx, opts) {
|
|
8
8
|
applyFontStyle(opts);
|
|
9
|
-
|
|
9
|
+
// まず改行で段落に分割
|
|
10
|
+
const paragraphs = text.split("\n");
|
|
10
11
|
const lines = [];
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (w <= maxWidthPx || !current) {
|
|
17
|
-
// まだ詰められる
|
|
18
|
-
current = candidate;
|
|
19
|
-
currentWidth = w;
|
|
12
|
+
for (const paragraph of paragraphs) {
|
|
13
|
+
// 空の段落(連続した改行)も1行としてカウント
|
|
14
|
+
if (paragraph === "") {
|
|
15
|
+
lines.push({ widthPx: 0 });
|
|
16
|
+
continue;
|
|
20
17
|
}
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
const words = splitForWrap(paragraph);
|
|
19
|
+
let current = "";
|
|
20
|
+
let currentWidth = 0;
|
|
21
|
+
for (const word of words) {
|
|
22
|
+
const candidate = current ? current + word : word;
|
|
23
|
+
const w = ctx.measureText(candidate).width;
|
|
24
|
+
if (w <= maxWidthPx || !current) {
|
|
25
|
+
// まだ詰められる
|
|
26
|
+
current = candidate;
|
|
27
|
+
currentWidth = w;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// 折り返す
|
|
31
|
+
lines.push({ widthPx: currentWidth });
|
|
32
|
+
current = word;
|
|
33
|
+
currentWidth = ctx.measureText(word).width;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (current) {
|
|
23
37
|
lines.push({ widthPx: currentWidth });
|
|
24
|
-
current = word;
|
|
25
|
-
currentWidth = ctx.measureText(word).width;
|
|
26
38
|
}
|
|
27
39
|
}
|
|
28
|
-
if (current) {
|
|
29
|
-
lines.push({ widthPx: currentWidth });
|
|
30
|
-
}
|
|
31
40
|
const lineHeightRatio = opts.lineHeight ?? 1.3;
|
|
32
41
|
const lineHeightPx = opts.fontSizePx * lineHeightRatio;
|
|
33
42
|
const widthPx = lines.length ? Math.max(...lines.map((l) => l.widthPx)) : 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderPptx.d.ts","sourceRoot":"","sources":["../../src/renderPptx/renderPptx.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,aAAa,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG/C,eAAO,MAAM,SAAS,KAAK,CAAC;AAC5B,eAAO,MAAM,MAAM,GAAI,IAAI,MAAM,WAAmB,CAAC;AACrD,eAAO,MAAM,MAAM,GAAI,IAAI,MAAM,WAA0B,CAAC;AAE5D,KAAK,OAAO,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAExC;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,EAAE,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"renderPptx.d.ts","sourceRoot":"","sources":["../../src/renderPptx/renderPptx.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,aAAa,MAAM,WAAW,CAAC;AAE3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG/C,eAAO,MAAM,SAAS,KAAK,CAAC;AAC5B,eAAO,MAAM,MAAM,GAAI,IAAI,MAAM,WAAmB,CAAC;AACrD,eAAO,MAAM,MAAM,GAAI,IAAI,MAAM,WAA0B,CAAC;AAE5D,KAAK,OAAO,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAExC;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,EAAE,EAAE,OAAO,EAAE,OAAO,iBAqMnE"}
|
|
@@ -67,6 +67,7 @@ export function renderPptx(pages, slidePx) {
|
|
|
67
67
|
align: "left",
|
|
68
68
|
valign: "top",
|
|
69
69
|
margin: 0,
|
|
70
|
+
lineSpacingMultiple: 1.3,
|
|
70
71
|
};
|
|
71
72
|
slide.addText(node.text ?? "", opts);
|
|
72
73
|
break;
|
|
@@ -164,6 +165,7 @@ export function renderPptx(pages, slidePx) {
|
|
|
164
165
|
color: node.fontColor,
|
|
165
166
|
align: node.alignText ?? "center",
|
|
166
167
|
valign: "middle",
|
|
168
|
+
lineSpacingMultiple: 1.3,
|
|
167
169
|
});
|
|
168
170
|
}
|
|
169
171
|
else {
|
package/package.json
CHANGED