Use per-page annotation spacing with inferred margin fallback
This commit is contained in:
1 parent
b069805988
commit
0bb6f7d97c
10 files changed
+170
-39
No files matched your search
@@ -61,13 +61,26 @@ def move_answer_pdf(source, destination):
|
||||
metadata_path(source).unlink(missing_ok=True)
|
||||
|
||||
|
||||
def added_margin(margin_mm):
|
||||
"""Interpolate the configured (millimetres, pixels) points, clamping at ends."""
|
||||
if margin_mm is None:
|
||||
return configuration.ANNOTATION_MARGIN_LEFT
|
||||
points = configuration.ANNOTATION_MARGIN_POINTS
|
||||
if (not points or any(x < 0 or type(y) is not int or y < 0 for x, y in points)
|
||||
or any(a[0] >= b[0] for a, b in zip(points, points[1:]))):
|
||||
raise ValueError('Annotation margin points must have increasing mm and non-negative integer pixels')
|
||||
if margin_mm <= points[0][0]:
|
||||
return points[0][1]
|
||||
for (x0, y0), (x1, y1) in zip(points, points[1:]):
|
||||
if margin_mm <= x1:
|
||||
return round(y0 + (y1 - y0) * (margin_mm - x0) / (x1 - x0))
|
||||
return points[-1][1]
|
||||
|
||||
|
||||
def layout_for(pdf):
|
||||
low = any(part.get('margin_status') == 'low' for part in answer_parts(pdf))
|
||||
margin = (configuration.ANNOTATION_LOW_MARGIN_LEFT if low
|
||||
else configuration.ANNOTATION_MARGIN_LEFT)
|
||||
if type(margin) is not int or margin < 0:
|
||||
raise ValueError('Annotation left margins must be non-negative integers')
|
||||
return {'version': 1, 'margin_left': margin, 'narrow_left_pad_limit': 300}
|
||||
margins = [added_margin(part.get('margin_mm')) for part in answer_parts(pdf)]
|
||||
return {'version': 2, 'margin_left': max(margins, default=added_margin(None)),
|
||||
'page_margins': margins, 'narrow_left_pad_limit': 0}
|
||||
|
||||
|
||||
def legacy_layout():
|
||||
|
||||
Reference in new issue
Block a user