/* hypertext conversion for deprecated functions */ char * pdf_convert_hypertext_depr(PDF *p, const char *text, int len) { int outlen; pdf_get_hypertextencoding_param(p, NULL); return pdf_convert_hypertext(p, text, len, p->hypertextformat, p->hypertextencoding, p->hypertextcodepage, &outlen, PDC_UTF8_FLAG, pdc_true); }
pdf_dest * pdf_get_option_destname(PDF *p, pdc_resopt *resopts, pdc_encoding hypertextencoding, int hypertextcodepage) { pdc_text_format hypertextformat = pdc_bytes; pdf_dest *dest = NULL; char **strlist; int outlen; if (pdc_get_optvalues("destname", resopts, NULL, &strlist)) { dest = pdf_init_destination(p); dest->type = nameddest; if (pdc_is_lastopt_utf8(resopts)) hypertextformat = PDC_UTF8; dest->name = pdf_convert_hypertext(p, strlist[0], 0, hypertextformat, hypertextencoding, hypertextcodepage, &outlen, PDC_UTF8_FLAG, pdc_true); } return dest; }
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__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); }