utils/pdf: do not crash on field without a /Rect (#75698)
gitea/passerelle/pipeline/head This commit looks good Details

This commit is contained in:
Benjamin Dauvergne 2023-03-22 12:18:27 +01:00 committed by Gitea
parent 64456cde9f
commit 2fbfeedb14
1 changed files with 14 additions and 3 deletions

View File

@ -38,6 +38,8 @@ class Rect(typing.NamedTuple):
@classmethod
def from_pdf_annotation(cls, annotation):
if not annotation.Rect:
raise ValueError('annotation has no rect')
return cls(*map(float, annotation.Rect))
@ -120,14 +122,23 @@ class Widget:
@property
def rect(self):
return self.rects[0]
rects = self.rects
return self.rects[0] if rects else Rect(9999, 9999, 9999, 9999)
@property
def rects(self):
annotations = []
if self.widget_type == 'radio':
return [Rect.from_pdf_annotation(kid) for kid in self.kids_ordered_by_rect]
annotations = self.kids_ordered_by_rect
else:
return [Rect.from_pdf_annotation(self.annotation)]
annotations = [self.annotation]
rects = []
for annotation in annotations:
try:
rects.append(Rect.from_pdf_annotation(annotation))
except ValueError:
pass
return rects
@property
def digest_id(self):