
; Irregular Slab
;
; Christopher Gutteridge, cjg@ecs.soton.ac.uk
;

; Define the function:

(define (script-fu-chris-slabtext inText inFont inFontSize inDistressText inDistressSlab inGilt inTextColor inTextOpacity inBufferAmount inFollowShape inWoodLook inBG inBGColor inFlatten)

              (set! theImageWidth 10)

              (set! theImageHeight 10)

              (set! theImage (car (gimp-image-new theImageWidth theImageHeight RGB) ) )

          (set! theTextLayer (car (gimp-layer-new theImage theImageWidth theImageHeight RGBA_IMAGE "Text Layer" 100 NORMAL) ) )
          (gimp-image-add-layer theImage theTextLayer 0)


          (gimp-palette-set-background '(255 255 255) )
          (gimp-palette-set-foreground '(0 0 0) )

          (gimp-selection-all theImage)
          (gimp-edit-clear theImage theTextLayer)
          (gimp-selection-none theImage)

          (set! theText (car (gimp-text theImage theTextLayer 0 0 inText 0 TRUE inFontSize PIXELS "*" inFont "*" "r" "*" "*")))

          (set! theImageWidth  (car (gimp-drawable-width  theText) ) )
          (set! theImageHeight (car (gimp-drawable-height theText) ) )

          (gimp-image-resize theImage theImageWidth theImageHeight 0 0)
          (gimp-layer-resize theTextLayer theImageWidth theImageHeight 0 0)
          (gimp-floating-sel-anchor theText)
	  (gimp-display-new theImage)
	  (script-fu-chris-irregular-slab theImage theTextLayer inDistressText inDistressSlab inGilt inTextColor inTextOpacity inBufferAmount inFollowShape inWoodLook inBG inBGColor inFlatten)
)

(script-fu-register
    "script-fu-chris-slabtext"
    "<Toolbox>/Xtns/Script-Fu/Logos/Irregular Slab"
    "Applies irregualr slab to some text."
    "Chris Gutteridge"
    "1998, Christopher Gutteridge, ECS Dept. Uni. of Southampton"
    "April 28, 1998"
    ""
    SF-VALUE "Text:"       "\"Dr. Dee\""
    SF-VALUE "Font:"       "\"Charter\""
    SF-VALUE "Font size:"  "45"
    SF-TOGGLE "Distress Text?" FALSE
    SF-TOGGLE "Distress Slab?" TRUE
    SF-TOGGLE "Gilt?" TRUE
    SF-COLOR "Paint Color (not used if gilt):"   '(0 0 0)
    SF-VALUE "Paint Opacity (%) (not used if gilt):"   "50"
    SF-VALUE "Buffer amount:" "20"
    SF-TOGGLE "Follow Shape of text?" TRUE
    SF-TOGGLE "Wood Splinter Effect?" FALSE
    SF-TOGGLE "Add a background?" TRUE
    SF-COLOR "Background Color:"   '(255 255 255)
    SF-TOGGLE "Flatten Image?" TRUE

)

(define (script-fu-chris-irregular-slab inImage inSourceLayer inDistress inDistressSlab inGilt inPaintColor inPaintOpacity inBufferAmount inFollowShape inWoodLook inBG inBGColor inFlatten)

        (set! theImage inImage)
        (set! theSourceLayer inSourceLayer)


          ;(plug-in-autocrop TRUE theImage theSourceLayer)

          (set! theImageWidth  (car (gimp-drawable-width  inSourceLayer) ) )
          (set! theImageHeight (car (gimp-drawable-height inSourceLayer) ) )
          (set! theBuffer inBufferAmount)
          (set! theInc (max 50 (* theBuffer 4)))
          (set! theImageHeight (+ theImageHeight theInc) )
          (set! theImageWidth  (+ theImageWidth  theInc) )

          (gimp-image-resize theImage theImageWidth theImageHeight 0 0)
          ;(gimp-layer-resize theSourceLayer theImageWidth theImageHeight 0 0)

          (gimp-layer-set-offsets theSourceLayer (/ theInc 2) (/  theInc 2))
          (gimp-selection-layer-alpha theImage theSourceLayer)

          (gimp-edit-clear theImage theSourceLayer)
          (gimp-selection-invert theImage)
          (gimp-edit-clear theImage theSourceLayer)
          (gimp-selection-invert theImage)
	  (if (= inDistress TRUE) 
	      (script-fu-distress-selection theImage theSourceLayer 127 2 1.5 2 TRUE TRUE)
              (plug-in-gauss-iir TRUE theImage theSourceLayer 1 TRUE TRUE) 
          )
          (gimp-palette-set-background '(255 255 255) )
          (gimp-palette-set-foreground '(0 0 0) )
          (gimp-edit-fill theImage theSourceLayer)
          (gimp-selection-all theImage)




          (set! thePattLayer (car (gimp-layer-new theImage theImageWidth theImageHeight RGBA_IMAGE "Pattern Layer" 100 NORMAL) ) )
          (gimp-edit-clear theImage thePattLayer)
          (gimp-image-add-layer theImage thePattLayer 0)

          (set! theBumpLayer (car (gimp-layer-new theImage theImageWidth theImageHeight RGBA_IMAGE "BumpMap Layer 1" 100 NORMAL) ) )
	  (gimp-palette-set-background '(255 255 255))
          (gimp-edit-fill theImage theBumpLayer)
          (gimp-image-add-layer theImage theBumpLayer 2)

          (gimp-selection-layer-alpha theImage theSourceLayer)
          (if (= inFollowShape FALSE)
              (let ( (b (cdr (gimp-selection-bounds theImage))))
                   (gimp-rect-select 	theImage 
                              		(car b) 
					(cadr b) 
					(- (caddr b) (car b)) 
					(- (car (cdddr b)) (cadr b))
					REPLACE
 					FALSE
					0)
              )
              ()
          )
         
	  (gimp-selection-grow theImage theBuffer )

          (if (= inDistressSlab TRUE) 
	     (script-fu-distress-selection theImage theSourceLayer 127 8 4 
                   (if (= inWoodLook TRUE) 8 2) TRUE (if (= inWoodLook TRUE) FALSE TRUE))
             ()
          )
	  (gimp-palette-set-background '(0 0 0))
	  (gimp-edit-fill theImage thePattLayer)
          (gimp-edit-fill theImage theBumpLayer)
          
          (gimp-selection-none theImage)

	  (set! theShadowLayer (car(gimp-layer-copy thePattLayer FALSE)))
          (gimp-layer-set-name theShadowLayer "Shadow")
          (gimp-image-add-layer theImage theShadowLayer 3)

	  (set! thePaintLayer (car(gimp-layer-copy thePattLayer FALSE)))
          (gimp-layer-set-name thePaintLayer "Paint")
          (gimp-image-add-layer theImage thePaintLayer 0)

          (gimp-selection-layer-alpha theImage thePattLayer)
          (gimp-bucket-fill theImage thePattLayer PATTERN-BUCKET-FILL NORMAL 100 0 FALSE 0 0)

          (gimp-selection-none theImage)
	  
          (plug-in-gauss-iir TRUE theImage theShadowLayer 8 TRUE TRUE) 
          (plug-in-autocrop TRUE theImage theShadowLayer)

	  (set! thePaintMask (car(gimp-layer-create-mask thePaintLayer ALPHA-MASK)))
	  (gimp-image-add-layer-mask theImage thePaintLayer thePaintMask)
          (gimp-selection-all theImage)
          (gimp-edit-clear theImage thePaintLayer)
          (gimp-selection-layer-alpha theImage theSourceLayer)
	  (if (= TRUE inGilt)
              (begin 
	         (gimp-palette-set-background '(190 190 0) )
                 (gimp-edit-fill theImage thePaintLayer)
                 (gimp-gradients-set-active "Golden")
                 (gimp-blend theImage thePaintLayer CUSTOM LIGHTEN-ONLY LINEAR 100 0 REPEAT-NONE FALSE 0 0 
        0 0 theImageWidth theImageHeight)       
              )
              (begin
	         (gimp-palette-set-background inPaintColor)
                 (gimp-edit-fill theImage thePaintLayer)
              )
          )
          
   
          (gimp-selection-none theImage)


;(gimp-display-new theImage)) (define fish  ()

          (plug-in-gauss-iir TRUE theImage theSourceLayer 2 TRUE TRUE) 
          (gimp-layer-set-visible theShadowLayer FALSE)
          (gimp-layer-set-visible thePattLayer FALSE)
          (gimp-layer-set-visible thePaintLayer FALSE)
          (set! theBumpLayer (car(gimp-image-merge-visible-layers theImage 0)))
	  (gimp-layer-set-visible theBumpLayer FALSE)
	  (gimp-layer-set-visible thePattLayer TRUE)
	  (gimp-layer-set-visible thePaintLayer TRUE)
          (gimp-layer-set-opacity thePaintLayer (if (= inGilt TRUE) 97 inPaintOpacity))
          (set! thePattLayer (car(gimp-image-merge-visible-layers theImage 0)))
	  (gimp-layer-set-visible theShadowLayer TRUE)

	  (plug-in-bump-map TRUE theImage thePattLayer theBumpLayer 135 45 3 0 0 0 50 TRUE TRUE 1 )

          (gimp-image-remove-layer theImage theBumpLayer)
	  (if (= inBG TRUE)
              (begin
                 (set! theBackground (car (gimp-layer-new theImage theImageWidth theImageHeight RGBA_IMAGE "Background" 100 NORMAL) ) )
                 (gimp-palette-set-background '(255 255 255) )
          	 (gimp-selection-all theImage)
                 (gimp-edit-fill theImage theBackground)
                 (gimp-image-add-layer theImage theBackground 2)
              )
              ()
          )
                  

          (if     (= inFlatten TRUE)
                  (gimp-image-flatten theImage)
                  ()
          )


          (gimp-image-clean-all theImage)


)


; Register the function with the GIMP:

(script-fu-register
    "script-fu-chris-irregular-slab"
    "<Image>/Script-Fu/Stencil Ops/Irregular Slab"
    "Embosses the current image (according to it's alpha) onto an irregularly shaped slab in of the current pattern."
    "Chris Gutteridge"
    "1998, Christopher Gutteridge, ECS Dept. Uni. of Southampton"
    "April 28, 1998"
    "RGBA"
    SF-IMAGE "The Image" 0
    SF-DRAWABLE "The Layer" 0
    SF-TOGGLE "Distress Source?" FALSE
    SF-TOGGLE "Distress Slab?" TRUE
    SF-TOGGLE "Gilt?" TRUE
    SF-COLOR "Paint Color:"   '(0 0 0)
    SF-VALUE "Paint Opacity (%):"   "50"
    SF-VALUE "Buffer amount:" "20"
    SF-TOGGLE "Follow Shape of source?" TRUE
    SF-TOGGLE "Wood Splinter Effect?" FALSE
    SF-TOGGLE "Add a background?" TRUE
    SF-COLOR "Background Color:"   '(255 255 255)
    SF-TOGGLE "Flatten Image?" TRUE
    

)
