Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check which fonts contain a specific character with perl? [duplicate]

Tags:

fonts

perl

Here are already questions:

  • How to determine which fonts contain a specific character?
  • Checking if certain characters are supported by a font

I have many different fonts. Many of them are "ascii only", and i need to check what fonts contains several accented characters. (latin - unicode codepoints - texts are encoded as utf8) like: (áäčďéěíĺľňóôöőŕřšťúůüűýž)

Have mainly:

  • TrueType fonts (with the extension .ttf)
  • TrueType collections (extension .ttc)
  • OpenType fonts (.otf)

What is the usual (correct) way to do this with perl? (it is the only language what i know a bit and the above questions are for C). Asking before I start install all CPAN modules what contains "font":).

I'm on OS X (if this is matters, and can install any macports package - if it helps).

like image 928
cajwine Avatar asked Jun 03 '13 20:06

cajwine


1 Answers

For .ttf files, you can use Font::TTF and related modules:

use Font::TTF::Font;
my $font = Font::TTF::Font->open( "C:/Windows/Fonts/ariali.ttf" );
my @supported_codepoints = sort { $a <=> $b } $font->{cmap}->reverse;

I'm getting out of my depth, but there's also a Font::TTF::Ttc module in the Font::TTF distribution that you could poke around in and see if you can extract more information about supported code points.

(Font::TTF suggestion came from here)

like image 126
mob Avatar answered Oct 10 '22 19:10

mob