Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 05-03-2015, 06:33 PM   #1
LQ Newbie
Registered: Apr 2015
Posts: 20

Rep: Reputation: Disabled
Calculating window size based on font size & number of characters?

When specifying a window size, some programs use
others use
but in either case, I would like to make a text window be set to cover the longest line of the text. Now the longest line can be calculated. Given that I know he font size (say Courier 18 or Monospace 20), does anyone know a formula that would tell me the window width based on line length and font size?

Similarly, window height based on number of lines and font size?

Of course, I'd have to add some for anything else the window displays but those should be fixed.

For my program, this will apply to yad windows.
Old 05-03-2015, 07:30 PM   #2
Keith Hedger
Senior Member
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 3,103

Rep: Reputation: 836Reputation: 836Reputation: 836Reputation: 836Reputation: 836Reputation: 836Reputation: 836
calculating the width is not just a case of knowing the font size as different fonts will have different widths for the characters, and the same string in the same fontsize will give different widths for different fonts, you will need to examine the font metrics, how you do this will depend on what programming language you are using and probably also what gui toolkit you are using, without the answer to both of those questions you are only going to get general answers like this.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change window size ... to an exact number Skaperen Linux - Desktop 8 05-04-2012 11:14 PM
Inactive window font size & Webpage fonts Norwood Linux - Newbie 1 03-02-2010 03:57 PM
How do I limit the smallest font size to make characters at least recognizable timyang Linux - Desktop 2 09-08-2008 02:41 PM
change font size in terminal window homerjpbody Linux - Newbie 3 08-08-2008 10:26 PM
change font(size) for GTK based applications? the_low Linux - Newbie 2 08-03-2005 04:49 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:09 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration