[pango/round-glyphs-option: 2/4] context: Add an option for rounding glyph positions



commit b1f44c8f8f70e760ff519e95d611d9f366d2105f
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 3 15:59:58 2019 -0400

    context: Add an option for rounding glyph positions
    
    This is a global option, similar in spirit to
    font options, so it makes sense to keep it in
    PangoContext.
    
    Default to rounding glyph positions, which preserves
    the pre-1.44 behavior and should help cure all
    the 'broken' font rendering with older cairo
    versions.

 docs/pango-sections.txt |  2 ++
 pango/pango-context.c   | 43 +++++++++++++++++++++++++++++++++++++++++++
 pango/pango-context.h   |  7 +++++++
 3 files changed, 52 insertions(+)
---
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 2855c247..7a95d401 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -62,6 +62,8 @@ pango_context_get_gravity_hint
 pango_context_set_gravity_hint
 pango_context_get_matrix
 pango_context_set_matrix
+pango_context_get_round_glyph_positions
+pango_context_set_round_glyph_positions
 pango_context_load_font
 pango_context_load_fontset
 pango_context_get_metrics
diff --git a/pango/pango-context.c b/pango/pango-context.c
index 6ba64ce1..b7d85ef1 100644
--- a/pango/pango-context.c
+++ b/pango/pango-context.c
@@ -79,6 +79,8 @@ struct _PangoContext
   PangoMatrix *matrix;
 
   PangoFontMap *font_map;
+
+  gboolean round_glyph_positions;
 };
 
 struct _PangoContextClass
@@ -103,6 +105,7 @@ pango_context_init (PangoContext *context)
   context->set_language = NULL;
   context->language = pango_language_get_default ();
   context->font_map = NULL;
+  context->round_glyph_positions = TRUE;
 
   context->font_desc = pango_font_description_new ();
   pango_font_description_set_family_static (context->font_desc, "serif");
@@ -1857,3 +1860,43 @@ pango_context_get_serial (PangoContext *context)
   check_fontmap_changed (context);
   return context->serial;
 }
+
+/**
+ * pango_context_set_round_glyph_positions:
+ * @context: a #PangoContext
+ * @round_positions: whether to round glyph positions
+ *
+ * Sets whether font rendering with this context should
+ * round glyph positions and widths to integral positions,
+ * in device units.
+ *
+ * This is useful when the renderer can't handle subpixel
+ * positioning of glyphs.
+ *
+ * Since: 1.44
+ */
+void
+pango_context_set_round_glyph_positions (PangoContext *context,
+                                         gboolean      round_positions)
+{
+  if (context->round_glyph_positions != round_positions)
+    {
+      context->round_glyph_positions = round_positions;
+      context_changed (context);
+    }
+}
+
+/**
+ * pango_context_get_round_glyph_positions:
+ * @context: a #PangoContext
+ *
+ * Returns whether font rendering with this context should
+ * round glyph positions and widths.
+ *
+ * Since: 1.44
+ */
+gboolean
+pango_context_get_round_glyph_positions (PangoContext *context)
+{
+  return context->round_glyph_positions;
+}
diff --git a/pango/pango-context.h b/pango/pango-context.h
index af934491..0f775ff4 100644
--- a/pango/pango-context.h
+++ b/pango/pango-context.h
@@ -113,6 +113,13 @@ void                      pango_context_set_matrix           (PangoContext
 PANGO_AVAILABLE_IN_1_6
 const PangoMatrix *       pango_context_get_matrix           (PangoContext      *context);
 
+PANGO_AVAILABLE_IN_1_44
+void                      pango_context_set_round_glyph_positions (PangoContext *context,
+                                                                   gboolean      round_positions);
+PANGO_AVAILABLE_IN_1_44
+gboolean                  pango_context_get_round_glyph_positions (PangoContext *context);
+
+
 /* Break a string of Unicode characters into segments with
  * consistent shaping/language engine and bidrectional level.
  * Returns a #GList of #PangoItem's


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