Bugzilla – Attachment 191812 Details for
Bug 40478
Add option to justify barcode on labels
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40478: Add ability to justify CODE39 barcodes
Bug-40478-Add-ability-to-justify-CODE39-barcodes.patch (text/plain), 14.99 KB, created by
Lucas Gass (lukeg)
on 2026-01-21 18:33:14 UTC
(
hide
)
Description:
Bug 40478: Add ability to justify CODE39 barcodes
Filename:
MIME Type:
Creator:
Lucas Gass (lukeg)
Created:
2026-01-21 18:33:14 UTC
Size:
14.99 KB
patch
obsolete
>From 0c4b1138b996512c31397c4230e7451622e5c78b Mon Sep 17 00:00:00 2001 >From: Lucas Gass <lucas@bywatersolutions.com> >Date: Wed, 21 Jan 2026 18:31:51 +0000 >Subject: [PATCH] Bug 40478: Add ability to justify CODE39 barcodes > >--- > C4/Creators/Layout.pm | 32 ++++----- > C4/Labels/Label.pm | 38 +++++++++-- > .../en/modules/labels/label-edit-layout.tt | 12 ++++ > labels/label-create-pdf.pl | 3 + > labels/label-edit-layout.pl | 66 ++++++++++--------- > 5 files changed, 98 insertions(+), 53 deletions(-) > >diff --git a/C4/Creators/Layout.pm b/C4/Creators/Layout.pm >index 3edb8b19625..7153bd64e13 100644 >--- a/C4/Creators/Layout.pm >+++ b/C4/Creators/Layout.pm >@@ -35,6 +35,7 @@ sub _check_params { > 'scale_height', > 'callnum_split', > 'text_justify', >+ 'barcode_justify', > 'format_string', > 'layout_xml', # FIXME: all layouts should be stored in xml format to greatly simplify handling -chris_n > 'creator', >@@ -69,21 +70,22 @@ sub new { > my $type = ref($invocant) || $invocant; > if ( grep { $_ eq 'Labels' } @_ ) { > $self = { >- layout_xml => '', >- units => 'POINT', >- start_label => 1, >- barcode_type => 'CODE39', >- printing_type => 'BAR', >- layout_name => 'DEFAULT', >- guidebox => 0, >- oblique_title => 1, >- font => 'TR', >- font_size => 3, >- scale_width => 0.8, >- scale_height => 0.01, >- callnum_split => 0, >- text_justify => 'L', >- format_string => join( ', ', @{ PRESET_FIELDS() } ), >+ layout_xml => '', >+ units => 'POINT', >+ start_label => 1, >+ barcode_type => 'CODE39', >+ printing_type => 'BAR', >+ layout_name => 'DEFAULT', >+ guidebox => 0, >+ oblique_title => 1, >+ font => 'TR', >+ font_size => 3, >+ scale_width => 0.8, >+ scale_height => 0.01, >+ callnum_split => 0, >+ text_justify => 'L', >+ barcode_justify => 'L', >+ format_string => join( ', ', @{ PRESET_FIELDS() } ), > @_, > }; > } elsif ( grep { $_ eq 'Patroncards' } @_ ) { >diff --git a/C4/Labels/Label.pm b/C4/Labels/Label.pm >index e7a28efc9f2..f8c118c56d0 100644 >--- a/C4/Labels/Label.pm >+++ b/C4/Labels/Label.pm >@@ -317,6 +317,7 @@ sub new { > scale_height => $params{'scale_height'}, > callnum_split => $params{'callnum_split'}, > justify => $params{'justify'}, >+ barcode_justify => $params{'barcode_justify'}, > format_string => $params{'format_string'}, > text_wrap_cols => $params{'text_wrap_cols'}, > barcode => $params{'barcode'}, >@@ -368,10 +369,11 @@ sub create_label { > if ( $self->{'printing_type'} =~ /BAR/ ) { > barcode( > $self, >- llx => $barcode_llx, >- lly => $barcode_lly, >- width => $barcode_width, >- y_scale_factor => $barcode_y_scale_factor, >+ llx => $barcode_llx, >+ lly => $barcode_lly, >+ width => $barcode_width, >+ y_scale_factor => $barcode_y_scale_factor, >+ barcode_justify => $self->{'barcode_justify'}, > ); > } > return $label_text if $label_text; >@@ -516,9 +518,13 @@ sub draw_guide_box { > sub barcode { > my $self = shift; > my %params = @_; >+ > $params{'barcode_data'} = ( $self->{'barcode'} || _get_label_item( $self->{'item_number'}, 1 ) ) > if !$params{'barcode_data'}; > $params{'barcode_type'} = $self->{'barcode_type'} if !$params{'barcode_type'}; >+ >+ my $barcode_justify = $params{'barcode_justify'} || 'L'; >+ > my $x_scale_factor = 1; > my $num_of_bars = length( $params{'barcode_data'} ); > my $tot_bar_length = 0; >@@ -541,8 +547,18 @@ sub barcode { > my $oGdB = GD::Barcode::Code39->new("*$params{'barcode_data'}*"); > my $whole_barcode_length = ( length( $oGdB->barcode() ) * 0.9 ) + 20; > $x_scale_factor = ( $params{'width'} / $whole_barcode_length ); >+ >+ my $adjusted_llx = $params{'llx'}; >+ my $barcode_width = $whole_barcode_length * $x_scale_factor; >+ >+ if ( $barcode_justify eq 'C' ) { >+ $adjusted_llx = $params{'llx'} + ( ( $self->{'width'} - $barcode_width ) / 2 ); >+ } elsif ( $barcode_justify eq 'R' ) { >+ $adjusted_llx = $params{'llx'} + ( $self->{'width'} - $barcode_width ); >+ } >+ > PDF::Reuse::Barcode::Code39( >- x => $params{'llx'}, >+ x => $adjusted_llx, > y => $params{'lly'}, > value => "*$params{barcode_data}*", > xSize => $x_scale_factor, >@@ -559,9 +575,13 @@ sub barcode { > $bar_length = '9.43333333333333'; > $tot_bar_length = ( $bar_length * $num_of_bars ) + ( $guard_length * 2 ); > $x_scale_factor = ( $params{'width'} / $tot_bar_length ) * 0.9; >+ >+ my $adjusted_llx = $params{'llx'}; >+ my $barcode_width = $tot_bar_length * $x_scale_factor; >+ > eval { > PDF::Reuse::Barcode::COOP2of5( >- x => $params{'llx'}, >+ x => $adjusted_llx, > y => $params{'lly'}, > value => $params{barcode_data}, > xSize => $x_scale_factor, >@@ -576,9 +596,13 @@ sub barcode { > $bar_length = '13.1333333333333'; > $tot_bar_length = ( $bar_length * $num_of_bars ) + ( $guard_length * 2 ); > $x_scale_factor = ( $params{'width'} / $tot_bar_length ) * 0.9; >+ >+ my $adjusted_llx = $params{'llx'}; >+ my $barcode_width = $tot_bar_length * $x_scale_factor; >+ > eval { > PDF::Reuse::Barcode::Industrial2of5( >- x => $params{'llx'}, >+ x => $adjusted_llx, > y => $params{'lly'}, > value => $params{barcode_data}, > xSize => $x_scale_factor, >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-layout.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-layout.tt >index 73bd4d53fa4..d0a15a0330e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-layout.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-layout.tt >@@ -184,6 +184,18 @@ > [% END %] > </select> > </li> >+ <li> >+ <label for="barcode_justify">Barcode justification: </label> >+ <select name="barcode_justify" id="barcode_justify"> >+ [% FOREACH barcode_justification_type IN barcode_justification_types %] >+ [% IF ( barcode_justification_type.selected ) %] >+ <option value="[% barcode_justification_type.type | html %]" selected="selected">[% PROCESS translate_justification_types type=barcode_justification_type.type %]</option> >+ [% ELSE %] >+ <option value="[% barcode_justification_type.type | html %]">[% PROCESS translate_justification_types type=barcode_justification_type.type %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ </li> > <li> > <label for="font">Font: </label> > <select name="font" id="font"> >diff --git a/labels/label-create-pdf.pl b/labels/label-create-pdf.pl >index bbdeccc9395..d4e97e87e48 100755 >--- a/labels/label-create-pdf.pl >+++ b/labels/label-create-pdf.pl >@@ -149,6 +149,7 @@ foreach my $item ( @{$items} ) { > scale_height => $layout->get_attr('scale_height'), > callnum_split => $layout->get_attr('callnum_split'), > justify => $layout->get_attr('text_justify'), >+ barcode_justify => $layout->get_attr('barcode_justify'), > format_string => $layout->get_attr('format_string'), > text_wrap_cols => $layout->get_text_wrap_cols( > label_width => $template->get_attr('label_width'), >@@ -178,6 +179,7 @@ foreach my $item ( @{$items} ) { > scale_height => $layout->get_attr('scale_height'), > callnum_split => $layout->get_attr('callnum_split'), > justify => $layout->get_attr('text_justify'), >+ barcode_justify => $layout->get_attr('barcode_justify'), > format_string => $layout->get_attr('format_string'), > text_wrap_cols => $layout->get_text_wrap_cols( > label_width => $template->get_attr('label_width'), >@@ -209,6 +211,7 @@ foreach my $item ( @{$items} ) { > scale_height => $layout->get_attr('scale_height'), > callnum_split => $layout->get_attr('callnum_split'), > justify => $layout->get_attr('text_justify'), >+ barcode_justify => $layout->get_attr('barcode_justify'), > format_string => $layout->get_attr('format_string'), > text_wrap_cols => $layout->get_text_wrap_cols( > label_width => $template->get_attr('label_width'), >diff --git a/labels/label-edit-layout.pl b/labels/label-edit-layout.pl >index 7ff8129598f..fb4dfb7e8d8 100755 >--- a/labels/label-edit-layout.pl >+++ b/labels/label-edit-layout.pl >@@ -103,18 +103,19 @@ if ( $op eq 'edit_form' ) { > $cgi->param( 'format_string', $format_string ); > } > my @params = ( >- barcode_type => scalar $cgi->param('barcode_type') || 'CODE39', >- printing_type => scalar $cgi->param('printing_type') || 'BAR', >- layout_name => scalar $cgi->param('layout_name') || 'DEFAULT', >- guidebox => ( $cgi->param('guidebox') ? 1 : 0 ), >- oblique_title => ( $cgi->param('oblique_title') ? 1 : 0 ), >- font => scalar $cgi->param('font') || 'TR', >- font_size => scalar $cgi->param('font_size') || 3, >- scale_width => scalar $cgi->param('scale_width') || 0.8, >- scale_height => scalar $cgi->param('scale_height') || 0.01, >- callnum_split => ( $cgi->param('callnum_split') ? 1 : 0 ), >- text_justify => scalar $cgi->param('text_justify') || 'L', >- format_string => scalar $cgi->param('format_string') >+ barcode_type => scalar $cgi->param('barcode_type') || 'CODE39', >+ printing_type => scalar $cgi->param('printing_type') || 'BAR', >+ layout_name => scalar $cgi->param('layout_name') || 'DEFAULT', >+ guidebox => ( $cgi->param('guidebox') ? 1 : 0 ), >+ oblique_title => ( $cgi->param('oblique_title') ? 1 : 0 ), >+ font => scalar $cgi->param('font') || 'TR', >+ font_size => scalar $cgi->param('font_size') || 3, >+ scale_width => scalar $cgi->param('scale_width') || 0.8, >+ scale_height => scalar $cgi->param('scale_height') || 0.01, >+ callnum_split => ( $cgi->param('callnum_split') ? 1 : 0 ), >+ text_justify => scalar $cgi->param('text_justify') || 'L', >+ barcode_justify => scalar $cgi->param('barcode_justify') || 'L', >+ format_string => scalar $cgi->param('format_string') > || 'title, author, isbn, issn, itemtype, barcode, itemcallnumber', > ); > if ($layout_id) { # if a label_id was passed in, this is an update to an existing layout >@@ -132,28 +133,31 @@ if ( $op eq 'edit_form' ) { > $layout = C4::Labels::Layout->new(); > } > >-my $barcode_types = _set_selected( get_barcode_types(), $layout, 'barcode_type' ); >-my $label_types = _set_selected( get_label_types(), $layout, 'printing_type' ); >-my $font_types = _set_selected( get_font_types(), $layout, 'font' ); >-my $text_justification_types = _set_selected( get_text_justification_types(), $layout, 'text_justify' ); >+my $barcode_types = _set_selected( get_barcode_types(), $layout, 'barcode_type' ); >+my $label_types = _set_selected( get_label_types(), $layout, 'printing_type' ); >+my $font_types = _set_selected( get_font_types(), $layout, 'font' ); >+my $text_justification_types = _set_selected( get_text_justification_types(), $layout, 'text_justify' ); >+my $barcode_justification_types = _set_selected( get_text_justification_types(), $layout, 'barcode_justify' ); >+ > my ( $select_text_fields, $select_text_fields_cnt ) = _select_format_string( $layout->get_attr('format_string') ); > > $template->param( >- barcode_types => $barcode_types, >- label_types => $label_types, >- font_types => $font_types, >- text_justification_types => $text_justification_types, >- fields => $select_text_fields, >- field_count => $select_text_fields_cnt, >- layout_id => $layout->get_attr('layout_id') > -1 ? $layout->get_attr('layout_id') : '', >- layout_name => $layout->get_attr('layout_name'), >- guidebox => $layout->get_attr('guidebox'), >- oblique_title => $layout->get_attr('oblique_title'), >- font_size => $layout->get_attr('font_size'), >- scale_width => $layout->get_attr('scale_width'), >- scale_height => $layout->get_attr('scale_height'), >- callnum_split => $layout->get_attr('callnum_split'), >- format_string => $layout->get_attr('format_string'), >+ barcode_types => $barcode_types, >+ label_types => $label_types, >+ font_types => $font_types, >+ text_justification_types => $text_justification_types, >+ barcode_justification_types => $barcode_justification_types, >+ fields => $select_text_fields, >+ field_count => $select_text_fields_cnt, >+ layout_id => $layout->get_attr('layout_id') > -1 ? $layout->get_attr('layout_id') : '', >+ layout_name => $layout->get_attr('layout_name'), >+ guidebox => $layout->get_attr('guidebox'), >+ oblique_title => $layout->get_attr('oblique_title'), >+ font_size => $layout->get_attr('font_size'), >+ scale_width => $layout->get_attr('scale_width'), >+ scale_height => $layout->get_attr('scale_height'), >+ callnum_split => $layout->get_attr('callnum_split'), >+ format_string => $layout->get_attr('format_string'), > layout_string => 1, # FIXME: This should not be hard-coded; It should perhaps be yet another syspref... CN > ); > output_html_with_http_headers $cgi, $cookie, $template->output; >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40478
:
191811
|
191812
|
192111
|
192112
|
192113
|
192114