[pango] Bug 602257 - Make pango_matrix_get_font_scale_factors() public



commit d4e0fb667815ad80bff60491a2125321ee88d1b7
Author: Behdad Esfahbod <behdad behdad org>
Date:   Thu Apr 30 17:23:38 2015 -0400

    Bug 602257 - Make pango_matrix_get_font_scale_factors() public

 docs/pango-docs.sgml    |   10 ++++++-
 docs/pango-sections.txt |    1 +
 pango/pango-matrix.c    |   69 ++++++++++++++++++++++++++++++----------------
 pango/pango-matrix.h    |    2 +
 pango/pango.def         |    1 +
 pango/pangofc-private.h |   42 ----------------------------
 6 files changed, 58 insertions(+), 67 deletions(-)
---
diff --git a/docs/pango-docs.sgml b/docs/pango-docs.sgml
index c5e3bb8..f7b8a16 100644
--- a/docs/pango-docs.sgml
+++ b/docs/pango-docs.sgml
@@ -135,8 +135,16 @@
     <xi:include href="xml/api-index-1.32.4.xml"><xi:fallback /></xi:include>
   </index>
   <index id="api-index-1-34" role="1.34">
-    <title>Index of new symbols in 1.32</title>
+    <title>Index of new symbols in 1.34</title>
     <xi:include href="xml/api-index-1.34.xml"><xi:fallback /></xi:include>
   </index>
+  <index id="api-index-1-36" role="1.36">
+    <title>Index of new symbols in 1.36</title>
+    <xi:include href="xml/api-index-1.36.xml"><xi:fallback /></xi:include>
+  </index>
+  <index id="api-index-1-38" role="1.38">
+    <title>Index of new symbols in 1.38</title>
+    <xi:include href="xml/api-index-1.38.xml"><xi:fallback /></xi:include>
+  </index>
 
 </book>
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 41db64d..d8ac758 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -92,6 +92,7 @@ pango_matrix_transform_distance
 pango_matrix_transform_rectangle
 pango_matrix_transform_pixel_rectangle
 pango_matrix_get_font_scale_factor
+pango_matrix_get_font_scale_factors
 PangoGlyph
 PANGO_GLYPH_EMPTY
 PANGO_GLYPH_INVALID_INPUT
diff --git a/pango/pango-matrix.c b/pango/pango-matrix.c
index b4c27d7..4ec54d6 100644
--- a/pango/pango-matrix.c
+++ b/pango/pango-matrix.c
@@ -192,7 +192,8 @@ pango_matrix_concat (PangoMatrix       *matrix,
  *
  * Returns the scale factor of a matrix on the height of the font.
  * That is, the scale factor in the direction perpendicular to the
- * vector that the X coordinate is mapped to.
+ * vector that the X coordinate is mapped to.  If the scale in the X
+ * coordinate is needed as well, use pango_matrix_get_font_scale_factors().
  *
  * Return value: the scale factor of @matrix on the height of the font,
  * or 1.0 if @matrix is %NULL.
@@ -202,43 +203,63 @@ pango_matrix_concat (PangoMatrix       *matrix,
 double
 pango_matrix_get_font_scale_factor (const PangoMatrix *matrix)
 {
+  double yscale;
+  pango_matrix_get_font_scale_factors (matrix, NULL, &yscale);
+  return yscale;
+}
+
+/**
+ * pango_matrix_get_font_scale_factors:
+ * @matrix: (nullable): a #PangoMatrix, or %NULL
+ * @xscale: (out) (allow-none): output scale factor in the x direction, or %NULL
+ * @rect: (inout) (allow-none): output scale factor perpendicular to the x direction, or %NULL
+ *
+ * Calculates the scale factor of a matrix on the width and height of the font.
+ * That is, @xscale is the scale factor in the direction of the X coordinate,
+ * and @yscale is the scale factor in the direction perpendicular to the
+ * vector that the X coordinate is mapped to.
+ *
+ * Note that output numbers will always be non-negative.
+ *
+ * Since: 1.38
+ **/
+void
+pango_matrix_get_font_scale_factors (const PangoMatrix *matrix,
+                                    double *xscale, double *yscale)
+{
 /*
  * Based on cairo-matrix.c:_cairo_matrix_compute_scale_factors()
  *
  * Copyright 2005, Keith Packard
  */
-  double det;
+  double major = 1., minor = 1.;
 
-  if (!matrix)
-    return 1.0;
-
-  det = matrix->xx * matrix->yy - matrix->yx * matrix->xy;
-
-  if (det == 0)
-    {
-      return 0.0;
-    }
-  else
+  if (matrix)
     {
       double x = matrix->xx;
       double y = matrix->yx;
-      double major, minor;
-
       major = sqrt (x*x + y*y);
 
-      /*
-       * ignore mirroring
-       */
-      if (det < 0)
-       det = - det;
-
       if (major)
-       minor = det / major;
-      else
-       minor = 0.0;
+       {
+         double det = matrix->xx * matrix->yy - matrix->yx * matrix->xy;
+
+         /*
+          * ignore mirroring
+          */
+         if (det < 0)
+           det = - det;
 
-      return minor;
+         minor = det / major;
+       }
+      else
+        minor = 0.;
     }
+
+  if (xscale)
+    *xscale = major;
+  if (yscale)
+    *yscale = minor;
 }
 
 /**
diff --git a/pango/pango-matrix.h b/pango/pango-matrix.h
index 235c386..85c4b1d 100644
--- a/pango/pango-matrix.h
+++ b/pango/pango-matrix.h
@@ -110,6 +110,8 @@ void pango_matrix_transform_rectangle (const PangoMatrix *matrix,
 void pango_matrix_transform_pixel_rectangle (const PangoMatrix *matrix,
                                             PangoRectangle    *rect);
 double pango_matrix_get_font_scale_factor (const PangoMatrix *matrix) G_GNUC_PURE;
+void pango_matrix_get_font_scale_factors (const PangoMatrix *matrix,
+                                         double *xscale, double *yscale);
 
 
 G_END_DECLS
diff --git a/pango/pango.def b/pango/pango.def
index f34fae2..8c2e975 100644
--- a/pango/pango.def
+++ b/pango/pango.def
@@ -328,6 +328,7 @@ EXPORTS
        pango_matrix_copy
        pango_matrix_free
        pango_matrix_get_font_scale_factor
+       pango_matrix_get_font_scale_factors
        pango_matrix_get_type
        pango_matrix_rotate
        pango_matrix_scale
diff --git a/pango/pangofc-private.h b/pango/pangofc-private.h
index 5c99396..e0ffdc4 100644
--- a/pango/pangofc-private.h
+++ b/pango/pangofc-private.h
@@ -109,48 +109,6 @@ _pango_fc_shape (PangoFont           *font,
                 const char          *paragraph_text,
                 unsigned int         paragraph_length);
 
-/* To be made public at some point */
-
-#include <math.h>
-
-static G_GNUC_UNUSED void
-pango_matrix_get_font_scale_factors (const PangoMatrix *matrix,
-                                    double *xscale, double *yscale)
-{
-/*
- * Based on cairo-matrix.c:_cairo_matrix_compute_scale_factors()
- *
- * Copyright 2005, Keith Packard
- */
-  double major = 0, minor = 0;
-
-  if (matrix) {
-    double det = matrix->xx * matrix->yy - matrix->yx * matrix->xy;
-
-    if (det)
-      {
-       double x = matrix->xx;
-       double y = matrix->yx;
-
-       major = sqrt (x*x + y*y);
-
-       /*
-        * ignore mirroring
-        */
-       if (det < 0)
-         det = - det;
-
-       if (major)
-         minor = det / major;
-      }
-  }
-
-  if (xscale)
-    *xscale = major;
-  if (yscale)
-    *yscale = minor;
-}
-
 G_END_DECLS
 
 #endif /* __PANGOFC_PRIVATE_H__ */


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