Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/backend
diff options
context:
space:
mode:
authorJonathan Blandford <jrb@redhat.com>2005-06-30 05:44:28 (GMT)
committer Jonathan Blandford <jrb@src.gnome.org>2005-06-30 05:44:28 (GMT)
commite93b3a265bbc02546d230204402e3f41e83d6ab5 (patch)
tree9a56861f73e0b9a523a2d8cba2d817318a639605 /backend
parenta50ca0528a09e8e001c4600371048774e4029057 (diff)
Massive changes. We now support text selection of pdfs, and not just
Thu Jun 30 01:43:00 2005 Jonathan Blandford <jrb@redhat.com> * shell/*: * backend/ev-render-context.[ch]: * backend/ev-selection.[ch]: Massive changes. We now support text selection of pdfs, and not just rectangular selection. This is pretty broken still, but I want to get something into CVS.
Diffstat (limited to 'backend')
-rw-r--r--backend/Makefile.am4
-rw-r--r--backend/ev-document.c26
-rw-r--r--backend/ev-document.h22
-rw-r--r--backend/ev-render-context.c79
-rw-r--r--backend/ev-render-context.h75
-rw-r--r--backend/ev-selection.c80
-rw-r--r--backend/ev-selection.h68
7 files changed, 337 insertions, 17 deletions
diff --git a/backend/Makefile.am b/backend/Makefile.am
index b000dc4..8ce117d 100644
--- a/backend/Makefile.am
+++ b/backend/Makefile.am
@@ -30,6 +30,10 @@ libevbackend_la_SOURCES= \
ev-document-info.h \
ev-ps-exporter.c \
ev-ps-exporter.h \
+ ev-render-context.h \
+ ev-render-context.c \
+ ev-selection.h \
+ ev-selection.c \
ev-document-misc.h \
ev-document-misc.c \
$(NULL)
diff --git a/backend/ev-document.c b/backend/ev-document.c
index 9bccc4c..3395bf7 100644
--- a/backend/ev-document.c
+++ b/backend/ev-document.c
@@ -203,9 +203,8 @@ ev_document_get_links (EvDocument *document,
GdkPixbuf *
-ev_document_render_pixbuf (EvDocument *document,
- int page,
- double scale)
+ev_document_render_pixbuf (EvDocument *document,
+ EvRenderContext *rc)
{
EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
GdkPixbuf *retval;
@@ -213,7 +212,7 @@ ev_document_render_pixbuf (EvDocument *document,
LOG ("ev_document_render_pixbuf");
g_assert (iface->render_pixbuf);
- retval = iface->render_pixbuf (document, page, scale);
+ retval = iface->render_pixbuf (document, rc);
return retval;
}
@@ -250,3 +249,22 @@ ev_document_info_free (EvDocumentInfo *info)
g_free (info);
}
+
+
+/* Compares two rects. returns 0 if they're equal */
+#define EPSILON 0.0000001
+
+gint
+ev_rect_cmp (EvRectangle *a,
+ EvRectangle *b)
+{
+ if (a == b)
+ return 0;
+ if (a == NULL || b == NULL)
+ return 1;
+
+ return ! ((ABS (a->x1 - b->x1) < EPSILON) &&
+ (ABS (a->y1 - b->y1) < EPSILON) &&
+ (ABS (a->x2 - b->x2) < EPSILON) &&
+ (ABS (a->y2 - b->y2) < EPSILON));
+}
diff --git a/backend/ev-document.h b/backend/ev-document.h
index 044014f..e95ce96 100644
--- a/backend/ev-document.h
+++ b/backend/ev-document.h
@@ -28,6 +28,7 @@
#include "ev-link.h"
#include "ev-document-info.h"
+#include "ev-render-context.h"
G_BEGIN_DECLS
@@ -55,14 +56,6 @@ typedef enum
EV_DOCUMENT_ERROR_ENCRYPTED
} EvDocumentError;
-typedef enum
-{
- EV_ORIENTATION_PORTRAIT,
- EV_ORIENTATION_LANDSCAPE,
- EV_ORIENTATION_UPSIDEDOWN,
- EV_ORIENTATION_SEASCAPE
-} EvOrientation;
-
typedef struct {
double x1;
double y1;
@@ -94,9 +87,8 @@ struct _EvDocumentIface
EvRectangle *rect);
GList * (* get_links) (EvDocument *document,
int page);
- GdkPixbuf * (* render_pixbuf) (EvDocument *document,
- int page,
- double scale);
+ GdkPixbuf * (* render_pixbuf) (EvDocument *document,
+ EvRenderContext *rc);
EvOrientation (* get_orientation) (EvDocument *document);
void (* set_orientation) (EvDocument *document,
EvOrientation orientation);
@@ -130,12 +122,16 @@ char *ev_document_get_text (EvDocument *document,
GList *ev_document_get_links (EvDocument *document,
int page);
GdkPixbuf *ev_document_render_pixbuf (EvDocument *document,
- int page,
- double scale);
+ EvRenderContext *rc);
EvOrientation ev_document_get_orientation (EvDocument *document);
void ev_document_set_orientation (EvDocument *document,
EvOrientation orientation);
+
+gint ev_rect_cmp (EvRectangle *a,
+ EvRectangle *b);
+
+
G_END_DECLS
#endif
diff --git a/backend/ev-render-context.c b/backend/ev-render-context.c
new file mode 100644
index 0000000..2d09d44
--- /dev/null
+++ b/backend/ev-render-context.c
@@ -0,0 +1,79 @@
+#include "ev-render-context.h"
+
+static void ev_render_context_init (EvRenderContext *rc);
+static void ev_render_context_class_init (EvRenderContextClass *class);
+
+
+G_DEFINE_TYPE (EvRenderContext, ev_render_context, G_TYPE_OBJECT);
+
+static void ev_render_context_init (EvRenderContext *rc) { /* Do Nothing */ }
+
+static void
+ev_render_context_dispose (GObject *object)
+{
+ EvRenderContext *rc;
+
+ rc = (EvRenderContext *) object;
+
+ if (rc->destroy) {
+ (*rc->destroy) (rc->data);
+ rc->destroy = NULL;
+ }
+
+ (* G_OBJECT_CLASS (ev_render_context_parent_class)->dispose) (object);
+}
+
+static void
+ev_render_context_class_init (EvRenderContextClass *class)
+{
+ GObjectClass *oclass;
+
+ oclass = G_OBJECT_CLASS (class);
+
+ oclass->dispose = ev_render_context_dispose;
+}
+
+
+EvRenderContext *
+ev_render_context_new (EvOrientation orientation,
+ gint page,
+ gdouble scale)
+{
+ EvRenderContext *rc;
+
+ rc = (EvRenderContext *) g_object_new (EV_TYPE_RENDER_CONTEXT, NULL);
+
+ rc->orientation = orientation;
+ rc->page = page;
+ rc->scale = scale;
+
+ return rc;
+}
+
+void
+ev_render_context_set_page (EvRenderContext *rc,
+ gint page)
+{
+ g_return_if_fail (rc != NULL);
+
+ rc->page = page;
+}
+
+void
+ev_render_context_set_orientation (EvRenderContext *rc,
+ EvOrientation orientation)
+{
+ g_return_if_fail (rc != NULL);
+
+ rc->orientation = orientation;
+}
+
+void
+ev_render_context_set_scale (EvRenderContext *rc,
+ gdouble scale)
+{
+ g_return_if_fail (rc != NULL);
+
+ rc->scale = scale;
+}
+
diff --git a/backend/ev-render-context.h b/backend/ev-render-context.h
new file mode 100644
index 0000000..7bd73d6
--- /dev/null
+++ b/backend/ev-render-context.h
@@ -0,0 +1,75 @@
+/* this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2005 Jonathan Blandford <jrb@gnome.org>
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * 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.
+ */
+
+#ifndef EV_RENDER_CONTEXT_H
+#define EV_RENDER_CONTEXT_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef struct _EvRenderContext EvRenderContext;
+typedef struct _EvRenderContextClass EvRenderContextClass;
+
+#define EV_TYPE_RENDER_CONTEXT (ev_render_context_get_type())
+#define EV_RENDER_CONTEXT(context) ((EvRenderContext *) (context))
+#define EV_RENDER_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_RENDER_CONTEXT, EvRenderContext))
+#define EV_IS_RENDER_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_RENDER_CONTEXT))
+
+typedef enum
+{
+ EV_ORIENTATION_PORTRAIT,
+ EV_ORIENTATION_LANDSCAPE,
+ EV_ORIENTATION_UPSIDEDOWN,
+ EV_ORIENTATION_SEASCAPE
+} EvOrientation;
+
+
+struct _EvRenderContextClass
+{
+ GObjectClass klass;
+};
+
+struct _EvRenderContext
+{
+ GObject parent;
+ EvOrientation orientation;
+ gint page;
+ gdouble scale;
+
+ gpointer data;
+ GDestroyNotify destroy;
+};
+
+
+GType ev_render_context_get_type (void) G_GNUC_CONST;
+EvRenderContext *ev_render_context_new (EvOrientation orientation,
+ gint page,
+ gdouble scale);
+void ev_render_context_set_page (EvRenderContext *rc,
+ gint page);
+void ev_render_context_set_orientation (EvRenderContext *rc,
+ EvOrientation orientation);
+void ev_render_context_set_scale (EvRenderContext *rc,
+ gdouble scale);
+
+
+G_END_DECLS
+
+#endif /* !EV_RENDER_CONTEXT */
diff --git a/backend/ev-selection.c b/backend/ev-selection.c
new file mode 100644
index 0000000..fc8caa6
--- /dev/null
+++ b/backend/ev-selection.c
@@ -0,0 +1,80 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
+/*
+ * Copyright (C) 2005 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ *
+ */
+
+#include "config.h"
+
+#include "ev-selection.h"
+
+static void ev_selection_base_init (gpointer g_class);
+
+GType
+ev_selection_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0))
+ {
+ static const GTypeInfo our_info =
+ {
+ sizeof (EvSelectionIface),
+ ev_selection_base_init,
+ NULL,
+ };
+
+ type = g_type_register_static (G_TYPE_INTERFACE,
+ "EvSelection",
+ &our_info, (GTypeFlags)0);
+ }
+
+ return type;
+}
+
+static void
+ev_selection_base_init (gpointer g_class)
+{
+ static gboolean initialized = FALSE;
+
+ if (!initialized) {
+ }
+}
+
+
+void
+ev_selection_render_selection (EvSelection *selection,
+ EvRenderContext *rc,
+ GdkPixbuf **pixbuf,
+ EvRectangle *points,
+ EvRectangle *old_points)
+{
+ EvSelectionIface *iface = EV_SELECTION_GET_IFACE (selection);
+
+ iface->render_selection (selection, rc,
+ pixbuf,
+ points, old_points);
+}
+
+GdkRegion *ev_selection_get_selection_region (EvSelection *selection,
+ EvRenderContext *rc,
+ EvRectangle *points)
+{
+ EvSelectionIface *iface = EV_SELECTION_GET_IFACE (selection);
+
+ return iface->get_selection_region (selection, rc, points);
+}
diff --git a/backend/ev-selection.h b/backend/ev-selection.h
new file mode 100644
index 0000000..a07d639
--- /dev/null
+++ b/backend/ev-selection.h
@@ -0,0 +1,68 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
+/*
+ * Copyright (C) 2000-2003 Marco Pesenti Gritti
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ *
+ */
+
+#ifndef EV_SELECTION_H
+#define EV_SELECTION_H
+
+#include <glib-object.h>
+#include <glib.h>
+#include <gdk/gdkpixbuf.h>
+#include <gdk/gdk.h>
+#include "ev-document.h"
+
+G_BEGIN_DECLS
+
+#define EV_TYPE_SELECTION (ev_selection_get_type ())
+#define EV_SELECTION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_SELECTION, EvSelection))
+#define EV_SELECTION_IFACE(k) (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_SELECTION, EvSelectionIface))
+#define EV_IS_SELECTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EV_TYPE_SELECTION))
+#define EV_IS_SELECTION_IFACE(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EV_TYPE_SELECTION))
+#define EV_SELECTION_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), EV_TYPE_SELECTION, EvSelectionIface))
+
+typedef struct _EvSelection EvSelection;
+typedef struct _EvSelectionIface EvSelectionIface;
+
+struct _EvSelectionIface
+{
+ GTypeInterface base_iface;
+
+ void (* render_selection) (EvSelection *selection,
+ EvRenderContext *rc,
+ GdkPixbuf **pixbuf,
+ EvRectangle *points,
+ EvRectangle *old_points);
+ GdkRegion * (* get_selection_region) (EvSelection *selection,
+ EvRenderContext *rc,
+ EvRectangle *points);
+};
+
+GType ev_selection_get_type (void);
+void ev_selection_render_selection (EvSelection *selection,
+ EvRenderContext *rc,
+ GdkPixbuf **pixbuf,
+ EvRectangle *points,
+ EvRectangle *old_points);
+GdkRegion *ev_selection_get_selection_region (EvSelection *selection,
+ EvRenderContext *rc,
+ EvRectangle *points);
+
+G_END_DECLS
+
+#endif