font: caption block name
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 6 Mar 2015 08:09:09 +0000 (09:09 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 9 Jun 2015 03:43:43 +0000 (05:43 +0200)
font.plp

index 886792114ba97f74b23ad6c146e0e729ca22ccff..8c9b098d960d59fbaf43c390e2a4a460b3acd3c4 100644 (file)
--- a/font.plp
+++ b/font.plp
@@ -18,7 +18,8 @@ if (my $font = $ENV{PATH_INFO} =~ s{^/}{}r) {
 
        require Unicode::UCD;
 
 
        require Unicode::UCD;
 
-       my $size = 0x200;
+       my $pagerows = 0x200;
+       my $pagecols = 32;
        my $offset = eval {
                local $_ = $get{q} || 0;
                return $_ if /\A\d+\z/;  # numeric
        my $offset = eval {
                local $_ = $get{q} || 0;
                return $_ if /\A\d+\z/;  # numeric
@@ -52,28 +53,47 @@ if (my $font = $ENV{PATH_INFO} =~ s{^/}{}r) {
        say <<"EOT";
 
 <style>
        say <<"EOT";
 
 <style>
-       .glyphs tbody th { text-align: right }
+       .glyphs tbody th[!colspan] { text-align: right }
        .glyphs tbody td { font-family: "$fontmeta->{name}" }
 </style>
 EOT
        say '<table class="glyphs big">';
        .glyphs tbody td { font-family: "$fontmeta->{name}" }
 </style>
 EOT
        say '<table class="glyphs big">';
+
        say "<caption>$_</caption>" for join(' ', grep {$_}
        say "<caption>$_</caption>" for join(' ', grep {$_}
-               $offset > $size && sprintf('<a rel="start" href="?q=%d">◄</a>', 0),
+               $offset > $pagerows && sprintf('<a rel="start" href="?q=%d">◄</a>', 0),
                $offset > 0 && sprintf(
                        '<a rel="prev" href="?q=%d" title="U+%1$04X">◅</a>',
                $offset > 0 && sprintf(
                        '<a rel="prev" href="?q=%d" title="U+%1$04X">◅</a>',
-                       $offset - $size,
+                       $offset - $pagerows,
                ),
                ),
-               sprintf('U+%04X', $offset), #TODO: block name
-               $offset + $size < 0x11_0000 && sprintf(
+               sprintf('U+%04X', $offset),
+               Unicode::UCD::charblock($offset),
+               $offset + $pagerows < 0x11_0000 && sprintf(
                        '<a rel="next" href="?q=%d" title="U+%1$04X">▻</a>',
                        '<a rel="next" href="?q=%d" title="U+%1$04X">▻</a>',
-                       $offset + $size,
+                       $offset + $pagerows,
                ),
        );
                ),
        );
-       for my $cp ($offset .. $offset+$size-1) {
+
+       for my $cp ($offset .. $offset+$pagerows-1) {
+               state $sameblock;
+               my $block = Unicode::UCD::charblock($cp);
+
+               if ($sameblock and $sameblock ne $block and $block ne 'No_Block') {
+                       say sprintf '<tbody><tr><th colspan=%d>%s', $pagecols+1, $block;
+                       undef $sameblock;
+               }
+
+               if (not $sameblock) {
+                       $sameblock = $block;
+                       if (my $gap = $cp % $pagecols) {
+                               say sprintf '<tr><th>%X<th colspan=%d>', $cp, $gap;
+                       }
+               }
+
+               say sprintf '<tr><th>%X', $cp if $cp % $pagecols == 0;
+
                my $info = $glyphs->glyph_info($cp);
                my ($class, $name, $mnem, $html, $string) = @{$info};
                my $np = $class =~ /\bC\S\b/;  # noprint if control or invalid
                my $info = $glyphs->glyph_info($cp);
                my ($class, $name, $mnem, $html, $string) = @{$info};
                my $np = $class =~ /\bC\S\b/;  # noprint if control or invalid
-               say sprintf '<tr><th>%X', $cp if $cp % 32 == 0;
                say sprintf '<td class="%s" title="U+%04X%s">%s',
                        !$class ? ('l0', $cp, '', '') :
                        $cover{$cp} ? $np ? 'l2' : 'l5' : $np ? 'Xi' : 'l1',
                say sprintf '<td class="%s" title="U+%04X%s">%s',
                        !$class ? ('l0', $cp, '', '') :
                        $cover{$cp} ? $np ? 'l2' : 'l5' : $np ? 'Xi' : 'l1',