summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-24 20:55:16 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-24 20:55:16 -0300
commited26fb9c937582345f4cf20e7ff44297188d450e (patch)
treeb4752b27e631276359ed9bf635a367f47e1fb132
parent8911a3baf04324cd3e233cd7cb55f14313c0b2a6 (diff)
downloadeeshow-ed26fb9c937582345f4cf20e7ff44297188d450e.tar.gz
eeshow-ed26fb9c937582345f4cf20e7ff44297188d450e.tar.bz2
eeshow-ed26fb9c937582345f4cf20e7ff44297188d450e.zip
gfx/cro.c: don't set layout if we already have the right size
This removes about 88% of the calls to pango_font_description_set_absolute_size and pango_layout_set_font_description, and seems to reduce run time by some 5%, from 3.55 s to 3.36 s for an initial index on neo900.pro. For comparison, using Cairo's "toy" text interface we're done in about 330 ms.
-rw-r--r--gfx/cro.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/gfx/cro.c b/gfx/cro.c
index abb27c9..d650fcc 100644
--- a/gfx/cro.c
+++ b/gfx/cro.c
@@ -57,6 +57,7 @@ struct cro_ctx {
PangoFontDescription *pango_desc;
PangoLayout *pango_layout;
+ double pango_size;
struct record *sheets; /* for PDF */
unsigned n_sheets;
@@ -240,10 +241,15 @@ static void cr_text_pango(void *ctx, int x, int y, const char *s, unsigned size,
{
struct cro_ctx *cc = ctx;
PangoRectangle ink;
-
- pango_font_description_set_absolute_size(cc->pango_desc,
- cd(cc, size) * TEXT_STRETCH * PANGO_SCALE);
- pango_layout_set_font_description(cc->pango_layout, cc->pango_desc);
+ double pango_size = cd(cc, size) * TEXT_STRETCH * PANGO_SCALE;
+
+ if (pango_size != cc->pango_size) {
+ pango_font_description_set_absolute_size(cc->pango_desc,
+ pango_size);
+ pango_layout_set_font_description(cc->pango_layout,
+ cc->pango_desc);
+ cc->pango_size = pango_size;
+ }
pango_layout_set_text(cc->pango_layout, s, -1);
pango_layout_get_extents(cc->pango_layout, &ink, NULL);
@@ -332,6 +338,8 @@ static struct cro_ctx *new_cc(void)
cc->xo = cc->yo = 0;
cc->scale = cc->default_scale = DEFAULT_SCALE;
+ cc->pango_size = 0;
+
cc->sheets = NULL;
cc->n_sheets = 0;