[racket] Setting font for drawing to dc%

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Dec 7 06:56:06 EST 2012

I'm not sure. Can you provide a small program that illustrates the problem?

At Fri, 7 Dec 2012 00:26:47 -0800, Jordan Johnson wrote:
> Hi all,
> 
> I was delighted to find awhile back that it's pretty easy to obtain a PDF of 
> syntax-colored code that looks more or less like what I see in my DrRacket 
> window, by drawing the text% to a PDF-dc%.  I am now using that in conjunction 
> with the handin server to grade and mark up student work on my iPad (annotating 
> the PDFs via GoodReader and emailing them straight back to students), and it 
> works beautifully. (I am happy to share the code for this with anyone who is 
> interested; email me if so.)
> 
> One glitch: I can't get Racket to give me a fixed-width font in the PDF.  I 
> have tried inserting
>   (send dc set-font (make-object font% 12 'modern))
> where dc is my pdf-dc%, and alternately
>   (send dc set-font (send the-font-list find-or-create-font 12 'modern 'normal 
> 'normal))
> but in both cases the generated PDF is still in a sans-serif non-fixed-width 
> font.  It does not seem to matter whether I put the above lines before or after 
> the
>   (send dc start-doc "")
> that begins the drawing process.
> 
> Interestingly, in a test I ran just now, if I generate a PDF by directly 
> creating a racket:text% object, putting some Racket program text in it, and 
> calling the same make-PDF function I use in the handin-server (calling set-font 
> using the-font-list, as described above), it gives me fixed-width text as I'd 
> expect.  That's regardless of whether I set the font before or after the 
> start-doc command. (racket:text% is just a guess at the text% subclass that the 
> handin server is providing, based on it being a representation of the 
> Definitions window.)
> 
> Any ideas how to solve this, or further tests I could run to determine the 
> cause?
> 
> Thanks for your consideration,
> Jordan
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.