Commit 7a2a2c90 by ramdayalmunda

user can now add more letter on the same line and it would wrap to the next…

user can now add more letter on the same line and it would wrap to the next line: Issue: looping with last character fixed
parent e042810a
......@@ -186,13 +186,16 @@ var ADocEditor = function (customConfig) {
let maxWidth = config.pageSetup.canvasWidth
let wordEndIndex = 0
let wordsLength = 0;
let sentenceLength = 0;
let wordsWidth = 0
dataBlock.formatedText = []
for (let i = 0; i < dataBlock.plainContent.length; i++) {
let blankSpace = false
if (/\s+/.test(dataBlock.plainContent[i])) {
wordEndIndex = i
wordsWidth = 0
blankSpace = true
}
......@@ -215,11 +218,21 @@ var ADocEditor = function (customConfig) {
}
x += charWidth
if (wordsLength + charWidth <= maxWidth) {
wordsLength += charWidth
wordsWidth+= blankSpace?0:charWidth
if (wordsWidth>=maxWidth){
wordEndIndex = i-1
sentenceLength = 0
wordsWidth = 0
y += style.fontSize
x = 0;
i=wordEndIndex
}
if (sentenceLength + charWidth <= maxWidth) {
sentenceLength += charWidth
} else {
i = wordEndIndex
wordsLength = 0
sentenceLength = 0
wordsWidth = 0
y += style.fontSize
x = 0;
......@@ -248,10 +261,13 @@ var ADocEditor = function (customConfig) {
let ctx = canvasList[canvasIndex].el.getContext('2d', { willReadFrequently: true })
ctx.save()
dataBlock.style.canvasIndex = canvasIndex
for (let i = 0; i < dataBlock.formatedText.length; i++) {
ctx.font = `${dataBlock.formatedText[i].fontSize}px ${dataBlock.formatedText[i].fontFamily}`
ctx.fillStyle = dataBlock.formatedText[i].fontColor
ctx.fillText(dataBlock.formatedText[i].char, dataBlock.formatedText[i].x, (dataBlock.formatedText[i].y-pageYOffset))
dataBlock.formatedText[i].canvasIndex = canvasIndex
}
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