From 0f913ead7c1e1e7ba4976e8763d73c3167f8cf73 Mon Sep 17 00:00:00 2001 From: oetiker Date: Mon, 9 May 2005 13:22:23 +0000 Subject: [PATCH] * switch to courier if the font is unknown * fix font positioning git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@525 a5681a0c-68f1-0310-ab6d-d61299d08faa --- src/rrd_afm.c | 19 +++++++++++------- src/rrd_gfx.c | 64 +++++++++++++++++++++++++++++++++++++---------------------- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/rrd_afm.c b/src/rrd_afm.c index 5bf6e91..a7cb295 100644 --- a/src/rrd_afm.c +++ b/src/rrd_afm.c @@ -34,7 +34,7 @@ */ #define ENABLE_LIGATURES 0 -static const afm_fontinfo *afm_last_used_font; +static const afm_fontinfo *afm_last_used_font = NULL; #define is_font(p, name) \ (!strcmp(p->postscript_name, name) || !strcmp(p->fullname, name)) @@ -55,34 +55,39 @@ static const afm_fontinfo *afm_searchfont(const char *name) return NULL; } +static const char *last_unknown_font = NULL; + static const afm_fontinfo *afm_findfont(const char *name) { const afm_fontinfo *p = afm_searchfont(name); if (p) return p; - if (1 || DEBUG) fprintf(stderr, "Can't find font '%s'\n", name); - p = afm_searchfont("Helvetica"); + if (!last_unknown_font || strcmp(name, last_unknown_font)) { + fprintf(stderr, "Can't find font '%s'\n", name); + last_unknown_font = name; + } + p = afm_searchfont("Courier"); if (p) return p; - return NULL; + return afm_fontinfolist; // anything, just anything. } const char *afm_get_font_postscript_name(const char* font) { const afm_fontinfo *p = afm_findfont(font); - return p ? p->postscript_name : "Helvetica"; + return p->postscript_name; } double afm_get_ascender(const char* font, double size) { const afm_fontinfo *p = afm_findfont(font); - return p ? p->ascender : 10; /* just a guess to avoid really bad design if we don't know the font */ + return size * p->ascender / 1000.0; } double afm_get_descender(const char* font, double size) { const afm_fontinfo *p = afm_findfont(font); - return p ? p->descender : 4; /* just a guess to avoid really bad design if we don't know the font */ + return size * p->descender / 1000.0; } static int afm_find_char_index(const afm_fontinfo *fontinfo, diff --git a/src/rrd_gfx.c b/src/rrd_gfx.c index 86d2b56..6f83bc5 100644 --- a/src/rrd_gfx.c +++ b/src/rrd_gfx.c @@ -1389,8 +1389,8 @@ int gfx_render_svg (gfx_canvas_t *canvas, "\n" "