Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@gnome.org>2005-02-24 12:47:27 (GMT)
committer Marco Pesenti Gritti <marco@src.gnome.org>2005-02-24 12:47:27 (GMT)
commit6d7f9e7cf7678b48828be0722ae2e998ce85b7a7 (patch)
tree3ac765c1e0b92a5be0ce6a637d8577a0525d3eda
parent810d8b0808591ebb17d4913da4d20e489e9b8cde (diff)
Separate page/scale notifications
2005-02-24 Marco Pesenti Gritti <marco@gnome.org> * backend/ev-document.c: (ev_document_class_init), (ev_document_page_changed), (ev_document_scale_changed): * backend/ev-document.h: Separate page/scale notifications * pdf/xpdf/pdf-document.cc: Emit the new signals. Do not display the pdf page in _render, do it when scale/page are requested. * ps/ps-document.c: (ps_document_set_zoom), (ps_document_widget_event): * ps/ps-document.h: Emit the new signals. * shell/ev-view.c: (ev_view_size_request), (expose_bin_window), (ev_view_init), (page_changed_callback), (scale_changed_callback), (ev_view_set_document), (ev_view_zoom), (ev_view_zoom_in), (ev_view_zoom_out), (size_to_zoom_factor), (ev_view_set_size): * shell/ev-view.h: * shell/ev-window.c: (ev_window_cmd_view_normal_size), (ev_window_cmd_view_page_width), (size_allocate_cb), (ev_window_set_sizing_mode): Rework sizing to be pixel based. There are bugs but should be already way better.
-rw-r--r--ChangeLog32
-rw-r--r--backend/ev-document.c31
-rw-r--r--backend/ev-document.h6
-rw-r--r--pdf/xpdf/pdf-document.cc52
-rw-r--r--ps/ps-document.c11
-rw-r--r--ps/ps-document.h2
-rw-r--r--shell/ev-view.c171
-rw-r--r--shell/ev-view.h15
-rw-r--r--shell/ev-window.c20
9 files changed, 175 insertions, 165 deletions
diff --git a/ChangeLog b/ChangeLog
index 7fd9fd3..8e9c482 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,35 @@
+2005-02-24 Marco Pesenti Gritti <marco@gnome.org>
+
+ * backend/ev-document.c: (ev_document_class_init),
+ (ev_document_page_changed), (ev_document_scale_changed):
+ * backend/ev-document.h:
+
+ Separate page/scale notifications
+
+ * pdf/xpdf/pdf-document.cc:
+
+ Emit the new signals.
+ Do not display the pdf page in _render, do it
+ when scale/page are requested.
+
+ * ps/ps-document.c: (ps_document_set_zoom),
+ (ps_document_widget_event):
+ * ps/ps-document.h:
+
+ Emit the new signals.
+
+ * shell/ev-view.c: (ev_view_size_request), (expose_bin_window),
+ (ev_view_init), (page_changed_callback), (scale_changed_callback),
+ (ev_view_set_document), (ev_view_zoom), (ev_view_zoom_in),
+ (ev_view_zoom_out), (size_to_zoom_factor), (ev_view_set_size):
+ * shell/ev-view.h:
+ * shell/ev-window.c: (ev_window_cmd_view_normal_size),
+ (ev_window_cmd_view_page_width), (size_allocate_cb),
+ (ev_window_set_sizing_mode):
+
+ Rework sizing to be pixel based.
+ There are bugs but should be already way better.
+
2005-02-23 Marco Pesenti Gritti <marco@gnome.org>
* shell/ev-window.c: (ev_window_init):
diff --git a/backend/ev-document.c b/backend/ev-document.c
index a53cbea..5109969 100644
--- a/backend/ev-document.c
+++ b/backend/ev-document.c
@@ -27,7 +27,8 @@ static void ev_document_class_init (gpointer g_class);
enum
{
- CHANGED,
+ PAGE_CHANGED,
+ SCALE_CHANGED,
LAST_SIGNAL
};
@@ -69,11 +70,21 @@ ev_document_error_quark (void)
static void
ev_document_class_init (gpointer g_class)
{
- signals[CHANGED] =
- g_signal_new ("changed",
+ signals[PAGE_CHANGED] =
+ g_signal_new ("page_changed",
EV_TYPE_DOCUMENT,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (EvDocumentIface, changed),
+ G_STRUCT_OFFSET (EvDocumentIface, page_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ signals[SCALE_CHANGED] =
+ g_signal_new ("scale_changed",
+ EV_TYPE_DOCUMENT,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EvDocumentIface, scale_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
@@ -201,7 +212,13 @@ ev_document_render (EvDocument *document,
}
void
-ev_document_changed (EvDocument *document)
+ev_document_page_changed (EvDocument *document)
+{
+ g_signal_emit (G_OBJECT (document), signals[PAGE_CHANGED], 0);
+}
+
+void
+ev_document_scale_changed (EvDocument *document)
{
- g_signal_emit (G_OBJECT (document), signals[CHANGED], 0);
-}
+ g_signal_emit (G_OBJECT (document), signals[SCALE_CHANGED], 0);
+}
diff --git a/backend/ev-document.h b/backend/ev-document.h
index 18819f4..b54a0b9 100644
--- a/backend/ev-document.h
+++ b/backend/ev-document.h
@@ -53,7 +53,8 @@ struct _EvDocumentIface
GTypeInterface base_iface;
/* Signals */
- void (* changed) (EvDocument *document);
+ void (* page_changed) (EvDocument *document);
+ void (* scale_changed) (EvDocument *document);
/* Methods */
gboolean (* load) (EvDocument *document,
@@ -126,7 +127,8 @@ void ev_document_render (EvDocument *document,
int clip_y,
int clip_width,
int clip_height);
-void ev_document_changed (EvDocument *document);
+void ev_document_page_changed (EvDocument *document);
+void ev_document_scale_changed (EvDocument *document);
G_END_DECLS
diff --git a/pdf/xpdf/pdf-document.cc b/pdf/xpdf/pdf-document.cc
index edb8122..777e949 100644
--- a/pdf/xpdf/pdf-document.cc
+++ b/pdf/xpdf/pdf-document.cc
@@ -90,7 +90,6 @@ struct _PdfDocument
UnicodeMap *umap;
gchar *password;
- gboolean page_valid;
PdfDocumentSearch *search;
};
@@ -136,29 +135,21 @@ document_init_links (PdfDocument *pdf_document)
obj.free ();
}
-static gboolean
-document_validate_page (PdfDocument *pdf_document)
+static void
+document_display_page (PdfDocument *pdf_document)
{
- if (!pdf_document->page_valid) {
- pdf_document->doc->displayPage (pdf_document->out, pdf_document->page,
- 72 * pdf_document->scale,
- 72 * pdf_document->scale,
- 0, gTrue, gTrue);
-
- document_init_links (pdf_document);
+ pdf_document->doc->displayPage (pdf_document->out, pdf_document->page,
+ 72 * pdf_document->scale,
+ 72 * pdf_document->scale,
+ 0, gTrue, gTrue);
- pdf_document->page_valid = TRUE;
-
- ev_document_changed (EV_DOCUMENT (pdf_document));
-
- /* Update the search results available to the app since
- * we only provide full results on the current page
- */
- if (pdf_document->search)
- pdf_document_search_page_changed (pdf_document->search);
- }
+ document_init_links (pdf_document);
- return pdf_document->page_valid;
+ /* Update the search results available to the app since
+ * we only provide full results on the current page
+ */
+ if (pdf_document->search)
+ pdf_document_search_page_changed (pdf_document->search);
}
static gboolean
@@ -227,8 +218,6 @@ pdf_document_load (EvDocument *document,
if (pdf_document->out)
pdf_document->out->startDoc(pdf_document->doc->getXRef());
- pdf_document->page_valid = FALSE;
-
g_object_notify (G_OBJECT (pdf_document), "title");
return TRUE;
@@ -274,7 +263,8 @@ pdf_document_set_page (EvDocument *document,
if (page != pdf_document->page) {
pdf_document->page = page;
- pdf_document->page_valid = FALSE;
+ document_display_page (pdf_document);
+ ev_document_page_changed (EV_DOCUMENT (pdf_document));
}
}
@@ -321,7 +311,7 @@ pdf_document_set_target (EvDocument *document,
}
- pdf_document->page_valid = FALSE;
+ document_display_page (pdf_document);
}
}
@@ -333,7 +323,8 @@ pdf_document_set_scale (EvDocument *document,
if (pdf_document->scale != scale) {
pdf_document->scale = scale;
- pdf_document->page_valid = FALSE;
+ document_display_page (pdf_document);
+ ev_document_scale_changed (EV_DOCUMENT (pdf_document));
}
}
@@ -384,7 +375,7 @@ pdf_document_render (EvDocument *document,
GdkRectangle page;
GdkRectangle draw;
- if (!document_validate_page (pdf_document) || !pdf_document->target)
+ if (!pdf_document->target)
return;
page.x = pdf_document->page_x_offset;
@@ -486,12 +477,6 @@ pdf_document_search_page_changed (PdfDocumentSearch *search)
current_page = pdf_document->page;
- if (!pdf_document->page_valid) {
- /* we can't do anything until displayPage() */
- search->current_page = -1;
- return;
- }
-
if (search->current_page == current_page)
return;
@@ -1363,7 +1348,6 @@ pdf_document_init (PdfDocument *pdf_document)
pdf_document->page_y_offset = 0;
pdf_document->scale = 1.;
- pdf_document->page_valid = FALSE;
pdf_document->password = NULL;
}
diff --git a/ps/ps-document.c b/ps/ps-document.c
index 1df82e2..dea5ddf 100644
--- a/ps/ps-document.c
+++ b/ps/ps-document.c
@@ -1678,7 +1678,8 @@ ps_document_set_zoom(PSDocument * gs, gfloat zoom)
set_up_page(gs);
gs->changed = TRUE;
}
-
+
+ gs->scaling = TRUE;
ps_document_goto_page(gs, gs->current_page);
}
@@ -1760,7 +1761,13 @@ ps_document_widget_event (GtkWidget *widget, GdkEvent *event, gpointer data)
if (event->client.message_type == gs_class->page_atom) {
LOG ("GS rendered the document");
gs->busy = FALSE;
- ev_document_changed (EV_DOCUMENT (gs));
+
+ if (gs->scaling) {
+ ev_document_scale_changed (EV_DOCUMENT (gs));
+ gs->scaling = FALSE;
+ } else {
+ ev_document_page_changed (EV_DOCUMENT (gs));
+ }
}
return TRUE;
diff --git a/ps/ps-document.h b/ps/ps-document.h
index fb58ca4..5bdd282 100644
--- a/ps/ps-document.h
+++ b/ps/ps-document.h
@@ -110,6 +110,8 @@ struct _PSDocument {
int page_x_offset;
int page_y_offset;
+
+ gboolean scaling;
};
struct _PSDocumentClass {
diff --git a/shell/ev-view.c b/shell/ev-view.c
index f837ad7..c667bf9 100644
--- a/shell/ev-view.c
+++ b/shell/ev-view.c
@@ -70,12 +70,6 @@ typedef enum {
#define MIN_SCALE 0.05409
#define MAX_SCALE 18.4884
-/* FIXME: temporarily setting the epsilon very high until we figure out how to
- * constrain the size of the window to a pixel width, instead of to the zoom
- * level */
-#define ZOOM_EPSILON 1e-2
-
-
struct _EvView {
GtkWidget parent_instance;
@@ -106,7 +100,8 @@ struct _EvView {
int spacing;
double scale;
- EvSizingMode sizing_mode;
+ int width;
+ int height;
};
struct _EvViewClass {
@@ -248,10 +243,10 @@ ev_view_size_request (GtkWidget *widget,
GtkBorder border;
gint width, height;
- if (! GTK_WIDGET_REALIZED (widget))
+ if (!GTK_WIDGET_REALIZED (widget))
return;
- if (! view->document) {
+ if (!view->document) {
requisition->width = 1;
requisition->height = 1;
return;
@@ -261,22 +256,18 @@ ev_view_size_request (GtkWidget *widget,
&width, &height);
ev_document_misc_get_page_border_size (width, height, &border);
- switch (view->sizing_mode) {
- case EV_SIZING_BEST_FIT:
- requisition->width = MIN_SCALE * ((float) width) / view->scale;
- requisition->height = MIN_SCALE * ((float) height) / view->scale;
- break;
- case EV_SIZING_FIT_WIDTH:
- requisition->width = MIN_SCALE * ((float) width) / view->scale;
- requisition->height = height + border.top + border.bottom;
- requisition->height += view->spacing * 2;
- break;
- case EV_SIZING_FREE:
- requisition->width = width + border.left + border.right;
- requisition->height = height + border.top + border.bottom;
- requisition->width += view->spacing * 2;
- requisition->height += view->spacing * 2;
- break;
+ if (view->width >= 0) {
+ requisition->width = 0;
+ } else {
+ requisition->width = width + border.left + border.right +
+ view->spacing * 2;
+ }
+
+ if (view->height >= 0) {
+ requisition->height = 0;
+ } else {
+ requisition->height = height + border.top + border.bottom +
+ view->spacing * 2;
}
}
@@ -490,8 +481,10 @@ expose_bin_window (GtkWidget *widget,
view->x_offset + border.left,
view->y_offset + border.top);
- LOG ("Render area %d %d %d %d", event->area.x, event->area.y,
- event->area.width, event->area.height);
+ LOG ("Render area %d %d %d %d - Offset %d %d",
+ event->area.x, event->area.y,
+ event->area.width, event->area.height,
+ view->x_offset, view->y_offset);
ev_document_render (view->document,
event->area.x, event->area.y,
@@ -1030,7 +1023,6 @@ ev_view_init (EvView *view)
view->scale = 1.0;
view->pressed_button = -1;
view->cursor = EV_VIEW_CURSOR_NORMAL;
- view->sizing_mode = EV_SIZING_BEST_FIT;
}
static void
@@ -1210,7 +1202,7 @@ find_changed_cb (EvDocument *document, int page, EvView *view)
}
static void
-document_changed_callback (EvDocument *document,
+page_changed_callback (EvDocument *document,
EvView *view)
{
gtk_widget_queue_draw (GTK_WIDGET (view));
@@ -1220,6 +1212,13 @@ document_changed_callback (EvDocument *document,
}
}
+static void
+scale_changed_callback (EvDocument *document,
+ EvView *view)
+{
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+}
+
/*** Public API ***/
GtkWidget*
@@ -1255,8 +1254,12 @@ ev_view_set_document (EvView *view,
view);
}
g_signal_connect (view->document,
- "changed",
- G_CALLBACK (document_changed_callback),
+ "page_changed",
+ G_CALLBACK (page_changed_callback),
+ view);
+ g_signal_connect (view->document,
+ "scale_changed",
+ G_CALLBACK (scale_changed_callback),
view);
}
@@ -1269,17 +1272,6 @@ ev_view_set_document (EvView *view,
}
}
-void
-ev_view_set_mode (EvView *view,
- EvSizingMode sizing_mode)
-{
- if (view->sizing_mode == sizing_mode)
- return;
-
- view->sizing_mode = sizing_mode;
- gtk_widget_queue_resize (GTK_WIDGET (view));
-}
-
static void
go_to_link (EvView *view, EvLink *link)
{
@@ -1341,100 +1333,81 @@ ev_view_zoom (EvView *view,
scale = CLAMP (scale, MIN_SCALE, MAX_SCALE);
- if (ABS (scale - view->scale) < ZOOM_EPSILON)
- return;
-
view->scale = scale;
ev_document_set_scale (view->document, view->scale);
-
- gtk_widget_queue_resize (GTK_WIDGET (view));
}
void
ev_view_zoom_in (EvView *view)
{
+ view->width = view->height = -1;
ev_view_zoom (view, ZOOM_IN_FACTOR, TRUE);
}
void
ev_view_zoom_out (EvView *view)
{
+ view->width = view->height = -1;
ev_view_zoom (view, ZOOM_OUT_FACTOR, TRUE);
}
-void
-ev_view_normal_size (EvView *view)
-{
- ev_view_zoom (view, 1.0, FALSE);
-}
-
-/* Unfortunately this is not idempotent (!) (numerical stability
- * issues because width and height are rounded) */
-void
-ev_view_best_fit (EvView *view, int allocation_width, int allocation_height)
+static double
+size_to_zoom_factor (EvView *view, int width, int height)
{
- int target_width, target_height;
- int width, height;
+ int doc_width, doc_height;
+ double scale, scale_w, scale_h;
GtkBorder border;
- if (!GTK_WIDGET_REALIZED (view) || view->document == NULL)
- return;
-
- width = height = 0;
- /* This is the bad part. You could make it stable by doing
- * ev_document_set_scale 1.0. But at least with pdf this means
- * redrawing the whole page */
- ev_document_get_page_size (view->document, -1, &width, &height);
+ doc_width = doc_height = 0;
+ scale = scale_w = scale_h = 1.0;
+ ev_document_get_page_size (view->document, -1, &doc_width, &doc_height);
/* FIXME: The border size isn't constant. Ugh. Still, if we have extra
* space, we just cut it from the border */
- ev_document_misc_get_page_border_size (width, height, &border);
+ ev_document_misc_get_page_border_size (doc_width, doc_height, &border);
- target_width = allocation_width - (view->spacing * 2 + border.left + border.right);
- target_height = allocation_height - (view->spacing * 2 + border.top + border.bottom);
+ if (doc_width == 0 && doc_height == 0) {
+ return 0;
+ }
- LOG ("Best fit %d %d", allocation_width, allocation_height);
+ if (width >= 0) {
+ int target_width;
- if (width != 0 && height != 0) {
- double scale;
- double scale_w, scale_h;
+ target_width = width - (view->spacing * 2 + border.left + border.right);
+ scale = scale_w = (double)target_width * view->scale / doc_width;
+ }
- scale_w = (double)target_width * view->scale / width;
- scale_h = (double)target_height * view->scale / height;
+ if (height >= 0) {
+ int target_height;
- scale = (scale_w < scale_h) ? scale_w : scale_h;
+ target_height = height - (view->spacing * 2 + border.top + border.bottom);
+ scale = scale_h = (double)target_height * view->scale / doc_height;
+ }
- ev_view_zoom (view, scale, FALSE);
+ if (width >= 0 && height >= 0) {
+ scale = (scale_w < scale_h) ? scale_w : scale_h;
}
+ return scale;
}
void
-ev_view_fit_width (EvView *view, int allocation_width, int allocation_height,
- int vsb_width)
+ev_view_set_size (EvView *view,
+ int width,
+ int height)
{
- int target_width, target_height;
- int width, height;
- GtkBorder border;
+ double factor;
- if (view->document == NULL)
+ if (!view->document) {
return;
+ }
- width = height = 0;
- ev_document_get_page_size (view->document, -1, &width, &height);
- ev_document_misc_get_page_border_size (width, height, &border);
-
- target_width = allocation_width - (view->spacing * 2 + border.left + border.right);
- target_height = allocation_height - (view->spacing * 2 + border.top + border.bottom);
-
- if (width) {
- double scale;
- scale = (double)target_width * view->scale / width;
-
- if (height * scale / view->scale > target_height)
- scale = ((double)(target_width - vsb_width) * view->scale / width);
-
- ev_view_zoom (view, scale, FALSE);
+ if (view->width != width ||
+ view->height != height) {
+ view->width = width;
+ view->height = height;
+ factor = size_to_zoom_factor (view, width, height);
+ ev_view_zoom (view, factor, FALSE);
}
}
diff --git a/shell/ev-view.h b/shell/ev-view.h
index 2fdb38a..cc90fb8 100644
--- a/shell/ev-view.h
+++ b/shell/ev-view.h
@@ -31,13 +31,6 @@ G_BEGIN_DECLS
#define EV_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_VIEW, EvView))
#define EV_IS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EV_TYPE_VIEW))
-
-typedef enum {
- EV_SIZING_BEST_FIT,
- EV_SIZING_FIT_WIDTH,
- EV_SIZING_FREE,
-} EvSizingMode;
-
typedef struct _EvView EvView;
typedef struct _EvViewClass EvViewClass;
@@ -45,8 +38,6 @@ GType ev_view_get_type (void) G_GNUC_CONST;
GtkWidget* ev_view_new (void);
void ev_view_set_document (EvView *view,
EvDocument *document);
-void ev_view_set_mode (EvView *view,
- EvSizingMode mode);
/* Clipboard */
void ev_view_copy (EvView *view);
@@ -66,9 +57,9 @@ int ev_view_get_page (EvView *view);
/* Page size */
void ev_view_zoom_in (EvView *view);
void ev_view_zoom_out (EvView *view);
-void ev_view_normal_size (EvView *view);
-void ev_view_best_fit (EvView *view, int width, int height);
-void ev_view_fit_width (EvView *view, int width, int height, int vsb_width);
+void ev_view_set_size (EvView *view,
+ int width,
+ int height);
/* Find */
void ev_view_find_next (EvView *view);
diff --git a/shell/ev-window.c b/shell/ev-window.c
index df25cc2..dc88f70 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -61,6 +61,12 @@
#include "ev-stock-icons.h"
typedef enum {
+ EV_SIZING_BEST_FIT,
+ EV_SIZING_FIT_WIDTH,
+ EV_SIZING_FREE,
+} EvSizingMode;
+
+typedef enum {
PAGE_MODE_SINGLE_PAGE,
PAGE_MODE_CONTINUOUS_PAGE,
PAGE_MODE_PASSWORD,
@@ -1367,7 +1373,7 @@ ev_window_cmd_view_normal_size (GtkAction *action, EvWindow *ev_window)
{
g_return_if_fail (EV_IS_WINDOW (ev_window));
- ev_view_normal_size (EV_VIEW (ev_window->priv->view));
+ ev_view_set_size (EV_VIEW (ev_window->priv->view), -1, -1);
}
static void
@@ -1417,9 +1423,7 @@ ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
ev_window_set_sizing_mode (ev_window, EV_SIZING_FIT_WIDTH);
- ev_view_fit_width (EV_VIEW (ev_window->priv->view),
- width, height,
- vsb_requisition.width + scrollbar_spacing);
+ ev_view_set_size (EV_VIEW (ev_window->priv->view), width, height);
}
static void
@@ -1487,7 +1491,7 @@ size_allocate_cb (GtkWidget *scrolled_window,
height -= 2 * ev_window->priv->view->style->ythickness;
if (ev_window->priv->sizing_mode == EV_SIZING_BEST_FIT) {
- ev_view_best_fit (EV_VIEW (ev_window->priv->view),
+ ev_view_set_size (EV_VIEW (ev_window->priv->view),
MAX (1, width), MAX (1, height));
} else if (ev_window->priv->sizing_mode == EV_SIZING_FIT_WIDTH) {
gtk_widget_size_request (GTK_SCROLLED_WINDOW (ev_window->priv->scrolled_window)->vscrollbar,
@@ -1495,9 +1499,8 @@ size_allocate_cb (GtkWidget *scrolled_window,
gtk_widget_style_get (ev_window->priv->scrolled_window,
"scrollbar_spacing", &scrollbar_spacing,
NULL);
- ev_view_fit_width (EV_VIEW (ev_window->priv->view),
- width, height,
- vsb_requisition.width + scrollbar_spacing);
+ ev_view_set_size (EV_VIEW (ev_window->priv->view),
+ width - vsb_requisition.width - scrollbar_spacing, -1);
}
}
@@ -1542,7 +1545,6 @@ ev_window_set_sizing_mode (EvWindow *ev_window,
break;
}
- ev_view_set_mode (EV_VIEW (ev_window->priv->view), sizing_mode);
update_sizing_buttons (ev_window);
}