#! /usr/bin/perl

use Jcode;

if ($#ARGV != 0) {
    print STDERR "usage: $0 <font path>\n";
    exit 1;
}

$fontFile = $ARGV[0];

push(@INC, "./blib/arch");
push(@INC, "./blib/lib");
eval("use FreeType");

FreeType::TT_Init_FreeType($engine);
FreeType::TT_Open_Face($engine, $fontFile, $face);
FreeType::TT_Get_Face_Properties($face, $properties);
$numFace = $properties->{num_Faces};
if (0 == $numFace) {
    print "num face : not correction\n";
    $numFace = 1;
} else {
    print "num face : ", $numFace, "\n";
}
FreeType::TT_Close_Face($face);

for ($j=0; $j<$numFace; $j++) {
    FreeType::TT_Open_Collection($engine, $fontFile, $j, $face);
    $count=FreeType::TT_Get_Name_Count($face);
    print "face number : $j\n";
    print "  count : $count\n";
    for ($i=0; $i<$count; $i++) {
        FreeType::TT_Get_Name_ID($face, $i, $platformID,
                                 $encodingID, $languageID, $nameID);
        FreeType::TT_Get_Name_String($face, $i, $string);
        if (3 == $platformID && 1 == $encodingID) {
            $tmp = $string;
            undef $string;
            foreach ($tmp =~ m,..,g) {
                ($b1, $b2) = m,.,g;
                if (ord($b1) == 0) {
                    $b1 = '';
                } else {
                    $b1 = $b2 = '.';
                }
                $string .= $b1.$b2;
            }
        }
        Jcode::convert(*string, 'euc', 'sjis');
        printf
            "    %03d : platformID=%d encoding=%d, languageID=%d, " .
            "nameID=%d, name=\"%s\"\n",
              $i, $platformID, $encodingID, $languageID, $nameID, $string;
    }
}
FreeType::TT_Done_FreeType($engine);

# end of file