[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[mgp-users-jp 00046] Word wrapping



$B$A$g$C$HI,MW$K$+$i$l$F!J>P!K(Bmgp$B$N1QJ89TKv=hM}$r$$$8$C$F$_$^$7$?!#4pK\(B
$BE*$K(B ' ' < c < DEL $B$NJ8;zNs$r0lC10L$H$7!"$=$NCf$G$O2~9T$7$^$;$s!#(B
USE_XDRAWSTRING_ONLY_SMALL$B$,Dj5A$5$l$F$$$k$H1QJ8$NItJ,$OA4$F(B 
XDrawString$B$r;H$&$h$&$K$7$^$7$?!#!J$H$$$&$N$O(B draw_onechar_vf$B$^$G$$$8$k(B
$B855$$,$J$+$C$?$+$i$G$9!#(B^_^;$B!K(B

$B$^$?!"1QC18l$NESCf$GB0@-$rJQ$($k$H$=$3$G2~9T$7$F$7$^$&$3$H$b$"$j$^$9!#(B
draw_string()$B$,8F$P$l$k;~E@$G@Z$l$F$$$k$N$G!"$3$l$rD>$9$N$O7k9=BgJQ$=(B
$B$&$G$9!#(B

$B$h$/J,$+$C$F$$$J$$>e$K$d$C$D$1;E;v$G$9$,!"$H$j$"$($:F0$$$F$$$k$h$&$J$N(B
$B$G$3$3$K=P$7$^$9!#<Q$k$J$j>F$/$J$j$I$&$>8f<+M3$K!#!J$9$4$/JQ99$7$F$$$k(B
$B$h$&$K8+$($k$+$b$7$l$^$;$s$,!"$[$H$s$I$O?tCf9T$^$k$4$H%3%T!<$7$?$@$1$G(B
$B$9!#!K(B

$B$"$5$_(B
=======
--- ./draw.c.org	Thu Dec 25 22:26:39 1997
+++ ./draw.c	Thu Jan  8 06:25:41 1998
@@ -88,6 +88,8 @@
 #endif
 static u_int draw_onechar_x __P((struct render_state *, u_int, u_int,
 	u_int));
+static u_int draw_oneword_x __P((struct render_state *, u_char *, u_int));
+static void load_newfont __P((struct render_state *, int));
 
 static void back_gradation __P((struct render_state *, struct ctrl_grad *));
 static void image_load __P((struct render_state *, char *, int, int, int, int, int, int));
@@ -738,6 +740,8 @@
 
 	p = data;
 
+	/* if kanji, render one character at a time; otherwise, render
+	   one word (string of characters between ' ' and DEL) at a time */
 	while (*p != '\n' && *p != 0) {
 		if (*p == 0x1b && *(p+1) == '$' &&
 				(*(p+2) == 'B' || *(p+2) == '@')) {
@@ -770,9 +774,13 @@
 			state->linewidth, PM_POSY(char_size));
 #else
 # ifdef USE_XDRAWSTRING_ONLY_SMALL
-		if (!kanji && char_size < 25) {
-			char_len = draw_onechar_x(state, code,
-				state->linewidth, PM_POSY(char_size));
+		if (!kanji) {
+			u_char *q;
+			p--;
+			for (q = p ; *q != '\0' && *q > ' ' && *q < 0x7f; q++)
+			    ;
+			char_len = draw_oneword_x(state, p, q-p);
+			p = q;
 		} else
 # endif
 		{
@@ -791,6 +799,8 @@
 			draw_line_end(state);
 			draw_line_start(state);
 			state->linewidth = state->leftfillpos;
+			if (!kanji && isspace(*p))
+				p++;
 		}
 	}
 }
@@ -830,6 +840,8 @@
 }
 #endif /*VFLIB*/
 
+static XFontStruct *xfontstruct;
+
 static u_int
 draw_onechar_x(state, code, x, y)
 	struct render_state *state;
@@ -837,17 +849,127 @@
 	u_int x, y;
 {
 	u_char fontstring[BUFSIZ];
-	static u_int last_char_size = 0;
-	static u_char last_xfont[BUFSIZ] = "";
 	u_int i;
 	u_int char_len;
 	u_int char_height;
-	static XFontStruct *xfontstruct;
-	static int lastkanjimode = -1;
 	int kanjimode;
 
 	kanjimode = (code & 0xff00) ? 1 : 0;
 
+	load_newfont(state, kanjimode);
+
+#define YCONTROL	(xfontstruct->descent / 2)
+	draw_line_itemsize(state,
+		(char_size > xfontstruct->ascent)
+			? char_size + xfontstruct->descent + 4
+			: xfontstruct->ascent + xfontstruct->descent + 4);
+	if (kanjimode) {
+		XChar2b kch[2];
+
+		kch[0].byte1 = (code >> 8) & 0xff;
+		kch[0].byte2 = code & 0xff;
+
+		char_len = XTextWidth16(xfontstruct, kch, 1);
+
+		if (COMPLEX_BGIMAGE) {
+			XDrawString16(display, pixmap, gcfore,
+				x, y + char_size - YCONTROL, kch, 1);
+			XDrawString16(display, maskpix, gcall,
+				x, y + char_size - YCONTROL, kch, 1);
+		} else {
+			XDrawString16(display, pixmap, gcfb,
+				x, y + char_size - YCONTROL, kch, 1);
+		}
+	} else {
+		u_char ch[2];
+		ch[0] = code & 0xff;
+
+		char_len = XTextWidth(xfontstruct, ch, 1);
+
+		if (COMPLEX_BGIMAGE) {
+			XDrawString(display, pixmap, gcfore,
+				x, y + char_size - YCONTROL, ch, 1);
+			XDrawString(display, maskpix, gcall,
+				x, y + char_size - YCONTROL, ch, 1);
+		} else {
+			XDrawString(display, pixmap, gcfb,
+				x, y + char_size - YCONTROL, ch, 1);
+		}
+	}
+#undef YCONTROL
+
+	return char_len;
+}
+
+static u_int
+draw_oneword_x(state, word, count)
+	struct render_state *state;
+	u_char *word;
+	u_int count;
+{
+	u_int i;
+	u_int word_len;
+	u_int char_height;
+	u_int x, y;
+
+#if 0
+	fprintf(stderr, "printing \"") ;
+	for (i = 0 ; i < count ; i++)
+	    fputc(word[i], stderr);
+	fprintf(stderr, "\" at ") ;
+	fflush(stderr);
+#endif
+	load_newfont(state, 0);
+
+	word_len = XTextWidth(xfontstruct, word, count);
+	
+	if (state->align == AL_LEFTFILL1
+	    && window_width < state->linewidth + word_len) {
+		draw_line_end(state);
+		draw_line_start(state);
+		state->linewidth = state->leftfillpos;
+	}
+
+	draw_line_itemsize(state,
+			   (char_size > xfontstruct->ascent)
+			   ? char_size + xfontstruct->descent + 4
+			   : xfontstruct->ascent + xfontstruct->descent + 4);
+
+#define YCONTROL	(xfontstruct->descent / 2)
+
+	x = state->linewidth;
+	y = PM_POSY(char_size);
+
+#if 0
+	fprintf(stderr, "(%d, %d)\n", x, y) ;
+#endif
+
+	if (COMPLEX_BGIMAGE) {
+		XDrawString(display, pixmap, gcfore,
+			    x, y + char_size - YCONTROL, word, count);
+		XDrawString(display, maskpix, gcall,
+			    x, y + char_size - YCONTROL, word, count);
+	} else {
+		XDrawString(display, pixmap, gcfb,
+			    x, y + char_size - YCONTROL, word, count);
+	}
+
+#undef YCONTROL
+
+	return word_len;
+}
+
+static void
+load_newfont(state, kanjimode)
+	struct render_state *state;
+	int kanjimode;
+{
+	static u_int last_char_size = 0;
+	static u_char last_xfont[BUFSIZ] = "";
+	static int lastkanjimode = -1;
+	u_int i;
+	u_char fontstring[BUFSIZ];
+
 	if (strcmp(state->xfont, last_xfont) || char_size != last_char_size
 	 || kanjimode != lastkanjimode) {
 		/* load new font */
@@ -904,48 +1026,6 @@
 		strcpy(last_xfont, state->xfont);
 	}
 	lastkanjimode = kanjimode;
-
-#define YCONTROL	(xfontstruct->descent / 2)
-	draw_line_itemsize(state,
-		(char_size > xfontstruct->ascent)
-			? char_size + xfontstruct->descent + 4
-			: xfontstruct->ascent + xfontstruct->descent + 4);
-	if (kanjimode) {
-		XChar2b kch[2];
-
-		kch[0].byte1 = (code >> 8) & 0xff;
-		kch[0].byte2 = code & 0xff;
-
-		char_len = XTextWidth16(xfontstruct, kch, 1);
-
-		if (COMPLEX_BGIMAGE) {
-			XDrawString16(display, pixmap, gcfore,
-				x, y + char_size - YCONTROL, kch, 1);
-			XDrawString16(display, maskpix, gcall,
-				x, y + char_size - YCONTROL, kch, 1);
-		} else {
-			XDrawString16(display, pixmap, gcfb,
-				x, y + char_size - YCONTROL, kch, 1);
-		}
-	} else {
-		u_char ch[2];
-		ch[0] = code & 0xff;
-
-		char_len = XTextWidth(xfontstruct, ch, 1);
-
-		if (COMPLEX_BGIMAGE) {
-			XDrawString(display, pixmap, gcfore,
-				x, y + char_size - YCONTROL, ch, 1);
-			XDrawString(display, maskpix, gcall,
-				x, y + char_size - YCONTROL, ch, 1);
-		} else {
-			XDrawString(display, pixmap, gcfb,
-				x, y + char_size - YCONTROL, ch, 1);
-		}
-	}
-#undef YCONTROL
-
-	return char_len;
 }
 
 /*