@@ -0,0 +1,2776 @@
+#!/usr/bin/python%0A#%0A# Copyright 2014 Google Inc. All rights reserved.%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22);%0A# you may not use this file except in compliance with the License.%0A# You may obtain a copy of the License at%0A#%0A#     http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0A%0A%22%22%22Routines for subsetting fonts.%22%22%22%0A%0A__author__ = 'roozbeh@google.com (Roozbeh Pournader)'%0A%0Aimport sys%0A%0Afrom fontTools import subset%0A%0Aimport coverage%0A%0A%0Adef subset_font(source_file, target_file,%0A                include=None, exclude=None, options=None):%0A    %22%22%22Subsets a font file.%0A%0A    Subsets a font file based on a specified character set. If only include is%0A    specified, only characters from that set would be included in the output%0A    font.  If only exclude is specified, all characters except those in that%0A    set will be included.  If neither is specified, the character set will%0A    remain the same, but inaccessible glyphs will be removed.%0A%0A    Args:%0A      source_file: Input file name.%0A      target_file: Output file name%0A      include: The list of characters to include from the source font.%0A      exclude: The list of characters to exclude from the source font.%0A      options: A dictionary listing which options should be different from the%0A          default.%0A%0A    Raises:%0A      NotImplementedError: Both include and exclude were specified.%0A    %22%22%22%0A    opt = subset.Options()%0A    opt.recalc_bounds = True%0A    opt.recalc_timestamp = True%0A    opt.canonical_order = True%0A    opt.name_IDs = %5B'*'%5D%0A    opt.name_legacy = True%0A    opt.name_languages = %5B'*'%5D%0A%0A    if options is not None:%0A        for name, value in options:%0A            setattr(opt, name, value)%0A%0A    if include is not None:%0A        if exclude is not None:%0A            raise NotImplementedError(%0A                'Subset cannot include and exclude a set at the same time.')%0A        target_charset = include%0A    else:%0A        if exclude is None:%0A            exclude = %5B%5D%0A        source_charset = coverage.character_set(source_file)%0A        target_charset = source_charset - set(exclude)%0A%0A    font = subset.load_font(source_file, opt)%0A    subsetter = subset.Subsetter(options=opt)%0A    subsetter.populate(unicodes=target_charset)%0A    subsetter.subset(font)%0A    subset.save_font(font, target_file, opt)%0A%0A%0Adef main(argv):%0A    %22%22%22Subset the first argument to second, dropping unused parts of the font.%0A    %22%22%22%0A    subset_font(argv%5B1%5D, argv%5B2%5D)%0A%0A%0Aif __name__ == '__main__':%0A    main(sys.argv)%0A

Add basic font subsetting module.