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_mbox * pdf_parse_mbox_optlist(PDF *p, const char *optlist) { static const char fn[] = "pdf_parse_mbox_optlist"; pdc_resopt *resopts = NULL; pdf_mbox *mbox; char **strlist = NULL; pdc_scalar margin; int i, ns; resopts = pdc_parse_optionlist(p->pdc, optlist, pdf_create_mbox_options, NULL, pdc_true); mbox = (pdf_mbox *) pdc_malloc(p->pdc, sizeof(pdf_mbox), fn); pdf_reclaim_mbox(mbox); if (pdc_get_optvalues("name", resopts, NULL, NULL)) mbox->name = (char *) pdc_save_lastopt(resopts, PDC_OPT_SAVE1ELEM); pdc_get_optvalues("boxheight", resopts, mbox->boxheight, NULL); if (pdc_get_optvalues("clipping", resopts, mbox->clipping, NULL)) { for (i = 0; i < 4; i++) mbox->percentclipping[i] = pdc_is_lastopt_percent(resopts, i) ? pdc_true : pdc_false; } pdc_get_optvalues("innerbox", resopts, &mbox->innerbox, NULL); pdc_get_optvalues("openrect", resopts, &mbox->openrect, NULL); ns = pdc_get_optvalues("fillcolor", resopts, NULL, &strlist); if (ns) pdf_parse_coloropt(p, "fillcolor", strlist, ns, (int) color_max, &mbox->fillcolor); pdf_init_coloropt(p, &mbox->strokecolor); ns = pdc_get_optvalues("strokecolor", resopts, NULL, &strlist); if (ns) pdf_parse_coloropt(p, "strokecolor", strlist, ns, (int) color_max, &mbox->strokecolor); pdc_get_optvalues("borderwidth", resopts, &mbox->borderwidth, NULL); mbox->dashlength = pdc_get_optvalues("dasharray", resopts, mbox->dasharray, NULL); pdc_get_optvalues("dashphase", resopts, &mbox->dashphase, NULL); pdc_get_optvalues("linecap", resopts, &mbox->linecap, NULL); pdc_get_optvalues("linejoin", resopts, &mbox->linejoin, NULL); pdc_get_optvalues("drawleft", resopts, &mbox->drawleft, NULL); pdc_get_optvalues("drawbottom", resopts, &mbox->drawbottom, NULL); pdc_get_optvalues("drawright", resopts, &mbox->drawright, NULL); pdc_get_optvalues("drawtop", resopts, &mbox->drawtop, NULL); if (pdc_get_optvalues("margin", resopts, &margin, NULL)) { mbox->offsetleft = margin; mbox->percentleft = pdc_is_lastopt_percent(resopts, 0); mbox->offsetbottom = margin; mbox->percentbottom = pdc_is_lastopt_percent(resopts, 0); mbox->offsetright = -margin; mbox->percentright = pdc_is_lastopt_percent(resopts, 0); mbox->offsettop = -margin; mbox->percenttop = pdc_is_lastopt_percent(resopts, 0); } if (pdc_get_optvalues("offsetleft", resopts, &mbox->offsetleft, NULL)) { mbox->percentleft = pdc_is_lastopt_percent(resopts, 0); } if (pdc_get_optvalues("offsetbottom", resopts, &mbox->offsetbottom, NULL)) { mbox->percentbottom = pdc_is_lastopt_percent(resopts, 0); } if (pdc_get_optvalues("offsetright", resopts, &mbox->offsetright, NULL)) { mbox->percentright = pdc_is_lastopt_percent(resopts, 0); } if (pdc_get_optvalues("offsettop", resopts, &mbox->offsettop, NULL)) { mbox->percenttop = pdc_is_lastopt_percent(resopts, 0); } pdc_cleanup_optionlist(p->pdc, resopts); return mbox; }