summaryrefslogtreecommitdiff
path: root/ui/font.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-06-04 21:14:45 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-06-04 21:14:45 +0100
commit6e94848aec5d42eed5f9e1f5548ade26915ce90b (patch)
treeb6cf5bc39f7da4c8853491da4008c29406b135f3 /ui/font.cpp
parentTidy of glRef (diff)
downloadilt-6e94848aec5d42eed5f9e1f5548ade26915ce90b.tar.bz2
ilt-6e94848aec5d42eed5f9e1f5548ade26915ce90b.tar.xz
ilt-6e94848aec5d42eed5f9e1f5548ade26915ce90b.zip
Tidy many stringy messes with std::format
Diffstat (limited to 'ui/font.cpp')
-rw-r--r--ui/font.cpp79
1 files changed, 41 insertions, 38 deletions
diff --git a/ui/font.cpp b/ui/font.cpp
index b6669b0..ebd29d0 100644
--- a/ui/font.cpp
+++ b/ui/font.cpp
@@ -1,6 +1,7 @@
#include "font.h"
#include <algorithm>
#include <cctype>
+#include <format>
#include <ft2build.h>
#include FT_FREETYPE_H
#include "gl_traits.h"
@@ -15,49 +16,51 @@
// IWYU pragma: no_forward_declare FT_LibraryRec_
-std::string
-FT_Error_StringSafe(FT_Error err)
-{
- if (const auto errstr = FT_Error_String(err)) {
- return {errstr};
+namespace {
+ std::string
+ FT_Error_StringSafe(FT_Error err)
+ {
+ if (const auto errstr = FT_Error_String(err)) {
+ return {errstr};
+ }
+ return std::format("Unknown FT error: {}", err);
}
- return std::to_string(err);
-}
-template<auto Func, typename... Args>
-void
-FT_Check(Args &&... args)
-{
- if (const auto err = Func(std::forward<Args>(args)...)) {
- throw std::runtime_error {std::string {"FreeType error: "} + FT_Error_StringSafe(err)};
+ template<auto Func, typename... Args>
+ void
+ FT_Check(Args &&... args)
+ {
+ if (const auto err = Func(std::forward<Args>(args)...)) {
+ throw std::runtime_error {std::format("FreeType error: {}", FT_Error_StringSafe(err))};
+ }
}
-}
-const std::string BASIC_CHARS = []() {
- std::string chars;
- for (char c {}; c >= 0; c++) {
- if (isgraph(c)) {
- chars += c;
+ const std::string BASIC_CHARS = []() {
+ std::string chars {"£€²³"};
+ for (char c {}; c >= 0; c++) {
+ if (isgraph(c)) {
+ chars += c;
+ }
}
- }
- return chars + "£€²³";
-}();
-
-using FT = glRef<FT_Library,
- []() {
- FT_Library ft {};
- FT_Check<FT_Init_FreeType>(&ft);
- return ft;
- },
- FT_Done_FreeType>;
-
-using Face = glRef<FT_Face,
- [](FT_Library ft, const char * const name) {
- FT_Face face {};
- FT_Check<FT_New_Face>(ft, name, 0, &face);
- return face;
- },
- FT_Done_Face>;
+ return chars;
+ }();
+
+ using FT = glRef<FT_Library,
+ []() {
+ FT_Library ft {};
+ FT_Check<FT_Init_FreeType>(&ft);
+ return ft;
+ },
+ FT_Done_FreeType>;
+
+ using Face = glRef<FT_Face,
+ [](FT_Library ft, const char * const name) {
+ FT_Face face {};
+ FT_Check<FT_New_Face>(ft, name, 0, &face);
+ return face;
+ },
+ FT_Done_Face>;
+}
Font::Font(std::filesystem::path p, unsigned s) : path {std::move(p)}, size {getTextureSize(s)}
{