.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}
.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}
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',
([@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) {
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/;
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>
<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>
-<: }
use re '/msx';
use JSON 'decode_json';
use Data::Dump 'pp';
+use Shiar_Sheet::FormatChar;
our $VERSION = '1.01';
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) {
} 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__
=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.