Blame src/fcmatrix.c

Packit 352660
/*
Packit 352660
 * fontconfig/src/fcmatrix.c
Packit 352660
 *
Packit 352660
 * Copyright © 2000 Tuomas J. Lukka
Packit 352660
 *
Packit 352660
 * Permission to use, copy, modify, distribute, and sell this software and its
Packit 352660
 * documentation for any purpose is hereby granted without fee, provided that
Packit 352660
 * the above copyright notice appear in all copies and that both that
Packit 352660
 * copyright notice and this permission notice appear in supporting
Packit 352660
 * documentation, and that the name of Tuomas Lukka not be used in
Packit 352660
 * advertising or publicity pertaining to distribution of the software without
Packit 352660
 * specific, written prior permission.  Tuomas Lukka makes no
Packit 352660
 * representations about the suitability of this software for any purpose.  It
Packit 352660
 * is provided "as is" without express or implied warranty.
Packit 352660
 *
Packit 352660
 * TUOMAS LUKKA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
Packit 352660
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
Packit 352660
 * EVENT SHALL TUOMAS LUKKA BE LIABLE FOR ANY SPECIAL, INDIRECT OR
Packit 352660
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
Packit 352660
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
Packit 352660
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
Packit 352660
 * PERFORMANCE OF THIS SOFTWARE.
Packit 352660
 */
Packit 352660
Packit 352660
#include "fcint.h"
Packit 352660
#include <math.h>
Packit 352660
#include <stdlib.h>
Packit 352660
#include <ctype.h>
Packit 352660
Packit 352660
const FcMatrix    FcIdentityMatrix = { 1, 0, 0, 1 };
Packit 352660
Packit 352660
FcMatrix *
Packit 352660
FcMatrixCopy (const FcMatrix *mat)
Packit 352660
{
Packit 352660
    FcMatrix *r;
Packit 352660
    if(!mat)
Packit 352660
	return 0;
Packit 352660
    r = (FcMatrix *) malloc (sizeof (*r) );
Packit 352660
    if (!r)
Packit 352660
	return 0;
Packit 352660
    *r = *mat;
Packit 352660
    return r;
Packit 352660
}
Packit 352660
Packit 352660
void
Packit 352660
FcMatrixFree (FcMatrix *mat)
Packit 352660
{
Packit 352660
    if (mat != &FcIdentityMatrix)
Packit 352660
	free (mat);
Packit 352660
}
Packit 352660
Packit 352660
FcBool
Packit 352660
FcMatrixEqual (const FcMatrix *mat1, const FcMatrix *mat2)
Packit 352660
{
Packit 352660
    if(mat1 == mat2) return FcTrue;
Packit 352660
    if(mat1 == 0 || mat2 == 0) return FcFalse;
Packit 352660
    return mat1->xx == mat2->xx &&
Packit 352660
	   mat1->xy == mat2->xy &&
Packit 352660
	   mat1->yx == mat2->yx &&
Packit 352660
	   mat1->yy == mat2->yy;
Packit 352660
}
Packit 352660
Packit 352660
void
Packit 352660
FcMatrixMultiply (FcMatrix *result, const FcMatrix *a, const FcMatrix *b)
Packit 352660
{
Packit 352660
    FcMatrix	r;
Packit 352660
Packit 352660
    r.xx = a->xx * b->xx + a->xy * b->yx;
Packit 352660
    r.xy = a->xx * b->xy + a->xy * b->yy;
Packit 352660
    r.yx = a->yx * b->xx + a->yy * b->yx;
Packit 352660
    r.yy = a->yx * b->xy + a->yy * b->yy;
Packit 352660
    *result = r;
Packit 352660
}
Packit 352660
Packit 352660
void
Packit 352660
FcMatrixRotate (FcMatrix *m, double c, double s)
Packit 352660
{
Packit 352660
    FcMatrix	r;
Packit 352660
Packit 352660
    /*
Packit 352660
     * X Coordinate system is upside down, swap to make
Packit 352660
     * rotations counterclockwise
Packit 352660
     */
Packit 352660
    r.xx = c;
Packit 352660
    r.xy = -s;
Packit 352660
    r.yx = s;
Packit 352660
    r.yy = c;
Packit 352660
    FcMatrixMultiply (m, &r, m);
Packit 352660
}
Packit 352660
Packit 352660
void
Packit 352660
FcMatrixScale (FcMatrix *m, double sx, double sy)
Packit 352660
{
Packit 352660
    FcMatrix	r;
Packit 352660
Packit 352660
    r.xx = sx;
Packit 352660
    r.xy = 0;
Packit 352660
    r.yx = 0;
Packit 352660
    r.yy = sy;
Packit 352660
    FcMatrixMultiply (m, &r, m);
Packit 352660
}
Packit 352660
Packit 352660
void
Packit 352660
FcMatrixShear (FcMatrix *m, double sh, double sv)
Packit 352660
{
Packit 352660
    FcMatrix	r;
Packit 352660
Packit 352660
    r.xx = 1;
Packit 352660
    r.xy = sh;
Packit 352660
    r.yx = sv;
Packit 352660
    r.yy = 1;
Packit 352660
    FcMatrixMultiply (m, &r, m);
Packit 352660
}
Packit 352660
#define __fcmatrix__
Packit 352660
#include "fcaliastail.h"
Packit 352660
#undef __fcmatrix__