static double pdf_value(PDF *p, const char *key, double value, int minver) { if (p->compatibility < minver) pdc_error(p->pdc, PDC_E_PAR_VERSION, key, pdc_get_pdfversion(p->pdc, minver), 0, 0); return value; }
pdc_bool pdc_init_output( void *opaque, pdc_output *out, int compatibility, pdc_outctl *oc) { static const char *fn = "pdc_init_output"; pdc_core *pdc = out->pdc; int i; pdc_cleanup_output(out, pdc_false); out->opaque = opaque; out->lastobj = 0; #if defined(MVS) || defined(MVS_TEST) out->fopenparams = oc->fopenparams; out->recordsize = oc->recordsize; #endif if (out->file_offset == NULL) { out->file_offset_capacity = ID_CHUNKSIZE; out->file_offset = (pdc_off_t *) pdc_malloc(pdc, sizeof(pdc_off_t) * out->file_offset_capacity, fn); } for (i = 1; i < out->file_offset_capacity; ++i) out->file_offset[i] = PDC_BAD_ID; out->compresslevel = PDF_DEFAULT_COMPRESSION; out->compr_changed = pdc_false; out->flush = oc->flush; memcpy(out->id[0], out->id[1], MD5_DIGEST_LENGTH); if (!pdc_init_stream(pdc, out, oc->filename, oc->fp, oc->writeproc)) return pdc_false; { /* Write the document header */ pdc_printf(out, "%%PDF-%s\n", pdc_get_pdfversion(pdc, compatibility)); #define PDC_MAGIC_BINARY "\045\344\343\317\322\012" pdc_write(out, PDC_MAGIC_BINARY, sizeof(PDC_MAGIC_BINARY) - 1); } out->open = pdc_true; return pdc_true; }
static double pdf_pos_value(PDF *p, const char *key, double value, int minver) { if (p->compatibility < minver) pdc_error(p->pdc, PDC_E_PAR_VERSION, key, pdc_get_pdfversion(p->pdc, minver), 0, 0); if (value <= 0) pdc_error(p->pdc, PDC_E_PAR_ILLVALUE, pdc_errprintf(p->pdc, "%f", value), key, 0, 0); return value; }
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_resopt * pdc_parse_optionlist(pdc_core *pdc, const char *optlist, const pdc_defopt *defopt, const pdc_clientdata *clientdata, pdc_bool verbose) { static const char *fn = "pdc_parse_optionlist"; pdc_bool logg5 = pdc_logg_is_enabled(pdc, 5, trc_optlist); const char *stemp1 = NULL, *stemp2 = NULL, *stemp3 = NULL, *s1, *s2; char **items = NULL, *keyword = NULL; char **values = NULL, *value = NULL, **strings = NULL; int i, j, k, nd, is, iss, it, iv, icoord; int numdef, nitems = 0, nvalues, ncoords = 0, errcode = 0; void *resval; double dz, maxval; int retval, iz; pdc_sint32 lz = 0; pdc_uint32 ulz = 0; size_t len; const pdc_defopt *dopt = NULL; pdc_resopt *resopt = NULL; pdc_bool ignore = pdc_false; pdc_bool boolval = pdc_false; pdc_bool tocheck = pdc_false; pdc_bool issorted = pdc_true; pdc_bool ishandle = pdc_true; pdc_bool isutf8 = pdc_false; pdc_logg_cond(pdc, 1, trc_optlist, "\n\tOption list: \"%T\"\n", optlist ? optlist : "", 0); /* split option list */ if (optlist != NULL) { nitems = pdc_split_stringlist(pdc, optlist, PDC_OPT_LISTSEPS, PDC_SPLIT_ISOPTLIST, &items); isutf8 = pdc_is_utf8_bytecode(optlist); } if (nitems < 0) { keyword = (char *) optlist; errcode = PDC_E_OPT_NOTBAL; goto PDC_OPT_SYNTAXERROR; } /* initialize result list */ for (numdef = 0; defopt[numdef].name != NULL; numdef++) { /* */ ; } /* allocate temporary memory for option parser result struct */ resopt = (pdc_resopt *) pdc_calloc_tmp(pdc, numdef * sizeof(pdc_resopt), fn, pdc, pdc_cleanup_optionlist_tmp); for (i = 0; i < numdef; i++) { resopt[i].numdef = numdef; resopt[i].defopt = &defopt[i]; if (defopt[i].flags & PDC_OPT_IGNOREIF1 || defopt[i].flags & PDC_OPT_IGNOREIF2 || defopt[i].flags & PDC_OPT_REQUIRIF1 || defopt[i].flags & PDC_OPT_REQUIRIF2 || defopt[i].flags & PDC_OPT_REQUIRED) tocheck = pdc_true; if (i && issorted) issorted = (strcmp(defopt[i-1].name, defopt[i].name) <= 0) ? pdc_true : pdc_false; } /* loop over all option list elements */ for (is = 0; is < nitems; is++) { pdc_bool isequal = pdc_false; /* search keyword */ boolval = pdc_undef; keyword = items[is]; for (it = 0; it < numdef; it++) { s1 = keyword; s2 = defopt[it].name; /* if (!pdc_stricmp(keyword, defopt[it].name)) * isequal = pdc_true; */ for (; *s1; ++s1, ++s2) { if (pdc_tolower(*s1) != pdc_tolower(*s2)) break; } if (pdc_tolower(*s1) == pdc_tolower(*s2)) isequal = pdc_true; /* special handling for booleans */ if (defopt[it].type == pdc_booleanlist) { if (isequal || (keyword[1] != 0 && !pdc_stricmp(&keyword[2], defopt[it].name))) { iss = is + 1; if (iss == nitems || (pdc_stricmp(items[iss], "true") && pdc_stricmp(items[iss], "false"))) { i = pdc_strincmp(defopt[it].name, "no", 2) ? 0 : 2; if (!pdc_strincmp(&keyword[i], "no", 2)) { boolval = pdc_false; break; } else if (isequal) { boolval = pdc_true; break; } } } } if (isequal) break; } if (logg5) pdc_logg(pdc, "\t\t\toption \"%s\" specified: ", keyword); if (it == numdef) { errcode = PDC_E_OPT_UNKNOWNKEY; goto PDC_OPT_SYNTAXERROR; } /* initialize */ dopt = &defopt[it]; ignore = pdc_false; nvalues = 1; values = NULL; ishandle = pdc_true; /* compatibility */ if (clientdata && clientdata->compatibility) { int compatibility = clientdata->compatibility; for (iv = PDC_1_3; iv <= PDC_X_X_LAST; iv++) { if (logg5 && (dopt->flags & (1L<<iv))) pdc_logg(pdc, "(compatibility >= %s) ", pdc_get_pdfversion(pdc, iv)); if ((dopt->flags & (1L<<iv)) && compatibility < iv) { if (logg5) pdc_logg(pdc, "\n"); stemp2 = pdc_get_pdfversion(pdc, compatibility); errcode = PDC_E_OPT_VERSION; goto PDC_OPT_SYNTAXERROR; } } } /* not supported */ if (dopt->flags & PDC_OPT_UNSUPP) { if (logg5) pdc_logg(pdc, "(unsupported)\n"); keyword = (char *) dopt->name; errcode = PDC_E_OPT_UNSUPP; goto PDC_OPT_SYNTAXERROR; } /* parse values */ if (boolval == pdc_undef) { is++; if (is == nitems) { errcode = PDC_E_OPT_NOVALUES; goto PDC_OPT_SYNTAXERROR; } if (!ignore) { if (dopt->type == pdc_stringlist && pdc_is_utf8_bytecode(items[is])) resopt[it].flags |= PDC_OPT_ISUTF8; if (dopt->type != pdc_stringlist || dopt->maxnum > 1) nvalues = pdc_split_stringlist(pdc, items[is], (dopt->flags & PDC_OPT_SUBOPTLIST) ? PDC_OPT_LISTSEPS : NULL, PDC_SPLIT_ISOPTLIST, &values); if (dopt->flags & PDC_OPT_DUPORIGVAL) resopt[it].origval = pdc_strdup(pdc, items[is]); } } /* ignore */ if (ignore) continue; /* number of values check */ if (nvalues < dopt->minnum) { stemp2 = pdc_errprintf(pdc, "%d", dopt->minnum); errcode = PDC_E_OPT_TOOFEWVALUES; goto PDC_OPT_SYNTAXERROR; } else if (nvalues > dopt->maxnum) { stemp2 = pdc_errprintf(pdc, "%d", dopt->maxnum); errcode = PDC_E_OPT_TOOMANYVALUES; goto PDC_OPT_SYNTAXERROR; } /* number of values must be even */ if (dopt->flags & PDC_OPT_EVENNUM && (nvalues % 2)) { errcode = PDC_E_OPT_ODDNUM; goto PDC_OPT_SYNTAXERROR; } /* number of values must be odd */ if (dopt->flags & PDC_OPT_ODDNUM && !(nvalues % 2)) { errcode = PDC_E_OPT_EVENNUM; goto PDC_OPT_SYNTAXERROR; } /* deprecated option since PDFlib 7 */ if (dopt->flags & PDC_OPT_PDFLIB_7) { pdc_logg_cond(pdc, 2, trc_api, "[Option \"%s\" is deprecated since PDFlib 7]\n", keyword); } /* option already exists */ if (resopt[it].num) { pdc_delete_optvalue(pdc, &resopt[it]); } /* no values */ if (!nvalues ) continue; /* maximal value */ switch (dopt->type) { case pdc_3ddatahandle: maxval = clientdata->max3ddata; break; case pdc_3dviewhandle: maxval = clientdata->max3dview; break; case pdc_actionhandle: maxval = clientdata->maxaction; break; case pdc_bookmarkhandle: maxval = clientdata->maxbookmark; break; case pdc_colorhandle: maxval = clientdata->maxcolor; break; case pdc_documenthandle: maxval = clientdata->maxdocument; break; case pdc_fonthandle: maxval = clientdata->maxfont; break; case pdc_gstatehandle: maxval = clientdata->maxgstate; break; case pdc_iccprofilehandle: maxval = clientdata->maxiccprofile; break; case pdc_imagehandle: maxval = clientdata->maximage; break; case pdc_layerhandle: maxval = clientdata->maxlayer; break; case pdc_pagehandle: maxval = clientdata->maxpage; break; case pdc_patternhandle: maxval = clientdata->maxpattern; break; case pdc_shadinghandle: maxval = clientdata->maxshading; break; case pdc_tablehandle: maxval = clientdata->maxtable; break; case pdc_templatehandle: maxval = clientdata->maxtemplate; break; case pdc_textflowhandle: maxval = clientdata->maxtextflow; break; case pdc_stringhandle: maxval = clientdata->maxstring; break; case pdc_polylinelist: ncoords = 0; default: maxval = dopt->maxval; ishandle = pdc_false; break; } /* allocate value array */ resopt[it].val = pdc_calloc(pdc, (size_t) (nvalues * pdc_typesizes[dopt->type]), fn); resopt[it].num = nvalues; resopt[it].currind = it; if (dopt->flags & PDC_OPT_PERCENT) memset(resopt[it].pcbits, 0, PDC_PCBITS_SIZE); if (logg5) pdc_logg(pdc, "{"); /* analyze type */ resval = resopt[it].val; for (iv = 0; iv < nvalues; iv++) { errcode = 0; if (dopt->maxnum > 1 && nvalues) value = values[iv]; else value = items[is]; if (logg5) pdc_logg(pdc, "%s{%T}", iv ? " " : "", value, 0); switch (dopt->type) { /* boolean list */ case pdc_booleanlist: if (boolval == pdc_true || !pdc_stricmp(value, "true")) { *(pdc_bool *) resval = pdc_true; } else if (boolval == pdc_false || !pdc_stricmp(value, "false")) { *(pdc_bool *) resval = pdc_false; } else { errcode = PDC_E_OPT_ILLBOOLEAN; } break; /* string list */ case pdc_stringlist: if (dopt->flags & PDC_OPT_NOSPACES) { if (pdc_split_stringlist(pdc, value, NULL, 0, &strings) > 1) errcode = PDC_E_OPT_ILLSPACES; pdc_cleanup_stringlist(pdc, strings); } if (!errcode) { len = strlen(value); dz = (double) len; if (dz < dopt->minval) { stemp3 = pdc_errprintf(pdc, "%d", (int) dopt->minval); errcode = PDC_E_OPT_TOOSHORTSTR; } else if (dz > maxval) { stemp3 = pdc_errprintf(pdc, "%d", (int) maxval); errcode = PDC_E_OPT_TOOLONGSTR; } if (dopt->flags & PDC_OPT_CONVUTF8) { int flags = PDC_CONV_EBCDIC | PDC_CONV_WITHBOM; if (isutf8 || (resopt[it].flags & PDC_OPT_ISUTF8)) flags |= PDC_CONV_ISUTF8; *((char **) resval) = pdc_convert_name(pdc, value, 0, flags); } else { *((char **) resval) = pdc_strdup(pdc, value); } } break; /* keyword list */ case pdc_keywordlist: if (dopt->flags & PDC_OPT_CASESENS) iz = pdc_get_keycode(value, dopt->keylist); else iz = pdc_get_keycode_ci(value, dopt->keylist); if (iz == PDC_KEY_NOTFOUND) { errcode = PDC_E_OPT_ILLKEYWORD; } else { *(int *) resval = iz; } break; /* character list */ case pdc_unicharlist: iz = pdc_string2unicode(pdc, value, dopt->flags, dopt->keylist, pdc_false); if (iz < 0) { errcode = PDC_E_OPT_ILLCHAR; break; } dz = iz; if (dz < dopt->minval) { stemp3 = pdc_errprintf(pdc, "%g", dopt->minval); errcode = PDC_E_OPT_TOOSMALLVAL; } else if (dz > maxval) { stemp3 = pdc_errprintf(pdc, "%g", maxval); errcode = PDC_E_OPT_TOOBIGVAL; } *(int *) resval = iz; break; /* string list */ case pdc_polylinelist: { int np = pdc_split_stringlist(pdc, value, NULL, 0, &strings); pdc_polyline *pl = (pdc_polyline *) resval; pl->np = np / 2; pl->p = NULL; /* number of coordinates must be even */ if (np % 2) { errcode = PDC_E_OPT_ODDNUM; np = 0; } /* polyline must be a box */ else if ((dopt->flags & PDC_OPT_ISBOX) && np != 4) { errcode = PDC_E_OPT_ILLBOX; np = 0; } /* polyline will be closed */ else if ((dopt->flags & PDC_OPT_CLOSEPOLY) && np <= 4) { errcode = PDC_E_OPT_ILLPOLYLINE; np = 0; } /* polyline not empty */ if (np) { if (dopt->flags & PDC_OPT_CLOSEPOLY) pl->np += 1; pl->p = (pdc_vector *) pdc_malloc(pdc, pl->np * sizeof(pdc_vector), fn); iz = PDC_KEY_NOTFOUND; j = 0; icoord = ncoords; for (i = 0; i < np; i++) { char *sk = strings[i]; if (dopt->keylist) { /* optional keyword list */ if (dopt->flags & PDC_OPT_CASESENS) iz = pdc_get_keycode(sk, dopt->keylist); else iz = pdc_get_keycode_ci(sk, dopt->keylist); } if (iz == PDC_KEY_NOTFOUND) { /* percentage */ if (dopt->flags & PDC_OPT_PERCENT) { k = (int) strlen(sk) - 1; if (sk[k] == '%') { sk[k] = 0; if (ncoords < PDC_MAX_PERCENTS) { pdc_setbit(resopt[it].pcbits, ncoords); } else { errcode = PDC_E_OPT_TOOMANYPERCVALS; } } } retval = pdc_str2double(sk, &dz); if (!retval) { errcode = PDC_E_OPT_ILLNUMBER; } else if (pdc_getbit(resopt[it].pcbits, ncoords)) { if (dopt->flags & PDC_OPT_PERCRANGE) { if (dz < 0) errcode = PDC_E_OPT_TOOSMALLPERCVAL; if (dz > 100) errcode = PDC_E_OPT_TOOBIGPERCVAL; } dz /= 100.0; } } else { dz = (double) iz; } if (!(i % 2)) { pl->p[j].x = dz; } else { pl->p[j].y = dz; j++; } ncoords++; } if (dopt->flags & PDC_OPT_CLOSEPOLY) { pl->p[pl->np - 1] = pl->p[0]; if (pdc_getbit(resopt[it].pcbits, icoord)) pdc_setbit(resopt[it].pcbits, ncoords); ncoords++; if (pdc_getbit(resopt[it].pcbits, icoord + 1)) pdc_setbit(resopt[it].pcbits, ncoords); ncoords++; } } pdc_cleanup_stringlist(pdc, strings); } break; /* number list */ case pdc_3ddatahandle: case pdc_3dviewhandle: case pdc_actionhandle: case pdc_bookmarkhandle: case pdc_colorhandle: case pdc_documenthandle: case pdc_fonthandle: case pdc_gstatehandle: case pdc_iccprofilehandle: case pdc_imagehandle: case pdc_layerhandle: case pdc_pagehandle: case pdc_patternhandle: case pdc_shadinghandle: case pdc_tablehandle: case pdc_templatehandle: case pdc_textflowhandle: case pdc_integerlist: case pdc_floatlist: case pdc_doublelist: case pdc_scalarlist: if (dopt->keylist && (!(dopt->flags & PDC_OPT_KEYLIST1) || !iv)) { /* optional keyword and/or allowed integer list */ if (dopt->flags & PDC_OPT_CASESENS) iz = pdc_get_keycode(value, dopt->keylist); else iz = pdc_get_keycode_ci(value, dopt->keylist); if (iz == PDC_KEY_NOTFOUND) { if (dopt->flags & PDC_OPT_INTLIST) { errcode = PDC_E_OPT_ILLINTEGER; break; } } else { switch (dopt->type) { default: case pdc_integerlist: *(int *) resval = iz; break; case pdc_floatlist: *(float *) resval = (float) iz; break; case pdc_doublelist: *(double *) resval = (double) iz; break; case pdc_scalarlist: *(pdc_scalar *) resval = (pdc_scalar) iz; break; } break; } } /* percentage */ if (dopt->flags & PDC_OPT_PERCENT) { i = (int) strlen(value) - 1; if (value[i] == '%') { value[i] = 0; if (iv < PDC_MAX_PERCENTS) { pdc_setbit(resopt[it].pcbits, iv); } else { errcode = PDC_E_OPT_TOOMANYPERCVALS; } } } case pdc_stringhandle: if (dopt->type == pdc_floatlist || dopt->type == pdc_doublelist || dopt->type == pdc_scalarlist) { retval = pdc_str2double(value, &dz); } else { if (dopt->minval >= 0) { retval = pdc_str2integer(value, PDC_INT_UNSIGNED, &ulz); dz = ulz; } else { retval = pdc_str2integer(value, 0, &lz); dz = lz; } if (retval && ishandle && pdc->hastobepos && dopt->type != pdc_bookmarkhandle && dopt->type != pdc_stringhandle) { dz -= 1; lz = (pdc_sint32) dz; ulz = (pdc_uint32) dz; } } if (!retval) { errcode = PDC_E_OPT_ILLNUMBER; } else { if (pdc_getbit(resopt[it].pcbits, iv)) { if (dopt->flags & PDC_OPT_PERCRANGE) { if (dz < 0) errcode = PDC_E_OPT_TOOSMALLPERCVAL; if (dz > 100) errcode = PDC_E_OPT_TOOBIGPERCVAL; } dz /= 100.0; } if (errcode == 0) { if (dz < dopt->minval) { if (ishandle) { stemp3 = pdc_get_keyword(dopt->type, pdc_handletypes); errcode = PDC_E_OPT_ILLHANDLE; } else { stemp3 = pdc_errprintf(pdc, "%g", dopt->minval); errcode = PDC_E_OPT_TOOSMALLVAL; } } else if (dz > maxval) { if (ishandle) { stemp3 = pdc_get_keyword(dopt->type, pdc_handletypes); errcode = PDC_E_OPT_ILLHANDLE; } else { stemp3 = pdc_errprintf(pdc, "%g", maxval); errcode = PDC_E_OPT_TOOBIGVAL; } } else if (dopt->flags & PDC_OPT_NOZERO && fabs(dz) < PDC_FLOAT_PREC) { errcode = PDC_E_OPT_ZEROVAL; } else if (dopt->type == pdc_scalarlist) { *(pdc_scalar *) resval = dz; } else if (dopt->type == pdc_doublelist) { *(double *) resval = dz; } else if (dopt->type == pdc_floatlist) { *(float *) resval = (float) dz; } else { if (dopt->minval >= 0) *(pdc_uint32 *) resval = ulz; else *(pdc_sint32 *) resval = lz; } } } break; } if (errcode) { stemp2 = pdc_errprintf(pdc, "%.*s", PDC_ERR_MAXSTRLEN, value); goto PDC_OPT_SYNTAXERROR; } /* increment value pointer */ resval = (void *) ((char *)(resval) + pdc_typesizes[dopt->type]); } pdc_cleanup_stringlist(pdc, values); values = NULL; if (logg5) pdc_logg(pdc, "}\n"); /* build OR bit pattern */ if (dopt->flags & PDC_OPT_BUILDOR && nvalues > 1) { int *bcode = (int *) resopt[it].val; for (iv = 1; iv < nvalues; iv++) { bcode[0] |= bcode[iv]; } resopt[it].num = 1; } } pdc_cleanup_stringlist(pdc, items); items = NULL; /* required and to be ignored options */ for (is = 0; tocheck && is < numdef; is++) { /* to be ignored option */ if (resopt[is].num) { nd = 0; if (defopt[is].flags & PDC_OPT_IGNOREIF1) nd = 1; if (defopt[is].flags & PDC_OPT_IGNOREIF2) nd = 2; for (it = is - 1; it >= is - nd && it >= 0; it--) { if (resopt[it].num) { pdc_delete_optvalue(pdc, &resopt[is]); if (verbose) pdc_warning(pdc, PDC_E_OPT_IGNORE, defopt[is].name, defopt[it].name, 0, 0); } } } /* required option */ if (!resopt[is].num && ((defopt[is].flags & PDC_OPT_REQUIRED) || (defopt[is].flags & PDC_OPT_REQUIRIF1 && resopt[is-1].num) || (defopt[is].flags & PDC_OPT_REQUIRIF2 && (resopt[is-1].num || resopt[is-2].num)))) { keyword = (char *) defopt[is].name; errcode = PDC_E_OPT_NOTFOUND; goto PDC_OPT_SYNTAXERROR; } } /* is no sorted */ if (!issorted) { qsort((void *)resopt, (size_t) numdef, sizeof(pdc_resopt), pdc_optname_compare); } /* global UTF-8 check after sort */ if (isutf8) resopt[0].isutf8 = pdc_true; /* index of last got option */ resopt[0].lastind = -1; /* protocol */ if (pdc_logg_is_enabled(pdc, 1, trc_optlist)) { for (is = 0; is < numdef; is++) { if (resopt[is].num) pdc_logg(pdc, "\tOption \"%s\": %d value%s found\n", resopt[is].defopt->name, resopt[is].num, resopt[is].num == 1 ? "" : "s"); else if (logg5) pdc_logg(pdc, "\t\t\toption \"%s\" not specified\n", resopt[is].defopt->name); for (iv = 0; iv < resopt[is].num; iv++) { switch (resopt[is].defopt->type) { case pdc_booleanlist: case pdc_keywordlist: case pdc_integerlist: case pdc_3ddatahandle: case pdc_3dviewhandle: case pdc_actionhandle: case pdc_bookmarkhandle: case pdc_colorhandle: case pdc_documenthandle: case pdc_fonthandle: case pdc_gstatehandle: case pdc_iccprofilehandle: case pdc_imagehandle: case pdc_layerhandle: case pdc_pagehandle: case pdc_patternhandle: case pdc_shadinghandle: case pdc_tablehandle: case pdc_templatehandle: case pdc_textflowhandle: case pdc_stringhandle: pdc_logg(pdc, "\tValue %d: %d\n", iv + 1, *((int *) resopt[is].val + iv)); break; case pdc_stringlist: pdc_logg(pdc, "\tValue %d: \"%T\"\n", iv + 1, *((char **) resopt[is].val + iv), 0); break; case pdc_floatlist: pdc_logg(pdc, "\tValue %d: %f\n", iv + 1, *((float *) resopt[is].val + iv)); break; case pdc_doublelist: pdc_logg(pdc, "\tValue %d: %f\n", iv + 1, *((double *) resopt[is].val + iv)); break; case pdc_scalarlist: pdc_logg(pdc, "\tValue %d: %f\n", iv + 1, *((pdc_scalar *) resopt[is].val + iv)); break; case pdc_unicharlist: pdc_logg(pdc, "\tValue %d: %d\n", iv + 1, *((int *) resopt[is].val + iv)); break; case pdc_polylinelist: pdc_logg(pdc, "\t\t#%d: ", iv + 1); { pdc_polyline *pl = (pdc_polyline *) resopt[is].val + iv; for (j = 0; j < pl->np; j++) pdc_logg(pdc, "%f,%f ", pl->p[j].x, pl->p[j].y); pdc_logg(pdc, "\n"); } break; } } } } return resopt; PDC_OPT_SYNTAXERROR: stemp1 = pdc_errprintf(pdc, "%.*s", PDC_ERR_MAXSTRLEN, keyword); pdc_cleanup_stringlist(pdc, items); pdc_cleanup_stringlist(pdc, values); pdc_set_errmsg(pdc, errcode, stemp1, stemp2, stemp3, 0); if (verbose) pdc_error(pdc, -1, 0, 0, 0, 0); return NULL; }
/* ** Returns CMap slot and for standard CJK fonts: fontandle. ** ** pdc_invalidenc: predefined CMap not found ** pdc_cid or pdc_unicode: predefined CMap found ** ** *o_slot: ** >= 0: standard font found ** < 0: |error code| */ pdc_bool pdf_handle_cidfont(PDF *p, const char *fontname, const char *encoding, pdc_encoding enc, pdf_font *font, int *o_slot, pdc_encoding *newenc) { const char *encapiname = encoding; fnt_cmap_info cmapinfo; const fnt_font_metric *fontmetric; pdc_bool isidentity = pdc_false; pdc_bool isstdfont = pdc_false; pdc_bool iscjkcp = pdc_false; int charcoll, slot; (void) enc; (void) iscjkcp; (void) encapiname; *o_slot = -1; *newenc = pdc_invalidenc; /* * Look whether font is already in the cache. * If font with same name and encoding is found, * returns its slot number. */ for (slot = 0; slot < p->fonts_number; slot++) { if (p->fonts[slot].ft.enc == pdc_cid && p->fonts[slot].opt.fontstyle == font->opt.fontstyle && p->fonts[slot].opt.embedding == font->opt.embedding && !strcmp(p->fonts[slot].apiname, fontname) && !strcmp(p->fonts[slot].ft.cmapname, encoding)) { *o_slot = slot; *newenc = pdc_cid; return pdc_true; } } /* Check the requested CMap */ charcoll = fnt_get_predefined_cmap_info(encoding, &cmapinfo); if (charcoll == (int) cc_none) return pdc_true; pdc_logg_cond(p->pdc, 1, trc_font, "\tPredefined CMap \"%s\" found\n", encoding); /* Check whether this CMap is supported in the desired PDF version */ if (cmapinfo.compatibility > p->compatibility) { pdc_set_errmsg(p->pdc, PDF_E_DOC_PDFVERSION, encoding, pdc_get_pdfversion(p->pdc, p->compatibility), 0, 0); return pdc_false; } /* For Unicode capable language wrappers only UCS2/UTF16 CMaps allowed */ if (cmapinfo.codesize == 0 && p->pdc->unicaplang) { pdc_set_errmsg(p->pdc, PDF_E_FONT_NEEDUCS2, 0, 0, 0, 0); return pdc_false; } /* Check whether the font name is among the known Acrobat CJK fonts */ charcoll = fnt_get_preinstalled_cidfont(fontname, &fontmetric); isidentity = cmapinfo.charcoll == (int) cc_identity; if (isidentity) cmapinfo.charcoll = abs(charcoll); /* known Acrobat CID font */ if (charcoll != (int) cc_none) { pdc_logg_cond(p->pdc, 1, trc_font, "\tStandard CJK font \"%s\" found\n", fontname); /* Selected CMap and known standard font don't match */ if ((cmapinfo.charcoll != abs(charcoll) || (charcoll == (int) cc_japanese && cmapinfo.codesize == -2))) { pdc_set_errmsg(p->pdc, PDF_E_CJK_UNSUPP_CHARCOLL, 0, 0, 0, 0); return pdc_false; } isstdfont = pdc_true; /* Embedding not possible */ if (font->opt.embedding) { pdc_set_errmsg(p->pdc, PDF_E_FONT_EMBEDCMAP, 0, 0, 0, 0); return pdc_false; } } #ifdef WIN32 else if (iscjkcp && !p->pdc->ptfrun) { return pdc_true; } #endif /* embedding check */ if (!pdf_check_font_embedding(p, font, fontname)) return pdc_false; /* supplement number, number of codes = (maximal) number of CIDs */ font->supplement = fnt_get_supplement(&cmapinfo, p->compatibility); if (isidentity) font->supplement = -1; font->ft.numcodes = fnt_get_maxcid(cmapinfo.charcoll, font->supplement) + 1; { font->passthrough = pdc_true; font->codesize = 0; } /* CMap and default settings */ font->ft.vertical = cmapinfo.vertical; font->ft.cmapname = pdc_strdup(p->pdc, encoding); if (font->outcmapname == NULL) font->outcmapname = pdc_strdup(p->pdc, encoding); font->ft.enc = pdc_cid; font->iscidfont = pdc_true; /* Fill up the font struct */ fnt_fill_font_metric(p->pdc, &font->ft, pdc_false, fontmetric); /* CID widths not available */ font->widthsmissing = pdc_true; pdc_logg_cond(p->pdc, 1, trc_font, "\n\t%s CJK font: \"%s\"\n\tPredefined CMap: \"%s\"\n" "\tOrdering: \"%s\"\n\tSupplement: %d\n", font->ft.isstdfont ? "Adobe Standard" : "Custom", fontname, encoding, fnt_get_ordering_cid(font->ft.m.charcoll), font->supplement); *newenc = pdc_cid; return pdc_true; }