Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Font Character Number Viewer

by merrymonk (Hermit)
on Jul 11, 2011 at 08:21 UTC ( [id://913662]=CUFP: print w/replies, xml ) Need Help??

I wanted to use characters from fonts such as Wingdings. To do this I used chr(n) where n is the character number.
To help identify the number for the character I wanted I adapted the font viewer from Mastering Perl TK.
The Perl for this is below in case anyone else wanted a similar thing.
You will find that there is a commented out line for an ‘Entry’ definition near the Mainloop command.
If this comment is removed and one added to the previous line you can see the characters in Entry boxes rather than as labels. I did alter the check box for weight to a pull down that has all the possible options for font weight. These are normal, bold, medium, book, light, demi and demibold.
Not all of these seem to change the characters appearance for all of the fonts.
use Tk; use strict; my (%char_num, $jc, %wg, %wg_res, $jrow, $jcol, $cou); require Tk::BrowseEntry; my $mw = MainWindow->new(-title => 'Font Viewer'); my $f = $mw->Frame->grid(-row => 0, -column => 0); my $family = 'Courier'; $jcol = 0; my $be = $f->BrowseEntry( -label => "Family:", -variable => \$family, -browsecmd => \&apply_font, )->grid(-row => 0, -column => $jcol); $be->insert('end', sort $mw->fontFamilies); $jcol += 1; my $size = 14; my $bentry = $f->BrowseEntry( -label => 'Size', -variable => \$size, -browsecmd => \&apply_font, )->grid(-row => 0, -column => $jcol); $bentry->insert('end', (3 .. 32)); $jcol += 1; my @weight_options = qw (normal bold medium book light demi demibold); my $weight = "normal"; $f->Optionmenu( -variable => \$weight, -options => [@weight_options], -command => \&apply_font, )->grid(-row => 0, -column => $jcol); $jcol += 1; my $slant = "roman"; $f->Checkbutton( -onvalue => "italic", -offvalue => "roman", -text => "Slant", -variable => \$slant, -command => \&apply_font, )->grid(-row => 0, -column => $jcol); $jcol += 1; my $underline = 0; $f->Checkbutton( -text => "Underline", -variable => \$underline, -command => \&apply_font, )->grid(-row => 0, -column => $jcol); $jcol += 1; my $overstrike = 0; $f->Checkbutton( -text => "Overstrike", -variable => \$overstrike, -command => \&apply_font, )->grid(-row => 0, -column => $jcol); #my $stext = "Sample Text"; # set up all characters my $stext = ''; for($jc = 1; $jc <= 255; $jc ++) { $stext .= chr($jc); } # add the lables and entries $jcol = -1; $jrow = 0; my $f2 = $mw->Frame->grid(-row => 1, -column => 0); for($cou = 1; $cou <= 255; $cou ++) { $jcol += 1; if($jcol >= 25) { $jcol = 0; $jrow += 2; } $f2->Label(-text => $cou, -justify => 'center')->grid(-row => $jro +w, -column => $jcol); $wg_res{$cou} = chr($cou); $wg{$cou}= $f2->Label(-text => $wg_res{$cou}, -justify => 'center' +, -bg => 'white')->grid(-row => $jrow+1, -column => $jcol, -padx => 1 +); # $wg{$cou} = $f2->Entry(-textvariable => \$wg_res{$cou}, -width => +3, -justify => 'center')->grid(-row => $jrow + 1, -column => $jcol); } my $sample; &apply_font; MainLoop; sub apply_font { my $jwg; foreach $jwg (sort {$a <=> $b} keys %wg) { $wg{$jwg}->configure(-font => [-family => $family, -size => $size, -weight => $weight, -slant => $slant, -underline => $underline, -overstrike => $overstrike ], ); } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://913662]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-25 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found