* 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.
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"sync"
|
|
|
|
"github.com/yetone/magpie/internal/fonts"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// onFonts updates existing webviews even while the other one has focus.
|
|
var onFonts func()
|
|
|
|
func sameFont(a, b *fonts.Face) bool {
|
|
return a == nil && b == nil || a != nil && b != nil && *a == *b
|
|
}
|
|
|
|
func fontSettingsJS(s settings.Settings) string {
|
|
b, _ := json.Marshal(map[string]any{"uiFont": s.UIFont, "codeFont": s.CodeFont})
|
|
return "window.receiveFonts?.(" + string(b) + ");"
|
|
}
|
|
|
|
// Font discovery belongs to the desktop, never to a remote browser's
|
|
// server. A failed refresh leaves the last successful collection intact.
|
|
func fontRoutes(mux *http.ServeMux, web bool, discover func() ([]fonts.Family, error)) {
|
|
var mu sync.Mutex
|
|
var cached []fonts.Family
|
|
mux.HandleFunc("GET /api/fonts", func(rw http.ResponseWriter, r *http.Request) {
|
|
if web {
|
|
http.Error(rw, "installed fonts are available only in the desktop app", http.StatusNotFound)
|
|
return
|
|
}
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
if cached == nil || r.URL.Query().Get("refresh") == "1" {
|
|
found, err := discover()
|
|
if err != nil {
|
|
http.Error(rw, "could not read installed fonts", http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
cached = found
|
|
if cached == nil {
|
|
cached = []fonts.Family{}
|
|
}
|
|
}
|
|
writeJSON(rw, cached)
|
|
})
|
|
}
|