#! /usr/bin/fontforge # # Copyright (C) 2005, 2008 Davide Viti # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the Free # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307 USA # # "glyphs_to_remove" argument can be a single code point # or a range of codepoints separated by ":" # # code points can be specified both as integers and as unicode # you can also mix the two formats (i.e "48:u54") # # example: # # "strip_glyphs --input in.ttf --output out.ttf --format ttf --glyphs 12 u20 100:150 u200:u230 u300:65000" # or, the opposite, strip anything _but_ the selection # "strip_glyphs --include --input in.ttf --output out.ttf --format ttf --glyphs 12 u20 100:150 u200:u230 u300:65000" if ($argc < 7) Print( "Usage: strip_glyphs [--include] --format --input --output --glyphs " ) Quit() endif done_parsing=0 use_inverted_selection=0 format="" infile="" outfile="" while ($argc > 1 && done_parsing==0) if ( $1=="--format" ) shift if ( $argc > 1 ) format = $1 if ( format!="ttf" && format!="sfd" ) Error( "Expected one of 'ttf', 'sfd' for format" ) endif endif elseif ( $1=="--include" ) use_inverted_selection=1 elseif ( $1=="--input" ) shift if ( $argc > 1 ) infile=$1 endif elseif ( $1=="--output" ) shift if ( $argc > 1 ) outfile=$1 endif elseif ( $1=="--glyphs" ) shift if ( $argc > 1 ) done_parsing=1 else Error( "No glyphs specified" ) endif else break endif shift endloop if (format=="" || infile=="" || outfile=="" || done_parsing==0 ) Print() Print("Format: ", format) Print("Infile: ", infile) Print("Outfile: ", outfile) Print() Error( "Missing mandatory argument(s)" ) Quit() endif Open(infile) Reencode("unicode") # # Loop through the arguments and select the glyphs # which need to be cleared # while ($argc > 1) len = Strlen($1) colon_idx = Strstr($1, ":") # # argument is a single glyph # if (colon_idx == -1) if(Strstr($1, "u") == -1) SelectMore(Strtol($1)) ## Integer else SelectMore($1) ## Unicode code point (i.e "u0027") endif # # argument is a range low:high # else low = Strsub($1, 0, colon_idx) if(Strstr($1, "u") == -1) low = Strtol(low) ## Integer endif high = Strsub($1, colon_idx+1, len) if(Strstr($1, "u") == -1) high = Strtol(high) ## Integer endif SelectMore(low, high); endif shift endloop if (use_inverted_selection == 1) SelectInvert() endif Clear() if (format=="ttf") Generate(outfile, "") else Save(outfile) endif Quit()