summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dobrowolski <admin@tastycode.pl>2017-05-29 00:51:24 +0200
committerPiotr Dobrowolski <admin@tastycode.pl>2017-05-29 00:51:24 +0200
commit3a98c2383837d5dfeafc74cc059da52f94a18bff (patch)
tree837c95a3311f1ba72b78a4ea936870358b090466
parentf3e0f3ff9e37526f8ffaefa6efeaa05ba7ba06d5 (diff)
downloadspejstore-labelmaker-3a98c2383837d5dfeafc74cc059da52f94a18bff.tar.gz
spejstore-labelmaker-3a98c2383837d5dfeafc74cc059da52f94a18bff.tar.bz2
spejstore-labelmaker-3a98c2383837d5dfeafc74cc059da52f94a18bff.zip
Better margins, sizing, layout...
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock14
-rw-r--r--main.rb37
3 files changed, 30 insertions, 23 deletions
diff --git a/Gemfile b/Gemfile
index 07bd885..3391828 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,7 +1,7 @@
source 'https://rubygems.org'
gem 'prawn'
-gem 'prawn-qrcode'
+gem 'prawn-qrcode', :git => 'https://github.com/jabbrwcky/prawn-qrcode', :ref => 'd492904'
gem 'prawn-svg'
gem 'sinatra'
gem 'color'
diff --git a/Gemfile.lock b/Gemfile.lock
index 628de18..f7f0c59 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,3 +1,12 @@
+GIT
+ remote: https://github.com/jabbrwcky/prawn-qrcode
+ revision: d4929043950962f299cb16873fc500bc4682bbed
+ ref: d492904
+ specs:
+ prawn-qrcode (0.3.0)
+ prawn (>= 1)
+ rqrcode (>= 0.4.1)
+
GEM
remote: https://rubygems.org/
specs:
@@ -13,9 +22,6 @@ GEM
prawn (2.1.0)
pdf-core (~> 0.6.1)
ttfunk (~> 1.4.0)
- prawn-qrcode (0.3.0)
- prawn (>= 1)
- rqrcode (>= 0.4.1)
prawn-svg (0.26.0)
css_parser (~> 1.3)
prawn (>= 0.11.1, < 3)
@@ -41,7 +47,7 @@ DEPENDENCIES
excon
json
prawn
- prawn-qrcode
+ prawn-qrcode!
prawn-svg
rmagick
sinatra
diff --git a/main.rb b/main.rb
index 837d332..32b5ab9 100644
--- a/main.rb
+++ b/main.rb
@@ -21,7 +21,7 @@ module Excon
end
end
-BACKEND_URL = 'http://inventory.waw.hackerspace.pl/api/1/'
+BACKEND_URL = 'https://inventory.waw.hackerspace.pl/api/1/'
CODE_PREFIX = "HTTP://I/"
def api(uri)
@@ -52,12 +52,11 @@ def render_identicode(data, id, extent)
end
def render_label(label)
- margin = 2
label = api("labels/#{label}")
pdf = Prawn::Document.new(page_size: [89, 36].map { |x| mm2pt(x) },
- margin: mm2pt(margin)) do
+ margin: [2, 2, 2, 6].map { |x| mm2pt(x) }) do
font_families.update("DejaVuSans" => {
normal: "fonts/DejaVuSans.ttf",
italic: "fonts/DejaVuSans-Oblique.ttf",
@@ -67,21 +66,23 @@ def render_label(label)
font 'DejaVuSans'
- svg IO.read("hsyrenka.svg"),
- position: :right, vposition: :bottom,
- height: 0.5*bounds.height
-
- print_qr_code CODE_PREFIX + label['id'], stroke: false,
- extent: mm2pt(36-2*margin), foreground_color: color,
- pos: [bounds.left, bounds.top]
-
- text_box label['item']['name'],
- size: 30, align: :center, valign: :center,
- inline_format: true,
- width: bounds.width - bounds.height - 8,
- height: bounds.height - 10,
- at: [bounds.left+bounds.height, bounds.top - 5],
- overflow: :shrink_to_fit
+
+ # 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,
+ 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'],
+ size: 30, align: :center, valign: :center,
+ inline_format: true, overflow: :shrink_to_fit
+ end
end
pdf.render