036a21f9212c007161ca4112fc620fb26e986c54
[sheet.git] / keyboard / altgr / groups.inc.pl
1 use strict;
2 use warnings;
3 use Unicode::Normalize qw( NFKD );
4 use Text::Unidecode qw( unidecode );
5 use Shiar_Sheet::FormatChar;
6
7 our %rows;
8
9 my $uc = Shiar_Sheet::FormatChar->new;
10 my %g; # present group classes
11 {
12         rows => [1, 0],
13         def => {
14                 '' => {
15                         map {
16                                 my $v = $rows{$_};
17                                 my $class = (
18                                           !defined $v || $_ eq $v ? 1 # identical
19                                         : $v =~ /\A\p{Mn}+\z/ ? 9 # combining accent
20                                         : $v =~ /\A[\p{Sk}\p{Lm}]+\z/ ? 8 # modifier symbol
21                                         : $v =~ /\A[\pM\pP]+\z/ ? 7 # mark
22                                         : NFKD($v) =~ /\Q$_/ ? 2 # decomposed equivalent
23                                         : unidecode($v) =~ /\Q$_\E+/i ? 4 # transliterated
24                                         : $v =~ /^\p{Latin}/ ? 5 # latin script
25                                         : 6
26                                 );
27                                 $g{$class} = 1;
28                                 $_ => "g$class"
29                         } keys %rows
30                 },
31         },
32         key => {
33                 map {
34                         my ($glyph, $title) = $uc->glyph_html($rows{$_});
35                         $_ => join "\n", $glyph, $title
36                 } keys %rows
37         },
38         flag => {
39                 g2 => ['accented', "decomposes to the original letter with a combining accent"],
40                 g4 => ['similar', "transliterates (mostly) into the unmodified letter"],
41                 g5 => ['latin', "a different (accented) latin letter"],
42                 g6 => ['symbol', "other character not directly deducible from key"],
43                 g7 => ['punctuation', "(punctuation) mark"],
44                         !$g{9} ? () : (
45                 g8 => ['mark', "modifier letter or mark (spacing diacritic)"],
46                 g9 => ['combining', "diacritical mark to be combined with a following character"],
47                         ),
48         },
49 }