PDFLIB_API void PDFLIB_CALL PDF_setdashpattern(PDF *p, const char *optlist) { static const char fn[] = "PDF_setdashpattern"; pdc_resopt *results; float *darray, phase; int length; if (!pdf_enter_api(p, fn, pdf_state_content, "(p[%p], \"%s\")\n", (void *) p, optlist)) return; /* parsing optlist */ results = pdc_parse_optionlist(p->pdc, optlist, pdf_dashoptions, NULL, pdc_true); length = pdc_get_optvalues(p->pdc, "dasharray", results, NULL, (void **) &darray); phase = (float) 0.0; (void) pdc_get_optvalues(p->pdc, "dashphase", results, &phase, NULL); pdc_cleanup_optionlist(p->pdc, results); pdf__setdashpattern(p, darray, length, phase); if (darray) pdc_free(p->pdc, darray); }
int pdc_get_opt_utf8strings(pdc_core *pdc, const char *keyword, pdc_resopt *resopt, int flags, char ***strings) { int ns = pdc_get_optvalues(keyword, resopt, NULL, strings); if (ns) { if (pdc_is_lastopt_utf8(resopt)) { int i = resopt[0].lastind; pdc_resopt *ropt = &resopt[i]; char **s = (char **) ropt->val; int j; for (j = 0; j < ropt->num; j++) { char *sb = pdc_strdup_withbom(pdc, s[j]); if (s[j] != NULL) pdc_free(pdc, s[j]); s[j] = sb; } } pdc_save_lastopt(resopt, flags); } return ns; }
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; }
void pdf__setdashpattern(PDF *p, const char *optlist) { pdc_resopt *results; char **strlist; pdc_scalar *darray = NULL, phase = 0; int length; /* parsing optlist */ results = pdc_parse_optionlist(p->pdc, optlist, pdf_dashoptions, NULL, pdc_true); length = pdc_get_optvalues("dasharray", results, NULL, &strlist); darray = (pdc_scalar *) strlist; pdc_get_optvalues("dashphase", results, &phase, NULL); pdf_setdashpattern_internal(p, darray, length, phase); pdc_cleanup_optionlist(p->pdc, results); }
pdc_bool pdf_get_errorpolicy(PDF *p, pdc_resopt *resopts, pdc_bool verbose) { int errpol = (int) p->errorpolicy; if (resopts != NULL) pdc_get_optvalues("errorpolicy", resopts, &errpol, NULL); if (errpol != (int) errpol_legacy) verbose = errpol; return verbose; }
void pdf__create_pvf(PDF *p, const char *filename, int reserved, const void *data, size_t size, const char *optlist) { static const char fn[] = "pdf__create_pvf"; pdc_bool iscopy = pdc_false; pdf_virtfile *vfile, *lastvfile = NULL; pdc_resopt *results; (void) reserved; /* Parse optlist */ results = pdc_parse_optionlist(p->pdc, optlist, pdf_create_pvf_options, NULL, pdc_true); pdc_get_optvalues(p->pdc, "copy", results, &iscopy, NULL); pdc_cleanup_optionlist(p->pdc, results); /* Find virtual file in file system */ vfile = pdf_find_pvf(p, filename, &lastvfile); /* Name already exists */ if (vfile != NULL) pdc_error(p->pdc, PDC_E_PVF_NAMEEXISTS, filename, 0, 0, 0); /* New virtual file */ vfile = (pdf_virtfile *) pdc_calloc(p->pdc, sizeof(pdf_virtfile), fn); if (lastvfile) lastvfile->next = vfile; else p->filesystem = vfile; /* Fill up file struct */ vfile->name = pdc_strdup(p->pdc, filename); if (iscopy == pdc_true) { vfile->data = (const void *) pdc_malloc(p->pdc, size, fn); memcpy((void *) vfile->data, data, size); } else { vfile->data = data; } vfile->size = size; vfile->iscopy = iscopy; vfile->lockcount = 0; vfile->next = NULL; }
const char * pdc_get_opt_filename(pdc_core *pdc, const char *keyword, pdc_resopt *resopts) { const char *filename = NULL; char **strlist; if (pdc_get_optvalues(keyword, resopts, NULL, &strlist)) { pdc_bool isutf8 = pdc_is_lastopt_utf8(resopts); int flags = PDC_CONV_WITHBOM; if (isutf8) flags |= PDC_CONV_ISUTF8; filename = pdc_convert_filename(pdc, strlist[0], 0, keyword, flags); } return filename; }
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; }
pdc_encoding pdf_get_hypertextencoding_opt(PDF *p, pdc_resopt *resopts, int *codepage, pdc_bool verbose) { char **strlist; pdc_encoding htenc; if (pdc_get_optvalues("hypertextencoding", resopts, NULL, &strlist)) { int cp; htenc = pdf_get_hypertextencoding(p, strlist[0], &cp, verbose); pdf_check_hypertextencoding(p, htenc); if (codepage) *codepage = cp; } else { htenc = pdf_get_hypertextencoding_param(p, codepage); } return htenc; }
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; }
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_get_opt_textlist(PDF *p, const char *keyword, pdc_resopt *resopts, pdc_encoding enc, int codepage, pdc_bool ishypertext, const char *fieldname, char **text, char ***textlist) { pdc_bool logg1 = pdc_logg_is_enabled(p->pdc, 1, trc_optlist); int ns; char **strlist; ns = pdc_get_optvalues(keyword, resopts, NULL, &strlist); if (ns) { pdc_byte *string = NULL; pdc_encodingvector *inev = NULL, *outev = NULL; pdc_text_format intextformat = pdc_bytes; pdc_text_format outtextformat = pdc_utf16be; pdc_text_format textformat; int convflags = PDC_CONV_WITHBOM; pdc_bool isutf8; int i, outlen; /* whole option list or string list is in UTF-8 */ isutf8 = pdc_is_lastopt_utf8(resopts); /* Encoding */ if (ishypertext) { /* Initialize */ if (!isutf8) { if (enc < 0 && enc != pdc_unicode && enc != pdc_cid) enc = pdf_get_hypertextencoding(p, "auto", &codepage, pdc_true); if (enc >= 0) inev = pdc_get_encoding_vector(p->pdc, enc); } outev = pdc_get_encoding_vector(p->pdc, pdc_pdfdoc); /* conversion to PDFDocEncoding if possible */ convflags |= PDC_CONV_TRYBYTES; } else { if (enc == pdc_invalidenc) { if (fieldname) { pdc_cleanup_optionlist(p->pdc, resopts); pdc_error(p->pdc, PDF_E_FF_FONTMISSING, fieldname, 0, 0, 0); } return 0; } else if (enc >= 0 && !isutf8) { /* bug #2069: always conversion to UTF-16BE */ inev = pdc_get_encoding_vector(p->pdc, enc); } } if (logg1) { if (isutf8) { pdc_logg(p->pdc, "\tOption \"%s\" is "PDC_UTF8_STRG" encoded\n", keyword); } else { pdc_logg(p->pdc, "\tOption \"%s\" is %s encoded\n", keyword, pdc_get_user_encoding(p->pdc, enc)); } } for (i = 0; i < ns; i++) { string = (pdc_byte *) strlist[i]; { if (ishypertext || isutf8 || inev != NULL) { intextformat = isutf8 ? PDC_UTF8 : pdc_bytes; if (pdc_logg_is_enabled(p->pdc, 3, trc_text)) convflags |= PDC_CONV_LOGGING; pdf_set_convertflags(p, &convflags); textformat = outtextformat; pdc_convert_string(p->pdc, intextformat, codepage, inev, string, (int) strlen((char *) string), &textformat, outev, &string, &outlen, convflags, pdc_true); pdc_free(p->pdc, strlist[i]); strlist[i] = (char *) string; } } } if (text) *text = strlist[0]; else *textlist = strlist; if (fieldname) { strlist = (char **) pdc_save_lastopt(resopts, PDC_OPT_SAVEALL); pdf_insert_stringlist(p, strlist, ns); } } return ns; }
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); }
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; }
void pdf_get_fit_options(PDF *p, pdc_bool fortflow, pdf_fit_options *fit, pdc_resopt *resopts) { char **strlist = NULL; int inum; (void) fortflow; if (pdc_get_optvalues("fitmethod", resopts, &inum, NULL)) { fit->fitmethod = (pdc_fitmethod) inum; fit->mask |= (1L << fit_fitmethod); } if (pdc_get_optvalues("rotate", resopts, &fit->rotate, NULL)) fit->mask |= (1L << fit_rotate); if (pdc_get_optvalues("orientate", resopts, &fit->orientate, NULL)) fit->mask |= (1L << fit_orientate); pdc_get_optvalues("showborder", resopts, &fit->showborder, NULL); if (fit->flags & is_textline) { inum = pdc_get_optvalues("margin", resopts, fit->margin, NULL); if (inum) { if (inum == 1) fit->margin[1] = fit->margin[0]; fit->mask |= (1L << fit_margin); } if (pdc_get_optvalues("alignchar", resopts, &inum, NULL)) { fit->alignchar = (pdc_ushort) inum; fit->mask |= (1L << fit_alignchar); } } if (fit->flags & is_block) { if (pdc_get_optvalues("refpoint", resopts, fit->refpoint, NULL)) fit->mask |= (1L << fit_refpoint); } if (fit->flags & is_block || !(fit->flags & is_textflow)) { if (pdc_get_optvalues("boxsize", resopts, fit->boxsize, NULL)) fit->mask |= (1L << fit_boxsize); if (pdc_get_optvalues("shrinklimit", resopts, &fit->shrinklimit, NULL)) fit->mask |= (1L << fit_shrinklimit); inum = pdc_get_optvalues("position", resopts, fit->position, NULL); if (inum) { pdf_set_position_values(p, fit->position, inum); fit->mask |= (1L << fit_position); } if (pdc_get_optvalues("matchbox", resopts, NULL, &strlist)) { fit->matchbox = pdf_parse_mbox_optlist(p, strlist[0]); fit->mask |= (1L << fit_matchbox); } } }
char * pdf_get_opt_filename(PDF *p, const char *keyword, pdc_resopt *resopts, pdc_encoding enc, int codepage) { pdc_bool logg1 = pdc_logg_is_enabled(p->pdc, 1, trc_optlist); pdc_bool logg3 = pdc_logg_is_enabled(p->pdc, 3, trc_text); pdc_byte *filename = NULL; char **strlist; if (pdc_get_optvalues(keyword, resopts, NULL, &strlist)) { pdc_encodingvector *inev = NULL, *outev = NULL; pdc_text_format intextformat = pdc_bytes; pdc_text_format outtextformat = pdc_utf16; /* sic! */ int convflags = PDC_CONV_NOBOM | PDC_CONV_TRYBYTES | PDC_CONV_NEWALLOC; pdc_bool isutf8; int ic, outlen; /* whole option list or string list is in UTF-8 */ isutf8 = pdc_is_lastopt_utf8(resopts); if (!isutf8) { if (enc < 0 && enc != pdc_unicode && enc != pdc_cid) enc = pdf_get_hypertextencoding(p, "auto", &codepage, pdc_true); if (enc >= 0) inev = pdc_get_encoding_vector(p->pdc, enc); } else { intextformat = PDC_UTF8; } if (logg1) { if (isutf8) { pdc_logg(p->pdc, "\tOption \"%s\" is "PDC_UTF8_STRG" encoded\n", keyword); } else { pdc_logg(p->pdc, "\tOption \"%s\" is %s encoded\n", keyword, pdc_get_user_encoding(p->pdc, enc)); } } outev = pdc_get_encoding_vector(p->pdc, pdc_winansi); if (logg3) convflags |= PDC_CONV_LOGGING; pdf_set_convertflags(p, &convflags); pdc_convert_string(p->pdc, intextformat, codepage, inev, (pdc_byte *) strlist[0], (int) strlen(strlist[0]), &outtextformat, outev, &filename, &outlen, convflags, pdc_true); if (outtextformat == pdc_utf16) { pdc_ushort uv, *unifilename = (pdc_ushort *) filename; int code; if (p->compatibility < PDC_1_7) pdc_error(p->pdc, PDC_E_IO_UNSUPP_PDFUNINAME, 0, 0, 0, 0); /* we must replace non-WinAnsi characters by period * and omit the BOM to get a WinAnsi string. */ outlen /= 2; for (ic = 0; ic < outlen; ic++) { uv = unifilename[ic]; code = pdc_get_encoding_bytecode(p->pdc, outev, uv); if (code <= 0) uv = PDC_UNICODE_PERIOD; filename[ic] = (char) uv; } filename[ic] = 0; } if (logg3) pdc_logg_hexdump(p->pdc, "output filename", "\t\t", (char *) filename, strlen((char *) filename)); } return (char *) filename; }
void pdf__begin_font( PDF *p, const char *fontname, float a, float b, float c, float d, float e, float f, const char *optlist) { static const char fn[] = "pdf__begin_font"; pdc_resopt *results; pdc_font *font; float det; int colorized = pdc_false; int slot; /* parsing optlist */ results = pdc_parse_optionlist(p->pdc, optlist, pdf_begin_font_options, NULL, pdc_true); pdc_get_optvalues(p->pdc, "colorized", results, &colorized, NULL); pdc_cleanup_optionlist(p->pdc, results); 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); /* look for an already existing font */ for (slot = 0; slot < p->fonts_number; slot++) { if (!strcmp(p->fonts[slot].apiname, fontname)) { pdc_error(p->pdc, PDF_E_T3_FONTEXISTS, fontname, 0, 0, 0); } } PDF_SET_STATE(p, pdf_state_font); pdf_init_tstate(p); pdf_init_gstate(p); pdf_init_cstate(p); /* slot for new font struct */ slot = pdf_init_newfont(p); font = &p->fonts[slot]; p->fonts_number++; /* * 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. */ font->type = pdc_Type3; font->obj_id = pdc_alloc_id(p->out); font->name = NULL; font->apiname = pdc_strdup(p->pdc, fontname); font->encoding = pdc_invalidenc; /* initially there is no encoding */ font->widths = (int *) pdc_calloc(p->pdc, font->numOfCodes * sizeof(int), fn); font->t3font = (pdc_t3font*) pdc_malloc(p->pdc, sizeof(pdc_t3font), fn); pdf_init_t3font_struct(p, font->t3font, T3GLYPHS_CHUNKSIZE); font->t3font->fontname = pdc_strdup(p->pdc, fontname); font->t3font->colorized = colorized; /* the resource id is needed until the font dict is written */ font->t3font->res_id = pdc_alloc_id(p->out); font->t3font->matrix.a = a; font->t3font->matrix.b = b; font->t3font->matrix.c = c; font->t3font->matrix.d = d; font->t3font->matrix.e = e; font->t3font->matrix.f = f; /* We won't receive glyph bounding box values for colorized true, * so we use the font matrix to get an approximation instead. * * Writing the font matrix should be optional according to the * PDF reference, but we must write it in order to work around a * display bug in Acrobat. */ if (font->t3font->colorized == pdc_true) { font->t3font->bbox.llx = 0; font->t3font->bbox.lly = 0; font->t3font->bbox.urx = (d-b)/det; font->t3font->bbox.ury = (a-c)/det; } /* * 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->t3font = font->t3font; }
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; }
int pdf__shading( PDF *p, const char *type, pdc_scalar x_0, pdc_scalar y_0, pdc_scalar x_1, pdc_scalar y_1, pdc_scalar c_1, pdc_scalar c_2, pdc_scalar c_3, pdc_scalar c_4, const char *optlist) { pdf_shadingtype_e shtype = shnone; pdf_color *color0, color1; pdf_colorspace *cs; pdc_resopt *results; pdc_scalar N = 1.0; pdc_scalar r_0, r_1; pdc_bool extend0 = pdc_false, extend1 = pdc_false, antialias = pdc_false; int retval = -1; if (p->compatibility == PDC_1_3) pdc_error(p->pdc, PDF_E_SHADING13, 0, 0, 0, 0); if (!pdc_stricmp(type, "axial")) { shtype = axial; } else if (!pdc_stricmp(type, "radial")) { shtype = radial; } else pdc_error(p->pdc, PDC_E_ILLARG_STRING, "type", type, 0, 0); pdc_check_number(p->pdc, "x_0", x_0); pdc_check_number(p->pdc, "y_0", y_0); pdc_check_number(p->pdc, "x_1", x_1); pdc_check_number(p->pdc, "y_1", y_1); pdc_check_number(p->pdc, "c_1", c_1); pdc_check_number(p->pdc, "c_2", c_2); pdc_check_number(p->pdc, "c_3", c_3); pdc_check_number(p->pdc, "c_4", c_4); color0 = pdf_get_cstate(p, pdf_fill); color1.cs = color0->cs; cs = &p->colorspaces[color0->cs]; switch (cs->type) { case DeviceGray: color1.val.gray = c_1; break; case DeviceRGB: color1.val.rgb.r = c_1; color1.val.rgb.g = c_2; color1.val.rgb.b = c_3; break; case DeviceCMYK: color1.val.cmyk.c = c_1; color1.val.cmyk.m = c_2; color1.val.cmyk.y = c_3; color1.val.cmyk.k = c_4; break; default: pdc_error(p->pdc, PDF_E_INT_BADCS, pdc_errprintf(p->pdc, "%d", color0->cs), 0, 0, 0); } results = pdc_parse_optionlist(p->pdc, optlist, pdf_shading_options, NULL, pdc_true); (void) pdc_get_optvalues("N", results, &N, NULL); (void) pdc_get_optvalues("antialias", results, &antialias,NULL); if (shtype == radial) { if (pdc_get_optvalues("r0", results, &r_0, NULL) != 1) pdc_error(p->pdc, PDC_E_OPT_NOTFOUND, "r0", 0, 0, 0); if (pdc_get_optvalues("r1", results, &r_1, NULL) != 1) pdc_error(p->pdc, PDC_E_OPT_NOTFOUND, "r1", 0, 0, 0); } if (shtype == axial) { if (pdc_get_optvalues("r0", results, &r_0, NULL) == 1) pdc_warning(p->pdc, PDC_E_OPT_IGNORED, "r0", 0, 0, 0); if (pdc_get_optvalues("r1", results, &r_1, NULL) == 1) pdc_warning(p->pdc, PDC_E_OPT_IGNORED, "r1", 0, 0, 0); } if (shtype == radial || shtype == axial) { pdc_get_optvalues("extend0", results, &extend0, NULL); pdc_get_optvalues("extend1", results, &extend1, NULL); } pdc_cleanup_optionlist(p->pdc, results); if (p->shadings_number == p->shadings_capacity) pdf_grow_shadings(p); if (PDF_GET_STATE(p) == pdf_state_page) pdf_end_contents_section(p); /* Shading object */ p->shadings[p->shadings_number].obj_id = pdc_begin_obj(p->out, PDC_NEW_ID); pdc_begin_dict(p->out); /* Shading dict*/ pdc_printf(p->out, "/ShadingType %d\n", (int) shtype); pdc_printf(p->out, "/ColorSpace"); pdf_write_colorspace(p, color1.cs, pdc_false); pdc_puts(p->out, "\n"); if (antialias) pdc_printf(p->out, "/AntiAlias true\n"); switch (shtype) { case axial: /* Type 2 */ pdc_printf(p->out, "/Coords[%f %f %f %f]\n", x_0, y_0, x_1, y_1); if (extend0 || extend1) pdc_printf(p->out, "/Extend[%s %s]\n", extend0 ? "true" : "false", extend1 ? "true" : "false"); pdc_puts(p->out, "/Function"); pdf_write_function_dict(p, color0, &color1, N); break; case radial: /* Type 3 */ pdc_printf(p->out, "/Coords[%f %f %f %f %f %f]\n", x_0, y_0, r_0, x_1, y_1, r_1); if (extend0 || extend1) pdc_printf(p->out, "/Extend[%s %s]\n", extend0 ? "true" : "false", extend1 ? "true" : "false"); pdc_puts(p->out, "/Function"); pdf_write_function_dict(p, color0, &color1, N); break; default: break; } pdc_end_dict(p->out); /* Shading dict */ pdc_end_obj(p->out); /* Shading object */ if (PDF_GET_STATE(p) == pdf_state_page) pdf_begin_contents_section(p); retval = p->shadings_number; p->shadings_number++; return retval; }
PDFLIB_API int PDFLIB_CALL PDF_create_gstate(PDF *p, const char *optlist) { static const char fn[] = "PDF_create_gstate"; pdf_extgstateresource *gs; int slot = -1; int font = pdc_undef; int inum; pdc_clientdata data; pdc_resopt *results; if (!pdf_enter_api(p, fn, (pdf_state) (pdf_state_document | pdf_state_content), "(p[%p], \"%s\")", (void *) p, optlist)) { PDF_RETURN_HANDLE(p, slot) } 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 */ data.compatibility = p->compatibility; data.maxfont = p->fonts_number - 1; data.hastobepos = p->hastobepos; results = pdc_parse_optionlist(p->pdc, optlist, pdf_create_gstate_options, &data, pdc_true); pdc_get_optvalues(p->pdc, "alphaisshape", results, &gs->alpha_is_shape, NULL); if (pdc_get_optvalues(p->pdc, "blendmode", results, &inum, NULL)) gs->blendmode = (pdf_blendmode) inum; gs->dash_count = pdc_get_optvalues(p->pdc, "dasharray", results, NULL, (void **) &gs->dash_array); pdc_get_optvalues(p->pdc, "dashphase", results, &gs->dash_phase, NULL); pdc_get_optvalues(p->pdc, "flatness", results, &gs->flatness, NULL); pdc_get_optvalues(p->pdc, "font", results, &font, NULL); if (font != pdc_undef) gs->font_obj = p->fonts[font].obj_id; pdc_get_optvalues(p->pdc, "fontsize", results, &gs->font_size, NULL); pdc_get_optvalues(p->pdc, "linecap", results, &gs->line_cap, NULL); pdc_get_optvalues(p->pdc, "linejoin", results, &gs->line_join, NULL); pdc_get_optvalues(p->pdc, "linewidth", results, &gs->line_width, NULL); pdc_get_optvalues(p->pdc, "miterlimit", results, &gs->miter_limit, NULL); pdc_get_optvalues(p->pdc, "opacityfill", results, &gs->opacity_fill, NULL); pdc_get_optvalues(p->pdc, "opacitystroke", results, &gs->opacity_stroke, NULL); pdc_get_optvalues(p->pdc, "overprintfill", results, &gs->overprint_fill, NULL); pdc_get_optvalues(p->pdc, "overprintmode", results, &gs->overprint_mode, NULL); pdc_get_optvalues(p->pdc, "overprintstroke", results, &gs->overprint_stroke, NULL); if (pdc_get_optvalues(p->pdc, "renderingintent", results, &inum, NULL)) gs->ri = (pdf_renderingintent) inum; pdc_get_optvalues(p->pdc, "smoothness", results, &gs->smoothness, NULL); pdc_get_optvalues(p->pdc, "strokeadjust", results, &gs->stroke_adjust, NULL); pdc_get_optvalues(p->pdc, "textknockout", results, &gs->text_knockout, NULL); pdc_cleanup_optionlist(p->pdc, results); PDF_RETURN_HANDLE(p, slot) }