@@ -10,8 +10,8 @@ use num_enum::TryFromPrimitive;
10
10
11
11
use crate :: pdf:: { PdfGraftMap , PdfObject , PdfPage } ;
12
12
use crate :: {
13
- context, Buffer , CjkFontOrdering , Destination , DestinationKind , Document , Error , Font , Image ,
14
- Outline , Point , SimpleFontEncoding , Size , WriteMode ,
13
+ context, Buffer , CjkFontOrdering , Destination , DestinationKind , Document , Error , FilePath ,
14
+ Font , Image , Outline , Point , SimpleFontEncoding , Size , WriteMode ,
15
15
} ;
16
16
17
17
bitflags ! {
@@ -202,11 +202,15 @@ impl PdfWriteOptions {
202
202
}
203
203
204
204
pub fn set_owner_password ( & mut self , pwd : & str ) -> & mut Self {
205
- let len = pwd. len ( ) + 1 ;
206
- let c_pwd = CString :: new ( pwd) . unwrap ( ) ;
205
+ assert ! ( pwd. len( ) < self . inner. opwd_utf8. len( ) ) ;
207
206
unsafe {
208
- ptr:: copy_nonoverlapping ( c_pwd. as_ptr ( ) , self . inner . opwd_utf8 . as_mut_ptr ( ) , len) ;
207
+ ptr:: copy_nonoverlapping (
208
+ pwd. as_ptr ( ) . cast ( ) ,
209
+ self . inner . opwd_utf8 . as_mut_ptr ( ) ,
210
+ pwd. len ( ) ,
211
+ ) ;
209
212
}
213
+ self . inner . opwd_utf8 [ pwd. len ( ) ] = 0 ;
210
214
self
211
215
}
212
216
@@ -216,11 +220,15 @@ impl PdfWriteOptions {
216
220
}
217
221
218
222
pub fn set_user_password ( & mut self , pwd : & str ) -> & mut Self {
219
- let len = pwd. len ( ) + 1 ;
220
- let c_pwd = CString :: new ( pwd) . unwrap ( ) ;
223
+ assert ! ( pwd. len( ) < self . inner. upwd_utf8. len( ) ) ;
221
224
unsafe {
222
- ptr:: copy_nonoverlapping ( c_pwd. as_ptr ( ) , self . inner . upwd_utf8 . as_mut_ptr ( ) , len) ;
225
+ ptr:: copy_nonoverlapping (
226
+ pwd. as_ptr ( ) . cast ( ) ,
227
+ self . inner . upwd_utf8 . as_mut_ptr ( ) ,
228
+ pwd. len ( ) ,
229
+ ) ;
223
230
}
231
+ self . inner . upwd_utf8 [ pwd. len ( ) ] = 0 ;
224
232
self
225
233
}
226
234
}
@@ -245,8 +253,8 @@ impl PdfDocument {
245
253
}
246
254
}
247
255
248
- pub fn open ( filename : & str ) -> Result < Self , Error > {
249
- let doc = Document :: open ( filename ) ?;
256
+ pub fn open < P : AsRef < FilePath > + ? Sized > ( p : & P ) -> Result < Self , Error > {
257
+ let doc = Document :: open ( p ) ?;
250
258
Self :: try_from ( doc)
251
259
}
252
260
0 commit comments