53#ifndef WXMAXIMA_FONTATTRIBS_H
54#define WXMAXIMA_FONTATTRIBS_H
56#include "EnumWrapper.h"
58#include <wx/version.h>
98 constexpr static float Size_Unit = 0.05f;
101 using value_type = int16_t;
103 constexpr static float Minimum_Size = 4.0f;
104 constexpr static float Maximum_Size = std::numeric_limits<value_type>::max() * Size_Unit;
107 constexpr explicit AFontSize(
float size) : m_uSize(ToUSize(size)) {}
109 m_uSize(std::max(minimum.m_uSize, ToUSize(
static_cast<float>(size)))) {}
113 constexpr void Set(
float size) { m_uSize = ToUSize(size); }
114 constexpr void Clear() { m_uSize = {}; }
119 constexpr auto operator<=>(
const AFontSize& o)
const =
default;
120 constexpr float Get()
const {
return IsValid() ? m_uSize * Size_Unit : Minimum_Size; }
121 constexpr long GetAsLong()
const {
return long(Get() + 0.5f); }
123 constexpr bool IsNull()
const {
return !IsValid(); }
124 constexpr bool IsValid()
const {
return m_uSize > 0; }
125 constexpr bool IsMinimal()
const {
return m_uSize == ToUSize(Minimum_Size); }
133 value_type m_uSize = {};
134 constexpr static value_type ToUSize(
float size);
137constexpr double operator*(
double factor,
AFontSize size) {
return factor * size.Get(); }
138constexpr double operator*(
AFontSize size,
double factor) {
return size.Get() * factor; }
139constexpr double operator/(
double dividend,
AFontSize size) {
return dividend / size.Get(); }
140constexpr double operator/(
AFontSize size,
double divisor) {
return size.Get() / divisor; }
141constexpr double operator+(
double offset,
AFontSize size) {
return offset + size.Get(); }
142constexpr double operator+(
AFontSize size,
double offset) {
return size.Get() + offset; }
143constexpr double operator-(
double offset,
AFontSize size) {
return offset - size.Get(); }
144constexpr double operator-(
AFontSize size,
double offset) {
return size.Get() - offset; }
146{
return size.Set(
static_cast<float>(size - factor)), size; }
148constexpr AFontSize::value_type AFontSize::ToUSize(
float size)
150 return AFontSize::value_type(std::clamp(size, Minimum_Size, Maximum_Size) / Size_Unit + 0.5f);
A Type-Safe Fixed-Point Font Size.
Definition: FontAttribs.h:97
constexpr auto GetForWX() const
Get the numerical value suitable for passing to wxFont/wxFontInfo.
Definition: FontAttribs.h:154
friend bool EqualToWithin(AFontSize, AFontSize, float)
Whether the difference between to font sizes is below a provided limit value.
Definition: FontAttribs.cpp:64
Definition: FontAttribs.h:127