Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Querida web, cual es el equivalente pitónico de fc-match?

$ fc-­ma­tch "Droid San­s" Droi­d­San­s.­ttf: "Droid San­s" "Re­gu­la­r"

O in­clu­si­ve:

$ fc-match "Droid Sans" -v | grep file:
      file: "/usr/share/fonts/TTF/DroidSans.ttf"

¿En­ton­ce­s, co­mo ha­go eso, ir de un nom­bre de fuen­te a un ar­chi­vo de fuen­te, si no ten­go fon­tcon­fi­g?

En­contré có­di­go pa­ra eso en el mó­du­lo fon­t_­ma­na­ger de ma­tplo­tlib pe­ro pa­re­ce di­fi­cil de se­pa­rar y re­que­rir ma­tplo­tlib es de­ma­sia­do­...

Si no hay una so­lu­ción por­ta­ble, me al­can­za con tres so­lu­cio­nes in­de­pen­dien­tes y pro­me­to pu­bli­car una ca­pa de abs­trac­ción so­bre ellas ;-)

En­ton­ce­s, que­ri­dos pi­to­nis­tas en win­do­ws y ma­c... ¿al­gu­na pis­ta?

Orestis Markou / 2009-09-30 08:29:

You need to use PyObjC and NSFont to get an NSFont object from a name, but a cursory search doesn't indicate a way to get a font file from an NSFont object...

Roberto Alsina / 2009-09-30 11:37:

That's on OSX, right?

Orestis Markou / 2009-09-30 12:14:

Yes, OSX. Why do you need access to the font files themselves? If you have drawing to do OSX has very nice font mechanisms, perhaps you can use these directly.

Roberto Alsina / 2009-09-30 13:20:

I need the file to embed in a PDF.

Orestis Markou / 2009-09-30 14:18:

The closest I can see is this:

Though this probably won't be accessible through PyObjC.

The reason there's no API is that an NSFont instance does not always map to a file (could be mapped to memory, could be in another application bundle) and so on.

Annoying, isn't it? Perhaps you can use Quartz (Core Graphics) to construct the PDF. Then things should work... (Note: I'm not a PDF expert).

Roberto Alsina / 2009-09-30 15:02:

Oh, well. I think I found a way for windows, mac users are probably not the target for this app anyway.

jjconti / 2009-09-30 15:11:

De la versión en inglés te quedó un "Or even:"

Roberto Alsina / 2009-09-30 15:37:

Gracias Juanjo, corregido!

Marius Gedminas / 2009-09-30 16:30:

pygame.font does this (goes from a font name to a filename). A few years back its Linux version was actually calling fc-match in a subprocess.

Anonymous / 2009-09-30 20:20:

In windows, I believe you have to scan the registry looking for the font file thats providing your face name.

Stani / 2009-10-01 14:08:

Which solution did you find for Windows? I'd like to know.

How about this solution which should work for Windows, Mac and Linux?

This was also suggested by Marius Gedminas, but taking you to the file makes it more easy.

Roberto Alsina / 2009-10-01 14:23:

@stani I get a 404.

I did check Marius solution, it's the best so far. I'll try to extract it from pygame in a day or two.

Contents © 2000-2023 Roberto Alsina