mork 0.18.0 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mork/magicko.rb +22 -9
- data/lib/mork/sheet_pdf.rb +12 -4
- data/lib/mork/version.rb +1 -1
- data/spec/mork/magicko_spec.rb +24 -0
- data/spec/mork/sheet_pdf_spec.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8cdb6af94ff682ccad23d669fb624d263ea4fb28d5911e3ada2ceeb200c8fd4a
|
|
4
|
+
data.tar.gz: 956342c055f892ee7e4c44187711b3660eefd8fcee68723bfd1cb2fb245d0a75
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0c75eaac5ad245b5c86dde97f7e68c43a08486c248014e27963c8c1f763b2cc14fbe545d13f1d75675f1367daaf11df05f8109fdf88d752324cf7972a560e9e4
|
|
7
|
+
data.tar.gz: 8864848f8f6a4a9cada44dd6f74183928fcdbf15986c97a27eb4d95ba6f60f2c9f0dd6a95ec8029fe961df0f4289da21703e8b9472c4ba6ad3f70929c043ffeb
|
data/lib/mork/magicko.rb
CHANGED
|
@@ -18,7 +18,11 @@ module Mork
|
|
|
18
18
|
# a default of 150 dpi seems sensible. It should not affect bitmaps.
|
|
19
19
|
density = 150
|
|
20
20
|
# inspect the source file
|
|
21
|
-
|
|
21
|
+
identify = MiniMagick.identify
|
|
22
|
+
identify.density density
|
|
23
|
+
identify.format '%w %h %m'
|
|
24
|
+
identify << path
|
|
25
|
+
s1, s2, s3 = Open3.capture3(*identify.command)
|
|
22
26
|
if s3.success?
|
|
23
27
|
# parse the identify command output
|
|
24
28
|
w, h, @type = s1.split(' ')
|
|
@@ -54,16 +58,17 @@ module Mork
|
|
|
54
58
|
# (i.e. the centers of the four registration marks)
|
|
55
59
|
# pp: a hash in the form of pp[:tl][:x], pp[:tl][:y], etc.
|
|
56
60
|
def registered_bytes(pp)
|
|
57
|
-
read_bytes
|
|
61
|
+
read_bytes '-distort', 'Perspective', pps(pp)
|
|
58
62
|
end
|
|
59
63
|
|
|
60
64
|
# Reading from the image file the bytes from one of the four corner
|
|
61
65
|
# squares encompassing each registration mark; the blur and dilation
|
|
62
66
|
# manipulations may prevent registration misalignments due to stray dark pixels
|
|
63
67
|
def rm_patch(c, blr=0, dlt=0)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
params = ['-crop', c.cropper]
|
|
69
|
+
params.concat ['-blur', "#{blr*3}x#{blr}"] unless blr == 0
|
|
70
|
+
params.concat ['-morphology', 'Dilate', "Octagon:#{dlt}"] unless dlt == 0
|
|
71
|
+
read_bytes(*params)
|
|
67
72
|
end
|
|
68
73
|
|
|
69
74
|
##################################
|
|
@@ -171,10 +176,18 @@ module Mork
|
|
|
171
176
|
|
|
172
177
|
# calling imagemagick and capturing the converted image
|
|
173
178
|
# into an array of bytes
|
|
174
|
-
def read_bytes(params
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
179
|
+
def read_bytes(*params)
|
|
180
|
+
# MiniMagick selects `convert` on ImageMagick 6 and `magick` on
|
|
181
|
+
# ImageMagick 7. Execute its argv directly to preserve binary stdout
|
|
182
|
+
# (MiniMagick::Tool#call strips a trailing newline) and avoid a shell.
|
|
183
|
+
command = MiniMagick.convert
|
|
184
|
+
command.depth 8
|
|
185
|
+
command.density @density if @density
|
|
186
|
+
command << @path
|
|
187
|
+
command.merge!(params)
|
|
188
|
+
command << 'gray:-'
|
|
189
|
+
|
|
190
|
+
stdout, stderr, status = Open3.capture3(*command.command)
|
|
178
191
|
if status.success?
|
|
179
192
|
stdout.unpack('C*')
|
|
180
193
|
else
|
data/lib/mork/sheet_pdf.rb
CHANGED
|
@@ -8,7 +8,8 @@ module Mork
|
|
|
8
8
|
class SheetPDF < Prawn::Document
|
|
9
9
|
DEFAULT_FONT_FAMILY = 'Open Sans'
|
|
10
10
|
DEFAULT_FONT_PATH = File.expand_path('fonts/OpenSans-Regular.ttf', __dir__)
|
|
11
|
-
|
|
11
|
+
ITEM_TEXT_RISE_EM = 0.177
|
|
12
|
+
private_constant :DEFAULT_FONT_FAMILY, :DEFAULT_FONT_PATH, :ITEM_TEXT_RISE_EM
|
|
12
13
|
|
|
13
14
|
include Extensions
|
|
14
15
|
def initialize(content, layout=nil, duplex=false)
|
|
@@ -142,7 +143,7 @@ module Mork
|
|
|
142
143
|
def question_numbers
|
|
143
144
|
ch_len.first.length.times do |i|
|
|
144
145
|
text_box "#{i+1}",
|
|
145
|
-
at: @grip.qnum_xy(i),
|
|
146
|
+
at: item_text_at(@grip.qnum_xy(i)),
|
|
146
147
|
width: @grip.qnum_width,
|
|
147
148
|
height: @grip.height_of_cell,
|
|
148
149
|
align: :right,
|
|
@@ -176,7 +177,7 @@ module Mork
|
|
|
176
177
|
@grip.width_of_uid,
|
|
177
178
|
@grip.height_of_uid,
|
|
178
179
|
@grip.uround
|
|
179
|
-
text_box i, at: [offx, 0],
|
|
180
|
+
text_box i, at: item_text_at([offx, 0]),
|
|
180
181
|
width: @grip.width_of_uid,
|
|
181
182
|
height: @grip.height_of_uid,
|
|
182
183
|
align: :center,
|
|
@@ -201,13 +202,20 @@ module Mork
|
|
|
201
202
|
@grip.height_of_cell,
|
|
202
203
|
@grip.cround
|
|
203
204
|
text_box l,
|
|
204
|
-
at: [x,0],
|
|
205
|
+
at: item_text_at([x, 0]),
|
|
205
206
|
width: @grip.width_of_cell,
|
|
206
207
|
height: @grip.height_of_cell,
|
|
207
208
|
align: :center,
|
|
208
209
|
valign: :center
|
|
209
210
|
end
|
|
210
211
|
|
|
212
|
+
# Prawn vertically centers the font's full ascender box. Open Sans has a
|
|
213
|
+
# tall ascender relative to its visible capitals and digits, so raise only
|
|
214
|
+
# item text while leaving the OMR geometry unchanged.
|
|
215
|
+
def item_text_at(position)
|
|
216
|
+
[position[0], position[1] + @grip.item_font_size * ITEM_TEXT_RISE_EM]
|
|
217
|
+
end
|
|
218
|
+
|
|
211
219
|
def equal_choice_number?
|
|
212
220
|
return @equal_choice_number unless @equal_choice_number.nil?
|
|
213
221
|
|
data/lib/mork/version.rb
CHANGED
data/spec/mork/magicko_spec.rb
CHANGED
|
@@ -39,6 +39,30 @@ module Mork
|
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
describe 'ImageMagick command selection' do
|
|
43
|
+
let(:status) { instance_double(Process::Status, success?: true) }
|
|
44
|
+
|
|
45
|
+
it 'uses ImageMagick 6 convert through MiniMagick and preserves raw bytes' do
|
|
46
|
+
magicko = ma
|
|
47
|
+
allow(MiniMagick).to receive(:imagemagick7?).and_return(false)
|
|
48
|
+
expect(Open3).to receive(:capture3).with(
|
|
49
|
+
'convert', '-depth', '8', sh.image_path, '-crop', co.cropper, 'gray:-'
|
|
50
|
+
).and_return(["\x00\x0a\xff".b, '', status])
|
|
51
|
+
|
|
52
|
+
expect(magicko.rm_patch(co)).to eq [0, 10, 255]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'uses ImageMagick 7 magick through MiniMagick' do
|
|
56
|
+
magicko = ma
|
|
57
|
+
allow(MiniMagick).to receive(:imagemagick7?).and_return(true)
|
|
58
|
+
expect(Open3).to receive(:capture3).with(
|
|
59
|
+
'magick', '-depth', '8', sh.image_path, '-crop', co.cropper, 'gray:-'
|
|
60
|
+
).and_return(["\x00".b, '', status])
|
|
61
|
+
|
|
62
|
+
expect(magicko.rm_patch(co)).to eq [0]
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
42
66
|
describe 'overlay stroke width' do
|
|
43
67
|
it 'defaults to the legacy 3-pixel width' do
|
|
44
68
|
expect(ma.overlay_stroke_width).to eq 3
|
data/spec/mork/sheet_pdf_spec.rb
CHANGED
|
@@ -68,6 +68,18 @@ module Mork
|
|
|
68
68
|
expect(bytes).to include 'OpenSans-Regular'
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
it 'raises item labels without changing their OMR coordinates' do
|
|
72
|
+
pdf = SheetPDF.new({})
|
|
73
|
+
grid = pdf.instance_variable_get('@grip')
|
|
74
|
+
cell_position = grid.item_xy(0)
|
|
75
|
+
|
|
76
|
+
text_position = pdf.send(:item_text_at, cell_position)
|
|
77
|
+
|
|
78
|
+
expect(text_position[0]).to eq cell_position[0]
|
|
79
|
+
expect(text_position[1] - cell_position[1]).to be_within(0.001).of(1.593)
|
|
80
|
+
expect(grid.item_xy(0)).to eq cell_position
|
|
81
|
+
end
|
|
82
|
+
|
|
71
83
|
it 'creates a minimal PDF sheet' do
|
|
72
84
|
s = SheetPDF.new({})
|
|
73
85
|
s.save dest 'minimal'
|