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__lineto(PDF *p, pdc_scalar x, pdc_scalar y) { pdf_ppt *ppt = p->curr_ppt; pdc_check_number(p->pdc, "x", x); pdc_check_number(p->pdc, "y", y); pdc_printf(p->out, "%f %f l\n", x, y); ppt->gstate[ppt->sl].x = x; ppt->gstate[ppt->sl].y = y; }
void pdf__rlineto(PDF *p, pdc_scalar x, pdc_scalar y) { pdf_ppt *ppt = p->curr_ppt; pdc_scalar x_0 = ppt->gstate[ppt->sl].x; pdc_scalar y_0 = ppt->gstate[ppt->sl].y; pdc_check_number(p->pdc, "x", x); pdc_check_number(p->pdc, "y", y); pdf__lineto(p, x_0 + x, y_0 + y); }
void pdf__arcn(PDF *p, pdc_scalar x, pdc_scalar y, pdc_scalar r, pdc_scalar alpha, pdc_scalar beta) { pdc_check_number(p->pdc, "x", x); pdc_check_number(p->pdc, "y", y); pdc_check_number_limits(p->pdc, "r", r, PDC_FLOAT_PREC, PDC_FLOAT_MAX); pdc_check_number(p->pdc, "alpha", alpha); pdc_check_number(p->pdc, "beta", beta); pdf_orient_arc(p, x, y, r, p->ydirection * alpha, p->ydirection * beta, -p->ydirection); }
void pdf__moveto(PDF *p, pdc_scalar x, pdc_scalar y) { pdf_ppt *ppt = p->curr_ppt; pdc_check_number(p->pdc, "x", x); pdc_check_number(p->pdc, "y", y); ppt->gstate[ppt->sl].startx = ppt->gstate[ppt->sl].x = x; ppt->gstate[ppt->sl].starty = ppt->gstate[ppt->sl].y = y; pdf_begin_path(p); pdc_printf(p->out, "%f %f m\n", x, y); }
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__rect(PDF *p, pdc_scalar x, pdc_scalar y, pdc_scalar width, pdc_scalar height) { pdf_ppt *ppt = p->curr_ppt; pdc_check_number(p->pdc, "x", x); pdc_check_number(p->pdc, "y", y); pdc_check_number(p->pdc, "width", width); pdc_check_number(p->pdc, "height", height); ppt->gstate[ppt->sl].startx = ppt->gstate[ppt->sl].x = x; ppt->gstate[ppt->sl].starty = ppt->gstate[ppt->sl].y = y; pdf_begin_path(p); pdc_printf(p->out, "%f %f %f %f re\n", x, y, width, p->ydirection * height); }
void pdf__circle(PDF *p, pdc_scalar x, pdc_scalar y, pdc_scalar r) { pdc_check_number(p->pdc, "x", x); pdc_check_number(p->pdc, "y", y); pdc_check_number_limits(p->pdc, "r", r, PDC_FLOAT_PREC, PDC_FLOAT_MAX); /* * pdf_begin_path() not required since we descend to other * path segment functions. */ /* draw four Bezier curves to approximate a circle */ pdf__moveto(p, x + r, y); pdf__curveto(p, x + r, y + r*ARC_MAGIC, x + r*ARC_MAGIC, y + r, x, y + r); pdf__curveto(p, x - r*ARC_MAGIC, y + r, x - r, y + r*ARC_MAGIC, x - r, y); pdf__curveto(p, x - r, y - r*ARC_MAGIC, x - r*ARC_MAGIC, y - r, x, y - r); pdf__curveto(p, x + r*ARC_MAGIC, y - r, x + r, y - r*ARC_MAGIC, x + r, y); pdf__closepath(p); }
void pdf__curveto(PDF *p, pdc_scalar x_1, pdc_scalar y_1, pdc_scalar x_2, pdc_scalar y_2, pdc_scalar x_3, pdc_scalar y_3) { pdf_ppt *ppt = p->curr_ppt; pdc_check_number(p->pdc, "x_1", x_1); pdc_check_number(p->pdc, "y_1", y_1); pdc_check_number(p->pdc, "x_2", x_2); pdc_check_number(p->pdc, "y_2", y_2); pdc_check_number(p->pdc, "x_3", x_3); pdc_check_number(p->pdc, "y_3", y_3); /* second c.p. coincides with final point */ if (fabs(x_2 - x_3) < PDC_FLOAT_PREC && fabs(y_2 - y_3) < PDC_FLOAT_PREC) pdc_printf(p->out, "%f %f %f %f y\n", x_1, y_1, x_3, y_3); /* general case with four distinct points */ else pdc_printf(p->out, "%f %f %f %f %f %f c\n", x_1, y_1, x_2, y_2, x_3, y_3); ppt->gstate[ppt->sl].x = x_3; ppt->gstate[ppt->sl].y = y_3; }
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__setmatrix(PDF *p, pdc_scalar a, pdc_scalar b, pdc_scalar c, pdc_scalar d, pdc_scalar e, pdc_scalar f) { pdc_matrix n; 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); n.a = a; n.b = b; n.c = c; n.d = d; n.e = e; n.f = f; pdf_setmatrix_e(p, &n); }
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); }
void pdf__rcurveto(PDF *p, pdc_scalar x_1, pdc_scalar y_1, pdc_scalar x_2, pdc_scalar y_2, pdc_scalar x_3, pdc_scalar y_3) { pdf_ppt *ppt = p->curr_ppt; pdc_scalar x_0 = ppt->gstate[ppt->sl].x; pdc_scalar y_0 = ppt->gstate[ppt->sl].y; pdc_check_number(p->pdc, "x_1", x_1); pdc_check_number(p->pdc, "y_1", y_1); pdc_check_number(p->pdc, "x_2", x_2); pdc_check_number(p->pdc, "y_2", y_2); pdc_check_number(p->pdc, "x_3", x_3); pdc_check_number(p->pdc, "y_3", y_3); pdf__curveto(p, x_0 + x_1, y_0 + y_1, x_0 + x_2, y_0 + y_2, x_0 + x_3, y_0 + y_3); }
void pdf__begin_glyph( PDF *p, const char *glyphname, pdc_scalar wx, pdc_scalar llx, pdc_scalar lly, pdc_scalar urx, pdc_scalar ury) { static const char fn[] = "pdf__begin_glyph"; pdf_font *font; pdf_t3font *t3font; pdf_t3glyph *glyph = NULL; pdc_scalar tbc; int ig; if (glyphname == NULL || *glyphname == '\0') pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "glyphname", 0, 0, 0); font = &p->fonts[p->t3slot]; t3font = font->t3font; /* error message prefix */ pdc_push_errmsg(p->pdc, PDF_E_T3_FONT_PREFIX, font->apiname, 0, 0, 0); for (ig = 0; ig < t3font->next_glyph; ig++) { glyph = &t3font->glyphs[ig]; if (!pdc_strcmp(glyph->name, glyphname)) { if (t3font->pass == glyph->pass) pdc_error(p->pdc, PDF_E_T3_GLYPH, glyphname, 0, 0, 0); else break; } } /* new glyph */ if (ig == t3font->next_glyph) { if (t3font->pass == 2) pdc_error(p->pdc, PDF_E_T3_UNKOWNGLYPH, glyphname, 0, 0, 0); pdc_check_number(p->pdc, "wx", wx); pdc_check_number(p->pdc, "llx", llx); pdc_check_number(p->pdc, "lly", lly); pdc_check_number(p->pdc, "urx", urx); pdc_check_number(p->pdc, "ury", ury); if (t3font->colorized == pdc_true && (llx != 0 || lly != 0 || urx != 0 || ury != 0)) pdc_error(p->pdc, PDF_E_T3_BADBBOX, 0, 0, 0, 0); if (urx < llx) { tbc = llx; llx = urx; urx = tbc; } if (ury < lly) { tbc = lly; lly = ury; ury = tbc; } if (ig == t3font->capacity) { t3font->capacity *= 2; t3font->glyphs = (pdf_t3glyph *) pdc_realloc(p->pdc, t3font->glyphs, t3font->capacity * sizeof (pdf_t3glyph), fn); } glyph = &t3font->glyphs[ig]; glyph->charproc_id = PDC_BAD_ID; glyph->name = pdc_strdup(p->pdc, glyphname); glyph->wx = wx; glyph->llx = llx; glyph->lly = lly; glyph->urx = urx; glyph->ury = ury; /* see comment in p_font.c for explanation */ glyph->width = 1000 * wx * font->ft.matrix.a; /* if the strdup above fails, cleanup won't touch this slot. */ t3font->next_glyph++; } glyph->pass = t3font->pass; t3font->curr_glyph = ig; pdc_logg_cond(p->pdc, 1, trc_font, "\tBegin of Type3 font glyph \"%s\"\n", glyphname); if (t3font->pass != 1) { if (t3font->pass == 2) pdc_logg_cond(p->pdc, 2, trc_font, "\t\tglyph [%d] was used in text\n", ig); glyph->charproc_id = pdc_begin_obj(p->out, PDC_NEW_ID); pdc_begin_dict(p->out); p->length_id = pdc_alloc_id(p->out); pdc_objref(p->out, "/Length", p->length_id); if (pdc_get_compresslevel(p->out)) pdc_puts(p->out, "/Filter/FlateDecode\n"); pdc_end_dict(p->out); pdc_begin_pdfstream(p->out); if (t3font->colorized == pdc_true) pdc_printf(p->out, "%f 0 d0\n", glyph->wx); else { pdc_printf(p->out, "%f 0 %f %f %f %f d1\n", glyph->wx, glyph->llx, glyph->lly, glyph->urx, glyph->ury); /* adjust the font's bounding box */ if (glyph->llx < font->ft.bbox.llx) font->ft.bbox.llx = glyph->llx; if (glyph->lly < font->ft.bbox.lly) font->ft.bbox.lly = glyph->lly; if (glyph->urx > font->ft.bbox.urx) font->ft.bbox.urx = glyph->urx; if (glyph->ury > font->ft.bbox.ury) font->ft.bbox.ury = glyph->ury; } /* we must initialize the text, graphics and color state * otherwise the user get unpredictable appearance of a * glyph because of optimizing outputting graphics properties. * Following statements were inserted due to bug #719 */ pdf_init_tstate(p); pdf_init_gstate(p); pdf_init_cstate(p); PDF_SET_STATE(p, pdf_state_glyph); } else { PDF_SET_STATE(p, pdf_state_glyphmetrics); } pdc_pop_errmsg(p->pdc); if (!p->pdc->smokerun) pdc_logg_cond(p->pdc, 1, trc_api, "[Begin glyph %d]\n", ig); }
void pdf__set_value(PDF *p, const char *key, double value) { int i; int ivalue = (int) value; pdf_ppt *ppt; i = pdf_get_index(p, key, pdc_true); ppt = p->curr_ppt; pdc_check_number(p->pdc, "value", value); switch (i) { #if defined(WIN32) && !defined(__BORLANDC__) && !defined(__CYGWIN__) /* CDPDF */ case PDF_PARAMETER_MAXFILEHANDLES: ivalue = pdc_set_maxfilehandles(p->pdc, ivalue); if (ivalue == -1) pdc_error(p->pdc, PDC_E_PAR_ILLVALUE, pdc_errprintf(p->pdc, "%f", value), key, 0, 0); break; #endif case PDF_PARAMETER_COMPRESS: if (ivalue < 0 || ivalue > 9) pdc_error(p->pdc, PDC_E_PAR_ILLVALUE, pdc_errprintf(p->pdc, "%f", value), key, 0, 0); if (pdc_get_compresslevel(p->out) != ivalue) { /* * We must restart the compression engine and start a new * contents section if we're in the middle of a page. */ if (PDF_GET_STATE(p) == pdf_state_page) { pdf_end_contents_section(p); pdc_set_compresslevel(p->out, ivalue); pdf_begin_contents_section(p); } else pdc_set_compresslevel(p->out, ivalue); } break; case PDF_PARAMETER_FLOATDIGITS: if (3 <= ivalue && ivalue <= 6) { p->pdc->floatdigits = ivalue; } else pdc_error(p->pdc, PDC_E_PAR_ILLVALUE, pdc_errprintf(p->pdc, "%d", ivalue), key, 0, 0); break; /* TODO (york): take /CropBox into account? */ case PDF_PARAMETER_PAGEWIDTH: { const pdc_rectangle *box = pdf_get_pagebox(p, pdf_mediabox); if (p->ydirection == -1) pdc_error(p->pdc, PDF_E_PAGE_ILLCHGSIZE, 0, 0, 0, 0); if (value < PDF_ACRO_MINPAGE || value > PDF_ACRO_MAXPAGE) pdc_warning(p->pdc, PDF_E_PAGE_SIZE_ACRO, 0, 0, 0, 0); pdf_set_pagebox_urx(p, pdf_mediabox, box->llx + pdf_pos_value(p, key, value, PDC_1_3)); break; } /* TODO (york): take /CropBox into account? */ case PDF_PARAMETER_PAGEHEIGHT: { const pdc_rectangle *box = pdf_get_pagebox(p, pdf_mediabox); if (p->ydirection == -1) pdc_error(p->pdc, PDF_E_PAGE_ILLCHGSIZE, 0, 0, 0, 0); if (value < PDF_ACRO_MINPAGE || value > PDF_ACRO_MAXPAGE) pdc_warning(p->pdc, PDF_E_PAGE_SIZE_ACRO, 0, 0, 0, 0); pdf_set_pagebox_ury(p, pdf_mediabox, box->lly + pdf_pos_value(p, key, value, PDC_1_3)); break; } case PDF_PARAMETER_CROPBOX_LLX: pdf_set_pagebox_llx(p, pdf_cropbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_CROPBOX_LLY: pdf_set_pagebox_lly(p, pdf_cropbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_CROPBOX_URX: pdf_set_pagebox_urx(p, pdf_cropbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_CROPBOX_URY: pdf_set_pagebox_ury(p, pdf_cropbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_BLEEDBOX_LLX: pdf_set_pagebox_llx(p, pdf_bleedbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_BLEEDBOX_LLY: pdf_set_pagebox_lly(p, pdf_bleedbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_BLEEDBOX_URX: pdf_set_pagebox_urx(p, pdf_bleedbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_BLEEDBOX_URY: pdf_set_pagebox_ury(p, pdf_bleedbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_TRIMBOX_LLX: pdf_set_pagebox_llx(p, pdf_trimbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_TRIMBOX_LLY: pdf_set_pagebox_lly(p, pdf_trimbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_TRIMBOX_URX: pdf_set_pagebox_urx(p, pdf_trimbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_TRIMBOX_URY: pdf_set_pagebox_ury(p, pdf_trimbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_ARTBOX_LLX: pdf_set_pagebox_llx(p, pdf_artbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_ARTBOX_LLY: pdf_set_pagebox_lly(p, pdf_artbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_ARTBOX_URX: pdf_set_pagebox_urx(p, pdf_artbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_ARTBOX_URY: pdf_set_pagebox_ury(p, pdf_artbox, pdf_value(p, key, value, PDC_1_3)); break; case PDF_PARAMETER_LEADING: pdf_set_tstate(p, value, to_leading); break; case PDF_PARAMETER_TEXTRISE: pdf_set_tstate(p, value, to_textrise); break; case PDF_PARAMETER_HORIZSCALING: pdf_set_tstate(p, value /100, to_horizscaling); break; case PDF_PARAMETER_ITALICANGLE: pdf_set_tstate(p, value, to_italicangle); break; case PDF_PARAMETER_TEXTRENDERING: pdf_set_tstate(p, value, to_textrendering); break; case PDF_PARAMETER_CHARSPACING: pdf_set_tstate(p, value, to_charspacing); break; case PDF_PARAMETER_WORDSPACING: pdf_set_tstate(p, value, to_wordspacing); break; case PDF_PARAMETER_UNDERLINEWIDTH: pdf_set_tstate(p, value, to_underlinewidth); break; case PDF_PARAMETER_UNDERLINEPOSITION: pdf_set_tstate(p, value, to_underlineposition); break; case PDF_PARAMETER_DEFAULTGRAY: break; case PDF_PARAMETER_DEFAULTRGB: break; case PDF_PARAMETER_DEFAULTCMYK: break; case PDF_PARAMETER_SETCOLOR_ICCPROFILEGRAY: break; case PDF_PARAMETER_SETCOLOR_ICCPROFILERGB: break; case PDF_PARAMETER_SETCOLOR_ICCPROFILECMYK: break; /*****************************************************************************/ /** deprecated historical parameters **/ /*****************************************************************************/ case PDF_PARAMETER_SUBSETLIMIT: case PDF_PARAMETER_SUBSETMINSIZE: { pdc_warning(p->pdc, PDF_E_UNSUPP_SUBSET, 0, 0, 0, 0); break; } case PDF_PARAMETER_DURATION: pdf_set_duration(p, value); break; default: pdc_error(p->pdc, PDC_E_PAR_UNKNOWNKEY, key, 0, 0, 0); break; } /* switch */ } /* pdf__set_value */
int pdf__shading( PDF *p, const char *type, pdc_scalar x_0, pdc_scalar y_0, pdc_scalar x_1, pdc_scalar y_1, pdc_scalar c_1, pdc_scalar c_2, pdc_scalar c_3, pdc_scalar c_4, const char *optlist) { pdf_shadingtype_e shtype = shnone; pdf_color *color0, color1; pdf_colorspace *cs; pdc_resopt *results; pdc_scalar N = 1.0; pdc_scalar r_0, r_1; pdc_bool extend0 = pdc_false, extend1 = pdc_false, antialias = pdc_false; int retval = -1; if (p->compatibility == PDC_1_3) pdc_error(p->pdc, PDF_E_SHADING13, 0, 0, 0, 0); if (!pdc_stricmp(type, "axial")) { shtype = axial; } else if (!pdc_stricmp(type, "radial")) { shtype = radial; } else pdc_error(p->pdc, PDC_E_ILLARG_STRING, "type", type, 0, 0); pdc_check_number(p->pdc, "x_0", x_0); pdc_check_number(p->pdc, "y_0", y_0); pdc_check_number(p->pdc, "x_1", x_1); pdc_check_number(p->pdc, "y_1", y_1); pdc_check_number(p->pdc, "c_1", c_1); pdc_check_number(p->pdc, "c_2", c_2); pdc_check_number(p->pdc, "c_3", c_3); pdc_check_number(p->pdc, "c_4", c_4); color0 = pdf_get_cstate(p, pdf_fill); color1.cs = color0->cs; cs = &p->colorspaces[color0->cs]; switch (cs->type) { case DeviceGray: color1.val.gray = c_1; break; case DeviceRGB: color1.val.rgb.r = c_1; color1.val.rgb.g = c_2; color1.val.rgb.b = c_3; break; case DeviceCMYK: color1.val.cmyk.c = c_1; color1.val.cmyk.m = c_2; color1.val.cmyk.y = c_3; color1.val.cmyk.k = c_4; break; default: pdc_error(p->pdc, PDF_E_INT_BADCS, pdc_errprintf(p->pdc, "%d", color0->cs), 0, 0, 0); } results = pdc_parse_optionlist(p->pdc, optlist, pdf_shading_options, NULL, pdc_true); (void) pdc_get_optvalues("N", results, &N, NULL); (void) pdc_get_optvalues("antialias", results, &antialias,NULL); if (shtype == radial) { if (pdc_get_optvalues("r0", results, &r_0, NULL) != 1) pdc_error(p->pdc, PDC_E_OPT_NOTFOUND, "r0", 0, 0, 0); if (pdc_get_optvalues("r1", results, &r_1, NULL) != 1) pdc_error(p->pdc, PDC_E_OPT_NOTFOUND, "r1", 0, 0, 0); } if (shtype == axial) { if (pdc_get_optvalues("r0", results, &r_0, NULL) == 1) pdc_warning(p->pdc, PDC_E_OPT_IGNORED, "r0", 0, 0, 0); if (pdc_get_optvalues("r1", results, &r_1, NULL) == 1) pdc_warning(p->pdc, PDC_E_OPT_IGNORED, "r1", 0, 0, 0); } if (shtype == radial || shtype == axial) { pdc_get_optvalues("extend0", results, &extend0, NULL); pdc_get_optvalues("extend1", results, &extend1, NULL); } pdc_cleanup_optionlist(p->pdc, results); if (p->shadings_number == p->shadings_capacity) pdf_grow_shadings(p); if (PDF_GET_STATE(p) == pdf_state_page) pdf_end_contents_section(p); /* Shading object */ p->shadings[p->shadings_number].obj_id = pdc_begin_obj(p->out, PDC_NEW_ID); pdc_begin_dict(p->out); /* Shading dict*/ pdc_printf(p->out, "/ShadingType %d\n", (int) shtype); pdc_printf(p->out, "/ColorSpace"); pdf_write_colorspace(p, color1.cs, pdc_false); pdc_puts(p->out, "\n"); if (antialias) pdc_printf(p->out, "/AntiAlias true\n"); switch (shtype) { case axial: /* Type 2 */ pdc_printf(p->out, "/Coords[%f %f %f %f]\n", x_0, y_0, x_1, y_1); if (extend0 || extend1) pdc_printf(p->out, "/Extend[%s %s]\n", extend0 ? "true" : "false", extend1 ? "true" : "false"); pdc_puts(p->out, "/Function"); pdf_write_function_dict(p, color0, &color1, N); break; case radial: /* Type 3 */ pdc_printf(p->out, "/Coords[%f %f %f %f %f %f]\n", x_0, y_0, r_0, x_1, y_1, r_1); if (extend0 || extend1) pdc_printf(p->out, "/Extend[%s %s]\n", extend0 ? "true" : "false", extend1 ? "true" : "false"); pdc_puts(p->out, "/Function"); pdf_write_function_dict(p, color0, &color1, N); break; default: break; } pdc_end_dict(p->out); /* Shading dict */ pdc_end_obj(p->out); /* Shading object */ if (PDF_GET_STATE(p) == pdf_state_page) pdf_begin_contents_section(p); retval = p->shadings_number; p->shadings_number++; return retval; }
void pdf__begin_font( PDF *p, const char *fontname, int len, pdc_scalar a, pdc_scalar b, pdc_scalar c, pdc_scalar d, pdc_scalar e, pdc_scalar f, const char *optlist) { static const char fn[] = "pdf__begin_font"; pdc_resopt *results; pdf_font tmpfont, *font; pdf_font_options fo; pdc_scalar det; pdc_clientdata cdata; int colorized = pdc_false; int metricsonly = pdc_false; int slot; if (fontname == NULL) pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "fontname", 0, 0, 0); /* Converting fontname */ fontname = pdf_convert_name(p, fontname, len, PDC_CONV_WITHBOM | PDC_CONV_TMPALLOC); if (fontname == NULL || *fontname == '\0') pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "fontname", 0, 0, 0); pdc_logg_cond(p->pdc, 1, trc_font, "\tBegin of Type3 font \"%s\"\n", fontname); /* error message prefix */ pdc_push_errmsg(p->pdc, PDF_E_T3_FONT_PREFIX, fontname, 0, 0, 0); /* look for an already existing font */ for (slot = 0; slot < p->fonts_number; slot++) { if (!pdc_strcmp(p->fonts[slot].apiname, fontname)) { if (p->fonts[slot].t3font->pass == 1) { pdc_logg_cond(p->pdc, 1, trc_font, "\tType3 font [%d] with metric definition found\n", slot); PDF_CHECK_STATE(p, pdf_state_document); p->fonts[slot].t3font->pass = 2; p->t3slot = slot; pdc_pop_errmsg(p->pdc); pdf_pg_suspend(p); PDF_SET_STATE(p, pdf_state_font); return; } pdc_error(p->pdc, PDF_E_T3_FONTEXISTS, 0, 0, 0, 0); } } 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); det = a*d - b*c; if (det == 0) 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); /* parsing optlist */ pdf_set_clientdata(p, &cdata); results = pdc_parse_optionlist(p->pdc, optlist, pdf_begin_font_options, &cdata, pdc_true); pdc_get_optvalues("colorized", results, &colorized, NULL); pdc_get_optvalues("widthsonly", results, &metricsonly, NULL); pdc_cleanup_optionlist(p->pdc, results); /* initialize font struct */ font = &tmpfont; pdf_init_font_options(p, &fo); pdf_init_font(p, font, &fo); /* * We store the new font in a font slot marked with "invalidenc" encoding. * When the font is used for the first time we modify the encoding. * Later uses will make a copy if the encoding is different. */ /* API font name */ font->apiname = pdc_strdup(p->pdc, fontname); font->ft.m.type = fnt_Type3; font->hasoriginal = pdc_true; font->ft.matrix.a = a; font->ft.matrix.b = b; font->ft.matrix.c = c; font->ft.matrix.d = d; font->ft.matrix.e = e; font->ft.matrix.f = f; font->t3font = (pdf_t3font*) pdc_malloc(p->pdc, sizeof(pdf_t3font), fn); pdf_init_t3font(p, font->t3font, T3GLYPHS_CHUNKSIZE); font->t3font->colorized = colorized; /* the resource id is needed until the font dict is written */ font->t3font->res_id = pdc_alloc_id(p->out); /* Now everything is fine, insert Type3 font with invalid encoding */ slot = pdf_insert_font(p, font); /* * We must store a pointer to the current font because its glyph * definitions may use other fonts and we would be unable to find * "our" current font again. This pointer lives throughout the * font definition, and will be reset in PDF_end_font() below. */ p->t3slot = slot; if (metricsonly) { font->t3font->pass = 1; pdc_logg_cond(p->pdc, 2, trc_font, "\t\tonly for metric definition\n"); } else { pdf_pg_suspend(p); } pdc_pop_errmsg(p->pdc); PDF_SET_STATE(p, pdf_state_font); if (!p->pdc->smokerun) pdc_logg_cond(p->pdc, 1, trc_api, "[Begin font %d]\n", p->t3slot); }