@contrail/documents 1.0.97 → 1.0.99
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/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/types/document-element.d.ts +4 -2
- package/lib/util/measure-text/measure-text.d.ts +5 -0
- package/lib/util/measure-text/measure-text.js +53 -0
- package/lib/util/measure-text/widths-map.d.ts +1651 -0
- package/lib/util/measure-text/widths-map.js +1654 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -20,3 +20,4 @@ __exportStar(require("./document-element-factory"), exports);
|
|
|
20
20
|
__exportStar(require("./document-element-property-binding-handler"), exports);
|
|
21
21
|
__exportStar(require("./document-element-component-size-handler"), exports);
|
|
22
22
|
__exportStar(require("./document-action"), exports);
|
|
23
|
+
__exportStar(require("./util/measure-text/measure-text"), exports);
|
|
@@ -28,15 +28,17 @@ export interface DocumentElement extends Document {
|
|
|
28
28
|
documentGenerationConfigId?: string;
|
|
29
29
|
entityData?: any;
|
|
30
30
|
points?: Array<[number, number]>;
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
rowIds?: Array<string>;
|
|
32
|
+
columnIds?: Array<string>;
|
|
33
33
|
columnId?: string;
|
|
34
34
|
rowId?: string;
|
|
35
|
+
tableId?: string;
|
|
35
36
|
propertyBindingsMetaData?: {
|
|
36
37
|
displayFunction: string;
|
|
37
38
|
propertyType: string;
|
|
38
39
|
typeId?: string;
|
|
39
40
|
numberFormat?: any;
|
|
40
41
|
dateFormat?: any;
|
|
42
|
+
displayLabel?: boolean;
|
|
41
43
|
};
|
|
42
44
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const widths_map_1 = require("./widths-map");
|
|
4
|
+
const settingsDefaults = { fontFamily: 'Arial', fontSize: 14 };
|
|
5
|
+
const measureText = (string, settings) => {
|
|
6
|
+
if (string === null || string === undefined) {
|
|
7
|
+
return { width: 0, height: 0 };
|
|
8
|
+
}
|
|
9
|
+
const sett = Object.assign(Object.assign({}, settingsDefaults), settings);
|
|
10
|
+
let font = sett.fontFamily.toLowerCase();
|
|
11
|
+
const fontSize = sett.fontSize;
|
|
12
|
+
const variant = 0 + (sett.bold ? 1 : 0) + (sett.italic ? 2 : 0);
|
|
13
|
+
const map = sett.map || widths_map_1.WIDTHS_MAP;
|
|
14
|
+
const available = Object.keys(map);
|
|
15
|
+
if (available.indexOf(font) === -1) {
|
|
16
|
+
font = 'arial';
|
|
17
|
+
}
|
|
18
|
+
let totalWidth = 0;
|
|
19
|
+
let lines = 1;
|
|
20
|
+
let lineWidth = 0;
|
|
21
|
+
const str = string.toString().normalize('NFD');
|
|
22
|
+
const words = str.split(/(\s|-)/);
|
|
23
|
+
const fixedWidth = settings.width ? (settings.width * 100) / fontSize : null;
|
|
24
|
+
words.forEach((word, index) => {
|
|
25
|
+
let wordWidth = 0;
|
|
26
|
+
word.split('').forEach((char) => {
|
|
27
|
+
if (/[\x00-\x1F]/.test(char)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
const widths = map[font][char] || map[font].x;
|
|
31
|
+
const width = widths[variant];
|
|
32
|
+
totalWidth += width;
|
|
33
|
+
wordWidth += width;
|
|
34
|
+
return true;
|
|
35
|
+
});
|
|
36
|
+
if (fixedWidth != null) {
|
|
37
|
+
lineWidth = lineWidth + wordWidth;
|
|
38
|
+
if (lineWidth > fixedWidth) {
|
|
39
|
+
lineWidth = wordWidth % fixedWidth;
|
|
40
|
+
lines = (index === 0 ? 0 : lines) + Math.max(1, Math.ceil(wordWidth / fixedWidth));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
let width = Math.ceil(totalWidth * (fontSize / 100));
|
|
45
|
+
let height = Math.ceil(fontSize * 1.16);
|
|
46
|
+
if ((settings === null || settings === void 0 ? void 0 : settings.width) != null) {
|
|
47
|
+
width = settings.width;
|
|
48
|
+
height = height * lines;
|
|
49
|
+
}
|
|
50
|
+
height = height + 1 * ((settings === null || settings === void 0 ? void 0 : settings.scale) || 1);
|
|
51
|
+
return { width, height };
|
|
52
|
+
};
|
|
53
|
+
exports.default = measureText;
|