Commit 92a95c7769f12f091b4bb1fab8c7e32a95f0607f
1 parent
35b14de2
Exists in
master
and in
1 other branch
Fixing fonte resize when terminal/view height changes.
Showing
4 changed files
with
52 additions
and
26 deletions
Show diff stats
src/terminal/font.c
| @@ -32,11 +32,9 @@ | @@ -32,11 +32,9 @@ | ||
| 32 | #include <lib3270.h> | 32 | #include <lib3270.h> |
| 33 | #include <lib3270/log.h> | 33 | #include <lib3270/log.h> |
| 34 | 34 | ||
| 35 | - #define WIDTH_IN_PIXELS(terminal,x) (x * cols) | ||
| 36 | - #define HEIGHT_IN_PIXELS(terminal,x) (x * (rows+1)) | ||
| 37 | 35 | ||
| 38 | - #define CONTENTS_WIDTH(terminal) (cols * terminal->font.width) | ||
| 39 | - #define CONTENTS_HEIGHT(terminal) (((rows+2) * terminal->font.spacing)+OIA_TOP_MARGIN+2) | 36 | + #define VIEW_HEIGTH_FROM_FONT(font_height) (( ((unsigned int) font_height) * (rows+1)) + OIA_TOP_MARGIN + 2) |
| 37 | + #define VIEW_WIDTH_FROM_FONT(max_x_advance) (((unsigned int) max_x_advance) * cols) | ||
| 40 | 38 | ||
| 41 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ | 39 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ |
| 42 | 40 | ||
| @@ -53,7 +51,16 @@ const gchar * v3270_get_default_font_name() | @@ -53,7 +51,16 @@ const gchar * v3270_get_default_font_name() | ||
| 53 | return v3270_default_font; | 51 | return v3270_default_font; |
| 54 | } | 52 | } |
| 55 | 53 | ||
| 56 | -void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height) | 54 | +/** |
| 55 | + * @brief Update font metrics based on view sizes. | ||
| 56 | + * | ||
| 57 | + * @param terminal v3270 terminal widget. | ||
| 58 | + * @param cr Cairo context. | ||
| 59 | + * @param width View width in pixels. | ||
| 60 | + * @param height View height in pixels. | ||
| 61 | + * | ||
| 62 | + */ | ||
| 63 | +void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, unsigned int width, unsigned int height) | ||
| 57 | { | 64 | { |
| 58 | // update font metrics | 65 | // update font metrics |
| 59 | unsigned int rows, cols, hFont, size; | 66 | unsigned int rows, cols, hFont, size; |
| @@ -61,7 +68,7 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig | @@ -61,7 +68,7 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig | ||
| 61 | cairo_font_extents_t extents; | 68 | cairo_font_extents_t extents; |
| 62 | 69 | ||
| 63 | lib3270_get_screen_size(terminal->host,&rows,&cols); | 70 | lib3270_get_screen_size(terminal->host,&rows,&cols); |
| 64 | - debug("Screen_size: %ux%u Scalled=%s",rows,cols,terminal->font.scaled ? "Yes" : "No"); | 71 | + 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)); |
| 65 | 72 | ||
| 66 | terminal->font.weight = lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; | 73 | terminal->font.weight = lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; |
| 67 | 74 | ||
| @@ -69,33 +76,38 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig | @@ -69,33 +76,38 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig | ||
| 69 | 76 | ||
| 70 | if(terminal->font.scaled) | 77 | if(terminal->font.scaled) |
| 71 | { | 78 | { |
| 79 | + /* | ||
| 72 | double w = ((double) width) / ((double)cols); | 80 | double w = ((double) width) / ((double)cols); |
| 73 | - double h = ((double) height) / ((double) (rows+2)); | ||
| 74 | - double s = w < h ? w : h; | 81 | + double h = ((double) height) / ((double) ((rows + OIA_TOP_MARGIN + 3))); |
| 82 | + double s = (w < h) ? w : h; | ||
| 83 | + */ | ||
| 84 | + | ||
| 85 | + double s = 0.1; | ||
| 75 | 86 | ||
| 76 | cairo_set_font_size(cr,s); | 87 | cairo_set_font_size(cr,s); |
| 77 | cairo_font_extents(cr,&extents); | 88 | cairo_font_extents(cr,&extents); |
| 78 | 89 | ||
| 79 | - while( HEIGHT_IN_PIXELS(terminal,(extents.height+extents.descent)) < height && WIDTH_IN_PIXELS(terminal,extents.max_x_advance) < width ) | 90 | + while( (VIEW_HEIGTH_FROM_FONT( (extents.height+extents.descent) ) < height) && (VIEW_WIDTH_FROM_FONT(extents.max_x_advance) < width) ) |
| 80 | { | 91 | { |
| 81 | - s += 1.0; | 92 | + s += 0.5; |
| 82 | cairo_set_font_size(cr,s); | 93 | cairo_set_font_size(cr,s); |
| 83 | cairo_font_extents(cr,&extents); | 94 | cairo_font_extents(cr,&extents); |
| 84 | } | 95 | } |
| 85 | 96 | ||
| 86 | - s -= 1.0; | 97 | + s -= 0.5; |
| 87 | 98 | ||
| 88 | cairo_set_font_size(cr,s < 1.0 ? 1.0 : s); | 99 | cairo_set_font_size(cr,s < 1.0 ? 1.0 : s); |
| 89 | cairo_font_extents(cr,&extents); | 100 | cairo_font_extents(cr,&extents); |
| 101 | + | ||
| 90 | } | 102 | } |
| 91 | else | 103 | else |
| 92 | { | 104 | { |
| 93 | - 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 }; | ||
| 94 | - int f; | 105 | + 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 }; |
| 106 | + size_t f; | ||
| 95 | 107 | ||
| 96 | size = font_size[0]; | 108 | size = font_size[0]; |
| 97 | 109 | ||
| 98 | - for(f=0;font_size[f];f++) | 110 | + for(f=0;f < G_N_ELEMENTS(font_size);f++) |
| 99 | { | 111 | { |
| 100 | cairo_set_font_size(cr,font_size[f]); | 112 | cairo_set_font_size(cr,font_size[f]); |
| 101 | cairo_font_extents(cr,&extents); | 113 | cairo_font_extents(cr,&extents); |
| @@ -106,10 +118,21 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig | @@ -106,10 +118,21 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig | ||
| 106 | terminal->minimum_height = ((rows+1) * (extents.height + extents.descent)) + (OIA_TOP_MARGIN+2); | 118 | terminal->minimum_height = ((rows+1) * (extents.height + extents.descent)) + (OIA_TOP_MARGIN+2); |
| 107 | } | 119 | } |
| 108 | 120 | ||
| 109 | - if( HEIGHT_IN_PIXELS(terminal,(extents.height+extents.descent)) < height && WIDTH_IN_PIXELS(terminal,extents.max_x_advance) < width ) | 121 | + debug("font_size=%d y_advance=%u font_extents=%u+%u font_height=%u view_height=%u", |
| 122 | + font_size[f], | ||
| 123 | + (unsigned int) extents.max_y_advance, | ||
| 124 | + (unsigned int) extents.height, (unsigned int) extents.descent, | ||
| 125 | + VIEW_HEIGTH_FROM_FONT( (unsigned int) (extents.height + extents.descent) ), | ||
| 126 | + height | ||
| 127 | + ); | ||
| 128 | + | ||
| 129 | + if( VIEW_HEIGTH_FROM_FONT((extents.height + extents.descent)) < height && VIEW_WIDTH_FROM_FONT(extents.max_x_advance) < width) | ||
| 110 | size = font_size[f]; | 130 | size = font_size[f]; |
| 131 | + | ||
| 111 | } | 132 | } |
| 112 | 133 | ||
| 134 | + debug("font_size=%d",size); | ||
| 135 | + | ||
| 113 | cairo_set_font_size(cr,size); | 136 | cairo_set_font_size(cr,size); |
| 114 | 137 | ||
| 115 | #if !GTK_CHECK_VERSION(3,0,0) | 138 | #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 | @@ -134,7 +157,7 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig | ||
| 134 | terminal->font.ascent = (int) extents.ascent; | 157 | terminal->font.ascent = (int) extents.ascent; |
| 135 | terminal->font.descent = (int) extents.descent; | 158 | terminal->font.descent = (int) extents.descent; |
| 136 | 159 | ||
| 137 | - hFont = terminal->font.height + terminal->font.descent; | 160 | + hFont = (unsigned int) (terminal->font.height + terminal->font.descent); |
| 138 | 161 | ||
| 139 | // Create new cursor surface | 162 | // Create new cursor surface |
| 140 | if(terminal->cursor.surface) | 163 | if(terminal->cursor.surface) |
| @@ -143,7 +166,7 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig | @@ -143,7 +166,7 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig | ||
| 143 | terminal->cursor.surface = gdk_window_create_similar_surface(gtk_widget_get_window(GTK_WIDGET(terminal)),CAIRO_CONTENT_COLOR,terminal->font.width,hFont); | 166 | terminal->cursor.surface = gdk_window_create_similar_surface(gtk_widget_get_window(GTK_WIDGET(terminal)),CAIRO_CONTENT_COLOR,terminal->font.width,hFont); |
| 144 | 167 | ||
| 145 | // Center image | 168 | // Center image |
| 146 | - size = CONTENTS_WIDTH(terminal); | 169 | + size = VIEW_WIDTH_FROM_FONT(terminal->font.width); |
| 147 | 170 | ||
| 148 | if(width >= size) { | 171 | if(width >= size) { |
| 149 | 172 | ||
| @@ -158,11 +181,14 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig | @@ -158,11 +181,14 @@ void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int heig | ||
| 158 | 181 | ||
| 159 | debug("Width=%u size=%u left=%d",height, size, terminal->font.left); | 182 | debug("Width=%u size=%u left=%d",height, size, terminal->font.left); |
| 160 | 183 | ||
| 161 | - terminal->font.spacing = height / (rows+2); | 184 | + /* |
| 185 | + terminal->font.spacing = height / (rows+1); | ||
| 162 | if((int) terminal->font.spacing < hFont) | 186 | if((int) terminal->font.spacing < hFont) |
| 163 | terminal->font.spacing = hFont; | 187 | terminal->font.spacing = hFont; |
| 188 | + */ | ||
| 164 | 189 | ||
| 165 | - size = CONTENTS_HEIGHT(terminal); | 190 | + terminal->font.spacing = hFont; |
| 191 | + size = VIEW_HEIGTH_FROM_FONT(terminal->font.spacing); | ||
| 166 | 192 | ||
| 167 | if(height >= size) { | 193 | if(height >= size) { |
| 168 | 194 |
src/terminal/private.h
| @@ -311,7 +311,7 @@ G_GNUC_INTERNAL void v3270_draw_ssl_status(v3270 *widget, cairo_t *cr, GdkRec | @@ -311,7 +311,7 @@ G_GNUC_INTERNAL void v3270_draw_ssl_status(v3270 *widget, cairo_t *cr, GdkRec | ||
| 311 | 311 | ||
| 312 | G_GNUC_INTERNAL void v3270_update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor); | 312 | G_GNUC_INTERNAL void v3270_update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor); |
| 313 | 313 | ||
| 314 | -G_GNUC_INTERNAL void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height); | 314 | +G_GNUC_INTERNAL void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, unsigned int width, unsigned int height); |
| 315 | 315 | ||
| 316 | G_GNUC_INTERNAL void v3270_update_cursor_rect(v3270 *widget, GdkRectangle *rect, unsigned char chr, unsigned short attr); | 316 | G_GNUC_INTERNAL void v3270_update_cursor_rect(v3270 *widget, GdkRectangle *rect, unsigned char chr, unsigned short attr); |
| 317 | 317 |
src/terminal/properties.c
| @@ -213,7 +213,7 @@ | @@ -213,7 +213,7 @@ | ||
| 213 | // Creating toggle properties. | 213 | // Creating toggle properties. |
| 214 | for(ix = 0; ix < LIB3270_TOGGLE_COUNT; ix++) | 214 | for(ix = 0; ix < LIB3270_TOGGLE_COUNT; ix++) |
| 215 | { | 215 | { |
| 216 | - debug("Property %u=%s (Toggle)",(unsigned int) v3270_properties.type.toggle + ix, lib3270_get_toggle_name(ix)); | 216 | +// debug("Property %u=%s (Toggle)",(unsigned int) v3270_properties.type.toggle + ix, lib3270_get_toggle_name(ix)); |
| 217 | 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); | 217 | 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); |
| 218 | v3270_install_property(gobject_class, v3270_properties.type.toggle + ix, v3270_properties.toggle[ix]); | 218 | v3270_install_property(gobject_class, v3270_properties.type.toggle + ix, v3270_properties.toggle[ix]); |
| 219 | } | 219 | } |
| @@ -222,7 +222,7 @@ | @@ -222,7 +222,7 @@ | ||
| 222 | // Creating boolean properties. | 222 | // Creating boolean properties. |
| 223 | for(ix = 0; bool_props[ix].name; ix++) | 223 | for(ix = 0; bool_props[ix].name; ix++) |
| 224 | { | 224 | { |
| 225 | - debug("Property %u=%s (Boolean)",(unsigned int) v3270_properties.type.boolean + ix, bool_props[ix].name); | 225 | +// debug("Property %u=%s (Boolean)",(unsigned int) v3270_properties.type.boolean + ix, bool_props[ix].name); |
| 226 | 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))); | 226 | 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))); |
| 227 | v3270_install_property(gobject_class, v3270_properties.type.boolean + ix, spec); | 227 | v3270_install_property(gobject_class, v3270_properties.type.boolean + ix, spec); |
| 228 | 228 | ||
| @@ -231,7 +231,7 @@ | @@ -231,7 +231,7 @@ | ||
| 231 | // Creating integer properties. | 231 | // Creating integer properties. |
| 232 | for(ix = 0; int_props[ix].name; ix++) | 232 | for(ix = 0; int_props[ix].name; ix++) |
| 233 | { | 233 | { |
| 234 | - debug("Property %u=%s (Integer)",(unsigned int) v3270_properties.type.integer + ix, int_props[ix].name); | 234 | +// debug("Property %u=%s (Integer)",(unsigned int) v3270_properties.type.integer + ix, int_props[ix].name); |
| 235 | 235 | ||
| 236 | spec = g_param_spec_int( | 236 | spec = g_param_spec_int( |
| 237 | int_props[ix].name, | 237 | int_props[ix].name, |
src/testprogram/testprogram.c
| @@ -258,9 +258,9 @@ static GtkToolItem * create_tool_item(GtkWidget *terminal, const gchar *label, c | @@ -258,9 +258,9 @@ static GtkToolItem * create_tool_item(GtkWidget *terminal, const gchar *label, c | ||
| 258 | GtkToolItem * item = gtk_toggle_tool_button_new(); | 258 | GtkToolItem * item = gtk_toggle_tool_button_new(); |
| 259 | gtk_tool_button_set_label(GTK_TOOL_BUTTON(item),label); | 259 | gtk_tool_button_set_label(GTK_TOOL_BUTTON(item),label); |
| 260 | 260 | ||
| 261 | - gtk_widget_set_can_focus(item,FALSE); | ||
| 262 | - gtk_widget_set_can_default(item,FALSE); | ||
| 263 | - gtk_widget_set_focus_on_click(item,FALSE); | 261 | + gtk_widget_set_can_focus(GTK_WIDGET(item),FALSE); |
| 262 | + gtk_widget_set_can_default(GTK_WIDGET(item),FALSE); | ||
| 263 | + gtk_widget_set_focus_on_click(GTK_WIDGET(item),FALSE); | ||
| 264 | 264 | ||
| 265 | g_signal_connect(GTK_WIDGET(item), "toggled", G_CALLBACK(callback), terminal); | 265 | g_signal_connect(GTK_WIDGET(item), "toggled", G_CALLBACK(callback), terminal); |
| 266 | 266 |