Skip to content

Add maximum line length option for screenreader accessibility#403

Open
vcaparica wants to merge 1 commit intotrypsynth:masterfrom
vcaparica:feature/text-wrapping-option
Open

Add maximum line length option for screenreader accessibility#403
vcaparica wants to merge 1 commit intotrypsynth:masterfrom
vcaparica:feature/text-wrapping-option

Conversation

@vcaparica
Copy link
Copy Markdown

Summary

  • Adds a Maximum line length setting to the Options dialog (Reading tab), allowing users to define how many characters per line before wrapping at word boundaries
  • Default is 0 (entire line, preserving current behavior). Setting it to e.g. 100 breaks long paragraphs into ~100-character lines so screenreaders read manageable chunks instead of entire paragraphs at once
  • The wrapping algorithm replaces spaces with newlines at word boundaries, preserving exact character count — so bookmarks, cursor positions, find results, and TOC navigation remain accurate with no position mapping needed
  • Also fixes an accessibility issue where checkboxes in the Options dialog were not announcing their labels to screenreaders, by setting explicit accessible names on all controls

Technical Details

  • wrap_content() in text.rs: processes each paragraph independently, splitting at word boundaries. Words longer than the limit are kept intact (no mid-word truncation)
  • apply_line_wrapping() in document.rs: applies wrapping to the document buffer and rebuilds newline position tracking
  • Wrapping is applied after parsing in DocumentSession::new(), before the document handle is created
  • When the setting changes, all open documents are saved, closed, and re-opened with the new wrapping applied
  • Includes unit tests for the wrapping function

Test plan

  • Open an EPUB with long paragraphs, verify lines display as full paragraphs with default setting (0)
  • Set maximum line length to 100, verify paragraphs wrap at ~100 characters at word boundaries
  • Verify screenreader reads one wrapped line at a time instead of entire paragraphs
  • Verify bookmarks, find, and TOC navigation work correctly after changing the setting
  • Verify changing the setting re-opens documents and restores cursor position
  • Verify all Options dialog controls announce their labels to screenreaders

Adds a configurable maximum line length setting to the Options dialog
(Reading tab). When set, long lines are wrapped at word boundaries so
screenreaders read manageable chunks instead of entire paragraphs at
once. The default value of 0 preserves the current behavior (entire
line). The wrapping replaces spaces with newlines, preserving character
count so bookmarks, positions, and navigation remain accurate.

Also sets explicit accessible names on all Options dialog controls to
ensure screenreaders announce checkbox labels correctly.
@trypsynth
Copy link
Copy Markdown
Owner

Hi @vcaparica and thanks for the contribution! Can I ask what the use case of this feature is exactly? I'm happy to review and merge it even if I won't ever use it myself, Paperback is full of config options to make the widest array of users happy, but off the top of my head I'm struggling to come up with a use case for this. That said I primarily use Paperback to read nonfiction (e.g. programming textbooks, biographies, etc.), and I personally would never want the lines wrapped; I keep word wrap off too. Please just explain to me when you might use this feature, especially over traditional word wrap, and I'll gladly give the code a look.
Thanks!

@amirsol81
Copy link
Copy Markdown

@trypsynth This can come in handy in cases where large paragraphs in Epub or DAISY books are presented on a single long line. This is oftentimes the case, and I myself sometimes struggle to move among sentences or phrases inside such paragraphs on a single line.

@trypsynth
Copy link
Copy Markdown
Owner

What's wrong with the existing work wrap?

@4sensegaming
Copy link
Copy Markdown
Contributor

That it doesn't work. It seems to do absolutely nothing for me (Windows 11, NVDA) with any of the documents I've tried reading in Paperback so far. It acts as though there was no word wrap at all, even if enabled.

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.

4 participants