// Detect It Easy: detection rule file
// Author: LinXP
// Info  : Adobe Type I Font (AFM, PFB, PFM)
// Status: WIP

meta("font");

function detect() {
    if (Binary.getSize() >= 0x0F) {
        if (Binary.compare("'StartFontMetrics '") && Binary.compare("'.'", 0x12)) {
            sName = "Adobe Font Metrics (.AFM)";
            sVersion = "v" + Binary.getString(0x11, 0x03);
            bDetected = true;
        } else if (Binary.read_uint16(0) == 384 && Binary.read_uint16(Binary.getSize() - 2) == 896) {
            sName = "Adobe Printer Font Binary (.PFB)";
            bDetected = true;
            if (Binary.isVerbose()) {
                var sFontText = Binary.getString(0x06, 0x0200);
                var aFontName = sFontText.match(/%!PS-AdobeFont-1.0: (.*?)[\r\n]/);
                if (aFontName) {
                    sOption(aFontName[1]);
                }
            }
        } else if (Binary.compare("0001") && Binary.getSize() == Binary.read_uint32(0x02)) {
            sName = "Adobe Printer Font Metrics (.PFM)";
            bDetected = true;
            if (Binary.isVerbose()) {
                sOptions = Binary.getString(0x06, 0x3C);
            }

        }
    }

    return result();
}