freebsd-ports/chinese/enscript/files/patch-aa
Jing-Tang Keith Jang 995edaf768 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.
2000-11-27 18:00:45 +00:00

268 lines
7.5 KiB
Text

--- ./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 @@
ENC_VMS,
ENC_HP8,
ENC_KOI8,
- ENC_PS
+ ENC_PS,
+ ENC_BIG5,
+ ENC_UNICNS_UTF8,
} InputEncoding;
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 @@
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"));
@@ -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 @@
/* 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)
@@ -1473,8 +1486,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;
@@ -1624,6 +1641,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))
{
@@ -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 @@
* 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)
{
@@ -796,7 +804,7 @@
buf));
}
}
-
+
/* Apply encoding. */
switch (encoding)
{
@@ -879,6 +887,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. */
@@ -888,20 +902,57 @@
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;