gnucash maint: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Mon Mar 14 12:31:25 EDT 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/e63baa62 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/6fa3c9e5 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/99879286 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/c84d82e3 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/f8fc796c (commit)
	from  https://github.com/Gnucash/gnucash/commit/ccae437e (commit)



commit e63baa6270f75c7b50bda96bbc064e543ba7c667
Merge: ccae437e5 6fa3c9e5d
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Mar 14 09:25:42 2022 -0700

    Merge Bob Fewell's 'rtl' into maint.


commit 6fa3c9e5d90f74ba03d821ca1468991df97e3261
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Mon Mar 7 11:06:21 2022 +0000

    Invoice status bar currencies not displayed correctly for Hebrew
    
    When Gnucash is run in Hebrew which is a RTL language, on the invoice
    pages the status bar currencies are not displayed correctly...
    
    To fix this, when creating the displayed monetary amount insert a BiDi
    ltr isolate uni-character at the start of the string.

diff --git a/gnucash/gnome/dialog-invoice.c b/gnucash/gnome/dialog-invoice.c
index b1585b59c..4f1830e9d 100644
--- a/gnucash/gnome/dialog-invoice.c
+++ b/gnucash/gnome/dialog-invoice.c
@@ -1715,10 +1715,14 @@ static void
 gnc_invoice_reset_total_label (GtkLabel *label, gnc_numeric amt, gnc_commodity *com)
 {
     char string[256];
+    gchar *bidi_string;
 
     amt = gnc_numeric_convert (amt, gnc_commodity_get_fraction(com), GNC_HOW_RND_ROUND_HALF_UP);
     xaccSPrintAmount (string, amt, gnc_commodity_print_info (com, TRUE));
-    gtk_label_set_text (label, string);
+
+    bidi_string = gnc_wrap_text_with_bidi_ltr_isolate (string);
+    gtk_label_set_text (label, bidi_string);
+    g_free (bidi_string);
 }
 
 static void

commit 99879286382f62c635bd08dbe345612992a3dd82
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Mar 6 11:47:50 2022 +0000

    Register status bar currencies not displayed correctly for Hebrew
    
    When Gnucash is run in Hebrew which is a RTL language, on the register
    pages the status bar currencies are not displayed correctly...
    
    To fix this, when creating the displayed monetary amount insert a BiDi
    ltr isolate uni-character at the start of the string.

diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index 298adaaa3..323fd857f 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -578,7 +578,7 @@ gsr_update_summary_label( GtkWidget *label,
     char string[256];
     const gchar *label_str = NULL;
     GtkWidget *text_label, *hbox;
-    gchar *tooltip;
+    gchar *bidi_string;
 
     if ( label == NULL )
         return;
@@ -605,11 +605,13 @@ gsr_update_summary_label( GtkWidget *label,
     }
 
     gnc_set_label_color( label, amount );
-    gtk_label_set_text( GTK_LABEL(label), string );
+    bidi_string = gnc_wrap_text_with_bidi_ltr_isolate (string);
+    gtk_label_set_text( GTK_LABEL(label), bidi_string );
+    g_free (bidi_string);
 
     if (label_str)
     {
-        tooltip = g_strdup_printf ("%s %s", label_str, string);
+        gchar *tooltip = g_strdup_printf ("%s %s", label_str, string);
         gtk_widget_set_tooltip_text (GTK_WIDGET(hbox), tooltip);
         g_free (tooltip);
     }

commit c84d82e3e986081180e2ee475e5d966ee5f1e24f
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Fri Nov 12 15:53:23 2021 +0000

    Summary bar currencies not displayed correctly for Hebrew
    
    When Gnucash is run in Hebrew which is a RTL language, on the accounts
    page the summary bar currencies are not displayed correctly...
    
    To fix this, when creating the displayed monetary amount insert a BiDi
    ltr isolate uni-character at the start of the string.

diff --git a/gnucash/gnome-utils/window-main-summarybar.c b/gnucash/gnome-utils/window-main-summarybar.c
index 503dc703c..44708becc 100644
--- a/gnucash/gnome-utils/window-main-summarybar.c
+++ b/gnucash/gnome-utils/window-main-summarybar.c
@@ -399,6 +399,7 @@ gnc_main_window_summary_refresh (GNCMainSummary * summary)
         for (current = g_list_first(currency_list); current; current = g_list_next(current))
         {
             gchar *total_mode_label;
+            gchar *bidi_total, *bidi_asset_amount, *bidi_profit_amount;
 
             currency_accum = current->data;
 
@@ -412,16 +413,22 @@ gnc_main_window_summary_refresh (GNCMainSummary * summary)
 
             gtk_list_store_append(summary->datamodel, &iter);
             total_mode_label = get_total_mode_label (currency_accum);
+            bidi_total = gnc_wrap_text_with_bidi_ltr_isolate(total_mode_label);
+            bidi_asset_amount = gnc_wrap_text_with_bidi_ltr_isolate(asset_amount_string);
+            bidi_profit_amount = gnc_wrap_text_with_bidi_ltr_isolate(profit_amount_string);    
             gtk_list_store_set(summary->datamodel, &iter,
-                               COLUMN_MNEMONIC_TYPE, total_mode_label,
+                               COLUMN_MNEMONIC_TYPE, bidi_total,
                                COLUMN_ASSETS,        _("Net Assets:"),
-                               COLUMN_ASSETS_VALUE,  asset_amount_string,
+                               COLUMN_ASSETS_VALUE,  bidi_asset_amount,
                                COLUMN_ASSETS_NEG,    gnc_numeric_negative_p(currency_accum->assets),
                                COLUMN_PROFITS,       _("Profits:"),
-                               COLUMN_PROFITS_VALUE, profit_amount_string,
+                               COLUMN_PROFITS_VALUE, bidi_profit_amount,
                                COLUMN_PROFITS_NEG,   gnc_numeric_negative_p(currency_accum->profits),
                                -1);
             g_free(total_mode_label);
+            g_free(bidi_total);
+            g_free(bidi_asset_amount);
+            g_free(bidi_profit_amount);
         }
         gtk_combo_box_set_model(GTK_COMBO_BOX(summary->totals_combo),
                                 GTK_TREE_MODEL(summary->datamodel));

commit f8fc796c959a20af95aa29b82dceab6ba274f44a
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 3 15:34:42 2021 +0000

    Bug797501 - Currency symbols in Hebrew (RTL) language
    
    When Gnucash is run in Hebrew which is a RTL language, on the accounts
    page the tree view is displaying the required number as the following...
    
    TreeView entry is   '1,500.00 ₪' or '-1,500.00 ₪'
    TreeModel string is '₪ 1,500.00‬' or '₪ 1,500.00-‬'
    
    This seems to be down to the GTK 'Unicode Bidirectional Text Algorithm'
    which is changing the representation of the model string based on the
    first strongly typed character, in this case the Israeli shekel sign.
    
    To fix this, when creating the displayed monetary amount insert a BiDi
    ltr isolate uni-character at the start of the string.

diff --git a/gnucash/gnome-utils/gnc-tree-model-account.c b/gnucash/gnome-utils/gnc-tree-model-account.c
index 5c3160e5a..e04eac9ad 100644
--- a/gnucash/gnome-utils/gnc-tree-model-account.c
+++ b/gnucash/gnome-utils/gnc-tree-model-account.c
@@ -560,6 +560,7 @@ gnc_tree_model_account_compute_period_balance (GncTreeModelAccount *model,
                                                gboolean *negative)
 {
     GncTreeModelAccountPrivate *priv;
+    GNCPrintAmountInfo print_info;
     time64 t1, t2;
     gnc_numeric b3;
 
@@ -583,7 +584,9 @@ gnc_tree_model_account_compute_period_balance (GncTreeModelAccount *model,
     if (negative)
         *negative = gnc_numeric_negative_p (b3);
 
-    return g_strdup(xaccPrintAmount (b3, gnc_account_print_info (acct, TRUE)));
+    print_info = gnc_account_print_info (acct, TRUE);
+
+    return g_strdup (gnc_print_amount_with_bidi_ltr_isolate (b3, print_info));
 }
 
 static gboolean
diff --git a/libgnucash/app-utils/gnc-ui-balances.c b/libgnucash/app-utils/gnc-ui-balances.c
index b46b53199..9227aefb2 100644
--- a/libgnucash/app-utils/gnc-ui-balances.c
+++ b/libgnucash/app-utils/gnc-ui-balances.c
@@ -146,7 +146,8 @@ gnc_ui_account_get_print_balance (xaccGetBalanceInCurrencyFn fn,
     balance = gnc_ui_account_get_balance_full(fn, account, recurse,
               negative, NULL);
     print_info = gnc_account_print_info(account, TRUE);
-    return g_strdup(xaccPrintAmount(balance, print_info));
+
+    return g_strdup (gnc_print_amount_with_bidi_ltr_isolate (balance, print_info));
 }
 
 
@@ -178,7 +179,8 @@ gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn,
     balance = gnc_ui_account_get_balance_full(fn, account, recurse,
               negative, report_commodity);
     print_info = gnc_commodity_print_info(report_commodity, TRUE);
-    return g_strdup(xaccPrintAmount(balance, print_info));
+
+    return g_strdup (gnc_print_amount_with_bidi_ltr_isolate (balance, print_info));
 }
 
 static gnc_numeric
@@ -312,7 +314,8 @@ gnc_ui_owner_get_print_balance (GncOwner *owner,
 
     balance = gnc_ui_owner_get_balance_full (owner, negative, NULL);
     print_info = gnc_commodity_print_info (gncOwnerGetCurrency (owner), TRUE);
-    return g_strdup (xaccPrintAmount (balance, print_info));
+
+    return g_strdup (gnc_print_amount_with_bidi_ltr_isolate (balance, print_info));
 }
 
 /**
@@ -338,6 +341,7 @@ gnc_ui_owner_get_print_report_balance (GncOwner *owner,
     balance = gnc_ui_owner_get_balance_full (owner, negative,
               report_commodity);
     print_info = gnc_commodity_print_info (report_commodity, TRUE);
-    return g_strdup (xaccPrintAmount (balance, print_info));
+
+    return g_strdup (gnc_print_amount_with_bidi_ltr_isolate (balance, print_info));
 }
 
diff --git a/libgnucash/app-utils/gnc-ui-util.c b/libgnucash/app-utils/gnc-ui-util.c
index 5bcb8eb63..d391bb3a9 100644
--- a/libgnucash/app-utils/gnc-ui-util.c
+++ b/libgnucash/app-utils/gnc-ui-util.c
@@ -1850,11 +1850,13 @@ xaccSPrintAmount (char * bufp, gnc_numeric val, GNCPrintAmountInfo info)
     return (bufp - orig_bufp);
 }
 
+#define BUFLEN 1024
+
 const char *
 xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info)
 {
     /* hack alert -- this is not thread safe ... */
-    static char buf[1024];
+    static char buf[BUFLEN];
 
     if (!xaccSPrintAmount (buf, val, info))
         buf[0] = '\0';
@@ -1863,6 +1865,55 @@ xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info)
     return buf;
 }
 
+const char *
+gnc_print_amount_with_bidi_ltr_isolate (gnc_numeric val, GNCPrintAmountInfo info)
+{
+    /* hack alert -- this is not thread safe ... */
+    static char buf[BUFLEN];
+    static const char ltr_isolate[] = { 0xe2, 0x81, 0xa6 };
+    static const char ltr_pop_isolate[] = { 0xe2, 0x81, 0xa9 };
+    size_t offset = info.use_symbol ? 3 : 0;
+
+    memset (buf, 0, BUFLEN);
+    if (!xaccSPrintAmount (buf + offset, val, info))
+    {
+        buf[0] = '\0';
+        return buf;
+    };
+
+    if (!info.use_symbol)
+        return buf;
+
+    memcpy (buf, ltr_isolate, 3);
+
+    if (buf[BUFLEN - 4] == '\0')
+    {
+        size_t length = strlen (buf);
+        memcpy (buf + length, ltr_pop_isolate, 3);
+    }
+    else
+    {
+        buf[BUFLEN - 1] = '\0';
+        memcpy (buf + BUFLEN - 4, ltr_pop_isolate, 3);
+
+        PWARN("buffer length %d exceeded, string truncated was %s", BUFLEN, buf);
+    }
+    /* its OK to return buf, since we declared it static
+       and is immediately g_strdup'd */
+    return buf;
+}
+
+gchar *
+gnc_wrap_text_with_bidi_ltr_isolate (const gchar *text)
+{
+    static const char *ltr = "\u2066"; // ltr isolate
+    static const char *pop = "\u2069"; // pop directional formatting
+
+    if (!text)
+        return NULL;
+
+    return g_strconcat (ltr, text, pop, NULL);
+}
 
 /********************************************************************\
  ********************************************************************/
diff --git a/libgnucash/app-utils/gnc-ui-util.h b/libgnucash/app-utils/gnc-ui-util.h
index b9bb385c6..4e8867d10 100644
--- a/libgnucash/app-utils/gnc-ui-util.h
+++ b/libgnucash/app-utils/gnc-ui-util.h
@@ -401,6 +401,28 @@ xaccParseAmountExtended (const char * in_str, gboolean monetary,
                          gunichar group_separator, const char *ignore_list,
                          gnc_numeric *result, char **endstr);
 
+/**
+ * Make a string representation of a gnc_numeric.  Warning, the
+ * gnc_numeric is not checked for validity and the returned char* may
+ * point to random garbage.
+ *
+ * This is the same as xaccPrintAmount but wraps the output with BiDi
+ * left to right isolate if a symbol is displayed.
+ */
+const char *
+gnc_print_amount_with_bidi_ltr_isolate (gnc_numeric val, GNCPrintAmountInfo info);
+
+/**
+ * This function helps with GTK's use of 'Unicode Bidirectional
+ * Text Algorithm'. To keep the format of the text, this function wraps
+ * the text with a BiDi isolate charatcter and a BiDi closing character.
+ *
+ * This helps with monetary values in RTL languages that display the
+ * currency symbol.
+ */
+gchar *
+gnc_wrap_text_with_bidi_ltr_isolate (const char *text);
+
 /* Initialization ***************************************************/
 
 void gnc_ui_util_init (void);
@@ -446,9 +468,9 @@ gchar * gnc_filter_text_for_currency_symbol (const gchar *incoming_text,
                                              const gchar *symbol);
 
 /** Returns the incoming text removed of currency symbol
- * 
+ *
  * @param comm commodity of entry if known
- * 
+ *
  * @param incoming_text The text to filter
  *
  * @param symbol return the symbol used



Summary of changes:
 gnucash/gnome-utils/gnc-tree-model-account.c |  5 ++-
 gnucash/gnome-utils/window-main-summarybar.c | 13 +++++--
 gnucash/gnome/dialog-invoice.c               |  6 +++-
 gnucash/gnome/gnc-split-reg.c                |  8 +++--
 libgnucash/app-utils/gnc-ui-balances.c       | 12 ++++---
 libgnucash/app-utils/gnc-ui-util.c           | 53 +++++++++++++++++++++++++++-
 libgnucash/app-utils/gnc-ui-util.h           | 26 ++++++++++++--
 7 files changed, 108 insertions(+), 15 deletions(-)



More information about the gnucash-changes mailing list