Skip to content

Commit

Permalink
address various nits
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Apr 4, 2024
1 parent 4bfb461 commit ac7903f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/devel/changelog_staging.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<!-- List character: dash (-) -->

# Changelog for next release
- PdfDocument.get_toc(): Replaced bookmark namedtuple `PdfOutlineItem` with method-oriented wrapper classes `PdfBookmark` and `PdfDest`, so callers may retrieve only the properties they actually need. This is closer to pdfium's original API and exposes the underlying raw objects. Also provide signed count as-is rather than needlessly splitting it in two variables (unsigned int `n_kids` and bool `is_closed`).
- `PdfDocument.get_toc()`: Replaced `PdfOutlineItem` namedtuple with method-oriented wrapper classes `PdfBookmark` and `PdfDest`, so callers may retrieve only the properties they actually need. This is closer to pdfium's original API and exposes the underlying raw objects. Also provide signed count as-is rather than needlessly splitting in two variables (unsigned int `n_kids` and bool `is_closed`).

<!-- TODO
See https://github.com/pypdfium2-team/pypdfium2/blob/devel_old/docs/devel/changelog_staging.md
for how to proceed. Note that some things are already done, and some rejected, though.
for how to proceed. Note that some things are already done, and some rejected.
-->
4 changes: 2 additions & 2 deletions src/pypdfium2/_cli/toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def main(args):
count, dest = bm.get_count(), bm.get_dest()
out = " " * bm.level
out += "[%s] %s -> " % (
"*" if count == 0 else f"{count:+}",
f"{count:+}" if count != 0 else "*",
bm.get_title(),
)
# distinguish between "no dest" and "dest with invalid values" while keeping result machine readable
# distinguish between "no dest" and "dest with unknown mode" while keeping result machine readable
if dest:
index, (view_mode, view_pos) = dest.get_index(), dest.get_view()
out += "%s # %s %s" % (
Expand Down
8 changes: 4 additions & 4 deletions src/pypdfium2/_helpers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def new_page(self, width, height, index=None):
def del_page(self, index):
"""
Remove the page at *index* (zero-based).
It is recommended to close any open handles to the page before deleting it.
It is recommended to close any open handles to the page before calling this method.
"""
# FIXME not sure how pdfium would behave if the caller tries to access a handle to a deleted page...
pdfium_c.FPDFPage_Delete(self, index)
Expand Down Expand Up @@ -519,7 +519,7 @@ def get_toc(
if level < max_depth-1:
yield from self.get_toc(max_depth=max_depth, parent=bm_ptr, level=level+1, seen=seen)
elif pdfium_c.FPDFBookmark_GetFirstChild(self, bm_ptr):
# Warn only if there actually is a subtree. If level == max_depth but the tree ends there, it's fine as no information is skipped.
# Warn only if there actually is a subtree. If level == max_depth but the tree ends there, it's fine as no info is skipped.
logger.warning(f"Maximum recursion depth {max_depth} reached (subtree skipped).")

bm_ptr = pdfium_c.FPDFBookmark_GetNextSibling(self, bm_ptr)
Expand Down Expand Up @@ -606,7 +606,7 @@ def as_pageobject(self):
Returns:
PdfObject: An independent page object representation of the XObject.
If multiple page objects are created from one XObject, they share resources.
Page objects created from an XObject remain valid after the XObject is closed.
Pageobjects created from an XObject remain valid after the XObject is closed.
"""
raw_pageobj = pdfium_c.FPDF_NewFormObjectFromXObject(self)
return PdfObject( # not a child object (see above)
Expand Down Expand Up @@ -651,7 +651,7 @@ class PdfBookmark (pdfium_i.AutoCastable):
pdf (PdfDocument):
Reference to the document this bookmark belongs to.
level (int):
The bookmark's nesting level in the TOC tree. Corresponds to the number of parent bookmarks.
The bookmark's nesting level in the TOC tree (zero-based). Corresponds to the number of parent bookmarks.
"""

def __init__(self, raw, pdf, level):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_gettoc():
for bm in toc:
dest = bm.get_dest()
view_mode, view_pos = dest.get_view()
assert view_mode is pdfium_c.PDFDEST_VIEW_XYZ
assert view_mode == pdfium_c.PDFDEST_VIEW_XYZ
assert round(view_pos[0]) == 89

# check last bookmark
Expand Down

0 comments on commit ac7903f

Please sign in to comment.