[plt-scheme] The missing drawing context

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Thu Mar 19 16:17:49 EDT 2009

The pasteboard has to be in an editor-canvas to have a dc, I believe.
In general, there are multiple possible dc classes that have different
font sizing information (eg, canvas-dc% that draws on the screen and
post-script-dc% that prints).

Robby

On Thu, Mar 19, 2009 at 3:14 PM, Jens Axel Soegaard
<jensaxel at soegaard.net> wrote:
> Hi All,
>
> In the code below I need to calculate the size of
> the string snips. In order to do that I need a
> drawing context. Since the string snips belong
> to a pasteboard, I thought I could get the
> drawing context with
>
>    (send pasteboard get-dc)
>
> but all I get is #f.
>
> The pasteboard belongs to an editor snip, since
> I want to use the pasteboard from within DrScheme.
>
> Most likely I am missing something obvious - but what?
>
> /Jens Axel
>
> #lang scheme/gui
>
> (define (make-string-snip string)
>  (make-object string-snip% string))
>
> (define (insert-snip editor snip)
>  (send editor insert snip))
>
> (define (insert-snips editor snips)
>  (for-each (? (s) (insert-snip editor s)) snips))
>
> (define (get-width dc snip)
>  (let ([w (box 0)])
>    (send snip get-extent dc 0 0 w)
>    (unbox w)))
>
> (define pasteboard (new pasteboard%))
> (define editor-snip (new editor-snip%
>                         [editor pasteboard]
>                         [min-width 100]
>                         [min-height 100]))
>
> (define snips (map make-string-snip '("Foo" "Bar" "Baz" "Qux")))
> (insert-snips pasteboard snips)
>
> (let ([dc (send pasteboard get-dc)])
>  (if dc
>      (map (? (s) (get-width dc s)) snips)
>      'hmm))
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.