home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / GXMATRIX.H < prev    next >
C/C++ Source or Header  |  1994-07-27  |  3KB  |  76 lines

  1. /* Copyright (C) 1989, 1990, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gxmatrix.h */
  20. /* Internal matrix routines for Ghostscript library */
  21.  
  22. #ifndef gxmatrix_INCLUDED
  23. #  define gxmatrix_INCLUDED
  24.  
  25. #include "gsmatrix.h"
  26.  
  27. /* A matrix with a cached fixed-point copy of the translation. */
  28. /* This is only used by a few routines; they are responsible */
  29. /* for ensuring the validity of the cache */
  30. /* (by calling gs_update_matrix_fixed). */
  31. typedef struct gs_matrix_fixed_s {
  32.     _matrix_body;
  33.     fixed tx_fixed, ty_fixed;
  34. } gs_matrix_fixed;
  35. void    gs_update_matrix_fixed(P1(gs_matrix_fixed *));
  36.  
  37. /* Coordinate transformations to fixed point. */
  38. int    gs_point_transform2fixed(P4(const gs_matrix_fixed *, floatp, floatp, gs_fixed_point *)),
  39.     gs_distance_transform2fixed(P4(const gs_matrix_fixed *, floatp, floatp, gs_fixed_point *));
  40.  
  41. /* Macro for testing whether matrix coefficients are zero, */
  42. /* for shortcuts when the matrix has no skew. */
  43. #define is_skewed(pmat) !is_fzero2((pmat)->xy, (pmat)->yx)
  44.  
  45. /*
  46.  * Define the fixed-point coefficient structure for avoiding
  47.  * floating point in coordinate transformations.
  48.  * Currently this is used only by the Type 1 font interpreter.
  49.  * The setup is in gscoord.c.
  50.  */
  51. typedef struct {
  52.     long l;
  53.     fixed f;
  54. } coeff1;
  55. typedef struct {
  56.     coeff1 xx, xy, yx, yy;
  57.     int skewed;
  58.     int shift;            /* see m_fixed */
  59.     int max_bits;            /* max bits of coefficient */
  60.     fixed round;            /* ditto */
  61. } fixed_coeff;
  62. /*
  63.  * Multiply a fixed whose integer part usually does not exceed max_bits
  64.  * in magnitude by a coefficient from a fixed_coeff.
  65.  * We can use a faster algorithm if the fixed is an integer within
  66.  * a range that doesn't cause the multiplication to overflow an int.
  67.  */
  68. #define m_fixed(v, c, fc, maxb)\
  69.   (((v) + (fixed_1 << (maxb - 1))) &\
  70.     ((-fixed_1 << maxb) | _fixed_fraction_v) ?    /* out of range, or has fraction */\
  71.    (fixed2int_var(v) * (fc).c.f +\
  72.     arith_rshift(fixed_fraction(v) * (fc).c.f + fixed_half, _fixed_shift)) :\
  73.    arith_rshift(fixed2int_var(v) * (fc).c.l + (fc).round, (fc).shift))
  74.  
  75. #endif                    /* gxmatrix_INCLUDED */
  76.