Index: kit/CHANGELOG diff -u kit/CHANGELOG:1.9 kit/CHANGELOG:removed --- kit/CHANGELOG:1.9 Sat Sep 5 00:11:21 1998 +++ kit/CHANGELOG Mon Jul 12 05:10:00 2004 @@ -1,51 +0,0 @@ -CHANGELOG for magicpoint -$Id: CHANGELOG,v 1.9 1998/09/04 15:11:21 onoe Exp $ - -Fri Sep 5 1998 onoe@sm.sony.co.jp - * handle key inputs from invoked terminal as pressed on Xserver, - even if the Xserver is running on a remote host. - -Mon Aug 26 1998 itojun@iijlab.net - * new copyright. (BSDish copyright without clause 3) - -Mon Aug 25 1998 itojun@iijlab.net - * print.c: better x11/freetype/vflib -> postscript font mapping. - -Mon Aug 23 1998 kato@wide.ad.jp - * embedded image support (added mgpembed.pl and embed.c) - -Mon Aug 22 1998 itojun@iijlab.net - * added contrib/xmindpath, MindPath PocketPoint user-level driver. - -Fri Jul 10 11:57:59 JST 1998 itojun@iijlab.net - * cache gs-generated image file. - Suggested by: luigi@FreeBSD.org - -Mon Jul 6 11:38:32 JST 1998 itojun@iijlab.net - * capable of handling GB2312 and KSC5601 encoding. - they must be encoded by using iso-2022 like escape sequences. - EUC-cn or EUC-kr does not work. - * -x option is added. - -Thu Jul 2 18:04:16 JST 1998 itojun@iijlab.net - * eliminate gsview. - * revamp "xfont" directive. (see SYNTAX for detail) - -Thu Jun 25 13:10:28 JST 1998 itojun@iijlab.net - * print.c: color postscript support by "mgp2ps -c". - -changes between 1.02a and 1.03a: - * To allow color name that has space inbetween ("dark blue"), - color name after directives SHOULD come with doublequote. - Therefore, - %fore blue - should be - %fore "blue" - At this moment, doublequote can be ommitted for backward - compatibility. We may require to have doublequote in the future. - Font names and other string parameter obeys the same rule. - * %image is now capable of rendering encapsulated postscript files - (*.eps). - %image foo.eps - should work fine. - By using -X option, you can specify device name for ghostscript. Index: kit/Imakefile.in diff -u kit/Imakefile.in:1.52 kit/Imakefile.in:1.53 --- kit/Imakefile.in:1.52 Sat Feb 28 06:06:14 2004 +++ kit/Imakefile.in Thu Jul 8 15:09:53 2004 @@ -1,13 +1,13 @@ -# $Id: Imakefile.in,v 1.52 2004/02/27 21:06:14 itojun Exp $ +# $Id: Imakefile.in,v 1.53 2004/07/08 06:09:53 nishida Exp $ @SET_MAKE@ srcdir= @srcdir@ VPATH= @srcdir@ SRCS= mgp.c draw.c parse.c plist.c print.c globals.c x11.c x11dummy.c \ font.c background.c scanner.c grammar.c postscript.c tfont.c \ - embed.c unimap.c mng.c + embed.c unimap.c mng.c m17n.c TPOBJS= mgp.o draw.o parse.o plist.o globals.o x11.o font.o background.o \ - scanner.o grammar.o postscript.o tfont.o embed.o unimap.o mng.o + scanner.o grammar.o postscript.o tfont.o embed.o unimap.o mng.o m17n.o PROBJS= print.o parse.o globals.o x11dummy.o scanner.o grammar.o postscript.o \ embed.o LIBOBJS= @LIBOBJS@ @@ -69,6 +69,7 @@ SpecialObjectRule(grammar.o,grammar.c, $(DEFS) $(OPTFLAGS)) SpecialObjectRule(embed.o,embed.c, $(DEFS) $(OPTFLAGS)) SpecialObjectRule(mng.o,mng.c, $(DEFS) $(OPTFLAGS)) +SpecialObjectRule(m17n.o,m17n.c, $(DEFS) $(OPTFLAGS)) #define PassCDebugFlags #define IHaveSubdirs Index: kit/configure diff -u kit/configure:1.92 kit/configure:1.93 --- kit/configure:1.92 Sat Feb 28 06:06:14 2004 +++ kit/configure Thu Jul 8 15:09:53 2004 @@ -308,7 +308,7 @@ # include #endif" -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS SET_MAKE build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP AWK YACC LEX LEXLIB LEX_OUTPUT_ROOT mgp_cv_path_perl mgp_cv_path_uuencode mgp_cv_path_gzip mgp_cv_path_uudecode mgp_cv_path_gunzip OPTFLAGS DEPLIBS EGREP LIBOBJS mgp_cv_vflib_a USE_IMLIB mgp_keywords LTLIBOBJS' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS SET_MAKE build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP AWK YACC LEX LEXLIB LEX_OUTPUT_ROOT mgp_cv_path_perl mgp_cv_path_uuencode mgp_cv_path_gzip mgp_cv_path_uudecode mgp_cv_path_gunzip OPTFLAGS DEPLIBS EGREP LIBOBJS mgp_cv_vflib_a USE_IMLIB HAVE_M17NLIB mgp_keywords LTLIBOBJS' ac_subst_files='' # Initialize some variables set by options. @@ -861,6 +861,7 @@ --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-vfontcap=PATH use PATH as vfontcap --with-x use the X Window System + --with-m17n-lib use the m17n library Some influential environment variables: CC C compiler command @@ -5983,6 +5984,58 @@ LIBS="$LIBS $GIFLIB" fi + +# Check whether --with-m17n-lib or --without-m17n-lib was given. +if test "${with_m17n_lib+set}" = set; then + withval="$with_m17n_lib" + +fi; +if test "x$with_m17n_lib" = "xyes"; then + # Extract the first word of "m17n-config", so it can be a program name with args. +set dummy m17n-config; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_HAVE_M17NLIB+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$HAVE_M17NLIB"; then + ac_cv_prog_HAVE_M17NLIB="$HAVE_M17NLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_HAVE_M17NLIB="yes" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +fi +fi +HAVE_M17NLIB=$ac_cv_prog_HAVE_M17NLIB +if test -n "$HAVE_M17NLIB"; then + echo "$as_me:$LINENO: result: $HAVE_M17NLIB" >&5 +echo "${ECHO_T}$HAVE_M17NLIB" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + + if test "x$HAVE_M17NLIB" = "xyes"; then + cat >>confdefs.h <<\_ACEOF +#define USE_M17N 1 +_ACEOF + + OPTFLAGS="$OPTFLAGS `m17n-config X --cflags`" + LIBS="$LIBS `m17n-config X --libs` -lm17n-core" + fi +fi + mgp_keywords=`$mgp_cv_path_perl $srcdir/keywords.pl $srcdir/globals.c` @@ -6659,6 +6712,7 @@ s,@LIBOBJS@,$LIBOBJS,;t t s,@mgp_cv_vflib_a@,$mgp_cv_vflib_a,;t t s,@USE_IMLIB@,$USE_IMLIB,;t t +s,@HAVE_M17NLIB@,$HAVE_M17NLIB,;t t s,@mgp_keywords@,$mgp_keywords,;t t s,@LTLIBOBJS@,$LTLIBOBJS,;t t CEOF Index: kit/configure.in diff -u kit/configure.in:1.89 kit/configure.in:1.90 --- kit/configure.in:1.89 Sat Feb 28 06:06:14 2004 +++ kit/configure.in Thu Jul 8 15:09:54 2004 @@ -3,7 +3,7 @@ dnl independent (using srcdir), however, xmkmf and Imake.tmpl do not dnl allow us to switch compilation directory. dnl -dnl $Id: configure.in,v 1.89 2004/02/27 21:06:14 itojun Exp $ +dnl $Id: configure.in,v 1.90 2004/07/08 06:09:54 nishida Exp $ AC_INIT(image/imagetypes.c) dnl Checks for programs. @@ -458,6 +458,16 @@ LIBS="$LIBS $GIFLIB" fi +AC_ARG_WITH(m17n-lib, [ --with-m17n-lib use the m17n library]) +if test "x$with_m17n_lib" = "xyes"; then + AC_CHECK_PROG(HAVE_M17NLIB, m17n-config, yes) + if test "x$HAVE_M17NLIB" = "xyes"; then + AC_DEFINE(USE_M17N) + OPTFLAGS="$OPTFLAGS `m17n-config X --cflags`" + LIBS="$LIBS `m17n-config X --libs` -lm17n-core" + fi +fi + dnl keyword substitution. mgp_keywords=`$mgp_cv_path_perl $srcdir/keywords.pl $srcdir/globals.c` AC_SUBST(mgp_keywords) Index: kit/ctlwords.pl diff -u kit/ctlwords.pl:1.2 kit/ctlwords.pl:removed --- kit/ctlwords.pl:1.2 Sat Sep 5 06:05:08 1998 +++ kit/ctlwords.pl Mon Jul 12 05:10:01 2004 @@ -1,12 +0,0 @@ -#! /usr/bin/perl -$counter = 0; # 0 origin -print "/* generated by ctlwords.awk. do not edit by hand. */\n"; - -while (<>) { - next if (!/^\/\*CTL\*\//); - next if ($_ !~ /(CTL_[A-Z0-9]+)/); - - $word = $1; - print "#define $word\t$counter\n"; - $counter++; -} Index: kit/draw.c diff -u kit/draw.c:1.216 kit/draw.c:1.218 --- kit/draw.c:1.216 Sat Feb 28 18:59:01 2004 +++ kit/draw.c Fri Jul 9 23:27:02 2004 @@ -26,7 +26,7 @@ * SUCH DAMAGE. */ /* - * $Id: draw.c,v 1.216 2004/02/28 09:59:01 nishida Exp $ + * $Id: draw.c,v 1.218 2004/07/09 14:27:02 nishida Exp $ */ #include "mgp.h" @@ -66,7 +66,7 @@ static int set_position __P((struct render_state *)); static void draw_line_start __P((struct render_state *)); -static void draw_line_itemsize __P((struct render_state *, int, int)); +void draw_line_itemsize __P((struct render_state *, int, int)); static void draw_line_output __P((struct render_state *, char *)); static void draw_line_end __P((struct render_state *)); static void cutin __P((struct render_state *, int, int, int)); @@ -889,6 +889,13 @@ printf("this mgp cannot use %%opaque, needs to be built with xft2\n"); #endif break; + case CTL_M17N: +#ifdef USE_M17N + M17N_process_direc(cp->ctc2_value1, cp->ctc2_value2); +#else + fprintf(stderr, "this mgp cannot use %%m17n, needs to be built with m17n-lib\n"); +#endif + break; default: fprintf(stderr, @@ -944,7 +951,7 @@ obj_free(state, obj); } -static void +void draw_line_itemsize(state, ascent, descent) struct render_state *state; int ascent; @@ -975,7 +982,14 @@ struct render_state *state; char *data; { +#ifdef USE_M17N + if (mgp_flag & FL_NOM17N) + draw_string(state, data); + else + M17N_draw_string(state, data); +#else draw_string(state, data); +#endif } static void @@ -1035,6 +1049,11 @@ int round; Window cutinWin; +#ifdef USE_M17N + // we cannot use cutin with m17n-lib so far. + return; +#endif + if (state->repaint) return; @@ -1163,7 +1182,6 @@ int charset16 = 0; p = (u_char *)data; - while (*p && *p != '\n') { /* 94x94 charset */ if (p[0] == 0x1b && p[1] == '$' && @@ -1255,9 +1273,14 @@ struct render_state backup0, backup; enum { MODE_UNKNOWN, MODE_X, MODE_VFLIB, MODE_FREETYPE } mode = MODE_UNKNOWN; -#ifdef USE_XFT2 char *p0; - +#ifdef USE_M17N + if (!(mgp_flag & FL_NOM17N)){ + p0 = M17N_draw_fragment(state, p, len); + if (p0) return p0; + } +#endif +#ifdef USE_XFT2 if (!(mgp_flag & FL_NOXFT)){ p0 = xft_draw_fragment(state, p, len, registry, charset16); if (p0) return p0; @@ -1550,6 +1573,12 @@ free(obj->data.xftfont.registry); break; #endif +#ifdef USE_M17N + case O_M17NTEXT: + /* XXX we need to add free function for mtext data here! */ +// m17n_object_unref(obj->data.m17ntext.mt); + break; +#endif #ifdef MNG case O_ANIM: break; @@ -1696,6 +1725,10 @@ obj->ascent = 0; /*XXX*/ obj->descent = isize; /*XXX*/ obj->vertloc = VL_CENTER; +#ifdef USE_M17N + // Adjust icon position for line folding function + obj->vertloc = VL_TOP; +#endif return 1; } @@ -2204,6 +2237,11 @@ obj->data.xftfont.len); break; #endif +#ifdef USE_M17N + case O_M17NTEXT: + M17N_draw_object(obj, target, x, y); + break; +#endif case O_XFONT: y += obj->y; code = obj->data.xfont.code; @@ -4814,3 +4852,28 @@ return last_xftfont; } #endif +#ifdef USE_M17N +obj_new_mtext(state, x, y, mt, drawframe, ascent, descent) + struct render_state *state; + int x, y; + MText *mt; + MFrame *drawframe; + int ascent, descent; +{ + struct render_object *obj; + + obj = obj_alloc(state); + if (obj == NULL) return 0; + obj->x = x; + obj->y = y; + obj->fore = fore_color[caching]; /* we don't need this */ + obj->type = O_M17NTEXT; + obj->ascent = ascent; + obj->descent = descent; + obj->vertloc = VL_BASE; + obj->data.m17ntext.mt = mt; + obj->data.m17ntext.drawframe = drawframe; + obj->data.m17ntext.len = mtext_len(mt); + return 1; +} +#endif Index: kit/globals.c diff -u kit/globals.c:1.49 kit/globals.c:1.50 --- kit/globals.c:1.49 Fri Sep 12 11:04:54 2003 +++ kit/globals.c Thu Jul 8 15:09:54 2004 @@ -26,7 +26,7 @@ * SUCH DAMAGE. */ /* - * $Id: globals.c,v 1.49 2003/09/12 02:04:54 nishida Exp $ + * $Id: globals.c,v 1.50 2004/07/08 06:09:54 nishida Exp $ */ #include "mgp.h" @@ -159,5 +159,6 @@ /*CTL*/ { CTL_SUP, T_VOID, "sup", 3 }, /*CTL*/ { CTL_SUB, T_VOID, "sub", 3 }, /*CTL*/ { CTL_SETSUP, T_INT, "setsup", 6 }, +/*CTL*/ { CTL_M17N, T_STR2, "m17n", 4 }, { 0, 0, NULL, 0 }, }; Index: kit/grammar.y diff -u kit/grammar.y:1.43 kit/grammar.y:1.44 --- kit/grammar.y:1.43 Fri Sep 12 11:04:54 2003 +++ kit/grammar.y Thu Jul 8 15:09:54 2004 @@ -27,7 +27,7 @@ * SUCH DAMAGE. */ /* - * $Id: grammar.y,v 1.43 2003/09/12 02:04:54 nishida Exp $ + * $Id: grammar.y,v 1.44 2004/07/08 06:09:54 nishida Exp $ */ /* * partly derived from lbl libpcap source code, which has the following @@ -770,6 +770,7 @@ %token KW_CHARSET KW_TMFONT KW_PCACHE KW_TMFONT0 KW_ANIM KW_VALIGN KW_AREA %token KW_OPAQUE %token KW_SUP KW_SUB KW_SETSUP +%token KW_M17N %type toplevel %type line defaultline tabline shellline deffontline @@ -1032,6 +1033,15 @@ "in this configuration"); #endif } + | KW_M17N STRorID STRorID { +#ifdef USE_M17N + $$ = gen_str2(CTL_M17N, $2, $3); +#else + $$ = gen_str2(CTL_NOOP, $2, $3); + yywarn("directive \"m17n\" not supported " + "in this configuration"); +#endif + } | KW_VALIGN STRorID { $$ = gen_valign($2); } Index: kit/m17n.c diff -u /dev/null kit/m17n.c:1.1 --- /dev/null Mon Jul 12 05:10:01 2004 +++ kit/m17n.c Fri Jul 9 17:24:08 2004 @@ -0,0 +1,444 @@ +/* + * Copyright (C) 1997 and 1998 WIDE Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +/* + * $Id: m17n.c,v 1.1 2004/07/09 08:24:08 nishida Exp $ + */ + +#ifdef USE_M17N +#include "mgp.h" +#define M17N_MAX_CACHE 100 + +static void M17N_format_line(); + +static MDrawControl control; +static MText *mt; +static MFace *face_size; +static MFace *face_color; +static MFace *face_other; +static MSymbol lang; +/* M-text containing a single space. It is used to get normal + ascent/descent of an ASCII font selected for the current set of + faces. */ +static MText *space; +static struct render_state *current_state; +static int current_linewidth; +static int current_indent; + +static int kinsoku_range [][2] = { + 0x3041, 0x30FF, /* Kana */ + 0x2E80, 0x2FDF, /* radical */ + 0x3400, 0x4DB5, /* CJK Ideograph Extention A */ + 0x4E00, 0x9FAF, /* CJK Ideograph */ + 0XF900, 0xFAFF, /* CJK COMPATIBILITY IDEOGRAPH */ + 0X20000, 0x2A6D6, /* CJK Ideograph Extention B */ + 0x2F800, 0x2FA1D /* CJK COMPATIBILITY IDEOGRAPH */ +}; + +static int kinsoku_list [] = { +/* UNICODE */ +0x2019, 0x201A, 0x201D, 0x201E, 0x2032, 0x2033, 0x2034, 0x203A, +0x203C, 0x203D, 0x2046, 0x2047, 0x2048, 0x2049, 0x204D, 0x3000, +0x3001, 0x3002, 0x3009, 0x300B, 0x300D, 0x300F, 0x3011, 0x3015, +0x3017, 0x3018, 0x309B, 0x309C, 0x309D, 0x309E, 0x30FD, 0x30FD, +0xFF01, 0xFF09, 0xFF0C, 0xFF0E, 0xFF1A, 0xFF1B, 0xFF1F, 0xFF3D, +0xFF5D, 0xFF60, 0xFF61, 0xFF63, 0xFF64, +/* JISX208 */ +0x00A7, 0x00B0, 0x2018, 0x201C, 0x2032, 0x2033, 0x2103, 0x3008, +0x300A, 0x300C, 0x300E, 0x3010, 0x3014, 0x3016, 0xFF02, 0xFF08, +0xFF20, 0xFF3B, 0xFF5B +}; + +static MCharTable *kinsoku_table; +static MSymbol Mkinsoku; + +static int +m17n_line_break (mt, pos, from, to, line, y) + MText *mt; + int pos, from, to; + int line, y; +{ + int c, i = 0, opos = pos; + c = mtext_ref_char(mt, pos); + if (mchartable_lookup(kinsoku_table, c) == Mt) return pos; + while(pos != from){ + if (i ++ > 10) return opos; /* for stupidly long line */ + pos --; + c = mtext_ref_char(mt, pos); + if (c < 256 && isspace(c)) return pos +1; + if (mchartable_lookup(kinsoku_table, c) == Mt) return pos; + } + + return pos; +} + +void +M17N_init() +{ + int i; + M17N_INIT(); + + space = mtext_from_data (" ", 1, MTEXT_FORMAT_US_ASCII); +#if 0 + face_other = mface (); + // default fontset is not truetype +// mface_put_prop (face_other, Mfontset, mfontset ("truetype")); + mface_put_prop (face_other, Mfontset, mfontset ("default")); +#endif + memset (&control, 0, sizeof control); + control.two_dimensional = 1; + control.enable_bidi = 1; + control.ignore_formatting_char = 1; + control.disable_caching = 0; + control.max_line_width = 0; + control.anti_alias = 1; + control.format = M17N_format_line; +// control.line_break = mdraw_default_line_break; + control.line_break = m17n_line_break; + + /* Generate kinsoku_char_table. */ + Mkinsoku = msymbol ("kinsoku"); + kinsoku_table = mchartable (Msymbol, Mnil); + for (i = 0; i < (sizeof(kinsoku_range) / sizeof(kinsoku_range[0])); i++) + mchartable_set_range (kinsoku_table, kinsoku_range[i][0], + kinsoku_range[i][1], Mt); + for (i = 0; i < (sizeof kinsoku_list / sizeof (int)); i++) + mchartable_set (kinsoku_table, kinsoku_list[i], Mkinsoku); +} + +#define MAXCACHEDMTEXT 40 +MText * +M17N_gen_mtext (p) + u_char *p; +{ + static MText *cached_mt[MAXCACHEDMTEXT]; + static u_char *cached_txt[MAXCACHEDMTEXT][BUFSIZ]; + static int cached_txt_len[MAXCACHEDMTEXT]; + static int cached_count; + MSymbol coding; + MText *mt = 0; + int i, len = strlen (p); + + if (len == 0) return; + for (i = 0; i < cached_count; i ++) + if ((len == cached_txt_len[i]) && + !memcmp((void *)p, (void *)cached_txt[i], cached_txt_len[i])) return cached_mt[i]; + + if (strchr (p, '\033')) { + /* Try ISO-2022 encoding. */ + coding = mconv_resolve_coding (msymbol ("iso-2022-7bit")); + if (coding) mt = mconv_decode_buffer (coding, p, len); + } + if (!mt) { + /* Try UTF-8. */ + coding = mconv_resolve_coding (msymbol ("utf-8")); + if (coding) mt = mconv_decode_buffer (coding, p, len); + } + if (!mt){ + /* Try the encoding of the current locale. */ + mt = mconv_decode_buffer (Mnil, p, len); + } + + bzero(cached_txt[cached_count], BUFSIZ); + if (cached_mt[cached_count]) + m17n_object_unref(cached_mt[cached_count]); + strcpy((char *)cached_txt[cached_count], p); + cached_txt_len[cached_count] = strlen(p); + cached_mt[cached_count] = mt; + cached_count = (cached_count + 1) % MAXCACHEDMTEXT; + + return mt; +} + +void +M17N_set_size(size) + int size; +{ + static MFace *msize[M17N_MAX_CACHE]; + static int msize_num = 0; + int i, targetsize; + int delta, mindelta, mindelta_i; + + targetsize = size * 10; + + mindelta = -1; + for (i = 0; i < msize_num; i ++){ + if (msize[i]){ + delta = abs((int)mface_get_prop(msize[i], Msize) - targetsize); + if (!delta){ + face_size = msize[i]; + return; + } else { + if (mindelta < 0){ mindelta = delta; mindelta_i = i; } + else if (mindelta > delta) { mindelta = delta; mindelta_i = i; } + } + } + } + + /* If msize_num exceeds limit, choose the closest size */ + if (msize_num == M17N_MAX_CACHE) { + face_size = msize[mindelta_i]; + return; + } + + /* create new face */ + msize[msize_num] = mface(); + mface_put_prop (msize[msize_num], Msize, (void *) targetsize); + face_size = msize[msize_num]; + msize_num ++; + return; +} + +void +M17N_set_color(color) + u_long color; +{ + static u_long mcolor_val[M17N_MAX_CACHE]; + static MFace *mcolor[M17N_MAX_CACHE]; + static int mcolor_num = 0; + int i, delta, mindelta, mindelta_i; + char color_string[20]; + XColor xcolor; + + for (i = 0; i < mcolor_num; i ++){ + delta = abs(mcolor_val[i] - color); + if (!delta){ + face_color = mcolor[i]; + return; + } else { + if (mindelta < 0){ mindelta = delta; mindelta_i = i; } + else if (mindelta > delta) { mindelta = delta; mindelta_i = i; } + } + } + + /* If mcolor_num exceeds limit, choose the closest color */ + if (mcolor_num == M17N_MAX_CACHE) { + face_color = mcolor[mindelta_i]; + return; + } + + /* create new face */ + xcolor.pixel = color; + XQueryColor(display, colormap, &xcolor); + sprintf(color_string, "#%04X%04X%04X\0", xcolor.red, xcolor.green, xcolor.blue); + mcolor[mcolor_num] = mface(); + mcolor_val[mcolor_num] = color; + mface_put_prop(mcolor[mcolor_num], Mforeground, msymbol(color_string)); + face_color = mcolor[mcolor_num]; + mcolor_num ++; + return; +} + +char * +M17N_draw_fragment(state, p, len) + struct render_state *state; + u_char *p; + u_int len; +{ + static MFrame *drawframe; + static MFace *drawface; + static MPlist *plist; + MFace *faces[256]; + MText *mt; + MDrawGlyphInfo info; + MDrawMetric rect; + int ascent = 0, descent = 0, i, n; + char tmptext[10000]; + Bool flag_s, flag_c, flag_o; + + if (!drawface) drawface = mface(); + if (!plist){ + plist = mplist (); + mplist_add(plist, Mdisplay, display); + drawframe = mframe (plist); + } + M17N_set_size(char_size[caching]); + M17N_set_color(fore_color[caching]); + + if (len >= 10000) len = 9999; + strncpy(tmptext, p, len); + tmptext[len] = 0; + mt = M17N_gen_mtext(tmptext); + + /* check if the faces attached Mface are already cached */ + flag_s = flag_c = flag_o = True; + n = mtext_get_prop_values (mt, 0, Mface, (void **) faces, 256); + for (i = 0; i < n; i ++){ + if (faces[i] == face_size) flag_s = False; + if (faces[i] == face_color) flag_c = False; + if (faces[i] == face_other) flag_o = False; + } + + /* if faces are not cached, push them to Mface */ + if (flag_s) mtext_push_prop (mt, 0, mtext_len(mt), Mface, face_size); + if (flag_c) mtext_push_prop (mt, 0, mtext_len(mt), Mface, face_color); + if (flag_o) mtext_push_prop (mt, 0, mtext_len(mt), Mface, face_other); + if (lang) mtext_push_prop (mt, 0, mtext_len(mt), Mlanguage, lang); + + current_linewidth = state->width - state->leftfillpos / 2 - state->linewidth; + current_indent = state->leftfillpos; + + /* Compare the normal ascent/descent and the physical + ascent/descent of this M-text, and use the bigger ones. */ + mdraw_text_extents(drawframe, space, 0, 1, + &control, NULL, &rect, NULL); + ascent = - rect.y, descent = rect.height + rect.y; + mdraw_text_extents(drawframe, mt, 0, mtext_len(mt), + &control, &rect, NULL, NULL); + if (ascent < - rect.y) + ascent = - rect.y; + if (descent < rect.height + rect.y) + descent = rect.height + rect.y; + if (rect.width > 0) + state->brankline = 0; + + draw_line_itemsize(state, ascent, descent); + if (obj_new_mtext(state, state->linewidth, 0, mt, + drawframe, ascent, descent)){ + state->linewidth += rect.width; + return p + len; + } else + return NULL; +} + +void +M17N_draw_object(obj, target, x, y) + struct render_object *obj; + Drawable target; + int x, y; +{ + MFace *faces[256]; + int i, n; + + mdraw_text_with_control ( + obj->data.m17ntext.drawframe, + (MDrawWindow) target, x, y, + obj->data.m17ntext.mt, 0, + obj->data.m17ntext.len, &control); + + /* detach extra properties */ + n = mtext_get_prop_values (obj->data.m17ntext.mt, 0, Mface, (void **) faces, 256); + for (i = n; i > 3; i --){ + mtext_pop_prop (obj->data.m17ntext.mt, 0, + obj->data.m17ntext.len, Mface); + } +} + +void +M17N_draw_string(state, data) + struct render_state *state; + char *data; +{ + char *p = data; + char *registry = NULL; + int charset16 = 0; + + if (strlen(p)) + M17N_draw_fragment(state, p, strlen(p)); +} + +static void +M17N_format_line(line, y, indent, width) + int line, y, *indent, *width; +{ + *indent = 0; // we don't need to set this. + *width = current_linewidth; +} + + +#define M17NMAXKEY 3 +#define M17NMAXVAL 128 +void +M17N_process_direc(key, value) + char *key, *value; +{ + static u_char *mfontset_val[M17N_MAX_CACHE]; + static u_char *mfamily_val[M17N_MAX_CACHE]; + static MFace *mfontset_face[M17N_MAX_CACHE]; + static MFace *mfamily_face[M17N_MAX_CACHE]; + static int mfontset_num = 0; + static int mfamily_num = 0; + static MFace *last_used; + + char *keywords[M17NMAXKEY] = {"fontset", "family", "language"}; + int i; + + for (i = 0; i < M17NMAXKEY; i ++) { + if (!strcmp(key, keywords[i])) { + break; + } + } + switch(i){ + case 0: + for (i = 0; i < mfontset_num; i ++){ + if (strlen(mfontset_val[i]) == strlen(value) && + !(strcmp(mfontset_val[i], value))){ + face_other = mfontset_face[i]; + goto done; + } + } + if (mfontset_num == M17N_MAX_CACHE){ + face_other = mfontset_face[0]; // adhoc + goto done; + } + mfontset_face[mfontset_num] = mface(); + mface_put_prop (mfontset_face[mfontset_num], Mfontset, mfontset (value)); + face_other = mfontset_face[mfontset_num]; + mfontset_val[mfontset_num] = strdup(value); + mfontset_num ++; + goto done; + break; + case 1: + for (i = 0; i < mfamily_num; i ++){ + if (strlen(mfamily_val[i]) == strlen(value) && + !(strcmp(mfamily_val[i], value))){ + face_other = mfamily_face[i]; + goto done; + } + } + if (mfamily_num == M17N_MAX_CACHE){ + face_other = mfamily_face[0]; // adhoc + goto done; + } + mfamily_face[mfamily_num] = mface(); + mface_put_prop (mfamily_face[mfamily_num], Mfamily, msymbol (value)); + face_other = mfamily_face[mfamily_num]; + mfamily_val[mfamily_num] = strdup(value); + mfamily_num ++; + goto done; + break; + case 2: + lang = msymbol(value); + break; + default: + fprintf(stderr, "unknown keyword:%s for m17n-lib\n", key); + } +done: + last_used = face_other; + return; +} +#endif Index: kit/mgp.c diff -u kit/mgp.c:1.133 kit/mgp.c:1.134 --- kit/mgp.c:1.133 Mon Mar 15 22:03:33 2004 +++ kit/mgp.c Fri Jul 9 23:27:02 2004 @@ -26,7 +26,7 @@ * SUCH DAMAGE. */ /* - * $Id: mgp.c,v 1.133 2004/03/15 13:03:33 nishida Exp $ + * $Id: mgp.c,v 1.134 2004/07/09 14:27:02 nishida Exp $ */ static char *mgp_version = "1.10a (20030624)"; @@ -378,6 +378,8 @@ mgp_flag |= FL_NOFREETYPE; else if (strcmp(optarg, "xft") == 0) mgp_flag |= FL_NOXFT; + else if (strcmp(optarg, "m17n") == 0) + mgp_flag |= FL_NOM17N; else { fprintf(stderr, "unknown rendering engine %s\n", optarg); Index: kit/mgp.h diff -u kit/mgp.h:1.136 kit/mgp.h:1.137 --- kit/mgp.h:1.136 Mon Jun 14 19:23:26 2004 +++ kit/mgp.h Thu Jul 8 15:09:54 2004 @@ -26,7 +26,7 @@ * SUCH DAMAGE. */ /* - * $Id: mgp.h,v 1.136 2004/06/14 10:23:26 nishida Exp $ + * $Id: mgp.h,v 1.137 2004/07/08 06:09:54 nishida Exp $ */ #include @@ -62,12 +62,7 @@ #include #include #ifdef USE_XFT2 -#if 0 #include -#else -#include -#include FT_FREETYPE_H -#endif #include #include #ifdef HAVE_ICONV @@ -108,6 +103,12 @@ #undef TTY_KEYINPUT #endif +#ifdef USE_M17N +#include +#include +#include +#endif + #define DEFAULT_FORE "yellow" #define DEFAULT_BACK "black" #define PAGELIST_FONT "a14" @@ -186,6 +187,7 @@ #define FL_GLYPHEDGE 0x4000 #define FL_FRDCACHE 0x8000 #define FL_NOXFT 0x10000 +#define FL_NOM17N 0x20000 /* page attribute flags */ #define PGFLAG_NODEF 0x01 /* nodefault */ @@ -472,7 +474,10 @@ #endif /* MNG */ #ifdef USE_XFT2 O_XTFONT, -#endif /* MNG */ +#endif +#ifdef USE_M17N + O_M17NTEXT, +#endif O_ICON } type; u_long fore; @@ -517,6 +522,13 @@ int charset16; } xftfont; #endif +#ifdef USE_M17N + struct { + MText *mt; + MFrame *drawframe; + int len; + } m17ntext; +#endif } data; }; @@ -806,3 +818,14 @@ #define COLOR_BUGFIX #endif +#ifdef USE_M17N +void M17N_init __P((void)); +void M17N_set_size __P((int)); +void M17N_set_color __P((u_long)); +MText * M17N_gen_mtext __P((u_char *)); +void M17N_process_direc __P((char *, char *)); +void M17N_draw_string __P((struct render_state *, char *)); +char * M17N_draw_fragment __P((struct render_state *, u_char *, u_int)); +void M17N_draw_object __P((struct render_object *, Drawable, int, int)); +#endif + Index: kit/parse.c diff -u kit/parse.c:1.97 kit/parse.c:1.98 --- kit/parse.c:1.97 Mon May 24 18:57:49 2004 +++ kit/parse.c Thu Jul 8 15:09:54 2004 @@ -26,7 +26,7 @@ * SUCH DAMAGE. */ /* - * $Id: parse.c,v 1.97 2004/05/24 09:57:49 nishida Exp $ + * $Id: parse.c,v 1.98 2004/07/08 06:09:54 nishida Exp $ */ #include "mgp.h" @@ -974,6 +974,24 @@ tmpstr[5] = ctlalloc1(CTL_XFONT2); tmpstr[5]->ctc2_value1 = strdup("k14"); tmpstr[5]->ctc2_value2 = strdup("jisx0208.1983-*"); +#ifdef USE_M17N + tmpstr[6] = ctlalloc1(CTL_M17N); + tmpstr[6]->ctc2_value1 = strdup("fontset"); + tmpstr[6]->ctc2_value2 = strdup("default"); + tmpstr[7] = ctlalloc1(CTL_M17N); + tmpstr[7]->ctc2_value1 = strdup("family"); + tmpstr[7]->ctc2_value2 = strdup("default"); + tmpstr[8] = ctlalloc1(CTL_M17N); + tmpstr[8]->ctc2_value1 = strdup("language"); + tmpstr[8]->ctc2_value2 = strdup("default"); +#else + tmpstr[6] = ctlalloc1(CTL_NOOP); + tmpstr[6]->ctc_value = strdup(""); + tmpstr[7] = ctlalloc1(CTL_NOOP); + tmpstr[7]->ctc_value = strdup(""); + tmpstr[8] = ctlalloc1(CTL_NOOP); + tmpstr[8]->ctc_value = strdup(""); +#endif tmplong[0] = ctlalloc1(CTL_FORE); get_color(DEFAULT_FORE, &tmplong[0]->ctl_value); tmplong[1] = ctlalloc1(CTL_BACK); Index: kit/scanner.l diff -u kit/scanner.l:1.24 kit/scanner.l:1.25 --- kit/scanner.l:1.24 Fri Sep 12 11:04:55 2003 +++ kit/scanner.l Thu Jul 8 15:09:54 2004 @@ -27,7 +27,7 @@ * SUCH DAMAGE. */ /* - * $Id: scanner.l,v 1.24 2003/09/12 02:04:55 nishida Exp $ + * $Id: scanner.l,v 1.25 2004/07/08 06:09:54 nishida Exp $ */ /* * partly derived from lbl libpcap source code, which has the following @@ -169,6 +169,7 @@ (SUP|sup) return KW_SUP; (SUB|sub) return KW_SUB; (SETSUP|setsup) return KW_SETSUP; +(M17N|m17n) return KW_M17N; [ \n\t] ; Index: kit/x11.c diff -u kit/x11.c:1.31 kit/x11.c:1.32 --- kit/x11.c:1.31 Mon Mar 15 22:03:33 2004 +++ kit/x11.c Thu Jul 8 15:09:54 2004 @@ -26,7 +26,7 @@ * SUCH DAMAGE. */ /* - * $Id: x11.c,v 1.31 2004/03/15 13:03:33 nishida Exp $ + * $Id: x11.c,v 1.32 2004/07/08 06:09:54 nishida Exp $ */ #include "mgp.h" @@ -226,7 +226,7 @@ xsa.colormap = colormap; mask = CWBorderPixel | CWBackPixel | CWBackingStore | CWColormap; -#if 0 // this method is obsolute. we have to use WM_STATE_FULLSCREEN. +#if 1 // this method is old. we should use WM_STATE_FULLSCREEN. if (!(mgp_flag & FL_OVER)) { xsa.override_redirect = True; mask |= CWOverrideRedirect; @@ -349,6 +349,11 @@ if (!(mgp_flag & FL_OVER)) { toggle_fullscreen(); } + +#ifdef USE_M17N + /* initaiize M17N library */ + M17N_init(); +#endif } void Index: kit/image/gif.h diff -u kit/image/gif.h:1.2 kit/image/gif.h:removed --- kit/image/gif.h:1.2 Mon Dec 28 17:23:03 1998 +++ kit/image/gif.h Mon Jul 12 05:10:01 2004 @@ -1,72 +0,0 @@ -/* gif.h: - * - * gifin.h - * kirk johnson - * november 1989 - * external interface to gifin.c - * - * Copyright 1989 Kirk L. Johnson (see the included file - * "kljcpyrght.h" for complete copyright information) - */ - -/* - * gifin return codes - */ -#define GIFIN_SUCCESS 0 /* success */ -#define GIFIN_DONE 1 /* no more images */ - -#define GIFIN_ERR_BAD_SD -1 /* bad screen descriptor */ -#define GIFIN_ERR_BAD_SEP -2 /* bad image separator */ -#define GIFIN_ERR_BAD_SIG -3 /* bad signature */ -#define GIFIN_ERR_EOD -4 /* unexpected end of raster data */ -#define GIFIN_ERR_EOF -5 /* unexpected end of input stream */ -#define GIFIN_ERR_FAO -6 /* file already open */ -#define GIFIN_ERR_IAO -7 /* image already open */ -#define GIFIN_ERR_NFO -8 /* no file open */ -#define GIFIN_ERR_NIO -9 /* no image open */ - -/* - * colormap indices - */ - -#define GIF_RED 0 -#define GIF_GRN 1 -#define GIF_BLU 2 - -/* - * typedef BYTE for convenience - */ - -typedef unsigned char BYTE; - -static int gifin_open_file(); -static int gifin_open_image(); -static int gifin_get_pixel(); -#if 0 -static int gifin_close_image(); -#endif -static int gifin_close_file(); -static int gifin_load_cmap(); -static int gifin_skip_extension(); -static int gifin_read_data_block(); -static int gifin_push_string(); -static void gifin_add_string(); -static void gifin_fatal(); - -/* #defines, typedefs, and such - */ - -#define GIF_SIG "GIF87a" -#define GIF_SIG_89 "GIF89a" -#define GIF_SIG_LEN 6 /* GIF signature length */ -#define GIF_SD_SIZE 7 /* GIF screen descriptor size */ -#define GIF_ID_SIZE 9 /* GIF image descriptor size */ - -#define GIF_SEPARATOR ',' /* GIF image separator */ -#define GIF_EXTENSION '!' /* GIF extension block marker */ -#define GIF_TERMINATOR ';' /* GIF terminator */ - -#define STAB_SIZE 4096 /* string table size */ -#define PSTK_SIZE 4096 /* pixel stack size */ - -#define NULL_CODE -1 /* string table null code */ Index: kit/sample/cloud.gif Index: kit/sample/dad.gif Index: kit/sample/dns-jp.mgp diff -u kit/sample/dns-jp.mgp:1.5 kit/sample/dns-jp.mgp:removed --- kit/sample/dns-jp.mgp:1.5 Fri Sep 4 21:33:18 1998 +++ kit/sample/dns-jp.mgp Mon Jul 12 05:10:01 2004 @@ -1,130 +0,0 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% -%% This file is automatically created from the file -%% main.pre modified at Fri Jan 23 14:31:24 1998 -%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% -%include "default.mgp" -%% "noop" cancels definitions in default.mgp -%default 1 left, size 7, fore "light yellow", back "blue4", font "standard", ccolor "white", vgap 35 -%default 2 noop -%default 3 fore "white", bar "gray70", vgap 10 -%default 4 noop -%tab 1 noop -%tab 2 noop -%tab 3 noop -%%% -%page -%nodefault -%fore "red", back "blue4", size 9, vgap 15 -%center, fore "yellow", font "thick" -%ccolor "white" - - - -Root DNS `M' について - -%size 6, fore "red", font "thick" -加藤 朗 - -%size 5, fore "white", font "standard" -東京大学大型計算機センター - - -%font "typewriter" -kato@wide.ad.jp -%font "standard" -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%page - -%back "blue4" - 経緯 (1) -%fore "red", size 6, font "thick" - ☆ Root DNS -%fore "white", size 5, font "standard" - ・ 9台で運用 -%fore "white", size 5, font "standard" - − 8台が US - − Stockholm に1台 -%fore "white", size 5, font "standard" - ・ 最大で13台 -%fore "white", size 5, font "standard" - − パケット長の制約 -%fore "red", size 6, font "thick" - ☆ Root DNS の運用基準 -%fore "white", size 5, font "standard" - ・ RFC 2010 - ・ gTLD との関係 -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%page - -%back "blue4" - 経緯 (2) -%fore "red", size 6, font "thick" - ☆ IEPG で拡張を検討 - ☆ ヨーロッパ地域 -%fore "white", size 5, font "standard" - ・ LINX に新設 : 1997 年 4 月 -%fore "white", size 5, font "standard" - − RIPE/NCC が管理 - − `K' -%fore "red", size 6, font "thick" - ☆ アジア太平洋地域 -%fore "white", size 5, font "standard" - ・ NSPIXP-2 : 1997 年 8 月 -%fore "white", size 5, font "standard" - − WIDE が管理 - − `M' -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%page - -%back "blue4" - `M' -%fore "red", size 6, font "thick" - ☆ 構成 -%fore "white", size 5, font "standard" - ・ 2台の PentiumPro 200MHz - ・ Primary/Backup、 自動切り替え -%fore "red", size 6, font "thick" - ☆ Root-only サーバ -%fore "white", size 5, font "standard" - ・ -%cont, font "typewriter" -202.12.27.33 -%font "standard" - ・ 400 〜 500 query/sec -%fore "red", size 6, font "thick" - ☆ 運用管理 -%fore "white", size 5, font "standard" - ・ WIDE および ISP 有志 -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%page - -%back "blue4" - お願い -%fore "red", size 6, font "thick" - ☆ 最新の root.cache の入れ換え -%fore "white", size 5, font "standard" - ・ -%cont, font "typewriter" -1997082200 -%fore "red", size 6, font "thick" - ☆ Named の更新 -%fore "white", size 5, font "standard" - ・ 4.9.6/8.8.1 -%fore "red", size 6, font "thick" - ☆ 遊ばないで: -%fore "white", size 5, font "standard" - ・ -%cont, font "typewriter" -ping/traceroute -%font "standard" - ・ -%cont, font "typewriter" -telnet/spray/... -%fore "red", size 6, font "thick" - ☆ Thanks to -%fore "white", size 5, font "standard" - ・ 日本 Cisco/多くの ISP - ・ `M' 管理グループ Index: kit/sample/mgp-old1.gif Index: kit/sample/mgp-old2.gif Index: kit/sample/mgp-old3.gif Index: kit/sample/mgp1.gif Index: kit/sample/mgp2.gif Index: kit/sample/mgp3.gif Index: kit/sample/v6header.gif .