Line 0
Link Here
|
|
|
1 |
--- document.c.orig 2014-10-16 22:21:41 UTC |
2 |
+++ document.c |
3 |
@@ -51,14 +51,14 @@ pdf_document_open(zathura_document_t* do |
4 |
} |
5 |
|
6 |
/* authenticate if password is required and given */ |
7 |
- if (fz_needs_password(mupdf_document->document) != 0) { |
8 |
- if (password == NULL || fz_authenticate_password(mupdf_document->document, (char*) password) == 0) { |
9 |
+ if (fz_needs_password(mupdf_document->ctx, mupdf_document->document) != 0) { |
10 |
+ if (password == NULL || fz_authenticate_password(mupdf_document->ctx, mupdf_document->document, (char*) password) == 0) { |
11 |
error = ZATHURA_ERROR_INVALID_PASSWORD; |
12 |
goto error_free; |
13 |
} |
14 |
} |
15 |
|
16 |
- zathura_document_set_number_of_pages(document, fz_count_pages(mupdf_document->document)); |
17 |
+ zathura_document_set_number_of_pages(document, fz_count_pages(mupdf_document->ctx, mupdf_document->document)); |
18 |
zathura_document_set_data(document, mupdf_document); |
19 |
|
20 |
return error; |
21 |
@@ -67,10 +67,10 @@ error_free: |
22 |
|
23 |
if (mupdf_document != NULL) { |
24 |
if (mupdf_document->document != NULL) { |
25 |
- fz_close_document(mupdf_document->document); |
26 |
+ fz_drop_document(mupdf_document->ctx, mupdf_document->document); |
27 |
} |
28 |
if (mupdf_document->ctx != NULL) { |
29 |
- fz_free_context(mupdf_document->ctx); |
30 |
+ fz_drop_context(mupdf_document->ctx); |
31 |
} |
32 |
|
33 |
free(mupdf_document); |
34 |
@@ -90,8 +90,8 @@ pdf_document_free(zathura_document_t* do |
35 |
return ZATHURA_ERROR_INVALID_ARGUMENTS; |
36 |
} |
37 |
|
38 |
- fz_close_document(mupdf_document->document); |
39 |
- fz_free_context(mupdf_document->ctx); |
40 |
+ fz_drop_document(mupdf_document->ctx, mupdf_document->document); |
41 |
+ fz_drop_context(mupdf_document->ctx); |
42 |
free(mupdf_document); |
43 |
zathura_document_set_data(document, NULL); |
44 |
|
45 |
@@ -112,7 +112,7 @@ pdf_document_save_as(zathura_document_t* |
46 |
* options. */ |
47 |
|
48 |
fz_write_options opts = { 0 }; /* just use the default options */ |
49 |
- fz_write_document(mupdf_document->document, (char*) path, &opts); |
50 |
+ fz_write_document(mupdf_document->ctx, mupdf_document->document, (char*) path, &opts); |
51 |
} fz_catch (mupdf_document->ctx) { |
52 |
return ZATHURA_ERROR_UNKNOWN; |
53 |
} |
54 |
--- image.c.orig 2014-10-16 22:21:41 UTC |
55 |
+++ image.c |
56 |
@@ -9,8 +9,8 @@ |
57 |
#include "plugin.h" |
58 |
|
59 |
static void pdf_zathura_image_free(zathura_image_t* image); |
60 |
-static void get_images(pdf_obj* dict, girara_list_t* list); |
61 |
-static void get_resources(pdf_obj* resource, girara_list_t* list); |
62 |
+static void get_images(zathura_page_t* page, pdf_obj* dict, girara_list_t* list); |
63 |
+static void get_resources(zathura_page_t* page, pdf_obj* resource, girara_list_t* list); |
64 |
|
65 |
girara_list_t* |
66 |
pdf_page_images_get(zathura_page_t* page, mupdf_page_t* mupdf_page, zathura_error_t* error) |
67 |
@@ -30,12 +30,12 @@ pdf_page_images_get(zathura_page_t* page |
68 |
|
69 |
mupdf_document_t* mupdf_document = zathura_document_get_data(document); |
70 |
|
71 |
- pdf_obj* page_object = pdf_load_object((pdf_document*) mupdf_document->document, zathura_page_get_index(page), 0); |
72 |
+ pdf_obj* page_object = pdf_load_object(mupdf_document->ctx, (pdf_document*) mupdf_document->document, zathura_page_get_index(page), 0); |
73 |
if (page_object == NULL) { |
74 |
goto error_free; |
75 |
} |
76 |
|
77 |
- pdf_obj* resource = pdf_dict_gets(page_object, "Resources"); |
78 |
+ pdf_obj* resource = pdf_dict_gets(mupdf_document->ctx, page_object, "Resources"); |
79 |
if (resource == NULL) { |
80 |
goto error_free; |
81 |
} |
82 |
@@ -50,7 +50,7 @@ pdf_page_images_get(zathura_page_t* page |
83 |
|
84 |
girara_list_set_free_function(list, (girara_free_function_t) pdf_zathura_image_free); |
85 |
|
86 |
- get_resources(resource, list); |
87 |
+ get_resources(page, resource, list); |
88 |
|
89 |
return list; |
90 |
|
91 |
@@ -81,20 +81,32 @@ pdf_zathura_image_free(zathura_image_t* |
92 |
} |
93 |
|
94 |
static void |
95 |
-get_images(pdf_obj* dict, girara_list_t* list) |
96 |
+get_images(zathura_page_t* page, pdf_obj* dict, girara_list_t* list) |
97 |
{ |
98 |
if (dict == NULL || list == NULL) { |
99 |
return; |
100 |
} |
101 |
|
102 |
- for (int i = 0; i < pdf_dict_len(dict); i++) { |
103 |
- pdf_obj* image_dict = pdf_dict_get_val(dict, i); |
104 |
- if (pdf_is_dict(image_dict) == 0) { |
105 |
+ if (page == NULL) { |
106 |
+ return; |
107 |
+ } |
108 |
+ |
109 |
+ zathura_document_t* document = zathura_page_get_document(page); |
110 |
+ |
111 |
+ if (document == NULL) { |
112 |
+ return; |
113 |
+ } |
114 |
+ |
115 |
+ mupdf_document_t* mupdf_document = zathura_document_get_data(document); |
116 |
+ |
117 |
+ for (int i = 0; i < pdf_dict_len(mupdf_document->ctx, dict); i++) { |
118 |
+ pdf_obj* image_dict = pdf_dict_get_val(mupdf_document->ctx, dict, i); |
119 |
+ if (pdf_is_dict(mupdf_document->ctx, image_dict) == 0) { |
120 |
continue; |
121 |
} |
122 |
|
123 |
- pdf_obj* type = pdf_dict_gets(image_dict, "Subtype"); |
124 |
- if (strcmp(pdf_to_name(type), "Image") != 0) { |
125 |
+ pdf_obj* type = pdf_dict_gets(mupdf_document->ctx, image_dict, "Subtype"); |
126 |
+ if (strcmp(pdf_to_name(mupdf_document->ctx, type), "Image") != 0) { |
127 |
continue; |
128 |
} |
129 |
|
130 |
@@ -110,8 +122,8 @@ get_images(pdf_obj* dict, girara_list_t* |
131 |
continue; |
132 |
} |
133 |
|
134 |
- pdf_obj* width = pdf_dict_gets(image_dict, "Width"); |
135 |
- pdf_obj* height = pdf_dict_gets(image_dict, "Height"); |
136 |
+ pdf_obj* width = pdf_dict_gets(mupdf_document->ctx, image_dict, "Width"); |
137 |
+ pdf_obj* height = pdf_dict_gets(mupdf_document->ctx, image_dict, "Height"); |
138 |
|
139 |
zathura_image_t* zathura_image = g_malloc(sizeof(zathura_image_t)); |
140 |
|
141 |
@@ -120,33 +132,45 @@ get_images(pdf_obj* dict, girara_list_t* |
142 |
// FIXME: Get correct image coordinates |
143 |
zathura_image->data = image_dict; |
144 |
zathura_image->position.x1 = 0; |
145 |
- zathura_image->position.x2 = pdf_to_int(width); |
146 |
+ zathura_image->position.x2 = pdf_to_int(mupdf_document->ctx, width); |
147 |
zathura_image->position.y1 = 0; |
148 |
- zathura_image->position.y2 = pdf_to_int(height); |
149 |
+ zathura_image->position.y2 = pdf_to_int(mupdf_document->ctx, height); |
150 |
|
151 |
girara_list_append(list, zathura_image); |
152 |
} |
153 |
} |
154 |
|
155 |
static void |
156 |
-get_resources(pdf_obj* resource, girara_list_t* list) |
157 |
+get_resources(zathura_page_t* page, pdf_obj* resource, girara_list_t* list) |
158 |
{ |
159 |
if (resource == NULL || list == NULL) { |
160 |
return; |
161 |
} |
162 |
|
163 |
- pdf_obj* x_object = pdf_dict_gets(resource, "XObject"); |
164 |
+ if (page == NULL) { |
165 |
+ return; |
166 |
+ } |
167 |
+ |
168 |
+ zathura_document_t* document = zathura_page_get_document(page); |
169 |
+ |
170 |
+ if (document == NULL) { |
171 |
+ return; |
172 |
+ } |
173 |
+ |
174 |
+ mupdf_document_t* mupdf_document = zathura_document_get_data(document); |
175 |
+ |
176 |
+ pdf_obj* x_object = pdf_dict_gets(mupdf_document->ctx, resource, "XObject"); |
177 |
if (x_object == NULL) { |
178 |
return; |
179 |
} |
180 |
|
181 |
- get_images(x_object, list); |
182 |
+ get_images(page, x_object, list); |
183 |
|
184 |
- for (int i = 0; i < pdf_dict_len(x_object); i++) { |
185 |
- pdf_obj* obj = pdf_dict_get_val(x_object, i); |
186 |
- pdf_obj* subsrc = pdf_dict_gets(obj, "Resources"); |
187 |
- if (subsrc != NULL && pdf_objcmp(resource, subsrc)) { |
188 |
- get_resources(subsrc, list); |
189 |
+ for (int i = 0; i < pdf_dict_len(mupdf_document->ctx, x_object); i++) { |
190 |
+ pdf_obj* obj = pdf_dict_get_val(mupdf_document->ctx, x_object, i); |
191 |
+ pdf_obj* subsrc = pdf_dict_gets(mupdf_document->ctx, obj, "Resources"); |
192 |
+ if (subsrc != NULL && pdf_objcmp(mupdf_document->ctx, resource, subsrc)) { |
193 |
+ get_resources(page, subsrc, list); |
194 |
} |
195 |
} |
196 |
} |
197 |
--- index.c.orig 2014-10-16 22:21:41 UTC |
198 |
+++ index.c |
199 |
@@ -19,7 +19,7 @@ pdf_document_index_generate(zathura_docu |
200 |
} |
201 |
|
202 |
/* get outline */ |
203 |
- fz_outline* outline = fz_load_outline(mupdf_document->document); |
204 |
+ fz_outline* outline = fz_load_outline(mupdf_document->ctx, mupdf_document->document); |
205 |
if (outline == NULL) { |
206 |
if (error != NULL) { |
207 |
*error = ZATHURA_ERROR_UNKNOWN; |
208 |
@@ -32,7 +32,7 @@ pdf_document_index_generate(zathura_docu |
209 |
build_index(outline, root); |
210 |
|
211 |
/* free outline */ |
212 |
- fz_free_outline(mupdf_document->ctx, outline); |
213 |
+ fz_drop_outline(mupdf_document->ctx, outline); |
214 |
|
215 |
return root; |
216 |
} |
217 |
--- links.c.orig 2014-10-16 22:21:41 UTC |
218 |
+++ links.c |
219 |
@@ -31,7 +31,7 @@ pdf_page_links_get(zathura_page_t* page, |
220 |
goto error_free; |
221 |
} |
222 |
|
223 |
- fz_link* link = fz_load_links(mupdf_document->document, mupdf_page->page); |
224 |
+ fz_link* link = fz_load_links(mupdf_document->ctx, mupdf_page->page); |
225 |
for (; link != NULL; link = link->next) { |
226 |
/* extract position */ |
227 |
zathura_rectangle_t position; |
228 |
--- page.c.orig 2014-10-16 22:21:41 UTC |
229 |
+++ page.c |
230 |
@@ -29,12 +29,12 @@ pdf_page_init(zathura_page_t* page) |
231 |
|
232 |
/* load page */ |
233 |
fz_try (mupdf_page->ctx) { |
234 |
- mupdf_page->page = fz_load_page(mupdf_document->document, index); |
235 |
+ mupdf_page->page = fz_load_page(mupdf_document->ctx, mupdf_document->document, index); |
236 |
} fz_catch (mupdf_page->ctx) { |
237 |
goto error_free; |
238 |
} |
239 |
|
240 |
- fz_bound_page(mupdf_document->document, (fz_page*) mupdf_page->page, &mupdf_page->bbox); |
241 |
+ fz_bound_page(mupdf_document->ctx, (fz_page*) mupdf_page->page, &mupdf_page->bbox); |
242 |
|
243 |
/* get page dimensions */ |
244 |
zathura_page_set_width(page, mupdf_page->bbox.x1 - mupdf_page->bbox.x0); |
245 |
@@ -74,15 +74,15 @@ pdf_page_clear(zathura_page_t* page, mup |
246 |
|
247 |
if (mupdf_page != NULL) { |
248 |
if (mupdf_page->text != NULL) { |
249 |
- fz_free_text_page(mupdf_page->ctx, mupdf_page->text); |
250 |
+ fz_drop_text_page(mupdf_page->ctx, mupdf_page->text); |
251 |
} |
252 |
|
253 |
if (mupdf_page->sheet != NULL) { |
254 |
- fz_free_text_sheet(mupdf_page->ctx, mupdf_page->sheet); |
255 |
+ fz_drop_text_sheet(mupdf_page->ctx, mupdf_page->sheet); |
256 |
} |
257 |
|
258 |
if (mupdf_page->page != NULL) { |
259 |
- fz_free_page(mupdf_document->document, mupdf_page->page); |
260 |
+ fz_drop_page(mupdf_document->ctx, mupdf_page->page); |
261 |
} |
262 |
|
263 |
free(mupdf_page); |
264 |
--- render.c.orig 2014-10-16 22:21:41 UTC |
265 |
+++ render.c |
266 |
@@ -26,12 +26,12 @@ pdf_page_render_to_buffer(mupdf_document |
267 |
fz_try (mupdf_document->ctx) { |
268 |
fz_matrix m; |
269 |
fz_scale(&m, scalex, scaley); |
270 |
- fz_run_page(mupdf_document->document, mupdf_page->page, device, &m, NULL); |
271 |
+ fz_run_page(mupdf_document->ctx, mupdf_page->page, device, &m, NULL); |
272 |
} fz_catch (mupdf_document->ctx) { |
273 |
return ZATHURA_ERROR_UNKNOWN; |
274 |
} |
275 |
|
276 |
- fz_free_device(device); |
277 |
+ fz_drop_device(mupdf_page->ctx, device); |
278 |
|
279 |
fz_irect irect = { .x1 = page_width, .y1 = page_height }; |
280 |
fz_rect rect = { .x1 = page_width, .y1 = page_height }; |
281 |
@@ -41,8 +41,8 @@ pdf_page_render_to_buffer(mupdf_document |
282 |
fz_clear_pixmap_with_value(mupdf_page->ctx, pixmap, 0xFF); |
283 |
|
284 |
device = fz_new_draw_device(mupdf_page->ctx, pixmap); |
285 |
- fz_run_display_list(display_list, device, &fz_identity, &rect, NULL); |
286 |
- fz_free_device(device); |
287 |
+ fz_run_display_list(mupdf_page->ctx, display_list, device, &fz_identity, &rect, NULL); |
288 |
+ fz_drop_device(mupdf_page->ctx, device); |
289 |
|
290 |
unsigned char* s = fz_pixmap_samples(mupdf_page->ctx, pixmap); |
291 |
unsigned int n = fz_pixmap_components(mupdf_page->ctx, pixmap); |
292 |
--- utils.c.orig 2014-10-16 22:21:41 UTC |
293 |
+++ utils.c |
294 |
@@ -17,9 +17,9 @@ mupdf_page_extract_text(mupdf_document_t |
295 |
text_device = fz_new_text_device(mupdf_page->ctx, mupdf_page->sheet, mupdf_page->text); |
296 |
fz_matrix ctm; |
297 |
fz_scale(&ctm, 1.0, 1.0); |
298 |
- fz_run_page(mupdf_document->document, mupdf_page->page, text_device, &ctm, NULL); |
299 |
+ fz_run_page(mupdf_page->ctx, mupdf_page->page, text_device, &ctm, NULL); |
300 |
} fz_always (mupdf_document->ctx) { |
301 |
- fz_free_device(text_device); |
302 |
+ fz_drop_device(mupdf_page->ctx, text_device); |
303 |
} fz_catch(mupdf_document->ctx) { |
304 |
} |
305 |
|