summaryrefslogtreecommitdiff
path: root/pango
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
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')
-rw-r--r--pango/pango-context.c13
-rw-r--r--pango/pango-gravity.c58
-rw-r--r--pango/pango-gravity.h5
-rw-r--r--pango/pango.def1
4 files changed, 63 insertions, 14 deletions
diff --git a/pango/pango-context.c b/pango/pango-context.c
index 40579686..6ec0b56f 100644
--- a/pango/pango-context.c
+++ b/pango/pango-context.c
@@ -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)
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)
diff --git a/pango/pango-gravity.h b/pango/pango-gravity.h
index 2e42ebd8..d2fa9647 100644
--- a/pango/pango-gravity.h
+++ b/pango/pango-gravity.h
@@ -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
diff --git a/pango/pango.def b/pango/pango.def
index 39ab42bc..d941ebe8 100644
--- a/pango/pango.def
+++ b/pango/pango.def
@@ -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