X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_afm.c;h=a7cb2956e41e97a2d40a8d3b8039829b22973644;hb=0f913ead7c1e1e7ba4976e8763d73c3167f8cf73;hp=5bf6e91696b1de68c3a9a518a0ecf25f7f213eac;hpb=ee5c354c98d7393c92829a865279e3eb83a3b038;p=rrdtool.git 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,