[pango/pango2: 11/14] Drop pango_cairo_create_layout




commit ad353ef55efd5033c6335a5cf7136597371e7b96
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jun 8 21:54:57 2022 -0400

    Drop pango_cairo_create_layout
    
    It is inefficient, as the docs say.

 examples/cairosimple.c          |  5 ++-
 examples/cairotwisted.c         |  5 ++-
 pango/meson.build               |  2 +
 pango/pangocairo-context.c      | 98 ++++-------------------------------------
 pango/pangocairo-context.h      | 42 ++++++++++++++++++
 pango/pangocairo-render.h       | 74 +++++++++++++++++++++++++++++++
 pango/pangocairo.h              | 89 +------------------------------------
 tests/test-pangocairo-threads.c |  5 ++-
 8 files changed, 141 insertions(+), 179 deletions(-)
---
diff --git a/examples/cairosimple.c b/examples/cairosimple.c
index 6235a02a..239e0e39 100644
--- a/examples/cairosimple.c
+++ b/examples/cairosimple.c
@@ -17,6 +17,7 @@ draw_text (cairo_t *cr)
  */
 #define TWEAKABLE_SCALE ((double) 0.1)
 
+  PangoContext *context;
   PangoLayout *layout;
   PangoLines *lines;
   PangoFontDescription *desc;
@@ -27,7 +28,9 @@ draw_text (cairo_t *cr)
   cairo_translate (cr, RADIUS / TWEAKABLE_SCALE, RADIUS / TWEAKABLE_SCALE);
 
   /* Create a PangoLayout, set the font and text */
-  layout = pango_cairo_create_layout (cr);
+  context = pango_cairo_create_context (cr);
+  layout = pango_layout_new (context);
+  g_object_unref (context);
 
   pango_layout_set_text (layout, "Test\nسَلام", -1);
 
diff --git a/examples/cairotwisted.c b/examples/cairotwisted.c
index ff7952d4..631289b1 100644
--- a/examples/cairotwisted.c
+++ b/examples/cairotwisted.c
@@ -471,6 +471,7 @@ draw_text (cairo_t *cr,
            const char *font,
            const char *text)
 {
+  PangoContext *context;
   PangoLayout *layout;
   PangoLine *line;
   PangoFontDescription *desc;
@@ -484,7 +485,9 @@ draw_text (cairo_t *cr,
   cairo_set_font_options (cr, font_options);
   cairo_font_options_destroy (font_options);
 
-  layout = pango_cairo_create_layout (cr);
+  context = pango_cairo_create_context (cr);
+  layout = pango_layout_new (context);
+  g_object_unref (context);
 
   desc = pango_font_description_from_string (font);
   pango_layout_set_font_description (layout, desc);
diff --git a/pango/meson.build b/pango/meson.build
index 68294d64..6aa4d133 100644
--- a/pango/meson.build
+++ b/pango/meson.build
@@ -102,6 +102,8 @@ pango_gir_includes = [
 if cairo_dep.found()
   pango_headers += [
     'pangocairo.h',
+    'pangocairo-context.h',
+    'pangocairo-render.h',
   ]
 
   pango_sources += [
diff --git a/pango/pangocairo-context.c b/pango/pangocairo-context.c
index 21dce46d..e9a3a908 100644
--- a/pango/pangocairo-context.c
+++ b/pango/pangocairo-context.c
@@ -10,7 +10,7 @@
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
@@ -31,7 +31,6 @@ typedef struct _PangoCairoContextInfo PangoCairoContextInfo;
 
 struct _PangoCairoContextInfo
 {
-  double dpi;
   gboolean set_options_explicit;
 
   cairo_font_options_t *set_options;
@@ -54,7 +53,7 @@ free_context_info (PangoCairoContextInfo *info)
 
 static PangoCairoContextInfo *
 get_context_info (PangoContext *context,
-                 gboolean      create)
+                  gboolean      create)
 {
   static GQuark context_info_quark; /* MT-safe */
   PangoCairoContextInfo *info;
@@ -68,7 +67,6 @@ retry:
   if (G_UNLIKELY (!info) && create)
     {
       info = g_slice_new0 (PangoCairoContextInfo);
-      info->dpi = -1.0;
 
       if (!g_object_replace_qdata (G_OBJECT (context), context_info_quark, NULL,
                                    info, (GDestroyNotify)free_context_info,
@@ -84,7 +82,7 @@ retry:
 
 static void
 _pango_cairo_update_context (cairo_t      *cr,
-                            PangoContext *context)
+                             PangoContext *context)
 {
   PangoCairoContextInfo *info;
   cairo_matrix_t cairo_matrix;
@@ -117,7 +115,7 @@ _pango_cairo_update_context (cairo_t      *cr,
   if (old_merged_options)
     {
       if (!cairo_font_options_equal (merged_options, old_merged_options))
-       changed = TRUE;
+        changed = TRUE;
       cairo_font_options_destroy (old_merged_options);
       old_merged_options = NULL;
     }
@@ -162,7 +160,7 @@ _pango_cairo_update_context (cairo_t      *cr,
  */
 void
 pango_cairo_update_context (cairo_t      *cr,
-                           PangoContext *context)
+                            PangoContext *context)
 {
   g_return_if_fail (cr != NULL);
   g_return_if_fail (PANGO_IS_CONTEXT (context));
@@ -170,49 +168,6 @@ pango_cairo_update_context (cairo_t      *cr,
   _pango_cairo_update_context (cr, context);
 }
 
-/**
- * pango_cairo_context_set_resolution:
- * @context: a `PangoContext`, from a pangocairo font map
- * @dpi: the resolution in "dots per inch". (Physical inches aren't actually
- *   involved; the terminology is conventional.) A 0 or negative value
- *   means to use the resolution from the font map.
- *
- * Sets the resolution for the context.
- *
- * This is a scale factor between points specified in a `PangoFontDescription`
- * and Cairo units. The default value is 96, meaning that a 10 point font will
- * be 13 units high. (10 * 96. / 72. = 13.3).
- */
-void
-pango_cairo_context_set_resolution (PangoContext *context,
-                                   double        dpi)
-{
-  PangoCairoContextInfo *info = get_context_info (context, TRUE);
-  info->dpi = dpi;
-}
-
-/**
- * pango_cairo_context_get_resolution:
- * @context: a `PangoContext`, from a pangocairo font map
- *
- * Gets the resolution for the context.
- *
- * See [func@PangoCairo.context_set_resolution]
- *
- * Return value: the resolution in "dots per inch". A negative value will
- *   be returned if no resolution has previously been set.
- */
-double
-pango_cairo_context_get_resolution (PangoContext *context)
-{
-  PangoCairoContextInfo *info = get_context_info (context, FALSE);
-
-  if (info)
-    return info->dpi;
-  else
-    return -1.0;
-}
-
 /**
  * pango_cairo_context_set_font_options:
  * @context: a `PangoContext`, from a pangocairo font map
@@ -226,7 +181,7 @@ pango_cairo_context_get_resolution (PangoContext *context)
  */
 void
 pango_cairo_context_set_font_options (PangoContext               *context,
-                                     const cairo_font_options_t *options)
+                                      const cairo_font_options_t *options)
 {
   PangoCairoContextInfo *info;
 
@@ -237,8 +192,7 @@ pango_cairo_context_set_font_options (PangoContext               *context,
   if (!info->set_options && !options)
     return;
 
-  if (info->set_options &&
-      options &&
+  if (info->set_options && options &&
       cairo_font_options_equal (info->set_options, options))
     return;
 
@@ -316,9 +270,9 @@ _pango_cairo_context_get_merged_font_options (PangoContext *context)
       info->merged_options = cairo_font_options_create ();
 
       if (info->surface_options)
-       cairo_font_options_merge (info->merged_options, info->surface_options);
+        cairo_font_options_merge (info->merged_options, info->surface_options);
       if (info->set_options)
-       cairo_font_options_merge (info->merged_options, info->set_options);
+        cairo_font_options_merge (info->merged_options, info->set_options);
     }
 
   return info->merged_options;
@@ -356,40 +310,6 @@ pango_cairo_create_context (cairo_t *cr)
   return context;
 }
 
-/**
- * pango_cairo_create_layout:
- * @cr: a Cairo context
- *
- * Creates a layout object set up to match the current transformation
- * and target surface of the Cairo context.
- *
- * This layout can then be used for text measurement with functions
- * like [method@Pango.Lines.get_size] or drawing with functions like
- * [func@show_layout]. If you change the transformation or target
- * surface for @cr, you need to call [func@update_layout].
- *
- * This function is the most convenient way to use Cairo with Pango,
- * however it is slightly inefficient since it creates a separate
- * `PangoContext` object for each layout. This might matter in an
- * application that was laying out large amounts of text.
- *
- * Return value: (transfer full): the newly created `PangoLayout`
- */
-PangoLayout *
-pango_cairo_create_layout (cairo_t *cr)
-{
-  PangoContext *context;
-  PangoLayout *layout;
-
-  g_return_val_if_fail (cr != NULL, NULL);
-
-  context = pango_cairo_create_context (cr);
-  layout = pango_layout_new (context);
-  g_object_unref (context);
-
-  return layout;
-}
-
 /**
  * pango_cairo_update_layout:
  * @cr: a Cairo context
diff --git a/pango/pangocairo-context.h b/pango/pangocairo-context.h
new file mode 100644
index 00000000..0840727a
--- /dev/null
+++ b/pango/pangocairo-context.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 1999, 2004 Red Hat, Inc.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <pango/pango.h>
+#include <cairo.h>
+
+G_BEGIN_DECLS
+
+PANGO_AVAILABLE_IN_ALL
+PangoContext *          pango_cairo_create_context              (cairo_t                        *cr);
+PANGO_AVAILABLE_IN_ALL
+void                    pango_cairo_update_context              (cairo_t                        *cr,
+                                                                 PangoContext                   *context);
+PANGO_AVAILABLE_IN_ALL
+void                    pango_cairo_update_layout               (cairo_t                        *cr,
+                                                                 PangoLayout                    *layout);
+PANGO_AVAILABLE_IN_ALL
+void                    pango_cairo_context_set_font_options    (PangoContext                   *context,
+                                                                 const cairo_font_options_t     *options);
+PANGO_AVAILABLE_IN_ALL
+const cairo_font_options_t *
+                        pango_cairo_context_get_font_options    (PangoContext                   *context);
+
+G_END_DECLS
diff --git a/pango/pangocairo-render.h b/pango/pangocairo-render.h
new file mode 100644
index 00000000..aadb831e
--- /dev/null
+++ b/pango/pangocairo-render.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 1999, 2004 Red Hat, Inc.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <pango/pango.h>
+#include <cairo.h>
+
+G_BEGIN_DECLS
+
+PANGO_AVAILABLE_IN_ALL
+void    pango_cairo_show_glyph_string           (cairo_t          *cr,
+                                                 PangoFont        *font,
+                                                 PangoGlyphString *glyphs);
+
+PANGO_AVAILABLE_IN_ALL
+void    pango_cairo_show_glyph_item             (cairo_t          *cr,
+                                                 const char       *text,
+                                                 PangoGlyphItem   *glyph_item);
+PANGO_AVAILABLE_IN_ALL
+void     pango_cairo_show_line                  (cairo_t          *cr,
+                                                 PangoLine        *line);
+PANGO_AVAILABLE_IN_ALL
+void    pango_cairo_show_lines                  (cairo_t          *cr,
+                                                 PangoLines       *lines);
+PANGO_AVAILABLE_IN_ALL
+void    pango_cairo_show_layout                 (cairo_t          *cr,
+                                                 PangoLayout      *layout);
+
+PANGO_AVAILABLE_IN_ALL
+void    pango_cairo_show_error_underline        (cairo_t          *cr,
+                                                 double            x,
+                                                 double            y,
+                                                 double            width,
+                                                 double            height);
+
+PANGO_AVAILABLE_IN_ALL
+void    pango_cairo_glyph_string_path           (cairo_t          *cr,
+                                                 PangoFont        *font,
+                                                 PangoGlyphString *glyphs);
+PANGO_AVAILABLE_IN_ALL
+void    pango_cairo_layout_path                 (cairo_t          *cr,
+                                                 PangoLayout      *layout);
+PANGO_AVAILABLE_IN_ALL
+void    pango_cairo_line_path                   (cairo_t          *cr,
+                                                 PangoLine        *line);
+PANGO_AVAILABLE_IN_ALL
+void    pango_cairo_lines_path                  (cairo_t          *cr,
+                                                 PangoLines       *lines);
+
+PANGO_AVAILABLE_IN_ALL
+void    pango_cairo_error_underline_path        (cairo_t          *cr,
+                                                 double            x,
+                                                 double            y,
+                                                 double            width,
+                                                 double            height);
+
+G_END_DECLS
diff --git a/pango/pangocairo.h b/pango/pangocairo.h
index 51a5f5ea..a2658f82 100644
--- a/pango/pangocairo.h
+++ b/pango/pangocairo.h
@@ -19,90 +19,5 @@
 
 #pragma once
 
-#include <pango/pango.h>
-#include <cairo.h>
-
-G_BEGIN_DECLS
-
-/* Update a Pango context for the current state of a cairo context
- */
-PANGO_AVAILABLE_IN_ALL
-void         pango_cairo_update_context (cairo_t      *cr,
-                                         PangoContext *context);
-
-PANGO_AVAILABLE_IN_ALL
-void                        pango_cairo_context_set_font_options (PangoContext               *context,
-                                                                  const cairo_font_options_t *options);
-PANGO_AVAILABLE_IN_ALL
-const cairo_font_options_t *pango_cairo_context_get_font_options (PangoContext               *context);
-
-PANGO_AVAILABLE_IN_ALL
-void               pango_cairo_context_set_resolution     (PangoContext       *context,
-                                                           double              dpi);
-PANGO_AVAILABLE_IN_ALL
-double             pango_cairo_context_get_resolution     (PangoContext       *context);
-
-/* Convenience
- */
-PANGO_AVAILABLE_IN_ALL
-PangoContext *pango_cairo_create_context (cairo_t   *cr);
-PANGO_AVAILABLE_IN_ALL
-PangoLayout *pango_cairo_create_layout (cairo_t     *cr);
-PANGO_AVAILABLE_IN_ALL
-void         pango_cairo_update_layout (cairo_t     *cr,
-                                        PangoLayout *layout);
-
-/*
- * Rendering
- */
-PANGO_AVAILABLE_IN_ALL
-void pango_cairo_show_glyph_string (cairo_t          *cr,
-                                    PangoFont        *font,
-                                    PangoGlyphString *glyphs);
-PANGO_AVAILABLE_IN_ALL
-void pango_cairo_show_glyph_item   (cairo_t          *cr,
-                                    const char       *text,
-                                    PangoGlyphItem   *glyph_item);
-PANGO_AVAILABLE_IN_ALL
-void pango_cairo_show_line         (cairo_t          *cr,
-                                    PangoLine        *line);
-PANGO_AVAILABLE_IN_ALL
-void pango_cairo_show_lines        (cairo_t          *cr,
-                                    PangoLines       *lines);
-PANGO_AVAILABLE_IN_ALL
-void pango_cairo_show_layout       (cairo_t          *cr,
-                                    PangoLayout      *layout);
-
-PANGO_AVAILABLE_IN_ALL
-void pango_cairo_show_error_underline (cairo_t       *cr,
-                                       double         x,
-                                       double         y,
-                                       double         width,
-                                       double         height);
-
-
-/*
- * Rendering to a path
- */
-PANGO_AVAILABLE_IN_ALL
-void pango_cairo_glyph_string_path (cairo_t          *cr,
-                                    PangoFont        *font,
-                                    PangoGlyphString *glyphs);
-PANGO_AVAILABLE_IN_ALL
-void pango_cairo_layout_path       (cairo_t          *cr,
-                                    PangoLayout      *layout);
-PANGO_AVAILABLE_IN_ALL
-void pango_cairo_line_path         (cairo_t          *cr,
-                                    PangoLine        *line);
-PANGO_AVAILABLE_IN_ALL
-void pango_cairo_lines_path        (cairo_t          *cr,
-                                    PangoLines       *lines);
-
-PANGO_AVAILABLE_IN_ALL
-void pango_cairo_error_underline_path (cairo_t       *cr,
-                                       double         x,
-                                       double         y,
-                                       double         width,
-                                       double         height);
-
-G_END_DECLS
+#include <pango/pangocairo-context.h>
+#include <pango/pangocairo-render.h>
diff --git a/tests/test-pangocairo-threads.c b/tests/test-pangocairo-threads.c
index aa1e1bca..429e3011 100644
--- a/tests/test-pangocairo-threads.c
+++ b/tests/test-pangocairo-threads.c
@@ -21,9 +21,12 @@ create_surface (void)
 static PangoLayout *
 create_layout (cairo_t *cr)
 {
+  PangoContext *context;
   PangoLayout *layout;
 
-  layout = pango_cairo_create_layout (cr);
+  context = pango_cairo_create_context (cr);
+  layout = pango_layout_new (context);
+  g_object_unref (context);
   pango_layout_set_text (layout, text, -1);
   pango_layout_set_width (layout, WIDTH * PANGO_SCALE);
 


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