예제 #1
0
int
pxSetPageScale(px_args_t *par, px_state_t *pxs)
{	
    int code;
    real sx = 1;
    real sy = 1;
    static const real units_conversion_table[3][3] = {
        { 1, 25.4, 254 },     /* in -> in, mill, 1/10 mill */
        { 0.0394, 1, 10 },    /* mill -> in, mill, 1/10 mill */
        { 0.00394, .1, 1 }    /* 1/10 mill -> in, mill, 1/10 mill */ 
    };

    /* measuure and units of measure.  Actually session user units
       divided by new user unit, bizarre. */
    if ( par->pv[1] && par->pv[2] ) {
        /* new user measure */
        real nux = real_value(par->pv[2], 0);
        real nuy = real_value(par->pv[2], 1);
        if ( nux != 0 && nuy != 0 ) {
            /* new measure */
            pxeMeasure_t mt = par->pv[1]->value.i;
            /* convert to session units */
            real factor = units_conversion_table[pxs->measure][mt];
            real sux = nux * factor;
            real suy = nuy * factor;
            sx = pxs->units_per_measure.x / sux;
            sy = pxs->units_per_measure.y / suy;
            /* check for overflow.  NB we should do a better job here */
            if ( fabs(sx) > 1000.0 ) {
                dprintf2("warning probable overflow avoided for scaling factors %f %f\n", 
			 sx, sy );
                sx = sy = 1;
            }
        }
    } else if ( par->pv[0] ) { /* page scale */
        sx = real_value(par->pv[0], 0);
        sy = real_value(par->pv[0], 1);
    }
    code = gs_scale(pxs->pgs, sx, sy);
    if ( code < 0 )
        return code;
    /* Post-multiply the text CTM by the scale matrix. */
    { 
        gs_matrix smat;
        px_gstate_t *pxgs = pxs->pxgs;
        gs_make_scaling(sx, sy, &smat);
        gs_matrix_multiply(&pxgs->text_ctm, &smat, &pxgs->text_ctm);
    }
    return 0;
}
예제 #2
0
RELOC_PTRS_END

static int
is_image_visible(const gs_image_common_t * pic, gs_state * pgs, gx_clip_path *pcpath)
{
    /* HACK : We need the source image size here, 
       but gs_image_common_t doesn't pass it.
       We would like to move Width, Height to gs_image_common,
       but gs_image2_t appears to have those fields of double type.
     */
    if (pic->type->begin_typed_image == gx_begin_image1) {
	gs_image1_t *pim = (gs_image1_t *) pic;
	gs_rect image_rect = {{0, 0}, {0, 0}};
	gs_rect device_rect;
	gs_int_rect device_int_rect;
	gs_matrix mat;
	int code;

	image_rect.q.x = pim->Width;
	image_rect.q.y = pim->Height;
	if (pic->ImageMatrix.xx == ctm_only(pgs).xx &&
            pic->ImageMatrix.xy == ctm_only(pgs).xy &&
            pic->ImageMatrix.yx == ctm_only(pgs).yx &&
            pic->ImageMatrix.yy == ctm_only(pgs).yy) {
            /* Handle common special case separately to accept singular matrix */
            mat.xx = mat.yy = 1.;
            mat.yx = mat.xy = 0.;
            mat.tx = ctm_only(pgs).tx - pic->ImageMatrix.tx;
            mat.ty = ctm_only(pgs).ty - pic->ImageMatrix.ty;
        } else {
	code = gs_matrix_invert(&pic->ImageMatrix, &mat);
	if (code < 0)
	    return code;
	code = gs_matrix_multiply(&mat, &ctm_only(pgs), &mat);
	if (code < 0)
	    return code;
        }
	code = gs_bbox_transform(&image_rect, &mat, &device_rect);
	if (code < 0)
	    return code;
	device_int_rect.p.x = (int)floor(device_rect.p.x);
	device_int_rect.p.y = (int)floor(device_rect.p.y);
	device_int_rect.q.x = (int)ceil(device_rect.q.x);
	device_int_rect.q.y = (int)ceil(device_rect.q.y);
	if (!gx_cpath_rect_visible(pcpath, &device_int_rect))
	    return 0;
    }
    return 1;
}
예제 #3
0
int
gs_concat(gs_state * pgs, const gs_matrix * pmat)
{
    gs_matrix cmat;
    int code = gs_matrix_multiply(pmat, &ctm_only(pgs), &cmat);

    if (code < 0)
        return code;
    update_ctm(pgs, cmat.tx, cmat.ty);
    set_ctm_only(pgs, cmat);
#ifdef DEBUG
    if (gs_debug_c('x'))
        dlprintf("[x]concat:\n"), trace_matrix(pmat), trace_ctm(pgs);
#endif
    return code;
}
예제 #4
0
파일: pxvendor.c 프로젝트: hackqiang/gs
static int
vu_begin_image(px_state_t * pxs)
{
    px_vendor_state_t *v_state = pxs->vendor_state;
    gs_image_t image = v_state->image;
    px_bitmap_params_t params;
    gs_point origin;
    int code;

    if (v_state->color_space == eGraySub)
	params.color_space = eGray;
    else
	params.color_space = eSRGB;
    params.width = params.dest_width = v_state->SourceWidth;
    params.height = params.dest_height = v_state->BlockHeight;
    params.depth = 8;
    params.indexed = false;
    code = px_image_color_space(&image, &params,
				(const gs_string *)&pxs->pxgs->palette,
				pxs->pgs);
    if (code < 0) {
	return code;
    }

    /* Set up the image parameters. */
    if (gs_currentpoint(pxs->pgs, &origin) < 0)
	return_error(errorCurrentCursorUndefined);
    image.Width = v_state->SourceWidth;
    image.Height = v_state->BlockHeight;
    {
	gs_matrix imat, dmat;

	gs_make_scaling(image.Width, image.Height, &imat);
	gs_make_translation(origin.x, origin.y + v_state->StartLine, &dmat);
	gs_matrix_scale(&dmat, image.Width, image.Height, &dmat);
	/* The ImageMatrix is dmat' * imat. */
	gs_matrix_invert(&dmat, &dmat);
	gs_matrix_multiply(&dmat, &imat, &image.ImageMatrix);
    }
    image.CombineWithColor = true;
    image.Interpolate = pxs->interpolate;
    code = pl_begin_image(pxs->pgs, &image, &v_state->info);
    if (code < 0)
	return code;
    return 0;
}
예제 #5
0
/* Note that this may be based on a font other than the current font. */
int
gs_setcharmatrix(gs_state * pgs, const gs_matrix * pmat)
{
    gs_matrix cmat;
    int code = gs_matrix_multiply(pmat, &ctm_only(pgs), &cmat);

    if (code < 0)
        return code;
    update_matrix_fixed(pgs->char_tm, cmat.tx, cmat.ty);
    char_tm_only(pgs) = cmat;
#ifdef DEBUG
    if (gs_debug_c('x'))
        dlprintf("[x]setting char_tm:"), trace_matrix_fixed(&pgs->char_tm);
#endif
    pgs->char_tm_valid = true;
    return 0;
}
예제 #6
0
/* <matrix1> <matrix2> <matrix> concatmatrix <matrix> */
static int
zconcatmatrix(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    gs_matrix m1, m2, mp;
    int code;

    if ((code = read_matrix(imemory, op - 2, &m1)) < 0 ||
        (code = read_matrix(imemory, op - 1, &m2)) < 0 ||
        (code = gs_matrix_multiply(&m1, &m2, &mp)) < 0 ||
        (code = write_matrix(op, &mp)) < 0
        )
        return code;
    op[-2] = *op;
    pop(2);
    return code;
}
예제 #7
0
int
pxSetPageRotation(px_args_t *par, px_state_t *pxs)
{	/* Since the Y coordinate of user space is inverted, */
	/* we must negate rotation angles. */
	real angle = -real_value(par->pv[0], 0);
	int code = gs_rotate(pxs->pgs, angle);

	if ( code < 0 )
	  return code;
	/* Post-multiply the text CTM by the rotation matrix. */
	{ gs_matrix rmat;
	  px_gstate_t *pxgs = pxs->pxgs;

	  gs_make_rotation(angle, &rmat);
	  gs_matrix_multiply(&pxgs->text_ctm, &rmat, &pxgs->text_ctm);
	}
	return 0;
}
예제 #8
0
static int
bbox_image_begin(const gs_imager_state * pis, const gs_matrix * pmat,
		 const gs_image_common_t * pic, const gs_int_rect * prect,
		 const gx_clip_path * pcpath, gs_memory_t * memory,
		 bbox_image_enum ** ppbe)
{
    int code;
    gs_matrix mat;
    bbox_image_enum *pbe;

    if (pmat == 0)
	pmat = &ctm_only(pis);
    if ((code = gs_matrix_invert(&pic->ImageMatrix, &mat)) < 0 ||
	(code = gs_matrix_multiply(&mat, pmat, &mat)) < 0
	)
	return code;
    pbe = gs_alloc_struct(memory, bbox_image_enum, &st_bbox_image_enum,
			  "bbox_image_begin");
    if (pbe == 0)
	return_error(gs_error_VMerror);
    pbe->memory = memory;
    pbe->matrix = mat;
    pbe->pcpath = pcpath;
    pbe->target_info = 0;	/* in case no target */
    pbe->params_are_const = false;	/* check the first time */
    if (prect) {
	pbe->x0 = prect->p.x, pbe->x1 = prect->q.x;
	pbe->y = prect->p.y, pbe->height = prect->q.y - prect->p.y;
    } else {
	gs_int_point size;
	int code = (*pic->type->source_size) (pis, pic, &size);

	if (code < 0) {
	    gs_free_object(memory, pbe, "bbox_image_begin");
	    return code;
	}
	pbe->x0 = 0, pbe->x1 = size.x;
	pbe->y = 0, pbe->height = size.y;
    }
    *ppbe = pbe;
    return 0;
}
예제 #9
0
/*
 * Form the transformation matrix required to render a pattern.
 */
  void
pcl_xfm_get_pat_xfm(
    const pcl_state_t *     pcs,
    pcl_pattern_t *         pptrn,
    gs_matrix *             pmat
)
{
    const pcl_xfm_state_t * pxfmst = &(pcs->xfm_state);
    int                     rot = (pcs->pat_orient - pxfmst->lp_orient) & 0x3;

    *pmat = pxfmst->lp2dev_mtx;
    pmat->tx = pcs->pat_ref_pt.x;
    pmat->ty = pcs->pat_ref_pt.y;

    /* record the referenc point used in the rendering structure */
    pptrn->ref_pt = pcs->pat_ref_pt;

    /* rotate as necessar */
    if (rot != 0)
        gs_matrix_multiply(&(rot_mtx[rot]), pmat, pmat);

    /* scale to the appropriate resolution (before print direction rotation) */
    gs_matrix_scale( pmat,
                     inch2coord(1.0 / (floatp)pptrn->ppat_data->xres),
                     inch2coord(1.0 / (floatp)pptrn->ppat_data->yres),
                     pmat
                     );

    /* avoid parameters that are slightly different from integers */
    pmat->xx = adjust_param(pmat->xx);
    pmat->xy = adjust_param(pmat->xy);
    pmat->yx = adjust_param(pmat->yx);
    pmat->yy = adjust_param(pmat->yy);

    /* record the rotation used for rendering */
    pptrn->orient = pcs->pat_orient;
}
예제 #10
0
파일: pcpage.c 프로젝트: ststeiger/ghostsvg
/*
 * Update the transformations stored in the PCL state. This will also update
 * the device clipping region information in device and logical page space.
 * The text region margins are preserved.
 *
 * This routine should be called for:
 *
 *     changes in the paper size
 *     transition from page front to page back for duplexing
 *         (this facility is not currently implemented)
 *     change of left or top offset registration
 *     change of logical page orientation
 *     change of print direction
 *
 * The paper size, left/top offsets, logical page orientation, and print
 * direction should be set before this procedure is called.
 */
  static void
update_xfm_state(
    pcl_state_t *               pcs,
    bool                        reset_initial
)
{
    pcl_xfm_state_t *           pxfmst = &(pcs->xfm_state);
    const pcl_paper_size_t *    psize = pxfmst->paper_size;
    coord                       offset;
    gs_matrix                   pg2dev, pg2lp;
    gs_rect                     print_rect, dev_rect, text_rect;
    gs_point                    cur_pt;
    floatp                      loff = pxfmst->left_offset_cp;
    floatp                      toff = pxfmst->top_offset_cp;

    /* preserve the current point and text rectangle in logical page space */
    if ( !reset_initial )
        preserve_cap_and_margins(pcs, &cur_pt, &text_rect);

    /* get the page to device transformation */
    gs_defaultmatrix(pcs->pgs, &pg2dev);

    /*
     * Get the logical to page space transformation, and the dimensions of the
     * logical page.
     *
     * NOT YET IMPLEMENT - if on back of a duplex page, change size of offsets
     *
     * if (duplex_back(pcs)) {
     *    loff = -loff;
     *    toff = -toff;
     * }
     */
    pcl_make_rotation( pxfmst->lp_orient,
                       (floatp)(psize->width),
                       (floatp)(psize->height),
                       &(pxfmst->lp2pg_mtx)
                       );
    pxfmst->lp2pg_mtx.tx += loff;
    pxfmst->lp2pg_mtx.ty += toff;
    if ( pcs->personality == rtl )
        offset = 0;
    else
        offset = ( (pxfmst->lp_orient & 0x1) != 0 ? psize->offset_landscape
                   : psize->offset_portrait );

    /* we need an extra 1/10 inch on each side to support 80
       characters vs. 78 at 10 cpi.  Only apply to A4. */
    if ( ( pcs->wide_a4 ) &&
         (psize->width == 59520) &&
         (psize->height == 84168) )
        offset -= inch2coord(1.0/10.0);

    gs_matrix_translate( &(pxfmst->lp2pg_mtx),
                         (floatp)offset,
                         0.0,
                         &(pxfmst->lp2pg_mtx)
                         );
    if ((pxfmst->lp_orient & 0x1) != 0) {
        pxfmst->lp_size.x = psize->height - 2 * offset;
        pxfmst->lp_size.y = psize->width;
    } else {
        pxfmst->lp_size.x = psize->width - 2 * offset;
        pxfmst->lp_size.y = psize->height;
    }

    /* then the logical page to device transformation */
    gs_matrix_multiply(&(pxfmst->lp2pg_mtx), &pg2dev,  &(pxfmst->lp2dev_mtx));
    pg2dev.ty = round(pg2dev.ty); pg2dev.tx = round(pg2dev.tx);
    pxfmst->lp2dev_mtx.tx = round(pxfmst->lp2dev_mtx.tx);
    pxfmst->lp2dev_mtx.ty = round(pxfmst->lp2dev_mtx.ty);
    /* the "pseudo page direction to logical page/device transformations */
    pcl_make_rotation( pxfmst->print_dir,
                       (floatp)pxfmst->lp_size.x,
                       (floatp)pxfmst->lp_size.y,
                       &(pxfmst->pd2lp_mtx)
                       );
    gs_matrix_multiply( &(pxfmst->pd2lp_mtx),
                        &(pxfmst->lp2dev_mtx),
                        &(pxfmst->pd2dev_mtx)
                        );

    /* calculate the print direction page size */
    if ((pxfmst->print_dir) & 0x1) {
        pxfmst->pd_size.x = pxfmst->lp_size.y;
        pxfmst->pd_size.y = pxfmst->lp_size.x;
    } else
        pxfmst->pd_size = pxfmst->lp_size;

    {
        gx_device *pdev = gs_currentdevice(pcs->pgs);
        /* We must not set up a clipping region beyond the hardware margins of
           the device, but the pcl language definition requires hardware
           margins to be 1/6".  We set all margins to the the maximum of the
           PCL language defined 1/6" and the actual hardware margin.  If 1/6"
           is not available pcl will not work correctly all of the time. */
        if ( pcs->personality == rtl ) {
            print_rect.p.x = inch2coord(pdev->HWMargins[0] / 72.0);
            print_rect.p.y = inch2coord(pdev->HWMargins[1]) / 72.0;
            print_rect.q.x = psize->width - inch2coord(pdev->HWMargins[2] / 72.0);
            print_rect.q.y = psize->height - inch2coord(pdev->HWMargins[3] / 72.0);
        } else {
            print_rect.p.x = max(PRINTABLE_MARGIN_CP, inch2coord(pdev->HWMargins[0] / 72.0));
            print_rect.p.y = max(PRINTABLE_MARGIN_CP, inch2coord(pdev->HWMargins[1]) / 72.0);
            print_rect.q.x = psize->width - max(PRINTABLE_MARGIN_CP, inch2coord(pdev->HWMargins[2] / 72.0));
            print_rect.q.y = psize->height - max(PRINTABLE_MARGIN_CP, inch2coord(pdev->HWMargins[3] / 72.0));
        }
        pcl_transform_rect(pcs->memory, &print_rect, &dev_rect, &pg2dev);
        pxfmst->dev_print_rect.p.x = float2fixed(round(dev_rect.p.x));
        pxfmst->dev_print_rect.p.y = float2fixed(round(dev_rect.p.y));
        pxfmst->dev_print_rect.q.x = float2fixed(round(dev_rect.q.x));
        pxfmst->dev_print_rect.q.y = float2fixed(round(dev_rect.q.y));
    }
    pcl_invert_mtx(&(pxfmst->lp2pg_mtx), &pg2lp);
    pcl_transform_rect(pcs->memory, &print_rect, &(pxfmst->lp_print_rect), &pg2lp);

    /* restablish the current point and text region */
    if ( !reset_initial )
        restore_cap_and_margins(pcs, &cur_pt, &text_rect);

    /*
     * No need to worry about pat_orient or pat_ref_pt; these will always
     * be recalculated just prior to use.
     */
}
예제 #11
0
int
zdefault_make_font(gs_font_dir * pdir, const gs_font * oldfont,
                   const gs_matrix * pmat, gs_font ** ppfont)
{
    gs_font *newfont = *ppfont;
    gs_memory_t *mem = newfont->memory;
    /* HACK: we know this font was allocated by the interpreter. */
    gs_ref_memory_t *imem = (gs_ref_memory_t *)mem;
    ref *fp = pfont_dict(oldfont);
    font_data *pdata;
    ref newdict, newmat, scalemat;
    uint dlen = dict_maxlength(fp);
    uint mlen = dict_length(fp) + 3;	/* FontID, OrigFont, ScaleMatrix */
    int code;

    if (dlen < mlen)
        dlen = mlen;
    if ((pdata = gs_alloc_struct(mem, font_data, &st_font_data,
                                 "make_font(font_data)")) == 0
        )
        return_error(e_VMerror);
    /*
     * This dictionary is newly created: it's safe to pass NULL as the
     * dstack pointer to dict_copy and dict_put_string.
     */
    if ((code = dict_alloc(imem, dlen, &newdict)) < 0 ||
        (code = dict_copy(fp, &newdict, NULL)) < 0 ||
        (code = gs_alloc_ref_array(imem, &newmat, a_all, 12,
                                   "make_font(matrices)")) < 0
        )
        return code;
    refset_null_new(newmat.value.refs, 12, imemory_new_mask(imem));
    ref_assign(&scalemat, &newmat);
    r_set_size(&scalemat, 6);
    scalemat.value.refs += 6;
    /*
     * Create the scaling matrix.  We could do this several different
     * ways: by "dividing" the new FontMatrix by the base FontMatrix, by
     * multiplying the current scaling matrix by a ScaleMatrix kept in
     * the gs_font, or by multiplying the current scaling matrix by the
     * ScaleMatrix from the font dictionary.  We opt for the last of
     * these.
     */
    {
        gs_matrix scale, prev_scale;
        ref *ppsm;

        if (!(dict_find_string(fp, "ScaleMatrix", &ppsm) > 0 &&
              read_matrix(mem, ppsm, &prev_scale) >= 0 &&
              gs_matrix_multiply(pmat, &prev_scale, &scale) >= 0)
            )
            scale = *pmat;
        write_matrix_new(&scalemat, &scale, imem);
    }
    r_clear_attrs(&scalemat, a_write);
    r_set_size(&newmat, 6);
    write_matrix_new(&newmat, &newfont->FontMatrix, imem);
    r_clear_attrs(&newmat, a_write);
    if ((code = dict_put_string(&newdict, "FontMatrix", &newmat, NULL)) < 0 ||
        (code = dict_put_string(&newdict, "OrigFont", pfont_dict(oldfont->base), NULL)) < 0 ||
        (code = dict_put_string(&newdict, "ScaleMatrix", &scalemat, NULL)) < 0 ||
        (code = add_FID(NULL, &newdict, newfont, imem)) < 0
        )
        return code;
    newfont->client_data = pdata;
    *pdata = *pfont_data(oldfont);
    pdata->dict = newdict;
    r_clear_attrs(dict_access_ref(&newdict), a_write);
    return 0;
}
예제 #12
0
파일: gdeveprn.c 프로젝트: hackqiang/gs
void eprn_get_initial_matrix(gx_device *device, gs_matrix *mptr)
{
  eprn_Device *dev = (eprn_Device *)device;
  float
    /*  The following two arrays are oriented w.r.t. pixmap device space, i.e.,
        the index 0 refers to the x coordinate (horizontal) and the index 1 to
        the y coordinate (vertical) in pixmap device space. */
    extension[2],       /* media extension in pixels */
    pixels_per_bp[2];   /* resolution */
  int
    j,
    quarters;

#ifdef EPRN_TRACE
  if_debug0(EPRN_TRACE_CHAR, "! eprn_get_initial_matrix()...\n");
#endif

  /* We need 'default_orientation' and also the margins. */
  if (dev->eprn.code == ms_none) {
#ifdef EPRN_TRACE
    if_debug0(EPRN_TRACE_CHAR,
      "! eprn_get_initial_matrix(): code is still ms_none.\n");
#endif
    if (eprn_set_page_layout(dev) != 0)
      eprintf("  Processing can't be stopped at this point although this error "
        "occurred.\n");
      /* The current function has a signature without the ability to signal
         an error condition. */
  }

  quarters = dev->eprn.default_orientation +
    (dev->MediaSize[0] <= dev->MediaSize[1]? 0: 1);
     /* Number of quarter-circle rotations by +90 degrees necessary to obtain
        default user space starting with the y axis upwards in pixmap device
        space.
        It's not documented, but 'MediaSize' is the requested "PageSize" page
        device parameter value and hence is to be interpreted in default (not
        default default!) user space. The condition above therefore tests
        whether landscape orientation has been requested.
      */

  /* Soft tumble option: rotate default user space by 180 degrees on every
     second page */
  if (dev->eprn.soft_tumble && dev->ShowpageCount % 2 != 0) quarters += 2;

  /* Prepare auxiliary data */
  for (j = 0; j < 2; j++) pixels_per_bp[j] = dev->HWResolution[j]/BP_PER_IN;
  /*  'HWResolution[]' contains the standard PostScript page device parameter
      'HWResolution' which is defined in pixels per inch with respect to
       device space. */
  if (quarters % 2 == 0) {
    /* Default user space and pixmap device space agree in what is "horizontal"
       and what is "vertical". */
    extension[0] = dev->MediaSize[0];
    extension[1] = dev->MediaSize[1];
  }
  else {
    extension[0] = dev->MediaSize[1];
    extension[1] = dev->MediaSize[0];
  }
  /* Convert from bp to pixels: */
  for (j = 0; j < 2; j++) extension[j] *= pixels_per_bp[j];
   /* Note that we are using the user-specified extension of the sheet, not the
      "official" one we could obtain in most cases from 'size'. */

  switch (quarters % 4) {
  case 0:
    /*  The y axis of default user space points upwards in pixmap device space.
        The CTM is uniquely characterized by the following mappings from
        default user space to pixmap device space:
          (0, 0)                -> (0, height in pixels)
          (width in bp, 0)      -> (width in pixels, height in pixels)
          (0, height in bp)     -> (0, 0)
        'width' and 'height' refer to the sheet's extension as seen from pixmap
        device space, i.e., width in pixels == extension[0] and
        height in pixels == extension[1].

        From the PLR we find that the CTM is a PostScript matrix
        [a b c d tx ty] used for mapping user space coordinates (x, y) to
        device space coordinates (x', y') as follows:
          x' = a*x + c*y + tx
          y' = b*x + d*y + ty
        Ghostscript's matrix type 'gs_matrix' writes its structure components
        'xx' etc. in storage layout order into a PostScript matrix (see
        write_matrix() in iutil.c), hence we obtain by comparison with
        gsmatrix.h the PostScript matrix [ xx xy yx yy tx ty ].
        The correspondence can also be seen by comparison of the equations
        above with the code in gs_point_transform() in gsmatrix.c.
        It would, however, still be reassuring to have a corresponding
        statement in ghostscript's documentation.
    */
    gx_default_get_initial_matrix(device, mptr);
    /*  Of course, I could also set this directly:
          mptr->xx = pixels_per_bp[0];
          mptr->xy = 0;
          mptr->yx = 0;
          mptr->yy = -pixels_per_bp[1];
          mptr->tx = 0;
          mptr->ty = extension[1];
        Doing it in this way is, however, more stable against dramatic changes
        in ghostscript.
    */
    break;
  case 1:
    /*  The y axis of default user space points to the left in pixmap device
        space. The CTM is uniquely characterized by the following mappings from
        default user space to pixmap device space:
          (0, 0)                -> (width in pixels, height in pixels)
          (height in bp, 0)     -> (width in pixels, 0)
          (0, width in bp)      -> (0, height in pixels)
    */
    mptr->xx = 0;
    mptr->xy = -pixels_per_bp[1];
    mptr->yx = -pixels_per_bp[0];
    mptr->yy = 0;
    mptr->tx = extension[0];
    mptr->ty = extension[1];
    break;
  case 2:
    /*  The y axis of default user space points downwards in pixmap device
        space. The CTM is uniquely characterized by the following mappings from
        default user space to pixmap device space:
          (0, 0)                -> (width in pixels, 0)
          (width in bp, 0)      -> (0, 0)
          (0, height in bp)     -> (width in pixels, height in pixels)
    */
    mptr->xx = -pixels_per_bp[0];
    mptr->xy = 0;
    mptr->yx = 0;
    mptr->yy = pixels_per_bp[1];
    mptr->tx = extension[0];
    mptr->ty = 0;
    break;
  case 3:
    /*  The y axis of default user space points to the right in pixmap device
        space. The CTM is uniquely characterized by the following mappings from
        default user space to pixmap device space:
          (0, 0)                -> (0, 0)
          (height in bp, 0)     -> (0, height in pixels)
          (0, width in bp)      -> (width in pixels, 0)
    */
    mptr->xx = 0;
    mptr->xy = pixels_per_bp[1];
    mptr->yx = pixels_per_bp[0];
    mptr->yy = 0;
    mptr->tx = 0;
    mptr->ty = 0;
    break;
  }

  /*  Finally, shift the device space origin to the top-left corner of the
      printable area. I am deliberately not using the corresponding shift
      feature in gx_device_set_margins() because it achieves its effect by
      using the 'Margins' array which should remain at the user's disposal for
      correcting misadjustments. In addition, gx_device_set_margins() will not
      work correctly for quarters % 4 != 0 anyway.
  */
  {
    gs_matrix translation;

    /*  Translation of pixmap device space origin by top and left margins in
        pixmap device space */
    gs_make_translation(
      -dev->eprn.right_shift*pixels_per_bp[0],
      -dev->eprn.down_shift *pixels_per_bp[1],
      &translation);

    /* Multiply the initial matrix from the right with the translation matrix,
       i.e., in going from user to device space the translation will be applied
       last. */
    gs_matrix_multiply(mptr, &translation, mptr);
  }

#ifdef EPRN_TRACE
  if_debug6(EPRN_TRACE_CHAR, "  Returning [%g %g %g %g %g %g].\n",
    mptr->xx, mptr->xy, mptr->yx, mptr->yy, mptr->tx, mptr->ty);
#endif
  return;
}
예제 #13
0
/* makefont */
int
gs_makefont(gs_font_dir *pdir, const gs_font *pfont, const gs_matrix *pmat,
  gs_font **ppfont, gs_font **pdfont)
{	int code;
	gs_font *prev = 0, *pf_out = pdir->scaled_fonts;
	gs_matrix newmat;
	*pdfont = 0;
	gs_make_identity(&newmat);	/* fill in tags */
	if ( (code = gs_matrix_multiply(&pfont->FontMatrix, pmat, &newmat)) < 0 )
	  return code;
	/* Check for the font already being in the scaled font cache. */
	/* Only attempt to share fonts if the current font has */
	/* a real UniqueID (i.e., not -1). */
#ifdef DEBUG
if ( gs_debug['m'] )
   {	dprintf2("[m]UniqueID=%ld, FontType=%d,\n",
	  pfont->data.base.UniqueID, pfont->FontType);
	dprintf6("[m]  new FontMatrix=[%g %g %g %g %g %g]\n",
	  pmat->xx, pmat->xy, pmat->yx, pmat->yy,
	  pmat->tx, pmat->ty);
   }
#endif
	if ( pfont->data.base.UniqueID != -1 )
	  for ( ; pf_out != 0; prev = pf_out, pf_out = pf_out->next )
		if (	pf_out->data.base.UniqueID == pfont->data.base.UniqueID &&
			pf_out->FontType == pfont->FontType &&
			pf_out->FontMatrix.xx == newmat.xx &&
			pf_out->FontMatrix.xy == newmat.xy &&
			pf_out->FontMatrix.yx == newmat.yx &&
			pf_out->FontMatrix.yy == newmat.yy &&
			pf_out->FontMatrix.tx == newmat.tx &&
			pf_out->FontMatrix.ty == newmat.ty
		   )
		   {	*ppfont = pf_out;
			if_debug1('m', "[m]found font=%lx\n", (ulong)pf_out);
			return 0;
		   }
	pf_out = (gs_font *)(*pdir->alloc)(1, sizeof(gs_font), "gs_makefont");
	if ( !pf_out ) return_error(gs_error_VMerror);
	*pf_out = *pfont;
	pf_out->FontMatrix = newmat;
	if ( pdir->ssize == pdir->smax )
	  { /* Must discard a cached scaled font. */
	    /* Scan for the oldest font if we didn't already. */
	    if ( !prev )
	      for ( prev = pdir->scaled_fonts;
		    prev->next != 0;
		    prev = prev->next
		  ) ;
	    if_debug1('m', "[m]discarding font %lx\n", (ulong)prev);
	    *pdfont = prev;
	    prev->prev->next = 0;
	  }
	else
	  pdir->ssize++;
	link_first(pdir->scaled_fonts, pf_out);
	pf_out->base = pfont->base;
	pf_out->dir = pdir;
	*ppfont = pf_out;
	if_debug1('m', "[m]new font=%lx\n", (ulong)pf_out);
	return 1;
}
예제 #14
0
/*
 * Enter raster graphics mode.
 *
 * The major function of this routine is to establish the raster to device
 * space transformations. This is rather involved:
 *
 * 1. The first feature to be established is the orientation of raster space
 *    relative to page space. Three state parameters are involved in
 *    determining this orientation: the logical page orientation, the current
 *    print direction, and the raster presentation mode. These are combined
 *    in the following manner:
 *
 *        tr = (print_direction / 90) + logical_page_orientation
 *
 *        raster_rotate = (presentation_mode == 0 ? tr : tr & 0x2)
 *
 * 2. The next step is to determine the location of the origin of the raster
 *    to page transformation. Intially this origin is set at the appropriate
 *    corner of the logical page, based on the orientation determined above.
 *    The origin is then shift based on the manner in which graphics mode is
 *    entered (the mode operand):
 *
 *        If entry is IMPLICIT (i.e.: via a transfer data command rather than
 *        an enter graphics mode command), translation by the existing left
 *        graphics margin is used, in the orientation of raster space.
 *
 *        If entry is via an enter graphics mode command which specifies moving
 *        the origin to the logical page boundary (NO_SCALE_LEFT_MARG (0) or
 *        SCALE_LEFT_MARG (2)), action depends on whether or not horizontal
 *        access of print direction space and of raster space are the same:
 *
 *            if there are the same, the origin is left unchanged
 *
 *            if they are not the same, the origin is shifted 1/6" (1200 centi-
 *            points) in the positive horizontal raster space axis.
 *
 *        The latter correction is not documented by HP, and there is no clear
 *        reason why it should apply, but it has been verified to be the case
 *        for all HP products testd.
 *
 *        If entry is via an enter graphics mode command with specifies use
 *        of the current point (NO_SCALE_CUR_PT(1) or SCALE_CUR_PT(3)), the
 *        current point is transformed to raster space and its "horizontal"
 *        component is used as the new graphics margin.
 *
 *    Irrespective of how the "horizontal" component of the raster image origin
 *    is specified, the vertical component is always derived from the current
 *    addressable point, by converting the point to raster space.
 *
 * 3. Next, the scale of the raster to page space transformation is established.
 *    This depends on whether or not PCL raster scaling is to be employed.
 *    For raster scaling to be used, all of the following must hold:
 *
 *        the scale_raster flag in the PCL raster state must be set
 *        the current palette must be writable
 *        the raster source height and width must have been explicitly set
 *
 *    The scale_raster flag in the PCL raster state is normally set by the
 *    enter raster graphics command. Hence, if graphics mode is entered
 *    explicitly, the first requirement follows the behavior of the HP Color
 *    LaserJet 5/5M. The DeskJet 1600C/CM behaves differently: it will never
 *    user raster scaling if graphics mode is entered implicitly.
 *
 *    The reason for the second requirement is undoubtedly related to some
 *    backwards compatibility requirement, but is otherwise obscure. The
 *    restriction is, however, both document and uniformly applied by all
 *    HP products that support raster scaling.
 *
 *    If raster scaling is not used, the scale of raster space is determined
 *    by the ratio of the graphics resolution (set by the graphics resolution
 *    command) and unit of page space (centi-points). This factor is applied
 *    in both scan directions.
 *
 *    If scaling is employed, the situation is somewhat more complicated. It
 *    is necessary, in this case, to know which of the raster destination
 *    dimensions have been explicitly set:
 *
 *        If both dimensions are specified, the ration of these dimensions
 *        to the source raster width and height determine the raster scale.
 *
 *        If only one destination dimension is specified, the ratio of this
 *        dimension to the corresponding source dimension determins the
 *        raster scale for both dimensions; With strange interactions with 
 *        the 1200centipoint margin and rotated pages (Bug emulation).
 *
 *        If neither dimension is specified, the page printable region is
 *        transformed to raster space, the intersection of this with the
 *        positive quadrant is taken. The dimensions of the resulting region
 *        are compared with the dimensions of the source raster. The smaller
 *        of the two dest_dim / src_dim ratios is used as the ratio for 
 *        the raster scale in both dimensions (i.e.: select the largest
 *        isotropic scaling that does not cause clipping).
 *
 * 4. Finally, the extent of raster space must be determined. This is done by
 *    converting the page printable region to raster space and intersecting
 *    the result with the positive quadrant. This region is used to determine
 *    the useable source raster width and height.
 *        
 */
   int
pcl_enter_graphics_mode(
    pcl_state_t *       pcs,
    pcl_gmode_entry_t   mode
)
{
    floatp                  scale_x, scale_y;
    pcl_xfm_state_t *       pxfmst = &(pcs->xfm_state);
    pcl_raster_state_t *    prstate = &(pcs->raster_state);
    float                   gmargin_cp = (float)prstate->gmargin_cp;
    gs_point                cur_pt;
    gs_matrix               rst2lp, rst2dev, lp2rst;
    gs_rect                 print_rect;
    uint                    src_wid, src_hgt;
    int                     rot;
    int                     code = 0;
    double                  dwid, dhgt;
    int                     clip_x, clip_y;
    /*
     * Check if the raster is to be clipped fully; see rtrstst.h for details.
     * Since this is a discontinuous effect, the equality checks below
     * should be made while still in centipoints.
     */
    prstate->clip_all = ( (pcs->cap.x == pxfmst->pd_size.x) ||
                          (pcs->cap.y == pxfmst->pd_size.y)   );

    /* create to raster space to logical page space transformation */
    rot = pxfmst->lp_orient + pxfmst->print_dir;
    if (prstate->pres_mode_3)
        rot &= 0x2;
    rot = (rot - pxfmst->lp_orient) & 0x3;
    if (prstate->y_advance == -1)
        rot = (rot + 2) & 0x3;
    pcl_make_rotation(rot, pxfmst->lp_size.x, pxfmst->lp_size.y, &rst2lp);
    pcl_invert_mtx(&rst2lp, &lp2rst);

    /* convert the current point to raster space */
    cur_pt.x = (double)pcs->cap.x + adjust_pres_mode(pcs);
    cur_pt.y = (double)pcs->cap.y;
    pcl_xfm_to_logical_page_space(pcs, &cur_pt);
    gs_point_transform(cur_pt.x, cur_pt.y, &lp2rst, &cur_pt);

    /* translate the origin of the forward transformation */
    if (((int)mode & 0x1) != 0)
        gmargin_cp = cur_pt.x;
    gs_matrix_translate(&rst2lp, gmargin_cp, cur_pt.y, &rst2lp);
    prstate->gmargin_cp = gmargin_cp;

    /* isotropic scaling with missing parameter is based on clipped raster dimensions */

    /* transform the clipping window to raster space */
    get_raster_print_rect(pcs->memory, &(pxfmst->lp_print_rect), &print_rect, &rst2lp);
    dwid = print_rect.q.x - print_rect.p.x;
    dhgt = print_rect.q.y - print_rect.p.y;

    clip_x = pxfmst->lp_print_rect.p.x;  /* if neg then: */
    clip_y = pxfmst->lp_print_rect.p.y;  /* = 1200centipoints */

    /* set the matrix scale */
    if ( !prstate->scale_raster       ||
         !prstate->src_width_set      ||
         !prstate->src_height_set     ||
         (pcs->ppalet->pindexed->pfixed  && mode == IMPLICIT) ) {
        scale_x = 7200.0 / (floatp)prstate->resolution;
        scale_y = scale_x;

    } else if (prstate->dest_width_set) {
	scale_x = (floatp)prstate->dest_width_cp / (floatp)prstate->src_width;

	if ( clip_x < 0 && pxfmst->lp_orient == 3 ) { 
	    scale_y = (floatp)(prstate->dest_width_cp - clip_y ) / (floatp)prstate->src_width;
	    if ( rot == 2 && scale_y <=  2* prstate->src_width) /* empirical test 1 */
		scale_y = scale_x;   
	}
	else if ( clip_x < 0 && pxfmst->lp_orient == 1 && rot == 3 ) {
	    scale_y = (floatp)(prstate->dest_width_cp - clip_y) / (floatp)prstate->src_width;

	    if ( prstate->dest_width_cp <= 7200 )  /* empirical test 2 */
		scale_y = (floatp)(prstate->dest_width_cp + clip_y) / (floatp)prstate->src_width;
	}
	else 
	    scale_y = scale_x;

        if (prstate->dest_height_set) 
	    scale_y = (floatp)prstate->dest_height_cp / (floatp)prstate->src_height;

    } else if (prstate->dest_height_set) {    	 
	scale_x = scale_y = (floatp)prstate->dest_height_cp / (floatp)prstate->src_height;
    } else {

        /* select isotropic scaling with no clipping */
	scale_x = (floatp)dwid / (floatp)prstate->src_width;
	scale_y = (floatp)dhgt / (floatp)prstate->src_height;
        if (scale_x > scale_y)
            scale_x = scale_y;
        else
            scale_y = scale_x;
    }

    gs_matrix_scale(&rst2lp, scale_x, scale_y, &rst2lp);
    gs_matrix_multiply(&rst2lp, &(pxfmst->lp2dev_mtx), &rst2dev);

    rst2dev.tx = (double)((int)(rst2dev.tx + 0.5));
    rst2dev.ty = (double)((int)(rst2dev.ty + 0.5));
    /*
     * Set up the graphic stat for rasters. This turns out to be more difficult
     * than might first be imagined.
     *
     * One problem is that two halftones may be needed simultaneously:
     *
     *     the foreground CRD and halftone, in case the current "texture" is a
     *     a solid color or an uncolored pattern
     *
     *     the palette CRD and halftone, to be used in rendering the raster
     *     itself
     *
     * Since the graphic state can only hold one CRD and one halftone method
     * at a time, this presents a bit of a problem.
     *
     * To get around the problem, an extra graphic state is necessary. Patterns
     * in the graphic library are given their own graphic state. Hence, by
     * replacing a solid color with an uncolored pattern that takes the
     * foreground value everywhere, the desired effect can be achieved. Code
     * in pcpatrn.c handles these matters.
     *
     * The second problem is a limitation in the graphic library's support of
     * CIE color spaces. These spaces require a joint cache, which is only
     * created when the color space is installed in the graphic state. However,
     * the current color space at the time a raster is rendered may need to
     * be a pattern color space, so that the proper interaction between the
     * raster and the texture generated by the pattern. To work around this
     * problem, we install the raster's color space in the current graphic
     * state, perform a gsave, then place what may be a patterned color space
     * in the new graphic state.
     */
    pcl_set_graphics_state(pcs);
    pcl_set_drawing_color(pcs, pcl_pattern_raster_cspace, 0, true);
    pcl_gsave(pcs);
    pcl_set_drawing_color(pcs, pcs->pattern_type, pcs->current_pattern_id, true);
    gs_setmatrix(pcs->pgs, &rst2dev);

    /* translate the origin of the forward transformation */
    /* tansform the clipping window to raster space; udpate source dimensions */
    get_raster_print_rect(pcs->memory, &(pxfmst->lp_print_rect), &print_rect, &rst2lp);

    /* min size is 1 pixel */
    src_wid = max(1, (uint)(floor(print_rect.q.x) - floor(print_rect.p.x)));
    src_hgt = max(1, (uint)(floor(print_rect.q.y) - floor(print_rect.p.y)));
    if (prstate->src_width_set && (src_wid > prstate->src_width))
        src_wid = prstate->src_width;
    if (prstate->src_height_set && (src_hgt > prstate->src_height))
        src_hgt = prstate->src_height;

    if (src_wid <= 0 || src_hgt <= 0) {
        pcl_grestore(pcs);
        return 1; /* hack, we want to return a non critical warning */
    }
    /* determine (conservatively) if the region of interest has been
       marked */
    pcs->page_marked = true;
    if ((code = pcl_start_raster(src_wid, src_hgt, pcs)) >= 0)
        prstate->graphics_mode = true;
    else
        pcl_grestore(pcs);
    return code;
}