Files
plotter/include/plot/render/detail/text_scale.hpp
T
Martino Ferrari ed3a8ce645 licence: MIT LICENSE and SPDX identifiers in every first-party file
The repository had no licence at all, so every source was all-rights-reserved
by default. Add the verbatim MIT text at LICENSE (Copyright (c) 2026 Martino
Ferrari) and a two-line SPDX header to each of the 113 first-party sources --
48 include/plot, 26 src, 10 adapters, 5 examples, 21 tests, 3 tools -- so the
grant travels with each file rather than relying on the root document alone.

Scripts keep their shebang on line 1; the SPDX lines follow it. Genuinely
vendored code is untouched: third_party/stb_truetype.h carries no header of
ours. src/render/embedded_mono_font.cpp is generated, so tools/fonts/gen_atlas.py
emit() now writes the two lines into its header comment and the file was
regenerated -- gen_atlas.py --check passes and the regeneration adds only those
comment lines to the previously committed file.

README's provenance section now states MIT and links LICENSE.

No code, test or public API change.
2026-09-28 22:13:40 +02:00

30 lines
1.3 KiB
C++

// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2026 Martino Ferrari
#pragma once
#include <plot/core/types.hpp>
namespace plot::render::detail {
/// The factor a text run is drawn by: `requested_px / em_px`, a plain ratio.
///
/// It is a ratio rather than a whole multiple because the renderer's built-in
/// face is anti-aliased: a style asking for 12 px from a 13 px bake is drawn at
/// 12/13, where a 1-bit glyph would have had to snap to the nearest multiple of
/// its cell. Everything the renderer stages is scaled by this one factor, so the
/// labels a plot laid out and the glyphs the pipeline draws cannot disagree.
///
/// A backend that cannot state an em -- `em_px()` at or below zero, or NaN --
/// yields a 1:1 scale rather than dividing by it or propagating a NaN into every
/// vertex. The requested size being NaN, zero or negative does the same. The rule
/// lives here, not inline in the renderer, so it is one function and can be
/// asserted without a GL context; it is instrumentation-free and part of no
/// public surface (`*/detail/` headers stay out of the umbrella).
inline f32 text_scale(f32 requested_px, f32 em_px) noexcept {
const f32 ratio = requested_px / em_px;
return (em_px > 0.0f && ratio > 0.0f) ? ratio : 1.0f;
}
} // namespace plot::render::detail