#!/usr/bin/perl # Build example map numbering tables for 臺灣地區像片基本圖圖幅 # orthophotomap numbering, via the following ugly program. # Author: Dan Jacobson. See https://www.jidanni.org/geo/special.html # Copyright: https://www.gnu.org/licenses/gpl.html # Created: 2024-12-06T19:07:59+0000 # Last-Updated: 2024-12-10T00:25:55+0000 # Update #: 154 # use strict; use warnings q(all); use XML::LibXML; my $body = XML::LibXML::Element->new('body'); # a Lazy HTML method my $o = XML::LibXML::Element->new('ol'); $body->appendChild($o); my @s = ( 10, 5 ); for (@s) { for my $st ( 1, 0 ) { fff( { title => "1:" . $s[ $_ / 5 - 1 ] * 1000, start => $st, dimension => $_, format => $st ? "sequential" : "YX" } ); } } print $body->toString(1); sub fff { my $d = $_[0]; my $width = length( $d->{dimension}**2 - 1 + $d->{start} ); my $l = XML::LibXML::Element->new('li'); $o->appendChild($l); my $h = XML::LibXML::Element->new('h4'); $l->appendChild($h); $h->appendText( sprintf "%s %0${width}d..%0${width}d (%s)", $d->{title}, $d->{start}, ( $d->{format} eq "sequential" ? ( $d->{dimension}**2 + $d->{start} - 1 ) : ( ( ( $d->{dimension} - 1 ) x 2 ) + $d->{start} ) ), $d->{format} ); $h->setAttribute( "id", join ".", "_", sort values %$d ); my $table = XML::LibXML::Element->new('table'); $l->appendChild($table); $table->setAttribute( "border", 1 ); $table->setAttribute( "class", "rows_cols_" . $d->{dimension} ); for my $row ( 0 .. $d->{dimension} - 1 ) { my $tr; if ( $row == 0 || $row == 1 || $row == $d->{dimension} - 1 ) { $tr = XML::LibXML::Element->new('tr'); $table->appendChild($tr); } elsif ( $row == 2 ) { my $tr = XML::LibXML::Element->new('tr'); my $td = XML::LibXML::Element->new('td'); $tr->appendChild($td); $td->setAttribute( "colspan", $d->{dimension} ); ## $td->appendText("…"); # see note at XML::LibXML::Document createEntityReference $td->appendText("..."); $table->appendChild($tr); } for ( 0 .. $d->{dimension} - 1 ) { if ( defined $tr ) { my $td = XML::LibXML::Element->new('td'); $tr->appendChild($td); $td->appendText( sprintf "%0${width}d", $d->{format} eq "sequential" ? ( $row * $d->{dimension} + $_ + $d->{start} ) : ( ( $row . $_ ) + $d->{start} ) ); } } } } # Local Variables: # compile-command: "perl sheet_num | w3m -T text/html | cat" # End: