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. +
+