summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0f913ea)
raw | patch | inline | side by side (parent: 0f913ea)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Mon, 9 May 2005 14:01:21 +0000 (14:01 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Mon, 9 May 2005 14:01:21 +0000 (14:01 +0000) |
-- Peter Speck speck from vitality.dk
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@526 a5681a0c-68f1-0310-ab6d-d61299d08faa
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@526 a5681a0c-68f1-0310-ab6d-d61299d08faa
src/rrd_afm.c | patch | blob | history | |
src/rrd_afm.h | patch | blob | history | |
src/rrd_gfx.c | patch | blob | history |
diff --git a/src/rrd_afm.c b/src/rrd_afm.c
index a7cb2956e41e97a2d40a8d3b8039829b22973644..0bb0ac4f0cf30ec0ac6459f094533e928b8ef113 100644 (file)
--- a/src/rrd_afm.c
+++ b/src/rrd_afm.c
#define ENABLE_LIGATURES 0
static const afm_fontinfo *afm_last_used_font = NULL;
+static const char *last_unknown_font = NULL;
#define is_font(p, name) \
(!strcmp(p->postscript_name, name) || !strcmp(p->fullname, name))
return NULL;
}
-static const char *last_unknown_font = NULL;
+/* returns always a font, never NULL.
+ The rest of the code depends on the result never being NULL.
+ See rrd_afm.h */
static const afm_fontinfo *afm_findfont(const char *name)
{
const afm_fontinfo *p = afm_searchfont(name);
fprintf(stderr, "Can't find font '%s'\n", name);
last_unknown_font = name;
}
- p = afm_searchfont("Courier");
+ p = afm_searchfont(RRD_AFM_DEFAULT_FONT);
if (p)
return p;
return afm_fontinfolist; // anything, just anything.
return p->postscript_name;
}
+const char *afm_get_font_name(const char* font)
+{
+ const afm_fontinfo *p = afm_findfont(font);
+ return p->fullname;
+}
+
double afm_get_ascender(const char* font, double size)
{
const afm_fontinfo *p = afm_findfont(font);
diff --git a/src/rrd_afm.h b/src/rrd_afm.h
index 6a59318986aad2216f01e04b8d211bad611c10f2..655a87382b71dc0b0ea392e121568a03558bc9fb 100644 (file)
--- a/src/rrd_afm.h
+++ b/src/rrd_afm.h
#ifndef RRD_AFM_H
#define RRD_AFM_H
+/*
+ If the font specified by the name parameter in the routes below
+ is not found
+ (because it is not compiled into rrd_afm_data.c by compile_afm.pl)
+ the font specified by RRD_AFM_DEFAULT_FONT will be used.
+ If it is not installed, it uses the first font compiled
+ into rrd_afm_data.c
+ So they will always use some font.
+*/
+
+#define RRD_AFM_DEFAULT_FONT "Courier"
+
/* measure width of a text string */
/* fontname can be full name or postscript name */
double afm_get_text_width ( double start, const char* font, double size,
/* get postscript name from fullname or postscript name */
const char *afm_get_font_postscript_name ( const char* font);
+const char *afm_get_font_name(const char* font);
/* cc -E -dM /dev/null */
#ifdef __APPLE__
diff --git a/src/rrd_gfx.c b/src/rrd_gfx.c
index 6f83bc561fa88b170f9acc2c98d99d42f5bba38f..e288f034bbb3165d39695a3abb0c0abbec358ccd 100644 (file)
--- a/src/rrd_gfx.c
+++ b/src/rrd_gfx.c
*/
static int svg_indent = 0;
static int svg_single_line = 0;
-static const char *svg_default_font = "Helvetica";
+static const char *svg_default_font = "-dummy-";
typedef struct svg_dash
{
int dash_enable;
static void svg_text(FILE *fp, gfx_node_t *node)
{
pdf_coords g;
+ const char *fontname;
/* as svg has 0,0 in top-left corner (like most screens) instead of
bottom-left corner like pdf and eps, we have to fake the coords
using offset and inverse sin(r) value */
svg_write_number(fp, page_height - g.tmy);
fputs("\"", fp);
}
-
-/* if (strcmp(node->filename, svg_default_font))
- fprintf(fp, " font-family=\"%s\"", node->filename);
- */
- fputs(" font-family=\"Helvetica", fp);
- fputs("\" font-size=\"", fp);
+ fontname = afm_get_font_name(node->filename);
+ if (strcmp(fontname, svg_default_font))
+ fprintf(fp, " font-family=\"%s\"", fontname);
+ fputs(" font-size=\"", fp);
svg_write_number(fp, node->size);
fputs("\"", fp);
if (!svg_color_is_black(node->color))
art_u32 width, art_u32 height,
gfx_color_t background, FILE *fp){
gfx_node_t *node = canvas->firstnode;
+ /* Find the first font used, and assume it is the mostly used
+ one. It reduces the number of font-familty attributes. */
+ while (node) {
+ if (node->type == GFX_TEXT && node->filename) {
+ svg_default_font = afm_get_font_name(node->filename);
+ break;
+ }
+ node = node->next;
+ }
fputs(
"<?xml version=\"1.0\" standalone=\"no\"?>\n"
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\"\n"
fprintf(fp, " x=\"0\" y=\"0\" width=\"%d\" height=\"%d\"", width, height);
svg_write_color(fp, background, "fill");
svg_close_tag_empty_node(fp);
+ node = canvas->firstnode;
while (node) {
switch (node->type) {
case GFX_LINE: