Skip to content

Commit 7af721f

Browse files
committed
Fixed y-offset error for wider aspect ratios
1 parent fd408a8 commit 7af721f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

rmrl/pens/highlighter.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ def paint_stroke(self, canvas, stroke):
5555
width = segment.width
5656

5757
l = [x1-x0, y1-y0]
58-
v0 = -l[1]/l[0]
59-
scale = (1+v0**2)**0.5
60-
orthogonal = [v0/scale, 1/scale]
58+
if l[0] == 0:
59+
orthogonal = [1, 0]
60+
else:
61+
v0 = -l[1]/l[0]
62+
scale = (1+v0**2)**0.5
63+
orthogonal = [v0/scale, 1/scale]
6164

6265
xmin = x0-width/2*orthogonal[0]
6366
ymin = y0-width/2*orthogonal[1]

rmrl/render.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ def do_apply_ocg(basepage, rmpage, i, uses_base_pdf, ocgprop, annotations):
390390
return ocgorderinner
391391

392392
def invert_coords(point) -> Tuple[float]:
393-
print(point)
394393
x = (point.x * PTPERPX)
395394
y = PDFHEIGHT - (point.y * PTPERPX)
396395
return (x, y)
@@ -410,7 +409,6 @@ def apply_annotations(rmpage, page_annot, ocgorderinner):
410409

411410
w = x2-x1
412411
h = y1-y2
413-
print(a.quadpoints.points)
414412
qp = [c for p in map(invert_coords, a.quadpoints.points) for c in p]
415413

416414
pdf_a = PdfDict(Type=PdfName('Annot'),
@@ -505,6 +503,8 @@ def merge_pages(basepage, rmpage, changed_page, expand_pages):
505503
else:
506504
assert False, f"Unexpected rotation: {effective_rotation}"
507505

506+
annot_adjust = [0, 0]
507+
508508
if bpage_ratio <= rpage_ratio:
509509
# These ratios < 1, so this indicates the basepage is more
510510
# narrow, and thus we need to extend the width. Extra space
@@ -521,6 +521,9 @@ def merge_pages(basepage, rmpage, changed_page, expand_pages):
521521
# Height and width are flipped for the basepage
522522
new_height = rpage_ratio * bpage_w
523523
scale = bpage_w / rpage_h
524+
# Not needed in the x-dim b/c extra space is added to the
525+
# right side, which doesn't impact alignment
526+
annot_adjust[1] = bpage_box[3] - new_height
524527
if effective_rotation == 90:
525528
bpage_box[3] = new_height + bpage_box[1]
526529
else:
@@ -531,6 +534,7 @@ def merge_pages(basepage, rmpage, changed_page, expand_pages):
531534
if not flip_base_dims:
532535
new_height = 1/rpage_ratio * bpage_w
533536
scale = bpage_w / rpage_w
537+
annot_adjust[1] = bpage_box[3] - new_height
534538
if effective_rotation == 0:
535539
bpage_box[1] = bpage_box[3] - new_height
536540
else:
@@ -585,7 +589,6 @@ def merge_pages(basepage, rmpage, changed_page, expand_pages):
585589
qp = annot.QuadPoints
586590
rmpage.Annots[a].QuadPoints = PdfArray(rotate_annot_points(qp))
587591

588-
annot_adjust = [0, 0]
589592

590593
if '/Annots' in rmpage:
591594
for a, annot in enumerate(rmpage.Annots):

0 commit comments

Comments
 (0)