File: glyphlist.php

package info (click to toggle)
php-ps 1.4.4%2B1.3.7-7
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 2,392 kB
  • sloc: ansic: 3,852; php: 1,628; xml: 667; makefile: 1
file content (105 lines) | stat: -rw-r--r-- 3,216 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php

function usage() {
	printf("Usage: glyphlist <list of fontnames>\n\n");
}

$ps = ps_new();

if (!ps_open_file($ps, "glyphlist.ps")) {
	print "Cannot open PostScript file\n";
	exit;
}


ps_set_info($ps, "Creator", "glyphlist.php");
ps_set_info($ps, "Author", "Uwe Steinmann");
ps_set_info($ps, "Title", "List of glyphs");
ps_set_info($ps, "Keywords", "glyph, font");
ps_set_info($ps, "BoundingBox", "0 0 596 842");

$colwidth = 30;
$rowheight = 30;
$leftmargin = 70;
$bottommargin = 270;
$fontsize = 10.0;
$fontsamplesize = 14.0;

if($_SERVER["argc"] < 2) {
	usage();
	exit(1);
}

$psfont = ps_findfont($ps, "Helvetica", "", 0);
printf("Creating %d pages\n", $_SERVER["argc"]-1);
for($k=1; $k<$_SERVER["argc"]; $k++) {
	printf("Creating page for %s\n", $_SERVER["argv"][$k]);

	$samplefont = ps_findfont($ps, $_SERVER["argv"][$k], "", 1);

	if($glyphlist = ps_glyph_list($ps, $samplefont)) {
		$listlen = count($glyphlist);
		printf("Font has %d glyphs\n", $listlen);
		$pages = (int) ($listlen / 256) + 1;

		$glc = 0;
		for($p=0; $p<$pages; $p++) {
			ps_begin_page($ps, 596, 842);
			for($i=0; $i<=16; $i++) {
				ps_moveto($ps, $leftmargin+$i*$colwidth, $bottommargin);
				ps_lineto($ps, $leftmargin+$i*$colwidth, $bottommargin+16*$rowheight);
				ps_stroke($ps);
			}
			for($j=0; $j<=16; $j++) {
				ps_moveto($ps, $leftmargin, $bottommargin+$j*$rowheight);
				ps_lineto($ps, $leftmargin+16*$colwidth, $bottommargin+$j*$rowheight);
				ps_stroke($ps);
			}

			ps_setfont($ps, $psfont, $fontsize);
			for($i=0; $i<16; $i++) {
				$text = sprintf("x%X", $i);
				$textwidth = ps_stringwidth($ps, $text,  $psfont, $fontsize);
				ps_show_xy($ps, $text, $leftmargin+$i*$colwidth+$colwidth/2-$textwidth/2, $bottommargin+16*$rowheight+$fontsize/2);
			}
			for($j=0; $j<16; $j++) {
				$text = sprintf("%Xx", $j);
				ps_show_xy($ps, $text, $leftmargin-1.7*$fontsize, $bottommargin+(15-$j)*$rowheight+$rowheight/2-$fontsize/2);
			}

			/* The symbol itself */
			ps_setfont($ps, $samplefont, $fontsamplesize);
			ps_setlinewidth($ps, 0.2);
			for($j=0; $j<16; $j++) {
				for($i=0; $i<16; $i++) {
					if($glc+($j*16+$i) < $listlen) {
						$textwidth = ps_glyph_width($ps, $glyphlist[$glc+($j*16+$i)], 0, $fontsamplesize);
						ps_set_value($ps, "textx", $leftmargin+$i*$colwidth+$colwidth/2-$textwidth/2);
						ps_set_value($ps, "texty", $bottommargin+(15-$j)*$rowheight+$rowheight/2+3-$fontsize/2);
						ps_glyph_show($ps, $glyphlist[$glc+($j*16+$i)]);
						ps_moveto($ps, $leftmargin+$i*$colwidth+$colwidth/2-$textwidth/2, $bottommargin+(15-$j)*$rowheight+$rowheight/2+3-$fontsize/2);
						ps_lineto($ps, $leftmargin+$i*$colwidth+$colwidth/2+$textwidth/2, $bottommargin+(15-$j)*$rowheight+$rowheight/2+3-$fontsize/2);
						ps_stroke($ps);
					}
				}
			}

			/* The name of the symbol */
			ps_setfont($ps, $psfont, 3);
			for($j=0; $j<16; $j++) {
				for($i=0; $i<16; $i++) {
					if($glc+($j*16+$i) < $listlen) {
						ps_set_value($ps, "textx", $leftmargin+$i*$colwidth+2);
						ps_set_value($ps, "texty", $bottommargin+(15-$j)*$rowheight+2);
						ps_show($ps, $glyphlist[$glc+($j*16+$i)]);
					}
				}
			}
			ps_end_page($ps);
			$glc += 256;
		}
	}
}
ps_close($ps);
ps_delete($ps);
?>