/* Copyright (C) 1997, 1998, 1999, 2000 artofcode LLC. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA, 02111-1307. */ /*$Id: gstrap.c,v 1.3.6.1.2.1 2003/01/17 00:49:03 giles Exp $ */ /* Setting trapping parameters and zones */ #include "string_.h" #include "gx.h" #include "gserrors.h" #include "gstrap.h" #include "gsparamx.h" /* Put a float parameter. */ private bool check_unit(float *pval) { return (*pval >= 0 && *pval <= 1); } private bool check_positive(float *pval) { return (*pval > 0); } private int trap_put_float_param(gs_param_list * plist, gs_param_name param_name, float *pval, bool(*check) (P1(float *pval)), int ecode) { int code; switch (code = param_read_float(plist, param_name, pval)) { case 0: if ((*check) (pval)) return 0; code = gs_error_rangecheck; default: ecode = code; param_signal_error(plist, param_name, ecode); break; case 1: break; } return ecode; } /* settrapparams */ int gs_settrapparams(gs_trap_params_t * pparams, gs_param_list * plist) { gs_trap_params_t params; int ecode = 0; static const char *const trap_placement_names[] = { gs_trap_placement_names, 0 }; params = *pparams; ecode = trap_put_float_param(plist, "BlackColorLimit", ¶ms.BlackColorLimit, check_unit, ecode); ecode = trap_put_float_param(plist, "BlackDensityLimit", ¶ms.BlackDensityLimit, check_positive, ecode); ecode = trap_put_float_param(plist, "BlackWidth", ¶ms.BlackWidth, check_positive, ecode); ecode = param_put_bool(plist, "Enabled", ¶ms.Enabled, ecode); ecode = param_put_bool(plist, "ImageInternalTrapping", ¶ms.ImageInternalTrapping, ecode); ecode = param_put_bool(plist, "ImagemaskTrapping", ¶ms.ImagemaskTrapping, ecode); ecode = param_put_int(plist, "ImageResolution", ¶ms.ImageResolution, ecode); if (params.ImageResolution <= 0) param_signal_error(plist, "ImageResolution", ecode = gs_error_rangecheck); ecode = param_put_bool(plist, "ImageToObjectTrapping", ¶ms.ImageToObjectTrapping, ecode); { int placement = params.ImageTrapPlacement; ecode = param_put_enum(plist, "ImageTrapPlacement", &placement, trap_placement_names, ecode); params.ImageTrapPlacement = placement; } ecode = trap_put_float_param(plist, "SlidingTrapLimit", ¶ms.SlidingTrapLimit, check_unit, ecode); ecode = trap_put_float_param(plist, "StepLimit", ¶ms.StepLimit, check_unit, ecode); ecode = trap_put_float_param(plist, "TrapColorScaling", ¶ms.TrapColorScaling, check_unit, ecode); ecode = trap_put_float_param(plist, "TrapWidth", ¶ms.TrapWidth, check_positive, ecode); if (ecode < 0) return ecode; *pparams = params; return 0; }