@@ -20,7 +20,7 @@ use document::{Document, DocumentRes, PublicRes, Annotations, PageAnnot};
20
20
use ofd:: { Ofd , OfdNode } ;
21
21
use page:: Page ;
22
22
use render:: Renderable ;
23
- use types:: ct;
23
+ // use types::ct;
24
24
25
25
pub fn read_ofd ( file_path : & str ) -> Result < Ofd , Box < dyn Error > > {
26
26
let file = File :: open ( file_path) ?;
@@ -46,7 +46,7 @@ pub fn read_ofd(file_path: &str) -> Result<Ofd, Box<dyn Error>> {
46
46
Ok ( ofd_result)
47
47
}
48
48
49
- pub fn export_ofd_to_png ( ofd : & mut Ofd , output_path : & str ) -> Result < ( ) , Box < dyn Error > > {
49
+ pub fn render_ofd_to_context ( ofd : & mut Ofd , context : & mut cairo :: Context ) -> Result < ( ) , Box < dyn Error > > {
50
50
// create a new String to store the content of the DocRoot file.
51
51
let mut content = String :: new ( ) ;
52
52
@@ -128,17 +128,7 @@ pub fn export_ofd_to_png(ofd: &mut Ofd, output_path: &str) -> Result<(), Box<dyn
128
128
}
129
129
}
130
130
131
-
132
-
133
- // Create a cairo surface and context.
134
- let pybox = ct:: PageArea :: from ( document. common_data . page_area . physical_box . clone ( ) ) . to_pixel ( ) ;
135
- let surface = cairo:: ImageSurface :: create (
136
- cairo:: Format :: ARgb32 ,
137
- pybox. width as i32 ,
138
- pybox. height as i32 ,
139
- ) ?;
140
-
141
- let mut context = cairo:: Context :: new ( & surface) ?;
131
+ // let _pybox = ct::PageArea::from(document.common_data.page_area.physical_box.clone()).to_pixel();
142
132
143
133
// draw page
144
134
let pages = & document. pages . page ;
@@ -160,10 +150,24 @@ pub fn export_ofd_to_png(ofd: &mut Ofd, output_path: &str) -> Result<(), Box<dyn
160
150
page_file. read_to_string ( & mut content) ?;
161
151
}
162
152
let page = Page :: from_xml ( & content) ?;
163
- page. render ( & mut context, ofd, & document) ?;
153
+ page. render ( context, ofd, & document) ?;
164
154
}
165
155
156
+ Ok ( ( ) )
157
+ }
158
+
159
+ pub fn export_ofd_to_png ( ofd : & mut Ofd , output_path : & str , width : u32 , height : u32 ) -> Result < ( ) , Box < dyn Error > > {
160
+ let surface = cairo:: ImageSurface :: create (
161
+ cairo:: Format :: ARgb32 ,
162
+ width as i32 ,
163
+ height as i32 ,
164
+ ) ?;
165
+
166
+ let mut context = cairo:: Context :: new ( & surface) ?;
167
+ render_ofd_to_context ( ofd, & mut context) ?;
168
+
166
169
let mut file = File :: create ( output_path) ?;
167
170
surface. write_to_png ( & mut file) ?;
171
+
168
172
Ok ( ( ) )
169
- }
173
+ }
0 commit comments