From 6e716296ff89ba090c9ee1b913f644957e3bed62 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Wed, 10 May 2023 12:30:32 +0200
Subject: [PATCH] Formatting
---
include/cairo/font.hpp | 553 ++++++++++++++++++-----------------
include/cairo/utils.hpp | 103 +++----
include/utils/string.hpp | 72 ++---
src/cairo/utils.cpp | 330 ++++++++++-----------
src/utils/string.cpp | 617 +++++++++++++++++++--------------------
5 files changed, 840 insertions(+), 835 deletions(-)
diff --git a/include/cairo/font.hpp b/include/cairo/font.hpp
index 488a0875..5b396480 100644
--- a/include/cairo/font.hpp
+++ b/include/cairo/font.hpp
@@ -15,327 +15,332 @@
POLYBAR_NS
namespace cairo {
- /**
- * @brief Global pointer to the Freetype library handler
- */
- static FT_Library g_ftlib;
+/**
+ * @brief Global pointer to the Freetype library handler
+ */
+static FT_Library g_ftlib;
+
+/**
+ * @brief Abstract font face
+ */
+class font {
+ public:
+ explicit font(cairo_t* cairo, double offset) : m_cairo(cairo), m_offset(offset) {}
+ virtual ~font(){};
+
+ virtual string name() const = 0;
+ virtual string file() const = 0;
+ virtual double offset() const = 0;
+ virtual double size(double dpi) const = 0;
+
+ virtual cairo_font_extents_t extents() = 0;
+
+ virtual void use() {
+ cairo_set_font_face(m_cairo, cairo_font_face_reference(m_font_face));
+ }
+
+ virtual size_t match(utils::unicode_character& character) = 0;
+ virtual size_t match(utils::unicode_charlist& charlist) = 0;
+ virtual size_t render(const string& text, double x = 0.0, double y = 0.0) = 0;
+ virtual void textwidth(const string& text, cairo_text_extents_t* extents) = 0;
+
+ protected:
+ cairo_t* m_cairo;
+ cairo_font_face_t* m_font_face{nullptr};
+ cairo_font_extents_t m_extents{};
+ double m_offset{0.0};
+};
+
+/**
+ * @brief Font based on fontconfig/freetype
+ */
+class font_fc : public font {
+ public:
+ explicit font_fc(cairo_t* cairo, FcPattern* pattern, double offset, double dpi_x, double dpi_y)
+ : font(cairo, offset), m_pattern(pattern) {
+ cairo_matrix_t fm;
+ cairo_matrix_t ctm;
+ cairo_matrix_init_scale(&fm, size(dpi_x), size(dpi_y));
+ cairo_get_matrix(m_cairo, &ctm);
+
+ auto fontface = cairo_ft_font_face_create_for_pattern(m_pattern);
+ auto opts = cairo_font_options_create();
+ m_scaled = cairo_scaled_font_create(fontface, &fm, &ctm, opts);
+ cairo_font_options_destroy(opts);
+ cairo_font_face_destroy(fontface);
+
+ auto status = cairo_scaled_font_status(m_scaled);
+ if (status != CAIRO_STATUS_SUCCESS) {
+ throw application_error(sstream() << "cairo_scaled_font_create(): " << cairo_status_to_string(status));
+ }
+
+ auto lock = make_unique(m_scaled);
+ auto face = static_cast(*lock);
+
+ if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) == FT_Err_Ok) {
+ return;
+ } else if (FT_Select_Charmap(face, FT_ENCODING_BIG5) == FT_Err_Ok) {
+ return;
+ } else if (FT_Select_Charmap(face, FT_ENCODING_SJIS) == FT_Err_Ok) {
+ return;
+ }
+
+ lock.reset();
+ }
+
+ ~font_fc() override {
+ if (m_scaled != nullptr) {
+ cairo_scaled_font_destroy(m_scaled);
+ }
+ if (m_pattern != nullptr) {
+ FcPatternDestroy(m_pattern);
+ }
+ }
+
+ cairo_font_extents_t extents() override {
+ cairo_scaled_font_extents(m_scaled, &m_extents);
+ return m_extents;
+ }
+
+ string name() const override {
+ return property("family");
+ }
+
+ string file() const override {
+ return property("file");
+ }
+
+ double offset() const override {
+ return m_offset;
+ }
/**
- * @brief Abstract font face
+ * Calculates the font size in pixels for the given dpi
+ *
+ * We use the two font properties size and pixelsize. size is in points and
+ * needs to be scaled with the given dpi. pixelsize is not scaled.
+ *
+ * If both size properties are 0, we fall back to a default value of 10
+ * points for scalable fonts or 10 pixel for non-scalable ones. This should
+ * only happen if both properties are purposefully set to 0
+ *
+ * For scalable fonts we try to use the size property scaled according to
+ * the dpi.
+ * For non-scalable fonts we try to use the pixelsize property as-is
*/
- class font {
- public:
- explicit font(cairo_t* cairo, double offset) : m_cairo(cairo), m_offset(offset) {}
- virtual ~font(){};
+ double size(double dpi) const override {
+ bool scalable;
+ double fc_pixelsize = 0, fc_size = 0;
- virtual string name() const = 0;
- virtual string file() const = 0;
- virtual double offset() const = 0;
- virtual double size(double dpi) const = 0;
+ property(FC_SCALABLE, &scalable);
- virtual cairo_font_extents_t extents() = 0;
+ // Size in points
+ property(FC_SIZE, &fc_size);
- virtual void use() {
- cairo_set_font_face(m_cairo, cairo_font_face_reference(m_font_face));
- }
+ // Size in pixels
+ property(FC_PIXEL_SIZE, &fc_pixelsize);
- virtual size_t match(utils::unicode_character& character) = 0;
- virtual size_t match(utils::unicode_charlist& charlist) = 0;
- virtual size_t render(const string& text, double x = 0.0, double y = 0.0) = 0;
- virtual void textwidth(const string& text, cairo_text_extents_t* extents) = 0;
+ // Fall back to a default value if the size is 0
+ double pixelsize = fc_pixelsize == 0 ? 10 : fc_pixelsize;
+ double size = fc_size == 0 ? 10 : fc_size;
- protected:
- cairo_t* m_cairo;
- cairo_font_face_t* m_font_face{nullptr};
- cairo_font_extents_t m_extents{};
- double m_offset{0.0};
- };
+ // Font size in pixels if we use the pixelsize property
+ int px_pixelsize = pixelsize + 0.5;
- /**
- * @brief Font based on fontconfig/freetype
- */
- class font_fc : public font {
- public:
- explicit font_fc(cairo_t* cairo, FcPattern* pattern, double offset, double dpi_x, double dpi_y)
- : font(cairo, offset), m_pattern(pattern) {
- cairo_matrix_t fm;
- cairo_matrix_t ctm;
- cairo_matrix_init_scale(&fm, size(dpi_x), size(dpi_y));
- cairo_get_matrix(m_cairo, &ctm);
-
- auto fontface = cairo_ft_font_face_create_for_pattern(m_pattern);
- auto opts = cairo_font_options_create();
- m_scaled = cairo_scaled_font_create(fontface, &fm, &ctm, opts);
- cairo_font_options_destroy(opts);
- cairo_font_face_destroy(fontface);
-
- auto status = cairo_scaled_font_status(m_scaled);
- if (status != CAIRO_STATUS_SUCCESS) {
- throw application_error(sstream() << "cairo_scaled_font_create(): " << cairo_status_to_string(status));
- }
-
- auto lock = make_unique(m_scaled);
- auto face = static_cast(*lock);
-
- if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) == FT_Err_Ok) {
- return;
- } else if (FT_Select_Charmap(face, FT_ENCODING_BIG5) == FT_Err_Ok) {
- return;
- } else if (FT_Select_Charmap(face, FT_ENCODING_SJIS) == FT_Err_Ok) {
- return;
- }
-
- lock.reset();
- }
-
- ~font_fc() override {
- if (m_scaled != nullptr) {
- cairo_scaled_font_destroy(m_scaled);
- }
- if (m_pattern != nullptr) {
- FcPatternDestroy(m_pattern);
- }
- }
-
- cairo_font_extents_t extents() override {
- cairo_scaled_font_extents(m_scaled, &m_extents);
- return m_extents;
- }
-
- string name() const override {
- return property("family");
- }
-
- string file() const override {
- return property("file");
- }
-
- double offset() const override {
- return m_offset;
- }
-
- /**
- * Calculates the font size in pixels for the given dpi
- *
- * We use the two font properties size and pixelsize. size is in points and
- * needs to be scaled with the given dpi. pixelsize is not scaled.
- *
- * If both size properties are 0, we fall back to a default value of 10
- * points for scalable fonts or 10 pixel for non-scalable ones. This should
- * only happen if both properties are purposefully set to 0
- *
- * For scalable fonts we try to use the size property scaled according to
- * the dpi.
- * For non-scalable fonts we try to use the pixelsize property as-is
+ /*
+ * Font size in pixels if we use the size property. Since the size
+ * specifies the font size in points, this is converted to pixels
+ * according to the dpi given.
+ * One point is 1/72 inches, thus this gives us the number of 'dots'
+ * (or pixels) for this font
*/
- double size(double dpi) const override {
- bool scalable;
- double fc_pixelsize = 0, fc_size = 0;
+ int px_size = size / 72.0 * dpi + 0.5;
- property(FC_SCALABLE, &scalable);
-
- // Size in points
- property(FC_SIZE, &fc_size);
-
- // Size in pixels
- property(FC_PIXEL_SIZE, &fc_pixelsize);
-
- // Fall back to a default value if the size is 0
- double pixelsize = fc_pixelsize == 0 ? 10 : fc_pixelsize;
- double size = fc_size == 0 ? 10 : fc_size;
-
- // Font size in pixels if we use the pixelsize property
- int px_pixelsize = pixelsize + 0.5;
+ if (fc_size == 0 && fc_pixelsize == 0) {
+ return scalable ? px_size : px_pixelsize;
+ }
+ if (scalable) {
/*
- * Font size in pixels if we use the size property. Since the size
- * specifies the font size in points, this is converted to pixels
- * according to the dpi given.
- * One point is 1/72 inches, thus this gives us the number of 'dots'
- * (or pixels) for this font
+ * Use the point size if it's not 0. The pixelsize is only used if the
+ * size property is 0 and pixelsize is not
*/
- int px_size = size / 72.0 * dpi + 0.5;
-
- if (fc_size == 0 && fc_pixelsize == 0) {
- return scalable ? px_size : px_pixelsize;
- }
-
- if (scalable) {
- /*
- * Use the point size if it's not 0. The pixelsize is only used if the
- * size property is 0 and pixelsize is not
- */
- if (fc_size != 0) {
- return px_size;
- } else {
- return px_pixelsize;
- }
+ if (fc_size != 0) {
+ return px_size;
} else {
- /*
- * Non-scalable fonts do it the other way around, here the size
- * property is only used if pixelsize is 0 and size is not
- */
- if (fc_pixelsize != 0) {
- return px_pixelsize;
- } else {
- return px_size;
- }
+ return px_pixelsize;
+ }
+ } else {
+ /*
+ * Non-scalable fonts do it the other way around, here the size
+ * property is only used if pixelsize is 0 and size is not
+ */
+ if (fc_pixelsize != 0) {
+ return px_pixelsize;
+ } else {
+ return px_size;
+ }
+ }
+ }
+
+ void use() override {
+ cairo_set_scaled_font(m_cairo, m_scaled);
+ }
+
+ size_t match(utils::unicode_character& character) override {
+ auto lock = make_unique(m_scaled);
+ auto face = static_cast(*lock);
+ return FT_Get_Char_Index(face, character.codepoint) ? 1 : 0;
+ }
+
+ size_t match(utils::unicode_charlist& charlist) override {
+ auto lock = make_unique(m_scaled);
+ auto face = static_cast(*lock);
+ size_t available_chars = 0;
+ for (auto&& c : charlist) {
+ if (FT_Get_Char_Index(face, c.codepoint)) {
+ available_chars++;
+ } else {
+ break;
}
}
- void use() override {
- cairo_set_scaled_font(m_cairo, m_scaled);
- }
+ return available_chars;
+ }
- size_t match(utils::unicode_character& character) override {
- auto lock = make_unique(m_scaled);
- auto face = static_cast(*lock);
- return FT_Get_Char_Index(face, character.codepoint) ? 1 : 0;
- }
+ size_t render(const string& text, double x = 0.0, double y = 0.0) override {
+ cairo_glyph_t* glyphs{nullptr};
+ cairo_text_cluster_t* clusters{nullptr};
+ cairo_text_cluster_flags_t cf{};
+ int nglyphs = 0;
+ int nclusters = 0;
- size_t match(utils::unicode_charlist& charlist) override {
- auto lock = make_unique(m_scaled);
- auto face = static_cast(*lock);
- size_t available_chars = 0;
- for (auto&& c : charlist) {
- if (FT_Get_Char_Index(face, c.codepoint)) {
- available_chars++;
- } else {
- break;
- }
+ string utf8 = string(text);
+ auto status = cairo_scaled_font_text_to_glyphs(
+ m_scaled, x, y, utf8.c_str(), utf8.size(), &glyphs, &nglyphs, &clusters, &nclusters, &cf);
+
+ if (status != CAIRO_STATUS_SUCCESS) {
+ logger::make().notice("ERROR %d", status);
+ for (char& c : utf8) {
+ logger::make().notice("0x%02x", c);
}
-
- return available_chars;
+ throw application_error(sstream() << "cairo_scaled_font_text_to_glyphs() " << cairo_status_to_string(status));
}
- size_t render(const string& text, double x = 0.0, double y = 0.0) override {
- cairo_glyph_t* glyphs{nullptr};
- cairo_text_cluster_t* clusters{nullptr};
- cairo_text_cluster_flags_t cf{};
- int nglyphs = 0, nclusters = 0;
+ size_t bytes = 0;
+ for (int g = 0; g < nglyphs; g++) {
+ if (glyphs[g].index) {
+ bytes += clusters[g].num_bytes;
+ } else {
+ break;
+ }
+ }
- string utf8 = string(text);
+ if (bytes && bytes < text.size()) {
+ cairo_glyph_free(glyphs);
+ cairo_text_cluster_free(clusters);
+
+ utf8 = text.substr(0, bytes);
auto status = cairo_scaled_font_text_to_glyphs(
m_scaled, x, y, utf8.c_str(), utf8.size(), &glyphs, &nglyphs, &clusters, &nclusters, &cf);
if (status != CAIRO_STATUS_SUCCESS) {
- throw application_error(sstream() << "cairo_scaled_font_text_to_glyphs()" << cairo_status_to_string(status));
- }
-
- size_t bytes = 0;
- for (int g = 0; g < nglyphs; g++) {
- if (glyphs[g].index) {
- bytes += clusters[g].num_bytes;
- } else {
- break;
- }
- }
-
- if (bytes && bytes < text.size()) {
- cairo_glyph_free(glyphs);
- cairo_text_cluster_free(clusters);
-
- utf8 = text.substr(0, bytes);
- auto status = cairo_scaled_font_text_to_glyphs(
- m_scaled, x, y, utf8.c_str(), utf8.size(), &glyphs, &nglyphs, &clusters, &nclusters, &cf);
-
- if (status != CAIRO_STATUS_SUCCESS) {
- throw application_error(sstream() << "cairo_scaled_font_text_to_glyphs()" << cairo_status_to_string(status));
- }
- }
-
- if (bytes) {
- // auto lock = make_unique(cairo_surface_get_device(cairo_get_target(m_cairo)));
- // if (lock.get()) {
- // cairo_glyph_path(m_cairo, glyphs, nglyphs);
- // }
-
- cairo_text_extents_t extents{};
- cairo_scaled_font_glyph_extents(m_scaled, glyphs, nglyphs, &extents);
- cairo_show_text_glyphs(m_cairo, utf8.c_str(), utf8.size(), glyphs, nglyphs, clusters, nclusters, cf);
- cairo_fill(m_cairo);
- cairo_move_to(m_cairo, x + extents.x_advance, 0.0);
- }
-
- cairo_glyph_free(glyphs);
- cairo_text_cluster_free(clusters);
-
- return bytes;
- }
-
- void textwidth(const string& text, cairo_text_extents_t* extents) override {
- cairo_scaled_font_text_extents(m_scaled, text.c_str(), extents);
- }
-
- protected:
- string property(string&& property) const {
- FcChar8* file;
- if (FcPatternGetString(m_pattern, property.c_str(), 0, &file) == FcResultMatch) {
- return string(reinterpret_cast(file));
- } else {
- return "";
+ throw application_error(sstream() << "cairo_scaled_font_text_to_glyphs() " << cairo_status_to_string(status));
}
}
- void property(string&& property, bool* dst) const {
- FcBool b;
- FcPatternGetBool(m_pattern, property.c_str(), 0, &b);
- *dst = b;
+ if (bytes) {
+ // auto lock = make_unique(cairo_surface_get_device(cairo_get_target(m_cairo)));
+ // if (lock.get()) {
+ // cairo_glyph_path(m_cairo, glyphs, nglyphs);
+ // }
+
+ cairo_text_extents_t extents{};
+ cairo_scaled_font_glyph_extents(m_scaled, glyphs, nglyphs, &extents);
+ cairo_show_text_glyphs(m_cairo, utf8.c_str(), utf8.size(), glyphs, nglyphs, clusters, nclusters, cf);
+ cairo_fill(m_cairo);
+ cairo_move_to(m_cairo, x + extents.x_advance, 0.0);
}
- void property(string&& property, double* dst) const {
- FcPatternGetDouble(m_pattern, property.c_str(), 0, dst);
+ cairo_glyph_free(glyphs);
+ cairo_text_cluster_free(clusters);
+
+ return bytes;
+ }
+
+ void textwidth(const string& text, cairo_text_extents_t* extents) override {
+ cairo_scaled_font_text_extents(m_scaled, text.c_str(), extents);
+ }
+
+ protected:
+ string property(string&& property) const {
+ FcChar8* file;
+ if (FcPatternGetString(m_pattern, property.c_str(), 0, &file) == FcResultMatch) {
+ return string(reinterpret_cast(file));
+ } else {
+ return "";
}
+ }
- void property(string&& property, int* dst) const {
- FcPatternGetInteger(m_pattern, property.c_str(), 0, dst);
- }
+ void property(string&& property, bool* dst) const {
+ FcBool b;
+ FcPatternGetBool(m_pattern, property.c_str(), 0, &b);
+ *dst = b;
+ }
- private:
- cairo_scaled_font_t* m_scaled{nullptr};
- FcPattern* m_pattern{nullptr};
- };
+ void property(string&& property, double* dst) const {
+ FcPatternGetDouble(m_pattern, property.c_str(), 0, dst);
+ }
- /**
- * Match and create font from given fontconfig pattern
- */
- inline decltype(auto) make_font(cairo_t* cairo, string&& fontname, double offset, double dpi_x, double dpi_y) {
- static bool fc_init{false};
- if (!fc_init && !(fc_init = FcInit())) {
- throw application_error("Could not load fontconfig");
- } else if (FT_Init_FreeType(&g_ftlib) != FT_Err_Ok) {
- throw application_error("Could not load FreeType");
- }
+ void property(string&& property, int* dst) const {
+ FcPatternGetInteger(m_pattern, property.c_str(), 0, dst);
+ }
- static scope_util::on_exit fc_cleanup([] {
- FT_Done_FreeType(g_ftlib);
- FcFini();
- });
+ private:
+ cairo_scaled_font_t* m_scaled{nullptr};
+ FcPattern* m_pattern{nullptr};
+};
- auto pattern = FcNameParse((FcChar8*)fontname.c_str());
+/**
+ * Match and create font from given fontconfig pattern
+ */
+inline decltype(auto) make_font(cairo_t* cairo, string&& fontname, double offset, double dpi_x, double dpi_y) {
+ static bool fc_init{false};
+ if (!fc_init && !(fc_init = FcInit())) {
+ throw application_error("Could not load fontconfig");
+ } else if (FT_Init_FreeType(&g_ftlib) != FT_Err_Ok) {
+ throw application_error("Could not load FreeType");
+ }
- if (!pattern) {
- logger::make().err("Could not parse font \"%s\"", fontname);
- throw application_error("Could not parse font \"" + fontname + "\"");
- }
+ static scope_util::on_exit fc_cleanup([] {
+ FT_Done_FreeType(g_ftlib);
+ FcFini();
+ });
- FcDefaultSubstitute(pattern);
- FcConfigSubstitute(nullptr, pattern, FcMatchPattern);
+ auto pattern = FcNameParse((FcChar8*)fontname.c_str());
- FcResult result;
- FcPattern* match = FcFontMatch(nullptr, pattern, &result);
- FcPatternDestroy(pattern);
+ if (!pattern) {
+ logger::make().err("Could not parse font \"%s\"", fontname);
+ throw application_error("Could not parse font \"" + fontname + "\"");
+ }
- if (match == nullptr) {
- throw application_error("Could not load font \"" + fontname + "\"");
- }
+ FcDefaultSubstitute(pattern);
+ FcConfigSubstitute(nullptr, pattern, FcMatchPattern);
+
+ FcResult result;
+ FcPattern* match = FcFontMatch(nullptr, pattern, &result);
+ FcPatternDestroy(pattern);
+
+ if (match == nullptr) {
+ throw application_error("Could not load font \"" + fontname + "\"");
+ }
#ifdef DEBUG_FONTCONFIG
- FcPatternPrint(match);
+ FcPatternPrint(match);
#endif
- return make_shared(cairo, match, offset, dpi_x, dpi_y);
- }
+ return make_shared(cairo, match, offset, dpi_x, dpi_y);
+}
} // namespace cairo
POLYBAR_NS_END
diff --git a/include/cairo/utils.hpp b/include/cairo/utils.hpp
index 5db3a145..bd0497c1 100644
--- a/include/cairo/utils.hpp
+++ b/include/cairo/utils.hpp
@@ -1,6 +1,7 @@
#pragma once
#include
+
#include
#include "common.hpp"
@@ -8,63 +9,63 @@
POLYBAR_NS
namespace cairo {
- namespace utils {
- /**
- * @brief RAII wrapper used acquire cairo_device_t
- */
- class device_lock {
- public:
- explicit device_lock(cairo_device_t* device);
- ~device_lock();
- operator bool() const;
- operator cairo_device_t*() const;
+namespace utils {
+ /**
+ * @brief RAII wrapper used acquire cairo_device_t
+ */
+ class device_lock {
+ public:
+ explicit device_lock(cairo_device_t* device);
+ ~device_lock();
+ operator bool() const;
+ operator cairo_device_t*() const;
- private:
- cairo_device_t* m_device{nullptr};
- };
+ private:
+ cairo_device_t* m_device{nullptr};
+ };
- /**
- * @brief RAII wrapper used to access the underlying
- * FT_Face of a scaled font face
- */
- class ft_face_lock {
- public:
- explicit ft_face_lock(cairo_scaled_font_t* font);
- ~ft_face_lock();
- operator FT_Face() const;
+ /**
+ * @brief RAII wrapper used to access the underlying
+ * FT_Face of a scaled font face
+ */
+ class ft_face_lock {
+ public:
+ explicit ft_face_lock(cairo_scaled_font_t* font);
+ ~ft_face_lock();
+ operator FT_Face() const;
- private:
- cairo_scaled_font_t* m_font;
- FT_Face m_face;
- };
+ private:
+ cairo_scaled_font_t* m_font;
+ FT_Face m_face;
+ };
- /**
- * @brief Unicode character containing converted codepoint
- * and details on where its position in the source string
- */
- struct unicode_character {
- explicit unicode_character();
- unsigned long codepoint;
- int offset;
- int length;
- };
- using unicode_charlist = std::list;
+ /**
+ * @brief Unicode character containing converted codepoint
+ * and details on where its position in the source string
+ */
+ struct unicode_character {
+ explicit unicode_character();
+ unsigned long codepoint;
+ int offset;
+ int length;
+ };
+ using unicode_charlist = std::list;
- /**
- * @see
- */
- cairo_operator_t str2operator(const string& mode, cairo_operator_t fallback);
+ /**
+ * @see
+ */
+ cairo_operator_t str2operator(const string& mode, cairo_operator_t fallback);
- /**
- * @brief Create a UCS-4 codepoint from a utf-8 encoded string
- */
- bool utf8_to_ucs4(const unsigned char* src, unicode_charlist& result_list);
+ /**
+ * @brief Create a UCS-4 codepoint from a utf-8 encoded string
+ */
+ bool utf8_to_ucs4(const unsigned char* src, unicode_charlist& result_list);
- /**
- * @brief Convert a UCS-4 codepoint to a utf-8 encoded string
- */
- size_t ucs4_to_utf8(char* utf8, unsigned int ucs);
- }
-}
+ /**
+ * @brief Convert a UCS-4 codepoint to a utf-8 encoded string
+ */
+ size_t ucs4_to_utf8(char* utf8, unsigned int ucs);
+} // namespace utils
+} // namespace cairo
POLYBAR_NS_END
diff --git a/include/utils/string.hpp b/include/utils/string.hpp
index c2ee4ead..68399933 100644
--- a/include/utils/string.hpp
+++ b/include/utils/string.hpp
@@ -34,53 +34,53 @@ class sstream {
};
namespace string_util {
- /**
- * Hash type
- */
- using hash_type = unsigned long;
+/**
+ * Hash type
+ */
+using hash_type = unsigned long;
- bool contains(const string& haystack, const string& needle);
- bool contains_ignore_case(const string& haystack, const string& needle);
- bool ends_with(const string& haystack, const string& suffix);
- string upper(const string& s);
- string lower(const string& s);
- bool compare(const string& s1, const string& s2);
+bool contains(const string& haystack, const string& needle);
+bool contains_ignore_case(const string& haystack, const string& needle);
+bool ends_with(const string& haystack, const string& suffix);
+string upper(const string& s);
+string lower(const string& s);
+bool compare(const string& s1, const string& s2);
- string replace(const string& haystack, const string& needle, const string& replacement, size_t start = 0,
- size_t end = string::npos);
- string replace_all(const string& haystack, const string& needle, const string& replacement, size_t start = 0,
- size_t end = string::npos);
+string replace(const string& haystack, const string& needle, const string& replacement, size_t start = 0,
+ size_t end = string::npos);
+string replace_all(const string& haystack, const string& needle, const string& replacement, size_t start = 0,
+ size_t end = string::npos);
- string squeeze(const string& haystack, char needle);
+string squeeze(const string& haystack, char needle);
- string strip(const string& haystack, char needle);
- string strip_trailing_newline(const string& haystack);
+string strip(const string& haystack, char needle);
+string strip_trailing_newline(const string& haystack);
- string ltrim(string value, function pred);
- string rtrim(string value, function pred);
- string trim(string value, function pred);
+string ltrim(string value, function pred);
+string rtrim(string value, function pred);
+string trim(string value, function pred);
- string ltrim(string&& value, const char& needle = ' ');
- string rtrim(string&& value, const char& needle = ' ');
- string trim(string&& value, const char& needle = ' ');
+string ltrim(string&& value, const char& needle = ' ');
+string rtrim(string&& value, const char& needle = ' ');
+string trim(string&& value, const char& needle = ' ');
- size_t char_len(const string& value);
- string utf8_truncate(string&& value, size_t len);
+size_t char_len(const string& value);
+string utf8_truncate(string&& value, size_t len);
- string join(const vector& strs, const string& delim);
- vector split(const string& s, char delim);
- std::vector tokenize(const string& str, char delimiters);
+string join(const vector& strs, const string& delim);
+vector split(const string& s, char delim);
+std::vector tokenize(const string& str, char delimiters);
- size_t find_nth(const string& haystack, size_t pos, const string& needle, size_t nth);
+size_t find_nth(const string& haystack, size_t pos, const string& needle, size_t nth);
- string floating_point(double value, size_t precision, bool fixed = false, const string& locale = "");
- string filesize_mib(unsigned long long kibibytes, size_t precision = 0, const string& locale = "");
- string filesize_gib(unsigned long long kibibytes, size_t precision = 0, const string& locale = "");
- string filesize_gib_mib(
- unsigned long long kibibytes, size_t precision_mib = 0, size_t precision_gib = 0, const string& locale = "");
- string filesize(unsigned long long kbytes, size_t precision = 0, bool fixed = false, const string& locale = "");
+string floating_point(double value, size_t precision, bool fixed = false, const string& locale = "");
+string filesize_mib(unsigned long long kibibytes, size_t precision = 0, const string& locale = "");
+string filesize_gib(unsigned long long kibibytes, size_t precision = 0, const string& locale = "");
+string filesize_gib_mib(
+ unsigned long long kibibytes, size_t precision_mib = 0, size_t precision_gib = 0, const string& locale = "");
+string filesize(unsigned long long kbytes, size_t precision = 0, bool fixed = false, const string& locale = "");
- hash_type hash(const string& src);
+hash_type hash(const string& src);
} // namespace string_util
POLYBAR_NS_END
diff --git a/src/cairo/utils.cpp b/src/cairo/utils.cpp
index b58e4309..f5649130 100644
--- a/src/cairo/utils.cpp
+++ b/src/cairo/utils.cpp
@@ -1,176 +1,176 @@
-#include