Skip to content

refactor: extract BaseVisualReader for common zoom/fit/layout#16

Merged
gvonness-apolitical merged 1 commit intomainfrom
refactor/base-visual-reader
Feb 3, 2026
Merged

refactor: extract BaseVisualReader for common zoom/fit/layout#16
gvonness-apolitical merged 1 commit intomainfrom
refactor/base-visual-reader

Conversation

@gvonness-apolitical
Copy link
Copy Markdown
Collaborator

Summary

Extracts common zoom, fit mode, layout mode, and TOC state management into a shared BaseVisualReader base class, reducing code duplication across PDF, CBZ, and EPUB readers.

Changes

  • Create BaseVisualReader extending BaseReader with:

    • Protected state: zoomLevel, fitMode, layoutMode, cachedToc
    • Public methods: getZoom, setZoom, getFitMode, setFitMode, getLayout, setLayout
    • Abstract onDisplayChange() for subclass-specific re-rendering
    • Abstract goToTocItem() for format-specific TOC navigation
    • Default getToc() returning cached TOC
  • Update readers to extend BaseVisualReader:

    • PdfReader: Implements onDisplayChange() to call renderPage(currentPage)
    • CbzReader: Implements onDisplayChange() to call renderPage(currentPageNum)
    • EpubReader: Implements onDisplayChange() to call applyZoom() and applyLayout()

Impact

  • Removes ~100 lines of duplicate code
  • Centralizes zoom clamping and state management
  • Makes it easier to add new visual readers with consistent behavior

Test plan

  • All 149 existing tests pass
  • Build succeeds
  • Manual testing: PDF, CBZ, EPUB zoom/fit/layout controls

- Create BaseVisualReader extending BaseReader with shared state management
- Move zoomLevel, fitMode, layoutMode, cachedToc to base class
- Implement common getZoom, setZoom, getFitMode, setFitMode, getLayout, setLayout
- Add abstract onDisplayChange() for subclass-specific re-rendering
- Update PDF, CBZ, and EPUB readers to extend BaseVisualReader
- Removes ~100 lines of duplicate code across readers
@gvonness-apolitical gvonness-apolitical merged commit 9e56fa8 into main Feb 3, 2026
3 checks passed
@gvonness-apolitical gvonness-apolitical deleted the refactor/base-visual-reader branch February 3, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant