An exec. utility to get text width and height in pixels. PIC

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

An exec. utility to get text width and height in pixels. PIC

#1 Post by sunburnt »

### All credit for this utility goes to vovchik who posted the code and helped out at the BaCon forum.

This utility is a life saver for sizing text widgets and their containers and windows.

# With a BaCon label display it can rotate the text and display markup text.

# Very fancy indeed.!

Uses BaCon`s Hug for it`s label widget, so it may not want to work for non-Precise Puppies ( Slacko ).
If I can get more help with it, I`ll use all GTK imports and eliminate Hug. So then it may be more portable.

For help just type: text-size

The caret character "^" is the input separator ( delimiter ).

Code: Select all

Example: text-size ^Many here among us feel that life is but a joke.^Sans Bold 16^0^0
# Figured I ought to show a pic. of what can be done with it. Pretty impressive huh.?

The exec. only calculates the width x height. But additional dialogs can make use of it.

# I could make a text splash dialog like shown here if there`s interest.???
Attachments
text-size_markup_sm.png
Pic of vovchik`s BaCon label dialog that can rotate the text, and uses text-size to get the dialog`s size.
(73.43 KiB) Downloaded 171 times
text-size.gz
(16.63 KiB) Downloaded 220 times
Last edited by sunburnt on Sun 01 Sep 2013, 05:09, edited 1 time in total.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#2 Post by musher0 »

Hi, sunburnt.

Good show!

The graphic equivalent of

Code: Select all

wc -l some.txt
, I suppose?

BFN.

musher0
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#3 Post by sunburnt »

Hi musher; More or less, like:
W=`wc -c some.txt`
H=`wc -l some.txt`

Except in pixels Wide and High instead of Characters and Lines.
I use to use a mono-font and estimate the text length, it worked fairly well...
But now we can get the exact pixel measurements so you can use any font, style, and size.

GtkDialog and all other GUI kits I`ve seen measure in pixels ( screen measurements ).
Average button is 20 to 25 pixels high, so get the text`s Width and Height + 5 or 10 for padding.

Now I`ve made a menu that allows each button to have an individual font, style, and size.
The same could be done in GtkDialog or most other GUI tool kits.
.

Post Reply