racket/draw unable to load some font-weights on macOS?

51 views
Skip to first unread message

Joel Dueck

unread,
Feb 15, 2018, 3:44:42 PM2/15/18
to Racket Users
Greetings, long time lurker/first time posting here. I have been working on this one for a couple of days and can't seem to figure it out.

I'm having an issue where on macOS, there are some fonts/variants returned by get-face-list that I can't actually use with a drawing function like text.

#lang racket
(require pict racket/draw)

(define (list-fonts str)
  (filter (lambda(s) (string=? str (substring s 0 (min (string-length str) (string-length s)))))
          (get-face-list #:all-variants? #t)))

(define (demo-font str)
  (apply vl-append (map (lambda (f) (text f f 30)) (list-fonts str))))


Attached is a screenshot comparison of the results of this code on Windows and macOS, both using Racket 6.12.

To sum up the problem “narratively”, as it were: on Windows, among the strings returned by get-face-list is "IBM Plex Sans Text, Medium" and I can do (text "Hello" "IBM Plex Sans Text, Medium" 30), and pict will draw using that font.

But on macOS, where get-face-list will include the string "IBM Plex Sans, Text" (note comma), if I do (text "Hello" "IBM Plex Sans, Text"), I instead get the result in the default sans serif font.

Furthermore, all of IBM Plex Sans’s 16 weights work properly on macOS/Racket—except the "Text" weight!

A similar problem happens with some other fonts on macOS, e.g. Halyard Micro Regular and Halyard Micro Book — the Regular weight works but the Book weight displays using the Regular weight, despite using the exact string found in get-face-list as the font/variant name in the call to text.

I did my main example using IBM Plex Sans since it's a free font [1] should anyone wish to replicate my results for themselves.

How would I best go about finding out what is happening here? Are certain words like “book” or “text” just not recognized/useable as a font weight on macOS? Apologies if I’m missing something obvious!

[1]: https://ibm.github.io/type/

drracket-font-comparison.png

Robby Findler

unread,
Feb 16, 2018, 4:48:51 PM2/16/18
to Joel Dueck, Racket Users
I'm not sure what the right answer is here, but in some specific cases
that have happened to me along these lines, I've found that specifying
'italic or 'bold works out.

Sorry that's not much to go on.

Robby
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Joel Dueck

unread,
Feb 16, 2018, 11:27:25 PM2/16/18
to Racket Users
I appreciate it. I had already tried bold and italic, but your note did give me the idea to try specifying the weights directly, e.g. "IBM Plex Sans, weight=700" —which, sadly, didn't solve my problem, but may have made the problem itself a bit more clear.

Going off of the list of weights in Pango’s documentation [1] I cooked up this test:

#lang racket
(require pict)
 
(define weights
  '("100"   ; thin       (since Pango 1.24)
    "200"   ; ultralight
    "300"   ; light
    "350"   ; semilight  (since Pango 1.36.7)
    "380"   ; book       (since Pango 1.24)
    "400"   ; default
    "500"   ; normal     (since Pango 1.24)
    "600"   ; semibold
    "700"   ; bold
    "800"   ; ultrabold
    "900"   ; heavy
    "1000")); ultraheavy (since Pango 1.24)

(define (compare-weights font-name)
  (apply vl-append (map (lambda (f) (text font-name (string-append font-name ", weight=" f) 34)) weights)))

When I do (compare-weights "IBM Plex Sans") it becomes obvious that Racket is actually only able to use four of Plex Sans’s seven weights (on macOS). 

Input Serif [2] is another good example. It has six weights but this test shows only three of them being used.

Jens Axel Søgaard

unread,
Feb 17, 2018, 5:56:28 AM2/17/18
to Joel Dueck, Racket Users
Which version of Pango is Racket using?

To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
--
Jens Axel Søgaard

Joel Dueck

unread,
Feb 17, 2018, 12:20:14 PM2/17/18
to Racket Users
I wouldn’t know for sure, but looking at the github repo for racket/draw [1] …it looks like, maybe, 1.0.0??

If so, maybe that’s the problem.

--
Jens Axel Søgaard

Matthew Flatt

unread,
Feb 17, 2018, 12:24:49 PM2/17/18
to Racket Users
We're using Pango 1.36.6.

I try to keep track of the versions in

https://github.com/racket/racket/blob/master/racket/src/native-libs/README.txt

At Sat, 17 Feb 2018 09:20:14 -0800 (PST), Joel Dueck wrote:
> I wouldn’t know for sure, but looking at the github repo for racket/draw
> [1] …it looks like, maybe, 1.0.0??
>
> If so, maybe that’s the problem.
>
> [1]:
> https://github.com/racket/draw/blob/master/draw-lib/racket/draw/unsafe/pango.rk
> t
>
> On Saturday, February 17, 2018 at 4:56:28 AM UTC-6, Jens Axel Søgaard wrote:
> >
> > Which version of Pango is Racket using?
> >
> > 2018-02-17 5:27 GMT+01:00 Joel Dueck <dueck...@gmail.com <javascript:>>:
> >> email to racket-users...@googlegroups.com <javascript:>.
> >> For more options, visit https://groups.google.com/d/optout.
> >>
> >
> >
> >
> > --
> > --
> > Jens Axel Søgaard
> >
> >
>
Reply all
Reply to author
Forward
0 new messages