# Is ruby pango right for this?

**URL:** <https://www.ruby-forum.com/t/is-ruby-pango-right-for-this/82021>\
**Category:** Ruby-Gnome 2\
**Created:** [January 16, 2007, 10:10pm UTC](https://www.ruby-forum.com/t/is-ruby-pango-right-for-this/82021 "2007-01-16T22:10:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![robbiemuffin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@robbiemuffin](https://www.ruby-forum.com/u/robbiemuffin)\
**Post date:** [January 16, 2007, 10:10pm UTC](https://www.ruby-forum.com/t/is-ruby-pango-right-for-this/82021/1 "2007-01-16T22:10:35Z")

</div>

Hi all, and pardon me for posting right away! (there is no ettiquette  
information at the listinfo page)

I have a task, which _sounds_ simple enough but it is looking  
surprisingly involved. I need to display some information about font  
files: Mac & PC PostScript (type 1), Mac and PC TTF, and OpenType.

> From all the PS/TTF files, I need the fontname (much preffered to be  
> as Mac displays it) and it’s weight/face details: I need to  
> concatenate the fontname/weights to things like “Neue Helvetica Black  
> Italic”, etc. But fonts seem to place/misplace names all throughout  
> the fontfile and a simple extraction of, for example the “postscript  
> full name” will usually show the wrong information.

I also need the glyphnames for any glyphs that appear in the font.

And I need the unicode, if available, so I can distinguish, for  
example, latin characters from turkish, or symbol fonts (or OTFs,  
etc). This last part is easy enough for me to look up from the  
unicode range, I think.

It’s with opentype that things get funky. A single opentype font file  
can have different faces, and different ligature substitutions for  
small caps, subscripts, etc. (Its all defined in it’s layout tables)

I’m not looking forward to processing all this, it’s amazingly  
complicated for such a simple thing. But I have to gather and process  
all this information, and best I can tell there’s no tools around that  
do this for me all in one package.

So I’m looking at Pango to do it – to me it’s just an added boon that  
Ruby has a pango interface! But I’m wondering, does anyone know how  
easy, or even possible this is? Can I get these informations all from  
ruby-gnome2, for each of the font formats?

Thanks for reading!  
Robbie

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![robbiemuffin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@robbiemuffin](https://www.ruby-forum.com/u/robbiemuffin)\
**Post date:** [January 18, 2007, 5:47pm UTC](https://www.ruby-forum.com/t/is-ruby-pango-right-for-this/82021/2 "2007-01-18T17:47:49Z")

</div>

Hi,

I think you will be able to get some of the data you want like font  
metrics or character set coverage but some others like the glyph names  
are likely to be too low level for Pango. Also, one problem I can think  
of is that Pango, through Fontconfig, is only aware of fonts in terms of  
“what they provide” (languages covered, weight etc). You may not be able  
to load fonts from their file name. If nobody answers you here, I would  
suggest you ask your question on the pango list.

To me though, it seems clear that the way to go is the freetype library.  
It can do exactly what you want for the font formats you have mentioned.  
AFAIK however, there does not exist Ruby bindings for it. You will have  
to take care of this 😉

I am the author of a pure Ruby library to manipulate TrueType fonts.  
[http://rubyforge.org/projects/ttf-ruby/](http://rubyforge.org/projects/ttf-ruby/)

It will do what you want for TrueType fonts. And you could possibly read  
other fonts by converting them to TrueType with some utilities. This  
library is still at an early stage though.

Mathieu

PS: I have tried the following and get a segfault at line 6:

require “pango”

fd = Pango::FontDescription.new  
fd.family = “DejaVu Sans”

font = Pango::FontMap.new.load\_font(Pango::Context.new, fd)

puts font.inspect

I am not sure whether it is a bug or I misunderstood something in the  
API.

Mathieu

Robbie Muffin wrote:

> Italic", etc. But fonts seem to place/misplace names all throughout  
> It’s with opentype that things get funky. A single opentype font file  
> easy, or even possible this is? Can I get these informations all from
> 
> * * *
> 
> ruby-gnome2-devel-en mailing list  
> removed\_email\_address@domain.invalid  
> [ruby-gnome2-devel-en List Signup and Options](https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en)

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![robbiemuffin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@robbiemuffin](https://www.ruby-forum.com/u/robbiemuffin)\
**Post date:** [January 19, 2007, 3:44pm UTC](https://www.ruby-forum.com/t/is-ruby-pango-right-for-this/82021/3 "2007-01-19T15:44:52Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“[ruby-gnome2-devel-en] is ruby pango right for this?” on Tue, 16 Jan  
2007 16:09:54 -0500,  
“Robbie Muffin” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > From all the PS/TTF files, I need the fontname (much preffered to be  
> > as Mac displays it)

require ‘gtk2’

families = Gtk::Invisible.new.pango\_context.families  
p families.collect {|family| family.name}

> ```
> and it's weight/face details: I need to
> 
> ```

p families.collect {|family| family.faces {|face| face.name}}

> as Mac displays it) and it’s weight/face details: I need to  
> concatenate the fontname/weights to things like “Neue Helvetica Black  
> Italic”, etc.

p families.collect {|family| family.faces {|face| face.describe.to\_s}}

## Thanks,

kou

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![robbiemuffin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3d9bf3/32.png) [@robbiemuffin](https://www.ruby-forum.com/u/robbiemuffin)\
**Post date:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/is-ruby-pango-right-for-this/82021/4 "2007-01-19T16:30:11Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] is ruby pango right for this?” on Thu, 18  
Jan 2007 16:25:44 +0100,  
Mathieu B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am not sure whether it is a bug or I misunderstood something in the API.

You shouldn’t instantiate Pango::FontMap directory. We can  
only use modularized Pango::FontMap. (like Pango::FcFontMap,  
Pango::CairoFcFontMap and so on.) They will be loaded  
dynamically.

## Thanks,

kou

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)
