From 8f93eb6627b93ef73026457b041c7210b098ba74 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 22 Feb 2024 18:56:51 +0100 Subject: [PATCH] digraphs: prepare xorg comparison in prebuilt data 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 | 12 +++++------ digraphs.plp | 50 ++++++------------------------------------- tools/mkdigraphs-xorg | 45 +++++++++++++++++++++++++++----------- 3 files changed, 44 insertions(+), 63 deletions(-) diff --git a/base.css b/base.css index b0f7312..e4ed58d 100644 --- 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} diff --git a/digraphs.plp b/digraphs.plp index 6b1a5c2..57d0b0f 100644 --- a/digraphs.plp +++ b/digraphs.plp @@ -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 = "$glyph" if $script =~ /\bZs\b/; @@ -135,19 +109,8 @@ say ''; print '
' if exists $get{split}; } -if ($mode) { :> -
- -
matching RFC-1345 - matching proposal - unique to Xorg - conflict - duplicate -
-
-<: } else { :> -
+
<: unless ($cmp) { :>
control space @@ -168,12 +131,11 @@ if ($mode) { japanese chinese
- +<: } :> <: - print qq(\n\t
$di->{flag}->{$_}) + printf qq(\n\t%s), (!$cmp && 'u-').$_, $di->{flag}->{$_} for sort keys %{ $di->{flag} }; :>
-<: } diff --git a/tools/mkdigraphs-xorg b/tools/mkdigraphs-xorg index ec0e862..8df64cd 100755 --- a/tools/mkdigraphs-xorg +++ b/tools/mkdigraphs-xorg @@ -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 with Unicode code points keyed by mnemonics. Any errors and warnings are given at STDERR. -- 2.30.0