From 5c9cd1031a991e317af87664987cc82e00636d59 Mon Sep 17 00:00:00 2001 From: Bernardo Gonzalez Kriegel Date: Tue, 8 Apr 2014 21:35:56 -0300 Subject: [PATCH] Bug 8375 - Followup 2 - Fix label justification/aligning This patch use prText alignment to produce center or right align in text To test (with former patches applied): 1. Try a batch of mixed scripts with layout alignment center or right, only latin scripts align almost correctly. I would suggest to use Helvetica 2. Apply the patch 3. Verify again, now strings must be correctly aligned --- labels/label-create-pdf.pl | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/labels/label-create-pdf.pl b/labels/label-create-pdf.pl index 3976d4e..05fde1a 100755 --- a/labels/label-create-pdf.pl +++ b/labels/label-create-pdf.pl @@ -90,7 +90,17 @@ sub _print_text { foreach my $text_line (@$label_text) { $pdf->Font($layout->get_attr('font')); $pdf->FontSize( $text_line->{'font_size'} ); - $pdf->Text( $text_line->{'text_llx'}, $text_line->{'text_lly'}, $text_line->{'line'} ); + my $llx = $text_line->{'text_llx'}; + my $align = ''; + if ( $layout->get_attr('text_justify') eq 'C' ) { + $llx += $template->get_attr('label_width')/2.0; + $align = 'center'; + } + elsif ( $layout->get_attr('text_justify') eq 'R' ) { + $llx += $template->get_attr('label_width'); + $align = 'right'; + } + $pdf->Text( $llx, $text_line->{'text_lly'}, $text_line->{'line'}, $align ); } } @@ -142,7 +152,6 @@ foreach my $item (@{$items}) { font => $layout->get_attr('font'), font_size => $layout->get_attr('font_size'), callnum_split => $layout->get_attr('callnum_split'), - justify => $layout->get_attr('text_justify'), format_string => $layout->get_attr('format_string'), text_wrap_cols => $layout->get_text_wrap_cols(label_width => $template->get_attr('label_width'), left_text_margin => $template->get_attr('left_text_margin')), ); @@ -165,7 +174,6 @@ foreach my $item (@{$items}) { font => $layout->get_attr('font'), font_size => $layout->get_attr('font_size'), callnum_split => $layout->get_attr('callnum_split'), - justify => $layout->get_attr('text_justify'), format_string => $layout->get_attr('format_string'), text_wrap_cols => $layout->get_text_wrap_cols(label_width => $template->get_attr('label_width'), left_text_margin => $template->get_attr('left_text_margin')), ); @@ -191,7 +199,6 @@ foreach my $item (@{$items}) { font => $layout->get_attr('font'), font_size => $layout->get_attr('font_size'), callnum_split => $layout->get_attr('callnum_split'), - justify => $layout->get_attr('text_justify'), format_string => $layout->get_attr('format_string'), text_wrap_cols => $layout->get_text_wrap_cols(label_width => $template->get_attr('label_width'), left_text_margin => $template->get_attr('left_text_margin')), ); -- 1.7.9.5