Skip to content

Commit

Permalink
Fixed y-offset error for wider aspect ratios
Browse files Browse the repository at this point in the history
  • Loading branch information
brush701 committed Apr 7, 2021
1 parent fd408a8 commit ab9b844
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions rmrl/pens/highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ def paint_stroke(self, canvas, stroke):
width = segment.width

l = [x1-x0, y1-y0]
v0 = -l[1]/l[0]
scale = (1+v0**2)**0.5
orthogonal = [v0/scale, 1/scale]
if l[0] == 0:
orthogonal = [1, 0]
else:
v0 = -l[1]/l[0]
scale = (1+v0**2)**0.5
orthogonal = [v0/scale, 1/scale]

xmin = x0-width/2*orthogonal[0]
ymin = y0-width/2*orthogonal[1]
Expand Down
11 changes: 7 additions & 4 deletions rmrl/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ def do_apply_ocg(basepage, rmpage, i, uses_base_pdf, ocgprop, annotations):
return ocgorderinner

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

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

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

annot_adjust = [0, 0]

if bpage_ratio <= rpage_ratio:
# These ratios < 1, so this indicates the basepage is more
# narrow, and thus we need to extend the width. Extra space
Expand All @@ -521,7 +521,10 @@ def merge_pages(basepage, rmpage, changed_page, expand_pages):
# Height and width are flipped for the basepage
new_height = rpage_ratio * bpage_w
scale = bpage_w / rpage_h
if effective_rotation == 90:
# Not needed in the x-dim b/c extra space is added to the
# right side, which doesn't impact alignment
annot_adjust[1] = bpage_box[3] - new_height
if effective_rotation == 90:
bpage_box[3] = new_height + bpage_box[1]
else:
bpage_box[1] = bpage_box[3] - new_height
Expand All @@ -531,6 +534,7 @@ def merge_pages(basepage, rmpage, changed_page, expand_pages):
if not flip_base_dims:
new_height = 1/rpage_ratio * bpage_w
scale = bpage_w / rpage_w
annot_adjust[1] = bpage_box[3] - new_height
if effective_rotation == 0:
bpage_box[1] = bpage_box[3] - new_height
else:
Expand Down Expand Up @@ -585,7 +589,6 @@ def merge_pages(basepage, rmpage, changed_page, expand_pages):
qp = annot.QuadPoints
rmpage.Annots[a].QuadPoints = PdfArray(rotate_annot_points(qp))

annot_adjust = [0, 0]

if '/Annots' in rmpage:
for a, annot in enumerate(rmpage.Annots):
Expand Down

0 comments on commit ab9b844

Please sign in to comment.