Created
February 19, 2013 10:54
-
-
Save tluyben/4984856 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
$f = $ARGV[0]; | |
$pagestart = 0; | |
$charstart = 0; | |
$kernstart = 0; | |
$s = "<?xml version=\"1.0\"?>\n<font>\n"; | |
open(F, $f); | |
while(<F>) { | |
s/\ (.+?)=([^\".]+?)[\ \n]/\ $1\=\"$2\"\ /isgm; | |
s/\ (.+?)=([^\".]+?)[\ \n]/\ $1\=\"$2\"\ /isgm; | |
if (/^(info.*)$/) { | |
$s .= "<$1 />\n"; | |
} | |
if (/^(common.*)$/) { | |
$s .= "<$1 />\n"; | |
} | |
if (not $pagestart and /^(page.*)$/) { | |
$pagestart = 1; | |
$s .= "<pages>\n"; | |
} | |
if ($pagestart and not /^(page.*)$/) { | |
$pagestart = 0; | |
$s .="\n</pages>\n"; | |
} | |
if ($pagestart and /^(page.*)$/) { | |
$s .= "<$1 />\n"; | |
} | |
if (/^(chars.*)$/) { | |
$charstart = 1; | |
$s .= "<$1>\n"; | |
} | |
if ($charstart and not /^(char.*)$/) { | |
$charstart = 0; | |
$s .="\n</chars>\n"; | |
} | |
if ($charstart and /^(char\ .*)$/) { | |
$s .= "<$1 />\n"; | |
} | |
if (/^(kernings.*)$/) { | |
$kernstart = 1; | |
$s .= "<$1>\n"; | |
} | |
if ($kernstart and not /^(kerning.*)$/) { | |
$kernstart = 0; | |
#$s .="\n</kernings>\n"; | |
} | |
if ($kernstart and /^(kerning\ .*)$/) { | |
$s .= "<$1 />\n"; | |
} | |
} | |
close F; | |
$s .= "\n</kernings>\n</font>"; | |
open(F, ">$f"); | |
print F $s; | |
close F; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not familiar with Perl at all, can you provide a sample command showing how to use this script? I tried
perl script.pl -MyFont.fnt
but it just spit out an xml file with the following: