8#include "glyph_atlas_info.hpp"
9#include "../graphic_path.hpp"
10#include "../geometry/module.hpp"
11#include "../utility/module.hpp"
22hi_warning_ignore_msvc(26401);
25hi_warning_ignore_msvc(26409);
27namespace hi::inline
v1 {
48 _num_graphemes = (value >> 4) & 0xf;
49 std::get<0>(_glyphs) =
glyph_id{(value >> 16) & 0xffff};
50 std::get<1>(_glyphs) = new_id;
53 _num_graphemes = (value >> 4) & 0xf;
54 std::get<0>(_glyphs) =
glyph_id{(value >> 16) & 0xffff};
55 std::get<1>(_glyphs) =
glyph_id{(value >> 32) & 0xffff};
56 std::get<2>(_glyphs) =
glyph_id{(value >> 48) & 0xffff};
57 std::get<3>(_glyphs) = new_id;
61 [[nodiscard]]
constexpr std::size_t num_glyphs() const noexcept
66 [[nodiscard]]
constexpr std::size_t num_graphemes() const noexcept
68 return _num_graphemes;
71 constexpr void set_num_graphemes(
std::size_t num_graphemes)
noexcept
74 _num_graphemes = narrow_cast<uint8_t>(num_graphemes);
77 [[nodiscard]]
constexpr std::size_t hash() const noexcept
81 for (
auto i = 0_uz; i != _num_glyphs; ++i) {
83 r ^= std::rotl(r, 16);
89 constexpr glyph_ids_long& operator+=(glyph_id
id)
noexcept
92 if (_num_glyphs < _glyphs.size()) {
93 _glyphs[_num_glyphs++] = id;
98 [[nodiscard]]
constexpr glyph_id
const& operator[](
std::size_t i)
const noexcept
104 template<std::
size_t I>
105 [[nodiscard]]
constexpr friend glyph_id get(glyph_ids_long
const& rhs)
noexcept
108 return std::get<I>(rhs._glyphs);
111 [[nodiscard]]
constexpr friend bool operator==(glyph_ids_long
const&, glyph_ids_long
const&)
noexcept =
default;
115 uint8_t _num_graphemes;
143 constexpr glyph_ids(
glyph_ids const& other) noexcept : _font(other._font), _ptr(other._ptr)
152 hi_return_on_self_assignment(other);
165 constexpr glyph_ids(
glyph_ids&& other) noexcept : _font(other._font), _ptr(std::exchange(other._ptr, make_ptr(1))) {}
179 constexpr glyph_ids() noexcept : _font(
nullptr), _ptr(make_ptr(1)) {}
191 [[nodiscard]]
constexpr font const&
font() const noexcept
218 [[nodiscard]]
constexpr bool empty() const noexcept
220 return _ptr == make_ptr(1);
225 constexpr operator bool() const noexcept
237 template<std::
size_t N>
240 static_assert(N <= num_glyphs_mask);
242 constexpr std::size_t mask = (num_glyphs_mask << num_glyphs_shift) | 1;
243 constexpr std::size_t value = (N << num_glyphs_shift) | 1;
244 return (make_value(_ptr) & mask) == value;
259 return is_long() ? _ptr->num_glyphs() : (make_value(_ptr) >> 1) & num_glyphs_mask;
262 [[nodiscard]]
constexpr std::size_t num_graphemes() const noexcept
264 return is_long() ? _ptr->num_graphemes() : (make_value(_ptr) >> 4) & 0xf;
267 constexpr void set_num_graphemes(
std::size_t num_graphemes)
noexcept
270 _ptr->set_num_graphemes(num_graphemes);
272 hi_axiom(num_graphemes <= num_graphemes_mask);
274 (make_value(_ptr) & ~(num_graphemes_mask << num_graphemes_shift)) | (num_graphemes << num_graphemes_shift));
282 return is_long() ? _ptr->hash() : make_value(_ptr);
294 }
else if (
hilet index = short_num_glyphs(); index < num_glyphs_mask) {
295 increment_num_glyphs();
296 set_glyph(index,
id);
313 return (*_ptr)[index];
315 return get_glyph(index);
319 template<std::
size_t I>
323 return get<I>(*rhs._ptr);
326 return glyph_id{(make_value(rhs._ptr) >> shift) & 0xffff};
330 [[nodiscard]]
constexpr friend bool operator==(glyph_ids
const& lhs, glyph_ids
const& rhs)
noexcept
332 hilet lhs_value = make_value(lhs._ptr);
333 hilet rhs_value = make_value(rhs._ptr);
335 if (lhs._font != rhs._font) {
337 }
else if (lhs_value == rhs_value) {
340 return ((lhs_value | rhs_value) & 1) == 0 and *lhs._ptr == *rhs._ptr;
352 [[nodiscard]]
std::pair<
graphic_path, aarectangle> get_path_and_bounding_box() const noexcept;
358 [[nodiscard]] aarectangle get_bounding_box() const noexcept;
361 static_assert(sizeof(
std::
size_t) == sizeof(detail::glyph_ids_long *));
363 static constexpr
std::
size_t num_glyphs_shift = 1;
364 static constexpr
std::
size_t num_glyphs_mask = sizeof(
std::
size_t) == 4 ? 1 : 3;
365 static constexpr
std::
size_t num_graphemes_shift = 4;
366 static constexpr
std::
size_t num_graphemes_mask = 15;
381 detail::glyph_ids_long *_ptr;
383 constexpr
void increment_num_glyphs() noexcept
386 hi_axiom(short_num_glyphs() < num_glyphs_mask);
388 _ptr = make_ptr(make_value(_ptr) + (1 << num_glyphs_shift));
399 constexpr void set_glyph(
std::size_t i, glyph_id
id)
noexcept
405 _ptr = make_ptr((make_value(_ptr) & ~mask) | (
static_cast<std::size_t>(
id) << shift));
408 [[nodiscard]]
constexpr std::size_t short_num_glyphs() const noexcept
411 return (make_value(_ptr) >> num_glyphs_shift) & num_glyphs_mask;
414 [[nodiscard]]
constexpr bool is_short() const noexcept
416 return to_bool(make_value(_ptr) & 1);
419 [[nodiscard]]
constexpr bool is_long() const noexcept
421 return not is_short();
424 [[nodiscard]]
static constexpr detail::glyph_ids_long *make_ptr(
std::size_t value)
noexcept
426 return std::bit_cast<detail::glyph_ids_long *>(value);
429 [[nodiscard]]
static constexpr std::size_t make_value(detail::glyph_ids_long *ptr)
noexcept
431 return std::bit_cast<std::size_t>(ptr);
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
#define hi_assert_not_null(x,...)
Assert if an expression is not nullptr.
Definition assert.hpp:223
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
@ shift
The shift key is being held.
geometry/margins.hpp
Definition cache.hpp:11
Definition glyph_atlas_info.hpp:12
Definition glyph_ids.hpp:32
constexpr glyph_ids_long(std::size_t value, glyph_id new_id) noexcept
Construct a list of glyphs starting with a packed set of glyphs.
Definition glyph_ids.hpp:44
A set of glyph-ids of a font which composites into a single glyph.
Definition glyph_ids.hpp:134
glyph_atlas_info & atlas_info() const noexcept
Get information where the glyph is drawn in the atlas.
constexpr glyph_id get_single() const noexcept
Get the value of the single glyph.
Definition glyph_ids.hpp:249
constexpr std::size_t num_glyphs() const noexcept
Get the number of glyphs.
Definition glyph_ids.hpp:257
constexpr font const & font() const noexcept
Get the font for this glyph_ids object.
Definition glyph_ids.hpp:191
constexpr std::size_t hash() const noexcept
Get the hash value.
Definition glyph_ids.hpp:280
constexpr glyph_ids() noexcept
Create an empty glyph_ids object.
Definition glyph_ids.hpp:179
constexpr glyph_ids & operator+=(glyph_id id) noexcept
Add a glyph to this object.
Definition glyph_ids.hpp:289
constexpr bool has_num_glyphs() const noexcept
Check if this object contains a number of glyphs.
Definition glyph_ids.hpp:238
constexpr bool empty() const noexcept
Check if glyphs are attached.
Definition glyph_ids.hpp:218
constexpr glyph_id operator[](std::size_t index) const noexcept
Get a glyph.
Definition glyph_ids.hpp:308
constexpr void clear() noexcept
Clear the glyphs in this glyph_ids object.
Definition glyph_ids.hpp:208
void set_font(hi::font const &font) noexcept
Set the font for this glyph_ids object.
Definition glyph_ids.hpp:199
constexpr glyph_ids(hi::font const &font) noexcept
Create an empty glyph_ids for a font.
Definition glyph_ids.hpp:187
A path is a vector graphics object.
Definition graphic_path.hpp:26