From 68033ab7d2c020eb2f01ea7db1b4ac70c052e578 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Tue, 23 Apr 2024 20:09:39 +0300 Subject: [PATCH] fix files link position --- lib/submissions/generate_result_attachments.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/submissions/generate_result_attachments.rb b/lib/submissions/generate_result_attachments.rb index 7d4e060c..80cf2ccf 100644 --- a/lib/submissions/generate_result_attachments.rb +++ b/lib/submissions/generate_result_attachments.rb @@ -147,17 +147,22 @@ module Submissions attachment_uuid = Array.wrap(value)[acc] attachment = submitter.attachments.find { |a| a.uuid == attachment_uuid } - next_index = - lines[(index + 1)..].index { |l| l.items.first.is_a?(HexaPDF::Layout::InlineBox) } || (lines.size - 1) + next_index = lines[(index + 1)..].index { |l| l.items.first.is_a?(HexaPDF::Layout::InlineBox) } + next_index += index if next_index + next_index ||= lines.size - 1 + + diff = ((area['h'] * height) / 2) - (lines.sum(&:height) / 2) page[:Annots] << pdf.add( { Type: :Annot, Subtype: :Link, Rect: [ (area['x'] * width) + TEXT_LEFT_MARGIN, - height - (area['y'] * height) - lines[...index].sum(&:height) + height_diff, + height - (area['y'] * height) - lines[...index].sum(&:height) + + height_diff - (height_diff.zero? ? diff : 0), (area['x'] * width) + (area['w'] * width) + TEXT_LEFT_MARGIN, - height - (area['y'] * height) - lines[..next_index].sum(&:height) + height_diff + height - (area['y'] * height) - lines[..next_index].sum(&:height) + + height_diff - (height_diff.zero? ? diff : 0) ], A: { Type: :Action, S: :URI, URI: ActiveStorage::Blob.proxy_url(attachment.blob) }