summaryrefslogtreecommitdiffstats
path: root/source/l/gtk+/gtk+-1.2.10-ahiguti.patch
blob: 68f091c5f4ecccf1af8dd79326af16ad2bca8dba (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
Return-Path: a-higuti@math.sci.hokudai.ac.jp
Delivery-Date: Thu Sep 23 14:52:43 1999
Return-Path: <a-higuti@math.sci.hokudai.ac.jp>
Received: from localhost (IDENT:otaylor@localhost [127.0.0.1])
	by fresnel.labs.redhat.com (8.9.3/8.9.3) with ESMTP id OAA00891
	for <otaylor@localhost>; Thu, 23 Sep 1999 14:52:41 -0400
Received: from lacrosse.redhat.com
	by localhost with POP3 (fetchmail-5.0.0)
	for otaylor@localhost (single-drop); Thu, 23 Sep 1999 14:52:42 -0400 (EDT)
Received: from mail.redhat.com (mail.redhat.com [199.183.24.239])
	by lacrosse.corp.redhat.com (8.9.3/8.9.3) with ESMTP id OAA19205
	for <otaylor@lacrosse.redhat.com>; Thu, 23 Sep 1999 14:01:27 -0400
Received: from math.sci.hokudai.ac.jp (seki.math.sci.hokudai.ac.jp [133.50.152.8])
	by mail.redhat.com (8.8.7/8.8.7) with ESMTP id OAA13383
	for <otaylor@redhat.com>; Thu, 23 Sep 1999 14:01:49 -0400
Received: from heathcliff (a-higuti@hilbert.math.sci.hokudai.ac.jp [133.50.152.11])
	by math.sci.hokudai.ac.jp (8.8.8/3.6W01/06/98) with SMTP id DAA23889
	for <otaylor@redhat.com>; Fri, 24 Sep 1999 03:01:10 +0900 (JST)
Date: Fri, 24 Sep 1999 03:01:10 +0900 (JST)
Message-Id: <199909231801.DAA23889@math.sci.hokudai.ac.jp>
From: a-higuti@math.sci.hokudai.ac.jp (Akira Higuchi)
To: otaylor@redhat.com
Subject: Adding more gdk_isw* macros
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Status:  O
Lines: 528
Xref: fresnel.labs.redhat.com prog-gtk:648

Hello Owen,

I'm working on adding CJK support to gnome apps, and I need your advice.

As you know, gtk+-1.2 has some support for CJK. It's sufficient for most
gnome apps to be internationalized, but some problems remain. The most
problem is that there is no way of doing word wrapping for CJK strings.

For example, gtk-xmhtml shows Japanese text very uglily, because Japanese
sentences are recognized as very long words. (a Japanese sentence 
contain any spaces in most cases.) The same problem is in gtk+ itself, too;
Word wrapping in GtkLabel and GtkText doesn't work correctly for CJK text,
because of the same reason as above.

In order to fix it, we need more gdk_isw* functions than we already have
in gdki18n.h. (I regret I didn't add them before gtk+-1.2 was released.)
I attach herewith a patch which fixes it, but I think it's not acceptable
to adding a new macro to a stable version of gtk+. (is it?)

The question I want to ask you is: what's the best way of fixing the
problem without adding these macros to gdki18n.h? A solution is to add
these macros to each *.c files (in GtkLabel, GtkText, and gtkxmhtml etc.)
rather than gtki18n.h, but it's very ugly I think. 

Please don't say "wait until gscript is completed" ;-(  I don't want to
wait for a long time. (Please let me know if I can help you with gscript
BTW. I've not hacked gscript yet, because it seems to be too early to be
hacked by other than you.)

Thanks,
Akira Higuchi
---------------- x8 ---------------- x8 ---------------- x8 ----------------
diff -up gtk+-1.2.10/gdk/gdki18n.h.ahiguti gtk+-1.2.10/gdk/gdki18n.h
--- gtk+-1.2.10/gdk/gdki18n.h.ahiguti	2000-01-24 03:58:21.000000000 +0100
+++ gtk+-1.2.10/gdk/gdki18n.h	2008-10-02 10:43:26.000000000 +0200
@@ -51,4 +51,32 @@
 #  define gdk_iswspace(c) ((wchar_t)(c) <= 0xFF && isspace(c))
 #endif
 
+/* The following 9 macros are added in gtk+ 1.2.X. Don't use them without
+ * checking GTK_CHECK_VERSION. For example,
+ *	#if GTK_CHECK_VERSION (1,2,X)
+ *	    ... code which uses gdk_iswalpha(), gdk_iswcntrl(), etc. ...
+ *      #endif
+ */
+#if !defined(G_HAVE_BROKEN_WCTYPE) && (defined(G_HAVE_WCTYPE_H) || defined(G_HAVE_WCHAR_H)) && !defined(X_LOCALE)
+#  define gdk_iswalpha(c)  iswalpha(c)
+#  define gdk_iswcntrl(c)  iswcntrl(c)
+#  define gdk_iswdigit(c)  iswdigit(c)
+#  define gdk_iswlower(c)  iswlower(c)
+#  define gdk_iswgraph(c)  iswgraph(c)
+#  define gdk_iswprint(c)  iswprint(c)
+#  define gdk_iswpunct(c)  iswpunct(c)
+#  define gdk_iswupper(c)  iswupper(c)
+#  define gdk_iswxdigit(c) iswxdigit(c)
+#else
+#  define gdk_iswalpha(c)  ((wchar_t)(c) <= 0xFF && isalpha(c))
+#  define gdk_iswcntrl(c)  ((wchar_t)(c) <= 0xFF && iscntrl(c))
+#  define gdk_iswdigit(c)  ((wchar_t)(c) <= 0xFF && isdigit(c))
+#  define gdk_iswlower(c)  ((wchar_t)(c) <= 0xFF && islower(c))
+#  define gdk_iswgraph(c)  ((wchar_t)(c) >  0xFF || isgraph(c))
+#  define gdk_iswprint(c)  ((wchar_t)(c) >  0xFF || isprint(c))
+#  define gdk_iswpunct(c)  ((wchar_t)(c) <= 0xFF && ispunct(c))
+#  define gdk_iswupper(c)  ((wchar_t)(c) <= 0xFF && isupper(c))
+#  define gdk_iswxdigit(c) ((wchar_t)(c) <= 0xFF && isxdigit(c))
+#endif
+
 #endif /* __GDK_I18N_H__ */
diff -up gtk+-1.2.10/gtk/gtkentry.c.ahiguti gtk+-1.2.10/gtk/gtkentry.c
--- gtk+-1.2.10/gtk/gtkentry.c.ahiguti	2001-04-02 04:14:54.000000000 +0200
+++ gtk+-1.2.10/gtk/gtkentry.c	2008-10-02 10:43:26.000000000 +0200
@@ -2036,11 +2036,21 @@ gtk_entry_move_word (GtkEditable *editab
     }
 }
 
+static gboolean
+alnum_or_ideogram (GtkEntry *entry, guint index)
+{
+  GdkWChar ch;
+  ch = entry->text[index];
+  if (entry->use_wchar)
+    return !(gdk_iswpunct (ch) || gdk_iswcntrl (ch) || gdk_iswspace (ch));
+  else
+    return !(ispunct (ch) || iscntrl (ch) || isspace (ch));
+}
+
 static void
 gtk_move_forward_word (GtkEntry *entry)
 {
   GtkEditable *editable;
-  GdkWChar *text;
   gint i;
 
   editable = GTK_EDITABLE (entry);
@@ -2054,21 +2064,12 @@ gtk_move_forward_word (GtkEntry *entry)
 
   if (entry->text && (editable->current_pos < entry->text_length))
     {
-      text = entry->text;
-      i = editable->current_pos;
-	  
-      if ((entry->use_wchar) ? (!gdk_iswalnum (text[i])) : (!isalnum (text[i])))
-	for (; i < entry->text_length; i++)
-	  {
-	    if ((entry->use_wchar) ? gdk_iswalnum (text[i]) : isalnum (text[i]))
-	      break;
-	  }
-
+      for (i = editable->current_pos; i < entry->text_length; i++)
+	if (alnum_or_ideogram (entry, i))
+	  break;
       for (; i < entry->text_length; i++)
-	{
-	  if ((entry->use_wchar) ? (!gdk_iswalnum (text[i])) : (!isalnum (text[i])))
-	    break;
-	}
+	if (!alnum_or_ideogram (entry, i))
+	  break;
 
       editable->current_pos = i;
     }
@@ -2078,7 +2079,6 @@ static void
 gtk_move_backward_word (GtkEntry *entry)
 {
   GtkEditable *editable;
-  GdkWChar *text;
   gint i;
 
   editable = GTK_EDITABLE (entry);
@@ -2092,26 +2092,19 @@ gtk_move_backward_word (GtkEntry *entry)
 
   if (entry->text && editable->current_pos > 0)
     {
-      text = entry->text;
-      i = editable->current_pos - 1;
-      if ((entry->use_wchar) ? (!gdk_iswalnum (text[i])) : (!isalnum (text[i])))
-	for (; i >= 0; i--)
+      for (i = editable->current_pos - 1; i >= 0; i--)
+	if (alnum_or_ideogram (entry, i))
+	  break;
+      for (; i >= 0; i--)
+	if (!alnum_or_ideogram (entry, i))
 	  {
-	    if ((entry->use_wchar) ? gdk_iswalnum (text[i]) : isalnum (text[i]))
-	      break;
+	    i++;
+	    break;
 	  }
-      for (; i >= 0; i--)
-	{
-	  if ((entry->use_wchar) ? (!gdk_iswalnum (text[i])) : (!isalnum (text[i])))
-	    {
-	      i++;
-	      break;
-	    }
-	}
-	  
+
       if (i < 0)
 	i = 0;
-	  
+  
       editable->current_pos = i;
     }
 }
diff -up gtk+-1.2.10/gtk/gtklabel.c.ahiguti gtk+-1.2.10/gtk/gtklabel.c
--- gtk+-1.2.10/gtk/gtklabel.c.ahiguti	2001-04-02 05:12:38.000000000 +0200
+++ gtk+-1.2.10/gtk/gtklabel.c	2008-10-02 10:43:26.000000000 +0200
@@ -56,6 +56,7 @@ struct _GtkLabelWord
   GtkLabelWord *next;
   gint uline_y;
   GtkLabelULine *uline;
+  gboolean paragraph_break;
 };
 
 struct _GtkLabelULine
@@ -396,6 +397,7 @@ gtk_label_word_alloc (void)
   word->beginning = NULL;
   word->next = NULL;
   word->uline = NULL;
+  word->paragraph_break = FALSE;
 
   return word;
 }
@@ -441,6 +443,7 @@ gtk_label_split_text (GtkLabel *label)
       if (str == label->label_wc || str[-1] == '\n')
 	{
 	  /* Paragraph break */
+	  word->paragraph_break = TRUE;
 	  word->space = 0;
 	  
 	  max_line_width = MAX (line_width, max_line_width);
@@ -488,6 +491,7 @@ gtk_label_split_text (GtkLabel *label)
     {
       word = gtk_label_word_alloc ();
       
+      word->paragraph_break = TRUE;
       word->space = 0;
       word->beginning = str;
       word->length = 0;
@@ -500,6 +504,13 @@ gtk_label_split_text (GtkLabel *label)
   return MAX (line_width, max_line_width);
 }
 
+static gboolean
+is_ideogram (GdkWChar wc)
+{
+  return !(gdk_iswalnum (wc) || gdk_iswspace (wc) ||
+	   gdk_iswpunct (wc) || gdk_iswcntrl (wc));
+}
+
 /* this needs to handle white space better. */
 static gint
 gtk_label_split_text_wrapped (GtkLabel *label)
@@ -526,6 +537,7 @@ gtk_label_split_text_wrapped (GtkLabel *
       if (str == label->label_wc || str[-1] == '\n')
 	{
 	  /* Paragraph break */
+	  word->paragraph_break = TRUE;
 	  word->space = 0;
 	  
 	  max_line_width = MAX (line_width, max_line_width);
@@ -546,24 +558,30 @@ gtk_label_split_text_wrapped (GtkLabel *
 	  else
 	    word->space = space_width * nspaces;
 	}
-      else
+      else if (gdk_iswspace (str[-1]))
 	{
 	  /* Regular inter-word space */
 	  word->space = space_width;
 	}
+      else
+	{
+	  word->space = 0;
+	}
       
       word->beginning = str;
       word->length = 0;
       p = word->beginning;
       while (*p && !gdk_iswspace (*p))
 	{
+	  if (word->length > 0 && (is_ideogram (p[-1]) || is_ideogram (*p)))
+	    break;
 	  word->length++;
 	  p++;
 	}
       word->width = gdk_text_width_wc (GTK_WIDGET (label)->style->font, str, word->length);
       
       str += word->length;
-      if (*str)
+      if (*str && gdk_iswspace (*str))
 	str++;
       
       line_width += word->space + word->width;
@@ -600,7 +618,7 @@ gtk_label_pick_width (GtkLabel *label,
   width = 0;
   for (word = label->words; word; word = word->next)
     {
-      if (word->space == 0
+      if (word->paragraph_break
 	  || (line_width
 	      && (line_width >= min_width
 		  || line_width + word->width + word->space > max_width)))
@@ -716,7 +734,8 @@ gtk_label_finalize_lines_wrap (GtkLabel 
   GtkLabelWord *word, *line, *next_line;
   GtkWidget *widget;
   gchar *ptrn;
-  gint x, y, space, extra_width, add_space, baseline_skip;
+  gint x, y, space, num_words, extra_width, add_space, baseline_skip;
+  gboolean deliver_equivalently;
   
   g_return_if_fail (label->wrap);
   
@@ -724,20 +743,24 @@ gtk_label_finalize_lines_wrap (GtkLabel 
   y = 0;
   baseline_skip = (GTK_WIDGET (label)->style->font->ascent +
 		   GTK_WIDGET (label)->style->font->descent + 1);
+  deliver_equivalently = FALSE;
   
   for (line = label->words; line != 0; line = next_line)
     {
-      space = 0;
+      space = num_words = 0;
       extra_width = max_line_width - line->width;
       
       for (next_line = line->next; next_line; next_line = next_line->next)
 	{
-	  if (next_line->space == 0)
+	  if (next_line->paragraph_break)
 	    break;		/* New paragraph */
 	  if (next_line->space + next_line->width > extra_width)
 	    break;
+	  if (next_line->space == 0)
+	    deliver_equivalently = TRUE; /* An ideogram is found. */
 	  extra_width -= next_line->space + next_line->width;
 	  space += next_line->space;
+	  num_words++;
 	}
       
       line->x = 0;
@@ -747,14 +770,18 @@ gtk_label_finalize_lines_wrap (GtkLabel 
       
       for (word = line->next; word != next_line; word = word->next)
 	{
-	  if (next_line && next_line->space)
+	  if (next_line && !next_line->paragraph_break &&
+	      label->jtype == GTK_JUSTIFY_FILL &&
+	      (deliver_equivalently ? num_words : space) > 0)
 	    {
-	      /* Not last line of paragraph --- fill line if needed */
-	      if (label->jtype == GTK_JUSTIFY_FILL) {
+	      /* Not last line of paragraph --- fill line */
+	      if (deliver_equivalently)
+		add_space = (extra_width + num_words / 2) / num_words;
+	      else
 		add_space = (extra_width * word->space + space / 2) / space;
-		extra_width -= add_space;
-		space -= word->space;
-	      }
+	      extra_width -= add_space;
+	      space -= word->space;
+	      num_words--;
 	    }
 	  
 	  word->x = x + word->space + add_space;
@@ -925,7 +952,7 @@ gtk_label_expose (GtkWidget      *widget
 
       for (word = label->words; word; word = word->next)
 	{
-	  gchar save = word->beginning[word->length];
+	  GdkWChar save = word->beginning[word->length];
 	  word->beginning[word->length] = '\0';
 	  gtk_label_paint_word (label, x, y, word, &event->area);
 	  word->beginning[word->length] = save;
diff -up gtk+-1.2.10/gtk/gtktext.c.ahiguti gtk+-1.2.10/gtk/gtktext.c
--- gtk+-1.2.10/gtk/gtktext.c.ahiguti	2001-03-15 21:15:12.000000000 +0100
+++ gtk+-1.2.10/gtk/gtktext.c	2008-10-02 10:43:27.000000000 +0200
@@ -101,6 +101,13 @@ enum {
   ARG_WORD_WRAP
 };
 
+typedef enum {
+  CHAR_CLASS_SPACE,
+  CHAR_CLASS_ALNUM,
+  CHAR_CLASS_IDEOGRAM,
+  CHAR_CLASS_OTHERS     /* punct, cntrl */
+} CharClass;
+
 typedef struct _TextProperty          TextProperty;
 typedef struct _TabStopMark           TabStopMark;
 typedef struct _PrevTabCont           PrevTabCont;
@@ -300,6 +307,8 @@ static LineParams find_line_params (GtkT
 				    const GtkPropertyMark *mark,
 				    const PrevTabCont *tab_cont,
 				    PrevTabCont *next_cont);
+static void find_word_wrap_position (GtkText* text, LineParams *lp);
+static CharClass char_class (GtkText* text, guint index);
 static void recompute_geometry (GtkText* text);
 static void insert_expose (GtkText* text, guint old_pixels, gint nchars, guint new_line_count);
 static void delete_expose (GtkText* text,
@@ -4111,27 +4120,21 @@ gtk_text_move_forward_word (GtkText *tex
   
   undraw_cursor (text, FALSE);
   
-  if (text->use_wchar)
+  while (!LAST_INDEX (text, text->cursor_mark))
     {
-      while (!LAST_INDEX (text, text->cursor_mark) && 
-	     !gdk_iswalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index)))
-	advance_mark (&text->cursor_mark);
-      
-      while (!LAST_INDEX (text, text->cursor_mark) && 
-	     gdk_iswalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index)))
-	advance_mark (&text->cursor_mark);
+      CharClass cc = char_class (text, text->cursor_mark.index);
+      if (cc == CHAR_CLASS_ALNUM || cc == CHAR_CLASS_IDEOGRAM)
+	break;
+      advance_mark (&text->cursor_mark);
     }
-  else
+  while (!LAST_INDEX (text, text->cursor_mark))
     {
-      while (!LAST_INDEX (text, text->cursor_mark) && 
-	     !isalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index)))
-	advance_mark (&text->cursor_mark);
-      
-      while (!LAST_INDEX (text, text->cursor_mark) && 
-	     isalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index)))
-	advance_mark (&text->cursor_mark);
+      CharClass cc = char_class (text, text->cursor_mark.index);
+      if (cc != CHAR_CLASS_ALNUM && cc != CHAR_CLASS_IDEOGRAM)
+	break;
+      advance_mark (&text->cursor_mark);
     }
-  
+
   find_cursor (text, TRUE);
   draw_cursor (text, FALSE);
 }
@@ -4143,25 +4146,19 @@ gtk_text_move_backward_word (GtkText *te
   
   undraw_cursor (text, FALSE);
   
-  if (text->use_wchar)
+  while (text->cursor_mark.index > 0)
     {
-      while ((text->cursor_mark.index > 0) &&
-	     !gdk_iswalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index-1)))
-	decrement_mark (&text->cursor_mark);
-      
-      while ((text->cursor_mark.index > 0) &&
-	     gdk_iswalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index-1)))
-	decrement_mark (&text->cursor_mark);
+      CharClass cc = char_class (text, text->cursor_mark.index - 1);
+      if (cc == CHAR_CLASS_ALNUM || cc == CHAR_CLASS_IDEOGRAM)
+	break;
+      decrement_mark (&text->cursor_mark);
     }
-  else
+  while (text->cursor_mark.index > 0)
     {
-      while ((text->cursor_mark.index > 0) &&
-	     !isalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index-1)))
-	decrement_mark (&text->cursor_mark);
-      
-      while ((text->cursor_mark.index > 0) &&
-	     isalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index-1)))
-	decrement_mark (&text->cursor_mark);
+      CharClass cc = char_class (text, text->cursor_mark.index - 1);
+      if (cc != CHAR_CLASS_ALNUM && cc != CHAR_CLASS_IDEOGRAM)
+	break;
+      decrement_mark (&text->cursor_mark);
     }
   
   find_cursor (text, TRUE);
@@ -4782,27 +4779,8 @@ find_line_params (GtkText* text,
 		      GtkPropertyMark saved_mark = lp.end;
 		      guint saved_characters = lp.displayable_chars;
 		      
-		      lp.displayable_chars += 1;
-		      
-		      if (text->use_wchar)
-			{
-			  while (!gdk_iswspace (GTK_TEXT_INDEX (text, lp.end.index)) &&
-				 (lp.end.index > lp.start.index))
-			    {
-			      decrement_mark (&lp.end);
-			      lp.displayable_chars -= 1;
-			    }
-			}
-		      else
-			{
-			  while (!isspace(GTK_TEXT_INDEX (text, lp.end.index)) &&
-				 (lp.end.index > lp.start.index))
-			    {
-			      decrement_mark (&lp.end);
-			      lp.displayable_chars -= 1;
-			    }
-			}
-		      
+		      find_word_wrap_position (text, &lp);
+
 		      /* If whole line is one word, revert to char wrapping */
 		      if (lp.end.index == lp.start.index)
 			{
@@ -4850,6 +4828,54 @@ find_line_params (GtkText* text,
   return lp;
 }
 
+static CharClass
+char_class (GtkText* text, guint index)
+{
+  GdkWChar wc;
+  wc = GTK_TEXT_INDEX (text, index);
+  if (text->use_wchar)
+    {
+      if (gdk_iswspace (wc))
+	return CHAR_CLASS_SPACE;
+      else if (gdk_iswalnum (wc))
+	return CHAR_CLASS_ALNUM;
+      else if (gdk_iswpunct (wc) || gdk_iswcntrl (wc))
+	return CHAR_CLASS_OTHERS;
+      else
+	return CHAR_CLASS_IDEOGRAM;
+    }
+  else
+    {
+      if (isspace (wc))
+	return CHAR_CLASS_SPACE;
+      else if (isalnum (wc))
+	return CHAR_CLASS_ALNUM;
+      else if (ispunct (wc) || iscntrl (wc))
+	return CHAR_CLASS_OTHERS;
+      else
+	return CHAR_CLASS_IDEOGRAM;
+    }
+}
+
+static void
+find_word_wrap_position (GtkText* text, LineParams *lp)
+{
+  while (lp->end.index > lp->start.index &&
+	 char_class (text, lp->end.index) != CHAR_CLASS_SPACE &&
+	 char_class (text, lp->end.index) != CHAR_CLASS_IDEOGRAM &&
+	 char_class (text, lp->end.index - 1) != CHAR_CLASS_IDEOGRAM)
+    {
+      decrement_mark (&lp->end);
+      lp->displayable_chars -= 1;
+    }
+
+  /* lp->end.index points the position to be cut just now. If it's not a
+   * space, move it to the next display line. */
+  if (lp->end.index > lp->start.index &&
+      char_class (text, lp->end.index) != CHAR_CLASS_SPACE)
+    decrement_mark (&lp->end);
+}
+
 static void
 expand_scratch_buffer (GtkText* text, guint len)
 {
---------------- x8 ---------------- x8 ---------------- x8 ----------------

--------------------------------------
Akira Higuchi
Dept. of Mathematics, Hokkaido Univ.
Hokkaido, Japan
Email: a-higuti@math.sci.hokudai.ac.jp