use strict; use warnings; use feature 'say'; use File::Spec::Functions; use Font::TTF::Useall; my $dir = catdir $ENV{ SystemRoot }, 'Fonts'; say 'Looks like these our fonts are sans serif and regular:'; for my $fn ( glob( catfile $dir, '*.{ttf,otf}' )) { my $f = Font::TTF::Font-> open( $fn ); next unless $f-> { name }-> read-> find_name( 2 ) eq 'Regular'; next unless $f-> { 'OS/2' }-> read-> { sFamilyClass } >> 8 == 8; say $fn }
If you want to further define, which kind of sans serif font you prefer, see Table 56 for subclasses (check lower byte): https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6OS2.html
And, of course, see this distribution for details: https://metacpan.org/release/Font-TTF
Edit: From the "OS/2" table, you can also check usWeightClass and usWidthClass values, to filter out too narrow, thin, expanded, etc. fonts. See https://www.microsoft.com/typography/otspec/os2.htm, because Apple's page linked above seems to provide incorrect constants for the usWeightClass.
BTW, as to lower byte of sFamilyClass, I'd use it to exclude things like "Typewriter", "Matrix", etc.
P.P.S. The "Regular" string, above, is to exclude "Bold", "Italic" (but sometimes "Oblique"), "BI" ("BO"). Yet, some vendors/authors include string "Book" rather than "Regular" (cf. "DejaVu Sans" font). Because it's correct, in their opinion. It's messy and complicated :-).
Also, e.g. the particular version of "Arial Black" font at one computer I'm at now, has the same value of usWeightClass as "Arial Regular". A perfectionist might wish to also parse and/or hard-code some font names. I.e. many of these entries in TTF tables are just supplemental information, no obligations.
|
|---|