Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
font_scope.hpp
Go to the documentation of this file.
1// font_scope.hpp
2//
3// A `FontScope` is a named owner of font registrations. Three built-in
4// scopes exist:
5//
6// * `Scope::Global` — what `register_font()` writes today; behaves
7// identically for back-compat.
8// * `Scope::Plugin(id)` — per-plugin registrations. Two plugins loaded
9// into the same host see *only* their own registrations plus the
10// Global scope; they cannot pollute each other's resolution.
11// * `Scope::View(id)` — per-view overrides. Used by design-import hot
12// reload and by `pulp-ui-preview --font` flags.
13//
14// Resolution (in `FontResolver::resolve_*`) walks scopes in this order:
15//
16// View → Plugin → Global → Bundled → Platform
17//
18// Each scope tracks its own monotonic generation counter; the resolver
19// merges them (`merged_generation_for(FontScopeId)`) into the
20// `registry_generation` field of `FontOptions` so every downstream cache
21// key is correctly invalidated when *any* applicable scope mutates.
22//
23// A generation bump in Plugin(A) must not dirty measure callbacks
24// belonging to Plugin(B). This is enforced by `merged_generation_for`
25// returning a value that only changes when scopes the caller actually
26// consults change.
27
28#pragma once
29
31
32#include <atomic>
33#include <cstddef>
34#include <cstdint>
35#include <memory>
36#include <string>
37
38namespace pulp::canvas {
39
40class FontScope {
41public:
42 explicit FontScope(FontScopeId id);
44
45 FontScope(const FontScope&) = delete;
46 FontScope& operator=(const FontScope&) = delete;
47
48 FontScopeId id() const noexcept { return id_; }
49
52 std::uint64_t generation() const noexcept;
53
58
62 bool register_font(const std::uint8_t* data, std::size_t size,
63 const std::string& family_override = "");
64
66 bool register_font_file(const std::string& path,
67 const std::string& family_override = "");
68
71 bool is_registered(const std::string& family) const;
72
78 void set_memory_budget(std::size_t bytes);
79 std::size_t memory_budget() const noexcept;
80
85
86private:
87 FontScopeId id_;
88 std::atomic<std::uint64_t> generation_{0};
89 std::atomic<std::size_t> memory_budget_{0};
90
91 struct Impl;
92 std::unique_ptr<Impl> impl_;
93};
94
95// ── Built-in scope accessors ─────────────────────────────────────────────
96
100
103FontScope& plugin_scope(std::uint64_t plugin_id);
104
109FontScope& view_scope(std::uint64_t view_id);
110
115void release_view_scope(std::uint64_t view_id);
116
117// ── Generation merging ───────────────────────────────────────────────────
118
133std::uint64_t merged_generation_for(FontScopeId requesting_scope);
134
135} // namespace pulp::canvas
Definition font_scope.hpp:40
void prune_to_budget()
Explicit prune-to-budget trigger.
void set_memory_budget(std::size_t bytes)
Memory budget (in bytes) for caches associated with this scope: FontResolver typeface entries,...
FontScope(FontScopeId id)
FontScopeId id() const noexcept
Definition font_scope.hpp:48
void bump_generation()
Forces a generation bump without a registration.
std::uint64_t generation() const noexcept
Monotonic counter; incremented by every successful registration in this scope.
bool register_font_file(const std::string &path, const std::string &family_override="")
File variant.
bool register_font(const std::uint8_t *data, std::size_t size, const std::string &family_override="")
Register a font from raw TTF/OTF bytes into THIS scope.
FontScope & operator=(const FontScope &)=delete
std::size_t memory_budget() const noexcept
bool is_registered(const std::string &family) const
Family-name lookup limited to this scope.
FontScope(const FontScope &)=delete
Definition affine_transform.hpp:24
std::uint64_t merged_generation_for(FontScopeId requesting_scope)
Returns a generation value that is the combined monotonic counter of every scope a resolver looking u...
void release_view_scope(std::uint64_t view_id)
Tear down a view scope.
FontScope & view_scope(std::uint64_t view_id)
Look up (or lazily create) the view scope for view_id.
@ path
Definition scene_node.hpp:93
FontScope & plugin_scope(std::uint64_t plugin_id)
Look up (or lazily create) the plugin scope for plugin_id.
FontScope & global_scope()
Process-wide global scope.
STL namespace.
Opaque identifier for a FontScope (defined in font_scope.hpp).
Definition font_options.hpp:168