1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
/* Copyright (C) 1989, 1992, 1994 Aladdin Enterprises. All rights reserved.
This file is part of GNU Ghostscript.
GNU 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 GNU Ghostscript General Public License for full details.
*/
/* gsline.c */
/* Line parameter operators for Ghostscript library */
#include "math_.h"
#include "memory_.h"
#include "gx.h"
#include "gserrors.h"
#include "gxfixed.h" /* ditto */
#include "gxmatrix.h" /* for gzstate */
#include "gzstate.h"
#include "gzline.h"
/* ------ Device-independent parameters ------ */
/* setlinewidth */
int
gs_setlinewidth(gs_state *pgs, floatp width)
{ pgs->line_params->width = width / 2;
return 0;
}
/* currentlinewidth */
float
gs_currentlinewidth(const gs_state *pgs)
{ return (float)(pgs->line_params->width * 2);
}
/* setlinecap */
int
gs_setlinecap(gs_state *pgs, gs_line_cap cap)
{ pgs->line_params->cap = cap;
return 0;
}
/* currentlinecap */
gs_line_cap
gs_currentlinecap(const gs_state *pgs)
{ return pgs->line_params->cap;
}
/* setlinejoin */
int
gs_setlinejoin(gs_state *pgs, gs_line_join join)
{ pgs->line_params->join = join;
return 0;
}
/* currentlinejoin */
gs_line_join
gs_currentlinejoin(const gs_state *pgs)
{ return pgs->line_params->join;
}
/* setmiterlimit */
int
gs_setmiterlimit(gs_state *pgs, floatp limit)
{ if ( limit < 1.0 ) return_error(gs_error_rangecheck);
pgs->line_params->miter_limit = limit;
/* The supplied miter limit is an upper bound on */
/* 1/sin(phi/2). We convert this to a lower bound on */
/* tan(phi). Note that if phi > pi/2, this is negative. */
/* We use the half-angle and angle-sum formulas here */
/* to avoid the trig functions.... */
{ double limit_sq = limit * limit;
/* We need a special check for phi/2 close to pi/4. */
/* Some C compilers can't handle the following as a */
/* conditional expression.... */
if ( limit_sq < 2.0001 && limit_sq > 1.9999 )
pgs->line_params->miter_check = 1.0e6;
else
pgs->line_params->miter_check =
sqrt(limit_sq - 1) * 2 / (limit_sq - 2);
}
return 0;
}
/* currentmiterlimit */
float
gs_currentmiterlimit(const gs_state *pgs)
{ return pgs->line_params->miter_limit;
}
/* setdash */
int
gs_setdash(gs_state *pgs, const float *pattern, uint length, floatp offset)
{ uint n = length;
const float *dfrom = pattern;
bool ink = true;
int index = 0;
float pattern_length = 0.0;
float dist_left;
gx_dash_params *dash = &pgs->line_params->dash;
float *ppat;
/* Check the dash pattern */
while ( n-- )
{ float elt = *dfrom++;
if ( elt < 0 )
return_error(gs_error_rangecheck);
pattern_length += elt;
}
if ( length == 0 ) /* empty pattern */
{ dist_left = 0.0;
ppat = 0;
}
else
{ if ( pattern_length == 0 )
return_error(gs_error_rangecheck);
/* Compute the initial index, ink_on, and distance left */
/* in the pattern, according to the offset. */
#define f_mod(a, b) ((a) - floor((a) / (b)) * (b))
if ( length & 1 )
{ /* Odd and even repetitions of the pattern */
/* have opposite ink values! */
float length2 = pattern_length * 2;
dist_left = f_mod(offset, length2);
if ( dist_left >= pattern_length )
dist_left -= pattern_length,
ink = !ink;
}
else
dist_left = f_mod(offset, pattern_length);
while ( (dist_left -= pattern[index]) >= 0 )
ink = !ink, index++;
ppat = (float *)gs_alloc_bytes(pgs->memory,
length * sizeof(float),
"dash pattern");
if ( ppat == 0 ) return_error(gs_error_VMerror);
memcpy(ppat, pattern, length * sizeof(float));
}
dash->pattern = ppat;
dash->pattern_size = length;
dash->offset = offset;
dash->init_ink_on = ink;
dash->init_index = index;
dash->init_dist_left = -dist_left;
return 0;
}
/* currentdash */
uint
gs_currentdash_length(const gs_state *pgs)
{ return pgs->line_params->dash.pattern_size;
}
const float *
gs_currentdash_pattern(const gs_state *pgs)
{ return pgs->line_params->dash.pattern;
}
float
gs_currentdash_offset(const gs_state *pgs)
{ return pgs->line_params->dash.offset;
}
/* Internal accessor for line parameters */
const gx_line_params *
gs_currentlineparams(const gs_state *pgs)
{ return pgs->line_params;
}
/* ------ Device-dependent parameters ------ */
/* setflat */
int
gs_setflat(gs_state *pgs, floatp flat)
{ if ( flat <= 0.2 ) flat = 0.2;
else if ( flat > 100 ) flat = 100;
pgs->flatness = flat;
return 0;
}
/* currentflat */
float
gs_currentflat(const gs_state *pgs)
{ return pgs->flatness;
}
/* setstrokeadjust */
int
gs_setstrokeadjust(gs_state *pgs, bool stroke_adjust)
{ pgs->stroke_adjust = stroke_adjust;
return 0;
}
/* currentstrokeadjust */
bool
gs_currentstrokeadjust(const gs_state *pgs)
{ return pgs->stroke_adjust;
}
|