A la fin, il y a une ligne de commentaire marqué "Ligne à modifier", suivant
d'une ligne "(clear-modified-flag image)". Commentez/décommentez cette instruction, et voyez la différence. Si vous laissez le flag dirty, la selection seule apparaît décalée, mais si mettez le flag dirty à zéro, le selection ET le texte ensemble sont décalé.
Note : clear-modified-flag est en fait un appel à gimp-image-clean-all
C'est assez surprenant que la manipulation du flag dirty ait de tels effets...
Alors bug ou pas bug ?
; Main steps of a GIMP script :
; Create an image with new-image
; Create a layer with new-layer
; Add a layer into an image with add-layer
; Fix the layer geometry with set-layer-size and set-layer-offset
; You may resize an image to its layers with resize-image-to-layers
; Create a mask with new-mask
; Add a mask into a layer with add-mask
; Initialize a drawable with fill-drawable
; SF-IMAGE
; Integer
; An image id
; Used to get an image id
; SF-DRAWABLE
; Integer
; A drawable id
; Get a drawable id
; SF-VALUE
; String
; "..."
; Input a numeric value
; SF-TOGGLE
; Boolean
; TRUE or FALSE
; Input a booleon value
; SF-PATTERN
; String
; "A pattern name"
; Lets you select a pattern
; SF-ADJUSTMENT
; List
; (start-value min-value max-value small-step large-step [int] [slider])
; Creates a slider bar or a input box with range values
; SF-FILENAME
; String
; "A pathname"
; Lets you browse for the file
; SF-STRING
; String
; "..."
; Creates a input box
; SF-FONT
; String
; "Fontname"
; Lets you select a font
; SF-COLOR
; List
; (red green blue)
; Lets you select a color
; SF-OPTION
; List of strings
; ("..." "..." "...")
; Lets you select an item out of a list
; SF-GRADIENT
; String
; "Gradient name"
; Lets you select a gradient
; ===== Images ===============================================================
; ----------------------------------------------------------------------------
(define
(new-image ; The image is created hidden and without any layers.
width ; 1..262144
height ; 1..262144
type ; { RGB, GRAY, INDEXED }
) ; Returns an image ID.
; See also.
; display-in-new-view, add-layer
(car (gimp-image-new width height type))
)
(define
(display-in-new-view ; Create a new UI display for an image.
image ; The image to display.
) ; Returns a display ID.
(car (gimp-display-new image))
)
(define
(clear-modified-flag
image ; The image to clear on the dirty flag.
) ; Returns nothing.
(gimp-image-clean-all image)
()
)
(define
(set-image-size
image ; The image to apply the size on.
width ; 1..262144
height ; 1..262144
) ; Returns nothing.
(gimp-image-resize image width height 0 0)
; It is not a good idea to have offsetq here, as it may be confusing :
; offset are indeed applyed to image layers, and not to the image.
; An image has not offsets. It is a better idea to explicitly set
; layers offsets.
()
)
(define
(resize-image-to-layers
image ; The image to resize
) ; Returns nothing
(gimp-image-resize-to-layers image)
()
)
(define
(image-width
image ; The drawable to get the width from.
) ; Returns the height (1..262144).
(car (gimp-image-width image))
)
(define
(image-height
image ; The drawable to get the height from.
) ; Returns the height (1..262144).
(car (gimp-image-height image))
)
; ===== Layers ===============================================================
; ----------------------------------------------------------------------------
(define
(new-layer ; The layer is not added to the image.
image ; The image where the layer is to be later added.
width ; 1..262144
height ; 1..262144
type ; See layer types.
name ; A string
opacity ; 0..100
mode ; See layer modes.
) ; Returns a layer ID.
; Layer types.
; RGB-IMAGE, RGBA-IMAGE, GRAY-IMAGE, GRAYA-IMAGE, INDEXED-IMAGE,
; INDEXEDA-IMAGE
; Layer modes.
; NORMAL-MODE, DISSOLVE-MODE, BEHIND-MODE, MULTIPLY-MODE, SCREEN-MODE,
; OVERLAY-MODE, DIFFERENCE-MODE, ADDITION-MODE, SUBTRACT-MODE,
; DARKEN-ONLY-MODE, LIGHTEN-ONLY-MODE, HUE-MODE, SATURATION-MODE,
; COLOR-MODE, VALUE-MODE, DIVIDE-MODE, DODGE-MODE, BURN-MODE,
; HARDLIGHT-MODE, SOFTLIGHT-MODE, GRAIN-EXTRACT-MODE,
; GRAIN-MERGE-MODE, COLOR-ERASE-MODE, ERASE-MODE, REPLACE-MODE,
; ANTI-ERASE-MODE
; Others.
; Offsets are not set there.
; See also.
; add-layer, set-layer-offset
(car (gimp-layer-new image width height type name opacity mode))
)
(define
(add-layer
image ; The image where to add the layer.
layer ; The layer to add.
position ; The desired position in the actual list of image layers.
) ; Returns nothing.
; Notes.
; If the position is -1, the the layer is added above the active
; layer.
(gimp-image-add-layer image layer position)
()
)
(define
(remove-layer
image ; The image from which one to remove the layer.
layer ; The layer to remove.
) ; Returns nothing.
; Notes.
; If the position is -1, the the layer is added above the active
; layer.
(gimp-image-remove-layer image layer)
()
)
(define
(set-layer-size
layer ; The layer to modify the geometry.
width ; 1..262144
height ; 1..262144
) ; Returns nothing.
(gimp-layer-resize layer width height 0 0)
; It is not a good idea to use this offsets, beceause there are
; relatives, and this may be confusing.
()
)
(define
(set-layer-offset
layer ; The layer to be modified.
offset-x ; Offset from left.
offset-y ; offset from top.
) ; Returns nothing.
(gimp-layer-set-offsets layer offset-x offset-y)
()
)
; ===== Masks ================================================================
; ----------------------------------------------------------------------------
(define
(new-mask ; The mask is not added to the layer.
layer ; The layer where the mask is to later be added.
type ; See mask types.
) ; Returns a mask ID.
; Mask types.
; ADD-WHITE-MASK, ADD-BLACK-MASK, ADD-ALPHA-MASK,
; ADD-ALPHA-TRANSFER-MASK, ADD-SELECTION-MASK, ADD-COPY-MASK,
; ADD-CHANNEL-MASK
; See also.
; add-mask
(car (gimp-layer-create-mask layer type))
)
(define
(add-mask
layer ; Layer where to add the mask.
mask ; The mask ID.
) ; Returns nothing.
(gimp-layer-add-mask layer mask)
()
)
; ===== Drawables ============================================================
; ----------------------------------------------------------------------------
(define
(drawable-width
drawable ; The drawable to get the width from.
) ; Returns the width (1..262144).
(car (gimp-drawable-width drawable))
)
(define
(drawable-height
drawable ; The drawable to get the width from.
) ; Returns the height (1..262144).
(car (gimp-drawable-height drawable))
)
(define
(fill-drawable
drawable ; The drawable to fill.
fill-type ; See fill types.
) ; Returns nothing.
; Fill types.
; FOREGROUND-FILL, BACKGROUND-FILL, WHITE-FILL, TRANSPARENT-FILL,
; PATTERN-FILL, NO-FILL
(gimp-drawable-fill drawable fill-type)
()
)
; ===== Texts ================================================================
; ----------------------------------------------------------------------------
(define
(new-floating-text image layer x y text font-name font-size border-size)
(car
(gimp-text-fontname
image
layer
x
y
text
border-size
TRUE
font-size
PIXELS
font-name
)
)
)
(define
(new-text-layer image x y text font-name font-size border-size)
(car
(gimp-text-fontname
image
-1
x
y
text
border-size
TRUE
font-size
PIXELS
font-name
)
)
)
; ===== Context ==============================================================
; ----------------------------------------------------------------------------
(define
(set-default-background-color color)
(gimp-context-set-background color)
)
(define
(set-default-color color)
(gimp-context-set-foreground color)
)
; ============================================================================
; ----------------------------------------------------------------------------
(define
(script-fu-text-box
source-text
font
font-size
color
buffer-amount
)
(let*
(
(width 10) ; largeur initiale
(height 10) ; hauteur initiale
(image (new-image width height RGB))
(layer
(new-layer
image
width
height
RGB-IMAGE
"Layer 1"
100
NORMAL-MODE
)
)
(floating-text) ; un drawable
(text-layer)
(text2)
(buffer)
)
(add-layer image layer 0)
(set-default-background-color (list 255 255 255))
(set-default-color color)
(fill-drawable layer BACKGROUND-FILL)
(set!
floating-text
(new-floating-text image layer 0 0 source-text "Sans" font-size 0)
)
;(set! text-layer (new-text-layer image 0 0 "ABCDEF" "Sans" font-size 0))
(set! width (drawable-width floating-text))
(set! height (drawable-height floating-text))
(set-image-size image width height 0 0)
(set-layer-size layer width height)
(display-in-new-view image)
(set! buffer (* height (/ buffer-amount 100)))
(set! height (+ height buffer buffer))
(set! width (+ width buffer buffer))
(set-layer-offset floating-text buffer buffer)
;Ligne à modifier
;(clear-modified-flag image)
(list image layer floating-text)
)
)
(script-fu-register
"script-fu-text-box" ; func name
"<Toolbox>/Xtns/Script-Fu/Test/Text 2 Box"
"Creates a simple text box, sized to fit\ ; description
around the user's choice of text,\
font, font size, and color."
"Michael Terry" ; author
"copyright 1997, Michael Terry" ; copyright notice
"October 27, 1997" ; date created
"" ; image type accepted
SF-STRING "Text:" "Text Box" ; a string variable
SF-FONT "Font:" "Charter" ; a font variable
SF-ADJUSTMENT "Font size" '(50 1 1000 1 10 0 1)
SF-COLOR "Color:" (list 0 0 0) ; color variable
SF-ADJUSTMENT "Buffer amount" '(35 0 100 1 10 1 0)
)