+ let segmentedNodes = paragraphized.map((x)=>breakLineAlgorithms.segmentedNodes(x, this.attrs.defaultFrameStyle.width));
+
+ let segmentedNodesToBox = segmentedNodes.map((x)=>
+ this.segmentedNodesToFrameBoxAux(x, <FrameBox>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);
+
+
+ (<Box[]>boxesFixed.content).map((e)=>{console.log(e.y)});
+
+
+ // generate pdf
+ const doc = new PDFDocument({size: 'A4'});
+ doc.pipe(fs.createWriteStream('output.pdf'));
+ this.grid(doc);
+
+ let styleCache : any = {};
+ let fontPairCache : fontPathPSNamePair = {path : "", psName : ""};
+ await this.putText(doc, boxesFixed, <TextStyle>styleCache, fontPairCache);
+ // putChar
+ doc.end();
+
+
+ }
+
+ paragraphize(calculated : BoxesItem[]): BoxesItem[][]{
+ var res : BoxesItem[][] = [[]];
+ for (var i=0;i<calculated.length;i++){
+ if ("isBR" in <Box>(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;
+ }
+
+ async putText(doc : PDFKit.PDFDocument, box : Box, styleCache : TextStyle,
+ fontPairCache : fontPathPSNamePair):
+ Promise<[PDFKit.PDFDocument, TextStyle, fontPathPSNamePair]>{
+ var fontPair;
+
+
+ if (box.textStyle !== null){
+
+ if(box.textStyle == styleCache){
+ fontPair = fontPairCache;
+ }else{
+ fontPair = 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 = await this.putText(doc, box.content[k], styleCache, fontPairCache);
+ doc = tmp[0];
+ styleCache = tmp[1];
+ fontPairCache = tmp[2];
+ }
+ }else if (box.content !== null){
+ await doc.text(box.content,
+ (box.x!==null? box.x: undefined),
+ (box.y!==null? box.y: undefined));
+ }
+
+ }
+
+
+ return [doc, styleCache, fontPairCache];
+ };
+
+
+
+ private grid(doc: any) {
+ for (var j = 0; j < A4_IN_PX.width; j += 5) {
+ if (j % 50 == 0) {
+ doc.save().fill('#000000')
+ .fontSize(8).text(j.toString(), j*0.75, 50);
+
+ doc
+ .save()
+ .lineWidth(0.4)
+ .strokeColor("#dddddd")
+ .moveTo(j*0.75, 0)
+ .lineTo(j*0.75, 1000)
+ .stroke();
+ }
+
+ doc
+ .save()
+ .lineWidth(0.2)
+ .strokeColor("#dddddd")
+ .moveTo(j*0.75, 0)
+ .lineTo(j*0.75, 1000)
+ .stroke();
+ }
+
+ for (var i = 0; i < 1050; i += 5) {
+ if (i % 50 == 0) {
+ doc.save()
+ .fontSize(8).text(i.toString(), 50, i*0.75);
+
+ doc
+ .save()
+ .lineWidth(0.4)
+ .strokeColor("#bbbbbb")
+ .moveTo(0, i*0.75)
+ .lineTo(1000, i*0.75)
+ .stroke();
+ }
+ doc
+ .save()
+ .lineWidth(0.2)
+ .strokeColor("#bbbbbb")
+ .moveTo(0, i*0.75)
+ .lineTo(1000, i*0.75)
+ .stroke();
+ }
+ doc
+ .save()
+ .moveTo(0, 200)
+ .lineTo(1000, 200)
+ .fill('#FF3300');