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
22cae6ee
Commit
22cae6ee
authored
Jan 10, 2024
by
ramdayalmunda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
margin and padding added on the text written
parent
aeefff86
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
19 deletions
+20
-19
a-doc-editor2.js
dist/assets/a-doc-editor2.js
+19
-18
index.html
dist/index.html
+1
-1
No files found.
dist/assets/a-doc-editor2.js
View file @
22cae6ee
...
@@ -9,12 +9,12 @@ var ADocEditor = function (customConfig) {
...
@@ -9,12 +9,12 @@ var ADocEditor = function (customConfig) {
pageSetup
:
{
size
:
"A4"
},
zoom
:
1
,
pageSetup
:
{
size
:
"A4"
},
zoom
:
1
,
format
:
{
format
:
{
background
:
"#fff"
,
background
:
"#fff"
,
margin
:
20
,
margin
:
20
,
// mm
border
:
""
,
border
:
""
,
tabWidth
:
20
,
tabWidth
:
20
,
// mm
},
},
style
:
{
style
:
{
fontSize
:
1
00
,
fontSize
:
1
6
,
// this is in mm
fontFamily
:
'Calibri'
,
fontFamily
:
'Calibri'
,
bold
:
false
,
bold
:
false
,
italic
:
false
,
italic
:
false
,
...
@@ -199,7 +199,7 @@ var ADocEditor = function (customConfig) {
...
@@ -199,7 +199,7 @@ var ADocEditor = function (customConfig) {
function
calculateTextSizeAndPosition
()
{
function
calculateTextSizeAndPosition
()
{
let
d
=
0
,
c
=
0
;
let
d
=
0
,
c
=
0
;
function
getLineObj
()
{
function
getLineObj
()
{
let
newLineObj
=
{
let
newLineObj
=
{
...
@@ -224,25 +224,25 @@ var ADocEditor = function (customConfig) {
...
@@ -224,25 +224,25 @@ var ADocEditor = function (customConfig) {
// to calculate the lines
// to calculate the lines
let
tempLineWidth
=
0
;
let
tempLineWidth
=
0
;
let
maxLineWidth
=
config
.
pageSetup
.
pxWidth
-
(
config
.
format
.
margin
*
config
.
pageSetup
.
pxWidth
*
2
)
/
100
let
maxLineWidth
=
config
.
pageSetup
.
pxWidth
-
(
config
.
format
.
margin
*
pxMmRatio
*
2
)
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;
for
(
c
=
0
;
c
<
dataBlock
.
plainContent
.
length
;
c
++
)
{
for
(
c
=
0
;
c
<
dataBlock
.
plainContent
.
length
;
c
++
)
{
let
style
=
dataBlock
?.
formatedText
?.[
d
]
let
style
=
dataBlock
?.
formatedText
?.[
c
]
if
(
/
\s
/
.
test
(
dataBlock
.
plainContent
[
c
]))
{
if
(
/
\s
/
.
test
(
dataBlock
.
plainContent
[
c
]))
{
wordEndIndex
=
c
wordEndIndex
=
c
lineObj
.
charEndIndex
=
c
lineObj
.
charEndIndex
=
c
}
}
let
charWidth
=
getCharacterWidth
(
d
,
dataBlock
.
plainContent
[
c
],
style
)
let
charWidth
=
getCharacterWidth
(
d
ataBlock
.
plainContent
[
c
],
style
)
dataBlock
.
formatedText
[
c
]
=
{
dataBlock
.
formatedText
[
c
]
=
{
...
config
.
style
,
...
config
.
style
,
...
style
,
...
style
,
width
:
charWidth
width
:
charWidth
}
}
tempLineWidth
+=
charWidth
tempLineWidth
+=
charWidth
if
(
tempLineWidth
>
maxLineWidth
){
if
(
tempLineWidth
>
maxLineWidth
)
{
// 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
+
1
)
lineObj
.
plainContent
=
dataBlock
.
plainContent
.
slice
(
lineObj
.
charStartIndex
,
lineObj
.
charEndIndex
+
1
)
lines
.
push
(
lineObj
)
lines
.
push
(
lineObj
)
lineObj
=
new
getLineObj
()
lineObj
=
new
getLineObj
()
...
@@ -275,21 +275,21 @@ var ADocEditor = function (customConfig) {
...
@@ -275,21 +275,21 @@ var ADocEditor = function (customConfig) {
function
renderLines
()
{
function
renderLines
()
{
console
.
log
(
'render lines'
,
lines
)
console
.
log
(
'render lines'
,
lines
)
let
x
=
0
,
y
=
0
;
let
x
=
0
,
y
=
config
.
format
.
margin
*
pxMmRatio
;
for
(
let
l
=
0
;
l
<
lines
.
length
;
l
++
)
{
for
(
let
l
=
0
;
l
<
lines
.
length
;
l
++
)
{
let
ctx
=
pageList
[
0
].
el
.
getContext
(
'2d'
,
{
willReadFrequently
:
true
})
let
ctx
=
pageList
[
0
].
el
.
getContext
(
'2d'
,
{
willReadFrequently
:
true
})
console
.
log
(
lines
[
l
])
console
.
log
(
lines
[
l
])
x
=
0
x
=
config
.
format
.
margin
*
pxMmRatio
y
=
y
+
lines
[
l
].
maxFontSize
y
=
y
+
(
lines
[
l
].
maxFontSize
*
pxMmRatio
)
ctx
.
save
()
ctx
.
save
()
let
setData
=
dataList
[
lines
[
l
].
dataIndex
]
let
setData
=
dataList
[
lines
[
l
].
dataIndex
]
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
)
{
let
style
=
setData
.
formatedText
[
c
]
let
style
=
setData
.
formatedText
[
c
]
ctx
.
save
()
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
*
pxMmRatio
}
px
$
{
style
.
fontFamily
}
`
ctx.fillStyle = `
$
{
style
?.
fontColor
}
`
ctx.fillStyle = `
$
{
style
?.
fontColor
}
`
ctx.fillText(char, x, y)
ctx.fillText(char, x, y)
setData.formatedText[c].x = x
setData.formatedText[c].x = x
...
@@ -352,11 +352,12 @@ var ADocEditor = function (customConfig) {
...
@@ -352,11 +352,12 @@ var ADocEditor = function (customConfig) {
renderCaret()
renderCaret()
}, caretData.timeoutDuration)
}, caretData.timeoutDuration)
}
}
function getCharacterWidth(canvasIndex, char, style) {
function getCharacterWidth(char, style) {
let canvas = pageList[canvasIndex].el
console.log('style', style)
let canvas = pageList[0].el
let ctx = canvas.getContext('2d', { willReadFrequently: true })
let ctx = canvas.getContext('2d', { willReadFrequently: true })
ctx.save()
ctx.save()
ctx.font = `
$
{
style
?.
bold
?
'bold '
:
''
}
$
{
style
?.
italic
?
'italic '
:
''
}
$
{
style
.
fontSize
*
config
.
pageSetup
.
multipler
}
px
$
{
style
.
fontFamily
}
`
ctx.font = `
$
{
style
?.
bold
?
'bold '
:
''
}
$
{
style
?.
italic
?
'italic '
:
''
}
$
{
style
.
fontSize
*
pxMmRatio
}
px
$
{
style
.
fontFamily
}
`
ctx.fillStyle = `
$
{
style
?.
fontColor
}
`
ctx.fillStyle = `
$
{
style
?.
fontColor
}
`
let width = ctx.measureText(char).width
let width = ctx.measureText(char).width
ctx.restore()
ctx.restore()
...
...
dist/index.html
View file @
22cae6ee
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
</head>
</head>
<body>
<body>
<div
class=
"body"
></div>
<div
class=
"body"
></div>
<p
>
Click on the
<span
style=
"font-family: 'customfont';"
>
canvas
</span>
and start typing
<p
style=
"font-family: 'Calibri';"
>
Click on the
<span
>
canvas
</span>
and start typing
<button
onclick=
"extractData()"
>
Extract
</button>
<button
onclick=
"extractData()"
>
Extract
</button>
<button
onclick=
"setData()"
>
Set Data
</button>
<button
onclick=
"setData()"
>
Set Data
</button>
<button
onclick=
"generatePDF()"
>
Generate PDF
</button>
<button
onclick=
"generatePDF()"
>
Generate PDF
</button>
...
...
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