Bug 12194: Add option 'Oblique title' in labels
authorBernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Fri, 26 Jun 2015 19:13:52 +0000 (16:13 -0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Thu, 22 Oct 2015 12:42:31 +0000 (09:42 -0300)
This patch adds a checkbox on Label creator
to use or not an oblique variant of main font
for title

Also fix font selection for title in case an
oblique variant is used.

To test:
Before patch
1) Go to Tools > Label creator
2) Create a new layout, default values but select
any 'Oblique' variant for main font and
'Biblio/Barcode' for layout type
3) Go to Manage batches, create a batch, add items,
export PDF, download
4) Check logs, you must find a line with
'ERROR in koha-conf.xml -- missing <font type="COO">'
for example if main font Courier-Oblique

5) Open PDF, title could be right but not using selected font

After patch
6) Apply the patch
7) Run updatedatabase.pl
8) Repeat 1-2, note new checkbox 'Oblique title',
default checked
9) Repeat export, no new warnings on log
10) Create a new layout or edit an existent one,
uncheck 'Oblique title', save, export again
Check PDF has non slanted title

Followed test plan, works as expected. (See comment #11).
Signed-off-by: Marc VĂ©ron <veron@veron.ch>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
C4/Creators/Layout.pm
C4/Labels/Label.pm
installer/data/mysql/atomicupdate/bug-12194-add-column-oblique_title.sql [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-layout.tt
labels/label-create-pdf.pl
labels/label-edit-layout.pl

index a660ef6..cf0b751 100644 (file)
@@ -33,6 +33,7 @@ sub _check_params {
         'printing_type',
         'layout_name',
         'guidebox',
+        'oblique_title',
         'font',
         'font_size',
         'callnum_split',
@@ -78,6 +79,7 @@ sub new {
             printing_type   =>      'BAR',
             layout_name     =>      'DEFAULT',
             guidebox        =>      0,
+            oblique_title   =>      1,
             font            =>      'TR',
             font_size       =>      3,
             callnum_split   =>      0,
index 271c6bc..ca12437 100644 (file)
@@ -35,6 +35,7 @@ sub _check_params {
         'barcode_type',
         'printing_type',
         'guidebox',
+        'oblique_title',
         'font',
         'font_size',
         'callnum_split',
@@ -326,6 +327,7 @@ sub new {
         barcode_type            => $params{'barcode_type'},
         printing_type           => $params{'printing_type'},
         guidebox                => $params{'guidebox'},
+        oblique_title           => $params{'oblique_title'},
         font                    => $params{'font'},
         font_size               => $params{'font_size'},
         callnum_split           => $params{'callnum_split'},
@@ -408,8 +410,18 @@ sub draw_label_text {
         else {
             $field->{'data'} = _get_barcode_data($field->{'code'},$item,$record);
         }
-        #FIXME: We should not force the title to oblique; this should be selectible in the layout configuration
-        ($field->{'code'} eq 'title') ? (($font =~ /T/) ? ($font = 'TI') : ($font = ($font . 'O'))) : ($font = $font);
+        # Find apropriate font it oblique title selected, except main font is oblique
+        if ( ( $field->{'code'} eq 'title' ) and ( $self->{'oblique_title'} == 1 ) ) {
+            if ( $font =~ /^TB$/ ) {
+                $font .= 'I';
+            }
+            elsif ( $font =~ /^TR$/ ) {
+                $font = 'TI';
+            }
+            elsif ( $font !~ /^T/ and $font !~ /O$/ ) {
+                $font .= 'O';
+            }
+        }
         my $field_data = $field->{'data'};
         if ($field_data) {
             $field_data =~ s/\n//g;
diff --git a/installer/data/mysql/atomicupdate/bug-12194-add-column-oblique_title.sql b/installer/data/mysql/atomicupdate/bug-12194-add-column-oblique_title.sql
new file mode 100644 (file)
index 0000000..200379f
--- /dev/null
@@ -0,0 +1,10 @@
+ALTER TABLE creator_layouts ADD COLUMN oblique_title INT(1) NULL DEFAULT 1 AFTER guidebox;
+
+-- $DBversion = "3.21.00.XXX";
+-- if ( CheckVersion($DBversion) ) {
+--     $dbh->do(q|
+--         ALTER TABLE creator_layouts ADD COLUMN oblique_title INT(1) NULL DEFAULT 1 AFTER guidebox
+--     |);
+--     print "Upgrade to $DBversion done (Bug 12194: Add column oblique_title to layouts)\n";
+--     SetVersion($DBversion);
+-- }
index 0b334f2..b53fa06 100644 (file)
                     $('#layout_string').hide();
                 }
             }
+            function checkOblique() {
+                var font = document.getElementById("font");
+                var selectedfont = font.options[font.selectedIndex].value;
+                if ( selectedfont.match("I$") || selectedfont.match("O$") ) {
+                    document.getElementById("oblique_title").disabled = true;
+                } else {
+                    document.getElementById("oblique_title").disabled = false;
+                }
+            }
         //]]>
     </script>
 </head>
                                 </li>
                                 <li>
                                     <label for="font">Font: </label>
-                                    <select name="font" id="font">
+                                    <select name="font" id="font" onchange="checkOblique()">
                                         [% FOREACH font_type IN font_types %]
                                         [% IF ( font_type.selected ) %]
                                         <option value="[% font_type.type %]" selected="selected">[% font_type.name %]</option>
                                     <label for="font_size">Font size: </label>
                                     <input type="text" name="font_size" id="font_size" size="2" value="[% font_size |html %]" />
                                 </li>
+                                <li>
+                                    <label for="font">Oblique title: </label>
+                                    [% IF ( oblique_title ) %]
+                                    <input type="checkbox" name="oblique_title" id="oblique_title" value="1"  checked="checked" />
+                                    [% ELSE %]
+                                    <input type="checkbox" name="oblique_title" id="oblique_title" value="1" />
+                                    [% END %]
+                                </li>
                             </ol>
                         </fieldset>
                         <fieldset class="action">
index e69ba41..5589fb6 100755 (executable)
@@ -139,6 +139,7 @@ foreach my $item (@{$items}) {
                                         barcode_type        => $layout->get_attr('barcode_type'),
                                         printing_type       => 'BIB',
                                         guidebox            => $layout->get_attr('guidebox'),
+                                        oblique_title       => $layout->get_attr('oblique_title'),
                                         font                => $layout->get_attr('font'),
                                         font_size           => $layout->get_attr('font_size'),
                                         callnum_split       => $layout->get_attr('callnum_split'),
@@ -162,6 +163,7 @@ foreach my $item (@{$items}) {
                                         barcode_type        => $layout->get_attr('barcode_type'),
                                         printing_type       => 'BAR',
                                         guidebox            => $layout->get_attr('guidebox'),
+                                        oblique_title       => $layout->get_attr('oblique_title'),
                                         font                => $layout->get_attr('font'),
                                         font_size           => $layout->get_attr('font_size'),
                                         callnum_split       => $layout->get_attr('callnum_split'),
@@ -188,6 +190,7 @@ foreach my $item (@{$items}) {
                                         barcode_type        => $layout->get_attr('barcode_type'),
                                         printing_type       => $layout->get_attr('printing_type'),
                                         guidebox            => $layout->get_attr('guidebox'),
+                                        oblique_title       => $layout->get_attr('oblique_title'),
                                         font                => $layout->get_attr('font'),
                                         font_size           => $layout->get_attr('font_size'),
                                         callnum_split       => $layout->get_attr('callnum_split'),
index 150ad3d..f84a01d 100755 (executable)
@@ -107,6 +107,7 @@ elsif  ($op eq 'save') {
                     printing_type   => $cgi->param('printing_type') || 'BAR',
                     layout_name     => $cgi->param('layout_name') || 'DEFAULT',
                     guidebox        => ($cgi->param('guidebox') ? 1 : 0),
+                    oblique_title   => ($cgi->param('oblique_title') ? 1 : 0),
                     font            => $cgi->param('font') || 'TR',
                     font_size       => $cgi->param('font_size') || 3,
                     callnum_split   => ($cgi->param('callnum_split') ? 1 : 0),
@@ -145,6 +146,7 @@ $template->param(
         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'),
         callnum_split   => $layout->get_attr('callnum_split'),
         format_string   => $layout->get_attr('format_string'),