Measuring Fonts - Script Writing - CHDK Forum

Measuring Fonts

  • 3 Replies
  • 2159 Views
Measuring Fonts
« on: 03 / September / 2016, 21:35:46 »
Advertisements
Another weekend, time for a fun CHDK project.  This time I want to add a nice manual mode GUI to my SD1200, just like the expensive SX50 has.  First problem, trying to layout text.  I can't do this without knowing what font is being used, and having some idea of the height of the characters.
Code: [Select]
draw.add("text"...)

uses pixel coordinates, while
Code: [Select]
set_console_layout(...)

is in terms of characters, so there's two different coordinate systems and no way to convert between them,
or to set a specific font or even tell which one is being used, so
The simplest addition, in terms of feature request I can see, it just making the "currect location" available,
in pixels, whcih is updated after a print.  Even better would be a way to get the size of a string in pixels
 before it's displayed.  Then I could really layout text.


« Last Edit: 04 / September / 2016, 00:40:58 by jmac698 »

Re: Measuring Fonts
« Reply #1 on: 03 / September / 2016, 23:29:54 »
Another weekend, time for a fun CHDK project.  This time I want to add a nice manual mode GUI to my SD1200, just like the expensive SX50 has. 
You might be able to find some things in this script that you can use : CHDKplus
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 14033
Re: Measuring Fonts
« Reply #2 on: 04 / September / 2016, 00:21:28 »
I can't do this without knowing what font is being used, and having some idea of the height of the characters.
Code: [Select]
draw.add("text"...)

uses pixel coordinates, while
Code: [Select]
set_console_layout(...)

is in terms of characters, so there's two different coordinate systems and no way to convert between them,
or to set a specific font or even tell which one is being used, so
AFAIK, both console and script draw_string always uses the 8x16 OSD/console font (optionally scaled, for draw_string), not the menu font that you can select. This is a fixed pitch font, so calculating pixel size is trivial.

FWIW, you should be able to get the current menu font using get_config_value, but this is probably not relevant to your problem.
Don't forget what the H stands for.

Re: Measuring Fonts
« Reply #3 on: 04 / September / 2016, 00:40:38 »
Thanks, very helpful answer.  However, upon looking at chdkplus, it has all the features I would want in such a script.
Dealing with layout however, will be useful in the future.


 

Related Topics