Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redex PDF output contains a wrong font, while Racket REPL renders the correct font #263

Open
o6po5fcs opened this issue Jun 28, 2023 · 2 comments

Comments

@o6po5fcs
Copy link

When I try to use Source Code Pro as the font for nonterminals, the font is correctly rendered in the output of the racket REPL, but when outputting as pdf then a different font is used in the pdf, namely Source Code Variable with weight ExtraLight.

My OS is macOS Ventura 13.4.1, running Racket 8.9 [cs].

A nearly minimal example to reproduce the issue. Some of the style modifications are undoubtedly redundant since they do not affect nonterminals, but this is the actual configuration that I am using in a project (which may be relevant). If needed, the used fonts can be acquired here: Source Code Pro and CMU Serif.

#lang racket

(require redex
         redex/pict)

(define-language CommonLang
  (atom ::= number boolean string ())
  (r/w ::= READ WRITE))

(define sans-serif-style "Source Code Pro")
(define roman-style "CMU Serif")
(label-style sans-serif-style)
(literal-style sans-serif-style)
(metafunction-style sans-serif-style)
(paren-style roman-style)
(default-style roman-style)
(grammar-style roman-style)
(non-terminal-subscript-style `(subscript large-script italic . ,roman-style))
(non-terminal-superscript-style `(superscript large-script italic . ,roman-style))
(non-terminal-style `(italic . ,roman-style))

(render-language CommonLang)
(render-language CommonLang "./commonlang.pdf")

Pictures of the issue:

Correct font for the READ and WRITE terminals:
correct

Incorrect font for the READ and WRITE terminals:
incorrect

@rfindler
Copy link
Member

Below is some code that demonstrates the issue just at the level of pict and racket/gui.

I see that changing the weight does change the output of the pict in the REPL but not in the PDF file so I wonder if the recent changes to racket/draw need more changes?

That is, replacing the definition of p with this:

(define p (text "READ WRITE" (cons (cons 'weight 'heavy) "Source Code Pro")))

exaggerates the difference between the PDF version and the repl version.

#lang racket
(require pict racket/gui/base)

(define p (text "READ WRITE" "Source Code Pro"))
p

(define ps-setup (make-object ps-setup%))
(send ps-setup copy-from (current-ps-setup))
(send ps-setup set-file "commonlang.pdf")
(send ps-setup set-mode 'file)
(define ps/pdf-dc
  (parameterize ([current-ps-setup ps-setup])
    (make-object pdf-dc% #f #f)))
(parameterize ([dc-for-text-size ps/pdf-dc])
  (send ps/pdf-dc start-doc "x")
  (send ps/pdf-dc start-page)
  (draw-pict p ps/pdf-dc 0 0)
  (send ps/pdf-dc end-page)
  (send ps/pdf-dc end-doc))

@rfindler
Copy link
Member

Here's a version that eliminates the pict library from the dependencies.

#lang racket
(require racket/gui/base)

;; changing this doesn't seem to affect the PDF output
;; but it does affect the window output
(define weight 500)

(define (write-it f)
  (define ps-setup (make-object ps-setup%))
  (send ps-setup copy-from (current-ps-setup))
  (send ps-setup set-file "commonlang.pdf")
  (send ps-setup set-mode 'file)
  (define ps/pdf-dc
    (parameterize ([current-ps-setup ps-setup])
      (make-object pdf-dc% #f #f)))
  (send ps/pdf-dc start-doc "x")
  (send ps/pdf-dc start-page)
  (f ps/pdf-dc)
  (send ps/pdf-dc end-page)
  (send ps/pdf-dc end-doc))

(define (draw dc)
  (define font (send dc get-font))
  (send dc set-font
        (send the-font-list find-or-create-font 12 "Source Code Pro"
              'default 'normal weight
              #f 'default #t 'unaligned))
  (send dc draw-text "READ WRITE" 10 10)
  (send dc set-font font))
(write-it draw)

(define f (new frame% [label ""] [width 200] [height 200]))
(define c (new canvas% [parent f] [paint-callback (λ (c dc) (draw dc))]))
(send f show #t)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants