~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/script-fu/scripts/font-map.scm

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
;; font-select
2
2
;; Spencer Kimball
3
3
 
4
 
(define (max-font-width text use-name font-list font-size)
5
 
  (let* ((list     font-list)
6
 
         (width    0)
7
 
         (maxwidth 0)
8
 
         (font     "")
9
 
         (extents  '()))
10
 
    (while list
11
 
           (set! font (car list))
12
 
           (set! list (cdr list))
13
 
           (if (= use-name TRUE)
14
 
               (set! text font))
15
 
           (set! extents (gimp-text-get-extents-fontname text
16
 
                                                         font-size PIXELS
17
 
                                                         font))
18
 
           (set! width (nth 0 extents))
19
 
           (if (> width maxwidth)
20
 
               (set! maxwidth width)))
21
 
    maxwidth))
22
 
 
23
 
 
24
 
(define (max-font-height text use-name font-list font-size)
25
 
  (let* ((list      font-list)
26
 
         (height    0)
27
 
         (maxheight 0)
28
 
         (font      "")
29
 
         (extents   '()))
30
 
    (while list
31
 
           (set! font (car list))
32
 
           (set! list (cdr list))
33
 
           (if (= use-name TRUE)
34
 
               (set! text font))
35
 
           (set! extents (gimp-text-get-extents-fontname text
36
 
                                                         font-size PIXELS
37
 
                                                         font))
38
 
           (set! height (nth 1 extents))
39
 
           (if (> height maxheight)
40
 
               (set! maxheight height)))
41
 
    maxheight))
42
 
 
43
 
 
44
4
(define (script-fu-font-map text
45
 
                            use-name
46
 
                            labels
47
 
                            font-filter
48
 
                            font-size
49
 
                            border
50
 
                            colors)
51
 
  (let* ((font        "")
52
 
         (count       0)
53
 
         (font-list  (cadr (gimp-fonts-get-list font-filter)))
54
 
         (num-fonts  (length font-list))
55
 
         (label-size (/ font-size 2))
56
 
         (border     (+ border (* labels (/ label-size 2))))
57
 
         (y           border)
58
 
         (maxheight  (max-font-height text use-name font-list font-size))
59
 
         (maxwidth   (max-font-width  text use-name font-list font-size))
60
 
         (width      (+ maxwidth (* 2 border)))
61
 
         (height     (+ (+ (* maxheight num-fonts) (* 2 border))
62
 
                        (* labels (* label-size num-fonts))))
63
 
         (img        (car (gimp-image-new width height (if (= colors 0)
64
 
                                                           GRAY RGB))))
65
 
         (drawable   (car (gimp-layer-new img width height (if (= colors 0)
66
 
                                                               GRAY-IMAGE RGB-IMAGE)
67
 
                                          "Background" 100 NORMAL-MODE)))) 
 
5
                            use-name
 
6
                            labels
 
7
                            font-filter
 
8
                            font-size
 
9
                            border
 
10
                            colors)
 
11
 
 
12
  (define (max-font-width text use-name list-cnt list font-size)
 
13
    (let* ((count    0)
 
14
           (width    0)
 
15
           (maxwidth 0)
 
16
           (font     "")
 
17
           (extents  '()))
 
18
      (while (< count list-cnt)
 
19
        (set! font (aref list count))
 
20
 
 
21
        (if (= use-name TRUE)
 
22
            (set! text font))
 
23
        (set! extents (gimp-text-get-extents-fontname text
 
24
                                                      font-size PIXELS
 
25
                                                      font))
 
26
        (set! width (car extents))
 
27
        (if (> width maxwidth)
 
28
            (set! maxwidth width))
 
29
 
 
30
        (set! count (+ count 1))
 
31
      )
 
32
 
 
33
      maxwidth
 
34
    )
 
35
  )
 
36
 
 
37
  (define (max-font-height text use-name list-cnt list font-size)
 
38
    (let* ((count     0)
 
39
           (height    0)
 
40
           (maxheight 0)
 
41
           (font      "")
 
42
           (extents   '()))
 
43
      (while (< count list-cnt)
 
44
        (set! font (aref list count))
 
45
 
 
46
        (if (= use-name TRUE)
 
47
            (set! text font)
 
48
        )
 
49
        (set! extents (gimp-text-get-extents-fontname text
 
50
                                                      font-size PIXELS
 
51
                                                      font))
 
52
        (set! height (cadr extents))
 
53
        (if (> height maxheight)
 
54
            (set! maxheight height)
 
55
        )
 
56
 
 
57
        (set! count (+ count 1))
 
58
      )
 
59
 
 
60
      maxheight
 
61
    )
 
62
  )
 
63
 
 
64
  (let* (
 
65
        (font-data  (gimp-fonts-get-list font-filter))
 
66
        (font-list  (cadr font-data))
 
67
        (num-fonts  (car font-data))
 
68
        (label-size (/ font-size 2))
 
69
        (border     (+ border (* labels (/ label-size 2))))
 
70
        (y          border)
 
71
        (maxheight  (max-font-height text use-name num-fonts font-list font-size))
 
72
        (maxwidth   (max-font-width  text use-name num-fonts font-list font-size))
 
73
        (width      (+ maxwidth (* 2 border)))
 
74
        (height     (+ (+ (* maxheight num-fonts) (* 2 border))
 
75
                       (* labels (* label-size num-fonts))))
 
76
        (img        (car (gimp-image-new width height (if (= colors 0)
 
77
                                                          GRAY RGB))))
 
78
        (drawable   (car (gimp-layer-new img width height (if (= colors 0)
 
79
                                                              GRAY-IMAGE RGB-IMAGE)
 
80
                                         "Background" 100 NORMAL-MODE)))
 
81
        (count      0)
 
82
        (font)
 
83
        )
68
84
 
69
85
    (gimp-context-push)
70
86
 
71
87
    (gimp-image-undo-disable img)
72
88
 
73
89
    (if (= colors 0)
74
 
        (begin
75
 
          (gimp-context-set-background '(255 255 255))
76
 
          (gimp-context-set-foreground '(0 0 0))))
 
90
        (begin
 
91
          (gimp-context-set-background '(255 255 255))
 
92
          (gimp-context-set-foreground '(0 0 0))))
77
93
 
78
94
    (gimp-image-add-layer img drawable 0)
79
95
    (gimp-edit-clear drawable)
80
96
 
81
97
    (if (= labels TRUE)
82
 
        (begin
83
 
          (set! drawable (car (gimp-layer-new img width height
84
 
                                              (if (= colors 0)
85
 
                                                  GRAYA-IMAGE RGBA-IMAGE)
86
 
                                              "Labels" 100 NORMAL-MODE)))
87
 
          (gimp-image-add-layer img drawable -1)))
88
 
          (gimp-edit-clear drawable)
89
 
 
90
 
    (while font-list
91
 
           (set! font (car font-list))
92
 
           (set! font-list (cdr font-list))
93
 
 
94
 
           (if (= use-name TRUE)
95
 
               (set! text font))
96
 
 
97
 
           (gimp-text-fontname img -1
98
 
                               border
99
 
                               y
100
 
                               text
101
 
                               0 TRUE font-size PIXELS
102
 
                               font)
103
 
 
104
 
           (set! y (+ y maxheight))
105
 
 
106
 
           (if (= labels TRUE)
107
 
               (begin
108
 
                 (gimp-floating-sel-anchor (car (gimp-text-fontname img drawable
109
 
                                                                    (- border
110
 
                                                                       (/ label-size 2))
111
 
                                                                    (- y
112
 
                                                                       (/ label-size 2))
113
 
                                                                    font
114
 
                                                                    0 TRUE
115
 
                                                                    label-size PIXELS
116
 
                                                                    "Sans")))
117
 
                (set! y (+ y label-size))))
118
 
 
119
 
 
120
 
           (set! count (+ count 1)))
 
98
        (begin
 
99
          (set! drawable (car (gimp-layer-new img width height
 
100
                                              (if (= colors 0)
 
101
                                                  GRAYA-IMAGE RGBA-IMAGE)
 
102
                                              "Labels" 100 NORMAL-MODE)))
 
103
          (gimp-image-add-layer img drawable -1)))
 
104
          (gimp-edit-clear drawable)
 
105
 
 
106
    (while (< count num-fonts)
 
107
      (set! font (aref font-list count))
 
108
 
 
109
      (if (= use-name TRUE)
 
110
          (set! text font))
 
111
 
 
112
      (gimp-text-fontname img -1
 
113
                          border
 
114
                          y
 
115
                          text
 
116
                          0 TRUE font-size PIXELS
 
117
                          font)
 
118
 
 
119
      (set! y (+ y maxheight))
 
120
 
 
121
      (if (= labels TRUE)
 
122
          (begin
 
123
            (gimp-floating-sel-anchor (car (gimp-text-fontname img drawable
 
124
                                                               (- border
 
125
                                                                  (/ label-size 2))
 
126
                                                               (- y
 
127
                                                                  (/ label-size 2))
 
128
                                                               font
 
129
                                                               0 TRUE
 
130
                                                               label-size PIXELS
 
131
                                                               "Sans")))
 
132
          (set! y (+ y label-size))
 
133
          )
 
134
      )
 
135
 
 
136
      (set! count (+ count 1))
 
137
    )
121
138
 
122
139
    (gimp-image-set-active-layer img drawable)
123
140
 
124
141
    (gimp-image-undo-enable img)
125
142
    (gimp-display-new img)
126
143
 
127
 
    (gimp-context-pop)))
 
144
    (gimp-context-pop)
 
145
  )
 
146
)
128
147
 
129
148
(script-fu-register "script-fu-font-map"
130
 
                    _"_Font Map..."
131
 
                    "Generate a listing of fonts matching a filter"
132
 
                    "Spencer Kimball"
133
 
                    "Spencer Kimball"
134
 
                    "1997"
135
 
                    ""
136
 
                    SF-STRING     _"_Text" "How quickly daft jumping zebras vex."
137
 
                    SF-TOGGLE     _"Use font _name as text" FALSE
138
 
                    SF-TOGGLE     _"_Labels"                TRUE
139
 
                    SF-STRING     _"_Filter (regexp)"       "Sans"
140
 
                    SF-ADJUSTMENT _"Font _size (pixels)"    '(32 2 1000 1 10 0 1)
141
 
                    SF-ADJUSTMENT _"_Border (pixels)"       '(10 0  200 1 10 0 1)
142
 
                    SF-OPTION     _"_Color scheme"          '(_"Black on white"
143
 
                                                              _"Active colors"))
 
149
  _"Render _Font Map..."
 
150
  _"Create an image filled with previews of fonts matching a fontname filter"
 
151
  "Spencer Kimball"
 
152
  "Spencer Kimball"
 
153
  "1997"
 
154
  ""
 
155
  SF-STRING     _"_Text"                  "How quickly daft jumping zebras vex."
 
156
  SF-TOGGLE     _"Use font _name as text" FALSE
 
157
  SF-TOGGLE     _"_Labels"                TRUE
 
158
  SF-STRING     _"_Filter (regexp)"       "Sans"
 
159
  SF-ADJUSTMENT _"Font _size (pixels)"    '(32 2 1000 1 10 0 1)
 
160
  SF-ADJUSTMENT _"_Border (pixels)"       '(10 0  200 1 10 0 1)
 
161
  SF-OPTION     _"_Color scheme"          '(_"Black on white" _"Active colors")
 
162
)
144
163
 
145
164
(script-fu-menu-register "script-fu-font-map"
146
 
                         _"<Toolbox>/Xtns/Script-Fu/Utils")
 
165
                         "<Fonts>")