From: Mischa POSLAWSKY Date: Thu, 23 Dec 2010 21:21:54 +0000 (+0100) Subject: formatchar: annotation fallback X-Git-Tag: v1.5~97 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/9cabbcb99510ce7c9256d085d1c9de6c0b5fc8ce formatchar: annotation fallback --- diff --git a/Shiar_Sheet/FormatChar.pm b/Shiar_Sheet/FormatChar.pm index 30aab5e..647280e 100644 --- a/Shiar_Sheet/FormatChar.pm +++ b/Shiar_Sheet/FormatChar.pm @@ -14,7 +14,7 @@ our %di = map { $diinfo->{$_}->[0] => $_ } grep { ref $diinfo->{$_} } sub new { my ($class) = @_; - bless { unicode => 0, anno => 'di', style => 'di' }, $class; + bless { anno => ['di', 0], style => 'di' }, $class; } sub glyph_info { @@ -107,17 +107,28 @@ sub cell { } } + my $anno = ''; + for (@{ $self->{anno} }) { + if ($_ eq 'di') { + if (defined $mnem and length $mnem) { + $anno = sprintf(' %s', EscapeHTML($mnem)); + last; + } + } + else { + if ($_ eq 'hex' or $cell =~ /^[^a-zA-Z]$/) { + $anno = sprintf(' %04X', 'value', ord $cell); + last; + } + } + } + return sprintf('%s%s', defined $title ? qq{ title="$title"} : '', @class ? sprintf(' class="%s"', join ' ', @class) : '', $html || '', - $cell eq '' ? (' ', '') : ($cell, - $self->{anno} eq 'di' && defined $mnem && length $mnem - ? sprintf(' %s', EscapeHTML($mnem)) - : $self->{unicode} + $cell =~ /^[^a-zA-Z]$/ > 0 - ? sprintf(' %04X', 'value', ord $cell) - : '' - ), + $cell eq '' ? ' ' : $cell, + $anno, ); } @@ -164,7 +175,7 @@ sub table { } return sprintf qq{\n%s
\n}, - $self->{anno} || $self->{unicode} >= 0 ? ' dilabel' : '', + @{ $self->{anno} } ? ' dilabel' : '', join '', map {"$_\n"} @rows; } diff --git a/unicode.plp b/unicode.plp index 5b3093d..2f9969a 100644 --- a/unicode.plp +++ b/unicode.plp @@ -31,12 +31,10 @@ use Shiar_Sheet::FormatChar; my $glyphs = Shiar_Sheet::FormatChar->new; if (exists $get{di}) { - $glyphs->{anno} = (!defined $get{di} || $get{di}) && 'di'; - $glyphs->{unicode} = 1; + $glyphs->{anno} = [ (!defined $get{di} || $get{di}) && 'di', 'hex' ]; } if (exists $get{q}) { - $glyphs->{unicode} = -1; - $glyphs->{anno} = 0; + $glyphs->{anno} = []; } our $verbose = exists $get{v};