186d9c6cdSmaya#!/usr/bin/python3 286d9c6cdSmaya# 386d9c6cdSmaya# setisFixedPitch-fonttools.py 486d9c6cdSmaya# 586d9c6cdSmaya# Copyright (c) 2012 Pravin Satpute <psatpute@redhat.com> 686d9c6cdSmaya# 786d9c6cdSmaya# Licensed under the Apache License, Version 2.0 (the "License"); 886d9c6cdSmaya# you may not use this file except in compliance with the License. 986d9c6cdSmaya# You may obtain a copy of the License at 1086d9c6cdSmaya# 1186d9c6cdSmaya# http://www.apache.org/licenses/LICENSE-2.0 1286d9c6cdSmaya# 1386d9c6cdSmaya# Unless required by applicable law or agreed to in writing, software 1486d9c6cdSmaya# distributed under the License is distributed on an "AS IS" BASIS, 1586d9c6cdSmaya# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1686d9c6cdSmaya# See the License for the specific language governing permissions and 1786d9c6cdSmaya# limitations under the License. 1886d9c6cdSmaya# 1986d9c6cdSmaya# This program takes a TTF font and set isFixedPitch bit used to detect font as a Monospace. 2086d9c6cdSmaya# 2186d9c6cdSmaya# This script depends on fontTools Python library, available 2286d9c6cdSmaya# in most packaging systems and sf.net/projects/fonttools/ 2386d9c6cdSmaya# 2486d9c6cdSmaya# Usage: 2586d9c6cdSmaya# 2686d9c6cdSmaya# $ ./setisFixedPitch-fonttools.py FontIn.ttf 2786d9c6cdSmaya# input font will be overwriten and backup will be created for input font 2886d9c6cdSmaya 2986d9c6cdSmaya# Import our system library and fontTools ttLib 3086d9c6cdSmayaimport sys 3186d9c6cdSmayafrom fontTools import ttLib 3286d9c6cdSmaya 3386d9c6cdSmayafor i in range(1, len(sys.argv)): 3486d9c6cdSmaya# Open the font file supplied as the first argument on the command line 3586d9c6cdSmaya fontfile = sys.argv[i] 3686d9c6cdSmaya print(fontfile) 3786d9c6cdSmaya font = ttLib.TTFont(fontfile) 3886d9c6cdSmaya 3986d9c6cdSmaya# Print the Post table 4086d9c6cdSmaya if 'post' in font: 4186d9c6cdSmaya if font["post"].isFixedPitch == 0: 4286d9c6cdSmaya font["post"].isFixedPitch = 1 4386d9c6cdSmaya print("isFixedPitch is now: ", font["post"].isFixedPitch) 4486d9c6cdSmaya else: 4586d9c6cdSmaya print("Post table not found") 4686d9c6cdSmaya 4786d9c6cdSmaya# Save the new file with the name of the input file 4886d9c6cdSmaya newfont = fontfile[0:-4] + '-fixed' + fontfile[-4:] 4986d9c6cdSmaya font.save(newfont) 5086d9c6cdSmaya print(newfont, "saved.") 51