GUAC-718: Scale text layout to fit within ideal size.
This commit is contained in:
parent
122a8095e4
commit
b106e13bb1
@ -42,6 +42,13 @@ AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/socket.h time.h sys/time.h syslo
|
|||||||
# Source characteristics
|
# Source characteristics
|
||||||
AC_DEFINE([_XOPEN_SOURCE], [700], [Uses X/Open and POSIX APIs])
|
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 <math.h>])])
|
||||||
|
|
||||||
# libpng
|
# libpng
|
||||||
AC_CHECK_LIB([png], [png_write_png], [PNG_LIBS=-lpng],
|
AC_CHECK_LIB([png], [png_write_png], [PNG_LIBS=-lpng],
|
||||||
AC_MSG_ERROR("libpng is required for writing png messages"))
|
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_CHECK_LIB([wsock32], [main])
|
||||||
|
|
||||||
AC_SUBST(LIBADD_DLOPEN)
|
AC_SUBST(LIBADD_DLOPEN)
|
||||||
|
AC_SUBST(MATH_LIBS)
|
||||||
AC_SUBST(PNG_LIBS)
|
AC_SUBST(PNG_LIBS)
|
||||||
AC_SUBST(CAIRO_LIBS)
|
AC_SUBST(CAIRO_LIBS)
|
||||||
AC_SUBST(PTHREAD_LIBS)
|
AC_SUBST(PTHREAD_LIBS)
|
||||||
|
@ -50,5 +50,5 @@ libguac_terminal_la_SOURCES = \
|
|||||||
terminal_handlers.c
|
terminal_handlers.c
|
||||||
|
|
||||||
libguac_terminal_la_LIBADD = @LIBGUAC_LTLIB@ @COMMON_LTLIB@
|
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@
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
@ -143,8 +144,11 @@ guac_terminal_glyph* __guac_terminal_get_glyph(guac_terminal_display* display, i
|
|||||||
|
|
||||||
cairo_surface_t* surface;
|
cairo_surface_t* surface;
|
||||||
cairo_t* cairo;
|
cairo_t* cairo;
|
||||||
|
int surface_width, surface_height;
|
||||||
|
|
||||||
PangoLayout* layout;
|
PangoLayout* layout;
|
||||||
|
int layout_width, layout_height;
|
||||||
|
int ideal_layout_width, ideal_layout_height;
|
||||||
|
|
||||||
/* Get codepoint hash */
|
/* Get codepoint hash */
|
||||||
int hashcode = __guac_terminal_hash_codepoint(codepoint);
|
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)
|
if (width < 0)
|
||||||
width = 1;
|
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 */
|
/* Prepare surface */
|
||||||
surface = cairo_image_surface_create(
|
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
|
||||||
CAIRO_FORMAT_ARGB32,
|
surface_width, surface_height);
|
||||||
cell_width, display->char_height);
|
|
||||||
cairo = cairo_create(surface);
|
cairo = cairo_create(surface);
|
||||||
|
|
||||||
/* Get layout */
|
/* Get layout */
|
||||||
layout = pango_cairo_create_layout(cairo);
|
layout = pango_cairo_create_layout(cairo);
|
||||||
pango_layout_set_font_description(layout, display->font_desc);
|
pango_layout_set_font_description(layout, display->font_desc);
|
||||||
pango_layout_set_text(layout, utf8, bytes);
|
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 */
|
/* Draw */
|
||||||
cairo_set_source_rgba(cairo,
|
cairo_set_source_rgba(cairo,
|
||||||
|
Loading…
Reference in New Issue
Block a user