mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 03:29:02 +01: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"), |         title: t("fonts.generic-fonts"), | ||||||
|         items: [ |         items: [ | ||||||
|             { value: "theme", label: t("fonts.theme_defined") }, |             { value: "theme", label: t("fonts.theme_defined") }, | ||||||
|  |             { value: "system", label: t("fonts.system-default") }, | ||||||
|             { value: "serif", label: t("fonts.serif") }, |             { value: "serif", label: t("fonts.serif") }, | ||||||
|             { value: "sans-serif", label: t("fonts.sans-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", |     "handwriting-system-fonts": "Handwriting system fonts", | ||||||
|     "serif": "Serif", |     "serif": "Serif", | ||||||
|     "sans-serif": "Sans Serif", |     "sans-serif": "Sans Serif", | ||||||
|     "monospace": "Monospace" |     "monospace": "Monospace", | ||||||
|  |     "system-default": "System default" | ||||||
|   }, |   }, | ||||||
|   "max_content_width": { |   "max_content_width": { | ||||||
|     "title": "Content Width", |     "title": "Content Width", | ||||||
|  | |||||||
| @ -561,7 +561,8 @@ | |||||||
|     "serif-system-fonts": "Fonturi de sistem cu serifuri", |     "serif-system-fonts": "Fonturi de sistem cu serifuri", | ||||||
|     "monospace": "Monospațiu", |     "monospace": "Monospațiu", | ||||||
|     "sans-serif": "Fără serifuri", |     "sans-serif": "Fără serifuri", | ||||||
|     "serif": "Cu serifuri" |     "serif": "Cu serifuri", | ||||||
|  |     "system-default": "Fontul predefinit al sistemului" | ||||||
|   }, |   }, | ||||||
|   "global_menu": { |   "global_menu": { | ||||||
|     "about": "Despre TriliumNext Notes", |     "about": "Despre TriliumNext Notes", | ||||||
|  | |||||||
| @ -2,6 +2,21 @@ import { Request, Response } from 'express'; | |||||||
| import optionService from "../../services/options.js"; | import optionService from "../../services/options.js"; | ||||||
| import { OptionMap } from '../../services/options_interface.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) { | function getFontCss(req: Request, res: Response) { | ||||||
|     res.setHeader('Content-Type', 'text/css'); |     res.setHeader('Content-Type', 'text/css'); | ||||||
| 
 | 
 | ||||||
| @ -22,23 +37,41 @@ function getFontCss(req: Request, res: Response) { | |||||||
|     res.send(style); |     res.send(style); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function getFontFamily(optionsMap: OptionMap) { | function getFontFamily({ mainFontFamily, treeFontFamily, detailFontFamily, monospaceFontFamily }: OptionMap) { | ||||||
|     let style = ""; |     let style = ""; | ||||||
| 
 | 
 | ||||||
|     if (optionsMap.mainFontFamily !== 'theme') { |     // System override
 | ||||||
|         style += `--main-font-family: ${optionsMap.mainFontFamily};`; |     if (mainFontFamily === "system") { | ||||||
|  |         mainFontFamily = SYSTEM_SANS_SERIF; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (optionsMap.treeFontFamily !== 'theme') { |     if (treeFontFamily === "system") { | ||||||
|         style += `--tree-font-family: ${optionsMap.treeFontFamily};`; |         treeFontFamily = SYSTEM_SANS_SERIF; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (optionsMap.detailFontFamily !== 'theme') { |     if (detailFontFamily === "system") { | ||||||
|         style += `--detail-font-family: ${optionsMap.detailFontFamily};`; |         detailFontFamily = SYSTEM_SANS_SERIF; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (optionsMap.monospaceFontFamily !== 'theme') { |     if (monospaceFontFamily === "system") { | ||||||
|         style += `--monospace-font-family: ${optionsMap.monospaceFontFamily};`; |         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; |     return style; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran