Debian Codegraph @

en/build/bin/make-iso-tables

raw
1 #!/usr/bin/perl -- # -*- Perl -*-
2 # build the character entity tables from the glyphtable map
3 # This script must be run in the 'build' directory
4
5 use XML::DOM;
6
7 $verbose = shift @ARGV;
8
9 $entities = "lib/entities.xml";
10
11 my $parser = new XML::DOM::Parser (NoExpand => 0);
12 print STDERR "Loading $entities...";
13 $doc = $parser->parsefile($entities);
14 $root = $doc->getDocumentElement();
15 $entlist = $root->getElementsByTagName('entity');
16 print STDERR "\n";
17
18 %hex = ();
19 %desc = ();
20 for (my $count = 0; $count < $entlist->getLength(); $count++) {
21 my $ent = $entlist->item($count);
22 my $ucode = $ent->getAttribute('ucode');
23 my $name = $ent->getAttribute('name');
24 my $iso = $ent->getAttribute('iso');
25 my $desce = $ent->getElementsByTagName('desc')->item(0);
26 my $text = $desce->toString();
27 $text = $1 if $text =~ /<desc>(.*)<\/desc>/;
28
29 next if $ucode eq '';
30 warn "Ignoring dup: $name\n", next if $hex{$name};
31
32 $hex{$name} = $ucode;
33 $desc{$name} = $text;
34 }
35
36 $dir = "lib/isoents";
37 $tbldir = ".";
38 $glyphdir = "../../glyphs/100dpi";
39
40 $missglyph = 0;
41 $unkglyph = 0;
42
43 opendir(DIR, $dir);
44 while ($name = readdir(DIR)) {
45 $file = "$dir/$name";
46
47 next if ! -f $file;
48 next if $name !~ /^(.*)\.ent$/;
49
50 $base = $1;
51
52 open (TBL, ">$tbldir/$base.gen");
53
54 print TBL "<informaltable pgwide='1'>\n";
55 print TBL "<tgroup cols='4'>\n";
56 print TBL "<?dbhtml table-summary=\"Unicode character entity table\"?>\n";
57 print TBL "<colspec colwidth=\"15*\"/>\n";
58 print TBL "<colspec colwidth=\"15*\" align='center'/>\n";
59 print TBL "<colspec colwidth=\"10*\" align='center'/>\n";
60 print TBL "<colspec colwidth=\"60*\"/>\n";
61 print TBL "<thead>\n";
62 print TBL "<row>\n";
63 print TBL " <entry align='center'>Entity <?lb?>Name</entry>\n";
64 print TBL " <entry align='center'>Unicode <?lb?>Code point</entry>\n";
65 print TBL " <entry align='center'>Sample <?lb?>Glyph</entry>\n";
66 print TBL " <entry align='left'>Description</entry>\n";
67 print TBL "</row>\n";
68 print TBL "</thead>\n";
69 print TBL "<tbody>\n";
70
71 open(F, $file);
72 while (<F>) {
73 chop;
74 if (/<!ENTITY\s+(\S+)\s+.*?--[=\/]?(.*)--/) {
75 my($name, $desc) = ($1,$2);
76
77 $desc = $1 if $desc =~ /[A-Z]:\s*(.*)/;
78 $desc =~ s/\&/\&amp;/g;
79 $desc =~ s/\</\&lt;/g;
80
81 $desc = $desc{$name} if exists($desc{$name});
82
83 $glyph = "Blank";
84
85 $code = "&nbsp;";
86 $code = $hex{$name} if $hex{$name};
87
88 if ($hex{$name} && -f "$glyphdir/U$code.png") {
89 $glyph = "U$code";
90 if (! -f "$glyphdir/$glyph.png") {
91 $glyph = "Unknown";
92 print STDERR "$name\t$code\t$desc\n" if $verbose;
93 $missglyph++;
94 }
95 } else {
96 $glyph = "$name";
97 $glyph = "vsubn-cap-E" if $name eq 'vsubnE';
98 $glyph = "vsupn-cap-E" if $name eq 'vsupnE';
99 $glyph = "xh-cap-Arr" if $name eq 'xhArr';
100
101 if (! -f "$glyphdir/$glyph.png") {
102 $glyph = "Unknown";
103 $code = "&nbsp;";
104 print STDERR "$name\t\t$desc\n" if $verbose;
105 $unkglyph++;
106 }
107 }
108
109 print TBL "<row>\n <entry> $name</entry><entry align='center'>$code</entry>\n";
110 print TBL " <entry valign='bottom'>";
111 print TBL "<mediaobject>\n<imageobject>\n";
112 print TBL "<imagedata fileref=\"&$glyph.glyph;\"/>\n";
113 print TBL "</imageobject>\n";
114 print TBL "<textobject>\n";
115 print TBL "<phrase>Unicode $code</phrase>\n";
116 print TBL "</textobject>\n";
117 print TBL "</mediaobject>";
118 print TBL "</entry>\n <entry>$desc</entry>\n";
119 print TBL "</row>\n";
120 }
121 }
122 close (F);
123
124 print TBL "</tbody>\n";
125 print TBL "</tgroup>\n";
126 print TBL "</informaltable>\n";
127
128 }
129 closedir(DIR);
130
131 print "$missglyph missing glyphs.\n";
132 print "$unkglyph unknown glyphs.\n";