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.


In reply to Re: How might I portably determine the TrueType Font filespecs for 'Generic' font specifications like 'sans-serif'? by vr
in thread How might I portably determine the TrueType Font filespecs for 'Generic' font specifications like 'sans-serif'? by ozboomer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.