summaryrefslogtreecommitdiff
path: root/src/hyprerror/HyprError.cpp
diff options
context:
space:
mode:
authorgiskard <rtgiskard@gmail.com>2024-05-22 16:09:36 +0800
committerGitHub <noreply@github.com>2024-05-22 10:09:36 +0200
commit93fea890433ec11d7a915f5e0466b2e8b513e895 (patch)
treecee3c8acde01dd29c45d4184917f3596622edeac /src/hyprerror/HyprError.cpp
parente419ef1873de01b0762f7f1a411994170a4d8cab (diff)
renderer: render fonts with pango, add global `font_family` config option (#6138)
Diffstat (limited to 'src/hyprerror/HyprError.cpp')
-rw-r--r--src/hyprerror/HyprError.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/hyprerror/HyprError.cpp b/src/hyprerror/HyprError.cpp
index e7e2ff0d..d147a6bb 100644
--- a/src/hyprerror/HyprError.cpp
+++ b/src/hyprerror/HyprError.cpp
@@ -1,3 +1,4 @@
+#include <pango/pangocairo.h>
#include "HyprError.hpp"
#include "../Compositor.hpp"
#include "../config/ConfigValue.hpp"
@@ -94,12 +95,19 @@ void CHyprError::createQueued() {
// draw the text with a common font
const CColor textColor = m_cQueued.r + m_cQueued.g + m_cQueued.b < 0.2f ? CColor(1.0, 1.0, 1.0, 1.0) : CColor(0, 0, 0, 1.0);
-
- cairo_select_font_face(CAIRO, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
- cairo_set_font_size(CAIRO, FONTSIZE);
cairo_set_source_rgba(CAIRO, textColor.r, textColor.g, textColor.b, textColor.a);
- float yoffset = TOPBAR ? FONTSIZE : Y - PAD + FONTSIZE;
+ static auto fontFamily = CConfigValue<std::string>("misc:font_family");
+ PangoLayout* layoutText = pango_cairo_create_layout(CAIRO);
+ PangoFontDescription* pangoFD = pango_font_description_new();
+
+ pango_font_description_set_family(pangoFD, (*fontFamily).c_str());
+ pango_font_description_set_absolute_size(pangoFD, FONTSIZE * PANGO_SCALE);
+ pango_font_description_set_style(pangoFD, PANGO_STYLE_NORMAL);
+ pango_font_description_set_weight(pangoFD, PANGO_WEIGHT_NORMAL);
+ pango_layout_set_font_description(layoutText, pangoFD);
+
+ float yoffset = TOPBAR ? 0 : Y - PAD;
int renderedcnt = 0;
while (!m_szQueued.empty() && renderedcnt < VISLINECOUNT) {
std::string current = m_szQueued.substr(0, m_szQueued.find('\n'));
@@ -108,17 +116,22 @@ void CHyprError::createQueued() {
else
m_szQueued = "";
cairo_move_to(CAIRO, PAD + 1 + RADIUS, yoffset + PAD + 1);
- cairo_show_text(CAIRO, current.c_str());
+ pango_layout_set_text(layoutText, current.c_str(), -1);
+ pango_cairo_show_layout(CAIRO, layoutText);
yoffset += FONTSIZE + (FONTSIZE / 10.f);
renderedcnt++;
}
if (VISLINECOUNT < LINECOUNT) {
std::string moreString = std::format("({} more...)", LINECOUNT - VISLINECOUNT);
cairo_move_to(CAIRO, PAD + 1 + RADIUS, yoffset + PAD + 1);
- cairo_show_text(CAIRO, moreString.c_str());
+ pango_layout_set_text(layoutText, moreString.c_str(), -1);
+ pango_cairo_show_layout(CAIRO, layoutText);
}
m_szQueued = "";
+ pango_font_description_free(pangoFD);
+ g_object_unref(layoutText);
+
cairo_surface_flush(CAIROSURFACE);
// copy the data to an OpenGL texture we have