Skip to content

Commit

Permalink
Improve fonts support
Browse files Browse the repository at this point in the history
JavaFX doesn't support CSS font fallback (sigh...). So instead we add a CSS per platform and try to figure it out there.
  • Loading branch information
zapek committed Nov 12, 2023
1 parent 74b8f89 commit d82b4cc
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 9 deletions.
13 changes: 13 additions & 0 deletions ui/src/main/java/io/xeres/ui/support/util/UiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import javafx.stage.Popup;
import javafx.stage.Stage;
import javafx.stage.Window;
import org.apache.commons.lang3.SystemUtils;
import org.springframework.web.reactive.function.client.WebClientResponseException;

import java.io.BufferedReader;
Expand Down Expand Up @@ -164,6 +165,18 @@ public static void setDefaultIcon(Stage stage)
public static void setDefaultStyle(Scene scene)
{
scene.getStylesheets().add("/view/default.css");
if (SystemUtils.IS_OS_WINDOWS)
{
scene.getStylesheets().add("/view/windows.css");
}
else if (SystemUtils.IS_OS_LINUX)
{
scene.getStylesheets().add("/view/linux.css");
}
else if (SystemUtils.IS_OS_MAC)
{
scene.getStylesheets().add("/view/mac.css");
}
}

/**
Expand Down
9 changes: 0 additions & 9 deletions ui/src/main/resources/view/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,6 @@
-fx-padding: 0px 0.25em 0px 0px;
}

/* this is needed to display emojis before sending them */
.chat-send {
-fx-font-family: "Segoe UI Emoji", "Noto Color Emoji", "Noto Emoji", "Apple Color Emoji";
}

.fixed-font {
-fx-font-family: "Consolas", "Courier New", "Courier", "monospace";
}

.chat-user-list {
-fx-border-width: 0 1 1 1;
}
Expand Down
27 changes: 27 additions & 0 deletions ui/src/main/resources/view/linux.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2023 by David Gerber - https://zapek.com
*
* This file is part of Xeres.
*
* Xeres is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xeres is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xeres. If not, see <http://www.gnu.org/licenses/>.
*/

.fixed-font {
-fx-font-family: "monospace";
}

/* this is needed to display emojis before sending them */
.chat-send {
-fx-font-family: "Noto Color Emoji";
}
27 changes: 27 additions & 0 deletions ui/src/main/resources/view/mac.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2023 by David Gerber - https://zapek.com
*
* This file is part of Xeres.
*
* Xeres is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xeres is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xeres. If not, see <http://www.gnu.org/licenses/>.
*/

.fixed-font {
-fx-font-family: "monospace";
}

/* this is needed to display emojis before sending them */
.chat-send {
-fx-font-family: "Apple Color Emoji";
}
27 changes: 27 additions & 0 deletions ui/src/main/resources/view/windows.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2023 by David Gerber - https://zapek.com
*
* This file is part of Xeres.
*
* Xeres is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xeres is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xeres. If not, see <http://www.gnu.org/licenses/>.
*/

.fixed-font {
-fx-font-family: "Consolas";
}

/* this is needed to display emojis before sending them */
.chat-send {
-fx-font-family: "Segoe UI Emoji";
}

0 comments on commit d82b4cc

Please sign in to comment.