From ab6da3b21280d8a6e639338125496bbb024c0dc8 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sat, 12 Mar 2022 17:50:07 +0300 Subject: [PATCH] Add 10x12 bold font --- libs/ui/include/psemek/ui/font.hpp | 1 + libs/ui/resources/font_10x12_bold_glyphs.txt | 97 ++++++++++++++++++++ libs/ui/resources/font_9x12_glyphs.txt | 2 +- libs/ui/source/default_fonts.cpp | 21 +++-- 4 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 libs/ui/resources/font_10x12_bold_glyphs.txt diff --git a/libs/ui/include/psemek/ui/font.hpp b/libs/ui/include/psemek/ui/font.hpp index 85bf4260..ad0d2ebe 100644 --- a/libs/ui/include/psemek/ui/font.hpp +++ b/libs/ui/include/psemek/ui/font.hpp @@ -68,5 +68,6 @@ namespace psemek::ui std::unique_ptr make_default_monospace_9x12_font(); std::unique_ptr make_default_9x12_font(); + std::unique_ptr make_default_10x12_bold_font(); } diff --git a/libs/ui/resources/font_10x12_bold_glyphs.txt b/libs/ui/resources/font_10x12_bold_glyphs.txt new file mode 100644 index 00000000..4c522120 --- /dev/null +++ b/libs/ui/resources/font_10x12_bold_glyphs.txt @@ -0,0 +1,97 @@ +# + +32 0 0 1 0 0 0 7 # ' ' +33 17 3 2 8 0 0 3 # ! +34 27 3 6 3 0 5 7 # " +35 39 3 6 9 0 -1 7 # # +36 51 3 5 9 0 -1 6 # $ +37 63 3 6 8 0 0 7 # % +38 75 5 6 6 0 0 7 # & +39 89 3 2 4 0 4 3 # ' +40 101 2 3 10 0 -1 4 # ( +41 112 2 3 10 0 -1 4 # ) +42 123 3 6 5 0 3 7 # * +43 134 4 8 7 0 0 9 # + +44 148 9 4 4 0 -2 5 # , +45 159 7 6 1 0 3 7 # - +46 172 9 3 2 0 0 4 # . +47 183 3 6 9 0 -1 7 # / +48 3 17 6 8 0 0 7 # 0 +49 15 17 6 8 0 0 7 # 1 +50 27 17 6 8 0 0 7 # 2 +51 39 17 6 8 0 0 7 # 3 +52 51 17 7 8 0 0 8 # 4 +53 63 17 6 8 0 0 7 # 5 +54 75 17 6 8 0 0 7 # 6 +55 87 17 6 8 0 0 7 # 7 +56 99 17 6 8 0 0 7 # 8 +57 111 17 6 8 0 0 7 # 9 +58 124 19 3 6 0 0 4 # : +59 136 19 4 7 0 -1 5 # ; +60 146 18 7 7 0 0 8 # < +61 159 20 6 3 0 2 7 # = +62 170 18 7 7 0 0 8 # > +63 184 18 5 7 0 0 6 # ? +64 3 30 6 10 0 -1 7 # @ +65 14 31 8 8 0 0 9 # A +66 26 31 7 8 0 0 8 # B +67 39 31 6 8 0 0 7 # C +68 50 31 7 8 0 0 8 # D +69 62 31 7 8 0 0 8 # E +70 74 31 7 8 0 0 8 # F +71 87 31 7 8 0 0 8 # G +72 98 31 8 8 0 0 9 # H +73 111 31 6 8 0 0 7 # I +74 123 31 6 8 0 0 7 # J +75 134 31 8 8 0 0 9 # K +76 147 31 6 8 0 0 7 # L +77 158 31 8 8 0 0 9 # M +78 170 31 8 8 0 0 9 # N +79 183 31 6 8 0 0 7 # O +80 3 45 6 8 0 0 7 # P +81 15 45 6 9 0 -1 7 # Q +82 26 45 8 8 0 0 9 # R +83 39 45 6 8 0 0 7 # S +84 50 45 8 8 0 0 9 # T +85 62 45 8 8 0 0 9 # U +86 74 45 8 8 0 0 9 # V +87 85 45 8 8 0 0 9 # W +88 98 45 8 8 0 0 9 # X +89 110 45 8 8 0 0 9 # Y +90 123 45 6 8 0 0 7 # Z +91 136 44 4 10 0 -1 5 # [ +92 147 45 5 9 0 -1 6 # \ +93 160 44 4 10 0 -1 5 # ] +94 171 45 6 4 0 4 7 # ^ +95 182 54 8 1 0 -2 9 # _ +96 5 58 3 2 0 7 4 # ` +97 15 61 7 6 0 0 8 # a +98 26 59 7 8 0 0 8 # b +99 39 61 6 6 0 0 7 # c +100 51 59 7 8 0 0 8 # d +101 63 61 6 6 0 0 7 # e +102 75 59 6 8 0 0 7 # f +103 87 61 7 8 0 -2 8 # g +104 98 59 8 8 0 0 9 # h +105 111 59 6 8 0 0 7 # i +106 123 59 5 10 0 -2 6 # j +107 134 59 7 8 0 0 8 # k +108 147 59 6 8 0 0 7 # l +109 158 61 8 6 0 0 9 # m +110 170 61 8 6 0 0 9 # n +111 183 61 6 6 0 0 7 # o +112 2 75 7 8 0 -2 8 # p +113 15 75 7 8 0 -2 8 # q +114 27 75 6 6 0 0 7 # r +115 39 75 6 6 0 0 7 # s +116 50 74 7 7 0 0 8 # t +117 62 75 8 6 0 0 9 # u +118 73 75 9 6 0 0 10 # v +119 85 75 9 6 0 0 10 # w +120 99 75 7 6 0 0 8 # x +121 110 75 8 8 0 -2 9 # y +122 123 75 6 6 0 0 7 # z +123 136 72 4 10 0 -1 5 # { +124 149 72 2 9 0 0 3 # | +125 160 72 4 10 0 -1 5 # } +126 171 73 6 2 0 6 7 # ~ diff --git a/libs/ui/resources/font_9x12_glyphs.txt b/libs/ui/resources/font_9x12_glyphs.txt index ce32123c..5fc2f318 100644 --- a/libs/ui/resources/font_9x12_glyphs.txt +++ b/libs/ui/resources/font_9x12_glyphs.txt @@ -19,7 +19,7 @@ 49 14 17 5 8 0 0 6 # 1 50 25 17 5 8 0 0 6 # 2 51 36 17 5 8 0 0 6 # 3 -52 47 17 6 8 0 0 7 # 4 +52 47 17 5 8 0 0 6 # 4 53 58 17 5 8 0 0 6 # 5 54 69 17 5 8 0 0 6 # 6 55 80 17 5 8 0 0 6 # 7 diff --git a/libs/ui/source/default_fonts.cpp b/libs/ui/source/default_fonts.cpp index 55e5087e..0c18bd4e 100644 --- a/libs/ui/source/default_fonts.cpp +++ b/libs/ui/source/default_fonts.cpp @@ -4,6 +4,8 @@ #include #include +#include +#include #include @@ -44,12 +46,9 @@ namespace psemek::ui return std::make_unique(range, name, size, std::move(atlas), std::move(texcoords)); } - std::unique_ptr make_default_9x12_font() + static std::unique_ptr make_default_font(std::string_view name, geom::vector const & size, rs::resource const & atlas_resource, rs::resource const & glyphs_resource) { - 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})); + gfx::texture_2d atlas = gfx::texture_2d::from_pixmap(gfx::read_png_monochrome(io::memory_istream{atlas_resource.data})); atlas.nearest_filter(); atlas.clamp(); gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_G, gl::RED); @@ -58,7 +57,7 @@ namespace psemek::ui std::unordered_map glyphs; { - std::istringstream is{std::string(ui::resources::font_9x12_glyphs_txt.data)}; + std::istringstream is{std::string(glyphs_resource.data)}; std::string line; while (std::getline(is, line)) @@ -81,4 +80,14 @@ namespace psemek::ui return std::make_unique(name, size, 2, std::move(atlas), std::move(glyphs)); } + std::unique_ptr make_default_9x12_font() + { + return make_default_font("default_9x12", {9, 12}, gfx::resource::font_9x12_png, ui::resources::font_9x12_glyphs_txt); + } + + std::unique_ptr make_default_10x12_bold_font() + { + return make_default_font("default_10x12_bold", {10, 12}, gfx::resource::font_10x12_bold_png, ui::resources::font_10x12_bold_glyphs_txt); + } + }