Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display all font file characters

I'm wondering if there is a way to display all font file characters using HTML/CSS/JS/PHP?

Let's say I would like to display all possible "Arial" characters. Or characters from custom @font-face font.

like image 348
Atadj Avatar asked Sep 28 '12 12:09

Atadj


People also ask

How do I see all the characters in a font file?

Windows' Character Map (found in the Programs > Accessories > System Tools menu) shows all the characters in a font in the form of a scrollable grid.

How do I see all font glyphs on Mac?

To access glyphs on a Mac, go to the Finder, Click Applications and then scroll to find the Font Book. Open the Font Book and click on the Font that you want to use. Then scroll and find the glyph you want to use.


2 Answers

Fonts can map a wide range of Unicode characters, using codes from 0 to 0x10FFFF. Thus if you really want to see everything in any random font, doing it in a loop as has been suggested in other answers is really going to be problematic. Even for the "simple" example of Arial, the lowest mapped character is U+0020 and the highest is U+FB02. Not everything in that range is mapped, however, so if you did that in a loop you'd end up with a lot of empties. Not to mention it would likely be pretty slow.

To do what you want effectively, you're going to need something to crack open the font file, examine the cmap table, and get a list of mapped characters (not a range). I'm not sure what your setup is, but you could probably do this server-side with something like FreeType or some such.

like image 100
djangodude Avatar answered Oct 23 '22 14:10

djangodude


I would like to suggest you try GD library imagettftext() function. Example from manual:

// Set the content-type
header('Content-Type: image/png');

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The string with character sets
for($i=0; $i<256; $i++){ 
     $text.= chr($i); 
} 

// Replace path by your own font path
$font = 'arial.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
like image 24
chridam Avatar answered Oct 23 '22 16:10

chridam