Image-Bitmap2Paths

 view release on metacpan or  search on metacpan

script/hex2font.pl  view on Meta::CPAN

          my $Xl = $X - $eps_px_size;	my $Xr = $X + $eps_px_size;
          my $Yt = $Y + $eps_px_size;	my $Yb = $Y - $eps_px_size;
          print <<EOP;
$Xl $Y m 1
  $X $Yt l 1
  $Xr $Y l 1
  $X $Yb l 1
  $Xl $Y l 1
EOP
          next;
        }
        $_ ||= 0 for $merge_prev, $merge_next;
        my $no_mid;
        if ($merge_prev and $merge_next) {
          if ($len2 > 4) {
            $merge_next = $merge_prev = 1/sqrt($len2);		# Contribute length=1 to the curved part
          } else {
            $no_mid = $merge_prev = $merge_next = 0.5;
          } 
        } elsif ($merge_prev) {
          if ($len2 > 1/0.49) {
            $merge_prev = 1/sqrt($len2);
          } else {
            $merge_prev = 0.7;
          } 
        } elsif ($merge_next) {
          if ($len2 >= 1/0.49) {
            $merge_next = 1/sqrt($len2);
          } else {
            $merge_next = 0.7;
          } 
        }
  #  }
  #  for my $i (0..$#DO) {
  #      my($go_through_start_point, $x, $y, $x1, $y1) = @{ $DO[$i] };
  ##      my $do_end = $i != $#DO;
  ##      $do_end ||= $go_through_start_point1;
        if ($go_through_start_point and $i >= 0) {{	# for blobs, fixbug on $i==0 will be handled by close-loop code
          my $X  =  $x * $scale + $xoff;
          my $Y = ($height - $y*($y<0 ? $yscale_bottom : $yscale) - $yoff - $px_descent + 0.5)*$px_size;
          ($X, $Y) = ($prev_X, $prev_Y) if $merge_prev;
          last if $i and $p_X == $X and $p_Y == $Y;
          ($p_X, $p_Y) = ($X, $Y);
          ($s_X, $s_Y) = ($X, $Y) unless $i;
          my ($sp, $how) = ($i ? ('  ', 'l') : ('', 'm'));	# The "breaks" indicate *unwanted* breaks
          print <<EOP;
$sp$X $Y $how 1
EOP
        }}
        if ($merge_prev) {
          my $X  =  $x * $scale + $xoff;
          my $Y = ($height - $y*($y<0 ? $yscale_bottom : $yscale) - $yoff - $px_descent + 0.5)*$px_size;
          my $XX = ($x1 - $x) * $merge_prev + $x;
          my $YY = ($y1 - $y) * $merge_prev + $y;
          $XX  =  $XX * $scale + $xoff;
          $YY = ($height - $YY*($YY<0 ? $yscale_bottom : $yscale) - $yoff - $px_descent + 0.5)*$px_size;
          my($preX, $preY, $postX, $postY) 
            = ($splineP*$X+$splineQ*$prev_X, $splineP*$Y+$splineQ*$prev_Y, $splineP*$X+$splineQ*$XX, $splineP*$Y+$splineQ*$YY);
          # For going with constant speed along a straight line, use equally distanced control points for cubic spline;
          # At t=.5, the point is the weighted average with weights 1,3,3,1; if we want it to be the middle of the arc connecting
          # endpoints, T must divide the interval I=[point,controlpoint] in ratio 3:1; here T is the intersection of I
          # with the tangent at midpoint of the arc.  If C is the intersection of tangents to the spline at endpoints, then
          # controlpoint divides [point,C] in ratio 2:1 for parabolas (and small arcs), and in ratio 0.55:0.45 for arc of 90°
          # (in general, its position on [point,C] is 4/3 · cos α/(1+cos α) ??? for an arc of 2α).
          if ($i >= 0) {
            print <<EOP;
  $preX $preY $postX $postY $XX $YY c 1
EOP
            $break_loop = 0, $go_through_start_point = 1, print <<EOP if $break_loop and !$i ; # Make it interpreted as non-closed
$XX $YY m 1
EOP
            ($p_X, $p_Y) = ($XX, $YY);
          }
          $prev_X = $XX, $prev_Y = $YY if $no_mid;
        }
        $x1 = ($x1 - $x) * (1 - $merge_next) + $x;
        $y1 = ($y1 - $y) * (1 - $merge_next) + $y;
        unless ($no_mid) {
          my $X1  =  $x1 * $scale + $xoff;
          my $Y1 = ($height - $y1*($y1<0 ? $yscale_bottom : $yscale) - $yoff - $px_descent + 0.5)*$px_size;
          $prev_X = $X1;   $prev_Y = $Y1;
          my $is_corner = 1;	# $merge_next ? 0 : 1;
          if ($i >= 0) {
            print <<EOP unless $no_mid;
  $X1 $Y1 l $is_corner
EOP
            $break_loop = 0, $go_through_start_point = 1, print <<EOP if $break_loop and !$i; # Make it interpreted as non-closed
$X1 $Y1 m 1
EOP
            ($p_X, $p_Y) = ($X1, $Y1);
          }
        }
        if ($BLOB and $i == $#DO and ($s_X != $p_X or $s_Y != $p_Y)) {
          print <<EOP;		# finish the loop
  $s_X $s_Y l 1
EOP
        }
    }
  }

  for my $e (@$entryPoint) {		# coarse_blobs
    my($c, $x, $y, $dir, $C) = (0, @$e);
    my $X = $x * $scale + $xoff;
    my $Y = ($height - $y*($y<0 ? $yscale_bottom : $yscale) - $yoff - $px_descent + 0.5)*$px_size;
    my($dx,$dy) = ($dx[($dir-2)%8], $dy[($dir-2)%8]);
    $X += $dx * $eps_px_size; $Y -= $dy * $eps_px_size;
    print <<EOP;
$X $Y m 1
EOP
    while ($c++ < $C) {
      ($x,$y,$dir) = @{ $nextEdge->[$dir][$y][$x] };
      $X = $x * $scale + $xoff;
      $Y = ($height - $y*($y<0 ? $yscale_bottom : $yscale) - $yoff - $px_descent + 0.5)*$px_size;
      ($dx,$dy) = ($dx[($dir-2)%8], $dy[($dir-2)%8]);
      $X += $dx * $eps_px_size; $Y -= $dy * $eps_px_size;
    print <<EOP;
  $X $Y l 1
EOP
    }
  }
  print << "END";
EndSplineSet



( run in 0.816 second using v1.01-cache-2.11-cpan-524268b4103 )