[goffice] Fix fraction alignment #584380
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Fix fraction alignment #584380
- Date: Tue, 2 Aug 2011 06:30:54 +0000 (UTC)
commit dd4358f6a3cab8db720e8d1f4d158f45ff2d58db
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Tue Aug 2 00:30:01 2011 -0600
Fix fraction alignment #584380
2011-08-02 Andreas J. Guelzow <aguelzow pyrshep ca>
* goffice/utils/go-format.c (go_format_execute): insert space in case
of short nominators
ChangeLog | 5 ++++
NEWS | 2 +-
goffice/utils/go-format.c | 52 ++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 57 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fbe616c..2ebda93 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-08-02 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * goffice/utils/go-format.c (go_format_execute): insert space in case
+ of short nominators
+
2011-08-01 Andreas J. Guelzow <aguelzow pyrshep ca>
* configure.in: disable gtk depreciation check
diff --git a/NEWS b/NEWS
index 00b1d06..b293a0e 100644
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,7 @@
goffice 0.9.0:
Andreas:
- * Use pango attributes for formatting.
+ * Use pango attributes for formatting. [#584380][#651561]
--------------------------------------------------------------------------
goffice 0.8.17:
diff --git a/goffice/utils/go-format.c b/goffice/utils/go-format.c
index 0e4ba80..354baf2 100644
--- a/goffice/utils/go-format.c
+++ b/goffice/utils/go-format.c
@@ -3163,7 +3163,12 @@ SUFFIX(go_format_execute) (PangoLayout *layout, GString *dst,
val = fraction.d;
break;
- case OP_NUM_FRACTION_BLANK:
+ case OP_NUM_FRACTION_BLANK: {
+ gsize total_chars = g_utf8_strlen (dst->str + fraction.nominator_start, -1);
+ gsize denom_chars = g_utf8_strlen (dst->str + fraction.denominator_start, -1);
+ gsize nom_chars = total_chars - denom_chars - 1;
+ int diff = denom_chars - nom_chars;
+
if (fraction.n == 0) {
/* Replace all added characters by spaces of the right length. */
char const *f = dst->str + fraction.nominator_start;
@@ -3209,8 +3214,53 @@ SUFFIX(go_format_execute) (PangoLayout *layout, GString *dst,
memset (dst->str + fraction.nominator_start, ' ', chars);
g_string_truncate (dst, fraction.nominator_start + chars);
}
+ }
+
+ if (layout && pango_context_get_font_map (pango_layout_get_context (layout))) {
+ if (diff > 0) {
+ /* We should insert properly sized spaces. Here we use FIGURE SPACE U+2007 */
+ int i;
+ guint start = (fraction.n == 0) ? dst->len : fraction.nominator_start;
+ GList *plist, *l;
+ GString *zero_str = g_string_sized_new (diff + 1);
+
+ for (i = diff; i > 0; i--)
+ g_string_append_c (zero_str, '0');
+
+ plist = pango_itemize (pango_layout_get_context (layout),
+ zero_str->str,
+ 0,
+ diff,
+ attrs,
+ NULL);
+ for (l = plist; l != NULL; l = l->next) {
+ PangoItem *pi = l->data;
+ PangoGlyphString *glyphs = pango_glyph_string_new ();
+ PangoAttribute *attr;
+ PangoRectangle ink_rect;
+ PangoRectangle logical_rect;
+
+ pango_shape (zero_str->str, diff, &pi->analysis, glyphs);
+ pango_glyph_string_extents (glyphs,
+ pi->analysis.font,
+ &ink_rect,
+ &logical_rect);
+ pango_glyph_string_free (glyphs);
+
+ attr = pango_attr_shape_new (&ink_rect, &logical_rect);
+ attr->start_index = start;
+ attr->end_index = start + 1;
+ g_string_insert_c (dst, start, ' ');
+ pango_attr_list_insert (attrs, attr);
+
+ start++;
+ }
+ go_list_free_custom (plist, (GFreeFunc) pango_item_free);
+ g_string_free (zero_str, TRUE);
+ }
}
break;
+ }
#ifdef ALLOW_PI_SLASH
case OP_NUM_FRACTION_SIMPLIFY_PI:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]