digraphs: prepare xorg comparison in prebuilt data
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 22 Feb 2024 17:56:51 +0000 (18:56 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 6 Mar 2024 00:38:51 +0000 (01:38 +0100)
Replace the entire character table, unifying level classes with vim
foregrounds (renaming u-l3 in the process).

Differences are indicated similar to before, but keeping declared alias
preferences without effort to find vim matches (which is accidental and not
of interest to most users, while losing distinction of intended precedence).

base.css
digraphs.plp
tools/mkdigraphs-xorg

index b0f7312fa53098e784cfca27b7bb095246d9cd61..e4ed58d7fb2da99e8fbd74814177f6124730add6 100644 (file)
--- a/base.css
+++ b/base.css
@@ -520,10 +520,10 @@ table.dimap {
 .u-invalid {background: #BBB} /* invalid, impossible */
 
 /* foreground representation */
-#digraphs .u-l3 {color: #080} /* partial */
-#digraphs .u-l3.ex {color: #4C0} /* experimental */
-#digraphs .u-l2 {color: #A44; color: rgba(128, 0, 0, .6)} /* unofficial proposal */
-#digraphs .u-l1 {color: #D00; color: rgba(255, 0, 0, .8)} /* minimal or invalid */
+#digraphs .u-l4 {color: #080} /* partial */
+#digraphs .u-l5 {color: #4C0} /* experimental */
+#digraphs .u-l2 {color: #A44; color: rgba(128, 0, 0, .6)} /* unofficial */
+#digraphs .u-l1 {color: #D00; color: rgba(255, 0, 0, .8)} /* missing */
 
 /* support percentage (browser cells) */
 .p0         {opacity: .6}
@@ -595,8 +595,8 @@ table.dimap {
 .l3:hover                                  {background: #FF8}
 .l4:hover                                  {background: #CF8}
 .l5:hover                                  {background: #8F8}
-.u-l3:hover    {outline: 1px solid #080}
-.u-l3.ex:hover {outline: 1px solid #8F0}
+.u-l4:hover    {outline: 1px solid #080}
+.u-l5:hover    {outline: 1px solid #8F0}
 .u-l2:hover    {outline: 1px solid #800}
 .u-l1:hover    {outline: 1px solid #F00}
 
index 6b1a5c21bc05371f6c51971a2003684be250ce44..57d0b0f5e53e6975b117d2ceee591d9b783347d2 100644 (file)
@@ -2,6 +2,7 @@
 
 my $mode = ($Request // '') eq 'xorg' || exists $get{xorg};
 my $modename = $mode ? 'X.Org' : 'RFC-1345';
+my $cmp = exists $get{cmp} ? ($get{cmp} // 1) : !!$Request;
 
 Html({
        title => 'digraph cheat sheet',
@@ -58,36 +59,9 @@ my @columns = !exists $get{split} ? \@chars2 :
        ([@chars2[0, 1, 3, 4, 6]], [@chars2[2, 5, 7]]);
 
 if ($mode) {
-       my $xorg = Data('digraphs-xorg');
-       $_->[3] = undef for values %{$xorg};  # reset alias classes
-       $xorg->{$_}->[2] = # class = compatibility
-               !$di->{key}->{$_} ? 'l2' :  # free
-               $di->{key}->{$_}->[0] != $xorg->{$_}->[0] ? 'l1' :  # conflict
-               $di->{key}->{$_}->[2] eq 'l4' ? 'l5' :  # rfc
-               'l3'  # any
-               for keys %{$xorg};
-
-       for my $cp (map {$_->[0]} values %{$xorg}) {
-               next if (state $seen = {})->{$cp}++;  # List::MoreUtils::uniq
-
-               # find multiple equivalent mnemonics
-               my @equiv = grep {$cp eq $_->[0]}
-                       map {$xorg->{$_}} sort keys %{$xorg}; # values ordered by mnem.
-
-               # search for the most compatible match
-               my ($compat) = sort {
-                       $equiv[$b]->[2] cmp $equiv[$a]->[2]  # highest level
-                       || $b <=> $a  # fallback to last mnemonic
-               } 0 .. $#equiv;
-
-               # reclassify all but one as level 0 (omitted)
-               splice @equiv, $compat // -1, 1, ();
-               $_->[2] = 'l0 ex' for @equiv;
-       }
-
+       $di = Data('digraphs-xorg');
        $chars2[0] = [qw( # ^ _ ` ~ )];
        @chars = @chars2;
-       $di->{key} = $xorg;
 }
 
 for my $colchars (@columns) {
@@ -120,7 +94,7 @@ for my $c1group (@chars) {
                        utf8::upgrade($glyph);  # prevent latin1 output
                        my $desc = $mnem . ($name && " ($name)");
                        my @class = ('X', grep {$_} $script);
-                       push @class, $mode ? $support : "u-$support" if $support;
+                       push @class, $cmp ? $support : "u-$support" if $support;
 
                        $glyph = EscapeHTML($glyph);
                        $glyph = "<span>$glyph</span>" if $script =~ /\bZs\b/;
@@ -135,19 +109,8 @@ say '</table>';
 print '<hr>' if exists $get{split};
 }
 
-if ($mode) {
 :>
-<div class="legend">
-       <table class="glyphs"><tr>
-       <td class="X l5">matching RFC-1345
-       <td class="X l3">matching proposal
-       <td class="X l2">unique to Xorg
-       <td class="X l1">conflict
-       <td class="X l0 ex">duplicate
-       </table>
-</div>
-<: } else { :>
-<div class="legend">
+<div class="legend"><: unless ($cmp) { :>
        <table class="glyphs"><tr>
        <td class="X Cc">control
        <td class="X Zs"><span>space</span>
@@ -168,12 +131,11 @@ if ($mode) {
        <td class="X Hiragana">japanese
        <td class="X Bopomofo">chinese
        </table>
-
+<: } :>
        <table class="glyphs"><tr><:
-       print qq(\n\t<td class="X u-$_">$di->{flag}->{$_})
+       printf qq(\n\t<td class="X %s">%s), (!$cmp && 'u-').$_, $di->{flag}->{$_}
                for sort keys %{ $di->{flag} };
 :>
        </table>
 </div>
 
-<: }
index ec0e8626213c9054396f9f883c9f9ca63e9133fc..8df64cdaa41cffe664bca2982dee251894dc011a 100755 (executable)
@@ -6,6 +6,7 @@ use open IO => ':encoding(utf-8)', ':std';
 use re '/msx';
 use JSON 'decode_json';
 use Data::Dump 'pp';
+use Shiar_Sheet::FormatChar;
 
 our $VERSION = '1.01';
 
@@ -15,9 +16,11 @@ my $symname = eval {
        return decode_json(readline $keysymh);
 } or die "Could not read keysym definitions: $@\n";
 
-# optionally get unicode character information
-my $uninfo = do './data/unicode-char.inc.pl'
-       or warn "could not include unicode details: ", $@ // $!;
+my $vidi = eval {
+       open my $jsfh, '<', 'data/digraphs.json' or die $!;
+       local $/;
+       return JSON->new->decode(readline $jsfh);
+} or warn "Could not read comparison digraphs: $@\n";
 
 my %table;
 while ($_ = readline) {
@@ -31,17 +34,33 @@ while ($_ = readline) {
        } or warn($@), next;
        $mnem =~ m/\A [\x20-\x7F]{2} \z/ or next;  # only interested in two ascii
        my $alias = (state $seen = {})->{$chr}++;  # assume first is preferred
+       my $cp = ord $chr;
+       my $uninfo = Shiar_Sheet::FormatChar->glyph_info($cp);
+       my $comparison = (
+               !$vidi->{key}->{$mnem} ? 'l3' :  # free
+               $vidi->{key}->{$mnem}->[0] != $cp ? 'l1' :  # conflict
+               $vidi->{key}->{$mnem}->[2] eq 'l4' ? 'l5' :  # rfc
+               'l4'  # any
+       );
        $table{$mnem} = [
-               ord $chr,
-               $uninfo->{$chr}->[1] // '',  # name
-               0,  # comparison
-               $alias ? 'l0 ex' :
-               ($uninfo->{$chr}->[0] // '') =~ s/ u-di| u-prop| ex//gr,  # class
-               $uninfo->{$chr}->[4] // (),  # string
+               $cp,
+               $uninfo->[1] // '',  # name
+               $comparison,
+               $alias ? 'l0 ex' : $uninfo->[0] // '',  # class
+               $uninfo->[4] // (),  # string
        ];
 }
 
-print JSON->new->canonical->indent->encode(\%table);
+print JSON->new->canonical->indent->encode({
+       key   => \%table,
+       flag  => {
+               'l5' => "matching RFC-1345",
+               'l4' => "matching proposal",
+               'l3' => "unique to Xorg",
+               'l1' => "conflict",
+               'l0 ex' => "duplicate",
+       },
+});
 
 __END__
 
@@ -52,13 +71,13 @@ mkdigraphs-xorg - Output Xorg compose sequences
 =head1 SYNOPSIS
 
 
-    mkdigraphs-xorg /usr/share/X11/locale/en_US.UTF-8/Compose >digraphs-xorg.inc.pl
-    perl -e'$di = do "digraphs-xorg.inc.pl"; print chr $di->{AT}'
+    mkdigraphs-xorg /usr/share/X11/locale/en_US.UTF-8/Compose |
+    jq -r '.key."AT"[0]' | perl -nE 'say chr' # @
 
 =head1 DESCRIPTION
 
 Extracts Multi_key definitions from X11/Xorg Compose.pre include file.
-If successful, Perl code is output resulting in a hash
+If successful, a JSON object is output containing a digraphs list in C<key>
 with Unicode code points keyed by mnemonics.
 Any errors and warnings are given at STDERR.