[pango/line-height: 1/5] Add line height to font metrics



commit 3b44adffa371d3ca50e0e6962ef24b79488a023b
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jul 4 22:06:06 2019 +0000

    Add line height to font metrics
    
    Add a getter for the line height of a font.

 pango/fonts.c              | 23 +++++++++++++++++++++++
 pango/pango-font-private.h |  1 +
 pango/pango-font.h         |  2 ++
 pango/pangocairo-font.c    |  1 +
 pango/pangofc-font.c       | 13 +++++++++++--
 5 files changed, 38 insertions(+), 2 deletions(-)
---
diff --git a/pango/fonts.c b/pango/fonts.c
index 6a7778d3..f273cd26 100644
--- a/pango/fonts.c
+++ b/pango/fonts.c
@@ -1793,6 +1793,7 @@ pango_font_get_metrics (PangoFont        *font,
 
       metrics->ascent = PANGO_SCALE * PANGO_UNKNOWN_GLYPH_HEIGHT;
       metrics->descent = 0;
+      metrics->height = 0;
       metrics->approximate_char_width = PANGO_SCALE * PANGO_UNKNOWN_GLYPH_WIDTH;
       metrics->approximate_digit_width = PANGO_SCALE * PANGO_UNKNOWN_GLYPH_WIDTH;
       metrics->underline_position = -PANGO_SCALE;
@@ -1939,6 +1940,28 @@ pango_font_metrics_get_descent (PangoFontMetrics *metrics)
   return metrics->descent;
 }
 
+/**
+ * pango_font_metrics_get_height:
+ * @metrics: a #PangoFontMetrics structure
+ *
+ * Gets the line height from a font metrics structure. The
+ * line height is the distance between successive baselines
+ * in wrapped text.
+ *
+ * If the line height is not available, 0 is returned.
+ *
+ * Return value: the height, in Pango units
+ *
+ * Since: 1.44
+ */
+int
+pango_font_metrics_get_height (PangoFontMetrics *metrics)
+{
+  g_return_val_if_fail (metrics != NULL, 0);
+
+  return metrics->height;
+}
+
 /**
  * pango_font_metrics_get_approximate_char_width:
  * @metrics: a #PangoFontMetrics structure
diff --git a/pango/pango-font-private.h b/pango/pango-font-private.h
index 13b05254..44d19dee 100644
--- a/pango/pango-font-private.h
+++ b/pango/pango-font-private.h
@@ -41,6 +41,7 @@ struct _PangoFontMetrics
 
   int ascent;
   int descent;
+  int height;
   int approximate_char_width;
   int approximate_digit_width;
   int underline_position;
diff --git a/pango/pango-font.h b/pango/pango-font.h
index 60501216..ceaf9643 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -335,6 +335,8 @@ PANGO_AVAILABLE_IN_ALL
 int               pango_font_metrics_get_ascent                  (PangoFontMetrics *metrics) G_GNUC_PURE;
 PANGO_AVAILABLE_IN_ALL
 int               pango_font_metrics_get_descent                 (PangoFontMetrics *metrics) G_GNUC_PURE;
+PANGO_AVAILABLE_IN_1_44
+int               pango_font_metrics_get_height                  (PangoFontMetrics *metrics) G_GNUC_PURE;
 PANGO_AVAILABLE_IN_ALL
 int               pango_font_metrics_get_approximate_char_width  (PangoFontMetrics *metrics) G_GNUC_PURE;
 PANGO_AVAILABLE_IN_ALL
diff --git a/pango/pangocairo-font.c b/pango/pangocairo-font.c
index cc2e7bee..0769675b 100644
--- a/pango/pangocairo-font.c
+++ b/pango/pangocairo-font.c
@@ -293,6 +293,7 @@ _pango_cairo_font_get_metrics (PangoFont     *font,
 
          info->metrics->ascent *= xscale;
          info->metrics->descent *= xscale;
+         info->metrics->height *= xscale;
          info->metrics->underline_position *= xscale;
          info->metrics->underline_thickness *= xscale;
          info->metrics->strikethrough_position *= xscale;
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 7fd7db0f..b8e8928a 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -390,6 +390,7 @@ get_face_metrics (PangoFcFont      *fcfont,
     {
       metrics->descent = 0;
       metrics->ascent = PANGO_SCALE * PANGO_UNKNOWN_GLYPH_HEIGHT;
+      metrics->height = metrics->ascent;
       metrics->underline_thickness = PANGO_SCALE;
       metrics->underline_position = - PANGO_SCALE;
       metrics->strikethrough_thickness = PANGO_SCALE;
@@ -422,24 +423,32 @@ get_face_metrics (PangoFcFont      *fcfont,
       vector.y = face->size->metrics.ascender;
       FT_Vector_Transform (&vector, &ft_matrix);
       metrics->ascent = PANGO_UNITS_26_6 (vector.y);
+
+      vector.x = 0;
+      vector.y = face->size->metrics.height;
+      FT_Vector_Transform (&vector, &ft_matrix);
+      metrics->height = PANGO_UNITS_26_6 (vector.y);
     }
   else if (fcfont->is_hinted ||
           (face->face_flags & FT_FACE_FLAG_SCALABLE) == 0)
     {
       metrics->descent = - PANGO_UNITS_26_6 (face->size->metrics.descender);
       metrics->ascent = PANGO_UNITS_26_6 (face->size->metrics.ascender);
+      metrics->height = PANGO_UNITS_26_6 (face->size->metrics.height);
     }
   else
     {
-      FT_Fixed ascender, descender;
+      FT_Fixed ascender, descender, height;
 
       descender = FT_MulFix (face->descender, face->size->metrics.y_scale);
       metrics->descent = - PANGO_UNITS_26_6 (descender);
 
       ascender = FT_MulFix (face->ascender, face->size->metrics.y_scale);
       metrics->ascent = PANGO_UNITS_26_6 (ascender);
-    }
 
+      height = FT_MulFix (face->height, face->size->metrics.y_scale);
+      metrics->height = PANGO_UNITS_26_6 (height);
+    }
 
   metrics->underline_thickness = 0;
   metrics->underline_position = 0;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]