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/utility.hpp"
8#include "../parser/parser.hpp"
9#include "../macros.hpp"
10#include <concepts>
11
12hi_export_module(hikogui.font.otype_utilities);
13
14hi_export namespace hi { inline namespace v1 {
15
19 big_uint32_buf_t x;
20
21 constexpr float operator*() const noexcept
22 {
23 return static_cast<float>(*x) / 65536.0f;
24 }
25};
26
31
32 constexpr float operator*() const noexcept
33 {
34 return static_cast<float>(*x) / 16384.0f;
35 }
36};
37
42 [[nodiscard]] constexpr float operator*(float Em_scale) const noexcept
43 {
44 return static_cast<float>(*x) * Em_scale;
45 }
46};
47
51 int8_t x;
52 [[nodiscard]] constexpr float operator*(float Em_scale) const noexcept
53 {
54 return static_cast<float>(x) * Em_scale;
55 }
56};
57
62 [[nodiscard]] constexpr float operator*(float Em_scale) const noexcept
63 {
64 return static_cast<float>(*x) * Em_scale;
65 }
66};
67
68inline std::optional<std::string>
69otype_get_string(std::span<std::byte const> bytes, uint16_t platform_id, uint16_t platform_specific_id)
70{
71 switch (platform_id) {
72 case 2: // Deprecated, but compatible with unicode.
73 case 0: // Unicode, encoded as UTF-16BE, should not be UTF-16LE, but sometimes it is.
74 hi_check(bytes.size() % 2 == 0, "Length in bytes of a name must be multiple of two");
75 return char_converter<"utf-16", "utf-8">{}.read(bytes.data(), bytes.size(), std::endian::big);
76
77 case 1: // Macintosh
78 if (platform_specific_id == 0) { // Roman script ASCII
79 return char_converter<"utf-8", "utf-8">{}.read(bytes.data(), bytes.size());
80 }
81 break;
82
83 case 3: // Windows
84 if (platform_specific_id == 1 or platform_specific_id == 10) { // UTF-16BE
85 hi_check(bytes.size() % 2 == 0, "Length in bytes of a name must be multiple of two");
86 return char_converter<"utf-16", "utf-8">{}.read(bytes.data(), bytes.size(), std::endian::big);
87 }
88 break;
89
90 default:
91 break;
92 }
93 return {};
94}
95
96}} // namespace hi::v1
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
A converter between character encodings.
Definition char_converter.hpp:98
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:186
Open-type 16.16 signed fixed point, range between -32768.0 and 32767.999.
Definition otype_utilities.hpp:18
Open-type 16-bit signed fraction, range between -2.0 and 1.999.
Definition otype_utilities.hpp:29
Open-type for 16 signed integer that must be scaled by the EM-scale.
Definition otype_utilities.hpp:40
Open-type for 8 signed integer that must be scaled by the EM-scale.
Definition otype_utilities.hpp:50
Open-type for 16 unsigned integer that must be scaled by the EM-scale.
Definition otype_utilities.hpp:60