Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Tiny font

by vr (Curate)
on Sep 27, 2017 at 14:05 UTC ( [id://1200198]=note: print w/replies, xml ) Need Help??


in reply to Tiny font

use strict; use warnings; use utf8; use Imager; my $im = Imager -> new( xsize => 400, ysize => 200 ) -> box( filled => 1, color => 'white' ) -> to_paletted( make_colors => 'mono' ); my $text = 'JORDBÆR PÅ FLØDE (jordbær på fløde)'; my $y = 50; $im-> string( x => 50, y => $y += 25, string => $text, font => $_, color => 'black', size => 16 ) for map { Imager::Font-> new( file => $_, type => 'ft2' ) or die Imager-> errstr } ( 'unifont-10.0.06.ttf', 'ucs-fonts/6x9.bdf', 'ucs-fonts/6x12.bdf', 'ucs-fonts/8x13.bdf', ); $im-> write( file => 'test.png' );

Wikipedia says, the original Unifont was bitmapped font 16 px high. Looks like vectorized to TTF with pixels literally becoming squares (united to rectangles where possible). So rendering, without AA, to any size other than 16, 32, 48, ... will not likely be pretty, especially to smaller sizes (try changing size, above).

You can experiment with other TTF fonts and check if all required (now and in the future ;-) ) glyphs render w/o AA without ugly artifacts at chosen height. It's not totally impossible.

Maybe better go with bitmapped fonts. Note: these are monospaced, + different sizes differ in Unicode coverage. 'Size' parameter appears to be ignored by Imager. + Complex glyphs are also not very beautiful at small sizes.

Replies are listed 'Best First'.
Re^2: Tiny font
by oha (Friar) on Sep 28, 2017 at 06:52 UTC
    Thanks you so much vr, Unifont requires a too big font size, i was hoping to stay between 8 to 12 pixels I found PixelOperator8.ttf as a very good compromise, so let me share my findings in case someone else need it:
    use strict; use warnings; use utf8; use Imager; use Data::Dumper; my $img = Imager->new(xsize=>128, ysize=>8); my $small = Imager::Font->new(file => 'PixelOperator/PixelOperator8.tt +f') or die; $small->align(string => "Færevåg Øst", size => 8, x => 0, y => 0, valign => 'top', image => $img); for (my $y=0; $y<8; $y++) { for (my $x=0; $x<128; $x++) { my $col = $img->getpixel(x=>$x, y=>$y); print [$col->rgba()]->[0] ? "O" : " "; } print "\n"; }
    OOOOO OOO OOO O + O O O O O + O O OOO OOO O OO OOO O O OOO OOOO O OO OOO + OOOO OOO O O O O O O O O O O O O O O O + O O OOOOOOOO OO OOOOO O O OOOO O O OO O OOO + O O O O O O O O O O OOOO O O O + O O OOO OOO O OOO O OOOO O O OOO OOOO + OOO OOO
    It is a very limited subset of unicode, but good enough for my case and i can fall back to unifont with bigger size conditionally. HTH

      Thanks for sharing your results, oha. Author of "PixelOperator8.ttf" has clearly put some effort into his font, so that at 8 px height text looks as good as it possibly ever can, probably. (See some comparisons below.) I just hope these 8 px are not modern display pixels, but something larger.

      Your link is to outdated (and named differently) version, which produces "somewhat" inferior result. Here is better link.

      Below is "screenshot" (produced in a way similar to what you did:

      say $im-> getscanline( y => $_, type => 'index' ) =~ tr/\0\1/O /r for 0 .. $im-> getheight - 1;

      , for "paletted" image 80x60, similar to what I did :) ), for these test subjects:

      '10714/8bitOperatorPlus8-Regular.ttf', # Abomination from wrong link 'pixel_operator/PixelOperator8.ttf', # Correct version 'ucs-fonts/6x12.bdf', # 'Fixed', from my answer above + 'uw-ttyp0-1.3/genbdf/t0-12-uni.bdf', # http://people.mpi-inf.mpg.de/ +~uwe/misc/uw-ttyp0/ 'gohufont-2.1/gohufont-uni-11.pcf', # http://font.gohu.org/

        thank you so much vr, I didn't know about those other fonts and they look way better than the one I found, so great you found the time for this!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1200198]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-28 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found