Better margins, sizing, layout...
This commit is contained in:
parent
f3e0f3ff9e
commit
3a98c23838
2
Gemfile
2
Gemfile
|
@ -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'
|
||||||
|
|
14
Gemfile.lock
14
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
|
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
|
||||||
|
|
33
main.rb
33
main.rb
|
@ -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
|
|
||||||
|
|
||||||
print_qr_code CODE_PREFIX + label['id'], stroke: false,
|
# Width of right side
|
||||||
extent: mm2pt(36-2*margin), foreground_color: color,
|
rw = bounds.height/2
|
||||||
pos: [bounds.left, bounds.top]
|
|
||||||
|
|
||||||
text_box label['item']['name'],
|
# Right side
|
||||||
size: 30, align: :center, valign: :center,
|
bounding_box([bounds.right - rw, bounds.top], :width => rw) do
|
||||||
inline_format: true,
|
print_qr_code CODE_PREFIX + label['id'], stroke: false,
|
||||||
width: bounds.width - bounds.height - 8,
|
foreground_color: '000000',
|
||||||
height: bounds.height - 10,
|
extent: bounds.width, margin: 0, pos: bounds.top_left
|
||||||
at: [bounds.left+bounds.height, bounds.top - 5],
|
end
|
||||||
overflow: :shrink_to_fit
|
|
||||||
|
# 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
|
end
|
||||||
|
|
||||||
pdf.render
|
pdf.render
|
||||||
|
|
Loading…
Reference in New Issue