From 7e4da5f0de16c35ce304620bd37b08d57ff46858 Mon Sep 17 00:00:00 2001 From: alyx Date: Fri, 12 Jan 2024 01:28:22 -0500 Subject: [PATCH] Custom font support complete --- TODO.md | 62 ++++++++++++++++++++------------- src/config.rs | 83 ++++++++++++++++++++++++++++++++------------ src/ctx.rs | 35 ++++++++++++++----- src/font.rs | 1 + src/main.rs | 3 +- src/themes/plain.hbs | 8 ++--- 6 files changed, 131 insertions(+), 61 deletions(-) diff --git a/TODO.md b/TODO.md index e6cfb75..d55c742 100644 --- a/TODO.md +++ b/TODO.md @@ -1,32 +1,10 @@ # Future plans for this project: -## Custom Fonts - -For ease-of-inclusion this should probably be handled by internal code, and provided as a set of properties on `lfm_embed::ctx::model::Data`. - -There are 3 main kinds of fonts we should support. -- User-hosted fonts. These would be loaded directly from a link to a TTF,WOFF2,etc font file. -- Google fonts fonts. In theory, we'd proxy these, but that's not 100% necessary. -- Named fonts. e.x. 'serif', 'sans-serif', 'monospace'. Browser will handle these. - -There is no good way to expose a typed enum with the current wizard UI, and the resulting UI from this could allow added user flexibility. - -### Query Parameters - -- `?font=foo` corresponds directly with `* { font-family: 'foo' }` in the CSS. -- `?font=foo&include-font=https://example.com/font.otf` will additionally append `@font-face { font-family: 'foo' src: url('https://example.com/font.otf') }`. -- `?include-stylesheet` allows for general stylesheet inclusion. It may be specified N times. - -### Context Members - -- `font: object` null if no font params specified. -- `font.name: string` contains `?font` -- `font.additional_css` will contain the `?include-font` css, as well as the proxied contents of `?include-stylesheet`. - - ## Move more things internal +Untouched. + Of the crates currently relied on, the following appear too feature-packed should be replaced with simpler internal code, to reduce binary size. - duration-str @@ -35,6 +13,8 @@ Of the crates currently relied on, the following appear too feature-packed shoul ## Watermarking +Untouched. + Support for a limited form of (optional) watermaking. It would be up to the themes to include it. ### Query Parameters @@ -64,12 +44,16 @@ A warning should be output on startup. ## Additional Helpers +Untouched. + - `(range Number start: Number = 0): Number` Generates values from start to the main argument, exclusive. - `(random): Number` Generates a random float. ## Additional Services to Support +Untouched. + This should be as transparent as possible to the theme and end-user. ### Services @@ -94,3 +78,33 @@ This should be as transparent as possible to the theme and end-user. - `user.service` never not null - `user.service.type` `(audioscrobbler|listenbrainz|gnukebox)` - `user.service.domain` the string for the service's domain. + + +## Error Cache + +Untouched. + +Add support to `lfm_embed::cache::AsyncCache` for caching `Err` values with a different lifetime from `Ok` values. + + +# Completed Features + + +## Custom Fonts + +Implemented! + +### Query Parameters + +Each of these are mutually exclusive, and take priority over eachother in the order listed below. +The highest one detected will be handled and others, if present, will be silently ignored. + +- `?google_font=` the name of a google font to try loading. If it exists, the `fonts.googleapis.com` stylesheet will end up in `font.css`. The font name will end up in `font.name`. +- `?include_font=` the URL to a font to include. `font.css` will be a generated `@font-family` declaration. A provided name will be in `font.name`. +- `?font=` the name of a browser-native or system font. This will only set `font.name`. + +### Context Members + +- `font: object` null if no font overrides are present. +- `font.name: string` All text elements should have their font set to this. +- `font.css` If present, it should be placed inside a ` -- 2.45.2