Commit b89d6638 by ramdayalmunda

rendering list completed

parent 05f1f83f
...@@ -17,6 +17,7 @@ var ADocEditor = function (customConfig) { ...@@ -17,6 +17,7 @@ var ADocEditor = function (customConfig) {
margin: 20, margin: 20,
border: "", border: "",
fontSize: 10, fontSize: 10,
tabWidth: 20,
}, },
style: { style: {
fontSize: 30, fontSize: 30,
...@@ -38,12 +39,15 @@ var ADocEditor = function (customConfig) { ...@@ -38,12 +39,15 @@ var ADocEditor = function (customConfig) {
type: 0, type: 0,
formatedText: [], formatedText: [],
plainContent: "", plainContent: "",
tabCount: 0,
style: { ...config.style } style: { ...config.style }
}, },
] ]
// // these lines are added only for testing please remove this on completion // // these lines are added only for testing please remove this on completion
// // paragraphs // // paragraphs
dataSet = JSON.parse( '[{"id":1,"type":0,"formatedText":[],"plainContent":"Rendering text in HTML canvas involves using the CanvasRenderingContext2D interface to display text content within a canvas element. This process allows for dynamic text display, enabling the creation of custom text effects, labels, captions, or textual elements within the canvas.","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#001"}},{"id":2,"type":0,"plainContent":"To render text on a canvas, developers typically use the fillText() method provided by the Canvas API. This method allows the specification of text content, font styles, position, and color. Additionally, the measureText() method helps in determining the width of text, facilitating accurate positioning and layout arrangements.","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#001"}},{"id":3,"type":0,"plainContent":"Text in canvas can be customized by setting various font properties like font family, font size, style (bold, italic), alignment, and color. However, canvas text rendering lacks the text reflow and responsive layout capabilities inherent in HTML and CSS.","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#001"}},{"id":4,"type":0,"plainContent":"Despite its intricacies, canvas text rendering offers unparalleled creative freedom, enabling the development of immersive graphical experiences, custom typography, and visually stunning representations that enhance user engagement and interactivity within web-based applications and games.","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#001"}},{"id":5,"type":0,"plainContent":"Developers often use canvas text rendering to create graphical representations of text-based information, such as game interfaces, data visualizations, charts, and diagrams. Despite its flexibility in text manipulation and artistic possibilities, rendering text in canvas may require additional manual adjustments for formatting, spacing, and alignment compared to traditional HTML text rendering.","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#001"}}]') dataSet = JSON.parse( '[{"id":1,"type":0,"formatedText":[],"plainContent":"Rendering text in HTML canvas involves using the CanvasRenderingContext2D interface to display text content within a canvas element. This process allows for dynamic text display, enabling the creation of custom text effects, labels, captions, or textual elements within the canvas.","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#001"}},{"id":2,"type":0,"plainContent":"To render text on a canvas, developers typically use the fillText() method provided by the Canvas API. This method allows the specification of text content, font styles, position, and color. Additionally, the measureText() method helps in determining the width of text, facilitating accurate positioning and layout arrangements.","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#001"}},{"id":3,"type":0,"plainContent":"Text in canvas can be customized by setting various font properties like font family, font size, style (bold, italic), alignment, and color. However, canvas text rendering lacks the text reflow and responsive layout capabilities inherent in HTML and CSS.","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#001"}},{"id":4,"type":0,"plainContent":"Despite its intricacies, canvas text rendering offers unparalleled creative freedom, enabling the development of immersive graphical experiences, custom typography, and visually stunning representations that enhance user engagement and interactivity within web-based applications and games.","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#001"}},{"id":5,"type":0,"plainContent":"Developers often use canvas text rendering to create graphical representations of text-based information, such as game interfaces, data visualizations, charts, and diagrams. Despite its flexibility in text manipulation and artistic possibilities, rendering text in canvas may require additional manual adjustments for formatting, spacing, and alignment compared to traditional HTML text rendering.","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#001"}}]')
// // lists
dataSet = JSON.parse('[{"id":1,"type":0,"plainContent":"Hey there buddy! Can you bring these items from the groceries please. It will be really helpfull.","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#003"},"formatedText":[]},{"id":2,"type":1,"tabCount":0,"plainContent":"Recipie book for vegetarian noodles","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#003"},"formatedText":[]},{"id":3,"type":1,"tabCount":0,"plainContent":"Noodles","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#003"},"formatedText":[]},{"id":4,"type":1,"tabCount":0,"plainContent":"Onion","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#003"},"formatedText":[]},{"id":5,"type":1,"tabCount":0,"plainContent":"Garlic","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#003"},"formatedText":[]},{"id":6,"type":1,"tabCount":0,"plainContent":"Some School stationaries for Arvind","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#003"},"formatedText":[]},{"id":7,"type":1,"tabCount":1,"plainContent":"Full pack of pen","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#003"},"formatedText":[]},{"id":8,"type":1,"tabCount":1,"plainContent":"Drawing kit","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#003"},"formatedText":[]},{"id":9,"type":1,"tabCount":1,"plainContent":"2 register size notebook","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#003"},"formatedText":[]},{"id":10,"type":1,"tabCount":0,"plainContent":"Window shields","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#003"},"formatedText":[]},{"id":11,"type":1,"tabCount":0,"plainContent":"Mosquito repelant","style":{"fontSize":30,"fontFamily":"Arial","bold":false,"italic":false,"fontColor":"#003"},"formatedText":[]}]')
var lines = [] var lines = []
...@@ -146,7 +150,6 @@ var ADocEditor = function (customConfig) { ...@@ -146,7 +150,6 @@ var ADocEditor = function (customConfig) {
} }
function reRenderPages(dataList, option) { function reRenderPages(dataList, option) {
console.clear()
if (renderInProgress) return if (renderInProgress) return
renderInProgress = true renderInProgress = true
...@@ -201,11 +204,38 @@ var ADocEditor = function (customConfig) { ...@@ -201,11 +204,38 @@ var ADocEditor = function (customConfig) {
dataLineArr.push(lineObj) dataLineArr.push(lineObj)
lineObj.type = dataBlock.type lineObj.type = dataBlock.type
lineObj.blockStart = true lineObj.blockStart = true
let lineIndex = 0
let lineFirstCharIndex = 0; // this is the index of the first character in any line;; will change inside the loop
let wordEndIndex = 0; // this stores the index of the word which can fit in the line; let wordEndIndex = 0; // this stores the index of the word which can fit in the line;
let tempLineWidth = 0; let tempLineWidth = 0;
let maxLineWidth = config.pageSetup.canvasWidth - (config.format.margin * 2 * config.pageSetup.canvasMultiplier) let maxLineWidth = config.pageSetup.canvasWidth - (config.format.margin * 2 * config.pageSetup.canvasMultiplier)
if (dataBlock.tabCount || dataBlock.type == 1){
let finalTabCount = dataBlock.tabCount
if (dataBlock.type==1){
finalTabCount++
}
let tabDistance = finalTabCount*config.format.tabWidth*config.pageSetup.canvasMultiplier
if (tabDistance>maxLineWidth*5/6){ tabDistance = 0 }
maxLineWidth = maxLineWidth-tabDistance
}
lineObj.maxLineWidth = maxLineWidth
lineObj.tabCount = dataBlock.tabCount
// // for checking the listIndex
if (dataBlock.type == 1){
for (let i=dataSetIndex-1; i>=0; i--){
if (dataList[i].type!=1){
dataBlock.listIndex = 0
break;
}else if (dataList[i].tabCount == dataBlock.tabCount){
dataBlock.listIndex = dataList[i].listIndex+1
break
}else if (dataList[i].tabCount<dataBlock.tabCount){
dataBlock.listIndex = 0
break;
}
}
}
lineObj.listIndex = dataBlock.listIndex
let i = 0 let i = 0
for (i = 0; i < dataBlock.plainContent.length; i++) { for (i = 0; i < dataBlock.plainContent.length; i++) {
let style = dataBlock?.formatedText?.[i] let style = dataBlock?.formatedText?.[i]
...@@ -229,8 +259,11 @@ var ADocEditor = function (customConfig) { ...@@ -229,8 +259,11 @@ var ADocEditor = function (customConfig) {
// cannot add this// new line should be added// // cannot add this// new line should be added//
i = wordEndIndex; i = wordEndIndex;
lineObj.plainContent = dataBlock.plainContent.slice(lineObj.charStartIndex, lineObj.charEndIndex) lineObj.plainContent = dataBlock.plainContent.slice(lineObj.charStartIndex, lineObj.charEndIndex+1)
lineObj = new getLineObj() lineObj = new getLineObj()
lineObj.listIndex = dataBlock.listIndex
lineObj.maxLineWidth = maxLineWidth
lineObj.tabCount = dataBlock.tabCount
lineObj.charStartIndex = i lineObj.charStartIndex = i
lineObj.charEndIndex = i lineObj.charEndIndex = i
dataLineArr.push(lineObj) dataLineArr.push(lineObj)
...@@ -238,7 +271,7 @@ var ADocEditor = function (customConfig) { ...@@ -238,7 +271,7 @@ var ADocEditor = function (customConfig) {
} }
} }
lineObj.plainContent = dataBlock.plainContent.slice(lineObj.charStartIndex, lineObj.charEndIndex) lineObj.plainContent = dataBlock.plainContent.slice(lineObj.charStartIndex, lineObj.charEndIndex+1)
// there is chance that the last line is not at the width// so we need to handle the last line separately // there is chance that the last line is not at the width// so we need to handle the last line separately
if (lineObj.charEndIndex <= dataBlock.plainContent.length) { if (lineObj.charEndIndex <= dataBlock.plainContent.length) {
lineObj.charEndIndex = dataBlock.plainContent.length - 1 lineObj.charEndIndex = dataBlock.plainContent.length - 1
...@@ -260,6 +293,8 @@ var ADocEditor = function (customConfig) { ...@@ -260,6 +293,8 @@ var ADocEditor = function (customConfig) {
let maxVericalWidth = (config.pageSetup.canvasHeight - config.format.margin * config.pageSetup.canvasMultiplier * 2) let maxVericalWidth = (config.pageSetup.canvasHeight - config.format.margin * config.pageSetup.canvasMultiplier * 2)
for (let l = 0; l < lines.length; l++) { for (let l = 0; l < lines.length; l++) {
x = (config.format.margin * config.pageSetup.canvasMultiplier); x = (config.format.margin * config.pageSetup.canvasMultiplier);
y += lines[l].maxFontSize y += lines[l].maxFontSize
if (lines[l].blockStart && l != 0) y += lines[l].maxFontSize if (lines[l].blockStart && l != 0) y += lines[l].maxFontSize
if ((maxVericalWidth + lines[l].maxFontSize) < (y - lines[l].maxFontSize)) { if ((maxVericalWidth + lines[l].maxFontSize) < (y - lines[l].maxFontSize)) {
...@@ -270,11 +305,30 @@ var ADocEditor = function (customConfig) { ...@@ -270,11 +305,30 @@ var ADocEditor = function (customConfig) {
ctx = canvasList[canvasIndex].el.getContext('2d', { willReadFrequently: true }) ctx = canvasList[canvasIndex].el.getContext('2d', { willReadFrequently: true })
y = lines[l].maxFontSize + (config.format.margin * config.pageSetup.canvasMultiplier) y = lines[l].maxFontSize + (config.format.margin * config.pageSetup.canvasMultiplier)
} }
let setData = dataSet[lines[l].dataSetIndex]
lines[l].y = y lines[l].y = y
if (lines[l].listIndex>=0){
let totalTabDistance = config.format.tabWidth*config.pageSetup.canvasMultiplier*(lines[l].tabCount+1)
x += totalTabDistance;
let numberX = x - config.format.tabWidth*config.pageSetup.canvasMultiplier/2
if (lines[l].blockStart){
let style = {
...config.style,
...setData.style
}
ctx.save()
ctx.fillStyle = `${style.fontColor}`
ctx.font = `${style.bold?'bold ':''}${style.italic?'italic ':''} ${style.fontSize}px ${style.fontFamily}`
ctx.fillText(`${lines[l].listIndex+1}.`, numberX,y)
ctx.restore()
}
}
lines[l].x = x lines[l].x = x
lines[l].canvasIndex = canvasIndex lines[l].canvasIndex = canvasIndex
let setData = dataSet[lines[l].dataSetIndex]
for (let c = lines[l].charStartIndex; c <= lines[l].charEndIndex; c++) { for (let c = lines[l].charStartIndex; c <= lines[l].charEndIndex; c++) {
let char = setData?.plainContent[c] let char = setData?.plainContent[c]
if (char) { if (char) {
......
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