@@ -98,7 +98,7 @@ class ChapterNavigator:
|
||||
# Create position for this heading
|
||||
position = RenderingPosition(
|
||||
chapter_index=current_chapter_index,
|
||||
block_index=0, # Heading is first block in its chapter
|
||||
block_index=block_index, # Use actual block index
|
||||
word_index=0,
|
||||
table_row=0,
|
||||
table_col=0,
|
||||
@@ -233,7 +233,11 @@ class BidirectionalLayouter:
|
||||
current_pos = position.copy()
|
||||
|
||||
# Start laying out blocks from the current position
|
||||
while current_pos.chapter_index < len(self.blocks) and page.free_space()[1] > 0:
|
||||
while current_pos.block_index < len(self.blocks) and page.free_space()[1] > 0:
|
||||
# Additional bounds check to prevent IndexError
|
||||
if current_pos.block_index >= len(self.blocks):
|
||||
break
|
||||
|
||||
block = self.blocks[current_pos.block_index]
|
||||
|
||||
# Apply font scaling to the block
|
||||
@@ -246,6 +250,12 @@ class BidirectionalLayouter:
|
||||
# Block doesn't fit, we're done with this page
|
||||
break
|
||||
|
||||
# Ensure new position doesn't go beyond bounds
|
||||
if new_pos.block_index >= len(self.blocks):
|
||||
# We've reached the end of the document
|
||||
current_pos = new_pos
|
||||
break
|
||||
|
||||
current_pos = new_pos
|
||||
|
||||
return page, current_pos
|
||||
|
||||
@@ -164,7 +164,8 @@ class EreaderLayoutManager:
|
||||
page_size: Tuple[int, int],
|
||||
document_id: str = "default",
|
||||
buffer_size: int = 5,
|
||||
page_style: Optional[PageStyle] = None):
|
||||
page_style: Optional[PageStyle] = None,
|
||||
bookmarks_dir: str = "bookmarks"):
|
||||
"""
|
||||
Initialize the ereader layout manager.
|
||||
|
||||
@@ -174,6 +175,7 @@ class EreaderLayoutManager:
|
||||
document_id: Unique identifier for the document (for bookmarks/position)
|
||||
buffer_size: Number of pages to cache in each direction
|
||||
page_style: Custom page styling (uses default if None)
|
||||
bookmarks_dir: Directory to store bookmark files
|
||||
"""
|
||||
self.blocks = blocks
|
||||
self.page_size = page_size
|
||||
@@ -187,7 +189,7 @@ class EreaderLayoutManager:
|
||||
# Initialize core components
|
||||
self.renderer = BufferedPageRenderer(blocks, page_style, buffer_size, page_size)
|
||||
self.chapter_navigator = ChapterNavigator(blocks)
|
||||
self.bookmark_manager = BookmarkManager(document_id)
|
||||
self.bookmark_manager = BookmarkManager(document_id, bookmarks_dir)
|
||||
|
||||
# Current state
|
||||
self.current_position = RenderingPosition()
|
||||
|
||||
Reference in New Issue
Block a user