Skip to content

Commit

Permalink
fix: now we are faster again (special-case get_transformed_bound)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Nov 27, 2024
1 parent 086bf96 commit 6631464
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## PLAYA 0.2.x
- [ ] update `pdfplumber` branch and run `pdfplumber` tests in CI
- [ ] make a separate directory for third party tests
- [ ] fix incorrect bboxes when rotation/skewing is applied (performance hit...)
- [x] fix incorrect bboxes when rotation is applied
- [x] return more useful names for custom colorspaces/patterns
- [ ] `decode_text` is remarkably slow
- [ ] `render_char` and `render_string` are also quite slow
- [ ] remove the rest of the meaningless abuses of `cast`
Expand Down
8 changes: 4 additions & 4 deletions playa/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -1419,10 +1419,10 @@ def make_path(
linewidth=gstate.linewidth,
dash_pattern=gstate.dash.dash,
dash_phase=gstate.dash.phase,
stroking_colorspace=str(gstate.scs),
stroking_colorspace=gstate.scs.name,
stroking_color=gstate.scolor.values,
stroking_pattern=gstate.scolor.pattern,
non_stroking_colorspace=str(gstate.ncs),
non_stroking_colorspace=gstate.ncs.name,
non_stroking_color=gstate.ncolor.values,
non_stroking_pattern=gstate.ncolor.pattern,
)
Expand Down Expand Up @@ -1604,10 +1604,10 @@ def render_char(
render_mode=self.textstate.render_mode,
dash_pattern=self.graphicstate.dash.dash,
dash_phase=self.graphicstate.dash.phase,
stroking_colorspace=str(self.graphicstate.scs),
stroking_colorspace=self.graphicstate.scs.name,
stroking_color=self.graphicstate.scolor.values,
stroking_pattern=self.graphicstate.scolor.pattern,
non_stroking_colorspace=str(self.graphicstate.ncs),
non_stroking_colorspace=self.graphicstate.ncs.name,
non_stroking_color=self.graphicstate.ncolor.values,
non_stroking_pattern=self.graphicstate.ncolor.pattern,
mcid=None if self.mcs is None else self.mcs.mcid,
Expand Down
8 changes: 8 additions & 0 deletions playa/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ def get_transformed_bound(matrix: Matrix, bbox: Rect) -> Rect:
"""Transform a bounding box and return the rectangle that covers
the points of the resulting shape."""
x0, y0, x1, y1 = bbox
# No rotation involved, corners are still valid. FIXME: proof
if matrix[1] >= 0 and matrix[2] >= 0:
return get_bound(
(
apply_matrix_pt(matrix, (x0, y0)),
apply_matrix_pt(matrix, (x1, y1)),
)
)
return get_bound(
(
apply_matrix_pt(matrix, (x0, y0)),
Expand Down

0 comments on commit 6631464

Please sign in to comment.