Skip to content

Commit d1a722c

Browse files
committed
feat: stringify all labels (so mcid can be used, for instance)
1 parent 3e7f9ee commit d1a722c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/paves/image.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pathlib import Path
1212
from typing import (
1313
TYPE_CHECKING,
14+
Any,
1415
Callable,
1516
Dict,
1617
Iterable,
@@ -314,7 +315,7 @@ def show(page: Page, dpi: int = 72) -> Image.Image:
314315
return next(convert(page, dpi=dpi))
315316

316317

317-
LabelFunc = Callable[[Union[Annotation, ContentObject, Element, Rect]], str]
318+
LabelFunc = Callable[[Union[Annotation, ContentObject, Element, Rect]], Any]
318319
BoxFunc = Callable[[Union[Annotation, ContentObject, Element, Rect]], Rect]
319320

320321

@@ -519,7 +520,7 @@ def box(
519520
except ValueError: # it has no content and no box
520521
continue
521522
draw = ImageDraw.ImageDraw(image)
522-
text = labelfunc(obj)
523+
text = str(labelfunc(obj))
523524
obj_color = make_color(text)
524525
draw.rectangle((left, top, right, bottom), outline=obj_color)
525526
if label:
@@ -588,7 +589,7 @@ def mark(
588589
except ValueError: # it has no content and no box
589590
continue
590591
draw = ImageDraw.ImageDraw(overlay)
591-
text = labelfunc(obj)
592+
text = str(labelfunc(obj))
592593
obj_color = make_color(text)
593594
draw.rectangle((left, top, right, bottom), fill=obj_color)
594595
mask_draw = ImageDraw.ImageDraw(mask)

0 commit comments

Comments
 (0)