View | Details | Raw Unified | Return to bug 18541
Collapse All | Expand All

(-)a/C4/Patroncards/Patroncard.pm (-1 / +88 lines)
Lines 24-30 use autouse 'Data::Dumper' => qw(Dumper); Link Here
24
use Text::Wrap qw(wrap);
24
use Text::Wrap qw(wrap);
25
#use Font::TTFMetrics;
25
#use Font::TTFMetrics;
26
26
27
use C4::Creators::Lib qw(get_font_types);
27
use C4::Creators::Lib qw(get_font_types get_unit_values);
28
use C4::Creators::PDF qw(StrWidth);
28
use C4::Creators::PDF qw(StrWidth);
29
use C4::Patroncards::Lib qw(unpack_UTF8 text_alignment leading box get_borrower_attributes);
29
use C4::Patroncards::Lib qw(unpack_UTF8 text_alignment leading box get_borrower_attributes);
30
30
Lines 32-37 use C4::Patroncards::Lib qw(unpack_UTF8 text_alignment leading box get_borrower_ Link Here
32
sub new {
32
sub new {
33
    my ($invocant, %params) = @_;
33
    my ($invocant, %params) = @_;
34
    my $type = ref($invocant) || $invocant;
34
    my $type = ref($invocant) || $invocant;
35
36
    my $units = get_unit_values();
37
    my $unitvalue = 1;
38
    my $unitdesc = '';
39
    foreach my $un (@$units){
40
        if ($un->{'type'} eq $params{'layout'}->{'units'}) {
41
            $unitvalue = $un->{'value'};
42
            $unitdesc = $un->{'desc'};
43
        }
44
    }
45
35
    my $self = {
46
    my $self = {
36
        batch_id                => $params{'batch_id'},
47
        batch_id                => $params{'batch_id'},
37
        #card_number             => $params{'card_number'},
48
        #card_number             => $params{'card_number'},
Lines 41-46 sub new { Link Here
41
        height                  => $params{'height'},
52
        height                  => $params{'height'},
42
        width                   => $params{'width'},
53
        width                   => $params{'width'},
43
        layout                  => $params{'layout'},
54
        layout                  => $params{'layout'},
55
        unitvalue               => $unitvalue,
56
        unitdesc                => $unitdesc,
44
        text_wrap_cols          => $params{'text_wrap_cols'},
57
        text_wrap_cols          => $params{'text_wrap_cols'},
45
        barcode_height_scale    => $params{'layout'}->{'barcode'}[0]->{'height_scale'} || 0.01,
58
        barcode_height_scale    => $params{'layout'}->{'barcode'}[0]->{'height_scale'} || 0.01,
46
        barcode_width_scale     => $params{'layout'}->{'barcode'}[0]->{'width_scale'} || 0.8,
59
        barcode_width_scale     => $params{'layout'}->{'barcode'}[0]->{'width_scale'} || 0.8,
Lines 69-74 sub draw_barcode { Link Here
69
sub draw_guide_box {
82
sub draw_guide_box {
70
    my ($self, $pdf) = @_;
83
    my ($self, $pdf) = @_;
71
    warn sprintf('No pdf object passed in.') and return -1 if !$pdf;
84
    warn sprintf('No pdf object passed in.') and return -1 if !$pdf;
85
72
    my $obj_stream = "q\n";                            # save the graphic state
86
    my $obj_stream = "q\n";                            # save the graphic state
73
    $obj_stream .= "0.5 w\n";                          # border line width
87
    $obj_stream .= "0.5 w\n";                          # border line width
74
    $obj_stream .= "1.0 0.0 0.0  RG\n";                # border color red
88
    $obj_stream .= "1.0 0.0 0.0  RG\n";                # border color red
Lines 79-84 sub draw_guide_box { Link Here
79
    $pdf->Add($obj_stream);
93
    $pdf->Add($obj_stream);
80
}
94
}
81
95
96
sub draw_guide_grid {
97
    my ($self, $pdf) = @_;
98
    warn sprintf('No pdf object passed in.') and return -1 if !$pdf;
99
100
    # Set up the grid in user defined units.
101
    # Each 5th and 10th line get separate values
102
103
    my $obj_stream = "q\n";   # save the graphic state
104
    my $x = $self->{'llx'};
105
    my $y = $self->{'lly'};
106
107
    my $cnt = 0;
108
    for ( $x = $self->{'llx'}/$self->{'unitvalue'}; $x <= ($self->{'llx'} + $self->{'width'})/$self->{'unitvalue'}; $x++) {
109
        my $xx = $x*$self->{'unitvalue'};
110
        my $yy = $y + $self->{'height'};
111
        if ( ($cnt % 10) && ! ($cnt % 5) ) {
112
            $obj_stream .= "0.0 1.0 0.0  RG\n";
113
            $obj_stream .= "0 w\n";
114
        } elsif ( $cnt % 5 ) {
115
            $obj_stream .= "0.0 1.0 1.0  RG\n";
116
            $obj_stream .= "0 w\n";
117
        } else {
118
            $obj_stream .= "0.0 0.0 1.0  RG\n";
119
            $obj_stream .= "0 w\n";
120
        }
121
        $cnt ++;
122
123
        $obj_stream .= "$xx $y m\n";
124
        $obj_stream .= "$xx $yy l\n";
125
126
        $obj_stream .= "s\n";
127
    }
128
129
    $x = $self->{'llx'};
130
    $y = $self->{'lly'};
131
    $cnt = 0;
132
    for ( $y = $self->{'lly'}/$self->{'unitvalue'}; $y <= ($self->{'lly'} + $self->{'height'})/$self->{'unitvalue'}; $y++) {
133
134
        my $xx = $x + $self->{'width'};
135
        my $yy = $y*$self->{'unitvalue'};
136
137
        if ( ($cnt % 10) && ! ($cnt % 5) ) {
138
            $obj_stream .= "0.0 1.0 0.0  RG\n";
139
            $obj_stream .= "0 w\n";
140
        } elsif ( $cnt % 5 ) {
141
            $obj_stream .= "0.0 1.0 1.0  RG\n";
142
            $obj_stream .= "0 w\n";
143
        } else {
144
            $obj_stream .= "0.0 0.0 1.0  RG\n";
145
            $obj_stream .= "0 w\n";
146
        }
147
        $cnt ++;
148
149
        $obj_stream .= "$x $yy m\n";
150
        $obj_stream .= "$xx $yy l\n";
151
        $obj_stream .= "s\n";
152
    }
153
154
    $obj_stream .= "Q\n"; # restore the graphic state
155
    $pdf->Add($obj_stream);
156
157
    # Add info about units
158
    my $strbottom = "0/0 $self->{'unitdesc'}";
159
    my $strtop = sprintf('%.2f', $self->{'width'}/$self->{'unitvalue'}) .'/'. sprintf('%.2f', $self->{'height'}/$self->{'unitvalue'});
160
    my $font_size = 6;
161
    $pdf->Font( 'Courier' );
162
    $pdf->FontSize( $font_size );
163
    my $strtop_len = $pdf->StrWidth($strtop) * 1.5;
164
    $pdf->Text( $self->{'llx'} + 2, $self->{'lly'} + 2, $strbottom );
165
    $pdf->Text( $self->{'llx'} + $self->{'width'} - $strtop_len , $self->{'lly'} + $self->{'height'} - $font_size , $strtop );
166
}
167
168
82
sub draw_text {
169
sub draw_text {
83
    my ($self, $pdf, %params) = @_;
170
    my ($self, $pdf, %params) = @_;
84
    warn sprintf('No pdf object passed in.') and return -1 if !$pdf;
171
    warn sprintf('No pdf object passed in.') and return -1 if !$pdf;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/edit-layout.tt (+10 lines)
Lines 176-181 Link Here
176
                                    <input type="radio" name="guide_box" id="guide_box" value="0" checked="checked" />Off
176
                                    <input type="radio" name="guide_box" id="guide_box" value="0" checked="checked" />Off
177
                                    [% END %]
177
                                    [% END %]
178
                                </li>
178
                                </li>
179
                                <li>
180
                                    <label for="guide_grid">Guide grid:</label>
181
                                    [% IF ( guide_grid ) %]
182
                                    <input type="radio" name="guide_grid" id="guide_grid" value="1" checked="checked" />On
183
                                    <input type="radio" name="guide_grid" id="guide_grid" value="0" />Off
184
                                    [% ELSE %]
185
                                    <input type="radio" name="guide_grid" id="guide_grid" value="1" />On
186
                                    <input type="radio" name="guide_grid" id="guide_grid" value="0" checked="checked" />Off
187
                                    [% END %]
188
                                </li>
179
                                </ol>
189
                                </ol>
180
                                </fieldset>
190
                                </fieldset>
181
                                </li>
191
                                </li>
(-)a/patroncards/create-pdf.pl (-2 / +3 lines)
Lines 155-162 foreach my $item (@{$items}) { Link Here
155
                text_wrap_cols          => 30, #FIXME: hardcoded,
155
                text_wrap_cols          => 30, #FIXME: hardcoded,
156
        );
156
        );
157
157
158
        $patron_card->draw_guide_box($pdf) if $print_layout_xml->{'guide_box'};
158
        $patron_card->draw_guide_box($pdf) if $layout_xml->{'guide_box'};
159
        $patron_card->draw_barcode($pdf) if $print_layout_xml->{'barcode'};
159
        $patron_card->draw_guide_grid($pdf) if $layout_xml->{'guide_grid'};
160
        $patron_card->draw_barcode($pdf) if $layout_xml->{'barcode'};
160
161
161
#       Do image foo and place binary image data into layout hash
162
#       Do image foo and place binary image data into layout hash
162
        my $image_data = {};
163
        my $image_data = {};
(-)a/patroncards/edit-layout.pl (-1 / +2 lines)
Lines 156-161 if ($op eq 'edit') { Link Here
156
            layout_name     => $layout->get_attr('layout_name'),
156
            layout_name     => $layout->get_attr('layout_name'),
157
            page_side       => ($layout_xml->{'page_side'} eq 'F' ? 0 : 1),
157
            page_side       => ($layout_xml->{'page_side'} eq 'F' ? 0 : 1),
158
            guide_box       => $layout_xml->{'guide_box'},
158
            guide_box       => $layout_xml->{'guide_box'},
159
            guide_grid      => $layout_xml->{'guide_grid'},
159
            units           => $units,
160
            units           => $units,
160
            @barcode,
161
            @barcode,
161
            barcode_type    => _set_selected($layout_xml->{'barcode'}->[0]->{'type'}, $barcode_types),
162
            barcode_type    => _set_selected($layout_xml->{'barcode'}->[0]->{'type'}, $barcode_types),
Lines 218-223 elsif ($op eq 'save') { Link Here
218
            $layout->{'units'} = $cgi->param($parameter) if $parameter eq 'units';
219
            $layout->{'units'} = $cgi->param($parameter) if $parameter eq 'units';
219
            $layout->{'page_side'} = $cgi->param($parameter) if $parameter eq 'page_side';
220
            $layout->{'page_side'} = $cgi->param($parameter) if $parameter eq 'page_side';
220
            $layout->{'guide_box'} = $cgi->param($parameter) if $parameter eq 'guide_box';
221
            $layout->{'guide_box'} = $cgi->param($parameter) if $parameter eq 'guide_box';
222
            $layout->{'guide_grid'} = $cgi->param($parameter) if $parameter eq 'guide_grid';
221
        }
223
        }
222
    }
224
    }
223
    $layout->{'text'} = $text_lines;
225
    $layout->{'text'} = $text_lines;
224
- 

Return to bug 18541