| 1 | package PDF::Boxer::Role::BoxDev; | ||
| 2 | { | ||
| 3 | $PDF::Boxer::Role::BoxDev::VERSION = '0.004'; | ||
| 4 | } | ||
| 5 | use Moose::Role; | ||
| 6 | # ABSTRACT: methods to aid development | ||
| 7 | |||
| 8 | sub ruler_h{ | ||
| 9 | my ($self, $color) = @_; | ||
| 10 | $color ||= 'blue'; | ||
| 11 | my $gfx = $self->boxer->doc->gfx; | ||
| 12 | $gfx->strokecolor($color); | ||
| 13 | $gfx->move(10,0); | ||
| 14 | $gfx->vline($self->margin_height); | ||
| 15 | my $y = 10; | ||
| 16 | while ($y < $self->boxer->max_height){ | ||
| 17 | $gfx->move(10,$y); | ||
| 18 | $gfx->hline($y % 50 ? 15 : 20); | ||
| 19 | $y += 10; | ||
| 20 | } | ||
| 21 | $gfx->stroke; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub add_marker{ | ||
| 25 | my ($self, $color) = @_; | ||
| 26 | $color ||= 'blue'; | ||
| 27 | my $gfx = $self->boxer->doc->gfx; | ||
| 28 | $gfx->linewidth(1); | ||
| 29 | $gfx->strokecolor($color); | ||
| 30 | $gfx->move($self->margin_left, $self->margin_top); | ||
| 31 | $gfx->hline($self->margin_left + 3); | ||
| 32 | $gfx->stroke; | ||
| 33 | $gfx->move($self->margin_left, $self->margin_top); | ||
| 34 | $gfx->vline($self->margin_top-3); | ||
| 35 | $gfx->stroke; | ||
| 36 | } | ||
| 37 | |||
| 38 | sub cross_hairs{ | ||
| 39 | my ($self, $x, $y, $color) = @_; | ||
| 40 | $color ||= 'blue'; | ||
| 41 | my $gfx = $self->boxer->doc->gfx; | ||
| 42 | $gfx->strokecolor($color); | ||
| 43 | $gfx->move($x,0); | ||
| 44 | $gfx->vline($self->margin_height); | ||
| 45 | $gfx->move(0,$y); | ||
| 46 | $gfx->hline($self->margin_width); | ||
| 47 | $gfx->stroke; | ||
| 48 | } | ||
| 49 | |||
| 50 | sub dump_all{ | ||
| 51 | my ($self) = @_; | ||
| 52 | return unless $self->debug; | ||
| 53 | warn "\n===========================\n"; | ||
| 54 | warn '=== '.$self->name. ' ==='."\n"; | ||
| 55 | warn $self->dump_spec; | ||
| 56 | warn $self->dump_position; | ||
| 57 | warn $self->dump_size; | ||
| 58 | warn $self->dump_attr; | ||
| 59 | warn "===========================\n"; | ||
| 60 | $self->add_marker; | ||
| 61 | } | ||
| 62 | |||
| 63 | sub dump_spec{ | ||
| 64 | my ($self) = @_; | ||
| 65 | my @lines = ( | ||
| 66 | '== Spec ==', | ||
| 67 | (sprintf 'Margin: %s %s %s %s', @{$self->margin}), | ||
| 68 | (sprintf 'Border: %s %s %s %s', @{$self->border}), | ||
| 69 | (sprintf 'Paddin: %s %s %s %s', @{$self->padding}), | ||
| 70 | ); | ||
| 71 | $_ .= "\n" foreach @lines; | ||
| 72 | return join('', @lines); | ||
| 73 | } | ||
| 74 | |||
| 75 | sub dump_attr{ | ||
| 76 | my ($self) = @_; | ||
| 77 | my @lines = ( | ||
| 78 | '== Attr ==', | ||
| 79 | (sprintf 'width: %s', $self->width), | ||
| 80 | (sprintf 'height: %s', $self->height), | ||
| 81 | ); | ||
| 82 | $_ .= "\n" foreach @lines; | ||
| 83 | return join('', @lines); | ||
| 84 | } | ||
| 85 | |||
| 86 | |||
| 87 | sub dump_size{ | ||
| 88 | my ($self) = @_; | ||
| 89 | my @lines = ( | ||
| 90 | '== Size: '.$self->name.' ==', | ||
| 91 | (sprintf 'Max: %s x %s', $self->max_width, $self->max_height), | ||
| 92 | (sprintf 'Margin: %s x %s', $self->margin_width, $self->margin_height), | ||
| 93 | (sprintf 'Border: %s x %s', $self->border_width, $self->border_height), | ||
| 94 | (sprintf 'Padding: %s x %s', $self->padding_width, $self->padding_height), | ||
| 95 | (sprintf 'Content: %s x %s', $self->width, $self->height), | ||
| 96 | (sprintf 'Content: %s x %s', $self->width, $self->height), | ||
| 97 | ); | ||
| 98 | $_ .= "\n" foreach @lines; | ||
| 99 | return join('', @lines); | ||
| 100 | } | ||
| 101 | |||
| 102 | |||
| 103 | sub dump_position{ | ||
| 104 | my ($self) = @_; | ||
| 105 | my @lines = ( | ||
| 106 | '== Pos: '.$self->name.' ==', | ||
| 107 | (sprintf 'Margin: %s %s %s %s', $self->margin_top, $self->margin_right, $self->margin_bottom, $self->margin_left), | ||
| 108 | (sprintf 'Border: %s x %s', $self->border_left, $self->border_top), | ||
| 109 | (sprintf 'Padding: %s x %s', $self->padding_left, $self->padding_top), | ||
| 110 | (sprintf 'Content: %s x %s', $self->content_left, $self->content_top), | ||
| 111 | ); | ||
| 112 | $_ .= "\n" foreach @lines; | ||
| 113 | return join('', @lines); | ||
| 114 | } | ||
| 115 | |||
| 116 | 1; | ||
| 117 | |||
| 118 | |||
| 119 | __END__ |