estimate_textlayout(graph_t *g, textpara_t * para, char **fontpath)
{
double *Fontwidth;
- char c, *p;
+ char c, *p, *fp;
para->width = 0.0;
para->height = para->fontsize * LINESPACING;
para->free_layout = NULL;
if (!strncasecmp(para->fontname, "cour", 4)) {
- *fontpath = "[internal courier]";
+ fp = "[internal courier]";
Fontwidth = courFontWidth;
} else if (!strncasecmp(para->fontname, "arial", 5)
|| !strncasecmp(para->fontname, "helvetica", 9)) {
- *fontpath = "[internal arial]";
+ fp = "[internal arial]";
Fontwidth = arialFontWidth;
} else {
- *fontpath = "[internal times]";
+ fp = "[internal times]";
Fontwidth = timesFontWidth;
}
+ if (fontpath)
+ *fontpath = fp;
if ((p = para->str)) {
while ((c = *p++))
para->width += Fontwidth[(unsigned char) c];
pointf textsize(graph_t *g, textpara_t * para, char *fontname, double fontsize)
{
- char *fontpath = NULL;
+ char **fp = NULL, *fontpath = NULL;
pointf size;
para->fontname = fontname;
para->postscript_alias = translate_postscript_fontname(fontname);
- if (! gvtextlayout(GD_gvc(g), para, &fontpath) || !fontpath)
- estimate_textlayout(g, para, &fontpath);
+ if (Verbose && emit_once(para->fontname))
+ fp = &fontpath;
- if (Verbose) {
- if (emit_once(para->fontname)) {
- fprintf(stderr, "%s: fontname \"%s\" resolved to \"%s\"\n",
+ if (! gvtextlayout(GD_gvc(g), para, fp))
+ estimate_textlayout(g, para, fp);
+
+ if (fp)
+ fprintf(stderr, "%s: fontname \"%s\" resolved to: %s\n",
GD_gvc(g)->common.cmdname, para->fontname, fontpath);
- }
- }
+
size.x = para->width;
size.y = para->height;
return size;
/* $Id$ $Revision$ */
/* vim:set shiftwidth=4 ts=8: */
-/**********************************************************
-* This software is part of the graphviz package *
-* http://www.graphviz.org/ *
-* *
-* Copyright (c) 1994-2004 AT&T Corp. *
-* and is licensed under the *
-* Common Public License, Version 1.0 *
-* by AT&T Corp. *
-* *
-* Information and Software Systems Research *
-* AT&T Research, Florham Park NJ *
+/*********************************************************
+* This software is part of the graphviz package *
+* http://www.graphviz.org/ *
+* *
+* Copyright (c) 1994-2004 AT&T Corp. *
+* and is licensed under the *
+* Common Public License, Version 1.0 *
+* by AT&T Corp. *
+* *
+* Information and Software Systems Research *
+* AT&T Research, Florham Park NJ *
**********************************************************/
#ifdef HAVE_CONFIG_H
#endif
#include <string.h>
+#include <fontconfig/fontconfig.h>
#include "gvplugin_textlayout.h"
#ifdef HAVE_PANGOCAIRO
g_object_unref((PangoLayout*)layout);
}
-static void pango_textlayout(GVCOMMON_t *common, textpara_t * para, char **fontpath)
+static boolean pango_textlayout(GVCOMMON_t *common, textpara_t * para, char **fontpath)
{
- static char buf[512]; /* returned in fontpath, only good until next call */
+ static char buf[1024]; /* returned in fontpath, only good until next call */
static PangoFontMap *fontmap;
static PangoContext *context;
static PangoFontDescription *desc;
static char *fontname;
+ char *fnt;
PangoLayout *layout;
PangoRectangle ink_rect, logical_rect;
#if ENABLE_PANGO_XSHOW
GError *error = NULL;
#endif
char *text;
- const char *family;
- PangoStyle style;
- PangoWeight weight;
- PangoVariant variant;
- PangoStretch stretch;
if (!fontmap)
- fontmap = pango_cairo_font_map_get_default();
+ fontmap = pango_cairo_font_map_get_default();
pango_cairo_font_map_set_resolution(PANGO_CAIRO_FONT_MAP(fontmap), (double)POINTS_PER_INCH);
if (!context)
- context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP(fontmap));
+ context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP(fontmap));
if (!fontname || strcmp(fontname, para->fontname)) {
fontname = para->fontname;
- pango_font_description_free (desc);
+ pango_font_description_free (desc);
if (para->postscript_alias) {
int comma=0;
comma = 1;
strcat(buf, para->postscript_alias->style);
}
- desc = pango_font_description_from_string(buf);
+ fnt = buf;
}
else
- desc = pango_font_description_from_string(fontname);
- }
- family = pango_font_description_get_family (desc);
- style = pango_font_description_get_style (desc);
- weight = pango_font_description_get_weight (desc);
- variant = pango_font_description_get_variant (desc);
- stretch = pango_font_description_get_stretch (desc);
- strcpy(buf,family);
- switch (style) {
- case PANGO_STYLE_NORMAL: /* strcat(buf, ", normal");*/ break;
- case PANGO_STYLE_OBLIQUE: strcat(buf, ", oblique"); break;
- case PANGO_STYLE_ITALIC: strcat(buf, ", italic"); break;
- }
- switch (weight) {
- case PANGO_WEIGHT_ULTRALIGHT: strcat(buf, ", ultralight"); break;
- case PANGO_WEIGHT_LIGHT: strcat(buf, ", light"); break;
- case PANGO_WEIGHT_NORMAL: /* strcat(buf, ", normal");*/ break;
- case PANGO_WEIGHT_SEMIBOLD: strcat(buf, ", semibold"); break;
- case PANGO_WEIGHT_BOLD: strcat(buf, ", bold"); break;
- case PANGO_WEIGHT_ULTRABOLD: strcat(buf, ", ultrabold"); break;
- case PANGO_WEIGHT_HEAVY: strcat(buf, ", heavy"); break;
- }
- switch (variant) {
- case PANGO_VARIANT_NORMAL: /* strcat(buf, ", normal");*/ break;
- case PANGO_VARIANT_SMALL_CAPS: strcat(buf, ", smallcaps"); break;
- }
- switch (stretch) {
- case PANGO_STRETCH_ULTRA_CONDENSED: strcat(buf, ", ultracondensed"); break;
- case PANGO_STRETCH_EXTRA_CONDENSED: strcat(buf, ", extracondensed"); break;
- case PANGO_STRETCH_CONDENSED: strcat(buf, ", condensed"); break;
- case PANGO_STRETCH_SEMI_CONDENSED: strcat(buf, ", semicondensed"); break;
- case PANGO_STRETCH_NORMAL: /* strcat(buf, ", normal");*/ break;
- case PANGO_STRETCH_SEMI_EXPANDED: strcat(buf, ", semiexpanded"); break;
- case PANGO_STRETCH_EXPANDED: strcat(buf, ", expanded"); break;
- case PANGO_STRETCH_EXTRA_EXPANDED: strcat(buf, ", extraexpanded"); break;
- case PANGO_STRETCH_ULTRA_EXPANDED: strcat(buf, ", ultraexpanded"); break;
+ fnt = fontname;
+
+ desc = pango_font_description_from_string(fnt);
+
+ if (fontpath) { /* -v support */
+ FcPattern *pat, *match;
+ FcFontSet *fs;
+ FcResult result;
+
+ if (! FcInit())
+ return FALSE;
+
+ pat = FcNameParse((FcChar8 *) fnt);
+ FcConfigSubstitute (0, pat, FcMatchPattern);
+ FcDefaultSubstitute (pat);
+ fs = FcFontSetCreate();
+ match = FcFontMatch (0, pat, &result);
+ if (match)
+ FcFontSetAdd (fs, match);
+ FcPatternDestroy (pat);
+ strcpy(buf,"");
+ if (fs) {
+ FcChar8 *family, *style, *file;
+
+ if (FcPatternGetString (fs->fonts[0], FC_FILE, 0, &file) != FcResultMatch)
+ file = (FcChar8 *) "<unknown font filename>";
+ if (FcPatternGetString (fs->fonts[0], FC_FAMILY, 0, &family) != FcResultMatch)
+ family = (FcChar8 *) "<unknown font family>";
+ if (FcPatternGetString (fs->fonts[0], FC_STYLE, 0, &style) != FcResultMatch)
+ style = (FcChar8 *) "<unknown font style>";
+ strcat(buf, "\"");
+ strcat(buf, (char *)family);
+ strcat(buf, ", ");
+ strcat(buf, (char *)style);
+ strcat(buf, "\" ");
+ strcat(buf, (char *)file);
+ }
+ *fontpath = buf;
+ FcFontSetDestroy(fs);
+ }
}
- *fontpath = buf;
-
pango_font_description_set_size (desc, (gint)(para->fontsize * PANGO_SCALE));
+
#ifdef ENABLE_PANGO_MARKUP
if (! pango_parse_markup (para->str, -1, 0, &attrs, &text, NULL, &error))
die(error->message);
pango_layout_get_extents (layout, &ink_rect, &logical_rect);
/* if pango doesn't like the font then it sets width=0 but height = garbage */
- if (logical_rect.width == 0) {
- *fontpath = NULL; /* indicate a problem */
+ if (logical_rect.width == 0)
logical_rect.height = 0;
- }
para->width = (double)logical_rect.width / PANGO_SCALE;
para->height = (double)logical_rect.height / PANGO_SCALE;
/* FIXME - unfinished code */
iter = pango_layout_get_iter (layout);
do {
- pango_layout_iter_get_char_extents (iter, &char_rect);
+ pango_layout_iter_get_char_extents (iter, &char_rect);
char_rect.x /= PANGO_SCALE;
char_rect.y /= PANGO_SCALE;
} while (pango_layout_iter_next_char (iter));
pango_layout_iter_free (iter);
#endif
+ if (logical_rect.width == 0)
+ return FALSE;
+ return TRUE;
}
static gvtextlayout_engine_t pango_textlayout_engine = {