Better margins, sizing, layout...

This commit is contained in:
Piotr Dobrowolski 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' source 'https://rubygems.org'
gem 'prawn' gem 'prawn'
gem 'prawn-qrcode' gem 'prawn-qrcode', :git => 'https://github.com/jabbrwcky/prawn-qrcode', :ref => 'd492904'
gem 'prawn-svg' gem 'prawn-svg'
gem 'sinatra' gem 'sinatra'
gem 'color' 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 GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
@ -13,9 +22,6 @@ GEM
prawn (2.1.0) prawn (2.1.0)
pdf-core (~> 0.6.1) pdf-core (~> 0.6.1)
ttfunk (~> 1.4.0) ttfunk (~> 1.4.0)
prawn-qrcode (0.3.0)
prawn (>= 1)
rqrcode (>= 0.4.1)
prawn-svg (0.26.0) prawn-svg (0.26.0)
css_parser (~> 1.3) css_parser (~> 1.3)
prawn (>= 0.11.1, < 3) prawn (>= 0.11.1, < 3)
@ -41,7 +47,7 @@ DEPENDENCIES
excon excon
json json
prawn prawn
prawn-qrcode prawn-qrcode!
prawn-svg prawn-svg
rmagick rmagick
sinatra sinatra

27
main.rb
View File

@ -21,7 +21,7 @@ module Excon
end end
end end
BACKEND_URL = 'http://inventory.waw.hackerspace.pl/api/1/' BACKEND_URL = 'https://inventory.waw.hackerspace.pl/api/1/'
CODE_PREFIX = "HTTP://I/" CODE_PREFIX = "HTTP://I/"
def api(uri) def api(uri)
@ -52,12 +52,11 @@ def render_identicode(data, id, extent)
end end
def render_label(label) def render_label(label)
margin = 2
label = api("labels/#{label}") label = api("labels/#{label}")
pdf = Prawn::Document.new(page_size: [89, 36].map { |x| mm2pt(x) }, 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" => { font_families.update("DejaVuSans" => {
normal: "fonts/DejaVuSans.ttf", normal: "fonts/DejaVuSans.ttf",
italic: "fonts/DejaVuSans-Oblique.ttf", italic: "fonts/DejaVuSans-Oblique.ttf",
@ -67,21 +66,23 @@ def render_label(label)
font 'DejaVuSans' font 'DejaVuSans'
svg IO.read("hsyrenka.svg"),
position: :right, vposition: :bottom,
height: 0.5*bounds.height
# 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, print_qr_code CODE_PREFIX + label['id'], stroke: false,
extent: mm2pt(36-2*margin), foreground_color: color, foreground_color: '000000',
pos: [bounds.left, bounds.top] 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'], text_box label['item']['name'],
size: 30, align: :center, valign: :center, size: 30, align: :center, valign: :center,
inline_format: true, inline_format: true, overflow: :shrink_to_fit
width: bounds.width - bounds.height - 8, end
height: bounds.height - 10,
at: [bounds.left+bounds.height, bounds.top - 5],
overflow: :shrink_to_fit
end end
pdf.render pdf.render