latin: cmymap row of subtractive colour mix
[sheet.git] / digraphs.plp
1 <(common.inc.plp)><:
2
3 my $mode = ($Request // '') eq 'xorg' || exists $get{xorg};
4 my $modename = $mode ? 'X.Org' : 'RFC-1345';
5
6 Html({
7         title => 'digraph cheat sheet',
8         version => '1.2',
9         description => [
10                 "Complete table of digraph characters from $modename.",
11         ],
12         keywords => [qw'
13                 digraph mnemonic compose composition pair
14                 character char glyph table unicode vim xorg x11 x
15         '],
16         stylesheet => [qw'light'],
17         data => [qw( digraphs.inc.pl )],
18 });
19
20 :>
21 <h1><:= $modename :> Digraphs</h1>
22
23 <p>Character mnemonics following compose key ⎄<:
24 say join("\n",
25         $mode ? (
26                 ' in the X Window System (Shift+AltGr by default).',
27                 'Differences from <a href="/digraphs">RFC-1345</a> are indicated.',
28         ) : (':',
29                 'i^k in <a href="/vi">Vim</a>,',
30                 '^u^\ in <a href="/readline">Emacs</a>,',
31                 '^a^v in <a href="/screen">Screen</a>.',
32                 'Similar but different from <a href="/digraphs/xorg">X.Org</a>.',
33         ),
34         'Also see <a href="/unicode">common Unicode</a>.</p>',
35 );
36 say '<p class="aside">Unofficial <span class="u-l2">proposals</span>',
37         ' are available as <a href="/digraphs.vim">ex commands</a>.' if not $mode;
38 :>
39
40 <:
41 my $di = do 'digraphs.inc.pl'
42         or die "Error loading digraphs data: ", $@ // $!;
43
44 if (exists $get{v}) {
45         # show characters for inverted mnemonics (vim alternatives)
46         $di->{ substr($_, 1, 1) . substr($_, 0, 1) } ||=
47                 [ $di->{$_}->[0], '', 'l0 ex', '', $di->{$_}->[4] ]
48                 for grep { ref $di->{$_} } keys %{$di};
49 }
50
51 my @chars = (
52         [qw{! " % ' ( ) * + , - . /}],
53         ['0'..'9'], [qw{: ; < = > ?}],
54         ['A'..'M'], ['N'..'Z'],
55         ['a'..'m'], ['n'..'z'],
56 );
57 my @chars2 = (['_'], @chars);  # trailing character (extended set)
58 my @columns = !exists $get{split} ? \@chars2 :
59         ([@chars2[0, 1, 3, 4, 6]], [@chars2[2, 5, 7]]);
60
61 if ($mode) {
62         my $xorg = do 'data/digraphs-xorg.inc.pl'
63                 or die "Error loading Xorg data: ", $@ // $!;
64         $_ = [ord $_] for values %{$xorg};
65         $xorg->{$_}->[2] = # class = compatibility
66                 $di->{$_} ? $di->{$_}->[0] != $xorg->{$_}->[0] ? 'l1' :  # conflict
67                 $di->{$_}->[2] =~ /\bu-di\b/ ? 'l5' : 'l3' : 'l2'  # rfc|any|none
68                 for keys %{$xorg};
69
70         for my $cp (map {$_->[0]} values %{$xorg}) {
71                 next if (state $seen = {})->{$cp}++;  # List::MoreUtils::uniq
72
73                 # find multiple equivalent mnemonics
74                 my @equiv = grep {$cp eq $_->[0]}
75                         map {$xorg->{$_}} sort keys %{$xorg}; # values ordered by mnem.
76
77                 # search for the most compatible match
78                 my ($compat) = sort {
79                         $equiv[$b]->[2] cmp $equiv[$a]->[2]  # highest level
80                         || $b <=> $a  # fallback to last mnemonic
81                 } 0 .. $#equiv;
82
83                 # reclassify all but one as level 0 (omitted)
84                 splice @equiv, $compat // -1, 1, ();
85                 $_->[2] = 'l0 ex' for @equiv;
86         }
87
88         $chars2[0] = [qw( # ^ _ ` ~ )];
89         @chars = @chars2;
90         $di = $xorg;
91 }
92
93 for my $colchars (@columns) {
94 print '<table class="glyphs dimap"><col>';
95 print qq'<colgroup span="$_">' for map {scalar @$_} @{$colchars};
96 say '</colgroup><col>';
97 for my $section (qw{thead tfoot}) {
98         print "<$section><tr><th>↳";
99         print '<th>', EscapeHTML($_) for map {@$_} @{$colchars};
100         say '<th>&nbsp;';
101 }
102 for my $c1group (@chars) {
103         print '<tbody>';
104         for my $c1 (@$c1group) {
105                 print '<tr><th>', EscapeHTML($c1);
106                 for my $c2 (map {@$_} @$colchars) {
107                         my $mnem = $c1 . $c2;
108                         if (not defined $di->{$mnem}) {
109                                 print '<td>';
110                                 next;
111                         }
112                         if (ref $di->{$mnem} ne 'ARRAY') {
113                                 printf '<td class="X Xr" title="%s">', EscapeHTML($mnem);
114                                 next;
115                         }
116                         my ($codepoint, $name, $support, $script, $string) = @{ $di->{$mnem} };
117
118                         my $glyph = $string || chr $codepoint;
119                         utf8::upgrade($glyph);  # prevent latin1 output
120                         my $desc = $mnem . ($name && " ($name)");
121                         my @class = ('X', grep {$_} $support && "u-$support", $script);
122
123                         $glyph = EscapeHTML($glyph);
124                         $glyph = "<span>$glyph</span>" if $script =~ /\bZs\b/;
125
126                         printf "\n".'<td class="%s" title="%s">%s',
127                                 join(' ', @class), EscapeHTML($desc), $glyph;
128                 }
129                 say "\n<th>", EscapeHTML($c1);
130         }
131 }
132 say '</table>';
133 print '<hr>' if exists $get{split};
134 }
135
136 if ($mode) {
137 :>
138 <div class="legend">
139         <table class="glyphs"><tr>
140         <td class="X l5">matching RFC-1345
141         <td class="X l3">matching proposal
142         <td class="X l2">unique to Xorg
143         <td class="X l1">conflict
144         <td class="X l0 ex">duplicate
145         </table>
146 </div>
147 <: } else { :>
148 <div class="legend">
149         <table class="glyphs"><tr>
150         <td class="X Cc">control
151         <td class="X Zs"><span>space</span>
152         <td class="X Mn">combining
153         <td class="X Sk">spacing&nbsp;modifier
154         <td class="X Pf">quote
155         <td class="X Po">punctuation
156         <td class="X So">symbol
157         <td class="X Sm">math
158         <td class="X Sc">currency
159         <td class="X No">numeric
160         <td class="X Greek">greek
161         <td class="X Cyrillic">cyrillic
162         <td class="X Latin">latin
163         <td class="X Hebrew">hebrew
164         <td class="X Arabic">arabic
165         <td class="X Hangul">korean
166         <td class="X Hiragana">japanese
167         <td class="X Bopomofo">chinese
168         </table>
169
170         <table class="glyphs"><tr>
171         <td class="X u-l4">full support
172         <td class="X u-l3">vim extension
173         <td class="X u-l3 ex">vim v8.0
174         <td class="X u-l2">proposal
175         <td class="X u-l1">not in vim
176         </table>
177 </div>
178
179 <: }