6895N/AComposite fonts support, needed for handling Japanese EUC-JP encoding
6895N/ARoughly based on Yasuyuki Furukawa's patch
6895N/A===================================================================
6895N/A===================================================================
6895N/A===================================================================
6895N/A ########################################################################
6895N/A # Some architectures specific char sets
6895N/A ########################################################################
6895N/A===================================================================
6895N/A+# Description of the EUC-JP encoding
6895N/A+# Copyright (c) 1988, 89, 90, 91, 92, 93 Miguel Santana
6895N/A+# Copyright (c) 1995, 96, 97, 98 Akim Demaille, Miguel Santana
6895N/A+# Copyright (c) 2003 Masayuki Hatta
6895N/A+# This program is free software; you can redistribute it
and/or modify
6895N/A+# it under the terms of the GNU General Public License as published by
6895N/A+# the Free Software Foundation; either version 2, or (at your option)
6895N/A+# This program is distributed in the hope that it will be useful,
6895N/A+# but WITHOUT ANY WARRANTY; without even the implied warranty of
6895N/A+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6895N/A+# GNU General Public License for more details.
6895N/A+# You should have received a copy of the GNU General Public License
6895N/A+# along with this program; see the file COPYING. If not, write to
6895N/A+# the Free Software Foundation, 59 Temple Place - Suite 330,
6895N/A+# Boston, MA 02111-1307, USA.
6895N/A+The EUC-JP encoding is a 8-bit character set widely used in Japan.
6895N/A+# If there is an unknown font requested, use Courier
6895N/A+# Automatic spell checking :)
6895N/A+Substitute: Times Times-Roman
6895N/A+Substitute: Helvetica-Italic Helvetica-Oblique
6895N/A+Substitute: Helvetica-BoldItalic Helvetica-BoldOblique
6895N/A+# SlantFont for Japanese Italic Kanji font
6895N/A+# new font source font value
6895N/A+SlantFont: Ryumin-Light-EUC-H-Italic Ryumin-Light-EUC-H 0.2
6895N/A+SlantFont: GothicBBB-Medium-EUC-H-Italic GothicBBB-Medium-EUC-H 0.2
6895N/A+# Compose fonts for Japanese EUC code
6895N/A+# target font additional font width size rate
6895N/A+DefaultComposite: Ryumin-Light-EUC-H 1.0 1.1
6895N/A+#DefaultComposite: Ryumin-Light-EUC-H 1.0 0.8333
6895N/A+#DefaultComposite: Ryumin-Light-EUC-H 1.0 1.6666
6895N/A+Composite: Helvetica GothicBBB-Medium-EUC-H 1.0 1.1
6895N/A+Composite: Helvetica-Oblique GothicBBB-Medium-EUC-H-Italic 1.0 1.1
6895N/A+Composite: Helvetica-Bold GothicBBB-Medium-EUC-H 1.0 1.1
6895N/A+Composite: Helvetica-BoldOblique GothicBBB-Medium-EUC-H-Italic 1.0 1.1
6895N/A+Composite: Courier-Oblique Ryumin-Light-EUC-H-Italic 1.0 1.1
6895N/A+Composite: Courier-Bold GothicBBB-Medium-EUC-H 1.0 1.1
6895N/A+Composite: Courier-BoldOblique GothicBBB-Medium-EUC-H-Italic 1.0 1.1
6895N/A+Composite: Times-Bold GothicBBB-Medium-EUC-H 1.0 1.1
6895N/A+.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
6895N/A+.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
6895N/A+.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
6895N/A+.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
6895N/A+space exclam quotedbl numbersign dollar percent ampersand quoteright
6895N/A+parenleft parenright asterisk plus comma minus period slash
6895N/A+zero one two three four five six seven
6895N/A+eight nine colon semicolon less equal greater question
6895N/A+X Y Z bracketleft backslash bracketright asciicircum underscore
6895N/A+x y z braceleft bar braceright asciitilde .notdef
6895N/A+.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
6895N/A+.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
6895N/A+.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
6895N/A+.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
6895N/A+space exclamdown cent sterling currency yen brokenbar section
6895N/A+dieresis copyright ordfeminine guillemotleft logicalnot hyphen registered macron
6895N/A+degree plusminus twosuperior threesuperior acute mu paragraph bullet
6895N/A+cedilla onesuperior ordmasculine guillemotright onequarter onehalf threequarters questiondown
6895N/A+Agrave Aacute Acircumflex Atilde Adieresis Aring AE Ccedilla
6895N/A+Egrave Eacute Ecircumflex Edieresis Igrave Iacute Icircumflex Idieresis
6895N/A+Eth Ntilde Ograve Oacute Ocircumflex Otilde Odieresis multiply
6895N/A+Oslash Ugrave Uacute Ucircumflex Udieresis Yacute Thorn germandbls
6895N/A+agrave aacute acircumflex atilde adieresis aring ae ccedilla
6895N/A+egrave eacute ecircumflex edieresis igrave iacute icircumflex idieresis
6895N/A+eth ntilde ograve oacute ocircumflex otilde odieresis divide
6895N/A+oslash ugrave uacute ucircumflex udieresis yacute thorn ydieresis
6895N/A===================================================================
6895N/A * Association of suffixes rules, and corresponding style sheet
6895N/A * (The hashing is upon `alias')
6895N/A+ int composite_flag; /* flag for composite font */
6895N/A uchar * documentation; /* Useful pieces of text */
6895N/A char * default_font; /* When a font can't be used
6895N/A struct pair_htable * substitutes; /*
e.g. in latin2, don't use
6895N/A * Courier, but Courier-Ogonki */
6895N/A+ struct pair_htable * composite;
6895N/A+ struct slantfont_info slantfont[NB_FACES];
6895N/A char * vector[256]; /* Define the char set */
6895N/A struct darray * font_names_used;
6895N/A struct hash_table_s * fonts; /* Contains cells that are
6895N/A * 1. name of font, 2. int wx[256] */
6895N/A unsigned int * faces_wx[NB_FACES];
6895N/A+ unsigned int composite_wx[NB_FACES]; /* fixed length font width */
6895N/A+ float composite_ratio[NB_FACES]; /* size ratio of additonal and original font */
6895N/A+ res->composite_flag = false;
6895N/A /* Vector will be set by setup */
6895N/A res->substitutes = pair_table_new ();
6895N/A+ res->composite = pair_table_new ();
6895N/A+ res->slantfont[0].name = NULL;
6895N/A res->font_names_used = da_new ("List of font names", 10,
6895N/A (da_print_func_t) da_str_print,
6895N/A+ * Add a composite font in the current encoding
6895N/A+encoding_add_composite_font (struct encoding * encoding,
6895N/A+ const char * orig, const char * subs,
6895N/A+ encoding->composite_flag = true;
6895N/A+ pair_add2 (encoding->composite, orig, subs, wx, ratio);
6895N/A+ * Add a composite font in the current encoding
6895N/A+encoding_add_slant_font (struct encoding * encoding,
6895N/A+ const char * new, const char * src,
6895N/A+ encoding->slantfont[num].name = strdup(new);
6895N/A+ encoding->slantfont[num].src = strdup(src);
6895N/A+ encoding->slantfont[num].ratio = ratio;
6895N/A+ encoding->slantfont[num+1].name = NULL;
6895N/A * When FONT_NAME is used with ENCODING, return the
6895N/A * real font name to use (
e.g., in latin2, Courier-Ogonki
6895N/A * should be returned when asked for Courier).
6895N/A+ (stderr, "In encoding %s, composite font for %s is resolved as %s\n",
6895N/A+ encoding->key, font_name, res));
6895N/A+ * Get composite font size and ratio
6895N/A+composite_font_info_get_wx(struct a2ps_job * job,
6895N/A+ struct encoding * encoding,
6895N/A+ astrcpy (font_list_copy, font_list);
6895N/A+ font_name = strtok (font_list_copy, ",<>;");
6895N/A+ wx = pair_get_wx (encoding->composite, font_name);
6895N/A+ wx = pair_get_wx (encoding->composite, "default_composite__");
6895N/A+composite_font_info_get_ratio(struct a2ps_job * job,
6895N/A+ struct encoding * encoding,
6895N/A+ astrcpy (font_list_copy, font_list);
6895N/A+ font_name = strtok (font_list_copy, ",<>;");
6895N/A+ ratio = pair_get_ratio (encoding->composite, font_name);
6895N/A+ ratio = pair_get_ratio (encoding->composite, "default_composite__");
6895N/A+encoding_resolve_composite_font (struct a2ps_job * job,
6895N/A+ struct encoding * encoding,
6895N/A+ astrcpy (font_list_copy, font_list);
6895N/A+ font_name = strtok (font_list_copy, ",<>;");
6895N/A+ /* Find if there is a substitute for that font */
6895N/A+ res = pair_get (encoding->composite, font_name);
6895N/A+ /* We've found nothing interesting. Last chance is the default
6895N/A+ res = pair_get (encoding->composite, "default_composite__");
6895N/A+ error (1, 0, "Cannot find font %s, nor any composite font",
6895N/A (stderr, "In encoding %s, font %s is resolved as %s\n",
6895N/A encoding->key, font_name, res));
6895N/A encoding_add_font_substitute (encoding, orig, subs);
6895N/A+ else if (strequ (token, "DefaultComposite:"))
6895N/A+ token2 = GET_TOKEN (NULL);
6895N/A+ token2 = GET_TOKEN (NULL);
6895N/A+ wx = (int)atof(token2)*1000;
6895N/A+ token2 = GET_TOKEN (NULL);
6895N/A+ encoding_add_composite_font(encoding, "default_composite__",
6895N/A+ else if (strequ (token, "Composite:"))
6895N/A+ token2 = GET_TOKEN (NULL);
6895N/A+ token2 = GET_TOKEN (NULL);
6895N/A+ token2 = GET_TOKEN (NULL);
6895N/A+ wx = (int)atof(token2)*1000;
6895N/A+ token2 = GET_TOKEN (NULL);
6895N/A+ encoding_add_composite_font(encoding, orig, subs, wx, ratio);
6895N/A+ else if (strequ (token, "SlantFont:"))
6895N/A+ token2 = GET_TOKEN (NULL);
6895N/A+ token2 = GET_TOKEN (NULL);
6895N/A+ token2 = GET_TOKEN (NULL);
6895N/A+ for (num = 0 ; encoding->slantfont[num].name ; num ++ );
6895N/A+ if (num > sizeof encoding->slantfont - 1){
6895N/A+ error_at_line (1, 0, fname, firstline,
6895N/A+ _("too many slant font: `%s'"), new);
6895N/A+ encoding_add_slant_font(encoding, new, src, ratio);
6895N/A error_at_line (1, 0, fname, firstline,
6895N/A _("invalid option `%s'"), quotearg (token));
6895N/A+ * Return the flag of composite flag
6895N/A+encoding_get_composite_flag (struct encoding * enc)
6895N/A+ return enc->composite_flag;
6895N/A * Prepare the environment (a dictionary) for the support
6895N/A * of ENCODING, dump it into STREAM.
6895N/A struct encoding * encoding)
6895N/A const char * real_font_name; /* After subsitution */
6895N/A char ** font_names = (char **) encoding->font_names_used->content;
6895N/A /* How many fonts are there? */
6895N/A da_qsort (encoding->font_names_used);
6895N/A da_unique (encoding->font_names_used, (da_map_func_t) free);
6895N/A * in the current ENCODING */
6895N/A nb = encoding->font_names_used->len;
6895N/A+ /* The number of slant fonts */
6895N/A+ for (i= 0, ns=0 ; encoding->slantfont[i].name ; i++ )
6895N/A /* Create the dictionary and fill it */
6895N/A fprintf (stream, "%% Dictionary for %s support\n",
6895N/A- fprintf (stream, "/%sdict %d dict begin\n", encoding->key, nb);
6895N/A+ fprintf (stream, "/%sdict %d dict begin\n", encoding->key,
6895N/A+ (encoding->composite_flag == true)? nb+nb+ns:nb+ns);
6895N/A fprintf (stream, " /f%s %sEncoding /%s reencode_font\n",
6895N/A encoding_resolve_font_substitute (job, encoding, font_names [i]));
6895N/A+ for (i = 0 ; encoding->slantfont[i].name ; i++ )
6895N/A+ fprintf (stream, " /%s /%s %f slantfont definefont pop\n",
6895N/A+ encoding->slantfont[i].name,
6895N/A+ encoding->slantfont[i].src,
6895N/A+ encoding->slantfont[i].ratio);
6895N/A+ * If kanji font size is larger than alphabet character,
6895N/A+ * set base font size to kanji charactor size.
6895N/A+ if (encoding->composite_flag == true) {
6895N/A+ for (i = 0 ; i < nb ; i++)
6895N/A+ fprintf (stream, " /f%s /f%s /%s %f %f false compositefont "
6895N/A+ encoding_resolve_composite_font (job, encoding, font_names [i]),
6895N/A+ encoding->composite_ratio[i],
6895N/A+ (encoding->composite_ratio[i] > 1.0)?
6895N/A+ 0: (1-encoding->composite_ratio[i])/2.0,
6895N/A+ (encoding->composite_ratio[i] > 1.0)?
6895N/A+ 1.0/encoding->composite_ratio[i]: 1.0 );
6895N/A fputs ("currentdict end def\n", stream);
6895N/A encoding->faces_wx [face]);
6895N/A+ if (encoding->composite_flag)
6895N/A+ encoding->composite_ratio[i] =
6895N/A+ composite_font_info_get_ratio(job, encoding,
6895N/A+ job->face_eo_font [face]);
6895N/A+ encoding->composite_wx[i] =
6895N/A+ composite_font_info_get_wx(job, encoding,
6895N/A+ job->face_eo_font [face]);
6895N/A+ /* If kanji font size is larger than alphabet character,
6895N/A+ fit kanji charactor size to base font size */
6895N/A+ if (encoding->composite_ratio[i] < 1.0)
6895N/A+ encoding->composite_wx[i] *= encoding->composite_ratio[i];
6895N/A+char_composite_WX (a2ps_job * job, uchar c)
6895N/A+ return (job->encoding->composite_wx[job->status->face]/
6895N/A+ job->encoding->composite_ratio[job->status->face]);
6895N/A * Returns the WX of a string (including M- and ^)
6895N/A===================================================================
6895N/A unsigned int char_WX PARAMS ((struct a2ps_job * job, uchar c));
6895N/A unsigned int string_WX PARAMS ((struct a2ps_job * job, uchar * string));
6895N/A+unsigned int char_composite_WX PARAMS ((struct a2ps_job * job, uchar c));
6895N/A /************************************************************************/
6895N/A int encoding_char_exists PARAMS ((struct encoding * enc,
6895N/A enum face_e face, uchar c));
6895N/A+int encoding_get_composite_flag (struct encoding * enc);
6895N/A get_encoding_by_alias PARAMS ((struct a2ps_job * job,
6895N/A PARAMS ((struct a2ps_job * job,
6895N/A struct encoding * encoding,
6895N/A+const char * encoding_resolve_composite_font
6895N/A+ PARAMS ((struct a2ps_job * job,
6895N/A+ struct encoding * encoding,
6895N/A * Have a struct encoding determine the faces_wx
6895N/A===================================================================
6895N/A+ * Add a pair, with your own allocation for them.
6895N/A+ * It KEY is yet used, override its value with VALUE
6895N/A+pair_add2 (struct hash_table_s * table,
6895N/A+ const char * key, const char * value, int wx, float ratio)
6895N/A+ struct pair * item, token;
6895N/A+ item = (struct pair *) hash_find_item (table, &token);
6895N/A+ item = XMALLOC (struct pair, 1);
6895N/A+ item->value = xstrdup (value);
6895N/A+ hash_insert (table, item);
6895N/A * Remove a pair and free it.
6895N/A * It KEY is yet used, override its value with VALUE
6895N/A+pair_get_wx (struct hash_table_s * table, const char * key)
6895N/A+ struct pair * item, token;
6895N/A+ item = (struct pair *) hash_find_item (table, &token);
6895N/A+pair_get_ratio (struct hash_table_s * table, const char * key)
6895N/A+ struct pair * item, token;
6895N/A+ item = (struct pair *) hash_find_item (table, &token);
6895N/A * Return the content of the hash table, ordered
6895N/A===================================================================
6895N/A void pair_add PARAMS ((struct pair_htable * table,
6895N/A const char * key, const char * value));
6895N/A+void pair_add2 PARAMS ((struct pair_htable * table,
6895N/A+ const char * key, const char * value,
6895N/A * The key and value of the matching item will be free'd
6895N/A * (No problem if KEY matches nothing)
6895N/A char * pair_get PARAMS ((struct pair_htable * table,
6895N/A+int pair_get_wx PARAMS ((struct pair_htable * table,
6895N/A+float pair_get_ratio PARAMS ((struct pair_htable * table,
6895N/A void pair_table_list_short PARAMS ((struct pair_htable * table,
6895N/A===================================================================
6895N/A job->status->face_declared = false;
6895N/A+ if (c > 127 && encoding_get_composite_flag (job->encoding) &&
6895N/A+ job->status->face != Symbol) {
6895N/A+ nchars = ps_escape_char (job, mb_flag, buf) +
6895N/A+ ps_escape_char (job, c, buf);
6895N/A+ job->status->wx += char_composite_WX(job, c);
6895N/A+ job->status->column += nchars;
6895N/A+ fold_line (job, new_face);
6895N/A+ job->status->column = nchars*2;
6895N/A+ job->status->wx = char_composite_WX(job, c);
6895N/A+ job->status->is_in_cut = true;
6895N/A nchars = ps_escape_char (job, c, buf);
6895N/A job->status->wx += char_WX (job, c);
6895N/A job->status->column += nchars;
6895N/A+ job->status->chars+=nchars;
6895N/A===================================================================
6895N/A % Return the y size of the current font
6895N/A- currentfont /FontMatrix get 3 get 1000 mul
6895N/A+ currentfont /FontType get 0 eq {
6895N/A+ currentfont /FontMatrix get 3 get
6895N/A+ currentfont /FontMatrix get 3 get 1000 mul
6895N/A+% composite fonts for ASCII-EUC mixed strings
6895N/A+% Original Ken'ichi HANDA (handa@etl.go.jp)
6895N/A+% Modified Norio Katayama (katayama@rd.nacsis.ac.jp),1998
6895N/A+% Extend & Fix Koji Nakamaru (maru@on.cs.keio.ac.jp), 1999
6895N/A+% Anyone can freely copy, modify, distribute this program.
6895N/A+/copyfont { % font-dic extra-entry-count copyfont font-dic
6895N/A+ 1 index maxlength add dict begin
6895N/A+ { 1 index /FID ne 2 index /UniqueID ne and
6895N/A+/compositefont { % ASCIIFontName EUCFontName RomanScale RomanOffset Rot(T/F) compositefont font
6895N/A+ userdict /fixeucfont_dict known not {
6895N/A+ /fixeucfont_dict 2 dict begin
6895N/A+ 16#00 1 16#20 { pop 0 } for
6895N/A+ 16#21 1 16#28 { 16#20 sub } for
6895N/A+ 16#29 1 16#2F { pop 0 } for
6895N/A+ 16#30 1 16#74 { 16#27 sub } for
6895N/A+ 16#75 1 16#FF { pop 0 } for
6895N/A+ 16#00 1 16#A0 { pop /.notdef } for
6895N/A+ 16#A1 1 16#FE { 16#80 sub 16 2 string cvrs
6895N/A+ findfont dup /FontType get 0 eq {
6895N/A+ /FontInfo (7+8 bit EUC font) readonly def
6895N/A+ /Encoding fixeucfont_dict /UpperByteEncoding get def
6895N/A+ { EUCFont /WMode get /WMode exch def }
6895N/A+ EUCFont /FDepVector get 0 get
6895N/A+ [ 16#21 1 16#28 {} for 16#30 1 16#74 {} for ]
6895N/A+ /UpperByte exch 16#80 add def
6895N/A+ /FontInfo (EUC lower byte font) readonly def
6895N/A+ fixeucfont_dict /LowerByteEncoding get def
6895N/A+ exch dup /EUCFont get setfont
6895N/A+ dup stringwidth setcharwidth
6895N/A+ /lowerbytefont exch definefont
6895N/A+ findfont 1 copyfont dup begin
6895N/A+ [ 0 RomanScale neg RomanScale 0 RomanOffset neg 0 ]
6895N/A+ [ RomanScale 0 0 RomanScale 0 RomanOffset ] matrix concatmatrix
6895N/A+ {pop pop pop pop 0 exch -1000 exch 2 div 880} def
6895N/A+ /asciifont exch definefont
6895N/A+ /FDepVector [ 4 2 roll ] def
6895N/A+% /FontHeight 1.0 def % XXXX
6895N/A+ /FontHeight RomanScale 1.0 ge { RomanScale }{ 1.0 } ifelse def
6895N/A+/slantfont { % FontName slant-degree slantfont font'
6895N/A+ exch findfont 1 copyfont begin
6895N/A+ [ 1 0 4 -1 roll 1 0 0 ] FontMatrix exch matrix concatmatrix
6895N/A % Function print line number (<string> # -)