mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 13:57:06 +00:00
font-manager: the details sheet's copyright, upstream link, NOTICE and licence text
This commit is contained in:
@@ -46,7 +46,8 @@ The layout follows Adobe Fonts' and Google Fonts' browse pages.
|
||||
with the switch that changes it, the source, designer, licence, scripts and languages, and what a
|
||||
preview downloads. With a preview service, styles not installed draw with its subsets: a static
|
||||
file's sample, and one subset of each variable file with every axis kept, drawn at each named
|
||||
instance and at the values of its axis sliders.
|
||||
instance and at the values of its axis sliders. The copyright and the upstream link, and
|
||||
an Apache family's NOTICE and, on request, the licence text, read through the store.
|
||||
- **Installed**: system and font store fonts as the same cards, filtered by source. Only font
|
||||
store families can be removed; system fonts are removed with the system's own tools.
|
||||
- **Sources** (`sources_ui`, for a host's settings page): the built-in sources, the index URLs the
|
||||
|
||||
@@ -34,6 +34,7 @@ use crate::panel::browse::{FontsBrowseWords, Texts};
|
||||
use crate::panel::details::DetailsSheet;
|
||||
use crate::panel::i18n::LANGUAGES;
|
||||
use crate::panel::jobs::{self, Finished, Jobs, Kind, Request};
|
||||
use crate::panel::legal::LegalTexts;
|
||||
use crate::panel::samples;
|
||||
use crate::panel::subsets::Subsets;
|
||||
|
||||
@@ -295,6 +296,8 @@ pub struct FontsPanel {
|
||||
pub(crate) subsets: Subsets,
|
||||
/// The values the user set on the details sheet's axis sliders, by file sha256.
|
||||
pub(crate) detail_axes: HashMap<String, AxisValues>,
|
||||
/// Licence and NOTICE texts, by family, text and file.
|
||||
pub(crate) legal: LegalTexts,
|
||||
pub(crate) jobs: Jobs,
|
||||
pub(crate) asking: Option<Pending>,
|
||||
/// By lower-case family name.
|
||||
@@ -403,6 +406,7 @@ impl FontsPanel {
|
||||
previewed: HashMap::new(),
|
||||
subsets,
|
||||
detail_axes: HashMap::new(),
|
||||
legal: LegalTexts::new(),
|
||||
jobs: Jobs::new(),
|
||||
asking: None,
|
||||
failed: HashMap::new(),
|
||||
@@ -657,6 +661,7 @@ impl FontsPanel {
|
||||
}
|
||||
}
|
||||
self.poll_sources();
|
||||
self.poll_legal();
|
||||
}
|
||||
|
||||
fn record_copy(&mut self, family: &str, copied: Option<Result<MadeAvailable, StoreError>>) {
|
||||
|
||||
@@ -468,7 +468,7 @@ impl FontsPanel {
|
||||
{
|
||||
return None;
|
||||
}
|
||||
Some(SubsetRow { family, text: self.family_sample(index, family) })
|
||||
Some((family, self.family_sample(index, family)))
|
||||
}
|
||||
|
||||
/// The sample a family of the index shows.
|
||||
|
||||
@@ -23,8 +23,10 @@ use craft_ui::dialog::Dialog;
|
||||
use craft_ui::display::{Badge, Progress, Shade, Text};
|
||||
use craft_ui::layout_components::{Grid, Row, Stack};
|
||||
use craft_ui::notices::{Notice, NoticeAction};
|
||||
use craft_ui::primitives::Wrap;
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
use craft_ui::style::Variant;
|
||||
use craft_ui::text::TextField;
|
||||
use egui::{Response, Ui};
|
||||
|
||||
use self::rows::{Action, Lines, StyleLine, StyleList, StyleRow};
|
||||
@@ -35,8 +37,10 @@ use crate::panel::app::{
|
||||
};
|
||||
use crate::panel::faces::Owner;
|
||||
use crate::panel::jobs::Kind;
|
||||
use crate::panel::legal::{Legal, legal_key};
|
||||
use crate::panel::specimen::{FontSample, HeldFace};
|
||||
use crate::panel::subsets::SubsetFont;
|
||||
use crate::store::LegalText;
|
||||
use crate::{FaceInfo, Source};
|
||||
|
||||
/// The sample is at least this many points: the sheet shows styles, not thumbnails.
|
||||
@@ -46,6 +50,9 @@ const HERO_POINTS: f32 = 96.0;
|
||||
/// The most languages the sheet lists; the rest are counted.
|
||||
const LANGUAGES_SHOWN: usize = 60;
|
||||
|
||||
/// The lines of a licence or NOTICE text in view; the rest scrolls.
|
||||
const LEGAL_LINES: usize = 10;
|
||||
|
||||
/// The facts' labels over their values.
|
||||
const FACT_COLUMNS: [ColumnWidth; 2] = [ColumnWidth::Content, ColumnWidth::fill(1.0)];
|
||||
|
||||
@@ -81,6 +88,14 @@ craft_ui::words! {
|
||||
preview: "fontDetails.preview" = "Preview";
|
||||
install: "fontDetails.install" = "Install";
|
||||
remove: "fontDetails.remove" = "Remove";
|
||||
copyright: "fontDetails.copyright" = "Copyright";
|
||||
/// `{url}`.
|
||||
upstream: template "fontDetails.upstream" = "Upstream: {url}";
|
||||
show_licence: "fontDetails.showLicence" = "Show licence text";
|
||||
show_notice: "fontDetails.showNotice" = "Show notice";
|
||||
licence_text: "fontDetails.licenceText" = "Licence text";
|
||||
notice_text: "fontDetails.noticeText" = "Notice";
|
||||
loading_text: "fontDetails.loadingText" = "Loading…";
|
||||
/// The style of a variable file that names no instances.
|
||||
default_style: "fontDetails.defaultStyle" = "Default";
|
||||
/// `{style}`.
|
||||
@@ -178,6 +193,34 @@ enum Do {
|
||||
Ask(Pending),
|
||||
Remove { faces: Vec<FaceInfo>, whole: bool },
|
||||
AvailableToAll { files: Vec<PathBuf>, on: bool },
|
||||
ReadLegal(LegalText),
|
||||
}
|
||||
|
||||
/// A licence or NOTICE text as the sheet shows it.
|
||||
enum LegalShown {
|
||||
/// Not read yet.
|
||||
Offer,
|
||||
Loading,
|
||||
Text(String),
|
||||
Failed(String),
|
||||
}
|
||||
|
||||
/// The licence and NOTICE texts `family` has, as far as they are read.
|
||||
fn legal_texts(panel: &FontsPanel, family: &Family) -> Vec<(LegalText, LegalShown)> {
|
||||
let files = [(LegalText::Notice, family.notice_file.is_some()), (LegalText::License, family.license_file_name().is_some())];
|
||||
files
|
||||
.into_iter()
|
||||
.filter(|(_, has)| *has)
|
||||
.filter_map(|(which, _)| {
|
||||
let shown = match panel.legal.get(&legal_key(family, which)) {
|
||||
None => LegalShown::Offer,
|
||||
Some(Legal::Loading(_)) => LegalShown::Loading,
|
||||
Some(Legal::Ready(text)) => LegalShown::Text(text.clone()?),
|
||||
Some(Legal::Failed(error)) => LegalShown::Failed(error.clone()),
|
||||
};
|
||||
Some((which, shown))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The job running for the whole family, as the header shows it.
|
||||
@@ -300,6 +343,9 @@ struct Sheet {
|
||||
axes: Vec<FileAxes>,
|
||||
facts: Vec<(Label, String)>,
|
||||
languages: Vec<String>,
|
||||
/// The web page of the family's own project.
|
||||
upstream: Option<String>,
|
||||
legal: Vec<(LegalText, LegalShown)>,
|
||||
/// The family's position in the index; none for an installed family, whose styles cannot be installed.
|
||||
index: Option<usize>,
|
||||
sample: String,
|
||||
@@ -342,6 +388,7 @@ impl<'a> DetailsSheet<'a> {
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<DetailsWords>();
|
||||
let host: Option<Arc<Host>> = env.view().host().cloned();
|
||||
panel.read_notice(host.as_ref());
|
||||
let Some(sheet) = Sheet::read(panel, &env, &words) else {
|
||||
panel.detail = None;
|
||||
return DetailsOutput { response: ui.response(), closed: true };
|
||||
@@ -372,6 +419,11 @@ impl<'a> DetailsSheet<'a> {
|
||||
match action {
|
||||
Do::Ask(pending) => panel.ask(host.as_ref(), pending),
|
||||
Do::Remove { faces, whole } => panel.remove(host.as_ref(), &sheet.title, &faces, whole),
|
||||
Do::ReadLegal(which) => {
|
||||
if let Some(i) = sheet.index {
|
||||
panel.load_legal(host.as_ref(), i, which);
|
||||
}
|
||||
}
|
||||
Do::AvailableToAll { files, on } => panel.set_available_to_all(host.as_ref(), &sheet.title, files, on),
|
||||
}
|
||||
}
|
||||
@@ -459,6 +511,8 @@ impl Sheet {
|
||||
axes,
|
||||
facts,
|
||||
languages: languages.into_iter().map(|l| l.name.clone()).collect(),
|
||||
upstream: family.upstream.clone().filter(|url| url.starts_with("https://") || url.starts_with("http://")),
|
||||
legal: legal_texts(panel, &family),
|
||||
index: Some(i),
|
||||
sample,
|
||||
})
|
||||
@@ -512,6 +566,8 @@ impl Sheet {
|
||||
axes: Vec::new(),
|
||||
facts,
|
||||
languages: Vec::new(),
|
||||
upstream: None,
|
||||
legal: Vec::new(),
|
||||
index: None,
|
||||
sample: panel.installed_sample(&family.name),
|
||||
})
|
||||
@@ -618,7 +674,10 @@ impl Sheet {
|
||||
AxisSliders::new(file.label.clone(), &file.axes, Bind::bound(values)).show(ui);
|
||||
}
|
||||
});
|
||||
Stack::new().show(ui, |ui, _| self.side(ui, env, words));
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
self.side(ui, env, words);
|
||||
self.licence(ui, words, todo);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -667,6 +726,47 @@ impl Sheet {
|
||||
}
|
||||
}
|
||||
|
||||
impl Sheet {
|
||||
/// The project's page, and the licence and NOTICE texts: each a button that reads it, then the text, or why it
|
||||
/// couldn't be read.
|
||||
fn licence(&self, ui: &mut Ui, words: &DetailsWords, todo: &mut Vec<Do>) {
|
||||
if let Some(url) = &self.upstream {
|
||||
let shown = url.trim_start_matches("https://").trim_start_matches("http://").trim_end_matches('/');
|
||||
Link::new(shown.to_owned()).url(url.clone()).wrap(Wrap::Elide).description(words.upstream.fill(&[("url", url)])).show(ui);
|
||||
}
|
||||
for (at, (which, shown)) in self.legal.iter().enumerate() {
|
||||
let (show, title) = match which {
|
||||
LegalText::License => (&words.show_licence, &words.licence_text),
|
||||
LegalText::Notice => (&words.show_notice, &words.notice_text),
|
||||
};
|
||||
let read = match shown {
|
||||
LegalShown::Offer => clicked(&Button::new(show.clone()).variant(Variant::SECONDARY).show(ui)),
|
||||
LegalShown::Loading => {
|
||||
Text::new(words.loading_text.clone()).shade(Shade::Muted).show(ui);
|
||||
false
|
||||
}
|
||||
LegalShown::Text(text) => {
|
||||
Text::new(title.clone()).shade(Shade::Faint).show(ui);
|
||||
TextField::new(title.clone(), Bind::given(text.clone()))
|
||||
.lines(LEGAL_LINES)
|
||||
.max_lines(LEGAL_LINES)
|
||||
.mono()
|
||||
.read_only(true)
|
||||
.show(ui);
|
||||
false
|
||||
}
|
||||
LegalShown::Failed(error) => {
|
||||
let retry = NoticeAction::new(words.retry.clone());
|
||||
Notice::new(Tone::Bad, error.clone()).id_salt(("legal", at)).title(title.clone()).action(retry).show(ui).action.is_some()
|
||||
}
|
||||
};
|
||||
if read {
|
||||
todo.push(Do::ReadLegal(*which));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A job's progress: the job and the percent done when known, with a bar.
|
||||
fn progress(ui: &mut Ui, env: &Env, words: &DetailsWords, what: &Label, fraction: Option<f32>) {
|
||||
let what = env.view().resolve(what);
|
||||
@@ -819,6 +919,9 @@ fn family_facts(env: &Env, words: &DetailsWords, index: &Index, family: &Family,
|
||||
facts.push((words.designer.clone(), family.designer.clone()));
|
||||
}
|
||||
facts.push((words.licence.clone(), licence_name(&family.license).to_owned()));
|
||||
if let Some(copyright) = family.copyright.as_deref().map(str::trim).filter(|text| !text.is_empty()) {
|
||||
facts.push((words.copyright.clone(), copyright.to_owned()));
|
||||
}
|
||||
facts.push((words.styles_fact.clone(), format.integer(style_count(family) as u64)));
|
||||
facts.push((words.files_fact.clone(), format.integer(family.files.len() as u64)));
|
||||
facts.push((words.download_size.clone(), size.to_owned()));
|
||||
|
||||
@@ -48,6 +48,7 @@ pub(crate) fn story_catalog() -> Arc<Catalog> {
|
||||
}
|
||||
|
||||
/// A variable font (`wght`), for the samples drawn at variation coordinates.
|
||||
#[cfg(feature = "suite")]
|
||||
pub(crate) const VARIABLE: &[u8] = include_bytes!("../../../font-subset/tests/data/orbitron/Orbitron[wght].ttf");
|
||||
|
||||
/// The panel over the story catalog and index; its store is a fake that refuses downloads.
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
//! A family's licence and NOTICE texts, read through the store on request.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::sync::mpsc::{Receiver, TryRecvError, channel};
|
||||
|
||||
use craft_host::Host;
|
||||
|
||||
use crate::index::Family;
|
||||
use crate::panel::app::{Detail, FontsPanel, family_key};
|
||||
use crate::panel::jobs;
|
||||
use crate::store::{LegalText, StoreError};
|
||||
|
||||
/// A licence or NOTICE text being read, or read.
|
||||
pub(crate) enum Legal {
|
||||
Loading(Receiver<Result<Option<String>, StoreError>>),
|
||||
/// `None` when the family has no such file.
|
||||
Ready(Option<String>),
|
||||
Failed(String),
|
||||
}
|
||||
|
||||
/// What a licence or NOTICE text is kept by: the family's key, which text, and the file's sha256 (else its path), so a
|
||||
/// file an index refresh changed is read again.
|
||||
pub(crate) type LegalKey = (String, LegalText, String);
|
||||
|
||||
pub(crate) type LegalTexts = HashMap<LegalKey, Legal>;
|
||||
|
||||
pub(crate) fn legal_key(family: &Family, which: LegalText) -> LegalKey {
|
||||
let file = match which {
|
||||
LegalText::License => family.license_file.as_ref(),
|
||||
LegalText::Notice => family.notice_file.as_ref(),
|
||||
};
|
||||
let identity = match (file, which) {
|
||||
(Some(file), _) => file.sha256.clone(),
|
||||
(None, LegalText::License) => family.license_path.clone().unwrap_or_default(),
|
||||
(None, LegalText::Notice) => String::new(),
|
||||
};
|
||||
(family_key(&family.source, &family.family), which, identity)
|
||||
}
|
||||
|
||||
impl FontsPanel {
|
||||
/// Takes in the texts that were read.
|
||||
pub(crate) fn poll_legal(&mut self) {
|
||||
for state in self.legal.values_mut() {
|
||||
if let Legal::Loading(rx) = state {
|
||||
match rx.try_recv() {
|
||||
Ok(Ok(text)) => *state = Legal::Ready(text),
|
||||
Ok(Err(e)) => *state = Legal::Failed(e.0),
|
||||
Err(TryRecvError::Empty) => {}
|
||||
Err(TryRecvError::Disconnected) => *state = Legal::Ready(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads the NOTICE of the family the details sheet shows once downloads are allowed: an Apache family's NOTICE is
|
||||
/// shown with its fonts.
|
||||
pub(crate) fn read_notice(&mut self, host: Option<&Arc<Host>>) {
|
||||
let Some((index, i)) = self.index().zip(self.detail_family()) else { return };
|
||||
let unread = index.families().get(i).is_some_and(|f| f.notice_file.is_some() && !self.legal.contains_key(&legal_key(f, LegalText::Notice)));
|
||||
if unread && self.allowed() {
|
||||
self.load_legal(host, i, LegalText::Notice);
|
||||
}
|
||||
}
|
||||
|
||||
fn detail_family(&self) -> Option<usize> {
|
||||
match &self.detail {
|
||||
Some(Detail::Family(i)) => Some(*i),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads the licence or NOTICE text of the `i`th family through the store, as a job.
|
||||
pub(crate) fn load_legal(&mut self, host: Option<&Arc<Host>>, i: usize, which: LegalText) {
|
||||
let Some(index) = self.index() else { return };
|
||||
let Some(family) = index.families().get(i).cloned() else { return };
|
||||
let (tx, rx) = channel();
|
||||
self.legal.insert(legal_key(&family, which), Legal::Loading(rx));
|
||||
let installer = Arc::clone(&self.installer);
|
||||
let wake = self.jobs.waker();
|
||||
jobs::spawn(
|
||||
host,
|
||||
"font-licence",
|
||||
Box::new(move || {
|
||||
let _ = tx.send(installer.legal_text(&index, &family, which));
|
||||
wake.wake();
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ pub(crate) mod faces;
|
||||
#[cfg(feature = "screen-testing")]
|
||||
pub(crate) mod fixtures;
|
||||
pub(crate) mod jobs;
|
||||
pub(crate) mod legal;
|
||||
pub(crate) mod samples;
|
||||
pub(crate) mod sources;
|
||||
pub(crate) mod specimen;
|
||||
|
||||
@@ -19,10 +19,7 @@ pub(crate) use none::Subsets;
|
||||
pub(crate) use service::Subsets;
|
||||
|
||||
/// A row of the list: the family, whose list face draws it, and the text it shows.
|
||||
pub(crate) struct Row<'a> {
|
||||
pub(crate) family: &'a Family,
|
||||
pub(crate) text: String,
|
||||
}
|
||||
pub(crate) type Row<'a> = (&'a Family, String);
|
||||
|
||||
/// A subset that is here: its key among the document faces, and the font.
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
@@ -272,7 +272,7 @@ impl Subsets {
|
||||
if self.fonts.contains_key(want) {
|
||||
return Some(want);
|
||||
}
|
||||
self.shown.get(&face_of(want)).filter(|last| self.fonts.contains_key(last))
|
||||
self.shown.get(&face_of(want)).filter(|last| self.fonts.contains_key(*last))
|
||||
}
|
||||
|
||||
fn subset_font(&self, key: &PreviewKey) -> Option<SubsetFont> {
|
||||
@@ -336,12 +336,13 @@ impl Subsets {
|
||||
let mut settled = true;
|
||||
let mut latin = Vec::new();
|
||||
for row in visible.clone().filter_map(row) {
|
||||
let family = row.0;
|
||||
// A family without a sample text still gets the subset its row's text needs.
|
||||
if let Some(sample) = list_file(row.family).and_then(|f| self.sample_key(index, row.family, f, Instance::List)) {
|
||||
if let Some(sample) = list_file(family).and_then(|f| self.sample_key(index, family, f, Instance::List)) {
|
||||
settled &= self.fonts.contains_key(&sample) || self.has_failed(&sample);
|
||||
self.want(&mut wanted, sample, VISIBLE);
|
||||
}
|
||||
if let Some(ascii) = covers_latin(row.family).then(|| subset_key(row.family, Subset::Ascii)).flatten() {
|
||||
if let Some(ascii) = covers_latin(family).then(|| subset_key(family, Subset::Ascii)).flatten() {
|
||||
latin.push(ascii);
|
||||
}
|
||||
let Some(key) = self.key(index, row) else { continue };
|
||||
@@ -361,9 +362,9 @@ impl Subsets {
|
||||
}
|
||||
let above = visible.start.saturating_sub(screen)..visible.start;
|
||||
let below = visible.end..visible.end.saturating_add(2 * screen);
|
||||
for row in above.chain(below).filter_map(row) {
|
||||
for (family, _) in above.chain(below).filter_map(row) {
|
||||
if let Some(sample) =
|
||||
list_file(row.family).and_then(|f| sample_subset(index, row.family, f, Instance::List)).filter(|k| !self.sample_missing.contains(k))
|
||||
list_file(family).and_then(|f| sample_subset(index, family, f, Instance::List)).filter(|k| !self.sample_missing.contains(k))
|
||||
{
|
||||
self.want(&mut wanted, sample, WINDOW);
|
||||
}
|
||||
@@ -400,8 +401,8 @@ impl Subsets {
|
||||
if self.sample_missing.contains(&sample) { sample_fallback(index, family, file, instance) } else { Some(sample) }
|
||||
}
|
||||
|
||||
fn key(&self, index: &Index, row: &Row<'_>) -> Option<PreviewKey> {
|
||||
text_key(index, row.family, list_file(row.family)?, Instance::List, &row.text, &self.sample_missing)
|
||||
fn key(&self, index: &Index, (family, text): &Row<'_>) -> Option<PreviewKey> {
|
||||
text_key(index, family, list_file(family)?, Instance::List, text, &self.sample_missing)
|
||||
}
|
||||
|
||||
/// Adds `key` to `wanted` at `priority` unless it is here, failed lately, or can't load: with previews off, only
|
||||
|
||||
Reference in New Issue
Block a user