Line 0
Link Here
|
|
|
1 |
--- image.c.orig 2015-05-12 16:41:50 UTC |
2 |
+++ image.c |
3 |
@@ -9,8 +9,8 @@ |
4 |
#include "plugin.h" |
5 |
|
6 |
static void pdf_zathura_image_free(zathura_image_t* image); |
7 |
-static void get_images(pdf_obj* dict, girara_list_t* list); |
8 |
-static void get_resources(pdf_obj* resource, girara_list_t* list); |
9 |
+static void get_images(zathura_page_t* page, pdf_obj* dict, girara_list_t* list); |
10 |
+static void get_resources(zathura_page_t* page, pdf_obj* resource, girara_list_t* list); |
11 |
|
12 |
girara_list_t* |
13 |
pdf_page_images_get(zathura_page_t* page, mupdf_page_t* mupdf_page, zathura_error_t* error) |
14 |
@@ -30,12 +30,12 @@ pdf_page_images_get(zathura_page_t* page |
15 |
|
16 |
mupdf_document_t* mupdf_document = zathura_document_get_data(document); |
17 |
|
18 |
- pdf_obj* page_object = pdf_load_object((pdf_document*) mupdf_document->document, zathura_page_get_index(page), 0); |
19 |
+ pdf_obj* page_object = pdf_load_object(mupdf_document->ctx, (pdf_document*) mupdf_document->document, zathura_page_get_index(page), 0); |
20 |
if (page_object == NULL) { |
21 |
goto error_free; |
22 |
} |
23 |
|
24 |
- pdf_obj* resource = pdf_dict_gets(page_object, "Resources"); |
25 |
+ pdf_obj* resource = pdf_dict_gets(mupdf_document->ctx, page_object, "Resources"); |
26 |
if (resource == NULL) { |
27 |
goto error_free; |
28 |
} |
29 |
@@ -50,7 +50,7 @@ pdf_page_images_get(zathura_page_t* page |
30 |
|
31 |
girara_list_set_free_function(list, (girara_free_function_t) pdf_zathura_image_free); |
32 |
|
33 |
- get_resources(resource, list); |
34 |
+ get_resources(page, resource, list); |
35 |
|
36 |
return list; |
37 |
|
38 |
@@ -81,20 +81,32 @@ pdf_zathura_image_free(zathura_image_t* |
39 |
} |
40 |
|
41 |
static void |
42 |
-get_images(pdf_obj* dict, girara_list_t* list) |
43 |
+get_images(zathura_page_t* page, pdf_obj* dict, girara_list_t* list) |
44 |
{ |
45 |
if (dict == NULL || list == NULL) { |
46 |
return; |
47 |
} |
48 |
|
49 |
- for (int i = 0; i < pdf_dict_len(dict); i++) { |
50 |
- pdf_obj* image_dict = pdf_dict_get_val(dict, i); |
51 |
- if (pdf_is_dict(image_dict) == 0) { |
52 |
+ if (page == NULL) { |
53 |
+ return; |
54 |
+ } |
55 |
+ |
56 |
+ zathura_document_t* document = zathura_page_get_document(page); |
57 |
+ |
58 |
+ if (document == NULL) { |
59 |
+ return; |
60 |
+ } |
61 |
+ |
62 |
+ mupdf_document_t* mupdf_document = zathura_document_get_data(document); |
63 |
+ |
64 |
+ for (int i = 0; i < pdf_dict_len(mupdf_document->ctx, dict); i++) { |
65 |
+ pdf_obj* image_dict = pdf_dict_get_val(mupdf_document->ctx, dict, i); |
66 |
+ if (pdf_is_dict(mupdf_document->ctx, image_dict) == 0) { |
67 |
continue; |
68 |
} |
69 |
|
70 |
- pdf_obj* type = pdf_dict_gets(image_dict, "Subtype"); |
71 |
- if (strcmp(pdf_to_name(type), "Image") != 0) { |
72 |
+ pdf_obj* type = pdf_dict_gets(mupdf_document->ctx, image_dict, "Subtype"); |
73 |
+ if (strcmp(pdf_to_name(mupdf_document->ctx, type), "Image") != 0) { |
74 |
continue; |
75 |
} |
76 |
|
77 |
@@ -110,8 +122,8 @@ get_images(pdf_obj* dict, girara_list_t* |
78 |
continue; |
79 |
} |
80 |
|
81 |
- pdf_obj* width = pdf_dict_gets(image_dict, "Width"); |
82 |
- pdf_obj* height = pdf_dict_gets(image_dict, "Height"); |
83 |
+ pdf_obj* width = pdf_dict_gets(mupdf_document->ctx, image_dict, "Width"); |
84 |
+ pdf_obj* height = pdf_dict_gets(mupdf_document->ctx, image_dict, "Height"); |
85 |
|
86 |
zathura_image_t* zathura_image = g_malloc(sizeof(zathura_image_t)); |
87 |
|
88 |
@@ -120,33 +132,45 @@ get_images(pdf_obj* dict, girara_list_t* |
89 |
// FIXME: Get correct image coordinates |
90 |
zathura_image->data = image_dict; |
91 |
zathura_image->position.x1 = 0; |
92 |
- zathura_image->position.x2 = pdf_to_int(width); |
93 |
+ zathura_image->position.x2 = pdf_to_int(mupdf_document->ctx, width); |
94 |
zathura_image->position.y1 = 0; |
95 |
- zathura_image->position.y2 = pdf_to_int(height); |
96 |
+ zathura_image->position.y2 = pdf_to_int(mupdf_document->ctx, height); |
97 |
|
98 |
girara_list_append(list, zathura_image); |
99 |
} |
100 |
} |
101 |
|
102 |
static void |
103 |
-get_resources(pdf_obj* resource, girara_list_t* list) |
104 |
+get_resources(zathura_page_t* page, pdf_obj* resource, girara_list_t* list) |
105 |
{ |
106 |
if (resource == NULL || list == NULL) { |
107 |
return; |
108 |
} |
109 |
|
110 |
- pdf_obj* x_object = pdf_dict_gets(resource, "XObject"); |
111 |
+ if (page == NULL) { |
112 |
+ return; |
113 |
+ } |
114 |
+ |
115 |
+ zathura_document_t* document = zathura_page_get_document(page); |
116 |
+ |
117 |
+ if (document == NULL) { |
118 |
+ return; |
119 |
+ } |
120 |
+ |
121 |
+ mupdf_document_t* mupdf_document = zathura_document_get_data(document); |
122 |
+ |
123 |
+ pdf_obj* x_object = pdf_dict_gets(mupdf_document->ctx, resource, "XObject"); |
124 |
if (x_object == NULL) { |
125 |
return; |
126 |
} |
127 |
|
128 |
- get_images(x_object, list); |
129 |
+ get_images(page, x_object, list); |
130 |
|
131 |
- for (int i = 0; i < pdf_dict_len(x_object); i++) { |
132 |
- pdf_obj* obj = pdf_dict_get_val(x_object, i); |
133 |
- pdf_obj* subsrc = pdf_dict_gets(obj, "Resources"); |
134 |
- if (subsrc != NULL && pdf_objcmp(resource, subsrc)) { |
135 |
- get_resources(subsrc, list); |
136 |
+ for (int i = 0; i < pdf_dict_len(mupdf_document->ctx, x_object); i++) { |
137 |
+ pdf_obj* obj = pdf_dict_get_val(mupdf_document->ctx, x_object, i); |
138 |
+ pdf_obj* subsrc = pdf_dict_gets(mupdf_document->ctx, obj, "Resources"); |
139 |
+ if (subsrc != NULL && pdf_objcmp(mupdf_document->ctx, resource, subsrc)) { |
140 |
+ get_resources(page, subsrc, list); |
141 |
} |
142 |
} |
143 |
} |