Question

I'm trying to better understand the Rebol 3 graphics at a lower level (i.e. not using R3-GUI). I'm having a problem rendering text in a draw gob.

This works:

REBOL []

par: make system/standard/para []

gob-svg: make gob! [ ;this GOB is just for SVG graphics
    offset: 0x0
    size: 640x480
    draw: none
]

rt: bind/only [
    size 18 para par text "This is a test!"
] import 'text

gob-svg/draw: bind compose/only [
    box 20x20 50x50 1 text 100x100 640x480 anti-aliased rt
] import 'draw 

view gob-svg

This does not work:

REBOL []

par: make system/standard/para []

gob-svg: make gob! [ ;this GOB is just for SVG graphics
    offset: 0x0
    size: 640x480
    draw: none
]

gob-svg/draw: bind compose/only [
    box 20x20 50x50 1 text 100x100 640x480 anti-aliased (
        bind/only compose [
            size 18 para (par) text "This is a test!"
        ] import 'text
    )
] import 'draw

view gob-svg

Any ideas about what I'm doing wrong? Shouldn't the second script be functionally equivalent to the first?

Thanks.

Was it helpful?

Solution

Cyphre (Richard Smolak) answered my question over at AltMe. The summary is that I should have done a bind/only instead of just a bind. He also cleaned up my example such as eliminating an unnecessary compose. See his full response below:

ddharing: here is working version of your code snippet:

par: make system/standard/para []

gob-svg: make gob! [;this GOB is just for SVG graphics
    offset: 0x0
    size: 640x480
    draw: none
]

gob-svg/draw: bind/only compose/only [
    box 20x20 50x50 1
    text 100x100 640x480 vectorial (
        bind [
            size 18
            para par
            text "This is a test!"
        ] import 'text
    )
] import 'draw

view gob-svg

For much easier preprocessing of DRAW block I suggest to use the dialect preprocessor I included into R3-GUI. See here: https://github.com/saphirion/r3-gui/blob/master/source/gfx-pre.r3.

This code can work independently of r3-gui as well...just execute the gfx-pre.r3 script before your actual code and then you have TO-TEXT and TO-DRAW functions awailable for your convenience.

The draw preprocessor is using the 'classic' DRAW dialect syntax (no need to use the command! calls directly) so your code example could then look like this:

do %gfx-pre.r3

par: make system/standard/para []

gob-svg: make gob! [;this GOB is just for SVG graphics
    offset: 0x0
    size: 640x480
    draw: none
]

gob-svg/draw: to-draw [
    box 20x20 50x50
    text 100x100 640x480 vectorial [
        size 18
        para par
        "This is a test!"
    ]
] copy []

view gob-svg

The reference for R3 DRAW dialect syntax can be found here: http://www.rebol.com/r3/docs/view/draw.html.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top