source: recognise [sample] text include references
[sheet.git] / writing-latn.inc.pl
index c9c655cb8df8d84ec91c71a120b225ded2e2489a..c7bc11cb9d267126651638017abee052c385498a 100644 (file)
@@ -1,10 +1,48 @@
 use 5.014;
 use utf8;
+use warnings;
 use List::Util qw( pairs pairmap sum );
 
-my %C = qw(red #EC1C24  blue #3953A3  yellow #F9EC31  black #231F20);
+my %C = (
+       red    => '#EC1C24',
+       blue   => '#3953A3',
+       yellow => '#F9EC31',
+       black  => '#231F20',
+);
 my $U = 0;  # optional unicode alternatives
 
+my @wrapstyle = (
+       'td { white-space: normal; word-spacing: 10em }',
+               # force line break between words
+       '.sample { word-spacing: 0 }',
+       '.sample span { margin-right: 1ex; white-space: nowrap; display: inline-block }',
+               # larger space between letters
+);
+my $spacestyle = '.sample span { margin-right: 0.5ex }';  # separate letters
+my @tapstyle = (
+       @wrapstyle,
+       '{ line-height: 1ex }',
+       'td:not(.sample) { vertical-align: top }',
+       '.sample { font-size: 80% }',
+);
+
+my @hueorder = (
+       2,11,20,19,18,21,24,15,6,7,8,5,13, # red .. magenta, grey
+       1,10,9,12,3,4,0, 14,23,22,25,16,17,26, # dark, light hues
+);
+
+# Order to put similar sounds close to each other:
+#        ┌ R Y G C B M X
+#       ┌┼──────────────
+#       W│ o e y h s f -
+#        │muaixqgkdtbp l
+#       K│ w n j c z v r
+
+my @hueletters = ((26) x 27);
+@hueletters[map { ord($_) - ord('a') } qw(
+       u a i x q g k d t b p m l   w n j c z v r   o e y h s f
+)] = @hueorder;
+
 sub disptap {
        my $code = shift;
        my ($prefix, @dots) = $code =~ m/\A(-?)(\d)(\d)/ or return $code;
@@ -37,21 +75,51 @@ sub dispbar {
        );
 }
 
+sub disphues {
+       my ($index, $hues, $opaque) = @_;
+       $index >= 0 or $index = 26;
+       my @lum = ($index % 3, $index / 3 % 3, $index / 9);  # hue opacities (0..2)x3
+       my @lumf = $opaque ? ('hsl(%s,100%%,50%%)', 'hsl(%s,100%%,25%%)') :
+               ('hsl(%s,100%%,50%%)', 'hsla(%s,100%%,50%%,.5)');
+       return sprintf(
+               '<svg width="16" height="16" viewBox="0 0 12 12">%s</svg>',
+               join '', map {
+                       my $colf = $lumf[ $lum[$_] ];
+                       !$colf ? () : sprintf('<circle cx="%d" cy="%d" r="%d" fill="%s"/>',
+                               5 + $_, $_ == 1 ? 7 : 5, 5, sprintf($colf, $hues->[$_])
+                       );
+               } 0 .. 2
+       );
+}
+
 (
-'Uppercase' => {
+uppercase => {
        list => [qw{ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z }],
 },
-'Lowercase' => {
+lowercase => {
        list => [qw{ a b c d e f g h i j k l m n o p q r s t u v w x y z }],
 },
-'Sütterlin' => {
+suetterlin => {
+       title => 'Sütterlin',
+       style => [
+               '@font-face {
+                       font-family: Suetterlin; /* R. G. Arens */
+                       src: url("/suetterlin.ttf");
+               }',
+               'td { font-family: Suetterlin }',
+       ],
        list => [qw{ a b c d e f g h i j k l m n o p q r ſ s t u v w x y z }],
 },
-'Old Roman Cursive' => {
+roman => {
+       title => 'Old Roman Cursive',
+       style => [
+               'svg path { stroke-linecap: round; stroke-linejoin: round }',
+               '.sample span { margin-right: -10px }',
+       ],
        list => [
                map {
-                       !m/^(-?)(\w.+)/ ? $_ :
-                       $1.'<svg width="20" height="20" viewBox="0 0 12 20"><path d="'.$2.'"/></svg>'
+                       s{\A-?\K(\w.+)}
+                        {<svg width="20" height="20" viewBox="0 0 12 20"><path d="$1"/></svg>}r
                }
                "m2,4 c1,2 8,9 8,9 M2,15 6,9",
                "m2,4 c0,0 3,-2 4,1 1,2 0,9 3,9 1,-0 2,-1 2,-1 m-6,-2 c-5,4 -0,6 1,3",
@@ -81,7 +149,9 @@ sub dispbar {
                "-m3,6 c4,-1 3,3 3,3 -1,3 -2,5 -1,5 1,1 3,0 3,0",
        ],
 },
-'Sutton <abbr title="American Sign Lanugage">ASL</abbr>' => {
+sutton => {
+       title => 'Sutton <abbr title="American Sign Lanugage">ASL</abbr>',
+       style => $spacestyle,
        list => [
                # American manual alphabet in Sutton (U+1D800+) notation
                map { !!$_ && pack 'W*', map { hex "1D$_" } unpack '(A3)*', $_ } qw{
@@ -94,7 +164,10 @@ sub dispbar {
                0         965aa6
        }],
 },
-'Unistrokes' => {
+unistrokes => {
+       title => 'Unistrokes',
+       url   => 'https://www.google.com/patents/US5596656', # by Xerox
+       style => 'svg path { stroke-linecap: round; stroke-linejoin: round }',
        list => [
                map { '<svg width="14" height="16" viewBox="-1 -1 8 10">'.$_.'</svg>' }
                map {
@@ -130,18 +203,48 @@ sub dispbar {
                'M3,4',
        ],
 },
-# 'Palm Graffiti' => {},
-'<abbr title="International Telegraph Alphabet">ITA</abbr>2' => {
+edgewrite => {
+       title => 'EdgeWrite',
+       url   => 'http://depts.washington.edu/ewrite/', # patented US7729542
+       style => 'svg path { stroke-linecap: round; stroke-linejoin: round }',
+       list => [
+               map { '<svg width="14" height="14" viewBox="-1 -1 10 10">'.$_.'</svg>' }
+               map {
+                       my @route = split //;
+                       my @coords = map { $_ % 2 << 3, $_ >> 1 << 3 } @route; # x,y,
+                       sprintf('<circle cx="%s" cy="%s" r="1"/><path d="M%s"/>',
+                               @coords[0, 1],  # start point
+                               join(' ', map {
+                                       my $pos = join(',', @coords[$_*2, $_*2 + 1]);
+                                       $_ > 1 && $route[$_] == $route[$_ - 2] # curve back
+                                               ? 'Q4,4 '.$pos.'L' : $pos
+                               } 0 .. $#route),
+                       )
+               }
+               # corners (0..3) clockwise from top-left in order
+               qw(
+                       213 0232 1023 1323 103 102 10132 0213 02 132 02123 023 20313 2031
+                       10231 0102 10131 201 1032 013 0231 021 02131 0312 0313 0123  01
+               )
+       ],
+},
+#graffiti => {
+#      title => 'Palm Graffiti',
+#},
+ita2 => {
+       title => '<abbr title="International Telegraph Alphabet">ITA</abbr>2',
+       style => [@wrapstyle, 'td { font-size: 50% }'],
        list => [map { tr/01/○●/r =~ s/..\K/ /r } qw(
                11000 10011 01110 10010 10000 10110 01011 00101 01100 11010 11110 01001 00111
                00110 00011 01101 11101 01010 10100 00001 11100 01111 11001 10111 10101 10001
                00100
        )],
 },
-'Braille' => {
+braille => {
        list => [qw{ ⠁ ⠃ ⠉ ⠙ ⠑ ⠋ ⠛ ⠓ ⠊ ⠚ ⠅ ⠇ ⠍ ⠝ ⠕ ⠏ ⠟ ⠗ ⠎ ⠞ ⠥ ⠧ ⠺ ⠭ ⠽ ⠵ }],
 },
-'5-point Tactile' => {
+tactile => {
+       title => '5-point Tactile',
        list => [
                map { '<svg width="9" height="12" viewBox="0 0 18 24">'.$_.'</svg>' }
                map {
@@ -158,31 +261,39 @@ sub dispbar {
                }
        ],
 },
-'Morse' => {
+morse => {
+       style => $spacestyle,
        list => [map {tr/.-/‧‑/r} qw{
                .- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. --
                -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..
        }],
 },
-'Tap code' => {
+tap => {
+       title => 'Tap code',
+       style => \@tapstyle,
        list => [map { disptap($_) } qw{
                11 12 13 14 15 21 22 23  > 24 25 31 32
                33 34 35 41 42 43 44 45 51 52 53 54 55
        }],
 },
-'Short Tap' => {
+shorttap => {
+       title => 'Short Tap',
+       style => \@tapstyle,
        list => [map { disptap($_) } qw{
                11 12 13 14 21 22 23 20 > 31 -13 32 33
                30 41 42 -13 43 40 10 51 52 53 50 -31 -40
        }],
 },
-'Cards' => {
+cards => {
+       style => 'td { font-family: Symbola, "DejaVu Sans", serif, sans }',
        list => [(
                map { chr(0x1F0A0 + $_), sprintf('<b>%s</b>', chr(0x1F0B0 + $_)) }  # spades, hearts
                1 .. 11, 13, 14  # A 2-10 J Q K
        ), '', chr(0x1F0CF), chr(0x1F0DF) ],
 },
-'Maritime flags' => {
+maritime => {
+       title => 'Maritime flags',
+       style => $spacestyle,
        list => [
                # International Code of Signals, SVG fills
                map { !!$_ && '<svg width="20" height="20" viewBox="0 0 30 30">'.s/\n?\t+//gr.'</svg>' }
@@ -226,7 +337,8 @@ sub dispbar {
                        <path fill="$C{yellow}" d="M0,0 h15 v15 h-15 M15,15 h15 v15 h-15"/>
 
                        <path fill="white" d="M0,0 h30v30 h-30z"/>
-                       <path fill="$C{blue}" d="M4,0h22l-11,11 M4,30h22l-11,-11 M0,4v22l11,-11 M30,4v22l-11,-11"/>
+                       <path fill="$C{blue}" d="M4,0h22l-11,11 M4,30h22l-11,-11
+                               M0,4v22l11,-11 M30,4v22l-11,-11"/>
 
                        <path fill="white" d="M0,0 h30v30 h-30z"/>
                        <path fill="$C{blue}" d="
@@ -259,7 +371,8 @@ sub dispbar {
                        <path fill="$C{red}" d="M0,0 h15 v15 h-15 M15,15 h15 v15 h-15"/>
 
                        <path fill="$C{red}" d="M0,0 h30v30 h-30z"/>
-                       <path fill="white" d="M4,0h22l-11,11 M4,30h22l-11,-11 M0,4v22l11,-11 M30,4v22l-11,-11"/>
+                       <path fill="white" d="M4,0h22l-11,11 M4,30h22l-11,-11
+                               M0,4v22l11,-11 M30,4v22l-11,-11"/>
 
                        <path fill="$C{blue}" d="M0,0 h30v30 h-30z"/>
                        <path fill="white" d="M5,5 h20 v20 h-20"/>
@@ -270,8 +383,8 @@ sub dispbar {
                        <path fill="$C{blue}" d="M0,12.5 h30 v5 h-30"/>
 
                        <path fill="$C{red}" d="M0,0 h30v30 h-30z"/>
-                       <path fill="$C{yellow}" d="M0,0h6l-6,6 M12,0h6l-18,18v-6 M24,0h6l-30,30v-6
-                               M30,6v6l-18,18h-6 M30,18v6l-6,6h-6"/>
+                       <path fill="$C{yellow}" d="M0,0h6l-6,6 M12,0h6l-18,18v-6
+                               M24,0h6l-30,30v-6 M30,6v6l-18,18h-6 M30,18v6l-6,6h-6"/>
 
                        <path fill="$C{black}" d="M0,0 h30v30 h-30z"/>
                        <path fill="$C{blue}" d="M30,0 v31 l-15,-15"/>
@@ -288,7 +401,8 @@ sub dispbar {
                },
        ],
 },
-'Flag semaphore' => {
+flag => {
+       title => 'Flag semaphore',
        list => [
                map {
                        local $_ = $_;
@@ -303,7 +417,8 @@ sub dispbar {
                )
        ],
 },
-'Chappe semaphore' => {
+chappe => {
+       title => 'Chappe semaphore',
        list => [
                map {
                        my ($r, $pr, $pl) = split //, $_;
@@ -327,7 +442,8 @@ sub dispbar {
                )
        ],
 },
-'Prussian semaphore' => {
+prussian => {
+       title => 'Prussian semaphore',
        list => [
                map { /^\D+$/ ? $_ : sprintf
                        join('',
@@ -349,7 +465,8 @@ sub dispbar {
                )
        ],
 },
-'Code 39' => {
+code39 => {
+       title => 'Code 39',
        list => [map { dispbar($_) } qw(
                2111121121 1121121121 2121121111 1111221121 2111221111 1121221111
                1111122121 2111122111 1121122111 1111222111 2111111221 1121111221
@@ -358,21 +475,24 @@ sub dispbar {
                2211211111 1221211111            1221112111 0 1211212111
        )], # ISO/IEC 16388
 },
-'Code 93' => {
+code93 => {
+       title => 'Code 93',
        list => [map { dispbar($_) } qw(
                211113 211212 211311 221112 221211 231111 112113 112212 112311 122112
                132111 111123 111222 111321 121122 131121 212112 212211 211122 211221
                221121 222111 112122 112221 122121 123111        311211 0 111141
        )],
 },
-'Code 128' => {
+code128 => {
+       title => 'Code 128',
        list => [map { dispbar($_) } qw(
                111323 131123 131321 112313 132113 132311 211313 231113 231311 112133
                112331 132131 113123 113321 133121 313121 211331 231131 213113 213311
-               213131 311123 311321 331121 312113 312311        212222 0 211412 2331112
+               213131 311123 311321 331121 312113 312311      212222 0 211412 23311120
        )],
 },
-'<abbr title="Royal Mail 4-State Customer Code">RM4SCC</abbr>' => {
+rm4scc => {
+       title => '<abbr title="Royal Mail 4-State Customer Code">RM4SCC</abbr>',
        list => [
                map {
                        my $len = length $_;
@@ -399,10 +519,39 @@ sub dispbar {
                '', 1, 3  # start/end
        ],
 },
-"D'ni" => {
+rgbmap => {
+       title => 'RGBmap',
+       style => [
+               'svg { isolation: isolate }',
+               'svg circle { mix-blend-mode: screen }',
+               '.sample { background: black }',
+       ],
+       list => [
+               map { disphues($_, [0, 240, 120], 1) } # Red, Blue, Green
+               @hueorder[23..25,20..22, 12, 6..11,0..5, 16..18, 13..15, 19, 26],
+       ],
+},
+cmymap => {
+       title => 'CMYmap',
+       style => [
+               'svg { isolation: isolate }',  # mix on white
+               'svg circle { mix-blend-mode: multiply }',
+               '.sample { background: white }',
+       ],
+       list => [
+               map { disphues($_, [180, 60, 300]) } # Cyan, Yellow, Magenta
+#              @hueorder[13..18, 19, 0..11, 20..25, 12, 26],
+               @hueletters
+       ],
+},
+dni => {
+       title => "D'ni",
+       style => [
+               'svg { border: 1px solid currentColor }',
+               '.sample span + span svg { border-left: 0 }',
+       ],
        list => [
                map {
-                       state $window = 'M-.5,-.5H8.5V8.5H-.5Z';
                        state $v = [
                                '',
                                'M0,4 8,4',
@@ -419,12 +568,18 @@ sub dispbar {
                                'M4,-.5 0,4 4,8.5',
                                'M4,8 4,2 8,2',
                        ];
-                       sprintf '<svg width="16" height="16" viewBox="-.5 -.5 9 9"><path d="%s"/></svg>',
-                               $window . ($h->[$_ % 5] . $v->[$_ / 5] || $v->[6]);
+                       sprintf(
+                               '<svg width="16" height="16" viewBox="0 0 8 8"><path d="%s"/></svg>',
+                               $h->[$_ % 5] . $v->[$_ / 5] || $v->[6],
+                       );
                } 0 .. 5*5
        ],
 },
-'Pigpen' => {
+pigpen => {
+       style => [
+               'svg path { stroke-linecap: square }',
+               '.sample svg { margin-right: 0.1em }',
+       ],
        list => [
                map {
                        qq(<svg width="12" height="12" viewBox="-.5 -.5 7 7">$_</svg>)
@@ -448,7 +603,15 @@ sub dispbar {
                ),
        ],
 },
-'Nyctographs' => {
+nyctographs => {
+       style => [
+               'svg path { stroke-linecap: round; stroke-linejoin: round }',
+               '.sample svg {
+                       background: rgba(0,0,0, .1);
+                       padding: 0.1em;
+                       margin-right: 0.2em;
+               }',
+       ],
        list => [
                map { s/M[\d,\hM]+(?=[M"])//gr }  # clean up superfluous moves
                map { sprintf
@@ -461,26 +624,29 @@ sub dispbar {
                # draw style (0=empty, 1=dot, 2=line connect) to right, down, left, up
                qw(
                        0010 0112 2022 2220 2000 2012 0122 0202 0020 0220 0012 0022 2202
-                       0222 2222 0102 0200 2201 2002 2200 0100 0110 0120 2001 2010 2020 0
+                       0222 2222 0102 0200 2201 2002 2200 0100 0110 0120 2001 2010 2020
+                       0000
                ),
        ],
 },
-'Chromacons' => {
+chromacons => {
+#      style => '.sample { word-break: break-all }',
        list => [
                # Colour Alphabet by Paul Green-Armytage (2010)
                map {
                        sprintf('<span%s>%s</span>',
                                !!$_ && sprintf(' style="background:#%s" title="%s"', split /:/),
-                               chr(8195), # em space
+                               chr(8195) . (!$_ && chr(8203)) # em space (plus zwsp for spaces)
                        );
                }
                qw{
-                       F0A3FF:Amethyst 0075DC:Blue      993F00:Caramel  4C005C:Damson   191919:Ebony
-                       005C31:Forest   2BCE48:Green     FFCC99:Honeydew 808080:Iron     94FFB5:Jade
-                       8F7C00:Khaki    9DCC00:Lime      C20088:Mallow
-                       003380:Navy     FFA405:Orpiment  FFA8BB:Pink     426600:Quagmire FF0010:Red
-                       5EF1F2:Sky      00998F:Turquoise E0FF66:Uranium  740AFF:Violet   990000:Wine
-                       FFFF80:Xanthin  FFFF00:Yellow    FF5005:Zinnia   0
+                       F0A3FF:Amethyst 0075DC:Blue     993F00:Caramel  4C005C:Damson
+                       191919:Ebony    005C31:Forest   2BCE48:Green    FFCC99:Honeydew
+                       808080:Iron     94FFB5:Jade     8F7C00:Khaki    9DCC00:Lime
+                       C20088:Mallow   003380:Navy     FFA405:Orpiment FFA8BB:Pink
+                       426600:Quagmire FF0010:Red      5EF1F2:Sky      00998F:Turquoise
+                       E0FF66:Uranium  740AFF:Violet   990000:Wine     FFFF80:Xanthin
+                       FFFF00:Yellow   FF5005:Zinnia   0
                }
        ],
 },