diff --git a/configure.ac b/configure.ac index d12bb23b..63fada60 100644 --- a/configure.ac +++ b/configure.ac @@ -42,6 +42,13 @@ AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/socket.h time.h sys/time.h syslo # Source characteristics AC_DEFINE([_XOPEN_SOURCE], [700], [Uses X/Open and POSIX APIs]) +# Check for whether math library is required +AC_CHECK_LIB([m], [cos], + [MATH_LIBS=-lm], + [AC_CHECK_DECL([cos],, + AC_MSG_ERROR("Complex math functions are missing and no libm was found") + [#include ])]) + # libpng AC_CHECK_LIB([png], [png_write_png], [PNG_LIBS=-lpng], AC_MSG_ERROR("libpng is required for writing png messages")) @@ -62,6 +69,7 @@ AC_CHECK_LIB([cunit], [CU_run_test], [CUNIT_LIBS=-lcunit]) AC_CHECK_LIB([wsock32], [main]) AC_SUBST(LIBADD_DLOPEN) +AC_SUBST(MATH_LIBS) AC_SUBST(PNG_LIBS) AC_SUBST(CAIRO_LIBS) AC_SUBST(PTHREAD_LIBS) diff --git a/src/terminal/Makefile.am b/src/terminal/Makefile.am index 8d286fe1..412e75a5 100644 --- a/src/terminal/Makefile.am +++ b/src/terminal/Makefile.am @@ -50,5 +50,5 @@ libguac_terminal_la_SOURCES = \ terminal_handlers.c libguac_terminal_la_LIBADD = @LIBGUAC_LTLIB@ @COMMON_LTLIB@ -libguac_terminal_la_LDFLAGS = @PTHREAD_LIBS@ @PANGO_LIBS@ @PANGOCAIRO_LIBS@ @CAIRO_LIBS@ +libguac_terminal_la_LDFLAGS = @PTHREAD_LIBS@ @PANGO_LIBS@ @PANGOCAIRO_LIBS@ @CAIRO_LIBS@ @MATH_LIBS@ diff --git a/src/terminal/display.c b/src/terminal/display.c index c9240c7e..6a5ea431 100644 --- a/src/terminal/display.c +++ b/src/terminal/display.c @@ -26,6 +26,7 @@ #include "display.h" #include "types.h" +#include #include #include #include @@ -143,8 +144,11 @@ guac_terminal_glyph* __guac_terminal_get_glyph(guac_terminal_display* display, i cairo_surface_t* surface; cairo_t* cairo; + int surface_width, surface_height; PangoLayout* layout; + int layout_width, layout_height; + int ideal_layout_width, ideal_layout_height; /* Get codepoint hash */ int hashcode = __guac_terminal_hash_codepoint(codepoint); @@ -175,16 +179,39 @@ guac_terminal_glyph* __guac_terminal_get_glyph(guac_terminal_display* display, i if (width < 0) width = 1; + surface_width = width * display->char_width; + surface_height = display->char_height; + + ideal_layout_width = surface_width * PANGO_SCALE; + ideal_layout_height = surface_height * PANGO_SCALE; + /* Prepare surface */ - surface = cairo_image_surface_create( - CAIRO_FORMAT_ARGB32, - cell_width, display->char_height); + surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, + surface_width, surface_height); cairo = cairo_create(surface); /* Get layout */ layout = pango_cairo_create_layout(cairo); pango_layout_set_font_description(layout, display->font_desc); pango_layout_set_text(layout, utf8, bytes); + pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); + + pango_layout_get_size(layout, &layout_width, &layout_height); + + /* If layout bigger than available space, scale it back */ + if (layout_width > ideal_layout_width || layout_height > ideal_layout_height) { + + double scale = fmin(ideal_layout_width / (double) layout_width, + ideal_layout_height / (double) layout_height); + + cairo_scale(cairo, scale, scale); + + /* Update layout to reflect scaled surface */ + pango_layout_set_width(layout, ideal_layout_width / scale); + pango_layout_set_height(layout, ideal_layout_height / scale); + pango_cairo_update_layout(cairo, layout); + + } /* Draw */ cairo_set_source_rgba(cairo,