diff --git a/src/terminal/font.c b/src/terminal/font.c index 3b8abea..2ce8fc6 100644 --- a/src/terminal/font.c +++ b/src/terminal/font.c @@ -32,11 +32,9 @@ #include #include - #define WIDTH_IN_PIXELS(terminal,x) (x * cols) - #define HEIGHT_IN_PIXELS(terminal,x) (x * (rows+1)) - #define CONTENTS_WIDTH(terminal) (cols * terminal->font.width) - #define CONTENTS_HEIGHT(terminal) (((rows+2) * terminal->font.spacing)+OIA_TOP_MARGIN+2) + #define VIEW_HEIGTH_FROM_FONT(font_height) (( ((unsigned int) font_height) * (rows+1)) + OIA_TOP_MARGIN + 2) + #define VIEW_WIDTH_FROM_FONT(max_x_advance) (((unsigned int) max_x_advance) * cols) /*--[ Globals ]--------------------------------------------------------------------------------------*/ @@ -53,7 +51,16 @@ const gchar * v3270_get_default_font_name() return v3270_default_font; } -void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height) +/** + * @brief Update font metrics based on view sizes. + * + * @param terminal v3270 terminal widget. + * @param cr Cairo context. + * @param width View width in pixels. + * @param height View height in pixels. + * + */ +void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, unsigned int width, unsigned int height) { // update font metrics unsigned int rows, cols, hFont, size; @@ -61,7 +68,7 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig cairo_font_extents_t extents; lib3270_get_screen_size(terminal->host,&rows,&cols); - debug("Screen_size: %ux%u Scalled=%s",rows,cols,terminal->font.scaled ? "Yes" : "No"); + debug("Screen_size: %ux%u Scalled=%s view_rows=%d view_cols=%d",rows,cols,terminal->font.scaled ? "Yes" : "No", (rows+OIA_TOP_MARGIN+3)); terminal->font.weight = lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; @@ -69,33 +76,38 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig if(terminal->font.scaled) { + /* double w = ((double) width) / ((double)cols); - double h = ((double) height) / ((double) (rows+2)); - double s = w < h ? w : h; + double h = ((double) height) / ((double) ((rows + OIA_TOP_MARGIN + 3))); + double s = (w < h) ? w : h; + */ + + double s = 0.1; cairo_set_font_size(cr,s); cairo_font_extents(cr,&extents); - while( HEIGHT_IN_PIXELS(terminal,(extents.height+extents.descent)) < height && WIDTH_IN_PIXELS(terminal,extents.max_x_advance) < width ) + while( (VIEW_HEIGTH_FROM_FONT( (extents.height+extents.descent) ) < height) && (VIEW_WIDTH_FROM_FONT(extents.max_x_advance) < width) ) { - s += 1.0; + s += 0.5; cairo_set_font_size(cr,s); cairo_font_extents(cr,&extents); } - s -= 1.0; + s -= 0.5; cairo_set_font_size(cr,s < 1.0 ? 1.0 : s); cairo_font_extents(cr,&extents); + } 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; + static const unsigned 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 }; + size_t f; size = font_size[0]; - for(f=0;font_size[f];f++) + for(f=0;f < G_N_ELEMENTS(font_size);f++) { cairo_set_font_size(cr,font_size[f]); cairo_font_extents(cr,&extents); @@ -106,10 +118,21 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig terminal->minimum_height = ((rows+1) * (extents.height + extents.descent)) + (OIA_TOP_MARGIN+2); } - if( HEIGHT_IN_PIXELS(terminal,(extents.height+extents.descent)) < height && WIDTH_IN_PIXELS(terminal,extents.max_x_advance) < width ) + debug("font_size=%d y_advance=%u font_extents=%u+%u font_height=%u view_height=%u", + font_size[f], + (unsigned int) extents.max_y_advance, + (unsigned int) extents.height, (unsigned int) extents.descent, + VIEW_HEIGTH_FROM_FONT( (unsigned int) (extents.height + extents.descent) ), + height + ); + + if( VIEW_HEIGTH_FROM_FONT((extents.height + extents.descent)) < height && VIEW_WIDTH_FROM_FONT(extents.max_x_advance) < width) size = font_size[f]; + } + debug("font_size=%d",size); + cairo_set_font_size(cr,size); #if !GTK_CHECK_VERSION(3,0,0) @@ -134,7 +157,7 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig terminal->font.ascent = (int) extents.ascent; terminal->font.descent = (int) extents.descent; - hFont = terminal->font.height + terminal->font.descent; + hFont = (unsigned int) (terminal->font.height + terminal->font.descent); // Create new cursor surface if(terminal->cursor.surface) @@ -143,7 +166,7 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig terminal->cursor.surface = gdk_window_create_similar_surface(gtk_widget_get_window(GTK_WIDGET(terminal)),CAIRO_CONTENT_COLOR,terminal->font.width,hFont); // Center image - size = CONTENTS_WIDTH(terminal); + size = VIEW_WIDTH_FROM_FONT(terminal->font.width); if(width >= size) { @@ -158,11 +181,14 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig debug("Width=%u size=%u left=%d",height, size, terminal->font.left); - terminal->font.spacing = height / (rows+2); + /* + terminal->font.spacing = height / (rows+1); if((int) terminal->font.spacing < hFont) terminal->font.spacing = hFont; + */ - size = CONTENTS_HEIGHT(terminal); + terminal->font.spacing = hFont; + size = VIEW_HEIGTH_FROM_FONT(terminal->font.spacing); if(height >= size) { diff --git a/src/terminal/private.h b/src/terminal/private.h index 0e8fd91..197d742 100644 --- a/src/terminal/private.h +++ b/src/terminal/private.h @@ -311,7 +311,7 @@ G_GNUC_INTERNAL void v3270_draw_ssl_status(v3270 *widget, cairo_t *cr, GdkRec G_GNUC_INTERNAL void v3270_update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor); -G_GNUC_INTERNAL void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height); +G_GNUC_INTERNAL void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, unsigned int width, unsigned int height); G_GNUC_INTERNAL void v3270_update_cursor_rect(v3270 *widget, GdkRectangle *rect, unsigned char chr, unsigned short attr); diff --git a/src/terminal/properties.c b/src/terminal/properties.c index 0d0174f..38729c0 100644 --- a/src/terminal/properties.c +++ b/src/terminal/properties.c @@ -213,7 +213,7 @@ // Creating toggle properties. for(ix = 0; ix < LIB3270_TOGGLE_COUNT; ix++) { - debug("Property %u=%s (Toggle)",(unsigned int) v3270_properties.type.toggle + ix, lib3270_get_toggle_name(ix)); +// debug("Property %u=%s (Toggle)",(unsigned int) v3270_properties.type.toggle + ix, lib3270_get_toggle_name(ix)); v3270_properties.toggle[ix] = g_param_spec_boolean(lib3270_get_toggle_name(ix),lib3270_get_toggle_name(ix),lib3270_get_toggle_description(ix),FALSE,G_PARAM_WRITABLE|G_PARAM_READABLE); v3270_install_property(gobject_class, v3270_properties.type.toggle + ix, v3270_properties.toggle[ix]); } @@ -222,7 +222,7 @@ // Creating boolean properties. for(ix = 0; bool_props[ix].name; ix++) { - debug("Property %u=%s (Boolean)",(unsigned int) v3270_properties.type.boolean + ix, bool_props[ix].name); +// debug("Property %u=%s (Boolean)",(unsigned int) v3270_properties.type.boolean + ix, bool_props[ix].name); spec = g_param_spec_boolean(bool_props[ix].name, bool_props[ix].name, bool_props[ix].description, FALSE,(bool_props[ix].set == NULL ? G_PARAM_READABLE : (G_PARAM_READABLE|G_PARAM_WRITABLE))); v3270_install_property(gobject_class, v3270_properties.type.boolean + ix, spec); @@ -231,7 +231,7 @@ // Creating integer properties. for(ix = 0; int_props[ix].name; ix++) { - debug("Property %u=%s (Integer)",(unsigned int) v3270_properties.type.integer + ix, int_props[ix].name); +// debug("Property %u=%s (Integer)",(unsigned int) v3270_properties.type.integer + ix, int_props[ix].name); spec = g_param_spec_int( int_props[ix].name, diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index 27d6d2d..2e81456 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -258,9 +258,9 @@ static GtkToolItem * create_tool_item(GtkWidget *terminal, const gchar *label, c GtkToolItem * item = gtk_toggle_tool_button_new(); gtk_tool_button_set_label(GTK_TOOL_BUTTON(item),label); - gtk_widget_set_can_focus(item,FALSE); - gtk_widget_set_can_default(item,FALSE); - gtk_widget_set_focus_on_click(item,FALSE); + gtk_widget_set_can_focus(GTK_WIDGET(item),FALSE); + gtk_widget_set_can_default(GTK_WIDGET(item),FALSE); + gtk_widget_set_focus_on_click(GTK_WIDGET(item),FALSE); g_signal_connect(GTK_WIDGET(item), "toggled", G_CALLBACK(callback), terminal); -- libgit2 0.21.2