/* Draw a one-pixel-wide line. */ int gz_draw_line_fixed(fixed ixf, fixed iyf, fixed itoxf, fixed itoyf, const gx_device_color *pdevc, gs_state *pgs) { int ix = fixed2int_var(ixf); int iy = fixed2int_var(iyf); int itox = fixed2int_var(itoxf); int itoy = fixed2int_var(itoyf); gx_device *dev; gp_check_interrupts(); if ( itoy == iy ) /* horizontal line */ { return (ix <= itox ? gz_fill_rectangle(ix, iy, itox - ix + 1, 1, pdevc, pgs) : gz_fill_rectangle(itox, iy, ix - itox + 1, 1, pdevc, pgs) ); } if ( itox == ix ) /* vertical line */ { return (iy <= itoy ? gz_fill_rectangle(ix, iy, 1, itoy - iy + 1, pdevc, pgs) : gz_fill_rectangle(ix, itoy, 1, iy - itoy + 1, pdevc, pgs) ); } if ( color_is_pure(pdevc) && (dev = pgs->device->info, (*dev->procs->draw_line)(dev, ix, iy, itox, itoy, pdevc->color1)) >= 0 ) return 0; { fixed h = itoyf - iyf; fixed w = itoxf - ixf; fixed tf; #define fswap(a, b) tf = a, a = b, b = tf if ( (w < 0 ? -w : w) <= (h < 0 ? -h : h) ) { if ( h < 0 ) fswap(ixf, itoxf), fswap(iyf, itoyf), h = -h; return gz_fill_trapezoid_fixed(ixf - fixed_half, fixed_1, iyf, itoxf - fixed_half, fixed_1, h, 0, pdevc, pgs); } else { if ( w < 0 ) fswap(ixf, itoxf), fswap(iyf, itoyf), w = -w; return gz_fill_trapezoid_fixed(iyf - fixed_half, fixed_1, ixf, itoyf - fixed_half, fixed_1, w, 1, pdevc, pgs); } #undef fswap } }
/* Draw a one-pixel-wide line. */ int gz_draw_line_fixed(fixed ixf, fixed iyf, fixed itoxf, fixed itoyf, gx_device_color *pdevc, gs_state *pgs) { int ix = fixed2int(ixf); int iy = fixed2int(iyf); int itox = fixed2int(itoxf); int itoy = fixed2int(itoyf); if ( itoy == iy ) /* horizontal line */ { if ( ix <= itox ) gz_fill_rectangle(ix, iy, fixed2int_ceiling(itoxf) - ix, 1, pdevc, pgs); else gz_fill_rectangle(itox, iy, fixed2int_ceiling(ixf) - itox, 1, pdevc, pgs); } else { gx_device *dev = pgs->device->info; fixed h, w, tf; #define fswap(a, b) tf = a, a = b, b = tf if ( color_is_pure(pdevc) && (*dev->procs->draw_line)(dev, ix, iy, itox, itoy, pdevc->color1) >= 0 ) return 0; h = itoyf - iyf; w = itoxf - ixf; #define fixed_eps (fixed)1 if ( (w < 0 ? -w : w) <= (h < 0 ? -h : h) ) { if ( h < 0 ) fswap(ixf, itoxf), fswap(iyf, itoyf), h = -h; gz_fill_trapezoid_fixed(ixf, fixed_eps, iyf, itoxf, fixed_eps, h, 0, pdevc, pgs); } else { if ( w < 0 ) fswap(ixf, itoxf), fswap(iyf, itoyf), w = -w; gz_fill_trapezoid_fixed(iyf, fixed_eps, ixf, itoyf, fixed_eps, w, 1, pdevc, pgs); } #undef fixed_eps #undef fswap } return 0; }
/* We should swap axes to get best accuracy, but we don't. */ int gz_fill_pgram_fixed(fixed px, fixed py, fixed ax, fixed ay, fixed bx, fixed by, const gx_device_color *pdevc, gs_state *pgs) { fixed t; fixed qx, dx, wx, pax, qax; int code; #define swap(r, s) (t = r, r = s, s = t) /* Reorder the points so that 0 <= ay <= by. */ if ( ay < 0 ) px += ax, py += ay, ax = -ax, ay = -ay; if ( by < 0 ) px += bx, py += by, bx = -bx, by = -by; if ( ay > by ) swap(ax, bx), swap(ay, by); if ( by == 0 ) return 0; /* degenerate (line) */ qx = px + ax + bx; /* Compute the distance from p to the point on the line (p, p+b) */ /* whose Y coordinate is equal to ay. */ dx = (fixed)((double)bx * ay / by); if ( dx < ax ) pax = px + dx, qax = qx - ax, wx = ax - dx; else pax = px + ax, qax = qx - dx, wx = dx - ax; if ( ay >= fixed_1 || fixed_rounded(py) != fixed_rounded(py + ay) ) { code = gz_fill_trapezoid_fixed(px, fixed_0, py, pax, wx, ay, 0, pdevc, pgs); if ( code < 0 ) return code; } code = gz_fill_trapezoid_fixed(pax, wx, py + ay, qax, wx, by - ay, 0, pdevc, pgs); if ( code < 0 ) return code; py += by; if ( ay >= fixed_1 || fixed_rounded(py) != fixed_rounded(py + ay) ) return gz_fill_trapezoid_fixed(qax, wx, py, qx, fixed_0, ay, 0, pdevc, pgs); #undef swap return 0; }