]> granicus.if.org Git - graphviz/commitdiff
Much improved font information with "dot -v"
authorellson <devnull@localhost>
Fri, 7 Mar 2008 19:09:56 +0000 (19:09 +0000)
committerellson <devnull@localhost>
Fri, 7 Mar 2008 19:09:56 +0000 (19:09 +0000)
Now returns the actual font used by pango (if using fontconfig/freetype backend)

plugin/pango/Makefile.am
plugin/pango/gvtextlayout_pango.c

index 0c3826d3ded90065e22e1e0b8be8a44f276a129a..3ede470d75fe8469d792715338ecd33a26b965cf 100644 (file)
@@ -8,7 +8,7 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/lib/gvc \
        -I$(top_srcdir)/lib/graph \
        -I$(top_srcdir)/lib/cdt \
-       $(PANGOCAIRO_CFLAGS) $(LIBGVC_CFLAGS)
+       $(PANGOCAIRO_CFLAGS) $(FREETYPE2_CFLAGS) $(LIBGVC_CFLAGS)
 
 if WITH_PANGOCAIRO
 noinst_LTLIBRARIES = libgvplugin_pango_C.la
index 0d28b62516915d740398dacab18b41e4f5cac5e6..9ec3326e5b712dc8c7c988587baae0acf271fbc7 100644 (file)
@@ -25,7 +25,7 @@
 #ifdef HAVE_PANGOCAIRO
 #include <pango/pangocairo.h>
 #ifdef HAVE_FONTCONFIG
-#include <fontconfig/fontconfig.h>
+#include <pango/pangofc-font.h>
 #endif
 
 static void pango_free_layout (void *layout)
@@ -180,63 +180,51 @@ static boolean pango_textlayout(textpara_t * para, char **fontpath)
            char *tfont;
 
             font = pango_font_map_load_font(fontmap, context, desc);
-           tdesc = pango_font_describe(font);
-           tfont = pango_font_description_to_string(tdesc);
+
            buf[0] = '\0';
            if (psfnt)
                strcat(buf, "(ps) ");
-           strcat(buf, "\"");
-           strcat(buf, tfont);
-           strcat(buf, "\" ");
-
 #ifdef HAVE_FONTCONFIG
-           FcPattern *pat, *match;
-           FcFontSet *fs;
-           FcResult result;
-    
-            if (! FcInit())
-               return FALSE;
-
-#define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0])) 
-
-           pat = FcPatternBuild (0,
-               FC_FAMILY, FcTypeString,
-                   pango_font_description_get_family(tdesc),
-               FC_STYLE, FcTypeString,
-                   string_field( style_map, ARRAY_SIZE(style_map),
-                       pango_font_description_get_style(tdesc) ),
-               FC_WEIGHT, FcTypeInteger,
-                   pango_fc_convert_weight_to_fc(
-                       pango_font_description_get_weight(tdesc) ),
-               (char *) 0);
-
-           FcConfigSubstitute (0, pat, FcMatchPattern);
-           FcDefaultSubstitute (pat);
-           fs = FcFontSetCreate();
-           match = FcFontMatch (0, pat, &result);
-           if (match)
-               FcFontSetAdd (fs, match);
-           FcPatternDestroy (pat);
-           if (fs) {
-               FcChar8 *family, *style, *file;
+           {
+               FT_Face face;
+               PangoFcFont *fcfont;
+               FT_Stream stream;
+               FT_StreamDesc streamdesc;
+               fcfont = PANGO_FC_FONT(font);
+               if (fcfont) {
+                   face = pango_fc_font_lock_face(fcfont);
+                   if (face) {
+                       strcat(buf, "\"");
+                       strcat(buf, face->family_name);
+                       strcat(buf, ", ");
+                       strcat(buf, face->style_name);
+                       strcat(buf, "\" ");
     
-               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);
+                       stream = face->stream;
+                       if (stream) {
+                           streamdesc = stream->pathname;
+                           if (streamdesc.pointer)
+                               strcat(buf, (char*)streamdesc.pointer);
+                           else
+                               strcat(buf, "*no pathname available*");
+                       }
+                       else
+                           strcat(buf, "*no stream available*");
+                   }
+                   pango_fc_font_unlock_face(fcfont);
+               }
+               else
+                   strcat(buf, "*not using fontconfig*");
            }
-           FcFontSetDestroy(fs);
+#else
+           tdesc = pango_font_describe(font);
+           tfont = pango_font_description_to_string(tdesc);
+           strcat(buf, "\"");
+           strcat(buf, tfont);
+           strcat(buf, "\" ");
+           g_free(tfont);
 #endif
             *fontpath = buf;
-           g_free(tfont);
         }
     }