mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
feat(client): add support for system font
This commit is contained in:
parent
dfc9cdb25a
commit
d34e575488
@ -18,9 +18,10 @@ const FONT_FAMILIES: FontGroup[] = [
|
||||
title: t("fonts.generic-fonts"),
|
||||
items: [
|
||||
{ value: "theme", label: t("fonts.theme_defined") },
|
||||
{ value: "system", label: t("fonts.system-default") },
|
||||
{ value: "serif", label: t("fonts.serif") },
|
||||
{ value: "sans-serif", label: t("fonts.sans-serif") },
|
||||
{ value: "monospace", label: t("fonts.monospace") },
|
||||
{ value: "monospace", label: t("fonts.monospace") }
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -1071,7 +1071,8 @@
|
||||
"handwriting-system-fonts": "Handwriting system fonts",
|
||||
"serif": "Serif",
|
||||
"sans-serif": "Sans Serif",
|
||||
"monospace": "Monospace"
|
||||
"monospace": "Monospace",
|
||||
"system-default": "System default"
|
||||
},
|
||||
"max_content_width": {
|
||||
"title": "Content Width",
|
||||
|
@ -561,7 +561,8 @@
|
||||
"serif-system-fonts": "Fonturi de sistem cu serifuri",
|
||||
"monospace": "Monospațiu",
|
||||
"sans-serif": "Fără serifuri",
|
||||
"serif": "Cu serifuri"
|
||||
"serif": "Cu serifuri",
|
||||
"system-default": "Fontul predefinit al sistemului"
|
||||
},
|
||||
"global_menu": {
|
||||
"about": "Despre TriliumNext Notes",
|
||||
|
@ -2,6 +2,21 @@ import { Request, Response } from 'express';
|
||||
import optionService from "../../services/options.js";
|
||||
import { OptionMap } from '../../services/options_interface.js';
|
||||
|
||||
const SYSTEM_SANS_SERIF = [
|
||||
"-apple-system",
|
||||
"BlinkMacSystemFont",
|
||||
"Segoe UI",
|
||||
"Noto Sans",
|
||||
"Helvetica",
|
||||
"Arial",
|
||||
"sans-serif",
|
||||
"Apple Color Emoji","Segoe UI Emoji"
|
||||
].join(",");
|
||||
|
||||
const SYSTEM_MONOSPACE = [
|
||||
"monospace"
|
||||
].join(",");
|
||||
|
||||
function getFontCss(req: Request, res: Response) {
|
||||
res.setHeader('Content-Type', 'text/css');
|
||||
|
||||
@ -22,23 +37,41 @@ function getFontCss(req: Request, res: Response) {
|
||||
res.send(style);
|
||||
}
|
||||
|
||||
function getFontFamily(optionsMap: OptionMap) {
|
||||
function getFontFamily({ mainFontFamily, treeFontFamily, detailFontFamily, monospaceFontFamily }: OptionMap) {
|
||||
let style = "";
|
||||
|
||||
if (optionsMap.mainFontFamily !== 'theme') {
|
||||
style += `--main-font-family: ${optionsMap.mainFontFamily};`;
|
||||
// System override
|
||||
if (mainFontFamily === "system") {
|
||||
mainFontFamily = SYSTEM_SANS_SERIF;
|
||||
}
|
||||
|
||||
if (optionsMap.treeFontFamily !== 'theme') {
|
||||
style += `--tree-font-family: ${optionsMap.treeFontFamily};`;
|
||||
if (treeFontFamily === "system") {
|
||||
treeFontFamily = SYSTEM_SANS_SERIF;
|
||||
}
|
||||
|
||||
if (optionsMap.detailFontFamily !== 'theme') {
|
||||
style += `--detail-font-family: ${optionsMap.detailFontFamily};`;
|
||||
if (detailFontFamily === "system") {
|
||||
detailFontFamily = SYSTEM_SANS_SERIF;
|
||||
}
|
||||
|
||||
if (optionsMap.monospaceFontFamily !== 'theme') {
|
||||
style += `--monospace-font-family: ${optionsMap.monospaceFontFamily};`;
|
||||
if (monospaceFontFamily === "system") {
|
||||
monospaceFontFamily = SYSTEM_MONOSPACE;
|
||||
}
|
||||
|
||||
// Apply the font override if not using theme fonts.
|
||||
if (mainFontFamily !== 'theme') {
|
||||
style += `--main-font-family: ${mainFontFamily};`;
|
||||
}
|
||||
|
||||
if (treeFontFamily !== 'theme') {
|
||||
style += `--tree-font-family: ${treeFontFamily};`;
|
||||
}
|
||||
|
||||
if (detailFontFamily !== 'theme') {
|
||||
style += `--detail-font-family: ${detailFontFamily};`;
|
||||
}
|
||||
|
||||
if (monospaceFontFamily !== 'theme') {
|
||||
style += `--monospace-font-family: ${monospaceFontFamily};`;
|
||||
}
|
||||
|
||||
return style;
|
||||
|
Loading…
x
Reference in New Issue
Block a user