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

[mgp-users 01111] super/subscribe enabled mgp (patch)



Hi there! 
I am new to this list.
I found Mgp a really great tool, but I have one major complaint ...
inability to handle super/subscript.
The attached patch (for the CVS version) is to enable these.
This worked at least for me (I only tested in a ttf environment).
No printing yet.

For the details, please see http://www.linkclub.or.jp/~hiikoysd/ryohei/mgp.html.

Thanks, 
Ryohei
diff -uNr mgp-cvs/draw.c mgp-new/draw.c
--- mgp-cvs/draw.c	Sat Jan 11 23:42:46 2003
+++ mgp-new/draw.c	Sat Jan 11 23:45:27 2003
@@ -260,6 +260,8 @@
 {
 	state->ypos = 0;
 	state->have_mark = 0;
+        state->charoff = 0;
+	char_size[caching] = nonscaled_size[caching];   
 	free_alloc_colors(&image_clr);
 	free_alloc_colors(&font_clr);
 
@@ -474,8 +476,46 @@
 	}
 
 	switch(cp->ct_op) {
+	case CTL_SUP:
+	        if (sup_scale > 1.0 || sup_scale < 0.1){
+		      sup_scale = DEFAULT_SUPSCALE;
+		}
+	        if (sup_off > 1.0 || sup_scale < 0.1){
+		      sup_off = DEFAULT_SUPOFF;
+		}
+	        state->charoff = -sup_off * nonscaled_size[caching];	   
+		char_size[caching] = (int)(nonscaled_size[caching] * sup_scale);
+	        break;
+	case CTL_SUB:
+	        if (sup_scale > 1.0 || sup_scale < 0.1){
+		      sup_scale = DEFAULT_SUPSCALE;
+		}
+	        if (sub_off > 1.0 || sub_off < 0.1){
+		      sub_off = DEFAULT_SUBOFF;
+		}
+	        state->charoff = sub_off * nonscaled_size[caching];
+		char_size[caching] = (int)(nonscaled_size[caching] * sup_scale);	   
+	        break;   
+	case CTL_SETSUP:
+	        if (cp->cti3_value1 > 100 || cp->cti3_value1 < 10){
+	             sup_off = DEFAULT_SUPOFF;
+		}else{
+		     sup_off = cp->cti3_value2 / 100;
+		}
+	        if (cp->cti3_value2 > 100 || cp->cti3_value2 < 10){
+	             sub_off = DEFAULT_SUBOFF;
+		}else{
+		     sub_off = cp->cti3_value2 / 100;
+		}
+	        if (cp->cti3_value3 > 100 || cp->cti3_value3 < 10){
+		     sup_scale = DEFAULT_SUPSCALE;
+		}else{
+		     sup_scale = cp->cti3_value3 / 100;
+		}	   
+	        break;	   	   
 	case CTL_SIZE:
-		char_size[caching] = state->height * cp->ctf_value / 100;
+	        nonscaled_size[caching] = state->height * cp->ctf_value / 100;
+		char_size[caching] = nonscaled_size[caching];
 #ifdef FREETYPE
 		tfc_setsize(char_size[caching]);
 #endif
@@ -547,6 +587,8 @@
 		break;
 
 	case CTL_CONT:
+      	        state->charoff = 0;
+ 	        char_size[caching] = nonscaled_size[caching];
 		break;
 
 #ifdef VFLIB
@@ -660,6 +702,8 @@
 		break;
 
 	case CTL_LINESTART:
+      	        state->charoff = 0;
+ 	        char_size[caching] = nonscaled_size[caching];
 		if (state->line == 0) {
 			/*
 			 * set background of target 
@@ -874,6 +918,8 @@
 	int ascent;
 	int descent;
 {
+        ascent -= state->charoff;
+        descent += state->charoff;
 	if (ascent > state->maxascent)
 		state->maxascent = ascent;
 	if (descent > state->maxdescent)
@@ -1270,7 +1316,7 @@
 #ifdef VFLIB
 		case MODE_VFLIB:
 			char_len = draw_onechar_vf(state, code,
-				state->linewidth, 0,
+				state->linewidth, state->charoff,
 				registry ? char_size[caching]
 					 : (char_size[caching] * 4 / 5), /*XXX*/
 				char_size[caching]);
@@ -1284,7 +1330,7 @@
 			 * metric info derived from TrueType font file.
 			 */
 			char_len = draw_onechar_tf(state, code,
-				state->linewidth, 0,
+				state->linewidth, state->charoff,
 				char_size[caching], registry,
 				(len == (charset16 ? 2 : 1)) ? 1 : 0,
 				charset16);
@@ -1297,7 +1343,7 @@
 		case MODE_UNKNOWN:
 		case MODE_X:
 			char_len = draw_onechar_x(state, code,
-				state->linewidth, 0, char_size[caching],
+				state->linewidth, state->charoff, char_size[caching],
 				registry, (len == (charset16 ? 2 : 1)) ? 1 : 0);
 			if (char_len == 0) {
 				fprintf(stderr, "can't load font size %d "
@@ -1362,7 +1408,6 @@
 			state->obj = thisline;
 		state->objlast = thislineend;
 		state->align = backup.align;
-
 		/* fix up x position and maxascent. */
 		for (tail = state->obj; tail; tail = tail->next) {
 			tail->x -= startwidth;
@@ -1470,8 +1515,8 @@
 	obj->type = O_VFONT;
 	obj->data.vfc = vfc;
 	obj->data.vfc->size = size;
-	obj->ascent = obj->data.vfc->ascent;
-	obj->descent = obj->data.vfc->descent;
+	obj->ascent = obj->data.vfc->ascent - y;
+	obj->descent = obj->data.vfc->descent + y;
 	obj->vertloc = VL_BASE;
 	vfc->ref++;
 	return 1;
@@ -1495,8 +1540,8 @@
 	obj->fore = fore_color[caching];
 	obj->type = O_TFONT;
 	obj->data.tfc = tfc;
-	obj->ascent = obj->data.tfc->ascent;
-	obj->descent = obj->data.tfc->descent;
+	obj->ascent = obj->data.tfc->ascent - y;
+	obj->descent = obj->data.tfc->descent + y;
 	obj->vertloc = VL_BASE;
 	tfc->ref++;
 	return 1;
@@ -1524,8 +1569,8 @@
 	obj->data.xfont.csize = size;
 	obj->data.xfont.code = code;
 	obj->data.xfont.registry = registry;
-	obj->ascent = size;	/*XXX*/
-	obj->descent = 0;	/*XXX*/
+	obj->ascent = size - y;	/*XXX*/
+	obj->descent = -y;	/*XXX*/
 	obj->vertloc = VL_BASE;
 	return 1;
 }
@@ -1893,7 +1938,7 @@
 			break;
 		}
 #endif /* FREETYPE */
-	}
+	}       
 	if (obj != NULL) {	/* VFONT exist */
 		xim = XCreateImage(display, visual, depth, ZPixmap,
 				0, NULL, width, height,
@@ -1987,6 +2032,7 @@
 				y -= obj->descent;
 				break;
 			}
+		        y += obj->y;
 #ifdef VFLIB
 			if (obj->type == O_VFONT) {
 				(void)vfc_image(obj->data.vfc,
@@ -2055,7 +2101,7 @@
 			break;
 		}
 		x += xpos;
-		y += ypos;
+		y += ypos + obj->y;
 #endif
 		switch (obj->type) {
 #ifdef MNG
diff -uNr mgp-cvs/globals.c mgp-new/globals.c
--- mgp-cvs/globals.c	Sat Jan 11 23:42:46 2003
+++ mgp-new/globals.c	Sat Jan 11 23:45:27 2003
@@ -74,6 +74,10 @@
 u_long *free_clr = NULL;
 
 u_int char_size[2];
+u_int nonscaled_size[2];
+float sup_scale;
+float sup_off;
+float sub_off;
 u_int horiz_gap[2] = {DEFAULT_HGAP, DEFAULT_HGAP};
 u_int vert_gap[2] = {DEFAULT_VGAP, DEFAULT_VGAP};
 u_int depth;
@@ -150,5 +154,8 @@
 /*CTL*/	{ CTL_ANIM,		T_STR,	"anim", 4 },
 /*CTL*/	{ CTL_VALIGN,		T_STR,	"valign", 6 },
 /*CTL*/	{ CTL_AREA,		T_STR,	"area", 4 },
+/*CTL*/	{ CTL_SUP,		T_VOID, "sup", 4 },   
+/*CTL*/	{ CTL_SUB,		T_VOID, "sub", 4 },
+/*CTL*/	{ CTL_SETSUP,		T_INT, "sup", 4 },
 	{ 0, 0, NULL, 0 },
 };
diff -uNr mgp-cvs/grammar.y mgp-new/grammar.y
--- mgp-cvs/grammar.y	Sat Jan 11 23:42:52 2003
+++ mgp-new/grammar.y	Sat Jan 11 23:45:32 2003
@@ -178,6 +178,43 @@
 	return ct;
 }
 
+
+static struct ctrl *
+gen_int2(op, v1, v2)
+	int op;
+	int v1;
+	int v2;
+{
+	struct ctrl *ct;
+
+	if (!(ct = ctlalloc1(op))) {
+		yyerror("cannot allocate integer2 node");
+		return ct;
+	}
+	ct->cti2_value1 = v1;
+	ct->cti2_value2 = v2;
+	return ct;
+}
+
+static struct ctrl *
+gen_int3(op, v1, v2, v3)
+	int op;
+	int v1;
+	int v2;
+	int v3;
+{
+	struct ctrl *ct;
+
+	if (!(ct = ctlalloc1(op))) {
+		yyerror("cannot allocate integer3 node");
+		return ct;
+	}
+	ct->cti2_value1 = v1;
+	ct->cti2_value2 = v2;
+	ct->cti2_value2 = v3;	
+	return ct;
+}
+
 static struct ctrl *
 gen_str(op, str)
 	int op;
@@ -732,6 +769,7 @@
 %token KW_QUALITY KW_ICON KW_LEFTFILL KW_XSYSTEM KW_VFCAP KW_TFONT KW_TFDIR
 %token KW_DEFFONT KW_FONT KW_TFONT0 KW_EMBED KW_ENDEMBED KW_NEWIMAGE
 %token KW_CHARSET KW_TMFONT KW_PCACHE KW_TMFONT0 KW_ANIM KW_VALIGN KW_AREA
+%token KW_SUP KW_SUB KW_SETSUP
 
 %type <ct> toplevel
 %type <ct> line defaultline tabline shellline deffontline
@@ -797,6 +835,9 @@
 	| KW_AGAIN	{ $$ = gen_void(CTL_AGAIN); }
 	| KW_MARK	{ $$ = gen_void(CTL_MARK); }
 	| KW_PAGE	{ $$ = gen_void(CTL_PAGE); }
+	| KW_SETSUP NUM NUM NUM	{ $$ = gen_int3(CTL_SETSUP, $2, $3, $4); }
+	| KW_SUP	{ $$ = gen_void(CTL_SUP); }
+	| KW_SUB	{ $$ = gen_void(CTL_SUB); }		
 	| KW_SIZE NUM	{ $$ = gen_double_int(CTL_SIZE, $2); }
 	| KW_SIZE DOUBLE	{ $$ = gen_double(CTL_SIZE, $2); }
 	| KW_HGAP NUM	{ $$ = gen_int(CTL_HGAP, $2); }
diff -uNr mgp-cvs/mgp.h mgp-new/mgp.h
--- mgp-cvs/mgp.h	Sat Jan 11 23:50:12 2003
+++ mgp-new/mgp.h	Sat Jan 11 23:50:21 2003
@@ -101,6 +101,9 @@
 #define PAGELIST_KFONT	"k14"
 
 #define DEFAULT_CHARSIZE	10	/* 10% of height */
+#define DEFAULT_SUPSCALE        0.7
+#define DEFAULT_SUPOFF	        0.65
+#define DEFAULT_SUBOFF	        0.25
 #define DEFAULT_HGAP		0
 #define DEFAULT_VGAP		15
 #define DEFAULT_BQUALITY	100
@@ -188,6 +191,17 @@
 	u_int ct_value;
 };
 
+struct ctrl_int2 {
+	u_int ct_value1;
+        u_int ct_value2;
+};
+
+struct ctrl_int3 {
+	u_int ct_value1;
+        u_int ct_value2;
+        u_int ct_value3;   
+};
+
 struct ctrl_long {
 	u_long ct_value;
 };
@@ -279,6 +293,8 @@
 	union {
 		struct ctrl_double ctrl_double;
 		struct ctrl_int ctrl_int;
+	        struct ctrl_int2 ctrl_int2;
+	        struct ctrl_int3 ctrl_int3;	   
 		struct ctrl_long ctrl_long;
 		struct ctrl_char ctrl_char;
 		struct ctrl_char2 ctrl_char2;
@@ -294,6 +310,11 @@
 
 #define ctf_value	ct_val.ctrl_double.ct_value
 #define cti_value	ct_val.ctrl_int.ct_value
+#define cti2_value1	ct_val.ctrl_int2.ct_value1
+#define cti2_value2	ct_val.ctrl_int2.ct_value2
+#define cti3_value1	ct_val.ctrl_int3.ct_value1
+#define cti3_value2	ct_val.ctrl_int3.ct_value2
+#define cti3_value3	ct_val.ctrl_int3.ct_value3
 #define ctl_value	ct_val.ctrl_long.ct_value
 #define ctc_value	ct_val.ctrl_char.ct_value
 #define ctc2_value1	ct_val.ctrl_char2.ct_value1
@@ -403,6 +424,7 @@
 	int maxdescent;
 	u_int linewidth;
 	u_int brankline;
+        u_int charoff;
 	struct ctrl *xfont;
 	struct render_object *obj, *objlast;
 };
@@ -561,6 +583,10 @@
 extern struct alloc_color font_clr;
 
 extern u_int char_size[2];
+extern u_int nonscaled_size[2];
+extern float sup_scale;
+extern float sup_off;
+extern float sub_off;
 extern u_int horiz_gap[2];
 extern u_int vert_gap[2];
 extern u_int depth;
diff -uNr mgp-cvs/parse.c mgp-new/parse.c
--- mgp-cvs/parse.c	Sat Jan 11 23:42:46 2003
+++ mgp-new/parse.c	Sat Jan 11 23:45:27 2003
@@ -479,7 +479,7 @@
 			lex_init(buf + 1);
 			if (yyparse() || n_errors) {
 				fprintf(stderr,
-					"%s:%d: fatal syntax error detected\n",
+					"%s:%d: fatal syntax error detected !!!\n",
 					filename, lineno);
 				exit(-1);
 			}
diff -uNr mgp-cvs/scanner.l mgp-new/scanner.l
--- mgp-cvs/scanner.l	Sat Jan 11 23:42:49 2003
+++ mgp-new/scanner.l	Sat Jan 11 23:45:29 2003
@@ -165,6 +165,9 @@
 (ANIM|anim)	return KW_ANIM;
 (VALIGN|valign)	return KW_VALIGN;
 (AREA|area)	return KW_AREA;
+(SUP|sup)	return KW_SUP;
+(SUB|sub)	return KW_SUB;
+(SETSUP|setsup)	return KW_SETSUP;
 
 [ \n\t]		;
 ","		return COMMA;
diff -uNr mgp-cvs/tokdefs.h mgp-new/tokdefs.h
--- mgp-cvs/tokdefs.h	Sat Jan 11 23:50:12 2003
+++ mgp-new/tokdefs.h	Sat Jan 11 23:50:21 2003
@@ -66,6 +66,9 @@
 #define	KW_ANIM	316
 #define	KW_VALIGN	317
 #define	KW_AREA	318
+#define	KW_SUP	319
+#define	KW_SUB	320
+#define	KW_SETSUP	321
 
 
 extern YYSTYPE yylval;
diff -uNr mgp-cvs/x11.c mgp-new/x11.c
--- mgp-cvs/x11.c	Sat Jan 11 23:42:46 2003
+++ mgp-new/x11.c	Sat Jan 11 23:45:27 2003
@@ -199,6 +199,10 @@
 	}
 
 	char_size[0] = window_height * DEFAULT_CHARSIZE / 100;
+        nonscaled_size[0] = char_size[0];
+	sup_off = DEFAULT_SUPOFF;
+	sub_off = DEFAULT_SUBOFF;
+	sup_scale = DEFAULT_SUPSCALE;
 	(void)get_color(DEFAULT_FORE, &fore_color[0]);
 	ctrl_color[0] = fore_color[0];