-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththerealnotebook.rb
More file actions
56 lines (47 loc) · 1.46 KB
/
therealnotebook.rb
File metadata and controls
56 lines (47 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require "prawn"
require "prawn/measurement_extensions"
module TheRealNoteBook
NOTE_RULE_PADDING = (152.0/59.0).mm
CLEF_PADDING = 11.mm
CLEFS_PER_PAGE = 12
# (x * 5 + 11) * 12 - 11 - x = 273
# 60x + 132 - 11 - x = 273
# 59x = 152
# x = 152 / 59
TEXT_RULING_PADDING = 7.mm
TEXT_RULES_PER_PAGE = 40
# (40 - 1) * 7 = 273
PAGE_COUNT = 96
A4_PAGE_BOX = [210.mm - 12.mm - 25.mm, 297.mm - 12.mm - 12.mm]
# 297 - 24 = 273
ODD_MARGINS = { margin: 12.mm, left_margin: 25.mm }
EVEN_MARGINS = { margin: 12.mm, right_margin: 25.mm }
extend self
def call
Prawn::Document.generate("therealnotebook.pdf", margin: 12.mm, left_margin: 25.mm, page_size: "A4") do |pdf|
render_cover(pdf)
render_back_cover(pdf)
(PAGE_COUNT / 2).times do
render_note_sheet(pdf)
render_text_sheet(pdf)
end
end
end
def render_back_cover(pdf)
pdf.start_new_page
end
def render_text_sheet(pdf)
pdf.start_new_page(margin: 12.mm, right_margin: 25.mm)
TEXT_RULES_PER_PAGE.times { pdf.pad_bottom(TEXT_RULING_PADDING) { pdf.stroke_horizontal_rule } }
end
def render_note_sheet(pdf)
pdf.start_new_page(margin: 12.mm, left_margin: 25.mm)
CLEFS_PER_PAGE.times { pdf.pad_bottom(CLEF_PADDING) { render_clef(pdf) } }
end
def render_cover(pdf)
pdf.image "./manhog_cover.png", fit: A4_PAGE_BOX
end
def render_clef(pdf)
5.times { pdf.pad_bottom(NOTE_RULE_PADDING) { pdf.stroke_horizontal_rule } }
end
end