a cleaned up version of the script contributed by Kevin Cozens (see bug

2004-10-04  Sven Neumann  <sven@gimp.org>

	* plug-ins/script-fu/scripts/asc2img.scm: a cleaned up version of
	the script contributed by Kevin Cozens (see bug #153900).

	* plug-ins/script-fu/scripts/predator.scm: applied patch by Kevin
	Cozens that fixes use of the script on original layer (bug #152678).
This commit is contained in:
Sven Neumann 2004-10-04 09:02:00 +00:00 committed by Sven Neumann
parent 2119f890d4
commit 97b6636472
3 changed files with 210 additions and 184 deletions

View File

@ -1,3 +1,11 @@
2004-10-04 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/scripts/asc2img.scm: a cleaned up version of
the script contributed by Kevin Cozens (see bug #153900).
* plug-ins/script-fu/scripts/predator.scm: applied patch by Kevin
Cozens that fixes use of the script on original layer (bug #152678).
2004-10-04 Sven Neumann <sven@gimp.org> 2004-10-04 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/scripts/3d-outline.scm * plug-ins/script-fu/scripts/3d-outline.scm

View File

@ -32,17 +32,21 @@
inBackColor inBackColor
inBufferAmount) inBufferAmount)
(set! theImage (car (gimp-image-new 10 10 RGB))) (let* (
(set! theLayer (car (gimp-layer-new theImage (theImage (car (gimp-image-new 10 10 RGB) ) )
(theLayer (car (gimp-layer-new theImage
10 10
10 10
RGBA-IMAGE RGBA-IMAGE
"layer 1" "layer 1"
100 100
NORMAL-MODE))) NORMAL-MODE) ) )
(theImageWidth 0)
(theImageHeight 0)
(theBuffer)
)
(gimp-context-push) (gimp-context-push)
(gimp-context-set-background inBackColor) (gimp-context-set-background inBackColor)
(gimp-drawable-set-name theLayer "Background") (gimp-drawable-set-name theLayer "Background")
(gimp-image-add-layer theImage theLayer 0) (gimp-image-add-layer theImage theLayer 0)
@ -50,34 +54,29 @@
(script-fu-asc-2-img-layer theImage theLayer inFile inFont inFontSize (script-fu-asc-2-img-layer theImage theLayer inFile inFont inFontSize
inTextColor inBufferAmount) inTextColor inBufferAmount)
(set! theBuffer (* inFontSize (/ inBufferAmount 100))) (set! theImageWidth (car (gimp-drawable-width
(set! theImageWidth (+ theImageWidth theBuffer theBuffer)) (car (gimp-image-get-active-layer theImage)))))
(set! theImageHeight (+ theImageHeight theBuffer theBuffer)) (set! theImageHeight (car (gimp-drawable-height
(car (gimp-image-get-active-layer theImage)))))
(set! theBuffer (* inFontSize (/ inBufferAmount 100) ) )
(set! theImageWidth (+ theImageWidth theBuffer theBuffer ))
(set! theImageHeight (+ theImageHeight theBuffer ))
(gimp-image-resize theImage theImageWidth theImageHeight theBuffer theBuffer)
(gimp-layer-resize theLayer theImageWidth theImageHeight theBuffer theBuffer)
(gimp-image-resize theImage
theImageWidth
theImageHeight
theBuffer
theBuffer)
(gimp-layer-resize theLayer
theImageWidth
theImageHeight
theBuffer
theBuffer)
(gimp-selection-all theImage) (gimp-selection-all theImage)
(if (= inTrans TRUE) (if (= inTrans TRUE)
(gimp-edit-clear theLayer) (gimp-edit-clear theLayer)
(gimp-edit-fill theLayer BACKGROUND-FILL)) (gimp-edit-fill theLayer BACKGROUND-FILL)
)
(gimp-selection-none theImage) (gimp-selection-none theImage)
(gimp-display-new theImage) (gimp-display-new theImage)
(gimp-image-clean-all theImage)
(gimp-displays-flush) (gimp-displays-flush)
(gimp-context-pop) (gimp-context-pop)
)
(cons theImage ())
) )
(define (script-fu-asc-2-img-layer inImage (define (script-fu-asc-2-img-layer inImage
@ -87,16 +86,72 @@
inFontSize inFontSize
inTextColor) inTextColor)
(set! theImage inImage) (let* (
(set! theLayer inLayer) (theImage inImage)
(set! theFile (fopen inFile)) (theLayer inLayer)
(theFile (fopen inFile))
(set! otherLayers (cadr (gimp-image-get-layers theImage))) (otherLayers (cadr (gimp-image-get-layers theImage)))
(set! nLayers (car (gimp-image-get-layers theImage))) (nLayers (car (gimp-image-get-layers theImage)))
(set! n nLayers) (n nLayers)
(theImageWidth 0)
(theImageHeight 0)
(theData)
(theIndentList)
(theChar)
(allspaces)
(theIndent)
(theLine)
(theChar)
(theText)
(theCharWidth)
)
(define (cjg-add-text inData inIndentList inFont inFontSize)
(if (equal? () inData)
()
(let (
(theLine (car inData))
(theIndent (car inIndentList))
(theLineHeight 0)
(theText)
)
(if (equal? "" theLine)
()
(begin
(set! theText (car (gimp-text-fontname inImage
-1
0
0
theLine
0
TRUE
inFontSize
PIXELS
inFont)))
(set! theLineHeight (car (gimp-drawable-height theText)))
(gimp-layer-set-offsets theText
(* theCharWidth theIndent)
(+ theImageHeight
(- inFontSize theLineHeight)))
(set! theImageWidth (max
(+ (car (gimp-drawable-width theText))
(* theCharWidth theIndent))
theImageWidth ))
(if (= (car (gimp-layer-is-floating-sel theText)) TRUE)
(gimp-floating-sel-anchor theText)
)
(gimp-drawable-set-name theText theLine)
)
)
(cjg-add-text (cdr inData) (cdr inIndentList) inFont inFontSize)
)
)
)
(gimp-context-push) (gimp-context-push)
(gimp-context-set-foreground inTextColor) (gimp-context-set-foreground inTextColor)
(gimp-selection-none theImage) (gimp-selection-none theImage)
(set! theData ()) (set! theData ())
@ -106,21 +161,25 @@
(set! allspaces TRUE) (set! allspaces TRUE)
(set! theIndent 0) (set! theIndent 0)
(set! theLine "") (set! theLine "")
(while (begin (set! theChar (fread 1 theFile)) (while (begin
(set! theChar (fread 1 theFile))
(and (not (equal? "\n" theChar)) (and (not (equal? "\n" theChar))
(not (equal? () theChar)) (not (equal? () theChar))
) )
) )
(cond ( (equal? theChar "\t") (cond
(
(equal? theChar "\t")
(set! theChar " ") (set! theChar " ")
(if (= allspaces TRUE) (if (= allspaces TRUE)
(set! theIndent (+ theIndent 8)) (set! theIndent (+ theIndent 8))
())
) )
( (equal? theChar " ") )
(
(equal? theChar " ")
(if (= allspaces TRUE) (if (= allspaces TRUE)
(set! theIndent (+ theIndent 1)) (set! theIndent (+ theIndent 1))
()) )
) )
(TRUE (set! allspaces FALSE)) (TRUE (set! allspaces FALSE))
) )
@ -128,15 +187,14 @@
) )
(if (= allspaces TRUE) (if (= allspaces TRUE)
(set! theLine "") (set! theLine "")
()
) )
(if (and (equal? () theChar) (if (and (equal? () theChar)
(equal? "" theLine) (equal? "" theLine)
) )
() ()
(begin (set! theData (cons theLine theData)) (begin
(set! theIndentList (set! theData (cons theLine theData))
(cons theIndent theIndentList)) (set! theIndentList (cons theIndent theIndentList))
) )
) )
) )
@ -151,57 +209,15 @@
inFontSize inFontSize
PIXELS PIXELS
inFont))) inFont)))
(set! theCharWidth (car (gimp-drawable-width theText) )) (set! theCharWidth (car (gimp-drawable-width theText)))
(gimp-edit-cut theText) (gimp-edit-cut theText)
(set! theImageHeight 0) (cjg-add-text (reverse theData) (reverse theIndentList) inFont inFontSize)
(set! theImageWidth 0)
(cjg-add-text (reverse theData)
(reverse theIndentList)
inFont
inFontSize)
(set! n nLayers)
(gimp-displays-flush)
(gimp-context-pop))
(define (cjg-add-text inData inIndentList inFont inFontSize) (gimp-context-pop)
(if (equal? () inData) (gimp-displays-flush)
()
(let ((theLine (car inData)) (theIndent (car inIndentList)))
(if (equal? "" theLine)
()
(begin
(set! theText (car (gimp-text-fontname theImage
-1
0
0
(string-append
" " theLine)
0
TRUE
inFontSize
PIXELS
inFont)))
(set! theLineHeight (car (gimp-drawable-height theText) ) )
(gimp-layer-set-offsets theText
(* theCharWidth theIndent)
(+ theImageHeight
(- inFontSize theLineHeight)))
(set! theImageWidth (max
(+ (car (gimp-drawable-width theText) )
(* theCharWidth theIndent))
theImageWidth ))
(if (= (car (gimp-layer-is-floating-sel theText)) TRUE)
(gimp-floating-sel-anchor theText)
()
)
(gimp-drawable-set-name theText theLine)
)
)
(set! theImageHeight
(+ theImageHeight inFontSize))
(cjg-add-text (cdr inData) (cdr inIndentList) inFont inFontSize)))
) )
)
; Register the function with the GIMP: ; Register the function with the GIMP:
@ -215,14 +231,14 @@
"" ""
SF-FILENAME _"Filename" "afile" SF-FILENAME _"Filename" "afile"
SF-FONT _"Font" "Bitstream Charter" SF-FONT _"Font" "Bitstream Charter"
SF-ADJUSTMENT _"Font Size (pixels)" '(45 2 1000 1 10 0 1) SF-ADJUSTMENT _"Font size (pixels)" '(45 2 1000 1 10 0 1)
SF-COLOR _"Text Color" '(0 0 0) SF-COLOR _"Text color" '(0 0 0)
SF-TOGGLE _"Transparent Background" FALSE SF-TOGGLE _"Transparent background" FALSE
SF-COLOR _"Background Color" '(255 255 255) SF-COLOR _"Background color" '(255 255 255)
SF-ADJUSTMENT _"Buffer Amount (% Height of Text)" '(35 0 100 1 10 0 0) SF-ADJUSTMENT _"Buffer amount (% height of text)" '(35 0 100 1 10 0 0)
) )
(script-fu-register "script-fu-asc-2-img-layer" (script-fu-register "tiny-fu-asc-2-img-layer"
_"<Image>/Script-Fu/Utils/_ASCII to Layer..." _"<Image>/Script-Fu/Utils/_ASCII to Layer..."
"Create a new layer of text from a simple text file" "Create a new layer of text from a simple text file"
"Chris Gutteridge: cjg@ecs.soton.ac.uk" "Chris Gutteridge: cjg@ecs.soton.ac.uk"

View File

@ -84,8 +84,10 @@
(let ((floating-sel (car (gimp-edit-paste effect-layer FALSE)))) (let ((floating-sel (car (gimp-edit-paste effect-layer FALSE))))
(gimp-floating-sel-anchor floating-sel) (gimp-floating-sel-anchor floating-sel)
) )
(gimp-image-set-active-layer image effect-layer ))) (gimp-image-set-active-layer image effect-layer ))
(set! active-layer (car (gimp-image-get-active-layer image))) (set! effect-layer drawable)
)
(set! active-layer effect-layer)
; all the fun stuff goes here ; all the fun stuff goes here
(if (= pixelize TRUE) (if (= pixelize TRUE)