Commit b9416a4943167b9f0f6a290eb6495828e813ff87
1 parent
80458d0d
Exists in
master
and in
5 other branches
Incluindo opcao para ajustar a escala das fontes automaticamente
Showing
8 changed files
with
61 additions
and
65 deletions
Show diff stats
src/include/pw3270.h
| @@ -67,6 +67,7 @@ | @@ -67,6 +67,7 @@ | ||
| 67 | LIB3270_EXPORT void pw3270_set_session_name(GtkWidget *widget, const gchar *name); | 67 | LIB3270_EXPORT void pw3270_set_session_name(GtkWidget *widget, const gchar *name); |
| 68 | 68 | ||
| 69 | LIB3270_EXPORT gint pw3270_get_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint def); | 69 | LIB3270_EXPORT gint pw3270_get_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint def); |
| 70 | + LIB3270_EXPORT void pw3270_set_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint val); | ||
| 70 | 71 | ||
| 71 | typedef enum pw3270_src | 72 | typedef enum pw3270_src |
| 72 | { | 73 | { |
src/include/pw3270/v3270.h
| @@ -187,6 +187,7 @@ | @@ -187,6 +187,7 @@ | ||
| 187 | LIB3270_EXPORT const gchar * v3270_get_session_name(GtkWidget *widget); | 187 | LIB3270_EXPORT const gchar * v3270_get_session_name(GtkWidget *widget); |
| 188 | LIB3270_EXPORT void v3270_set_session_name(GtkWidget *widget, const gchar *name); | 188 | LIB3270_EXPORT void v3270_set_session_name(GtkWidget *widget, const gchar *name); |
| 189 | LIB3270_EXPORT int v3270_set_script(GtkWidget *widget, const gchar id, unsigned char on); | 189 | LIB3270_EXPORT int v3270_set_script(GtkWidget *widget, const gchar id, unsigned char on); |
| 190 | + LIB3270_EXPORT void v3270_set_scaled_fonts(GtkWidget *widget, gboolean on); | ||
| 190 | 191 | ||
| 191 | LIB3270_EXPORT void v3270_set_host(GtkWidget *widget, const gchar *uri); | 192 | LIB3270_EXPORT void v3270_set_host(GtkWidget *widget, const gchar *uri); |
| 192 | 193 |
src/pw3270/main.c
| @@ -184,12 +184,12 @@ int main(int argc, char *argv[]) | @@ -184,12 +184,12 @@ int main(int argc, char *argv[]) | ||
| 184 | static const GOptionEntry app_options[] = | 184 | static const GOptionEntry app_options[] = |
| 185 | { | 185 | { |
| 186 | #if ! defined( WIN32 ) | 186 | #if ! defined( WIN32 ) |
| 187 | - { "appname", 'a', 0, G_OPTION_ARG_CALLBACK, appname, N_( "Application name" ), PACKAGE_NAME }, | 187 | + { "appname", 'a', 0, G_OPTION_ARG_CALLBACK, appname, N_( "Application name" ), PACKAGE_NAME }, |
| 188 | #else | 188 | #else |
| 189 | - { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, | 189 | + { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, |
| 190 | #endif // WIN32 | 190 | #endif // WIN32 |
| 191 | - { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME }, | ||
| 192 | - { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL }, | 191 | + { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME }, |
| 192 | + { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL }, | ||
| 193 | { NULL } | 193 | { NULL } |
| 194 | }; | 194 | }; |
| 195 | 195 |
src/pw3270/print.c
| @@ -60,29 +60,6 @@ | @@ -60,29 +60,6 @@ | ||
| 60 | 60 | ||
| 61 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 61 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 62 | 62 | ||
| 63 | -/* | ||
| 64 | - static void setup_font(GtkPrintContext * context, PRINT_INFO *info) | ||
| 65 | - { | ||
| 66 | - cairo_t *cr = gtk_print_context_get_cairo_context(context); | ||
| 67 | - | ||
| 68 | - trace("Font: %s",info->font); | ||
| 69 | - cairo_select_font_face(cr, info->font, CAIRO_FONT_SLANT_NORMAL, info->fontweight); | ||
| 70 | - | ||
| 71 | - info->font_scaled = cairo_get_scaled_font(cr); | ||
| 72 | - cairo_scaled_font_reference(info->font_scaled); | ||
| 73 | - cairo_scaled_font_extents(info->font_scaled,&info->extents); | ||
| 74 | - | ||
| 75 | - info->width = ((double) info->cols) * info->extents.max_x_advance; | ||
| 76 | - info->height = ((double) info->rows) * (info->extents.height + info->extents.descent); | ||
| 77 | - | ||
| 78 | - // Center image | ||
| 79 | - info->left = (gtk_print_context_get_width(context)-info->width)/2; | ||
| 80 | - if(info->left < 2) | ||
| 81 | - info->left = 2; | ||
| 82 | - | ||
| 83 | - | ||
| 84 | - } | ||
| 85 | -*/ | ||
| 86 | static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) | 63 | static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) |
| 87 | { | 64 | { |
| 88 | cairo_t * cr = gtk_print_context_get_cairo_context(context); | 65 | cairo_t * cr = gtk_print_context_get_cairo_context(context); |
| @@ -602,6 +579,7 @@ static gchar * enum_to_string(GType type, guint enum_value) | @@ -602,6 +579,7 @@ static gchar * enum_to_string(GType type, guint enum_value) | ||
| 602 | { | 579 | { |
| 603 | case PW3270_SRC_ALL: | 580 | case PW3270_SRC_ALL: |
| 604 | case PW3270_SRC_SELECTED: | 581 | case PW3270_SRC_SELECTED: |
| 582 | + case PW3270_SRC_USER: | ||
| 605 | g_signal_connect(print,"draw_page",G_CALLBACK(draw_screen),info); | 583 | g_signal_connect(print,"draw_page",G_CALLBACK(draw_screen),info); |
| 606 | break; | 584 | break; |
| 607 | 585 | ||
| @@ -625,6 +603,8 @@ static gchar * enum_to_string(GType type, guint enum_value) | @@ -625,6 +603,8 @@ static gchar * enum_to_string(GType type, guint enum_value) | ||
| 625 | } | 603 | } |
| 626 | g_signal_connect(print,"draw_page",G_CALLBACK(draw_text),info); | 604 | g_signal_connect(print,"draw_page",G_CALLBACK(draw_text),info); |
| 627 | break; | 605 | break; |
| 606 | + | ||
| 607 | + | ||
| 628 | } | 608 | } |
| 629 | 609 | ||
| 630 | // Run Print dialog | 610 | // Run Print dialog |
src/pw3270/tools.c
| @@ -104,3 +104,8 @@ LIB3270_EXPORT gint pw3270_get_integer(GtkWidget *widget, const gchar *group, co | @@ -104,3 +104,8 @@ LIB3270_EXPORT gint pw3270_get_integer(GtkWidget *widget, const gchar *group, co | ||
| 104 | { | 104 | { |
| 105 | return get_integer_from_config(group, key, def); | 105 | return get_integer_from_config(group, key, def); |
| 106 | } | 106 | } |
| 107 | + | ||
| 108 | +LIB3270_EXPORT void pw3270_set_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint val) | ||
| 109 | +{ | ||
| 110 | + set_integer_to_config(group, key, val); | ||
| 111 | +} |
src/pw3270/v3270/private.h
| @@ -125,10 +125,11 @@ G_BEGIN_DECLS | @@ -125,10 +125,11 @@ G_BEGIN_DECLS | ||
| 125 | GtkWidget parent; | 125 | GtkWidget parent; |
| 126 | 126 | ||
| 127 | // flags | 127 | // flags |
| 128 | - int selecting : 1; /**< Selecting region */ | ||
| 129 | - int moving : 1; /**< Moving selected region */ | ||
| 130 | - int resizing : 1; /**< Resizing selected region */ | ||
| 131 | - int table : 1; /**< Copy mode is table */ | 128 | + int selecting : 1; /**< Selecting region */ |
| 129 | + int moving : 1; /**< Moving selected region */ | ||
| 130 | + int resizing : 1; /**< Resizing selected region */ | ||
| 131 | + int table : 1; /**< Copy mode is table */ | ||
| 132 | + int scaled_fonts : 1; /**< Use scaled fonts */ | ||
| 132 | 133 | ||
| 133 | #if GTK_CHECK_VERSION(3,0,0) | 134 | #if GTK_CHECK_VERSION(3,0,0) |
| 134 | 135 |
src/pw3270/v3270/widget.c
| @@ -521,9 +521,7 @@ static void v3270_class_init(v3270Class *klass) | @@ -521,9 +521,7 @@ static void v3270_class_init(v3270Class *klass) | ||
| 521 | void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height) | 521 | void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height) |
| 522 | { | 522 | { |
| 523 | // update font metrics | 523 | // update font metrics |
| 524 | - static const int font_size[] = { 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 24, 26, 28, 32, 36, 40, 48, 56, 64, 72, 0 }; | ||
| 525 | - int f, rows, cols, hFont; | ||
| 526 | - int size = font_size[0]; | 524 | + int rows, cols, hFont, size; |
| 527 | 525 | ||
| 528 | cairo_font_extents_t extents; | 526 | cairo_font_extents_t extents; |
| 529 | 527 | ||
| @@ -533,47 +531,46 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig | @@ -533,47 +531,46 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig | ||
| 533 | 531 | ||
| 534 | cairo_select_font_face(cr, terminal->font_family, CAIRO_FONT_SLANT_NORMAL,terminal->font_weight); | 532 | cairo_select_font_face(cr, terminal->font_family, CAIRO_FONT_SLANT_NORMAL,terminal->font_weight); |
| 535 | 533 | ||
| 536 | - for(f=0;font_size[f];f++) | ||
| 537 | - { | ||
| 538 | - cairo_set_font_size(cr,font_size[f]); | ||
| 539 | - cairo_font_extents(cr,&extents); | ||
| 540 | - | ||
| 541 | - if(f == 0) | ||
| 542 | - { | ||
| 543 | - terminal->minimum_width = (cols * extents.max_x_advance); | ||
| 544 | - terminal->minimum_height = ((rows+1) * (extents.height + extents.descent)) + (OIA_TOP_MARGIN+2); | ||
| 545 | - } | 534 | + if(terminal->scaled_fonts) |
| 535 | + { | ||
| 536 | + double w = ((double)width) / ((double)cols); | ||
| 537 | + double h = ((double) height) / ((double) (rows+2)); | ||
| 546 | 538 | ||
| 547 | - if( HEIGHT_IN_PIXELS(terminal,(extents.height+extents.descent)) < height && WIDTH_IN_PIXELS(terminal,extents.max_x_advance) < width ) | ||
| 548 | - size = font_size[f]; | ||
| 549 | - } | 539 | + cairo_set_font_size(cr,w < h ? w : h); |
| 540 | + } | ||
| 541 | + else | ||
| 542 | + { | ||
| 543 | + static const int font_size[] = { 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 24, 26, 28, 32, 36, 40, 48, 56, 64, 72, 0 }; | ||
| 544 | + int f; | ||
| 550 | 545 | ||
| 551 | - cairo_set_font_size(cr,size); | 546 | + size = font_size[0]; |
| 552 | 547 | ||
| 553 | -#if !GTK_CHECK_VERSION(3,0,0) | ||
| 554 | - gtk_widget_set_size_request(GTK_WIDGET(terminal),terminal->minimum_width,terminal->minimum_height); | ||
| 555 | -#endif // !GTK(3,0,0) | 548 | + for(f=0;font_size[f];f++) |
| 549 | + { | ||
| 550 | + cairo_set_font_size(cr,font_size[f]); | ||
| 551 | + cairo_font_extents(cr,&extents); | ||
| 556 | 552 | ||
| 557 | -/* | ||
| 558 | - double sx, sy; | ||
| 559 | - cairo_matrix_t font_matrix; | 553 | + if(f == 0) |
| 554 | + { | ||
| 555 | + terminal->minimum_width = (cols * extents.max_x_advance); | ||
| 556 | + terminal->minimum_height = ((rows+1) * (extents.height + extents.descent)) + (OIA_TOP_MARGIN+2); | ||
| 557 | + } | ||
| 560 | 558 | ||
| 561 | - cairo_set_font_size(cr,10); | ||
| 562 | - cairo_font_extents(cr,&extents); | 559 | + if( HEIGHT_IN_PIXELS(terminal,(extents.height+extents.descent)) < height && WIDTH_IN_PIXELS(terminal,extents.max_x_advance) < width ) |
| 560 | + size = font_size[f]; | ||
| 561 | + } | ||
| 563 | 562 | ||
| 564 | - trace("font - extents.height=%f extents.width=%f",extents.height,extents.max_x_advance); | 563 | + cairo_set_font_size(cr,size); |
| 565 | 564 | ||
| 566 | - sx = ((double) width) / (((double) terminal->cols) * extents.max_x_advance); | ||
| 567 | - sy = ((double) height) / (((double) terminal->rows) * extents.height); | 565 | + #if !GTK_CHECK_VERSION(3,0,0) |
| 566 | + gtk_widget_set_size_request(GTK_WIDGET(terminal),terminal->minimum_width,terminal->minimum_height); | ||
| 567 | + #endif // !GTK(3,0,0) | ||
| 568 | 568 | ||
| 569 | - trace("sy=%f sx=%f ",sy,sx); | 569 | + } |
| 570 | 570 | ||
| 571 | - cairo_get_font_matrix(cr,&font_matrix); | ||
| 572 | - cairo_matrix_scale(&font_matrix, sx, sy); | ||
| 573 | - cairo_set_font_matrix(cr,&font_matrix); | ||
| 574 | -*/ | 571 | + cairo_font_extents(cr,&extents); |
| 575 | 572 | ||
| 576 | - /* Save scaled font for use on next drawings */ | 573 | + // Save scaled font for use on next drawings |
| 577 | if(terminal->font_scaled) | 574 | if(terminal->font_scaled) |
| 578 | cairo_scaled_font_destroy(terminal->font_scaled); | 575 | cairo_scaled_font_destroy(terminal->font_scaled); |
| 579 | 576 | ||
| @@ -1407,6 +1404,15 @@ const gchar * v3270_get_session_name(GtkWidget *widget) | @@ -1407,6 +1404,15 @@ const gchar * v3270_get_session_name(GtkWidget *widget) | ||
| 1407 | return GTK_V3270(widget)->session_name; | 1404 | return GTK_V3270(widget)->session_name; |
| 1408 | } | 1405 | } |
| 1409 | 1406 | ||
| 1407 | +void v3270_set_scaled_fonts(GtkWidget *widget, gboolean on) | ||
| 1408 | +{ | ||
| 1409 | + g_return_if_fail(GTK_IS_V3270(widget)); | ||
| 1410 | + | ||
| 1411 | + GTK_V3270(widget)->scaled_fonts = on ? 1 : 0; | ||
| 1412 | + | ||
| 1413 | + trace("Sfonts is %s",GTK_V3270(widget)->scaled_fonts ? "YES" : "NO"); | ||
| 1414 | +} | ||
| 1415 | + | ||
| 1410 | void v3270_set_session_name(GtkWidget *widget, const gchar *name) | 1416 | void v3270_set_session_name(GtkWidget *widget, const gchar *name) |
| 1411 | { | 1417 | { |
| 1412 | g_return_if_fail(GTK_IS_V3270(widget)); | 1418 | g_return_if_fail(GTK_IS_V3270(widget)); |
src/pw3270/window.c
| @@ -196,6 +196,8 @@ | @@ -196,6 +196,8 @@ | ||
| 196 | if(pw3270_get_toggle(widget,LIB3270_TOGGLE_CONNECT_ON_STARTUP)) | 196 | if(pw3270_get_toggle(widget,LIB3270_TOGGLE_CONNECT_ON_STARTUP)) |
| 197 | v3270_connect(GTK_PW3270(widget)->terminal,NULL); | 197 | v3270_connect(GTK_PW3270(widget)->terminal,NULL); |
| 198 | 198 | ||
| 199 | + v3270_set_scaled_fonts(GTK_PW3270(widget)->terminal,get_integer_from_config("terminal","sfonts",0) ? TRUE : FALSE); | ||
| 200 | + | ||
| 199 | return widget; | 201 | return widget; |
| 200 | } | 202 | } |
| 201 | 203 |