forked from Blendman974/faceclaw
iOS TTF support; voice input
This commit is contained in:
1 parent
ae14edcb59
commit
b07ae0b479
67 files changed
+15717
-55
No files matched your search
@@ -4,14 +4,14 @@
|
||||
* app assets on first listing (so the directory is the single source of
|
||||
* truth), and user installs from the Files app ("Install" on a font file).
|
||||
*
|
||||
* Listing parses each file's name table for family/style (via the Java
|
||||
* FontFileRenderer) and probes monospace-ness by comparing advances, both
|
||||
* Listing parses each file's name table for family/style (via the native
|
||||
* font renderer) and probes monospace-ness by comparing advances, both
|
||||
* memoized per path for the session.
|
||||
*/
|
||||
import { File, Folder, knownFolders, path as nsPath } from "@nativescript/core";
|
||||
import { canLoadFontFile, fontFileDisplayName, isFontFile } from "../native/font-files";
|
||||
|
||||
declare const com: any;
|
||||
import { fontRenderer } from "../native/font-renderer";
|
||||
declare const java: any;
|
||||
declare const global: any;
|
||||
|
||||
@@ -62,7 +62,7 @@ let preinstalledEnsured = false;
|
||||
* before every listing.
|
||||
*/
|
||||
export function ensurePreinstalledFonts(): void {
|
||||
if (preinstalledEnsured || !global.isAndroid) return;
|
||||
if (preinstalledEnsured || (!global.isAndroid && !global.isIOS)) return;
|
||||
const assetsDir = nsPath.join(knownFolders.currentApp().path, "fonts/ttf");
|
||||
for (const fileName of PREINSTALLED_FONT_FILES) {
|
||||
const target = installedFontPath(fileName);
|
||||
@@ -83,7 +83,7 @@ export function ensurePreinstalledFonts(): void {
|
||||
* same-named file). Returns an error message for the UI, or null on success.
|
||||
*/
|
||||
export function installFontFile(sourcePath: string): string | null {
|
||||
if (!global.isAndroid) return "Not available on this platform.";
|
||||
if ((!global.isAndroid && !global.isIOS)) return "Not available on this platform.";
|
||||
if (!isFontFile(sourcePath)) return "Not a font file.";
|
||||
if (!canLoadFontFile(sourcePath)) return "This file could not be loaded as a font.";
|
||||
const fileName = sourcePath.slice(sourcePath.lastIndexOf("/") + 1);
|
||||
@@ -108,7 +108,7 @@ export function isFontInstalled(sourcePath: string): boolean {
|
||||
* then weight. Unloadable files are skipped.
|
||||
*/
|
||||
export function listInstalledFonts(): InstalledFont[] {
|
||||
if (!global.isAndroid) return [];
|
||||
if ((!global.isAndroid && !global.isIOS)) return [];
|
||||
ensurePreinstalledFonts();
|
||||
const fonts: InstalledFont[] = [];
|
||||
try {
|
||||
@@ -195,7 +195,7 @@ function styleWeightOrder(style: string): number {
|
||||
function isMonospaceFont(path: string): boolean {
|
||||
try {
|
||||
const measure = (text: string) =>
|
||||
Number(com.faceclaw.app.FontFileRenderer.measureTextExact(path, text, 48));
|
||||
Number(fontRenderer.measureTextExact(path, text, 48));
|
||||
const narrow = measure("i");
|
||||
if (!(narrow > 0)) return false;
|
||||
return (
|
||||
@@ -217,6 +217,14 @@ function isMonospaceFont(path: string): boolean {
|
||||
// isolates on first launch (each resolving the default UI font), and readers
|
||||
// must never see a half-written font file.
|
||||
function copyFileBytes(source: string, target: string): void {
|
||||
if (source === target) return;
|
||||
if (global.isIOS) {
|
||||
const data = NSData.dataWithContentsOfFile(source);
|
||||
// Foundation's atomic write uses a sibling temporary file and rename.
|
||||
// Multiple worker isolates can safely preinstall the same bundled face.
|
||||
if (!data || !data.writeToFileAtomically(target, true)) throw new Error(`Copy to ${target} failed`);
|
||||
return;
|
||||
}
|
||||
const temp = `${target}.tmp-${Math.floor(Math.random() * 0x7fffffff).toString(36)}`;
|
||||
const input = new java.io.FileInputStream(source);
|
||||
try {
|
||||
|
||||
+10
-11
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* TTF/OTF fonts for on-glasses UI text, rendered per-codepoint through the
|
||||
* Java FontFileRenderer (Android minikin/HarfBuzz: real shaping, kerning,
|
||||
* antialiasing) and cached as 4bpp coverage rasters that ride the
|
||||
* native font renderer (Android Paint / iOS Core Text) and cached as 4bpp coverage rasters that ride the
|
||||
* texture-cache glyph pipeline (CFW mode 14; see
|
||||
* notes/texture-cache-display-list-design.md and graphics/glyph-wire.ts).
|
||||
*
|
||||
@@ -14,9 +13,9 @@
|
||||
* never drifts.
|
||||
*
|
||||
* Kerning uses memoized per-pair measurements (measure("ab") - a - b);
|
||||
* ligatures are disabled Java-side so per-codepoint rasters plus pairwise
|
||||
* ligatures are disabled native-side so per-codepoint rasters plus pairwise
|
||||
* kerning fully describe a line. Glyph rasters and advances come from one
|
||||
* JNI render per (font, size, codepoint) per JS context, memoized forever.
|
||||
* native render per (font, size, codepoint) per JS context, memoized forever.
|
||||
*
|
||||
* Cross-context determinism: worker threads and the main thread each build
|
||||
* their own TtfFont, but the Java GlyphAtlas dedupes by atlasKey and treats
|
||||
@@ -26,8 +25,8 @@
|
||||
import { allocateFontFingerprintId, type Glyph } from "./bdffont";
|
||||
import { GrayImage, grayToNibble, type GlyphFont } from "./image";
|
||||
import { toUint8Array } from "../util/array-util";
|
||||
import { fontRenderer } from "../native/font-renderer";
|
||||
|
||||
declare const com: any;
|
||||
declare const global: any;
|
||||
|
||||
/**
|
||||
@@ -65,7 +64,7 @@ export class TtfFont implements GlyphFont {
|
||||
|
||||
/**
|
||||
* Load (or return the memoized) font at a pixel size. Null when the font
|
||||
* file is missing/unloadable or off-Android — callers fall back to a BDF
|
||||
* file is missing/unloadable or the platform has no renderer — callers fall back to a BDF
|
||||
* face.
|
||||
*/
|
||||
static load(path: string, sizePx: number, gamma = DEFAULT_TTF_GAMMA): TtfFont | null {
|
||||
@@ -73,9 +72,9 @@ export class TtfFont implements GlyphFont {
|
||||
const cached = loadedFonts.get(key);
|
||||
if (cached !== undefined) return cached;
|
||||
let font: TtfFont | null = null;
|
||||
if (global.isAndroid && sizePx > 0) {
|
||||
if ((global.isAndroid || global.isIOS) && Number.isFinite(sizePx) && sizePx > 0) {
|
||||
try {
|
||||
const raw = String(com.faceclaw.app.FontFileRenderer.getFontMetrics(path, sizePx) ?? "");
|
||||
const raw = String(fontRenderer.getFontMetrics(path, sizePx) ?? "");
|
||||
const parts = raw.split(" ").map((part) => parseInt(part, 10));
|
||||
if (parts.length === 3 && parts.every((part) => Number.isFinite(part))) {
|
||||
const [ascent, descent] = parts as [number, number, number];
|
||||
@@ -170,7 +169,7 @@ export class TtfFont implements GlyphFont {
|
||||
|
||||
/**
|
||||
* Kerning between two adjacent codepoints: measure(ab) - a - b, memoized.
|
||||
* One JNI measurement per distinct pair per JS context.
|
||||
* One native measurement per distinct pair per JS context.
|
||||
*/
|
||||
private kernBetween(a: number, b: number): number {
|
||||
const key = a * 0x200000 + b;
|
||||
@@ -179,7 +178,7 @@ export class TtfFont implements GlyphFont {
|
||||
let kern = 0;
|
||||
try {
|
||||
const pair = Number(
|
||||
com.faceclaw.app.FontFileRenderer.measureTextExact(
|
||||
fontRenderer.measureTextExact(
|
||||
this.path,
|
||||
String.fromCodePoint(a) + String.fromCodePoint(b),
|
||||
this.sizePx,
|
||||
@@ -203,7 +202,7 @@ export class TtfFont implements GlyphFont {
|
||||
let bytes: Uint8Array;
|
||||
try {
|
||||
bytes = toUint8Array(
|
||||
com.faceclaw.app.FontFileRenderer.renderGlyphCell(this.path, this.sizePx, codePoint, this.gamma),
|
||||
fontRenderer.renderGlyphCell(this.path, this.sizePx, codePoint, this.gamma),
|
||||
);
|
||||
} catch (error) {
|
||||
console.warn(`renderGlyphCell failed for U+${codePoint.toString(16)}: ${error}`);
|
||||
|
||||
Reference in new issue
Block a user