#!/usr/local/bin/fontforge -lang=ff

if ( Strtol($version)<20070924 )
  Error( "Please upgrade to a more recent version of fontforge" )
endif

if ( $argc <= 1 )
  Print( "fontlint: {fontfile}" )
  Print( "  Validates the listed fonts" )
return( 1 );
endif

while ( $argc > 1 )
  Open( $1, 8 )
  mask = Validate()
  blues = $privateState
  if ( $order==2 )
    blues = blues & ~0x010000;
  else
    mask = mask & ~0x80000;
  endif
  if ( mask==0 && $loadState==0 && blues==0 )
    Print("Validation " + $fontname + " ...Passed")
  else
    Print("Validation " + $fontname + " ...Failed")
    if ( mask & 0x2 )
      Print( "  Open Contour" )
    endif
    if ( mask & 0x4 )
      Print( "  Self Intersecting Glyph" )
    endif
    if ( mask & 0x8 )
      Print( "  Wrong Direction" )
    endif
    if ( mask & 0x10 )
      Print( "  Flipped Reference" )
    endif
    if ( mask & 0x20 )
      Print( "  Missing Points at Extrema" )
    endif
    if ( mask & 0x40 )
      Print( "  Unknown glyph referenced in GSUB/GPOS/MATH" )
    endif
    if ( mask & 0x80 )
      Print( "  More points in a glyph than PostScript allows" )
    endif
    if ( mask & 0x100 )
      Print( "  Too Many Hints" )
    endif
    if ( mask & 0x200 )
      Print( "  Bad Glyph Name" )
    endif
    if ( mask & 0x400 )
      Print( "  More points in a glyph than specified in 'maxp'" )
    endif
    if ( mask & 0x800 )
      Print( "  More paths in a glyph than specified in 'maxp'" )
    endif
    if ( mask & 0x1000 )
      Print( "  More points in a composite glyph than specified in 'maxp'" )
    endif
    if ( mask & 0x2000 )
      Print( "  More paths in a composite glyph than specified in 'maxp'" )
    endif
    if ( mask & 0x4000 )
      Print( "  Instructions longer than allowed in 'maxp'" )
    endif
    if ( mask & 0x8000 )
      Print( "  More references in a glyph than specified in 'maxp'" )
    endif
    if ( mask & 0x10000 )
      Print( "  References nested more deeply than specified in 'maxp'" )
    endif
    if ( mask & 0x20000 )
#      Print( "  'prep' or 'fpgm' tables are longer than specified in 'maxp'" )
#I no longer think this is an error
    endif
    if ( mask & 0x40000 )
      Print( "  Adjacent points too far apart in a glyph" )
    endif
    if ( mask & 0x80000 )
      Print( "  Non integral coordinates in a glyph" )
    endif
    if ( mask & 0x100000 )
      Print( "  A glyph uses at least one, but not all, anchor classes in a subtable" )
      Print( "   (I'm not absolutely sure this is an error)" )
    endif

    mask = $loadState;
    if ( mask & 0x01 )
      Print( "  Bad PostScript fontname entry in the 'name' table" )
    endif
    if ( mask & 0x02 )
      Print( "  Bad 'glyf' or 'loca' table" )
    endif
    if ( mask & 0x04 )
      Print( "  Bad 'CFF ' table" )
    endif
    if ( mask & 0x08 )
      Print( "  Bad 'hhea', 'hmtx', 'vhea' or 'vmtx' table" )
    endif
    if ( mask & 0x10 )
      Print( "  Bad 'cmap' table" )
    endif
    if ( mask & 0x20 )
      Print( "  Bad 'EBDT', 'bdat', 'EBLC' or 'bloc' (embedded bitmap) table" )
    endif
    if ( mask & 0x40 )
      Print( "  Bad Apple GX advanced typography table" )
    endif
    if ( mask & 0x80 )
      Print( "  Bad OpenType advanced typography table" )
    endif
    if ( mask & 0x100 )
      Print( "  Bad version number in OS/2 table (must be >0, and must be >1 for OT-CFF fonts)" )
    endif
    if ( mask & 0x200 )
      Print( "  Bad sfnt file header" )
    endif

    if ( blues & 0x010000 )
      Print( "  Missing BlueValues entry in PostScript Private dictionary" )
    endif
    if ( blues & 0x000001 )
      Print( "  Odd number of elements in either the BlueValues or OtherBlues entries in the PostScript Private dictionary" )
    endif
    if ( blues & 0x000002 )
      Print( "  Disordered elements in either the BlueValues or OtherBlues entries in the PostScript Private dictionary" )
    endif
    if ( blues & 0x000004 )
      Print( "  Too many elements in either the BlueValues or OtherBlues entries in the PostScript Private dictionary" )
    endif
    if ( blues & 0x000008 )
      Print( "  Elements too close in either the BlueValues or OtherBlues entries in the PostScript Private dictionary (must be at least 2*BlueFuzz+1 apart)" )
    endif
    if ( blues & 0x000010 )
      Print( "  Non-integral elements in either the BlueValues or OtherBlues entries in the PostScript Private dictionary" )
    endif
    if ( blues & 0x000020 )
      Print( "  Alignment zone height in either the BlueValues or OtherBlues is too big for the BlueScale in the PostScript Private dictionary" )
    endif
    if ( blues & 0x000100 )
      Print( "  Odd number of elements in either the FamilyBlues or FamilyOtherBlues entries in the PostScript Private dictionary" )
    endif
    if ( blues & 0x000200 )
      Print( "  Disordered elements in either the FamilyBlues or FamilyOtherBlues entries in the PostScript Private dictionary" )
    endif
    if ( blues & 0x000400 )
      Print( "  Too many elements in either the FamilyBlues or FamilyOtherBlues entries in the PostScript Private dictionary" )
    endif
    if ( blues & 0x000800 )
      Print( "  Elements too close in either the FamilyBlues or FamilyOtherBlues entries in the PostScript Private dictionary (must be at least 2*BlueFuzz+1 apart)" )
    endif
    if ( blues & 0x001000 )
      Print( "  Non-integral elements in either the FamilyBlues or FamilyOtherBlues entries in the PostScript Private dictionary" )
    endif
    if ( blues & 0x002000 )
      Print( "  Alignment zone height in either the FamilyBlues or FamilyOtherBlues is too big for the BlueScale in the PostScript Private dictionary" )
    endif
    if ( blues & 0x020000 )
      Print( "  Bad BlueFuzz entry in PostScript Private dictionary" )
    endif
    if ( blues & 0x040000 )
      Print( "  Bad BlueScale entry in PostScript Private dictionary" )
    endif
    if ( blues & 0x080000 )
      Print( "  Bad StdHW entry in PostScript Private dictionary" )
    endif
    if ( blues & 0x100000 )
      Print( "  Bad StdVW entry in PostScript Private dictionary" )
    endif
    if ( blues & 0x200000 )
      Print( "  Bad StemSnapH entry in PostScript Private dictionary" )
    endif
    if ( blues & 0x400000 )
      Print( "  Bad StemSnapV entry in PostScript Private dictionary" )
    endif
    if ( blues & 0x800000 )
      Print( "  StemSnapH does not contain StdHW value in PostScript Private dictionary" )
    endif
    if ( blues & 0x1000000 )
      Print( "  StemSnapV does not contain StdVW value in PostScript Private dictionary" )
    endif
    if ( blues & 0x2000000 )
      Print( "  Bad BlueShift entry in PostScript Private dictionary" )
    endif
Quit( 1 )
  endif
  Close()
  shift
endloop
