; Wax Text Logo - create wax-seal-looking text
; Copyright (C) 1998 by Jaroslav Benkovsky <benkovsk@pha.pvt.cz>
; 
; Version: 0.1
;
; Requires:
;   plug-in-mblur
;   plug-in-gauss-rle
;   script-fu-wax-seal

(define (script-fu-wax-text-logo text font size wax-color bg-color create-shadow?)
    (let* (
	   ; script parameters' defs
	   (light-azimuth 315)
	   (light-elevation 45)
	   (light-depth 20)
	   (bump-granularity 4)
	   (bump-smoothness 10)
	   (bump-seed 0)
	   (border (/ size 4))
	   (wax-thickness (/ size 10))
	   (shadow-depth (/ size 15))

	   (old-fg (car (gimp-palette-get-foreground)))
	   (old-bg (car (gimp-palette-get-background)))
      	   (dummy (gimp-palette-set-foreground '(0 0 0)))

	   (img (car (gimp-image-new 256 256 RGB)))
	   (text-layer (car (gimp-text img -1 0 0 text border TRUE size PIXELS "*" font "*" "*" "*" "*")))
	   (width (car (gimp-drawable-width text-layer)))
	   (height (car (gimp-drawable-height text-layer)))
	   )

    ; setup
    (gimp-image-disable-undo img)
    (gimp-image-resize img width height 0 0)

    ; "waxify" the text
    (set! text-layer (car (gimp-image-flatten img)))
    (script-fu-wax-seal img text-layer wax-color 
			light-azimuth light-elevation light-depth
			wax-thickness 20 TRUE FALSE 0 TRUE 
			bump-granularity bump-smoothness bump-seed)

    (set! layers (gimp-image-get-layers img))
    (set! layer-cnt (car layers))
    (set! text-layer (aref (cadr layers) 0))

    ; add background layer and color
    (set! bg-layer (car (gimp-layer-new img width height RGB_IMAGE "Background" 100 NORMAL)))
    (gimp-palette-set-background bg-color)
    (gimp-edit-fill img bg-layer)
    (gimp-image-add-layer img bg-layer layer-cnt)

    ; add shadow layer
    (if (= create-shadow? TRUE)
	(begin
	  (set! bg-layer (car (gimp-layer-new img width height RGBA_IMAGE "Shadow Layer" 75 NORMAL)))
	  (gimp-edit-clear img bg-layer)
	  (gimp-selection-layer-alpha img text-layer)
	  (gimp-bucket-fill img bg-layer FG-BUCKET-FILL NORMAL 100 100 FALSE 0 0)
	  (gimp-selection-none img)
	  (plug-in-mblur 1 img bg-layer 0 shadow-depth (- light-azimuth 90))
	  (plug-in-gauss-rle 1 img bg-layer shadow-depth TRUE TRUE)
	  (gimp-image-add-layer img bg-layer layer-cnt)
	  ))

    ; cleanup
    (gimp-palette-set-foreground old-fg)
    (gimp-palette-set-background old-bg)
    (gimp-image-enable-undo img)
    (gimp-display-new img)
))

(script-fu-register "script-fu-wax-text-logo"
		    "<Toolbox>/Xtns/Script-Fu/Logos/Wax Text"
		    "Create text logo made from seal wax (or plasticine)."
		    "Jaroslav Benkovsky <benkovsk@pha.pvt.cz>"
		    "Jaroslav Benkovsky"
		    "February 1998"
		    ""

		    SF-VALUE "Text String"    "\"GIMP\""
		    SF-VALUE "Font"           "\"becker\""
		    SF-VALUE "Size (pixels)"  "150"
		    SF-COLOR "Wax Color"      '(170 13 13)
		    SF-COLOR "BG Color"       '(255 255 255)
		    SF-TOGGLE "Create Shadow" TRUE
)
