<div dir="ltr">Thanks very much for looking into this. I'm sure the docs will benefit from what you figure out!<div><br></div><div>Robby</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 11, 2014 at 3:54 PM, Jens Axel Søgaard <span dir="ltr"><<a href="mailto:jensaxel@soegaard.net" target="_blank">jensaxel@soegaard.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">2014-02-11 20:07 GMT+01:00 Robby Findler <<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>>:<br>
<div class="">> I'm not sure I can give you more than just hints (and certainly not a<br>
> specification)<br>
<br>
</div>I suddenly realized I should look in the Cairo docs, to see their<br>
intended usage.<br>
<div class=""><br>
> but probably the difference is that pict->bitmap is drawing<br>
> the pict at (0,0) in the DC and scribble is drawing it at some random place.<br>
> But yeah, I'm sorry, that's still just a guess.<br>
<br>
</div>After some experiments I think the reason is that Cairo has both user<br>
space coordinates (aka logical coordinates) and pattern space. When a<br>
pattern is<br>
created it has the same coordinate system has the user space, but if<br>
a transformation is applied (to user space) the spaces become different.<br>
<br>
I haven't yet fully grokked what the implications are.<br>
<br>
It is still odd that DrRacket and Scribble render the same pict<br>
differently though.<br>
If I call (convert the-pict 'png-bytes) in DrRacket I get the correct image, and<br>
Scribble doesn't do anything more.<br>
<div class=""><br>
> And the examples at that link are really fantastic!<br>
<br>
</div>Thanks!<br>
<div class="HOEnZb"><div class="h5"><br>
> On Tue, Feb 11, 2014 at 1:03 PM, Jens Axel Søgaard <<a href="mailto:jensaxel@soegaard.net">jensaxel@soegaard.net</a>><br>
> wrote:<br>
>><br>
>> 2014-02-11 19:39 GMT+01:00 Robby Findler <<a href="mailto:robby@eecs.northwestern.edu">robby@eecs.northwestern.edu</a>>:<br>
>> > Is the problem that you need to use (more) absolute coordinates in the<br>
>> > coordinate arguments to linear-gradient% (either that or set the origin<br>
>> > of<br>
>> > the dc, in the case that you wanted to create the brush only once)?<br>
>><br>
>> The problem is that it is unspecified (as far as I know) whether brushes<br>
>> used in picts are specified using absolute or relative coordinates. For<br>
>> solid<br>
>> brushes this makes no difference. For non-solid brushes (gradients and<br>
>> textures) there is a choice to be made. I got surprised by the<br>
>> behavior and thought<br>
>> of it as a bug (I was looking for one - I have an example where a pict<br>
>> shows up perfectly in DrRacket but renders differently in Scribble).<br>
>><br>
>> If I in shady make a new gradient each time the pict is to be drawn, I get<br>
>> the<br>
>> behavior I want:<br>
>><br>
>> (new linear-gradient%<br>
>> [x0 x] [y0 y] [x1 (+ x (* 2 r))] [y1<br>
>> y] ; horizontal gradient<br>
>> [stops (list (list 0 red) ; (0,0)<br>
>> to ( r,0) red->green<br>
>> (list 1/2 green) ; (r,0)<br>
>> to (2r,0) green->blue<br>
>> (list 1 blue))])<br>
>><br>
>> Since the pict constructors such as filled-rectangle use the pen, there<br>
>> were no way to figure out what was intended.<br>
>><br>
>> The last example here: shows that Scribble converts p and (pict->bitmap p)<br>
>> differently. I am still puzzled by this.<br>
>><br>
>><br>
>> <a href="http://soegaard.github.io/docs/metapict/metapict.html#%28part._example-rgb-triangle%29" target="_blank">http://soegaard.github.io/docs/metapict/metapict.html#%28part._example-rgb-triangle%29</a><br>
>><br>
>> /Jens Axel<br>
>><br>
>><br>
>> > On Tue, Feb 11, 2014 at 10:49 AM, Jens Axel Søgaard<br>
>> > <<a href="mailto:jensaxel@soegaard.net">jensaxel@soegaard.net</a>><br>
>> > wrote:<br>
>> >><br>
>> >> The intent of hc-append is that (hc-append p1 p2) draws p1 and p2<br>
>> >> beside each other.<br>
>> >><br>
>> >> The question is whether (hc-append p p) should draw to identical picts?<br>
>> >><br>
>> >> When I use a non-solid brush I get the two ps are drawn differently.<br>
>> >> In (hc-append p1 p2) I was expecting a transformation (translation) on<br>
>> >> the brush.<br>
>> >><br>
>> >> As a demonstration I offer the following program (a bit long, but<br>
>> >> hopefully clear.<br>
>> >><br>
>> >> See a syntax-highligthed version here: <a href="http://pasterack.org/pastes/7953" target="_blank">http://pasterack.org/pastes/7953</a><br>
>> >> The DrRacket output is here: <a href="http://imgur.com/5BRiY0Z" target="_blank">http://imgur.com/5BRiY0Z</a><br>
>> >><br>
>> >> /Jens Axel<br>
>> >><br>
>> >><br>
>> >> #lang racket<br>
>> >> (require pict)<br>
>> >><br>
>> >> ; debug : value pict -> pict<br>
>> >> ; return a pict, that when drawn prints the<br>
>> >> ; brush and drawing context transformation<br>
>> >> (define (debug who pict)<br>
>> >> (dc (lambda (dc x y)<br>
>> >> (define b (send dc get-brush))<br>
>> >> (define bt (send b get-transformation))<br>
>> >> (define dct (send dc get-transformation))<br>
>> >> (displayln (list who 'x x 'y y 'brush: bt 'dc: dct))<br>
>> >> (draw-pict pict dc x y))<br>
>> >> (pict-width pict) (pict-height pict)))<br>
>> >><br>
>> >> (define r 20) ; use same box side for the entire example<br>
>> >><br>
>> >> ; a black filled rectangle<br>
>> >> (define (rect) (filled-rectangle r r))<br>
>> >><br>
>> >> ;;; Examine whether hc-append does any transformation.<br>
>> >> "Expected Image: Two squares a black and a red"<br>
>> >> "Expected Transformation: Same for A and B. Some difference for C."<br>
>> >> (debug 'A<br>
>> >> (hc-append (debug 'B (rect))<br>
>> >> (debug 'C (colorize (rect) "red" ))))<br>
>> >><br>
>> >> ;;; --------------------------------------------------------------<br>
>> >> (require racket/draw)<br>
>> >><br>
>> >> ; colors<br>
>> >> (define (color: name) (send the-color-database find-color name))<br>
>> >> (define red (color: "red"))<br>
>> >> (define green (color: "green"))<br>
>> >> (define blue (color: "blue"))<br>
>> >><br>
>> >> ; square-path : real real real real -> path%<br>
>> >> ; make square with side r and upper left corner (x,y)<br>
>> >> (define (square-path x y w h)<br>
>> >> (define p (new dc-path%))<br>
>> >> (send p move-to x y)<br>
>> >> (send p line-to x (+ y h))<br>
>> >> (send p line-to (+ x w)(+ y h))<br>
>> >> (send p line-to (+ x w)(+ y 0))<br>
>> >> (send p line-to (+ x 0)(+ y 0))<br>
>> >> p)<br>
>> >><br>
>> >> ; fill : pict -> pict<br>
>> >> ; draw a path around pict using current pen and brush<br>
>> >> (define (fill pict)<br>
>> >> (define w (pict-width pict))<br>
>> >> (define h (pict-height pict))<br>
>> >> (dc (lambda (dc x y)<br>
>> >> (draw-pict pict dc x y)<br>
>> >> (send dc draw-path (square-path x y w h)))<br>
>> >> w h))<br>
>> >><br>
>> >> ; shady : pict -> pict<br>
>> >> ; Draws pict with a brush given by a linear, horizontal<br>
>> >> ; gradient from (0,0) to (0,2r). The colors are red->green->blue.<br>
>> >> (define (shady pict)<br>
>> >> (dc (lambda (dc x y)<br>
>> >> ; get old brush<br>
>> >> (define b (send dc get-brush))<br>
>> >> ; make new brush, only change gradient<br>
>> >> (define new-brush<br>
>> >> (new brush%<br>
>> >> [color (send b get-color)]<br>
>> >> [style (send b get-style)]<br>
>> >> [stipple (send b get-stipple)]<br>
>> >> [gradient (new linear-gradient%<br>
>> >> [x0 0] [y0 0] [x1 (* 2 r)] [y1 0] ;<br>
>> >> horizontal gradient<br>
>> >> [stops (list (list 0 red) ; (0,0)<br>
>> >> to ( r,0) red->green<br>
>> >> (list 1/2 green) ; (r,0)<br>
>> >> to (2r,0) green->blue<br>
>> >> (list 1 blue))])]<br>
>> >> [transformation (send b get-transformation)]))<br>
>> >> ; use new brush to draw the pict<br>
>> >> (send dc set-brush new-brush)<br>
>> >> (draw-pict pict dc x y)<br>
>> >> ; restore old brush<br>
>> >> (send dc set-brush b))<br>
>> >> (pict-width pict) (pict-height pict)))<br>
>> >><br>
>> >> (define-syntax (echo stx) (syntax-case stx () [(_ expr) #'(values 'expr<br>
>> >> expr)]))<br>
>> >><br>
>> >> (newline) (newline)<br>
>> >> "Expected: A (black) rectangle"<br>
>> >> (echo (rect))<br>
>> >> "Expected: A rectangle filled with nothing (default brush is empty)"<br>
>> >> (echo (fill (rect)))<br>
>> >> "Expected: A rectangle filled with linear gradient (red to green)"<br>
>> >> (echo (shady (fill (rect))))<br>
>> >> "Expected: Two red-to-green rectangles"<br>
>> >> (echo (hc-append (shady (fill (rect))) (shady (fill (rect)))))<br>
>> >> "Expected: Two red-to-green rectangles"<br>
>> >> (echo (let () (define p (shady (fill (rect)))) (hc-append p p)))<br>
>> >><br>
>> >><br>
>> >><br>
>> >> --<br>
>> >> Jens Axel Søgaard<br>
>> >><br>
>> >> ____________________<br>
>> >> Racket Users list:<br>
>> >> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
>> ><br>
>> ><br>
>><br>
>><br>
>><br>
>> --<br>
>> --<br>
>> Jens Axel Søgaard<br>
><br>
><br>
<br>
<br>
<br>
--<br>
--<br>
Jens Axel Søgaard<br>
</div></div></blockquote></div><br></div>