Commit c8ab7bc6 by ramdayalmunda

creating new page if text in the last line of the current page is too big

parent 7a2a2c90
...@@ -252,21 +252,30 @@ var ADocEditor = function (customConfig) { ...@@ -252,21 +252,30 @@ var ADocEditor = function (customConfig) {
let dataBlock = dataSet[j] let dataBlock = dataSet[j]
if ( dataBlock.style.y - pageYOffset>= config.pageSetup.canvasHeight ){ if ( dataBlock.style.y - pageYOffset>= config.pageSetup.canvasHeight ){
pageYOffset = dataBlock.style.y - dataBlock.style.fontSize pageYOffset = dataBlock.style.y - dataBlock.style.fontSize; ; // calculate and use the max Font size on the current line in the formattedText array
canvasIndex++; canvasIndex++;
if (!canvasList[canvasIndex]) canvasList[canvasIndex] = { id: ++counter, el: createCanvas(), dataIndex: j } if (!canvasList[canvasIndex]) canvasList[canvasIndex] = { id: ++counter, el: createCanvas(), dataIndex: j }
} }
let ctx = canvasList[canvasIndex].el.getContext('2d', { willReadFrequently: true }) let ctx = canvasList[canvasIndex].el.getContext('2d', { willReadFrequently: true })
ctx.save() ctx.save()
dataBlock.style.canvasIndex = canvasIndex dataBlock.style.canvasIndex = canvasIndex
for (let i = 0; i < dataBlock.formatedText.length; i++) { for (let i = 0; i < dataBlock.formatedText.length; i++) {
if ( dataBlock.formatedText[i].y - pageYOffset>= config.pageSetup.canvasHeight ){
ctx.restore()
pageYOffset = dataBlock.formatedText[i].y - dataBlock.style.fontSize; // calculate and use the max Font size on the current line in the formattedText array
canvasIndex++;
if (!canvasList[canvasIndex]) canvasList[canvasIndex] = { id: ++counter, el: createCanvas(), dataIndex: j }
ctx = canvasList[canvasIndex].el.getContext('2d', { willReadFrequently: true })
ctx.save()
}
ctx.font = `${dataBlock.formatedText[i].fontSize}px ${dataBlock.formatedText[i].fontFamily}` ctx.font = `${dataBlock.formatedText[i].fontSize}px ${dataBlock.formatedText[i].fontFamily}`
ctx.fillStyle = dataBlock.formatedText[i].fontColor ctx.fillStyle = dataBlock.formatedText[i].fontColor
ctx.fillText(dataBlock.formatedText[i].char, dataBlock.formatedText[i].x, (dataBlock.formatedText[i].y-pageYOffset)) dataBlock.formatedText[i].canvasX = dataBlock.formatedText[i].x
dataBlock.formatedText[i].canvasY = (dataBlock.formatedText[i].y-pageYOffset)
ctx.fillText(dataBlock.formatedText[i].char, dataBlock.formatedText[i].canvasX, dataBlock.formatedText[i].canvasY)
dataBlock.formatedText[i].canvasIndex = canvasIndex dataBlock.formatedText[i].canvasIndex = canvasIndex
} }
ctx.restore() ctx.restore()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment