forked from Blendman974/faceclaw
Use TTF fonts throughout the UI; also add some more functions to app extension API
This commit is contained in:
1 parent
5abbe2a405
commit
96842ceb23
82 files changed
+2666
-288
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { truncateText, truncateLeft } from "../../graphics/textwrap";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { renderIcon, type IconName } from "../../graphics/icons";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../../ui/gestures";
|
||||
@@ -149,7 +149,7 @@ export class FileBrowserLayer implements Layer {
|
||||
return image;
|
||||
}
|
||||
|
||||
private paintList(image: GrayImage, font: BdfFont, rows: BrowserItem[], ctx: LayerContext): void {
|
||||
private paintList(image: GrayImage, font: UiFont, rows: BrowserItem[], ctx: LayerContext): void {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
this.listIndex = clamp(this.listIndex, 0, Math.max(0, rows.length - 1));
|
||||
|
||||
@@ -172,7 +172,7 @@ export class FileBrowserLayer implements Layer {
|
||||
image.drawText(font, 20, height - 16, `${GESTURE_CLICK} open ${GESTURE_DOUBLE_CLICK} up / back`, 110);
|
||||
}
|
||||
|
||||
private paintIcons(image: GrayImage, font: BdfFont, rows: BrowserItem[], ctx: LayerContext): void {
|
||||
private paintIcons(image: GrayImage, font: UiFont, rows: BrowserItem[], ctx: LayerContext): void {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const focused = ctx.stack.isFocused();
|
||||
const iconRows = buildIconRows(rows);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { wrapText } from "../../graphics/textwrap";
|
||||
import type { DirectoryEntry } from "../../native/file-access";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { readTextFile, type DirectoryEntry } from "../../native/file-access";
|
||||
import { isFontFile } from "../../native/font-files";
|
||||
import { installFontFile, isFontInstalled } from "../../graphics/installed-fonts";
|
||||
import { isDecodableImageFile } from "../../native/image-files";
|
||||
import { readEvenHubPackageManifest } from "../evenhub/installed-apps";
|
||||
import { EvenHubPermissionDialogLayer } from "../evenhub/permission-dialog";
|
||||
@@ -227,6 +228,16 @@ function fileOpenActions(entry: DirectoryEntry, options: FilesAppOptions): FileI
|
||||
];
|
||||
}
|
||||
if (isFontFile(entry.name)) {
|
||||
// Install copies into the app-internal fonts directory, making the face
|
||||
// available in the Settings font pickers. The row relabels itself with
|
||||
// the result (the dialog re-reads labels each paint).
|
||||
const install: FileInfoAction = {
|
||||
label: isFontInstalled(entry.path) ? "Reinstall" : "Install",
|
||||
onSelect: () => {
|
||||
const error = installFontFile(entry.path);
|
||||
install.label = error ?? "Installed";
|
||||
},
|
||||
};
|
||||
return [
|
||||
{
|
||||
label: "Preview here",
|
||||
@@ -242,6 +253,7 @@ function fileOpenActions(entry: DirectoryEntry, options: FilesAppOptions): FileI
|
||||
options.openFontWindow(entry.name, entry.path);
|
||||
},
|
||||
},
|
||||
install,
|
||||
];
|
||||
}
|
||||
return [];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
import {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||
import { type BdfFont } from "../../graphics/bdffont";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { loadImageFileAsGray } from "../../native/image-files";
|
||||
|
||||
@@ -1,15 +1,33 @@
|
||||
import { wrapText, truncateText } from "../../graphics/textwrap";
|
||||
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { getDefaultSmallFont, getUiFontSelection } from "../../graphics/ui-fonts";
|
||||
import { TtfFont } from "../../graphics/ttf-font";
|
||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext } from "../../ui/layers";
|
||||
|
||||
const MARGIN_X = 18;
|
||||
const TITLE_Y = 16;
|
||||
const BODY_X = 18;
|
||||
const BODY_Y = 44;
|
||||
const LINE_STEP = 14;
|
||||
const FOOTER_MARGIN = 36;
|
||||
|
||||
/**
|
||||
* Body text: the user's UI font when it's a TTF; otherwise bundled Inter
|
||||
* Light (the document viewer stays antialiased even while the UI default is
|
||||
* still a bitmap face), with the bitmap UI font as the last fallback.
|
||||
*/
|
||||
const FALLBACK_BODY_FONT_SIZE_PX = 16;
|
||||
/** Line step for the BDF fallback (the 12px font plus leading, as before). */
|
||||
const BDF_LINE_STEP = 14;
|
||||
|
||||
function getViewerFont(): UiFont {
|
||||
if (getUiFontSelection().kind === "ttf") return getDefaultSmallFont();
|
||||
return TtfFont.bundled("inter-light", FALLBACK_BODY_FONT_SIZE_PX) ?? getDefaultSmallFont();
|
||||
}
|
||||
|
||||
function lineStepOf(font: UiFont): number {
|
||||
return font instanceof TtfFont ? font.lineHeight : BDF_LINE_STEP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paged text viewer for a document. Sized to its hosting stack (a Files
|
||||
* document window, or pushed over the file browser for view-in-place).
|
||||
@@ -17,6 +35,7 @@ const FOOTER_MARGIN = 36;
|
||||
export class TextViewerLayer implements Layer {
|
||||
private lines: string[] | null = null;
|
||||
private wrappedForWidth = 0;
|
||||
private wrappedWithFont = 0;
|
||||
private firstLine = 0;
|
||||
private bodyLineCount = 14;
|
||||
|
||||
@@ -26,17 +45,18 @@ export class TextViewerLayer implements Layer {
|
||||
) {}
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const font = getViewerFont();
|
||||
const lineStep = lineStepOf(font);
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const footerY = height - FOOTER_MARGIN;
|
||||
this.bodyLineCount = Math.max(1, Math.floor((footerY - BODY_Y) / LINE_STEP));
|
||||
this.bodyLineCount = Math.max(1, Math.floor((footerY - BODY_Y) / lineStep));
|
||||
image.drawText(font, MARGIN_X + 4, TITLE_Y, truncateText(font, this.title, width - 2 * MARGIN_X - 8), 220);
|
||||
|
||||
const lines = this.getLines(font, width);
|
||||
const visibleLines = lines.slice(this.firstLine, this.firstLine + this.bodyLineCount);
|
||||
for (let index = 0; index < visibleLines.length; index++) {
|
||||
image.drawText(font, BODY_X, BODY_Y + index * LINE_STEP, visibleLines[index]!, 230);
|
||||
image.drawText(font, BODY_X, BODY_Y + index * lineStep, visibleLines[index]!, 230);
|
||||
}
|
||||
|
||||
const currentPage = Math.floor(this.firstLine / this.pageStep()) + 1;
|
||||
@@ -74,14 +94,15 @@ export class TextViewerLayer implements Layer {
|
||||
this.firstLine = Math.max(0, Math.min(maxFirstLine, this.firstLine + delta));
|
||||
}
|
||||
|
||||
private getLines(font: BdfFont, width: number): string[] {
|
||||
if (this.lines === null || this.wrappedForWidth !== width) {
|
||||
private getLines(font: UiFont, width: number): string[] {
|
||||
if (this.lines === null || this.wrappedForWidth !== width || this.wrappedWithFont !== font.fingerprintId) {
|
||||
const normalized = this.documentText.replace(/\t/g, " ").replace(/\r/g, "");
|
||||
this.lines = wrapText(font, normalized, width - BODY_X - 12, {
|
||||
preserveLeadingWhitespace: true,
|
||||
breakLongWords: true,
|
||||
});
|
||||
this.wrappedForWidth = width;
|
||||
this.wrappedWithFont = font.fingerprintId;
|
||||
}
|
||||
return this.lines;
|
||||
}
|
||||
@@ -93,4 +114,3 @@ export class TextViewerLayer implements Layer {
|
||||
return Math.ceil((lineCount - this.bodyLineCount) / this.pageStep()) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user