Commit f87fa5038eab314d466eba43171b7e1fc469926f
1 parent
759c2db9
Exists in
master
and in
1 other branch
Refactoring font size method.
Showing
11 changed files
with
324 additions
and
317 deletions
Show diff stats
Makefile.in
| ... | ... | @@ -36,6 +36,7 @@ SOURCES= \ |
| 36 | 36 | $(wildcard src/terminal/@OSNAME@/*.rc) \ |
| 37 | 37 | $(wildcard src/terminal/@OSNAME@/*.c) \ |
| 38 | 38 | $(wildcard src/terminal/properties/*.c) \ |
| 39 | + $(wildcard src/terminal/font/*.c) \ | |
| 39 | 40 | $(wildcard src/filetransfer/*.c) \ |
| 40 | 41 | $(wildcard src/selection/*.c) \ |
| 41 | 42 | $(wildcard src/selection/@OSNAME@/*.c) \ | ... | ... |
src/include/internals.h
| ... | ... | @@ -93,7 +93,6 @@ |
| 93 | 93 | /*--[ Constants ]------------------------------------------------------------------------------------*/ |
| 94 | 94 | |
| 95 | 95 | G_GNUC_INTERNAL const gchar * v3270_default_colors; |
| 96 | - G_GNUC_INTERNAL const gchar * v3270_default_font; | |
| 97 | 96 | |
| 98 | 97 | /*--[ Internal methods ]-----------------------------------------------------------------------------*/ |
| 99 | 98 | |
| ... | ... | @@ -216,7 +215,8 @@ |
| 216 | 215 | |
| 217 | 216 | G_GNUC_INTERNAL void v3270_update_char(H3270 *session, int addr, unsigned char chr, unsigned short attr, unsigned char cursor); |
| 218 | 217 | |
| 219 | - G_GNUC_INTERNAL void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, unsigned int width, unsigned int height); | |
| 218 | + G_GNUC_INTERNAL void v3270_update_font_metrics(v3270 *terminal, unsigned int width, unsigned int height); | |
| 219 | + G_GNUC_INTERNAL void v3270_compute_font_size(v3270 *terminal, cairo_t *cr, unsigned int width, unsigned int height); | |
| 220 | 220 | |
| 221 | 221 | G_GNUC_INTERNAL void v3270_update_cursor_rect(v3270 *widget, GdkRectangle *rect, const struct v3270_character *element); |
| 222 | 222 | ... | ... |
src/include/terminal.h
src/terminal/draw.c
| ... | ... | @@ -367,7 +367,8 @@ LIB3270_EXPORT void v3270_reload(GtkWidget *widget) |
| 367 | 367 | |
| 368 | 368 | // Update the created image |
| 369 | 369 | cr = cairo_create(terminal->surface); |
| 370 | - v3270_update_font_metrics(terminal, cr, width, height); | |
| 370 | + v3270_compute_font_size(terminal, cr, width, height); | |
| 371 | + v3270_update_font_metrics(terminal, width, height); | |
| 371 | 372 | |
| 372 | 373 | gdk_cairo_set_source_rgba(cr,terminal->color+V3270_COLOR_BACKGROUND); |
| 373 | 374 | cairo_rectangle(cr, 0, 0, width, height); | ... | ... |
src/terminal/font.c
| ... | ... | @@ -1,312 +0,0 @@ |
| 1 | -/* | |
| 2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | - * | |
| 6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | - * | |
| 8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | - * Free Software Foundation. | |
| 11 | - * | |
| 12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | - * obter mais detalhes. | |
| 16 | - * | |
| 17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | - * | |
| 21 | - * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | - * | |
| 23 | - * Contatos: | |
| 24 | - * | |
| 25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | - * | |
| 28 | - */ | |
| 29 | - | |
| 30 | - #include <config.h> | |
| 31 | - #include <terminal.h> | |
| 32 | - #include <lib3270.h> | |
| 33 | - #include <lib3270/log.h> | |
| 34 | - #include <lib3270/toggle.h> | |
| 35 | - | |
| 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) | |
| 38 | - | |
| 39 | -/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
| 40 | - | |
| 41 | -#ifdef _WIN32 | |
| 42 | - const gchar * v3270_default_font = "Lucida Console"; | |
| 43 | -#else | |
| 44 | - const gchar * v3270_default_font = "monospace"; | |
| 45 | -#endif // _WIN32 | |
| 46 | - | |
| 47 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 48 | - | |
| 49 | -const gchar * v3270_get_default_font_name() | |
| 50 | -{ | |
| 51 | - return v3270_default_font; | |
| 52 | -} | |
| 53 | - | |
| 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) | |
| 64 | -{ | |
| 65 | - // update font metrics | |
| 66 | - unsigned int rows, cols, hFont, size; | |
| 67 | - | |
| 68 | - cairo_font_extents_t extents; | |
| 69 | - | |
| 70 | - lib3270_get_screen_size(terminal->host,&rows,&cols); | |
| 71 | - | |
| 72 | - debug( | |
| 73 | - "Screen_size: %ux%u Scalled=%s view_rows=%d", | |
| 74 | - rows, | |
| 75 | - cols, | |
| 76 | - terminal->font.scaled ? "Yes" : "No", | |
| 77 | - (rows+OIA_TOP_MARGIN+3) | |
| 78 | - ); | |
| 79 | - | |
| 80 | - terminal->font.weight = lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; | |
| 81 | - | |
| 82 | - if(terminal->font.face) | |
| 83 | - { | |
| 84 | - cairo_font_face_destroy(terminal->font.face); | |
| 85 | - } | |
| 86 | - | |
| 87 | - terminal->font.face = cairo_toy_font_face_create(terminal->font.family, CAIRO_FONT_SLANT_NORMAL, terminal->font.weight); | |
| 88 | - cairo_set_font_face(cr,terminal->font.face); | |
| 89 | - | |
| 90 | - // cairo_select_font_face(cr,terminal->font.family, CAIRO_FONT_SLANT_NORMAL,terminal->font.weight); | |
| 91 | - | |
| 92 | - if(terminal->font.scaled) | |
| 93 | - { | |
| 94 | - | |
| 95 | - // double w = ((double) width) / ((double)cols); | |
| 96 | - // double h = ((double) height) / ((double) ((rows + OIA_TOP_MARGIN + 3))); | |
| 97 | - // double s = (w < h) ? w : h; | |
| 98 | - | |
| 99 | - double s = 0; | |
| 100 | - double selected = 0; | |
| 101 | - | |
| 102 | - do | |
| 103 | - { | |
| 104 | - selected = s; | |
| 105 | - | |
| 106 | - s += 0.5; | |
| 107 | - cairo_set_font_size(cr,s); | |
| 108 | - cairo_font_extents(cr,&extents); | |
| 109 | - | |
| 110 | - /* | |
| 111 | - debug("font_size=%lf x_advance=%lf y_advance=%lf font_extents=%u+%u font_height=%u view_height=%u view_width=%u", | |
| 112 | - s, | |
| 113 | - extents.max_x_advance, | |
| 114 | - extents.max_y_advance, | |
| 115 | - (unsigned int) extents.height, (unsigned int) extents.descent, | |
| 116 | - VIEW_HEIGTH_FROM_FONT( (unsigned int) (extents.height + extents.descent) ), | |
| 117 | - height, | |
| 118 | - VIEW_WIDTH_FROM_FONT(extents.max_x_advance) | |
| 119 | - ); | |
| 120 | - */ | |
| 121 | - | |
| 122 | - } while( (VIEW_HEIGTH_FROM_FONT( (extents.height+extents.descent) ) < height) && (VIEW_WIDTH_FROM_FONT(extents.max_x_advance) < width) ); | |
| 123 | - | |
| 124 | - debug("Selected size=%lf",selected); | |
| 125 | - | |
| 126 | - cairo_set_font_size(cr,selected); | |
| 127 | - cairo_font_extents(cr,&extents); | |
| 128 | - | |
| 129 | - | |
| 130 | - /* | |
| 131 | - | |
| 132 | - cairo_set_font_size(cr,s); | |
| 133 | - cairo_font_extents(cr,&extents); | |
| 134 | - | |
| 135 | - while( (VIEW_HEIGTH_FROM_FONT( (extents.height+extents.descent) ) < height) && (VIEW_WIDTH_FROM_FONT(extents.max_x_advance) < width) ) | |
| 136 | - { | |
| 137 | - s += 0.5; | |
| 138 | - cairo_set_font_size(cr,s); | |
| 139 | - cairo_font_extents(cr,&extents); | |
| 140 | - | |
| 141 | - debug("font_size=%lf x_advance=%lf y_advance=%lf font_extents=%u+%u font_height=%u view_height=%u view_width=%u", | |
| 142 | - s, | |
| 143 | - extents.max_x_advance, | |
| 144 | - extents.max_y_advance, | |
| 145 | - (unsigned int) extents.height, (unsigned int) extents.descent, | |
| 146 | - VIEW_HEIGTH_FROM_FONT( (unsigned int) (extents.height + extents.descent) ), | |
| 147 | - height, | |
| 148 | - VIEW_WIDTH_FROM_FONT(extents.max_x_advance) | |
| 149 | - ); | |
| 150 | - | |
| 151 | - } | |
| 152 | - | |
| 153 | - s -= 0.5; | |
| 154 | - */ | |
| 155 | - | |
| 156 | - | |
| 157 | - } | |
| 158 | - else | |
| 159 | - { | |
| 160 | - 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 }; | |
| 161 | - size_t f; | |
| 162 | - | |
| 163 | - size = font_size[0]; | |
| 164 | - | |
| 165 | - for(f=0;f < G_N_ELEMENTS(font_size);f++) | |
| 166 | - { | |
| 167 | - cairo_set_font_size(cr,font_size[f]); | |
| 168 | - cairo_font_extents(cr,&extents); | |
| 169 | - | |
| 170 | - if(f == 0) | |
| 171 | - { | |
| 172 | - terminal->minimum_width = (cols * extents.max_x_advance); | |
| 173 | - terminal->minimum_height = ((rows+1) * (extents.height + extents.descent)) + (OIA_TOP_MARGIN+2); | |
| 174 | - } | |
| 175 | - | |
| 176 | - /* | |
| 177 | - debug("font_size=%d x_advance=%lf y_advance=%lf font_extents=%u+%u font_height=%u view_height=%u view_width=%u", | |
| 178 | - font_size[f], | |
| 179 | - extents.max_x_advance, | |
| 180 | - extents.max_y_advance, | |
| 181 | - (unsigned int) extents.height, (unsigned int) extents.descent, | |
| 182 | - VIEW_HEIGTH_FROM_FONT( (unsigned int) (extents.height + extents.descent) ), | |
| 183 | - height, | |
| 184 | - VIEW_WIDTH_FROM_FONT(extents.max_x_advance) | |
| 185 | - ); | |
| 186 | - */ | |
| 187 | - | |
| 188 | - if( VIEW_HEIGTH_FROM_FONT((extents.height + extents.descent)) < height && VIEW_WIDTH_FROM_FONT(extents.max_x_advance) < width) | |
| 189 | - size = font_size[f]; | |
| 190 | - | |
| 191 | - } | |
| 192 | - | |
| 193 | - debug("font_size=%d",size); | |
| 194 | - | |
| 195 | - cairo_set_font_size(cr,size); | |
| 196 | - | |
| 197 | - #if !GTK_CHECK_VERSION(3,0,0) | |
| 198 | - gtk_widget_set_size_request(GTK_WIDGET(terminal),terminal->minimum_width,terminal->minimum_height); | |
| 199 | - #endif // !GTK(3,0,0) | |
| 200 | - | |
| 201 | - } | |
| 202 | - | |
| 203 | - cairo_font_extents(cr,&extents); | |
| 204 | - | |
| 205 | - // Save scaled font for use on next drawings | |
| 206 | - if(terminal->font.scaled) | |
| 207 | - cairo_scaled_font_destroy(terminal->font.scaled); | |
| 208 | - | |
| 209 | - terminal->font.scaled = cairo_get_scaled_font(cr); | |
| 210 | - cairo_scaled_font_reference(terminal->font.scaled); | |
| 211 | - | |
| 212 | - cairo_scaled_font_extents(terminal->font.scaled,&extents); | |
| 213 | - | |
| 214 | - terminal->font.width = (int) extents.max_x_advance; | |
| 215 | - terminal->font.height = (int) extents.height; | |
| 216 | - terminal->font.ascent = (int) extents.ascent; | |
| 217 | - terminal->font.descent = (int) extents.descent; | |
| 218 | - | |
| 219 | - hFont = (unsigned int) (terminal->font.height + terminal->font.descent); | |
| 220 | - | |
| 221 | - // Create new cursor surface | |
| 222 | - if(terminal->cursor.surface) | |
| 223 | - cairo_surface_destroy(terminal->cursor.surface); | |
| 224 | - | |
| 225 | - terminal->cursor.surface = gdk_window_create_similar_surface(gtk_widget_get_window(GTK_WIDGET(terminal)),CAIRO_CONTENT_COLOR,terminal->font.width,hFont); | |
| 226 | - | |
| 227 | - // Center image | |
| 228 | - size = VIEW_WIDTH_FROM_FONT(terminal->font.width); | |
| 229 | - | |
| 230 | - if(width >= size) { | |
| 231 | - | |
| 232 | - terminal->font.left = ((width - size) / 2); | |
| 233 | - | |
| 234 | - } else { | |
| 235 | - | |
| 236 | - terminal->font.left = 0; | |
| 237 | - } | |
| 238 | - | |
| 239 | - // terminal->font.left = (width >> 1) - ((size) >> 1); | |
| 240 | - | |
| 241 | - debug("Width=%u size=%u left=%d",height, size, terminal->font.left); | |
| 242 | - | |
| 243 | - /* | |
| 244 | - terminal->font.spacing = height / (rows+1); | |
| 245 | - if((int) terminal->font.spacing < hFont) | |
| 246 | - terminal->font.spacing = hFont; | |
| 247 | - */ | |
| 248 | - | |
| 249 | - terminal->font.spacing = hFont; | |
| 250 | - size = VIEW_HEIGTH_FROM_FONT(terminal->font.spacing); | |
| 251 | - | |
| 252 | - if(height >= size) { | |
| 253 | - | |
| 254 | - terminal->font.top = ((height - size) /2); | |
| 255 | - | |
| 256 | - } else { | |
| 257 | - | |
| 258 | - terminal->font.top = 0; | |
| 259 | - | |
| 260 | - } | |
| 261 | - | |
| 262 | - //terminal->font.top = (height >> 1) - (size >> 1); | |
| 263 | - | |
| 264 | - debug("screen_height=%u content_height=%u top=%d",height, size, terminal->font.top); | |
| 265 | - | |
| 266 | -} | |
| 267 | - | |
| 268 | -LIB3270_EXPORT void v3270_set_font_family(GtkWidget *widget, const gchar *name) | |
| 269 | -{ | |
| 270 | - v3270 * terminal; | |
| 271 | - | |
| 272 | - g_return_if_fail(GTK_IS_V3270(widget)); | |
| 273 | - | |
| 274 | - terminal = GTK_V3270(widget); | |
| 275 | - | |
| 276 | - if(!name) | |
| 277 | - { | |
| 278 | - name = v3270_default_font; | |
| 279 | - } | |
| 280 | - | |
| 281 | - if(g_ascii_strcasecmp(terminal->font.family,name)) | |
| 282 | - { | |
| 283 | - // Font has changed, update it | |
| 284 | - g_free(terminal->font.family); | |
| 285 | - | |
| 286 | - terminal->font.family = g_strdup(name); | |
| 287 | - terminal->font.weight = lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; | |
| 288 | - | |
| 289 | - g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_UPDATE_CONFIG], 0, "font-family", name); | |
| 290 | - g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.font_family); | |
| 291 | - | |
| 292 | - v3270_reload(widget); | |
| 293 | - gtk_widget_queue_draw(widget); | |
| 294 | - | |
| 295 | - } | |
| 296 | - | |
| 297 | - | |
| 298 | -} | |
| 299 | - | |
| 300 | -LIB3270_EXPORT const gchar * v3270_get_font_family(GtkWidget *widget) | |
| 301 | -{ | |
| 302 | - g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | |
| 303 | - return GTK_V3270(widget)->font.family; | |
| 304 | -} | |
| 305 | - | |
| 306 | -LIB3270_EXPORT void v3270_set_scaled_fonts(GtkWidget *widget, gboolean on) | |
| 307 | -{ | |
| 308 | - g_return_if_fail(GTK_IS_V3270(widget)); | |
| 309 | - | |
| 310 | - GTK_V3270(widget)->scaled_fonts = on ? 1 : 0; | |
| 311 | - | |
| 312 | -} |
| ... | ... | @@ -0,0 +1,98 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + #include <config.h> | |
| 31 | + #include "private.h" | |
| 32 | + | |
| 33 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * @brief Compute font size. | |
| 37 | + * | |
| 38 | + * @param terminal v3270 terminal widget. | |
| 39 | + * @param cr Cairo context. | |
| 40 | + * @param width Surface width in pixels. | |
| 41 | + * @param height Surface height in pixels. | |
| 42 | + * | |
| 43 | + */ | |
| 44 | + void v3270_compute_font_size(v3270 *terminal, cairo_t *cr, unsigned int width, unsigned int height) | |
| 45 | + { | |
| 46 | + unsigned int rows, cols; | |
| 47 | + cairo_font_extents_t extents; | |
| 48 | + | |
| 49 | + lib3270_get_screen_size(terminal->host,&rows,&cols); | |
| 50 | + | |
| 51 | + /* | |
| 52 | + debug( | |
| 53 | + "Screen_size: %ux%u Scalled=%s view_rows=%d", | |
| 54 | + rows, | |
| 55 | + cols, | |
| 56 | + terminal->font.scaled ? "Yes" : "No", | |
| 57 | + (rows+OIA_TOP_MARGIN+3) | |
| 58 | + ); | |
| 59 | + */ | |
| 60 | + | |
| 61 | + terminal->font.weight = lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; | |
| 62 | + | |
| 63 | + if(terminal->font.face) | |
| 64 | + cairo_font_face_destroy(terminal->font.face); | |
| 65 | + | |
| 66 | + terminal->font.face = cairo_toy_font_face_create(terminal->font.family, CAIRO_FONT_SLANT_NORMAL, terminal->font.weight); | |
| 67 | + cairo_set_font_face(cr,terminal->font.face); | |
| 68 | + | |
| 69 | + { | |
| 70 | + double s = terminal->zoom.step; | |
| 71 | + double selected = 0; | |
| 72 | + | |
| 73 | + do | |
| 74 | + { | |
| 75 | + selected = s; | |
| 76 | + | |
| 77 | + s += terminal->zoom.step; | |
| 78 | + cairo_set_font_size(cr,s); | |
| 79 | + cairo_font_extents(cr,&extents); | |
| 80 | + | |
| 81 | + } while( (VIEW_HEIGTH_FROM_FONT( (extents.height+extents.descent) ) < height) && (VIEW_WIDTH_FROM_FONT(extents.max_x_advance) < width) ); | |
| 82 | + | |
| 83 | + debug("Selected size=%lf",selected); | |
| 84 | + | |
| 85 | + cairo_set_font_size(cr,selected); | |
| 86 | + cairo_font_extents(cr,&extents); | |
| 87 | + | |
| 88 | + } | |
| 89 | + | |
| 90 | + // Save scaled font for use on next drawings | |
| 91 | + if(terminal->font.scaled) | |
| 92 | + cairo_scaled_font_destroy(terminal->font.scaled); | |
| 93 | + | |
| 94 | + terminal->font.scaled = cairo_get_scaled_font(cr); | |
| 95 | + cairo_scaled_font_reference(terminal->font.scaled); | |
| 96 | + | |
| 97 | + } | |
| 98 | + | ... | ... |
| ... | ... | @@ -0,0 +1,78 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + #include <config.h> | |
| 31 | + #include "private.h" | |
| 32 | + | |
| 33 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 34 | + | |
| 35 | +/** | |
| 36 | + * @brief Update font metrics based on view sizes. | |
| 37 | + * | |
| 38 | + * @param terminal v3270 terminal widget. | |
| 39 | + * @param cr Cairo context. | |
| 40 | + * @param width View width in pixels. | |
| 41 | + * @param height View height in pixels. | |
| 42 | + * | |
| 43 | + */ | |
| 44 | +void v3270_update_font_metrics(v3270 *terminal, unsigned int width, unsigned int height) | |
| 45 | +{ | |
| 46 | + unsigned int rows, cols, size; | |
| 47 | + cairo_font_extents_t extents; | |
| 48 | + | |
| 49 | + lib3270_get_screen_size(terminal->host,&rows,&cols); | |
| 50 | + | |
| 51 | + cairo_scaled_font_extents(terminal->font.scaled,&extents); | |
| 52 | + | |
| 53 | + // Update margins. | |
| 54 | + | |
| 55 | + terminal->font.width = (int) extents.max_x_advance; | |
| 56 | + terminal->font.height = (int) extents.height; | |
| 57 | + terminal->font.ascent = (int) extents.ascent; | |
| 58 | + terminal->font.descent = (int) extents.descent; | |
| 59 | + terminal->font.spacing = terminal->font.height + terminal->font.descent; | |
| 60 | + | |
| 61 | + // Create new cursor surface | |
| 62 | + if(terminal->cursor.surface) | |
| 63 | + cairo_surface_destroy(terminal->cursor.surface); | |
| 64 | + | |
| 65 | + terminal->cursor.surface = gdk_window_create_similar_surface(gtk_widget_get_window(GTK_WIDGET(terminal)),CAIRO_CONTENT_COLOR,terminal->font.width,terminal->font.spacing); | |
| 66 | + | |
| 67 | + // Center image | |
| 68 | + | |
| 69 | + size = VIEW_WIDTH_FROM_FONT(terminal->font.width); | |
| 70 | + terminal->font.left = ((width - size) / 2); | |
| 71 | + | |
| 72 | + size = VIEW_HEIGTH_FROM_FONT(terminal->font.spacing); | |
| 73 | + terminal->font.top = ((height - size) /2); | |
| 74 | + | |
| 75 | + debug("screen_height=%u content_height=%u top=%d",height, size, terminal->font.top); | |
| 76 | + | |
| 77 | +} | |
| 78 | + | ... | ... |
| ... | ... | @@ -0,0 +1,38 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + #include <config.h> | |
| 31 | + #include <terminal.h> | |
| 32 | + #include <lib3270.h> | |
| 33 | + #include <lib3270/log.h> | |
| 34 | + #include <lib3270/toggle.h> | |
| 35 | + | |
| 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) | |
| 38 | + | ... | ... |
| ... | ... | @@ -0,0 +1,89 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + #include <config.h> | |
| 31 | + #include "private.h" | |
| 32 | + | |
| 33 | +/*--[ Globals ]--------------------------------------------------------------------------------------*/ | |
| 34 | + | |
| 35 | + | |
| 36 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 37 | + | |
| 38 | +const gchar * v3270_get_default_font_name() | |
| 39 | +{ | |
| 40 | +#ifdef _WIN32 | |
| 41 | + return "Lucida Console"; | |
| 42 | +#else | |
| 43 | + return "monospace"; | |
| 44 | +#endif // _WIN32 | |
| 45 | +} | |
| 46 | + | |
| 47 | +LIB3270_EXPORT void v3270_set_font_family(GtkWidget *widget, const gchar *name) | |
| 48 | +{ | |
| 49 | + v3270 * terminal; | |
| 50 | + | |
| 51 | + g_return_if_fail(GTK_IS_V3270(widget)); | |
| 52 | + | |
| 53 | + terminal = GTK_V3270(widget); | |
| 54 | + | |
| 55 | + if(!name) | |
| 56 | + name = v3270_get_default_font_name(); | |
| 57 | + | |
| 58 | + if(g_ascii_strcasecmp(terminal->font.family,name)) | |
| 59 | + { | |
| 60 | + // Font has changed, update it | |
| 61 | + g_free(terminal->font.family); | |
| 62 | + | |
| 63 | + terminal->font.family = g_strdup(name); | |
| 64 | + terminal->font.weight = lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL; | |
| 65 | + | |
| 66 | + g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_UPDATE_CONFIG], 0, "font-family", name); | |
| 67 | + g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.font_family); | |
| 68 | + | |
| 69 | + v3270_reload(widget); | |
| 70 | + gtk_widget_queue_draw(widget); | |
| 71 | + | |
| 72 | + } | |
| 73 | + | |
| 74 | + | |
| 75 | +} | |
| 76 | + | |
| 77 | +LIB3270_EXPORT const gchar * v3270_get_font_family(GtkWidget *widget) | |
| 78 | +{ | |
| 79 | + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | |
| 80 | + return GTK_V3270(widget)->font.family; | |
| 81 | +} | |
| 82 | + | |
| 83 | +LIB3270_EXPORT void v3270_set_scaled_fonts(GtkWidget *widget, gboolean on) | |
| 84 | +{ | |
| 85 | + g_return_if_fail(GTK_IS_V3270(widget)); | |
| 86 | + | |
| 87 | + GTK_V3270(widget)->scaled_fonts = on ? 1 : 0; | |
| 88 | + | |
| 89 | +} | ... | ... |
src/terminal/widget.c
| ... | ... | @@ -503,6 +503,9 @@ static void v3270_init(v3270 *widget) |
| 503 | 503 | // Setup clipboard. |
| 504 | 504 | widget->selection.target = GDK_SELECTION_CLIPBOARD; |
| 505 | 505 | |
| 506 | + // Setup zoom | |
| 507 | + widget->zoom.step = 0.1; | |
| 508 | + | |
| 506 | 509 | // Reset timer |
| 507 | 510 | widget->activity.timestamp = time(0); |
| 508 | 511 | widget->activity.disconnect = 0; |
| ... | ... | @@ -529,7 +532,7 @@ static void v3270_init(v3270 *widget) |
| 529 | 532 | widget->drawing = 1; |
| 530 | 533 | |
| 531 | 534 | // Set defaults |
| 532 | - widget->font.family = g_strdup(v3270_default_font); | |
| 535 | + widget->font.family = g_strdup(v3270_get_default_font_name()); | |
| 533 | 536 | v3270_set_color_table(widget->color,v3270_default_colors); |
| 534 | 537 | |
| 535 | 538 | } | ... | ... |
v3270.cbp
| ... | ... | @@ -217,7 +217,14 @@ |
| 217 | 217 | <Unit filename="src/terminal/draw.c"> |
| 218 | 218 | <Option compilerVar="CC" /> |
| 219 | 219 | </Unit> |
| 220 | - <Unit filename="src/terminal/font.c"> | |
| 220 | + <Unit filename="src/terminal/font/compute.c"> | |
| 221 | + <Option compilerVar="CC" /> | |
| 222 | + </Unit> | |
| 223 | + <Unit filename="src/terminal/font/metrics.c"> | |
| 224 | + <Option compilerVar="CC" /> | |
| 225 | + </Unit> | |
| 226 | + <Unit filename="src/terminal/font/private.h" /> | |
| 227 | + <Unit filename="src/terminal/font/properties.c"> | |
| 221 | 228 | <Option compilerVar="CC" /> |
| 222 | 229 | </Unit> |
| 223 | 230 | <Unit filename="src/terminal/get.c"> | ... | ... |