text rotation macro for receipts/slips collab/phasefx/rotated_receipt_text
authorJason Etheridge <jason@esilibrary.com>
Mon, 14 May 2012 16:14:30 +0000 (12:14 -0400)
committerJason Etheridge <jason@esilibrary.com>
Mon, 14 May 2012 16:31:53 +0000 (12:31 -0400)
%ROTATE(degrees)%
%ROTATE(degrees,'extra CSS')%
%ROTATE_END%

Degrees is an integer, but typically you'd use values like 90, -90, 180, 45 etc.

The things between %ROTATE% and %ROTATE_END% macros will be rotated by the
specified number of degrees.  Negative values rotate counter-clockwise.  Except
for very minimal receipts with judicious use of line breaks, simple rotation
will probably truncate part of whatever is being rotated.  So, there's an
'extra CSS' variant where you can specify more CSS to fine tune positioning of
the rotated text/objects.

For an example, try this for a hold_slip template:

    Header:
        This item needs to be routed to <b>%route_to%</b>:<br/>
        Barcode: %item_barcode%<br/>
        Title: %item_title%<br/>
        <br/>
        %ROTATE(90,'position: absolute; top: 150px; left: 100px')%
        %hold_for_msg%<br/>
        Barcode: %PATRON_BARCODE%<br/>
        Notify by phone: %notify_by_phone%<br/>
        Notified by text: %notify_by_text%<br/>
        Notified by email: %notify_by_email%<br/>
        %ROTATE_END%
        %ROTATE(760,'position: absolute; top: 150px; left: 50px')%

    Line Item:
        %formatted_note%<br/>

    Footer:
        %ROTATE_END%
        <br/><br/><br/><br/><br/><br/>
        <br/><br/><br/><br/><br/><br/>
        Request date: %request_date%<br/>
        Slip Date: %TODAY_TRIM%<br/>
        Printed by %STAFF_FIRSTNAME% at %SHORTNAME%<br/>
        <br/>

And then try replacing the

        %ROTATE(90,'position: absolute; top: 150px; left: 100px')%

with a mere

        %ROTATE(90)%

and note how the text starts overlapping and becomes truncated.

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/xul/staff_client/chrome/content/util/print.js

index 166b486..ccd3a7d 100644 (file)
@@ -459,6 +459,34 @@ util.print.prototype = {
                 s = s.replace(/\s*%-TRIM%/g,'');
             } catch(E) { dump(E+'\n'); }
 
+            // Text rotation
+            try {
+                var rotate_patt=/%ROTATE\(\s*(-?\d+)\s*\)%/;
+                while(match = rotate_patt.exec(s)) {
+                    var degrees = parseInt(match[1]);
+                    s = s.replace(
+                        match[0],
+                        '<span style="-moz-transform: rotate(' + degrees + 'deg);">'
+                    );
+                }
+                var ex_rotate_patt=/%ROTATE\(\s*(-?\d+)\s*,\s*'(.*?)'\s*\)%/;
+                while(match = ex_rotate_patt.exec(s)) {
+                    var degrees = parseInt(match[1]);
+                    var extra_css = match[2]; // things like position: absolute; top: 150px; etc.
+                    s = s.replace(
+                        match[0],
+                        '<span style="-moz-transform: rotate(' + degrees + 'deg); ' + extra_css + '">'
+                    );
+                }
+                var end_rotate_patt=/%ROTATE_END%/;
+                while(match = end_rotate_patt.exec(s)) {
+                    s = s.replace(
+                        match[0],
+                        '</span>'
+                    );
+                }
+            } catch(E) { dump(E+'\n'); }
+
             return s;
         } catch(E) {
             alert('Error in print.js, template_sub(): ' + E);