Sha256: 7a75f1ced51146d201230458e5ee921b2a6250e5be88405b3cf7cb5d74c4df73
Contents?: true
Size: 1.79 KB
Versions: 1
Compression:
Stored size: 1.79 KB
Contents
# frozen_string_literal: true module Prawn module SwissQRBill # Horizontal and vertical cutting lines with a scissor symbol class CuttingLines SCISSOR_FILE = File.expand_path("#{__dir__}/images/scissor.png") SCISSOR_WIDTH = 5.mm SCISSOR_HEIGHT = 3.mm PAD_LEFT = 5.mm PAD_TOP = 1.mm attr_reader :doc, :receipt_width, :receipt_height def initialize(document) @doc = document @brain = {} load_specs end def draw set_styles draw_strokes draw_scissors reset_styles end private def load_specs specs = Specifications.new @receipt_height = specs.get('receipt.height').mm @receipt_width = specs.get('receipt.width').mm end def set_styles @brain[:line_width] = doc.line_width doc.line_width 0.5 doc.dash 2, space: 2 end def draw_strokes doc.stroke { doc.line [0, receipt_height], [doc.bounds.right, receipt_height] } doc.stroke { doc.line [receipt_width, receipt_height], [receipt_width, doc.bounds.bottom] } end def draw_scissors doc.bounding_box([doc.bounds.left + PAD_LEFT, receipt_height + (SCISSOR_HEIGHT / 2)], width: SCISSOR_WIDTH, height: SCISSOR_HEIGHT) do doc.image SCISSOR_FILE, width: SCISSOR_WIDTH end doc.bounding_box([receipt_width - (SCISSOR_HEIGHT / 2), receipt_height - PAD_TOP], width: SCISSOR_WIDTH, height: SCISSOR_HEIGHT) do doc.rotate(270, origin: [0, 0]) do doc.image SCISSOR_FILE, width: SCISSOR_WIDTH end end end def reset_styles doc.line_width = @brain[:line_width] doc.undash end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
prawn-swiss_qr_bill-0.4.1 | lib/prawn/swiss_qr_bill/cutting_lines.rb |