Better margins, sizing, layout...

master
informatic 2017-05-29 00:51:24 +02:00
parent f3e0f3ff9e
commit 3a98c23838
3 changed files with 28 additions and 21 deletions

View File

@ -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'

View File

@ -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

33
main.rb
View File

@ -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]
# Width of right side
rw = bounds.height/2
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
# 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