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 float value() const noexcept
29 {
30 return static_cast<float>(*x) / 16384.0f;
31 }
32};
33
37 big_int16_buf_t x;
38 [[nodiscard]] constexpr float operator*(float Em_scale) const noexcept
39 {
40 return static_cast<float>(*x) * Em_scale;
41 }
42};
43
47 int8_t x;
48 [[nodiscard]] constexpr float operator*(float Em_scale) const noexcept
49 {
50 return static_cast<float>(x) * Em_scale;
51 }
52};
53
57 big_uint16_buf_t x;
58 [[nodiscard]] constexpr float operator*(float Em_scale) const noexcept
59 {
60 return static_cast<float>(*x) * Em_scale;
61 }
62};
63
64inline std::optional<std::string>
65otype_get_string(std::span<std::byte const> bytes, uint16_t platform_id, uint16_t platform_specific_id)
66{
67 switch (platform_id) {
68 case 2: // Deprecated, but compatible with unicode.
69 case 0: // Unicode, encoded as UTF-16BE, should not be UTF-16LE, but sometimes it is.
70 hi_check(bytes.size() % 2 == 0, "Length in bytes of a name must be multiple of two");
71 return char_converter<"utf-16", "utf-8">{}.read(bytes.data(), bytes.size(), std::endian::big);
72
73 case 1: // Macintosh
74 if (platform_specific_id == 0) { // Roman script ASCII
75 return char_converter<"utf-8", "utf-8">{}.read(bytes.data(), bytes.size());
76 }
77 break;
78
79 case 3: // Windows
80 if (platform_specific_id == 1 or platform_specific_id == 10) { // UTF-16BE
81 hi_check(bytes.size() % 2 == 0, "Length in bytes of a name must be multiple of two");
82 return char_converter<"utf-16", "utf-8">{}.read(bytes.data(), bytes.size(), std::endian::big);
83 }
84 break;
85
86 default:
87 break;
88 }
89 return {};
90}
91
92}} // namespace hi::v1
#define hi_check(expression, message,...)
Check if the expression is valid, or throw a parse_error.
Definition assert.hpp:95
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:36
Open-type for 8 signed integer that must be scaled by the EM-scale.
Definition otype_utilities.hpp:46
Open-type for 16 unsigned integer that must be scaled by the EM-scale.
Definition otype_utilities.hpp:56