Skip to content

Commit

Permalink
Load the pango_font_metrics_get_height function lazily
Browse files Browse the repository at this point in the history
To be removed when Ardour updates their Pango library to 1.44
  • Loading branch information
paulfd committed Jan 14, 2024
1 parent bef165b commit 18d9ec4
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions vstgui/lib/platform/linux/cairofont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <pango/pango-features.h>
#include <pango/pangofc-fontmap.h>
#include <fontconfig/fontconfig.h>
#include <dlfcn.h>

//------------------------------------------------------------------------
namespace VSTGUI {
Expand Down Expand Up @@ -142,6 +143,21 @@ struct Font::Impl
CCoord capHeight {-1.};
};

// TODO: Remove when Ardour updates their pango version
typedef int(*pangoHeightFuncPointer)(PangoFontMetrics*);
auto get_height_function() -> pangoHeightFuncPointer
{
static pangoHeightFuncPointer f = [] () -> pangoHeightFuncPointer {
void *dlh = dlopen("libpango-1.0.so.0", RTLD_LAZY|RTLD_NOLOAD);
if (!dlh)
return nullptr;
void* f = dlsym(dlh, "pango_font_metrics_get_height");
dlclose(dlh);
return (pangoHeightFuncPointer) f;
}();
return f;
}

//------------------------------------------------------------------------
Font::Font (UTF8StringPtr name, const CCoord& size, const int32_t& style)
{
Expand All @@ -156,12 +172,12 @@ Font::Font (UTF8StringPtr name, const CCoord& size, const int32_t& style)
{
impl->ascent = pango_units_to_double (pango_font_metrics_get_ascent (metrics));
impl->descent = pango_units_to_double (pango_font_metrics_get_descent (metrics));
#if (PANGO_VERSION_MAJOR > 1) || ((PANGO_VERSION_MAJOR == 1) && PANGO_VERSION_MINOR >= 44)
auto height = pango_units_to_double (pango_font_metrics_get_height (metrics));
impl->leading = height - (impl->ascent + impl->descent);
#else
impl->leading = 0.;
#endif
if (auto pango_get_height = get_height_function()) {
auto height = pango_units_to_double (pango_get_height (metrics));
impl->leading = height - (impl->ascent + impl->descent);
} else {
impl->leading = 0.;
}
pango_font_metrics_unref (metrics);
}

Expand Down

0 comments on commit 18d9ec4

Please sign in to comment.