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); }
void pdf__add_nameddest( PDF *p, const char *name, int len, const char *optlist) { pdc_resopt *resopts = NULL; pdc_text_format hypertextformat = p->hypertextformat; pdc_encoding hypertextencoding; int hypertextcodepage; pdc_id obj_id = PDC_BAD_ID; char *name2 = NULL; pdf_dest *dest; int inum; len = pdc_check_text_length(p->pdc, &name, len, PDF_MAXSTRINGSIZE); if (!len) pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "name", 0, 0, 0); resopts = pdc_parse_optionlist(p->pdc, optlist, pdf_destination_options, NULL, 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); } pdc_cleanup_optionlist(p->pdc, resopts); /* create hypertext string */ name2 = pdf_convert_hypertext(p, name, len, hypertextformat, hypertextencoding, hypertextcodepage, &len, pdc_true, pdc_true); if (name2 == NULL || len == 0) pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "name", 0, 0, 0); /* parsing option list */ dest = pdf_parse_destination_optlist(p, optlist, 0, pdf_nameddest); /* interrupt the content stream if we are on a page */ if (PDF_GET_STATE(p) == pdf_state_page) pdf_end_contents_section(p); obj_id = pdc_begin_obj(p->out, PDC_NEW_ID); /* Dest object */ pdc_begin_dict(p->out); /* Destination dict */ pdc_puts(p->out, "/D"); pdf_write_destination(p, dest); pdc_end_dict(p->out); /* Destination dict */ pdc_end_obj(p->out); /* Dest object */ /* continue the contents stream */ if (PDF_GET_STATE(p) == pdf_state_page) pdf_begin_contents_section(p); pdf_cleanup_destination(p, dest); /* insert name in tree */ pdf_insert_name(p, name2, names_dests, obj_id); }
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; }
pdf_dest * pdf_parse_destination_optlist( PDF *p, const char *optlist, int page, pdf_destuse destuse) { int minpage; pdc_resopt *resopts; pdc_encoding hypertextencoding; int hypertextcodepage; const char *keyword; const char *type_name; char **strlist = NULL; int inum; pdc_bool boolval; /* Defaults */ pdf_dest *dest = pdf_init_destination(p); /* parse option list */ resopts = pdc_parse_optionlist(p->pdc, optlist, pdf_destination_options, NULL, pdc_true); if (pdc_get_optvalues("fitbbox", resopts, &boolval, NULL) && boolval == pdc_true) dest->type = fitvisible; if (pdc_get_optvalues("fitheight", resopts, &boolval, NULL) && boolval == pdc_true) dest->type = fitheight; if (pdc_get_optvalues("fitpage", resopts, &boolval, NULL) && boolval == pdc_true) dest->type = fitwindow; if (pdc_get_optvalues("fitwidth", resopts, &boolval, NULL) && boolval == pdc_true) dest->type = fitwidth; if (pdc_get_optvalues("retain", resopts, &boolval, NULL) && boolval == pdc_true) dest->type = fixed; if (pdc_get_optvalues("type", resopts, &inum, NULL)) dest->type = (pdf_desttype) inum; type_name = pdc_get_keyword(dest->type, pdf_type_keylist); hypertextencoding = pdf_get_hypertextencoding_opt(p, resopts, &hypertextcodepage, pdc_true); keyword = "name"; if (pdf_get_opt_textlist(p, keyword, resopts, hypertextencoding, hypertextcodepage, pdc_true, NULL, &dest->name, NULL)) { if (dest->type != nameddest) { dest->name = NULL; pdc_warning(p->pdc, PDF_E_HYP_OPTIGNORE_FORTYPE, keyword, type_name, 0, 0); } else pdc_save_lastopt(resopts, PDC_OPT_SAVE1ELEM); } keyword = "page"; if (pdc_get_optvalues(keyword, resopts, &page, NULL) && dest->type == filedest) pdc_warning(p->pdc, PDF_E_HYP_OPTIGNORE_FORTYPE, keyword, type_name, 0, 0); keyword = "group"; if (pdc_get_optvalues(keyword, resopts, NULL, &strlist)) { page = pdf_xlat_pageno(p, page, strlist[0]); } keyword = "zoom"; if (pdc_get_optvalues(keyword, resopts, &dest->zoom, NULL) && dest->type != fixed) pdc_warning(p->pdc, PDF_E_HYP_OPTIGNORE_FORTYPE, keyword, type_name, 0, 0); keyword = "left"; if (pdc_get_optvalues(keyword, resopts, &dest->left, NULL) && (dest->type == fitwindow || dest->type == fitwidth || dest->type == fitvisible || dest->type == fitvisiblewidth || dest->type == nameddest || dest->type == filedest)) pdc_warning(p->pdc, PDF_E_HYP_OPTIGNORE_FORTYPE, keyword, type_name, 0, 0); keyword = "right"; if (pdc_get_optvalues(keyword, resopts, &dest->right, NULL) && dest->type != fitrect) pdc_warning(p->pdc, PDF_E_HYP_OPTIGNORE_FORTYPE, keyword, type_name, 0, 0); keyword = "bottom"; if (pdc_get_optvalues(keyword, resopts, &dest->bottom, NULL) && dest->type != fitrect) pdc_warning(p->pdc, PDF_E_HYP_OPTIGNORE_FORTYPE, keyword, type_name, 0, 0); keyword = "top"; if (pdc_get_optvalues(keyword, resopts, &dest->top, NULL) && (dest->type == fitwindow || dest->type == fitheight || dest->type == fitvisible || dest->type == fitvisibleheight || dest->type == nameddest || dest->type == filedest)) pdc_warning(p->pdc, PDF_E_HYP_OPTIGNORE_FORTYPE, keyword, type_name, 0, 0); keyword = "color"; if (pdc_get_optvalues(keyword, resopts, &dest->color, NULL) && destuse != pdf_bookmark) pdc_warning(p->pdc, PDF_E_HYP_OPTIGNORE_FORELEM, keyword, 0, 0, 0); keyword = "fontstyle"; if (pdc_get_optvalues(keyword, resopts, &inum, NULL)) { dest->fontstyle = (fnt_fontstyle) inum; if (destuse != pdf_bookmark) pdc_warning(p->pdc, PDF_E_HYP_OPTIGNORE_FORELEM, keyword, 0, 0, 0); } keyword = "filename"; if (pdc_get_optvalues(keyword, resopts, NULL, NULL)) { if (dest->type != filedest) { pdc_warning(p->pdc, PDF_E_HYP_OPTIGNORE_FORTYPE, keyword, type_name, 0, 0); } else dest->filename = (char *) pdc_save_lastopt(resopts, PDC_OPT_SAVE1ELEM); } pdc_cleanup_optionlist(p->pdc, resopts); switch (dest->type) { case fitwidth: /* Trick: we don't know the height of a future page yet, * so we use a "large" value for top which will do for * most pages. If it doesn't work, not much harm is done. */ if (dest->top == -1) dest->top = 10000; break; case fitrect: case fitheight: case fitvisiblewidth: case fitvisibleheight: if (dest->left == -1) dest->left = 0; if (dest->bottom == -1) dest->bottom = 0; if (dest->right == -1) dest->right = 1000; if (dest->top == -1) dest->top = 1000; break; case nameddest: if (destuse == pdf_nameddest) { pdf_cleanup_destination(p, dest); pdc_error(p->pdc, PDC_E_OPT_ILLKEYWORD, "type", type_name, 0, 0); } if (dest->name == NULL) { pdf_cleanup_destination(p, dest); pdc_error(p->pdc, PDC_E_OPT_NOTFOUND, "name", 0, 0, 0); } break; case filedest: if (destuse != pdf_bookmark) { pdf_cleanup_destination(p, dest); pdc_error(p->pdc, PDC_E_OPT_ILLKEYWORD, "type", type_name, 0, 0); } if (dest->filename == NULL) { pdf_cleanup_destination(p, dest); pdc_error(p->pdc, PDC_E_OPT_NOTFOUND, "filename", 0, 0, 0); } break; default: break; } /* check for minpage */ minpage = (destuse == pdf_bookmark) ? 0 : 1; switch (destuse) { case pdf_nameddest: case pdf_locallink: if (page == 0) { page = pdf_current_page(p); } case pdf_openaction: case pdf_bookmark: case pdf_remotelink: if (page < minpage) { const char *stemp = pdc_errprintf(p->pdc, "%d", page); pdf_cleanup_destination(p, dest); pdc_error(p->pdc, PDC_E_ILLARG_HANDLE, "page", stemp, 0, 0); } break; } dest->pgnum = page; if (destuse != pdf_remotelink && destuse != pdf_openaction && page != 0) { dest->page = pdf_get_page_id(p, page); } /* remote page number */ if (destuse == pdf_remotelink) dest->remote_page = page; return dest; }