From 47f75c2b9a5502e98234b60d4c7595b69c131b9d Mon Sep 17 00:00:00 2001 From: beedaddy Date: Thu, 27 Nov 2025 14:45:47 +0100 Subject: [PATCH] Add option to force hyphenation in KEPUB (#1656) * Add option to force hyphenation in KEPUB Fixes #1465 * Default force hyphenation to false * Remove commented out code --- .../model/dto/settings/KoboSettings.java | 1 + .../appsettings/SettingPersistenceHelper.java | 3 ++- .../service/book/BookDownloadService.java | 3 ++- .../service/kobo/KepubConversionService.java | 13 +++++++++---- .../kobo-sync-settings-component.html | 18 ++++++++++++++++++ .../kobo-sync-settings-component.ts | 4 +++- .../src/app/shared/model/app-settings.model.ts | 1 + 7 files changed, 36 insertions(+), 7 deletions(-) diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/settings/KoboSettings.java b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/settings/KoboSettings.java index 7192789ff..e9565cb1c 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/settings/KoboSettings.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/settings/KoboSettings.java @@ -8,4 +8,5 @@ import lombok.Data; public class KoboSettings { private boolean convertToKepub; private int conversionLimitInMb; + private boolean forceEnableHyphenation; } diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/appsettings/SettingPersistenceHelper.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/appsettings/SettingPersistenceHelper.java index 53c9cffc9..30416db33 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/appsettings/SettingPersistenceHelper.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/appsettings/SettingPersistenceHelper.java @@ -253,6 +253,7 @@ public class SettingPersistenceHelper { return KoboSettings.builder() .convertToKepub(false) .conversionLimitInMb(100) + .forceEnableHyphenation(false) .build(); } -} \ No newline at end of file +} diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/book/BookDownloadService.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/book/BookDownloadService.java index bf35c53a4..6b6afb3f4 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/book/BookDownloadService.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/book/BookDownloadService.java @@ -97,7 +97,8 @@ public class BookDownloadService { if (asKepub) { tempDir = Files.createTempDirectory("kepub-output"); - fileToSend = kepubConversionService.convertEpubToKepub(inputFile, tempDir.toFile()); + fileToSend = kepubConversionService.convertEpubToKepub(inputFile, tempDir.toFile(), + koboSettings.isForceEnableHyphenation()); } setResponseHeaders(response, fileToSend); diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/kobo/KepubConversionService.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/kobo/KepubConversionService.java index 3039ab338..ffb0754ca 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/kobo/KepubConversionService.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/kobo/KepubConversionService.java @@ -28,11 +28,11 @@ public class KepubConversionService { private static final String BIN_LINUX_ARM = "kepubify-linux-arm"; private static final String BIN_LINUX_ARM64 = "kepubify-linux-arm64"; - public File convertEpubToKepub(File epubFile, File tempDir) throws IOException, InterruptedException { + public File convertEpubToKepub(File epubFile, File tempDir, boolean forceEnableHyphenation) throws IOException, InterruptedException { validateInputs(epubFile); Path kepubifyBinary = setupKepubifyBinary(); - File outputFile = executeKepubifyConversion(epubFile, tempDir, kepubifyBinary); + File outputFile = executeKepubifyConversion(epubFile, tempDir, kepubifyBinary, forceEnableHyphenation); log.info("Successfully converted {} to {} (size: {} bytes)", epubFile.getName(), outputFile.getName(), outputFile.length()); return outputFile; @@ -98,9 +98,14 @@ public class KepubConversionService { throw new IllegalStateException("Unsupported operating system or architecture: " + osName + " / " + osArch); } - private File executeKepubifyConversion(File epubFile, File tempDir, Path kepubifyBinary) throws IOException, InterruptedException { + private File executeKepubifyConversion(File epubFile, File tempDir, Path kepubifyBinary, boolean forceEnableHyphenation) throws IOException, InterruptedException { + ProcessBuilder pb; + + if (forceEnableHyphenation) + pb = new ProcessBuilder(kepubifyBinary.toAbsolutePath().toString(), "--hyphenate", "-o", tempDir.getAbsolutePath(), epubFile.getAbsolutePath()); + else + pb = new ProcessBuilder(kepubifyBinary.toAbsolutePath().toString(), "-o", tempDir.getAbsolutePath(), epubFile.getAbsolutePath()); - ProcessBuilder pb = new ProcessBuilder(kepubifyBinary.toAbsolutePath().toString(), "-o", tempDir.getAbsolutePath(), epubFile.getAbsolutePath()); pb.directory(tempDir); log.info("Starting kepubify conversion for {} -> output dir: {}", epubFile.getAbsolutePath(), tempDir.getAbsolutePath()); diff --git a/booklore-ui/src/app/features/settings/device-settings/component/kobo-sync-settings/kobo-sync-settings-component.html b/booklore-ui/src/app/features/settings/device-settings/component/kobo-sync-settings/kobo-sync-settings-component.html index 6c689312c..e588470db 100644 --- a/booklore-ui/src/app/features/settings/device-settings/component/kobo-sync-settings/kobo-sync-settings-component.html +++ b/booklore-ui/src/app/features/settings/device-settings/component/kobo-sync-settings/kobo-sync-settings-component.html @@ -207,6 +207,24 @@

+ +
+
+
+ + + +
+

+ Force enable hyphenation. Otherwise, hyphenation is only enabled when text alignment on the Kobo + device is explicitly set to justified. +

+
+
+ } diff --git a/booklore-ui/src/app/features/settings/device-settings/component/kobo-sync-settings/kobo-sync-settings-component.ts b/booklore-ui/src/app/features/settings/device-settings/component/kobo-sync-settings/kobo-sync-settings-component.ts index 2aea49e9c..12ddfb906 100644 --- a/booklore-ui/src/app/features/settings/device-settings/component/kobo-sync-settings/kobo-sync-settings-component.ts +++ b/booklore-ui/src/app/features/settings/device-settings/component/kobo-sync-settings/kobo-sync-settings-component.ts @@ -45,7 +45,8 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy { koboSettings: KoboSettings = { convertToKepub: false, - conversionLimitInMb: 100 + conversionLimitInMb: 100, + forceEnableHyphenation: false }; koboSyncSettings: KoboSyncSettings = { @@ -122,6 +123,7 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy { .subscribe(settings => { this.koboSettings.convertToKepub = settings?.koboSettings?.convertToKepub ?? true; this.koboSettings.conversionLimitInMb = settings?.koboSettings?.conversionLimitInMb ?? 100; + this.koboSettings.forceEnableHyphenation = settings?.koboSettings?.forceEnableHyphenation ?? false; }); } diff --git a/booklore-ui/src/app/shared/model/app-settings.model.ts b/booklore-ui/src/app/shared/model/app-settings.model.ts index ecbda9c34..666c4ca27 100644 --- a/booklore-ui/src/app/shared/model/app-settings.model.ts +++ b/booklore-ui/src/app/shared/model/app-settings.model.ts @@ -102,6 +102,7 @@ export interface PublicReviewSettings { export interface KoboSettings { convertToKepub: boolean; conversionLimitInMb: number; + forceEnableHyphenation: boolean; } export interface AppSettings {