summaryrefslogtreecommitdiff
path: root/pango/pango-gravity.c
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2009-07-22 16:24:43 -0400
committerBehdad Esfahbod <behdad@behdad.org>2009-07-22 16:24:43 -0400
commitac2ce962e9c257657eeceaf08d6aeeddd6faaa83 (patch)
tree16daaf469efe888429edd462499cb46ea4d7838c /pango/pango-gravity.c
parent0df5c40d43a8d87a917991780595d9fadd19afb6 (diff)
downloadpango-ac2ce962e9c257657eeceaf08d6aeeddd6faaa83.tar.gz
Bug 410169 – gravity problem with Common chars
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()
Diffstat (limited to 'pango/pango-gravity.c')
-rw-r--r--pango/pango-gravity.c58
1 files changed, 52 insertions, 6 deletions
diff --git a/pango/pango-gravity.c b/pango/pango-gravity.c
index b58ae85d..297199a5 100644
--- a/pango/pango-gravity.c
+++ b/pango/pango-gravity.c
@@ -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)