static int test2(gs_state * pgs, gs_memory_t * mem) { gs_client_color cc; gx_tile_bitmap tile; /*const */ byte tpdata[] = { /* Define a pattern that looks like this: ..xxxx .....x .....x ..xxxx .x.... x..... */ 0x3c, 0, 0, 0, 0x04, 0, 0, 0, 0x04, 0, 0, 0, 0x3c, 0, 0, 0, 0x40, 0, 0, 0, 0x80, 0, 0, 0 }; gs_newpath(pgs); gs_moveto(pgs, 100.0, 300.0); gs_lineto(pgs, 500.0, 500.0); gs_lineto(pgs, 200.0, 100.0); gs_lineto(pgs, 300.0, 500.0); gs_lineto(pgs, 500.0, 200.0); gs_closepath(pgs); gs_setrgbcolor(pgs, 0.0, 0.0, 0.0); gs_gsave(pgs); gs_fill(pgs); gs_grestore(pgs); tile.data = tpdata; tile.raster = 4; tile.size.x = tile.rep_width = 6; tile.size.y = tile.rep_height = 6; tile.id = gx_no_bitmap_id; gs_makebitmappattern(&cc, &tile, true, pgs, NULL); /* Note: color space is DeviceRGB */ cc.paint.values[0] = 0.0; cc.paint.values[1] = 1.0; cc.paint.values[2] = 1.0; gs_setpattern(pgs, &cc); gs_eofill(pgs); gs_makebitmappattern(&cc, &tile, false, pgs, NULL); gs_setcolor(pgs, &cc); gs_moveto(pgs, 50.0, 50.0); gs_lineto(pgs, 300.0, 50.0); gs_lineto(pgs, 50.0, 300.0); gs_closepath(pgs); gs_setrgbcolor(pgs, 1.0, 0.0, 0.0); gs_gsave(pgs); gs_fill(pgs); gs_grestore(pgs); gs_setpattern(pgs, &cc); gs_eofill(pgs); return 0; }
static int xps_true_callback_build_char(gs_show_enum *penum, gs_state *pgs, gs_font *pfont, gs_char chr, gs_glyph glyph) { gs_font_type42 *p42 = (gs_font_type42*)pfont; const gs_rect *pbbox; float sbw[4], w2[6]; gs_fixed_point saved_adjust; int code; // dprintf1("build char ttf %d\n", glyph); code = gs_type42_get_metrics(p42, glyph, sbw); if (code < 0) return code; w2[0] = sbw[2]; w2[1] = sbw[3]; pbbox = &p42->FontBBox; w2[2] = pbbox->p.x; w2[3] = pbbox->p.y; w2[4] = pbbox->q.x; w2[5] = pbbox->q.y; /* Expand the bbox when stroking */ if ( pfont->PaintType ) { float expand = max(1.415, gs_currentmiterlimit(pgs)) * gs_currentlinewidth(pgs) / 2; w2[2] -= expand, w2[3] -= expand; w2[4] += expand, w2[5] += expand; } if ( (code = gs_moveto(pgs, 0.0, 0.0)) < 0 ) return code; if ( (code = gs_setcachedevice(penum, pgs, w2)) < 0 ) return code; code = gs_type42_append(glyph, pgs, gx_current_path(pgs), (gs_text_enum_t*)penum, (gs_font*)p42, gs_show_in_charpath(penum) != cpm_show); if (code < 0) return code; /* Indicate that dropout prevention should be enabled by setting fill_adjust to the special value -1. */ saved_adjust = pgs->fill_adjust; pgs->fill_adjust.x = -1; pgs->fill_adjust.y = -1; code = (pfont->PaintType ? gs_stroke(pgs) : gs_fill(pgs)); if (code < 0) return code; pgs->fill_adjust = saved_adjust; return 0; }
static int test1(gs_state * pgs, gs_memory_t * mem) { int n; gs_scale(pgs, 72.0, 72.0); gs_translate(pgs, 4.25, 5.5); gs_scale(pgs, 4.0, 4.0); gs_newpath(pgs); for (n = 200; --n >= 0;) { int j; #define rf() (rand() / (1.0 * 0x10000 * 0x8000)) double r = rf(), g = rf(), b = rf(); double x0 = rf(), y0 = rf(), x1 = rf(), y1 = rf(), x2 = rf(), y2 = rf(); gs_setrgbcolor(pgs, r, g, b); for (j = 0; j < 6; j++) { gs_gsave(pgs); gs_rotate(pgs, 60.0 * j); gs_moveto(pgs, x0, y0); gs_lineto(pgs, x1, y1); gs_lineto(pgs, x2, y2); gs_fill(pgs); gs_grestore(pgs); } } #undef mem return 0; }
/* <userpath> ufill - */ static int zufill(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code = gs_gsave(igs); if (code < 0) return code; if ((code = upath_append(op, i_ctx_p, gs_currentcpsimode(imemory))) >= 0) code = gs_fill(igs); gs_grestore(igs); if (code < 0) return code; pop(1); return 0; }
/* We take the trouble to do this efficiently in the simple cases. */ int gs_rectfill(gs_state * pgs, const gs_rect * pr, uint count) { const gs_rect *rlist = pr; gx_clip_path *pcpath; uint rcount = count; int code; gx_device * pdev = pgs->device; gx_device_color *pdc = gs_currentdevicecolor_inline(pgs); const gs_imager_state *pis = (const gs_imager_state *)pgs; bool hl_color_available = gx_hld_is_hl_color_available(pis, pdc); bool hl_color = (hl_color_available && dev_proc(pdev, dev_spec_op)(pdev, gxdso_supports_hlcolor, NULL, 0)); bool center_of_pixel = (pgs->fill_adjust.x == 0 && pgs->fill_adjust.y == 0); /* Processing a fill object operation */ dev_proc(pgs->device, set_graphics_type_tag)(pgs->device, GS_PATH_TAG); code = gx_set_dev_color(pgs); if (code != 0) return code; if ((is_fzero2(pgs->ctm.xy, pgs->ctm.yx) || is_fzero2(pgs->ctm.xx, pgs->ctm.yy)) && gx_effective_clip_path(pgs, &pcpath) >= 0 && clip_list_is_rectangle(gx_cpath_list(pcpath)) && (hl_color || pdc->type == gx_dc_type_pure || pdc->type == gx_dc_type_ht_binary || pdc->type == gx_dc_type_ht_colored) && gs_state_color_load(pgs) >= 0 && (*dev_proc(pdev, get_alpha_bits)) (pdev, go_graphics) <= 1 && (!pgs->overprint || !pgs->effective_overprint_mode) ) { uint i; gs_fixed_rect clip_rect; gx_cpath_inner_box(pcpath, &clip_rect); /* We should never plot anything for an empty clip rectangle */ if ((clip_rect.p.x >= clip_rect.q.x) && (clip_rect.p.y >= clip_rect.q.y)) return 0; for (i = 0; i < count; ++i) { gs_fixed_point p, q; gs_fixed_rect draw_rect; if (gs_point_transform2fixed(&pgs->ctm, pr[i].p.x, pr[i].p.y, &p) < 0 || gs_point_transform2fixed(&pgs->ctm, pr[i].q.x, pr[i].q.y, &q) < 0 ) { /* Switch to the slow algorithm. */ goto slow; } draw_rect.p.x = min(p.x, q.x); draw_rect.p.y = min(p.y, q.y); draw_rect.q.x = max(p.x, q.x); draw_rect.q.y = max(p.y, q.y); if (hl_color) { rect_intersect(draw_rect, clip_rect); /* We do pass on 0 extant rectangles to high level devices. It isn't clear how a client and an output device should interact if one uses a center of pixel algorithm and the other uses any part of pixel. For now we punt and just pass the high level rectangle on without adjustment. */ if (draw_rect.p.x <= draw_rect.q.x && draw_rect.p.y <= draw_rect.q.y) { code = dev_proc(pdev, fill_rectangle_hl_color)(pdev, &draw_rect, pis, pdc, pcpath); if (code < 0) return code; } } else { int x, y, w, h; rect_intersect(draw_rect, clip_rect); if (center_of_pixel) { draw_rect.p.x = fixed_rounded(draw_rect.p.x); draw_rect.p.y = fixed_rounded(draw_rect.p.y); draw_rect.q.x = fixed_rounded(draw_rect.q.x); draw_rect.q.y = fixed_rounded(draw_rect.q.y); } else { /* any part of pixel rule - touched */ draw_rect.p.x = fixed_floor(draw_rect.p.x); draw_rect.p.y = fixed_floor(draw_rect.p.y); draw_rect.q.x = fixed_ceiling(draw_rect.q.x); draw_rect.q.y = fixed_ceiling(draw_rect.q.y); } x = fixed2int(draw_rect.p.x); y = fixed2int(draw_rect.p.y); w = fixed2int(draw_rect.q.x) - x; h = fixed2int(draw_rect.q.y) - y; /* clients that use the "any part of pixel" rule also fill 0 areas. This is true of current graphics library clients but not a general rule. */ if (!center_of_pixel) { if (w == 0) w = 1; /* yes Adobe Acrobat 8, seems to back up the y coordinate when the width is 0, sigh. */ if (h == 0) { y--; h = 1; } } if (gx_fill_rectangle(x, y, w, h, pdc, pgs) < 0) goto slow; } } return 0; slow:rlist = pr + i; rcount = count - i; } { bool do_save = !gx_path_is_null(pgs->path); if (do_save) { if ((code = gs_gsave(pgs)) < 0) return code; gs_newpath(pgs); } if ((code = gs_rectappend(pgs, rlist, rcount)) < 0 || (code = gs_fill(pgs)) < 0 ) DO_NOTHING; if (do_save) gs_grestore(pgs); else if (code < 0) gs_newpath(pgs); } return code; }
/* We take the trouble to do this efficiently in the simple cases. */ int gs_rectfill(gs_state * pgs, const gs_rect * pr, uint count) { const gs_rect *rlist = pr; gx_clip_path *pcpath; uint rcount = count; int code; gx_device * pdev = pgs->device; gx_device_color *pdc = pgs->dev_color; const gs_imager_state *pis = (const gs_imager_state *)pgs; bool hl_color_available = gx_hld_is_hl_color_available(pis, pdc); gs_fixed_rect empty = {{0, 0}, {0, 0}}; bool hl_color = (hl_color_available && dev_proc(pdev, fill_rectangle_hl_color)(pdev, &empty, pis, pdc, NULL) == 0); gx_set_dev_color(pgs); if ((is_fzero2(pgs->ctm.xy, pgs->ctm.yx) || is_fzero2(pgs->ctm.xx, pgs->ctm.yy)) && gx_effective_clip_path(pgs, &pcpath) >= 0 && clip_list_is_rectangle(gx_cpath_list(pcpath)) && (hl_color || pdc->type == gx_dc_type_pure || pdc->type == gx_dc_type_ht_binary || pdc->type == gx_dc_type_ht_colored /* DeviceN todo: add wts case */) && gs_state_color_load(pgs) >= 0 && (*dev_proc(pdev, get_alpha_bits)) (pdev, go_graphics) <= 1 && (!pgs->overprint || !pgs->effective_overprint_mode) ) { uint i; gs_fixed_rect clip_rect; gx_cpath_inner_box(pcpath, &clip_rect); for (i = 0; i < count; ++i) { gs_fixed_point p, q; gs_fixed_rect draw_rect; if (gs_point_transform2fixed(&pgs->ctm, pr[i].p.x, pr[i].p.y, &p) < 0 || gs_point_transform2fixed(&pgs->ctm, pr[i].q.x, pr[i].q.y, &q) < 0 ) { /* Switch to the slow algorithm. */ goto slow; } draw_rect.p.x = min(p.x, q.x); draw_rect.p.y = min(p.y, q.y); draw_rect.q.x = max(p.x, q.x); draw_rect.q.y = max(p.y, q.y); if (hl_color) { rect_intersect(draw_rect, clip_rect); if (draw_rect.p.x < draw_rect.q.x && draw_rect.p.y < draw_rect.q.y) { code = dev_proc(pdev, fill_rectangle_hl_color)(pdev, &draw_rect, pis, pdc, pcpath); if (code < 0) return code; } } else { int x, y, w, h; draw_rect.p.x -= pgs->fill_adjust.x; draw_rect.p.y -= pgs->fill_adjust.x; draw_rect.q.x += pgs->fill_adjust.x; draw_rect.q.y += pgs->fill_adjust.x; rect_intersect(draw_rect, clip_rect); x = fixed2int_pixround(draw_rect.p.x); y = fixed2int_pixround(draw_rect.p.y); w = fixed2int_pixround(draw_rect.q.x) - x; h = fixed2int_pixround(draw_rect.q.y) - y; if (w > 0 && h > 0) if (gx_fill_rectangle(x, y, w, h, pdc, pgs) < 0) goto slow; } } return 0; slow:rlist = pr + i; rcount = count - i; } { bool do_save = !gx_path_is_null(pgs->path); if (do_save) { if ((code = gs_gsave(pgs)) < 0) return code; gs_newpath(pgs); } if ((code = gs_rectappend(pgs, rlist, rcount)) < 0 || (code = gs_fill(pgs)) < 0 ) DO_NOTHING; if (do_save) gs_grestore(pgs); else if (code < 0) gs_newpath(pgs); } return code; }