diff options
author | giskard <[email protected]> | 2024-05-22 16:09:36 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2024-05-22 10:09:36 +0200 |
commit | 93fea890433ec11d7a915f5e0466b2e8b513e895 (patch) | |
tree | cee3c8acde01dd29c45d4184917f3596622edeac /src/render/OpenGL.cpp | |
parent | e419ef1873de01b0762f7f1a411994170a4d8cab (diff) | |
download | Hyprland-93fea890433ec11d7a915f5e0466b2e8b513e895.tar.gz Hyprland-93fea890433ec11d7a915f5e0466b2e8b513e895.zip |
renderer: render fonts with pango, add global `font_family` config option (#6138)
Diffstat (limited to 'src/render/OpenGL.cpp')
-rw-r--r-- | src/render/OpenGL.cpp | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index a8a20f30..a1e6f73e 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -1,9 +1,9 @@ +#include <random> +#include <pango/pangocairo.h> #include "Shaders.hpp" #include "OpenGL.hpp" #include "../Compositor.hpp" #include "../helpers/MiscFunctions.hpp" -#include "Shaders.hpp" -#include <random> #include "../config/ConfigValue.hpp" #include "../desktop/LayerSurface.hpp" #include "../protocols/LayerShell.hpp" @@ -2097,25 +2097,36 @@ void CHyprOpenGLImpl::renderMirrored() { } void CHyprOpenGLImpl::renderSplash(cairo_t* const CAIRO, cairo_surface_t* const CAIROSURFACE, double offsetY, const Vector2D& size) { - static auto PSPLASHCOLOR = CConfigValue<Hyprlang::INT>("misc:col.splash"); - - static auto PSPLASHFONT = CConfigValue<std::string>("misc:splash_font_family"); + static auto PSPLASHCOLOR = CConfigValue<Hyprlang::INT>("misc:col.splash"); + static auto PSPLASHFONT = CConfigValue<std::string>("misc:splash_font_family"); + static auto FALLBACKFONT = CConfigValue<std::string>("misc:font_family"); - cairo_select_font_face(CAIRO, (*PSPLASHFONT).c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + const auto FONTFAMILY = *PSPLASHFONT != STRVAL_EMPTY ? *PSPLASHFONT : *FALLBACKFONT; + const auto FONTSIZE = (int)(size.y / 76); + const auto COLOR = CColor(*PSPLASHCOLOR); - const auto FONTSIZE = (int)(size.y / 76); - cairo_set_font_size(CAIRO, FONTSIZE); + PangoLayout* layoutText = pango_cairo_create_layout(CAIRO); + PangoFontDescription* pangoFD = pango_font_description_new(); - const auto COLOR = CColor(*PSPLASHCOLOR); + pango_font_description_set_family_static(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); cairo_set_source_rgba(CAIRO, COLOR.r, COLOR.g, COLOR.b, COLOR.a); - cairo_text_extents_t textExtents; - cairo_text_extents(CAIRO, g_pCompositor->m_szCurrentSplash.c_str(), &textExtents); + int textW = 0, textH = 0; + pango_layout_set_text(layoutText, g_pCompositor->m_szCurrentSplash.c_str(), -1); + pango_layout_get_size(layoutText, &textW, &textH); + textW /= PANGO_SCALE; + textH /= PANGO_SCALE; - cairo_move_to(CAIRO, (size.x - textExtents.width) / 2.0, size.y - textExtents.height + offsetY); + cairo_move_to(CAIRO, (size.x - textW) / 2.0, size.y - textH * 2 + offsetY); + pango_cairo_show_layout(CAIRO, layoutText); - cairo_show_text(CAIRO, g_pCompositor->m_szCurrentSplash.c_str()); + pango_font_description_free(pangoFD); + g_object_unref(layoutText); cairo_surface_flush(CAIROSURFACE); } |