int gs_lineto(gs_state *pgs, floatp x, floatp y) { int code; gs_fixed_point pt; if ( (code = gs_point_transform2fixed(&pgs->ctm, x, y, &pt)) >= 0 ) code = gx_path_add_line(pgs->path, pt.x, pt.y); return code; }
int gs_rlineto(gs_state *pgs, floatp x, floatp y) { gs_fixed_point cpt, dpt; int code = gx_path_current_point(pgs->path, &cpt); if ( code < 0 ) return code; if ( (code = gs_distance_transform2fixed(&pgs->ctm, x, y, &dpt)) >= 0 ) code = gx_path_add_line(pgs->path, cpt.x + dpt.x, cpt.y + dpt.y); return code; }
/* We know ppath != ppath_old. */ int gx_path_copy_reversed(const gx_path *ppath_old, gx_path *ppath, int init) { const subpath *psub = ppath_old->first_subpath; #ifdef DEBUG if ( gs_debug['p'] ) gx_dump_path(ppath_old, "before reversepath"); #endif if ( init ) gx_path_init(ppath, &ppath_old->memory_procs); nsp: while ( psub ) { const segment *pseg = psub->last; const segment *prev; int code = gx_path_add_point(ppath, pseg->pt.x, pseg->pt.y); if ( code < 0 ) { gx_path_release(ppath); return code; } for ( ; ; pseg = prev ) { prev = pseg->prev; switch ( pseg->type ) { case s_start: /* Finished subpath */ if ( psub->closed ) code = gx_path_close_subpath(ppath); psub = (const subpath *)psub->last->next; goto nsp; case s_curve: { const curve_segment *pc = (const curve_segment *)pseg; code = gx_path_add_curve(ppath, pc->p2.x, pc->p2.y, pc->p1.x, pc->p1.y, prev->pt.x, prev->pt.y); break; } case s_line: case s_line_close: code = gx_path_add_line(ppath, prev->pt.x, prev->pt.y); break; } if ( code ) { gx_path_release(ppath); return code; } } /* not reached */ } ppath->position = ppath_old->position; /* restore current point */ #ifdef DEBUG if ( gs_debug['p'] ) gx_dump_path(ppath, "after reversepath"); #endif return 0; }
static inline int gs_lineto_aux(gs_state * pgs, floatp x, floatp y) { gx_path *ppath = pgs->path; gs_fixed_point pt; int code; code = clamp_point_aux(pgs->clamp_coordinates, &pt, x, y); if (code < 0) return code; code = gx_path_add_line(ppath, pt.x, pt.y); if (code < 0) return code; gx_setcurrentpoint(pgs, x, y); return 0; }
/* relatives. */ int gx_path_add_char_path(gx_path * to_path, gx_path * from_path, gs_char_path_mode mode) { int code; gs_fixed_rect bbox; switch (mode) { default: /* shouldn't happen! */ gx_path_new(from_path); return 0; case cpm_charwidth: { gs_fixed_point cpt; code = gx_path_current_point(from_path, &cpt); if (code < 0) break; return gx_path_add_point(to_path, cpt.x, cpt.y); } case cpm_true_charpath: case cpm_false_charpath: return gx_path_add_path(to_path, from_path); case cpm_true_charboxpath: gx_path_bbox(from_path, &bbox); code = gx_path_add_rectangle(to_path, bbox.p.x, bbox.p.y, bbox.q.x, bbox.q.y); break; case cpm_false_charboxpath: gx_path_bbox(from_path, &bbox); code = gx_path_add_point(to_path, bbox.p.x, bbox.p.y); if (code >= 0) code = gx_path_add_line(to_path, bbox.q.x, bbox.q.y); break; } if (code < 0) return code; gx_path_new(from_path); return 0; }
/* Internal routine for adding an arc to the path. */ static int arc_add(const arc_curve_params_t * arc, bool is_quadrant) { gx_path *path = arc->ppath; gs_imager_state *pis = arc->pis; double x0 = arc->p0.x, y0 = arc->p0.y; double xt = arc->pt.x, yt = arc->pt.y; floatp fraction; gs_fixed_point p0, p2, p3, pt; int code; if ((arc->action != arc_nothing && #if !PRECISE_CURRENTPOINT (code = gs_point_transform2fixed(&pis->ctm, x0, y0, &p0)) < 0) || (code = gs_point_transform2fixed(&pis->ctm, xt, yt, &pt)) < 0 || (code = gs_point_transform2fixed(&pis->ctm, arc->p3.x, arc->p3.y, &p3)) < 0 #else (code = gs_point_transform2fixed_rounding(&pis->ctm, x0, y0, &p0)) < 0) || (code = gs_point_transform2fixed_rounding(&pis->ctm, xt, yt, &pt)) < 0 || (code = gs_point_transform2fixed_rounding(&pis->ctm, arc->p3.x, arc->p3.y, &p3)) < 0 #endif ) return code; #if PRECISE_CURRENTPOINT if (!path_position_valid(path)) gs_point_transform(arc->p0.x, arc->p0.y, &ctm_only(arc->pis), &pis->subpath_start); #endif code = (arc->action == arc_nothing ? (p0.x = path->position.x, p0.y = path->position.y, 0) : arc->action == arc_lineto && path_position_valid(path) ? gx_path_add_line(path, p0.x, p0.y) : /* action == arc_moveto, or lineto with no current point */ gx_path_add_point(path, p0.x, p0.y)); if (code < 0) return code; /* Compute the fraction coefficient for the curve. */ /* See gx_path_add_partial_arc for details. */ if (is_quadrant) { /* one of |dx| and |dy| is r, the other is zero */ fraction = quarter_arc_fraction; if (arc->fast_quadrant > 0) { /* * The CTM is well-behaved, and we have pre-calculated the delta * from the circumference points to the control points. */ fixed delta = arc->quadrant_delta; if (pt.x != p0.x) p0.x = (pt.x > p0.x ? p0.x + delta : p0.x - delta); if (pt.y != p0.y) p0.y = (pt.y > p0.y ? p0.y + delta : p0.y - delta); p2.x = (pt.x == p3.x ? p3.x : pt.x > p3.x ? p3.x + delta : p3.x - delta); p2.y = (pt.y == p3.y ? p3.y : pt.y > p3.y ? p3.y + delta : p3.y - delta); goto add; } } else { double r = arc->radius; floatp dx = xt - x0, dy = yt - y0; double dist = dx * dx + dy * dy; double r2 = r * r; if (dist >= r2 * 1.0e8) /* almost zero radius; */ /* the >= catches dist == r == 0 */ fraction = 0.0; else fraction = (4.0 / 3.0) / (1 + sqrt(1 + dist / r2)); } p0.x += (fixed)((pt.x - p0.x) * fraction); p0.y += (fixed)((pt.y - p0.y) * fraction); p2.x = p3.x + (fixed)((pt.x - p3.x) * fraction); p2.y = p3.y + (fixed)((pt.y - p3.y) * fraction); add: if_debug8('r', "[r]Arc f=%f p0=(%f,%f) pt=(%f,%f) p3=(%f,%f) action=%d\n", fraction, x0, y0, xt, yt, arc->p3.x, arc->p3.y, (int)arc->action); /* Open-code gx_path_add_partial_arc_notes */ return gx_path_add_curve_notes(path, p0.x, p0.y, p2.x, p2.y, p3.x, p3.y, arc->notes | sn_from_arc); }