+/**
+ * calculate the text width and Height with a given `TextStyle`
+ * @param preprocessed
+ * @param defaultFontStyle
+ */
+function calculateTextWidthHeightAux(element, style) {
+ return __awaiter(this, void 0, void 0, function* () {
+ var result = [];
+ let fontPair = (0, canva_1.fontStyleTofont)(style);
+ if (fontPair.path.match(/\.ttc$/)) {
+ var font = yield fontkit.openSync(fontPair.path, fontPair.psName);
+ }
+ else {
+ var font = yield fontkit.openSync(fontPair.path);
+ }
+ if (!Array.isArray(element)) {
+ var run = font.layout(element, undefined, undefined, undefined, "ltr");
+ for (var j = 0; j < run.glyphs.length; j++) {
+ let runGlyphsItem = run.glyphs[j];
+ let item = {
+ x: null,
+ y: null,
+ textStyle: style,
+ direction: Direction.LTR,
+ width: (runGlyphsItem.advanceWidth) * (style.size) / 1000,
+ height: (runGlyphsItem.bbox.maxY - runGlyphsItem.bbox.minY) * (style.size) / 1000,
+ content: element[j],
+ minX: runGlyphsItem.bbox.minX,
+ maxX: runGlyphsItem.bbox.maxX,
+ minY: runGlyphsItem.bbox.minY,
+ maxY: runGlyphsItem.bbox.maxY
+ };
+ result.push(item);
+ }
+ return result;
+ }
+ else if (element[0] == "bp") {
+ var beforeNewLine = yield calculateTextWidthHeightAux(element[1], style);
+ if (Array.isArray(beforeNewLine)) {
+ beforeNewLine = beforeNewLine.flat();
+ }
+ let afterNewLine = yield calculateTextWidthHeightAux(element[2], style);
+ if (Array.isArray(afterNewLine)) {
+ afterNewLine = afterNewLine.flat();
+ }
+ let breakPointNode = {
+ original: beforeNewLine,
+ newLined: afterNewLine,
+ };
+ return breakPointNode;
+ }
+ else if (element[0] == "hglue" && !Array.isArray(element[1])) {
+ let hGlue = { stretchFactor: parseFloat(element[1]) };
+ return hGlue;
+ }
+ else {
+ return calculateTextWidthHeight(element, style);
+ }
+ });
+}
+exports.calculateTextWidthHeightAux = calculateTextWidthHeightAux;