From: Tobias Oetiker Date: Mon, 9 May 2005 13:22:23 +0000 (+0000) Subject: * switch to courier if the font is unknown X-Git-Tag: 1.2.5~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dbe6498a4eebd32b3a8243eb65be5c32d4fd3632;p=thirdparty%2Frrdtool-1.x.git * 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 --- diff --git a/src/rrd_afm.c b/src/rrd_afm.c index 5bf6e916..a7cb2956 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 86d2b564..6f83bc56 100644 --- a/src/rrd_gfx.c +++ b/src/rrd_gfx.c @@ -1389,8 +1389,8 @@ int gfx_render_svg (gfx_canvas_t *canvas, "\n" "