scripts: Use GimpFont object in Render Font Map

Resolves #11354

Due to improvements in the text API, we have to pass a GimpFont
object as the last parameter of gimp-text-get-extents-font rather
than just a String.
This commit is contained in:
Alx Sa 2024-04-18 23:06:31 +00:00
parent 26e116d9b1
commit e31de151fa

View file

@ -18,19 +18,21 @@
colors) colors)
(define (max-font-width text use-name list-cnt list font-size) (define (max-font-width text use-name list-cnt list font-size)
(let* ((count 0) (let* ((count 0)
(width 0) (width 0)
(maxwidth 0) (maxwidth 0)
(font "") (font "")
(extents '())) (font-object '())
(extents '()))
(while (< count list-cnt) (while (< count list-cnt)
(set! font (car list)) (set! font (car list))
(set! font-object (car (gimp-font-get-by-name font)))
(if (= use-name TRUE) (if (= use-name TRUE)
(set! text font)) (set! text font))
(set! extents (gimp-text-get-extents-font text (set! extents (gimp-text-get-extents-font text
font-size font-size
font)) font-object))
(set! width (car extents)) (set! width (car extents))
(if (> width maxwidth) (if (> width maxwidth)
(set! maxwidth width)) (set! maxwidth width))
@ -44,20 +46,22 @@
) )
(define (max-font-height text use-name list-cnt list font-size) (define (max-font-height text use-name list-cnt list font-size)
(let* ((count 0) (let* ((count 0)
(height 0) (height 0)
(maxheight 0) (maxheight 0)
(font "") (font "")
(extents '())) (font-object '())
(extents '()))
(while (< count list-cnt) (while (< count list-cnt)
(set! font (car list)) (set! font (car list))
(set! font-object (car (gimp-font-get-by-name font)))
(if (= use-name TRUE) (if (= use-name TRUE)
(set! text font) (set! text font)
) )
(set! extents (gimp-text-get-extents-font text (set! extents (gimp-text-get-extents-font text
font-size font-size
font)) font-object))
(set! height (cadr extents)) (set! height (cadr extents))
(if (> height maxheight) (if (> height maxheight)
(set! maxheight height) (set! maxheight height)
@ -74,23 +78,24 @@
(let* ( (let* (
; gimp-fonts-get-list returns a one element list of results, ; gimp-fonts-get-list returns a one element list of results,
; the only element is itself a list of fonts, possibly empty. ; the only element is itself a list of fonts, possibly empty.
(font-list (car (gimp-fonts-get-list font-filter))) (font-list (car (gimp-fonts-get-list font-filter)))
(num-fonts (length font-list)) (num-fonts (length font-list))
(label-size (/ font-size 2)) (label-size (/ font-size 2))
(border (+ border (* labels (/ label-size 2)))) (border (+ border (* labels (/ label-size 2))))
(y border) (y border)
(maxheight (max-font-height text use-name num-fonts font-list font-size)) (maxheight (max-font-height text use-name num-fonts font-list font-size))
(maxwidth (max-font-width text use-name num-fonts font-list font-size)) (maxwidth (max-font-width text use-name num-fonts font-list font-size))
(width (+ maxwidth (* 2 border))) (width (+ maxwidth (* 2 border)))
(height (+ (+ (* maxheight num-fonts) (* 2 border)) (height (+ (+ (* maxheight num-fonts) (* 2 border))
(* labels (* label-size num-fonts)))) (* labels (* label-size num-fonts))))
(img (car (gimp-image-new width height (if (= colors 0) (img (car (gimp-image-new width height (if (= colors 0)
GRAY RGB)))) GRAY RGB))))
(drawable (car (gimp-layer-new img width height (if (= colors 0) (drawable (car (gimp-layer-new img width height (if (= colors 0)
GRAY-IMAGE RGB-IMAGE) GRAY-IMAGE RGB-IMAGE)
"Background" 100 LAYER-MODE-NORMAL))) "Background" 100 LAYER-MODE-NORMAL)))
(count 0) (count 0)
(font "") (font "")
(font-object '())
) )
(gimp-context-push) (gimp-context-push)
@ -116,6 +121,7 @@
(while (< count num-fonts) (while (< count num-fonts)
(set! font (car font-list)) (set! font (car font-list))
(set! font-object (car (gimp-font-get-by-name font)))
(if (= use-name TRUE) (if (= use-name TRUE)
(set! text font)) (set! text font))
@ -125,7 +131,7 @@
y y
text text
0 TRUE font-size 0 TRUE font-size
font) font-object)
(set! y (+ y maxheight)) (set! y (+ y maxheight))
@ -139,7 +145,7 @@
font font
0 TRUE 0 TRUE
label-size label-size
"Sans"))) font-object)))
(set! y (+ y label-size)) (set! y (+ y label-size))
) )
) )