File: font-map.scm

package info (click to toggle)
gimp 2.2.13-1etch4
  • links: PTS
  • area: main
  • in suites: etch
  • size: 94,832 kB
  • ctags: 47,113
  • sloc: ansic: 524,858; xml: 36,798; lisp: 9,870; sh: 9,409; makefile: 7,923; python: 2,674; perl: 2,589; yacc: 520; lex: 334
file content (146 lines) | stat: -rw-r--r-- 3,937 bytes parent folder | download | duplicates (3)
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
145
146
;; font-select
;; Spencer Kimball

(define (max-font-width text use-name font-list font-size)
  (let* ((list     font-list)
	 (width    0)
	 (maxwidth 0)
	 (font     "")
	 (extents  '()))
    (while list
	   (set! font (car list))
	   (set! list (cdr list))
	   (if (= use-name TRUE)
	       (set! text font))
	   (set! extents (gimp-text-get-extents-fontname text
							 font-size PIXELS
							 font))
	   (set! width (nth 0 extents))
	   (if (> width maxwidth)
	       (set! maxwidth width)))
    maxwidth))


(define (max-font-height text use-name font-list font-size)
  (let* ((list      font-list)
	 (height    0)
	 (maxheight 0)
	 (font      "")
	 (extents   '()))
    (while list
	   (set! font (car list))
	   (set! list (cdr list))
	   (if (= use-name TRUE)
	       (set! text font))
	   (set! extents (gimp-text-get-extents-fontname text
							 font-size PIXELS
							 font))
	   (set! height (nth 1 extents))
	   (if (> height maxheight)
	       (set! maxheight height)))
    maxheight))


(define (script-fu-font-map text
			    use-name
			    labels
			    font-filter
			    font-size
			    border
			    colors)
  (let* ((font        "")
	 (count       0)
         (font-list  (cadr (gimp-fonts-get-list font-filter)))
	 (num-fonts  (length font-list))
	 (label-size (/ font-size 2))
	 (border     (+ border (* labels (/ label-size 2))))
	 (y           border)
	 (maxheight  (max-font-height text use-name font-list font-size))
	 (maxwidth   (max-font-width  text use-name font-list font-size))
	 (width      (+ maxwidth (* 2 border)))
	 (height     (+ (+ (* maxheight num-fonts) (* 2 border))
			(* labels (* label-size num-fonts))))
	 (img        (car (gimp-image-new width height (if (= colors 0)
							   GRAY RGB))))
	 (drawable   (car (gimp-layer-new img width height (if (= colors 0)
							       GRAY-IMAGE RGB-IMAGE)
					  "Background" 100 NORMAL-MODE)))) 

    (gimp-context-push)

    (gimp-image-undo-disable img)

    (if (= colors 0)
	(begin
	  (gimp-context-set-background '(255 255 255))
	  (gimp-context-set-foreground '(0 0 0))))

    (gimp-image-add-layer img drawable 0)
    (gimp-edit-clear drawable)

    (if (= labels TRUE)
	(begin
	  (set! drawable (car (gimp-layer-new img width height
					      (if (= colors 0)
						  GRAYA-IMAGE RGBA-IMAGE)
					      "Labels" 100 NORMAL-MODE)))
	  (gimp-image-add-layer img drawable -1)))
	  (gimp-edit-clear drawable)

    (while font-list
	   (set! font (car font-list))
	   (set! font-list (cdr font-list))

	   (if (= use-name TRUE)
	       (set! text font))

	   (gimp-text-fontname img -1
			       border
			       y
			       text
			       0 TRUE font-size PIXELS
			       font)

	   (set! y (+ y maxheight))

	   (if (= labels TRUE)
	       (begin
		 (gimp-floating-sel-anchor (car (gimp-text-fontname img drawable
								    (- border
								       (/ label-size 2))
								    (- y
								       (/ label-size 2))
								    font
								    0 TRUE
								    label-size PIXELS
								    "Sans")))
		(set! y (+ y label-size))))


	   (set! count (+ count 1)))

    (gimp-image-set-active-layer img drawable)

    (gimp-image-undo-enable img)
    (gimp-display-new img)

    (gimp-context-pop)))

(script-fu-register "script-fu-font-map"
		    _"_Font Map..."
		    "Generate a listing of fonts matching a filter"
		    "Spencer Kimball"
		    "Spencer Kimball"
		    "1997"
		    ""
		    SF-STRING     _"_Text" "How quickly daft jumping zebras vex."
		    SF-TOGGLE     _"Use font _name as text" FALSE
		    SF-TOGGLE     _"_Labels"                TRUE
		    SF-STRING     _"_Filter (regexp)"       "Sans"
		    SF-ADJUSTMENT _"Font _size (pixels)"    '(32 2 1000 1 10 0 1)
		    SF-ADJUSTMENT _"_Border (pixels)"       '(10 0  200 1 10 0 1)
		    SF-OPTION     _"_Color scheme"          '(_"Black on white"
							      _"Active colors"))

(script-fu-menu-register "script-fu-font-map"
			 _"<Toolbox>/Xtns/Script-Fu/Utils")