@@ -2,6 +2,9 @@ import type { Bitmap } from './bitmap.js';
2
2
import type { Document } from './document.js' ;
3
3
4
4
export class Page {
5
+ #width = 0 ;
6
+ #height = 0 ;
7
+
5
8
constructor (
6
9
public doc : Document ,
7
10
public index : number ,
@@ -31,6 +34,9 @@ export class Page {
31
34
if ( ! this . ptr ) return ;
32
35
this . runtime . closePage ( this . ptr ) ;
33
36
this . ptr = 0 ;
37
+
38
+ this . #width = 0 ;
39
+ this . #height = 0 ;
34
40
}
35
41
36
42
label ( ) {
@@ -57,11 +63,17 @@ export class Page {
57
63
}
58
64
59
65
width ( ) {
60
- return this . runtime . pageWidth ( this . ptr ) ;
66
+ if ( ! this . #width) {
67
+ this . #width = this . runtime . pageWidth ( this . ptr ) ;
68
+ }
69
+ return this . #width;
61
70
}
62
71
63
72
height ( ) {
64
- return this . runtime . pageHeight ( this . ptr ) ;
73
+ if ( ! this . #height) {
74
+ this . #height = this . runtime . pageHeight ( this . ptr ) ;
75
+ }
76
+ return this . #height;
65
77
}
66
78
67
79
rotation ( ) {
@@ -72,8 +84,24 @@ export class Page {
72
84
return ! ! this . runtime . pageTransparency ( this . ptr ) ;
73
85
}
74
86
87
+ size ( ) {
88
+ if ( ! this . #width || ! this . #height) {
89
+ const sizePtr = this . runtime . malloc ( 8 ) ;
90
+
91
+ this . runtime . pageSize ( this . doc . pointer , this . index , sizePtr ) ;
92
+
93
+ this . #width = this . runtime . getValue ( sizePtr , 'float' ) ;
94
+ this . #height = this . runtime . getValue ( sizePtr + 4 , 'float' ) ;
95
+
96
+ this . runtime . free ( sizePtr ) ;
97
+ }
98
+
99
+ return { width : this . #width, height : this . #height } ;
100
+ }
101
+
75
102
rect ( ) {
76
- return { bottom : 0 , left : 0 , top : this . height ( ) , right : this . width ( ) } ;
103
+ const { width : right , height : top } = this . size ( ) ;
104
+ return { bottom : 0 , left : 0 , top, right } ;
77
105
}
78
106
79
107
render (
0 commit comments