chiark / gitweb /
improved distance label placement when centrelines drawn
[trains.git] / layout / layout
index d20102316e4e885b4956c60bcc3c9ce069f8f079..31d1daf83046261aadb66e548b9abe00225e4fe0 100755 (executable)
@@ -165,12 +165,11 @@ our $lmu_marklw= 4;
 our $lmu_marktpt= 11;
 our $lmu_txtboxtxty= $lmu_marktpt * 0.300;
 our $lmu_txtboxh= $lmu_marktpt * 1.100;
-our $lmu_lenboxh= $lmu_marktpt * 1.100;
 our $lmu_txtboxpadx= $lmu_marktpt * 0.335;
-our $lmu_lenboxpadx= $lmu_marktpt * 0.005;
 our $lmu_txtboxoff= $lmu_marklw / 2;
-our $lmu_lenboxoff= -$lmu_marklw * 1.0;
 our $lmu_txtboxlw= 1;
+our $lmu_lenlabeloffctr= -$lmu_marklw * 1.0;
+our $lmu_lenlabeloff=     $lmu_marklw * 0.5;
 
 our $olu_left= 10 * $scale;
 our $olu_right= 217 * $scale - $olu_left;
@@ -774,15 +773,18 @@ print DEBUG "ps $p0 $p1 $lenperp ($ppu)\n";
        o("      stroke\n");
     }
     if ($draw =~ m/D/) {
-       my ($pt,$ad,$len);
+       my ($pt,$ad,$len,$off);
        $param= ($p0+$p1)*0.5;
        $pt= &$calcfn;
        $ad= ang2deg($pt->{A});
        $len= sprintf "%.0f", $lenperp * abs($p1-$p0);
+       $off= $draw =~ m/C/ ? $lmu_lenlabeloff : $lmu_lenlabeloffctr;
        ol("      gsave\n".
           "        $pt->{X} $pt->{Y} translate\n".
           "        $ad rotate\n".
-          "        lf setfont  0 $lmu_lenboxoff moveto  ($len) show\n".
+          "        lf setfont\n".
+          "        0 $off moveto\n".
+          "        ($len) show\n".
           "      grestore\n");
     }
     return unless $draw =~ m/[ARS]/;
@@ -1475,8 +1477,19 @@ dv("cmd__do $ctx @al ",'$ctx',$ctx);
                   "      $lmu_marklw setlinewidth stroke\n");
            }
            if ($draw =~ m/L/) {
-               ol("      $lmu_txtboxlw $lmu_txtboxh $lmu_txtboxpadx".
-                  " $lmu_txtboxoff ($id) label_in_box\n");
+               ol("      /s ($id) def\n".
+                  "      lf setfont\n".
+                  "      /sx5  s stringwidth pop\n".
+                  "      0.5 mul $lmu_txtboxpadx add def\n".
+                  "      -90 rotate  0 $lmu_txtboxoff translate  newpath\n".
+                  "      sx5 neg  0             moveto\n".
+                  "      sx5 neg  $lmu_txtboxh  lineto\n".
+                  "      sx5      $lmu_txtboxh  lineto\n".
+                  "      sx5      0             lineto closepath\n".
+                  "      gsave  1 setgray fill  grestore\n".
+                  "      $lmu_txtboxlw setlinewidth stroke\n".
+                  "      sx5 neg $lmu_txtboxpadx add  $lmu_txtboxtxty\n".
+                  "      moveto s show\n");
            }
            ol("      grestore\n");
        }
@@ -1567,28 +1580,6 @@ if ($page_x || $page_y) {
 o("  -$ps_page_xmul $page_x mul  -$ps_page_ymul $page_y mul  translate\n".
   "  $ptscale $ptscale scale\n");
 
-o("/label_in_box {\n".
-  '% linewidth $lmu_*boxh $lmu_*padx $lmu_*boxoff (s)'.
-  '  label_in_box  => _'."\n".
-  "  /s exch def\n".
-  "  /boxoff exch def\n".
-  "  /padx exch def\n".
-  "  /boxh exch def\n".
-  "  setlinewidth\n".
-  "  lf setfont\n".
-  "  /sx5  s stringwidth pop\n".
-  "  0.5 mul padx add def\n".
-  "  -90 rotate  0 boxoff translate  newpath\n".
-  "  sx5 neg  0             moveto\n".
-  "  sx5 neg  boxh  lineto\n".
-  "  sx5      boxh  lineto\n".
-  "  sx5      0             lineto closepath\n".
-  "  gsave  1 setgray fill  grestore\n".
-  "  stroke\n".
-  "  sx5 neg padx add  $lmu_txtboxtxty\n".
-  "  moveto s show\n".
-  "} def\n");
-
 newctx();
 
 open DEBUG, ($debug ? ">&2" : ">/dev/null") or die $!;