1#!/usr/bin/python3 2# 3# setisFixedPitch-fonttools.py 4# 5# Copyright (c) 2012 Pravin Satpute <psatpute@redhat.com> 6# 7# Licensed under the Apache License, Version 2.0 (the "License"); 8# you may not use this file except in compliance with the License. 9# You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, software 14# distributed under the License is distributed on an "AS IS" BASIS, 15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16# See the License for the specific language governing permissions and 17# limitations under the License. 18# 19# This program takes a TTF font and set isFixedPitch bit used to detect font as a Monospace. 20# 21# This script depends on fontTools Python library, available 22# in most packaging systems and sf.net/projects/fonttools/ 23# 24# Usage: 25# 26# $ ./setisFixedPitch-fonttools.py FontIn.ttf 27# input font will be overwriten and backup will be created for input font 28 29# Import our system library and fontTools ttLib 30import sys 31from fontTools import ttLib 32 33for i in range(1, len(sys.argv)): 34# Open the font file supplied as the first argument on the command line 35 fontfile = sys.argv[i] 36 print(fontfile) 37 font = ttLib.TTFont(fontfile) 38 39# Print the Post table 40 if 'post' in font: 41 if font["post"].isFixedPitch == 0: 42 font["post"].isFixedPitch = 1 43 print("isFixedPitch is now: ", font["post"].isFixedPitch) 44 else: 45 print("Post table not found") 46 47# Save the new file with the name of the input file 48 newfont = fontfile[0:-4] + '-fixed' + fontfile[-4:] 49 font.save(newfont) 50 print(newfont, "saved.") 51