]> granicus.if.org Git - graphviz/commitdiff
add postscript font name translation
authorellson <devnull@localhost>
Thu, 13 Jul 2006 23:36:01 +0000 (23:36 +0000)
committerellson <devnull@localhost>
Thu, 13 Jul 2006 23:36:01 +0000 (23:36 +0000)
plugin/pango/gvtextlayout_pango.c

index a5082287c1a2213dad9a67258808b06bb1636d93..1bc363499f26177c889cf1bfbef80cff9f3031b2 100644 (file)
 #include "config.h"
 #endif
 
+#include <string.h>
 #include "gvplugin_textlayout.h"
 
 #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);
@@ -43,7 +109,7 @@ static void pango_textlayout(textpara_t * para, char **fontpath)
     PangoAttrList *attrs;
     GError *error = NULL;
 #endif
-    char *text;
+    char *text, *psfont;
 
     if (!fontmap)
         fontmap = pango_cairo_font_map_get_default();
@@ -51,8 +117,10 @@ static void pango_textlayout(textpara_t * para, char **fontpath)
     if (!context)
         context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP(fontmap));
 
-    desc = pango_font_description_new();
-    pango_font_description_set_family (desc, para->fontname);
+    if ((psfont = find_postscript_font(para->fontname)))
+        desc = pango_font_description_from_string(psfont);
+    else
+        desc = pango_font_description_from_string(para->fontname);
     pango_font_description_set_size (desc, (gint)(para->fontsize * PANGO_SCALE));
 
 #ifdef ENABLE_PANGO_MARKUP