mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-10-01 15:48:30 +00:00
renderer: render fonts with pango, add global font_family
config option (#6138)
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user