Files
plotter/include/plot/render/text.hpp
T

33 lines
1.1 KiB
C++

#pragma once
#include <plot/core/types.hpp>
namespace plot::render {
/// Text metrics the plot layer lays axes and labels out with. It is a pure
/// interface so the layout code never depends on the bitmap font, and so a
/// caller can measure with a host toolkit's font instead.
///
/// Text is passed as UTF-8, not as a byte-per-character string: `plot::format_si`
/// emits U+00B5, U+00B0 and U+03A9 for micro, degree and ohm, and an
/// implementation that ignores that prints mojibake.
class TextBackend {
public:
TextBackend() noexcept = default;
TextBackend(const TextBackend&) = default;
TextBackend& operator=(const TextBackend&) = default;
virtual ~TextBackend() = default;
/// Width of `utf8` in the same units as `height()` (pixels for the bitmap
/// font). Zero for the empty string.
virtual f32 measure(const char* utf8) const = 0;
/// Line height: the cell a single line of text occupies.
virtual f32 height() const = 0;
/// Distance from the top of the cell to the baseline, so a caller can align
/// text bottoms instead of cell bottoms.
virtual f32 ascent() const = 0;
};
} // namespace plot::render