-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore unrecognized page titles in the outline
Issue #23
- Loading branch information
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from djvu import sexpr | ||
from pdfrw import IndirectPdfDict | ||
|
||
from .outline import OutlineTransformVisitor | ||
|
||
|
||
def test_basic_outline(): | ||
src = sexpr.ListExpression([ | ||
sexpr.SymbolExpression(sexpr.Symbol('bookmarks')), | ||
sexpr.ListExpression([ | ||
sexpr.StringExpression(b'Chapter 2'), | ||
sexpr.StringExpression(b'#100'), | ||
]) | ||
]) | ||
|
||
visitor = OutlineTransformVisitor() | ||
bookmarks = visitor.visit(src) | ||
assert bookmarks.Count == 1 | ||
assert bookmarks.First.Title == 'Chapter 2' | ||
assert bookmarks.First.A.D[0] == 99 # The page number | ||
|
||
|
||
def test_nested_outline(): | ||
src = sexpr.ListExpression([ | ||
sexpr.SymbolExpression(sexpr.Symbol('bookmarks')), | ||
sexpr.ListExpression([ | ||
sexpr.StringExpression(b'Chapter 2'), | ||
sexpr.StringExpression(b'#100'), | ||
sexpr.ListExpression([ | ||
sexpr.StringExpression(b'Chapter 2.1'), | ||
sexpr.StringExpression(b'#200'), | ||
]) | ||
]) | ||
]) | ||
|
||
visitor = OutlineTransformVisitor() | ||
bookmarks = visitor.visit(src) | ||
assert bookmarks.Count == 1 | ||
assert bookmarks.First.Count == 1 | ||
assert bookmarks.First.A.D[0] == 99 # The page number of chapter 2 | ||
assert bookmarks.First.First.A.D[0] == 199 # The page number of chapter 2.1 | ||
|
||
|
||
# Sometimes the page numbers are instead page titles, which our libdjvu bindings do not support | ||
# We ignore them since there is not much we can do in this case | ||
# See https://github.com/kcroker/dpsprep/issues/23 | ||
def test_outline_with_page_titles(): | ||
src = sexpr.ListExpression([ | ||
sexpr.SymbolExpression(sexpr.Symbol('bookmarks')), | ||
sexpr.ListExpression([ | ||
sexpr.StringExpression(b'Preface'), | ||
sexpr.StringExpression(b'#f007.djvu'), | ||
]), | ||
sexpr.ListExpression([ | ||
sexpr.StringExpression(b'Contents'), | ||
sexpr.StringExpression(b'#f011.djvu'), | ||
]), | ||
sexpr.ListExpression([ | ||
sexpr.StringExpression(b'0 Prologue'), | ||
sexpr.StringExpression(b'#p001.djvu') | ||
]) | ||
]) | ||
|
||
visitor = OutlineTransformVisitor() | ||
bookmarks = visitor.visit(src) | ||
empty_pdf_dict = IndirectPdfDict() | ||
assert bookmarks == empty_pdf_dict |