From 763403769c5c5773e505537b31832f0ad192b5fb Mon Sep 17 00:00:00 2001 From: Neil Hodgson Date: Fri, 28 Jan 2022 19:55:20 +1100 Subject: Use Pango library pango_units_from_double pango_units_to_double instead of custom equivalents as should no longer need to be compatible with very old Pango. --- gtk/PlatGTK.cxx | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index 64065602d..284ff247c 100755 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -55,17 +55,6 @@ constexpr double kPi = 3.14159265358979323846; constexpr double degrees = kPi / 180.0; -// The Pango version guard for pango_units_from_double and pango_units_to_double -// is more complex than simply implementing these here. - -constexpr int pangoUnitsFromDouble(double d) noexcept { - return static_cast(d * PANGO_SCALE + 0.5); -} - -constexpr float floatFromPangoUnits(int pu) noexcept { - return static_cast(pu) / PANGO_SCALE; -} - struct IntegerRectangle { int left; int top; @@ -112,7 +101,7 @@ public: if (pfd) { pango_font_description_set_family(pfd, (fp.faceName[0] == '!') ? fp.faceName + 1 : fp.faceName); - pango_font_description_set_size(pfd, pangoUnitsFromDouble(fp.size)); + pango_font_description_set_size(pfd, pango_units_from_double(fp.size)); pango_font_description_set_weight(pfd, static_cast(fp.weight)); pango_font_description_set_style(pfd, fp.italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); } @@ -861,11 +850,11 @@ public: positionStart = position; if (pango_layout_iter_next_cluster(iter)) { pango_layout_iter_get_cluster_extents(iter, nullptr, &pos); - position = floatFromPangoUnits(pos.x); + position = pango_units_to_double(pos.x); curIndex = pango_layout_iter_get_index(iter); } else { finished = true; - position = floatFromPangoUnits(pos.x + pos.width); + position = pango_units_to_double(pos.x + pos.width); curIndex = lenPositions; } distance = position - positionStart; @@ -949,7 +938,7 @@ void SurfaceImpl::MeasureWidths(const Font *font_, std::string_view text, XYPOSI // Something has gone wrong: exit quickly but pretend all the characters are equally spaced: int widthLayout = 0; pango_layout_get_size(layout, &widthLayout, nullptr); - const XYPOSITION widthTotal = floatFromPangoUnits(widthLayout); + const XYPOSITION widthTotal = pango_units_to_double(widthLayout); for (size_t bytePos=0; bytePospfd) { PangoFontMetrics *metrics = pango_context_get_metrics(pcontext, PFont(font_)->pfd, pango_context_get_language(pcontext)); - ascent = std::ceil(floatFromPangoUnits( + ascent = std::ceil(pango_units_to_double( pango_font_metrics_get_ascent(metrics))); pango_font_metrics_unref(metrics); } @@ -1099,7 +1088,7 @@ XYPOSITION SurfaceImpl::Descent(const Font *font_) { if (PFont(font_)->pfd) { PangoFontMetrics *metrics = pango_context_get_metrics(pcontext, PFont(font_)->pfd, pango_context_get_language(pcontext)); - const XYPOSITION descent = std::ceil(floatFromPangoUnits( + const XYPOSITION descent = std::ceil(pango_units_to_double( pango_font_metrics_get_descent(metrics))); pango_font_metrics_unref(metrics); return descent; -- cgit v1.2.3