Commit 84d8d20259df4412d77767458e1f95a0a3528d06
1 parent
2f07411b
Exists in
master
and in
1 other branch
Updating print dialog.
Showing
5 changed files
with
113 additions
and
10 deletions
Show diff stats
src/dialogs/print/begin.c
... | ... | @@ -49,10 +49,9 @@ |
49 | 49 | ); |
50 | 50 | |
51 | 51 | // Set font size based on text and context. |
52 | - | |
53 | 52 | cairo_font_extents_t extents; |
54 | 53 | double width = gtk_print_context_get_width(context); |
55 | - double cols = (double) operation->text.width; | |
54 | + double cols = (double) operation->contents.width; | |
56 | 55 | double current = width / cols; |
57 | 56 | double valid = current; |
58 | 57 | |
... | ... | @@ -68,7 +67,27 @@ |
68 | 67 | trace("Font size: %d",(int) valid); |
69 | 68 | cairo_set_font_size(cr,valid); |
70 | 69 | |
71 | - // Set view size | |
70 | + // Store font data. | |
71 | + operation->font.info.scaled = cairo_get_scaled_font(cr); | |
72 | + cairo_scaled_font_reference(operation->font.info.scaled); | |
73 | + cairo_scaled_font_extents(operation->font.info.scaled,&extents); | |
74 | + | |
75 | + operation->font.info.height = extents.height; | |
76 | + operation->font.info.descent = extents.descent; | |
77 | + operation->font.info.width = extents.max_x_advance; | |
78 | + | |
79 | + // Center text on page | |
80 | + operation->font.info.left = (gtk_print_context_get_width(context)-operation->font.info.width)/2; | |
81 | + if(operation->font.info.left < 2) | |
82 | + operation->font.info.left = 2; | |
83 | + | |
84 | + // Setup page size | |
85 | + operation->lpp = (gtk_print_context_get_height(context) / (extents.height + extents.descent)); | |
86 | + operation->pages = (operation->contents.height / operation->lpp)+1; | |
87 | + | |
88 | + trace("%d lines per page, %d pages to print",operation->lpp,operation->pages); | |
89 | + | |
90 | + gtk_print_operation_set_n_pages(prt,operation->pages); | |
72 | 91 | |
73 | 92 | } |
74 | 93 | ... | ... |
src/dialogs/print/print.c
... | ... | @@ -28,6 +28,7 @@ |
28 | 28 | */ |
29 | 29 | |
30 | 30 | #include "private.h" |
31 | + #include <sys/param.h> | |
31 | 32 | #include "../../v3270/private.h" // Required for v3270 signal. |
32 | 33 | #include <v3270/colorscheme.h> |
33 | 34 | #include <lib3270/selection.h> |
... | ... | @@ -117,7 +118,7 @@ |
117 | 118 | return GTK_WIDGET(grid); |
118 | 119 | } |
119 | 120 | |
120 | - static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget *widget) | |
121 | + static void custom_widget_apply(GtkPrintOperation *prt, GtkWidget G_GNUC_UNUSED(*widget)) | |
121 | 122 | { |
122 | 123 | V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt); |
123 | 124 | |
... | ... | @@ -135,6 +136,12 @@ |
135 | 136 | |
136 | 137 | V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(object); |
137 | 138 | |
139 | + if(operation->contents.text) | |
140 | + g_strfreev(operation->contents.text); | |
141 | + | |
142 | + if(operation->font.info.scaled) | |
143 | + cairo_scaled_font_destroy(operation->font.info.scaled); | |
144 | + | |
138 | 145 | g_free(operation->font.name); |
139 | 146 | |
140 | 147 | } |
... | ... | @@ -168,8 +175,7 @@ |
168 | 175 | widget->mode = LIB3270_PRINT_ALL; |
169 | 176 | widget->show_selection = FALSE; |
170 | 177 | widget->font.name = g_strdup(v3270_default_font); |
171 | - | |
172 | - widget->text.width = 80; | |
178 | + widget->contents.width = 80; | |
173 | 179 | |
174 | 180 | v3270_set_mono_color_table(widget->colors,"#000000","#FFFFFF"); |
175 | 181 | |
... | ... | @@ -185,6 +191,8 @@ V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT |
185 | 191 | operation->widget = GTK_V3270(widget); |
186 | 192 | operation->session = v3270_get_session(widget); |
187 | 193 | |
194 | + V3270PrintOperation_set_mode(operation, mode); | |
195 | + | |
188 | 196 | return operation; |
189 | 197 | } |
190 | 198 | |
... | ... | @@ -214,3 +222,72 @@ V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT |
214 | 222 | { |
215 | 223 | v3270_print(widget,LIB3270_PRINT_COPY); |
216 | 224 | } |
225 | + | |
226 | + void V3270PrintOperation_set_mode(V3270PrintOperation * operation, LIB3270_PRINT_MODE mode) | |
227 | + { | |
228 | + operation->mode = mode; | |
229 | + | |
230 | + // Text rectangle (in characters). | |
231 | + switch(mode) | |
232 | + { | |
233 | + case LIB3270_PRINT_ALL: | |
234 | + operation->contents.height = lib3270_get_height(operation->session); | |
235 | + operation->contents.width = lib3270_get_width(operation->session); | |
236 | + break; | |
237 | + | |
238 | + case LIB3270_PRINT_SELECTED: | |
239 | + { | |
240 | + int row, col; | |
241 | + | |
242 | + GdkRectangle rect; | |
243 | + memset(&rect,0,sizeof(rect)); | |
244 | + rect.x = lib3270_get_width(operation->session); | |
245 | + rect.y = lib3270_get_height(operation->session); | |
246 | + | |
247 | + int baddr = 0; | |
248 | + for(row = 0; row < lib3270_get_height(operation->session); row++) | |
249 | + { | |
250 | + for(col = 0; col < lib3270_get_width(operation->session); col++) | |
251 | + { | |
252 | + if(lib3270_is_selected(operation->session,baddr)) | |
253 | + { | |
254 | + rect.x = MIN(rect.x,col); | |
255 | + rect.width = MAX(rect.width,col); | |
256 | + | |
257 | + rect.y = MIN(rect.y,row); | |
258 | + rect.height = MAX(rect.height,row); | |
259 | + } | |
260 | + } | |
261 | + } | |
262 | + | |
263 | + operation->contents.height = rect.height; | |
264 | + operation->contents.width = rect.width; | |
265 | + | |
266 | + } | |
267 | + break; | |
268 | + | |
269 | + case LIB3270_PRINT_COPY: | |
270 | + { | |
271 | + lib3270_autoptr(char) text = v3270_get_copy(GTK_WIDGET(operation->widget)); | |
272 | + if(text) | |
273 | + { | |
274 | + size_t r; | |
275 | + | |
276 | + operation->contents.text = g_strsplit(text,"\n",-1); | |
277 | + operation->contents.height = g_strv_length(operation->contents.text); | |
278 | + operation->contents.width = 0; | |
279 | + | |
280 | + for(r=0;r < operation->contents.height;r++) | |
281 | + { | |
282 | + operation->contents.width = MAX(operation->contents.width,strlen(operation->contents.text[r])); | |
283 | + } | |
284 | + | |
285 | + } | |
286 | + } | |
287 | + break; | |
288 | + | |
289 | + } | |
290 | + | |
291 | + debug("%s: width=%u height=%u",__FUNCTION__,(unsigned int) operation->contents.width, (unsigned int) operation->contents.height); | |
292 | + | |
293 | + } | ... | ... |
src/dialogs/print/private.h
... | ... | @@ -48,12 +48,15 @@ |
48 | 48 | v3270 * widget; |
49 | 49 | H3270 * session; |
50 | 50 | |
51 | + size_t lpp; ///< @brief Lines per page (in rows). | |
52 | + size_t pages; ///< @brief Number of pages. | |
53 | + | |
51 | 54 | struct |
52 | 55 | { |
53 | - size_t width; ///< @brief Maximun text width (in characters) | |
54 | - size_t rows; ///< @brief Number of text rows. | |
55 | - size_t pages; ///< @brief Number of pages. | |
56 | - } text; | |
56 | + size_t width; ///< @brief Width of the contents (in columns); | |
57 | + size_t height; ///< @brief Height of the contents (in rows); | |
58 | + gchar **text; ///< @brief Text contents; | |
59 | + } contents; | |
57 | 60 | |
58 | 61 | struct |
59 | 62 | { | ... | ... |
src/include/v3270/print.h
... | ... | @@ -52,8 +52,11 @@ |
52 | 52 | /*--[ Prototipes ]-----------------------------------------------------------------------------------*/ |
53 | 53 | |
54 | 54 | LIB3270_EXPORT V3270PrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_PRINT_MODE mode); |
55 | + LIB3270_EXPORT void V3270PrintOperation_set_mode(V3270PrintOperation * operation, LIB3270_PRINT_MODE mode); | |
56 | + | |
55 | 57 | LIB3270_EXPORT GtkWidget * v3270_font_selection_new(const gchar *fontname); |
56 | 58 | |
59 | + | |
57 | 60 | LIB3270_EXPORT GType V3270PrintOperation_get_type(void); |
58 | 61 | |
59 | 62 | G_END_DECLS | ... | ... |
src/testprogram/testprogram.c
... | ... | @@ -201,6 +201,7 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { |
201 | 201 | GtkWidget *grid = gtk_grid_new(); |
202 | 202 | GtkWidget *color = v3270_color_scheme_new(); |
203 | 203 | GtkWidget *print = gtk_button_new_with_label("Print"); |
204 | + gtk_widget_set_focus_on_click(print,FALSE); | |
204 | 205 | |
205 | 206 | g_signal_connect(G_OBJECT(print),"clicked",G_CALLBACK(print_clicked),terminal); |
206 | 207 | ... | ... |