7#include "otype_utilities.hpp"
8#include "font_weight.hpp"
9#include "../utility/utility.hpp"
13hi_export_module(hikogui.font.otype_os2);
15hi_export
namespace hi {
inline namespace v1 {
17[[nodiscard]]
inline auto otype_parse_os2(std::span<std::byte const> bytes,
float em_scale)
25 uint8_t stroke_variation;
32 struct header_type_0 {
33 big_uint16_buf_t version;
34 big_int16_buf_t avg_char_width;
35 big_uint16_buf_t weight_class;
36 big_uint16_buf_t width_class;
37 big_uint16_buf_t type;
38 big_int16_buf_t subscript_x_size;
39 big_int16_buf_t subscript_y_size;
40 big_int16_buf_t subscript_x_offset;
41 big_int16_buf_t subscript_y_offset;
42 big_int16_buf_t superscript_x_size;
43 big_int16_buf_t superscript_y_size;
44 big_int16_buf_t superscript_x_offset;
45 big_int16_buf_t superscript_y_offset;
46 big_int16_buf_t strikeout_size;
47 big_int16_buf_t strikeout_position;
48 big_int16_buf_t family_class;
50 big_uint32_buf_t unicode_range_1;
51 big_uint32_buf_t unicode_range_2;
52 big_uint32_buf_t unicode_range_3;
53 big_uint32_buf_t unicode_range_4;
54 big_uint32_buf_t ach_vend_id;
55 big_uint16_buf_t selection;
56 big_uint16_buf_t first_char_index;
57 big_uint16_buf_t last_char_index;
60 struct header_type_2 : header_type_0 {
61 big_int16_buf_t typo_ascender;
62 big_int16_buf_t typo_descender;
63 big_int16_buf_t typo_line_gap;
64 big_uint16_buf_t win_ascent;
65 big_uint16_buf_t win_descent;
66 big_uint32_buf_t code_page_range_1;
67 big_uint32_buf_t code_page_range_2;
68 otype_fword_buf_t x_height;
69 otype_fword_buf_t cap_height;
70 big_uint16_buf_t default_char;
71 big_uint16_buf_t break_char;
72 big_uint16_buf_t max_context;
77 bool condensed =
false;
79 bool monospace =
false;
81 float x_height = 0.0f;
82 float cap_height = 0.0f;
85 auto const& header = implicit_cast<header_type_0>(bytes);
86 hi_check(*header.version <= 5,
"'OS/2' version must be between 0 and 5");
88 auto r = return_type{};
90 auto const weight_value = *header.weight_class;
91 if (weight_value >= 1 && weight_value <= 1000) {
95 auto const width_value = *header.width_class;
96 if (width_value >= 1 && width_value <= 4) {
98 }
else if (width_value >= 5 && width_value <= 9) {
102 auto const serif_value = header.panose.serif_style;
103 if ((serif_value >= 2 && serif_value <= 10) || (serif_value >= 14 && serif_value <= 15)) {
105 }
else if (serif_value >= 11 && serif_value <= 13) {
112 switch (header.panose.weight) {
114 r.weight = font_weight::thin;
117 r.weight = font_weight::extra_light;
120 r.weight = font_weight::light;
123 r.weight = font_weight::regular;
126 r.weight = font_weight::medium;
129 r.weight = font_weight::semi_bold;
132 r.weight = font_weight::bold;
135 r.weight = font_weight::extra_bold;
138 r.weight = font_weight::black;
141 r.weight = font_weight::extra_black;
147 switch (header.panose.proportion) {
167 auto const letterform_value = header.panose.letterform;
168 if (letterform_value >= 2 && letterform_value <= 8) {
170 }
else if (letterform_value >= 9 && letterform_value <= 15) {
174 if (*header.version >= 2) {
175 auto const &header_v2 = implicit_cast<header_type_2>(bytes);
177 r.x_height = header_v2.x_height * em_scale;
178 r.cap_height = header_v2.cap_height * em_scale;
The HikoGUI namespace.
Definition array_generic.hpp:20
@ italic
A font that is italic.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
constexpr font_weight font_weight_from_int(numeric_integral auto rhs)
Convert a font weight value between 50 and 1000 to a font weight.
Definition font_weight.hpp:63
font_weight
Definition font_weight.hpp:21