GtkAction *action_prev;
GtkAction *action_next;
+ GtkAction *action_zoom_in;
+ GtkAction *action_zoom_out;
+ GtkAction *action_zoom_100;
+
GtkWidget *drawing_area;
PopplerDocument *document;
PopplerPage *page;
gint page_no;
+ gdouble scale;
} RaktWindowPriv;
static void window_finalize (GObject *object);
static void on_action_open (GtkAction *action, RaktWindow *window);
static void on_action_go_next (GtkAction *action, RaktWindow *window);
static void on_action_go_previous (GtkAction *action, RaktWindow *window);
+static void on_action_zoom (GtkAction *action, RaktWindow *window);
static void on_action_about (GtkAction *action, RaktWindow *window);
static const GtkActionEntry action_entries[] = {
{
"GoMenu", NULL, "_Go", NULL, NULL, NULL
},
+ {
+ "ViewMenu", NULL, "_View", NULL, NULL, NULL
+ },
{
"HelpMenu", NULL, "_Help", NULL, NULL, NULL
},
"<control>p", "Previous",
G_CALLBACK (on_action_go_previous)
},
+ {
+ "Zoom In", GTK_STOCK_ZOOM_IN, "Zoom _In",
+ "<control>plus", "Zoom In",
+ G_CALLBACK (on_action_zoom)
+ },
+ {
+ "Zoom Out", GTK_STOCK_ZOOM_OUT, "Zoom _Out",
+ "<control>minus", "Zoom Out",
+ G_CALLBACK (on_action_zoom)
+ },
+ {
+ "Zoom 100", GTK_STOCK_ZOOM_100, "Zoom 100%",
+ NULL, "Zoom 100%",
+ G_CALLBACK (on_action_zoom)
+ },
{
"Quit", GTK_STOCK_QUIT, "_Quit",
"<control>Q", "Quit the application",
" <menuitem action='Previous'/>"
" <menuitem action='Next'/>"
" </menu>"
+ " <menu action='ViewMenu'>"
+ " <menuitem action='Zoom In'/>"
+ " <menuitem action='Zoom Out'/>"
+ " <menuitem action='Zoom 100'/>"
+ " </menu>"
" <menu action='HelpMenu'>"
" <menuitem action='About'/>"
" </menu>"
" <toolitem action='Open'/>"
" <toolitem action='Previous'/>"
" <toolitem action='Next'/>"
+ " <toolitem action='Zoom In'/>"
+ " <toolitem action='Zoom Out'/>"
+ " <toolitem action='Zoom 100'/>"
" </toolbar>"
"</ui>";
gtk_action_set_sensitive (priv->action_prev, priv->page_no > 0);
gtk_action_set_sensitive (priv->action_next, priv->page_no < n_pages - 1);
+ gtk_action_set_sensitive (priv->action_zoom_in, priv->scale < 3.0);
+ gtk_action_set_sensitive (priv->action_zoom_out, priv->scale > 0.4);
+ gtk_action_set_sensitive (priv->action_zoom_100, priv->scale != 1.0);
+
priv->page = poppler_document_get_page (priv->document, priv->page_no);
poppler_page_get_size (priv->page, &tmpw, &tmph);
- width = (int) (tmpw + 0.5);
- height = (int) (tmph + 0.5);
+ width = (int) (tmpw * priv->scale + 0.5);
+ height = (int) (tmph * priv->scale + 0.5);
gtk_widget_set_size_request (priv->drawing_area, width, height);
gtk_widget_queue_draw_area (priv->drawing_area, 0, 0, width, height);
"ui/ToolBar/Previous");
priv->action_next = gtk_ui_manager_get_action (priv->ui_manager,
"ui/ToolBar/Next");
+ priv->action_zoom_in = gtk_ui_manager_get_action (priv->ui_manager,
+ "ui/ToolBar/Zoom In");
+ priv->action_zoom_out = gtk_ui_manager_get_action (priv->ui_manager,
+ "ui/ToolBar/Zoom Out");
+ priv->action_zoom_100 = gtk_ui_manager_get_action (priv->ui_manager,
+ "ui/ToolBar/Zoom 100");
gtk_action_set_sensitive (priv->action_prev, false);
gtk_action_set_sensitive (priv->action_next, false);
+
+ gtk_action_set_sensitive (priv->action_zoom_in, false);
+ gtk_action_set_sensitive (priv->action_zoom_out, false);
+ gtk_action_set_sensitive (priv->action_zoom_100, false);
}
static gboolean
cairo_set_source_rgb (cr, 255, 255, 255);
cairo_paint (cr);
+ cairo_scale (cr, priv->scale, priv->scale);
+
if (priv->page)
poppler_page_render (priv->page, cr);
priv = GET_PRIV (window);
+ priv->scale = 1.0;
+
gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
render_page (window);
}
+static void
+on_action_zoom (GtkAction *action, RaktWindow *window)
+{
+ RaktWindowPriv *priv;
+
+ priv = GET_PRIV (window);
+
+ if (action == priv->action_zoom_in)
+ priv->scale += 0.2;
+ else if (action == priv->action_zoom_out)
+ priv->scale -= 0.2;
+ else
+ priv->scale = 1.0;
+
+ render_page (window);
+}
+
static void
on_action_about (GtkAction *action, RaktWindow *window)
{