big fonts for CHDK

  • 41 Replies
  • 4553 Views
big fonts for CHDK
« on: 30 / October / 2013, 23:19:42 »
Advertisements
From time to time while writing scripts,  I've found myself wishing for a way to display text on the camera's LCD in a larger font.  Something that can be read from several feet away ( at least ).  It doesn't take a lot of imagination to find situations where this could be very useful.

I took a look at the underlying code for the Lua text display function  draw_string() and quickly came to the conclusion that the code was not written with any thought to allowing the user to specify fonts or font sizes.  Changing that looks like a really big job !

So I decide to write a Q&D  (quick & dirty) routine to let you display text in various font sizes.  I ended up with a C language patch file for the existing CHDK trunk and a Lua-only routine to do much the same thing.  I'll admit right here that my code does not let you specify the font face and it does not do proportional spacing, kerning, decenders, font hinting, anti-aliasing, or anything else fancy.   Its just a way to put up a BIG message on the screen for those situations where you really need a big message - ugly fonts or otherwise.  The image below show the displayed text in various user specified font sizes and colors.



The new function is called draw_big_chars( xpos, ypos , text_string , fg_color , bg_color , font_size ).

Code: [Select]
        draw_big_chars( 45, 15,"SMALL",258,259, 1)
        draw_big_chars( 25, 30,"MEDIUM",271,266, 6)
        draw_big_chars( 35, 90,"BIG",270,262, 12)
The attached zip file has a patch file to add code to Lua to make this a built-in function,  a test script for that new function,  and it also has a Lua only version of the function that will work with any current version of CHDK.

Can this be improved? Absolutely!  But working code is 100x better than good intentions so I'll post it here for anyone to enjoy.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline philmoz

  • *****
  • 3070
    • Photos
Re: big fonts for CHDK
« Reply #1 on: 31 / October / 2013, 05:28:16 »
Here's a version that uses the built-in font data instead of adding another font.
This also has the advantage of supporting all the special and non-english characters already in the built-in font.

I've added an optional 7th parameter that allows the Y scale to be set separately, if not included it defaults to the 6th parameter.

The built in font is 8x16 so if you set the vertical scale to 1/2 the horizontal scale you get same size characters on screen as your original patch.
Or you can do funky stuff like tall skinny characters or short fat ones :)

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)

Re: big fonts for CHDK
« Reply #2 on: 31 / October / 2013, 05:28:26 »
That's very good idea!

But wouldn't it be better just add such functions to drawings module, instead of pushing them to lua itself? Just a suggestion.
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

*

Offline msl

  • *****
  • 1237
  • A720 IS, SX220 HS 1.01a
    • CHDK inside
Re: big fonts for CHDK
« Reply #3 on: 31 / October / 2013, 08:21:01 »
Very interesting idea. I also think, it's better to add this function  to the draw functions modul.

There are also a few suggestions in the SDM source code: http://trac.assembla.com/chdkde/browser/branches/SDM/core/draw_palette.c#L411

But working code is 100x better than good intentions so I'll post it here for anyone to enjoy.


msl
German CHDK pages:  CHDK forum | CHDK inside | CHDK Twitter News by msl | Download CHDK-DE (Autobuild)
Note: SDM violates the GPL rules!


Re: big fonts for CHDK
« Reply #4 on: 31 / October / 2013, 08:40:25 »
I decide to write a Q&D  (quick & dirty) routine to let you display text in various font sizes.

SDM 1.86 Beta does of course already fully support this.

Quote
There are also a few suggestions in the SDM source code: http://trac.assembla.com/chdkde/browser/branches/SDM/core/draw_palette.c#L411

Although that function still exists it is now redundant.

As far as I am concerned, SDM 1.86 Beta testing is now completed.
I will next update the documentation, then clean-up the code and finally an official release.

These days, because of the extreme selfishness and laziness of testers, this will not be a top priority for me.

I have photography to do instead.

Re: big fonts for CHDK
« Reply #5 on: 31 / October / 2013, 09:21:22 »
Another little Lua script to exercise philmoz's  version :

Code: [Select]
--[[
         @title Big Font
--]]
stretch = 4
for size= 1, 10 do
    for count = 0, 10 do
        draw_big_chars( 1, 20,"ABC",258,259, size , stretch)
        sleep(100)
    end
    if ( size ==4 ) then stretch=3 end
end
Fonts look much nicer his way.
« Last Edit: 31 / October / 2013, 09:50:44 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

Re: big fonts for CHDK
« Reply #6 on: 31 / October / 2013, 09:25:22 »
Here's a version that uses the built-in font data instead of adding another font.
As I said in my original post,  mine was Q&D.  This is much better.

But wouldn't it be better just add such functions to drawings module, instead of pushing them to lua itself?
I wrote it in C originally thinking of a patch to the svn.   Then I realized I could code it in Lua and did so, wondering if there would be a noticeable speed difference.  From what I could actually see,  the Lua version worked just as well. 

Putting it into the drawing module is probably the best way to avoid increasing the size of the installed CHDK image if the script doesn't need/use the function.  However,  I don't believe that would allow philmoz's trick of using the currently installed font - which has much more resolution than the font file I found online.

Update : maybe a good compromise is a small Lua function that just returns the address of the current font bitmap so that the rest of the code can be in the drawing module?
« Last Edit: 31 / October / 2013, 09:52:12 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline philmoz

  • *****
  • 3070
    • Photos
Re: big fonts for CHDK
« Reply #7 on: 31 / October / 2013, 14:57:05 »
Putting it into the drawing module is probably the best way to avoid increasing the size of the installed CHDK image if the script doesn't need/use the function.  However,  I don't believe that would allow philmoz's trick of using the currently installed font - which has much more resolution than the font file I found online.

Update : maybe a good compromise is a small Lua function that just returns the address of the current font bitmap so that the rest of the code can be in the drawing module?

I think outslider and msl meant to put the function in gui_draw.c rather than luascript.c
By using the built-in font the function becomes quite small so it won't add much to the core CHDK size.

I'd suggest adding two new functions to gui_draw.c - 'draw_char_scaled' and 'draw_string_scaled' to be consistent with the current draw_char and draw_string functions.

Note: this will still only use the built-in font, it won't allow scaled rendering of the RBF fonts.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)


Re: big fonts for CHDK
« Reply #8 on: 31 / October / 2013, 15:08:09 »
I think outslider and msl meant to put the function in gui_draw.c rather than luascript.c
I'm not sure that you are correct (outslider wrote the drawings.lua module after all) but regardless,  it could go into drawings.lua in the CHDK/LUALIB SD card folder.   Having said that,  my personal preference would be to build it in as you suggest.

Quote
By using the built-in font the function becomes quite small so it won't add much to the core CHDK size.
I'd suggest adding two new functions to gui_draw.c - 'draw_char_scaled' and 'draw_string_scaled' to be consistent with the current draw_char and draw_string functions.
I played with a uBASIC function to do this as well but quit when I got the Lua version working.  Even though uBASIC string handling is pretty much limited to the print function,  it could still be useful.

Quote
Note: this will still only use the built-in font, it won't allow scaled rendering of the RBF fonts.
I think we can live with that.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline msl

  • *****
  • 1237
  • A720 IS, SX220 HS 1.01a
    • CHDK inside
Re: big fonts for CHDK
« Reply #9 on: 31 / October / 2013, 16:04:33 »
... msl meant to put the function in gui_draw.c rather than luascript.c
That is correct. So we can use this function for other GUI applications. People ask me very often whether it is possible to represent CHDK OSD text elements greater?

msl
German CHDK pages:  CHDK forum | CHDK inside | CHDK Twitter News by msl | Download CHDK-DE (Autobuild)
Note: SDM violates the GPL rules!

 

Related Topics