Bundle fonts to not rely on fontconfig

This commit is contained in:
crschnick 2023-12-31 05:05:03 +00:00
parent e3b451b600
commit 38e1b929d6
9 changed files with 51 additions and 11 deletions

View file

@ -58,14 +58,6 @@ public class AppFont {
node.setStyle(node.getStyle() + "-fx-font-size: " + (baseSize + off) + "pt;");
}
public static void verifyFontLoadingFunctional() {
try {
Font.getDefault();
} catch (Throwable t) {
throw new IllegalStateException("Unable to load any fonts. Check whether your system is properly configured with fontconfig", t);
}
}
public static void init() {
TrackEvent.info("Loading fonts ...");
AppResources.with(
@ -75,7 +67,7 @@ public class AppFont {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
try (var in = Files.newInputStream(file)) {
Font.loadFont(in, 12);
Font.loadFont(in, OsType.getLocal() == OsType.LINUX ? 11 : 12);
} catch (Throwable t) {
// Font loading can fail in rare cases. This is however not important, so we can just ignore it
}

View file

@ -68,6 +68,10 @@ public class AppProperties {
}
}
public static void setDynamicProperties() {
System.setProperty("prism.fontdir", XPipeInstallation.getBundledFontsPath().toString());
}
public static void logArguments(String[] args) {
TrackEvent.withInfo("Detected arguments")
.tag("list", Arrays.asList(args))

View file

@ -0,0 +1,15 @@
package io.xpipe.app.core.check;
import javafx.scene.text.Font;
public class AppFontCheck {
public static void check() {
try {
Font.getDefault();
} catch (Throwable t) {
throw new IllegalStateException("Unable to load any fonts. Check whether your system is properly configured with fontconfig", t);
}
}
}

View file

@ -1,6 +1,7 @@
package io.xpipe.app.core.mode;
import io.xpipe.app.core.*;
import io.xpipe.app.core.check.AppFontCheck;
import io.xpipe.app.core.check.AppTempCheck;
import io.xpipe.app.core.check.AppUserDirectoryCheck;
import io.xpipe.app.ext.DataStoreProviders;
@ -103,8 +104,9 @@ public abstract class OperationMode {
AppProperties.logArguments(args);
AppProperties.logSystemProperties();
AppProperties.logPassedProperties();
AppProperties.setDynamicProperties();
XPipeSystemId.init();
AppFont.verifyFontLoadingFunctional();
AppFontCheck.check();
TrackEvent.info("mode", "Finished initial setup");
} catch (Throwable ex) {
ErrorEvent.fromThrowable(ex).term().handle();

View file

@ -282,6 +282,18 @@ public class XPipeInstallation {
return path;
}
public static Path getBundledFontsPath() {
var install = getCurrentInstallationBasePath();
var type = OsType.getLocal();
if (type.equals(OsType.WINDOWS)) {
return install.resolve("app").resolve("fonts");
} else if (type.equals(OsType.LINUX)) {
return install.resolve("app").resolve("fonts");
} else {
return install.resolve("Contents").resolve("Resources").resolve("fonts");
}
}
public static String getDaemonDebugScriptPath(OsType type) {
if (type.equals(OsType.WINDOWS)) {
return FileNames.join("app", "scripts", "xpiped_debug.bat");

12
dist/base.gradle vendored
View file

@ -26,6 +26,10 @@ if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
from "$projectDir/logo/logo.ico"
into "$distDir/base/app"
}
copy {
from "$projectDir/fonts"
into "$distDir/base/app/fonts"
}
def debugArguments = file("$projectDir/debug/debug_arguments.txt").text.lines().map(s -> '"' + s + '"').collect(Collectors.joining(
' '))
@ -79,6 +83,10 @@ if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
from "$projectDir/logo/logo.png"
into "$distDir/base/"
}
copy {
from "$projectDir/fonts"
into "$distDir/base/app/fonts"
}
// Fixes a JPackage bug
copy {
@ -159,6 +167,10 @@ if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
from "$distDir/cli/xpipe_completion"
into "$distDir/$app/Contents/Resources/cli/"
}
copy {
from "$projectDir/fonts"
into "$distDir/$app/Contents/Resources/fonts"
}
copy {
from "$projectDir/PkgInstaller/darwin/Resources/uninstall.sh"

View file

@ -12,7 +12,7 @@
## Changes
- The SSH config importer now supports include statements. Included files are automatically resolved and joined
- Improve performance mode appearance setting gains by removing more styling
- Improve performance mode speedup by removing more styling. You can find the mode under Settings -> Appearance
- Change layout of connection names and status to better handle very long
connection names across all window sizes
- Make any connection quickly renameable in the edit window without verifying whether we can actually connect

BIN
dist/fonts/Roboto-Regular.ttf vendored Normal file

Binary file not shown.

3
dist/fonts/allfonts.properties vendored Normal file
View file

@ -0,0 +1,3 @@
family.0=Roboto
font.0=Roboto Regular
file.0=Roboto-Regular.ttf