DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T g

⟦d261b1103⟧ TextFile

    Length: 4818 (0x12d2)
    Types: TextFile
    Names: »gscoord.c«

Derivation

└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89
    └─⟦ff23ba0e6⟧ »./ghostscript-1.3.tar.Z« 
        └─⟦a24a58cd3⟧ 
            └─⟦this⟧ »gscoord.c« 

TextFile

/* Copyright (C) 1989 Aladdin Enterprises.  All rights reserved.
   Distributed by Free Software Foundation, Inc.

This file is part of Ghostscript.

Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing.  Refer
to the Ghostscript General Public License for full details.

Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License.  A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities.  It should be in a file named COPYING.  Among other
things, the copyright notice and this notice must be preserved on all
copies.  */

/* gscoord.c */
/* Coordinate system operators for GhostScript library */
#include <math.h>
#include "gx.h"
#include "gserrors.h"
#include "gxfixed.h"
#include "gxmatrix.h"
#include "gzstate.h"
#include "gzdevice.h"			/* requires gsstate */
#include "gscoord.h"			/* requires gsmatrix, gsstate */

/* Macro for ensuring ctm_inverse is valid */
#ifdef DEBUG
#define print_inverse(pgs)\
if ( gs_debug['x'] )\
	printf("[x]Inverting:\n"), trace_ctm(pgs), trace_matrix(&pgs->ctm_inverse)
#else
#define print_inverse(pgs) 0
#endif
#define ensure_inverse_valid(pgs)\
	if ( !pgs->inverse_valid )\
	   {	int code = gs_matrix_invert(&pgs->ctm, &pgs->ctm_inverse);\
		print_inverse(pgs);\
		if ( code < 0 ) return code;\
		pgs->inverse_valid = 1;\
	   }

/* Macro for updating fixed version of ctm */
#define update_ctm(pgs)\
	pgs->ctm.tx_fixed = float2fixed(pgs->ctm.tx),\
	pgs->ctm.ty_fixed = float2fixed(pgs->ctm.ty),\
	pgs->inverse_valid = 0, pgs->char_tm_valid = 0

/* ------ Coordinate system definition ------ */

int
gs_initmatrix(gs_state *pgs)
{	ctm_only(pgs) = pgs->device->info->initial_matrix;
	update_ctm(pgs);
#ifdef DEBUG
if ( gs_debug['x'] )
	printf("[x]initmatrix:\n"), trace_ctm(pgs);
#endif
	return 0;
}

int
gs_defaultmatrix(gs_state *pgs, gs_matrix *pmat)
{	*pmat = pgs->device->info->initial_matrix;
	return 0;
}

int
gs_currentmatrix(gs_state *pgs, gs_matrix *pmat)
{	*pmat = ctm_only(pgs);
	return 0;
}

int
gs_setmatrix(gs_state *pgs, gs_matrix *pmat)
{	ctm_only(pgs) = *pmat;
	update_ctm(pgs);
#ifdef DEBUG
if ( gs_debug['x'] )
	printf("[x]setmatrix:\n"), trace_ctm(pgs);
#endif
	return 0;
}

int
gs_translate(gs_state *pgs, floatp dx, floatp dy)
{	gs_point pt;
	int code;
	if ( (code = gs_distance_transform((float)dx, (float)dy, &pgs->ctm, &pt)) < 0 )
		return code;
	pgs->ctm.tx += pt.x;
	pgs->ctm.ty += pt.y;
	update_ctm(pgs);
#ifdef DEBUG
if ( gs_debug['x'] )
	printf("[x]translate: %f %f -> %f %f\n",
		dx, dy, pt.x, pt.y),
	trace_ctm(pgs);
#endif
	return 0;
}

int
gs_scale(gs_state *pgs, floatp sx, floatp sy)
{	pgs->ctm.xx *= sx;
	pgs->ctm.xy *= sx;
	pgs->ctm.yx *= sy;
	pgs->ctm.yy *= sy;
	pgs->inverse_valid = 0, pgs->char_tm_valid = 0;
#ifdef DEBUG
if ( gs_debug['x'] )
	printf("[x]scale: %f %f\n", sx, sy), trace_ctm(pgs);
#endif
	return 0;
}

int
gs_rotate(gs_state *pgs, floatp ang)
{	int code = gs_matrix_rotate(&pgs->ctm, (float)ang, &pgs->ctm);
	pgs->inverse_valid = 0, pgs->char_tm_valid = 0;
#ifdef DEBUG
if ( gs_debug['x'] )
	printf("[x]rotate: %f\n", ang), trace_ctm(pgs);
#endif
	return code;
}

int
gs_concat(gs_state *pgs, gs_matrix *pmat)
{	int code = gs_matrix_multiply(pmat, &pgs->ctm, &pgs->ctm);
	update_ctm(pgs);
#ifdef DEBUG
if ( gs_debug['x'] )
	printf("[x]concat:\n"), trace_matrix(pmat), trace_ctm(pgs);
#endif
	return code;
}

/* ------ Coordinate transformation ------ */

int
gs_transform(gs_state *pgs, floatp x, floatp y, gs_point *pt)
{	return gs_point_transform((float)x, (float)y, &pgs->ctm, pt);
}

int
gs_dtransform(gs_state *pgs, floatp dx, floatp dy, gs_point *pt)
{	return gs_distance_transform((float)dx, (float)dy, &pgs->ctm, pt);
}

int
gs_itransform(gs_state *pgs, floatp x, floatp y, gs_point *pt)
{	ensure_inverse_valid(pgs);
	return gs_point_transform((float)x, (float)y, &pgs->ctm_inverse, pt);
}

int
gs_idtransform(gs_state *pgs, floatp dx, floatp dy, gs_point *pt)
{	ensure_inverse_valid(pgs);
	return gs_distance_transform((float)dx, (float)dy, &pgs->ctm_inverse, pt);
}

/* ------ Debugging printout ------ */

#ifdef DEBUG
/* Print a matrix */
private int
trace_ctm(gs_state *pgs)
{	gs_matrix_fixed *pmat = &pgs->ctm;
	trace_matrix((gs_matrix *)pmat);
	printf("\t\tt_fixed: [%6g %6g]\n",
		fixed2float(pmat->tx_fixed), fixed2float(pmat->ty_fixed));
}
private int
trace_matrix(register gs_matrix *pmat)
{	printf("\t[%6g %6g %6g %6g %6g %6g]\n",
		pmat->xx, pmat->xy, pmat->yx, pmat->yy, pmat->tx, pmat->ty);
}
#endif