LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Calculating window size based on font size & number of characters? (https://www.linuxquestions.org/questions/linux-software-2/calculating-window-size-based-on-font-size-and-number-of-characters-4175541520/)

honest_abe 05-03-2015 05:33 PM

Calculating window size based on font size & number of characters?
 
When specifying a window size, some programs use
--width=
others use
--geometry=
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.

Keith Hedger 05-03-2015 06:30 PM

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.


All times are GMT -5. The time now is 03:54 PM.