Browse Source

load bundled font for "Cryptomator" title

Sebastian Stenzel 5 năm trước cách đây
mục cha
commit
0a132351a8

+ 18 - 0
main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowController.java

@@ -4,6 +4,7 @@ import javafx.beans.binding.BooleanBinding;
 import javafx.fxml.FXML;
 import javafx.scene.layout.HBox;
 import javafx.scene.layout.Region;
+import javafx.scene.text.Font;
 import javafx.stage.Stage;
 import org.cryptomator.ui.common.FxController;
 import org.cryptomator.ui.fxapp.FxApplication;
@@ -13,10 +14,13 @@ import org.slf4j.LoggerFactory;
 
 import javax.inject.Inject;
 import javax.inject.Named;
+import java.io.IOException;
+import java.io.InputStream;
 
 @MainWindowScoped
 public class MainWindowController implements FxController {
 
+	private static final String TITLE_FONT = "/css/dosis-bold.ttf";
 	private static final Logger LOG = LoggerFactory.getLogger(MainWindowController.class);
 
 	private final Stage window;
@@ -41,6 +45,7 @@ public class MainWindowController implements FxController {
 	@FXML
 	public void initialize() {
 		LOG.debug("init MainWindowController");
+		loadFont(TITLE_FONT);
 		titleBar.setOnMousePressed(event -> {
 			xOffset = event.getSceneX();
 			yOffset = event.getSceneY();
@@ -57,6 +62,19 @@ public class MainWindowController implements FxController {
 		updateChecker.automaticallyCheckForUpdatesIfEnabled();
 	}
 
+	private void loadFont(String resourcePath) {
+		try (InputStream in = getClass().getResourceAsStream(resourcePath)) {
+			Font font = Font.loadFont(in, 12.0);
+			if (font == null) {
+				LOG.warn("Error loading font from path: " + resourcePath);
+			} else {
+				LOG.debug("Loaded font {}", font.getFamily());
+			}
+		} catch (IOException e) {
+			LOG.warn("Error loading font from path: " + resourcePath, e);
+		}
+	}
+
 	@FXML
 	public void close() {
 		if (minimizeToSysTray) {

BIN
main/ui/src/main/resources/css/dosis-bold.ttf