From b9416a4943167b9f0f6a290eb6495828e813ff87 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Mon, 1 Oct 2012 22:54:17 +0000 Subject: [PATCH] Incluindo opcao para ajustar a escala das fontes automaticamente --- src/include/pw3270.h | 1 + src/include/pw3270/v3270.h | 1 + src/pw3270/main.c | 8 ++++---- src/pw3270/print.c | 26 +++----------------------- src/pw3270/tools.c | 5 +++++ src/pw3270/v3270/private.h | 9 +++++---- src/pw3270/v3270/widget.c | 74 ++++++++++++++++++++++++++++++++++++++++---------------------------------- src/pw3270/window.c | 2 ++ 8 files changed, 61 insertions(+), 65 deletions(-) diff --git a/src/include/pw3270.h b/src/include/pw3270.h index d64c7e1..f867d90 100644 --- a/src/include/pw3270.h +++ b/src/include/pw3270.h @@ -67,6 +67,7 @@ LIB3270_EXPORT void pw3270_set_session_name(GtkWidget *widget, const gchar *name); LIB3270_EXPORT gint pw3270_get_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint def); + LIB3270_EXPORT void pw3270_set_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint val); typedef enum pw3270_src { diff --git a/src/include/pw3270/v3270.h b/src/include/pw3270/v3270.h index 1f5d05a..febddef 100644 --- a/src/include/pw3270/v3270.h +++ b/src/include/pw3270/v3270.h @@ -187,6 +187,7 @@ LIB3270_EXPORT const gchar * v3270_get_session_name(GtkWidget *widget); LIB3270_EXPORT void v3270_set_session_name(GtkWidget *widget, const gchar *name); LIB3270_EXPORT int v3270_set_script(GtkWidget *widget, const gchar id, unsigned char on); + LIB3270_EXPORT void v3270_set_scaled_fonts(GtkWidget *widget, gboolean on); LIB3270_EXPORT void v3270_set_host(GtkWidget *widget, const gchar *uri); diff --git a/src/pw3270/main.c b/src/pw3270/main.c index fe7db7e..e99c689 100644 --- a/src/pw3270/main.c +++ b/src/pw3270/main.c @@ -184,12 +184,12 @@ int main(int argc, char *argv[]) static const GOptionEntry app_options[] = { #if ! defined( WIN32 ) - { "appname", 'a', 0, G_OPTION_ARG_CALLBACK, appname, N_( "Application name" ), PACKAGE_NAME }, + { "appname", 'a', 0, G_OPTION_ARG_CALLBACK, appname, N_( "Application name" ), PACKAGE_NAME }, #else - { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, + { "appname", 'a', 0, G_OPTION_ARG_STRING, &appname, N_( "Application name" ), PACKAGE_NAME }, #endif // WIN32 - { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME }, - { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL }, + { "session", 's', 0, G_OPTION_ARG_STRING, &session_name, N_( "Session name" ), PACKAGE_NAME }, + { "host", 'h', 0, G_OPTION_ARG_STRING, &host, N_( "Host to connect"), NULL }, { NULL } }; diff --git a/src/pw3270/print.c b/src/pw3270/print.c index 258c477..3984fb9 100644 --- a/src/pw3270/print.c +++ b/src/pw3270/print.c @@ -60,29 +60,6 @@ /*--[ Implement ]------------------------------------------------------------------------------------*/ -/* - static void setup_font(GtkPrintContext * context, PRINT_INFO *info) - { - cairo_t *cr = gtk_print_context_get_cairo_context(context); - - trace("Font: %s",info->font); - cairo_select_font_face(cr, info->font, CAIRO_FONT_SLANT_NORMAL, info->fontweight); - - info->font_scaled = cairo_get_scaled_font(cr); - cairo_scaled_font_reference(info->font_scaled); - cairo_scaled_font_extents(info->font_scaled,&info->extents); - - info->width = ((double) info->cols) * info->extents.max_x_advance; - info->height = ((double) info->rows) * (info->extents.height + info->extents.descent); - - // Center image - info->left = (gtk_print_context_get_width(context)-info->width)/2; - if(info->left < 2) - info->left = 2; - - - } -*/ static void begin_print(GtkPrintOperation *prt, GtkPrintContext *context, PRINT_INFO *info) { cairo_t * cr = gtk_print_context_get_cairo_context(context); @@ -602,6 +579,7 @@ static gchar * enum_to_string(GType type, guint enum_value) { case PW3270_SRC_ALL: case PW3270_SRC_SELECTED: + case PW3270_SRC_USER: g_signal_connect(print,"draw_page",G_CALLBACK(draw_screen),info); break; @@ -625,6 +603,8 @@ static gchar * enum_to_string(GType type, guint enum_value) } g_signal_connect(print,"draw_page",G_CALLBACK(draw_text),info); break; + + } // Run Print dialog diff --git a/src/pw3270/tools.c b/src/pw3270/tools.c index 4e70e19..b5e84ad 100644 --- a/src/pw3270/tools.c +++ b/src/pw3270/tools.c @@ -104,3 +104,8 @@ LIB3270_EXPORT gint pw3270_get_integer(GtkWidget *widget, const gchar *group, co { return get_integer_from_config(group, key, def); } + +LIB3270_EXPORT void pw3270_set_integer(GtkWidget *widget, const gchar *group, const gchar *key, gint val) +{ + set_integer_to_config(group, key, val); +} diff --git a/src/pw3270/v3270/private.h b/src/pw3270/v3270/private.h index e097107..5909eaa 100644 --- a/src/pw3270/v3270/private.h +++ b/src/pw3270/v3270/private.h @@ -125,10 +125,11 @@ G_BEGIN_DECLS GtkWidget parent; // flags - int selecting : 1; /**< Selecting region */ - int moving : 1; /**< Moving selected region */ - int resizing : 1; /**< Resizing selected region */ - int table : 1; /**< Copy mode is table */ + int selecting : 1; /**< Selecting region */ + int moving : 1; /**< Moving selected region */ + int resizing : 1; /**< Resizing selected region */ + int table : 1; /**< Copy mode is table */ + int scaled_fonts : 1; /**< Use scaled fonts */ #if GTK_CHECK_VERSION(3,0,0) diff --git a/src/pw3270/v3270/widget.c b/src/pw3270/v3270/widget.c index decb246..9a00240 100644 --- a/src/pw3270/v3270/widget.c +++ b/src/pw3270/v3270/widget.c @@ -521,9 +521,7 @@ static void v3270_class_init(v3270Class *klass) void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height) { // update font metrics - 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 }; - int f, rows, cols, hFont; - int size = font_size[0]; + int rows, cols, hFont, size; cairo_font_extents_t extents; @@ -533,47 +531,46 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig cairo_select_font_face(cr, terminal->font_family, CAIRO_FONT_SLANT_NORMAL,terminal->font_weight); - for(f=0;font_size[f];f++) - { - cairo_set_font_size(cr,font_size[f]); - cairo_font_extents(cr,&extents); - - if(f == 0) - { - terminal->minimum_width = (cols * extents.max_x_advance); - terminal->minimum_height = ((rows+1) * (extents.height + extents.descent)) + (OIA_TOP_MARGIN+2); - } + if(terminal->scaled_fonts) + { + double w = ((double)width) / ((double)cols); + double h = ((double) height) / ((double) (rows+2)); - if( HEIGHT_IN_PIXELS(terminal,(extents.height+extents.descent)) < height && WIDTH_IN_PIXELS(terminal,extents.max_x_advance) < width ) - size = font_size[f]; - } + cairo_set_font_size(cr,w < h ? w : h); + } + else + { + 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 }; + int f; - cairo_set_font_size(cr,size); + size = font_size[0]; -#if !GTK_CHECK_VERSION(3,0,0) - gtk_widget_set_size_request(GTK_WIDGET(terminal),terminal->minimum_width,terminal->minimum_height); -#endif // !GTK(3,0,0) + for(f=0;font_size[f];f++) + { + cairo_set_font_size(cr,font_size[f]); + cairo_font_extents(cr,&extents); -/* - double sx, sy; - cairo_matrix_t font_matrix; + if(f == 0) + { + terminal->minimum_width = (cols * extents.max_x_advance); + terminal->minimum_height = ((rows+1) * (extents.height + extents.descent)) + (OIA_TOP_MARGIN+2); + } - cairo_set_font_size(cr,10); - cairo_font_extents(cr,&extents); + if( HEIGHT_IN_PIXELS(terminal,(extents.height+extents.descent)) < height && WIDTH_IN_PIXELS(terminal,extents.max_x_advance) < width ) + size = font_size[f]; + } - trace("font - extents.height=%f extents.width=%f",extents.height,extents.max_x_advance); + cairo_set_font_size(cr,size); - sx = ((double) width) / (((double) terminal->cols) * extents.max_x_advance); - sy = ((double) height) / (((double) terminal->rows) * extents.height); + #if !GTK_CHECK_VERSION(3,0,0) + gtk_widget_set_size_request(GTK_WIDGET(terminal),terminal->minimum_width,terminal->minimum_height); + #endif // !GTK(3,0,0) - trace("sy=%f sx=%f ",sy,sx); + } - cairo_get_font_matrix(cr,&font_matrix); - cairo_matrix_scale(&font_matrix, sx, sy); - cairo_set_font_matrix(cr,&font_matrix); -*/ + cairo_font_extents(cr,&extents); - /* Save scaled font for use on next drawings */ + // Save scaled font for use on next drawings if(terminal->font_scaled) cairo_scaled_font_destroy(terminal->font_scaled); @@ -1407,6 +1404,15 @@ const gchar * v3270_get_session_name(GtkWidget *widget) return GTK_V3270(widget)->session_name; } +void v3270_set_scaled_fonts(GtkWidget *widget, gboolean on) +{ + g_return_if_fail(GTK_IS_V3270(widget)); + + GTK_V3270(widget)->scaled_fonts = on ? 1 : 0; + + trace("Sfonts is %s",GTK_V3270(widget)->scaled_fonts ? "YES" : "NO"); +} + void v3270_set_session_name(GtkWidget *widget, const gchar *name) { g_return_if_fail(GTK_IS_V3270(widget)); diff --git a/src/pw3270/window.c b/src/pw3270/window.c index f6988ab..47b28c4 100644 --- a/src/pw3270/window.c +++ b/src/pw3270/window.c @@ -196,6 +196,8 @@ if(pw3270_get_toggle(widget,LIB3270_TOGGLE_CONNECT_ON_STARTUP)) v3270_connect(GTK_PW3270(widget)->terminal,NULL); + v3270_set_scaled_fonts(GTK_PW3270(widget)->terminal,get_integer_from_config("terminal","sfonts",0) ? TRUE : FALSE); + return widget; } -- libgit2 0.21.2