<html><head/><body><html><head></head><body>Ah, that could work nicely since I may eventually want to be inserting some other stuff in the editor for printing, anyway. (Currently I&#39;m inserting a simple rubric -- which I generate using web-server/templates -- at the top, but it will be nice to have a checker that inserts some comments at the site where they&#39;re relevant, too.)  So I may indeed switch over to that method.<br>
<br>
Thanks again!<br>
<br>
Best,<br>
jmj <br>
-- <br>
Sent from my Android phone with K-9 Mail.<br><br><div class="gmail_quote">Robby Findler &lt;robby@eecs.northwestern.edu&gt; wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre style="white-space: pre-wrap; word-wrap:break-word; font-family: monospace; margin-top: 0px">It looks like unpack-submission creates only text% objects, not<br />text:racket% objects. But I think you can iterate over the snips in<br />teh editor (find-first-snip method on the text% and next on teh snip%)<br />and use the copy method of the snip to create new ones to insert into<br />a text:racket% object. Then if you just call freeze-colorer, you'll<br />get the fixed width font (without explicitly setting the style) and<br />you'll get the syntax highlighting.<br /><br />Robby<br /><br />On Fri, Dec 7, 2012 at 3:14 PM, Jordan Johnson &lt;jmj@fellowhuman.com&gt; wrote:<br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;">Hi Robby, Matthew,<br /><br />Thanks for the replies.  Robby, that was exactly what I needed, since I hadn't thought to look at the text% hierarchy recently for style changes.  (Even knowing
that, it took a while to work it out; owing to my not having a full understanding of what triggers a reload of files the checker depends on, I didn't get the version below to work until I manually restarted the server. But it's all good now.  Also of interest: I learned that even if I set the style correctly as below, if I subsequently set the font to fixed-width in the dc as I'd erroneously been doing, the text reverted to the non-fixed sans serif.  That was surprising!)<br /><br />Here is my corrected, working code:<br /><br />#lang s-exp handin-server/checker<br /><br />(require racket/gui/base racket/class  ;; for PDF rendering<br />racket/draw)<br /><br /><br />(define fixed-width<br />(send (new style-delta%) set-delta 'change-family 'modern))<br /><br />;; make-pdf : String text% -&gt; any<br />;; Generates a PDF of the given Definitions window, saved in<br />;; /tmp/test-pdf-writing.pdf:<br />(define (make-pdf file defs)<br />(define dc (new pdf-dc%<br />[interactive #f]<br
/>[output "/tmp/test-pdf-writing.pdf"]))<br />(send defs select-all)<br />(send defs change-style fixed-width)<br />(send dc start-doc "")<br />(send defs print-to-dc dc -1)<br />(send dc end-doc))<br /><br />(check: :language '(special beginner)<br />:textualize? #t<br />(define user-string<br />(if (list? users) (apply string-append users) users))<br />(define-values (defs ints) (unpack-submission submission))<br />(make-pdf user-string defs))<br /><br />;; end<br /><br />I suppose there are two remaining questions: does freeze-colorer need to be called even if the text% in question is not displayed, and where is the latest it can be called in the sequence above?<br /><br />Best,<br />Jordan<br /><br />On Dec 7, 2012, at 4:21 AM, Robby Findler &lt;robby@eecs.northwestern.edu&gt; wrote:<br /><br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;">Code would help understand, but setting the font in the dc isn't
the<br />way to go: you want the styles to be right (which is what racket:text%<br />does). And you'd need to call freeze-colorer to wait for the coloring<br />to finish, too, but that would affect only the colors, not the fonts.<br /><br />Robby<br /><br />On Fri, Dec 7, 2012 at 5:56 AM, Matthew Flatt &lt;mflatt@cs.utah.edu&gt; wrote:<br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">I'm not sure. Can you provide a small program that illustrates the problem?<br /><br />At Fri, 7 Dec 2012 00:26:47 -0800, Jordan Johnson wrote:<br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;">Hi all,<br /><br />I was delighted to find awhile back that it's pretty easy to obtain a PDF of<br />syntax-colored code that looks more or less like what I see in my DrRacket<br />window, by drawing the text% to a PDF-dc%.  I am now using that in conjunction<br />with
the handin server to grade and mark up student work on my iPad (annotating<br />the PDFs via GoodReader and emailing them straight back to students), and it<br />works beautifully. (I am happy to share the code for this with anyone who is<br />interested; email me if so.)<br /><br />One glitch: I can't get Racket to give me a fixed-width font in the PDF.  I<br />have tried inserting<br />(send dc set-font (make-object font% 12 'modern))<br />where dc is my pdf-dc%, and alternately<br />(send dc set-font (send the-font-list find-or-create-font 12 'modern 'normal<br />'normal))<br />but in both cases the generated PDF is still in a sans-serif non-fixed-width<br />font.  It does not seem to matter whether I put the above lines before or after<br />the<br />(send dc start-doc "")<br />that begins the drawing process.<br /><br />Interestingly, in a test I ran just now, if I generate a PDF by directly<br />creating a racket:text% object, putting some Racket program text in it, and<br
/>calling the same make-PDF function I use in the handin-server (calling set-font<br />using the-font-list, as described above), it gives me fixed-width text as I'd<br />expect.  That's regardless of whether I set the font before or after the<br />start-doc command. (racket:text% is just a guess at the text% subclass that the<br />handin server is providing, based on it being a representation of the<br />Definitions window.)<br /><br />Any ideas how to solve this, or further tests I could run to determine the<br />cause?<br /><br />Thanks for your consideration,<br />Jordan<br />____________________<br />Racket Users list:<br /><a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br /></blockquote>____________________<br />Racket Users list:<br /><a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br /></blockquote></blockquote></blockquote></pre></blockquote></div></body></html></body></html>