head	1.2;
access;
symbols
	RELEASE_8_3_0:1.2
	RELEASE_9_0_0:1.2
	RELEASE_7_4_0:1.2
	RELEASE_8_2_0:1.2
	RELEASE_6_EOL:1.2
	RELEASE_8_1_0:1.2
	RELEASE_7_3_0:1.2
	RELEASE_8_0_0:1.2
	RELEASE_7_2_0:1.2
	RELEASE_7_1_0:1.2
	RELEASE_6_4_0:1.2
	RELEASE_5_EOL:1.2
	RELEASE_7_0_0:1.2
	RELEASE_6_3_0:1.2
	PRE_XORG_7:1.2
	RELEASE_4_EOL:1.2
	RELEASE_6_2_0:1.2
	RELEASE_6_1_0:1.2
	RELEASE_5_5_0:1.2
	RELEASE_6_0_0:1.2
	RELEASE_5_4_0:1.2
	RELEASE_4_11_0:1.2
	RELEASE_5_3_0:1.2
	RELEASE_4_10_0:1.1
	RELEASE_5_2_1:1.1
	RELEASE_5_2_0:1.1
	RELEASE_4_9_0:1.1
	RELEASE_5_1_0:1.1
	RELEASE_4_8_0:1.1
	RELEASE_5_0_0:1.1
	RELEASE_4_7_0:1.1
	RELEASE_4_6_2:1.1
	RELEASE_4_6_1:1.1
	RELEASE_4_6_0:1.1
	RELEASE_5_0_DP1:1.1
	RELEASE_4_5_0:1.1
	RELEASE_4_4_0:1.1
	RELEASE_4_3_0:1.1;
locks; strict;
comment	@# @;


1.2
date	2004.05.13.17.01.42;	author vanilla;	state Exp;
branches;
next	1.1;

1.1
date	2000.11.27.18.00.45;	author keith;	state Exp;
branches;
next	;


desc
@@


1.2
log
@Unbroken it, and assign MAINTAINER to submitter.

PR:		ports/66595
Submitted by:	Rong-En Fan <rafan_at_infor.org>
No Responsed:	keith@@
@
text
@diff -ruN src.orib/gsint.h src/gsint.h
--- src.orib/gsint.h	Thu May 13 12:41:04 2004
+++ src/gsint.h	Thu May 13 12:58:29 2004
@@@@ -190,7 +190,9 @@@@
   ENC_VMS,
   ENC_HP8,
   ENC_KOI8,
-  ENC_PS
+  ENC_PS,
+  ENC_BIG5,
+  ENC_UNICNS_UTF8,
 } InputEncoding;
 
 struct encoding_registry_st
diff -ruN src.orib/main.c src/main.c
--- src.orib/main.c	Thu May 13 12:41:04 2004
+++ src/main.c	Thu May 13 12:42:28 2004
@@@@ -817,6 +817,8 @@@@
   {{"koi8", NULL, NULL},		ENC_KOI8,		'\n', 8},
   {{"ps", "PS", NULL},			ENC_PS, 		'\n', 8},
   {{"pslatin1", "ISOLatin1Encoding", NULL},	ENC_ISO_8859_1,	'\n', 8},
+  {{"big5", "Formal Chinese", NULL},	ENC_BIG5,		'\n', 8},
+  {{"UniCNS-UTF8", "Formal Chinese", NULL},	ENC_UNICNS_UTF8,	'\n', 8},
 
   {{NULL, NULL, NULL}, 0, 0, 0},
 };
diff -ruN src.orib/psgen.c src/psgen.c
--- src.orib/psgen.c	Thu May 13 12:41:04 2004
+++ src/psgen.c	Thu May 13 12:53:07 2004
@@@@ -323,15 +323,21 @@@@
   if (!paste_file ("enscript", ".pro"))
     FATAL ((stderr, _("couldn't find prolog \"%s\": %s\n"), "enscript.pro",
 	    strerror (errno)));
+  if (encoding == ENC_BIG5 || encoding == ENC_UNICNS_UTF8) 
+    { /*overwrite the defintion of MF for CJK */
+      OUTPUT((cofp, "/MF {exch findfont definefont pop} def\n"));
+    }
   OUTPUT ((cofp, "%%%%EndResource\n"));
 
   /* Encoding vector. */
-  OUTPUT ((cofp, "%%%%BeginResource: procset Enscript-Encoding-%s %s\n",
-	   encoding_name, ps_version_string));
-  if (!paste_file (encoding_name, ".enc"))
-    FATAL ((stderr, _("couldn't find encoding file \"%s.enc\": %s\n"),
-	    encoding_name, strerror (errno)));
-  OUTPUT ((cofp, "%%%%EndResource\n"));
+  if (encoding != ENC_BIG5 && encoding != ENC_UNICNS_UTF8) {
+    OUTPUT ((cofp, "%%%%BeginResource: procset Enscript-Encoding-%s %s\n",
+	     encoding_name, ps_version_string));
+    if (!paste_file (encoding_name, ".enc"))
+      FATAL ((stderr, _("couldn't find encoding file \"%s.enc\": %s\n"),
+	      encoding_name, strerror (errno)));
+    OUTPUT ((cofp, "%%%%EndResource\n"));
+  }
 
   OUTPUT ((cofp, "%%%%EndProlog\n"));
 
@@@@ -1129,7 +1135,12 @@@@
 /* Help macros. */
 
 /* Check if character <ch> fits to current line. */
-#define FITS_ON_LINE(ch) ((linepos + CHAR_WIDTH (ch) < linew) || col == 0)
+/* NO wraping for CJK at this moment. Added by C.S. Chin Sept.1 */
+
+#define FITS_ON_LINE(ch) ( ( (encoding == ENC_BIG5 && b5firstc) ||\
+			     (encoding == ENC_UNICNS_UTF8 && u8firstc) ) ?\
+			     (linepos + 2 * CHAR_WIDTH (ch) < linew) :\
+			     (linepos + CHAR_WIDTH (ch) < linew || in_u8) )
 
 /* Is line buffer empty? */
 #define BUFFER_EMPTY() (bufpos == 0)
@@@@ -1594,8 +1605,12 @@@@
   static unsigned int buflen = 0; /* output buffer's length */
   unsigned int bufpos = 0;	/* current position in output buffer */
   int ch = 0;
+  int ch2 = 0;
   int done = 0;
   int i;
+  int b5firstc = 0;
+  int u8firstc = 0;
+  int in_u8 = 0;
   static int pending_token = tNONE;
   unsigned int original_col = col;
 
@@@@ -1745,6 +1760,39 @@@@
 	      break;
 	    }
 
+	  /*Check for big5 characters*/
+	  if (encoding == ENC_BIG5) 
+	    {
+	      if (ch >= 161 && ch <= 249 && b5firstc == 0) 
+		{
+		  ch2 = is_getc (is);
+		  if ((ch2 >= 161 && ch2 <=254) || (ch2 >=64 && ch2 <= 126)) /*big5 char*/
+		    {
+		      b5firstc = 1;
+		    } else {
+		      b5firstc = 0;
+		    }
+		  is_ungetc(ch2, is);
+		} else {
+		  b5firstc = 0;
+		}
+	    }
+
+	  /*Check for utf8 character*/
+	  if (encoding == ENC_UNICNS_UTF8)
+	    {
+	      if (ch >= 0340 && u8firstc==0) {
+		u8firstc = 1;
+	      } else {
+		u8firstc = 0;
+	      }
+	      if (ch >= 0200) {
+		in_u8 = 1;
+	      } else {
+		in_u8 = 0;
+	      }
+	    }
+	  
 	  /* Check normal characters. */
 	  if (EXISTS (ch))
 	    {
diff -ruN src.orib/util.c src/util.c
--- src.orib/util.c	Thu May 13 12:41:04 2004
+++ src/util.c	Thu May 13 12:56:31 2004
@@@@ -890,11 +890,18 @@@@
 	       * Do not report failures for "Courier*" fonts because
 	       * AFM library's default font will fix them.
 	       */
-	      if (strncmp (Fname, COUR, strlen (COUR)) != 0)
-		MESSAGE (0,
-			 (stderr,
-			  _("couldn't open AFM file for font \"%s\", using default\n"),
-			  Fname));
+	      if (strncmp (Fname, COUR, strlen (COUR)) != 0) {
+		if (encoding == ENC_BIG5 || encoding == ENC_UNICNS_UTF8) 
+		  { MESSAGE(0, 
+			    (stderr, 
+			     _("CJK encoding, ignore AFM file, use default.\n"),Fname));
+		  } else {
+		    MESSAGE (0,
+			     (stderr,
+			      _("couldn't open AFM file for font \"%s\", using default\n"),
+			      Fname));
+		  }
+	      }
 	      error = afm_open_default_font (afm, &font);
 	      if (error != AFM_SUCCESS)
 		{
@@@@ -997,6 +1004,12 @@@@
 	    case ENC_PS:
 	      /* Let's use font's default encoding -- nothing here. */
 	      break;
+            case ENC_BIG5:
+              /* CJK encoding, ignore AFM, added by C.S.Chin Aug.31 00 */
+              break;
+            case ENC_UNICNS_UTF8:
+              /* CJK encoding, ignore AFM, added by C.S.Chin Aug.31 00 */
+              break;
 	    }
 
 	  /* Put it to the AFM cache. */
@@@@ -1006,20 +1019,56 @@@@
 
       font_info = (CachedFontInfo *) xcalloc (1, sizeof (*font_info));
       /* Read character widths and types. */
-      for (i = 0; i < 256; i++)
-	{
-	  AFMNumber w0x, w0y;
-
-	  (void) afm_font_charwidth (font, Fpt.w, i, &w0x, &w0y);
-	  font_info->font_widths[i] = w0x;
-
-	  if (font->encoding[i] == AFM_ENC_NONE)
-	    font_info->font_ctype[i] = ' ';
-	  else if (font->encoding[i] == AFM_ENC_NON_EXISTENT)
-	    font_info->font_ctype[i] = '.';
-	  else
-	    font_info->font_ctype[i] = '*';
-	}
+      if (encoding != ENC_BIG5 && encoding != ENC_UNICNS_UTF8) {
+        for (i = 0; i < 256; i++)
+	  {
+	    AFMNumber w0x, w0y;
+
+	    (void) afm_font_charwidth (font, Fpt.w, i, &w0x, &w0y);
+	    font_info->font_widths[i] = w0x;
+
+	    if (font->encoding[i] == AFM_ENC_NONE)
+	      font_info->font_ctype[i] = ' ';
+	    else if (font->encoding[i] == AFM_ENC_NON_EXISTENT)
+	      font_info->font_ctype[i] = '.';
+	    else
+	      font_info->font_ctype[i] = '*';
+	  }
+       } else {
+	if (encoding == ENC_BIG5) 
+	  {
+	    for (i = 0; i < 256; i++)
+	      {
+		AFMNumber w0x, w0y;
+		if ( i < 040 ) 
+		  {
+		    font_info->font_widths[i] = Fpt.w * 0.525;
+		    font_info->font_ctype[i] = ' ';
+		  } else {
+		    font_info->font_widths[i] = Fpt.w * 0.525;
+		    font_info->font_ctype[i] = '*';
+		  }
+	      }
+	  } else {
+	    /*UTF8*/
+	    for (i = 0; i < 256; i++)
+	      {
+		AFMNumber w0x, w0y;
+		if ( i < 040 ) 
+		  {
+		    font_info->font_widths[i] = Fpt.w * 0.525;
+		    font_info->font_ctype[i] = ' ';
+		  } else {
+		    if (i >= 0200) {
+		      font_info->font_widths[i] = Fpt.w * 0.525 * 2.0 / 3.0;
+		    } else {
+		      font_info->font_widths[i] = Fpt.w * 0.525;
+		    }
+		    font_info->font_ctype[i] = '*';
+		  }
+	      }
+	  }
+       }
 
       font_info->font_is_fixed
 	= font->writing_direction_metrics[0].IsFixedPitch;
@


1.1
log
@Initial version.

This port adds Chinese support to enscript, which means it can convert
a BIG5/CNS plain text to a PS document, with all the fancy features
provided by enscript.  Unlike bg5ps, it can't manage GB yet, but it's
easy to add.  Another useful feature is with the ps2pdf and zh-ghostscript6,
it is now possible to generate font-embedded Chinese pdf document from
plain text on the fly, which also means platform-independent.

Due to some problems in the CMap files provided by Adobe, Eten-B5-H and
B5-H CMaps are unable to map correct ascii glyphs in TTFs.  BIG5 users
are suggested to use B5pc-H for the time being.

Maybe it's time to re-organize ports/chinese/* font relationships.
@
text
@d1 4
a4 3
--- ./src/gsint.h.orig	Thu Jun 25 15:18:32 1998
+++ ./src/gsint.h	Mon Nov 27 22:18:18 2000
@@@@ -188,7 +188,9 @@@@
d14 17
a30 16
 typedef enum
--- ./src/main.c.orig	Thu Jun 25 16:26:00 1998
+++ ./src/main.c	Mon Nov 27 22:18:18 2000
@@@@ -864,7 +864,8 @@@@
     {{"koi8", NULL, NULL},		ENC_KOI8,		'\n', 8},
     {{"ps", "PS", NULL},		ENC_PS, 		'\n', 8},
     {{"pslatin1", "ISOLatin1Encoding", NULL},	ENC_ISO_8859_1,	'\n', 8},
-
+    {{"big5", "Formal Chinese", NULL},  ENC_BIG5,               '\n', 8},
+    {{"UniCNS-UTF8", "Formal Chinese", NULL}, ENC_UNICNS_UTF8,  '\n', 8},      
     {{NULL, NULL, NULL}, 0, 0, 0},
   };
 
--- ./src/psgen.c.orig	Thu Jun 25 15:18:54 1998
+++ ./src/psgen.c	Mon Nov 27 22:18:18 2000
@@@@ -303,15 +303,22 @@@@
d54 1
a54 2
+  } 
+    
d58 1
a58 9
@@@@ -339,6 +346,7 @@@@
   /* Select our fonts. */
 
   /* Header font HF. */
+  
   OUTPUT ((cofp, "/%s /HF-gs-font MF\n", HFname));
   OUTPUT ((cofp,
 	   "/HF /HF-gs-font findfont [HFpt_w 0 0 HFpt_h 0 0] makefont def\n"));
@@@@ -1033,7 +1041,12 @@@@
d63 1
a63 1
+/* NO wraping for CJK at this moment. Added by C.S. Chin Sept.1 */ 
d66 3
a68 3
+                             (encoding == ENC_UNICNS_UTF8 && u8firstc) ) ?\
+                             (linepos + 2 * CHAR_WIDTH (ch) < linew) :\
+                             (linepos + CHAR_WIDTH (ch) < linew || in_u8) )
d72 1
a72 1
@@@@ -1473,8 +1486,12 @@@@
d85 1
a85 1
@@@@ -1624,6 +1641,39 @@@@
d125 4
a128 20
@@@@ -1741,7 +1791,7 @@@@
   /* Got a string. */
 
   /* Check for wrapped line. */
-  if (done == DONE_WRAP)
+  if (done == DONE_WRAP) 
     {
       /* This line is too long. */
       ch = nl;
--- ./src/util.c.orig	Wed Jun 24 14:48:21 1998
+++ ./src/util.c	Mon Nov 27 22:18:18 2000
@@@@ -774,6 +774,7 @@@@
       if (!strhash_get (afm_cache, Fname, strlen (Fname), (void **) &font))
 	{
 	  /* AFM file was not cached, open it from disk. */
+	  
 	  error = afm_open_font (afm, AFM_I_COMPOSITES, Fname, &font);
 	  if (error != AFM_SUCCESS)
 	    {
@@@@ -782,11 +783,18 @@@@
d152 1
a152 10
@@@@ -796,7 +804,7 @@@@
 			  buf));
 		}
 	    }
-
+	    
 	  /* Apply encoding. */
 	  switch (encoding)
 	    {
@@@@ -879,6 +887,12 @@@@
d165 1
a165 1
@@@@ -888,20 +902,57 @@@@
d198 1
a198 1
+      } else {
d232 1
a232 2
+      }
+
@

