T168_111\appl\Text\Agfa:第75~82

if_type.h  、、、、、、、、、、、、、、、、、、、、、、、、、、、

/* 
 * Copyright (C) 2004 Agfa Monotype Corporation. All rights reserved.
 */
/* $Header:   I:/BULL/URIP/SYS/INC/IF_TYPE.H_V   1.139   Dec 14 2004 10:30:36   wuq  $ */
/* $Log:   I:/BULL/URIP/SYS/INC/IF_TYPE.H_V  $ 
 * 
 *    Rev 1.139   Dec 14 2004 10:30:36   wuq
 * Change num_entries of DIRECT_ACCESS_TABLES to capacity.
 * 
 *    Rev 1.138   Nov 15 2004 15:55:16   indreliunaiter
 * Backed out the MPR changes. 
 * 
 *    Rev 1.137   Nov 03 2004 10:08:16   DugganJ
 * Added new multithreading fields to IF_STATE.
 * 
 * 
 *    Rev 1.136   Oct 26 2004 12:53:54   dugganj
 * Multithreading changes.
 * 
 *    Rev 1.135   Oct 25 2004 18:18:48   galejss
 * tighten conditional compiles for expand_buf,char_buf
 * 
 *    Rev 1.134   Oct 18 2004 14:26:20   galejss
 * remove unneeded PS vbls "pxb", "pps"
 * 
 *    Rev 1.133   Oct 04 2004 15:27:34   jardima
 * Changes to enable unscaled bbox return in MicroType.
 * 
 *    Rev 1.132   Sep 27 2004 16:24:20   dugganj
 * Added multithread support.
 * 
 *    Rev 1.131   Sep 21 2004 11:20:48   galejss
 * fix compile error (psptr needed if ROM)
 * 
 *    Rev 1.130   Sep 20 2004 14:25:42   galejss
 * add new substructure "PCLEO_CALLBACK_DATA pcd" to replace globals in sample PCLEO code
 * 
 *    Rev 1.129   Sep 15 2004 08:03:32   dugganj
 * Stikoutl change support (by jwd)
 * 
 *    Rev 1.128   Sep 09 2004 16:48:04   galejss
 * change number of memory pools NP to 3
 * 
 *    Rev 1.127   Sep 02 2004 14:10:36   indreliunaiter
 * Changed MPR code to support a Stroke data on the characters basis.
 * 
 *    Rev 1.126   Aug 10 2004 12:48:22   galejss
 * changes for runtime no-symset-mapping option; move new fsg_Metrics structure here from shareinc.h
 * 
 *    Rev 1.125   Jul 16 2004 13:20:10   galejss
 * changes for extended disk/rom support
 * 
 *    Rev 1.124   Jun 04 2004 15:40:10   GalejsS
 * add "orThresholdIF" (to fix conflict between different or-thresholds for different FSTs)
 * 
 *    Rev 1.123   Apr 27 2004 11:06:02   GalejsS
 * removal of substructures in IF_STATE; remove Type0 data; NEW_PS_HINTS is only option now
 * 
 *    Rev 1.122   Oct 17 2003 14:42:20   Galejs
 * remove obsolete MEM_DUMP_INT option
 * 
 *    Rev 1.121   Sep 25 2003 16:24:16   Galejs
 * add PS_ERRORCHECK support; remove unused "pathname"
 * 
 *    Rev 1.120   Aug 22 2003 09:43:52   LynchR
 * Updated copyright notice.
 * 
 *    Rev 1.119   Aug 21 2003 14:01:06   IndrelR
 * Added feature for processing XL bitmaps.
 * 
 *    Rev 1.118   Aug 19 2003 13:05:56   Joe
 * Added "table-by-reference" support.
 * 
 *    Rev 1.117   Aug 14 2003 13:41:54   WuQ
 * Added a new field in FONT_INFO indicating whether to use the "top-level" or "low-level" fontId.
 * Added a new field in IF_STATE for saving user's original FONTCONTEXT.
 * Removed the LINKED_FNT pointer lfnt from IF_STATE.
 * 
 *    Rev 1.116   Aug 08 2003 12:28:18   Galejs
 * move hexasc enum from if_type.h to ix.h (fix wrong-order compile error)
 * 
 *    Rev 1.115   Aug 05 2003 16:46:16   WuQ
 * MAX_FONT_NUM defined as the maximum number of the fonts used by the user for linked font. 
 * 
 *    Rev 1.114   Aug 01 2003 16:32:56   WuQ
 * Updated struct LINKED_FNT, and struct FONT_INFO.
 * Updated variables in if_state for linked font.
 * 
 *    Rev 1.113   Jul 23 2003 17:32:00   Galejs
 * move "hexasc" enum here (since it's not just for CFF anymore)
 * 
 *    Rev 1.112   Jul 21 2003 17:49:02   Galejs
 * "trace_sw" now part of IF_STATE structure (rather than standalone global)
 * 
 *    Rev 1.111   Jul 14 2003 18:03:28   WuQ
 * fc_updated is added to IF_STATE for controlling whether user's fontcontext setting need to be copied.
 * 
 *    Rev 1.110   Jul 11 2003 11:57:26   Galejs
 * get rid of "cache_by_ref_mode" (replaced by CACHE_BY_REF define in cgconfig.h)
 * 
 *    Rev 1.109   Jun 27 2003 18:01:54   Galejs
 * add missing #endif
 * 
 *    Rev 1.108   Jun 27 2003 15:52:20   WuQ
 * changes for linked fonts
 * 
 *    Rev 1.107   Jun 23 2003 11:50:46   Galejs
 * add OUTL_COORD type for VLCOUTPUT; add USE_LOW_BYTE; move MEM_DUMP_INT
 * 
 *    Rev 1.106   Jun 12 2003 15:24:24   Joe
 * Added "cache-by-reference" support.
 * 
 *    Rev 1.105   Jan 07 2003 15:10:48   Joe
 * Added "update_reflines_flag_set" field to IF_STATE.
 * 
 *    Rev 1.104   Nov 04 2002 11:50:14   Joe
 * Added missing character substitution support.
 * 
 *    Rev 1.103   Oct 23 2002 19:02:02   Galejs
 * add NAME_QUERY structure and related defines (for CGIFtt_name_query = bug #57)
 * 
 *    Rev 1.102   Oct 23 2002 14:15:58   Joe
 * Added fields "xlpm" and "ylpm" to IF_STATE (moved
 * from FONTCONTEXT).
 * 
 *    Rev 1.101   Sep 26 2002 11:05:48   Joe
 * Added fields to IF_STATE for storing "HOxo" metrics for 
 * stroke fonts
 * 
 *    Rev 1.100   Sep 24 2002 20:01:26   Galejs
 * add FIX_CONTOURS fields (bug # 73) (for awr
 * 
 *    Rev 1.99   Sep 23 2002 14:35:42   Doolittl
 * Added OPTIMIZE_FCOACCESS constants and macros.
 * 
 *    Rev 1.98   Sep 23 2002 14:27:32   Galejs
 * test for multiple includes (part of bug # 76)
 * 
 *    Rev 1.97   Aug 27 2002 16:21:34   Joe
 * Added "lpm" field to IF_STATE structure.
 * 
 *    Rev 1.96   Apr 22 2002 17:54:18   Galejs
 * remove obsolete USE_SURFER_API references (UFST bug #8)
 * 
 *    Rev 1.95   07 Feb 2002 16:35:14   JOE
 * Moved "stik_font" and "stik_char" fields from IF_STATE to
 * fs_GlyphInfoType structure.
 * 
 *    Rev 1.94   Jan 16 2002 11:41:40   Joe
 * Removed conditional compile directives surrounding
 * "stik_font" and "stik_char" in IF_STATE to
 * resolve compiler errors.
 * 
 *    Rev 1.93   27 Aug 2001 14:35:08   JOE
 * Moved "PCL_font_type" outside of BYTEORDER block.
 * 
 *    Rev 1.92   24 Aug 2001 14:26:18   JOE
 * Added PCL_font_type field to IF_STATE.
 * 
 *    Rev 1.91   Jul 10 2001 14:33:06   Galejs
 * add "savenzw" field (used for FCO by new fast-fill code)
 * 
 *    Rev 1.90   Jul 06 2001 11:53:56   Galejs
 * allow 64-bit chunk to compile (although it still won't run...)
 * 
 *    Rev 1.89   Jun 18 2001 10:43:54   Paul
 * changes for PS_NEW_HINTS
 * 
  *    Rev 1.88   Jun 14 2001 16:35:44   Al
 * Added a tran buf to NZ_INSTANCE
 *
 *    Rev 1.87   May 21 2001 20:51:56   Galejs
 * add "psptr" for use by PST1_RAM and CFF_ROM options
 * 
 *    Rev 1.86   May 04 2001 16:49:50   Galejs
 * data-type cleanup; get rid of AGFATOOLS
 * 
 *    Rev 1.85   Apr 19 2001 16:02:06   Al
 * Added fields in NZ_NODE and NZ_INSTANCE to
 *  detect badly wound contours.
 * 
 *    Rev 1.84   Apr 02 2001 16:24:08   Al
 * Removed fixed size array from ACT memory management
 * 
 *    Rev 1.83   Apr 02 2001 14:24:36   Al
 * Return error if PS path doesn't start with moveto
 * 
 *    Rev 1.82   Dec 05 2000 14:56:34   Galejs
 * add new typedefs for CGIFtt_cmap_query() function
 * 
 *    Rev 1.81   Nov 28 2000 18:04:28   Galejs
 * remove FCO_TT option
 * 
 *    Rev 1.80   04 Oct 2000 10:08:32   JOE
 * In IF_STATE, added fields 'BitmapManipulated' and 'BitmapEmbedded'.
 * 
 *    Rev 1.79   Mar 29 2000 13:49:24   galejs
 * fix massively messed-up indents
 * 
 *    Rev 1.78   27 Mar 2000 15:00:42   JOE
 * CACHE with NO_SYMSET_MAPPING fix (by jwd).
 * 
 *    Rev 1.77   17 Feb 2000 10:22:32   AL
 * Hooked CHARalloc() into WINDCOMP nz winding
 * 
 *    Rev 1.76   10 Feb 2000 15:41:56   AL
 * Removed PST1_ROM
 * 
 *    Rev 1.75   03 Feb 2000 15:26:56   AL
 * Changed SWP799 to WINDCOMP
 * 
 *    Rev 1.74   Feb 02 2000 17:22:38   galejs
 * font_access field not conditional on SIMULDISKROM
 * 
 *    Rev 1.73   Feb 02 2000 11:40:22   galejs
 * add "font_access" field, DISK/ROM_ACCESS defines
 * 
 *    Rev 1.72   Jan 24 2000 15:07:30   galejs
 * vertical-writing changes (for keb)
 * 
 *    Rev 1.71   Dec 14 1999 13:00:56   galejs
 * delete ENTITYACT, rom_thing definitions
 * 
 *    Rev 1.70   17 Sep 1999 09:01:12   JOE
 * Replaced the NZW apparatus, enabled if SWP799 (by swp).
 * 
 *    Rev 1.69   Aug 18 1999 17:22:22   galejs
 * FONT becomes cacheFONT (to resolve conflict with customer's typedef)
 * 
 *    Rev 1.68   Jul 08 1999 16:47:20   galejs
 * add "gray_x/y_off"  for MSVC/Surfer port
 * 
 *    Rev 1.67   Jun 29 1999 15:06:00   galejs
 * signed/unsigned mismatch in BITSERVE_GM struct
 * 
 *    Rev 1.66   04 May 1999 10:52:06   JOE
 * Modified ODATA structure (by awr).
 * 
 *    Rev 1.65   26 Jan 1999 13:23:24   JOE
 * Removed ASIANVERT condition surrounding xl_char_class
 * (by keb).
 * 
 *    Rev 1.64   19 Jan 1999 18:20:04   GALEJS
 * contents of cache.h, bitmap.h moved here
 * 
 *    Rev 1.63   12 Jan 1999 18:04:30   GALEJS
 * "tfntname[]" also needed if AGFATOOLS
 * 
 *    Rev 1.62   06 Jan 1999 16:31:14   GALEJS
 * rearrange IF_STATE elements, delete "width_mixm"
 * 
 *    Rev 1.61   14 Dec 1998 08:34:44   JOE
 * Removed extra tabs (by keb).
 * 
 *    Rev 1.60   11 Dec 1998 11:39:56   JOE
 * Added code to support ASIANVERT for XLfonts (by keb).
 * 
 *    Rev 1.59   02 Oct 1998 08:35:08   JOE
 * Removed rstack (by tbh).
 * 
 *    Rev 1.58   29 Sep 1998 10:47:58   MARTIN
 * Changed rom_thing type from BOOLEAN to UW16 to fix ACT bug
 * running under MSVC.
 * 
 *    Rev 1.57   28 Sep 1998 11:21:22   AL
 * Added rstack to remove recursion from getNode() and procNode()
 * 
 *    Rev 1.56   15 Sep 1998 11:54:40   GALEJS
 * change conditional compile for "missing_ccparts"
 * 
 *    Rev 1.55   10 Sep 1998 17:24:18   GALEJS
 * move "hinttype" enum definition here from t1ihints.c
 * 
 *    Rev 1.54   02 Sep 1998 17:36:46   GALEJS
 * move GRAYIMAGE here from imagegr.h
 * 
 *    Rev 1.53   13 Aug 1998 15:11:30   GALEJS
 * undo my mistake
 * 
 *    Rev 1.51   06 Aug 1998 15:30:20   AL
 * Changed #if !ROM to #if DISK_FONTS
 * 
 *    Rev 1.50   21 Jul 1998 16:26:00   GALEJS
 * widthScale should be FPNUM, not double
 * 
 *    Rev 1.49   09 Jul 1998 19:11:00   GALEJS
 * remove first_loop()/next_loop() prototypes again
 * 
 *    Rev 1.48   09 Jul 1998 12:28:36   DAVID
 * Integrated new CFF processing support (by dek) into
 * UFST base code.  Changed copyright notice dates.
 * 
 *    Rev 1.47   08 Jul 1998 15:24:20   GALEJS
 * move XLfont, lots of Surfer vbls into IF_STATE
 * 
 *    Rev 1.46   22 Jun 1998 16:53:32   GALEJS
 * type change for (*pix_al_ptr); move some fn protos to shareinc
 * 
 *    Rev 1.45   12 Jun 1998 14:03:14   GALEJS
 * add parm changes for reentrancy, delete unused vbls
 * 
 *    Rev 1.44   29 May 1998 18:55:30   GALEJS
 * move /psi variables, swap macros here
 * 
 *    Rev 1.43   29 May 1998 16:28:34   AL
 * Added comments and numleft field to BITSERVE_IM to fix bogus memory accesse
 * 
 *    Rev 1.42   21 May 1998 15:47:46   JOE
 * Moved definition of ENTITYACT here (by keb).
 * 
 *    Rev 1.41   15 Apr 1998 16:47:36   GALEJS
 * move 8 more globals into IF_STATE
 * 
 *    Rev 1.40   14 Apr 1998 18:26:38   GALEJS
 * move GLOBALs fontindex, special_case into IF_STATE
 * 
 *    Rev 1.39   13 Apr 1998 13:08:24   AL
 * Moved MLOCAL pathnaname to IF_STATE to fix CGIFfont() with disk input
 * 
 *    Rev 1.38   02 Apr 1998 20:09:12   GALEJS
 * move GLOBALs from 10 .c files, typedefs from 2 .h files
 * 
 *    Rev 1.37   01 Apr 1998 19:25:24   GALEJS
 * MLOCALs from cubic.c, fc_intfl.c, plus some GLOBALs
 * 
 *    Rev 1.36   31 Mar 1998 18:28:54   GALEJS
 * move MLOCALs from 5 more files into IF_STATE
 * 
 *    Rev 1.35   30 Mar 1998 11:55:48   GALEJS
 * move MLOCALs from 11 files into IF_STATE, remove unused elts
 * 
 *    Rev 1.34   23 Feb 1998 14:44:18   AL
 * Removed if_state.glob_ital_tan (unused) and added DECENDER and adjust_angle
 * 
 *    Rev 1.33   03 Feb 1998 22:02:00   DAVID
 * Added defines for constants to convert from PostScript escapement values to
 * 
 *    Rev 1.32   28 Jan 1998 11:50:34   AL
 * Very large characters and re-entrant
 * 
 *    Rev 1.31   04 Sep 1997 17:05:46   MARTIN
 * Modified references to AGFA Compressed TrueType (ACT).
 * 
 *    Rev 1.30   04 Sep 1997 13:30:58   JOE
 * Removed all references to BJG_BOLD (by keb).
 * 
 *    Rev 1.29   02 Sep 1997 09:12:46   AL
 * Changed SMEAR_INSTANCE to process end loop better.
 * 
 *    Rev 1.28   29 Jul 1997 11:05:10   JOE
 * Added fields "startx" and "starty" to SMEAR_INSTANCE structure (by Al).
 * 
 *    Rev 1.27   24 Jul 1997 16:43:32   AL
 * Added SMEAR_INSTANCE.name for debugging
 * 
 *    Rev 1.26   15 Jul 1997 10:18:08   AL
 * Pseudo bold by manipulating the outline
 * 
 *    Rev 1.25   30 May 1997 09:45:46   MARTIN
 * Added TrueType ROM ACT (compressed random access).
 * 
 *    Rev 1.24   23 Apr 1997 11:32:16   MIKE
 * Conditionally removed elements from COORD_DATA and IF_STATE
 * 
 *    Rev 1.23   18 Mar 1997 16:33:44   PVCSADMN
 * Karen B. added 2 fields ro if_state structure.
 * 
 *    Rev 1.22   13 Jan 1997 12:49:54   DAVID
 * Removed CONVERGENT_FONTS option as part of project to trim ufst.
 * 
 *    Rev 1.21   10 Jan 1997 13:51:50   DAVID
 * Removed ELASTIC_X and ELASTIC_Y as part of project to trim ufst.
 * 
 *    Rev 1.20   14 Nov 1996 11:28:56   MIKE
 * Removed CTRL-Z
 * 
 *    Rev 1.19   25 Oct 1996 09:47:26   PVCSADMN
 * JFD Added boldembox field to IF_STATE structure.
 * 
 *    Rev 1.18   23 Oct 1996 12:03:18   PVCSADMN
 * Added emboldening for PCL 6 emulation.
 * 
 *    Rev 1.17   02 Oct 1996 14:28:26   MIKE
 * Adjust scaling constants (see last change)
 * 
 *    Rev 1.16   19 Sep 1996 08:58:16   MIKE
 * Added constants for escapement calculations
 * 
 *    Rev 1.15   29 Aug 1996 14:23:18   MIKE
 * Added IF_STATE.FCO_PluginH
 * 
 *    Rev 1.14   18 Apr 1995 17:03:12   JOE
 * Added "chIdptr" and "PSchar_name" fields to IF_STATE.
 * 
 *    Rev 1.13   07 Apr 1995 11:31:18   LISA
 * Changed copyright information from Miles Inc. to Bayer Corp.
 * 
 *    Rev 1.12   27 Jan 1995 11:34:38   MIKE
 * Added 'IF_STATE.fcoCleanup'.
 * 
 *    Rev 1.11   03 Aug 1994 13:58:26   MIKE
 * Added FCO change from 1.6.1.1
 * 
 *    Rev 1.10   26 Apr 1994 17:53:28   MIKE
 * Added IF_STATE.shear, for orthogonal rotation & nonzero shear.
 * 
 *    Rev 1.9   22 Apr 1994 15:31:20   LISA
 * Made modifications to copyright/disclaimer notice.
 * 
 *    Rev 1.8   06 Mar 1994 12:52:22   MIKE
 * In IF_STATE, conditionally compile lsb_adj if CONVERGENT_FONTS == 1.
 * 
 *    Rev 1.7   03 Feb 1994 11:40:12   MIKE
 * Added awtsub_on and lsb_adj to IF_STATE for Convergent Fonts.
 * 
 *    Rev 1.6   23 Sep 1993 17:21:42   MIKE
 * Add IF_STATE.usePlugins; ROM1 support. Remove IF_STATE.extern_font
 * 
 *    Rev 1.5   09 Jul 1993 11:01:58   MAIB
 * added back making_bold field
 * 
 *    Rev 1.4   01 Jul 1993 14:28:50   MAIB
 * changed making_bold to non_z_wind
 * 
 *    Rev 1.3   14 May 1993 16:14:40   JOE
 * In structure IF_STATE, conditionally compiled "pathname" and "font_name"
 * based on (PST1_DISK || TT_DISK || (DYNAMIC_FONTS && IF_DISK)) to resolve
 * compiler errors.
 * 
 *    Rev 1.0   09 Dec 1992 11:37:28   LISA
 * Initial revision.
*/
/* if_type.h */

/* History
 *    05-May-90 awr  moved char_buf into IF_CHAR structure
 *    15-Jun-90 awr  added max_des field to COORD_DATA
 *    28-Jun-90 bjg  added OUTLINE_PARAMS structure definition. 
 *    27-Jul-90 awr  corrected structure sizes in comments
 *    29_Nov-90 tbh  Changed COORD_DATA structure by adding field 
 *                   "st_variation[4]"
 *    09-Dec-90 awr  added fields in COORD_DATA for new tx() ty() calcs.
 *    15-Jan-91 jfd  Changed field "baseline_offset" in structure IF_CHAR
 *                   from UWORD to WORD.
 *    20-Dec-90 dET  add support for multi-model MSC compilation.
 *                   changed COORD_DATA comment to reflect 66 bytes.
 *    10-Feb-91 awr  Made global flag char_is_if part of IF_CHAR structure.
 *                   Made Global or_on part of IF_DATA structure.
 *                   Added making_bold to IF_DATA structure.
 *     9-Mar-91 awr  Removed OUTLINE_PARAMS.
 *    25-Apr-91 awr  reorg'd if_type to distinguish IF Scaling Intelligence
 *                   stuff from output scaling.
 *    19-May-91 awr  Changed IF_CHAR structure for next_loop()
 *     3-Jun-91 awr  HQ4 changes
 *     9-Jun-91 awr  removed bmwidth & depth from SCALE structure
 *    16-Jun-91 awr  changed XY structure references to WORDVECTOR
 *     4-Jul-91 awr  Removed COORD_DATA "max_des" field. No longer used.
 *                   In SCALE added "wrong_read" field
 *                            changed "quadrant" from UWORD to WORD
 *                            removed "px" and "py"
 *     5-Aug-91 bjg  Changed "defined(ELASTIC... to (ELASTIC....
 *    25-Aug-91 awr  Moved function decls from c modules
 *     3-Sep-92 awr  removed scale.tt0 and reduced scale.m[] to 4 elements
 *    24-Nov-91 awr  added log_xpix & log_ypix defines
 *     7-Mar-92 awr  added CHAR_STATS to if_stat
 *    19-Mar-92 awr  Moved BOX to port.h.
 *    02-Apr-92 jfd  Added diag_control_tol and margin to COORD_DATA
 *                   Added stan_STAN_i to DIMENSION
 *                   Added stan_STAN_dim_lim to IF_STATE
 *    02-Apr-92 rs   Portability cleanup (see port.h).
 *    12 May 92 ss   Changed conditional compile of EXTERN_FONT to use the
 *                   new define NON_IF_FONT.
 *    14-Jun-92 awr  Changed type of xlate, and tbound to INTRs
 *    18-Jul-92 awr  Added est_ouline flag to if_state structure.
 *    21-Jul-92 awr  Conditional compile changes.
 *    07-Aug-92 rs   Compatibility w/Windows 3.1 (FIXED, POINTFX).
 *    14-May-93 jd   In structure IF_STATE, conditionally compiled
 *                   "pathname" and "font_name" based on
 *                   (PST1_DISK || TT_DISK || (DYNAMIC_FONTS && IF_DISK))
 *                   to resolve compiler errors.
 *    01-Jul-93 maib changed making_bold to non_z_wind
 *    09-Jul-93 awr  Added back making_bold to IF_STATE structure
 *    22-Sep-93 mby  Add IF_STATE.usePlugins; ROM1 support.
 *                   Remove IF_STATE.extern_font (never used).
 *    03-Feb-94 mby  For CONVERGENT_FONTS, added awtsub_on (used to be in
 *                   FONTINDEX structure) and lsb_adj (horizontal offset)
 *                   to IF_STATE.
 *    06-Mar-94 mby  Convergent fonts: in IF_STATE, lsb_adj is conditionally compiled.
 *    26-Apr-94 mby  Added IF_STATE.shear to detect situations of orthogonal
 *                   rotation and nonzero shear.
 *    26-May-94 mby  FCO change from 1.6.1.1:
 *                     Added if_state.FCObject - FCO font handle.
 *    27-Jan-95 mby  Added 'fcoCleanup' flag to IF_STATE structure.
 *    18-Apr-95 jfd  Added 'chIdptr' and 'PSchar_name' fields to IF_STATE 
 *                   structure (loaded by CGIFchIdptr() call).
 *    26-Aug-96 mby  Added IF_STATE.FCO_PluginH (plugin FCO handle, moved here from ix.h).
 *    18-Sep-96 mby  Added scaling constants for escapement computations.
 *    02-Oct-96 mby  Adjust scaling constants slightly to match HP's results.
 *    10-Jan-97 dlk  Removed ELASTIC_X and ELASTIC_Y options as part of
 *                   project to trim ufst.  Removed function prototypes for
 *                   elastic pixel_align() and sd_pixel_align.
 *    13-Jan-97 dlk  Removed CONVERGENT_FONTS option as part of project to trim
 *                   ufst.
 *    17-Mar-97 keb  Added two fields to if_state to capture plugin search levels
 *    22-Apr-97 mby  In COORD_DATA & IF_STATE structures, conditionally
 *                   removed various elements not needed except by IF_RDR
 *                   or FCO_RDR.
 *    29-May-97 sbm  Add TT_ROM_ACT functionality.
 *    29-Jul-97 awr  Added fields "startx" and "starty" to SMEAR_INSTANCE
 *                   structure.
 *    04-Sep-97 keb  Removed all references to BJG_BOLD_P6
 *    23-Jan-98 awr  Added typedef PIF_STATE. Moved data into if_state
 *                   for re-entrant. Very large character changes.
 *    03-Feb-98 dlk  Added defines for constants to convert PostScript metric
 *                   data to TrueType units (1000->2048) for HP4000 Emulation
 *                   (PSDESIGNUNITS, PS2TTMUL, PS2TTDIV, and PS2TTADD).
 *    23-Feb-98 awr  Removed (unused) if_state.glob_ital_tan
 *                   Added if_state.DECEND and adjust_angle for ASIANVERT
 *      30-Mar-98 slg     Comment out unused IF_STATE elts = contour_data,
 *                     subst_wdth_fac, alt_black_width, alt_black_height,
 *                     contour_flag, PreBrokenContrs.
 *                     Make lots of IF_STATE elts IF_RDR-only.
 *                     Move ADJUSTED_SKEL typedef here from adj_skel.h.
 *                       Move MLOCALs from extmem.c, intmem.c, cache.c, bucket.c,
 *                     lineto.c, cmpr.c, if.c, kanmap.c, skeletal.c, pcl_swap.c,
 *                     symmap.c into IF_STATE.
 *      31-Mar-98 slg     Move MLOCALs from tt_if.c,    mixmodel.c,    fc_if.c,
 *                     graymap.c, imagegr.c into IF_STATE.
 *      01-Apr-98 slg     Move MLOCALs from cubic.c, fc_intfl.c into IF_STATE. Also
 *                     move GLOBALs from cache.c, intmem.c, extmem.c (+ CGIFinitstate).
 *      02-Apr-98 slg     Move GLOBALs from bitmap.c, maker.c, graymap.c, cgif.c,
 *                     fpmath.c, outdata.c, bucket.c, path.c, fm.c, manipula.c
 *                     into IF_STATE.    Move TRAN typedef from tr_type.h.
 *                     Move CHARWIDTH typedef from segments.h.
 *      14-Apr-98 slg     Move GLOBAL fontindex from ix.c; pathname must be !ROM;
 *                     move GLOBAL special_case from quadra.c.
 *      15-Apr-98 slg     Move GLOBALs: chr_def[], chr_def_hdr from chr_def.c;
 *                     symbolset, symbol_setIF[], symbol_setTT[], symbol_setMT[]
 *                     from symmap.c; dup_points[] from if_init.c;
 *                     hchar_buf from fm.c; 
 *    19-May-98 keb  Added ENTITYACT define for TT_ROM_ACT functionality
 *    24-May-98 awr   Added comments and new field "numleft"
 *                    to BITSERVE_IM to fix bogus memory accesses in
 *                    gichar()
 *      29-May-98 slg  Move /psi vbls: MLOCALs and GLOBALs from t1isfnt.c, 
 *                     t0ikan.c, t1idecod.c, t1ihints.c, t1iscan.c.
 *    12-Jun-98 slg  Delete "fcoCleanup" field of IF_STATE (never set), remove
 *                     MULTICALLER data; move F_ONE def here; add peculiar 
 *                     "FSPvoid" parameter to OUT_TBL typedef, to solve circular-
 *                     reference problem (because OUT_TBL, which is used within
 *                     IF_STATE typedef, must point to an instance of IF_STATE).
 *      22-Jun-98 slg     "pix_al_ptr" function-ptr type change for reentrancy; move
 *                     several fn prototypes into shareinc.h
 *      08-Jul-98 slg  Move XLfont, lots of Surfer vbls into IF_STATE.
 *    09-Jul-98 dlk  Integrated new CFF processing support into UFST code base.
 *                   Changed copyright notice dates.
 *      09-Jul-98 slg  Remove first_loop/next_loop prototypes again (these were
 *                     moved into shareinc.h)
 *    05-Aug-98 awr  Changed all !ROM to DISK_FONTS
 *      31-Aug-98 slg     Move GRAYIMAGE definition from imagegr.h
 *    01-Oct-98 tbh  Removed rstack
 *    11-Dec-98 keb  Added code to support ASIANVERT for XLfonts
 *      06-Jan-99 slg     Arrange IF_STATE elements somewhat less arbitrarily: 
 *                     put all elements that are not conditionally-compiled at 
 *                     start of structure; group all related conditionally-compiled
 *                     elements together; improve packing of structs somewhat
 *                     (the real size-reduction payoff will occur if we can turn
 *                     "int" elements into "SW16" elements, however). Also delete 
 *                     "width_mixm" (used only in obsolete "mixmodel.c").
 *      19-Jan-99 slg     Include contents of former cache.h, bitmap.h - moved
 *                        into if_type.h to resolve customer name conflict
 *    26-Jan-99 keb  Removed ASIANVERT condition from definition of xl_char_class
 *      July-99 swp  Replaced the NZW apparatus,  enabled if SWP799 is defined.
 *      17-Jan-00 slg     Vertical-writing changes (for keb): remove DECENDER,
 *                     adjust_angle, XLfont, xl_char_class from IF_STATE; 
 *                     add charVertWrit, have_adjusted_angle to IF_STATE.
 *      31-Jan-00 slg  Integrate disk/rom changes (for jd) - add "font_access"
 *                     to IF_STATE; add DISK_ACCESS / ROM_ACCESS defines.
 *    03-Feb-00 awr  Changed SWP799 to WINDCOMP
 *    10-Feb-00 awr  Removed PST1_ROM
 *    24-Mar-00 jwd  Cache w/NO_SYMSET_MAPPING fix.
 *    28-Sep-00 jfd  In IF_STATE, added fields 'BitmapManipulated' and 'BitmapEmbedded'.
 *      05-Dec-00 slg  Add new typedefs for CGIFtt_cmap_query() function: internal 
 *                     structs CMAP_SUBTABLE & CMAP_HEAD; return-info structs 
 *                     CMAP_ENTRY & CMAP_QUERY; MAX_NUM_CMAP define.
 *    02-Apr-01 awr  Return error if PS path doesn't start with a moveto
 *    02-Apr-01 awr  Removed fixed size array from ACT memory management
 *    19-Apr-01 awr  Added fields to NZ_NODE & NZ_instance to find wrong wound contours
 *      04-May-01 slg  Non-UFST data-type cleanup; get rid of AGFATOOLS hack;
 *                     tighten up conditional compile for embedded bitmaps.
 *    24-May-01 swp  removed T1I_HINT_STR, NUMHINTS from 50 to 96, and hinttype
 *                     enabled by #define NEW_PS_HINTS
 *    24-Aug-01 jfd  Added PCL_font_type field to IF_STATE.
 *    27-Aug-01 jfd  Moved "PCL_font_type" field outside of BYTEORDER block.
 *    06-Dec-01 jfd  Added new fields "stik_font" and "stik_char" to IF_STATE structure.
 *    16-Jan-02 jfd  Removed conditional compiles surrounding "stik_font" and "stik_char"
 *                   in IF_STATE.
 *    07-Feb-02 jfd  Moved "stik_font" and "stik_Char" fields from IF_STATE to fs_GlyphInfoType
 *                         structure.
 *    27-Aug-02 jfd  Added "lpm" field to IF_STATE structure.
 *    23-Sep-02 jwd  Added OPTIMIZE_FCOACCESS constants and macros.
 *    25-Sep-02 jfd   Added stroke font refline fields to IF_STATE.
 *    23-Oct-02 jfd   Added fields "xlpm" and "ylpm" to IF_STATE (moved from FONTCONTEXT).
 *    04-Nov-02 jfd   Added missing character substitution support.
 *    07-Jan-03 jfd  Added "update_reflines_flag_set" field to IF_STATE.
 *    12-Jun-03 jfd  Added "cache-by-reference" support.
 *    13-Aug-03 jfd  Added "table-by-reference" support.
 */

#ifndef __IF_TYPE__
#define __IF_TYPE__

/* The OUTL_COORD type is used for "outl_XYdata", below */
#if VLCOUTPUT
typedef SL32 OUTL_COORD;
#else
typedef SW16 OUTL_COORD;
#endif

/* Asian-cache constant */

#define USE_LOW_BYTE      1  /* set to 1 to use lo-byte of chId as offset */
                             /* into hash table for better distribution   */

/*** START moved from cache.h ***/

#if CACHE

#define HASHMAX         256   /* max rows to contain column hash lists */
#define SSMAX         256


/*----------------------*/
/*      Font            */
/*----------------------*/

typedef struct
{
    DLL   link;           /* doubly linked list pointers- this slot may be
                           * in an active least recently used list or it may
                           * be unused in the avail list.
                           */
    UW16 bitmapCount;    /* Number of bitmaps in this font */
    FONTCONTEXT fc;
#if DISK_FONTS
    PATHNAME pathname;
#endif
#if COMPRESSED_CACHE
    HIFBITMAP hifbm;
    PIFBITMAP pifbm;
    SL32 size;     /* size of pifbm->bm[] */
#endif

#if UFST_MULTITHREAD
    UL32 thread_ids[MAX_THREADS];
#endif
/*
 * 1/25/94 maib
 * new caching scheme for asian encoding
 */
#if USE_ASIAN_CACHE
    MEM_HANDLE hash_table[HASHMAX]; /* hash table */
#else
    HIFBITMAP hbuf[SSMAX];  /* buffer handles of cached characters */
#endif
}
cacheFONT;
typedef cacheFONT FARPTR * PFONT;

#endif /* CACHE */

/*** END moved from cache.h ***/

/*** START moved from bitmap.h ***/


#if NON_Z_WIND
#ifdef WINDCOMP    
/* new non-zero winding structures */
typedef struct {
    SL32 x;            /* the x coordinate of the transition */
    SL32 next;            /* the index of the next NZNODE in the raster */
    } NZNODE;
typedef struct {
    SW16 num;            /* number of slots in <indices> */
    SL32 next_index;    /* next available node number */
    SL32 stop_index;    /* 1+maximum node number */
    MEM_HANDLE htrans;
    MEM_HANDLE hindices;
    MEM_HANDLE hnodes;
    SL32 *indices;        /* the starting node for each row of bitmap */
    NZNODE *nodes;
    } NZTRANS;
#else /* ! WINDCOMP */

typedef struct NZ_NODE
        {
            struct NZ_NODE FARPTR * link;
            PNZCOUNTER  pval;
            NZCOUNTER   onoff;
            NZCOUNTER   lowRow;
            NZCOUNTER   valCount;
#if FIX_CONTOURS
            /* for detecting badly wound contours */
            SL32 right;        /* Number of transitions that matched our expectations */
            SL32 wrong;        /* Number we thought were on but were really off or vice versa */
            SW16 contourNum;   /* Contour that this transition run belongs to */
#endif /* FIX_CONTOURS */
        } NZ_NODE;

typedef NZ_NODE FARPTR * PNZ_NODE;

typedef struct
{
    NZCOUNTER  tran_run_ct;  /* number of transition runs = number of
                              * changes in y direction in character outline
                              */
    SW16       blackdepth;   /* longest transition run */
    NZ_NODE    pend_list;    /* head nodes for linked list */
    NZ_NODE    active_list;
    NZCOUNTER  start_row; /* startins row of current run */
    NZCOUNTER  valCount; /* number of transitions in current run */
    NZCOUNTER  overflow; /* we tried to write too many runs */
    NZCOUNTER  done;     /* all nodes exhausted; arms for overflow err */
    PNZ_NODE   nodes;  /* array of tran_run_ct nodes */
    NZCOUNTER  cur_node; /* index of current node */
    PNZCOUNTER transition; /* One row of transitions- starts just after nodes[] */
    PNZCOUNTER pvalues;   /* array of pvalues- starts just after nodes[] */
    PNZCOUNTER pval;      /* next place to write a transition value */
#if FIX_CONTOURS
    SW16 contourNum;        /* current contour number - copy into all new NZ_NODES */
    /* Next is for detecting badly wound contours */
    MEM_HANDLE hisWrong;    /* array indexed by contourNum, Set to 1 if the contour */
    LPUB8 isWrong;          /* is wound wrong; that is if black isn't on the right. */
    SW16 checkingContours;  /* Set if FC_ISCONTCHK(&if_state.fcCur)) and we're doing pcl6 bold,
                             * bold horizontal or missing pixel (or_on). Means we will check
                             * the characters contours for correct direction and build the
                             * array isWrong[]
                             */
#endif
} NZ_INSTANCE;
typedef NZ_INSTANCE FARPTR * PNZ_INSTANCE;
#endif /* WINDCOMP */
#endif /* NON_Z_WIND */


typedef struct
{
    CHAR_STATS o;
    LPUB8      tran_buffer;
    LPUB8      or_buffer;
    SW16VECTOR bmdim;     /* bitmap dimensions */
#if NON_Z_WIND

#ifdef WINDCOMP
    NZTRANS *trans;            /* new non-zero-winding aparatus */
#else /* !WINDCOMP */
    NZCOUNTER  tran_run_ct;  /* number of transition runs = number of
                              * changes in y direction in character outline
                              */
    NZ_INSTANCE nz_instance;
#endif /* WINDCOMP */
#endif

    UW16       polarity;
    SL32         ydir;
    SL32        tsize;       /* transition array size in bytes */
    SL32         dytran;
    SL32         yraster;
    SL32        toff;        /* offset to current raster in trans array */
    SL32         xx;          /* Bit offset into raster of transition */

#ifndef WINDCOMP
    /* only needed for old NZW aparatus */
   /* Missing Pixel Recovery */

    BOOLEAN     beam;         /*  TRUE if current segment makes on trans */

    BOOLEAN     first_tran;   /*  TRUE until 1st transition is produced  */

    SL32         ptran;        /*  previous transition: last xx produced  */
                              /*  by previous line segment.              */
    BOOLEAN     seton;        /*  Current line segment is producing on   */
                              /*  transitions.                           */
    BOOLEAN     wason;        /*  Previous line segment was producing on */
                              /*  transitions.                           */

        /*  Values when first transition is produced. These values are
         *  used to close the loop by linking the last transition in
         *  the loop to the first transition.
         */

    SL32         ydir1;
    BOOLEAN     seton1;
    SL32         xx1;
    SL32         dytran1;
    SL32        toff1;
#endif /* !WINDCOMP */

#if TILE
    SL32  above;
    SL32  below;
    INTR clip_fops_top;
    INTR clip_fops_bot;
#endif
} RASTER;

/*****************************************/
/*                                       */
/*      Raster Line Organizations        */
/*                                       */
/*****************************************/
#if (RASTER_ORG == EIGHT_BIT_CHUNK)

typedef UB8           CHUNK;
typedef UB8  FARPTR * LPCHUNK;
#define CHUNK_COUNT   1
#define CHUNK_SHIFT   3
#define CHUNK_MASK    7

#elif (RASTER_ORG == SIXTEEN_BIT_CHUNK)

typedef UW16          CHUNK;
typedef UW16 FARPTR * LPCHUNK;
#define CHUNK_COUNT   2
#define CHUNK_SHIFT   4
#define CHUNK_MASK    15

#elif (RASTER_ORG == THIRTYTWO_BIT_CHUNK)

typedef UL32          CHUNK;
typedef UL32 FARPTR * LPCHUNK;
#define CHUNK_COUNT   4
#define CHUNK_SHIFT   5
#define CHUNK_MASK    31

#elif (RASTER_ORG == SIXTYFOUR_BIT_CHUNK) && defined(HAS_FS_INT64)

/* defining CHUNK as "double" won't work - 64-bit ints required */
typedef FS_INT64        CHUNK;
typedef FS_INT64 FARPTR * LPCHUNK;
#define CHUNK_COUNT   8
#define CHUNK_SHIFT   6
#define CHUNK_MASK    63

#endif  /* RASTER_ORG == EIGHT_BIT_CHUNK */

/*** END moved from bitmap.h ***/

#define  MAX_DESIGN  0x3fff    /* 16K - 1, max design unit coordinate */
#define  MAX_LOOPS    64
#define  MAX_YCLASS  256
#define  MAX_YLINES  256
#define  MAX_SKEL    96
#define ROOT            (0xff)  /*  init value: assoc's parent spec   */
#define PROCESSED       1       /*  status of skel pnt: processed     */
#define NOT_PROC        0       /*  status of skel pnt: not processed */
#define NOT_ALIGNED     -1      /*  alignment status for skel points  */

#define R_TYPES         1       /*  1 turns on "R" type functionality */
#define R_TWO_I         2       /*  "R" type index of two             */
#define YPROC           1
#define XPROC           2


/*---------------------------------------*/
/* Constants for escapement computations */
/*---------------------------------------*/
#define  IFDESIGNUNITS  8782
#define  PSDESIGNUNITS  1000

#define  IF2TTMUL       3335L    /* Constants to scale DOWN by 0.23221 */
#define  IF2TTDIV       14362L   /* (8782 design units to 2048).  */
#define  IF2TTADD       7181L    /* .2322099986 */

#define  ADJWIDTHMUL    12500L   /* Constants to convert FCO metrics */
#define  ADJWIDTHDIV    12447L   /* from non-8782 to 8782 units if   */
#define  ADJWIDTHADD    6223L    /* DU_ESCAPEMENT = 0 */

#define  PS2TTMUL       4194L    /* Constants to scale UP by 2.048 */
#define  PS2TTDIV       2048L    /* (1000 design units to 2048).  */
#define  PS2TTADD       1024L    /* 2.048 */
                                 /* (72*2048) / (72*1000) = 2.048 */
                                 /* 2048*2.048=4194.304= 4194 */
                                 /* 1000*2.048=2048 */
                                 /* 2048*.5=1024 */

/* vertex code macros */

#define V_CONTACT(v)  (BOOLEAN)(((v)&1) == 0)
#define V_XSKEL(v)    ((v)&4)
#define V_YSKEL(v)    ((v)&8)


typedef struct
{
    SW16 xyoff;
    SB8 spare;
    SB8 polarity;
    SW16 child;
    SW16 sibling;
}
CTREE;
typedef CTREE FARPTR * PCTREE;

/*---------------------------------------------------------------------*/
#ifdef LINT_ARGS

typedef struct {
    UW16 (*start_char) (FSPvoid PVOID, PVOID);
    UW16 (*end_char)   (FSPvoid PVOID);
    UW16 (*start_loop) (FSPvoid PVOID, UW16);
    UW16 (*end_loop)   (FSPvoid PVOID);
    UW16 (*moveto)     (FSPvoid PVOID, INTR, INTR);
    UW16 (*lineto)     (FSPvoid PVOID, INTR, INTR);
    UW16 (*quadto)     (FSPvoid PVOID, INTR, INTR, INTR, INTR);
    UW16 (*cubeto)     (FSPvoid PVOID, INTR, INTR, INTR, INTR, INTR, INTR);
} OUT_TBL;
typedef OUT_TBL FARPTR * POUT_TBL;

#else  /* !LINT_ARGS */

typedef struct {
    UW16 (*start_char) ();
    UW16 (*end_char)   ();
    UW16 (*start_loop) ();
    UW16 (*end_loop)   ();
    UW16 (*moveto)     ();
    UW16 (*lineto)     ();
    UW16 (*quadto)     ();
    UW16 (*cubeto)     ();
} OUT_TBL;
typedef OUT_TBL FARPTR * POUT_TBL;

#endif /* LINT_ARGS */

typedef struct
{
    PSW16VECTOR cv;         /* coordinates (contacts are interleaved)     */ 
    LPSB8       v;          /* vertex codes                               */
    UW16       npnt;       /* number of curve points                     */
    UW16       ncontact;   /* number of contact points                   */
    UW16       ncoords;    /* number of vector coordinates               */
    SB8        polarity;
}
LOOP;
typedef LOOP FARPTR * PLOOP;


/*---------------------------------------------------------------------*/
/*                      S m e a r                                      */
#if BOLD_HORIZONTAL || BOLD_P6
typedef struct SMEAR_INSTANCE
{
    FILECHAR *name;
    SL32VECTOR xaxis;
    SL32VECTOR yaxis;
    SL32 dir;            /* +1 : */
                         /* -1 : */
    SL32 firstdir;    /* direction of first lineto() */

    /* Hook into render chain */
    PVOID p;       /* instance */
    OUT_TBL out;   /* function table containing starchar(), lineto() ...*/

    /* First curve element */
    SL32 isFirst;
    INTR p0x, p0y;   /* My callers last lineto() or moveto() */
    INTR startx, starty;   /* My caller's moveto() */
    UW16 polarity;
    BOOLEAN beam;    /* TRUE if current lineto is not in shift mode */
                     /* FALSE if shift mode is on                   */
    BOOLEAN firstbeam;
} SMEAR_INSTANCE;

typedef SMEAR_INSTANCE FARPTR  * PSMEAR_INSTANCE;
typedef PSMEAR_INSTANCE FARPTR * PPSMEAR_INSTANCE;
#endif /* BOLD_HORIZONTAL || BOLD_P6 */

/*                      S m e a r                                      */
/*---------------------------------------------------------------------*/
/*                      I F _ C H A R                                  */


/*---------------------------*/
/*     DIMENSION             */
/*---------------------------*/

typedef struct
{
    UB8   num_dim;       /*  number of dimensions              */
    UB8   stan_STAN_i;   /*  index to STANDARD standard dim    */
    LPUW16  value;         /*  arr of dimension values           */
    LPUB8  attrib;        /*  arr of dim flags (RTZ = bit 0)    */

}  DIMENSION;
typedef DIMENSION FARPTR * PDIMENSION;

/*---------------------------*/
/*   yclass_def_type         */
/*---------------------------*/

typedef struct
{
    UB8   num_yclass_def; /*  num of loc Y class definitions    */
    LPUB8  yline_high_i;   /*  arr of loc Y line indices         */
    LPUB8  yline_low_i;    /*  arr of loc Y line indices         */

}  YCLASS_DEF;
typedef YCLASS_DEF FARPTR * PYCLASS_DEF;

/* 38 or 43 SB8s */
typedef struct
{
    UB8  num_skel;        /* number of skels         */
    LPUB8 num_skel_loop;   /*  num of skel per loop   */
    LPUW16 skel_to_contr;   /*  skel indices to contr  */
    UB8  num_trees;       /* number of trees (roots) */
    UB8  num_nodes;       /* number of tree nodes    */
    LPUB8 tree_skel_i;     /* skeletal indices        */
    LPUB8 tree_attrib;     /* skeletal attributes     */

    UB8  stan_dim_i;

/** I6.2.3   Interpolated Association data */

    UB8  num_intrp;             /* number of pairs of interp skels */
    LPUB8 intrp1_skel_i;         /* 1st interp skel indices    */
    LPUB8 intrp2_skel_i;         /* 2nd interp skel indices    */
    LPUB8 num_intrp_assoc;       /* number of interps per pair */
    UB8  tot_num_intrp_assoc;   /* number of interp assocs    */
    LPUB8 intrp_assoc_skel_i;    /* interp assoc indices       */

}
SKEL;
typedef SKEL FARPTR * PSKEL;


/*                        C O O R D _ D A T A                          */
/*---------------------------------------------------------------------*/
/*                             S C A L E                               */

/*  NOTE: that all macros work properly regardless
 *        of the sign of the argument.
 */
#define log_xpix      if_state.x.grid_shift
#define log_ypix      if_state.y.grid_shift
#define xpix          if_state.x.pixel_size
#define ypix          if_state.y.pixel_size
#define half_xpix     if_state.x.half_pixel
#define half_ypix     if_state.y.half_pixel
#define XCEILING(v)   (1 + (((v) - 1) >> if_state.x.grid_shift))
#define XFLOOR(v)     ((v) >> if_state.x.grid_shift)
#define YCEILING(v)   (1 + (((v) - 1) >> if_state.y.grid_shift))
#define YFLOOR(v)     ((v) >> if_state.y.grid_shift)
#define XPIXEL(v)     (((v) + half_xpix) >> if_state.x.grid_shift)
#define YPIXEL(v)     (((v) + half_ypix) >> if_state.y.grid_shift)


typedef struct
{
  /* -----------Intellifont Scaling Intelligence  values----------- */

    INTR    grid_align;     /* x & grid_align is truncated to grid  */
    SW16    orig_pixel;     /*  Original imprecise pixel size       */
#if IF_RDR || FCO_RDR
    SW16    p_pixel;        /*  precise pixel - shifted so that     */
                            /*    16K <= p_size < 32K               */
    SW16    p_half_pix;     /*  half precise pixel                  */
    SW16    bin_places;     /*  bits after the binary point above   */
#endif  /* IF_RDR || FCO_RDR */
#if IF_RDR
    SL32    round[4];       /*  rounding value for 4 "R" types      */
    SW16    con_size;       /*  min value for constrained dim       */
    SW16    diag_control_tol;   /*  DWU tolerance for diag control  */
#endif  /* IF_RDR */


  /* --------------- Standard Dimensions -------------------------- */
#if IF_RDR
    SW16    stand_value;    /* Standard dimension in design units   */
    SW16    st_value[4];    /* These two arrays are results of      */
    SW16    st_pixels[4];   /* pixel_align() using all 4 R-types    */
    SW16    st_variation[4];/* Amount stan dim rounds 11-29-90 tbh  */
#endif  /* IF_RDR */

  /* --------------  Scaling to Output Space ---------------------- */

    SW16    pixel_size;     /* pixel dimension (power of 2)         */
    SW16    half_pixel;     /* half pixel dimension (power of 2)    */
    SW16    grid_shift;     /* x >> grid_shift is grid number       */
#if IF_RDR
    SW16    shift;          /* 16 - bin_places - grid_shift         */
    SW16    shift_rnd;      /* 2 ** (shift - 1)                     */
#endif  /* IF_RDR */

}  COORD_DATA;
typedef COORD_DATA FARPTR * PCOORD_DATA;

/* Save a comp_pix context to see what changes to next time. */
typedef struct {
   UW16       masterPt;            /* master point size    */
   UW16       xRes;
   UW16       yRes;
#if FCO_RDR
   UW16       orThreshold;         /* 10-13-94, mby */
   SB8        compositionFlag;     /* 0=IF compatible; 1=TT compatible */ 
#endif  /* FCO_RDR */
#if SLIM_FONTS
   UB8        mirflags;            /* mirror_flags   */
#endif
} COMP_PIX_CONTEXT;

/*  Values for quadrant field below.
 * A value of 0 means arbitrary rotation.
 */
#define ROT0    1
#define ROT90   2
#define ROT180  3
#define ROT270  4


/*** start of defines/ typedefs for UFST reentrancy ***/

#define DISK_ACCESS    0
#define ROM_ACCESS    1

/* moved here from fpmath.h */
#define F_ONE   0x10000L

/* moved here from /sys/inc/segments.h */
/*--------------------------------*/
/*  Character Width Segment (104) */
/*--------------------------------*/
typedef struct
{
    UW16 width;
    UW16 flags;

} CHARWIDTH;
typedef CHARWIDTH FARPTR * PCHARWIDTH;

/* moved here from intmem.c, extmem.c */
#define NP    3                /* number of memory pools      */

#if INT_MEM_MGT  /*  internal memory manager  */
/* moved here from intmem.c */
#define NH               9      /* number of handles */

typedef struct
{
    SL32        size;    /* size of free block */
    MEM_HANDLE  next;    /* next free block */
} MEMHEAD;
typedef MEMHEAD FARPTR * PMEMHEAD;

typedef struct
{
    MEMHEAD  nullblock[NP];    /* empty mem blocks for initialization      */
} PAGE0;

typedef struct
{
    SL32    size;        /*  size of block given to us thru CGIFfund() */
#if (HUGE_PTR_SUPPORT)
    HPSB8   ptr;         /* current address of this block */
#else
    LPSB8   ptr;         /* current address of this block */
#endif
    UW16   pool;        /* memory pool that block belongs to */
} MEM;
typedef MEM FARPTR * PMEM;
#endif    /* INT_MEM_MGT */

#if (CGBITMAP)
/* moved here from /bmp/lineto.c */
typedef struct tran_struct {
    SL32            toff;
    SL32            ydir;
    SL32            xx;
    SL32            dytran;
    BOOLEAN        seton;
} Tran_lineto;

typedef struct {
    SL32        toff;
    SL32            xx;
    SL32            ydir;
    SL32            ptran;
    SL32            yraster;
    SL32            dytran;
    BOOLEAN        beam;
    BOOLEAN        seton;
    BOOLEAN        wason;
} State_lineto;
#endif    /* CGBITMAP */

#if COMPRESSED_CACHE
/* moved here from /dep/cmpr.c */
/*  Bitserver.  This object represents a stream of bits. */
typedef struct
{
    SW16  error;
    UW16 *wordstream;   /* array of maxwordsinstream UW16s        */
    UL32  bitbuf;       /* bit buffer, read or write next UW16    */
                        /* from wordstream[numused]               */
    SW16  bitct;         /* number of bits stored in bitbuf       */
    INTG  numused;       /* num UW16's read or written            */
    INTG  maxwordsinstream;  /* number of UW16's in the stream    */

    SW16  bitWidth; /* word width in bits for putbits() & getbits() */
    UL32  mask;     /* bitbuf & mask is the next bitWidth bits in stream */
} BITSERV_CMPR;
#endif    /* COMPRESSED_CACHE */

#if OUTLINE
/* moved here from /out/outdata.c */
typedef struct
{
    INTR p0x, p0y;   /* My callers last lineto() or moveto() */
    CHAR_STATS s;             /* copy of outline stats */
#if OLDATA
    HIFOUTLINE hol;   /* Handle of outline being constructed */
    PIFOUTLINE pol;   /* pointer "   "       "        "      */

    POUTLINE_CHAR outcharptr;
    POUTLINE_LOOP oloop;      /* current loop under construction */
    LPSB8 segptr;             /* next segment in outline data structure */
    PINTRVECTOR pntptr;       /*  "   point   "     "      "      "     */

    UW16 format;      /* */
    SW16 tot_pnts;    /* total number of points generated   */
    SW16 tot_segs;    /* total number of segments generated */
#else
    VOID *pClientHook;  /* Adobe */
    VOID *pPathProcs;
    VOID *pCharIO;
    INTG  shiftToFixed;  /* shift fop data left to get 16.16 */
#endif
} ODATA;
typedef ODATA FARPTR * PODATA;
#endif    /* OUTLINE */

#if IF_RDR
/* moved here from /sys/inc/adj_skel.h */
typedef struct
        {
        SW16    original;       /*  original value of skel point      */
        SW16    intermed;   /*  intermediate "original" value     */
        SW16    adjusted;       /*  current abs skel point coord valu */

        SW16    baseproj;       /*  for yskel: same as original       */
                                /*  for xskel: baseline projection    */

        UB8   round_i;        /*  "R" type index for association    */

        }  ADJUSTED_SKEL;

typedef ADJUSTED_SKEL FARPTR * PADJUSTED_SKEL;

/* moved here from /sys/inc/tr_type.h */
typedef struct
{
  /* the current transform */
    SW16  num,den;
    SW16  old0;
    SW16  new0;     /* adjusted coordinate values */
    SW16  half_den;

/*-------- above is locked for assembly language access */

    SW16  old1;
    SW16  new1;

    LPUB8 num_skel_loop;   /* Number of skeletal points in next loop */
    PADJUSTED_SKEL skel;    /*  ptr to original & adjusted values */
                            /*  of next segment end               */
    LPUW16 skel_to_contr;   /*  skel indices to contr             */

    SW16  nsk;  /* number of skels in current loop */

  /* Current character */

    SW16 end;   /* end vector number in scaling  segment */
    SW16 sct;   /* number of skels processed in current loop  */

    /* Values at the start of a loop. These values will also */
    /* be used at the end of the loop.                       */

        SW16  num0,den0;
        SW16  half_den0;
        SW16  end0;
        SW16  old00;
        SW16  new00;
} TRAN;
typedef TRAN FARPTR * PTRAN;

#if BOLD
/* moved here from /cor/if_init.c */
typedef struct
{
    UW16 loop;
    UW16 coord_index;   /* coordinate index within loop */
    UW16 x;
    UW16 y;
    UB8 xsk0, xsk1, ysk0, ysk1;
} DUP_POINTS;
typedef DUP_POINTS * PDUP_POINTS;
#define MAX_DUP_POINTS 48
#endif    /* BOLD */  

#endif    /* IF_RDR */

#if GRAYSCALING
/* moved here from /gray/graymap.c */
#define MAXGSCOUNT    5
typedef struct
{
    UL32 maxbytestream;
    MEM_HANDLE bytestream;
    LPUB8 p_bytestream;
    UINTG numused;
    UW16 bitbuf;
    UB8  bitct;
} BITSERVE_GM;

/* moved here from /gray/imagegr.c */
/* Bit server: converts a stream of bytes to a stream of bits.    */
typedef struct
{
    SL32 numleft;     /* number of unused bytes left in the stream */
    UB8 *bytestream;  /* points to unused bytes in stream */
    UW16 bitbuf;      /* bit buffer normally contains 9 to 16 bits */
    UB8  bitct;       /* number of bits left in bit buf */
} BITSERVE_IM;

/* moved here from /gray/imagegr.h */
typedef struct
{
    /* Sub-pixel definition */
    SW16  numXsubpixels;
    SW16  numYsubpixels;
    SW16 maxpixval;     /* max gray value a pixel can have */
    SW16 maxphval;      /* max gray value a phase can have */
    /* Grayscale phasing */
    SW16 numXphases;
    SW16 numYphases;
    SW16 totphases;

    UW16 bsmask;     /*  buf&bsmask = the low few bits of bit stream  */
    UW16 bsct;       /*  buf>>bsshift = new buf discarding above bits */
} GRAYIMAGE;

#endif    /* GRAYSCALING */


#if BYTEORDER == LOHI
/* moved here from /psi/t1idecod.c (sharing "tmp_sw" struct definition) */
/* Swapping macros */

#define WSWAP  if_state.tmp_sw.w = *(UW16*)p; \
*p++ = if_state.tmp_sw.b.b1; \
*p++ = if_state.tmp_sw.b.b0;

#define LSWAP   \
  if_state.tmp_sw.w = *(LPUW16)p; \
  *((LPUW16)p) = *((LPUW16)(p+2)); \
  *((LPUW16)(p+2)) = if_state.tmp_sw.w; \
  WSWAP \
  WSWAP

#else
/* don't swap in this case, just bump pointer to keep up w/code -ss 10/24/91 */
#define WSWAP   p += 2;
#define LSWAP   p += 4;

#endif    /* BYTEORDER == LOHI */


#if PST1_RDR

#define NUMHINTS 96

#define T1ARGSTACKSIZE    50
#define T2ARGSTACKSIZE    50
#endif    /* PST1_RDR    */

/* new typedefs / defines for CGIFtt_cmap_query() function */
#if (TT_ROM || TT_DISK || TT_ROM_ACT)

#define MAX_NUM_CMAP 20
    
typedef struct 
{
    UW16 platId;
    UW16 specId;
    UL32 offset;
}
CMAP_SUBTABLE;
    
typedef struct
{
    UW16 version;
    UW16 numCmap;
    CMAP_SUBTABLE subtable[MAX_NUM_CMAP]; 
}
CMAP_HEAD;

typedef struct 
{
    UW16 platId;
    UW16 specId;
}
CMAP_ENTRY;
    
typedef struct
{
    UW16 version;
    UW16 numCmap;
    CMAP_ENTRY entry[MAX_NUM_CMAP]; 
}
CMAP_QUERY;

/* new typedefs / defines for CGIFtt_name_query() function */

/* buffer size limits for TTF_NAME structs */
#define MAX_FONT_NAME_LEN            50
#define MAX_FONT_FAMILY_NAME_LEN    50
#define MAX_COPYRIGHT_LEN            200

#define MSFT_ENC           3    /* platform ID */
#define US_ENGL       0x0409    /* language ID in name table */

typedef struct {
    SB8 font_name[MAX_FONT_NAME_LEN];
    BOOLEAN font_name_too_long;
    SB8 font_family_name[MAX_FONT_FAMILY_NAME_LEN];
    BOOLEAN font_family_name_too_long;
    SB8 copyright[MAX_COPYRIGHT_LEN];
    BOOLEAN copyright_too_long;
    } NAME_QUERY;        /* abbreviated contents */

#endif    /* (TT_ROM || TT_DISK || TT_ROM_ACT) */

#if LINKED_FONT

#define MAX_FONT_NUM 10
#define GLOBAL_FONT_ID 0
#define MEMBER_FONT_ID 1

typedef struct {
    
    SL32        font_id;
    UB8            font_id_used;    /* if true, font_id above is used */
    FILECHAR    nameInSet[CFFNAMELEN];
    UL32        optionalThreshold;
    UW16        ssnum;
    LPUB8        font_hdr;        /* pointer to font header of each seperate font */
    UL32        dl_ssnum;
    UW16        user_platID;    /* user-supplied platform ID of CMAP table */
    UW16        user_specID;    /* user-supplied specific ID of CMAP table */
    UL32        ExtndFlags;        /* not all bits needed */ 
    SW16        ttc_index;    /* index of font within TTC (TrueTypeCollection) file. */
    SW16        userDesignVector[4];  /* Multi Master user design vector */
    UW16        format;       /* format flags, only certain bits needed */
    
} FONT_INFO; 


typedef struct  {
    SB8        lf[11];
    SL32    version_num;    
    UL32    ft_counter;
    FONT_INFO font_info[MAX_FONT_NUM]; 
    } LINKED_FNT;

#endif

#if DIRECT_TT_TABLE_ACCESS
#define TT_TABLE_SLOT_UNUSED    (-1)
#define TT_TABLE_BLOCK_SIZE        10

typedef struct {
    LPUB8   pFont;            /* ptr to ROM, or pathname */
    LPUB8   pTable;            /* ptr to TT table */
    MEM_HANDLE hFont;        /* handle of pathname (DISK only) */
    MEM_HANDLE hTable;        /* handle of TT table */
    UL32    size;
    UL32    tag;            /* tag of TT table */
    SW16    ttc_index;        /* index of font within TTC if applicable */
    SW16    num_refs;        /* number of open references to table or  */
                            /* TT_TABLE_SLOT_UNUSED if available slot */
    BOOLEAN    buff_allocd;    /* = 1 if buffer needs to be freed, else = 0 */
} DIRECT_ACCESS_ENTRY;

typedef struct {
    /* UW16    num_entries; */
    UW16 capacity;
    MEM_HANDLE htables;
    DIRECT_ACCESS_ENTRY *tables;
} DIRECT_ACCESS_TABLES;
#endif

typedef void*  MUTEX;

typedef struct  {
    FONTCONTEXT cur_loc_fc; /* The last font context used by comp_pix() */

/* moved here from /da/bucket.c */
    MEM_HANDLE hBUCKlru;            /*  Least recently used list for BUCKETs */

/* moved here from /dep/extmem.c, intmem.c (two mutually-exclusive MLOCALs) */
    SL32   mem_avail[NP];   /* Available memory in pool    */
/* moved here from /dep/extmem.c, intmem.c (two mutually-exclusive GLOBALs) */
    SL32   mem_fund[NP];    /* Total memory in each pool   */

#if INT_MEM_MGT  /*  internal memory manager  */
/* MLOCALs moved here from intmem.c */
        MEM_HANDLE avail[NP];    /* circular linked list of free mem blocks */
        PAGE0 page0;
        MEM mem[NH];
#endif    /* INT_MEM_MGT */

#if CACHE
/* MLOCALs moved here from /dep/cache.c */
    MEM_HANDLE  hFNTlru;            /* Least recently used fonts       */
    MEM_HANDLE  hBMlru;             /* LRU character IFBITMAPs         */
#endif

#if UFST_MULTITHREAD
    UL32 client_count;                /* number of active clients ...    */
#endif

#if FCO_RDR
    /* don't free CG_SERVER until = 0  */
    MEM_HANDLE FCObject;     /* for Font Collection Object, from CGIFfont() */
    MEM_HANDLE FCO_PluginH;  /* handle of plugin FCO */
    MEM_HANDLE    FCO_List;  /* linked list of FCO handles */
#if PLUGINS
    MEM_HANDLE    FCO_pTrees;    /* MicroType plugin tree table */
    SL32  fco_StickyPlugin;    /* If set, turn off plugin processing in fco_InitFCO() */
#endif  /* PLUGINS */

#endif
    UW16 MTinitstate;
} CG_SERVER;
/*---------------------------------------------------------------------*/
/*                         I F _ S T A T E                             */

typedef struct
{
/*                             S C A L E                               */
  /* was in SCALE structure */

    COORD_DATA   x;           /* x grid alignment and scaling           */
    COORD_DATA   y;           /* y grid alignment and scaling           */
    FPNUM        m[4];        /* matrix trsnsform from design to output */
    SW16VECTOR   tt;
    INTRVECTOR   xlate;

    COMP_PIX_CONTEXT   comp_pix_context;  /* 27-Jan-98 awr */
    INTRBOX  tbound;          /* bounding box in working bitmap space   */

    INTRVECTOR  p0;           /* Current point in output path           */
    OUT_TBL     out;          /* Table of current output functions      */
    PVOID       out_instance; /* Output processor instance and state    */

    PBUCKET pbucket;         /* current typeface bucket */
    CHAR_STATS cs;          /* character stats */

    FONTCONTEXT cur_loc_fc; /* The last font context used by comp_pix() */

#if IF_RDR || PST1_RDR
    MEM_HANDLE  hchar_buf;
    LPSB8   char_buf;           /* character data buffer      */
    LPSB8   expand_buf;         /* character expansion buffer */
    UW16    expand_size;        /* size of expansion buffer   */
#endif


/* GLOBAL moved here from /da/symmap.c */
    SYMBOLSET symbolset;

/* GLOBAL moved here from /dep/cgif.c */
    FONTCONTEXT fcCur;      /* current FONTCONTEXT as passed into 
                                   CGIFfont() by application */

/* GLOBALs moved here from /da/chr_def.c */
/* Character specific data (# parts, escape, is_compound, etc.) */
    CHR_DEF chr_def[MAX_CC_PARTS];
    CHR_DEF_HDR chr_def_hdr;

/* GLOBAL moved here from /da/ix.c */
    FONTINDEX fontindex;

    SL32      right_shift;
    SL32      shear;           /* detects shear; see matrix_to_scale()   */

    SW16     origBaseline;    /* Original baseline in Design units (DU) */
    SW16     aBaselnVal;      /* grid aligned baseline value (DU)       */
    UW16     bit_map_width;   /* bitmap alignment                       */
    SW16     quadrant;        /* 90 rotations: ROT0 ROT90 ROT180 ROT270 */
    UW16     quality;         /* qulaity level 1, 2 or 3                */

/* bucket-related */
    UW16    fst_type;
    UW16    usePlugins;      /* true: character set Augmentation with buckets;
                              * false: no augmentation */

/* former IF_CHAR elements which are used throughout UFST */

    UW16    num_loops;          /* number of loops */
    SW16    alt_width;          /* if>0, alternate character width */
    UW16    orThreshold;    /* Pixel size threshold above which ON */
                            /* transitions may be OR-ed to bitmap. */

/* GLOBAL moved here from /dep/cgif.c */
    UW16  CGIFinitstate;
/* GLOBAL moved here from /dep/fpmath.c */
    UW16  fpmath_error;

    BOOLEAN  or_on;           /* 1 if or on transitions, 0 otherwise    */

    /*Backed out the MPR changes. In a future if you need to put the MPR*/ 
    /*changes back, please  search for the comments / * jwd, 06/29/04. */  
    /*in comp_pix.c, stikoutl.c, maker.c and IF_TYPE.H files.*/

    /*BOOLEAN  save_or_on; */     /* 1 if or on transitions, 0 otherwise    */
                              /* jwd, 06/29/04 */


    BOOLEAN  wrong_read;      /* TRUE if wrong reading                  */
    BOOLEAN  making_bold;     /* 1 if psuedo bold, 0 otherwise          */
    BOOLEAN  non_z_wind;      /* 1 if non-zero winding, 0 otherwise     */
#if FCO_RDR
    BOOLEAN  savenzw;            /* temp copy of "non_z_wind"    */
#endif
    BOOLEAN  est_outline;

/*----------------------------------------------------------------------*/

        CG_SERVER *pserver;    /* 06-22-04 jfd ... server data shared by mt clients */
        CG_SERVER server;

/*----------------------------------------------------------------------*/
#if CACHE
/* MLOCALs moved here from /dep/cache.c */
        HIFBITMAP   hBigBM;             /* buffer handle of big character  */

/* GLOBALs moved here from /dep/cache.c */
        HIFFONT     hfontCur;           /* handle of current FONT         */
        PFONT       pfontCur;           /* ptr to current FONT            */
        UW16    max_char_size;      /* max cached bitmap size          */
#if TILE
        HIFBITMAP htileBM;         /* Handle of last made tile part   */
#endif
#endif    /* CACHE */

/*----------------------------------------------------------------------*/
#if CHAR_SIZE
/* GLOBALs moved here from /dep/cgif.c */
        LPUB8    cc_buf;          /* compound character buffer        */
        SL32     cc_size;         /* size of comp. char. buffer       */
#endif

/*----------------------------------------------------------------------*/
#if (CGBITMAP)
/* formerly in "State_bm" */
    BOX            tile_box;
    SW16VECTOR     bmdim;
    SL32       nzw_size;
    MEM_HANDLE hnzw;   /* non zero winding buffer handle */
    LPUB8      nzw;
/* expand "BITMAP_BUFFERS bmb" */    /* For entire bitmap */
    MEM_HANDLE hbm;
    MEM_HANDLE horb;
    PIFBITMAP bm;
    LPUB8 orb;
/* end bmb */
    SL32            bmbufs_dyn;

#if IFBITSPLIT
    MEM_HANDLE bmdatahandle;
    UL32 *bmdataptr;
#endif

/* formerly in "SCAN_CONVERT" */
    SL32 tile_on;
    BOX tb;   /* box in output bitmap to clip to */
        IFBITMAP   entire_bm;     /* header of entire bitmap w/ metrics */

/* MLOCALs moved here from /bmp/lineto.c */
        Tran_lineto        pseudo_tran;
        State_lineto    state_lineto;
        SL32    pseudo_state;
        SL32    first_pseudo_tran;
#endif    /* CGBITMAP */

#if (CGBITMAP || GRAYSCALING)
/* GLOBAL moved here from /bmp/bitmap.c */
        RASTER ras;
#endif    /* CGBITMAP || GRAYSCALING */

#if GRAYSCALING
/* GLOBAL moved here from /gray/graymap.c */
        GRAYFILTER grayfilter;  /* global version */

/* MLOCALs moved here from /gray/graymap.c */
        BITSERVE_GM bs_gm;
        UINTG graysize[MAXGSCOUNT];
        INTG  gs_count;

/* MLOCAL moved here from /gray/imagegr.c */
        BITSERVE_IM bs_im;
#if UFST_MULTITHREAD
        int    maxpixval;
        int    maxpixval_4;
        LPUB8  gmBuff;
        int    gmBlackWid;
        LPUB8  charBuf;
        int    charBufSize;
#ifdef AGFADEBUG
        int    min_x;
        int    min_y;
        int    min_v;
        int    max_x;
        int    max_y;
        int    max_v;
#endif    /* AGFADEBUG */
#endif    /* UFST_MULTITHREAD */
#endif    /* GRAYSCALING */

/*----------------------------------------------------------------------*/
#if OUTLINE
/* GLOBAL moved here from /out/outdata.c */
        ODATA odata; /* Outline output processor */
#endif    /* OUTLINE && OLDATA */

/*----------------------------------------------------------------------*/

        UW16 font_access;    /* set by user to identify font access by */
                                /* DISK (DISK_ACCESS) or ROM (ROM_ACCESS) */

/*----------------------------------------------------------------------*/
#if DISK_FONTS

/* moved here from /da/path.c */
        SB8  ufstPath[PATHNAMELEN];
        SB8  typePath[PATHNAMELEN];
/* moved here from /da/bucket.c */
        UW16 num_open_files;      /* current number of open library files */
        UW16 max_open_files;      /* maximum   "     "   "     "      "   */

#if DISK_FONTS
    BOOLEAN  has_path;
#endif

/* MLOCALs moved here from /da/symmap.c */
        LPSB8 shortPath[NSS_FILES];
        LPUW16 symbol_set_symm[NSS_FILES];

/* GLOBALs moved here from /da/symmap.c */
#if (IF_RDR  ||  PST1_RDR)
        UW16    symbol_setIF[256];     /* current IF symbol set */
#endif
#if (TT_RDR || FCO_RDR)
        UW16    symbol_setTT[256];     /* current TT symbol set */
#endif
#if FCO_RDR
        UW16    symbol_setMT[256];     /* current MT symbol set */
#endif

#endif    /* DISK_FONTS */

/*----------------------------------------------------------------------*/
#if FCO_RDR

#if FCOACCESS
        FCTYPE   fc_acc;
        UW16     size_computed;
        FILECHAR *pStrings;
        FONTTYPE fcoFont_acc;
#endif    /* FCOACCESS */
        SL32    fco_Tmatrix[4];      /* char transformation matrix from bucket */
        SL32    fco_LocalTmatrix[4]; /* local transf matrix for transformPoint() */
        OUTL_COORD *outl_XYdata;    /* array of XY data: outl_CtXY         */
        SB8        *outl_Types;     /* array of point types: outl_CtPt + 1 */

        SL32          dimension;
        SL32          itaCoordValue;
        SL32          *xORyCoordOU;
        SL32          *xItaCoordOU;
        SL32          standardStemOU;
        SL32          standardWidthOU;
        SL32          FCWstandStemOU;
        SL32          FCWstandWidthOU;
        SL32          italicAngle_fci;
        SL32          *yCoordOU;
        PIXEL_DATA    *pixel_fci;
        struct
        {
            UL32  previous;
            UB8 immediat;
        } parent_fci[NUM_YX_SKEL];
        SL32 coordValue;
        SL32 alignShift;
        SL32 assocLength[256];
        SL32 remainder;
        SL32 sd_lo;
        SL32 sd_hi;
        SL32 sd_NA;
        SL32 sd_alignShift;
        UB8 *YXdimensions;
        UB8 *YXdimType;
        UB8 *YXdimProjType;
        UB8 *YXRTZflags;
        UB8 *YXconstDims;

        SL32        fco_TisOrthogonal;   /* Flag for orthogonal matrix */
        SL32        fco_polarity_flag;   /* BLACK_ON_RIGHT/LEFT. LEFT only for mirrored CC parts */
        SL32        fco_mxMirFlag;       /* values 0 - 7 mapped from if_state.quadrant */
        SL32        fco_ccMirFlag;       /* values 0 - 7 from ccPiece.longCCFlag */
        SL32        fco_MirFlag;         /* combination of above 2 flags */
        SL32    outl_FuncType;  /* flag used in outl_MoveTo(), _LineTo(), _QuadTo() */
        SL32    outl_CtXY;      /* counts # words of XY data. */
        SL32    outl_CtPt;      /* Tracks # points in char */

    UW16    fst_type_Lvl0;   /* fst type of TFS bucket */
    UB8     buck_SearchLvl;
    UB8 sd_enable;

#if USBOUNDBOX                    /* AJ - 10/04/04 */

        UW16    USBBOXorigScaleFactor;
        UW16    USBBOXscaleFactor;
        SL32    USBBOXxmin;     /* Unscaled Bounding box members. */
        SL32    USBBOXxmax;     /* jwd, 03/15/04.                 */
        SL32    USBBOXymin;
        SL32    USBBOXymax;

        SL32   *USBBOXXsyntell;
        SL32   *USBBOXYsyntell;
        SL32   *USBBOXIsyntell;
        SL32    USBBOXfco_TisOrthogonal;
        SL32    USBBOXfco_Tmatrix[5];
        SL32    USBBOXoutl_FuncType;
        
        SL32   *UScoordOU;
#endif

#endif    /* FCO_RDR */

/*----------------------------------------------------------------------*/

#if PST1_RDR


/* MLOCALs moved here from /psi/t1idecod.c */ 
/*
arguments for flexproc
add 12/16/91 - rs
and all arguments read from font
change from SW16 to SL32 to handle 32 bit div
*/
        SL32     args[T1ARGSTACKSIZE];

/*  5/14/93 - rs
   The following variables were move from 'type1char()' in order to
   integrade the Pipeline upgrade. They are now shared among multiple funcs.
*/
        LPSL32  argsptr;
#if PS_ERRORCHECK
        LPSL32    t1_stacklimit;        /* points to last entry of args[] */
#endif

        SL32  curve1[6];
        SL32  curve2[6];

/* subroutine call stack */
        struct
        {
              SW16 key;
              LPUB8 data;
        } subcalls[11];

/* GLOBALs moved here from /psi/t1idecod.c */
        PBUCKET   gpxb; /* add 1/6/92 - rs */
        PPS_BUCK   gpps;
        PCHAR_STATS  gpcs;

        SL32 record; /* init FALSE - 4/14/93 - rs */
        

/* MLOCALs moved here from /psi/t1iscan.c */
        SL32  scanning_proc;  /* recursion of procedure scan */

/* MLOCALs moved here from /psi/t1ihints.c */
        SW16 hintssorted;
#if NON_Z_WIND
        SW16   last_pt_is_start_pt; /* 10-07-93 jfd */
#endif  

        SW16 stemhints;

/* global pointer for PST1_RAM option */
#if ROM
        UB8 *psptr;
#endif

#endif    /* PST1_RDR */

/*----------------------------------------------------------------------*/
/* misc ASIAN-conditional vbls */

#if ASIAN_ENCODING && (PST1_RDR || TT_RDR)
/* MLOCALs moved here from /da/kanmap.c */

#if UNICODE_IN
#if JIS_ENCODING
        LPSB8 UnicodeToJisTbl;
        MEM_HANDLE hUnicodeToJisTbl;  /* 9-26-96 */
        UL32 u2jSize;
#endif
#if K_ENCODING
        LPSB8 UnicodeToKscTbl;
        MEM_HANDLE hUnicodeToKscTbl;  /* 9-26-96 */
        UL32 u2kSize;
#endif
#if BIG5_ENCODING
        LPSB8 UnicodeToBig5Tbl;
        MEM_HANDLE hUnicodeToBig5Tbl;  /* 9-26-96 */
        UL32 u2big5Size;
#endif
#if GB_ENCODING
        LPSB8 UnicodeToGbTbl;
        MEM_HANDLE hUnicodeToGbTbl;  /* 9-26-96 */
        UL32 u2gbSize;
#endif
#endif /* UNICODE_IN */

#if (UNICODE_MAPPING & JIS2UNI_MAP)
        LPSB8 JisToUnicodeTbl;
        MEM_HANDLE hJisToUnicodeTbl;  /* 9-26-96 */
        UL32 j2uSize;
#endif
#if (UNICODE_MAPPING & KSC2UNI_MAP)
        LPSB8 KscToUnicodeTbl;
        MEM_HANDLE hKscToUnicodeTbl;  /* 9-26-96 */
        UL32 k2uSize;
#endif
#if (UNICODE_MAPPING & BIG52UNI_MAP)
        LPSB8 Big5ToUnicodeTbl;
        MEM_HANDLE hBig5ToUnicodeTbl;  /* 9-26-96 */
        UL32 big52uSize;
#endif
#if (UNICODE_MAPPING & GB2UNI_MAP)
        LPSB8 GbToUnicodeTbl;
        MEM_HANDLE hGbToUnicodeTbl;  /* 9-26-96 */
        UL32 gb2uSize;
#endif
#endif /* ASIAN_ENCODING && (PST1_RDR || TT_RDR) */

/* keb 8/99 */
    UW16    CharVertWrit;
    UW16      have_adjusted_angle;      /* 1 if we have changed things due to adjust_angle */
                                    /* being 1, 0 otherwise, 2 initially */

#if EMBEDDED_BITMAPS && TT_RDR && CGBITMAP
    BOOLEAN        BitmapManipulated;        /* Requested character is to be manipulated (emboldened, sheared, etc.) */
    BOOLEAN     BitmapEmbedded;            /* Requested character exists in embedded bitmap table at req size */
#endif    /* EMBEDDED_BITMAPS && TT_RDR && CGBITMAP */

/*----------------------------------------------------------------------*/
/* misc TT_*-conditional vbls */

#if TT_TTPLUG
/* TT Plugins are in TrueType format. */
        SL32         ttplug_font_type;
#if DISK_FONTS
        PATHNAME    tt_universal;
#endif
        LPUB8       tt_fnt_hdr;
#endif    /* TT_TTPLUG */


/*----------------------------------------------------------------------*/
/* MISCELLANEOUS vbls */

    VOID  *chIdptr;          /* ptr to chId (used if ss mapping is removed) */
#if PST1_RDR
    VOID  *PSchar_name;      /* ptr to PS character name ( "  "   "  "    ) */
#endif  /* PST1_RDR */


#if BOLD_HORIZONTAL
        SMEAR_INSTANCE sihorizontal;
#endif
#if BOLD_P6
        SMEAR_INSTANCE sip6hor;
        SMEAR_INSTANCE sip6ver;
#endif
#if BOLD_P6 || BOLD_HORIZONTAL 
        SW16 boldembox;  /* !!!!! 10-25-96 !!!! */
#endif


#if SLIM_FONTS || PS_IFPLUG
/* GLOBALs moved here from /da/fm.c */
        CHARWIDTH missing_ccpart_widthinfo;
        SW16      missing_ccparts;
#endif


#if (BYTEORDER == LOHI)
/* try to merge a few of the myriad swapping macros... */
        union {
              SW16 w;
              struct{
                        SB8 b0;
                        SB8 b1;
                    }b;
           } tmp_sw;
#if PCLEO_RDR
/* MLOCALs moved here from /da/pcl_swap.c */
        UB8 even_odd;
        UB8 N_TR_pclsw;
#endif    /* PCLEO_RDR */
#endif    /* BYTEORDER == LOHI */

#if PCLEO_RDR
        UW16 PCL_font_type;    /* 0 = bound, 1 = Unbound */


        UW16 PCL_FSTTechnology; /* DL fonthdr technology field */
                                /* 1 = Scalable, 254 = bitmap. */
                                /* jwd, 07/21/03.              */

        MEM_HANDLE PCL_BitMapCharPtr; 

                                /* pntr to char returned from  */
                                /* PCLchId2ptr() jwd 07/21/03. */

        BOOLEAN DLBmpInProcess; /* Flag which indicates if PCL */
                                /* DL bitmaps are curently be- */
                                /* ing processed. 0=no, 1=yes. */
                                /* jwd 07/21/03                */

        PCLEO_CALLBACK_DATA pcd;    /* data structure to support demo code & callbacks */
                                    /* can be replaced with customer's own data structure */
#endif    /* PCLEO_RDR */


#if PST1_SFNTI
/* MLOCALs moved here from /psi/t1isfnt.c */
        LPUB8 ph; /* this will probably go away when the real thing is done */
#endif    /* PST1_SFNTI */


#if COMPRESSED_CACHE
/* MLOCAL moved here from /dep/cmpr.c */
        BITSERV_CMPR bs_cmpr;
#endif    /* COMPRESSED_CACHE */
    
/*----------------------------------------------------------------------*/
#if (IF_RDR)
/* was IF_CHAR structure */
    /* Intellifont 5.4.1 Global Standard Dimension Data */
    UW16    stan_dim_lim;   /*  pix size above which standrd used */
    UW16    stan_STAN_dim_lim; /* size above which STAN stan used */

/* was ALIGNED structure */
    SW16 gaso_pn;
    SW16 value;         /* aligned value */
    SW16 grid_line;     /* grid number   */

    SL32    if_init_face;    /* last typeface run through if_init. */

/* was IF_CHAR structure */
    BOX     bound_box;          /* character bounding box- design units */
    BOX     escape_box;         /* character escapement bex-  "     "   */

    SW16    loc_ital_ang;
    UW16    italic_flag;

    BOOLEAN char_is_if;    /* 10_feb-91 awr */

    SKEL    xskel;
    SKEL    yskel;

    SW16  baseline_offset;

  /* y-classes */
/*** I6.2.1.7   Y-class Character (local) data */
    UB8    num_yclass_ass;    /* number of y class assignments */
    LPUB8  num_root_p_ass;    /* number of roots per y class   */
    LPUB8  root_skel_i;       /* root indices in y class order */
    LPUB8  yclass_i;          /* y class indices */

/** local y classes */
    UB8    num_yclass_def;     /* number of local y class definitions */
    LPUB8  yline_high_i;       /* high y line indices */
    LPUB8  yline_low_i;        /* low y line indices */

/*** local y class definitions */
    UW16    num_ylines;         /* number of local y lines */
    LPUW16  ylines;             /* local y line values */

    UW16    HqFormat;           /* Hi-Q data format: 1 = HQ1 (tangent) */
                                /* 2 = HQ2 (contact) 3 = HQ3 (compact) */
    UW16    ConnectingChar;

    PCTREE  ctree;

    LPSB8    next_coord_data;

/*-----------------------------------*/
/*  Global Intellifont segment (100) */
/*-----------------------------------*/

/*      I5.0            Face Identifier                               */
        UW16    if_flag;        /*  flag to indicate if intellifont   */
                                /*  data is present                   */  

/*      I5.1            Global Y Class Definition Data                */
        UW16    num_gylines;     /*  number of Y lines                 */
        LPUW16  gylines;         /*  single arr of Y class Y lines     */
        YCLASS_DEF glob_yclass;
                                /*  actual Y class definitions        */

/*      I5.2            Global Dimension Data                         */
        DIMENSION   glob_x_dim;
        DIMENSION   glob_y_dim;

/*      I5.3            Global Italic Angle Data                      */
        SW16    glob_ital_ang;

/*      I5.4.2          [Generic Screen] Face Substituion Data        */
        UW16    subst_cutin;    /*  width fac. to adjust subst face   */

/* GLOBALs moved here from /cor/manipula.c */
        BOOLEAN no_skel;
        TRAN x_tran;
        TRAN y_tran;

/* MLOCALs moved here from /cor/if.c */
        ADJUSTED_SKEL     x_skel_if[MAX_SKEL];
        ADJUSTED_SKEL     y_skel_if[MAX_SKEL];

/* MLOCALs moved here from /cor/skeletal.c */
        UW16    pix_skel;            /*  pixel size in design units        */
#ifdef LINT_ARGS
        VOID (*pix_al_ptr)(FSPvoid SW16, PCOORD_DATA, UW16); /* ptr to pixel_align()*/
#else
        VOID (*pix_al_ptr)();   /* ptr to pixel_align() function      */
#endif
        UB8 stan_dim_option;
        SW16  curr_stan_value;

#if BOLD
/* GLOBAL moved here from /cor/if_init.c */
        DUP_POINTS dup_points[MAX_DUP_POINTS];
#endif  

#if CUBIC
/* MLOCALs moved here from /out/cubic.c */
        PSW16VECTOR coord_cb;
        SW16 xt_cb;
        SW16 yt_cb;
        SW16VECTOR START_cb;
        SW16VECTOR CONTACT_cb;
        SW16VECTOR END_cb;
        SW16 bzstart;
        SW16 bzend;
        SW16 base_cb[129];
        SW16 angle_cb[129];
        SW16VECTOR stack_cb[64];
        SW16VECTOR stack1_cb[64];
        SW16VECTOR stack2_cb[64];
        PSW16VECTOR stack_pntr;
        PSW16VECTOR ptr1_cb;
        PSW16VECTOR ptr2_cb;
        LPSW16 bzptr;
        LPSW16 angle_pntr;
        SL32 AcrossBprev;
        SW16 angEprev;
#endif    /* CUBIC */

#if SLIM_FONTS && (CGBITMAP || LINEAR || QUADRA || GRAYSCALING)
/* GLOBAL moved here from /out/quadra.c */
        SW16 special_case;
#endif

    UW16    orThresholdIF;    /* Pixel size threshold above which ON */
                              /* transitions may be OR-ed to bitmap. */

#endif    /* IF_RDR */

        SW16    lpm;
        SW16    xlpm;
        SW16    ylpm;

#if STIK && (TT_DISK || TT_ROM || TT_ROM_ACT)
        BOOLEAN update_reflines;        /* TRUE if "HOxo" metrics needed for autohint_stik() */
        BOOLEAN update_reflines_flag_set;    /* TRUE if test for "HOxo metrics needed" already done */
        BOOLEAN extract_outline_only;    /* TRUE if only requesting FS_OUTLINE data from extract_outline() */ 
        FS_FIXED lo_y;            /* smallest y coordinate returned by extract_outline() */
        FS_FIXED hi_y;            /* largest y coordinate returned by extract_outline() */
        FS_FIXED cap_round;
        FS_FIXED cap_square;
        FS_FIXED x_round;
        FS_FIXED x_square;
        FS_FIXED base_round;
        FS_FIXED base_square;
        FS_FIXED lc_accent_miny;    /* 01-22-04 jfd */
        FS_FIXED uc_accent_miny;    /* 01-22-04 jfd */
#endif

#if (TT_RDR || FCO_RDR)
        BOOLEAN substitute_hollow_box;
#endif

#if LINKED_FONT
    FONTCONTEXT fcLinkedFont;
#endif
#if DIRECT_TT_TABLE_ACCESS
    MEM_HANDLE    hdatables;
    DIRECT_ACCESS_TABLES *datables;
#endif

    SW16 trace_sw;        /* enable-debug-printout flag */
    BOOLEAN language_flag; /* added 4/21/04 bjg */
    MUTEX mutex_ptr;    /* the mutex used for multi-threading */
    MUTEX app_mutex_ptr;/* an application mutex for multi-threading that is user-callable */
    SL32 error;

} IF_STATE;
typedef  IF_STATE FARPTR * PIF_STATE;

#if FCOACCESS && OPTIMIZE_FCOACCESS    /* 02-11-02 jfd */
#define OPEN_FCO_BIT            0x0001
#define EXTRACT_INFO_BIT        0x0002
#define CLOSE_FCO_BIT            0x0004

#define OPEN_FCO        (if_state.size_computed & OPEN_FCO_BIT)
#define EXTRACT_INFO    (if_state.size_computed & EXTRACT_INFO_BIT)
#define CLOSE_FCO        (if_state.size_computed & CLOSE_FCO_BIT)
#endif    /* FCO_ACCESS && OPTIMIZE_FCOACCESS */

#ifdef NC_REWRITE
/* a new structure for passing metrics around */
typedef struct {
    F26DOT6 lsb_x;
    F26DOT6 lsb_y;
    F26DOT6 rsb_x;
    F26DOT6 rsb_y;
    SW16 lsb;    /* unscaled */
    SW16 aw;    /* unscaled */
    BOOLEAN useMyMetrics;
    } fsg_Metrics;

#endif /* NC_REWRITE */

/*---------------------------------------------------------------------*/

#endif    /* __IF_TYPE__ */
 

ifmem.h   、、、、、、、、、、、、、、、、、、、、、、、、、、、

/* Copyright (C) 2003 Agfa Monotype Corporation. All rights reserved. */

/* $Header:   I:/BULL/URIP/RTS/INC/IFMEM.H_V   1.21   Aug 21 2003 17:10:20   Galejs  $ */
/* $Log:   I:/BULL/URIP/RTS/INC/IFMEM.H_V  $ 
 * 
 *    Rev 1.21   Aug 21 2003 17:10:20   Galejs
 * update copyright notice
 * 
 *    Rev 1.20   Jan 08 2003 16:06:28   AOF
 * Added semicolon to EOL to allow ALPHA compilation. MD.
 * 
 *    Rev 1.19   Dec 11 2002 12:09:20   Galejs
 * experimental code to resolve alignment warnings (disabled by default)
 * 
 *    Rev 1.16   Sep 20 2002 20:14:50   Galejs
 * test for multiple includes (part of bug # 76)
 * 
 *    Rev 1.15   03 Aug 2001 13:10:44   JOE
 * If INT_MEM_MGT is 1, changed typedef for MEM_HANDLE to UL64 for
 * 64-bit platforms.
 * 
 *    Rev 1.14   Feb 08 2000 17:39:48   galejs
 * MSDOS becomes UFST_MSDOS
 * 
 *    Rev 1.13   12 Jun 1998 11:53:58   GALEJS
 * move all fn prototypes to shareinc.h
 * 
 *    Rev 1.12   15 Jul 1997 10:29:46   AL
 * Removed unused code conditioned on NOT1200DPI
 * 
 *    Rev 1.11   14 Apr 1997 16:59:22   MIKE
 * 
 *    Rev 1.10   14 Apr 1997 16:58:04   MIKE
 * LINT_ARGS replaces LINTARGS
 * 
 *    Rev 1.9   06 Jul 1995 08:21:16   MAC
 * Basic 1200 dpi support.
 * 
 *    Rev 1.8   07 Apr 1995 08:45:16   LISA
 * Changed copyright from Miles Inc. to Bayer Corp.
 * 
 *    Rev 1.7   13 Jan 1995 18:06:26   ROB
 * Support for > 64KB memory blocks in DOS.
 * 
 *    Rev 1.6   21 Nov 1994 10:30:18   JOE
 * Changed OFFBITS for 1200 DPI support.
 * 
 *    Rev 1.5   21 Apr 1994 15:48:40   LISA
 * Made modifications to copyright/disclaimer notice.
 * 
 *    Rev 1.4   08 Dec 1993 18:57:58   ROB
 * General cleanup for MSDOS, FLAT, OS2.
 * 
 *    Rev 1.2   17 Dec 1992 18:12:12   ROB
 * Make OFFBITS depend only on MSDOS 16 bit else other.
 * 
 *    Rev 1.1   14 Dec 1992 09:42:04   LISA
 * Made change to Log keyword
 * 
 *    Rev 1.0   10 Dec 1992 09:11:00   LISA
 * Initial revision.
*/
/* $Date:   Aug 21 2003 17:10:20  $ */
/* ifmem.h */
/*
 *
 *
 * History
 *
 *  17-Feb-91  awr  split off from cgif.h 
 *  23-Feb-91  awr  moved MEM_HANDLE offset and page macros from mem.c
 *   6-Jun-91  jfd  Added SUN support for OFFBITS() and OFF.
 *                  (FIX FROM EARLIER VERSION)
 *  24 Mar 92  ss   Added #define MEM_HANDLE_DEFINED needed in TT input code
 *                  to avoid redefine MEM_HANDLE if its already been done.
 *  03-Apr-92  rs   Portability cleanup (see port.h).
 *  13 Jul 92  ss   Changed condition compile of OFFBITS from ROM/SUN to
 *                  UNIX.  All UNIXs will now use more OFFBITS.
 *  13-Aug-92  rs   Added support for Watcom C386 (__FLAT__) model by
 *                  making OFFBITS same as for other 32 bit platforms.
 *  17-Dec-92  rs   Make OFFBITS depend only on 16 bit DOS else other.
 *  08-Dec-93  rs   General cleanup - MSDOS & FLAT -> CGFLAT32.
 *  21-Nov-94  jfd  Changed OFFBITS for 1200 DPI support.
 *  09-Jan-95  rob  Implement > 64KB support for internal memory mgt.
 *  06-Jul-95  mac  Basic 1200 dpi support.
 *  14-Apr-97  mby  Replaced "LINTARGS" with "LINT_ARGS".
 *    12-Jun-98  slg    All fn prototypes moved to shareinc.h
 *  03-Aug-01  jfd  If INT_MEM_MGT == 1, changed typedef for MEM_HANDLE
 *                  to UL64 for 64-bit platforms.
 */
/*
The internal functions of the Intellifont run time library require
a dynamic memory manager. This management may be supplied by the

    - c runtime library functions malloc() and free()
    - the module mem.c
    - an application specific memory manager

Source code for the first two options is supplied. Either option may be
selected by setting the define in cgconfig.h

    #define INT_MEM_MGT  0    Set to 1 for internal memory manager

The file ifmem.h then conditional defines one of the first two options.
For the last option, use the definition of external memory management at
the end of ifmem.h as a guide and replace it with your own.
 */

#ifndef __IFMEM__
#define __IFMEM__

#if INT_MEM_MGT   /*  If CG memory manager  */

/*
        I N T E R N A L    M E M O R Y    M A N A G E R

Initial memory is funded by the application. The application may provide
more than one block of memory for each pool. Each block of memory is
internally referred to as a PAGE and is assigned a page number.

Memory pages are subdivided into smaller blocks to fullfill MEMalloc()
requests. Each of these smaller blocks is refered to be a handle of type
MEM_HANDLE.

A memory handle is a ULONG interpreted as having two fields. A PAGE field
refers to the internally assigned page number and an offset field giving
the byte offset of the memory block from the start of the page.

The macros PAGE() and OFF() extract these fields from a MEM_HANDLE.
The maximum size for a memory block returned by MEMalloc() is determined
by the size of the offset field which is defined by OFFBITS.
*/

#if (USING_16_BIT_DOS && !HUGE_PTR_SUPPORT)
#define OFFBITS  16                   /* bits in offset field of handle */
#define OFF(x)   (x & 0xffff)
#else
  /*  need larger offset for addressing into font block on 32 bit machine  */
#define OFFBITS  25
#define OFF(x)   (x & 0x1ffffff)
#endif  /* USING_16_BIT_DOS && !HUGE_PTR_SUPPORT */

#define PAGE(x)  (UW16)(x >> OFFBITS)

#define MEM_HANDLE_DEFINED
#if (NAT_ALIGN == 8)        /* 08-03-01 jfd */
typedef UL64        MEM_HANDLE;
#else
typedef UL32        MEM_HANDLE;
#endif
typedef MEM_HANDLE FARPTR * PMEM_HANDLE;
#define NIL_MH       ((MEM_HANDLE)0L)

#else

/*   C    R U N    T I M E    M E M O R Y    M A N A G E R

We use malloc() and free() to provide the memory management.
Since handles aren't used we define a MEM_HANDLE to be a byte pointer
and the hndle to ptr conversion function is the identity macro.

*/

#define MEM_HANDLE_DEFINED
#if 1
typedef LPSB8        MEM_HANDLE;
#else    /* experimental code to resolve loose-to-strict alignment warnings (sandra, 26 nov 02) */
        /* part 1 of 2: must also use alternate version of MEMfree() in /dep/extmem.c */
typedef LPSL32        MEM_HANDLE;
/* typedef VOID *        MEM_HANDLE; */    /* this also works in Win32 environment */
/* would it be more correct to set the type as (pointer to union of all basic datatypes)? */
#endif    /* end experimental code */
typedef MEM_HANDLE FARPTR * PMEM_HANDLE;
#define NIL_MH       ((MEM_HANDLE)0)

#endif    /* INT_MEM_MGT */

#endif    /* __IFMEM__ */
 

imagegr.h   、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

/* 
 * Copyright (C) 2003 Agfa Monotype Corporation. All rights reserved.
 */
/* $Header:   I:/BULL/URIP/RTS/GRAY/IMAGEGR.H_V   1.12   Aug 22 2003 09:07:22   LynchR  $ */
/* $Log:   I:/BULL/URIP/RTS/GRAY/IMAGEGR.H_V  $ 
 * 
 *    Rev 1.12   Aug 22 2003 09:07:22   LynchR
 * Updated copyright notice.
 * 
 *    Rev 1.11   Aug 18 1999 11:20:44   galejs
 * PLACEMENT becomes grayPLACEMENT (prevent conflict with PCLEO define)
 * 
 *    Rev 1.10   02 Sep 1998 17:34:10   GALEJS
 * move GRAYIMAGE to if_type.h, prototypes to shareinc.h
 * 
 *    Rev 1.9   12 Jun 1998 13:32:30   GALEJS
 * modify prototype for reentrancy
 * 
 *    Rev 1.8   14 May 1997 10:29:28   MIKE
 *    Rev 1.7   21 Dec 1995 15:07:30   MERRILL
 * spelling change gray
 * 
 *    Rev 1.6   21 Dec 1995 09:50:08   AL
 * Separate graymap file and UFST inputs
 * 
 *    Rev 1.5   14 Dec 1995 15:28:22   MIKE
 * Changed GRAYIMAGE structure. Removed obsolete giXXXX functions.
 * 
 *    Rev 1.4   01 Dec 1995 12:12:20   MIKE
 * Added fontGm and rasterWidth to GRAYIMAGE structure.
 * 
 *    Rev 1.3   14 Nov 1995 11:30:34   MERRILL
 * Portability Issue: ANSI_DEFS for fuction calls
 * 
 *    Rev 1.2   18 Oct 1995 15:14:36   AL
 * performance improvements
 * 
 *    Rev 1.1   10 Oct 1995 11:10:28   LISA
 * Added header information for use with PVCS.
 * 
*/

/*----------------*/
/* imagegr.h      */
/*----------------*/
/* This is the interface definition between a higher level application
 * and Agfa supplied text imaging functions.
 */
/*  History
 *  20-Nov-95  mby  Added fontGm and rasterWidth to to GRAYIMAGE structure.
 *  14-Dec-95  mby  Added GRAYIMAGE.public. Removed 'fontGm', 'rasterWidth'.
 *                  Removed declaration of obsolete giXXXX functions.
 *    12-Jun-98  slg    Modify gichar() prototype for reentrancy
 *    31-Aug-98  slg    Move GRAYIMAGE definition to if_type.h, move prototypes to
 *                    shareinc.h (in order to build UFST as DLL)
 */
/*------------------------------------------------------------------------*/

#if defined (SUN)
#define SEEK_SET 0
#endif

/*----------------------Image Object--------------------------*/
/*
   This is another object oriented design.  The object is the structure
   GRAYIMAGE.  This structure contains the information needed by the imaging
   member functions to uncompress and reconstruct variously phased and
   formated graymaps.  It does not and should not contain text composition
   logic.
*/
#define  grayPLACEMENT  16    /* character placement is 1/grayPLACEMENT accurate */
                          /* A Placement Unit (PU) = 1/grayPLACEMENT pixel   */

imagegr.txt  、、、、、、、、、、、、、、、、、、、、、、、、、、

/* 
 * Copyright (C) 2003 Agfa Monotype Corporation. All rights reserved.
 */
/* $Header:   I:/BULL/URIP/RTS/GRAY/IMAGEGR.C_V   1.30   Aug 22 2003 09:07:22   LynchR  $ */
/* $Log:   I:/BULL/URIP/RTS/GRAY/IMAGEGR.C_V  $ 
 * 
 *    Rev 1.30   Aug 22 2003 09:07:22   LynchR
 * Updated copyright notice.
 * 
 *    Rev 1.29   Jun 19 2003 19:10:18   Galejs
 * ufstport.h
 * 
 *    Rev 1.28   Aug 09 1999 18:41:42   galejs
 * include-file changes
 * 
 *    Rev 1.27   21 Jan 1999 15:47:00   GALEJS
 * standardize #include tests
 * 
 *    Rev 1.26   12 Jan 1999 11:46:26   GALEJS
 * "nextbyte()" type should be VOID, not UW16 (no return value)
 * 
 *    Rev 1.25   04 Sep 1998 15:22:58   GALEJS
 * placeholder for new gichar() interface (don't use in UFST 4.0)
 * 
 *    Rev 1.24   08 Jul 1998 15:40:20   GALEJS
 * BLACKPIX, GRAYPIX also need reentrancy parm
 * 
 *    Rev 1.23   15 Jun 1998 11:29:38   GALEJS
 * reentrancy parm-passing changes
 * 
 *    Rev 1.22   29 May 1998 09:47:46   AL
 * Bit server was reading 2 extra bytes
 * 
 *    Rev 1.21   31 Mar 1998 18:34:00   GALEJS
 * move bitserver MLOCAL into IF_STATE; local xpix/ypix rename
 * 
 *    Rev 1.20   24 Mar 1998 08:41:24   AL
 * Added 128 & 256 gray levels to gifont()
 * 
 *    Rev 1.19   02 Feb 1998 18:19:02   GALEJS
 * no need to include "gray_mgt.h"
 * 
 *    Rev 1.18   30 Sep 1997 13:21:24   MIKE
 * Fix Unix-type line endings
 * 
 *    Rev 1.17   16 Sep 1997 13:58:58   GALEJS
 * fix compile for ARM/Helios
 * 
 *    Rev 1.16   02 May 1997 15:33:00   GALEJS
 * fix nextph() to handle maxphval=1 / phval=0 case properly
 * 
 *    Rev 1.15   08 Apr 1996 09:11:04   MERRILL
 * changed _if to _switch on phases
 * 
 *    Rev 1.14   21 Feb 1996 13:13:50   RICK
 * add else before if(gi->numYphases == 4)
 * 
 *    Rev 1.13   12 Jan 1996 11:14:52   JOE
 * Conditionally compiled "include <stdlib.h>" based on MSDOS (by DBK).
 * Corrected function declaration for gifont() (by DBK).
 * Corrected function declaration for gichar() (by DBK).
 * 
 *    Rev 1.12   11 Jan 1996 15:08:02   RICK
 * gichar() always returns SUCCESS
 * 
 *    Rev 1.11   05 Jan 1996 10:21:06   RICK
 * add return value to gichar()
 * 
 *    Rev 1.10   21 Dec 1995 15:11:28   RICK
 * spelling change gray
 * 
 *    Rev 1.9   21 Dec 1995 09:47:56   AL
 * Separate file and UFST input
 * 
 *    Rev 1.8   14 Dec 1995 15:46:34   MIKE
 * Big rewrite.
 * 
 *    Rev 1.7   04 Dec 1995 13:02:34   RICK
 * added conditional on unused parameters
 * 
 *    Rev 1.6   01 Dec 1995 15:49:50   MIKE
 * Changed to write graymap to RAM buffer; disable Borland graphics interface
 * ANSI_DEFS for function calls. Implemented giboundbox(), gifontClose().
 * 
 *    Rev 1.5   18 Oct 1995 15:16:22   AL
 * performance improvements
 *
 *    Rev 1.4   17 Oct 1995 12:14:20   RICK
 * No change.
 *
 *    Rev 1.3   10 Oct 1995 11:06:30   LISA
 * Added header information for use with PVCS.
 *
*/
/* $Date:   Aug 22 2003 09:07:22  $ */

/*----------------*/
/* imagegr.c      */
/*----------------*/
/*  History
 *  12-Nov-95  mby  Changed blackpix(), graypix() to write to a RAM buffer.
 *                  Disabled Borland graphics interface!
 *  12-Nov-95  jc   ANSI_DEFS, LINT_ARGS for function calls.
 *  20-Nov-95  mby  In gifont() allocate enough memory to hold largest
 *                  graymap, based on font bound box.
 *                  Implemented giboundbox() using CGIFbound_box().
 *                  Added new function gifontClose().
 *  14-Dec-95  mby  Removed blackpix(), graypix(), replaced w/ BLACKPIX &
 *                  GRAYPIX.  Removed giopen(), giclose(), gifontClose().
 *                  Removed application specific code in gifont(), gichar().
 *                  Removed giboundbox(), giescapement() - (use CGIF calls).
 *                  Removed GS1, GS2 conditional code. GS2 is always 1; GS1 is always 0.
 *                  Conditionally compiled _gm_font() functions.
 *  12-Jan-96  dbk  Conditionally compiled "include <stdlib.h>" based on
 *                  MSDOS.
 *                  Corrected function declaration for gifont().
 *                  Corrected function declaration for gichar().
 *  02-May-97  slg  Partial fix for phasing-in-Y: nextph() wasn't properly
 *                  handling case where maxphval=1 but actual phval=0 
 *  16-Sep-97  slg  Fix compile for ARM/Helios.
 *  23-Mar-98  awr  Added 128 & 256 graylevels to gifont()
 *    31-Mar-98  slg    "BITSERVER bs" becomes "BITSERVE_IM if_state.bs_im";
 *                    also need to change local xpix/ypix to xpix_gi/ypix_gi.
 *  23-May-98  awr  Bit server was loading in 2 bytes past the end
 *                  of the byte stream in order to keep bitbuf full.
 *  04-Sep-98  slg    Add commented-out alternate interface to gichar() 
 *                    (take pointers to application's BLACKPIX/GRAYPIX functions)
 *                     -  required if building as DLL, rather than static-linking. 
 *                    Also add commented-out Window-ptr to GRAYPIX/
 *                    BLACKPIX - somewhat klugey solution to interface with
 *                    multi-window UFST client application.
 */
/*------------------------------------------------------------------------*/


#include    "cgconfig.h"

#if GRAYSCALING           /* Conditionally compile entire module */

/* set to 1 to use standard interface; set to 0 to use DLL interface */
/* (TEMPORARY flag, to avoid major changes to UFST 4.0 interface) */
#define GRAYAPP_STATIC_LINK 1

#include    "ufstport.h"
#include "dbg_ufst.h"

#include    <stdio.h>
#include    <string.h>
#include    <stdlib.h>

#if defined (_OSK) || defined (_OS9000)
#include    <modes.h>
#endif

#if MAYBE_FCNTL_H
#include <fcntl.h>
#endif

#if MAYBE_FCNTL_HIF_H
#include <fcntl.h>
#endif

#if MAYBE_MALLOC_H
#include <malloc.h>
#endif

#include    <errno.h>

#include    "shareinc.h"

#ifdef LINT_ARGS
MLOCAL VOID nextbyte(FSP0);
MLOCAL VOID initbits(FSP UB8*, SL32);
MLOCAL UW16 nextbit(FSP0);
MLOCAL UW16 nextph(FSP GRAYIMAGE*);
MLOCAL VOID cleargrayrow(SW16*, SW16);
#else
MLOCAL VOID nextbyte();
MLOCAL VOID initbits();
MLOCAL UW16 nextbit();
MLOCAL UW16 nextph();
MLOCAL VOID cleargrayrow();
#endif

/*==================================================*/
/*  Character imaging                               */

#if defined (ANSI_DEFS)
GLOBAL UW16 gifont(GRAYIMAGE *gi, SW16  numXsubpixels,
                                  SW16  numYsubpixels,
                                  SW16 numXphases,
                                  SW16 numYphases)
#else
GLOBAL UW16
gifont(gi, numXsubpixels, numYsubpixels,
                                  numXphases, numYphases)
GRAYIMAGE *gi;
SW16 numXsubpixels, numYsubpixels, numXphases, numYphases;
#endif
{
    gi->numXsubpixels = numXsubpixels;
    gi->numYsubpixels = numYsubpixels;
    gi->numXphases    = numXphases;
    gi->numYphases    = numYphases;

    gi->totphases = numXphases * numYphases;
    gi->maxpixval = numXsubpixels* numYsubpixels;
    gi->maxphval  = gi->maxpixval/gi->totphases;
    switch(gi->maxphval)
    {
        case 256: gi->bsct = 8;  break;
        case 128: gi->bsct = 7;  break;
        case  64: gi->bsct = 6;  break;
        case  32: gi->bsct = 5;  break;
        case  16: gi->bsct = 4;  break;
        case   8: gi->bsct = 3;  break;
        case   4: gi->bsct = 2;  break;
        case   2: gi->bsct = 1;  break;
    }
    gi->bsmask = gi->maxphval-1;

    return SUCCESS;
} /* gifont */


/*======================================================================*/
/*--------------------*/
/*  gichar()          */
/*--------------------*/


#if defined (ANSI_DEFS)
MLOCAL VOID nextbyte(FSP0)
#else
MLOCAL VOID nextbyte()
#endif
{
    if(if_state.bs_im.numleft)
    {
        if_state.bs_im.bitbuf |=
                  (*if_state.bs_im.bytestream++)<<if_state.bs_im.bitct;
        if_state.bs_im.numleft--;
        if_state.bs_im.bitct += 8;
    }
}

#if defined (ANSI_DEFS)
MLOCAL VOID initbits(FSP UB8 *p, SL32 size)
#else
MLOCAL VOID initbits(p, size)
UB8 *p;
SL32 size;
#endif
{
    if_state.bs_im.bitbuf = 0;
    if_state.bs_im.bitct = 0;
    if_state.bs_im.bytestream = p;
    if_state.bs_im.numleft = size;
    /* Load two bytes into the bitbuf */
    nextbyte(FSA0);
    nextbyte(FSA0);
}


#if defined (ANSI_DEFS)
MLOCAL UW16 nextbit(FSP0)
#else
MLOCAL UW16 nextbit()
#endif
{
    SW16 retval;
    retval = if_state.bs_im.bitbuf & 1;
    if_state.bs_im.bitbuf >>=1;
    if_state.bs_im.bitct--;
    if(if_state.bs_im.bitct<=8)
        nextbyte(FSA0);
    return retval;
}


#if defined (ANSI_DEFS)
MLOCAL UW16 nextph(FSP GRAYIMAGE *gi)
#else
MLOCAL UW16 nextph(gi)
GRAYIMAGE *gi;
#endif
{
    SW16 retval;

    if(nextbit(FSA0)) {
        retval = gi->maxphval;
    }
    else if (gi->maxphval > 1)
    {
        retval = if_state.bs_im.bitbuf & gi->bsmask;
        if_state.bs_im.bitbuf >>=gi->bsct;
        if_state.bs_im.bitct -=gi->bsct;
        if(if_state.bs_im.bitct<=8)
            nextbyte(FSA0);
    }
    else {
        retval = 0;
    }

    return retval;
}


#if defined (ANSI_DEFS)
MLOCAL VOID cleargrayrow(SW16 *p, SW16 ct)
#else
MLOCAL VOID cleargrayrow(p, ct)
SW16 *p;
SW16 ct;
#endif
{
    while(ct--)
        *p++ = 0;
}

#if defined (ANSI_DEFS)
#if GRAYAPP_STATIC_LINK
GLOBAL UW16 gichar(FSP GRAYIMAGE *gi, PIFBITMAP pbm, SL32 xpos, SL32 ypos)
#else
GLOBAL UW16 gichar(FSP GRAYIMAGE *gi, PIFBITMAP pbm, SL32 xpos, SL32 ypos,
    VOID (*BLACKPIX_fn) (FSP SW16 x, SW16 y, void* winPtr),
    VOID (*GRAYPIX_fn) (FSP SW16 x, SW16 y, SW16 v, void* winPtr),
    VOID *winPtr
                   )
#endif
#else
GLOBAL UW16 gichar(gi, pbm, xpos, ypos)
GRAYIMAGE *gi;
PIFBITMAP pbm;
SL32 xpos;
SL32 ypos;
#endif
{
    SW16     w, d;
    SW16 xpix_gi, ypix_gi, xpix0;  /* pixel coordinate of gray level screen pixel */
    SW16 xphase, yphase;
    SW16 endxpix;
    SW16 bll, blr, bul, bur;

    DBG("gichar()\n");
    DBG1("width %d\n", pbm->width);

    if(!pbm->width)     /* Ignore empty bitmaps */
        return SUCCESS;

    w = pbm->black_width;     /* width in pixels */
    d = pbm->black_depth;     /* depth in pixel rasters */
    DBG2("black_width %d   black_depth %d\n", pbm->black_width,pbm->black_depth);


    /* Determine x and y phases for imaging graymap */
    switch( gi->numXphases ) {
      case 16:
        xphase = ((SW16)xpos & 0xf);       break;
      case 8:
        xphase = ((SW16)xpos & 0xf)>>1;    break;
      case 4:
        xphase = ((SW16)xpos & 0xf)>>2;    break;
      case 2:
        xphase = ((SW16)xpos & 0xf)>>3;    break;
      default:
        xphase = 0;
    }
    switch( gi->numYphases ) {
      case 16:
        yphase = ((SW16)ypos & 0xf);       break;
      case 8:
        yphase = ((SW16)ypos & 0xf)>>1;    break;
      case 4:
        yphase = ((SW16)ypos & 0xf)>>2;    break;
      case 2:
        yphase = ((SW16)ypos & 0xf)>>3;    break;
      default:
        yphase = 0;
    }

    /* compute 4 values for black pixel shifted to right and up */
    bur = xphase*yphase*gi->maxphval;
    bul = yphase*gi->numXphases*gi->maxphval-bur;
    blr = xphase*gi->numYphases*gi->maxphval-bur;
    bll = gi->maxpixval-bul-bur-blr;

    /* Compute display screen coordinate of pixel containing lower left corner */
    xpix0 = (SW16)((xpos + pbm->xorigin)/16L);
    ypix_gi  = (SW16)((ypos - pbm->yorigin)/16L) + d - 1;

    /* Prime the bit pump */
    initbits(FSA (UB8*)pbm->bm, pbm->size);

    endxpix = xpix0 + w;
    DBG2("numXsubpixels %d  numYsubpixels %d\n", gi->numXsubpixels, gi->numYsubpixels);

    if(gi->numXsubpixels==1 && gi->numYsubpixels==1)  {
        /* we are about to display the graymap format of a bitmap */
        while(d--)
        {
            for(xpix_gi = xpix0; xpix_gi < endxpix; xpix_gi++)
            {
                if(nextbit(FSA0))
                {
#if GRAYAPP_STATIC_LINK
                    BLACKPIX(FSA xpix_gi, ypix_gi);
#else
                    (*BLACKPIX_fn)(FSA xpix_gi, ypix_gi, winPtr);
#endif
                }
            }
            ypix_gi--;
        }
    }
else if(gi->numYphases == 1)    /* if no y phasing */
{
    /*  Develop the code for no y phasing first because it only requires
     *  a single value buffer instead of a whole raster line.  We don't
     *  want to complicate the simple case for the less likely case.
     */
    if(gi->numXphases == 1)  /* no phasing at all */
    {
        while(d--)
        {
            SW16 v;

            DBG1("d %d   ", d);
            DBG1("ypix_gi %d\n", ypix_gi);
            xpix_gi = xpix0;
            while(xpix_gi < endxpix)
            {
                DBG1("xpix_gi %d\n", xpix_gi);
                /* decode and image a single pixel */
                if(if_state.bs_im.bitbuf & 1)
                {
                    if(if_state.bs_im.bitbuf & 2)  /* am I black ? */
                    {
                        if_state.bs_im.bitbuf>>=2;
                        if_state.bs_im.bitct-=2;
#if GRAYAPP_STATIC_LINK
                        BLACKPIX(FSA xpix_gi, ypix_gi);
#else
                        (*BLACKPIX_fn)(FSA xpix_gi, ypix_gi, winPtr);
#endif
                    }
                    else
                    {
                        if_state.bs_im.bitbuf>>=2;
                        if_state.bs_im.bitct-=2;
                        if(gi->maxpixval == 2)
                            v = 1;
                        else
                        {
                            if(if_state.bs_im.bitct<=8)
                                nextbyte(FSA0);
                            v = if_state.bs_im.bitbuf & gi->bsmask;
                            if_state.bs_im.bitbuf >>=gi->bsct;
                            if_state.bs_im.bitct -=gi->bsct;
                        }
#if GRAYAPP_STATIC_LINK
                        GRAYPIX(FSA xpix_gi, ypix_gi, v);
#else
                        (*GRAYPIX_fn)(FSA xpix_gi, ypix_gi, v, winPtr);
#endif
                    }

                }
                else /* white pixel */
                {
                    if_state.bs_im.bitbuf>>=1;
                    if_state.bs_im.bitct--;
                }
                if(if_state.bs_im.bitct<=8)
                    nextbyte(FSA0);
                xpix_gi++;
            }  /* while(xpix_gi<endxpix) */
            ypix_gi--;
        }  /* while(d--) */
    }
    else  /* we have phasing only in x */
    {
        while(d--)
        {
#define ISWHITE 0
#define ISGRAY  1
#define ISBLACK 2
            SW16 pixtype;
            SW16 v, v1;

            pixtype = ISWHITE;
            v = 0;         /* current gray value under construction */
            xpix_gi = xpix0;
            while(xpix_gi < endxpix)
            {
                if(nextbit(FSA0))   /* pixel is not white */
                {
                    if(nextbit(FSA0))  /* pixel is black */
                    {
                        if(pixtype == ISBLACK)   /* write a black pixel */
                        {
#if GRAYAPP_STATIC_LINK
                            BLACKPIX(FSA xpix_gi, ypix_gi);
#else
                            (*BLACKPIX_fn)(FSA xpix_gi, ypix_gi, winPtr);
#endif
                        }
                        else       /* pixel is gray-  not white and not black */
                        {
                            v += bll;
#if GRAYAPP_STATIC_LINK
                            GRAYPIX(FSA xpix_gi, ypix_gi, v);
#else
                            (*GRAYPIX_fn)(FSA xpix_gi, ypix_gi, v, winPtr);
#endif
                            v = blr;
                            pixtype = ISBLACK;
                        }
                    }
                    else  /* pixel is gray */
                    {
                        SW16 ct = gi->numXphases-xphase;

                        /* finish v by adding in the rest of its phases */
                        while(ct--)
                            v += nextph(FSA gi);
                        v1 = 0;
                        ct = xphase;
                        while(ct--)
                            v1 += nextph(FSA gi);

                        if(v)
#if GRAYAPP_STATIC_LINK
                            GRAYPIX(FSA xpix_gi, ypix_gi, v);
#else
                            (*GRAYPIX_fn)(FSA xpix_gi, ypix_gi, v, winPtr);
#endif
                        v = v1;

                        pixtype = ISGRAY;
                    } /* else pixel is gray */
                }
                else  /* pixel is white */
                {
                    if(pixtype != ISWHITE)    /* if(iswhite) do nothing */
                    {
                        if(v)
                        {
#if GRAYAPP_STATIC_LINK
                            GRAYPIX(FSA xpix_gi, ypix_gi, v);
#else
                            (*GRAYPIX_fn)(FSA xpix_gi, ypix_gi, v, winPtr);
#endif
                            v = 0;
                        }
                        pixtype = ISWHITE;
                    }
                }
                xpix_gi++;
            }  /* while(x<endxpix) */
            ypix_gi--;
        }  /* while(d--) */
    }  /* else phasing in x */
}
else  /* we have to deal with y-phasing */
{
    SW16 buf0[MAXGRAYWIDTH];
    SW16 buf1[MAXGRAYWIDTH];
    SW16 *curbuf, *nxtbuf;
    SW16 i;

    curbuf = buf0;
    nxtbuf = buf1;
    cleargrayrow(curbuf, w);
    cleargrayrow(nxtbuf, w);

    while(d--)
    {
        /* Step 1.  read and decode next gray raster from input stream
         *          for each pixel, add to curbuf[] and nxtbuf[]
         */
        xpix_gi = xpix0;
        i = 0;
        while(xpix_gi < endxpix)
        {
            /* decode the next gray pixel from the input stream and add
             * all phase information to curbuf[] and nxtbuf[]
             */
            if(nextbit(FSA0))   /* pixel is not white */
            {
                if(nextbit(FSA0))  /* pixel is black */
                {
                    curbuf[i  ] += bll;
                    nxtbuf[i  ] += bul;
                    curbuf[i+1] += blr;
                    nxtbuf[i+1] += bur;
                }
                else  /* next pixel is gray */
                {
                    SW16 rowct, colct;
                    rowct = gi->numYphases - yphase;
                    while(rowct--)
                    {
                        colct = gi->numXphases - xphase;
                        while(colct--)
                            curbuf[i] += nextph(FSA gi);
                        colct = xphase;
                        while(colct--)
                            curbuf[i+1] += nextph(FSA gi);
                    }
                    rowct = yphase;
                    while(rowct--)
                    {
                        colct = gi->numXphases - xphase;
                        while(colct--)
                            nxtbuf[i] += nextph(FSA gi);
                        colct = xphase;
                        while(colct--)
                            nxtbuf[i+1] += nextph(FSA gi);
                    }

                }
            }
            else /* pixel is white */
            {
            }

            xpix_gi++;
            i++;
        }
        /* Step 2.  Image the curbuf[] */
        xpix_gi = xpix0;
        i = 0;
        while(xpix_gi < endxpix)
        {
            SW16 v;
            v = curbuf[i++];
            if(v)
#if GRAYAPP_STATIC_LINK
                GRAYPIX(FSA xpix_gi, ypix_gi, v);
#else
                (*GRAYPIX_fn)(FSA xpix_gi, ypix_gi, v, winPtr);
#endif
            xpix_gi++;
        }
        /* Step 3.  Switch buffers */
        {
            SW16 *tmp;
            tmp = curbuf;
            curbuf = nxtbuf;
            nxtbuf = tmp;
            cleargrayrow(nxtbuf, w);
        }
        ypix_gi--;
    }  /* while(d--) */
  }  /* else phasing in y */

    return SUCCESS;
} /* gichar() */
#endif  /* GRAYSCALING */

imath.h   、、、、、、、、、、、、、、、、、、

/* 
 * Copyright (C) 2003 Agfa Monotype Corporation. All rights reserved.
 */
/* $Header:   I:/BULL/URIP/SYS/INC/IMATH.H_V   1.8   Aug 22 2003 09:43:52   LynchR  $ */
/* $Log:   I:/BULL/URIP/SYS/INC/IMATH.H_V  $ 
 * 
 *    Rev 1.8   Aug 22 2003 09:43:52   LynchR
 * Updated copyright notice.
 * 
 *    Rev 1.7   Sep 23 2002 14:27:34   Galejs
 * test for multiple includes (part of bug # 76)
 * 
 *    Rev 1.6   22 Jun 1998 16:46:04   GALEJS
 * prototypes modified for reentrancy
 * 
 *    Rev 1.5   14 Jan 1998 14:07:40   GALEJS
 * delete unused externs
 * 
 *    Rev 1.4   07 Apr 1995 11:31:10   LISA
 * Changed copyright information from Miles Inc. to Bayer Corp.
 * 
 *    Rev 1.3   22 Apr 1994 15:31:36   LISA
 * Made modifications to copyright/disclaimer notice.
 * 
 *    Rev 1.2   14 Jan 1993 11:06:02   LISA
 * Removed CntrlZ character
 * 
 *    Rev 1.1   14 Dec 1992 08:46:42   LISA
 * Made change to Log keyword
 * 
 *    Rev 1.0   09 Dec 1992 11:37:38   LISA
 * Initial revision.
*/
/* $Date:   Aug 22 2003 09:43:52  $ */
/* imath.h */


/* History:
 *   3-Feb-91  awr  added lint args, removed scale_rem(), updated copyright.
 *  11-Nov-91  rs   add prototypes for 'cg_scale()'.
 *  02-Apr-92  rs   Portability cleanup (see port.h).
 */

#ifndef __IMATH__
#define __IMATH__

#ifdef LINT_ARGS
EXTERN SW16VECTOR nxy(FSP SW16VECTOR);
EXTERN SW16       scale_iii(SW16, SW16, SW16);
EXTERN SW16VECTOR cg_scale (FSP SW16VECTOR);
#else
EXTERN SW16VECTOR nxy();
EXTERN SW16       scale_iii();
EXTERN SW16VECTOR cg_scale ();
#endif

#endif    /* __IMATH__ */


 

imath.txt  、、、、、、、、、、、、、、、、、、、、、、

/* Copyright (C) 2003 Agfa Monotype Corporation. All rights reserved. */

/* $Header:   I:/BULL/URIP/RTS/COR/IMATH.C_V   1.13   Aug 21 2003 17:03:36   Galejs  $ */
/* $Log:   I:/BULL/URIP/RTS/COR/IMATH.C_V  $ 
 * 
 *    Rev 1.13   Aug 21 2003 17:03:36   Galejs
 * update copyright notice
 * 
 *    Rev 1.12   Jun 23 2003 14:17:20   Galejs
 * ufstport.h
 * 
 *    Rev 1.11   Oct 21 2002 18:15:54   Galejs
 * 
 *    Rev 1.10   Aug 13 1999 15:07:02   galejs
 * include-file changes
 * 
 *    Rev 1.9   22 Jun 1998 18:55:10   GALEJS
 * make Intellifont reentrant too
 * 
 *    Rev 1.8   02 Apr 1998 19:12:38   GALEJS
 * move externs to if_state
 * 
 *    Rev 1.7   24 Mar 1998 15:18:42   GALEJS
 * include-files changes
 * 
 *    Rev 1.6   02 Feb 1998 17:50:00   GALEJS
 * entire module should be conditional on IF_RDR
 * 
 *    Rev 1.5   06 Apr 1995 15:10:20   LISA
 * Changed copyright from Miles Inc. to Bayer Corp.
 * 
 *    Rev 1.4   22 Apr 1994 09:28:16   LISA
 * Modified copyright/disclaimer notice for 1994.
 * 
 *    Rev 1.3   12 Feb 1993 11:20:38   JOE
 * VXWorks support.
 * 
 *    Rev 1.2   07 Jan 1993 10:33:38   JOE
 * ANSI C function declaration changes.
 * 
 *    Rev 1.1   14 Dec 1992 09:36:28   LISA
 * Made change to Log keyword
 * 
 *    Rev 1.0   10 Dec 1992 08:37:26   LISA
 * Initial revision.
*/
/* $Date:   Aug 21 2003 17:03:36  $ */
/************************************************************************
**    imath.c                                                          **
**    -------------------------------------------------------------    **
 *
*************************************************************************/
/*
 *  10-Dec-90 awr  changed tx() and t() to account for the changed method
 *                 of computing output pixel size. See comp_pix().
 *  18-Jan-91 jfd  Trying to get rid of bogus value returned by "tx()"
 *                 and "ty()" when argument passed to it is a negative
 *                 number.
 *  30-Jan-91 dET  Added function prototyping for MSC
 *   3-Feb-91 awr  Removed scale_rem() and multiply_i_i - no longer used.
 *                 Moved function declarations to imath.h, updated copyright.
 *  20-Jun-91 bjg  Make rounding in nx() and ny() depend on sign.
 *  24-Jun-91 jfd  Moved "debug.h" after "port.h".
 *  26-Aug-91 awr  Moved tx() and ty() inline in des2bm().
 *                 Merged nx() and ny() into nxy()
 *  11-Nov-91 rs   Add 'cg_scale()' which was broken off from 'des2bm()'.
 *   7-Mar-92 awr  Reversed order in cg_scale(): scale 1st, rotate 2nd.
 *  03-Apr-92 rs   Portability cleanup (see port.h).
 *  15-Sep-92 jfd  Conditionally compiling entire module based on IF_RDR.
 *  22-Sep-92 jfd  Unconditionally compiling scale_iii().
 *  07-Jan-93 jfd  ANSI C function declaration changes.
 *  08-Feb-93 jfd  VXWorks support.
 */

#include "cgconfig.h"

#if IF_RDR        /* conditionally compile entire module */

#ifdef VXWORKS
#include "vxWorks.h"
#endif

#include <stdio.h>
#include "ufstport.h"
#include "dbg_ufst.h"

#include "shareinc.h"

#include "adj_skel.h"
#include "imath.h"    /* function declarations for this module */


/*-------------------------------------------------------------------*/
/*        scale_iii()                                                */
/*-------------------------------------------------------------------*/

#if defined (ANSI_DEFS)
SW16 scale_iii (SW16 x, SW16 y, SW16 z)
#else
SW16
scale_iii (x, y, z)

        SW16 x,y,z;
#endif
{
        return (
                  (SW16)(
                           ( (SL32)x  * (SL32)y ) / (SL32)z
                        )
               );
}

/*------------------*/
/*    nxy           */
/*------------------*/
#if defined (ANSI_DEFS)
GLOBAL SW16VECTOR nxy(FSP SW16VECTOR v)
#else
GLOBAL SW16VECTOR
nxy(v)
    SW16VECTOR v;
#endif
{
SW16VECTOR new;
SL32  x,y;

    new.x = v.x - if_state.x_tran.old0;
    new.y = v.y - if_state.y_tran.old0;

    if(new.x == 0)
        new.x = if_state.x_tran.new0;
    else
    {
        x = (SL32)(new.x) * (SL32)if_state.x_tran.num;
        if(x > 0)
            new.x = (SW16)((x + if_state.x_tran.half_den) / if_state.x_tran.den) + if_state.x_tran.new0;
        else
            new.x = (SW16)((x - if_state.x_tran.half_den) / if_state.x_tran.den) + if_state.x_tran.new0;
    }

    if(new.y == 0)
        new.y = if_state.y_tran.new0;
    else
    {
        y = (SL32)(new.y) * (SL32)if_state.y_tran.num;
        if(y > 0)
            new.y = (SW16)((y + if_state.y_tran.half_den) / if_state.y_tran.den) + if_state.y_tran.new0;
        else
            new.y = (SW16)((y - if_state.y_tran.half_den) / if_state.y_tran.den) + if_state.y_tran.new0;
    }

    return new;
}


#if defined (ANSI_DEFS)
GLOBAL SW16VECTOR cg_scale (FSP SW16VECTOR v)
#else
GLOBAL SW16VECTOR cg_scale (v)
SW16VECTOR v;
#endif
{
SW16    xx, yy;
SW16VECTOR    new={0,0};

   if (v.x < 0)
   {
      xx = -((  (UW16)(  ((UL32)-v.x << 16)  / if_state.x.p_pixel
                     ) + if_state.x.shift_rnd
            ) >> if_state.x.shift);
   }
   else
   {
      xx = (  (UW16)(  ((UL32)v.x << 16)  / if_state.x.p_pixel
                     ) + if_state.x.shift_rnd
            ) >> if_state.x.shift;
   }

   if (v.y < 0)
   {
      yy = -((  (UW16)(  ((UL32)-v.y << 16)  / if_state.y.p_pixel
                     ) + if_state.y.shift_rnd
            ) >> if_state.y.shift);
   }
   else
   {
      yy = (  (UW16)(  ((UL32)v.y << 16)  / if_state.y.p_pixel
                     ) + if_state.y.shift_rnd
            ) >> if_state.y.shift;
   }

   if(if_state.quadrant == ROT0)
   {
      new.x =  xx;
      new.y =  yy;
   }
   else if(if_state.quadrant == ROT90)
   {
      new.x = -yy;
      new.y =  xx;
   }
   else if(if_state.quadrant == ROT180)
   {
      new.x =  -xx;
      new.y =  -yy;
   }
   else if(if_state.quadrant == ROT270)
   {
      new.x =  yy;
      new.y = -xx;
   }
   else if(if_state.quadrant == -ROT0)    /* Next 4: mirror about y axis first */
   {
      new.x = -xx;
      new.y =  yy;
   }
   else if(if_state.quadrant == -ROT90)
   {
      new.x = -yy;
      new.y = -xx;
   }
   else if(if_state.quadrant == -ROT180)
   {
      new.x =   xx;
      new.y =  -yy;
   }
   else if(if_state.quadrant == -ROT270)
   {
      new.x = yy;
      new.y = xx;
   }

   new.x += if_state.tt.x;
   new.y += if_state.tt.y;

    return new;
}
#endif  /* IF_RDR */
 

intmem.c  、、、、、、、、、、、、、、、、、、、、、、、、

/* 
 * Copyright (C) 2003 Agfa Monotype Corporation. All rights reserved.
 */
/* $Header:   I:\bull\urip\rts\dep\intmem.c_v */
/* $Log:   I:/BULL/URIP/RTS/DEP/INTMEM.C_V  $ 
 * 
 *    Rev 1.31   Oct 01 2004 13:50:16   dugganj
 * Fixed compiler bugs due to multithread support addition.
 * 
 * 
 *    Rev 1.30   Sep 09 2004 18:17:18   galejss
 * in CGIFfund, change test for valid memory pool to use NP (rather than hardcoded pool ID)
 * 
 *    Rev 1.29   Oct 17 2003 16:44:50   Galejs
 * remove obsolete MEM_DUMP_INT code; compile fixes for MEM_TRACE option
 * 
 *    Rev 1.28   Aug 22 2003 08:57:10   LynchR
 * Updated copyright notice.
 * 
 *    Rev 1.27   Jun 19 2003 18:57:42   Galejs
 * clean up debugging options
 * 
 *    Rev 1.26   Jun 29 2001 17:57:02   Galejs
 * put all preprocessor lines in 1st column (for portability)
 * 
 *    Rev 1.25   May 03 2001 20:10:34   Galejs
 * fix unclosed comment
 * 
 *    Rev 1.24   17 Mar 2000 11:54:48   JOE
 * Added ulongmemset() (by ks).
 * 
 *    Rev 1.23   Aug 18 1999 14:46:32   galejs
 * fix CGIFfund() for 8-byte-align platforms
 * 
 *    Rev 1.22   Aug 17 1999 11:40:12   galejs
 * include-file changes
 * 
 *    Rev 1.21   20 Jan 1999 12:20:24   GALEJS
 * add 8-byte-align for 64-bit-pointer systems
 * 
 *    Rev 1.20   16 Sep 1998 19:17:44   GALEJS
 * MIPS also needs 8-byte-alignment (for doubles in structs)
 * 
 *    Rev 1.19   15 Jun 1998 14:24:10   GALEJS
 * get rid of MULTICALLER, MEMgethandlesize; reentrancy parms
 * 
 *    Rev 1.18   15 Apr 1998 17:47:24   GALEJS
 * symbolset in IF_STATE now
 * 
 *    Rev 1.17   02 Apr 1998 19:48:54   GALEJS
 * compile fix for MEMinst_Free()
 * 
 *    Rev 1.16   01 Apr 1998 18:56:46   GALEJS
 * mem_fund[] (and others) now in IF_STATE
 * 
 *    Rev 1.15   30 Mar 1998 12:26:06   GALEJS
 * move MLOCALs (+ supporting defines/typedefs) into if_state
 * 
 *    Rev 1.14   05 Jan 1996 10:16:34   MERRILL
 * Pragma warn -sig and fix pvcs err.
 * 
 *    Rev 1.13   11 Dec 1995 15:41:44   MERRILL
 * cleaned up warning messages, unused vars.
 * 
 *    Rev 1.12   07 Apr 1995 08:37:12   LISA
 * Changed copyright from Miles Inc. to Bayer Corp.
 * 
 *    Rev 1.11   13 Jan 1995 18:06:08   ROB
 * Support for > 64KB memory blocks in DOS.
 * 
 *    Rev 1.10   29 Sep 1994 14:44:40   MARTIN
 * Removed line in MEMalloc that forced the handle to the requested size. It w
 * 
 *    Rev 1.9   31 Aug 1994 14:20:30   JOE
 * Added MEMgethandlesize() routine and modified MEMalloc() so that it
 * returns the amount of memory requested, not more.
 * 
 *    Rev 1.8   03 Jun 1994 10:02:08   JOE
 * Changed all occurrences of ENTRY to CGENTRY to resolve conflict on
 * some compilers.
 * 
 *    Rev 1.7   21 Apr 1994 15:43:12   LISA
 * Made modifications to copyright/disclaimer notice.
 * 
 *    Rev 1.6   22 Feb 1994 16:31:36   JOE
 * In MEMalloc() and MEMfree(), if running on _AM29K system under UNIX,
 * must 8-byte align due to Type 1 structures containing "double" fields.
 * 
 *    Rev 1.5   03 Aug 1993 14:44:50   MAIB
 * Changed interface to resolve naming conflicts
 * 
 *    Rev 1.4   02 Aug 1993 14:21:00   MAIB
 * Changes to support multi-tasking
 * 
 *    Rev 1.3   12 Feb 1993 14:15:10   JOE
 * VXWorks support.
 * 
 *    Rev 1.2   22 Dec 1992 13:38:38   ROB
 * Added ANSI function declarations based on ANSI_DEFS. Added prototypes.
 * 
 *    Rev 1.1   11 Dec 1992 15:29:30   LISA
 * Made change to Log keyword
 * 
 *    Rev 1.0   09 Dec 1992 15:25:56   LISA
 * Initial revision.
*/
/* $Date:   Oct 01 2004 13:50:16  $ */
/*  intmem.c  */
/*
 *
 * History
 *
 *    04-Sep-91  jfd   Internal memory management routines extraced from
 *                     mem.c.
 *    29-Sep-91  awr   Start MEMinstFree() at page 1 instead of page 0
 *                     Simplified CGIFdefund() for buffer memory.
 *    26-Nov-91  jfd   In CGIFdefund(), conditionally declared 
 *                     "status" and "reinit_cache" based on CACHE
 *                     to get rid of compiler warnings.
 *    27-Feb-92  jfd   Moved "#if INT_MEM_MGT" statement to top of file.
 *    03-Apr-92  rs    Portability cleanup (see port.h).
 *    16 Apr 92  ss    Moved hfontCur, pfontCur defs out of CGIFmove_block()
 *                     to make the available to CGIFdefund().
 *                     In CGIFdefund(), added call to CGIFfont() to reset
 *                     fontcontext info after it got wiped out by CACdefund().
 *    02-Sep-92  jfd   In CGIFdefund(), before calling IXinit(), save
 *                     current symbol set number from "symbolset" structure
 *                     and restore it after call to IXinit() because IXinit()
 *                     calls SYMinit() which zeroes out this value.
 *                     Included "sym.h".
 *    22-Dec-92  rs    Add ANSI function declarations based upon ANSI_DEFS.
 *                     Add function prototypes.
 *    08-Feb-93  jfd   VXWorks support.
 *    02-Aug-93 maib Changed interface to prevent CGIFxxx() routines from
 *             calling other CGIFxxx() routines, required for 
 *             multi-tasking. also added multicaller support code to 
 *             CGIFxxx() routines
 *    03-Aug-93 maib changed definitions for cgifXXXX() routines to resolve
 *             naming conflicts
 *    17-Feb-94  jfd   In MEMalloc() and MEMfree(), if running on _AM29K
 *                     system under UNIX, must 8-byte align due to PS
 *                     structures containing "double" fields.
 *    03-Jun-94  jfd   Changed all occurrences of ENTRY to CGENTRY to resolve
 *                     conflict on some compilers.
 *    09-Aug-94  sbm   Added MEMgethandlesize routine, and modified MEMalloc
 *                     so that it returns the amount of memory requested, not more.
 *    28-Sep-94  sbm   Removed the above mentioned modification to MEMalloc,
 *                     it was causing a fragmentation of memory.
 *    09-Jan-95  rob   Modify internal memory mgt to support > 64KB blocks.
 *    25-Mar-98  slg    Move mem_avail[] into if_state (shared with extmem.c). Also 
 *                    move all other MLOCALs (and required defines/typedefs).
 *    01-Apr-98  slg  Move some referenced GLOBALs into IF_STATE; also move
 *                    mem_fund[] into IF_STATE (shared with intmem.c)
 *    02-Apr-98  slg    Compile fix for MEMinstFree().
 *    15-Jun-98  slg    Get rid of MULTICALLER code; comment out apparently-unused
 *                    function MEMgethandlesize(); reentrancy parm-passing
 *    16-Sep-98  slg    Need to use _AM29K 8-byte-align logic for MIPS as well
 *    20-Jan-99  slg    Add separate 8-byte-align for 64-bit-pointer systems.
 *  18-Aug-99  slg    CGIFfund() wasn't correct for 8-byte-align platforms - 
 *                        needed to add 8-byte-offset before calling MEMfree().
 *  16-Mar-00  ks   Added ulongmemset() to handle sizes > 64K on system with
 *                  16 bit ints. 
 */

#include "cgconfig.h"

#if INT_MEM_MGT  /*  internal memory manager  */

#ifdef VXWORKS
#include "vxWorks.h"
#endif

#include <stdio.h>

#include "ufstport.h"
#include "dbg_ufst.h"
#include "shareinc.h"

#if defined (LINT_ARGS)
#if (HUGE_PTR_SUPPORT)
UW16 CGENTRY CGIFmove_block (FSP UW16, HPSB8);
#else
UW16 CGENTRY CGIFmove_block (FSP UW16, LPSB8);
#endif

#if (HUGE_PTR_SUPPORT)
GLOBAL HPSB8 hMEMptr (FSP MEM_HANDLE);
#else
GLOBAL LPSB8 MEMptrFSP (FSP MEM_HANDLE);
#endif

#else /* no LINT_ARGS */
UW16 CGENTRY CGIFmove_block ();

#if (HUGE_PTR_SUPPORT)
GLOBAL HPSB8 hMEMptr ();
#else
GLOBAL LPSB8 MEMptr ();
#endif

#endif /* LINT_ARGS */

/*
The memory manager must handle two memory pools. The pools are referenced
by the defines in cgif.h:

        #define CACHE_POOL   0
        #define BUFFER_POOL  1

Each pool is funded with a number of bytes of memory stored in mem_fund[].
During operation, some of this memory will be given to clients via
MEMalloc() to be later returned via MEMfree(). The number of bytes that
are still availble is stored in mem_avail[]. Thus calls to MEMalloc()
decrease mem_avail[] while calls to MEMfree() increase mem_avail[].
If the number of bytes requested through MEMalloc() is more than
mem_avail[], the request fails and NIL_MH is returned.

*/

/*
The memory management option supported below is compiled depending on the
setting in cgconfig.h of INT_MEM_MGT.

The internal memory manager directly provides dynamic memory allocation.

Either the external or internal memory manager may by used. The external
memory manager may be modified to use other external allocation functions.

The two memory managers differ in the way that their pool memory is
funded. The internal manager is funded via a function CGIFfund().
The external manager's fund sizes are simply set in MEMinit().
*/


/*--------------------------------------------------------------------*/
/*       I n t e r n a l    M e m o r y    m a n a g e r              */

#define FRAG_MIN    64


/*----------------*/
/*   MEMptr       */
/*----------------*/
/*  Convert a memory handle to a pointer */

#if defined(__BORLANDC__)
#pragma warn -sig
#endif
#if defined (ANSI_DEFS)
#if (HUGE_PTR_SUPPORT)
GLOBAL HPSB8 hMEMptr (FSP MEM_HANDLE mem_handle)
#else
GLOBAL LPSB8 MEMptrFSP (FSP MEM_HANDLE mem_handle)
#endif
#else
#if (HUGE_PTR_SUPPORT)
GLOBAL HPSB8 hMEMptr(mem_handle)
#else
GLOBAL LPSB8 MEMptr(mem_handle)
#endif
    MEM_HANDLE mem_handle;
#endif /* ANSI_DEFS */
{
    return (if_state.pserver->mem[PAGE(mem_handle)].ptr + OFF(mem_handle));
}


/*----------------*/
/*   MEMinit      */
/*----------------*/
#if defined (ANSI_DEFS)
GLOBAL VOID MEMinit (FSP0)
#else
GLOBAL VOID MEMinit ()
#endif /* ANSI_DEFS */
{
    UW16 i, j;
    PMEM  mp;
    MEM_HANDLE handle;

    for(i=0, handle = 0; i<NP; i++, handle += sizeof(MEMHEAD))
    {

      /* Initialize nullblock. This is the start of a circular linked
       * list of available memory blocks.
       */

        if_state.pserver->page0.nullblock[i].size   = 0L;        /* I'm nothing but overhead */
        if_state.pserver->page0.nullblock[i].next   = handle;    /* point to me              */

        if_state.pserver->avail[i]      = handle;          /* point to nullblock       */
        if_state.pserver->mem_avail[i]  = 0L;
        if_state.pserver->mem_fund[i]   = 0L;
    }

  /* Initialize page table. */

    mp = if_state.pserver->mem;

  /* Set page 0 */

    mp->size = sizeof(PAGE0);
#if (HUGE_PTR_SUPPORT)
    mp->ptr  = (HPSB8)&if_state.pserver->page0;
#else
    mp->ptr  = (LPSB8)&if_state.pserver->page0;
#endif
       
  /*  Zero out all other block sizes. A zero block size means
   *  the handle is not in use.
   */

    for(j=1; j<NH; j++)
    {
        mp++;
        mp->size = 0L;
    }
}


/*----------------*/
/*  MEMalloc      */
/*----------------*/
#if defined (ANSI_DEFS)
GLOBAL MEM_HANDLE MEMalloc (FSP UW16 i, SL32 size)
#else
GLOBAL MEM_HANDLE MEMalloc (i, size)
    UW16 i;
    SL32  size;
#endif /* ANSI_DEFS */
{
    PMEMHEAD    prev, p;
    MEM_HANDLE hprev, hp;
    SL32      frag_size;

#if MEM_TRACE
    DBG2("\n\nMEMmalloc(%u, %ld)\n", i, size);
#endif

#if (NAT_ALIGN == 8)

  /* Align to 8-byte boundary (needed for 64-bit pointers) */
  /* WARNING - this code assumes that MEM_ALIGN==7 ! */

    size += ( sizeof( SL32 ) + sizeof( SL32 ) + MEM_ALIGN);
    size &= ~MEM_ALIGN;

#elif (defined(_AM29K) && defined(SUN)) || defined(MIPS)

  /*  Make room for "size" and round up for 8-byte alignment. This is
   *  necessary for _AM29K systems running under UNIX. - jfd 2-17-94
   */

    size += ( sizeof( SL32 ) + sizeof( SL32 ) + (MEM_ALIGN + 4));  /* MEMHEAD.size is long -ss */
    size &= ~(MEM_ALIGN + 4);
#else

  /*  Make room for "size" and round up for alignment */

    size += sizeof( SL32 ) + MEM_ALIGN;    /* MEMHEAD.size is long -ss */
    size &= ~MEM_ALIGN;
#endif
    size = MAX(size, (SL32)sizeof(MEMHEAD)); /* 9-apr-91 dET minimum size */

#if MEM_TRACE
    DBG1("    adjusted size %ld\n", size);
#endif

  /* First fit search for big enough block */

    hprev = if_state.pserver->avail[i];
#if (HUGE_PTR_SUPPORT)
    prev  = (PMEMHEAD)hMEMptr(FSA hprev);
    hp    = prev->next;
    p     = (PMEMHEAD)hMEMptr(FSA hp);
#else
    prev  = (PMEMHEAD)MEMptr(hprev);
    hp    = prev->next;
    p     = (PMEMHEAD)MEMptr(hp);
#endif
    for( ; ; )
    {
        if(p->size >= size) break;
        if(hp == if_state.pserver->avail[i])
            return NIL_MH;

        hprev = hp;
        prev  = p;
        hp    = p->next;
#if (HUGE_PTR_SUPPORT)
        p     = (PMEMHEAD)hMEMptr(FSA hp);
#else
        p     = (PMEMHEAD)MEMptr(hp);
#endif
    }

  /* If p is large enough, cut off the end and return it */

    frag_size = p->size - size;

    if(frag_size >= FRAG_MIN)
    {
        p->size = frag_size;                   /* shorten p                */
        hp = hp + frag_size;                   /* new handle for tail      */
#if (HUGE_PTR_SUPPORT)
        p = (PMEMHEAD)((HPSB8)p + frag_size);  /* point p at tail of block */
#else
        p = (PMEMHEAD)((LPSB8)p + frag_size);  /* point p at tail of block */
#endif
        p->size = size;
    }
    else
        prev->next = p->next;                  /* unlink p */

    if_state.pserver->avail[i] = hprev;

    if_state.pserver->mem_avail[i] -= p->size;

#if MEM_TRACE
    DBG("-------after------------\n");
    MEMstat(FSA i);
    DBG1("    %lx\n", hp + sizeof(SL32));
#endif

#if (defined(_AM29K) && defined(SUN)) || defined(MIPS) || (NAT_ALIGN == 8) 
    return hp + sizeof(SL32) + sizeof(SL32);  /* skip over ("size" + 4) -jfd 2-18-94 */
#else
    return hp + sizeof(SL32);    /* skip over "size"  - was '+ 4' -ss  */
#endif
}


/*----------------*/
/*  MEMfree       */
/*----------------*/
#if defined (ANSI_DEFS)
GLOBAL VOID MEMfree (FSP UW16 i, MEM_HANDLE hm)
#else
GLOBAL VOID MEMfree (i, hm)
    UW16 i;
    MEM_HANDLE hm;
#endif /* ANSI_DEFS */
{
    PMEMHEAD    p,  prev,  next;
    MEM_HANDLE  hp, hprev, hnext, t;


#if MEM_TRACE
    DBG2("MEMfree(%u, %lx)  ", i, hm);
#endif

    if(!hm) return;

#if (defined(_AM29K) && defined(SUN)) || defined(MIPS) || (NAT_ALIGN == 8) 
    hp = hm - (sizeof(SL32) + sizeof(SL32)); /* back up over "size + 4"  -jfd 2-18-94 */
#else
    hp = hm - sizeof(SL32);      /* back up over "size"  - was '- 4'  -ss  */
#endif
#if (HUGE_PTR_SUPPORT)
    p = (PMEMHEAD)hMEMptr(FSA hp);
#else
    p = (PMEMHEAD)MEMptr(hp);
#endif

    if_state.pserver->mem_avail[i] += p->size;                    /* checkbook deposit       */

#if MEM_TRACE
    DBG1("    size %ld\n", p->size);
#endif


  /* Find the right place to insert p in avail ring */

    hprev = if_state.pserver->avail[i];
#if (HUGE_PTR_SUPPORT)
    prev  = (PMEMHEAD)hMEMptr(FSA hprev);
    hnext = prev->next;
    next  = (PMEMHEAD)hMEMptr(FSA hnext);
#else
    prev  = (PMEMHEAD)MEMptr(hprev);
    hnext = prev->next;
    next  = (PMEMHEAD)MEMptr(hnext);
#endif
    while(  !(hprev < hp && hp < hnext)  )  /*  stop when hp is between
                                             *  hprev and hnext
                                             */
    {
      /*  Also stop when hprev is the largest address and hnext is
       *  the smallest address and hp is the new largest or the
       *  new smallest
       */

        if (hprev >= hnext && (hp > hprev || hp < hnext) ) break;
        hprev = hnext;
        prev  = next;
        hnext = next->next;
#if (HUGE_PTR_SUPPORT)
        next  = (PMEMHEAD)hMEMptr(FSA hnext);
#else
        next  = (PMEMHEAD)MEMptr(hnext);
#endif
    }

  /*  p should now be linked between prev and next. Here we check
   *  whether any or all of the three blocks need to be merged.
   */

    t = hp + p->size;             /* handle of block just after p     */
    if(t == hnext && PAGE(hp) == PAGE(hnext))
    {
      /* merge p and next */

        p->size += next->size;
        p->next  = next->next;
    }
    else
        p->next = hnext;   /* link p before next */

    t = hprev + prev->size;
    if(t == hp && PAGE(hprev) == PAGE(hp))
    {
      /* merge prev and p */

        prev->size += p->size;
        prev->next  = p->next;
    }
    else
        prev->next = hp;

    if_state.pserver->avail[i] = hprev;

#if MEM_TRACE
    DBG("-------after------------\n");
    MEMstat(FSA i);
#endif
}


/*----------------*/
/*  CGIFfund      */
/*----------------*/

#if defined (ANSI_DEFS)
#if (HUGE_PTR_SUPPORT)
UW16 CGENTRY CGIFfund (FSP UW16 pool, HPSB8 memptr, UL32 size, LPUW16 handle)
#else
UW16 CGENTRY CGIFfund (FSP UW16 pool, LPSB8 memptr, UL32 size, LPUW16 handle)
#endif
#else
UW16 CGENTRY CGIFfund (pool, memptr, size, handle)
    UW16  pool;
#if (HUGE_PTR_SUPPORT)
    HPSB8  memptr;
#else
    LPSB8  memptr;
#endif
    UL32  size;
    LPUW16 handle;
#endif /* ANSI_DEFS */
{
    SL32   lsize;   /* internal sizes are SL32  */
    PMEM   mp;
    UW16  h;

    if(pool > (NP-1)) 
    {
      return ERR_bad_pool;
    }

  /* Take care of alignment. */

    lsize = (SL32)size & ~MEM_ALIGN;  /* round size down to aligned value */

    /* get a page handle */
    /* Find first available handle */
    mp = if_state.pserver->mem;               /* get beginning of handle array       */
    for( h = 0; h < NH; h++ )
    {
        if ( !mp->size )    /* Look for an empty slot (size == 0)   */
        {
          /* fill in size and memory pointer */
          mp->pool = pool;
          mp->size = lsize;
          mp->ptr  = memptr;
          break;
        }
        mp++;
    }

    if(h >= NH)
    {
      return ERR_out_of_handles;
    }

    *handle = h;

    /* Free the page */

    ((PMEMHEAD)memptr)->size = lsize;

    /* in some cases, we should add 8 bytes to the offset, rather than 4, 
        because    the first thing that MEMfree() will do is to back up by
        that amount. (sandra, 18 aug 99) */

#if (defined(_AM29K) && defined(SUN)) || defined(MIPS) || (NAT_ALIGN == 8)
        MEMfree(FSA pool, ((UL32)h << OFFBITS) + sizeof(SL32) + sizeof(SL32));
#else
        MEMfree(FSA pool, ((UL32)h << OFFBITS) + sizeof(SL32));
#endif

    if_state.pserver->mem_fund[pool] += lsize;

    return SUCCESS;
}


/*----------------*/
/* CGIFmove_block */
/*----------------*/
#if defined (ANSI_DEFS)
#if (HUGE_PTR_SUPPORT)
UW16 CGENTRY CGIFmove_block (FSP UW16 page, HPSB8 memptr)
#else
UW16 CGENTRY CGIFmove_block (FSP UW16 page, LPSB8 memptr)
#endif
#else
UW16 CGENTRY CGIFmove_block (page, memptr)
    UW16 page;
#if (HUGE_PTR_SUPPORT)
    HPSB8 memptr;
#else
    LPSB8 memptr;
#endif
#endif /* ANSI_DEFS */
{
    PMEM  mp;

    if(page > NH) return ERR_bad_handle;
    mp = if_state.pserver->mem + page;
    if(!mp->size) return ERR_bad_handle;    /* page isn't active */
    mp->ptr = memptr;

#if CACHE
  /*  See if the page that moved contains the current FONT. If it does,
   *  recover the pointer now. This is done here so that we don't have
   *  to recover the FONT pointer everytine CGIFchar() is called. This
   *  makes a noticable difference in the cache speed.
   */
    {
         if(PAGE(if_state.hfontCur) == page)
#if (HUGE_PTR_SUPPORT)
           if_state.pfontCur = (PFONT)hMEMptr(FSA if_state.hfontCur);
#else
           if_state.pfontCur = (PFONT)MEMptr(if_state.hfontCur);
#endif
    }
#endif

    return SUCCESS;
}


/*---------------------------------------------------------------------*/
/*                           D E F U N D                               */
#if DEFUND

/*----------------*/
/*  CGIFdefund    */
/*----------------*/

#if defined (ANSI_DEFS)
GLOBAL UW16 CGENTRY CGIFdefund (FSP UW16 page)
#else
GLOBAL UW16 CGENTRY CGIFdefund (page)
    UW16  page;
#endif /* ANSI_DEFS */
{
    PMEM          mp;
    SL32          size;
    MEM_HANDLE    hp, hprev;
    PMEMHEAD      p, prev;
    UW16         pool;
#if CACHE
    BOOLEAN       reinit_cache;
    PFONT         sav_font;
#endif
#if DEFUND
    UW16         sav_curssnum;
#endif
    UW16         status;

    DBG1("CGIFdefund(page == %d)\n", page);

    if(page > NH)        return ERR_bad_handle;

    mp = if_state.mem + page;
    if(!(size = mp->size)) return ERR_bad_handle;    /* page isn't active */
    pool = mp->pool;

  /*================ C A C H E _ P O O L ======================*/
#if CACHE
    if(pool == CACHE_POOL)
    {
        sav_font = if_state.pfontCur;   /* save copy to get at FC later -ss 4/16/92 */
      /* Free FONTs and BITMAPs using this page */
        reinit_cache = CACdefund(FSA page);
    }
    else
#endif    

  /*================ B U F F E R _ P O O L ======================*/

    if(pool == BUFFER_POOL)
        IXexit(FSA0);

  /*================ Remove memory block from avail ring =============*/

    hprev = if_state.avail[pool];
#if (HUGE_PTR_SUPPORT)
    prev  = (PMEMHEAD)hMEMptr(FSA hprev);
    hp    = prev->next;
    p     = (PMEMHEAD)hMEMptr(FSA hp);
#else
    prev  = (PMEMHEAD)MEMptr(hprev);
    hp    = prev->next;
    p     = (PMEMHEAD)MEMptr(hp);
#endif
    for( ; ; )
    {
        if(PAGE(hp) == page) break;
        if(hp == if_state.avail[pool])
        {
            DBG("    failed\n");
            return ERR_missing_block;
        }
        hprev = hp;
        prev  = p;
        hp    = p->next;
#if (HUGE_PTR_SUPPORT)
        p     = (PMEMHEAD)hMEMptr(FSA hp);
#else
        p     = (PMEMHEAD)MEMptr(hp);
#endif
    }
    if_state.avail[pool] = hprev;

  /* Check that it's all there */

    if(p->size != size)
        return ERR_lost_mem;
    prev->next = p->next;                    /* unlink p */
    if_state.mem_avail[pool] -= size;

    mp->size = 0L;                        /* this page is now available */

  /*================ C A C H E _ P O O L ======================*/
#if CACHE
    if(pool == CACHE_POOL)
    {
        if(reinit_cache)
        {
            status = CACinit(FSA0);
            if (status)
                return status;
            if( sav_font )   /* if have valid pointer reinit fontcontext. */
            {                /*                              -ss 4/16/92  */
               status = CGIFfont( FSA &sav_font->fc );
               if (status)
               {
                   DBG1("(Reinit cache) CGIFfont error %d\n", status);
                   return status;
               }
            }  /* sav_font */
        }  /* reinit */
    }
    else
#endif
  /*================ B U F F E R _ P O O L ======================*/
    if(pool == BUFFER_POOL)
    {
        sav_curssnum = if_state.symbolset.curssnum; /* save ss number */
        status = IXinit(FSA0);
        if (status)
           return (status);
        if_state.symbolset.curssnum = sav_curssnum; /* restore ss number */
    }

    return SUCCESS;  /* to keep a compiler quiet */
}

#endif   /* DEFUND */
/*                           D E F U N D                               */
/*---------------------------------------------------------------------*/

#if MEM_TRACE

/*----------------*/
/*  MEMstat       */
/*----------------*/
#if defined (ANSI_DEFS)
GLOBAL VOID MEMstat (FSP UW16 i)
#else
GLOBAL VOID MEMstat (i)
    UW16  i;
#endif /* ANSI_DEFS */
{
    SL32  total, max_size;
    MEM_HANDLE hp;
    PMEMHEAD  p;


    total    = 0;
    max_size = 0;

    hp = if_state.avail[i];
#if (HUGE_PTR_SUPPORT)
    p  = (PMEMHEAD)hMEMptr(FSA hp);
#else
    p  = (PMEMHEAD)MEMptr(hp);
#endif
    for( ; ; )
    {
        if(p)
        {
          DBG4("pointer == %Fp  handle == %Fp size==%5ld  next== %Fp\n",
                                p, hp, p->size, p->next);
        }
        else
        {
          DBG("NULL POINTER \n");
        }

        if(p->size > max_size)  max_size = p->size;
        total += p->size;

        hp = p->next;
#if (HUGE_PTR_SUPPORT)
        p  = (PMEMHEAD)hMEMptr(FSA hp);
#else
        p  = (PMEMHEAD)MEMptr(hp);
#endif

        if(hp == if_state.avail[i])  break;
    }

    DBG1("MEMstat pool %u\n",i);
    DBG1("             Largest free block  %ld\n", max_size);
    DBG1("             Total available     %ld\n", total);
    DBG1("             Total in fund       %ld\n", if_state.mem_fund[i]);
    if(if_state.mem_avail[i] != total)
        DBG("?????????? does not compute ?????????\n");
}

#endif /* MEM_TRACE */


/* Mar 16, 2000
   Customer's system memset parameter is casted to int on
   their 16 bit platform, it couldn't handle bitmap buffer
   size > 64k.  The size parameter needs to be passed down 
   as long for MAX_BM_BITS 22                             */

#if defined( _OSK )

GLOBAL void *ulongmemset(void *dst, UW16 c, UL32 count)
{
LPUB8 idst, icc;
UB8 cc;
UL32 i;

idst = (LPUB8) dst;
cc = (UB8) c;
icc = (LPUB8) &cc;
for (i=0; i<count; i++)
    *idst++ = *icc;
return (dst);
} /* END ULONGMEMSET */

#endif /* _OSK */


/*       I n t e r n a l    M e m o r y    m a n a g e r              */
/*--------------------------------------------------------------------*/

#endif   /*  INT_MEM_MGT  */
 

io.h   、、、、、、、、、、、、、、、、、、、、、、、、

空文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值