Skip to content

feat: EPUB text alignment and hyphenation settings (refs #286) - #302

Merged
van-geaux merged 4 commits into
van-geaux:mainfrom
chortya:up/feat-epub-alignment-hyphenation
Oct 22, 2026
Merged

van-geaux merged 4 commits into
van-geaux:mainfrom
chortya:up/feat-epub-alignment-hyphenation

Conversation

@chortya

@chortya chortya commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Contribution pause

The maintainer lifted the pause and invited split PRs in #286.

  • The change is scoped to one feature (EPUB text alignment and hyphenation settings). Independent of the spread and OLED PRs.
  • Compatible with the provider-module refactor: reader preferences and UI only.
  • Tests and manual-validation status are documented.
  • No credentials, cookies, API keys, private server URLs, or generated local data are included.

Summary

EPUB text was never hyphenated, and there was no setting for it or for justification. Two per-library settings are added. They appear in the in-book reader options (Typography) and in the library reader settings (shared EpubTypesettingSettings):

Setting Values Readium mapping
Text alignment Left (default), Justified textAlign = START (follows text direction, so RTL books keep their own edge) / JUSTIFY
Hyphenation Auto (default), On, Off hyphens; Auto hyphenates justified text only

The defaults (Left + Auto) keep today's rendering.

Browser hyphenation needs a content language. Books that declare none get the device language through Readium's language preference (epubFallbackContentLanguage). This is skipped for RTL and CJK device languages, because Readium also derives RTL and vertical layout from the language and those scripts have no hyphenation patterns. All changes apply live without reopening the book. Older stored profiles default to Left + Auto.

Verification

  • ./gradlew :app:testDebugUnitTest — 953/953 pass (new EpubTypesettingPreferencesTest: storage round trip, legacy defaults, Auto rules, language fallback). :app:lintDebug — 0 errors. :app:assembleDebug succeeds. No added trailing whitespace; line endings preserved.
  • Connected, Pixel Fold API 36 emulator:
    • New EpubTypesettingActivityInstrumentedTest 2/2 — measured inside the reader WebView: default is ragged and unhyphenated; Justified hyphenates long words with flush lines; Off removes hyphens; Left + On hyphenates; a book without a declared language is hyphenated in the device language.
    • ReadiumEpubOpenInstrumentedTest 16/18; the 2 failures (selectsARealReadiumPositionForNonzeroServerPercentage, generatedEpubImageColorOverrideIsUniversalAndIdempotent) also fail on main on this emulator (new typesettingPreferencesMapToReadiumAlignmentHyphensAndLanguage passes).
    • EpubReaderOptionsOverlayInstrumentedTest 4/9 (new epubAlignmentAndHyphenationChoicesUpdateOnlyTheirSettings passes); the same 5 fail on main on this emulator.
  • Device: requested after a Galaxy Z Fold8 screenshot showed unhyphenated justified-looking text; used on that device from the fork build. This branch itself was run only on the emulator. The library-settings chips have no dedicated connected test.
  • Peer review (Codex GPT-6-Astra): the no-language test assumed an English device locale. Fixed: the page language is checked on any hyphenating locale, and the hyphenation check only runs when that language is English (the fixture text is English).

🤖 Generated with Claude Code

@van-geaux

Copy link
Copy Markdown
Owner

Thanks @chortya, the EPUB typesetting changes look good and CI is passing. GitHub still reports a conflict with main, so please update the branch and resolve it before merging.

@chortya
chortya force-pushed the up/feat-epub-alignment-hyphenation branch from 7469625 to 9e92753 Compare October 21, 2026 06:20
@chortya

chortya commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! Rebased onto current main and resolved the conflicts with #300: the readium preferences take both the spread and the typesetting parameters, and in the library reader settings "EPUB text" sits above "Unfolded screens". CI is green again. #303 is rebased on top of this branch.

Heads-up: #301 and #302 both add a section at the same spot in docs/testing.md and docs/architecture.md, so whichever merges second will need a quick docs-only rebase. I'll handle that.

@van-geaux

Copy link
Copy Markdown
Owner

Thanks @chortya, the implementation and tests look good. As you mentioned, please update the branch after PR #301 is merged and resolve the documentation conflicts. Once that’s done, this should be ready to merge.

chortya and others added 4 commits October 21, 2026 16:24
Adds per-library Text alignment (Left/Justified) and Hyphenation
(Auto/On/Off; Auto hyphenates justified text only) to the reader
settings and the in-book options sheet, mapped to Readium textAlign and
hyphens and applied live. Books that declare no language get the device
language so the browser can hyphenate; RTL and CJK device languages are
skipped because Readium derives layout from the language.

Tests: JVM storage/fallback rules; on-device measurement of hyphenated
words and flush lines on both spread pages, the no-language fallback,
and the options-sheet controls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The in-book options and the library reader settings share one
EpubTypesettingSettings composable, so both offer the same chips.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EpubTypesettingActivityInstrumentedTest runs on a single page: default
ragged and unhyphenated, Justified hyphenates with flush lines, Off
removes hyphens, Left with On hyphenates, and a book without a declared
language is hyphenated in the device language. Adds the reader test hooks
it needs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The page language is checked for every hyphenating device language; the
hyphenation check needs English, which the fixture text is in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chortya
chortya force-pushed the up/feat-epub-alignment-hyphenation branch from 9e92753 to 99c34d8 Compare October 21, 2026 14:50
@chortya

chortya commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Updated on top of #301: resolved the docs conflicts, keeping both the OLED and the alignment/hyphenation sections. CI is green.

@van-geaux van-geaux left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the latest head. No blocking correctness, security, lifecycle, or persistence issues found. Local verification passed 1,002 JVM tests, Android-test Kotlin compilation, lint, and debug APK assembly; GitHub build-and-test is also passing. The CRLF diff-check warning is limited to the repository's existing docs/testing.md line-ending convention.

@van-geaux
van-geaux merged commit 72338f3 into van-geaux:main Oct 22, 2026
1 check passed
van-geaux pushed a commit that referenced this pull request Oct 23, 2026
…d on #302, refs #286) (#303)

* feat: per-book language for read-aloud voices and hyphenation

Readium picks one read-aloud language (book metadata, else the device
locale) and lists only its voices, with no way to change it; the
hyphenation fallback made the same assumption. Adds a Book language
setting to the in-book options (This book): Auto shows whether it comes
from the book or the device, and an override is remembered per book,
sent to the EPUB navigator for hyphenation and to the read-aloud
navigator for voices, and applied live during playback.

Tests: JVM resolution and option rules; on-device voice lists with the
system speech engine (Auto, live switch, start in override), page
language and persistence across recreation, and the picker UI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: book-language changes during read-aloud preparation; lazy language picker

- A book-language (or voice setting) change made while read-aloud is
  preparing is applied once the navigator exists.
- The book-language picker is a dialog with a lazy list instead of a menu
  composing ~200 items.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: book-language override also applies to chapters that declare a language

Readium only injects its language into documents whose <html> declares
none. The current-document bridge now also sets the override on <html>
and <body> (lang and xml:lang) and restores the publisher's values on
Auto, so hyphenation follows the chosen language in every chapter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep each book's language choice separate per server profile

The same book ID can exist on another server or account, so the per-book
language override is now keyed by the active server profile (the boundary
#309 uses for downloads and snapshots) as well as the reader key.

Choices now survive switching profiles instead of being wiped for every
profile. Signing out clears only the signed-out profile's choices, for
BookOrbit, Kavita and Komga alike.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants