Commit 32cb28e15b14f580df2d8a8a1a4d01a188ba769b
1 parent
c6395548
Exists in
master
and in
1 other branch
Implementing print dialog.
Showing
2 changed files
with
76 additions
and
1 deletions
Show diff stats
src/dialogs/print/begin.c
| ... | ... | @@ -76,8 +76,12 @@ |
| 76 | 76 | operation->font.info.descent = extents.descent; |
| 77 | 77 | operation->font.info.width = extents.max_x_advance; |
| 78 | 78 | |
| 79 | + operation->font.info.width++; | |
| 80 | + | |
| 79 | 81 | // Center text on page |
| 80 | - operation->font.info.left = (gtk_print_context_get_width(context)-operation->font.info.width)/2; | |
| 82 | + // operation->font.info.left = 2; | |
| 83 | + | |
| 84 | + operation->font.info.left = (gtk_print_context_get_width(context)- (operation->font.info.width * operation->contents.width))/2; | |
| 81 | 85 | if(operation->font.info.left < 2) |
| 82 | 86 | operation->font.info.left = 2; |
| 83 | 87 | ... | ... |
src/dialogs/print/draw.c
| ... | ... | @@ -28,10 +28,81 @@ |
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | 30 | #include "private.h" |
| 31 | + #include <string.h> | |
| 31 | 32 | |
| 32 | 33 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 33 | 34 | |
| 34 | 35 | void V3270PrintOperation_draw_page(GtkPrintOperation *prt, GtkPrintContext *context, gint page) |
| 35 | 36 | { |
| 37 | + cairo_t * cr = gtk_print_context_get_cairo_context(context); | |
| 38 | + V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt); | |
| 39 | + | |
| 40 | + size_t from = page * operation->lpp; | |
| 41 | + | |
| 42 | + if(from > operation->contents.height) | |
| 43 | + return; | |
| 44 | + | |
| 45 | + // Create a rectangle with the size of 1 character. | |
| 46 | + GdkRectangle rect; | |
| 47 | + memset(&rect,0,sizeof(rect)); | |
| 48 | + rect.y = 2; | |
| 49 | + rect.height = operation->font.info.height + operation->font.info.descent; | |
| 50 | + rect.width = operation->font.info.width; | |
| 51 | + | |
| 52 | + // Draw "operation->lpp" lines starting from "from" | |
| 53 | + | |
| 54 | + // Clear contents. | |
| 55 | + gdk_cairo_set_source_rgba(cr,operation->colors + V3270_COLOR_BACKGROUND); | |
| 56 | + cairo_rectangle( | |
| 57 | + cr, | |
| 58 | + operation->font.info.left-1,0, | |
| 59 | + (rect.width * operation->contents.width) + 4, | |
| 60 | + (rect.height * operation->contents.height) + 4 | |
| 61 | + ); | |
| 62 | + | |
| 63 | + cairo_fill(cr); | |
| 64 | + cairo_stroke(cr); | |
| 65 | + | |
| 66 | + // draw "lpp" lines starting from "from" | |
| 67 | + size_t r; | |
| 68 | + | |
| 69 | + cairo_set_scaled_font(cr,operation->font.info.scaled); | |
| 70 | + | |
| 71 | + for(r = 0; r < operation->lpp; r++) | |
| 72 | + { | |
| 73 | + rect.x = operation->font.info.left; | |
| 74 | + | |
| 75 | + size_t row = r+from; | |
| 76 | + if(row > operation->contents.height || !operation->contents.text[row]) | |
| 77 | + break; | |
| 78 | + | |
| 79 | + size_t col; | |
| 80 | + column * columns = operation->contents.text[row]; | |
| 81 | + for(col = 0; col < operation->contents.width; col++) | |
| 82 | + { | |
| 83 | + if(columns[col].c) | |
| 84 | + { | |
| 85 | + // Draw character | |
| 86 | + v3270_draw_element( | |
| 87 | + cr, | |
| 88 | + columns[col].c, | |
| 89 | + columns[col].attr, | |
| 90 | + operation->session, | |
| 91 | + &operation->font.info, | |
| 92 | + &rect, | |
| 93 | + operation->colors | |
| 94 | + ); | |
| 95 | + | |
| 96 | + } | |
| 97 | + | |
| 98 | + // Advance to the next char | |
| 99 | + rect.x += (rect.width-1); | |
| 100 | + | |
| 101 | + } | |
| 102 | + | |
| 103 | + // Advance to the next row | |
| 104 | + rect.y += (rect.height-1); | |
| 105 | + | |
| 106 | + } | |
| 36 | 107 | |
| 37 | 108 | } | ... | ... |