keyboard: split character formatting fallback method
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 25 Jan 2024 21:02:20 +0000 (22:02 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 29 Jan 2024 17:17:48 +0000 (18:17 +0100)
Prepare uncached Shiar_Sheet/FormatChar::glyph_info code path for future use
in similar tools/mkcharinfo generation.

Shiar_Sheet/FormatChar.pm
tools/mkcharinfo

index 3d9b6fb65538fb57cc8b62652b26e5cfd3f54b51..f471497b1f4bbb8687920a461ae0f6635d2b3661 100644 (file)
@@ -8,7 +8,7 @@ use utf8;
 use Data::Dump 'pp';
 use PLP::Functions 'EscapeHTML';
 
-our $VERSION = '1.09';
+our $VERSION = '1.10';
 
 our $uc = do 'data/unicode-char.inc.pl';
 
@@ -17,14 +17,25 @@ sub new {
        bless { anno => ['di', 0], style => 'di' }, $class;
 }
 
-sub glyph_info {
+sub glyph_mkinfo {
        my ($self, $codepoint) = @_;
-       return $uc->{chr $codepoint} || eval {
+       # attempt to get unicode character information
+       my $info = eval {
                require Unicode::UCD;
-               if (my $fullinfo = Unicode::UCD::charinfo($codepoint)) {
-                       return [@$fullinfo{qw/category name - string/}];
-               }
-       } || [];
+               Unicode::UCD::charinfo($codepoint)
+                       || { category => 'Xn', name => '' };
+       } or return;
+       my $string;
+       if ($info->{combining}) {
+               # overlay combining diacritics
+               $string = chr(9676) . chr($codepoint);
+       }
+       return [@$info{qw( category name )}, undef, $string];
+}
+
+sub glyph_info {
+       my ($self, $codepoint) = @_;
+       return $uc->{chr $codepoint} || $self->glyph_mkinfo($codepoint) || [];
 }
 
 sub glyph_html {
index ace9dbe12b01a9c9e3d93006260e9757ec650045..da6aa87d5644d90a273e3ff5b89c86c9ade48832 100755 (executable)
@@ -84,6 +84,7 @@ eval {
 
 for my $chr (keys %info) {
        my $cp = ord $chr;
+       #my $info = glyph_mkinfo($cp) or next;
        # attempt to get unicode character information
        my $info = eval {
                require Unicode::UCD;