1#!/usr/bin/python 2# coding=UTF-8 3# 4# Copyright 2014 Google Inc. All rights reserved. 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17 18"""Subset for web fonts.""" 19 20__author__ = 'roozbeh@google.com (Roozbeh Pournader)' 21 22import sys 23 24from nototools import subset 25 26 27def read_charlist(filename): 28 """Returns a list of characters read from a charset text file.""" 29 with open(filename) as datafile: 30 charlist = [] 31 for line in datafile: 32 if '#' in line: 33 line = line[:line.index('#')] 34 line = line.strip() 35 if not line: 36 continue 37 if line.startswith('U+'): 38 line = line[2:] 39 char = int(line, 16) 40 charlist.append(char) 41 return charlist 42 43 44def main(argv): 45 """Subset the first argument to second, dropping unused parts of the font. 46 """ 47 charlist = read_charlist('res/charsets/web.txt') 48 # Add private use characters for legacy reasons 49 charlist += [0xEE01, 0xEE02, 0xF6C3] 50 51 features_to_keep = [ 52 'c2sc', 'ccmp', 'cpsp', 'dlig', 'dnom', 'frac', 'kern', 'liga', 'lnum', 53 'locl', 'numr', 'onum', 'pnum', 'smcp', 'ss01', 'ss02', 'ss03', 'ss04', 54 'ss05', 'ss06', 'ss07', 'tnum'] 55 56 source_filename = argv[1] 57 target_filename = argv[2] 58 subset.subset_font( 59 source_filename, target_filename, 60 include=charlist, 61 options={'layout_features': features_to_keep}) 62 63 64if __name__ == '__main__': 65 main(sys.argv) 66