#!/usr/bin/awk -f # Purpose: To make defoma fonts available to ImageMagick. # Converts a defoma .hints file to a file to be used by ImageMagick # Creator: Robert B Valliant # Date: July 28, 2007 # # Note: The fullname attribute is missing. # # If you use defoma, the debian font manager, to manage your # fonts, they will usually be found in # # /etc/defoma/hints # # with names like # gsfonts.hints # msttcorefonts.hints # ttf-bitstream-vera.hints # lmodern.hints # ps-bitstream.hints # ttf-dejavu.hints # # Example use: # # ./hints2IM.awk /etc/defoma/hints/gsfonts.hints > type-ghostscript.xml # # Output goes to standard out. function Usage() { print "USAGE: $0 /etc/defoma/hints/file.hints"; print "Change the 'file' above to a real file name."; exit 1; } BEGIN { if (ARGC-1 != 1) { Usage(); } print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print "]>"; print ""; } { if ($1 ~ /category/) { #print $2; format = $2; } if ($1 ~ /begin/) { if ("name" in fields) { if ( ! ("stretch" in fields)) { # try to catch the ttf fonts, and ps fonts that don't # have an X-FontName attribute f = tolower(fields["name"]); #print "-----",f,"-----"; if (f ~ /condens/) fields["stretch"] = "condensed"; else if (f ~ /extend/) fields["stretch"] = "extended"; else if (f ~ /expand/) fields["stretch"] = "expanded"; else fields["stretch"] = "normal"; } print ""; # Warning is a gawk extension. It may not be available # in all types of awk. delete fields; } fields["glyphs"] = $2; } else if ($1 ~ /GeneralFamily/) next; else if ($1 ~ /X-FontName/) { split($3,a,"-"); fields["stretch"] = a[6]; } else if ($1 ~ /AFM/) fields["metrics"] = $3; else if ($1 ~ /FontName/) fields["name"] = $3; else if ($1 ~ /Family/) fields["family"] = $3; else if ($1 ~ /Foundry/) fields["foundry"] = $3; else if ($1 ~ /Weight/) { f = tolower($3); if (f ~ /normal/) fields["weight"] = 400; else if (f ~ /black/) fields["weight"] = 900; else if (f ~ /bold/) fields["weight"] = 700; else if (f ~ /book/) fields["weight"] = 300; else if (f ~ /demibold/) fields["weight"] = 600; else if (f ~ /extrabold/) fields["weight"] = 800; else if (f ~ /heavy/) fields["weight"] = 950; else if (f ~ /light/) fields["weight"] = 200; else if (f ~ /medium/) fields["weight"] = 500; else if (f ~ /ultrabold/) fields["weight"] = 950; else if (f ~ /ultralight/) fields["weight"] = 100; else if (f ~ /extralight/) fields["weight"] = 100; else fields["weight"] = 400; } else if ($1 ~ /Shape/) { f = tolower($0); if (f ~ /upright/) fields["style"] = "normal"; else if (f ~ /oblique/) fields["style"] = "oblique"; else if (f ~ /italic/) fields["style"] = "italic"; } } END { if ( ! ("stretch" in fields)) { # try to catch the ttf fonts, and ps fonts that don't # have an X-FontName attribute f = tolower(fields["name"]); #print "-----",f,"-----"; if (f ~ /condens/) fields["stretch"] = "condensed"; else if (f ~ /extend/) fields["stretch"] = "extended"; else if (f ~ /expand/) fields["stretch"] = "expanded"; else fields["stretch"] = "normal"; } print ""; print ""; }