Bug 410169 – gravity problem with Common chars
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 22 Jul 2009 20:24:43 +0000 (16:24 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 22 Jul 2009 20:24:43 +0000 (16:24 -0400)
Only show wide chars (as in g_unichar_iswide()) upright.
This improves rendering of 1) digits in CJK context, and 2) Narrow
Hangul characters.

New public API:

pango_gravity_get_for_script_and_width()

docs/pango-sections.txt
docs/tmpl/vertical.sgml
pango/pango-context.c
pango/pango-gravity.c
pango/pango-gravity.h
pango/pango.def

index 0fbdc22..50abd19 100644 (file)
@@ -1104,6 +1104,7 @@ PangoGravityHint
 PANGO_GRAVITY_IS_VERTICAL
 pango_gravity_get_for_matrix
 pango_gravity_get_for_script
+pango_gravity_get_for_script_and_width
 pango_gravity_to_rotation
 <SUBSECTION Standard>
 PANGO_TYPE_GRAVITY
index 5a75d99..83e33a1 100644 (file)
@@ -121,6 +121,18 @@ pango_attr_gravity_hint_new()
 @Returns: 
 
 
+<!-- ##### FUNCTION pango_gravity_get_for_script_and_width ##### -->
+<para>
+
+</para>
+
+@script: 
+@wide: 
+@base_gravity: 
+@hint: 
+@Returns: 
+
+
 <!-- ##### FUNCTION pango_gravity_to_rotation ##### -->
 <para>
 
index 4057968..6ec0b56 100644 (file)
@@ -1293,15 +1293,11 @@ itemize_state_update_for_new_run (ItemizeState *state)
     {
       PangoGravity old_gravity = state->resolved_gravity;
 
+      /* Font-desc gravity overrides everything */
       if (state->font_desc_gravity != PANGO_GRAVITY_AUTO)
        {
          state->resolved_gravity = state->font_desc_gravity;
        }
-      else if (state->width_iter.wide)
-        {
-         /* Wide characters are always upright */
-          state->resolved_gravity = state->context->resolved_gravity;
-        }
       else
        {
          PangoGravity gravity = state->gravity;
@@ -1310,9 +1306,10 @@ itemize_state_update_for_new_run (ItemizeState *state)
          if (G_LIKELY (gravity == PANGO_GRAVITY_AUTO))
            gravity = state->context->resolved_gravity;
 
-         state->resolved_gravity = pango_gravity_get_for_script (state->script,
-                                                                 gravity,
-                                                                 gravity_hint);
+         state->resolved_gravity = pango_gravity_get_for_script_and_width (state->script,
+                                                                           state->width_iter.wide,
+                                                                           gravity,
+                                                                           gravity_hint);
        }
 
       if (old_gravity != state->resolved_gravity)
index b58ae85..297199a 100644 (file)
@@ -113,8 +113,9 @@ typedef struct {
   guint8 preferred_gravity;    /* Preferred context gravity */
 
   /* gboolean */
-  guint8 upright;              /* Whether glyphs are upright or
-                                * rotated in foreign context */
+  guint8 wide;                 /* Whether script is mostly wide.
+                                * Wide characters are upright (ie.
+                                * not rotated) in foreign context */
 } PangoScriptProperties;
 
 #define NONE PANGO_VERTICAL_DIRECTION_NONE
@@ -245,6 +246,7 @@ get_script_properties (PangoScript script)
  * pass %PANGO_GRAVITY_AUTO and %PANGO_GRAVITY_HINT_STRONG in.
  *
  * Return value: resolved gravity suitable to use for a run of text
+ * with @script.
  *
  * Since: 1.16
  */
@@ -262,17 +264,61 @@ pango_gravity_get_for_script (PangoScript      script,
 
   vertical = PANGO_GRAVITY_IS_VERTICAL (base_gravity);
 
+  return pango_gravity_get_for_script_and_width (script, props.wide,
+                                                base_gravity, hint);
+}
+
+/**
+ * pango_gravity_get_for_script_and_width:
+ * @script: #PangoScript to query
+ * @wide: %TRUE for wide characters as returned by g_unichar_iswide()
+ * @base_gravity: base gravity of the paragraph
+ * @hint: orientation hint
+ *
+ * Based on the script, East Asian width, base gravity, and hint,
+ * returns actual gravity to use in laying out a single character
+ * or #PangoItem.
+ *
+ * This function is similar to pango_gravity_get_for_script() except
+ * that this function makes a distinction between narrow/half-width and
+ * wide/full-width characters also.  Wide/full-width characters always
+ * stand <emph>upright</emph>, that is, they always take the base gravity,
+ * whereas narrow/full-width characters are always rotated in vertical
+ * context.
+ *
+ * If @base_gravity is %PANGO_GRAVITY_AUTO, it is first replaced with the
+ * preferred gravity of @script.
+ *
+ * Return value: resolved gravity suitable to use for a run of text
+ * with @script and @wide.
+ *
+ * Since: 1.26
+ */
+PangoGravity
+pango_gravity_get_for_script_and_width (PangoScript        script,
+                                       gboolean           wide,
+                                       PangoGravity       base_gravity,
+                                       PangoGravityHint   hint)
+{
+  PangoScriptProperties props = get_script_properties (script);
+  gboolean vertical;
+
+
+  if (G_UNLIKELY (base_gravity == PANGO_GRAVITY_AUTO))
+    base_gravity = props.preferred_gravity;
+
+  vertical = PANGO_GRAVITY_IS_VERTICAL (base_gravity);
+
   /* Everything is designed such that a system with no vertical support
    * renders everything correctly horizontally.  So, if not in a vertical
    * gravity, base and resolved gravities are always the same.
    *
-   * If the script should be upright all the time, like Chinese and Japenese,
-   * any base gravity should resolve to itself.
+   * Wide characters are always upright.
    */
-  if (G_LIKELY (!vertical || props.upright))
+  if (G_LIKELY (!vertical || wide))
     return base_gravity;
 
-  /* If here, we have a non-upright script in a vertical gravity setting.
+  /* If here, we have a narrow character in a vertical gravity setting.
    * Resolve depending on the hint.
    */
   switch (hint)
index 2e42ebd..d2fa964 100644 (file)
@@ -102,6 +102,11 @@ PangoGravity pango_gravity_get_for_matrix (const PangoMatrix *matrix) G_GNUC_PUR
 PangoGravity pango_gravity_get_for_script (PangoScript        script,
                                           PangoGravity       base_gravity,
                                           PangoGravityHint   hint) G_GNUC_CONST;
+PangoGravity pango_gravity_get_for_script_and_width
+                                         (PangoScript        script,
+                                          gboolean           wide,
+                                          PangoGravity       base_gravity,
+                                          PangoGravityHint   hint) G_GNUC_CONST;
 
 
 G_END_DECLS
index 39ab42b..d941ebe 100644 (file)
@@ -205,6 +205,7 @@ EXPORTS
        pango_glyph_string_x_to_index
        pango_gravity_get_for_matrix
        pango_gravity_get_for_script
+       pango_gravity_get_for_script_and_width
        pango_gravity_get_type
        pango_gravity_hint_get_type
        pango_gravity_to_rotation