Looks nice. I can't get it to do multiple faces though. I'll work on it. Thanks.
-Alan -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Henrik Mikael Kristensen Sent: Wednesday, October 01, 2008 11:54 AM To: [EMAIL PROTECTED] Subject: [REBOL] Re: drawing images on text face after displayed = "highlighting text" On Wed, Oct 1, 2008 at 5:47 PM, Alan Macleod <[EMAIL PROTECTED]> wrote: > > I tried some similar things to get the highlighted text in a temp face but > could not get it to work... My code so far (stolen from your original code submission): rebol [] pad: 20x30 set-highlight: func [ "Sets the highlight boxes in the given text face" face [object!] strings [block!] "Block of one or multiple string pairs describing the highlight start and end points" /no-show /local access ] [ if all [ access: get in face 'access in access 'set-face* ] [ access/set-highlight* face strings ] if not no-show [show face] face ] get-highlight: func [face [object!]] [ ; unimplemented ] window: layout [ style hl-text text with [ pane: make block! [] hl: none ; a single highlight face hl-face: make face [ color: 255.0.0 edge: none para: make para [origin: 0 margin: 0] effect: [gradient 0x1 255.128.0 255.0.0] ; just to make it look a little cooler ] ; the pane which stores all highlight faces hl-pane: make face [color: none pane: make block! []] ; the position in pane for the highlight pane as used by set-highlight* hl-pane-block: none make-hl-face: func [face str pos sz] [ append face/hl-pane-block make face/hl-face [offset: pos - 2 size: sz text: str] ] split-lines: make block! [] access: make access [ set-highlight*: func [face [object!] strings [block!] /local pos end-pos split-lines str sz done] [ face/hl: strings clear face/hl-pane-block ; create highlight boxes foreach [start end] face/hl [ ; paint a box for each highlight by finding the position on where to paint it using caret-to-offset to get the position. ; is the highlight split over multiple lines? ; the end-pos can't be used here, we need to do the split thing before calculating positions str: copy/part start end sz: size-text make face/hl-face [size: 2000x50 text: str] pos: caret-to-offset face start end-pos: caret-to-offset face end either pos/y <> end-pos/y [ ; multiple lines ; ---------- The code in this block is not working correctly ------------ ; paint one box per line for multiple line highlights ; that means that each line must paint right from start or beginning of line to either the end of highlight or end of line ; generate split-lines list of all indexes required for painting the lines clear split-lines line-pos: start ; we should be able to use the line list, but something is not right here. ; the line list is not set, but it would be manipulated by something, so we should figure out what that is until [ ; calculate start of line or none sol: ; calculate end of line or none eol: case [ ; start of line to end of line all [sol eol] [repend split-lines [sol eol] false] ; start of text to end of line all [none? sol eol] [repend split-lines [start eol] false] ; start of line to end of text all [sol none? eol] [repend split-lines [sol end] true] ] ] foreach [start end] split-lines [ str: copy/part start end sz: size-text make face/hl-face [size: 2000x50 text: str] pos: caret-to-offset face start make-hl-face face str pos sz ] ][ make-hl-face face str pos probe sz ] ] show face ] ] append init [ ; prepare the highlight face to have the right font hl-face/font: make font [offset: 0x0 color: white] unless all [block? pane none? pane] [pane: make block! []] ; position the hl-pane hl-pane/color: none hl-pane/size: size ; perhaps size optimize it later hl-pane/offset: offset append pane hl-pane ; prepare hl-pane-block hl-pane-block: get in last pane 'pane ] ] bx: box red 0x0 panel: panel [ tt: hl-text 500 font-size 12 {Here is a simple example how to use DRAW dialect for into alpha channel of the image. I think with the function make-alpha (bellow in the example) you can draw almost any kind of transparent shape though it is not the fastest method....IMO the possibility to use DRAW pens for alpha channel should be done at Rebol's native level} t: text 400 {Here is a simple example how to use DRAW dialect for e-alpha (bellow in the example) you can draw almost any kind of transparent shape though it is not the fastest method....IMO the possiinto alpha channel of the image. I think with the function make-alpha (bellow in the example) you can draw almost any kind of transparent shape though it is not the fastest method....IMO the possibility to use DRAW pens for alpha channel should be done at Rebol's native level} text 500 {can draw almost any kind of transparent shape though it is not the fastest method....IMO the possibility to use DRAW pens for alpha channel should be done at Rebol's naHere is a simple example how to use DRAW dialect for into alpha channel of the image. I think with the function make-alpha (bellow in the example) you can draw almost any kind of transparent shape though it is not the fastest method....IMO the possibility to use DRAW pens for alpha channel should be done at Rebol's native level}] button "Highlight" [foreach face panel/pane [if face/style = 'text [ system/view/focal-face: face system/view/highlight-start: find face/text "into alpha channel of the image" system/view/highlight-end: find/tail face/text "into alpha channel of the image" show face ]]] button "Paint" [foreach face panel/pane [if face/style = 'text [ keyword: "transparent" xy: caret-to-offset face find face/text keyword bx/offset: face/offset + pad + xy bx/size: as-pair (5.9 * length? keyword) 15 show face ]]] button "Box highlight" [ set-highlight tt reduce [ ; one start and end highlight component per line find tt/text "IMO" skip find tt/text "IMO" 10 find tt/text "native" skip find tt/text "native" 4 ] ] ] view window -- Regards, Henrik Mikael Kristensen -- To unsubscribe from the list, just send an email to lists at rebol.com with unsubscribe as the subject. -- To unsubscribe from the list, just send an email to lists at rebol.com with unsubscribe as the subject.
