* gui: choose installed interface and code fonts and styles Discover installed styles through DirectWrite, CoreText and Fontconfig. Keep choices per computer, apply them before paint and notify both desktop webviews after saving; defaults retain platform and Omarchy fallbacks. Verified seven focused Go tests, including real Windows discovery (90 families, 276 styles), 14 font browser cases in Chromium/WebKit, 68 settings/zoom/Omarchy/web cases, go vet, Windows amd64/arm64 and Linux nogui builds. Against the original assets, the new UI test fails with Settings must offer an interface font picker (0 != 1). Full Windows suites have separately reproduced upstream failures; macOS/Linux native discovery is covered by the added CI step. * gui: retain bundled Mac fonts and variable style precision Only filter an undownloaded CoreText face when it is explicitly downloadable; bundled fonts are installed without being downloaded. Use resolved font names when descriptors omit them. Preserve fractional weights and nonnegative CSS widths for named variable styles. * gui: restore the authored font cascade when returning to defaults Apply family-only trait overrides only while a custom face is active. The browser regression catches code under a bold parent becoming 700 instead of its original 400. Keep the compatibility shim first, and apply boot fonts before visible content. * gui: keep font picker review separate from CI integration Leave the native test sources and manual verification command with the feature. Move the added workflow step to a follow-up so the font picker can take the normal review path requested on PR #1007.
75 lines
2.6 KiB
Go
75 lines
2.6 KiB
Go
//go:build linux && cgo && !nogui
|
|
|
|
package fonts
|
|
|
|
/*
|
|
#cgo pkg-config: fontconfig
|
|
#include <fontconfig/fontconfig.h>
|
|
|
|
static FcFontSet *magpieFonts(void) {
|
|
FcPattern *pattern = FcPatternCreate();
|
|
if (!pattern) return NULL;
|
|
FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
|
|
FcObjectSet *objects = FcObjectSetBuild(FC_FAMILY, FC_STYLE, FC_WEIGHT, FC_SLANT, FC_WIDTH, NULL);
|
|
if (!objects) { FcPatternDestroy(pattern); return NULL; }
|
|
FcFontSet *fonts = FcFontList(NULL, pattern, objects);
|
|
FcObjectSetDestroy(objects);
|
|
FcPatternDestroy(pattern);
|
|
return fonts;
|
|
}
|
|
static FcPattern *magpieFontAt(FcFontSet *set, int i) { return set->fonts[i]; }
|
|
static const char *magpieFontString(FcPattern *font, const char *key) {
|
|
FcChar8 *value = NULL;
|
|
return FcPatternGetString(font, key, 0, &value) == FcResultMatch ? (const char *)value : "";
|
|
}
|
|
static double magpieFontNumber(FcPattern *font, const char *key, double fallback) {
|
|
FcValue value;
|
|
if (FcPatternGet(font, key, 0, &value) != FcResultMatch) return fallback;
|
|
if (value.type == FcTypeInteger) return value.u.i;
|
|
if (value.type == FcTypeDouble) return value.u.d;
|
|
return fallback;
|
|
}
|
|
static const char *magpieFontFamily(FcPattern *f) { return magpieFontString(f, FC_FAMILY); }
|
|
static const char *magpieFontStyle(FcPattern *f) { return magpieFontString(f, FC_STYLE); }
|
|
static double magpieFontWeight(FcPattern *f) { return magpieFontNumber(f, FC_WEIGHT, -1); }
|
|
static double magpieFontSlant(FcPattern *f) { return magpieFontNumber(f, FC_SLANT, FC_SLANT_ROMAN); }
|
|
static double magpieFontWidth(FcPattern *f) { return magpieFontNumber(f, FC_WIDTH, 100); }
|
|
*/
|
|
import "C"
|
|
|
|
import "errors"
|
|
|
|
const Available = true
|
|
|
|
func installed() ([]Face, error) {
|
|
set := C.magpieFonts()
|
|
if set == nil {
|
|
return nil, errors.New("Fontconfig could not list installed fonts")
|
|
}
|
|
defer C.FcFontSetDestroy(set)
|
|
faces := make([]Face, 0, int(set.nfont))
|
|
for i := C.int(0); i < set.nfont; i++ {
|
|
font := C.magpieFontAt(set, i)
|
|
// A variable font's range is not a named instance. Its enumerated
|
|
// named instances have numeric weights and are included normally.
|
|
weight := C.magpieFontWeight(font)
|
|
if weight < 0 {
|
|
continue
|
|
}
|
|
style := "normal"
|
|
switch int(C.magpieFontSlant(font)) {
|
|
case C.FC_SLANT_ITALIC:
|
|
style = "italic"
|
|
case C.FC_SLANT_OBLIQUE:
|
|
style = "oblique"
|
|
}
|
|
faces = append(faces, Face{
|
|
Family: C.GoString(C.magpieFontFamily(font)),
|
|
Name: C.GoString(C.magpieFontStyle(font)),
|
|
Weight: float64(C.FcWeightToOpenTypeDouble(weight)),
|
|
Style: style, Stretch: float64(C.magpieFontWidth(font)),
|
|
})
|
|
}
|
|
return faces, nil
|
|
}
|