utils/pdf: do not crash on field without a /Rect (#75698)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
64456cde9f
commit
2fbfeedb14
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue