X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/44e16a2ff933556dd5db83bdbf2315d61ce0640f..ed1c096fecf0abce1d1d061f5b9f7cb5fbef7645:/Shiar_Sheet/KeyboardChars.pm diff --git a/Shiar_Sheet/KeyboardChars.pm b/Shiar_Sheet/KeyboardChars.pm index 77be120..b2ee11d 100644 --- a/Shiar_Sheet/KeyboardChars.pm +++ b/Shiar_Sheet/KeyboardChars.pm @@ -2,17 +2,34 @@ package Shiar_Sheet::KeyboardChars; use 5.020; use warnings; +use utf8; use experimental 'signatures'; use parent 'Exporter'; use Unicode::Normalize qw( NFKD ); -use Text::Unidecode qw( unidecode ); +use Text::Unidecode (); use Shiar_Sheet::FormatChar; -our $VERSION = '1.01'; +our $VERSION = '1.04'; our @EXPORT = qw( kbchars kbmodes ); my $uc = Shiar_Sheet::FormatChar->new; +our %unaccent = qw( + ⍺ a ⍵ w ∊ E ⍷ E ⍴ r ⍳ i ⍸ i ○ O ⍥ O ⌿ / ⍟ (*) ⊕ (+) + Ʊ U ǝ e Ǝ E ʌ v ɥ h ʘ O ɰ mw ɯ mw Ɯ MW ə @ae Ə @AE + ɸ PF ʎ yl ɔ co Ɔ CO ɛ 3E ƣ q Ƣ Q ∀ A ∃ E ∪ u ∩ n ≠ != + ≈ =~ ∅ /0 ∘ o ⋅ . ∫ s ≝ =d ″ " ≤ < ≥ > √ rV ∛ 3V ∜ 4V + Α A Β B Γ G Δ D Ε E Ζ Z Η H Θ CQ Ι I Κ K Λ L Μ M + Ν N Ξ X Ο O Π P Ρ R Σ S Τ T Υ YU Φ F Χ CX Ψ Y Ω W + α a β b γ g δ d ε e ζ z η h θ cq ι i κ k λ l μ m + ν n ξ x ο o π p ρ r σ s τ t υ yu φ f χ cx ψ y ω w + ς sc ϑ cq µ mu +); + +sub unidecode { + return $unaccent{$_[0]} // Text::Unidecode::unidecode($_[0]); +} + sub kbchars ($rows) { return kbmodes({'' => $rows}); } @@ -20,6 +37,7 @@ sub kbchars ($rows) { sub kbmodes ($modes) { my %g; # present group classes my %info = ( + tableclass => 'keys big', rows => [1, 0], ); for my $lead (keys %{$modes}) { @@ -29,22 +47,23 @@ sub kbmodes ($modes) { $info{mode}->{$lead} //= "mode $lead"; $info{def}->{$lead}{$lead} = 'g1 mode'; # back } - while (my ($c, $v) = each %{ $modes->{$lead} }) { + while (my ($k, $v) = each %{ $modes->{$lead} }) { my ($glyph, $title) = $uc->glyph_html($v); - $info{key}{$lead.$c} = join "\n", $glyph, $title; - - my $class = 'g'.( - !defined $v || $c eq $v ? 1 # identical - : $v =~ /\A\p{Mn}+\z/ ? 9 # combining accent - : NFKD($v) =~ /\Q$c/ ? 2 # decomposed equivalent - : unidecode($v) =~ /\Q$c\E+/i ? 4 # transliterated - : $v =~ /\A[\p{Sk}\p{Lm}]+\z/ ? 8 # modifier symbol - : $v =~ /\A[\pM\pP]+\z/ ? 7 # mark - : $v =~ /^\p{Latin}/ ? 5 # latin script - : 6 + $info{key}{$lead.$k} = join "\n", $glyph, $title; + my $c = $k =~ s/\A[+^](?=.)//r; # trim modifier indicator + + my $class = ( + !defined $v || $c eq $v ? 'no' # identical + : $v =~ /\A\p{Mn}+\z/ ? 'g9' # combining accent + : NFKD($v) =~ /\Q$c/ ? 'g2' # decomposed equivalent + : unidecode($v) =~ /\Q$c\E+/i ? 'g4' # transliterated + : $v =~ /\A[\p{Sk}\p{Lm}]+\z/ ? 'g8' # modifier symbol + : $v =~ /\A[\pM\pP]+\z/ ? 'g7' # mark + : $v =~ /^\p{Latin}/ ? 'g5' # latin script + : 'g6' ); - $g{$class} = 1; - $info{def}{$lead}{$c} //= $class; + $g{$class} = 1 unless $class eq 'no'; + $info{def}{$lead}{$k} //= $class; } } $info{flag} = {%{{