Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
a-doc-editor
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ramdayal Munda
a-doc-editor
Commits
50f40c47
Commit
50f40c47
authored
Dec 12, 2023
by
ramdayalmunda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
multiple pages fix
parent
92eac048
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
40 deletions
+49
-40
a-doc-editor.js
dist/assets/a-doc-editor.js
+49
-40
No files found.
dist/assets/a-doc-editor.js
View file @
50f40c47
...
...
@@ -181,7 +181,7 @@ var ADocEditor = function (customConfig) {
// to calculate the lines
let
dataLineArr
=
[]
function
getLineObj
(){
function
getLineObj
()
{
return
{
id
:
++
counter
,
x
:
0
,
// this is the starting point x; it will change based on the tabNumber
...
...
@@ -193,44 +193,40 @@ var ADocEditor = function (customConfig) {
dataSetIndex
:
dataSetIndex
,
charStartIndex
:
0
,
// index from where to check
charEndIndex
:
0
,
// index till where to check// not including this index.
}
}
if
(
!
dataBlock
.
formatedText
)
dataBlock
.
formatedText
=
[]
let
lineObj
=
new
getLineObj
()
dataLineArr
.
push
(
lineObj
)
dataLineArr
.
push
(
lineObj
)
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
tempLineWidth
=
0
;
let
maxLineWidth
=
config
.
pageSetup
.
canvasWidth
let
i
=
0
for
(
i
=
0
;
i
<
dataBlock
.
plainContent
.
length
;
i
++
)
{
let
i
=
0
for
(
i
=
0
;
i
<
dataBlock
.
plainContent
.
length
;
i
++
)
{
let
style
=
dataBlock
?.
formatedText
?.[
i
]
if
(
!
style
)
style
=
JSON
.
parse
(
JSON
.
stringify
(
config
.
style
)
)
if
(
/
\s
/
.
test
(
dataBlock
.
plainContent
[
i
])
)
{
if
(
!
style
)
style
=
JSON
.
parse
(
JSON
.
stringify
(
config
.
style
)
)
if
(
/
\s
/
.
test
(
dataBlock
.
plainContent
[
i
]))
{
wordEndIndex
=
i
lineObj
.
charEndIndex
=
wordEndIndex
;
}
let
charWidth
=
getCharacterWidth
(
canvasIndex
,
dataBlock
.
plainContent
[
i
],
style
)
let
charWidth
=
getCharacterWidth
(
canvasIndex
,
dataBlock
.
plainContent
[
i
],
style
)
dataBlock
.
formatedText
[
i
]
=
{
...
config
.
style
,
width
:
charWidth
}
if
(
i
==
0
){
style
.
bold
=
true
;
//render problem
dataBlock
.
formatedText
[
0
].
bold
=
true
}
lineObj
.
maxFontSize
=
style
.
fontSize
tempLineWidth
+=
charWidth
if
(
tempLineWidth
<=
maxLineWidth
)
{
if
(
tempLineWidth
<=
maxLineWidth
)
{
// can be added to the line //
}
else
{
}
else
{
// cannot add this// new line should be added//
i
=
wordEndIndex
;
lineObj
.
plainContent
=
dataBlock
.
plainContent
.
slice
(
lineObj
.
charStartIndex
,
lineObj
.
charEndIndex
)
lineObj
.
plainContent
=
dataBlock
.
plainContent
.
slice
(
lineObj
.
charStartIndex
,
lineObj
.
charEndIndex
)
lineObj
=
new
getLineObj
()
lineObj
.
charStartIndex
=
i
lineObj
.
charEndIndex
=
i
...
...
@@ -244,48 +240,58 @@ var ADocEditor = function (customConfig) {
// break
// }
}
lineObj
.
plainContent
=
dataBlock
.
plainContent
.
slice
(
lineObj
.
charStartIndex
,
lineObj
.
charEndIndex
)
lineObj
.
plainContent
=
dataBlock
.
plainContent
.
slice
(
lineObj
.
charStartIndex
,
lineObj
.
charEndIndex
)
// 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
){
lineObj
.
charEndIndex
=
dataBlock
.
plainContent
.
length
-
1
if
(
lineObj
.
charEndIndex
<=
dataBlock
.
plainContent
.
length
)
{
lineObj
.
charEndIndex
=
dataBlock
.
plainContent
.
length
-
1
}
lineObj
.
plainContent
=
dataBlock
.
plainContent
.
slice
(
lineObj
.
charStartIndex
,
lineObj
.
charEndIndex
)
lineObj
.
plainContent
=
dataBlock
.
plainContent
.
slice
(
lineObj
.
charStartIndex
,
lineObj
.
charEndIndex
)
lines
.
push
(
...
dataLineArr
)
lines
.
push
(
...
dataLineArr
)
ctx
.
restore
()
return
true
}
function
renderTheLines
(){
let
canvas
=
canvasList
[
0
].
el
ctx
=
canvas
.
getContext
(
'2d'
,
{
willReadFrequently
:
true
})
function
renderTheLines
()
{
let
canvas
Index
=
0
let
ctx
=
canvasList
[
canvasIndex
].
el
.
getContext
(
'2d'
,
{
willReadFrequently
:
true
})
let
x
=
0
let
y
=
0
for
(
let
l
=
0
;
l
<
lines
.
length
;
l
++
)
{
for
(
let
l
=
0
;
l
<
lines
.
length
;
l
++
)
{
x
=
0
y
+=
lines
[
l
].
maxFontSize
let
setData
=
dataSet
[
lines
[
l
].
dataSetIndex
]
for
(
let
c
=
lines
[
l
].
charStartIndex
;
c
<
lines
[
l
].
charEndIndex
;
c
++
){
let
char
=
setData
?.
plainContent
[
c
]
if
(
char
){
if
(
canvasList
[
canvasIndex
].
el
.
height
<=
y
)
{
canvasIndex
++
if
(
!
canvasList
[
canvasIndex
])
{
canvasList
[
canvasIndex
]
=
{
id
:
++
counter
,
el
:
createCanvas
(),
dataIndex
:
lines
[
l
].
dataSetIndex
,
lineIndex
:
l
}
ctx
=
canvasList
[
canvasIndex
].
el
.
getContext
(
'2d'
,
{
willReadFrequently
:
true
})
}
y
=
lines
[
l
].
maxFontSize
}
lines
[
l
].
y
=
y
lines
[
l
].
x
=
x
let
setData
=
dataSet
[
lines
[
l
].
dataSetIndex
]
for
(
let
c
=
lines
[
l
].
charStartIndex
;
c
<
lines
[
l
].
charEndIndex
;
c
++
)
{
let
char
=
setData
?.
plainContent
[
c
]
if
(
char
)
{
let
style
=
setData
.
formatedText
[
c
]
ctx
.
save
()
ctx
.
font
=
`
${
style
?.
bold
?
'bold '
:
''
}
$
{
style
?.
italic
?
'italic '
:
''
}
$
{
style
.
fontSize
}
px
$
{
style
.
fontFamily
}
`
ctx
.
font
=
`
${
style
?.
bold
?
'bold '
:
''
}
$
{
style
?.
italic
?
'italic '
:
''
}
$
{
style
.
fontSize
}
px
$
{
style
.
fontFamily
}
`
ctx.fillStyle = `
$
{
style
?.
fontColor
}
`
ctx.fillText(
char, x,y
)
ctx.fillText(
char, x, y
)
setData.formatedText[c].x = x
setData.formatedText[c].y = y
ctx.restore()
if (setData.formatedText[c]?.width){
if (setData.formatedText[c]?.width)
{
x += setData.formatedText[c]?.width
}
}
}
}
console.log('dataSet', dataSet)
}
if (!caretData.blink && caretData.activeData) renderCaret()
...
...
@@ -293,7 +299,7 @@ var ADocEditor = function (customConfig) {
function renderCaret() {
let ctx = canvasList[caretData.canvasIndex].el.getContext('2d', { willReadFrequently: true })
ctx.save()
let rectX = 0, rectY = 0, rectWidth = 2, rectHeight = 5
*config.style.fontSize/
4;
let rectX = 0, rectY = 0, rectWidth = 2, rectHeight = 5
* config.style.fontSize /
4;
if (caretData.caretIndex == 0) {
// pick style from line
} else {
...
...
@@ -313,11 +319,11 @@ var ADocEditor = function (customConfig) {
ctx.restore()
}
function getCharacterWidth(canvasIndex, char, style){
function getCharacterWidth(canvasIndex, char, style)
{
let canvas = canvasList[canvasIndex].el
let ctx = canvas.getContext('2d', { willReadFrequently: true })
ctx.save()
ctx.font = `
$
{
style
?.
bold
?
'bold '
:
''
}
$
{
style
?.
italic
?
'italic '
:
''
}
$
{
style
.
fontSize
}
px
$
{
style
.
fontFamily
}
`
ctx.font = `
$
{
style
?.
bold
?
'bold '
:
''
}
$
{
style
?.
italic
?
'italic '
:
''
}
$
{
style
.
fontSize
}
px
$
{
style
.
fontFamily
}
`
ctx.fillStyle = `
$
{
style
?.
fontColor
}
`
let width = ctx.measureText(char).width
ctx.restore()
...
...
@@ -326,9 +332,12 @@ var ADocEditor = function (customConfig) {
function createCanvas() {
let canvas = document.createElement('canvas')
let ctx = canvas.getContext('2d', { willReadFrequently: true })
canvas.setAttribute('class', 'page')
canvas.width = config.pageSetup.canvasWidth
canvas.height = config.pageSetup.canvasHeight
ctx.fillStyle = config.format.background
ctx.fillRect(0, 0, canvas.width, canvas.height)
canvas.addEventListener('keydown', keydownHandler)
canvas.addEventListener('mousedown', mousedownHandler)
canvas.addEventListener("focus", onFocusHandler)
...
...
@@ -453,11 +462,11 @@ var ADocEditor = function (customConfig) {
}
renderInProgress = false
}
function removeStyles(dataList){
for (let i
=0; i<dataList.length; i++)
{
function removeStyles(dataList)
{
for (let i
= 0; i < dataList.length; i++)
{
dataList[i].formatedText = []
for
(let j=0; j<dataList[i].plainContent.length; j++)
{
dataList[i].formatedText.push(
JSON.parse( JSON.stringify( config.style ) )
)
for
(let j = 0; j < dataList[i].plainContent.length; j++)
{
dataList[i].formatedText.push(
JSON.parse(JSON.stringify(config.style))
)
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment