diff --git a/Gemfile b/Gemfile index 3391828..111df68 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' gem 'prawn' -gem 'prawn-qrcode', :git => 'https://github.com/jabbrwcky/prawn-qrcode', :ref => 'd492904' +gem 'prawn-qrcode', :git => 'https://github.com/jabbrwcky/prawn-qrcode' gem 'prawn-svg' gem 'sinatra' gem 'color' diff --git a/Gemfile.lock b/Gemfile.lock index 7ebd19a..3d5400b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,11 +1,10 @@ GIT remote: https://github.com/jabbrwcky/prawn-qrcode - revision: d4929043950962f299cb16873fc500bc4682bbed - ref: d492904 + revision: 08e457af2d6661ede3346a3a3dc3b99a9df9fd9b specs: - prawn-qrcode (0.3.0) + prawn-qrcode (0.5.1) prawn (>= 1) - rqrcode (>= 0.4.1) + rqrcode (>= 1.0.0) GEM remote: https://rubygems.org/ diff --git a/main.rb b/main.rb index aaa9dd3..64b3306 100644 --- a/main.rb +++ b/main.rb @@ -1,5 +1,6 @@ require 'rubygems' require 'sinatra' +require 'rqrcode' require 'prawn' require 'prawn/measurements' require 'prawn/qrcode' @@ -12,21 +13,20 @@ require 'zlib' include Prawn::Measurements -module Prawn - module Text - module Formatted #:nodoc: - # @private - class LineWrap #:nodoc: - def whitespace() - # Wrap by these special characters as well - "&:/\\" + - "\s\t#{zero_width_space()}" - end - end - end - end -end - +# module Prawn +# module Text +# module Formatted #:nodoc: +# # @private +# class LineWrap #:nodoc: +# def whitespace() +# # Wrap by these special characters as well +# "&:/\\" + +# "\s\t#{zero_width_space()}" +# end +# end +# end +# end +# end module Excon class Response @@ -67,11 +67,10 @@ def render_identicode(data, id, extent) fill_color '000000' end -def render_label(label) +def render_label(item_or_label_id, size = [89, 36]) + item = api("items/#{item_or_label_id}") - label = api("labels/#{label}") - - pdf = Prawn::Document.new(page_size: [89, 36].map { |x| mm2pt(x) }, + pdf = Prawn::Document.new(page_size: size.map { |x| mm2pt(x) }, margin: [2, 2, 2, 6].map { |x| mm2pt(x) }) do font_families.update("DejaVuSans" => { normal: "fonts/DejaVuSans.ttf", @@ -82,20 +81,19 @@ def render_label(label) font 'DejaVuSans' - # Width of right side rw = bounds.height/2 # Right side - bounding_box([bounds.right - rw, bounds.top], :width => rw) do - print_qr_code CODE_PREFIX + label['id'], stroke: false, + bounding_box([bounds.right - rw, bounds.top], width: rw) do + print_qr_code CODE_PREFIX + item['short_id'], stroke: false, foreground_color: '000000', extent: bounds.width, margin: 0, pos: bounds.top_left end # Left side - bounding_box(bounds.top_left, :width => bounds.width-rw) do - text_box label['item']['name'], + bounding_box(bounds.top_left, width: bounds.width - rw) do + text_box item['name'], size: 40, align: :center, valign: :center, width: bounds.width-10, inline_format: true, overflow: :shrink_to_fit, disable_wrap_by_char: true end