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

📄 eprnparm.c

📁 openmeetings组件之GS openmeetings组件之GS openmeetings组件之GS
💻 C
📖 第 1 页 / 共 3 页
字号:
        set. If one drops the blank, it will be set, also if there are        additional directives after %n. In addition, Cygwin does not (as of	early 2001) set the %n variable if there is trailing white space in the	string scanned. I don't want to know what's going on there, I just 	foil these bugs by removing all trailing white space from the input	line which means I don't have to scan it afterwards.    */    if (s == NULL) s = strchr(buffer, '\0');    while (buffer < s && isspace(*(s-1))) s--;    *s = '\0';    /* Ignore blank and comment lines */    s = buffer;    while (isspace(*s)) s++;    if (*s == '\0' || *s == '#') continue;    /* Check for unit specification */    if (is_word(s, "unit")) {      char *unit_name = next_word(s);      if (unit_name != NULL) {	s = next_word(unit_name);	if (s == NULL) {	  if (is_word(unit_name, "in")) {	    conversion_factor = BP_PER_IN;	    continue;	  }	  if (is_word(unit_name, "mm")) {	    conversion_factor = BP_PER_MM;	    continue;	  }	}	/* If 's' is not NULL or the unit is not recognized, the error message	   will be generated when the attempt to read the whole line as a media	   specification will fail because there is no media size called	   "unit". */      }    }    /* Extend the list */    {      eprn_PageDescription *new_list;      new_list = (eprn_PageDescription *)	realloc(list, (read+1)*sizeof(eprn_PageDescription));      if (new_list == NULL) {	eprintf2("%s" ERRPREF	  "Memory allocation failure in eprn_read_media_data(): %s.\n",	  epref, strerror(errno));	cleanup();	return_error(gs_error_VMerror);      }      list = new_list;    }    /* Set 'current' on the new entry */    current = list + read;    /* Isolate and identify the media size name */    s = buffer;    while (isspace(*s)) s++;    t = s + 1;	/* we checked above that the line is not empty */    while (*t != '\0' && !isspace(*t)) t++;    if (*t != '\0') {      *t = '\0';      t++;    }    {      ms_MediaCode code = ms_find_code_from_name(s, eprn->flag_desc);      if (code == ms_none) {	eprintf5("%s" ERRPREF "Unknown media name (%s) in "	    "media configuration file\n%s  %s, line %d.\n",	  epref, s, epref, eprn->media_file, line);	cleanup();	return_error(gs_error_rangecheck);      }      if (code & MS_ROTATED_FLAG) {	eprintf5("%s" ERRPREF "Invalid substring \"" MS_ROTATED_STRING	    "\" in media name (%s)\n"	  "%s  in media configuration file %s, line %d.\n",	  epref, s, epref, eprn->media_file, line);	cleanup();	return_error(gs_error_rangecheck);      }      current->code = code;    }    /* Look for margins */    if (sscanf(t, "%g %g %g %g%n", &current->left,	  &current->bottom, &current->right, &current->top, &chars_read) != 4 ||	t[chars_read] != '\0') {      if (*t != '\0') *(t-1) = ' ';	/* remove NUL after media name */      eprintf5("%s" ERRPREF	"Syntax error in media configuration file %s, line %d:\n%s    %s\n",	epref, eprn->media_file, line, epref, buffer);      cleanup();      return_error(gs_error_rangecheck);    }    /* Check for sign */    if (current->left < 0 || current->bottom < 0 || current->right < 0 ||	current->top < 0) {      eprintf4("%s" ERRPREF	"Ghostscript does not support negative margins (line %d in the\n"	"%s  media configuration file %s).\n",	epref, line, epref, eprn->media_file);      cleanup();      return_error(gs_error_rangecheck);    }    read++;    /* Convert to bp */    current->left   *= conversion_factor;    current->bottom *= conversion_factor;    current->right  *= conversion_factor;    current->top    *= conversion_factor;    /* A margin for custom page sizes without the corresponding capability in       the printer is useless although it would not lead to a failure of eprn.       The user might not notice the reason without help, hence we check. */    if (ms_without_flags(current->code) == ms_CustomPageSize &&	eprn->cap->custom == NULL)      eprintf6("%s" WARNPREF "The media configuration file %s\n"	"%s    contains a custom page size entry in line %d, "	  "but custom page sizes\n"	"%s    are not supported by the %s.\n",	wpref, eprn->media_file, wpref, line, wpref, eprn->cap->name);  }  if (ferror(f)) {    eprintf2("%s" ERRPREF      "Unidentified system error while reading `%s'.\n",      epref, eprn->media_file);    cleanup();    return_error(gs_error_invalidfileaccess);  }  fclose(f);  /* Was the file empty? */  if (read == 0) {    eprintf3("%s" ERRPREF "The media configuration file %s\n"      "%s  does not contain any media information.\n",      epref, eprn->media_file, epref);    return_error(gs_error_rangecheck);  }  /* Create a list in the device structure */  eprn->media_overrides = (eprn_PageDescription *) gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), read + 1,    sizeof(eprn_PageDescription), "eprn_read_media_data");  if (eprn->media_overrides == NULL) {    eprintf1("%s" ERRPREF      "Memory allocation failure from gs_malloc() in eprn_read_media_data().\n",      epref);    free(list);    return_error(gs_error_VMerror);  }  /* Copy the list and set the sentinel entry */  memcpy(eprn->media_overrides, list, read*sizeof(eprn_PageDescription));  eprn->media_overrides[read].code = ms_none;  /* Cleanup */  free(list);  return 0;}#undef BUFFER_SIZE#undef cleanup/******************************************************************************  Function: eprn_set_media_data  This function sets the media size and margin information in an 'eprn' device  from the specified media configuration file.  The return code will be zero an success and a ghostscript error code  otherwise. In the latter case, an error message will have been issued.  The 'length' may be positive in which case it denotes the length of the  string 'media_file' or zero in which case the string is assumed to be  NUL-terminated.  A NULL value or an empty string for 'media_file' is permitted and removes  all previous media descriptions read from a media configuration file.******************************************************************************/int eprn_set_media_data(eprn_Device *dev, const char *media_file, size_t length){  eprn_Eprn *eprn = &dev->eprn;  const char *epref = eprn->CUPS_messages? CUPS_ERRPREF: "";  int rc = 0;  /* Any previous size determination is obsolete now */  eprn->code = ms_none;  /* Free old storage */  if (eprn->media_file != NULL) {    gs_free(gs_lib_ctx_get_non_gc_memory_t(), eprn->media_file, strlen(eprn->media_file) + 1,      sizeof(char), "eprn_set_media_data");    eprn->media_file = NULL;  }  if (eprn->media_overrides != NULL) {    int n = 0;    while (eprn->media_overrides[n].code != ms_none) n++;    gs_free(gs_lib_ctx_get_non_gc_memory_t(), eprn->media_overrides, n+1, sizeof(eprn_PageDescription),      "eprn_set_media_data");    eprn->media_overrides = NULL;  }  /* Set the file name length if not given */  if (media_file != NULL && length == 0) length = strlen(media_file);  /* Read media configuration file, unless the name is NULL or the empty     string */  if (media_file != NULL && length > 0) {    eprn->media_file = (char *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), length + 1, sizeof(char),      "eprn_set_media_data");    if (eprn->media_file == NULL) {      eprintf1("%s" ERRPREF	"Memory allocation failure from gs_malloc() in "	"eprn_set_media_data().\n",	epref);      rc = gs_error_VMerror;    }    else {      strncpy(eprn->media_file, media_file, length);      eprn->media_file[length] = '\0';      if ((rc = eprn_read_media_data(eprn)) != 0) {	gs_free(gs_lib_ctx_get_non_gc_memory_t(), eprn->media_file, length + 1, sizeof(char),	  "eprn_set_media_data");	eprn->media_file = NULL;      }    }  }  return rc;}/******************************************************************************  Function: eprn_bits_for_levels  This function returns the number of bits used to represent 'levels' intensity  levels. 'levels' must be <= (ULONG_MAX+1)/2.******************************************************************************/unsigned int eprn_bits_for_levels(unsigned int levels){  unsigned int bits = 0;  unsigned long n;  for (n = 1; n < levels; n *= 2) bits++;  return bits;}/******************************************************************************  Function: res_supported  'list' must either bei NULL (all resolutions are accepted) or point to a  list of resolutions terminated with a {0.0, 0.0} entry.******************************************************************************/static bool res_supported(const eprn_Resolution *list, float hres, float vres){  if (list == NULL) return true;  while (list->h > 0.0 && (list->h != hres || list->v != vres)) list++;  return list->h > 0.0;}/******************************************************************************  Function: levels_supported  'list' may not be NULL and must point to a {0,0}-terminated list of  supported ranges.******************************************************************************/static bool levels_supported(const eprn_IntensityLevels *list,  unsigned int levels){  while (list->from > 0 && (levels < list->from || list->to < levels)) list++;  return list->from > 0;}/******************************************************************************  Function: reslev_supported******************************************************************************/static int reslev_supported(const eprn_ResLev *entry, float hres, float vres,  unsigned int levels){  return res_supported(entry->resolutions, hres, vres) &&    levels_supported(entry->levels, levels);}/******************************************************************************  Function: eprn_check_colour_info  This function checks the arguments starting at 'model' whether they are  supported according to 'list'. This list must satisfy the constraints for  'colour_info' in 'eprn_PrinterDescription'.  The function returns zero if the values are supported and a non-zero value  if they are not.******************************************************************************/int eprn_check_colour_info(const eprn_ColourInfo *list,  eprn_ColourModel *model, float *hres, float *vres,  unsigned int *black_levels, unsigned int *non_black_levels){  const eprn_ColourInfo *entry;  /* Search for a match. Successful exits are in the middle of the loop. */  for (entry = list; entry->info[0] != NULL; entry++)    if (entry->colour_model == *model ||	entry->colour_model == eprn_DeviceCMYK &&	  *model == eprn_DeviceCMY_plus_K) {      const eprn_ResLev *rl;      unsigned int levels = (entry->colour_model == eprn_DeviceRGB ||	  entry->colour_model == eprn_DeviceCMY? *non_black_levels:	*black_levels);      for (rl = entry->info[0]; rl->levels != NULL; rl++)	if (reslev_supported(rl, *hres, *vres, levels)) {	  const eprn_ResLev *rl2 = NULL;	  /* Check on info[1] needed? */	  if (entry->colour_model == eprn_DeviceGray ||	      entry->colour_model == eprn_DeviceRGB ||	      entry->colour_model == eprn_DeviceCMY)	    return 0;	  /* CMY+K or CMYK process colour models */	  if (entry->info[1] != NULL) {	    for (rl2 = entry->info[1]; rl2->levels != NULL; rl2++)	      if (reslev_supported(rl2, *hres, *vres, *non_black_levels)) break;	  }	  if (entry->info[1] == NULL && *black_levels == *non_black_levels ||	      entry->info[1] != NULL && rl2->levels != NULL)	    return 0;	}    }  return -1;}  /******************************************************************************  Function: set_derived_colour_data  This routine determines and sets various derived values in the device  structure based on the number of black and non-black levels requested.  The values to be set are 'eprn.bits_per_colorant' and the fields 'depth',  'max_gray', 'max_color', 'dither_grays' and 'dither_colors' in the  'color_info' structure.  The parameters 'black_levels' and 'non_black_levels' must be in the range  0 to 256 without 1. At least one of the two must be positive.******************************************************************************/static void set_derived_colour_data(eprn_Device *dev){  eprn_Eprn *eprn = &dev->eprn;  unsigned int levels;  /* Choose equal number of bits in 'gx_color_index' for all components present   */  if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) levels = 256;  else if (eprn->black_levels >= eprn->non_black_levels)    levels = eprn->black_levels;  else levels = eprn->non_black_levels;  eprn->bits_per_colorant = eprn_bits_for_levels(levels);  /* For the depth, consider all components and adjust to possible values.     Ghostscript permits pixel depths 1, 2, 4, 8, 16, 24 and 32. */  dev->color_info.depth =    (eprn->non_black_levels == 0? 1: 4) * eprn->bits_per_colorant;      /* No distinction between non-Gray colour models */  if (dev->color_info.depth > 2) {    if (dev->color_info.depth <= 4) dev->color_info.depth = 4;    else if (dev->color_info.depth <= 8) dev->color_info.depth = 8;    else dev->color_info.depth = ((dev->color_info.depth + 7)/8)*8;      /* Next multiple of 8 */  }  /*  Set ghostscript's color_info data. This is an area where ghostscript's      documentation (Drivers.htm) is not particularly intelligible. For      example: can there be situations where the dither_* parameters are      different from their corresponding max_* parameter plus one?  */  if (eprn->intensity_rendering != eprn_IR_halftones) {    /*  Here we cover two cases: retaining as much colour information as	possible and effectively setting up 1-pixel halftone cells. Both	demand that ghostscript is prevented from doing halftoning; the	remaining difference (which is the essential part) is then handled in

⌨️ 快捷键说明

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