コード例 #1
0
/* Initialize a Type 1 interpreter. */
static int
type1_exec_init(gs_type1_state *pcis, gs_text_enum_t *penum,
                gs_state *pgs, gs_font_type1 *pfont1)
{
    /*
     * We have to disregard penum->pis and penum->path, and render to
     * the current gstate and path.  This is a design bug that we will
     * have to address someday!
     */

    int alpha_bits = 1;
    gs_log2_scale_point log2_subpixels;

    if (color_is_pure(gs_currentdevicecolor_inline(pgs))) /* Keep consistency with alpha_buffer_bits() */
        alpha_bits = (*dev_proc(pgs->device, get_alpha_bits)) (pgs->device, go_text);
    if (alpha_bits <= 1) {
        /* We render to cache device or the target device has no alpha bits. */
        log2_subpixels = penum->log2_scale;
    } else {
        /* We'll render to target device through alpha buffer. */
        /* Keep consistency with alpha_buffer_init() */
        log2_subpixels.x = log2_subpixels.y = ilog2(alpha_bits);
    }
    return gs_type1_interp_init(pcis, (gs_imager_state *)pgs, pgs->path,
                                &penum->log2_scale, &log2_subpixels,
                                (penum->text.operation & TEXT_DO_ANY_CHARPATH) != 0 ||
                                penum->device_disabled_grid_fitting,
                                pfont1->PaintType, pfont1);
}
コード例 #2
0
ファイル: gspaint.c プロジェクト: ststeiger/ghostsvg
/* 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);
}
コード例 #3
0
ファイル: pldraw.c プロジェクト: computersforpeace/ghostpdl
/* Begin an image with parameters derived from a graphics state. */
int
pl_begin_image(gs_state * pgs, const gs_image_t * pim, void **pinfo)
{
    gx_device *dev = pgs->device;

    if (pim->ImageMask | pim->CombineWithColor) {
        int code = gx_set_dev_color(pgs);

        if (code != 0)
            return code;
    }
    return (*dev_proc(dev, begin_image))
        (dev, (const gs_imager_state *)pgs, pim,
         gs_image_format_chunky, (const gs_int_rect *)0,
         gs_currentdevicecolor_inline(pgs), pgs->clip_path, pgs->memory,
         (gx_image_enum_common_t **) pinfo);
}
コード例 #4
0
ファイル: gspaint.c プロジェクト: computersforpeace/ghostpdl
/* Fill the page with the current color. */
int
gs_fillpage(gs_state * pgs)
{
    gx_device *dev = gs_currentdevice(pgs);
    int code;
    gx_cm_color_map_procs *   pprocs;

    pprocs = get_color_mapping_procs_subclass(dev);
    /* If we get here without a valid get_color_mapping_procs, fail */
    if (pprocs == NULL ||
        /* Deliberately use the terminal device here */
        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 */
    dev_proc(pgs->device, set_graphics_type_tag)(pgs->device, GS_PATH_TAG);

    code = gx_set_dev_color(pgs);
    if (code != 0)
        return code;

    code = (*dev_proc(dev, fillpage))(dev, (gs_imager_state *)pgs,
                                      gs_currentdevicecolor_inline(pgs));
    if (code < 0)
        return code;

    /* If GrayDetection is set, make sure monitoring is enabled. */
    if (dev->icc_struct != NULL &&
            dev->icc_struct->graydetection && !dev->icc_struct->pageneutralcolor) {
        dev->icc_struct->pageneutralcolor = true;	/* start detecting again */
        code = gsicc_mcm_begin_monitor(pgs->icc_link_cache, dev);
    }
    if (code < 0)
        return code;
    return (*dev_proc(dev, sync_output)) (dev);
}
コード例 #5
0
ファイル: gspaint.c プロジェクト: computersforpeace/ghostpdl
static int
do_stroke(gs_state * pgs)
{
    int code, abits, acode, rcode = 0;
    bool devn;

    /* 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))) {
        dev_proc(pgs->device, set_graphics_type_tag)(pgs->device, GS_PATH_TAG);
    }
    else {
        dev_proc(pgs->device, set_graphics_type_tag)(pgs->device, GS_TEXT_TAG);
    }
    code = gx_set_dev_color(pgs);
    if (code != 0)
        return code;
    code = gs_state_color_load(pgs);
    if (code < 0)
        return code;
    abits = 0;
    {
        gx_device_color *col = gs_currentdevicecolor_inline(pgs);
        devn = color_is_devn(col);
        if (color_is_pure(col) || devn)
            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, devn);
        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, false);
        gs_setlinewidth(pgs, orig_width);
        scale_dash_pattern(pgs, 1.0 / scale);
        if (code >= 0)
            code = gx_fill_path(&spath, gs_currentdevicecolor_inline(pgs), 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 && rcode < 0)
        code = rcode;
    return code;
}
コード例 #6
0
ファイル: gspaint.c プロジェクト: computersforpeace/ghostpdl
static int do_fill(gs_state *pgs, int rule)
{
    int code, abits, acode, rcode = 0;
    bool devn;

    /* 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))) {
        dev_proc(pgs->device, set_graphics_type_tag)(pgs->device, GS_PATH_TAG);
    }
    else {
        dev_proc(pgs->device, set_graphics_type_tag)(pgs->device, GS_TEXT_TAG);
    }
    code = gx_set_dev_color(pgs);
    if (code != 0)
        return code;
    code = gs_state_color_load(pgs);
    if (code < 0)
        return code;
    abits = 0;
    {
        gx_device_color *col = gs_currentdevicecolor_inline(pgs);
        devn = color_is_devn(col);
        if (color_is_pure(col) || devn)
            abits = alpha_buffer_bits(pgs);
    }
    if (abits > 1) {
        acode = alpha_buffer_init(pgs, pgs->fill_adjust.x,
                                  pgs->fill_adjust.y, abits, devn);
        if (acode < 0)
            return acode;
    } else
        acode = 0;
    code = gx_fill_path(pgs->path, gs_currentdevicecolor_inline(pgs), pgs, rule,
                        pgs->fill_adjust.x, pgs->fill_adjust.y);
    if (acode > 0)
        rcode = alpha_buffer_release(pgs, code >= 0);
    if (code >= 0 && rcode < 0)
        code = rcode;

    return code;
}
コード例 #7
0
ファイル: gsdps1.c プロジェクト: computersforpeace/ghostpdl
/* 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;
}
コード例 #8
0
ファイル: xpstile.c プロジェクト: computersforpeace/ghostpdl
int
xps_high_level_pattern(xps_context_t *ctx)
{
    gs_matrix m;
    gs_rect bbox;
    gs_fixed_rect clip_box;
    int code;
    gx_device_color *pdc = gs_currentdevicecolor_inline(ctx->pgs);
    const gs_client_pattern *ppat = gs_getpattern(&pdc->ccolor);
    gs_pattern1_instance_t *pinst =
        (gs_pattern1_instance_t *)gs_currentcolor(ctx->pgs)->pattern;

    code = gx_pattern_cache_add_dummy_entry((gs_imager_state *)ctx->pgs,
        pinst, ctx->pgs->device->color_info.depth);
    if (code < 0)
        return code;

    code = gs_gsave(ctx->pgs);
    if (code < 0)
        return code;

    dev_proc(ctx->pgs->device, get_initial_matrix)(ctx->pgs->device, &m);
    gs_setmatrix(ctx->pgs, &m);
    code = gs_bbox_transform(&ppat->BBox, &ctm_only(ctx->pgs), &bbox);
    if (code < 0) {
        gs_grestore(ctx->pgs);
        return code;
    }
    clip_box.p.x = float2fixed(bbox.p.x);
    clip_box.p.y = float2fixed(bbox.p.y);
    clip_box.q.x = float2fixed(bbox.q.x);
    clip_box.q.y = float2fixed(bbox.q.y);
    code = gx_clip_to_rectangle(ctx->pgs, &clip_box);
    if (code < 0) {
        gs_grestore(ctx->pgs);
        return code;
    }

    {
        pattern_accum_param_s param;
        param.pinst = (void *)pinst;
        param.graphics_state = (void *)ctx->pgs;
        param.pinst_id = pinst->id;

        code = (*dev_proc(ctx->pgs->device, dev_spec_op))((gx_device *)ctx->pgs->device,
            gxdso_pattern_start_accum, &param, sizeof(pattern_accum_param_s));
    }

    if (code < 0) {
        gs_grestore(ctx->pgs);
        return code;
    }

    code = xps_paint_tiling_brush(&pdc->ccolor, ctx->pgs);
    if (code) {
        gs_grestore(ctx->pgs);
        return gs_rethrow(code, "high level pattern brush function failed");
    }

    code = gs_grestore(ctx->pgs);
    if (code < 0)
        return code;

    {
        pattern_accum_param_s param;
        param.pinst = (void *)pinst;
        param.graphics_state = (void *)ctx->pgs;
        param.pinst_id = pinst->id;

        code = (*dev_proc(ctx->pgs->device, dev_spec_op))((gx_device *)ctx->pgs->device,
            gxdso_pattern_finish_accum, &param, sizeof(pattern_accum_param_s));
    }

    return code;
}