@bendyline/squisq-formats 2.8.0 → 2.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-MVSHWYIE.js → chunk-AOY3UPE3.js} +1 -1
- package/dist/{chunk-32AQL6I6.js → chunk-GLIUMDYD.js} +13 -6
- package/dist/index.js +3 -3
- package/dist/outside-in/index.js +2 -2
- package/dist/pdf/index.js +1 -1
- package/dist/registry/index.js +1 -1
- package/package.json +2 -2
- /package/dist/{chunk-UJQHFM3K.js → chunk-X6WFQDZD.js} +0 -0
|
@@ -799,6 +799,13 @@ function flattenInlines(nodes, ctx, state) {
|
|
|
799
799
|
}
|
|
800
800
|
return spans;
|
|
801
801
|
}
|
|
802
|
+
var STANDARD_FONT_NAMES = new Set(Object.values(StandardFonts));
|
|
803
|
+
function drawnWidth(font, text, size) {
|
|
804
|
+
if (!STANDARD_FONT_NAMES.has(font.name)) return font.widthOfTextAtSize(text, size);
|
|
805
|
+
let width = 0;
|
|
806
|
+
for (const character of text) width += font.widthOfTextAtSize(character, size);
|
|
807
|
+
return width;
|
|
808
|
+
}
|
|
802
809
|
function textSpans(ctx, text, font, style) {
|
|
803
810
|
return ctx.runs.split(text, font).map((run) => ({ ...style, text: run.text, font: run.font }));
|
|
804
811
|
}
|
|
@@ -813,7 +820,7 @@ function drawTextLine(ctx, text, font, at) {
|
|
|
813
820
|
font: run.font,
|
|
814
821
|
color: rgb(at.color.r, at.color.g, at.color.b)
|
|
815
822
|
});
|
|
816
|
-
x += run.font
|
|
823
|
+
x += drawnWidth(run.font, run.text, at.size);
|
|
817
824
|
}
|
|
818
825
|
}
|
|
819
826
|
function pickFont(ctx, bold, italic) {
|
|
@@ -839,7 +846,7 @@ function drawSpans(spans, ctx, availableWidth, x0) {
|
|
|
839
846
|
font: span.font,
|
|
840
847
|
color: rgb(span.color.r, span.color.g, span.color.b)
|
|
841
848
|
});
|
|
842
|
-
const textWidth = span.font
|
|
849
|
+
const textWidth = drawnWidth(span.font, span.text, span.fontSize);
|
|
843
850
|
if (span.link) {
|
|
844
851
|
const baseline = spanBaseline;
|
|
845
852
|
ctx.page.drawLine({
|
|
@@ -890,7 +897,7 @@ function wrapSpans(spans, maxWidth) {
|
|
|
890
897
|
}
|
|
891
898
|
const words = splitIntoWords(span.text);
|
|
892
899
|
for (const word of words) {
|
|
893
|
-
const wordWidth = span.font
|
|
900
|
+
const wordWidth = drawnWidth(span.font, word, span.fontSize);
|
|
894
901
|
if (lineWidth + wordWidth > maxWidth && currentLine.length > 0 && word.trim().length > 0) {
|
|
895
902
|
lines.push(currentLine);
|
|
896
903
|
currentLine = [];
|
|
@@ -898,7 +905,7 @@ function wrapSpans(spans, maxWidth) {
|
|
|
898
905
|
}
|
|
899
906
|
const trimmedWord = currentLine.length === 0 ? word.replace(/^\s+/, "") : word;
|
|
900
907
|
if (trimmedWord.length > 0) {
|
|
901
|
-
const tw = span.font
|
|
908
|
+
const tw = drawnWidth(span.font, trimmedWord, span.fontSize);
|
|
902
909
|
currentLine.push({ ...span, text: trimmedWord });
|
|
903
910
|
lineWidth += tw;
|
|
904
911
|
}
|
|
@@ -1075,7 +1082,7 @@ function renderListItem(item, ctx, extraIndent, depth, ordered, counter) {
|
|
|
1075
1082
|
const indent = extraIndent + depth * LIST_INDENT;
|
|
1076
1083
|
const bullet = ordered ? `${counter}.` : BULLET_CHAR;
|
|
1077
1084
|
const bulletFont = ctx.fonts.regular;
|
|
1078
|
-
const bulletWidth = bulletFont
|
|
1085
|
+
const bulletWidth = drawnWidth(bulletFont, bullet + " ", ctx.fontSize);
|
|
1079
1086
|
const lineHeight = ctx.fontSize * LINE_HEIGHT_FACTOR;
|
|
1080
1087
|
ensureSpace(ctx, lineHeight);
|
|
1081
1088
|
ctx.page.drawText(bullet, {
|
|
@@ -1197,7 +1204,7 @@ function renderTable(node, ctx, extraIndent) {
|
|
|
1197
1204
|
font: span.font,
|
|
1198
1205
|
color: rgb(span.color.r, span.color.g, span.color.b)
|
|
1199
1206
|
});
|
|
1200
|
-
lx += span.font
|
|
1207
|
+
lx += drawnWidth(span.font, span.text, span.fontSize);
|
|
1201
1208
|
}
|
|
1202
1209
|
ctx.y -= getLineHeight(line);
|
|
1203
1210
|
}
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
renderOutsideInDocument,
|
|
29
29
|
withOutsideInMarkdownEditing,
|
|
30
30
|
withOutsideInMetadata
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-AOY3UPE3.js";
|
|
32
32
|
import {
|
|
33
33
|
DEFAULT_CONVERSION_LIMITS,
|
|
34
34
|
convert,
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
defaultRegistry,
|
|
38
38
|
prepareConversion,
|
|
39
39
|
resolveConversionLimits
|
|
40
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-X6WFQDZD.js";
|
|
41
41
|
import {
|
|
42
42
|
ConversionError
|
|
43
43
|
} from "./chunk-KXOZMWBS.js";
|
|
@@ -94,7 +94,7 @@ import {
|
|
|
94
94
|
markdownDocToPdf,
|
|
95
95
|
pdfToDoc,
|
|
96
96
|
pdfToMarkdownDoc
|
|
97
|
-
} from "./chunk-
|
|
97
|
+
} from "./chunk-GLIUMDYD.js";
|
|
98
98
|
import "./chunk-34KECNZO.js";
|
|
99
99
|
import "./chunk-BXWNU4T5.js";
|
|
100
100
|
import "./chunk-IIQYS2YH.js";
|
package/dist/outside-in/index.js
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
renderOutsideInDocument,
|
|
7
7
|
withOutsideInMarkdownEditing,
|
|
8
8
|
withOutsideInMetadata
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import "../chunk-
|
|
9
|
+
} from "../chunk-AOY3UPE3.js";
|
|
10
|
+
import "../chunk-X6WFQDZD.js";
|
|
11
11
|
import "../chunk-KXOZMWBS.js";
|
|
12
12
|
import {
|
|
13
13
|
OUTSIDE_IN_FORMAT_IDS,
|
package/dist/pdf/index.js
CHANGED
package/dist/registry/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bendyline/squisq-formats",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.2",
|
|
4
4
|
"description": "Document format converters — DOCX, PDF, OOXML import/export",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Bendyline",
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
"typecheck": "tsc --noEmit"
|
|
126
126
|
},
|
|
127
127
|
"dependencies": {
|
|
128
|
-
"@bendyline/squisq": "2.13.
|
|
128
|
+
"@bendyline/squisq": "2.13.1",
|
|
129
129
|
"@pdf-lib/fontkit": "1.1.1",
|
|
130
130
|
"@pdf-lib/upng": "1.0.1",
|
|
131
131
|
"@xmldom/xmldom": "0.9.12",
|
|
File without changes
|