From: Carlos Garcia Campos Date: Sun, 6 Aug 2006 18:11:18 +0000 (+0000) Subject: Convert from PDF style coordinates to X style coordinates in the backend X-Git-Tag: EVINCE_0_5_5~4 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=058053f904f5ca0c875399e748b3b92aecb956fd;p=evince.git Convert from PDF style coordinates to X style coordinates in the backend 2006-08-06 Carlos Garcia Campos * pdf/ev-poppler.cc: (ev_link_dest_from_dest), (ev_link_from_action), (build_tree), (pdf_document_links_get_links), (pdf_document_links_find_link_dest): * shell/ev-view.c: (goto_fitr_dest), (goto_fith_dest), (goto_xyz_dest): Convert from PDF style coordinates to X style coordinates in the backend rather than in the view. Fixes bug #338440 --- diff --git a/ChangeLog b/ChangeLog index 875c47eb..8580a645 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-08-06 Carlos Garcia Campos + + * pdf/ev-poppler.cc: (ev_link_dest_from_dest), (ev_link_from_action), + (build_tree), (pdf_document_links_get_links), + (pdf_document_links_find_link_dest): + * shell/ev-view.c: (goto_fitr_dest), (goto_fith_dest), + (goto_xyz_dest): + + Convert from PDF style coordinates to X style coordinates in the + backend rather than in the view. Fixes bug #338440 + 2006-08-06 Nickolay V. Shmyrev * shell/ev-window.c: diff --git a/pdf/ev-poppler.cc b/pdf/ev-poppler.cc index f6b1d64f..8745d775 100644 --- a/pdf/ev-poppler.cc +++ b/pdf/ev-poppler.cc @@ -80,9 +80,11 @@ static void pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails gint *height); static int pdf_document_get_n_pages (EvDocument *document); -static EvLinkDest *ev_link_dest_from_dest (PopplerDest *dest); -static EvLink *ev_link_from_action (PopplerAction *action); -static void pdf_document_search_free (PdfDocumentSearch *search); +static EvLinkDest *ev_link_dest_from_dest (PdfDocument *pdf_document, + PopplerDest *dest); +static EvLink *ev_link_from_action (PdfDocument *pdf_document, + PopplerAction *action); +static void pdf_document_search_free (PdfDocumentSearch *search); G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT, @@ -781,37 +783,62 @@ pdf_document_links_has_document_links (EvDocumentLinks *document_links) } static EvLinkDest * -ev_link_dest_from_dest (PopplerDest *dest) +ev_link_dest_from_dest (PdfDocument *pdf_document, + PopplerDest *dest) { EvLinkDest *ev_dest = NULL; const char *unimplemented_dest = NULL; g_assert (dest != NULL); - + switch (dest->type) { - case POPPLER_DEST_XYZ: + case POPPLER_DEST_XYZ: { + PopplerPage *poppler_page; + double height; + + poppler_page = poppler_document_get_page (pdf_document->document, + MAX (0, dest->page_num - 1)); + poppler_page_get_size (poppler_page, NULL, &height); ev_dest = ev_link_dest_new_xyz (dest->page_num - 1, dest->left, - dest->top, + height - dest->top, dest->zoom); + g_object_unref (poppler_page); + } break; case POPPLER_DEST_FIT: ev_dest = ev_link_dest_new_fit (dest->page_num - 1); break; - case POPPLER_DEST_FITH: + case POPPLER_DEST_FITH: { + PopplerPage *poppler_page; + double height; + + poppler_page = poppler_document_get_page (pdf_document->document, + MAX (0, dest->page_num - 1)); + poppler_page_get_size (poppler_page, NULL, &height); ev_dest = ev_link_dest_new_fith (dest->page_num - 1, - dest->top); + height - dest->top); + g_object_unref (poppler_page); + } break; case POPPLER_DEST_FITV: ev_dest = ev_link_dest_new_fitv (dest->page_num - 1, dest->left); break; - case POPPLER_DEST_FITR: + case POPPLER_DEST_FITR: { + PopplerPage *poppler_page; + double height; + + poppler_page = poppler_document_get_page (pdf_document->document, + MAX (0, dest->page_num - 1)); + poppler_page_get_size (poppler_page, NULL, &height); ev_dest = ev_link_dest_new_fitr (dest->page_num - 1, dest->left, - dest->bottom, + height - dest->bottom, dest->right, - dest->top); + height - dest->top); + g_object_unref (poppler_page); + } break; case POPPLER_DEST_FITB: unimplemented_dest = "POPPLER_DEST_FITB"; @@ -829,7 +856,7 @@ ev_link_dest_from_dest (PopplerDest *dest) unimplemented_dest = "POPPLER_DEST_UNKNOWN"; break; } - + if (unimplemented_dest) { g_warning ("Unimplemented named action: %s, please post a " "bug report in Evince bugzilla " @@ -844,7 +871,8 @@ ev_link_dest_from_dest (PopplerDest *dest) } static EvLink * -ev_link_from_action (PopplerAction *action) +ev_link_from_action (PdfDocument *pdf_document, + PopplerAction *action) { EvLink *link = NULL; EvLinkAction *ev_action = NULL; @@ -854,14 +882,14 @@ ev_link_from_action (PopplerAction *action) case POPPLER_ACTION_GOTO_DEST: { EvLinkDest *dest; - dest = ev_link_dest_from_dest (action->goto_dest.dest); + dest = ev_link_dest_from_dest (pdf_document, action->goto_dest.dest); ev_action = ev_link_action_new_dest (dest); } break; case POPPLER_ACTION_GOTO_REMOTE: { EvLinkDest *dest; - dest = ev_link_dest_from_dest (action->goto_remote.dest); + dest = ev_link_dest_from_dest (pdf_document, action->goto_remote.dest); ev_action = ev_link_action_new_remote (dest, action->goto_remote.file_name); @@ -926,22 +954,22 @@ build_tree (PdfDocument *pdf_document, dest = poppler_document_find_dest (pdf_document->document, action->goto_dest.dest->named_dest); if (!dest) { - link = ev_link_from_action (action); + link = ev_link_from_action (pdf_document, action); break; } - ev_dest = ev_link_dest_from_dest (dest); + ev_dest = ev_link_dest_from_dest (pdf_document, dest); poppler_dest_free (dest); ev_action = ev_link_action_new_dest (ev_dest); link = ev_link_new (action->any.title, ev_action); } else { - link = ev_link_from_action (action); + link = ev_link_from_action (pdf_document, action); } } break; default: - link = ev_link_from_action (action); + link = ev_link_from_action (pdf_document, action); break; } @@ -1017,7 +1045,8 @@ pdf_document_links_get_links (EvDocumentLinks *document_links, link_mapping = (PopplerLinkMapping *)list->data; ev_link_mapping = g_new (EvLinkMapping, 1); - ev_link_mapping->link = ev_link_from_action (link_mapping->action); + ev_link_mapping->link = ev_link_from_action (pdf_document, + link_mapping->action); ev_link_mapping->x1 = link_mapping->area.x1; ev_link_mapping->x2 = link_mapping->area.x2; /* Invert this for X-style coordinates */ @@ -1045,7 +1074,7 @@ pdf_document_links_find_link_dest (EvDocumentLinks *document_links, dest = poppler_document_find_dest (pdf_document->document, link_name); if (dest) { - ev_dest = ev_link_dest_from_dest (dest); + ev_dest = ev_link_dest_from_dest (pdf_document, dest); poppler_dest_free (dest); } diff --git a/shell/ev-view.c b/shell/ev-view.c index 3c2090db..6ef026b6 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -1080,22 +1080,20 @@ static void goto_fitr_dest (EvView *view, EvLinkDest *dest) { EvPoint doc_point; - int page; double zoom; zoom = zoom_for_size_best_fit (ev_link_dest_get_right (dest) - ev_link_dest_get_left (dest), - ev_link_dest_get_top (dest) - ev_link_dest_get_bottom (dest), + ev_link_dest_get_bottom (dest) - ev_link_dest_get_top (dest), ev_view_get_width (view), ev_view_get_height (view), 0, 0); ev_view_set_sizing_mode (view, EV_SIZING_FREE); ev_view_set_zoom (view, zoom, FALSE); - page = ev_link_dest_get_page (dest); doc_point.x = ev_link_dest_get_left (dest); doc_point.y = ev_link_dest_get_top (dest); - view->current_page = page; + view->current_page = ev_link_dest_get_page (dest); view->pending_point = doc_point; view->pending_scroll = SCROLL_TO_PAGE_POSITION; @@ -1140,7 +1138,7 @@ goto_fith_dest (EvView *view, EvLinkDest *dest) ev_page_cache_get_size (view->page_cache, page, 0, 1.0, &doc_width, &doc_height); doc_point.x = 0; - doc_point.y = doc_height - ev_link_dest_get_top (dest); + doc_point.y = ev_link_dest_get_top (dest); zoom = zoom_for_size_fit_width (doc_width, ev_link_dest_get_top (dest), ev_view_get_width (view), @@ -1195,7 +1193,7 @@ goto_xyz_dest (EvView *view, EvLinkDest *dest) } doc_point.x = ev_link_dest_get_left (dest); - doc_point.y = height - ev_link_dest_get_top (dest); + doc_point.y = ev_link_dest_get_top (dest); view->current_page = page; view->pending_point = doc_point;