-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvanced-text-box.scm
144 lines (138 loc) · 5.58 KB
/
advanced-text-box.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
(script-fu-register
"script-fu-advanced-text-box" ;function name
"Advanced Text Box" ;menu label
"Creates a simple text box, sized to fit\
around the user's choice of text,\
font, font size, and color." ;description
"Michael Terry" ;author
"copyright 1997, Michael Terry;\
2009, the GIMP Documentation Team" ;copyright notice
"October 27, 1997" ;date created
"" ;image type that the script works on
SF-TEXT "Text" "Advanced\nText Box" ;a string variable
SF-FONT "Font" "Charter" ;a font variable
SF-ADJUSTMENT "Font size" '(150 1 1000 1 10 0 0)
SF-COLOR "Color" '(0 0 0) ;color variable
SF-OPTION _"Text Justification" '("Centered" "Left" "Right" "Fill")
SF-ADJUSTMENT "Letter Spacing" '(0 -50 50 1 5 0 0)
SF-ADJUSTMENT "Line Spacing" '(-5 -300 300 1 10 0 0)
SF-ADJUSTMENT _"Shrink / Grow Text" '(0 -20 20 1 10 0 0)
SF-ADJUSTMENT _"Outline" '(0 0 20 1 10 0 0)
;a spin-button
SF-ADJUSTMENT "Buffer amount" '(35 0 100 1 10 1 0)
;a slider
)
(script-fu-menu-register "script-fu-advanced-text-box" "<Image>/File/Create/Text")
(define (script-fu-advanced-text-box inText inFont inFontSize inTextColor
justification
letter-spacing
line-spacing
grow-text
outline
inBufferAmount)
(let*
(
; define our local variables
; create a new image:
(theImageWidth 10)
(theImageHeight 10)
(theImage)
(theImage
(car
(gimp-image-new
theImageWidth
theImageHeight
RGB
)
)
)
(theText) ;a declaration for the text
(theBuffer) ;create a new layer for the image
(theLayer
(car
(gimp-layer-new
theImage
theImageWidth
theImageHeight
RGB-IMAGE
"layer 1"
100
LAYER-MODE-NORMAL
)
)
)
(justification (cond ((= justification 0) 2)
((= justification 1) 0)
((= justification 2) 1)
((= justification 3) 3)))
) ;end of our local variables
(gimp-image-insert-layer theImage theLayer 0 0)
(gimp-context-set-background '(255 255 255) )
(gimp-context-set-foreground inTextColor)
(gimp-drawable-fill theLayer FILL-BACKGROUND)
(set! theText
(if (= (string->number (substring (car(gimp-version)) 0 3)) 2.10)
(car
(gimp-text-fontname
theImage theLayer
0 0
inText
0
TRUE
inFontSize PIXELS
inFont)
)
(car
(gimp-text-font
theImage theLayer
0 0
inText
0
TRUE
inFontSize
inFont)
))
)
;; text alignment
(gimp-text-layer-set-justification theText justification) ; Text Justification (Rev Value)
(gimp-text-layer-set-letter-spacing theText letter-spacing) ; Set Letter Spacing
(gimp-text-layer-set-line-spacing theText line-spacing) ; Set Line Spacing
(set! theImageWidth (car (gimp-drawable-get-width theText) ) )
(set! theImageHeight (car (gimp-drawable-get-height theText) ) )
(set! theBuffer (* theImageHeight (/ inBufferAmount 100) ) )
(set! theImageHeight (+ theImageHeight theBuffer theBuffer) )
(set! theImageWidth (+ theImageWidth theBuffer theBuffer) )
(gimp-image-resize theImage theImageWidth theImageHeight 0 0)
(gimp-layer-resize theLayer theImageWidth theImageHeight 0 0)
(gimp-layer-set-offsets theText theBuffer theBuffer)
(gimp-floating-sel-to-layer theText)
(gimp-layer-resize-to-image-size theText)
;;;; shrink grow text
(cond ((> grow-text 0)
(gimp-selection-none theImage)
(gimp-image-select-item theImage 2 theText)
(gimp-selection-grow theImage (round grow-text))
(gimp-context-set-foreground inTextColor)
(gimp-drawable-edit-fill theText FILL-FOREGROUND)
)
((< grow-text 0)
(gimp-selection-none theImage)
(gimp-image-select-item theImage 2 theText)
(gimp-drawable-edit-clear theText)
(gimp-selection-shrink theImage (- grow-text))
(gimp-context-set-foreground inTextColor)
(gimp-drawable-edit-fill theText FILL-FOREGROUND)
))
;;; outline
(cond ((> outline 0)
(gimp-selection-none theImage)
(gimp-image-select-item theImage 2 theText)
(gimp-selection-shrink theImage (round outline))
(gimp-drawable-edit-clear theText)
(gimp-image-select-item theImage 2 theText)
))
; (gimp-image-resize-to-layers theImage)
(gimp-display-new theImage)
(list theImage theLayer theText)
)
)