paps/paps-0.6.6-fix-wcswidth.patch

48 lines
1.4 KiB
Diff
Raw Normal View History

diff -ruN paps-0.6.6.orig/src/paps.c paps-0.6.6/src/paps.c
--- paps-0.6.6.orig/src/paps.c 2006-12-04 20:08:36.000000000 +0900
+++ paps-0.6.6/src/paps.c 2006-12-04 20:16:59.000000000 +0900
@@ -712,7 +712,7 @@
PangoRectangle ink_rect, logical_rect;
wchar_t *wtext, *wnewtext;
gchar *newtext;
- size_t i, len, wwidth = 0, n;
+ int i, len, wwidth = 0, n;
wtext = (wchar_t *)g_utf8_to_ucs4 (para->text, para->length, NULL, NULL, NULL);
if (wtext == NULL)
@@ -722,11 +722,17 @@
}
len = wcswidth (wtext);
+ if (len < 0)
+ {
+ /* assuming that width of all characters in wtext may be 1 */
+ len = wcslen (wtext);
+ }
/* the amount of characters to be able to put on the line against CPI */
n = page_layout->column_width / 72.0 * cpi;
if (len > n)
{
- wnewtext = g_new (wchar_t, wcslen (wtext) + 1);
+ len = wcslen (wtext);
+ wnewtext = g_new (wchar_t, len + 1);
if (wnewtext == NULL)
{
fprintf (stderr, "Failed to allocate a memory.\n");
@@ -735,7 +741,14 @@
}
for (i = 0; i < len; i++)
{
- wwidth += wcwidth (wtext[i]);
+ int w = wcwidth (wtext[i]);
+
+ if (w < 0)
+ {
+ /* assuming that a width of this character may be 1 */
+ w = 1;
+ }
+ wwidth += w;
if (wwidth > n)
break;
wnewtext[i] = wtext[i];