@contrail/document-util 1.0.14 → 1.0.15
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.
|
@@ -10,6 +10,7 @@ export declare class MeasureTextSettings {
|
|
|
10
10
|
map?: any;
|
|
11
11
|
}
|
|
12
12
|
export declare class DocumentTextUtil {
|
|
13
|
+
private static readonly MAX_FONT_FALLBACK_INCREASE;
|
|
13
14
|
static measureText(string: string, settings: MeasureTextSettings): {
|
|
14
15
|
width: number;
|
|
15
16
|
height: number;
|
|
@@ -57,7 +57,15 @@ class DocumentTextUtil {
|
|
|
57
57
|
let letterSpacingWidth = sett.letterSpacing ? charLength * sett.letterSpacing : 0;
|
|
58
58
|
let width = Math.ceil(totalWidth * (fontSize / 100) + letterSpacingWidth);
|
|
59
59
|
if (fontNotFoundInMap && (settings === null || settings === void 0 ? void 0 : settings.width) == null) {
|
|
60
|
-
|
|
60
|
+
let multiplier = 1.2;
|
|
61
|
+
if (charLength > 50) {
|
|
62
|
+
multiplier = 1.1;
|
|
63
|
+
}
|
|
64
|
+
else if (charLength > 10) {
|
|
65
|
+
multiplier = 1.15;
|
|
66
|
+
}
|
|
67
|
+
const increase = width * (multiplier - 1);
|
|
68
|
+
width = Math.ceil(width + Math.min(increase, DocumentTextUtil.MAX_FONT_FALLBACK_INCREASE));
|
|
61
69
|
}
|
|
62
70
|
let height = Math.ceil(fontSize * 1.16);
|
|
63
71
|
if ((settings === null || settings === void 0 ? void 0 : settings.width) != null) {
|
|
@@ -69,3 +77,4 @@ class DocumentTextUtil {
|
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
79
|
exports.DocumentTextUtil = DocumentTextUtil;
|
|
80
|
+
DocumentTextUtil.MAX_FONT_FALLBACK_INCREASE = 100;
|