Esempio n. 1
0
/* Fill the page with the current color. */
int
gs_fillpage(gs_state * pgs)
{
    gx_device *dev = gs_currentdevice(pgs);
    int code;

    /* If we get here without a valid get_color_mapping_procs, fail */
    if (dev_proc(dev, get_color_mapping_procs) == NULL || 
        dev_proc(dev, get_color_mapping_procs) == gx_error_get_color_mapping_procs) {
	emprintf1(dev->memory,
                  "\n   *** Error: No get_color_mapping_procs for device: %s\n",
                  dev->dname);
	return_error(gs_error_Fatal);
    }
    /* Processing a fill object operation */
    gs_set_object_tag((gs_imager_state*) pgs, GS_PATH_TAG);

    gx_set_dev_color(pgs);

    code = (*dev_proc(dev, fillpage))(dev, (gs_imager_state *)pgs,
				      gs_currentdevicecolor_inline(pgs));
    if (code < 0)
	return code;
    return (*dev_proc(dev, sync_output)) (dev);
}
Esempio n. 2
0
/* Create an image enumerator given image parameters and a graphics state. */
int
gs_image_begin_typed(const gs_image_common_t * pic, gs_state * pgs,
		     bool uses_color, gx_image_enum_common_t ** ppie)
{
    gx_device *dev = gs_currentdevice(pgs);
    gx_clip_path *pcpath;
    int code = gx_effective_clip_path(pgs, &pcpath);
    gx_device *dev2 = dev;
    gx_device_color dc_temp, *pdevc = pgs->dev_color;

    if (code < 0)
	return code;
    /* Processing an image object operation */
    gs_set_object_tag(pgs, GS_IMAGE_TAG);

    if (uses_color) {
	gx_set_dev_color(pgs);
        code = gs_state_color_load(pgs);
        if (code < 0)
	    return code;
    }
    /* Imagemask with shading color needs a special optimization
       with converting the image into a clipping. 
       Check for such case after gs_state_color_load is done,
       because it can cause interpreter callout.
     */
    if (pic->type->begin_typed_image == &gx_begin_image1) {
	gs_image_t *image = (gs_image_t *)pic;

	if(image->ImageMask) {
	    code = gx_image_fill_masked_start(dev, pgs->dev_color, pcpath, pgs->memory, &dev2);
	    if (code < 0)
		return code;
	}
	if (dev2 != dev) {
	    set_nonclient_dev_color(&dc_temp, 1);
	    pdevc = &dc_temp;
	}
    }
    code = gx_device_begin_typed_image(dev2, (const gs_imager_state *)pgs,
		NULL, pic, NULL, pdevc, pcpath, pgs->memory, ppie);
    if (code < 0)
	return code;
    code = is_image_visible(pic, pgs, pcpath);
    if (code < 0)
	return code;
    if (!code)	
	(*ppie)->skipping = true;
    return 0;
}
Esempio n. 3
0
/* Stroke the current path */
int
gs_stroke(gs_state * pgs)
{
    int code;

    /*
     * If we're inside a charpath, just merge the current path
     * into the parent's path.
     */
    if (pgs->in_charpath) {
	if (pgs->in_charpath == cpm_true_charpath) {
	    /*
	     * A stroke inside a true charpath should do the
	     * equivalent of strokepath.
	     */
	    code = gs_strokepath(pgs);
	    if (code < 0)
		return code;
	}
	code = gx_path_add_char_path(pgs->show_gstate->path, pgs->path,
				     pgs->in_charpath);
    }
    if (gs_is_null_device(pgs->device)) {
	/* Handle separately to prevent gs_state_color_load. */
	gs_newpath(pgs);
	code = 0;
    } else {
	int abits, acode, rcode = 0;

        /* to distinguish text from vectors we hackly look at the
           target device 1 bit per component is a cache and this is
           text else it is a path */
        if (gx_device_has_color(gs_currentdevice(pgs)))
            gs_set_object_tag(pgs, GS_PATH_TAG);
        else
            gs_set_object_tag(pgs, GS_TEXT_TAG);

	/* Here we need to distinguish text from vectors to compute the object tag.
	   Actually we need to know whether this function is called to rasterize a character,
	   or to rasterize a vector graphics to the output device.
	   Currently we assume it works for the bitrgbtags device only,
	   which is a low level device with a 4-component color model.
	   We use the fact that with printers a character is usually being rendered 
	   to a 1bpp cache device rather than to the output device.
	   Therefore we hackly look whether the target device
	   "has a color" : either it's a multicomponent color model,
	   or it is not gray (such as a yellow separation).

	   This check has several limitations :
	   1. It doesn't work with -dNOCACHE.
	   2. It doesn't work with large characters,
	      which cannot fit into a cache cell and thus they
	      render directly to the output device.
	   3. It doesn't work for TextAlphaBits=2 or 4.
	      We don't care of this case because
	      text antialiasing usually usn't applied to printers.
	   4. It doesn't work for things like with "(xyz) true charpath stroke".
	      That's unfortunate, we'd like to improve someday.
	   5. It doesn't work for high level devices when a Type 3 character is being constructed.
	      This case is not important for low level devices
	      (which a printer is), because low level device doesn't accept
	      Type 3 charproc streams immediately.
	 */
        if (gx_device_has_color(gs_currentdevice(pgs))) {
            gs_set_object_tag(pgs, GS_PATH_TAG);
	}
	else {
            gs_set_object_tag(pgs, GS_TEXT_TAG);
	}
	gx_set_dev_color(pgs);
	code = gs_state_color_load(pgs);
	if (code < 0)
	    return code;
	abits = alpha_buffer_bits(pgs);
	if (abits > 1) {
	    /*
	     * Expand the bounding box by the line width.
	     * This is expensive to compute, so we only do it
	     * if we know we're going to buffer.
	     */
	    float xxyy = fabs(pgs->ctm.xx) + fabs(pgs->ctm.yy);
	    float xyyx = fabs(pgs->ctm.xy) + fabs(pgs->ctm.yx);
	    float scale = (float)(1 << (abits / 2));
	    float orig_width = gs_currentlinewidth(pgs);
	    float new_width = orig_width * scale;
	    fixed extra_adjust =
		float2fixed(max(xxyy, xyyx) * new_width / 2);
	    float orig_flatness = gs_currentflat(pgs);
	    gx_path spath;

	    /* Scale up the line width, dash pattern, and flatness. */
	    if (extra_adjust < fixed_1)
		extra_adjust = fixed_1;
	    acode = alpha_buffer_init(pgs,
				      pgs->fill_adjust.x + extra_adjust,
				      pgs->fill_adjust.y + extra_adjust,
				      abits);
	    if (acode < 0)
		return acode;
	    gs_setlinewidth(pgs, new_width);
	    scale_dash_pattern(pgs, scale);
	    gs_setflat(pgs, orig_flatness * scale);
	    /*
	     * The alpha-buffer device requires that we fill the
	     * entire path as a single unit.
	     */
	    gx_path_init_local(&spath, pgs->memory);
	    code = gx_stroke_add(pgs->path, &spath, pgs);
	    gs_setlinewidth(pgs, orig_width);
	    scale_dash_pattern(pgs, 1.0 / scale);
	    if (code >= 0)
		code = gx_fill_path(&spath, pgs->dev_color, pgs,
				    gx_rule_winding_number,
				    pgs->fill_adjust.x,
				    pgs->fill_adjust.y);
	    gs_setflat(pgs, orig_flatness);
	    gx_path_free(&spath, "gs_stroke");
	    if (acode > 0)
		rcode = alpha_buffer_release(pgs, code >= 0);
	} else
	    code = gx_stroke_fill(pgs->path, pgs);
	if (code >= 0)
	    gs_newpath(pgs);
	if (code >= 0 && rcode < 0)
	    code = rcode;
    }
    return code;
}
Esempio n. 4
0
/* Fill the current path using a specified rule. */
static int
fill_with_rule(gs_state * pgs, int rule)
{
    int code;

    /* If we're inside a charpath, just merge the current path */
    /* into the parent's path. */
    if (pgs->in_charpath)
	code = gx_path_add_char_path(pgs->show_gstate->path, pgs->path,
				     pgs->in_charpath);
    else if (gs_is_null_device(pgs->device)) {
	/* Handle separately to prevent gs_state_color_load - bug 688308. */
	gs_newpath(pgs);
	code = 0;
    } else {
	int abits, acode, rcode = 0;

	/* Here we need to distinguish text from vectors to compute the object tag.
	   Actually we need to know whether this function is called to rasterize a character,
	   or to rasterize a vector graphics to the output device.
	   Currently we assume it works for the bitrgbtags device only,
	   which is a low level device with a 4-component color model.
	   We use the fact that with printers a character is usually being rendered 
	   to a 1bpp cache device rather than to the output device.
	   Therefore we hackly look whether the target device
	   "has a color" : either it's a multicomponent color model,
	   or it is not gray (such as a yellow separation).

	   This check has several limitations :
	   1. It doesn't work with -dNOCACHE.
	   2. It doesn't work with large characters,
	      which cannot fit into a cache cell and thus they
	      render directly to the output device.
	   3. It doesn't work for TextAlphaBits=2 or 4.
	      We don't care of this case because
	      text antialiasing usually usn't applied to printers.
	   4. It doesn't work for things like with "(xyz) true charpath stroke".
	      That's unfortunate, we'd like to improve someday.
	   5. It doesn't work for high level devices when a Type 3 character is being constructed.
	      This case is not important for low level devices
	      (which a printer is), because low level device doesn't accept
	      Type 3 charproc streams immediately.
	   6. It doesn't work properly while an insiding testing,
	      which sets gs_hit_device, which is uncolored.
	 */
        if (gx_device_has_color(gs_currentdevice(pgs))) {
            gs_set_object_tag(pgs, GS_PATH_TAG);
	}
	else {
            gs_set_object_tag(pgs, GS_TEXT_TAG);
	}
	gx_set_dev_color(pgs);
	code = gs_state_color_load(pgs);
	if (code < 0)
	    return code;
	abits = alpha_buffer_bits(pgs);
	if (abits > 1) {
	    acode = alpha_buffer_init(pgs, pgs->fill_adjust.x,
				      pgs->fill_adjust.y, abits);
	    if (acode < 0)
		return acode;
	} else
	    acode = 0;
	code = gx_fill_path(pgs->path, pgs->dev_color, pgs, rule,
			    pgs->fill_adjust.x, pgs->fill_adjust.y);
	if (acode > 0)
	    rcode = alpha_buffer_release(pgs, code >= 0);
	if (code >= 0)
	    gs_newpath(pgs);
	if (code >= 0 && rcode < 0)
	    code = rcode;

    }
    return code;
}