From b3b71de70835c9edbdf320035d5bb54d4c31db46 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 25 Jan 2024 22:02:20 +0100 Subject: [PATCH] keyboard: split character formatting fallback method Prepare uncached Shiar_Sheet/FormatChar::glyph_info code path for future use in similar tools/mkcharinfo generation. --- Shiar_Sheet/FormatChar.pm | 25 ++++++++++++++++++------- tools/mkcharinfo | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Shiar_Sheet/FormatChar.pm b/Shiar_Sheet/FormatChar.pm index 3d9b6fb..f471497 100644 --- a/Shiar_Sheet/FormatChar.pm +++ b/Shiar_Sheet/FormatChar.pm @@ -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 { diff --git a/tools/mkcharinfo b/tools/mkcharinfo index ace9dbe..da6aa87 100755 --- a/tools/mkcharinfo +++ b/tools/mkcharinfo @@ -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; -- 2.30.0