[pango] Bug 410169 – gravity problem with Common chars
- From: Behdad Esfahbod <behdad src gnome org>
- To: svn-commits-list gnome org
- Subject: [pango] Bug 410169 – gravity problem with Common chars
- Date: Wed, 22 Jul 2009 20:31:10 +0000 (UTC)
commit ac2ce962e9c257657eeceaf08d6aeeddd6faaa83
Author: Behdad Esfahbod <behdad behdad org>
Date: Wed Jul 22 16:24:43 2009 -0400
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()
docs/pango-sections.txt | 1 +
docs/tmpl/vertical.sgml | 12 +++++++++
pango/pango-context.c | 13 ++++------
pango/pango-gravity.c | 58 ++++++++++++++++++++++++++++++++++++++++++-----
pango/pango-gravity.h | 5 ++++
pango/pango.def | 1 +
6 files changed, 76 insertions(+), 14 deletions(-)
---
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 0fbdc22..50abd19 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -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
diff --git a/docs/tmpl/vertical.sgml b/docs/tmpl/vertical.sgml
index 5a75d99..83e33a1 100644
--- a/docs/tmpl/vertical.sgml
+++ b/docs/tmpl/vertical.sgml
@@ -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>
diff --git a/pango/pango-context.c b/pango/pango-context.c
index 4057968..6ec0b56 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 b58ae85..297199a 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 2e42ebd..d2fa964 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 39ab42b..d941ebe 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]