HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
otype_utilities.hpp
1// Copyright Take Vos 2023.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../utility/module.hpp"
8#include "../placement.hpp"
9#include <concepts>
10
11namespace hi { inline namespace v1 {
12
16 big_uint32_buf_t x;
17
18 constexpr float operator*() const noexcept
19 {
20 return static_cast<float>(*x) / 65536.0f;
21 }
22};
23
27 big_int16_buf_t x;
28
29 constexpr float operator*() const noexcept
30 {
31 return static_cast<float>(*x) / 16384.0f;
32 }
33};
34
38 big_int16_buf_t x;
39 [[nodiscard]] constexpr float operator*(float Em_scale) const noexcept
40 {
41 return static_cast<float>(*x) * Em_scale;
42 }
43};
44
48 int8_t x;
49 [[nodiscard]] constexpr float operator*(float Em_scale) const noexcept
50 {
51 return static_cast<float>(x) * Em_scale;
52 }
53};
54
58 big_uint16_buf_t x;
59 [[nodiscard]] constexpr float operator*(float Em_scale) const noexcept
60 {
61 return static_cast<float>(*x) * Em_scale;
62 }
63};
64
65inline std::optional<std::string>
66otype_get_string(std::span<std::byte const> bytes, uint16_t platform_id, uint16_t platform_specific_id)
67{
68 switch (platform_id) {
69 case 2: // Deprecated, but compatible with unicode.
70 case 0: // Unicode, encoded as UTF-16BE, should not be UTF-16LE, but sometimes it is.
71 hi_check(bytes.size() % 2 == 0, "Length in bytes of a name must be multiple of two");
72 return char_converter<"utf-16", "utf-8">{}.read(bytes.data(), bytes.size(), std::endian::big);
73
74 case 1: // Macintosh
75 if (platform_specific_id == 0) { // Roman script ASCII
76 return char_converter<"utf-8", "utf-8">{}.read(bytes.data(), bytes.size());
77 }
78 break;
79
80 case 3: // Windows
81 if (platform_specific_id == 1 or platform_specific_id == 10) { // UTF-16BE
82 hi_check(bytes.size() % 2 == 0, "Length in bytes of a name must be multiple of two");
83 return char_converter<"utf-16", "utf-8">{}.read(bytes.data(), bytes.size(), std::endian::big);
84 }
85 break;
86
87 default:
88 break;
89 }
90 return {};
91}
92
93}} // namespace hi::v1
#define hi_check(expression, message,...)
Check if the expression is valid, or throw a parse_error.
Definition assert.hpp:110
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
A converter between character encodings.
Definition char_converter.hpp:92
OutRange read(void const *ptr, size_t size, std::endian endian=std::endian::native) noexcept
Read text from a byte array.
Definition char_converter.hpp:180
Open-type 16.16 signed fixed point, range between -32768.0 and 32767.999.
Definition otype_utilities.hpp:15
Open-type 16-bit signed fraction, range between -2.0 and 1.999.
Definition otype_utilities.hpp:26
Open-type for 16 signed integer that must be scaled by the EM-scale.
Definition otype_utilities.hpp:37
Open-type for 8 signed integer that must be scaled by the EM-scale.
Definition otype_utilities.hpp:47
Open-type for 16 unsigned integer that must be scaled by the EM-scale.
Definition otype_utilities.hpp:57