Files
klammertext/mac/font_store.h

60 lines
2.7 KiB
C
Raw Normal View History

Typed arguments, calculated tables, spans, closed-world fonts, top-level fnt/ and env/ Sync with klammertext-dev through b90b0e09: - Argument types end to end: :python_cast values are applied (Python @eval receives real bools/numbers/lists), argument values are validated against their argtype patterns with the argtype's description as the error message, argtypes can declare :default (overridable per declaration), and parameterized type families are supported: rest(N) casts a rest argument to an N-dimensional list (bar-count = dimension). - Unified indexed_range syntax (selector with parenthesized subsets, composable mnemonic names) for table lines and spans. - Table klammer: caption fonts fixed in both targets, :column_width / :leading / :colsep wired, :colspan and :rowspan render (HTML attributes; \multicolumn / \multirow), calculated cell values (:calc) with prefix operators, display-precision semantics, :calc_format and :decimal period|comma. - Fonts: closed-world resolution on the Klammertext font store (infrastructure in mac/font_store; no Google Fonts links or fetch). Default fonts live in the top-level fnt/; additional fonts install into KLAMMERTEXT_FONTS directories via kdesc --font (list, samples, preview, install — classification by font metadata). CSS font family names are quoted (digit-initial families were silently lost). - Environment files moved from mac/env/ to the top-level env/; shell profiles source env/runtime.env. Dead per-host variants removed. - Container: fnt/ ships in the image; curl removed (no network use).
2026-07-22 18:17:43 +02:00
#pragma once
// The Klammertext font store (infrastructure; see font_store.cpp).
#include <string>
#include <vector>
struct Resolved_font {
std::string family_name {}; // "Crimson Pro"
std::string dir_name {}; // "crimson-pro"
std::string font_dir {}; // Full path to font directory
std::string css_file {}; // Full path to .css file
// .ttf filenames for each variant (empty if variant not available):
std::string regular {};
std::string bold {};
std::string italic {};
std::string bold_italic {};
float xheight_ratio = 0.0f; // x-height / unitsPerEm from OS/2 table
float capheight_ratio = 0.0f; // cap-height / unitsPerEm from OS/2 table
};
std::string name_to_dirname(std::string name);
// Directories searched for installed fonts (KLAMMERTEXT_FONTS, default
// ~/.klammertext/fonts); the default font set is searched after them.
std::vector<std::string> installed_font_dirs();
// The distribution's default fonts: $KLAMMERTEXT_HOME/fnt.
std::string default_font_dir();
// Every installable font family found across those directories.
std::vector<std::string> available_font_families();
Resolved_font resolve_font(std::string family_name);
void install_resolved_font(const Resolved_font& font, std::string output_dir);
// One font file classified by its internal metadata (name table, OS/2).
struct Font_file {
std::string path {};
std::string family {}; // from name table (nameID 16, else 1)
std::string variant {}; // Regular | Bold | Italic | BoldItalic
std::string extension {}; // ".ttf" or ".otf"
bool variable = false; // has an 'fvar' table
int weight = 0; // OS/2 usWeightClass
std::string note {}; // reason when the file is not installable
};
// Recursively classify every .ttf/.otf under a directory.
std::vector<Font_file> classify_font_files(const std::string& directory);
// Install the classified families from source_dir into dest_dir (default:
// the first KLAMMERTEXT_FONTS directory, created if necessary), in the
// canonical relocatable layout <dest>/<family-kebab>/{Variant}.ttf plus a
// generated <family-kebab>.css with relative urls. Returns a report.
std::string install_fonts(const std::string& source_dir, std::string dest_dir = "");
// Describe every font in the store with provenance and variants.
std::string describe_fonts();
// Write an HTML specimen page for fonts into output_dir. With an empty
// source_dir, samples every available font in the store; otherwise
// classifies and samples the (possibly uninstalled) fonts in source_dir.
std::string write_font_samples(const std::string& output_dir, const std::string& source_dir = "");