const gchar * ev_document_get_uri (EvDocument *document) { g_return_val_if_fail (EV_IS_DOCUMENT (document), NULL); return document->priv->uri; }
EvDocumentInfo * ev_document_get_info (EvDocument *document) { g_return_val_if_fail (EV_IS_DOCUMENT (document), NULL); return document->priv->info; }
gint ev_document_get_max_label_len (EvDocument *document) { g_return_val_if_fail (EV_IS_DOCUMENT (document), -1); return document->priv->max_label; }
gboolean ev_document_is_page_size_uniform (EvDocument *document) { g_return_val_if_fail (EV_IS_DOCUMENT (document), TRUE); return document->priv->uniform; }
/** * ev_document_synctex_forward_search: * @document: a #EvDocument * @source_link: a #EvSourceLink * * Peforms a Synctex forward search to obtain the area in the document * corresponding to the position @line and @column number in the source Tex file * * Returns: An EvMapping with the page number and area corresponfing to * the given line in the source file. It must be free with g_free when done */ EvMapping * ev_document_synctex_forward_search (EvDocument *document, EvSourceLink *link) { EvMapping *result = NULL; synctex_scanner_t scanner; g_return_val_if_fail (EV_IS_DOCUMENT (document), NULL); scanner = document->priv->synctex_scanner; if (!scanner) return NULL; if (synctex_display_query (scanner, link->filename, link->line, link->col) > 0) { synctex_node_t node; gint page; if ((node = synctex_next_result (scanner))) { result = g_new (EvMapping, 1); page = synctex_node_page (node) - 1; result->data = GINT_TO_POINTER (page); result->area.x1 = synctex_node_box_visible_h (node); result->area.y1 = synctex_node_box_visible_v (node) - synctex_node_box_visible_height (node); result->area.x2 = synctex_node_box_visible_width (node) + result->area.x1; result->area.y2 = synctex_node_box_visible_depth (node) + synctex_node_box_visible_height (node) + result->area.y1; } } return result; }
gboolean ev_document_check_dimensions (EvDocument *document) { g_return_val_if_fail (EV_IS_DOCUMENT (document), FALSE); return (document->priv->max_width > 0 && document->priv->max_height > 0); }
gboolean ev_document_has_synctex (EvDocument *document) { g_return_val_if_fail (EV_IS_DOCUMENT (document), FALSE); return document->priv->synctex_scanner != NULL; }
/** * ev_document_synctex_backward_search: * @document: a #EvDocument * @page_index: the target page * @x: X coordinate * @y: Y coordinate * * Peforms a Synctex backward search to obtain the TeX input file, line and * (possibly) column corresponding to the position (@x,@y) (in 72dpi * coordinates) in the @page of @document. * * Returns: A pointer to the EvSourceLink structure that holds the result. @NULL if synctex * is not enabled for the document or no result is found. * The EvSourceLink pointer should be freed with g_free after it is used. */ EvSourceLink * ev_document_synctex_backward_search (EvDocument *document, gint page_index, gfloat x, gfloat y) { EvSourceLink *result = NULL; synctex_scanner_t scanner; g_return_val_if_fail (EV_IS_DOCUMENT (document), NULL); scanner = document->priv->synctex_scanner; if (!scanner) return NULL; if (synctex_edit_query (scanner, page_index + 1, x, y) > 0) { synctex_node_t node; /* We assume that a backward search returns either zero or one result_node */ node = synctex_next_result (scanner); if (node != NULL) { const gchar *filename; filename = synctex_scanner_get_name (scanner, synctex_node_tag (node)); if (filename) { result = ev_source_link_new (filename, synctex_node_line (node), synctex_node_column (node)); } } } return result; }
/** * ev_document_load_gfile: * @document: a #EvDocument * @file: a #GFile * @flags: flags from #EvDocumentLoadFlags * @cancellable: (allow-none): a #GCancellable, or %NULL * @error: (allow-none): a #GError location to store an error, or %NULL * * Synchronously loads the document from @file. * See ev_document_load() for more information. * * Returns: %TRUE if loading succeeded, or %FALSE on error with @error filled in * * Since: 3.6 */ gboolean ev_document_load_gfile (EvDocument *document, GFile *file, EvDocumentLoadFlags flags, GCancellable *cancellable, GError **error) { EvDocumentClass *klass; EvDocumentPrivate *priv; g_return_val_if_fail (EV_IS_DOCUMENT (document), FALSE); g_return_val_if_fail (G_IS_FILE (file), FALSE); g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); klass = EV_DOCUMENT_GET_CLASS (document); if (!klass->load_gfile) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Backend does not support loading from GFile"); return FALSE; } if (!klass->load_gfile (document, file, flags, cancellable, error)) return FALSE; ev_document_setup_cache (document); priv = document->priv; priv->uri = g_file_get_uri (file); priv->info = _ev_document_get_info (document); return TRUE; }
/** * ev_document_load_stream: * @document: a #EvDocument * @stream: a #GInputStream * @flags: flags from #EvDocumentLoadFlags * @cancellable: (allow-none): a #GCancellable, or %NULL * @error: (allow-none): a #GError location to store an error, or %NULL * * Synchronously loads the document from @stream. * See ev_document_load() for more information. * * Returns: %TRUE if loading succeeded, or %FALSE on error with @error filled in * * Since: 3.6 */ gboolean ev_document_load_stream (EvDocument *document, GInputStream *stream, EvDocumentLoadFlags flags, GCancellable *cancellable, GError **error) { EvDocumentClass *klass; g_return_val_if_fail (EV_IS_DOCUMENT (document), FALSE); g_return_val_if_fail (G_IS_INPUT_STREAM (stream), FALSE); g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); klass = EV_DOCUMENT_GET_CLASS (document); if (!klass->load_stream) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Backend does not support loading from stream"); return FALSE; } if (!klass->load_stream (document, stream, flags, cancellable, error)) return FALSE; ev_document_setup_cache (document); return TRUE; }
gboolean ev_document_has_text_page_labels (EvDocument *document) { g_return_val_if_fail (EV_IS_DOCUMENT (document), FALSE); return document->priv->page_labels != NULL; }
gint ev_document_get_n_pages (EvDocument *document) { g_return_val_if_fail (EV_IS_DOCUMENT (document), 0); return document->priv->n_pages; }
const gchar * ev_document_get_title (EvDocument *document) { g_return_val_if_fail (EV_IS_DOCUMENT (document), NULL); return (document->priv->info->fields_mask & EV_DOCUMENT_INFO_TITLE) ? document->priv->info->title : NULL; }
gboolean ev_document_get_backend_info (EvDocument *document, EvDocumentBackendInfo *info) { g_return_val_if_fail (EV_IS_DOCUMENT (document), FALSE); EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document); if (klass->get_backend_info == NULL) return FALSE; return klass->get_backend_info (document, info); }
gchar * ev_document_get_page_label (EvDocument *document, gint page_index) { g_return_val_if_fail (EV_IS_DOCUMENT (document), NULL); g_return_val_if_fail (page_index >= 0 || page_index < document->priv->n_pages, NULL); return (document->priv->page_labels && document->priv->page_labels[page_index]) ? g_strdup (document->priv->page_labels[page_index]) : g_strdup_printf ("%d", page_index + 1); }
void ev_document_get_min_page_size (EvDocument *document, gdouble *width, gdouble *height) { g_return_if_fail (EV_IS_DOCUMENT (document)); if (width) *width = document->priv->min_width; if (height) *height = document->priv->min_height; }
/** * ev_document_factory_add_filters: * @chooser: a #GtkFileChooser * @document: a #EvDocument, or %NULL * * Adds some file filters to @chooser. * Always add a "All documents" format. * * If @document is not %NULL, adds a #GtkFileFilter for @document's MIME type. * * If @document is %NULL, adds a #GtkFileFilter for each document type that atril * can handle. */ void ev_document_factory_add_filters (GtkWidget *chooser, EvDocument *document) { GList *all_types; GtkFileFilter *filter; GtkFileFilter *default_filter; GtkFileFilter *document_filter; g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser)); g_return_if_fail (document == NULL || EV_IS_DOCUMENT (document)); all_types = ev_backends_manager_get_all_types_info (); default_filter = document_filter = filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("All Documents")); g_list_foreach (all_types, (GFunc)file_filter_add_mime_types, filter); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); if (document) { EvTypeInfo *info; info = ev_backends_manager_get_document_type_info (document); default_filter = filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, info->desc); file_filter_add_mime_types (info, filter); g_free (info); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); } else { GList *l; for (l = all_types; l; l = g_list_next (l)){ EvTypeInfo *info; info = (EvTypeInfo *)l->data; default_filter = filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, info->desc); file_filter_add_mime_types (info, filter); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); } } g_list_foreach (all_types, (GFunc)g_free, NULL); g_list_free (all_types); filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("All Files")); gtk_file_filter_add_pattern (filter, "*"); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), document == NULL ? document_filter : default_filter); }
gboolean ev_sidebar_page_support_document (EvSidebarPage *sidebar_page, EvDocument *document) { EvSidebarPageInterface *iface; g_return_val_if_fail (EV_IS_SIDEBAR_PAGE (sidebar_page), FALSE); g_return_val_if_fail (EV_IS_DOCUMENT (document), FALSE); iface = EV_SIDEBAR_PAGE_GET_IFACE (sidebar_page); g_return_val_if_fail (iface->support_document, FALSE); return iface->support_document (sidebar_page, document); }
gboolean ev_document_find_page_by_label (EvDocument *document, const gchar *page_label, gint *page_index) { gint i, page; glong value; gchar *endptr = NULL; EvDocumentPrivate *priv = document->priv; g_return_val_if_fail (EV_IS_DOCUMENT (document), FALSE); g_return_val_if_fail (page_label != NULL, FALSE); g_return_val_if_fail (page_index != NULL, FALSE); /* First, look for a literal label match */ for (i = 0; priv->page_labels && i < priv->n_pages; i ++) { if (priv->page_labels[i] != NULL && ! strcmp (page_label, priv->page_labels[i])) { *page_index = i; return TRUE; } } /* Second, look for a match with case insensitively */ for (i = 0; priv->page_labels && i < priv->n_pages; i++) { if (priv->page_labels[i] != NULL && ! strcasecmp (page_label, priv->page_labels[i])) { *page_index = i; return TRUE; } } /* Next, parse the label, and see if the number fits */ value = strtol (page_label, &endptr, 10); if (endptr[0] == '\0') { /* Page number is an integer */ page = MIN (G_MAXINT, value); /* convert from a page label to a page offset */ page --; if (page >= 0 && page < priv->n_pages) { *page_index = page; return TRUE; } } return FALSE; }
/** * ev_document_factory_add_filters: * @chooser: a #GtkFileChooser * @document: a #EvDocument, or %NULL * * Adds some file filters to @chooser. * Always add a "All documents" format. * * If @document is not %NULL, adds a #GtkFileFilter for @document's MIME type. * * If @document is %NULL, adds a #GtkFileFilter for each document type that evince * can handle. */ void ev_document_factory_add_filters (GtkWidget *chooser, EvDocument *document) { GtkFileFilter *filter; GtkFileFilter *default_filter; GtkFileFilter *document_filter; g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser)); g_return_if_fail (document == NULL || EV_IS_DOCUMENT (document)); default_filter = document_filter = filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("All Documents")); g_list_foreach (ev_backends_list, (GFunc)file_filter_add_mime_types, filter); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); if (document) { EvBackendInfo *info; info = get_backend_info_for_document (document); g_assert (info != NULL); default_filter = filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, info->type_desc); file_filter_add_mime_types (info, filter); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); } else { GList *l; for (l = ev_backends_list; l; l = l->next) { EvBackendInfo *info = (EvBackendInfo *) l->data; default_filter = filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, info->type_desc); file_filter_add_mime_types (info, filter); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); } } filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("All Files")); gtk_file_filter_add_pattern (filter, "*"); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter); gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), document == NULL ? document_filter : default_filter); }
/** * ev_document_get_page_size: * @document: a #EvDocument * @page_index: index of page * @width: (out) (allow-none): return location for the width of the page, or %NULL * @height: (out) (allow-none): return location for the height of the page, or %NULL */ void ev_document_get_page_size (EvDocument *document, gint page_index, double *width, double *height) { g_return_if_fail (EV_IS_DOCUMENT (document)); g_return_if_fail (page_index >= 0 || page_index < document->priv->n_pages); if (width) *width = document->priv->uniform ? document->priv->uniform_width : document->priv->page_sizes[page_index].width; if (height) *height = document->priv->uniform ? document->priv->uniform_height : document->priv->page_sizes[page_index].height; }