+ let segmentedNodes = paragraphized.map((x) => breakLineAlgorithms.segmentedNodes(x, this.attrs.defaultFrameStyle.width));
+ let segmentedNodesToBox = segmentedNodes.map((x) => this.segmentedNodesToFrameBoxAux(x, this.attrs.defaultFrameStyle));
+ let boxWithParagraph = putInVBox(segmentedNodesToBox, this.attrs.defaultFrameStyle);
+ console.log(boxWithParagraph);
+ // fix the bug of main Frame x & y
+ if (boxWithParagraph.x !== null) {
+ boxWithParagraph.x *= 0.75;
+ }
+ if (boxWithParagraph.y !== null) {
+ boxWithParagraph.y *= 0.75;
+ }
+ let boxesFixed = this.fixenBoxesPosition(boxWithParagraph);
+ boxesFixed.content.map((e) => { console.log(e.y); });
+ // generate pdf
+ const doc = new PDFDocument({ size: 'A4' });
+ // let fsMemory = memfs();
+ doc.pipe(memfs_1.vol.createWriteStream('output.pdf'));
+ this.grid(doc);
+ let styleCache = {};
+ let fontPairCache = { path: "", psName: "" };
+ yield this.putText(doc, boxesFixed, styleCache, fontPairCache);
+ // putChar
+ doc.end();
+ });
+ }
+ paragraphize(calculated) {
+ var res = [[]];
+ for (var i = 0; i < calculated.length; i++) {
+ if ("isBR" in (calculated[i])) {
+ res[res.length - 1] = res[res.length - 1].concat(calculated[i]);
+ res.push([]);
+ }
+ else {
+ res[res.length - 1] = res[res.length - 1].concat(calculated[i]);
+ }
+ }
+ res = res.filter((x) => x.length !== 0);
+ return res;
+ }
+ putText(doc, box, styleCache, fontPairCache) {
+ return __awaiter(this, void 0, void 0, function* () {
+ var fontPair;
+ if (box.textStyle !== null) {
+ if (box.textStyle == styleCache) {
+ fontPair = fontPairCache;
+ }
+ else {
+ fontPair = (0, canva_1.fontStyleTofont)(box.textStyle);
+ styleCache = box.textStyle;
+ fontPairCache = fontPair;
+ let textColor = box.textStyle.color;
+ if (fontPair.path.match(/\.ttc$/g)) {
+ doc
+ .fillColor(textColor !== undefined ? textColor : "#000000")
+ .font(fontPair.path, fontPair.psName)
+ .fontSize(box.textStyle.size * 0.75);
+ }
+ else {
+ doc
+ .fillColor(textColor !== undefined ? textColor : "#000000")
+ .font(fontPair.path)
+ .fontSize(box.textStyle.size * 0.75); // 0.75 must added!
+ }
+ }
+ if (box.textStyle.color !== undefined) {
+ doc.fill(box.textStyle.color);
+ }
+ if (Array.isArray(box.content)) {
+ for (var k = 0; k < box.content.length; k++) {
+ let tmp = yield this.putText(doc, box.content[k], styleCache, fontPairCache);
+ doc = tmp[0];
+ styleCache = tmp[1];
+ fontPairCache = tmp[2];
+ }
+ }
+ else if (box.content !== null) {
+ yield doc.text(box.content, (box.x !== null ? box.x : undefined), (box.y !== null ? box.y : undefined));
+ }
+ }
+ return [doc, styleCache, fontPairCache];