X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=backend%2Fev-document.c;h=3395bf7c4ac40173364190840fb53483db9fbeab;hb=848665b157185945d190a7a746d054d7f5d5e6e0;hp=e80f95fccf2567a50dd204ce7e824f0ca66c31f3;hpb=81ab197b294eaaba8b6b99bf2c259c5adb1e2251;p=evince.git diff --git a/backend/ev-document.c b/backend/ev-document.c index e80f95fc..3395bf7c 100644 --- a/backend/ev-document.c +++ b/backend/ev-document.c @@ -21,18 +21,15 @@ #include "config.h" #include "ev-document.h" + #include "ev-backend-marshalers.h" static void ev_document_class_init (gpointer g_class); -enum -{ - CHANGED, - LAST_SIGNAL -}; -static guint signals[LAST_SIGNAL] = { 0 }; +GMutex *ev_doc_mutex = NULL; +#define LOG(x) GType ev_document_get_type (void) { @@ -56,115 +53,218 @@ ev_document_get_type (void) return type; } +GQuark +ev_document_error_quark (void) +{ + static GQuark q = 0; + if (q == 0) + q = g_quark_from_static_string ("ev-document-error-quark"); + + return q; +} + static void ev_document_class_init (gpointer g_class) { - signals[CHANGED] = - g_signal_new ("changed", - EV_TYPE_DOCUMENT, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EvDocumentIface, changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); +} + +GMutex * +ev_document_get_doc_mutex (void) +{ + if (ev_doc_mutex == NULL) { + ev_doc_mutex = g_mutex_new (); + } + return ev_doc_mutex; +} - g_object_interface_install_property (g_class, - g_param_spec_string ("title", - "Document Title", - "The title of the document", - NULL, - G_PARAM_READABLE)); +void +ev_document_doc_mutex_lock (void) +{ + g_mutex_lock (ev_document_get_doc_mutex ()); } +void +ev_document_doc_mutex_unlock (void) +{ + g_mutex_unlock (ev_document_get_doc_mutex ()); +} + + + gboolean ev_document_load (EvDocument *document, const char *uri, GError **error) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - return iface->load (document, uri, error); + gboolean retval; + LOG ("ev_document_load"); + retval = iface->load (document, uri, error); + + return retval; } -char * -ev_document_get_title (EvDocument *document) +gboolean +ev_document_save (EvDocument *document, + const char *uri, + GError **error) { - char *title; + EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); + gboolean retval; - g_object_get (document, "title", &title, NULL); + LOG ("ev_document_save"); + retval = iface->save (document, uri, error); - return title; + return retval; } int ev_document_get_n_pages (EvDocument *document) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - return iface->get_n_pages (document); + gint retval; + + LOG ("ev_document_get_n_pages"); + retval = iface->get_n_pages (document); + + return retval; } void -ev_document_set_page (EvDocument *document, - int page) +ev_document_get_page_size (EvDocument *document, + int page, + double *width, + double *height) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - iface->set_page (document, page); + + LOG ("ev_document_get_page_size"); + iface->get_page_size (document, page, width, height); } -int -ev_document_get_page (EvDocument *document) +char * +ev_document_get_page_label(EvDocument *document, + int page) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - return iface->get_page (document); + + LOG ("ev_document_get_page_label"); + if (iface->get_page_label == NULL) + return NULL; + + return iface->get_page_label (document, page); } -void -ev_document_set_target (EvDocument *document, - GdkDrawable *target) +gboolean +ev_document_can_get_text (EvDocument *document) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - iface->set_target (document, target); + + return iface->can_get_text (document); } -void -ev_document_set_scale (EvDocument *document, - double scale) +EvDocumentInfo * +ev_document_get_info (EvDocument *document) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - iface->set_scale (document, scale); + + return iface->get_info (document); } -void -ev_document_set_page_offset (EvDocument *document, - int x, - int y) +char * +ev_document_get_text (EvDocument *document, + int page, + EvRectangle *rect) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - iface->set_page_offset (document, x, y); + char *retval; + + LOG ("ev_document_get_text"); + retval = iface->get_text (document, page, rect); + + return retval; } -void -ev_document_get_page_size (EvDocument *document, - int *width, - int *height) +GList * +ev_document_get_links (EvDocument *document, + int page) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - iface->get_page_size (document, width, height); + GList *retval; + + LOG ("ev_document_get_link"); + if (iface->get_links == NULL) + return NULL; + retval = iface->get_links (document, page); + + return retval; +} + + + +GdkPixbuf * +ev_document_render_pixbuf (EvDocument *document, + EvRenderContext *rc) +{ + EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); + GdkPixbuf *retval; + + LOG ("ev_document_render_pixbuf"); + g_assert (iface->render_pixbuf); + + retval = iface->render_pixbuf (document, rc); + + return retval; +} + +EvOrientation +ev_document_get_orientation (EvDocument *document) +{ + EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); + + return iface->get_orientation (document); } void -ev_document_render (EvDocument *document, - int clip_x, - int clip_y, - int clip_width, - int clip_height) +ev_document_set_orientation (EvDocument *document, + EvOrientation orientation) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - iface->render (document, clip_x, clip_y, clip_width, clip_height); + + iface->set_orientation (document, orientation); } void -ev_document_changed (EvDocument *document) +ev_document_info_free (EvDocumentInfo *info) { - g_signal_emit (G_OBJECT (document), signals[CHANGED], 0); -} + if (info == NULL) + return; + + g_free (info->title); + g_free (info->format); + g_free (info->author); + g_free (info->subject); + g_free (info->keywords); + g_free (info->security); + + 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)); +}