#! /usr/bin/fontforge 
#
# stripttf - Strip TrueType font of unused characters
#
# Copyright (c) 2005 Hidetaka Iwai  <tyuyu@debian.or.jp>
#  

if ($argc < 4)
   Print( "Usage: stripttf in out used_codepoint..." )
   Quit()
endif

Open($1); shift
Reencode("unicode")
out = $1; shift

# Get the size of array from the last argument 
# (to do this, the given list must be sorted)
num = Strtol($argv[$argc - 1]) + 1

# Create an array to select used characters.
used = Array(num)

# Select used characters according to the given list
i = 0
while (i < num && $argc > 1)
  if (i == Strtol($1))
    used[i] = 1; shift
  else
    used[i] = 0
  endif
  ++i
endloop

# Remove unused characters.
Select(used); SelectInvert(); Clear()

# Output the result
Generate(out, "")
Quit()
