Bugfix in utils/pdf-slices.pl, wrong shift caused slices to be outside the media box

This commit is contained in:
Alessandro Ranellucci 2014-04-11 19:55:15 +02:00
parent 26bdbf0210
commit f9661b02a6
2 changed files with 37 additions and 14 deletions

View File

@ -218,6 +218,17 @@ sub center_instances_around_point {
}
}
sub align_instances_to_origin {
my ($self) = @_;
my $bb = $self->bounding_box;
return if !defined $bb;
my $new_center = $bb->size;
$new_center->translate(-$new_center->x/2, -$new_center->y/2); #//
$self->center_instances_around_point($new_center);
}
sub translate {
my $self = shift;
my @shift = @_;

View File

@ -12,7 +12,7 @@ BEGIN {
use Getopt::Long qw(:config no_auto_abbrev);
use PDF::API2;
use Slic3r;
use Slic3r::Geometry qw(unscale X Y);
use Slic3r::Geometry qw(scale unscale X Y);
use constant mm => 25.4 / 72;
@ -31,16 +31,21 @@ my %opt = ();
# prepare config
my $config = Slic3r::Config->new;
$config->set('layer_height', $opt{layer_height}) if $opt{layer_height};
$config->set('print_center', [0,0]);
# read model
my $model = Slic3r::Model->read_from_file(my $input_file = $ARGV[0]);
# init print object
my $sprint = Slic3r::Print::Simple->new;
$sprint->apply_config($config);
$sprint->set_model(Slic3r::Model->read_from_file(my $input_file = $ARGV[0]));
$sprint->set_model($model);
my $print = $sprint->_print;
# compute sizes
my $bb = $print->bounding_box;
my $mediabox = [ map unscale($_)/mm, @{$bb->size} ];
my $size = $bb->size;
my $mediabox = [ map unscale($_)/mm, @{$size} ];
# init PDF
my $pdf = PDF::API2->new();
@ -48,20 +53,27 @@ my %opt = ();
# slice and build output geometry
$_->slice for @{$print->objects};
foreach my $layer (@{ $print->objects->[0]->layers }) {
my $page = $pdf->page();
$page->mediabox(@$mediabox);
my $content = $page->gfx;
$content->fillcolor($color, 1);
foreach my $object (@{ $print->objects }) {
my $shift = $object->_shifted_copies->[0];
$shift->translate(map $_/2, @$size);
foreach my $expolygon (@{$layer->slices}) {
$content->poly(map { unscale($_->x)/mm, unscale($_->y)/mm } @{$expolygon->contour}); #)
$content->close;
foreach my $hole (@{$expolygon->holes}) {
$content->poly(map { unscale($_->x)/mm, unscale($_->y)/mm } @$hole); #)
foreach my $layer (@{ $object->layers }) {
my $page = $pdf->page();
$page->mediabox(@$mediabox);
my $content = $page->gfx;
$content->fillcolor($color, 1);
foreach my $expolygon (@{$layer->slices}) {
$expolygon = $expolygon->clone;
$expolygon->translate(@$shift);
$content->poly(map { unscale($_->x)/mm, unscale($_->y)/mm } @{$expolygon->contour}); #)
$content->close;
foreach my $hole (@{$expolygon->holes}) {
$content->poly(map { unscale($_->x)/mm, unscale($_->y)/mm } @$hole); #)
$content->close;
}
$content->fill; # non-zero by default
}
$content->fill; # non-zero by default
}
}