Skip to content

Instantly share code, notes, and snippets.

@iegik
Last active January 27, 2021 09:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iegik/47b61b41d3c2a1f3fbb4 to your computer and use it in GitHub Desktop.
Save iegik/47b61b41d3c2a1f3fbb4 to your computer and use it in GitHub Desktop.
FontForge scripts
#!/usr/local/bin/fontforge
#This is the sfddiff script which compares two fonts
if ( Strtol($version) < 20060330 )
Error( "Please upgrade to a more recent version of fontforge" )
endif
flags=0x789
outfile=""
while ( $argc > 1 && Strsub($1,0,1)=="-" )
temp = $1
if ( Strsub(temp,1,2)=='-' )
temp = Strsub(temp,1)
endif
if ( temp=="-ignorehints" )
flags = flags & ~0x8
elseif ( temp=="-ignorenames" )
flags = flags & ~0x100
elseif ( temp=="-ignoregpos" )
flags = flags & ~0x200
elseif ( temp=="-ignoregsub" )
flags = flags & ~0x400
elseif ( temp=="-ignorebitmaps" )
flags = flags & ~0x80
elseif ( temp=="-exact" )
flags = flags | 0x2
elseif ( temp=="-warn" )
flags = flags | 0x44
elseif ( temp=="-merge" )
flags = flags | 0x1800
shift
outfile = $1
elseif ( temp=="-help" )
Print( "sfddiff: [--version] [--help] [--usage] [--ignorehints] [--ignorenames] [--ignoregpos] [--ignoregsup] [--ignorebitmaps] [--warn] [--exact] fontfile1 fontfile2" )
Print( " Compares two fontfiles" )
Print( " --ignorehints: Do not compare postscript hints or truetype instructions" )
Print( " --ignorenames: Do not compare font names" )
Print( " --ignoregpos: Do not compare kerning, etc." )
Print( " --ignoregsub: Do not compare ligatures, etc." )
Print( " --ignorebitmaps: Do not compare bitmap strikes" )
Print( " --exact: Normally sfddiff will match contours which are not exact" )
Print( " but where the differences are slight (so you could compare" )
Print( " truetype and postscript and get reasonable answers). Also" )
Print( " normally sfddiff will unlink references before it compares" )
Print( " (so you can compare a postscript font (with no references)" )
Print( " to the original source (which does have references)). Setting")
Print( " this flag means glyphs must match exactly.")
Print( " --warn: Provides a warning when an exact match is not found" )
Print( " --merge outfile: Put any outline differences in the backgrounds of" )
Print( " appropriate glyphs" )
return(0)
elseif ( temp=="-version" )
Print( "Version 1.0" )
return(0)
else
break
endif
shift
endloop
if ( $argc!=3 || $1=="--usage" || $1=="-usage" )
Print( "sfddiff: [--version] [--help] [--usage] [--ignorehints] [--ignorenames] [--ignoregpos] [--ignoregsup] [--ignorebitmaps] [--warn] [--exact] [--merge outfile] fontfile1 fontfile2" )
return(0)
endif
Open($2)
Open($1)
CompareFonts($2,"-",flags)
if ( outfile!="" )
Save(outfile)
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment