Encuentra FontName desde un archivo TTF en UBUNTU

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 como salida.

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.

Gracias de antemano.

preguntado el 12 de junio de 12 a las 08:06

What have you searched for? I find it implausible that searching for "ruby ttf parser" returned zero useful results... -

3 Respuestas

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.

Respondido el 14 de junio de 12 a las 15:06

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

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

fop-ttfreader fontfile.ttf xmlfile.xml


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

Espero que esto pueda ayudar a alguien.

Respondido el 19 de junio de 12 a las 06:06

La 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)

Respondido el 12 de diciembre de 18 a las 03:12

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.