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); }
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; }