src/cmd/mp/pcf.c
author hnhn
Wed, 08 Oct 2008 12:13:30 +0200
changeset 294 9f7722099844
parent 0 542988ea726d
permissions -rw-r--r--
6754368: mp.conf patch for OpenSolaris
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
     1
/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
     2
 * CDDL HEADER START
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
     3
 *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").  
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
     7
 *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
     8
 * You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    11
 * and limitations under the License.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    12
 *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    14
 * file and include the License file at src/OPENSOLARIS.LICENSE.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    18
 *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    19
 * CDDL HEADER END
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    20
 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    21
/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    22
 * Copyright (c) 1999 by Sun Microsystems, Inc.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    23
 * All rights reserved.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    24
 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    25
/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    26
 * Copyright (C) 1994 X Consortium
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    27
 *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    28
 * Permission is hereby granted, free of charge, to any person obtaining a copy
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    29
 * of this software and associated documentation files (the "Software"), to
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    30
 * deal in the Software without restriction, including without limitation the
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    31
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    32
 * sell copies of the Software, and to permit persons to whom the Software is
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    33
 * furnished to do so, subject to the following conditions:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    34
 *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    35
 * The above copyright notice and this permission notice shall be included in
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    36
 * all copies or substantial portions of the Software.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    37
 *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    38
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    39
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    40
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    41
 * X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    42
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    43
 * TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    44
 *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    45
 * Except as contained in this notice, the name of the X Consortium shall not
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    46
 * be used in advertising or otherwise to promote the sale, use or other deal-
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    47
 * ings in this Software without prior written authorization from the X Consor-
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    48
 * tium.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    49
 *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    50
 * X Window System is a trademark of X Consortium, Inc.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    51
 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    52
#pragma ident   "@(#)pcf.c	1.3 00/02/02 SMI"
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    53
#include <stdio.h>
294
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
    54
#include <fcntl.h>
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
    55
#include <unistd.h>
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
    56
#include <string.h>
0
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    57
#include <X11/Xmd.h>
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    58
#include <assert.h>
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    59
#include <errno.h>
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    60
#include "general_header.h"
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    61
#include "print_preprocess.h"
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    62
#include "pcf_private.h"
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    63
#include "pcf.h"
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    64
#define pcfGetINT8(file, format) (position++, FontFileGetc(file))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    65
#define FileDes(f)  ((int) (f)->private)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    66
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    67
extern print_info	*print_info_st;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    68
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    69
static void dump_Fmetrics(pcffont_t *);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    70
static code_int getcode(CompressedFile *);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    71
static int BufFileClose(BufFilePtr,int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    72
static int get_font_property(FontPtr, char *, ulong_t *);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    73
static BufFilePtr BufFileCreate ( char *, int (*)(), int (*)(),int (*)() );
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    74
static int BufCompressedClose(BufFilePtr, int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    75
static int BufCompressedSkip(BufFilePtr, int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    76
static int BufCompressedFill(BufFilePtr);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    77
static BufFilePtr BufFilePushCompressed(BufFilePtr);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    78
static FontFilePtr FontFileOpen(char *);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    79
static void FontFileClose (FontFilePtr);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    80
static int pcfGetLSB32(FontFilePtr);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    81
static PCFTablePtr pcfReadTOC(FontFilePtr,int*);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    82
static Bool pcfGetProperties(FontInfoPtr,FontFilePtr, PCFTablePtr, int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    83
static void pcfGetCompressedMetric(FontFilePtr,CARD32, xCharInfo*);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    84
static Bool pcfSeekToType(FontFilePtr, PCFTablePtr, int, CARD32, CARD32*, CARD32*);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    85
static int pcfGetINT16(FontFilePtr, CARD32);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    86
static int pcfGetINT32(FontFilePtr, CARD32);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    87
static Bool pcfGetAccel(FontInfoPtr, FontFilePtr, PCFTablePtr, int, CARD32);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    88
static void pcfGetMetric(FontFilePtr, CARD32, xCharInfo *);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    89
static int pcfReadFont(FontPtr, FontFilePtr, int, int, int, int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    90
static char *NameForAtom(Atom);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    91
static BufFilePtr BufFileOpenRead(int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    92
static int BufFileRawFill(BufFilePtr);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    93
static int BufFileRawSkip(BufFilePtr, int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    94
static int BufFileRawClose (BufFilePtr, int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    95
static int bitmapGetGlyphs(FontPtr, unsigned long, unsigned char *, FontEncoding , unsigned long * , CharInfoPtr *);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    96
static int bitmapGetMetrics(FontPtr, unsigned long, unsigned char *, FontEncoding, unsigned long *, xCharInfo **);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    97
static void pcfUnloadFont(FontPtr);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    98
static int handle_cuferr(int , ucs4_t *, int *);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
    99
static int handle_illegalchar(ucs4_t *, int *);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   100
static int handle_nonidentchar(ucs4_t *, int *);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   101
static int handle_nobitmap(ucs4_t *, pcffont_t *, pcf_charmet_t *, pcf_bm_t **) ;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   102
static int handle_nongraphchar(ucs4_t *, int *);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   103
static pcf_bm_t * xpcf_getcbm(int , pcffont_t *, pcf_charmet_t *);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   104
static void BitOrderInvert(unsigned char *, int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   105
static Bool pcfHasType ( PCFTablePtr, int, CARD32);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   106
static void TwoByteSwap(unsigned char *, int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   107
static void FourByteSwap(unsigned char *, int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   108
static int RepadBitmap(char *, char *, unsigned int, unsigned int, int, int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   109
static Atom MakeAtom(char *, unsigned, int );
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   110
static Bool ResizeReverseMap ();
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   111
static NameEqual (char *, char *,int );
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   112
static Hash(char *, int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   113
static ResizeHashTable();
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   114
static void put_PSbitmap(ucs4_t , pcf_bm_t *, pcf_charmet_t *, pcf_SCcharmet_t *);
294
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
   115
static int gzcatfile(char *);
0
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   116
void init_putPS(void);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   117
unsigned long * Xrealloc(unsigned long   *, int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   118
unsigned long * Xalloc(int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   119
int BufFileRead (BufFilePtr, char *, int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   120
void pcf_postscript(ucs4_t c, pcf_bm_t *, pcf_charmet_t *, pcf_SCcharmet_t *);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   121
int pres_pcfbm(ucs4_t *, pcffont_t *, pcf_bm_t **, pcf_charmet_t *, pcf_SCcharmet_t *, int);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   122
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   123
double SPACINGwidth = -1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   124
ucs4_t SPACINGchar = (ucs4_t) 0x20;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   125
ucs4_t REFERENCEchar = (ucs4_t) 0x20;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   126
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   127
extern pcffont_t *pcf_fonts;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   128
extern pcffont_t	*CurrentFont;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   129
static int position;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   130
static CharInfoRec nonExistantChar;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   131
static AtomListPtr  *hashTable;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   132
static int          hashMask;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   133
static int          hashSize, hashUsed;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   134
static int          hashMask;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   135
static int          rehash;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   136
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   137
/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   138
static ucs4_t	pcf_bmap[4][UCS4_MAXVAL/sizeof(ucs4_t)];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   139
static int dictcnt = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   140
*/
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   141
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   142
static unsigned char _reverse_byte[0x100] = {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   143
	0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   144
	0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   145
	0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   146
	0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   147
	0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   148
	0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   149
	0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   150
	0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   151
	0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   152
	0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   153
	0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   154
	0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   155
	0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   156
	0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   157
	0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   158
	0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   159
	0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   160
	0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   161
	0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   162
	0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   163
	0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   164
	0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   165
	0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   166
	0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   167
	0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   168
	0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   169
	0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   170
	0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   171
	0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   172
	0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   173
	0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   174
	0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   175
};
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   176
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   177
static void
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   178
put_PSbitmap(ucs4_t code, pcf_bm_t *bitmap, 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   179
	pcf_charmet_t *Cmetrics, pcf_SCcharmet_t *Smetrics)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   180
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   181
    int j;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   182
    int k;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   183
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   184
    if (bitmap == NULL)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   185
	return;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   186
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   187
    fprintf(stdout,"/C%x { GR %.2f %.2f S %d %d T [%d 0 0 -%d 0 %d]\n\t{<", 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   188
    	    code,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   189
    	    Smetrics->widthBits, Smetrics->height,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   190
    	    Cmetrics->widthBits, Cmetrics->height,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   191
    	    Cmetrics->widthBits, Cmetrics->height,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   192
    	    Cmetrics->ascent);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   193
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   194
    k = Cmetrics->widthBytes * Cmetrics->height;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   195
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   196
#ifdef SDEBUG
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   197
	fprintf(stderr, "%d is -------Cmetrics->widthBytes for :C%x \n", Cmetrics->widthBytes, code);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   198
	fprintf(stderr, "%d is -------Cmetrics->height for :C%x \n", Cmetrics->height, code);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   199
	fprintf(stderr, "%d is ------ no. of glyph elems for:C%x \n", k, code);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   200
#endif
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   201
    for (j = 0; j < k; j++)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   202
	fprintf(stdout,"%.2x", bitmap[j]);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   203
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   204
    fprintf(stdout,">} IG } def\n"); 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   205
    fprintf(stdout,"C%x\n", code);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   206
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   207
    /*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   208
    dictcnt++;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   209
    */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   210
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   211
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   212
pcf_SCcharmet_t *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   213
get_SCmetrics(ucs4_t val)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   214
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   215
	int ndx;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   216
	ucs4_t v;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   217
	pcf_bm_t *bm;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   218
	pcf_charmet_t cm;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   219
	static pcf_SCcharmet_t sm;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   220
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   221
	/* map ucs4 val to a 'pcf_fonts' array index */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   222
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   223
	v = val;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   224
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   225
	if ((ndx = presform_fontndx(val)) == XU_UCS4UNDEF) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   226
		return NULL;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   227
	} else if ((pcf_ret <= -1 ) || ( pres_pcfbm(&v, &pcf_fonts[ndx], &bm, &cm, &sm, 1) < 0)) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   228
		return NULL;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   229
	} else if (v != val) {	/* return NULL if val got mapped to */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   230
				/* another character */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   231
		return NULL; 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   232
	} else {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   233
		return &sm;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   234
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   235
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   236
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   237
void
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   238
init_putPS(void)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   239
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   240
    pcf_SCcharmet_t *sm;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   241
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   242
    if ((sm = get_SCmetrics(REFERENCEchar)) \
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   243
		|| (sm = get_SCmetrics(SPACINGchar))) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   244
		SPACINGwidth = sm->origin_xoff;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   245
	} else SPACINGwidth = (float)SPACE_WIDTH_PER_PTSZ * current_pt_sz;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   246
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   247
void
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   248
pcf_postscript(ucs4_t c, pcf_bm_t *pcfbm, 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   249
    	pcf_charmet_t *Cmetrics, pcf_SCcharmet_t *scCmetrics)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   250
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   251
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   252
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   253
    put_PSbitmap(c, pcfbm, Cmetrics, scCmetrics);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   254
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   255
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   256
int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   257
load_pcf_font(pcffont_t *font)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   258
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   259
    FontRec fr;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   260
    FontInfoPtr fi;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   261
    FontFilePtr ff;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   262
    ulong_t value;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   263
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   264
    if ((ff = FontFileOpen(font->file)) == NULL)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   265
        return -1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   266
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   267
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   268
    if (pcfReadFont(&fr, ff, MSBFirst, MSBFirst, 1, 1) != Successful)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   269
    	return -1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   270
    fi = &(fr.info);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   271
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   272
    font->Fmetrics.ascent = fi->fontAscent;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   273
    font->Fmetrics.descent = fi->fontDescent;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   274
    font->Fmetrics.linespace = fi->fontAscent + fi->fontDescent;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   275
    font->Fmetrics.firstchar = (fi->firstRow * 256) + fi->firstCol;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   276
    font->Fmetrics.lastchar = (fi->lastRow * 256) + fi->lastCol;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   277
    font->Fmetrics.lastCol = fi->lastCol;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   278
    font->Fmetrics.firstCol = fi->firstCol;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   279
    
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   280
    font->bitmaps = ((BitmapFontPtr)(fr.fontPrivate))->encoding;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   281
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   282
    if (get_font_property(&fr, "POINT_SIZE", &value) == -1)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   283
    	return -1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   284
    font->Fmetrics.ptsz = (int) value;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   285
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   286
    if (get_font_property(&fr, "RESOLUTION_X", &value) == -1)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   287
    	return -1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   288
    font->Fmetrics.Xres = (int) value;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   289
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   290
    if (get_font_property(&fr, "RESOLUTION_Y", &value) == -1)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   291
    	return -1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   292
    font->Fmetrics.Yres = (int) value;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   293
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   294
#ifdef SDEBUG
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   295
    fprintf(stderr,"Fmetrics: ascent:%d, descent:%d, linespace:%d, "
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   296
	"ptsz:%d, Xres:%d, Yres:%d\n", font->Fmetrics.ascent, font->Fmetrics.descent,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   297
	(&(font->Fmetrics))->linespace, (&(font->Fmetrics))->ptsz, (&(font->Fmetrics))->Xres, (&(font->Fmetrics))->Yres);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   298
#endif
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   299
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   300
    debug(dump_Fmetrics(&(font->Fmetrics)));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   301
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   302
    FontFileClose(ff);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   303
    return 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   304
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   305
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   306
void
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   307
scaling_factors(pcffont_t *font, double ptsz, int Xres, int Yres)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   308
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   309
    font->Yscale = ((ptsz * (double)Yres) 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   310
	/ ((double)font->Fmetrics.ptsz * (double)font->Fmetrics.Xres));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   311
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   312
    font->Xscale = ((((double)Xres * (double)font->Fmetrics.Yres)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   313
	/ ((double)Yres * (double)font->Fmetrics.Xres))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   314
	    * (font->Yscale));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   315
#if 0
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   316
    if (xsflag == OPTARG_SET)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   317
    	font->Xscale = xs_argval;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   318
    else if (xsflag == OPTARG_ADD)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   319
    	font->Xscale += xs_argval;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   320
    else if (xsflag == OPTARG_SUB) 	/* for clarity, we subract a positive */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   321
    	font->Xscale -= xs_argval; 	/* rather than add a negative. */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   322
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   323
    if (ysflag == OPTARG_SET)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   324
    	font->Yscale = ys_argval;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   325
    else if (ysflag == OPTARG_ADD)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   326
    	font->Yscale += ys_argval;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   327
    else if (ysflag == OPTARG_SUB)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   328
    	font->Yscale -= ys_argval;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   329
#endif
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   330
#ifdef SDEBUG
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   331
	fprintf(stderr,"%f -- font->Yscale\n %f -- font->Xscale\n", font->Yscale, font->Xscale);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   332
#endif
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   333
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   334
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   335
void
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   336
scale_Fmetrics(pcffont_t *font) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   337
	font->scFmetrics.ascent = font->Fmetrics.ascent * font->Yscale;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   338
	font->scFmetrics.descent = font->Fmetrics.descent * font->Yscale;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   339
	font->scFmetrics.linespace = font->Fmetrics.linespace * font->Yscale;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   340
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   341
#ifdef SDEBUG
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   342
fprintf(stderr,"%f font->scFmetrics.ascent\n \
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   343
%f font->scFmetrics.descent\n\
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   344
%f font->scFmetrics.linespace\n", font->scFmetrics.ascent, font->scFmetrics.descent, font->scFmetrics.linespace);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   345
#endif
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   346
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   347
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   348
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   349
void
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   350
scale_Cmetrics(pcf_charmet_t *Cm, pcf_SCcharmet_t *Sm)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   351
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   352
	Sm->width = Cm->width * CurrentFont->Xscale;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   353
	Sm->height = Cm->height * CurrentFont->Yscale;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   354
	Sm->widthBits = Cm->widthBits * CurrentFont->Xscale;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   355
	Sm->ascent = Cm->ascent * CurrentFont->Yscale;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   356
	Sm->descent = Cm->descent * CurrentFont->Yscale;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   357
	Sm->origin_xoff = Cm->origin_xoff * CurrentFont->Xscale;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   358
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   359
#ifdef SDEBUG
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   360
	fprintf(stderr, "%f is CurrentFont->Xscale\n", CurrentFont->Xscale);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   361
	fprintf(stderr, "%f is CurrentFont->Yscale\n", CurrentFont->Yscale);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   362
	fprintf(stderr, "%d is Cm->widthBits\n", Cm->widthBits);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   363
	fprintf(stderr, "%d is Cm->height\n", Cm->height);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   364
	fprintf(stderr, "%f is Sm->widthBits\n", Sm->widthBits);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   365
	fprintf(stderr, "%f is Sm->height\n", Sm->height);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   366
#endif
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   367
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   368
	/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   369
	debug(dump_scCmetrics(Sm));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   370
	*/
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   371
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   372
int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   373
pres_pcfbm(ucs4_t *val, pcffont_t *font, pcf_bm_t **bitmap,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   374
    	pcf_charmet_t *Cmetrics, pcf_SCcharmet_t *scCmetrics, int dontcache)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   375
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   376
	int fv;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   377
	ucs4_t v;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   378
#if SDEBUG
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   379
	fprintf(stderr, "0x%08x -- ucs4val \n", *val);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   380
#endif
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   381
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   382
	v = *val;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   383
	if (is_motion_char(v)) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   384
		*bitmap = NULL;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   385
		return XU_MOTION_CHAR;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   386
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   387
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   388
	if (non_graphic_char(v)) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   389
		int ndx;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   390
		if ((fv = handle_nongraphchar(&v, &ndx)) == XU_IGNORE) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   391
			return XU_IGNORE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   392
		} else {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   393
			font = &pcf_fonts[ndx];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   394
			CurrentFont = font;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   395
		}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   396
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   397
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   398
	if ((fv = font->cuf(v)) < 0) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   399
		int ndx;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   400
		if ((fv = handle_cuferr(fv, &v, &ndx)) == XU_IGNORE) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   401
			return XU_IGNORE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   402
		} else {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   403
			font = &pcf_fonts[ndx];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   404
			CurrentFont = font;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   405
		}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   406
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   407
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   408
	if ((*bitmap = (pcf_bm_t *)xpcf_getcbm(fv, font, Cmetrics)) == NULL) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   409
		if (handle_nobitmap(&v, font, Cmetrics, bitmap) == XU_IGNORE)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   410
			return XU_IGNORE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   411
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   412
#if SDEBUG
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   413
	fprintf(stderr, "0x%02x -- **bitmap \n", (unsigned char)**bitmap);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   414
#endif
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   415
	*val = v;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   416
	scale_Cmetrics(Cmetrics, scCmetrics);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   417
	return(1);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   418
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   419
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   420
#ifdef DEBUG
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   421
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   422
static void
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   423
dump_Cmetrics(pcf_charmet_t *cm)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   424
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   425
    dprintf2("cmetrics: ascent:%d, descent:%d, ", cm->ascent, cm->descent);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   426
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   427
    dprintf3("width:%d, height:%d, widthBytes:%d, ", 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   428
    	cm->width, cm->height, cm->widthBytes);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   429
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   430
    dprintf3("LSB:%d,RSB: %d, xoff:%d\n ", 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   431
	cm->LSBearing, cm->RSBearing, cm->origin_xoff);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   432
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   433
static void
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   434
dump_Fmetrics(pcffont_t *fm)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   435
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   436
    dprintf6("Fmetrics: ascent:%d, descent:%d, linespace:%d, "
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   437
	"ptsz:%d, Xres:%d, Yres:%d\n", fm->ascent, fm->descent, 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   438
    	fm->linespace, fm->ptsz, fm->Xres, fm->Yres);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   439
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   440
#endif
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   441
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   442
unsigned long *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   443
Xrealloc (n,m)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   444
    unsigned long   *n;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   445
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   446
    if (!n)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   447
	return (unsigned long *) malloc (m);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   448
    else
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   449
	return (unsigned long *) realloc ((char *) n, m);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   450
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   451
unsigned long *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   452
Xalloc (m)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   453
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   454
    return (unsigned long *) malloc (m);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   455
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   456
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   457
/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   458
 *	Invert byte order within each 16-bits of an array.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   459
 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   460
void
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   461
TwoByteSwap(buf, nbytes)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   462
    unsigned char *buf;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   463
    int nbytes;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   464
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   465
    register unsigned char c;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   466
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   467
    for (; nbytes > 0; nbytes -= 2, buf += 2)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   468
    {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   469
	c = buf[0];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   470
	buf[0] = buf[1];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   471
	buf[1] = c;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   472
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   473
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   474
/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   475
 *	Invert byte order within each 32-bits of an array.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   476
 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   477
static void
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   478
FourByteSwap(buf, nbytes)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   479
    unsigned char *buf;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   480
    int nbytes;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   481
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   482
    register unsigned char c;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   483
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   484
    for (; nbytes > 0; nbytes -= 4, buf += 4) 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   485
    {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   486
	c = buf[0];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   487
	buf[0] = buf[3];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   488
	buf[3] = c;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   489
	c = buf[1];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   490
	buf[1] = buf[2];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   491
	buf[2] = c;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   492
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   493
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   494
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   495
handle_nongraphchar(ucs4_t *val, int *ndx)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   496
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   497
	return XU_IGNORE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   498
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   499
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   500
static Bool
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   501
pcfHasType (tables, ntables, type)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   502
    PCFTablePtr tables;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   503
    int         ntables;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   504
    CARD32      type;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   505
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   506
    int         i;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   507
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   508
    for (i = 0; i < ntables; i++)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   509
	if (tables[i].type == type)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   510
	    return TRUE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   511
    return FALSE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   512
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   513
/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   514
 *	Invert bit order within each BYTE of an array.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   515
 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   516
static void
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   517
BitOrderInvert(buf, nbytes)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   518
    unsigned char *buf;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   519
    int nbytes;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   520
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   521
    register unsigned char *rev = _reverse_byte;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   522
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   523
    for (; --nbytes >= 0; buf++)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   524
	*buf = rev[*buf];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   525
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   526
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   527
static pcf_bm_t *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   528
xpcf_getcbm(int code, pcffont_t *font, pcf_charmet_t *Cmetrics)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   529
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   530
    int j;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   531
    CharInfoPtr ci;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   532
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   533
    assert(font->loaded);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   534
    /*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   535
     * For the default no glyph character to appear in
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   536
     * output stream
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   537
     */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   538
     onemoretime:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   539
    if (code < font->Fmetrics.firstchar || code > font->Fmetrics.lastchar)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   540
	return NULL;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   541
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   542
    j = (code - (((code - font->Fmetrics.firstchar) / 256)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   543
    	* (font->Fmetrics.firstCol + (255 - font->Fmetrics.lastCol))))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   544
    	- font->Fmetrics.firstchar;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   545
#ifdef SDEBUG
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   546
	fprintf(stderr, "%d is -- codewidth of C%x\n", wcwidth(code), code);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   547
	fprintf(stderr, "%d is -- j value      C%x\n", wcwidth(code), code);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   548
#endif
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   549
    assert(j >= 0);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   550
    if (font->bitmaps[j] == NULL)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   551
	{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   552
			/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   553
			 * code added to replace the codepoints with
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   554
			 * no-glyph code
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   555
			 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   556
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   557
			if (wcwidth(code) == -1)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   558
				{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   559
				code = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   560
				goto onemoretime;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   561
				}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   562
        return NULL;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   563
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   564
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   565
    ci = font->bitmaps[j];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   566
    Cmetrics->width = GLYPHWIDTHPIXELS(ci);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   567
    Cmetrics->height = GLYPHHEIGHTPIXELS(ci);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   568
    Cmetrics->widthBytes = GLYPHWIDTHBYTES(ci);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   569
    Cmetrics->widthBits = GLYPHWIDTHBYTES(ci) * NBPB;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   570
    Cmetrics->ascent = ci->metrics.ascent;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   571
    Cmetrics->descent = ci->metrics.descent;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   572
    Cmetrics->LSBearing = ci->metrics.leftSideBearing;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   573
    Cmetrics->RSBearing = ci->metrics.rightSideBearing;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   574
    Cmetrics->origin_xoff = ci->metrics.characterWidth;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   575
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   576
#ifdef SDEBUG
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   577
	fprintf(stderr, "%d is -- Cmetrics->widthBytes of C%x\n", Cmetrics->widthBytes, code);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   578
	fprintf(stderr, "%d is -- Cmetrics->height value  of C%x\n", Cmetrics->height, code);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   579
#endif
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   580
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   581
#if 0
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   582
    if (cwflag) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   583
    	if (cwflag == OPTARG_ADD)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   584
    	    Cmetrics->origin_xoff += cw_argval;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   585
    	else if (cwflag == OPTARG_SUB)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   586
    	    Cmetrics->origin_xoff -= cw_argval;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   587
    	else if (cwflag == OPTARG_SET)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   588
    	    Cmetrics->origin_xoff = cw_argval;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   589
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   590
#endif
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   591
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   592
    debug(dump_Cmetrics(Cmetrics));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   593
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   594
    return (pcf_bm_t*) ci->bits;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   595
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   596
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   597
/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   598
 *	Repad a bitmap
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   599
 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   600
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   601
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   602
RepadBitmap (pSrc, pDst, srcPad, dstPad, width, height)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   603
    char	*pSrc, *pDst;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   604
    unsigned	srcPad, dstPad;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   605
    int		width, height;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   606
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   607
    int	    srcWidthBytes,dstWidthBytes;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   608
    int	    row,col;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   609
    char    *pTmpSrc,*pTmpDst;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   610
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   611
    switch (srcPad) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   612
    case 1:	
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   613
	srcWidthBytes = (width+7)>>3;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   614
	break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   615
    case 2:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   616
	srcWidthBytes = ((width+15)>>4)<<1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   617
	break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   618
    case 4:	
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   619
	srcWidthBytes = ((width+31)>>5)<<2;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   620
	break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   621
    case 8:	
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   622
	srcWidthBytes = ((width+63)>>6)<<3; 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   623
	break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   624
    default:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   625
	return 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   626
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   627
    switch (dstPad) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   628
    case 1:	
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   629
	dstWidthBytes = (width+7)>>3;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   630
	break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   631
    case 2:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   632
	dstWidthBytes = ((width+15)>>4)<<1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   633
	break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   634
    case 4:	
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   635
	dstWidthBytes = ((width+31)>>5)<<2;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   636
	break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   637
    case 8:	
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   638
	dstWidthBytes = ((width+63)>>6)<<3; 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   639
	break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   640
    default:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   641
	return 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   642
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   643
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   644
    width = srcWidthBytes;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   645
    if (width > dstWidthBytes)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   646
	width = dstWidthBytes;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   647
    pTmpSrc= pSrc;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   648
    pTmpDst= pDst;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   649
    for (row = 0; row < height; row++)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   650
    {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   651
	for (col = 0; col < width; col++)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   652
	    *pTmpDst++ = *pTmpSrc++;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   653
	while (col < dstWidthBytes)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   654
 	{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   655
	    *pTmpDst++ = '\0';
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   656
	    col++;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   657
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   658
	pTmpSrc += srcWidthBytes - width;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   659
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   660
    return dstWidthBytes * height;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   661
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   662
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   663
handle_cuferr(int err, ucs4_t *v, int *ndx)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   664
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   665
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   666
	if (err == CUF_ILCH) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   667
		return handle_illegalchar(v, ndx);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   668
	} else if (err == CUF_NICH) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   669
		return handle_nonidentchar(v, ndx);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   670
	} else {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   671
		err_exit( catgets(cat_fd, ERR_SET, 35, "%s: internal error: "
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   672
			"unable to get pcf glyph for 0x%08x\n"
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   673
			"file name:%s , line number:%d\n"), progname,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   674
			*v, __FILE__, __LINE__ );
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   675
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   676
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   677
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   678
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   679
handle_illegalchar(ucs4_t *val, int *ndx)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   680
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   681
	return XU_IGNORE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   682
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   683
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   684
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   685
handle_nonidentchar(ucs4_t *val, int *ndx)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   686
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   687
	return XU_IGNORE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   688
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   689
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   690
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   691
handle_nobitmap(ucs4_t *val, pcffont_t *font, pcf_charmet_t *Cm, pcf_bm_t **bitmap) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   692
	int fv;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   693
	/* Becasue NOBITMAPREPL is hard coded for FALLBACK_FONT */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   694
	if(strstr(font->file, FALLBACK_FONT)==NULL)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   695
		return XU_IGNORE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   696
	*val = NOBITMAPREPL;	
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   697
	if ((fv = font->cuf(*val)) < 0) return XU_IGNORE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   698
	if ((*bitmap = xpcf_getcbm(fv, font, Cm)) == NULL) return XU_IGNORE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   699
	return(1);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   700
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   701
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   702
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   703
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   704
BufFileRawFill (f)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   705
    BufFilePtr	f;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   706
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   707
    int	left;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   708
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   709
    left = read (FileDes(f), f->buffer, BUFFILESIZE);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   710
    if (left <= 0) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   711
	f->left = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   712
	return BUFFILEEOF;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   713
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   714
    f->left = left - 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   715
    f->bufp = f->buffer + 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   716
    return f->buffer[0];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   717
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   718
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   719
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   720
BufFileRawSkip (f, count)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   721
    BufFilePtr	f;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   722
    int		count;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   723
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   724
    int	    curoff;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   725
    int	    fileoff;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   726
    int	    todo;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   727
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   728
    curoff = f->bufp - f->buffer;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   729
    fileoff = curoff + f->left;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   730
    if (curoff + count <= fileoff) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   731
	f->bufp += count;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   732
	f->left -= count;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   733
    } else {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   734
	todo = count - (fileoff - curoff);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   735
	if (lseek (FileDes(f), todo, 1) == -1) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   736
	    if (errno != ESPIPE)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   737
		return BUFFILEEOF;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   738
	    while (todo) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   739
		curoff = BUFFILESIZE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   740
		if (curoff > todo)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   741
		    curoff = todo;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   742
		fileoff = read (FileDes(f), f->buffer, curoff);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   743
		if (fileoff <= 0)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   744
		    return BUFFILEEOF;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   745
		todo -= fileoff;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   746
	    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   747
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   748
	f->left = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   749
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   750
    return count;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   751
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   752
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   753
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   754
BufFileRawClose (f, doClose)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   755
    BufFilePtr	f;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   756
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   757
    if (doClose)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   758
	close (FileDes (f));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   759
    return 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   760
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   761
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   762
static
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   763
NameEqual (a, b, l)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   764
    char    *a, *b;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   765
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   766
    while (l--)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   767
	if (*a++ != *b++)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   768
	    return FALSE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   769
    return TRUE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   770
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   771
static BufFilePtr
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   772
BufFileOpenRead(fd)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   773
	 int fd;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   774
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   775
return BufFileCreate ((char *) fd, BufFileRawFill, BufFileRawSkip, BufFileRawClose);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   776
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   777
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   778
static AtomListPtr  *reverseMap;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   779
static int          reverseMapSize;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   780
static Atom         lastAtom;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   781
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   782
static Bool ResizeReverseMap ()
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   783
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   784
    if (reverseMapSize == 0)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   785
	reverseMapSize = 1000;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   786
    else
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   787
	reverseMapSize *= 2;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   788
    reverseMap = (AtomListPtr *) Xrealloc ((ulong_t *)reverseMap, reverseMapSize * sizeof (AtomListPtr));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   789
    if (!reverseMap)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   790
	return FALSE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   791
    else 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   792
	return TRUE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   793
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   794
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   795
static char *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   796
NameForAtom(atom)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   797
    Atom atom;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   798
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   799
    if (atom != None && atom <= lastAtom)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   800
	return reverseMap[atom]->name;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   801
    return 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   802
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   803
/*****************************************************************
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   804
 * TAG( getcode )
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   805
 *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   806
 * Read one code from the standard input.  If BUFFILEEOF, return -1.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   807
 * Inputs:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   808
 * 	stdin
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   809
 * Outputs:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   810
 * 	code or -1 is returned.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   811
 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   812
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   813
static char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   814
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   815
static code_int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   816
getcode(file)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   817
    CompressedFile  *file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   818
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   819
    register code_int code;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   820
    register int r_off, bits;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   821
    register char_type *bp = file->buf;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   822
    register BufFilePtr	raw;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   823
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   824
    if ( file->clear_flg > 0 || file->offset >= file->size ||
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   825
	file->free_ent > file->maxcode )
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   826
    {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   827
	/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   828
	 * If the next entry will be too big for the current code
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   829
	 * size, then we must increase the size.  This implies reading
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   830
	 * a new buffer full, too.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   831
	 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   832
	if ( file->free_ent > file->maxcode ) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   833
	    file->n_bits++;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   834
	    if ( file->n_bits == file->maxbits )
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   835
		file->maxcode = file->maxmaxcode;	/* won't get any bigger now */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   836
	    else
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   837
		file->maxcode = MAXCODE(file->n_bits);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   838
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   839
	if ( file->clear_flg > 0) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   840
    	    file->maxcode = MAXCODE (file->n_bits = INIT_BITS);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   841
	    file->clear_flg = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   842
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   843
	bits = file->n_bits;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   844
	raw = file->file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   845
	while (bits > 0 && (code = BufFileGet (raw)) != BUFFILEEOF)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   846
	{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   847
	    *bp++ = code;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   848
	    --bits;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   849
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   850
	bp = file->buf;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   851
	if (bits == file->n_bits)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   852
	    return -1;			/* end of file */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   853
	file->size = file->n_bits - bits;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   854
	file->offset = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   855
	/* Round size down to integral number of codes */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   856
	file->size = (file->size << 3) - (file->n_bits - 1);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   857
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   858
    r_off = file->offset;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   859
    bits = file->n_bits;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   860
    /*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   861
     * Get to the first byte.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   862
     */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   863
    bp += (r_off >> 3);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   864
    r_off &= 7;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   865
    /* Get first part (low order bits) */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   866
#ifdef NO_UCHAR
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   867
    code = ((*bp++ >> r_off) & rmask[8 - r_off]) & 0xff;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   868
#else
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   869
    code = (*bp++ >> r_off);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   870
#endif /* NO_UCHAR */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   871
    bits -= (8 - r_off);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   872
    r_off = 8 - r_off;		/* now, offset into code word */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   873
    /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   874
    if ( bits >= 8 ) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   875
#ifdef NO_UCHAR
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   876
	code |= (*bp++ & 0xff) << r_off;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   877
#else
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   878
	code |= *bp++ << r_off;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   879
#endif /* NO_UCHAR */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   880
	r_off += 8;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   881
	bits -= 8;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   882
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   883
    /* high order bits. */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   884
    if (rmask[bits])	
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   885
    	code |= (*bp & rmask[bits]) << r_off;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   886
    file->offset += file->n_bits;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   887
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   888
    return code;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   889
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   890
int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   891
BufFileClose (f, doClose)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   892
    BufFilePtr  f;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   893
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   894
	(void) (*f->close) (f, doClose);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   895
	xfree (f);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   896
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   897
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   898
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   899
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   900
get_font_property(FontPtr Fp, char *name, ulong_t *value)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   901
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   902
    int j;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   903
    int n;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   904
    char *prop_name;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   905
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   906
    n = Fp->info.nprops;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   907
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   908
    for (j = 0; j < n; j++) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   909
    	if (!(prop_name = NameForAtom(Fp->info.props[j].name)))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   910
    	    continue;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   911
    	if (eq(name, prop_name)) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   912
	    *value = (ulong_t) Fp->info.props[j].value;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   913
    	    return 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   914
    	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   915
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   916
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   917
    return -1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   918
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   919
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   920
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   921
static BufFilePtr
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   922
BufFileCreate (private, io, skip, close)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   923
    char    *private;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   924
    int	    (*io)();
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   925
    int	    (*skip)();
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   926
    int	    (*close)();
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   927
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   928
    BufFilePtr	f;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   929
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   930
    f = (BufFilePtr) xalloc (sizeof *f);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   931
    if (!f)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   932
	return 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   933
    f->private = private;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   934
    f->bufp = f->buffer;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   935
    f->left = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   936
    f->io = io;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   937
    f->skip = skip;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   938
    f->close = close;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   939
    return f;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   940
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   941
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   942
int hsize_table[] = {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   943
	5003,       /* 12 bits - 80% occupancy */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   944
	9001,       /* 13 bits - 91% occupancy */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   945
	18013,      /* 14 bits - 91% occupancy */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   946
	35023,      /* 15 bits - 94% occupancy */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   947
	69001       /* 16 bits - 95% occupancy */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   948
};
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   949
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   950
static int  BufCompressedFill(), BufCompressedSkip(), BufCompressedClose();
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   951
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   952
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   953
BufCompressedClose (f, doClose)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   954
    BufFilePtr	f;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   955
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   956
    CompressedFile  *file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   957
    BufFilePtr	    raw;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   958
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   959
    file = (CompressedFile *) f->private;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   960
    raw = file->file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   961
    xfree (file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   962
    BufFileClose (raw, doClose);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   963
    return 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   964
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   965
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   966
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   967
BufCompressedSkip (f, bytes)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   968
    BufFilePtr	f;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   969
    int		bytes;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   970
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   971
    int		    c;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   972
    while (bytes--) { 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   973
	if (BufFileGet(f) == BUFFILEEOF)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   974
		return BUFFILEEOF;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   975
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   976
    return 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   977
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   978
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   979
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   980
BufCompressedFill (f)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   981
    BufFilePtr	    f;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   982
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   983
    CompressedFile  *file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   984
    register char_type *stackp, *de_stack;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   985
    register char_type finchar;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   986
    register code_int code, oldcode, incode;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   987
    BufChar	    *buf, *bufend;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   988
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   989
    file = (CompressedFile *) f->private;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   990
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   991
    buf = f->buffer;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   992
    bufend = buf + BUFFILESIZE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   993
    stackp = file->stackp;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   994
    de_stack = file->de_stack;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   995
    finchar = file->finchar;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   996
    oldcode = file->oldcode;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   997
    while (buf < bufend) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   998
	while (stackp > de_stack && buf < bufend)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
   999
	    *buf++ = *--stackp;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1000
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1001
	if (buf == bufend)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1002
	    break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1003
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1004
	if (oldcode == -1)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1005
	    break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1006
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1007
	code = getcode (file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1008
	if (code == -1)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1009
	    break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1010
    
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1011
    	if ( (code == CLEAR) && file->block_compress ) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1012
	    for ( code = 255; code >= 0; code-- )
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1013
	    	file->tab_prefix[code] = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1014
	    file->clear_flg = 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1015
	    file->free_ent = FIRST - 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1016
	    if ( (code = getcode (file)) == -1 )	/* O, untimely death! */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1017
	    	break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1018
    	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1019
    	incode = code;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1020
    	/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1021
     	 * Special case for KwKwK string.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1022
     	 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1023
    	if ( code >= file->free_ent ) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1024
	    *stackp++ = finchar;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1025
	    code = oldcode;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1026
    	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1027
    
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1028
    	/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1029
     	 * Generate output characters in reverse order
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1030
     	 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1031
    	while ( code >= 256 )
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1032
    	{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1033
	    *stackp++ = file->tab_suffix[code];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1034
	    code = file->tab_prefix[code];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1035
    	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1036
	finchar = file->tab_suffix[code];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1037
	*stackp++ = finchar;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1038
    
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1039
    	/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1040
     	 * Generate the new entry.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1041
     	 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1042
    	if ( (code=file->free_ent) < file->maxmaxcode ) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1043
	    file->tab_prefix[code] = (unsigned short)oldcode;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1044
	    file->tab_suffix[code] = finchar;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1045
	    file->free_ent = code+1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1046
    	} 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1047
	/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1048
	 * Remember previous code.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1049
	 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1050
	oldcode = incode;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1051
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1052
    file->oldcode = oldcode;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1053
    file->stackp = stackp;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1054
    file->finchar = finchar;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1055
    if (buf == f->buffer) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1056
	f->left = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1057
	return BUFFILEEOF;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1058
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1059
    f->bufp = f->buffer + 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1060
    f->left = (buf - f->buffer) - 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1061
    return f->buffer[0];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1062
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1063
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1064
BufFilePtr
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1065
BufFilePushCompressed (f)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1066
    BufFilePtr	f;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1067
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1068
    int		    code;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1069
    int		    maxbits;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1070
    int		    hsize;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1071
    CompressedFile  *file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1072
    int		    extra;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1073
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1074
    if ((BufFileGet(f) != (magic_header[0] & 0xFF)) ||
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1075
	(BufFileGet(f) != (magic_header[1] & 0xFF)))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1076
    {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1077
	return 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1078
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1079
    code = BufFileGet (f);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1080
    maxbits = code & BIT_MASK;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1081
    if (maxbits > BITS || maxbits < 12)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1082
	return 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1083
    hsize = hsize_table[maxbits - 12];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1084
    extra = (1 << maxbits) * sizeof (char_type) +
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1085
	    hsize * sizeof (unsigned short);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1086
    file = (CompressedFile *) xalloc (sizeof (CompressedFile) + extra);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1087
    if (!file)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1088
	return 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1089
    file->file = f;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1090
    file->maxbits = maxbits;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1091
    file->block_compress = code & BLOCK_MASK;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1092
    file->maxmaxcode = 1 << file->maxbits;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1093
    file->tab_suffix = (char_type *) &file[1];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1094
    file->tab_prefix = (unsigned short *) (file->tab_suffix + file->maxmaxcode);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1095
    /*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1096
     * As above, initialize the first 256 entries in the table.
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1097
     */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1098
    file->maxcode = MAXCODE(file->n_bits = INIT_BITS);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1099
    for ( code = 255; code >= 0; code-- ) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1100
	file->tab_prefix[code] = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1101
	file->tab_suffix[code] = (char_type) code;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1102
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1103
    file->free_ent = ((file->block_compress) ? FIRST : 256 );
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1104
    file->clear_flg = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1105
    file->offset = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1106
    file->size = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1107
    file->stackp = file->de_stack;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1108
    file->finchar = file->oldcode = getcode (file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1109
    if (file->oldcode != -1)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1110
	*file->stackp++ = file->finchar;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1111
    return BufFileCreate ((char *) file,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1112
			  BufCompressedFill,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1113
			  BufCompressedSkip,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1114
			  BufCompressedClose);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1115
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1116
294
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1117
static 
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1118
int gzcatfile(char *name) {
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1119
    int    fd[2];
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1120
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1121
    if (pipe (fd) < 0)
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1122
        return -1;
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1123
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1124
    switch (fork ())
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1125
    {
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1126
        case -1:
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1127
            return -1;
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1128
        case 0:
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1129
            close (fd[0]);
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1130
            close (1);
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1131
            if (dup (fd[1]) != 1)
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1132
                return -1;
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1133
            close (fd[1]);
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1134
            execlp ("gzcat", "gzcat", name, 0);
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1135
            return -1;
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1136
        default:
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1137
            close (fd[1]);
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1138
            break;
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1139
    }
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1140
    return fd[0];
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1141
}
0
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1142
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1143
static FontFilePtr
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1144
FontFileOpen (char *name) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1145
    int		fd;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1146
    int		len;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1147
    BufFilePtr	raw, cooked;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1148
294
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1149
    len = strlen (name);
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1150
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1151
    /*
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1152
     * A little hack for .gz file support.
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1153
     * We gzcat the file and will treat the
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1154
     * resultant fd as a regular file's.
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1155
     */
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1156
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1157
    if (len > 3 && !strcmp (name + len - 3, ".gz"))
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1158
        fd = gzcatfile (name);
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1159
    else
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1160
        fd = open (name, 0);
9f7722099844 6754368: mp.conf patch for OpenSolaris
hnhn
parents: 0
diff changeset
  1161
0
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1162
    if (fd < 0)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1163
	return 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1164
    raw = BufFileOpenRead (fd);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1165
    if (!raw)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1166
    {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1167
	close (fd);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1168
	return 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1169
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1170
    if (len > 2 && !strcmp (name + len - 2, ".Z")) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1171
	cooked = BufFilePushCompressed (raw);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1172
	if (!cooked) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1173
	    BufFileClose (raw, TRUE);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1174
	    return 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1175
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1176
	raw = cooked;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1177
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1178
    return (FontFilePtr) raw;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1179
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1180
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1181
static void FontFileClose (FontFilePtr f)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1182
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1183
    BufFileClose ((BufFilePtr) f, TRUE);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1184
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1185
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1186
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1187
pcfGetLSB32(file)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1188
    FontFilePtr file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1189
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1190
    int         c;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1191
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1192
    c = FontFileGetc(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1193
    c |= FontFileGetc(file) << 8;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1194
    c |= FontFileGetc(file) << 16;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1195
    c |= FontFileGetc(file) << 24;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1196
    position += 4;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1197
    return c;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1198
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1199
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1200
static      PCFTablePtr
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1201
pcfReadTOC(file, countp)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1202
    FontFilePtr file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1203
    int        *countp;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1204
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1205
    CARD32      version;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1206
    PCFTablePtr tables;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1207
    int         count;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1208
    int         i;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1209
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1210
    position = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1211
    version = pcfGetLSB32(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1212
    if (version != PCF_FILE_VERSION)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1213
	return (PCFTablePtr) NULL;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1214
    count = pcfGetLSB32(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1215
    tables = (PCFTablePtr) xalloc(count * sizeof(PCFTableRec));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1216
    if (!tables)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1217
	return (PCFTablePtr) NULL;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1218
    for (i = 0; i < count; i++) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1219
	tables[i].type = pcfGetLSB32(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1220
	tables[i].format = pcfGetLSB32(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1221
	tables[i].size = pcfGetLSB32(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1222
	tables[i].offset = pcfGetLSB32(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1223
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1224
    *countp = count;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1225
    return tables;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1226
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1227
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1228
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1229
static
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1230
ResizeHashTable ()
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1231
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1232
    int		newHashSize;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1233
    int		newHashMask;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1234
    AtomListPtr	*newHashTable;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1235
    int		i;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1236
    int		h;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1237
    int		newRehash;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1238
    int		r;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1239
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1240
    if (hashSize == 0)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1241
	newHashSize = 1024;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1242
    else
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1243
	newHashSize = hashSize * 2;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1244
    newHashTable = (AtomListPtr *) xalloc (newHashSize * sizeof (AtomListPtr));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1245
    if (!newHashTable)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1246
	return FALSE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1247
    bzero ((char *) newHashTable, newHashSize * sizeof (AtomListPtr));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1248
    newHashMask = newHashSize - 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1249
    newRehash = (newHashMask - 2);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1250
    for (i = 0; i < hashSize; i++)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1251
    {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1252
	if (hashTable[i])
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1253
	{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1254
	    h = (hashTable[i]->hash) & newHashMask;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1255
	    if (newHashTable[h])
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1256
	    {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1257
		r = hashTable[i]->hash % newRehash | 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1258
		do {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1259
		    h += r;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1260
		    if (h >= newHashSize)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1261
			h -= newHashSize;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1262
		} while (newHashTable[h]);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1263
	    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1264
	    newHashTable[h] = hashTable[i];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1265
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1266
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1267
    xfree (hashTable);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1268
    hashTable = newHashTable;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1269
    hashSize = newHashSize;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1270
    hashMask = newHashMask;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1271
    rehash = newRehash;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1272
    return TRUE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1273
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1274
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1275
static
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1276
Hash(string, len)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1277
    char    *string;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1278
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1279
    int	h;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1280
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1281
    h = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1282
    while (len--)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1283
	h = (h << 3) ^ *string++;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1284
    if (h < 0)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1285
	return -h;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1286
    return h;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1287
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1288
static Atom 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1289
MakeAtom(string, len, makeit)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1290
    char *string;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1291
    unsigned len;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1292
    int makeit;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1293
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1294
    AtomListPtr	a;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1295
    int		hash;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1296
    int		h;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1297
    int		r;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1298
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1299
    hash = Hash (string, len);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1300
    if (hashTable)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1301
    {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1302
    	h = hash & hashMask;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1303
	if (hashTable[h])
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1304
	{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1305
	    if (hashTable[h]->hash == hash && hashTable[h]->len == len &&
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1306
	    	NameEqual (hashTable[h]->name, string, len))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1307
	    {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1308
	    	return hashTable[h]->atom;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1309
	    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1310
	    r = (hash % rehash) | 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1311
	    for (;;)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1312
	    {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1313
		h += r;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1314
		if (h >= hashSize)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1315
		    h -= hashSize;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1316
		if (!hashTable[h])
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1317
		    break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1318
		if (hashTable[h]->hash == hash && hashTable[h]->len == len &&
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1319
		    NameEqual (hashTable[h]->name, string, len))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1320
		{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1321
		    return hashTable[h]->atom;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1322
		}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1323
	    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1324
    	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1325
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1326
    if (!makeit)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1327
	return None;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1328
    a = (AtomListPtr) xalloc (sizeof (AtomListRec) + len + 1);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1329
    a->name = (char *) (a + 1);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1330
    a->len = len;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1331
    strncpy (a->name, string, len);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1332
    a->name[len] = '\0';
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1333
    a->atom = ++lastAtom;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1334
    a->hash = hash;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1335
    if (hashUsed >= hashSize / 2)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1336
    {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1337
	ResizeHashTable ();
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1338
	h = hash & hashMask;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1339
	if (hashTable[h])
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1340
	{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1341
	    r = (hash % rehash) | 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1342
	    do {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1343
		h += r;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1344
		if (h >= hashSize)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1345
		    h -= hashSize;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1346
	    } while (hashTable[h]);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1347
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1348
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1349
    hashTable[h] = a;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1350
    hashUsed++;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1351
    if (reverseMapSize <= a->atom)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1352
	ResizeReverseMap();
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1353
    reverseMap[a->atom] = a;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1354
    return a->atom;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1355
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1356
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1357
BufFileRead (f, b, n)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1358
    BufFilePtr	f;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1359
    char	*b;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1360
    int		n;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1361
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1362
    int	    c, cnt;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1363
    cnt = n;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1364
    while (cnt--) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1365
	c = BufFileGet (f);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1366
	if (c == BUFFILEEOF)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1367
	    break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1368
	*b++ = c;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1369
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1370
    return n - cnt - 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1371
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1372
static Bool
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1373
pcfGetProperties(pFontInfo, file, tables, ntables)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1374
    FontInfoPtr pFontInfo;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1375
    FontFilePtr file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1376
    PCFTablePtr tables;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1377
    int         ntables;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1378
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1379
    FontPropPtr props = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1380
    int         nprops;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1381
    char       *isStringProp = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1382
    CARD32      format;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1383
    int         i;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1384
    /* changed by suresh 07/12/99 from int to CARD 32*/
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1385
    CARD32         size;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1386
    int         string_size;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1387
    char       *strings;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1388
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1389
    /* font properties */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1390
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1391
    if (!pcfSeekToType(file, tables, ntables, PCF_PROPERTIES, &format, &size))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1392
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1393
    format = pcfGetLSB32(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1394
    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1395
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1396
    nprops = pcfGetINT32(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1397
    props = (FontPropPtr) xalloc(nprops * sizeof(FontPropRec));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1398
    if (!props)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1399
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1400
    isStringProp = (char *) xalloc(nprops * sizeof(char));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1401
    if (!isStringProp)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1402
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1403
    for (i = 0; i < nprops; i++) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1404
	props[i].name = pcfGetINT32(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1405
	isStringProp[i] = pcfGetINT8(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1406
	props[i].value = pcfGetINT32(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1407
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1408
    /* pad the property array */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1409
    /*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1410
     * clever here - nprops is the same as the number of odd-units read, as
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1411
     * only isStringProp are odd length
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1412
     */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1413
    if (nprops & 3)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1414
    {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1415
	i = 4 - (nprops & 3);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1416
	FontFileSkip(file, i);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1417
	position += i;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1418
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1419
    string_size = pcfGetINT32(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1420
    strings = (char *) xalloc(string_size);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1421
    if (!strings) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1422
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1423
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1424
    FontFileRead(file, strings, string_size);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1425
    position += string_size;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1426
    for (i = 0; i < nprops; i++) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1427
	props[i].name = MakeAtom(strings + props[i].name,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1428
				 strlen(strings + props[i].name), TRUE);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1429
	if (isStringProp[i]) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1430
	    props[i].value = MakeAtom(strings + props[i].value,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1431
				      strlen(strings + props[i].value), TRUE);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1432
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1433
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1434
    xfree(strings);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1435
    pFontInfo->isStringProp = isStringProp;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1436
    pFontInfo->props = props;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1437
    pFontInfo->nprops = nprops;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1438
    return TRUE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1439
Bail:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1440
    xfree(isStringProp);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1441
    xfree(props);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1442
    return FALSE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1443
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1444
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1445
static void
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1446
pcfGetCompressedMetric(file, format, metric)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1447
    FontFilePtr file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1448
    CARD32      format;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1449
    xCharInfo  *metric;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1450
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1451
    metric->leftSideBearing = pcfGetINT8(file, format) - 0x80;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1452
    metric->rightSideBearing = pcfGetINT8(file, format) - 0x80;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1453
    metric->characterWidth = pcfGetINT8(file, format) - 0x80;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1454
    metric->ascent = pcfGetINT8(file, format) - 0x80;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1455
    metric->descent = pcfGetINT8(file, format) - 0x80;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1456
    metric->attributes = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1457
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1458
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1459
static Bool
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1460
pcfSeekToType(file, tables, ntables, type, formatp, sizep)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1461
    FontFilePtr file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1462
    PCFTablePtr tables;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1463
    int         ntables;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1464
    CARD32      type;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1465
    CARD32     *formatp;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1466
    CARD32     *sizep;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1467
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1468
    int         i;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1469
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1470
    for (i = 0; i < ntables; i++)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1471
	if (tables[i].type == type) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1472
	    if (position > tables[i].offset)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1473
		return FALSE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1474
	    if (!FontFileSkip(file, tables[i].offset - position))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1475
		return FALSE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1476
	    position = tables[i].offset;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1477
	    *sizep = tables[i].size;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1478
	    *formatp = tables[i].format;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1479
	    return TRUE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1480
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1481
    return FALSE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1482
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1483
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1484
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1485
pcfGetINT32(file, format)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1486
    FontFilePtr file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1487
    CARD32      format;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1488
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1489
    int         c;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1490
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1491
    if (PCF_BYTE_ORDER(format) == MSBFirst) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1492
	c = FontFileGetc(file) << 24;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1493
	c |= FontFileGetc(file) << 16;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1494
	c |= FontFileGetc(file) << 8;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1495
	c |= FontFileGetc(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1496
    } else {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1497
	c = FontFileGetc(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1498
	c |= FontFileGetc(file) << 8;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1499
	c |= FontFileGetc(file) << 16;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1500
	c |= FontFileGetc(file) << 24;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1501
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1502
    position += 4;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1503
    return c;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1504
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1505
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1506
pcfGetINT16(file, format)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1507
    FontFilePtr file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1508
    CARD32      format;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1509
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1510
    int         c;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1511
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1512
    if (PCF_BYTE_ORDER(format) == MSBFirst) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1513
	c = FontFileGetc(file) << 8;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1514
	c |= FontFileGetc(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1515
    } else {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1516
	c = FontFileGetc(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1517
	c |= FontFileGetc(file) << 8;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1518
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1519
    position += 2;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1520
    return c;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1521
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1522
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1523
/*
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1524
 * pcfReadAccel
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1525
 *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1526
 * Fill in the accelerator information from the font file; used
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1527
 * to read both BDF_ACCELERATORS and old style ACCELERATORS
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1528
 */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1529
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1530
static Bool
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1531
pcfGetAccel(pFontInfo, file, tables, ntables, type)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1532
    FontInfoPtr pFontInfo;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1533
    FontFilePtr file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1534
    PCFTablePtr	tables;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1535
    int		ntables;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1536
    CARD32	type;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1537
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1538
    CARD32      format;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1539
    /* changed by suresh 07/12/99 from int to CARD 32*/
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1540
    CARD32		size;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1541
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1542
    if (!pcfSeekToType(file, tables, ntables, type, &format, &size))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1543
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1544
    format = pcfGetLSB32(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1545
    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) &&
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1546
	!PCF_FORMAT_MATCH(format, PCF_ACCEL_W_INKBOUNDS)) 
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1547
    {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1548
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1549
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1550
    pFontInfo->noOverlap = pcfGetINT8(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1551
    pFontInfo->constantMetrics = pcfGetINT8(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1552
    pFontInfo->terminalFont = pcfGetINT8(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1553
    pFontInfo->constantWidth = pcfGetINT8(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1554
    pFontInfo->inkInside = pcfGetINT8(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1555
    pFontInfo->inkMetrics = pcfGetINT8(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1556
    pFontInfo->drawDirection = pcfGetINT8(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1557
    pFontInfo->anamorphic = FALSE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1558
     /* natural alignment */ pcfGetINT8(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1559
    pFontInfo->fontAscent = pcfGetINT32(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1560
    pFontInfo->fontDescent = pcfGetINT32(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1561
    pFontInfo->maxOverlap = pcfGetINT32(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1562
    pcfGetMetric(file, format, &pFontInfo->minbounds);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1563
    pcfGetMetric(file, format, &pFontInfo->maxbounds);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1564
    if (PCF_FORMAT_MATCH(format, PCF_ACCEL_W_INKBOUNDS)) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1565
	pcfGetMetric(file, format, &pFontInfo->ink_minbounds);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1566
	pcfGetMetric(file, format, &pFontInfo->ink_maxbounds);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1567
    } else {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1568
	pFontInfo->ink_minbounds = pFontInfo->minbounds;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1569
	pFontInfo->ink_maxbounds = pFontInfo->maxbounds;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1570
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1571
    return TRUE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1572
Bail:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1573
    return FALSE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1574
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1575
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1576
static void
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1577
pcfGetMetric(file, format, metric)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1578
    FontFilePtr file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1579
    CARD32      format;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1580
    xCharInfo  *metric;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1581
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1582
    metric->leftSideBearing = pcfGetINT16(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1583
    metric->rightSideBearing = pcfGetINT16(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1584
    metric->characterWidth = pcfGetINT16(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1585
    metric->ascent = pcfGetINT16(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1586
    metric->descent = pcfGetINT16(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1587
    metric->attributes = pcfGetINT16(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1588
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1589
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1590
int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1591
bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1592
    FontPtr     pFont;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1593
    unsigned long count;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1594
    unsigned char *chars;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1595
    FontEncoding charEncoding;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1596
    unsigned long *glyphCount;	/* RETURN */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1597
    CharInfoPtr *glyphs;	/* RETURN */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1598
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1599
    BitmapFontPtr  bitmapFont;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1600
    unsigned int firstCol;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1601
    register unsigned int numCols;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1602
    unsigned int firstRow;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1603
    unsigned int numRows;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1604
    CharInfoPtr *glyphsBase;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1605
    register unsigned int c;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1606
    register CharInfoPtr pci;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1607
    unsigned int r;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1608
    CharInfoPtr *encoding;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1609
    CharInfoPtr pDefault;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1610
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1611
    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1612
    encoding = bitmapFont->encoding;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1613
    pDefault = bitmapFont->pDefault;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1614
    firstCol = pFont->info.firstCol;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1615
    numCols = pFont->info.lastCol - firstCol + 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1616
    glyphsBase = glyphs;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1617
    switch (charEncoding) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1618
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1619
    case Linear8Bit:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1620
    case TwoD8Bit:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1621
	if (pFont->info.firstRow > 0)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1622
	    break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1623
	if (pFont->info.allExist && pDefault) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1624
	    while (count--) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1625
		c = (*chars++) - firstCol;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1626
		if (c < numCols)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1627
		    *glyphs++ = encoding[c];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1628
		else
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1629
		    *glyphs++ = pDefault;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1630
	    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1631
	} else {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1632
	    while (count--) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1633
		c = (*chars++) - firstCol;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1634
		if (c < numCols && (pci = encoding[c]))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1635
		    *glyphs++ = pci;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1636
		else if (pDefault)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1637
		    *glyphs++ = pDefault;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1638
	    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1639
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1640
	break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1641
    case Linear16Bit:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1642
	if (pFont->info.allExist && pDefault) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1643
	    while (count--) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1644
		c = *chars++ << 8;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1645
		c = (c | *chars++) - firstCol;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1646
		if (c < numCols)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1647
		    *glyphs++ = encoding[c];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1648
		else
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1649
		    *glyphs++ = pDefault;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1650
	    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1651
	} else {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1652
	    while (count--) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1653
		c = *chars++ << 8;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1654
		c = (c | *chars++) - firstCol;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1655
		if (c < numCols && (pci = encoding[c]))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1656
		    *glyphs++ = pci;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1657
		else if (pDefault)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1658
		    *glyphs++ = pDefault;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1659
	    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1660
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1661
	break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1662
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1663
    case TwoD16Bit:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1664
	firstRow = pFont->info.firstRow;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1665
	numRows = pFont->info.lastRow - firstRow + 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1666
	while (count--) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1667
	    r = (*chars++) - firstRow;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1668
	    c = (*chars++) - firstCol;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1669
	    if (r < numRows && c < numCols &&
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1670
		    (pci = encoding[r * numCols + c]))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1671
		*glyphs++ = pci;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1672
	    else if (pDefault)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1673
		*glyphs++ = pDefault;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1674
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1675
	break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1676
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1677
    *glyphCount = glyphs - glyphsBase;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1678
    return Successful;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1679
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1680
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1681
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1682
int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1683
bitmapGetMetrics(pFont, count, chars, charEncoding, glyphCount, glyphs)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1684
    FontPtr     pFont;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1685
    unsigned long count;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1686
    unsigned char *chars;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1687
    FontEncoding charEncoding;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1688
    unsigned long *glyphCount;	/* RETURN */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1689
    xCharInfo **glyphs;		/* RETURN */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1690
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1691
    int         ret;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1692
    xCharInfo  *ink_metrics;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1693
    CharInfoPtr metrics;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1694
    BitmapFontPtr  bitmapFont;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1695
    CharInfoPtr	oldDefault;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1696
    int         i;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1697
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1698
    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1699
    oldDefault = bitmapFont->pDefault;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1700
    bitmapFont->pDefault = &nonExistantChar;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1701
    ret = bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, (CharInfoPtr *) glyphs);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1702
    if (ret == Successful) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1703
	if (bitmapFont->ink_metrics) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1704
	    metrics = bitmapFont->metrics;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1705
	    ink_metrics = bitmapFont->ink_metrics;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1706
	    for (i = 0; i < *glyphCount; i++) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1707
		if (glyphs[i] != (xCharInfo *) & nonExistantChar)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1708
		    glyphs[i] = ink_metrics + (((CharInfoPtr) glyphs[i]) - metrics);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1709
	    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1710
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1711
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1712
    bitmapFont->pDefault = oldDefault;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1713
    return ret;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1714
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1715
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1716
void
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1717
pcfUnloadFont(pFont)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1718
    FontPtr     pFont;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1719
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1720
    BitmapFontPtr  bitmapFont;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1721
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1722
    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1723
    xfree(bitmapFont->ink_metrics);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1724
    xfree(bitmapFont->encoding);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1725
    xfree(bitmapFont->bitmaps);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1726
    xfree(bitmapFont->metrics);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1727
    xfree(pFont->info.isStringProp);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1728
    xfree(pFont->info.props);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1729
    xfree(bitmapFont);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1730
    xfree(pFont);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1731
}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1732
static int
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1733
pcfReadFont(pFont, file, bit, byte, glyph, scan)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1734
    FontPtr     pFont;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1735
    FontFilePtr file;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1736
    int         bit,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1737
                byte,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1738
                glyph,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1739
                scan;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1740
{
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1741
    CARD32      format;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1742
    CARD32      size;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1743
    BitmapFontPtr  bitmapFont = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1744
    int         i;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1745
    PCFTablePtr tables = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1746
    int         ntables;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1747
    int         nmetrics;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1748
    int         nbitmaps;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1749
    int         sizebitmaps;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1750
    int         nink_metrics;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1751
    CharInfoPtr metrics = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1752
    xCharInfo  *ink_metrics = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1753
    char       *bitmaps = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1754
    CharInfoPtr *encoding = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1755
    int         nencoding;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1756
    int         encodingOffset;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1757
    CARD32      bitmapSizes[GLYPHPADOPTIONS];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1758
    CARD32     *offsets = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1759
    Bool	hasBDFAccelerators;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1760
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1761
    pFont->info.props = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1762
    if (!(tables = pcfReadTOC(file, &ntables)))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1763
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1764
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1765
    /* properties */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1766
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1767
    if (!pcfGetProperties(&pFont->info, file, tables, ntables))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1768
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1769
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1770
    /* Use the old accelerators if no BDF accelerators are in the file */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1771
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1772
    hasBDFAccelerators = pcfHasType (tables, ntables, PCF_BDF_ACCELERATORS);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1773
    if (!hasBDFAccelerators)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1774
	if (!pcfGetAccel (&pFont->info, file, tables, ntables, PCF_ACCELERATORS))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1775
	    goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1776
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1777
    /* metrics */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1778
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1779
    if (!pcfSeekToType(file, tables, ntables, PCF_METRICS, &format, &size)) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1780
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1781
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1782
    format = pcfGetLSB32(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1783
    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) &&
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1784
	    !PCF_FORMAT_MATCH(format, PCF_COMPRESSED_METRICS)) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1785
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1786
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1787
    if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1788
	nmetrics = pcfGetINT32(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1789
    else
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1790
	nmetrics = pcfGetINT16(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1791
    metrics = (CharInfoPtr) xalloc(nmetrics * sizeof(CharInfoRec));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1792
    if (!metrics) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1793
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1794
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1795
    for (i = 0; i < nmetrics; i++)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1796
	if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1797
	    pcfGetMetric(file, format, &(metrics + i)->metrics);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1798
	else
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1799
	    pcfGetCompressedMetric(file, format, &(metrics + i)->metrics);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1800
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1801
    /* bitmaps */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1802
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1803
    if (!pcfSeekToType(file, tables, ntables, PCF_BITMAPS, &format, &size))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1804
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1805
    format = pcfGetLSB32(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1806
    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1807
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1808
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1809
    nbitmaps = pcfGetINT32(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1810
    if (nbitmaps != nmetrics)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1811
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1812
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1813
    offsets = (CARD32 *) xalloc(nbitmaps * sizeof(CARD32));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1814
    if (!offsets)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1815
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1816
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1817
    for (i = 0; i < nbitmaps; i++)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1818
	offsets[i] = pcfGetINT32(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1819
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1820
    for (i = 0; i < GLYPHPADOPTIONS; i++)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1821
	bitmapSizes[i] = pcfGetINT32(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1822
    sizebitmaps = bitmapSizes[PCF_GLYPH_PAD_INDEX(format)];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1823
    bitmaps = (char *) xalloc(sizebitmaps);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1824
    if (!bitmaps)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1825
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1826
    FontFileRead(file, bitmaps, sizebitmaps);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1827
    position += sizebitmaps;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1828
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1829
    if (PCF_BIT_ORDER(format) != bit)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1830
	BitOrderInvert((unsigned char*)bitmaps, sizebitmaps);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1831
    if ((PCF_BYTE_ORDER(format) == PCF_BIT_ORDER(format)) != (bit == byte)) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1832
	switch (bit == byte ? PCF_SCAN_UNIT(format) : scan) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1833
	case 1:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1834
	    break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1835
	case 2:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1836
	    TwoByteSwap((unsigned char*)bitmaps, sizebitmaps);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1837
	    break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1838
	case 4:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1839
	    FourByteSwap((unsigned char*)bitmaps, sizebitmaps);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1840
	    break;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1841
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1842
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1843
    if (PCF_GLYPH_PAD(format) != glyph) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1844
	char       *padbitmaps;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1845
	int         sizepadbitmaps;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1846
	int         old,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1847
	            new;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1848
	xCharInfo  *metric;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1849
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1850
	sizepadbitmaps = bitmapSizes[PCF_SIZE_TO_INDEX(glyph)];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1851
	padbitmaps = (char *) xalloc(sizepadbitmaps);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1852
	if (!padbitmaps) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1853
	    goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1854
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1855
	new = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1856
	for (i = 0; i < nbitmaps; i++) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1857
	    old = offsets[i];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1858
	    metric = &metrics[i].metrics;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1859
	    offsets[i] = new;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1860
	    new += RepadBitmap(bitmaps + old, padbitmaps + new,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1861
			       PCF_GLYPH_PAD(format), glyph,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1862
			  metric->rightSideBearing - metric->leftSideBearing,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1863
			       metric->ascent + metric->descent);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1864
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1865
	xfree(bitmaps);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1866
	bitmaps = padbitmaps;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1867
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1868
    for (i = 0; i < nbitmaps; i++)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1869
	metrics[i].bits = bitmaps + offsets[i];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1870
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1871
    xfree(offsets);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1872
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1873
    /* ink metrics ? */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1874
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1875
    ink_metrics = NULL;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1876
    if (pcfSeekToType(file, tables, ntables, PCF_INK_METRICS, &format, &size)) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1877
	format = pcfGetLSB32(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1878
	if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) &&
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1879
		!PCF_FORMAT_MATCH(format, PCF_COMPRESSED_METRICS)) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1880
	    goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1881
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1882
	if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1883
	    nink_metrics = pcfGetINT32(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1884
	else
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1885
	    nink_metrics = pcfGetINT16(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1886
	if (nink_metrics != nmetrics)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1887
	    goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1888
	ink_metrics = (xCharInfo *) xalloc(nink_metrics * sizeof(xCharInfo));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1889
	if (!ink_metrics)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1890
	    goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1891
	for (i = 0; i < nink_metrics; i++)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1892
	    if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1893
		pcfGetMetric(file, format, ink_metrics + i);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1894
	    else
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1895
		pcfGetCompressedMetric(file, format, ink_metrics + i);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1896
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1897
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1898
    /* encoding */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1899
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1900
    if (!pcfSeekToType(file, tables, ntables, PCF_BDF_ENCODINGS, &format, &size))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1901
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1902
    format = pcfGetLSB32(file);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1903
    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1904
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1905
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1906
    pFont->info.firstCol = pcfGetINT16(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1907
    pFont->info.lastCol = pcfGetINT16(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1908
    pFont->info.firstRow = pcfGetINT16(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1909
    pFont->info.lastRow = pcfGetINT16(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1910
    pFont->info.defaultCh = pcfGetINT16(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1911
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1912
    nencoding = (pFont->info.lastCol - pFont->info.firstCol + 1) *
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1913
	(pFont->info.lastRow - pFont->info.firstRow + 1);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1914
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1915
    encoding = (CharInfoPtr *) xalloc(nencoding * sizeof(CharInfoPtr));
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1916
    if (!encoding)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1917
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1918
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1919
    pFont->info.allExist = TRUE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1920
    for (i = 0; i < nencoding; i++) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1921
	encodingOffset = pcfGetINT16(file, format);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1922
	if (encodingOffset == 0xFFFF) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1923
	    pFont->info.allExist = FALSE;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1924
	    encoding[i] = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1925
	} else
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1926
	    encoding[i] = metrics + encodingOffset;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1927
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1928
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1929
    /* BDF style accelerators (i.e. bounds based on encoded glyphs) */
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1930
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1931
    if (hasBDFAccelerators)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1932
	if (!pcfGetAccel (&pFont->info, file, tables, ntables, PCF_BDF_ACCELERATORS))
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1933
	    goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1934
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1935
    bitmapFont = (BitmapFontPtr) xalloc(sizeof *bitmapFont);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1936
    if (!bitmapFont)
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1937
	goto Bail;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1938
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1939
    bitmapFont->version_num = PCF_FILE_VERSION;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1940
    bitmapFont->num_chars = nmetrics;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1941
    bitmapFont->num_tables = ntables;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1942
    bitmapFont->metrics = metrics;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1943
    bitmapFont->ink_metrics = ink_metrics;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1944
    bitmapFont->bitmaps = bitmaps;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1945
    bitmapFont->encoding = encoding;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1946
    bitmapFont->pDefault = (CharInfoPtr) 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1947
    if (pFont->info.defaultCh != (unsigned short) NO_SUCH_CHAR) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1948
	int         r,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1949
	            c,
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1950
	            cols;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1951
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1952
	r = pFont->info.defaultCh >> 8;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1953
	c = pFont->info.defaultCh & 0xFF;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1954
	if (pFont->info.firstRow <= r && r <= pFont->info.lastRow &&
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1955
		pFont->info.firstCol <= c && c <= pFont->info.lastCol) {
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1956
	    cols = pFont->info.lastCol - pFont->info.firstCol + 1;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1957
	    r = r - pFont->info.firstRow;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1958
	    c = c - pFont->info.firstCol;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1959
	    bitmapFont->pDefault = encoding[r * cols + c];
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1960
	}
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1961
    }
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1962
    bitmapFont->bitmapExtra = (BitmapExtraPtr) 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1963
    pFont->fontPrivate = (pointer) bitmapFont;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1964
    pFont->get_glyphs = bitmapGetGlyphs;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1965
    pFont->get_metrics = bitmapGetMetrics;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1966
    pFont->unload_font = pcfUnloadFont;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1967
    pFont->bit = bit;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1968
    pFont->byte = byte;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1969
    pFont->glyph = glyph;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1970
    pFont->scan = scan;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1971
    xfree(tables);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1972
    return Successful;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1973
Bail:
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1974
    xfree(ink_metrics);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1975
    xfree(encoding);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1976
    xfree(bitmaps);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1977
    xfree(offsets);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1978
    xfree(metrics);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1979
    xfree(pFont->info.props);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1980
    pFont->info.props = 0;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1981
    xfree(bitmapFont);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1982
    xfree(tables);
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1983
    return AllocError;
542988ea726d initial version of Nevada G11N repository
simford
parents:
diff changeset
  1984
}