mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-25 06:42:51 +02:00
Add fallback fonts
This commit is contained in:
Binary file not shown.
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "129.9.0",
|
"version": "129.9.1",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+9
-6
@@ -11,10 +11,7 @@ const weights = {
|
|||||||
900: 'heavy',
|
900: 'heavy',
|
||||||
950: 'extraBlack'
|
950: 'extraBlack'
|
||||||
};
|
};
|
||||||
const variants = {
|
const fallbacks = ['Symbola', 'Noto-CJK'];
|
||||||
'Noto-CJK.otf': 'Noto Sans',
|
|
||||||
'Noto-Emoji.ttf': 'Noto Sans'
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = class Font {
|
module.exports = class Font {
|
||||||
constructor(path, filename, metadata) {
|
constructor(path, filename, metadata) {
|
||||||
@@ -25,6 +22,7 @@ module.exports = class Font {
|
|||||||
this.weight = weights[metadata.weight] || metadata.weight || 'normal';
|
this.weight = weights[metadata.weight] || metadata.weight || 'normal';
|
||||||
this.type = metadata.type;
|
this.type = metadata.type;
|
||||||
this.registered = false;
|
this.registered = false;
|
||||||
|
this.fallbacks = fallbacks.filter(fallback => fallback !== this.filenameNoExt);
|
||||||
}
|
}
|
||||||
|
|
||||||
register() {
|
register() {
|
||||||
@@ -33,8 +31,9 @@ module.exports = class Font {
|
|||||||
return registerFont(this.path, { family: this.filenameNoExt, style: this.style, weight: this.weight });
|
return registerFont(this.path, { family: this.filenameNoExt, style: this.style, weight: this.weight });
|
||||||
}
|
}
|
||||||
|
|
||||||
toCanvasString(size) {
|
toCanvasString(size, fallbacks = true) {
|
||||||
return `${this.style} ${this.weight} ${size}px ${this.filenameNoExt}`;
|
const shouldFall = fallbacks ? `, ${this.fallbacks.join(', ')}` : '';
|
||||||
|
return `${this.style} ${this.weight} ${size}px ${this.filenameNoExt}${shouldFall}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
get filenameNoExt() {
|
get filenameNoExt() {
|
||||||
@@ -44,4 +43,8 @@ module.exports = class Font {
|
|||||||
get isVariant() {
|
get isVariant() {
|
||||||
return variants[this.filename];
|
return variants[this.filename];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isFallback() {
|
||||||
|
return fallbacks.includes(this.filenameNoExt);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+3
-1
@@ -9,6 +9,7 @@ module.exports = class FontArgumentType extends ArgumentType {
|
|||||||
validate(value) {
|
validate(value) {
|
||||||
const choice = value.toLowerCase();
|
const choice = value.toLowerCase();
|
||||||
let found = this.client.fonts.filter(font => {
|
let found = this.client.fonts.filter(font => {
|
||||||
|
if (font.isFallback) return false;
|
||||||
if (font.isVariant) return false;
|
if (font.isVariant) return false;
|
||||||
if (font.name.toLowerCase().includes(choice)) return true;
|
if (font.name.toLowerCase().includes(choice)) return true;
|
||||||
if (font.filenameNoExt.toLowerCase().includes(choice)) return true;
|
if (font.filenameNoExt.toLowerCase().includes(choice)) return true;
|
||||||
@@ -24,13 +25,14 @@ module.exports = class FontArgumentType extends ArgumentType {
|
|||||||
if (foundExact.size === 1) return true;
|
if (foundExact.size === 1) return true;
|
||||||
if (foundExact.size > 0) found = foundExact;
|
if (foundExact.size > 0) found = foundExact;
|
||||||
return found.size <= 15
|
return found.size <= 15
|
||||||
? `${disambiguation(found.map(font => escapeMarkdown(font.name)), 'fonts', null)}\n`
|
? `${disambiguation(found.map(font => escapeMarkdown(font.filenameNoExt)), 'fonts', null)}\n`
|
||||||
: 'Multiple fonts found. Please be more specific.';
|
: 'Multiple fonts found. Please be more specific.';
|
||||||
}
|
}
|
||||||
|
|
||||||
parse(value) {
|
parse(value) {
|
||||||
const choice = value.toLowerCase();
|
const choice = value.toLowerCase();
|
||||||
const found = this.client.fonts.filter(font => {
|
const found = this.client.fonts.filter(font => {
|
||||||
|
if (font.isFallback) return false;
|
||||||
if (font.isVariant) return false;
|
if (font.isVariant) return false;
|
||||||
if (font.name.toLowerCase().includes(choice)) return true;
|
if (font.name.toLowerCase().includes(choice)) return true;
|
||||||
if (font.filenameNoExt.toLowerCase().includes(choice)) return true;
|
if (font.filenameNoExt.toLowerCase().includes(choice)) return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user