[pango/round-glyphs-option: 1/4] Add a pango_shape variant that takes flags



commit 8600b782dc93f933a3507263c1c0dd945b3c09d0
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 3 15:31:40 2019 -0400

    Add a pango_shape variant that takes flags
    
    The only flag currently defined affects whether
    glyph positions are rounded or not.

 docs/pango-sections.txt |  1 +
 pango/pango-glyph.h     | 45 ++++++++++++++++++------
 pango/shape.c           | 93 +++++++++++++++++++++++++++++++++++++------------
 3 files changed, 107 insertions(+), 32 deletions(-)
---
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 78a6b4cb..3c937eec 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -30,6 +30,7 @@ PangoLogAttr
 <SUBSECTION>
 pango_shape
 pango_shape_full
+pango_shape_with_flags
 
 <SUBSECTION Standard>
 PANGO_TYPE_ITEM
diff --git a/pango/pango-glyph.h b/pango/pango-glyph.h
index 917ec570..628eac96 100644
--- a/pango/pango-glyph.h
+++ b/pango/pango-glyph.h
@@ -189,18 +189,43 @@ void pango_glyph_string_x_to_index (PangoGlyphString *glyphs,
 /* Turn a string of characters into a string of glyphs
  */
 PANGO_AVAILABLE_IN_ALL
-void pango_shape (const gchar      *text,
-                 gint              length,
-                 const PangoAnalysis *analysis,
-                 PangoGlyphString *glyphs);
+void pango_shape (const char          *text,
+                  int                  length,
+                  const PangoAnalysis *analysis,
+                  PangoGlyphString    *glyphs);
 
 PANGO_AVAILABLE_IN_1_32
-void pango_shape_full (const gchar      *item_text,
-                      gint              item_length,
-                      const gchar      *paragraph_text,
-                      gint              paragraph_length,
-                      const PangoAnalysis *analysis,
-                      PangoGlyphString *glyphs);
+void pango_shape_full (const char          *item_text,
+                       int                  item_length,
+                       const char          *paragraph_text,
+                       int                  paragraph_length,
+                       const PangoAnalysis *analysis,
+                       PangoGlyphString    *glyphs);
+
+/**
+ * PangoShapeFlags:
+ * @PANGO_SHAPE_NONE: Default value.
+ * @PANGO_SHAPE_ROUND_POSITIONS: Round glyph positions
+ *     and widths to whole device units. This option should
+ *     be set if the target renderer can't do subpixel
+ *     positioning of glyphs.
+ *
+ * Flags influencing the shaping process.
+ * These can be passed to pango_shape_with_flags().
+ */
+typedef enum {
+  PANGO_SHAPE_NONE            = 0,
+  PANGO_SHAPE_ROUND_POSITIONS = 1 << 0,
+} PangoShapeFlags;
+
+PANGO_AVAILABLE_IN_1_44
+void pango_shape_with_flags (const char          *item_text,
+                             int                  item_length,
+                             const char          *paragraph_text,
+                             int                  paragraph_length,
+                             const PangoAnalysis *analysis,
+                             PangoGlyphString    *glyphs,
+                             PangoShapeFlags      flags);
 
 PANGO_AVAILABLE_IN_ALL
 GList *pango_reorder_items (GList *logical_items);
diff --git a/pango/shape.c b/pango/shape.c
index cb969e67..efdb3177 100644
--- a/pango/shape.c
+++ b/pango/shape.c
@@ -55,14 +55,51 @@
  * boundaries.
  */
 void
-pango_shape (const gchar      *text,
-            gint              length,
+pango_shape (const gchar         *text,
+            gint                 length,
             const PangoAnalysis *analysis,
-            PangoGlyphString *glyphs)
+            PangoGlyphString    *glyphs)
 {
   pango_shape_full (text, length, text, length, analysis, glyphs);
 }
 
+/**
+ * pango_shape_full:
+ * @item_text:        valid UTF-8 text to shape.
+ * @item_length:      the length (in bytes) of @item_text. -1 means nul-terminated text.
+ * @paragraph_text: (allow-none): text of the paragraph (see details).  May be %NULL.
+ * @paragraph_length: the length (in bytes) of @paragraph_text. -1 means nul-terminated text.
+ * @analysis:  #PangoAnalysis structure from pango_itemize().
+ * @glyphs:    glyph string in which to store results.
+ *
+ * Given a segment of text and the corresponding
+ * #PangoAnalysis structure returned from pango_itemize(),
+ * convert the characters into glyphs. You may also pass
+ * in only a substring of the item from pango_itemize().
+ *
+ * This is similar to pango_shape(), except it also can optionally take
+ * the full paragraph text as input, which will then be used to perform
+ * certain cross-item shaping interactions.  If you have access to the broader
+ * text of which @item_text is part of, provide the broader text as
+ * @paragraph_text.  If @paragraph_text is %NULL, item text is used instead.
+ *
+ * Since: 1.32
+ */
+void
+pango_shape_full (const char          *item_text,
+                  int                  item_length,
+                  const char          *paragraph_text,
+                  int                  paragraph_length,
+                  const PangoAnalysis *analysis,
+                  PangoGlyphString    *glyphs)
+{
+  pango_shape_with_flags (item_text, item_length,
+                          paragraph_text, paragraph_length,
+                          analysis,
+                          glyphs,
+                          PANGO_SHAPE_NONE);
+}
+
 static void
 fallback_shape (const char          *text,
                 unsigned int         length,
@@ -113,34 +150,36 @@ fallback_shape (const char          *text,
 }
 
 /**
- * pango_shape_full:
- * @item_text:        valid UTF-8 text to shape.
- * @item_length:      the length (in bytes) of @item_text. -1 means nul-terminated text.
- * @paragraph_text: (allow-none): text of the paragraph (see details).  May be %NULL.
- * @paragraph_length: the length (in bytes) of @paragraph_text. -1 means nul-terminated text.
- * @analysis:  #PangoAnalysis structure from pango_itemize().
- * @glyphs:    glyph string in which to store results.
+ * pango_shape_with_flags:
+ * @item_text: valid UTF-8 text to shape
+ * @item_length: the length (in bytes) of @item_text.
+ *     -1 means nul-terminated text.
+ * @paragraph_text: (allow-none): text of the paragraph (see details).
+ *     May be %NULL.
+ * @paragraph_length: the length (in bytes) of @paragraph_text.
+ *     -1 means nul-terminated text.
+ * @analysis:  #PangoAnalysis structure from pango_itemize()
+ * @glyphs: glyph string in which to store results
+ * @flags: flags influencing the shaping process
  *
  * Given a segment of text and the corresponding
  * #PangoAnalysis structure returned from pango_itemize(),
  * convert the characters into glyphs. You may also pass
  * in only a substring of the item from pango_itemize().
  *
- * This is similar to pango_shape(), except it also can optionally take
- * the full paragraph text as input, which will then be used to perform
- * certain cross-item shaping interactions.  If you have access to the broader
- * text of which @item_text is part of, provide the broader text as
- * @paragraph_text.  If @paragraph_text is %NULL, item text is used instead.
+ * This is similar to pango_shape_full(), except it also takes
+ * flags that can influence the shaping process.
  *
- * Since: 1.32
+ * Since: 1.44
  */
 void
-pango_shape_full (const gchar      *item_text,
-                 gint              item_length,
-                 const gchar      *paragraph_text,
-                 gint              paragraph_length,
-                 const PangoAnalysis *analysis,
-                 PangoGlyphString *glyphs)
+pango_shape_with_flags (const gchar         *item_text,
+                        gint                 item_length,
+                        const gchar         *paragraph_text,
+                        gint                 paragraph_length,
+                        const PangoAnalysis *analysis,
+                        PangoGlyphString    *glyphs,
+                        PangoShapeFlags      flags)
 {
   int i;
   int last_cluster;
@@ -243,4 +282,14 @@ pango_shape_full (const gchar      *item_text,
       /* *Fix* it so we don't crash later */
       pango_glyph_string_reverse_range (glyphs, 0, glyphs->num_glyphs);
     }
+
+  if (flags & PANGO_SHAPE_ROUND_POSITIONS)
+    {
+      for (i = 0; i < glyphs->num_glyphs; i++)
+        {
+          glyphs->glyphs[i].geometry.width    = PANGO_UNITS_ROUND (glyphs->glyphs[i].geometry.width );
+          glyphs->glyphs[i].geometry.x_offset = PANGO_UNITS_ROUND (glyphs->glyphs[i].geometry.x_offset);
+          glyphs->glyphs[i].geometry.y_offset = PANGO_UNITS_ROUND (glyphs->glyphs[i].geometry.y_offset);
+        }
+    }
 }


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