mork 0.18.0 → 0.18.1
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/sheet_pdf.rb +12 -4
- data/lib/mork/version.rb +1 -1
- 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: 9c871eb798a14173c833892d6cb6030e266158239058f9ef0fbb2ff359c1073f
|
|
4
|
+
data.tar.gz: 8e2ac94ee3e806455d617f959459eebe6964521c9711064e5f0c86facf9fda8f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 464bb64cfe62e30bba0037b154d527a00d165b1bd71b4ffa4534bc28cace42fd86aa8455d927d6d660c218d25be92cca4292f60aa66b787af8ce9ed7bea82ba9
|
|
7
|
+
data.tar.gz: 37ab32c16c165c6c120a8addca74a6bafbe44a02d494ab80968a499dd5d44bad1b6402031c3ff8703a94b8ffbcdd8fc6afd093369b9535883aa49aa2ff2dd0e3
|
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/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'
|