Reputation: 537
Is there any way that I can open, read and write a ttf file?
Example:
with open('xyz.ttf') as f:
content = f.readline()
print(content)
A bit more:
If I open a .ttf (font) file with windows font viewer we see the following image
From this I like to extract following lines as text, with proper style.
Upvotes: 5
Views: 21227
Reputation: 21
To display the images that are associated with each keyboard character using ttf format, add the ttf file to the path folder for Word/LibreOffice. Then find the name of the ttf file amongst the font file names; this will allow you to manipulate the font images like text in a text document. But if you copy-paste the font images, the Unicode name (which is the keyboard character that is associated with each image) will appear and NOT the image. To change the Unicode name I think you can use fontforge, but I have not yet tried it.
Upvotes: 0
Reputation: 7255
What is exactly inside this file with *.ttf extension. I think you need to add more details of the input
and output
. If you reffering to a font
type database you must first find a module/package to open and read it, since *.ttf isn't a normal text file.
Read the given links and install the required packages first:
https://pypi.python.org/pypi/FontTools
Then, as suggested:
from fontTools.ttLib import TTFont
font = TTFont('/path/to/font.ttf')
print(font)
<fontTools.ttLib.TTFont object at 0x10c34ed50>
If you need help with something else trying putting the input
and expected output
.
Other links:
Here is a another useful python script:
https://gist.github.com/pklaus/dce37521579513c574d0
Upvotes: 11