⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdeveprn.c

📁 openmeetings组件之GS openmeetings组件之GS openmeetings组件之GS
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************  File:     $Id: gdeveprn.c,v 1.25 2001/04/30 05:15:51 Martin Rel $  Contents: Implementation of the abstract ghostscript device 'eprn':            general functions and page layout  Author:   Martin Lottermoser, Greifswaldstrasse 28, 38124 Braunschweig,            Germany. E-mail: Martin.Lottermoser@t-online.de.********************************************************************************									      **	Copyright (C) 2000, 2001 by Martin Lottermoser			      **	All rights reserved						      **									      ********************************************************************************  Preprocessor variables:    EPRN_NO_PAGECOUNTFILE	Define this if you do not want to use eprn's pagecount-file feature.	You very likely must define this on Microsoft Windows.    EPRN_TRACE	Define this to enable tracing. Only useful for development.    EPRN_USE_GSTATE (integer)	Define this to be non-zero if the graphics state should be accessed	directly instead of via the interpreter context state. Newer ghostscript	versions require the latter path. The default is zero unless	GS_REVISION is defined and less than 600.    GS_REVISION (integer)	If defined, this must be the ghostscript version number, e.g., 601 for	ghostscript 6.01.******************************************************************************//* Configuration management identification */#ifndef lintstatic const char  cm_id[] = "@(#)$Id: gdeveprn.c,v 1.25 2001/04/30 05:15:51 Martin Rel $";#endif/*****************************************************************************/#ifndef _XOPEN_SOURCE#define _XOPEN_SOURCE	500#endif/* Preprocessor symbol with version-dependent default */#ifndef EPRN_USE_GSTATE#if !defined(GS_REVISION) || GS_REVISION >= 600#define EPRN_USE_GSTATE	0#else#define EPRN_USE_GSTATE	1#endif#endif	/* !EPRN_USE_GSTATE *//*****************************************************************************//* Special Aladdin header, must be included before <sys/types.h> on some   platforms (e.g., FreeBSD). */#include "std.h"/* Standard headers */#include <assert.h>#include <math.h>#include <string.h>#include <stdio.h>#include <stdlib.h>#ifdef EPRN_TRACE#include <time.h>#endif	/* EPRN_TRACE *//*  Ghostscript headers. With the exception of gdebug.h, these files are only    needed to compile eprn_forget_defaultmatrix() which needs the prototypes    for gs_setdefaultmatrix() (in gscoord.h) and gs_main_instance_default()    (in imain.h). Unfortunately and in disregard of good SE practice,    ghostscript's header files are not self-contained. Therefore, if this file    does not compile because of undefined symbols, just add include directives    until it does.  */#include "iref.h"	/* needed by icstate.h */#include "gsmemraw.h"	/* needed by icstate.h */#include "gsmemory.h"	/* needed by icstate.h */#include "gstypes.h"	/* needed by gsstate.h */#include "gsstate.h"	/* needed by icstate.h */#include "icstate.h"	/* for struct gs_context_state_s */#if !defined(GS_REVISION) || GS_REVISION >= 700#include "iapi.h"	/* needed by iminst.h */#endif	/* GS_REVISION */#include "iminst.h"	/* for struct gs_main_instance_s */#include "imain.h"	/* for gs_main_instance_default() */#include "gscoord.h"	/* for gs_setdefaultmatrix() */#if EPRN_USE_GSTATE#include "igstate.h"#endif	/* EPRN_USE_GSTATE */#ifdef EPRN_TRACE#include "gdebug.h"#endif	/* EPRN_TRACE */#include "gxstdio.h"/* Special headers for this device */#ifndef EPRN_NO_PAGECOUNTFILE#include "pagecount.h"#endif	/* EPRN_NO_PAGECOUNTFILE */#include "gdeveprn.h"/*****************************************************************************//* Prefix for error messages */#define ERRPREF "? eprn: "/******************************************************************************  Function: eprn_get_initial_matrix  This function returns the initial matrix for the device.  The result is based on the following parameters:  - eprn: default_orientation, down_shift, right_shift, soft_tumble  - HWResolution, MediaSize, ShowpageCount******************************************************************************/void eprn_get_initial_matrix(gx_device *device, gs_matrix *mptr){  eprn_Device *dev = (eprn_Device *)device;  float    /*  The following two arrays are oriented w.r.t. pixmap device space, i.e.,	the index 0 refers to the x coordinate (horizontal) and the index 1 to	the y coordinate (vertical) in pixmap device space. */    extension[2],	/* media extension in pixels */    pixels_per_bp[2];	/* resolution */  int    j,    quarters;#ifdef EPRN_TRACE  if_debug0(EPRN_TRACE_CHAR, "! eprn_get_initial_matrix()...\n");#endif  /* We need 'default_orientation' and also the margins. */  if (dev->eprn.code == ms_none) {#ifdef EPRN_TRACE    if_debug0(EPRN_TRACE_CHAR,      "! eprn_get_initial_matrix(): code is still ms_none.\n");#endif    if (eprn_set_page_layout(dev) != 0)      eprintf("  Processing can't be stopped at this point although this error "	"occurred.\n");      /* The current function has a signature without the ability to signal	 an error condition. */  }  quarters = dev->eprn.default_orientation +    (dev->MediaSize[0] <= dev->MediaSize[1]? 0: 1);     /* Number of quarter-circle rotations by +90 degrees necessary to obtain	default user space starting with the y axis upwards in pixmap device	space.	It's not documented, but 'MediaSize' is the requested "PageSize" page	device parameter value and hence is to be interpreted in default (not	default default!) user space. The condition above therefore tests	whether landscape orientation has been requested.      */  /* Soft tumble option: rotate default user space by 180 degrees on every     second page */  if (dev->eprn.soft_tumble && dev->ShowpageCount % 2 != 0) quarters += 2;  /* Prepare auxiliary data */  for (j = 0; j < 2; j++) pixels_per_bp[j] = dev->HWResolution[j]/BP_PER_IN;  /*  'HWResolution[]' contains the standard PostScript page device parameter      'HWResolution' which is defined in pixels per inch with respect to       device space. */  if (quarters % 2 == 0) {    /* Default user space and pixmap device space agree in what is "horizontal"       and what is "vertical". */    extension[0] = dev->MediaSize[0];    extension[1] = dev->MediaSize[1];  }  else {    extension[0] = dev->MediaSize[1];    extension[1] = dev->MediaSize[0];  }  /* Convert from bp to pixels: */  for (j = 0; j < 2; j++) extension[j] *= pixels_per_bp[j];   /* Note that we are using the user-specified extension of the sheet, not the      "official" one we could obtain in most cases from 'size'. */  switch (quarters % 4) {  case 0:    /*  The y axis of default user space points upwards in pixmap device space.	The CTM is uniquely characterized by the following mappings from	default user space to pixmap device space:	  (0, 0)		-> (0, height in pixels)	  (width in bp, 0)	-> (width in pixels, height in pixels)	  (0, height in bp)	-> (0, 0)	'width' and 'height' refer to the sheet's extension as seen from pixmap	device space, i.e., width in pixels == extension[0] and	height in pixels == extension[1].	From the PLR we find that the CTM is a PostScript matrix	[a b c d tx ty] used for mapping user space coordinates (x, y) to	device space coordinates (x', y') as follows:	  x' = a*x + c*y + tx	  y' = b*x + d*y + ty	Ghostscript's matrix type 'gs_matrix' writes its structure components	'xx' etc. in storage layout order into a PostScript matrix (see	write_matrix() in iutil.c), hence we obtain by comparison with	gsmatrix.h the PostScript matrix [ xx xy yx yy tx ty ].	The correspondence can also be seen by comparison of the equations	above with the code in gs_point_transform() in gsmatrix.c.	It would, however, still be reassuring to have a corresponding	statement in ghostscript's documentation.    */    gx_default_get_initial_matrix(device, mptr);    /*  Of course, I could also set this directly:	  mptr->xx = pixels_per_bp[0];	  mptr->xy = 0;	  mptr->yx = 0;	  mptr->yy = -pixels_per_bp[1];	  mptr->tx = 0;	  mptr->ty = extension[1];        Doing it in this way is, however, more stable against dramatic changes        in ghostscript.    */    break;  case 1:    /*  The y axis of default user space points to the left in pixmap device	space. The CTM is uniquely characterized by the following mappings from	default user space to pixmap device space:	  (0, 0)		-> (width in pixels, height in pixels)	  (height in bp, 0)	-> (width in pixels, 0)	  (0, width in bp)	-> (0, height in pixels)    */    mptr->xx = 0;    mptr->xy = -pixels_per_bp[1];    mptr->yx = -pixels_per_bp[0];    mptr->yy = 0;    mptr->tx = extension[0];    mptr->ty = extension[1];    break;  case 2:    /*  The y axis of default user space points downwards in pixmap device	space. The CTM is uniquely characterized by the following mappings from	default user space to pixmap device space:	  (0, 0)		-> (width in pixels, 0)	  (width in bp, 0)	-> (0, 0)	  (0, height in bp)	-> (width in pixels, height in pixels)    */    mptr->xx = -pixels_per_bp[0];    mptr->xy = 0;    mptr->yx = 0;    mptr->yy = pixels_per_bp[1];    mptr->tx = extension[0];    mptr->ty = 0;    break;  case 3:    /*  The y axis of default user space points to the right in pixmap device	space. The CTM is uniquely characterized by the following mappings from	default user space to pixmap device space:	  (0, 0)		-> (0, 0)	  (height in bp, 0)	-> (0, height in pixels)	  (0, width in bp)	-> (width in pixels, 0)    */    mptr->xx = 0;    mptr->xy = pixels_per_bp[1];    mptr->yx = pixels_per_bp[0];    mptr->yy = 0;    mptr->tx = 0;    mptr->ty = 0;    break;  }  /*  Finally, shift the device space origin to the top-left corner of the      printable area. I am deliberately not using the corresponding shift      feature in gx_device_set_margins() because it achieves its effect by      using the 'Margins' array which should remain at the user's disposal for      correcting misadjustments. In addition, gx_device_set_margins() will not      work correctly for quarters % 4 != 0 anyway.  */  {    gs_matrix translation;    /*	Translation of pixmap device space origin by top and left margins in	pixmap device space */    gs_make_translation(      -dev->eprn.right_shift*pixels_per_bp[0],      -dev->eprn.down_shift *pixels_per_bp[1],      &translation);    /* Multiply the initial matrix from the right with the translation matrix,       i.e., in going from user to device space the translation will be applied       last. */    gs_matrix_multiply(mptr, &translation, mptr);  }#ifdef EPRN_TRACE  if_debug6(EPRN_TRACE_CHAR, "  Returning [%g %g %g %g %g %g].\n",    mptr->xx, mptr->xy, mptr->yx, mptr->yy, mptr->tx, mptr->ty);#endif  return;}/******************************************************************************  Function: print_flags  Print a textual description of 'flags' to the error stream.******************************************************************************/static void print_flags(ms_MediaCode flags, const ms_Flag *user_flags){  /* Non-standard flags first */  if (user_flags != NULL) {    while (user_flags->code != ms_none) {      if (user_flags->code & flags) {	errprintf(user_flags->name);	flags &= ~user_flags->code;      }      user_flags++;    }  }  /* Standard substrings */  if (flags & MS_SMALL_FLAG) eprintf(MS_SMALL_STRING);  if (flags & MS_BIG_FLAG  ) eprintf(MS_BIG_STRING);  if (flags & MS_EXTRA_FLAG) eprintf(MS_EXTRA_STRING);  flags &= ~(MS_SMALL_FLAG | MS_BIG_FLAG | MS_EXTRA_FLAG);  /* Completeness check */  if (flags & ~MS_TRANSVERSE_FLAG)    eprintf1("0x%04X", (unsigned int)(flags & ~MS_TRANSVERSE_FLAG));  /* Standard qualifier */  if (flags & MS_TRANSVERSE_FLAG) eprintf("." MS_TRANSVERSE_STRING);  return;}/******************************************************************************  Function: eprn_flag_mismatch  This routine is called if the media size can be supported for some  combination of flags but not for that combination which has been requested.  The parameter 'no_match' indicates whether these flags are supported at all  for any of the supported sizes or not.  If the derived device has set a flag mismatch error reporting function, the  call will be passed to that function. Otherwise a general error message is  written through the graphics library's eprintf().******************************************************************************/static void eprn_flag_mismatch(const struct s_eprn_Device *eprn,  bool no_match){  if (eprn->fmr != NULL) (*eprn->fmr)(eprn, no_match);  else {    const char *epref = eprn->CUPS_messages? CUPS_ERRPREF: "";    eprintf2("%s" ERRPREF "The %s does not support ",      epref, eprn->cap->name);    if (eprn->desired_flags == 0) eprintf("an empty set of media flags");    else {      eprintf("the \"");      print_flags(eprn->desired_flags, eprn->flag_desc);      eprintf("\" flag(s)");    }    eprintf1("\n%s  (ignoring presence or absence of \"", epref);    {      ms_MediaCode optional = MS_TRANSVERSE_FLAG;      if (eprn->optional_flags != NULL) {	const ms_MediaCode *of = eprn->optional_flags;	while (*of != ms_none) optional |= *of++;      }      print_flags(optional, eprn->flag_desc);    }    eprintf("\") for ");    if (no_match) eprintf("any"); else eprintf("this");    eprintf(" page size.\n");  }  return;}/******************************************************************************  Function: better_flag_match  This function returns true iff the flags in 'new_code' match the requested  flags (strictly) better than those in 'old_code'.  ******************************************************************************/static bool better_flag_match(ms_MediaCode desired,  const ms_MediaCode *optional, ms_MediaCode old_code, ms_MediaCode new_code)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -