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
This commit is contained in:
beedaddy
2025-11-27 06:45:47 -07:00
committed by GitHub
parent 190cb1fc7a
commit 47f75c2b9a
7 changed files with 36 additions and 7 deletions
@@ -8,4 +8,5 @@ import lombok.Data;
public class KoboSettings {
private boolean convertToKepub;
private int conversionLimitInMb;
private boolean forceEnableHyphenation;
}
@@ -253,6 +253,7 @@ public class SettingPersistenceHelper {
return KoboSettings.builder()
.convertToKepub(false)
.conversionLimitInMb(100)
.forceEnableHyphenation(false)
.build();
}
}
}
@@ -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);
@@ -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());
@@ -207,6 +207,24 @@
</p>
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<label class="setting-label">Force Enable Hyphenation</label>
<p-toggle-switch
id="forceEnableHyphenation"
[(ngModel)]="koboSettings.forceEnableHyphenation"
(ngModelChange)="onToggleChange()">
</p-toggle-switch>
</div>
<p class="setting-description">
Force enable hyphenation. Otherwise, hyphenation is only enabled when text alignment on the Kobo
device is explicitly set to <i>justified</i>.
</p>
</div>
</div>
</div>
</div>
}
@@ -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;
});
}
@@ -102,6 +102,7 @@ export interface PublicReviewSettings {
export interface KoboSettings {
convertToKepub: boolean;
conversionLimitInMb: number;
forceEnableHyphenation: boolean;
}
export interface AppSettings {