RSS/Atom feed Twitter
Site is read-only, email is disabled

font size

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

2 of 2 messages available
Toggle history

Please log in to manage your subscriptions.

font size paynekj 04 Aug 10:28
  font size saulgoode@flashingtwelve.brickfilms.com 04 Aug 15:49
2010-08-04 10:28:20 UTC (over 14 years ago)
postings
16

font size

I'm trying to write a script to create text layers using the currently selected font.

Using the standard PDB procedures: gimp-text-fontname, gimp-text-layer-new, and the deprecated gimp-text, I need to supply a font name and size.

The currently active font name I can get using gimp-context-get-font, but I can't find anything to get the currently active font size.

Is it possible to get the current font size, or to create a text layer without having to specify a font size?

saulgoode@flashingtwelve.brickfilms.com
2010-08-04 15:49:54 UTC (over 14 years ago)

font size

Quoting Kevin :

I'm trying to write a script to create text layers using the currently selected font.
:
:
Is it possible to get the current font size, or to create a text layer without having to specify a font size?

Not to my knowledge.

If your ultimate goal is to fit text within a certain area -- for example sizing a label to fit on a button -- then you might find the following function useful for determining your font size. It's not pretty (but it works).

The fontsize% argument is a percentage value that allows you to effectively specify a "padding" around the text. For example, 100% means determine the largest fontsize possible such that the text will fit within the boundaries. Note that most fonts already include some padding around the characters (so you might find a value larger than 100 desirable).

Example: (set! fontsize (calc-fontsize "Hello" "Sans" 80 60 20))

============================================ (define (calc-fontsize text font fontsize% width height) (let* (
(fontsize 6) ;; minimum possible fontsize (extents nil)
(last-extents nil)
(last-fontsize 3)
(adjust 2)
)
(set! extents (gimp-text-get-extents-fontname text fontsize PIXELS font))
(set! width (* width fontsize% 0.01)) (set! height (* height fontsize% 0.01)) (while (and (<> last-fontsize fontsize) (not (equal? extents last-extents)))
(if (or (> (car extents) width) (> (cadr extents) height)) (begin
(set! fontsize last-fontsize) (set! adjust (+ (* (- adjust 1) 0.5) 1)) )
(begin
(set! last-extents extents) (set! last-fontsize fontsize) )
)
(set! fontsize (truncate (* fontsize adjust))) (set! extents (gimp-text-get-extents-fontname text fontsize PIXELS font))
)
(max fontsize 6)
)
)