#include #include #include #include #include #include #include namespace psemek::ui { std::unique_ptr make_default_monospace_9x12_font() { character_range range{32, 128}; std::string_view name = "default_monospace_9x12"; geom::vector size{9, 12}; gfx::texture_2d atlas = gfx::texture_2d::from_pixmap(gfx::read_png_monochrome(io::memory_istream{gfx::resource::font_9x12_png.data})); atlas.nearest_filter(); atlas.clamp(); gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_G, gl::RED); gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_B, gl::RED); gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_A, gl::RED); std::vector> texcoords(range.end - range.begin); for (char32_t c = range.begin; c < range.end; ++c) { int const row = 16; int x = (c - range.begin) % row; int y = (c - range.begin) / row; geom::box b; b[0].min = x * 11 + 1; b[0].max = b[0].min + 9; b[1].min = y * 14 + 1; b[1].max = b[1].min + 12; texcoords[c - range.begin] = b; } return std::make_unique(range, name, size, std::move(atlas), std::move(texcoords)); } std::unique_ptr make_default_9x12_font() { std::string_view name = "default_9x12"; geom::vector size{9, 12}; gfx::texture_2d atlas = gfx::texture_2d::from_pixmap(gfx::read_png_monochrome(io::memory_istream{gfx::resource::font_9x12_png.data})); atlas.nearest_filter(); atlas.clamp(); gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_G, gl::RED); gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_B, gl::RED); gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_A, gl::RED); std::unordered_map glyphs; { std::istringstream is{std::string(ui::resources::font_9x12_glyphs_txt.data)}; std::string line; while (std::getline(is, line)) { if (auto pos = line.find('#'); pos != std::string::npos) line = line.substr(0, pos); if (line.empty()) continue; std::istringstream is{std::move(line)}; int c; kerned_font::glyph_data data; is >> c >> data.start_x >> data.start_y >> data.size_x >> data.size_y >> data.offset_x >> data.offset_y >> data.advance; glyphs[c] = data; } } return std::make_unique(name, size, 2, std::move(atlas), std::move(glyphs)); } }