]> granicus.if.org Git - graphviz/commitdiff
Some improvements on translation of fontnames for the native svg codegen.
authornorth <devnull@localhost>
Tue, 6 Feb 2007 20:04:06 +0000 (20:04 +0000)
committernorth <devnull@localhost>
Tue, 6 Feb 2007 20:04:06 +0000 (20:04 +0000)
lib/common/mksvgfonts.pl [new file with mode: 0755]

diff --git a/lib/common/mksvgfonts.pl b/lib/common/mksvgfonts.pl
new file mode 100755 (executable)
index 0000000..1802eec
--- /dev/null
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+
+# translate a ghostscript config to a graphviz ps_font_equiv.h table
+use English;
+my %features = ();
+
+my %map = (
+"roman" => "serif",
+"sans-serif" => "sans-Serif",
+"typewriter" => "monospace"
+);
+
+# weight normal or bold
+# style normal or italic
+
+if ($#ARGV + 1 != 2) { die "usage: cf2psfe.pl fontmap.cfg ps_font_equiv.txt";}
+
+open(CONFIG,"< $ARGV[0]");
+while (<CONFIG>) {
+       next if /^#/;
+       if (/\[(.+)\]/) { $fontname = $1;}
+       if (/features\s*=\s*(.+)/) { $features{$fontname} = $1;}
+}
+
+open(SOURCE,"< $ARGV[1]");
+while (<SOURCE>) {
+       my ($fontfam, $weight, $style);
+       m/"([^"]+)"/;
+       $f = $features{$1};
+       while (($key,$value) = each(%map)) {
+               $fontfam = $value if ($f =~ /$key/);
+       }
+       $style = ($f =~ /italic/? q("italic") : 0);
+       $weight= ($f =~ /bold/? q("bold") : 0);
+       if ($fontfam eq "") {warn "don't know about $1\n"; $fontfam = "fantasy";}
+       $_ =~ s/},$/,\t\"$fontfam\",\t$weight,\t$style},/;
+       print $_;
+}