}
}
+typedef struct _PostscriptAlias {
+ char* name;
+ char* string_desc;
+} PostscriptAlias;
+
+/* This table maps standard Postscript font names to URW Type 1 fonts */
+static PostscriptAlias postscript_alias[] = {
+ { "AvantGarde-Book", "URW Gothic L, Book" },
+ { "AvantGarde-BookOblique", "URW Gothic L, Book, Oblique" },
+ { "AvantGarde-Demi", "URW Gothic L, Demi" },
+ { "AvantGarde-DemiOblique", "URW Gothic L, Demi, Oblique" },
+
+ { "Bookman-Demi", "URW Bookman L, Demi, Bold" },
+ { "Bookman-DemiItalic", "URW Bookman L, Demi, Bold, Italic" },
+ { "Bookman-Light", "URW Bookman L, Light" },
+ { "Bookman-LightItalic", "URW Bookman L, Light, Italic" },
+
+ { "Courier", "Nimbus Mono L, Regular" },
+ { "Courier-Oblique", "Nimbus Mono L, Regular, Oblique" },
+ { "Courier-Bold", "Nimbus Mono L, Bold" },
+ { "Courier-BoldOblique", "Nimbus Mono L, Bold, Oblique" },
+
+ { "Helvetica", "Nimbus Sans L, Regular" },
+ { "Helvetica-Oblique", "Nimbus Sans L, Regular, Italic" },
+ { "Helvetica-Bold", "Nimbus Sans L, Bold" },
+ { "Helvetica-BoldOblique", "Nimbus Sans L, Bold, Italic" },
+
+ { "Helvetica-Narrow", "Nimbus Sans L, Regular, Condensed" },
+ { "Helvetica-Narrow-Oblique", "Nimbus Sans L, Regular, Condensed, Italic" },
+ { "Helvetica-Narrow-Bold", "Nimbus Sans L, Bold, Condensed" },
+ { "Helvetica-Narrow-BoldOblique", "Nimbus Sans L, Bold, Condensed, Italic" },
+
+ { "NewCenturySchlbk-Roman", "Century Schoolbook L, Roman" },
+ { "NewCenturySchlbk-Italic", "Century Schoolbook L, Italic" },
+ { "NewCenturySchlbk-Bold", "Century Schoolbook L, Bold" },
+ { "NewCenturySchlbk-BoldItalic", "Century Schoolbook L, Bold, Italic" },
+
+ { "Palatino-Roman", "URW Palladio L, Roman" },
+ { "Palatino-Italic", "URW Palladio L, Italic" },
+ { "Palatino-Bold", "URW Palladio L, Bold" },
+ { "Palatino-BoldItalic", "URW Palladio L, Bold, Italic" },
+
+ { "Symbol", "Standard Symbols L, Regular" },
+
+ { "Times-Roman", "Nimbus Roman No9 L, Regular" },
+ { "Times-Italic", "Nimbus Roman No9 L, Regular, Italic" },
+ { "Times-Bold", "Nimbus Roman No9 L, Medium" },
+ { "Times-BoldItalic", "Nimbus Roman No9 L, Medium, Italic" },
+
+ { "ZapfChancery-MediumItalic", "URW Chancery L, Medium, Italic" },
+ { "ZapfDingbats", "Dingbats" },
+};
+
+static char* translate_postscript_fontname(char* fontname)
+{
+ int i;
+
+ for (i = 0; i < sizeof(postscript_alias)/sizeof(*postscript_alias); i++) {
+ if (strcmp(fontname, postscript_alias[i].name) == 0) {
+ return postscript_alias[i].string_desc;
+ }
+ }
+ return NULL;
+}
+
pointf textsize(graph_t *g, textpara_t * para, char *fontname, double fontsize)
{
char *fontpath = NULL;
para->fontname = fontname;
para->fontsize = fontsize;
+ para->translated_fontname = translate_postscript_fontname(fontname);
+
if (! gvtextlayout(GD_gvc(g), para, &fontpath) || !fontpath)
estimate_textlayout(g, para, &fontpath);
/* make sure that there is something to do */
if (tp->nparas < 1)
- return;
+ return;
/* set font attributes */
- if (tp->font) {
- if (tp->font->size > 0.0)
- fsize = tp->font->size;
- else
- fsize = env->finfo.size;
- if (tp->font->name)
- fname = tp->font->name;
- else
- fname = env->finfo.name;
- if (tp->font->color)
- fcolor = tp->font->color;
- else
- fcolor = env->finfo.color;
- } else {
- fsize = env->finfo.size;
- fname = env->finfo.name;
- fcolor = env->finfo.color;
- }
- halfwidth_x = ((double)(tp->box.UR.x - tp->box.LL.x))/2.0;
- p.x = env->p.x + ((double)(tp->box.UR.x + tp->box.LL.x))/2.0;
- p.y = env->p.y + ((double)(tp->box.UR.y + tp->box.LL.y))/2.0;
-
- emit_textparas(job, tp->nparas, tp->para, p,
- halfwidth_x, fname, fsize, fcolor);
- }
+ if (tp->font) {
+ if (tp->font->size > 0.0)
+ fsize = tp->font->size;
+ else
+ fsize = env->finfo.size;
+ if (tp->font->name)
+ fname = tp->font->name;
+ else
+ fname = env->finfo.name;
+ if (tp->font->color)
+ fcolor = tp->font->color;
+ else
+ fcolor = env->finfo.color;
+ } else {
+ fsize = env->finfo.size;
+ fname = env->finfo.name;
+ fcolor = env->finfo.color;
+ }
+ halfwidth_x = ((double)(tp->box.UR.x - tp->box.LL.x))/2.0;
+ p.x = env->p.x + ((double)(tp->box.UR.x + tp->box.LL.x))/2.0;
+ p.y = env->p.y + ((double)(tp->box.UR.y + tp->box.LL.y))/2.0;
+
+ emit_textparas(job, tp->nparas, tp->para, p,
+ halfwidth_x, fname, fsize, fcolor);
+}
#endif
static void
paraspacing = (int) (fsize * LINESPACING);
/* position for first para */
- p.y += paraspacing * (nparas - 1) / 2 /* cl of toppara */
+ p.y += paraspacing * (nparas - 1) / 2 /* cl of top para */
- fsize * 0.30; /* Empirically determined fudge factor */
gvrender_begin_context(job);
typedef struct textpara_t {
char *str; /* stored in utf-8 */
char *fontname;
+ char *translated_fontname;
char *xshow;
void *layout;
void (*free_layout) (void *layout); /* FIXME - this is ugly */
typedef enum { GVATTR_STRING, GVATTR_BOOL, GVATTR_COLOR } gvattr_t;
typedef struct {
- char *fontfam, fontopt;
gvcolor_t pencolor, fillcolor;
pen_type pen;
fill_type fill;
double penwidth;
- double fontsz;
} gvstyle_t;
#define EMIT_SORTED (1<<0)
/* init stack */
gvc->SP = 0;
job->style = &(gvc->styles[0]);
- job->style->fontfam = DEFAULT_FONTNAME;
- job->style->fontsz = DEFAULT_FONTSIZE;
- job->style->fontopt = FONT_REGULAR;
job->style->pen = PEN_SOLID;
job->style->fill = FILL_NONE;
job->style->penwidth = PENWIDTH_NORMAL;
{
gvrender_engine_t *gvre = job->render.engine;
- if (gvre) {
- job->style->fontfam = fontname;
- job->style->fontsz = fontsize;
- }
#ifdef WITH_CODEGENS
- else {
+ if (!gvre) {
codegen_t *cg = job->codegen;
if (cg && cg->set_font)
}
}
-static void svggen_font(GVJ_t * job)
+static void svggen_font(GVJ_t * job, char *fontname, double fontsize)
{
gvstyle_t *style = job->style;
char buf[BUFSIZ];
- int needstyle = 0;
strcpy(buf, " style=\"");
- if (strcasecmp(style->fontfam, DEFAULT_FONTNAME)) {
- sprintf(buf + strlen(buf), "font-family:%s;", style->fontfam);
- needstyle++;
- }
- if (style->fontsz != DEFAULT_FONTSIZE) {
- sprintf(buf + strlen(buf), "font-size:%.2f;", (style->fontsz));
- needstyle++;
- }
+ sprintf(buf + strlen(buf), "font-family:%s;", fontname);
+ sprintf(buf + strlen(buf), "font-size:%.2f;", fontsize);
switch (style->pencolor.type) {
case COLOR_STRING:
if (strcasecmp(style->pencolor.u.string, "black")) {
sprintf(buf + strlen(buf), "fill:%s;",
style->pencolor.u.string);
- needstyle++;
}
break;
case RGBA_BYTE:
sprintf(buf + strlen(buf), "fill:#%02x%02x%02x;",
style->pencolor.u.rgba[0],
style->pencolor.u.rgba[1], style->pencolor.u.rgba[2]);
- needstyle++;
break;
default:
assert(0); /* internal error */
}
- if (needstyle) {
- strcat(buf, "\"");
- svggen_fputs(job, buf);
- }
+ strcat(buf, "\"");
+ svggen_fputs(job, buf);
}
svggen_printf(job, "<g id=\"graph%d\" class=\"graph\"",
job->common->viewNum);
svggen_printf(job,
- " transform=\"scale(%g %g) rotate(%d) translate(%g %g)\"",
+ " transform=\"scale(%g %g) rotate(%d) translate(%g %g)\">\n",
job->scale.x, job->scale.y, job->rotation,
job->translation.x, job->translation.y);
/* default style */
- svggen_fputs(job, " style=\"font-family:");
- svggen_fputs(job, job->style->fontfam);
- svggen_printf(job, ";font-size:%.2f;\">\n", job->style->fontsz);
if (obj->g->name[0]) {
svggen_fputs(job, "<title>");
svggen_fputs(job, xml_string(obj->g->name));
svggen_printf(job, "<text text-anchor=\"%s\"", anchor);
svggen_printf(job, " x=\"%g\" y=\"%g\"", p.x, -p.y);
- svggen_font(job);
+ svggen_font(job, para->translated_fontname, para->fontsize);
svggen_fputs(job, ">");
svggen_fputs(job, xml_string(para->str));
svggen_fputs(job, "</text>\n");
#ifdef HAVE_PANGOCAIRO
#include <pango/pangocairo.h>
-typedef struct _PostscriptAlias {
- char* name;
- char* string_desc;
-} PostscriptAlias;
-
-/* This table maps standard Postscript font names to URW Type 1 fonts */
-static PostscriptAlias postscript_alias[] = {
- { "AvantGarde-Book", "URW Gothic L, Book" },
- { "AvantGarde-BookOblique", "URW Gothic L, Book, Oblique" },
- { "AvantGarde-Demi", "URW Gothic L, Demi" },
- { "AvantGarde-DemiOblique", "URW Gothic L, Demi, Oblique" },
-
- { "Bookman-Demi", "URW Bookman L, Demi, Bold" },
- { "Bookman-DemiItalic", "URW Bookman L, Demi, Bold, Italic" },
- { "Bookman-Light", "URW Bookman L, Light" },
- { "Bookman-LightItalic", "URW Bookman L, Light, Italic" },
-
- { "Courier", "Nimbus Mono L, Regular" },
- { "Courier-Oblique", "Nimbus Mono L, Regular, Oblique" },
- { "Courier-Bold", "Nimbus Mono L, Bold" },
- { "Courier-BoldOblique", "Nimbus Mono L, Bold, Oblique" },
-
- { "Helvetica", "Nimbus Sans L, Regular" },
- { "Helvetica-Oblique", "Nimbus Sans L, Regular, Italic" },
- { "Helvetica-Bold", "Nimbus Sans L, Bold" },
- { "Helvetica-BoldOblique", "Nimbus Sans L, Bold, Italic" },
-
- { "Helvetica-Narrow", "Nimbus Sans L, Regular, Condensed" },
- { "Helvetica-Narrow-Oblique", "Nimbus Sans L, Regular, Condensed, Italic" },
- { "Helvetica-Narrow-Bold", "Nimbus Sans L, Bold, Condensed" },
- { "Helvetica-Narrow-BoldOblique", "Nimbus Sans L, Bold, Condensed, Italic" },
-
- { "NewCenturySchlbk-Roman", "Century Schoolbook L, Roman" },
- { "NewCenturySchlbk-Italic", "Century Schoolbook L, Italic" },
- { "NewCenturySchlbk-Bold", "Century Schoolbook L, Bold" },
- { "NewCenturySchlbk-BoldItalic", "Century Schoolbook L, Bold, Italic" },
-
- { "Palatino-Roman", "URW Palladio L, Roman" },
- { "Palatino-Italic", "URW Palladio L, Italic" },
- { "Palatino-Bold", "URW Palladio L, Bold" },
- { "Palatino-BoldItalic", "URW Palladio L, Bold, Italic" },
-
- { "Symbol", "Standard Symbols L, Regular" },
-
- { "Times-Roman", "Nimbus Roman No9 L, Regular" },
- { "Times-Italic", "Nimbus Roman No9 L, Regular, Italic" },
- { "Times-Bold", "Nimbus Roman No9 L, Medium" },
- { "Times-BoldItalic", "Nimbus Roman No9 L, Medium, Italic" },
-
- { "ZapfChancery-MediumItalic", "URW Chancery L, Medium, Italic" },
- { "ZapfDingbats", "Dingbats" },
-};
-
-static char* find_postscript_font(char* fontname)
-{
- int i;
-
- for (i = 0; i < sizeof(postscript_alias)/sizeof(*postscript_alias); i++) {
- if (strcmp(fontname, postscript_alias[i].name) == 0) {
- return postscript_alias[i].string_desc;
- }
- }
- return NULL;
-}
-
static void pango_free_layout (void *layout)
{
g_object_unref((PangoLayout*)layout);
PangoAttrList *attrs;
GError *error = NULL;
#endif
- char *text, *fontreq;
+ char *text;
const char *family;
if (!fontmap)
if (!context)
context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP(fontmap));
- if (!fontname || strcmp(fontname, para->fontname)) {
- fontname = para->fontname;
+ if (!fontname || strcmp(fontname, para->translated_fontname)) {
+ fontname = para->translated_fontname;
pango_font_description_free (desc);
- /* try to find a match for a PostScript font
- * - or just get best available match */
- if (! (fontreq = find_postscript_font(fontname)))
- fontreq = fontname;
- desc = pango_font_description_from_string(fontreq);
+ desc = pango_font_description_from_string(fontname);
}
family = pango_font_description_get_family (desc);
*fontpath = (char *)family;