From 11a213a82ffdff85005dacdee26203dc6f6b2dc3 Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Fri, 7 Mar 2008 20:05:53 -0500 Subject: [PATCH] Bumping DB to 061 - Adding the ability to choose font type to the Label tool. Signed-off-by: Joshua Ferraro --- C4/Labels.pm | 108 ++++++++++-------- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 8 ++ .../modules/labels/label-create-template.tmpl | 14 ++- .../modules/labels/label-edit-template.tmpl | 10 ++ labels/label-create-template.pl | 30 ++++- labels/label-edit-template.pl | 22 ++++ labels/label-print-pdf.pl | 60 ++++------ labels/label-save-template.pl | 7 +- 9 files changed, 168 insertions(+), 92 deletions(-) diff --git a/C4/Labels.pm b/C4/Labels.pm index bdbce82444..1a1e8054f2 100644 --- a/C4/Labels.pm +++ b/C4/Labels.pm @@ -43,7 +43,7 @@ BEGIN { &get_layouts &get_barcode_types &get_batches &delete_batch - &add_batch &SetFontSize &printText + &add_batch &printText &GetItemFields &get_text_fields get_layout &save_layout &add_layout @@ -332,10 +332,10 @@ sub get_barcode_types { my $barcode = $layout->{'barcodetype'}; my @array; - push( @array, { code => 'CODE39', desc => 'Code 39' } ); - push( @array, { code => 'CODE39MOD', desc => 'Code39 + Modulo43' } ); + push( @array, { code => 'CODE39', desc => 'Code 39' } ); + push( @array, { code => 'CODE39MOD', desc => 'Code39 + Modulo43' } ); push( @array, { code => 'CODE39MOD10', desc => 'Code39 + Modulo10' } ); - push( @array, { code => 'ITF', desc => 'Interleaved 2 of 5' } ); + push( @array, { code => 'ITF', desc => 'Interleaved 2 of 5' } ); foreach my $line (@array) { if ( $line->{'code'} eq $barcode ) { @@ -358,19 +358,17 @@ sub GetUnitsValue { } sub GetTextWrapCols { - my ( $fontsize, $label_width ) = @_; - my $string = "0"; - my $left_text_margin = 3; - my ( $strtmp, $strwidth ); - my $count = 0; - my $textlimit = $label_width - $left_text_margin; + my ( $font, $fontsize, $label_width, $left_text_margin ) = @_; + my $string = '0'; + my $strwidth; + my $count = 0; + my $textlimit = $label_width - ( 2* $left_text_margin); while ( $strwidth < $textlimit ) { - $strwidth = prStrWidth( $string, 'C', $fontsize ); - $string = $string . '0'; - - # warn "strwidth $strwidth, $textlimit, $string"; $count++; + $strwidth = prStrWidth( $string, $font, $fontsize ); + $string = $string . '0'; + #warn "strwidth:$strwidth, textlimit:$textlimit, count:$count string:$string"; } return $count; } @@ -439,13 +437,14 @@ sub SaveTemplate { $tmpl_id, $tmpl_code, $tmpl_desc, $page_width, $page_height, $label_width, $label_height, $topmargin, $leftmargin, $cols, $rows, $colgap, - $rowgap, $fontsize, $units + $rowgap, $font, $fontsize, $units ) = @_; + warn "Passed \$font:$font"; my $dbh = C4::Context->dbh; my $query = " UPDATE labels_templates SET tmpl_code=?, tmpl_desc=?, page_width=?, page_height=?, label_width=?, label_height=?, topmargin=?, - leftmargin=?, cols=?, rows=?, colgap=?, rowgap=?, fontsize=?, + leftmargin=?, cols=?, rows=?, colgap=?, rowgap=?, font=?, fontsize=?, units=? WHERE tmpl_id = ?"; @@ -454,9 +453,11 @@ sub SaveTemplate { $tmpl_code, $tmpl_desc, $page_width, $page_height, $label_width, $label_height, $topmargin, $leftmargin, $cols, $rows, $colgap, $rowgap, - $fontsize, $units, $tmpl_id + $font, $fontsize, $units, $tmpl_id ); + my $dberror = $sth->errstr; $sth->finish; + return $dberror; } sub CreateTemplate { @@ -465,23 +466,26 @@ sub CreateTemplate { $tmpl_code, $tmpl_desc, $page_width, $page_height, $label_width, $label_height, $topmargin, $leftmargin, $cols, $rows, $colgap, $rowgap, - $fontsize, $units + $font, $fontsize, $units ) = @_; my $dbh = C4::Context->dbh; my $query = "INSERT INTO labels_templates (tmpl_code, tmpl_desc, page_width, page_height, label_width, label_height, topmargin, - leftmargin, cols, rows, colgap, rowgap, fontsize, units) - VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + leftmargin, cols, rows, colgap, rowgap, font, fontsize, units) + VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; my $sth = $dbh->prepare($query); $sth->execute( $tmpl_code, $tmpl_desc, $page_width, $page_height, $label_width, $label_height, $topmargin, $leftmargin, $cols, $rows, $colgap, $rowgap, - $fontsize, $units + $font, $fontsize, $units ); + my $dberror = $sth->errstr; + $sth->finish; + return $dberror; } sub GetAllLabelTemplates { @@ -831,8 +835,8 @@ sub deduplicate_batch { sub DrawSpineText { - my ( $y_pos, $label_height, $fontsize, $x_pos, $left_text_margin, - $text_wrap_cols, $item, $conf_data ) + my ( $y_pos, $label_height, $label_width, $font, $fontsize, $x_pos, $left_text_margin, + $text_wrap_cols, $item, $conf_data, $printingtype ) = @_; # hack to fix column name mismatch betwen labels_conf.class, and bibitems.classification $$item->{'class'} = $$item->{'classification'}; @@ -843,22 +847,21 @@ sub DrawSpineText { my $str; ## $item - my $top_text_margin = ( $fontsize + 3 ); - my $line_spacer = ($fontsize); # number of pixels between text rows. + my $top_text_margin = ( $fontsize + 3 ); #FIXME: This should be a template parameter and passed in... + my $line_spacer = ( $fontsize * 0.20 ); # number of pixels between text rows (This is actually leading: baseline to baseline minus font size. Recommended starting point is 20% of font size.). # add your printable fields manually in here -my $layout_id = $$conf_data->{'id'}; + my $layout_id = $$conf_data->{'id'}; # my @fields = GetItemFields(); -my $str_fields = get_text_fields($layout_id, 'codes' ); -my @fields = split(/ /, $str_fields); -#warn Dumper(@fields); -### @fields + my $str_fields = get_text_fields($layout_id, 'codes' ); + my @fields = split(/ /, $str_fields); + #warn Dumper(@fields); + ### @fields my $vPos = ( $y_pos + ( $label_height - $top_text_margin ) ); - my $hPos = ( $x_pos + $left_text_margin ); # warn Dumper $conf_data; #warn Dumper $item; @@ -879,7 +882,8 @@ my @fields = split(/ /, $str_fields); # strip out naughty existing nl/cr's $str =~ s/\n//g; $str =~ s/\r//g; - + # strip out division slashes + $str =~ s/\///g; # chop the string up into _upto_ 12 chunks # and seperate the chunks with newlines @@ -891,31 +895,39 @@ my @fields = split(/ /, $str_fields); # then loop for each string line foreach my $str (@strings) { - - #warn "HPOS , VPOS $hPos, $vPos "; - # set the font size A - - # prText( $hPos, $vPos, $str ); - PrintText( $hPos, $vPos, $fontsize, $str ); + my $hPos; + if ( $printingtype eq 'BIB' ) { #FIXME: This is a hack and needs to be implimented as a text justification option in the template... + # some code to try and center each line on the label based on font size and string point length... + my $stringwidth = prStrWidth($str, $font, $fontsize); + my $whitespace = ( $label_width - ( $stringwidth + (2 * $left_text_margin) ) ); + $hPos = ( ( $whitespace / 2 ) + $x_pos + $left_text_margin ); + warn "\$label_width=$label_width \$stringwidth=$stringwidth \$whitespace=$whitespace \$left_text_margin=$left_text_margin for $str"; + } else { + $hPos = ( $x_pos + $left_text_margin ); + } + PrintText( $hPos, $vPos, $font, $fontsize, $str ); $vPos = $vPos - $line_spacer; + } - } # if field is } #foreach feild - } + } # if field is + } #foreach feild } sub PrintText { - my ( $hPos, $vPos, $fontsize, $text ) = @_; - my $str = "BT /Ft1 $fontsize Tf $hPos $vPos Td ($text) Tj ET"; + my ( $hPos, $vPos, $font, $fontsize, $text ) = @_; + my $str = "BT /$font $fontsize Tf $hPos $vPos Td ($text) Tj ET"; prAdd($str); } -sub SetFontSize { +# Is this used anywhere? - my ($fontsize) = @_; -### fontsize - my $str = "BT/F13 30 Tf288 720 Td( AAAAAAAAAA ) TjET"; - prAdd($str); -} +#sub SetFontSize { +# +# my ($fontsize) = @_; +#### fontsize +# my $str = "BT/F13 30 Tf288 720 Td( AAAAAAAAAA ) TjET"; +# prAdd($str); +#} sub DrawBarcode { diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 1a821366c3..d6cac20fda 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1158,6 +1158,7 @@ CREATE TABLE `labels_templates` ( `active` int(1) default NULL, `units` char(20) default 'PX', `fontsize` int(4) NOT NULL default '3', + `font` char(10) NOT NULL default 'TR', PRIMARY KEY (`tmpl_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 80b32d994f..92ad818e26 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -1109,6 +1109,14 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.00.00.061"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE labels_templates ADD COLUMN font char(10) NOT NULL DEFAULT 'TR';"); + print "Upgrade to $DBversion done ( Added font column to labels_templates )\n"; + SetVersion ($DBversion); +} + + =item DropAllForeignKeys($table) Drop all foreign keys of the table $table diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-create-template.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-create-template.tmpl index 405304488d..a1f420baa8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-create-template.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-create-template.tmpl @@ -59,13 +59,21 @@ +
  • +
  • +
  • -
    - - Cancel
    +
    + + +
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-template.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-template.tmpl index a0615a0717..f37b31b80e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-template.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-template.tmpl @@ -89,6 +89,16 @@ +
  • +
  • " />
  • diff --git a/labels/label-create-template.pl b/labels/label-create-template.pl index 183ae66fb6..1b7e5261ef 100755 --- a/labels/label-create-template.pl +++ b/labels/label-create-template.pl @@ -29,6 +29,7 @@ my $rows = $query->param('rows'); my $colgap = $query->param('colgap'); my $rowgap = $query->param('rowgap'); my $units = $query->param('units'); +my $font = $query->param('fonts'); my $fontsize = $query->param('fontsize'); my $batch_id = $query->param('batch_id'); @@ -48,6 +49,21 @@ if ( $op eq 'blank' ) { { unit => 'POINT', desc => 'Postscript Points' }, ); + my @fonts = ( #FIXME: There is probably a way to discover what additional fonts are installed on a user's system and generate this list dynamically... + { font => 'TR', name => 'Times Roman' }, + { font => 'TB', name => 'Times Bold' }, + { font => 'TI', name => 'Times Italic' }, + { font => 'TBI', name => 'Times Bold Italic' }, + { font => 'C', name => 'Courier' }, + { font => 'CB', name => 'Courier Bold' }, + { font => 'CO', name => 'Courier Oblique' }, + { font => 'CBO', name => 'Courier Bold Oblique' }, + { font => 'H', name => 'Helvetica' }, + { font => 'HB', name => 'Helvetica Bold' }, + { font => 'HO', name => 'Helvetica Oblique' }, + { font => 'HBO', name => 'Helvetica Bold Oblique' }, + ); + ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "labels/label-create-template.tmpl", @@ -60,22 +76,28 @@ if ( $op eq 'blank' ) { ); $template->param( - units => \@units, + units => \@units, + fonts => \@fonts, ); } -elsif ( $op eq 'create' ) { +elsif ( $op eq 'Create' ) { CreateTemplate( - $tmpl_code, $tmpl_desc, $page_width, + $tmpl_code, $tmpl_desc, $page_width, $page_height, $label_width, $label_height, $topmargin, $leftmargin, $cols, $rows, $colgap, - $rowgap, $fontsize, $units ); + $rowgap, $font, $fontsize, $units ); print $query->redirect("./label-templates.pl"); exit; } +elsif ( $op eq 'Cancel' ) { + print $query->redirect("./label-home.pl"); + exit; +} + output_html_with_http_headers $query, $cookie, $template->output; diff --git a/labels/label-edit-template.pl b/labels/label-edit-template.pl index 0cb2ae6dff..47b6bd7246 100755 --- a/labels/label-edit-template.pl +++ b/labels/label-edit-template.pl @@ -76,10 +76,32 @@ foreach my $unit (@units) { } } +my @fonts = ( #FIXME: There is probably a way to discover what additional fonts are installed on a user's system and generate this list dynamically... + { font => 'TR', name => 'Times Roman' }, + { font => 'TB', name => 'Times Bold' }, + { font => 'TI', name => 'Times Italic' }, + { font => 'TBI', name => 'Times Bold Italic' }, + { font => 'C', name => 'Courier' }, + { font => 'CB', name => 'Courier Bold' }, + { font => 'CO', name => 'Courier Oblique' }, + { font => 'CBO', name => 'Courier Bold Oblique' }, + { font => 'H', name => 'Helvetica' }, + { font => 'HB', name => 'Helvetica Bold' }, + { font => 'HO', name => 'Helvetica Oblique' }, + { font => 'HBO', name => 'Helvetica Bold Oblique' }, +); + +foreach my $font (@fonts) { + if ( $font->{'font'} eq $tmpl->{'font'} ) { + $font->{'selected'} = 1; + } +} + $template->param( proflist => \@proflist, units => \@units, + fonts => \@fonts, tmpl_id => $tmpl->{'tmpl_id'}, tmpl_code => $tmpl->{'tmpl_code'}, diff --git a/labels/label-print-pdf.pl b/labels/label-print-pdf.pl index e2cfe2772b..68a6b7fc4e 100755 --- a/labels/label-print-pdf.pl +++ b/labels/label-print-pdf.pl @@ -10,7 +10,6 @@ use HTML::Template::Pro; use PDF::Reuse; use PDF::Reuse::Barcode; use POSIX; -#use C4::Labels; #use Smart::Comments; my $DEBUG = 0; @@ -27,7 +26,7 @@ my $spine_text = ""; # get the printing settings my $template = GetActiveLabelTemplate(); my $conf_data = get_label_options(); -my $profile = GetAssociatedProfile($template->{'tmpl_id'}); +my $profile = GetAssociatedProfile($template->{'tmpl_id'}); my $batch_id = $cgi->param('batch_id'); my @resultsloop = get_label_items($batch_id); @@ -45,21 +44,8 @@ warn "Starting on label #$start_label" if $DEBUG; my $fontsize = $template->{'fontsize'}; my $units = $template->{'units'}; -### $printingtype; - -=c -################### defaults for testing -my $barcodetype = 'CODE39'; -my $printingtype = 'BARBIB'; -my $guidebox = 1; -my $start_label = 1; -my $units = 'POINTS' -=cut - -#my $fontsize = 3; - -#warn "UNITS $units"; -#warn "fontsize = $fontsize"; +warn "UNITS $units"; +warn "fontsize = $fontsize"; #warn Dumper $template; my $unitvalue = GetUnitsValue($units); @@ -88,8 +74,24 @@ warn "pghth=$page_height, pgwth=$page_width, lblhth=$label_height, lblwth=$label my $label_cols = $template->{'cols'}; my $label_rows = $template->{'rows'}; -my $text_wrap_cols = GetTextWrapCols( $fontsize, $label_width ); +my $margin = $top_margin; +my $left_text_margin = 3; # FIXME: This value should not be hardcoded +my $str; + +prInitVars(); +$| = 1; +prFile(); + +# Some peritent notes from PDF::Reuse regarding prFont()... +# If a font wasn't found, Helvetica will be set. +# These names are always recognized: Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Courier, Courier-Bold, +# Courier-Oblique, Courier-BoldOblique, Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique +# They can be abbreviated: TR, TB, TI, TBI, C, CB, CO, CBO, H, HB, HO, HBO +my $fontname = $template->{'font'}; +my $font = prFont( $fontname ); + +my $text_wrap_cols = GetTextWrapCols( $font, $fontsize, $label_width, $left_text_margin ); #warn $label_cols, $label_rows; @@ -99,20 +101,8 @@ my $lowerLeftY = 0; my $upperRightX = $page_width; my $upperRightY = $page_height; -prInitVars(); -$| = 1; -prFile(); - prMbox( $lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY ); -# later feature, change the font-type and size? -prFont('C'); # Just setting a font -prFontSize($fontsize); - -my $margin = $top_margin; -my $left_text_margin = 3; -my $str; - #warn "STARTROW = $startrow\n"; #my $page_break_count = $startrow; @@ -223,7 +213,7 @@ foreach $item (@resultsloop) { DrawBarcode( $x_pos, $barcode_y, $barcode_height, $label_width, $barcode, $barcodetype ); - DrawSpineText( $y_pos, $text_height, $fontsize, $x_pos, + DrawSpineText( $y_pos, $text_height, $label_width, $font, $fontsize, $x_pos, $left_text_margin, $text_wrap_cols, \$item, \$conf_data ); CalcNextLabelPos(); @@ -234,7 +224,7 @@ foreach $item (@resultsloop) { my $barcode_height = $label_height / 2; DrawBarcode( $x_pos, $y_pos, $barcode_height, $label_width, $barcode, $barcodetype ); - DrawSpineText( $y_pos, $label_height, $fontsize, $x_pos, + DrawSpineText( $y_pos, $label_height, $label_width, $font, $fontsize, $x_pos, $left_text_margin, $text_wrap_cols, \$item, \$conf_data ); CalcNextLabelPos(); @@ -246,7 +236,7 @@ foreach $item (@resultsloop) { $barcodetype ); CalcNextLabelPos(); drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox; - DrawSpineText( $y_pos, $label_height, $fontsize, $x_pos, + DrawSpineText( $y_pos, $label_height, $label_width, $font, $fontsize, $x_pos, $left_text_margin, $text_wrap_cols, \$item, \$conf_data ); CalcNextLabelPos(); @@ -255,8 +245,8 @@ foreach $item (@resultsloop) { elsif ( $printingtype eq 'BIB' ) { drawbox( $x_pos, $y_pos, $label_width, $label_height ) if $guidebox; - DrawSpineText( $y_pos, $label_height, $fontsize, $x_pos, - $left_text_margin, $text_wrap_cols, \$item, \$conf_data ); + DrawSpineText( $y_pos, $label_height, $label_width, $font, $fontsize, $x_pos, + $left_text_margin, $text_wrap_cols, \$item, \$conf_data, $printingtype ); CalcNextLabelPos(); } diff --git a/labels/label-save-template.pl b/labels/label-save-template.pl index b8e477b179..492379023c 100755 --- a/labels/label-save-template.pl +++ b/labels/label-save-template.pl @@ -29,22 +29,25 @@ my $cols = $query->param('cols'); my $rows = $query->param('rows'); my $colgap = $query->param('colgap'); my $rowgap = $query->param('rowgap'); +my $font = $query->param('fonts'); my $fontsize = $query->param('fontsize'); my $units = $query->param('units'); my $active = $query->param('active'); my $prof_id = $query->param('prof_id'); -SaveTemplate( +my $dberror = SaveTemplate( $tmpl_id, $tmpl_code, $tmpl_desc, $page_width, $page_height, $label_width, $label_height, $topmargin, $leftmargin, $cols, $rows, $colgap, - $rowgap, $fontsize, $units + $rowgap, $font, $fontsize, $units ); SetAssociatedProfile( $prof_id, $tmpl_id ) if $prof_id; +warn "Database returned the following error: $dberror" if $dberror; + print $query->redirect("./label-templates.pl"); -- 2.39.2