fix all tests
Python CI / test (push) Failing after 7m0s

This commit is contained in:
2025-10-06 22:28:48 +02:00
parent 718027f3c8
commit fdb3023919
10 changed files with 389 additions and 54 deletions
+6 -1
View File
@@ -366,7 +366,12 @@ class Line(Box):
spacing_length = self._spacing[0] * (len(self._text_objects) - 1)
remaining=self._size[0] - word_length - spacing_length
fraction = remaining / text.width
spliter = max(1, round(fraction*len(word.text))) # get the split index for best spacing, use original word length
# Calculate split position: fraction represents what portion of the hyphenated word fits
# We need to scale this to the original word length, accounting for the hyphen
hyphenated_length = len(word.text) + 1 # +1 for hyphen
split_in_hyphenated = round(fraction * hyphenated_length)
# Map back to original word, ensuring we don't go past the word length
spliter = min(len(word.text) - 1, max(1, split_in_hyphenated))
split = [Text(word.text[:spliter]+"-", word.style, self._draw, line=self, source=word), Text(word.text[spliter:], word.style, self._draw, line=self, source=word)]
self._text_objects.append(split[0])
word.add_concete(split)
+12 -2
View File
@@ -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
+4 -2
View File
@@ -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()