Skip to content

Commit

Permalink
Plan an API-breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Apr 15, 2023
1 parent 5f2971c commit ecd8c3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
11 changes: 9 additions & 2 deletions docs/source/planned_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@

# Planned Changes

<!-- The following API breaking changes are in consideration for the next major release: -->
Currently, no API breaking changes are planned.
<!-- Currently, no API breaking changes are planned. -->

```{note}
You may search for `TODO(v5)` to find the code spots in question.
```

The following API breaking changes are in consideration for the next major release:
- `PdfDocument.get_toc()` / `PdfOutlineItem`: The parameters `is_closed` (bool) and `n_kids` (abs int)
will be replaced by `count` (int), where the state corresponds to the value's sign.
11 changes: 4 additions & 7 deletions src/pypdfium2/_helpers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,12 @@ def _get_bookmark(self, bookmark, level):
pdfium_c.FPDFBookmark_GetTitle(bookmark, buffer, n_bytes)
title = buffer.raw[:n_bytes-2].decode('utf-16-le')

# TODO(v5) just expose count as-is rather than using two variables and doing extra work
# it's also more obvious if the number's sign just corresponds to the state (- closed, + open), rather than the current inversion with is_closed
count = pdfium_c.FPDFBookmark_GetCount(bookmark)
if count < 0:
is_closed = True
elif count == 0:
is_closed = None
else:
is_closed = False

is_closed = True if count < 0 else None if count == 0 else False
n_kids = abs(count)

dest = pdfium_c.FPDFBookmark_GetDest(self, bookmark)
page_index = pdfium_c.FPDFDest_GetDestPageIndex(self, dest)
if page_index == -1:
Expand Down

0 comments on commit ecd8c3b

Please sign in to comment.