Image-Bitmap2Paths
view release on metacpan or search on metacpan
lib/Image/Bitmap2Paths.pm view on Meta::CPAN
$closed = 2, last unless abs(($stroke->[$i][0] - $stroke->[$i-1][0] + 4)%8 - 4) < 2; # At i=0, wraps back to the end
}
}
# $closed &&= -2 if abs(($stroke->[0][1] - $stroke->[-1][1] + 4)%8 - 4) < 2;
my($breaks, $runs) = [0];
if ($closed < 0) { # loop known to be smooth; stroke_2_strokes() won't find anything except ends
$runs = [[0],[$#$stroke+1]]; # fake corners at ends; [0] means: start at 0, no calculated lines until the next
} else {
($runs, $breaks) = stroke_2_strokes($stroke, \%inCalcEdge, $closed); # Meaning: $runs->[$break] starts a new sub-stroke
}
push @strokes, [$closed, !'blob', $stroke, $runs, $breaks]; # (strokes with endpoints: âopenâ)
}
# warn "found open strokes: ", scalar @strokes, "\n";
my(@closedStrokes, %edgesDone);
my @E;
for my $E (sort keys %$tailEdge) { # Best place to cut a closed strokeâââif present.
my $edge = $tailEdge->{$E}; # Need to normalize order, since bugs in fontforge are sensitive to the order
my($x,$y,$dir,$rot) = @$edge;
my $D = ($dir+4)%8;
my $x1 = $x + $dx[$dir];
my $y1 = $y + $dy[$dir]; # the encountered MForks are marked as already visited (by traverse_stroke())
script/hex2font.pl view on Meta::CPAN
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);
( run in 0.565 second using v1.01-cache-2.11-cpan-524268b4103 )