PDFLIB_API void PDFLIB_CALL PDF_setmatrix(PDF *p, float a, float b, float c, float d, float e, float f) { static const char fn[] = "PDF_setmatrix"; pdc_matrix m; float det = a * d - b * c; if (!pdf_enter_api(p, fn, pdf_state_content, "(p[%p], %g, %g, %g, %g, %g, %g)\n", (void *) p, a, b, c, d, e, f)) { return; } if (fabs(det) < (float) PDF_SMALLREAL) pdc_error(p->pdc, PDC_E_ILLARG_MATRIX, pdc_errprintf(p->pdc, "%f %f %f %f %f %f", a, b, c, d, e, f), 0, 0, 0); pdc_invert_matrix(p->pdc, &m, &p->gstate[p->sl].ctm); pdf_concat_raw(p, &m); m.a = (float) a; m.b = (float) b; m.c = (float) c; m.d = (float) d; m.e = (float) e; m.f = (float) f; pdf_concat_raw(p, &m); }
void pdf_set_topdownsystem(PDF *p, float height) { if (p->ydirection < (float) 0.0) { pdc_matrix m; pdc_translation_matrix(0, height, &m); pdf_concat_raw(p, &m); pdc_scale_matrix(1, -1, &m); pdf_concat_raw(p, &m); pdf_set_horiz_scaling(p, 100); } }
void pdf__setmatrix(PDF *p, pdc_matrix *n) { pdc_matrix m; float det = n->a * n->d - n->b * n->c; if (fabs(det) < (float) PDF_SMALLREAL) pdc_error(p->pdc, PDC_E_ILLARG_MATRIX, pdc_errprintf(p->pdc, "%f %f %f %f %f %f", n->a, n->b, n->c, n->d, n->e, n->f), 0, 0, 0); pdc_invert_matrix(p->pdc, &m, &p->gstate[p->sl].ctm); pdf_concat_raw(p, &m); pdf_concat_raw(p, n); }
PDFLIB_API void PDFLIB_CALL PDF_skew(PDF *p, float alpha, float beta) { static const char fn[] = "PDF_skew"; pdc_matrix m; if (!pdf_enter_api(p, fn, pdf_state_content, "(p[%p], %g, %g)\n", (void *) p, alpha, beta)) return; if (alpha == (float) 0 && beta == (float) 0) return; if (alpha > (float) 360 || alpha < (float) -360 || alpha == (float) -90 || alpha == (float) -270 || alpha == (float) 90 || alpha == (float) 270) { pdc_error(p->pdc, PDC_E_ILLARG_FLOAT, "alpha", pdc_errprintf(p->pdc, "%f", alpha), 0, 0); } if (beta > (float) 360 || beta < (float) -360 || beta == (float) -90 || beta == (float) -270 || beta == (float) 90 || beta == (float) 270) { pdc_error(p->pdc, PDC_E_ILLARG_FLOAT, "beta", pdc_errprintf(p->pdc, "%f", beta), 0, 0); } pdc_skew_matrix(p->ydirection * alpha, p->ydirection * beta, &m); pdf_concat_raw(p, &m); }
void pdf__skew(PDF *p, pdc_scalar alpha, pdc_scalar beta) { pdc_matrix m; pdc_check_number(p->pdc, "alpha", alpha); pdc_check_number(p->pdc, "beta", beta); if (alpha == 0 && beta == 0) return; if (alpha > 360 || alpha < -360 || alpha == -90 || alpha == -270 || alpha == 90 || alpha == 270) { pdc_error(p->pdc, PDC_E_ILLARG_FLOAT, "alpha", pdc_errprintf(p->pdc, "%f", alpha), 0, 0); } if (beta > 360 || beta < -360 || beta == -90 || beta == -270 || beta == 90 || beta == 270) { pdc_error(p->pdc, PDC_E_ILLARG_FLOAT, "beta", pdc_errprintf(p->pdc, "%f", beta), 0, 0); } pdc_skew_matrix(p->ydirection * alpha, p->ydirection * beta, &m); pdf_concat_raw(p, &m); }
void pdf_concat_raw_ob(PDF *p, pdc_matrix *m, pdc_bool blind) { if (!blind) pdf_concat_raw(p, m); else pdc_multiply_matrix(m, &p->gstate[p->sl].ctm); }
void pdf_setmatrix_e(PDF *p, pdc_matrix *n) { pdc_matrix m; pdc_invert_matrix(p->pdc, &m, &p->curr_ppt->gstate[p->curr_ppt->sl].ctm); pdc_multiply_matrix(n, &m); pdf_concat_raw(p, &m); }
void pdf_set_topdownsystem(PDF *p, pdc_scalar height) { if (p->ydirection < 0) { pdc_matrix m, sm; pdc_translation_matrix(0, height, &m); pdc_scale_matrix(1, -1, &sm); pdc_multiply_matrix(&sm, &m); pdf_concat_raw(p, &m); } }
void pdf__initgraphics(PDF *p) { pdc_matrix inv_ctm; pdf_reset_gstate(p); pdc_invert_matrix(p->pdc, &inv_ctm, &p->gstate[p->sl].ctm); pdf_concat_raw(p, &inv_ctm); /* This also resets the CTM which guards against rounding artifacts. */ pdf_init_gstate(p); }
void pdf__rotate(PDF *p, pdc_scalar phi) { pdc_matrix m; pdc_check_number(p->pdc, "phi", phi); if (phi == 0) return; pdc_rotation_matrix(p->ydirection * phi, &m); pdf_concat_raw(p, &m); }
void pdf__translate(PDF *p, pdc_scalar tx, pdc_scalar ty) { pdc_matrix m; pdc_check_number(p->pdc, "tx", tx); pdc_check_number(p->pdc, "ty", ty); if (tx == 0 && ty == 0) return; pdc_translation_matrix(tx, ty, &m); pdf_concat_raw(p, &m); }
void pdf__scale(PDF *p, pdc_scalar sx, pdc_scalar sy) { pdc_matrix m; pdc_check_number_zero(p->pdc, "sx", sx); pdc_check_number_zero(p->pdc, "sy", sy); if (sx == 1 && sy == 1) return; pdc_scale_matrix(sx, sy, &m); pdf_concat_raw(p, &m); }
PDFLIB_API void PDFLIB_CALL PDF_rotate(PDF *p, float phi) { static const char fn[] = "PDF_rotate"; pdc_matrix m; if (!pdf_enter_api(p, fn, pdf_state_content, "(p[%p], %g)\n", (void *) p, phi)) return; if (phi == (float) 0) return; pdc_rotation_matrix(p->ydirection * phi, &m); pdf_concat_raw(p, &m); }
PDFLIB_API void PDFLIB_CALL PDF_translate(PDF *p, float tx, float ty) { static const char fn[] = "PDF_translate"; pdc_matrix m; if (!pdf_enter_api(p, fn, pdf_state_content, "(p[%p], %g, %g)\n", (void *) p, tx, ty)) return; if (tx == (float) 0 && ty == (float) 0) return; pdc_translation_matrix(tx, ty, &m); pdf_concat_raw(p, &m); }
void pdf__concat(PDF *p, pdc_scalar a, pdc_scalar b, pdc_scalar c, pdc_scalar d, pdc_scalar e, pdc_scalar f) { pdc_matrix m; pdc_check_number(p->pdc, "a", a); pdc_check_number(p->pdc, "b", b); pdc_check_number(p->pdc, "c", c); pdc_check_number(p->pdc, "d", d); pdc_check_number(p->pdc, "e", e); pdc_check_number(p->pdc, "f", f); m.a = a; m.b = b; m.c = c; m.d = d; m.e = e; m.f = f; pdf_concat_raw(p, &m); }
PDFLIB_API void PDFLIB_CALL PDF_scale(PDF *p, float sx, float sy) { static const char fn[] = "PDF_scale"; pdc_matrix m; if (!pdf_enter_api(p, fn, pdf_state_content, "(p[%p], %g, %g)\n", (void *) p, sx, sy)) return; if (sx == (float) 0) pdc_error(p->pdc, PDC_E_ILLARG_FLOAT, "sx", "0", 0, 0); if (sy == (float) 0) pdc_error(p->pdc, PDC_E_ILLARG_FLOAT, "sy", "0", 0, 0); if (sx == (float) 1 && sy == (float) 1) return; pdc_scale_matrix(sx, sy, &m); pdf_concat_raw(p, &m); }
PDFLIB_API void PDFLIB_CALL PDF_place_image(PDF *p, int im, float x, float y, float scale) { static const char fn[] = "PDF_place_image"; pdf_matrix m; pdf_image *image; int row; int imageno; PDF_TRACE(("%s\t(pdf[%p], %d, %f, %f, %f);\n", fn, (void *) p, im, x, y, scale)); if (PDF_SANITY_CHECK_FAILED(p)) return; if (im < 0 || im >= p->images_capacity || !p->images[im].in_use || p->xobjects[p->images[im].no].type == pdi_xobject) { pdf_error(p, PDF_ValueError, "Bad image or template handle %d in PDF_place_image", im); } PDF_CHECK_SCOPE(p, fn, pdf_state_ppt); if (PDF_GET_STATE(p) == pdf_state_template && im == p->templ) pdf_error(p, PDF_ValueError, "Can't use template within its own definition"); image = &p->images[im]; if (fabs(scale) < (float) PDF_SMALLREAL) pdf_error(p, PDF_ValueError, "Scaling factor 0 for image %s", image->filename); if (p->xobjects[image->no].type == form_xobject) { pdf_end_text(p); pdf_begin_contents_section(p); imageno = image->no; m.a = scale; m.d = scale; m.b = m.c = (float) 0.0; m.e = x; m.f = y; PDF_save(p); pdf_concat_raw(p, &m); if (!p->inheritgs) pdf_reset_gstate(p); pdf_printf(p, "/I%d Do\n", imageno); p->xobjects[imageno].flags |= xobj_flag_write; PDF_restore(p); return; } switch (image->colorspace) { case ImageMask: case DeviceGray: p->procset |= ImageB; break; /* * It appears that indexed images require both, although this is * not documented. */ case Indexed: p->procset |= ImageI; p->procset |= ImageC; break; case DeviceRGB: case DeviceCMYK: p->procset |= ImageC; break; case CalGray: case CalRGB: case Lab: case PatternCS: case Separation: pdf_error(p, PDF_SystemError, "Bogus colorspace (%d) in PDF_place_image", (int) image->colorspace); /* image has been colorized with a spot color */ default: break; /* york: check the above carefully! ** original version: default: pdf_error(p, PDF_SystemError, "Bogus colorspace (%d) in PDF_place_image", (int) image->colorspace); */ } pdf_end_text(p); pdf_begin_contents_section(p); imageno = image->no; /* number of first strip */ if (image->strips == 1) image->rowsperstrip = (int) image->height; for (row = 0; row < image->height; row += image->rowsperstrip, imageno++) { int height; /* height of the current strip */ height = (row + image->rowsperstrip > image->height ? (int) image->height - row : image->rowsperstrip); PDF_save(p); m.a = image->width * scale; m.d = height * scale; m.b = m.c = (float) 0.0; m.e = x; m.f = y + scale * (image->height - row - height); pdf_concat_raw(p, &m); pdf_printf(p, "/I%d Do\n", imageno); p->xobjects[imageno].flags |= xobj_flag_write; if (image->mask != -1) p->xobjects[p->images[image->mask].no].flags |= xobj_flag_write; PDF_restore(p); } }