-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollation-4.py
217 lines (151 loc) · 7.04 KB
/
collation-4.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 25 20:11:01 2017
@author: Matthew Holford
"""
#version 4 : make canvas size relative to quire size
def draw_quire(quire, quire_no, start_folio, y, texts):
leaf_svg = ''
#controls the distance between final y coordinate of folios
#40 gives reasonable legibility with two inserted leaves in a row
interval = 40
leaves = quire[0]
canvas_height = (leaves*interval) + 50
#centre of quire
centre = [50, (canvas_height/2) + y]
#label the quire with its number
leaf_svg += '<text x="{}" y="{}" font-size="10">Quire {}</text>'.format(0, centre[1], quire_no)
missing_leaves = quire[1]
added_leaves = quire[2]
total_leaves = leaves + len(added_leaves)
#define middle opening of quire
middle = (leaves/2) +0.5 #or total_leaves?
folio_no = start_folio
#this keeps track of position relative to the original quire structure
leaf_counter = 1
for i in range(1, total_leaves+1):
#draw a missing leaf. Do not increment folio number. Do increment leaf counter.
if i in missing_leaves:
x1 = centre[0]
y1 = centre[1]
x2=x1+80
#y coord aligns with following or previous folio.
#This line could be shorter.
if leaf_counter < middle:
y2 = y1 - ((((leaves/2)-leaf_counter)+1)*(interval*0.75))
else:
y2 = y1 + ((leaf_counter-(leaves/2))*(interval*0.75))
leaf_svg += '<line x1="{}" y1="{}" x2="{}" y2="{}" stroke-width="1" stroke="black"/>'.format(x1, y1, x2, y2)
leaf_counter += 1
#draw an added leaf. Do increment folio number.Do not increment leaf counter.
elif i in added_leaves:
#centre relative to middle of quire
x1 = 90
x2 = x1 + 70
#position not just based on leaf_counter any more but on i
#say 2 leaves after quire leaf 6 (of 8) = now folios 7, 8
#y = 150 + 40 + ?5
#centre + (leaf_counter-leaves/2)*interval +
if leaf_counter < middle:
y1 = centre[1] - ((((leaves/2)-leaf_counter)+1)*(interval*0.5))-((i-leaf_counter) *2)
y2 = y1 - ((((leaves/2)-leaf_counter)+1)*(interval*0.75))-((i-leaf_counter) *6)
else:
y1 = centre[1] + (((leaf_counter-1)-(leaves/2))*(interval*0.5)) +((i-leaf_counter)*2)
y2 = y1 + (((leaf_counter-1)-(leaves/2))*(interval*0.75))+((i-leaf_counter)*6)
leaf_svg += '<line x1="{}" y1="{}" x2="{}" y2="{}" stroke-width="1" stroke="black"/>'.format(x1, y1, x2, y2)
#folio label
x2 += 10
leaf_svg += '<text x="{}" y="{}" font-size="10">Fol. {}</text>'.format(x2, y2, folio_no)
folio_no += 1
#draw a normal leaf. Do increment folio number. Do increment leaf counter.
else:
x1 = centre[0]
y1 = centre[1]
x2=x1+100
#calculate end y of leaf
#centre y is (say) 150
#if before middle:
#leaf 4 of 8 leaves = 130
# i.e. 150 - ((leaves/2) - leaf_counter)+1)*20
#leaf 5 of 8 = 170
#i.e. 150 + 20, i.e. leaf_counter-leaves/2 *20
if leaf_counter < middle:
y2 = y1 - ((((leaves/2)-leaf_counter)+1)*interval)
else:
y2 = y1 + ((leaf_counter-(leaves/2))*interval)
leaf_svg += '<line x1="{}" y1="{}" x2="{}" y2="{}" stroke-width="1" stroke="black"/>'.format(x1, y1, x2, y2)
#add folio label
x2 += 20
leaf_svg += '<text x="{}" y="{}" font-size="10">Fol. {}</text>'.format(x2, y2, folio_no)
leaf_counter += 1
folio_no += 1
#check to see if a text begins or ends
for text in texts:
if text[0] == folio_no:
x2 += 40
leaf_svg += '<text x="{}" y="{}" font-size="10">Beginning of text: {}</text>'.format(x2, y2, text[1])
return leaf_svg
#==============================================================================
# #sample date 1 from Penn MS Codex 1170
# #http://openn.library.upenn.edu/Data/0002/mscodex1170/data/mscodex1170_TEI.xml
#
# #quire data: number of leaves
# quires = [12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 4]
#
# #text data: start folio, title
# texts = [[2, 'Sermones de tribus partibus penitencie'],
# [146, 'Modus confitendi'], [155, 'Brevis tractalus de statu religionis']]
#
#
#==============================================================================
#EL 9 h 10
#1-58 610(through f. 50) 74 86 9-308 316 322 (+3, f. 245) 33-508
#==============================================================================
# quires = [[8, [], []], [8, [], []], [8, [], []], [8, [], []], [8, [], []],
# [10, [], []], [4, [], []], [6, [], []], [8, [], []], [8, [], []],
# [8, [], []], [8, [], []], [8, [], []], [8, [], []], [8, [], []], [8, [], []],
# [8, [], []], [8, [], []], [8, [], []], [8, [], []], [8, [], []],
# [8, [], []], [8, [], []], [8, [], []], [8, [], []], [8, [], []],
# [8, [], []], [8, [], []], [8, [], []], [8, [], []], [6, [], []],
# [2, [], [3]], [8, [], []], [8, [], []], [8, [], []], [8, [], []],
# [8, [], []], [8, [], []], [8, [], []], [8, [], []], [8, [], []],
# [8, [], []], [8, [], []], [8, [], []],[8, [], []],[8, [], []],[8, [], []],
# [8, [], []],[8, [], []],[8, [], []]]
#==============================================================================
#sample data
#quire = [leaves, [missing leaves], [added leaves]]
#maybe add start folio too?
ms_name = 'sample'
quires = [[8, [], [3]], [6, [5], [7]], [8, [], [7, 8]]]
texts = [[100, 100]]
#MAIN
svg = ''
svg += '''<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">'''
start_folio = 1
quire_no = 1
#incremental y coordinate
y=0
for quire in quires:
svg += draw_quire(quire, quire_no, start_folio, y, texts)
start_folio += quire[0] - len(quire[1]) + len(quire[2])
quire_no += 1
y += (quire[0]*40) + 100
svg += '</svg>'
print(svg)
#write svg to file
filename = ms_name + '.svg'
with open (filename, 'w') as f:
print(svg, file=f)
#write html file to embed svg so we can scroll if we need to
filename = ms_name + '.html'
with open (filename, 'w') as f:
print('''<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Collation of {}</title>
</head>
<body>
<p>Collation of {}</p>
<object data="{}.svg" type="image/svg+xml" height="{}" width="100%"/>
</body>
</html>'''.format(ms_name, ms_name, ms_name, y), file=f)