Commit 4aa1a1f9f487c5b178e04137b592f314dd39a60d
1 parent
b9a96fce
Exists in
master
and in
1 other branch
Incluindo opcao para ajustar a escala das fontes automaticamente
Showing
2 changed files
with
45 additions
and
38 deletions
Show diff stats
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 |
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)); |