Skip to content

Commit 28fed94

Browse files
authored
Merge pull request #116 from LibreSign/chore/replace-page-width-and-height-by-canvas-width-and-height
chore: replace page width and height by canvas width and height
2 parents 86cf20b + c73a8f9 commit 28fed94

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
@@ -143,8 +143,8 @@
143143
:origin-width="object.originWidth"
144144
:origin-height="object.originHeight"
145145
:page-scale="pagesScale[pIndex]"
146-
:page-width="pageSizes[pIndex + 1].width"
147-
:page-height="pageSizes[pIndex + 1].height"
146+
:canvas-width="object.canvasWidth"
147+
:canvas-height="object.canvasHeight"
148148
@onUpdate="updateObject(object.id, $event)"
149149
@onDelete="deleteObject(object.id)" />
150150
</div>
@@ -161,8 +161,8 @@
161161
:font-family="object.fontFamily"
162162
:current-page="object.currentPage"
163163
:page-scale="pagesScale[pIndex]"
164-
:page-width="pageSizes[pIndex + 1].width"
165-
:page-height="pageSizes[pIndex + 1].height"
164+
:canvas-width="object.canvasWidth"
165+
:canvas-height="object.canvasHeight"
166166
@onUpdate="updateObject(object.id, $event)"
167167
@onDelete="deleteObject(object.id)"
168168
@onSelectFont="selectFontFamily" />
@@ -176,8 +176,8 @@
176176
:origin-width="object.originWidth"
177177
:origin-height="object.originHeight"
178178
:page-scale="pagesScale[pIndex]"
179-
:page-width="pageSizes[pIndex + 1].width"
180-
:page-height="pageSizes[pIndex + 1].height"
179+
:canvas-width="object.canvasWidth"
180+
:canvas-height="object.canvasHeight"
181181
@onUpdate="updateObject(object.id, $event)"
182182
@onDelete="deleteObject(object.id)" />
183183
</div>
@@ -332,7 +332,6 @@ export default {
332332
pdfDocument: null,
333333
pages: [],
334334
pagesScale: [],
335-
pageSizes: [],
336335
allObjects: [],
337336
currentFont: 'Courier',
338337
focusId: null,
@@ -483,7 +482,6 @@ export default {
483482
this.pdfDocument = null
484483
this.pages = []
485484
this.pagesScale = []
486-
this.pageSizes = []
487485
this.allObjects = []
488486
},
489487
async addPDF(file) {
@@ -527,7 +525,6 @@ export default {
527525
width: measurement[2],
528526
height: measurement[3],
529527
}
530-
this.pageSizes[page.pageNumber] = data.measurement[page.pageNumber]
531528
})
532529
this.$emit('pdf-editor:end-init', data)
533530
}
@@ -570,8 +567,6 @@ export default {
570567
originHeight: height,
571568
canvasWidth,
572569
canvasHeight,
573-
pageWidth: this.pageSizes[this.selectedPageIndex + 1].width,
574-
pageHeight: this.pageSizes[this.selectedPageIndex + 1].height,
575570
x,
576571
y,
577572
isSealImage,
@@ -592,6 +587,12 @@ export default {
592587
addTextField(text = 'Please enter here', x = 0, y = 0, currentPage = this.selectedPageIndex) {
593588
const id = this.genID()
594589
fetchFont(this.currentFont)
590+
591+
const { canvasWidth, canvasHeight }
592+
= this.$refs[
593+
`page${this.selectedPageIndex}`
594+
][0].getCanvasMeasurement()
595+
595596
const object = {
596597
id,
597598
text,
@@ -600,8 +601,8 @@ export default {
600601
width: 0, // recalculate after editing
601602
lineHeight: 1.4,
602603
fontFamily: this.currentFont,
603-
pageWidth: this.pageSizes[currentPage + 1].width,
604-
pageHeight: this.pageSizes[currentPage + 1].height,
604+
canvasWidth,
605+
canvasHeight,
605606
x,
606607
y,
607608
currentPage,
@@ -617,6 +618,12 @@ export default {
617618
618619
addDrawing(originWidth, originHeight, path, scale = 1) {
619620
const id = this.genID()
621+
622+
const { canvasWidth, canvasHeight }
623+
= this.$refs[
624+
`page${this.selectedPageIndex}`
625+
][0].getCanvasMeasurement()
626+
620627
const object = {
621628
id,
622629
path,
@@ -627,6 +634,8 @@ export default {
627634
originHeight,
628635
width: originWidth * scale,
629636
height: originHeight * scale,
637+
canvasWidth,
638+
canvasHeight,
630639
scale,
631640
}
632641
this.addObject(object)

0 commit comments

Comments
 (0)