(root)/
fontconfig-2.14.2/
src/
fcmatrix.c
       1  /*
       2   * fontconfig/src/fcmatrix.c
       3   *
       4   * Copyright © 2000 Tuomas J. Lukka
       5   *
       6   * Permission to use, copy, modify, distribute, and sell this software and its
       7   * documentation for any purpose is hereby granted without fee, provided that
       8   * the above copyright notice appear in all copies and that both that
       9   * copyright notice and this permission notice appear in supporting
      10   * documentation, and that the name of Tuomas Lukka not be used in
      11   * advertising or publicity pertaining to distribution of the software without
      12   * specific, written prior permission.  Tuomas Lukka makes no
      13   * representations about the suitability of this software for any purpose.  It
      14   * is provided "as is" without express or implied warranty.
      15   *
      16   * TUOMAS LUKKA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
      17   * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
      18   * EVENT SHALL TUOMAS LUKKA BE LIABLE FOR ANY SPECIAL, INDIRECT OR
      19   * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
      20   * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
      21   * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
      22   * PERFORMANCE OF THIS SOFTWARE.
      23   */
      24  
      25  #include "fcint.h"
      26  #include <math.h>
      27  #include <stdlib.h>
      28  #include <ctype.h>
      29  
      30  const FcMatrix    FcIdentityMatrix = { 1, 0, 0, 1 };
      31  
      32  FcMatrix *
      33  FcMatrixCopy (const FcMatrix *mat)
      34  {
      35      FcMatrix *r;
      36      if(!mat)
      37  	return 0;
      38      r = (FcMatrix *) malloc (sizeof (*r) );
      39      if (!r)
      40  	return 0;
      41      *r = *mat;
      42      return r;
      43  }
      44  
      45  void
      46  FcMatrixFree (FcMatrix *mat)
      47  {
      48      if (mat != &FcIdentityMatrix)
      49  	free (mat);
      50  }
      51  
      52  FcBool
      53  FcMatrixEqual (const FcMatrix *mat1, const FcMatrix *mat2)
      54  {
      55      if(mat1 == mat2) return FcTrue;
      56      if(mat1 == 0 || mat2 == 0) return FcFalse;
      57      return mat1->xx == mat2->xx &&
      58  	   mat1->xy == mat2->xy &&
      59  	   mat1->yx == mat2->yx &&
      60  	   mat1->yy == mat2->yy;
      61  }
      62  
      63  void
      64  FcMatrixMultiply (FcMatrix *result, const FcMatrix *a, const FcMatrix *b)
      65  {
      66      FcMatrix	r;
      67  
      68      r.xx = a->xx * b->xx + a->xy * b->yx;
      69      r.xy = a->xx * b->xy + a->xy * b->yy;
      70      r.yx = a->yx * b->xx + a->yy * b->yx;
      71      r.yy = a->yx * b->xy + a->yy * b->yy;
      72      *result = r;
      73  }
      74  
      75  void
      76  FcMatrixRotate (FcMatrix *m, double c, double s)
      77  {
      78      FcMatrix	r;
      79  
      80      /*
      81       * X Coordinate system is upside down, swap to make
      82       * rotations counterclockwise
      83       */
      84      r.xx = c;
      85      r.xy = -s;
      86      r.yx = s;
      87      r.yy = c;
      88      FcMatrixMultiply (m, &r, m);
      89  }
      90  
      91  void
      92  FcMatrixScale (FcMatrix *m, double sx, double sy)
      93  {
      94      FcMatrix	r;
      95  
      96      r.xx = sx;
      97      r.xy = 0;
      98      r.yx = 0;
      99      r.yy = sy;
     100      FcMatrixMultiply (m, &r, m);
     101  }
     102  
     103  void
     104  FcMatrixShear (FcMatrix *m, double sh, double sv)
     105  {
     106      FcMatrix	r;
     107  
     108      r.xx = 1;
     109      r.xy = sh;
     110      r.yx = sv;
     111      r.yy = 1;
     112      FcMatrixMultiply (m, &r, m);
     113  }
     114  #define __fcmatrix__
     115  #include "fcaliastail.h"
     116  #undef __fcmatrix__