+static gboolean
+_ev_document_support_synctex (EvDocument *document)
+{
+ EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
+
+ return klass->support_synctex ? klass->support_synctex (document) : FALSE;
+}
+
+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:
+ * @page: the target page
+ * @x:
+ * @y:
+ *
+ * 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) {
+ result = g_new (EvSourceLink, 1);
+ result->filename = synctex_scanner_get_name (scanner,
+ synctex_node_tag (node));
+ result->line = synctex_node_line (node);
+ result->col = synctex_node_column (node);
+ }
+ }
+
+ return result;
+}
+
+/**
+ * ev_document_synctex_forward_search:
+ * @document:
+ * @source_link:
+ *
+ * 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;
+}
+