*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <string.h>
#include "ev-document.h"
+#include "synctex_parser.h"
#define EV_DOCUMENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EV_TYPE_DOCUMENT, EvDocumentPrivate))
gdouble max_width;
gdouble max_height;
+ gdouble min_width;
+ gdouble min_height;
gint max_label;
gchar **page_labels;
EvPageSize *page_sizes;
EvDocumentInfo *info;
+
+ synctex_scanner_t synctex_scanner;
};
-static gint _ev_document_get_n_pages (EvDocument *document);
-static void _ev_document_get_page_size (EvDocument *document,
- EvPage *page,
- double *width,
- double *height);
-static gchar *_ev_document_get_page_label (EvDocument *document,
- EvPage *page);
-static EvDocumentInfo *_ev_document_get_info (EvDocument *document);
+static gint _ev_document_get_n_pages (EvDocument *document);
+static void _ev_document_get_page_size (EvDocument *document,
+ EvPage *page,
+ double *width,
+ double *height);
+static gchar *_ev_document_get_page_label (EvDocument *document,
+ EvPage *page);
+static EvDocumentInfo *_ev_document_get_info (EvDocument *document);
+static gboolean _ev_document_support_synctex (EvDocument *document);
GMutex *ev_doc_mutex = NULL;
GMutex *ev_fc_mutex = NULL;
document->priv->info = NULL;
}
+ if (document->priv->synctex_scanner) {
+ synctex_scanner_free (document->priv->synctex_scanner);
+ document->priv->synctex_scanner = NULL;
+ }
+
G_OBJECT_CLASS (ev_document_parent_class)->finalize (object);
}
klass->get_page = ev_document_impl_get_page;
klass->get_info = ev_document_impl_get_info;
+ klass->get_backend_info = NULL;
g_object_class->finalize = ev_document_finalize;
}
priv->uniform_height = page_height;
priv->max_width = priv->uniform_width;
priv->max_height = priv->uniform_height;
+ priv->min_width = priv->uniform_width;
+ priv->min_height = priv->uniform_height;
} else if (priv->uniform &&
(priv->uniform_width != page_width ||
priv->uniform_height != page_height)) {
if (page_width > priv->max_width)
priv->max_width = page_width;
+ if (page_width < priv->min_width)
+ priv->min_width = page_width;
if (page_height > priv->max_height)
priv->max_height = page_height;
+ if (page_height < priv->min_height)
+ priv->min_height = page_height;
}
page_label = _ev_document_get_page_label (document, page);
if (page_label) {
- if (priv->page_labels) {
- priv->page_labels[i] = page_label;
- } else {
- gchar *numeric_label;
-
- numeric_label = g_strdup_printf ("%d", i + 1);
- if (strcmp (numeric_label, page_label) != 0) {
- priv->page_labels = g_new0 (gchar *, priv->n_pages);
- priv->page_labels[i] = page_label;
- }
- g_free (numeric_label);
- }
+ if (!priv->page_labels)
+ priv->page_labels = g_new0 (gchar *, priv->n_pages);
+
+ priv->page_labels[i] = page_label;
priv->max_label = MAX (priv->max_label,
g_utf8_strlen (page_label, 256));
}
}
priv->info = _ev_document_get_info (document);
+ if (_ev_document_support_synctex (document)) {
+ gchar *filename;
+
+ filename = g_filename_from_uri (uri, NULL, NULL);
+ if (filename != NULL) {
+ priv->synctex_scanner =
+ synctex_scanner_new_with_output_file (filename, NULL, 1);
+ g_free (filename);
+ }
+ }
}
return retval;
return klass->get_page (document, index);
}
+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;
+}
+
static gint
_ev_document_get_n_pages (EvDocument *document)
{
return document->priv->info;
}
+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);
+}
+
cairo_surface_t *
ev_document_render (EvDocument *document,
EvRenderContext *rc)
*height = document->priv->max_height;
}
+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;
+}
+
gboolean
ev_document_check_dimensions (EvDocument *document)
{