Index: trunk/extensions/timeline/EasyTimeline.pl |
— | — | @@ -59,7 +59,7 @@ |
60 | 60 | # - dot in folder name in input path was misunderstood as start of file extension |
61 | 61 | # - utf-8 chars within 160-255 range are translated to extended ascii |
62 | 62 | # however internal font used by Ploticus has strange mapping so some are replaced |
63 | | -# by undercore or unaccented version of character |
| 63 | +# by underscore or unaccented version of character |
64 | 64 | # this is a make do solution until full unicode support with external fonts will be added |
65 | 65 | # |
66 | 66 | # 1.12 June 2009 |
— | — | @@ -70,8 +70,9 @@ |
71 | 71 | # - change svg encoding from iso-8859-1 -> UTF-8 |
72 | 72 | # - allow font to be specified using -f option as opposed to hardcoded FreeSans. |
73 | 73 | |
| 74 | +use 5.010; |
| 75 | + |
74 | 76 | use strict; |
75 | | -use warnings; |
76 | 77 | |
77 | 78 | our $VERSION = '1.90'; |
78 | 79 | |
— | — | @@ -82,6 +83,8 @@ |
83 | 84 | |
84 | 85 | # Global variables. |
85 | 86 | # Many of these should be refactored. |
| 87 | +my $SVG_ONLY = 0; |
| 88 | + |
86 | 89 | my @PlotLines; |
87 | 90 | my $CntErrors = 0; |
88 | 91 | my @Errors; |
— | — | @@ -290,6 +293,10 @@ |
291 | 294 | $articlepath = "http://en.wikipedia.org/wiki/\$1"; |
292 | 295 | } |
293 | 296 | |
| 297 | + if (defined $options{"s"}) { |
| 298 | + $SVG_ONLY = 1; |
| 299 | + } |
| 300 | + |
294 | 301 | if (!-e $file_in) { |
295 | 302 | &Abort("Input file '" . $file_in . "' not found."); |
296 | 303 | } |
— | — | @@ -310,8 +317,6 @@ |
311 | 318 | $file_html = $file . ".html"; |
312 | 319 | $file_errors = $file . ".err"; |
313 | 320 | |
314 | | - # $file_pl_info = $file . ".inf" ; |
315 | | - # $file_pl_err = $file . ".err" ; |
316 | 321 | print "Output: Image files $file_bitmap & $file_vector\n"; |
317 | 322 | |
318 | 323 | if ($linkmap) { |
— | — | @@ -332,10 +337,6 @@ |
333 | 338 | sub SetImageFormat { |
334 | 339 | $env = ""; |
335 | 340 | |
336 | | - # $dir = cwd() ; # is there a better way to detect OS? |
337 | | - # if ($dir =~ /\//) { $env = "Linux" ; $image_file_fmt = "png" ; $pathseparator = "/";} |
338 | | - # if ($dir =~ /\\/) { $env = "Windows" ; $image_file_fmt = "gif" ; $pathseparator = "\\";} |
339 | | - # cwd always to returns '/'s ? -> |
340 | 341 | if ($OSNAME =~ /darwin/i) { |
341 | 342 | $env = "Linux"; |
342 | 343 | $image_file_fmt = "png"; |
— | — | @@ -346,7 +347,11 @@ |
347 | 348 | $image_file_fmt = "gif"; |
348 | 349 | $pathseparator = "\\"; |
349 | 350 | } |
350 | | - else { $env = "Linux"; $image_file_fmt = "png"; $pathseparator = "/"; } |
| 351 | + else { |
| 352 | + $env = "Linux"; |
| 353 | + $image_file_fmt = "png"; |
| 354 | + $pathseparator = "/"; |
| 355 | + } |
351 | 356 | |
352 | 357 | if ($env ne "") { |
353 | 358 | print |
— | — | @@ -646,12 +651,12 @@ |
647 | 652 | if ( ($name ne "bar") |
648 | 653 | && ($name ne "text") |
649 | 654 | && ($name ne "link") |
650 | | - && ($name ne "legend")) # && ($name ne "hint") |
| 655 | + && ($name ne "legend")) |
651 | 656 | { |
652 | 657 | $value = lc($value); |
653 | 658 | } |
654 | 659 | |
655 | | - if ($name eq "link") # restore colon |
| 660 | + if ($name eq "link") # restore colon |
656 | 661 | { |
657 | 662 | $value =~ s/'colon'/:/; |
658 | 663 | } |
— | — | @@ -678,7 +683,9 @@ |
679 | 684 | } |
680 | 685 | } |
681 | 686 | } |
682 | | - if (($name ne "") && ($Attributes{"single"} ne "")) { |
| 687 | + if ( (defined $name and $name ne "") |
| 688 | + and (defined $Attributes{"single"} and $Attributes{"single"} ne "")) |
| 689 | + { |
683 | 690 | &Error( "Invalid attribute '" |
684 | 691 | . $Attributes{"single"} |
685 | 692 | . "' ignored.\nSpecify attributes as 'name:value' pairs."); |
— | — | @@ -1386,7 +1393,6 @@ |
1387 | 1394 | } |
1388 | 1395 | } |
1389 | 1396 | } |
1390 | | - |
1391 | 1397 | elsif ($attribute =~ /BarIncrement/i) { |
1392 | 1398 | if (!&ValidAbs($attrvalue)) { |
1393 | 1399 | &Error( "ImageSize attribute '$attribute' invalid.\n" |
— | — | @@ -1397,11 +1403,6 @@ |
1398 | 1404 | |
1399 | 1405 | $Attributes{"barinc"} = $attrvalue; |
1400 | 1406 | } |
1401 | | - |
1402 | | - # if ($attribute =~ /Width/i) |
1403 | | - # { $Attributes{"width"} = $attrvalue ; } |
1404 | | - # elsif ($attribute =~ /Height/i) |
1405 | | - # { $Attributes{"height"} = $attrvalue ; } |
1406 | 1407 | } |
1407 | 1408 | |
1408 | 1409 | if ( ($Attributes{"width"} =~ /auto/i) |
— | — | @@ -1756,7 +1757,7 @@ |
1757 | 1758 | while ((!$InputParsed) && (!$NoData)) { |
1758 | 1759 | if (!&ValidAttributes("PlotData")) { &GetData; next; } |
1759 | 1760 | |
1760 | | - $bar = ""; # $barset = "" ; |
| 1761 | + $bar = ""; |
1761 | 1762 | $at = ""; |
1762 | 1763 | $from = ""; |
1763 | 1764 | $till = ""; |
— | — | @@ -1780,7 +1781,6 @@ |
1781 | 1782 | |
1782 | 1783 | if (defined($PlotDefs{"bar"})) { $bar = $PlotDefs{"bar"}; } |
1783 | 1784 | |
1784 | | - # if (defined ($PlotDefs{"barset"})) { $barset = $PlotDefs{"barset"} ; } |
1785 | 1785 | if (defined($PlotDefs{"color"})) { $color = $PlotDefs{"color"}; } |
1786 | 1786 | if (defined($PlotDefs{"bgcolor"})) { |
1787 | 1787 | $bgcolor = $PlotDefs{"bgcolor"}; |
— | — | @@ -2143,7 +2143,6 @@ |
2144 | 2144 | { |
2145 | 2145 | if ($bar ne "") { $PlotDefs{"bar"} = $bar; } |
2146 | 2146 | |
2147 | | - # if ($barset ne "") { $PlotDefs{"barset"} = $barset ; } |
2148 | 2147 | if ($color ne "") { $PlotDefs{"color"} = $color; } |
2149 | 2148 | if ($bgcolor ne "") { $PlotDefs{"bgcolor"} = $bgcolor; } |
2150 | 2149 | if ($textcolor ne "") { $PlotDefs{"textcolor"} = $textcolor; } |
— | — | @@ -2156,8 +2155,6 @@ |
2157 | 2156 | if ($mark ne "") { $PlotDefs{"mark"} = $mark; } |
2158 | 2157 | if ($markcolor ne "") { $PlotDefs{"markcolor"} = $markcolor; } |
2159 | 2158 | |
2160 | | - # if ($link ne "") { $PlotDefs{"link"} = $link ; } |
2161 | | - # if ($hint ne "") { $PlotDefs{"hint"} = $hint ; } |
2162 | 2159 | &GetData; |
2163 | 2160 | next PlotData; |
2164 | 2161 | } |
— | — | @@ -2606,8 +2603,7 @@ |
2607 | 2604 | $textcolor = $TextDefs{"textcolor"}; |
2608 | 2605 | } |
2609 | 2606 | |
2610 | | - # warn "data: $data"; # XXX $data is probably not really used |
2611 | | - my $data2; # = $data; # XXX see above |
| 2607 | + my $data2; |
2612 | 2608 | ($data2, $text) = &ExtractText($data2); |
2613 | 2609 | @Attributes = split(" ", $data2); |
2614 | 2610 | |
— | — | @@ -2724,9 +2720,6 @@ |
2725 | 2721 | $TextDefs{"pos"} = $pos; |
2726 | 2722 | } |
2727 | 2723 | |
2728 | | - # if ($link ne "") |
2729 | | - # { ($text, $link, $hint) = &ProcessWikiLink ($text, $link, $hint) ; } |
2730 | | - |
2731 | 2724 | if ($text eq "") # upd defaults |
2732 | 2725 | { |
2733 | 2726 | if ($pos ne "") { $TextDefs{"pos"} = $pos; } |
— | — | @@ -3453,14 +3446,6 @@ |
3454 | 3447 | if ($Axis{"time"} eq "x") { $AxisBars = "y"; } |
3455 | 3448 | else { $AxisBars = "x"; } |
3456 | 3449 | |
3457 | | - # if (($Axis{"time"} eq "y") && ($#Bars > 0)) |
3458 | | - # { |
3459 | | - # undef @BarsTmp ; |
3460 | | - # while ($#Bars >= 0) |
3461 | | - # { push @BarsTmp, pop @Bars ; } |
3462 | | - # @Bars = @BarsTmp ; |
3463 | | - # } |
3464 | | - |
3465 | 3450 | my $file_script; |
3466 | 3451 | if ($tmpdir ne "") { |
3467 | 3452 | $file_script = $tmpdir . $pathseparator . "EasyTimeline.txt.$$"; |
— | — | @@ -3469,16 +3454,10 @@ |
3470 | 3455 | $file_script = "EasyTimeline.txt"; |
3471 | 3456 | } |
3472 | 3457 | |
3473 | | - print "Ploticus input file = " . $file_script . "\n"; |
| 3458 | + print "Ploticus input file = $file_script\n"; |
3474 | 3459 | |
3475 | | - # $image_file_fmt = "gif" ; |
3476 | 3460 | open "FILE_OUT", ">", $file_script; |
3477 | 3461 | |
3478 | | - #proc settings |
3479 | | - # $script .= "#proc settings\n" ; |
3480 | | - # $script .= " xml_encoding: utf-8\n" ; |
3481 | | - # $script .= "\n" ; |
3482 | | - |
3483 | 3462 | # proc page |
3484 | 3463 | $script .= "#proc page\n"; |
3485 | 3464 | $script .= " dopagebox: no\n"; |
— | — | @@ -3689,7 +3668,6 @@ |
3690 | 3669 | |
3691 | 3670 | $script .= "\n([inc3])\n\n"; # will be replace by rects |
3692 | 3671 | |
3693 | | - # %x = %BarWidths; # XXX doesn't seem to be used |
3694 | 3672 | my ($bar, $width); |
3695 | 3673 | foreach my $entry (@PlotLines) { |
3696 | 3674 | ($bar) = split(",", $entry); |
— | — | @@ -3701,8 +3679,11 @@ |
3702 | 3680 | @PlotBarsNow = @PlotLines; |
3703 | 3681 | &PlotBars; |
3704 | 3682 | |
3705 | | - my ($scriptPng1, $scriptPng2, $scriptPng3); |
3706 | | - my ($scriptSvg1, $scriptSvg2); |
| 3683 | + my $scriptPng1 = q{}; |
| 3684 | + my $scriptPng2 = q{}; |
| 3685 | + my $scriptPng3 = q{}; |
| 3686 | + my $scriptSvg1 = q{}; |
| 3687 | + my $scriptSvg2 = q{}; |
3707 | 3688 | |
3708 | 3689 | #proc axis |
3709 | 3690 | if ($#Bars > 0) { |
— | — | @@ -3853,11 +3834,6 @@ |
3854 | 3835 | $scriptSvg1 .= "\n"; |
3855 | 3836 | } |
3856 | 3837 | |
3857 | | - # $script .= "#proc symbol\n" ; |
3858 | | - # $script .= " location: 01/01/1943(s) Korea \n" ; |
3859 | | - # $script .= " symbol: style=fill shape=downtriangle fillcolor=white radius=0.04\n" ; |
3860 | | - # $script .= "\n" ; |
3861 | | - |
3862 | 3838 | #proc axis |
3863 | 3839 | # repeat without grid to get axis on top of bar |
3864 | 3840 | # needed because axis may overlap bar slightly |
— | — | @@ -3959,16 +3935,17 @@ |
3960 | 3936 | |
3961 | 3937 | my $map = ($MapSVG) ? "-map" : ""; |
3962 | 3938 | |
3963 | | - print "Running Ploticus to generate svg file\n"; |
| 3939 | + print "Running Ploticus to generate svg file $file_vector\n"; |
3964 | 3940 | |
3965 | | - # my $cmd = "$pl $map -" . "svg" . " -o $file_vector $file_script -tightcrop -font \"Times\"" ; |
3966 | | - # my $cmd = "$pl $map -" . "svg" . " -o $file_vector $file_script -tightcrop" ; |
| 3941 | + my $escaped_font_file = EscapeShellArg($font_file); |
3967 | 3942 | my $cmd = |
3968 | 3943 | EscapeShellArg($pl) |
3969 | 3944 | . " $map -" . "svg" . " -o " |
3970 | 3945 | . EscapeShellArg($file_vector) . " " |
3971 | 3946 | . EscapeShellArg($file_script) |
3972 | | - . " -tightcrop -xml_encoding UTF-8"; |
| 3947 | + . " -tightcrop" |
| 3948 | + . " -font '$escaped_font_file'" |
| 3949 | + . " -xml_encoding UTF-8"; |
3973 | 3950 | print "$cmd\n"; |
3974 | 3951 | system($cmd); |
3975 | 3952 | |
— | — | @@ -4004,11 +3981,8 @@ |
4005 | 3982 | $map = ''; |
4006 | 3983 | } |
4007 | 3984 | |
4008 | | - # $crop = "-crop 0,0," + $ImageSize{"width"} . "," . $ImageSize{"height"} ; |
4009 | | - print "Running Ploticus to generate bitmap\n"; |
| 3985 | + print "Running Ploticus to generate bitmap file $file_bitmap\n"; |
4010 | 3986 | |
4011 | | - # $cmd = "$pl $map -" . $image_file_fmt . " -o $file_bitmap $file_script -tightcrop" ; # -v $file_bitmap" ; |
4012 | | - # $cmd = "$pl $map -" . $image_file_fmt . " -o $file_bitmap $file_script -tightcrop -diagfile $file_pl_info -errfile $file_pl_err" ; |
4013 | 3987 | $cmd = |
4014 | 3988 | EscapeShellArg($pl) |
4015 | 3989 | . " $map -" |
— | — | @@ -4076,18 +4050,38 @@ |
4077 | 4051 | } |
4078 | 4052 | |
4079 | 4053 | if (-e $file_vector) { |
4080 | | - open "FILE_IN", "<", $file_vector; |
4081 | | - my @svg = <FILE_IN>; |
4082 | | - close "FILE_IN"; |
| 4054 | + open my $file_vector_handle, '<', $file_vector |
| 4055 | + or Abort("Can't open $file_vector for reading: $OS_ERROR"); |
| 4056 | + my @svg = <$file_vector_handle>; |
| 4057 | + close $file_vector_handle |
| 4058 | + or Abort("Can't open $file_vector after reading: $OS_ERROR"); |
4083 | 4059 | |
4084 | 4060 | foreach (@svg) { |
4085 | 4061 | s/\{\{(\d+)\}\}x+/$textsSVG[$1]/gxe; |
4086 | | - s/\[(\d+)\[ (.*?) \]\d+\]/'<a style="fill:blue;" xlink:href="' . $linksSVG[$1] . '">' . $2 . '<\/a>'/gxe; |
| 4062 | + |
| 4063 | + if ($SVG_ONLY) { |
| 4064 | + s{ |
| 4065 | + ( |
| 4066 | + <text |
| 4067 | + .*? |
| 4068 | + ) |
| 4069 | + > |
| 4070 | + \[(\d+)\[ |
| 4071 | + (.*?) |
| 4072 | + \]\d+\] |
| 4073 | + } |
| 4074 | + {$1 style="fill:blue;">$3}gx; |
| 4075 | + } |
| 4076 | + else { |
| 4077 | + s/\[(\d+)\[ (.*?) \]\d+\]/'<a style="fill:blue;" xlink:href="' . $linksSVG[$1] . '">' . $2 . '<\/a>'/gxe; |
| 4078 | + } |
4087 | 4079 | } |
4088 | 4080 | |
4089 | | - open "FILE_OUT", ">", $file_vector; |
4090 | | - print FILE_OUT @svg; |
4091 | | - close "FILE_OUT"; |
| 4081 | + open $file_vector_handle, '>', $file_vector |
| 4082 | + or Abort("Can't open $file_vector for writing: $OS_ERROR"); |
| 4083 | + print {$file_vector_handle} @svg; |
| 4084 | + close $file_vector_handle |
| 4085 | + or Abort("Can't open $file_vector after writing: $OS_ERROR"); |
4092 | 4086 | } |
4093 | 4087 | |
4094 | 4088 | # not for Wikipedia, for offline use: |
— | — | @@ -4184,7 +4178,6 @@ |
4185 | 4179 | } |
4186 | 4180 | else { $ypos = "$at(s)"; $xpos = "[$barcnt](s)"; } |
4187 | 4181 | |
4188 | | - # XXX - $shiftx was defined inside the if block. |
4189 | 4182 | my ($shiftx, $shifty); |
4190 | 4183 | if ($shift ne "") { |
4191 | 4184 | ($shiftx, $shifty) = split(",", $shift); |
— | — | @@ -4270,24 +4263,9 @@ |
4271 | 4264 | my $grid = shift; |
4272 | 4265 | my ($color, $from, $till, $start); |
4273 | 4266 | |
4274 | | - # %x = %Period; # XXX doesn't seem to be used |
4275 | | - |
4276 | | - # if (($DateFormat =~ /\//) && ($grid)) |
4277 | | - # { return ; } |
4278 | | - |
4279 | | - # if (($DateFormat =~ /\//) |
4280 | | - # { |
4281 | | - # } |
4282 | | - |
4283 | | - # if (! $grid) # redefine area, scale linear for time axis, showl whole years always, Ploticus bug |
4284 | | - # { |
4285 | | - # $from = $Period{"from"} ; |
4286 | | - # $till = $Period{"till"} ; |
4287 | 4267 | $from = &DateToFloat($Period{"from"}); |
4288 | 4268 | $till = &DateToFloat($Period{"till"}); |
4289 | 4269 | |
4290 | | - # $from =~ s/.*\///g ; # delete dd mm if present |
4291 | | - # $till =~ s/.*\///g ; |
4292 | 4270 | #proc areadef |
4293 | 4271 | $script .= "#proc areadef\n"; |
4294 | 4272 | $script .= " #clone: A\n"; |
— | — | @@ -4306,15 +4284,10 @@ |
4307 | 4285 | |
4308 | 4286 | $script .= "\n"; |
4309 | 4287 | |
4310 | | - # } |
4311 | | - |
4312 | 4288 | $script .= "#proc " . $Axis{"time"} . "axis\n"; |
4313 | 4289 | |
4314 | 4290 | if (($scale eq "Major") && (!$grid)) { |
4315 | 4291 | |
4316 | | - # $script .= " stubs: incremental " . $Scales{"Major inc"} . " " . $Scales{"Major unit"} . "\n" ; |
4317 | | - # if ($DateFormat =~ /\//) |
4318 | | - # { $script .= " stubformat: " . $Axis{"format"} . "\n" ; } |
4319 | 4292 | # temp always show whole years (Ploticus autorange bug) |
4320 | 4293 | if ($Scales{"Major stubs"} eq "") # ($DateFormat !~ /\//) |
4321 | 4294 | { |
— | — | @@ -4324,10 +4297,7 @@ |
4325 | 4298 | } |
4326 | 4299 | else { $script .= " stubs: none\n"; } |
4327 | 4300 | |
4328 | | - if ($DateFormat !~ /\//) |
4329 | | - |
4330 | | - # { $script .= " ticincrement: " . $Scales{"$scale inc"} . " " . $Scales{"$scale unit"} . "\n" ; } |
4331 | | - { |
| 4301 | + if ($DateFormat !~ /\//) { |
4332 | 4302 | $script .= " ticincrement: " . $Scales{"$scale inc"} . "\n"; |
4333 | 4303 | } |
4334 | 4304 | else { |
— | — | @@ -4340,7 +4310,6 @@ |
4341 | 4311 | if (defined($Scales{"$scale start"})) { |
4342 | 4312 | $start = $Scales{"$scale start"}; |
4343 | 4313 | |
4344 | | - # $start =~ s/.*\///g ; # delete dd mm if present |
4345 | 4314 | $start = &DateToFloat($start); |
4346 | 4315 | if ($Axis{"order"} =~ /reverse/i) { |
4347 | 4316 | my $loop = 0; |
— | — | @@ -4362,10 +4331,10 @@ |
4363 | 4332 | $script .= " signreverse: yes\n"; |
4364 | 4333 | } |
4365 | 4334 | } |
4366 | | - else { $script .= " ticlen: 0.02\n"; } |
| 4335 | + else { |
| 4336 | + $script .= " ticlen: 0.02\n"; |
| 4337 | + } |
4367 | 4338 | |
4368 | | - # $script .= " location: 4\n" ; test |
4369 | | - |
4370 | 4339 | $color .= $Scales{"$scale grid"}; |
4371 | 4340 | |
4372 | 4341 | if (defined($Colors{$color})) { $color = $Colors{$color}; } |
— | — | @@ -4804,7 +4773,9 @@ |
4805 | 4774 | } |
4806 | 4775 | |
4807 | 4776 | # not part of barset ? return |
4808 | | - if ($bar != /\#\d+$/) { return ($false); } |
| 4777 | + if ($bar !~ /\#\d+$/) { |
| 4778 | + return ($false); |
| 4779 | + } |
4809 | 4780 | |
4810 | 4781 | # find previous bar in barset |
4811 | 4782 | my $barcnt = $bar; |
— | — | @@ -4834,10 +4805,7 @@ |
4835 | 4806 | return (CheckAttributes($command, "", "canvas,bars")); |
4836 | 4807 | } |
4837 | 4808 | |
4838 | | - if ($command =~ /^BarData$/i) |
4839 | | - |
4840 | | - # { return (CheckAttributes ($command, "", "bar,barset,barcount,link,text")) ; } |
4841 | | - { |
| 4809 | + if ($command =~ /^BarData$/i) { |
4842 | 4810 | return (CheckAttributes($command, "", "bar,barset,link,text")); |
4843 | 4811 | } |
4844 | 4812 | |
— | — | @@ -4969,8 +4937,11 @@ |
4970 | 4938 | |
4971 | 4939 | my $newcommand = $true; |
4972 | 4940 | my $addvalue = $true; |
4973 | | - my $prevcommand; |
4974 | | - if ($command =~ /^$prevcommand$/i) { $newcommand = $false; } |
| 4941 | + state $prevcommand = q{}; |
| 4942 | + if (lc $command eq lc $prevcommand) { |
| 4943 | + $newcommand = $false; |
| 4944 | + } |
| 4945 | + |
4975 | 4946 | if ((!$newcommand) && ($command =~ /^(?:DrawLines|PlotData|TextData)$/i)) |
4976 | 4947 | { |
4977 | 4948 | $addvalue = $false; |