Skip to content

Commit c73a8f9

Browse files
committed
chore: replace page width and height by canvas width and height
Signed-off-by: Vitor Mattos <vitor@php.rio>
1 parent 15d8379 commit c73a8f9

File tree

5 files changed

+34
-25
lines changed

5 files changed

+34
-25
lines changed

src/Components/Drawing.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ export default {
5858
'x',
5959
'y',
6060
'pageScale',
61-
'pageWidth',
62-
'pageHeight',
61+
'canvasWidth',
62+
'canvasHeight',
6363
'path',
6464
],
6565
data() {

src/Components/Image.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ export default {
7474
'x',
7575
'y',
7676
'pageScale',
77-
'pageWidth',
78-
'pageHeight',
77+
'canvasWidth',
78+
'canvasHeight',
7979
'fixSize',
8080
],
8181
data() {

src/Components/ItemEventsMixin.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export default {
4444
this.y_mixin = event.clientY
4545
window.removeEventListener('mousemove', this.handlePanMove)
4646
window.removeEventListener('mouseup', this.handlePanEnd)
47-
const x = Math.max(0, Math.min(this.x + this.dx, this.pageWidth - this.width))
48-
const y = Math.max(0, Math.min(this.y + this.dy, this.pageHeight - this.height))
47+
const x = Math.max(0, Math.min(this.x + this.dx, this.canvasWidth - this.width))
48+
const y = Math.max(0, Math.min(this.y + this.dy, this.canvasHeight - this.height))
4949
return {
5050
detail: { x, y },
5151
}
@@ -84,15 +84,15 @@ export default {
8484
8585
window.removeEventListener('touchmove', this.handlePanMove)
8686
window.removeEventListener('touchend', this.handlePanEnd)
87-
const x = Math.max(0, Math.min(this.x + this.dx, this.pageWidth - this.width))
88-
const y = Math.max(0, Math.min(this.y + this.dy, this.pageHeight - this.height))
87+
const x = Math.max(0, Math.min(this.x + this.dx, this.canvasWidth - this.width))
88+
const y = Math.max(0, Math.min(this.y + this.dy, this.canvasHeight - this.height))
8989
return {
9090
detail: { x, y },
9191
}
9292
},
9393
translateCoordinates() {
94-
const x = Math.max(0, Math.min(this.x + this.dx, this.pageWidth - this.width))
95-
const y = Math.max(0, Math.min(this.y + this.dy, this.pageHeight - this.height))
94+
const x = Math.max(0, Math.min(this.x + this.dx, this.canvasWidth - this.width))
95+
const y = Math.max(0, Math.min(this.y + this.dy, this.canvasHeight - this.height))
9696
return 'translate(' + x + 'px, ' + y + 'px)'
9797
}
9898
},

src/Components/TextItem.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ export default {
147147
'lineHeight',
148148
'x',
149149
'y',
150-
'pageWidth',
151-
'pageHeight',
152150
'fontFamily',
153151
'pageScale',
152+
'canvasWidth',
153+
'canvasHeight',
154154
'currentPage',
155155
'showLineSizeSelect',
156156
'showFontSelect',

src/VuePdfEditor.vue

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@
141141
:origin-width="object.originWidth"
142142
:origin-height="object.originHeight"
143143
:page-scale="pagesScale[pIndex]"
144-
:page-width="pageSizes[pIndex + 1].width"
145-
:page-height="pageSizes[pIndex + 1].height"
144+
:canvas-width="object.canvasWidth"
145+
:canvas-height="object.canvasHeight"
146146
@onUpdate="updateObject(object.id, $event)"
147147
@onDelete="deleteObject(object.id)" />
148148
</div>
@@ -159,8 +159,8 @@
159159
:font-family="object.fontFamily"
160160
:current-page="object.currentPage"
161161
:page-scale="pagesScale[pIndex]"
162-
:page-width="pageSizes[pIndex + 1].width"
163-
:page-height="pageSizes[pIndex + 1].height"
162+
:canvas-width="object.canvasWidth"
163+
:canvas-height="object.canvasHeight"
164164
@onUpdate="updateObject(object.id, $event)"
165165
@onDelete="deleteObject(object.id)"
166166
@onSelectFont="selectFontFamily" />
@@ -174,8 +174,8 @@
174174
:origin-width="object.originWidth"
175175
:origin-height="object.originHeight"
176176
:page-scale="pagesScale[pIndex]"
177-
:page-width="pageSizes[pIndex + 1].width"
178-
:page-height="pageSizes[pIndex + 1].height"
177+
:canvas-width="object.canvasWidth"
178+
:canvas-height="object.canvasHeight"
179179
@onUpdate="updateObject(object.id, $event)"
180180
@onDelete="deleteObject(object.id)" />
181181
</div>
@@ -330,7 +330,6 @@ export default {
330330
pdfDocument: null,
331331
pages: [],
332332
pagesScale: [],
333-
pageSizes: [],
334333
allObjects: [],
335334
currentFont: 'Courier',
336335
focusId: null,
@@ -481,7 +480,6 @@ export default {
481480
this.pdfDocument = null
482481
this.pages = []
483482
this.pagesScale = []
484-
this.pageSizes = []
485483
this.allObjects = []
486484
},
487485
async addPDF(file) {
@@ -525,7 +523,6 @@ export default {
525523
width: measurement[2],
526524
height: measurement[3],
527525
}
528-
this.pageSizes[page.pageNumber] = data.measurement[page.pageNumber]
529526
})
530527
this.$emit('pdf-editor:end-init', data)
531528
}
@@ -568,8 +565,6 @@ export default {
568565
originHeight: height,
569566
canvasWidth,
570567
canvasHeight,
571-
pageWidth: this.pageSizes[this.selectedPageIndex + 1].width,
572-
pageHeight: this.pageSizes[this.selectedPageIndex + 1].height,
573568
x,
574569
y,
575570
isSealImage,
@@ -590,6 +585,12 @@ export default {
590585
addTextField(text = 'Please enter here', x = 0, y = 0, currentPage = this.selectedPageIndex) {
591586
const id = this.genID()
592587
fetchFont(this.currentFont)
588+
589+
const { canvasWidth, canvasHeight }
590+
= this.$refs[
591+
`page${this.selectedPageIndex}`
592+
][0].getCanvasMeasurement()
593+
593594
const object = {
594595
id,
595596
text,
@@ -598,8 +599,8 @@ export default {
598599
width: 0, // recalculate after editing
599600
lineHeight: 1.4,
600601
fontFamily: this.currentFont,
601-
pageWidth: this.pageSizes[currentPage + 1].width,
602-
pageHeight: this.pageSizes[currentPage + 1].height,
602+
canvasWidth,
603+
canvasHeight,
603604
x,
604605
y,
605606
currentPage,
@@ -615,6 +616,12 @@ export default {
615616
616617
addDrawing(originWidth, originHeight, path, scale = 1) {
617618
const id = this.genID()
619+
620+
const { canvasWidth, canvasHeight }
621+
= this.$refs[
622+
`page${this.selectedPageIndex}`
623+
][0].getCanvasMeasurement()
624+
618625
const object = {
619626
id,
620627
path,
@@ -625,6 +632,8 @@ export default {
625632
originHeight,
626633
width: originWidth * scale,
627634
height: originHeight * scale,
635+
canvasWidth,
636+
canvasHeight,
628637
scale,
629638
}
630639
this.addObject(object)

0 commit comments

Comments
 (0)