5

I need to programmatically install (In Ubuntu) few hundreds of fonts for my application (Developed in Ruby on rails) and track the font names installed while installing.

So i need a tool or some library in UBUNTU which takes TTF file as input and provide the Font-Name as output.

Even if there is some way in ruby (GEM OR anything which can help) to find the font-name with given TTF file, will be great help.

Thanks in Advance.

max
  • 347
  • 3
  • 14
  • What have you searched for? I find it implausible that searching for "ruby ttf parser" returned zero useful results... – J. Holmes Jun 12 '12 at 07:50

3 Answers3

4

I imagine there ought to be a ruby font parser of some sort that could do this, but if you have a little skill you could probably make your own pretty easily. You'll need two important pieces of info:

Read the header, locate the 'name' table, search the 'name' table for a nameID 4 entry ("full name", e.g. "My Cool Font Bold Italic"). Or maybe nameID 1 if you just want the family name ("My Cool Font").

The data structures are pretty simple and should not be much trouble at all for even a beginner developer to understand and parse.

djangodude
  • 5,362
  • 3
  • 27
  • 39
  • Thanks djangodude. This links helped to understand the structure of font files. But i ahve found another solution which might be little messy.. :P Anyway posting it here below... :) – max Jun 19 '12 at 04:41
2

Basically i used fop-ttfreader to get the details from a TTF file..

fop-ttfreader fontfile.ttf xmlfile.xml

http://manpages.ubuntu.com/manpages/natty/man1/fop-ttfreader.1.html

So now this xml file can be parsed and get the font details.

This looks like its increased to 2 steps, instead as suggested by djangodude, it can be done in a simple code by parsing ourself. In my case it will be a one time process like a rake.. So this helped me to finish my job.. :P

Hope this may help someone.

max
  • 347
  • 3
  • 14
1

The ttfunk gem will do most of the heavy lifting without you needing to do any parsing yourself:

require 'ttfunk'

file = TTFunk::File.open("some/path/myfont.ttf")
puts "name: #{file.name.font_name.join(', ')}"

(excerpt from the readme in said gem)

Jon Burgess
  • 2,035
  • 2
  • 17
  • 27