int pdf__shading_pattern(PDF *p, int shading, const char *optlist) { pdc_resopt *results; pdc_clientdata data; int gstate = -1; int retval = -1; if (p->compatibility == PDC_1_3) pdc_error(p->pdc, PDF_E_SHADING13, 0, 0, 0, 0); pdf_check_handle(p, shading, pdc_shadinghandle); if (optlist && strlen(optlist)) { pdf_set_clientdata(p, &data); results = pdc_parse_optionlist(p->pdc, optlist, pdf_shading_pattern_options, &data, pdc_true); (void) pdc_get_optvalues("gstate", results, &gstate, NULL); pdc_cleanup_optionlist(p->pdc, results); } if (p->pattern_number == p->pattern_capacity) pdf_grow_pattern(p); if (PDF_GET_STATE(p) == pdf_state_page) pdf_end_contents_section(p); /* Pattern object */ p->pattern[p->pattern_number].obj_id = pdc_begin_obj(p->out, PDC_NEW_ID); /* Shadings don't have a painttype, but this signals to the * code which writes the pattern usage that no color values * will be required when setting the pattern color space. */ p->pattern[p->pattern_number].painttype = 1; pdc_begin_dict(p->out); /* Pattern dict*/ pdc_puts(p->out, "/PatternType 2\n"); /* shading pattern */ pdc_objref(p->out, "/Shading", p->shadings[shading].obj_id); p->shadings[shading].used_on_current_page = pdc_true; if (gstate != -1) pdc_objref(p->out, "/ExtGState", pdf_get_gstate_id(p, gstate)); pdc_end_dict(p->out); /* Pattern dict*/ pdc_end_obj(p->out); /* Pattern object */ if (PDF_GET_STATE(p) == pdf_state_page) pdf_begin_contents_section(p); retval = p->pattern_number; p->pattern_number++; return retval; }
int pdf__create_action(PDF *p, const char *type, const char *optlist) { pdc_resopt *resopts = NULL; pdc_clientdata data; pdf_action *action; pdf_actiontype atype; pdf_dest *dest = NULL; pdc_bool verbose = pdc_true; pdc_bool hasdest = pdc_false; pdc_encoding htenc; int htcp; const char *keyword; char **strlist; int i, k, ns; if (type == NULL || *type == '\0') pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "type", 0, 0, 0); k = pdc_get_keycode_ci(type, pdf_action_pdfkeylist); if (k == PDC_KEY_NOTFOUND) pdc_error(p->pdc, PDC_E_ILLARG_STRING, "type", type, 0, 0); atype = (pdf_actiontype) k; if (atype == pdf_javascript) pdc_error(p->pdc, PDF_E_UNSUPP_JAVASCRIPT, 0, 0, 0, 0); /* compatibility */ if (p->compatibility < PDC_1_6 && atype == pdf_goto3dview) { pdc_error(p->pdc, PDC_E_PAR_VERSION, type, pdc_get_pdfversion(p->pdc, PDC_1_6), 0, 0); } if (p->compatibility < PDC_1_5 && (atype == pdf_setocgstate || atype == pdf_trans)) { pdc_error(p->pdc, PDC_E_PAR_VERSION, type, pdc_get_pdfversion(p->pdc, PDC_1_5), 0, 0); } /* new action */ action = pdf_new_action(p); action->atype = atype; /* Parsing option list */ pdf_set_clientdata(p, &data); resopts = pdc_parse_optionlist(p->pdc, optlist, pdf_create_action_options, &data, pdc_true); keyword = "actionwarning"; pdc_get_optvalues(keyword, resopts, &verbose, NULL); verbose = pdf_get_errorpolicy(p, resopts, verbose); htenc = pdf_get_hypertextencoding_opt(p, resopts, &htcp, pdc_true); keyword = "destination"; if (pdc_get_optvalues(keyword, resopts, NULL, &strlist)) { if (!pdf_opt_effectless(p, keyword, atype, (pdf_actiontype) (pdf_goto | pdf_gotor))) { action->dest = pdf_parse_destination_optlist(p, strlist[0], (atype == pdf_goto) ? 0 : 1, (atype == pdf_goto) ? pdf_locallink : pdf_remotelink); hasdest = pdc_true; } } else { keyword = "destname"; if (atype == pdf_goto || atype == pdf_gotor) dest = pdf_get_option_destname(p, resopts, htenc, htcp); else if (pdc_get_optvalues(keyword, resopts, NULL, NULL)) pdf_opt_effectless(p, keyword, atype, (pdf_actiontype) (pdf_goto | pdf_gotor)); if (dest) { action->dest = dest; hasdest = pdc_true; } } /* filename or url */ for (i = 0; ; i++) { keyword = pdf_filename_keylist[i].word; if (keyword == NULL) break; if (!pdc_get_optvalues(keyword, resopts, NULL, NULL) || pdf_opt_effectless(p, keyword, atype, (pdf_actiontype) pdf_filename_keylist[i].code)) continue; /* DON'T change order */ /* native filename */ if (!i) action->nativefilename = pdf_get_opt_filename(p, keyword, resopts, htenc, htcp); /* Unicode filename */ pdf_get_opt_textlist(p, keyword, resopts, htenc, htcp, pdc_true, NULL, &action->filename, NULL); pdc_save_lastopt(resopts, PDC_OPT_SAVE1ELEM); } keyword = "parameters"; if (pdc_get_optvalues(keyword, resopts, NULL, NULL) && !pdf_opt_effectless(p, keyword, atype, pdf_launch)) action->parameters = (char *) pdc_save_lastopt(resopts, PDC_OPT_SAVE1ELEM); keyword = "operation"; if (pdc_get_optvalues(keyword, resopts, &k, NULL) && !pdf_opt_effectless(p, keyword, atype, (pdf_actiontype) (pdf_launch | pdf_movie))) { if ((atype == pdf_launch && k >= PDF_MIN_MOVIEKEY) || (atype == pdf_movie && k < PDF_MIN_MOVIEKEY)) { pdc_error(p->pdc, PDC_E_OPT_ILLKEYWORD, keyword, pdc_get_keyword(k, pdf_operation_pdfkeylist), 0, 0); } action->operation = (char *) pdc_get_keyword(k, pdf_operation_pdfkeylist); } keyword = "defaultdir"; if (pdc_get_optvalues(keyword, resopts, NULL, NULL) && !pdf_opt_effectless(p, keyword, atype, pdf_launch)) action->defaultdir = (char *) pdc_save_lastopt(resopts, PDC_OPT_SAVE1ELEM); keyword = "menuname"; if (pdc_get_optvalues(keyword, resopts, NULL, NULL) && !pdf_opt_effectless(p, keyword, atype, pdf_named)) { action->menuname = (char *) pdc_save_lastopt(resopts, PDC_OPT_SAVE1ELEM); } keyword = "namelist"; ns = pdc_get_optvalues(keyword, resopts, NULL, NULL); if (ns && !pdf_opt_effectless(p, keyword, atype, (pdf_actiontype) (pdf_hide | pdf_submitform | pdf_resetform))) { action->namelist = (char **) pdc_save_lastopt(resopts, PDC_OPT_SAVEALL); action->nsnames = ns; } keyword = "exportmethod"; if (pdc_get_optvalues(keyword, resopts, &k, NULL)) { action->exportmethod = (pdf_exportmethod) k; if (!pdf_opt_effectless(p, keyword, atype, pdf_submitform)) { if ((action->exportmethod & pdf_exp_fdf && (action->exportmethod | pdf_allfdf) != pdf_allfdf) || (action->exportmethod & pdf_exp_html && (action->exportmethod | pdf_allhtml) != pdf_allhtml) || (action->exportmethod & pdf_exp_xfdf && (action->exportmethod | pdf_allxfdf) != pdf_allxfdf) || (action->exportmethod & pdf_exp_pdf && (action->exportmethod | pdf_allpdf) != pdf_allpdf)) { pdc_error(p->pdc, PDC_E_OPT_ILLCOMB, keyword, 0, 0, 0); } if (action->exportmethod & pdf_exp_fdf) action->exportmethod = (pdf_exportmethod) (action->exportmethod & ~pdf_exp_fdf); } } keyword = "newwindow"; if (pdc_get_optvalues(keyword, resopts, &action->newwindow, NULL)) pdf_opt_effectless(p, keyword, atype, (pdf_actiontype) (pdf_gotor | pdf_launch)); keyword = "ismap"; if (pdc_get_optvalues(keyword, resopts, &action->ismap, NULL)) pdf_opt_effectless(p, keyword, atype, pdf_uri); keyword = "hide"; if (pdc_get_optvalues(keyword, resopts, &action->hide, NULL)) pdf_opt_effectless(p, keyword, atype, pdf_hide); keyword = "exclude"; if (pdc_get_optvalues(keyword, resopts, &action->exclude, NULL)) pdf_opt_effectless(p, keyword, atype, (pdf_actiontype) (pdf_submitform | pdf_resetform)); keyword = "submitemptyfields"; if (pdc_get_optvalues(keyword, resopts, &action->submitemptyfields, NULL)) pdf_opt_effectless(p, keyword, atype, pdf_submitform); keyword = "canonicaldate"; if (pdc_get_optvalues(keyword, resopts, &action->canonicaldate, NULL)) pdf_opt_effectless(p, keyword, atype, pdf_submitform); keyword = "transition"; if (pdc_get_optvalues(keyword, resopts, &action->transition, NULL)) pdf_opt_effectless(p, keyword, atype, pdf_trans); keyword = "duration"; if (pdc_get_optvalues(keyword, resopts, &action->duration, NULL)) pdf_opt_effectless(p, keyword, atype, pdf_trans); /* required options */ keyword = NULL; if (!hasdest && (atype == pdf_goto || atype == pdf_gotor)) keyword = "destination"; if (!action->filename && (atype == pdf_gotor || atype == pdf_launch || atype == pdf_importdata)) keyword = "filename"; if (!action->menuname && atype == pdf_named) keyword = "menuname"; if (!action->namelist && atype == pdf_hide) keyword = "namelist"; if (!action->filename && (atype == pdf_uri || atype == pdf_submitform)) keyword = "url"; if (keyword) pdc_error(p->pdc, PDC_E_OPT_NOTFOUND, keyword, 0, 0, 0); return pdf_get_max_action(p); }
pdc_bool pdf_parse_and_write_actionlist(PDF *p, pdf_event_object eventobj, pdc_id *act_idlist, const char *optlist) { const pdc_defopt *defopttable = NULL; const pdc_keyconn *keyconntable = NULL; pdc_resopt *resopts = NULL; pdc_clientdata data; pdc_id ret_id = PDC_BAD_ID; pdf_action *action = NULL; pdc_bool calcevent = pdc_false; const char *keyword, *type; char **strlist; int *actlist; int i, code, nsact, beginjava = 0; switch(eventobj) { case event_annotation: defopttable = pdf_annotevent_options; keyconntable = pdf_annotevent_keylist; beginjava = pdf_annotevent_beginjava; break; case event_bookmark: defopttable = pdf_bookmarkevent_options; keyconntable = pdf_bookmarkevent_keylist; beginjava = pdf_bookmarkevent_beginjava; break; case event_document: defopttable = pdf_documentevent_options; keyconntable = pdf_documentevent_keylist; beginjava = pdf_documentevent_beginjava; break; case event_page: defopttable = pdf_pageevent_options; keyconntable = pdf_pageevent_keylist; beginjava = pdf_pageevent_beginjava; break; default: break; } /* parsing option list */ pdf_set_clientdata(p, &data); resopts = pdc_parse_optionlist(p->pdc, optlist, defopttable, &data, pdc_true); /* write actions and saving action ids */ for (code = 0; ; code++) { keyword = pdc_get_keyword(code, keyconntable); if (keyword) { nsact = pdc_get_optvalues(keyword, resopts, NULL, &strlist); actlist = (int *) strlist; /* Not activate event */ if (code && nsact) { /* additional action type check */ for (i = 0; i < nsact; i++) { action = (pdf_action *) &pdc_vtr_at(p->actions, actlist[i], pdf_action); if (code >= beginjava && action->atype != pdf_javascript) { type = pdc_get_keyword(action->atype, pdf_action_pdfkeylist); pdc_error(p->pdc, PDF_E_ACT_BADACTTYPE, type, keyword, 0, 0); } } /* saving calculation event */ if (!strcmp(keyword, "calculate")) calcevent = pdc_true; } /* write action objects */ if (act_idlist != NULL) { ret_id = PDC_BAD_ID; if (nsact == 1) { action = (pdf_action *) &pdc_vtr_at(p->actions, actlist[0], pdf_action); if (action->obj_id == PDC_BAD_ID) ret_id = pdf_write_action(p, action, ret_id); else ret_id = action->obj_id; } else if (nsact > 1) { for (i = nsact-1; i >= 0; i--) { action = (pdf_action *) &pdc_vtr_at(p->actions, actlist[i], pdf_action); ret_id = pdf_write_action(p, action, ret_id); } } act_idlist[code] = ret_id; } } else break; } return calcevent; }
int pdf__create_bookmark(PDF *p, const char *text, int len, const char *optlist) { pdc_resopt *resopts = NULL; pdc_clientdata data; pdf_outline self; pdf_dest *dest = NULL; pdc_text_format hypertextformat; pdc_encoding hypertextencoding; pdf_coloropt textcolor; char *hypertext = NULL; const char *keyword = NULL; char **strlist = NULL; int hypertextcodepage; int ns, inum, outlen, retval = 0; int jndex = -2; len = pdc_check_text_length(p->pdc, &text, len, PDF_MAXSTRINGSIZE); if (!len) pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "text", 0, 0, 0); /* Initialize */ pdf_init_outline(p, &self); hypertextformat = p->hypertextformat; hypertextencoding = p->hypertextencoding; hypertextcodepage = p->hypertextcodepage; /* Parsing option list */ if (optlist && strlen(optlist)) { pdf_set_clientdata(p, &data); resopts = pdc_parse_optionlist(p->pdc, optlist, pdf_create_bookmark_options, &data, pdc_true); hypertextencoding = pdf_get_hypertextencoding_opt(p, resopts, &hypertextcodepage, pdc_true); if (pdc_get_optvalues("hypertextformat", resopts, &inum, NULL)) { hypertextformat = (pdc_text_format) inum; pdf_check_hypertextformat(p, hypertextformat); } ns = pdc_get_optvalues("textcolor", resopts, NULL, &strlist); if (ns) { pdf_parse_coloropt(p, "textcolor", strlist, ns, (int) color_rgb, &textcolor); self.textcolor[0] = textcolor.value[0]; self.textcolor[1] = textcolor.value[1]; self.textcolor[2] = textcolor.value[2]; } if (pdc_get_optvalues("fontstyle", resopts, &inum, NULL)) self.fontstyle = (fnt_fontstyle) inum; pdc_get_optvalues("parent", resopts, &self.parent, NULL); pdc_get_optvalues("index", resopts, &jndex, NULL); pdc_get_optvalues("open", resopts, &self.open, NULL); if (pdc_get_optvalues("destination", resopts, NULL, &strlist)) { self.dest = pdf_parse_destination_optlist(p, strlist[0], 0, pdf_bookmark); keyword = "destination"; } else { dest = pdf_get_option_destname(p, resopts, hypertextencoding, hypertextcodepage); if (dest) { self.dest = dest; keyword = "destname"; } } if (pdc_get_optvalues("action", resopts, NULL, &strlist)) { if (self.dest) { pdf_cleanup_destination(p, self.dest); self.dest = NULL; pdc_warning(p->pdc, PDC_E_OPT_IGNORE, keyword, "action", 0, 0); } /* parsing of action list */ pdf_parse_and_write_actionlist(p, event_bookmark, NULL, (const char *) strlist[0]); self.action = (char *) pdc_save_lastopt(resopts, PDC_OPT_SAVE1ELEM); } pdc_cleanup_optionlist(p->pdc, resopts); } /* create hypertext string */ hypertext = pdf_convert_hypertext(p, text, len, hypertextformat, hypertextencoding, hypertextcodepage, &outlen, PDC_UTF8_FLAG, pdc_true); if (hypertext) retval = pdf_insert_bookmark(p, hypertext, &self, jndex); 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); }
int pdf__create_gstate(PDF *p, const char *optlist) { pdf_extgstateresource *gs; int slot = -1; int font = pdc_undef; int inum; pdc_clientdata data; pdc_resopt *results; if (optlist == NULL || !*optlist) pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "optlist", 0, 0, 0); slot = p->extgstates_number; if (slot == p->extgstates_capacity) pdf_grow_extgstates(p); p->extgstates_number++; gs = &p->extgstates[slot]; gs->obj_id = pdc_alloc_id(p->out); /* parsing optlist */ pdf_set_clientdata(p, &data); results = pdc_parse_optionlist(p->pdc, optlist, pdf_create_gstate_options, &data, pdc_true); pdc_get_optvalues("alphaisshape", results, &gs->alpha_is_shape, NULL); if (pdc_get_optvalues("blendmode", results, &inum, NULL)) gs->blendmode = (pdf_blendmode) inum; gs->dash_count = pdc_get_optvalues("dasharray", results, NULL, NULL); gs->dash_array = (pdc_scalar *) pdc_save_lastopt(results, PDC_OPT_SAVEALL); pdc_get_optvalues("dashphase", results, &gs->dash_phase, NULL); pdc_get_optvalues("flatness", results, &gs->flatness, NULL); pdc_get_optvalues("font", results, &font, NULL); if (font != pdc_undef) gs->font_obj = p->fonts[font].obj_id; pdc_get_optvalues("fontsize", results, &gs->font_size, NULL); pdc_get_optvalues("linecap", results, &gs->line_cap, NULL); pdc_get_optvalues("linejoin", results, &gs->line_join, NULL); pdc_get_optvalues("linewidth", results, &gs->line_width, NULL); pdc_get_optvalues("miterlimit", results, &gs->miter_limit, NULL); pdc_get_optvalues("opacityfill", results, &gs->opacity_fill, NULL); pdc_get_optvalues("opacitystroke", results, &gs->opacity_stroke, NULL); pdc_get_optvalues("overprintfill", results, &gs->overprint_fill, NULL); pdc_get_optvalues("overprintmode", results, &gs->overprint_mode, NULL); pdc_get_optvalues("overprintstroke", results, &gs->overprint_stroke, NULL); if (pdc_get_optvalues("renderingintent", results, &inum, NULL)) gs->ri = (pdf_renderingintent) inum; pdc_get_optvalues("smoothness", results, &gs->smoothness, NULL); pdc_get_optvalues("strokeadjust", results, &gs->stroke_adjust, NULL); pdc_get_optvalues("textknockout", results, &gs->text_knockout, NULL); pdc_cleanup_optionlist(p->pdc, results); return slot; }