Files
klammertext/mac/font_store.h
T
ack af29bbf7ac Unicode sequences, @typeface, and the font/typeface distinction
A run of Unicode code points now needs one pair of carets, not one pair
each: ^9053 53EF 9053^ renders the characters adjacently, and a single
character inside such a run stands for itself.  An invalid code point is
an error naming the position that wrote it, rather than an apology
rendered into the finished document; noncharacters are refused alongside
surrogates; and a code point that lands on a Klammertext special is safe
through the re-reads that assemble a document.  The character tables now
produce the precomposed form, so a diacritic written as ^a" and one typed
directly are the same text to a search or a copy-paste.

"kdesc -u" describes how to write a Unicode character, with tables of
glyphs beside the codes that produce them.  It is new and not yet
complete: it predates the sequence form and the typeface klammer below.

A typeface and a style are no longer both called "font".  A typeface is a
family resolved by name; a style code is the one letter naming a type
style.  So @document takes :serif_typeface and its siblings, a table takes
:style, captions take :caption_style and :caption_size, the uniform scale
is :text_scale, and the command is "kdesc --typeface".  This renames
arguments a document may already use; an old name is a located error
rather than a silent omission.

@typeface sets a passage in another typeface for the length of that
passage:

    @typeface Noto Sans Egyptian Hieroglyphs | ^132AA 133CF^ :scale 1.5 @

Writing the klammer is the whole declaration -- the document resolves the
typeface, embeds it in what it produces, and carries its license along.
Two typefaces for scripts no text font covers now ship with Klammertext:
Noto Sans Egyptian Hieroglyphs and Noto Sans Cuneiform.  Every typeface in
the distribution now carries its license file.

(from dev 61e598698891)
2026-08-25 23:30:55 +02:00

65 lines
3.0 KiB
C++

#pragma once
// The Klammertext font store (infrastructure; see font_store.cpp).
#include <string>
#include "locator.h"
#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(const 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();
// The Locator is the DOCUMENT location to blame when the typeface is not
// installed: without it the "not installed" error cites font_store.cpp,
// a source location no user can act on (the no-.cpp-location rule).
Resolved_font resolve_font(const std::string& family_name,
const Locator& loc = Locator::none());
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 = "");