Merge lp:~ubuntu-branches/ubuntu/precise/apvlv/precise-201112121632 into lp:ubuntu/precise/apvlv
- Precise (12.04)
- precise-201112121632
- Merge into precise
Status: | Rejected |
---|---|
Rejected by: | Martin Pitt |
Proposed branch: | lp:~ubuntu-branches/ubuntu/precise/apvlv/precise-201112121632 |
Merge into: | lp:ubuntu/precise/apvlv |
Diff against target: |
1140 lines (+1080/-1) (has conflicts) 9 files modified
.pc/.quilt_patches (+1/-0) .pc/.quilt_series (+1/-0) .pc/.version (+1/-0) .pc/00git_poppler_render_to_pixbuf.patch/src/ApvlvFile.cpp (+907/-0) .pc/applied-patches (+1/-0) debian/changelog (+12/-0) debian/patches/00git_poppler_render_to_pixbuf.patch (+155/-0) debian/patches/series (+1/-0) debian/source/format (+1/-1) Text conflict in debian/changelog |
To merge this branch: | bzr merge lp:~ubuntu-branches/ubuntu/precise/apvlv/precise-201112121632 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu branches | Pending | ||
Review via email: mp+85359@code.launchpad.net |
Commit message
Description of the change
The package importer has detected a possible inconsistency between the package history in the archive and the history in bzr. As the archive is authoritative the importer has made lp:ubuntu/precise/apvlv reflect what is in the archive and the old bzr branch has been pushed to lp:~ubuntu-branches/ubuntu/precise/apvlv/precise-201112121632. This merge proposal was created so that an Ubuntu developer can review the situations and perform a merge/upload if necessary. There are three typical cases where this can happen.
1. Where someone pushes a change to bzr and someone else uploads the package without that change. This is the reason that this check is done by the importer. If this appears to be the case then a merge/upload should be done if the changes that were in bzr are still desirable.
2. The importer incorrectly detected the above situation when someone made a change in bzr and then uploaded it.
3. The importer incorrectly detected the above situation when someone just uploaded a package and didn't touch bzr.
If this case doesn't appear to be the first situation then set the status of the merge proposal to "Rejected" and help avoid the problem in future by filing a bug at https:/
(this is an automatically generated message)
Unmerged revisions
- 20. By Martin Pitt
-
releasing version 0.1.1-1.1ubuntu1
- 19. By Martin Pitt
-
Add 00git_poppler_
render_ to_pixbuf. patch: Add poppler_ render_ to_pixbuf
function for poppler no gdkpixbuf support. Patch taken from upstream git
head. - 18. By Martin Pitt
-
debian/
source/ format: Switch to 3.0 (quilt), to be able to apply patches.
Preview Diff
1 | === added directory '.pc' |
2 | === added file '.pc/.quilt_patches' |
3 | --- .pc/.quilt_patches 1970-01-01 00:00:00 +0000 |
4 | +++ .pc/.quilt_patches 2011-12-12 16:38:24 +0000 |
5 | @@ -0,0 +1,1 @@ |
6 | +debian/patches |
7 | |
8 | === added file '.pc/.quilt_series' |
9 | --- .pc/.quilt_series 1970-01-01 00:00:00 +0000 |
10 | +++ .pc/.quilt_series 2011-12-12 16:38:24 +0000 |
11 | @@ -0,0 +1,1 @@ |
12 | +series |
13 | |
14 | === added file '.pc/.version' |
15 | --- .pc/.version 1970-01-01 00:00:00 +0000 |
16 | +++ .pc/.version 2011-12-12 16:38:24 +0000 |
17 | @@ -0,0 +1,1 @@ |
18 | +2 |
19 | |
20 | === added directory '.pc/00git_poppler_render_to_pixbuf.patch' |
21 | === added file '.pc/00git_poppler_render_to_pixbuf.patch/.timestamp' |
22 | === added directory '.pc/00git_poppler_render_to_pixbuf.patch/src' |
23 | === added file '.pc/00git_poppler_render_to_pixbuf.patch/src/ApvlvFile.cpp' |
24 | --- .pc/00git_poppler_render_to_pixbuf.patch/src/ApvlvFile.cpp 1970-01-01 00:00:00 +0000 |
25 | +++ .pc/00git_poppler_render_to_pixbuf.patch/src/ApvlvFile.cpp 2011-12-12 16:38:24 +0000 |
26 | @@ -0,0 +1,907 @@ |
27 | +/* |
28 | +* This file is part of the apvlv package |
29 | +* Copyright (C) <2008> <Alf> |
30 | +* |
31 | +* Contact: Alf <naihe2010@gmail.com> |
32 | +* |
33 | +* This program is free software; you can redistribute it and/or modify |
34 | +* it under the terms of the GNU General Public License as published by |
35 | +* the Free Software Foundation; either version 2 of the License, or |
36 | +* (at your option) any later version. |
37 | +* |
38 | +* This program is distributed in the hope that it will be useful, |
39 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
40 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
41 | +* GNU General Public License for more details. |
42 | +* |
43 | +* You should have received a copy of the GNU General Public License along |
44 | +* with this program; if not, write to the Free Software Foundation, Inc., |
45 | +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
46 | +* |
47 | +*/ |
48 | +/* @CFILE ApvlvFile.cpp xxxxxxxxxxxxxxxxxxxxxxxxxx. |
49 | +* |
50 | +* Author: Alf <naihe2010@gmail.com> |
51 | +*/ |
52 | +/* @date Created: 2009/11/20 19:38:30 Alf*/ |
53 | + |
54 | +#include "ApvlvFile.hpp" |
55 | +#include "ApvlvUtil.hpp" |
56 | +#include "ApvlvView.hpp" |
57 | + |
58 | +#ifdef HAVE_LIBUMD |
59 | +#define LIBUMD_ENABLE_GTK |
60 | +#include <umd.h> |
61 | +#endif |
62 | +#include <glib.h> |
63 | + |
64 | +#include <sys/stat.h> |
65 | +#include <iostream> |
66 | +#include <fstream> |
67 | + |
68 | +namespace apvlv |
69 | + { |
70 | +#ifndef MAX |
71 | +#define MAX(a,b) ((a) > (b) ? (a) : (b)) |
72 | +#endif |
73 | + |
74 | + ApvlvFile::ApvlvFile (const char *filename, bool check) |
75 | + { |
76 | + mIndex = NULL; |
77 | + |
78 | + mRawdata = NULL; |
79 | + mRawdataSize = 0; |
80 | + } |
81 | + |
82 | + ApvlvFile::~ApvlvFile () |
83 | + { |
84 | + if (mRawdata != NULL) |
85 | + { |
86 | + delete[]mRawdata; |
87 | + mRawdata = NULL; |
88 | + } |
89 | + } |
90 | + |
91 | + ApvlvFile *ApvlvFile::newfile (const char *filename, bool check) |
92 | + { |
93 | + ApvlvFile *file = NULL; |
94 | + static const char *type_phrase[] = |
95 | + { |
96 | + ".PDF", |
97 | + ".umd", |
98 | + ".djvu" |
99 | + }; |
100 | + |
101 | + size_t i; |
102 | + for (i = 0; i < 3; ++ i) |
103 | + { |
104 | + if (strcasecmp (filename + strlen (filename) - strlen (type_phrase[i]), |
105 | + type_phrase[i]) == 0) |
106 | + { |
107 | + break; |
108 | + } |
109 | + } |
110 | + |
111 | + if (i == 3) |
112 | + { |
113 | + debug ("not a valid file: %s, treate as a PDF file", filename); |
114 | + i = 0; |
115 | + } |
116 | + |
117 | + try |
118 | + { |
119 | + switch (i) |
120 | + { |
121 | + case 0: |
122 | + file = new ApvlvPDF (filename); |
123 | + break; |
124 | + |
125 | + case 1: |
126 | + file = new ApvlvUMD (filename); |
127 | + break; |
128 | + |
129 | + case 2: |
130 | + file = new ApvlvDJVU (filename); |
131 | + break; |
132 | + |
133 | + default: |
134 | + ; |
135 | + } |
136 | + } |
137 | + |
138 | + catch (bad_alloc e) |
139 | + { |
140 | + delete file; |
141 | + file = NULL; |
142 | + } |
143 | + |
144 | + return file; |
145 | + } |
146 | + |
147 | + ApvlvPDF::ApvlvPDF (const char *filename, bool check):ApvlvFile (filename, |
148 | + check) |
149 | + { |
150 | + gchar *wfilename; |
151 | + |
152 | + if (filename == NULL |
153 | + || *filename == '\0' |
154 | + || g_file_test (filename, G_FILE_TEST_IS_REGULAR) == FALSE |
155 | + || (wfilename = |
156 | + g_locale_from_utf8 (filename, -1, NULL, NULL, NULL)) == NULL) |
157 | + { |
158 | + gView->errormessage ("filename error: %s", |
159 | + filename ? filename : "No name"); |
160 | + throw std::bad_alloc (); |
161 | + } |
162 | + |
163 | + size_t filelen; |
164 | + struct stat sbuf; |
165 | + int rt = stat (wfilename, &sbuf); |
166 | + if (rt < 0) |
167 | + { |
168 | + gView->errormessage ("Can't stat the PDF file: %s.", filename); |
169 | + throw std::bad_alloc (); |
170 | + } |
171 | + filelen = sbuf.st_size; |
172 | + |
173 | + if (mRawdata != NULL && mRawdataSize < filelen) |
174 | + { |
175 | + delete[]mRawdata; |
176 | + mRawdata = NULL; |
177 | + } |
178 | + |
179 | + if (mRawdata == NULL) |
180 | + { |
181 | + mRawdata = new char[filelen]; |
182 | + mRawdataSize = filelen; |
183 | + } |
184 | + |
185 | + ifstream ifs (wfilename, ios::binary); |
186 | + if (ifs.is_open ()) |
187 | + { |
188 | + ifs.read (mRawdata, filelen); |
189 | + ifs.close (); |
190 | + } |
191 | + |
192 | + g_free (wfilename); |
193 | + |
194 | + GError *error = NULL; |
195 | + mDoc = poppler_document_new_from_data (mRawdata, filelen, NULL, &error); |
196 | + |
197 | + if (mDoc == NULL && error && error->code == POPPLER_ERROR_ENCRYPTED) |
198 | + { |
199 | + GtkWidget *dia = gtk_message_dialog_new (NULL, |
200 | + GTK_DIALOG_DESTROY_WITH_PARENT, |
201 | + GTK_MESSAGE_QUESTION, |
202 | + GTK_BUTTONS_OK_CANCEL, |
203 | + "%s", error->message); |
204 | + g_error_free (error); |
205 | + |
206 | + |
207 | + GtkWidget *entry = gtk_entry_new (); |
208 | + gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE); |
209 | + gtk_entry_set_invisible_char (GTK_ENTRY (entry), '*'); |
210 | + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dia)->vbox), entry, TRUE, |
211 | + TRUE, 10); |
212 | + gtk_widget_show (entry); |
213 | + |
214 | + int ret = gtk_dialog_run (GTK_DIALOG (dia)); |
215 | + if (ret == GTK_RESPONSE_OK) |
216 | + { |
217 | + gchar *ans = (gchar *) gtk_entry_get_text (GTK_ENTRY (entry)); |
218 | + if (ans != NULL) |
219 | + { |
220 | + mDoc = |
221 | + poppler_document_new_from_data (mRawdata, filelen, ans, |
222 | + NULL); |
223 | + } |
224 | + } |
225 | + |
226 | + gtk_widget_destroy (dia); |
227 | + } |
228 | + |
229 | + if (mDoc == NULL) |
230 | + { |
231 | + throw std::bad_alloc (); |
232 | + } |
233 | + } |
234 | + |
235 | + ApvlvPDF::~ApvlvPDF () |
236 | + { |
237 | + if (mDoc) |
238 | + { |
239 | + g_object_unref (mDoc); |
240 | + } |
241 | + } |
242 | + |
243 | + bool ApvlvPDF::writefile (const char *filename) |
244 | + { |
245 | + debug ("write %p to %s", this, filename); |
246 | + gchar *path = absolutepath (filename); |
247 | + if (path == NULL) |
248 | + { |
249 | + debug ("filename error: %s", filename); |
250 | + return false; |
251 | + } |
252 | + |
253 | + GError *error = NULL; |
254 | + gchar *uri = g_filename_to_uri (path, NULL, &error); |
255 | + g_free (path); |
256 | + if (uri == NULL && error) |
257 | + { |
258 | + debug ("%d: %s", error->code, error->message); |
259 | + return false; |
260 | + } |
261 | + |
262 | + if (mDoc && uri != NULL) |
263 | + { |
264 | + gboolean ret = poppler_document_save (mDoc, uri, NULL); |
265 | + debug ("write pdf: %p to %s, return %d", mDoc, uri, ret); |
266 | + g_free (uri); |
267 | + return ret == TRUE ? true : false; |
268 | + } |
269 | + return false; |
270 | + } |
271 | + |
272 | + bool ApvlvPDF::pagesize (int pn, int rot, double *x, double *y) |
273 | + { |
274 | + PopplerPage *page = poppler_document_get_page (mDoc, pn); |
275 | + if (page != NULL) |
276 | + { |
277 | + if (rot == 90 || rot == 270) |
278 | + { |
279 | + poppler_page_get_size (page, y, x); |
280 | + } |
281 | + else |
282 | + { |
283 | + poppler_page_get_size (page, x, y); |
284 | + } |
285 | + return true; |
286 | + } |
287 | + return false; |
288 | + } |
289 | + |
290 | + int ApvlvPDF::pagesum () |
291 | + { |
292 | + return mDoc ? poppler_document_get_n_pages (mDoc) : 0; |
293 | + } |
294 | + |
295 | + ApvlvPoses *ApvlvPDF::pagesearch (int pn, const char *str, bool reverse) |
296 | + { |
297 | + PopplerPage *page = poppler_document_get_page (mDoc, pn); |
298 | + if (page == NULL) |
299 | + { |
300 | + return NULL; |
301 | + } |
302 | + |
303 | +// debug ("search %s", str); |
304 | + |
305 | + GList *list = poppler_page_find_text (page, str); |
306 | + if (list == NULL) |
307 | + { |
308 | + return NULL; |
309 | + } |
310 | + |
311 | + if (reverse) |
312 | + { |
313 | + list = g_list_reverse (list); |
314 | + } |
315 | + |
316 | + ApvlvPoses *poses = new ApvlvPoses; |
317 | + for (GList * tmp = list; tmp != NULL; tmp = g_list_next (tmp)) |
318 | + { |
319 | + PopplerRectangle *rect = (PopplerRectangle *) tmp->data; |
320 | +// debug ("results: %f-%f,%f-%f", rect->x1, rect->x2, rect->y1, |
321 | +// rect->y2); |
322 | + ApvlvPos pos = { rect->x1, rect->x2, rect->y1, rect->y2 }; |
323 | + poses->push_back (pos); |
324 | + } |
325 | + |
326 | + return poses; |
327 | + } |
328 | + |
329 | + bool ApvlvPDF::pagetext (int pn, int x1, int y1, int x2, int y2, char **out) |
330 | + { |
331 | + PopplerPage *page = poppler_document_get_page (mDoc, pn); |
332 | +#if POPPLER_CHECK_VERSION(0, 15, 1) |
333 | + PopplerRectangle rect = { x1, y2, x2, y1 }; |
334 | + *out = poppler_page_get_selected_text (page, POPPLER_SELECTION_WORD, &rect); |
335 | +#else |
336 | + PopplerRectangle rect = { x1, y1, x2, y2 }; |
337 | + *out = poppler_page_get_text (page, POPPLER_SELECTION_WORD, &rect); |
338 | +#endif |
339 | + if (*out != NULL) |
340 | + { |
341 | + return true; |
342 | + } |
343 | + return false; |
344 | + } |
345 | + |
346 | + bool ApvlvPDF::render (int pn, int ix, int iy, double zm, int rot, |
347 | + GdkPixbuf * pix, char *buffer) |
348 | + { |
349 | + PopplerPage *tpage; |
350 | + |
351 | + if ((tpage = poppler_document_get_page (mDoc, pn)) == NULL) |
352 | + { |
353 | + debug ("no this page: %d", pn); |
354 | + return false; |
355 | + } |
356 | + |
357 | + poppler_page_render_to_pixbuf (tpage, 0, 0, ix, iy, zm, rot, pix); |
358 | + return true; |
359 | + } |
360 | + |
361 | + bool ApvlvPDF::pageselectsearch (int pn, int ix, int iy, |
362 | + double zm, int rot, GdkPixbuf * pix, |
363 | + char *buffer, int sel, ApvlvPoses * poses) |
364 | + { |
365 | + ApvlvPos rect = (*poses)[sel]; |
366 | + |
367 | + // Caculate the correct position |
368 | + //debug ("pagex: %f, pagey: %f, x1: %f, y1: %f, x2: %f, y2: %f", pagex, pagey, rect->x1, rect->y1, rect->x2, rect->y2); |
369 | + gint x1 = MAX (rect.x1 * zm + 0.5, 0); |
370 | + gint x2 = MAX (rect.x2 * zm - 0.5, 1); |
371 | + gint y1 = MAX ((iy - rect.y2 * zm) + 0.5, 0); |
372 | + gint y2 = MAX ((iy - rect.y1 * zm) - 0.5, 1); |
373 | + //debug ("x1: %d, y1: %d, x2: %d, y2: %d", x1, y1, x2, y2); |
374 | + |
375 | + // heightlight the selection |
376 | + for (gint y = y1; y < y2; y++) |
377 | + { |
378 | + for (gint x = x1; x < x2; x++) |
379 | + { |
380 | + gint p = (gint) (y * ix * 3 + (x * 3)); |
381 | + buffer[p + 0] = 0xff - buffer[p + 0]; |
382 | + buffer[p + 1] = 0xff - buffer[p + 0]; |
383 | + buffer[p + 2] = 0xff - buffer[p + 0]; |
384 | + } |
385 | + } |
386 | + |
387 | + // change the back color of the selection |
388 | + for (ApvlvPoses::const_iterator itr = poses->begin (); |
389 | + itr != poses->end (); itr++) |
390 | + { |
391 | + // Caculate the correct position |
392 | + x1 = (gint) (itr->x1 * zm); |
393 | + x2 = (gint) (itr->x2 * zm); |
394 | + y1 = (gint) (iy - itr->y2 * zm); |
395 | + y2 = (gint) (iy - itr->y1 * zm); |
396 | + |
397 | + for (gint y = y1; y < y2; y++) |
398 | + { |
399 | + for (gint x = x1; x < x2; x++) |
400 | + { |
401 | + gint p = (gint) (y * 3 * ix + (x * 3)); |
402 | + buffer[p + 0] = 0xff - buffer[p + 0]; |
403 | + buffer[p + 1] = 0xff - buffer[p + 0]; |
404 | + buffer[p + 2] = 0xff - buffer[p + 0]; |
405 | + } |
406 | + } |
407 | + } |
408 | + |
409 | + return true; |
410 | + } |
411 | + |
412 | + ApvlvLinks *ApvlvPDF::getlinks (int pn) |
413 | + { |
414 | + PopplerPage *page = poppler_document_get_page (mDoc, pn); |
415 | + GList *list = poppler_page_get_link_mapping (page); |
416 | + if (list == NULL) |
417 | + { |
418 | + return NULL; |
419 | + } |
420 | + |
421 | + ApvlvLinks *links = new ApvlvLinks; |
422 | + |
423 | + for (GList * tmp = list; tmp != NULL; tmp = g_list_next (tmp)) |
424 | + { |
425 | + PopplerLinkMapping *map = (PopplerLinkMapping *) tmp->data; |
426 | + if (map) |
427 | + { |
428 | + PopplerAction *act = map->action; |
429 | + if (act && *(PopplerActionType *) act == POPPLER_ACTION_GOTO_DEST) |
430 | + { |
431 | + PopplerDest *pd = ((PopplerActionGotoDest *) act)->dest; |
432 | + if (pd->type == POPPLER_DEST_NAMED) |
433 | + { |
434 | + PopplerDest *destnew = poppler_document_find_dest (mDoc, |
435 | + pd->named_dest); |
436 | + if (destnew != NULL) |
437 | + { |
438 | + ApvlvLink link = { "", destnew->page_num - 1 }; |
439 | + links->insert (links->begin (), link); |
440 | + poppler_dest_free (destnew); |
441 | + } |
442 | + } |
443 | + else |
444 | + { |
445 | + ApvlvLink link = { "", pd->page_num - 1 }; |
446 | + links->insert (links->begin (), link); |
447 | + } |
448 | + } |
449 | + } |
450 | + } |
451 | + |
452 | + return links; |
453 | + } |
454 | + |
455 | + ApvlvFileIndex *ApvlvPDF::new_index () |
456 | + { |
457 | + if (mIndex != NULL) |
458 | + { |
459 | + debug ("file %p has index: %p, return", this, mIndex); |
460 | + return mIndex; |
461 | + } |
462 | + |
463 | + PopplerIndexIter *itr = poppler_index_iter_new (mDoc); |
464 | + if (itr == NULL) |
465 | + { |
466 | + debug ("no index."); |
467 | + return NULL; |
468 | + } |
469 | + |
470 | + mIndex = new ApvlvFileIndex; |
471 | + walk_poppler_index_iter (mIndex, itr); |
472 | + poppler_index_iter_free (itr); |
473 | + |
474 | + return mIndex; |
475 | + } |
476 | + |
477 | + void ApvlvPDF::free_index (ApvlvFileIndex * index) |
478 | + { |
479 | + delete index; |
480 | + } |
481 | + |
482 | + bool ApvlvPDF::walk_poppler_index_iter (ApvlvFileIndex * titr, |
483 | + PopplerIndexIter * iter) |
484 | + { |
485 | + bool has = false; |
486 | + do |
487 | + { |
488 | + has = false; |
489 | + ApvlvFileIndex *index = NULL; |
490 | + |
491 | + PopplerAction *act = poppler_index_iter_get_action (iter); |
492 | + if (act) |
493 | + { |
494 | + if (*(PopplerActionType *) act == POPPLER_ACTION_GOTO_DEST) |
495 | + { |
496 | + PopplerActionGotoDest *pagd = (PopplerActionGotoDest *) act; |
497 | + if (pagd->dest->type == POPPLER_DEST_NAMED) |
498 | + { |
499 | + PopplerDest *destnew = poppler_document_find_dest (mDoc, |
500 | + pagd-> |
501 | + dest-> |
502 | + named_dest); |
503 | + int pn = 1; |
504 | + if (destnew != NULL) |
505 | + { |
506 | + pn = destnew->page_num - 1; |
507 | + poppler_dest_free (destnew); |
508 | + } |
509 | + index = new ApvlvFileIndex; |
510 | + index->page = pn; |
511 | + } |
512 | + else |
513 | + { |
514 | + index = new ApvlvFileIndex; |
515 | + index->page = pagd->dest->page_num - 1; |
516 | + } |
517 | + |
518 | + if (index != NULL) |
519 | + { |
520 | + has = true; |
521 | + index->title = pagd->title; |
522 | + titr->children.push_back (*index); |
523 | + delete index; |
524 | + index = &(titr->children[titr->children.size () - 1]); |
525 | + debug ("titr: %p, index: %p", titr, index); |
526 | + } |
527 | + } |
528 | + poppler_action_free (act); |
529 | + } |
530 | + |
531 | + PopplerIndexIter *child = poppler_index_iter_get_child (iter); |
532 | + if (child) |
533 | + { |
534 | + bool chas = walk_poppler_index_iter (has ? index : titr, child); |
535 | + has = has ? has : chas; |
536 | + poppler_index_iter_free (child); |
537 | + } |
538 | + } |
539 | + while (poppler_index_iter_next (iter)); |
540 | + return has; |
541 | + } |
542 | + |
543 | + bool ApvlvPDF::pageprint (int pn, cairo_t * cr) |
544 | + { |
545 | +#ifdef WIN32 |
546 | + return false; |
547 | +#else |
548 | + PopplerPage *page = poppler_document_get_page (mDoc, pn); |
549 | + if (page != NULL) |
550 | + { |
551 | + poppler_page_render_for_printing (page, cr); |
552 | + return true; |
553 | + } |
554 | + else |
555 | + { |
556 | + return false; |
557 | + } |
558 | +#endif |
559 | + } |
560 | + |
561 | +#ifdef HAVE_LIBDJVU |
562 | + void handle_ddjvu_messages (ddjvu_context_t * ctx, int wait) |
563 | + { |
564 | + const ddjvu_message_t *msg; |
565 | + if (wait) |
566 | + ddjvu_message_wait (ctx); |
567 | + while ((msg = ddjvu_message_peek (ctx))) |
568 | + { |
569 | + debug ("tag: %d", msg->m_any.tag); |
570 | + switch (msg->m_any.tag) |
571 | + { |
572 | + case DDJVU_ERROR: |
573 | + break; |
574 | + case DDJVU_INFO: |
575 | + break; |
576 | + case DDJVU_PAGEINFO: |
577 | + break; |
578 | + default: |
579 | + break; |
580 | + } |
581 | + ddjvu_message_pop (ctx); |
582 | + } |
583 | + } |
584 | +#endif |
585 | + |
586 | + ApvlvDJVU::ApvlvDJVU (const char *filename, bool check):ApvlvFile (filename, |
587 | + check) |
588 | + { |
589 | +#ifdef HAVE_LIBDJVU |
590 | + mContext = ddjvu_context_create ("apvlv"); |
591 | + if (mContext) |
592 | + { |
593 | + mDoc = ddjvu_document_create_by_filename (mContext, filename, FALSE); |
594 | + } |
595 | + |
596 | + if (mDoc != NULL) |
597 | + { |
598 | + if (ddjvu_document_get_type (mDoc) == DDJVU_DOCTYPE_SINGLEPAGE) |
599 | + { |
600 | + debug ("djvu type: %d", ddjvu_document_get_type (mDoc)); |
601 | + } |
602 | + else |
603 | + { |
604 | + /* |
605 | + ddjvu_document_release (mDoc); |
606 | + mDoc = NULL; |
607 | + ddjvu_context_release (mContext); |
608 | + mContext = NULL; |
609 | + throw std::bad_alloc (); */ |
610 | + } |
611 | + } |
612 | + else |
613 | + { |
614 | + ddjvu_context_release (mContext); |
615 | + mContext = NULL; |
616 | + throw std::bad_alloc (); |
617 | + } |
618 | +#else |
619 | + throw std::bad_alloc (); |
620 | +#endif |
621 | + } |
622 | + |
623 | + ApvlvDJVU::~ApvlvDJVU () |
624 | + { |
625 | +#ifdef HAVE_LIBDJVU |
626 | + if (mContext) |
627 | + { |
628 | + ddjvu_context_release (mContext); |
629 | + } |
630 | + |
631 | + if (mDoc) |
632 | + { |
633 | + ddjvu_document_release (mDoc); |
634 | + } |
635 | +#endif |
636 | + } |
637 | + |
638 | + bool ApvlvDJVU::writefile (const char *filename) |
639 | + { |
640 | +#ifdef HAVE_LIBDJVU |
641 | + FILE *fp = fopen (filename, "wb"); |
642 | + if (fp != NULL) |
643 | + { |
644 | + ddjvu_job_t *job = ddjvu_document_save (mDoc, fp, 0, NULL); |
645 | + while (!ddjvu_job_done (job)) |
646 | + { |
647 | + handle_ddjvu_messages (mContext, TRUE); |
648 | + } |
649 | + fclose (fp); |
650 | + return true; |
651 | + } |
652 | + return false; |
653 | +#else |
654 | + return false; |
655 | +#endif |
656 | + } |
657 | + |
658 | + bool ApvlvDJVU::pagesize (int pn, int rot, double *x, double *y) |
659 | + { |
660 | +#ifdef HAVE_LIBDJVU |
661 | + ddjvu_status_t t; |
662 | + ddjvu_pageinfo_t info[1]; |
663 | + while ((t = ddjvu_document_get_pageinfo (mDoc, 0, info)) < DDJVU_JOB_OK) |
664 | + { |
665 | + handle_ddjvu_messages (mContext, true); |
666 | + } |
667 | + |
668 | + if (t == DDJVU_JOB_OK) |
669 | + { |
670 | + *x = info->width; |
671 | + *y = info->height; |
672 | + debug ("djvu page 1: %f-%f", *x, *y); |
673 | + } |
674 | + return true; |
675 | +#else |
676 | + return false; |
677 | +#endif |
678 | + } |
679 | + |
680 | + int ApvlvDJVU::pagesum () |
681 | + { |
682 | +#ifdef HAVE_LIBDJVU |
683 | + return mDoc ? ddjvu_document_get_pagenum (mDoc) : 0; |
684 | +#else |
685 | + return 0; |
686 | +#endif |
687 | + } |
688 | + |
689 | + bool ApvlvDJVU::render (int pn, int ix, int iy, double zm, int rot, |
690 | + GdkPixbuf * pix, char *buffer) |
691 | + { |
692 | +#ifdef HAVE_LIBDJVU |
693 | + ddjvu_page_t *tpage; |
694 | + |
695 | + if ((tpage = ddjvu_page_create_by_pageno (mDoc, pn)) == NULL) |
696 | + { |
697 | + debug ("no this page: %d", pn); |
698 | + return false; |
699 | + } |
700 | + |
701 | + ddjvu_rect_t prect[1] = { {0, 0, ix, iy} |
702 | + }; |
703 | + ddjvu_rect_t rrect[1] = { {0, 0, ix, iy} |
704 | + }; |
705 | + ddjvu_format_t *format = |
706 | + ddjvu_format_create (DDJVU_FORMAT_RGB24, 0, NULL); |
707 | + ddjvu_format_set_row_order (format, TRUE); |
708 | + |
709 | + gint retry = 0; |
710 | + while (retry <= 20 && ddjvu_page_render |
711 | + (tpage, DDJVU_RENDER_COLOR, prect, rrect, format, 3 * ix, |
712 | + (char *) buffer) == FALSE) |
713 | + { |
714 | + usleep (50 * 1000); |
715 | + debug ("fender failed, retry %d", ++retry); |
716 | + } |
717 | + |
718 | + return true; |
719 | +#else |
720 | + return false; |
721 | +#endif |
722 | + } |
723 | + |
724 | + bool ApvlvDJVU::pageselectsearch (int pn, int ix, int iy, double zm, |
725 | + int rot, GdkPixbuf * pix, char *buffer, |
726 | + int sel, ApvlvPoses * poses) |
727 | + { |
728 | + return false; |
729 | + } |
730 | + |
731 | + ApvlvPoses *ApvlvDJVU::pagesearch (int pn, const char *str, bool reverse) |
732 | + { |
733 | + return NULL; |
734 | + } |
735 | + |
736 | + ApvlvLinks *ApvlvDJVU::getlinks (int pn) |
737 | + { |
738 | + return NULL; |
739 | + } |
740 | + |
741 | + bool ApvlvDJVU::pagetext (int pn, int x1, int y1, int x2, int y2, |
742 | + char **out) |
743 | + { |
744 | + return false; |
745 | + } |
746 | + |
747 | + ApvlvFileIndex *ApvlvDJVU::new_index () |
748 | + { |
749 | + return NULL; |
750 | + } |
751 | + |
752 | + void ApvlvDJVU::free_index (ApvlvFileIndex * index) |
753 | + { |
754 | + } |
755 | + |
756 | + bool ApvlvDJVU::pageprint (int pn, cairo_t * cr) |
757 | + { |
758 | + return false; |
759 | + } |
760 | + |
761 | + ApvlvUMD::ApvlvUMD (const char *filename, bool check):ApvlvFile (filename, |
762 | + check) |
763 | + { |
764 | +#ifdef HAVE_LIBUMD |
765 | + gchar * lname = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL); |
766 | + if (lname) |
767 | + { |
768 | + mUmd = umd_new_from_file (lname); |
769 | + g_free (lname); |
770 | + } |
771 | + else |
772 | + { |
773 | + mUmd = umd_new_from_file (filename); |
774 | + } |
775 | + |
776 | + if (mUmd == NULL) |
777 | + { |
778 | + throw std::bad_alloc (); |
779 | + } |
780 | +#else |
781 | + throw std::bad_alloc (); |
782 | +#endif |
783 | + } |
784 | + |
785 | + ApvlvUMD::~ApvlvUMD () |
786 | + { |
787 | +#ifdef HAVE_LIBUMD |
788 | + if (mUmd) |
789 | + { |
790 | + umd_destroy (mUmd); |
791 | + } |
792 | +#endif |
793 | + } |
794 | + |
795 | + bool ApvlvUMD::writefile (const char *filename) |
796 | + { |
797 | +#ifdef HAVE_LIBUMD |
798 | + if (umd_write_file (mUmd, filename) == 0) |
799 | + { |
800 | + return true; |
801 | + } |
802 | + return false; |
803 | +#else |
804 | + return false; |
805 | +#endif |
806 | + } |
807 | + |
808 | + bool ApvlvUMD::pagesize (int pn, int rot, double *x, double *y) |
809 | + { |
810 | +#ifdef HAVE_LIBUMD |
811 | + umd_page_t * page; |
812 | + |
813 | + page = umd_get_nth_page (mUmd, pn); |
814 | + if (page) |
815 | + { |
816 | + int ix, iy; |
817 | + umd_page_get_size (page, &ix, &iy); |
818 | + *x = ix; |
819 | + *y = iy; |
820 | + return true; |
821 | + } |
822 | + return false; |
823 | +#else |
824 | + return false; |
825 | +#endif |
826 | + } |
827 | + |
828 | + int ApvlvUMD::pagesum () |
829 | + { |
830 | +#ifdef HAVE_LIBUMD |
831 | + return mUmd ? umd_get_page_n (mUmd) : 0; |
832 | +#else |
833 | + return 0; |
834 | +#endif |
835 | + } |
836 | + |
837 | + bool ApvlvUMD::render (int pn, int ix, int iy, double zm, int rot, |
838 | + GdkPixbuf * pix, char *buffer) |
839 | + { |
840 | +#ifdef HAVE_LIBUMD |
841 | + umd_page_t * page; |
842 | + |
843 | + page = umd_get_nth_page (mUmd, pn); |
844 | + if (page) |
845 | + { |
846 | + umd_page_render (page, 0, 0, ix, iy, zm, rot, (unsigned char *) buffer, 3 * ix); |
847 | + return true; |
848 | + } |
849 | + return false; |
850 | +#else |
851 | + return false; |
852 | +#endif |
853 | + } |
854 | + |
855 | + bool ApvlvUMD::pageselectsearch (int pn, int ix, int iy, double zm, |
856 | + int rot, GdkPixbuf * pix, char *buffer, |
857 | + int sel, ApvlvPoses * poses) |
858 | + { |
859 | + return false; |
860 | + } |
861 | + |
862 | + ApvlvPoses *ApvlvUMD::pagesearch (int pn, const char *str, bool reverse) |
863 | + { |
864 | + return NULL; |
865 | + } |
866 | + |
867 | + ApvlvLinks *ApvlvUMD::getlinks (int pn) |
868 | + { |
869 | + return NULL; |
870 | + } |
871 | + |
872 | + bool ApvlvUMD::pagetext (int pn, int x1, int y1, int x2, int y2, |
873 | + char **out) |
874 | + { |
875 | + return false; |
876 | + } |
877 | + |
878 | + ApvlvFileIndex *ApvlvUMD::new_index () |
879 | + { |
880 | +#ifdef HAVE_LIBUMD |
881 | + if (mIndex != NULL) |
882 | + { |
883 | + debug ("file %p has index: %p, return", this, mIndex); |
884 | + return mIndex; |
885 | + } |
886 | + |
887 | + int cpt_n = umd_get_chapter_n (mUmd); |
888 | + if (cpt_n <= 0) |
889 | + { |
890 | + debug ("no index."); |
891 | + return NULL; |
892 | + } |
893 | + |
894 | + mIndex = new ApvlvFileIndex; |
895 | + for (int i = 0; |
896 | + i < cpt_n; |
897 | + ++ i) |
898 | + { |
899 | + umd_chapter_t * chapter = umd_get_nth_chapter (mUmd, i); |
900 | + if (chapter) |
901 | + { |
902 | + ApvlvFileIndex inx; |
903 | + |
904 | + inx.title = chapter->title; |
905 | + inx.page = chapter->page_index; |
906 | + |
907 | + mIndex->children.push_back (inx); |
908 | + |
909 | + free (chapter->title); |
910 | + free (chapter->content); |
911 | + free (chapter); |
912 | + } |
913 | + } |
914 | + |
915 | + return mIndex; |
916 | +#else |
917 | + return NULL; |
918 | +#endif |
919 | + } |
920 | + |
921 | + void ApvlvUMD::free_index (ApvlvFileIndex * index) |
922 | + { |
923 | +#ifdef HAVE_LIBUMD |
924 | + delete mIndex; |
925 | +#endif |
926 | + } |
927 | + |
928 | + bool ApvlvUMD::pageprint (int pn, cairo_t * cr) |
929 | + { |
930 | + return false; |
931 | + } |
932 | + |
933 | +} |
934 | |
935 | === added file '.pc/applied-patches' |
936 | --- .pc/applied-patches 1970-01-01 00:00:00 +0000 |
937 | +++ .pc/applied-patches 2011-12-12 16:38:24 +0000 |
938 | @@ -0,0 +1,1 @@ |
939 | +00git_poppler_render_to_pixbuf.patch |
940 | |
941 | === modified file 'debian/changelog' |
942 | --- debian/changelog 2011-12-12 16:54:41 +0000 |
943 | +++ debian/changelog 2011-12-12 16:38:24 +0000 |
944 | @@ -1,3 +1,4 @@ |
945 | +<<<<<<< TREE |
946 | apvlv (0.1.1-1.1ubuntu1) precise; urgency=low |
947 | |
948 | * src/ApvlvFile.cpp Add poppler_render_to_pixbuf function for poppler |
949 | @@ -6,6 +7,17 @@ |
950 | |
951 | -- Martin Pitt <martin.pitt@ubuntu.com> Mon, 12 Dec 2011 16:54:41 +0100 |
952 | |
953 | +======= |
954 | +apvlv (0.1.1-1.1ubuntu1) precise; urgency=low |
955 | + |
956 | + * debian/source/format: Switch to 3.0 (quilt), to be able to apply patches. |
957 | + * Add 00git_poppler_render_to_pixbuf.patch: Add poppler_render_to_pixbuf |
958 | + function for poppler no gdkpixbuf support. Patch taken from upstream git |
959 | + head. |
960 | + |
961 | + -- Martin Pitt <martin.pitt@ubuntu.com> Mon, 12 Dec 2011 16:54:41 +0100 |
962 | + |
963 | +>>>>>>> MERGE-SOURCE |
964 | apvlv (0.1.1-1.1) unstable; urgency=low |
965 | |
966 | * Non-maintainer upload. |
967 | |
968 | === added directory 'debian/patches' |
969 | === added file 'debian/patches/00git_poppler_render_to_pixbuf.patch' |
970 | --- debian/patches/00git_poppler_render_to_pixbuf.patch 1970-01-01 00:00:00 +0000 |
971 | +++ debian/patches/00git_poppler_render_to_pixbuf.patch 2011-12-12 16:38:24 +0000 |
972 | @@ -0,0 +1,155 @@ |
973 | +From e5aec2fd102a0f041dc53f4aa8040ab89043e05d Mon Sep 17 00:00:00 2001 |
974 | +From: Alf <naihe2010@126.com> |
975 | +Date: Mon, 17 Oct 2011 10:15:02 +0800 |
976 | +Subject: add poppler_render_to_pixbuf function for poppler no gdkpixbuf support |
977 | + |
978 | +--- |
979 | + src/ApvlvPdf.cc | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
980 | + 1 files changed, 135 insertions(+), 0 deletions(-) |
981 | + |
982 | +Index: apvlv/src/ApvlvFile.cpp |
983 | +=================================================================== |
984 | +--- apvlv.orig/src/ApvlvFile.cpp 2011-12-12 16:44:56.000000000 +0100 |
985 | ++++ apvlv/src/ApvlvFile.cpp 2011-12-12 16:51:57.959351280 +0100 |
986 | +@@ -39,6 +39,141 @@ |
987 | + #include <iostream> |
988 | + #include <fstream> |
989 | + |
990 | ++#ifndef POPPLER_WITH_GDK |
991 | ++#include <goo/gtypes.h> |
992 | ++ |
993 | ++static void |
994 | ++copy_cairo_surface_to_pixbuf (cairo_surface_t *surface, |
995 | ++ GdkPixbuf *pixbuf) |
996 | ++{ |
997 | ++ int cairo_width, cairo_height, cairo_rowstride; |
998 | ++ unsigned char *pixbuf_data, *dst, *cairo_data; |
999 | ++ int pixbuf_rowstride, pixbuf_n_channels; |
1000 | ++ unsigned int *src; |
1001 | ++ int x, y; |
1002 | ++ |
1003 | ++ cairo_width = cairo_image_surface_get_width (surface); |
1004 | ++ cairo_height = cairo_image_surface_get_height (surface); |
1005 | ++ cairo_rowstride = cairo_image_surface_get_stride (surface); |
1006 | ++ cairo_data = cairo_image_surface_get_data (surface); |
1007 | ++ |
1008 | ++ pixbuf_data = gdk_pixbuf_get_pixels (pixbuf); |
1009 | ++ pixbuf_rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
1010 | ++ pixbuf_n_channels = gdk_pixbuf_get_n_channels (pixbuf); |
1011 | ++ |
1012 | ++ if (cairo_width > gdk_pixbuf_get_width (pixbuf)) |
1013 | ++ cairo_width = gdk_pixbuf_get_width (pixbuf); |
1014 | ++ if (cairo_height > gdk_pixbuf_get_height (pixbuf)) |
1015 | ++ cairo_height = gdk_pixbuf_get_height (pixbuf); |
1016 | ++ for (y = 0; y < cairo_height; y++) |
1017 | ++ { |
1018 | ++ src = (unsigned int *) (cairo_data + y * cairo_rowstride); |
1019 | ++ dst = pixbuf_data + y * pixbuf_rowstride; |
1020 | ++ for (x = 0; x < cairo_width; x++) |
1021 | ++ { |
1022 | ++ dst[0] = (*src >> 16) & 0xff; |
1023 | ++ dst[1] = (*src >> 8) & 0xff; |
1024 | ++ dst[2] = (*src >> 0) & 0xff; |
1025 | ++ if (pixbuf_n_channels == 4) |
1026 | ++ dst[3] = (*src >> 24) & 0xff; |
1027 | ++ dst += pixbuf_n_channels; |
1028 | ++ src++; |
1029 | ++ } |
1030 | ++ } |
1031 | ++} |
1032 | ++ |
1033 | ++static void |
1034 | ++_poppler_page_render_to_pixbuf (PopplerPage *page, |
1035 | ++ int src_x, int src_y, |
1036 | ++ int src_width, int src_height, |
1037 | ++ double scale, |
1038 | ++ int rotation, |
1039 | ++ GBool printing, |
1040 | ++ GdkPixbuf *pixbuf) |
1041 | ++{ |
1042 | ++ cairo_t *cr; |
1043 | ++ cairo_surface_t *surface; |
1044 | ++ |
1045 | ++ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, |
1046 | ++ src_width, src_height); |
1047 | ++ cr = cairo_create (surface); |
1048 | ++ cairo_save (cr); |
1049 | ++ switch (rotation) { |
1050 | ++ case 90: |
1051 | ++ cairo_translate (cr, src_x + src_width, -src_y); |
1052 | ++ break; |
1053 | ++ case 180: |
1054 | ++ cairo_translate (cr, src_x + src_width, src_y + src_height); |
1055 | ++ break; |
1056 | ++ case 270: |
1057 | ++ cairo_translate (cr, -src_x, src_y + src_height); |
1058 | ++ break; |
1059 | ++ default: |
1060 | ++ cairo_translate (cr, -src_x, -src_y); |
1061 | ++ } |
1062 | ++ |
1063 | ++ if (scale != 1.0) |
1064 | ++ cairo_scale (cr, scale, scale); |
1065 | ++ |
1066 | ++ if (rotation != 0) |
1067 | ++ cairo_rotate (cr, rotation * G_PI / 180.0); |
1068 | ++ |
1069 | ++ if (printing) |
1070 | ++ poppler_page_render_for_printing (page, cr); |
1071 | ++ else |
1072 | ++ poppler_page_render (page, cr); |
1073 | ++ cairo_restore (cr); |
1074 | ++ |
1075 | ++ cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER); |
1076 | ++ cairo_set_source_rgb (cr, 1., 1., 1.); |
1077 | ++ cairo_paint (cr); |
1078 | ++ |
1079 | ++ cairo_destroy (cr); |
1080 | ++ |
1081 | ++ copy_cairo_surface_to_pixbuf (surface, pixbuf); |
1082 | ++ cairo_surface_destroy (surface); |
1083 | ++} |
1084 | ++ |
1085 | ++/** |
1086 | ++ * poppler_page_render_to_pixbuf: |
1087 | ++ * @page: the page to render from |
1088 | ++ * @src_x: x coordinate of upper left corner |
1089 | ++ * @src_y: y coordinate of upper left corner |
1090 | ++ * @src_width: width of rectangle to render |
1091 | ++ * @src_height: height of rectangle to render |
1092 | ++ * @scale: scale specified as pixels per point |
1093 | ++ * @rotation: rotate the document by the specified degree |
1094 | ++ * @pixbuf: pixbuf to render into |
1095 | ++ * |
1096 | ++ * First scale the document to match the specified pixels per point, |
1097 | ++ * then render the rectangle given by the upper left corner at |
1098 | ++ * (src_x, src_y) and src_width and src_height. |
1099 | ++ * This function is for rendering a page that will be displayed. |
1100 | ++ * If you want to render a page that will be printed use |
1101 | ++ * poppler_page_render_to_pixbuf_for_printing() instead |
1102 | ++ * |
1103 | ++ * Deprecated: 0.16 |
1104 | ++ **/ |
1105 | ++void |
1106 | ++poppler_page_render_to_pixbuf (PopplerPage *page, |
1107 | ++ int src_x, int src_y, |
1108 | ++ int src_width, int src_height, |
1109 | ++ double scale, |
1110 | ++ int rotation, |
1111 | ++ GdkPixbuf *pixbuf) |
1112 | ++{ |
1113 | ++ g_return_if_fail (POPPLER_IS_PAGE (page)); |
1114 | ++ g_return_if_fail (scale > 0.0); |
1115 | ++ g_return_if_fail (pixbuf != NULL); |
1116 | ++ |
1117 | ++ _poppler_page_render_to_pixbuf (page, src_x, src_y, |
1118 | ++ src_width, src_height, |
1119 | ++ scale, rotation, |
1120 | ++ gFalse, |
1121 | ++ pixbuf); |
1122 | ++} |
1123 | ++#endif |
1124 | ++ |
1125 | + namespace apvlv |
1126 | + { |
1127 | + #ifndef MAX |
1128 | |
1129 | === added file 'debian/patches/series' |
1130 | --- debian/patches/series 1970-01-01 00:00:00 +0000 |
1131 | +++ debian/patches/series 2011-12-12 16:38:24 +0000 |
1132 | @@ -0,0 +1,1 @@ |
1133 | +00git_poppler_render_to_pixbuf.patch |
1134 | |
1135 | === modified file 'debian/source/format' |
1136 | --- debian/source/format 2011-06-01 22:18:49 +0000 |
1137 | +++ debian/source/format 2011-12-12 16:38:24 +0000 |
1138 | @@ -1,1 +1,1 @@ |
1139 | -1.0 |
1140 | +3.0 (quilt) |