[gedit/wip/printing-improvements] print-preview: clarify preview_draw()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/printing-improvements] print-preview: clarify preview_draw()
- Date: Sat, 27 Jun 2015 11:37:16 +0000 (UTC)
commit 8109ab57caaa97443aac147fd0b1061783d66a2e
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Jun 27 13:33:43 2015 +0200
print-preview: clarify preview_draw()
- With two nested loops, i and j are not good index variables. It's much
clearer with 'row' and 'col'.
- Avoid an indentation level with an early-return.
Now that the code is clearer, I suspect that there are some bugs in
there, let's see that for a future commit.
gedit/gedit-print-preview.c | 55 ++++++++++++++++++++++--------------------
1 files changed, 29 insertions(+), 26 deletions(-)
---
diff --git a/gedit/gedit-print-preview.c b/gedit/gedit-print-preview.c
index c582e06..ec685fa 100644
--- a/gedit/gedit-print-preview.c
+++ b/gedit/gedit-print-preview.c
@@ -938,47 +938,50 @@ preview_draw (GtkWidget *widget,
GeditPrintPreview *preview)
{
GdkWindow *bin_window;
- gint pg;
- gint i, j;
+ gint page_num;
+ gint col;
bin_window = gtk_layout_get_bin_window (preview->layout);
- if (gtk_cairo_should_draw_window (cr, bin_window))
+ if (!gtk_cairo_should_draw_window (cr, bin_window))
{
- cairo_save (cr);
+ return GDK_EVENT_STOP;
+ }
+
+ cairo_save (cr);
- gtk_cairo_transform_to_window (cr, widget, bin_window);
+ gtk_cairo_transform_to_window (cr, widget, bin_window);
- /* get the first page to display */
- pg = get_first_page_displayed (preview);
+ page_num = get_first_page_displayed (preview);
- for (i = 0; i < preview->cols; ++i)
+ for (col = 0; col < preview->cols; col++)
+ {
+ gint row;
+
+ for (row = 0; row < preview->rows; row++)
{
- for (j = 0; j < preview->rows; ++j)
+ if (!gtk_print_operation_preview_is_selected (preview->gtk_preview, page_num))
{
- if (!gtk_print_operation_preview_is_selected (preview->gtk_preview, pg))
- {
- continue;
- }
+ continue;
+ }
- if (pg == preview->n_pages)
- {
- break;
- }
+ if (page_num == preview->n_pages)
+ {
+ break;
+ }
- draw_page (cr,
- j * preview->tile_width,
- i * preview->tile_height,
- pg,
- preview);
+ draw_page (cr,
+ row * preview->tile_width,
+ col * preview->tile_height,
+ page_num,
+ preview);
- ++pg;
- }
+ page_num++;
}
-
- cairo_restore (cr);
}
+ cairo_restore (cr);
+
return GDK_EVENT_STOP;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]