예제 #1
0
파일: p_actions.c 프로젝트: LuaDist/cd
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);
}
예제 #2
0
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;
}
예제 #3
0
파일: p_params.c 프로젝트: Vulcanior/IUP
void
pdf__set_parameter(PDF *p, const char *key, const char *value)
{
    pdc_pagebox usebox = pdc_pbox_none;
    pdc_text_format textformat = pdc_auto;
    char optlist[PDC_GEN_BUFSIZE];
    pdf_ppt *ppt;
    int i, k;

    i = pdf_get_index(p, key, pdc_true);

    if (value == NULL) value = "";

    ppt = p->curr_ppt;

    switch (i)
    {
        case PDF_PARAMETER_PDIUSEBOX:
        case PDF_PARAMETER_VIEWAREA:
        case PDF_PARAMETER_VIEWCLIP:
        case PDF_PARAMETER_PRINTAREA:
        case PDF_PARAMETER_PRINTCLIP:
            k = pdc_get_keycode_ci(value, pdf_usebox_keylist);
            if (k == PDC_KEY_NOTFOUND)
                pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
            usebox = (pdc_pagebox) k;
            pdc_sprintf(p->pdc, pdc_false, optlist, "%s %s", key, value);
            break;

        case PDF_PARAMETER_TEXTFORMAT:
        case PDF_PARAMETER_HYPERTEXTFORMAT:
            k = pdc_get_keycode_ci(value, pdf_textformat_keylist);
            if (k == PDC_KEY_NOTFOUND)
                pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
            textformat = (pdc_text_format) k;
            break;
    }

    switch (i)
    {
        case PDF_PARAMETER_SEARCHPATH:
        case PDF_PARAMETER_FONTAFM:
	case PDF_PARAMETER_FONTPFM:
        case PDF_PARAMETER_FONTOUTLINE:
        case PDF_PARAMETER_HOSTFONT:
        case PDF_PARAMETER_ENCODING:
        case PDF_PARAMETER_ICCPROFILE:
        case PDF_PARAMETER_STANDARDOUTPUTINTENT:
	{
            pdf_add_pdflib_resource(p, key, value);
            break;
        }

	case PDF_PARAMETER_DEBUG:
	{
	    const unsigned char *c;

	    for (c = (const unsigned char *) value; *c; c++)
		p->debug[(int) *c] = 1;
	    break;
	}

	case PDF_PARAMETER_NODEBUG:
	{
	    const unsigned char *c;

	    for (c = (const unsigned char *) value; *c; c++)
                p->debug[(int) *c] = 0;
	    break;
	}

        case PDF_PARAMETER_BINDING:
            if (!p->pdc->binding)
                p->pdc->binding = pdc_strdup(p->pdc, value);
            break;

        case PDF_PARAMETER_OBJORIENT:
            p->pdc->objorient = pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_HASTOBEPOS:
            p->pdc->hastobepos = pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_PTFRUN:
            p->pdc->ptfrun = pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_SMOKERUN:
            p->pdc->smokerun = pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_UNICAPLANG:
            p->pdc->unicaplang = pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_ERRORPOLICY:
            k = pdc_get_keycode_ci(value, pdf_errpol_keylist);
            if (k == PDC_KEY_NOTFOUND)
                pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
            p->errorpolicy = (pdf_errpol) k;
            break;

	case PDF_PARAMETER_UNDERLINE:
            pdf_set_tstate(p, (double) pdf_bool_value(p, key, value),
                           to_underline);
	    break;

	case PDF_PARAMETER_OVERLINE:
            pdf_set_tstate(p, (double) pdf_bool_value(p, key, value),
                           to_overline);
	    break;

	case PDF_PARAMETER_STRIKEOUT:
            pdf_set_tstate(p, (double) pdf_bool_value(p, key, value),
                           to_strikeout);
	    break;

        case PDF_PARAMETER_KERNING:
            pdc_warning(p->pdc, PDF_E_UNSUPP_KERNING, 0, 0, 0, 0);
            break;

        case PDF_PARAMETER_FAKEBOLD:
            pdf_set_tstate(p, (double) pdf_bool_value(p, key, value),
                           to_fakebold);
            break;


        case PDF_PARAMETER_RESOURCEFILE:
            pdc_set_resourcefile(p->pdc, value);
            break;

        case PDF_PARAMETER_RENDERINGINTENT:
            k = pdc_get_keycode_ci(value, pdf_renderingintent_pdfkeylist);
            if (k == PDC_KEY_NOTFOUND)
                pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
            p->rendintent = (pdf_renderingintent) k;
            break;

        case PDF_PARAMETER_PRESERVEOLDPANTONENAMES:
            p->preserveoldpantonenames = pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_SPOTCOLORLOOKUP:
            p->spotcolorlookup = pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_PDISTRICT:
            p->pdi_strict = pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_TOPDOWN:
            if (pdf_bool_value(p, key, value))
                p->ydirection = -1.0;
            else
                p->ydirection = 1.0;
            break;

        case PDF_PARAMETER_USERCOORDINATES:
            p->usercoordinates = pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_USEHYPERTEXTENCODING:
            p->usehyptxtenc = pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_TEXTFORMAT:
            pdf_check_textformat(p, textformat);
            p->textformat = textformat;
            if (p->curr_ppt)
                pdf_set_tstate(p, (double) textformat, to_textformat);
            break;

        case PDF_PARAMETER_HYPERTEXTFORMAT:
            pdf_check_hypertextformat(p, textformat);
            p->hypertextformat = textformat;
            break;

        case PDF_PARAMETER_HYPERTEXTENCODING:
        {
            p->hypertextencoding =
                pdf_get_hypertextencoding(p, value, &p->hypertextcodepage,
                                          pdc_true);
            pdf_check_hypertextencoding(p, p->hypertextencoding);
            break;
        }

        case PDF_PARAMETER_CHARREF:
            pdc_warning(p->pdc, PDF_E_UNSUPP_CHARREF, 0, 0, 0, 0);
            break;

        case PDF_PARAMETER_ESCAPESEQUENCE:
            pdc_warning(p->pdc, PDF_E_UNSUPP_ESCAPESEQU, 0, 0, 0, 0);
            break;

        case PDF_PARAMETER_HONORLANG:
            pdc_warning(p->pdc, PDF_E_UNSUPP_HONORLANG, 0, 0, 0, 0);
            break;

        case PDF_PARAMETER_GLYPHCHECK:
            pdc_warning(p->pdc, PDF_E_UNSUPP_GLYPHCHECK, 0, 0, 0, 0);
            break;

        case PDF_PARAMETER_FILLRULE:
            k = pdc_get_keycode_ci(value, pdf_fillrule_keylist);
            if (k == PDC_KEY_NOTFOUND)
                pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
            ppt->fillrule = (pdf_fillrule) k;
            break;

        case PDF_PARAMETER_LOGGING:
            pdc_set_logg_options(p->pdc, value);
            break;

        case PDF_PARAMETER_LOGMSG:
            pdc_logg_cond(p->pdc, 1, trc_user, value);
            break;

        case PDF_PARAMETER_TRACEMSG:
            /* do nothing -- client-supplied string will show up
             * in the log file
             */
            break;

        case PDF_PARAMETER_NODEMOSTAMP:
            break;

        case PDF_PARAMETER_SERIAL:
        case PDF_PARAMETER_LICENCE:
        case PDF_PARAMETER_LICENSE:
            break;

        case PDF_PARAMETER_LICENCEFILE:
        case PDF_PARAMETER_LICENSEFILE:
            break;

        case PDF_PARAMETER_AUTOSPACE:
            pdc_warning(p->pdc, PDF_E_UNSUPP_TAGGED, 0, 0, 0, 0);
            break;

/*****************************************************************************/
/**                   deprecated historical parameters                      **/
/*****************************************************************************/

        case PDF_PARAMETER_OPENWARNING:
            p->debug[(int) 'o'] = (char) pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_FONTWARNING:
            p->debug[(int) 'F'] = (char) pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_ICCWARNING:
            p->debug[(int) 'I'] = (char) pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_IMAGEWARNING:
            p->debug[(int) 'i'] = (char) pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_PDIWARNING:
            p->debug[(int) 'p'] = (char) pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_HONORICCPROFILE:
            p->debug[(int) 'e'] = (char) pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_GLYPHWARNING:
            p->debug[(int) 'g'] = (char) pdf_bool_value(p, key, value);
            if (p->curr_ppt)
                pdf_set_tstate(p, (double) pdf_bool_value(p, key, value),
                               to_glyphwarning);
            break;

        case PDF_PARAMETER_TRACE:
        {
            pdc_bool bv = pdf_bool_value(p, key, value);
            if (bv)
                pdc_set_logg_options(p->pdc, "");
            else
                pdc_set_logg_options(p->pdc, "disable");
            break;
        }

        case PDF_PARAMETER_TRACEFILE:
            pdc_sprintf(p->pdc, pdc_false, optlist, "filename %s", value);
            pdc_set_logg_options(p->pdc, optlist);
            break;

        case PDF_PARAMETER_WARNING:
            break;

	case PDF_PARAMETER_MASTERPASSWORD:
	    pdc_warning(p->pdc, PDF_E_UNSUPP_CRYPT, 0, 0, 0, 0);
            break;

	case PDF_PARAMETER_USERPASSWORD:
            pdc_warning(p->pdc, PDF_E_UNSUPP_CRYPT, 0, 0, 0, 0);
            break;

	case PDF_PARAMETER_PERMISSIONS:
            pdc_warning(p->pdc, PDF_E_UNSUPP_CRYPT, 0, 0, 0, 0);
            break;

	case PDF_PARAMETER_COMPATIBILITY:
            pdf_set_compatibility(p, value);
	    break;

        case PDF_PARAMETER_FLUSH:
            pdf_set_flush(p, value);
            break;

	case PDF_PARAMETER_PDFX:
	    pdc_warning(p->pdc, PDF_E_UNSUPP_PDFX, 0, 0, 0, 0);
	    break;

	case PDF_PARAMETER_HIDETOOLBAR:
        case PDF_PARAMETER_HIDEMENUBAR:
        case PDF_PARAMETER_HIDEWINDOWUI:
        case PDF_PARAMETER_FITWINDOW:
        case PDF_PARAMETER_CENTERWINDOW:
        case PDF_PARAMETER_DISPLAYDOCTITLE:
	    if (pdf_bool_value(p, key, value))
                pdf_set_viewerpreference(p, key);
	    break;

	case PDF_PARAMETER_NONFULLSCREENPAGEMODE:
            if (!pdc_stricmp(value, "useoutlines"))
                pdf_set_viewerpreference(p, "nonfullscreenpagemode bookmarks");
            else if (!pdc_stricmp(value, "usethumbs"))
                pdf_set_viewerpreference(p, "nonfullscreenpagemode thumbnails");
            else if (!pdc_stricmp(value, "usenone"))
                pdf_set_viewerpreference(p, "nonfullscreenpagemode none");
	    else
		pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
	    break;

	case PDF_PARAMETER_DIRECTION:
            if (!pdc_stricmp(value, "r2l"))
                pdf_set_viewerpreference(p, "direction r2l");
            else if (!pdc_stricmp(value, "l2r"))
                pdf_set_viewerpreference(p, "direction l2r");
	    else
		pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
	    break;

	case PDF_PARAMETER_VIEWAREA:
        case PDF_PARAMETER_VIEWCLIP:
        case PDF_PARAMETER_PRINTAREA:
        case PDF_PARAMETER_PRINTCLIP:
            pdf_set_viewerpreference(p, optlist);
	    break;

	case PDF_PARAMETER_OPENACTION:
            pdf_set_openaction(p, value);
	    break;

	case PDF_PARAMETER_OPENMODE:
            pdf_set_openmode(p, value);
	    break;

	case PDF_PARAMETER_BOOKMARKDEST:
	    pdf_cleanup_destination(p, p->bookmark_dest);
            p->bookmark_dest =
                pdf_parse_destination_optlist(p, value, 0, pdf_bookmark);
	    break;

        case PDF_PARAMETER_INHERITGSTATE:
	    (void) pdf_bool_value(p, key, value);
	    break;

	case PDF_PARAMETER_TRANSITION:
	    pdf_set_transition(p, value);
	    break;

	case PDF_PARAMETER_BASE:
            pdf_set_uri(p, value);
	    break;

	case PDF_PARAMETER_LAUNCHLINK_PARAMETERS:
	    if (p->launchlink_parameters) {
		pdc_free(p->pdc, p->launchlink_parameters);
		p->launchlink_parameters = NULL;
	    }
	    p->launchlink_parameters = pdc_strdup(p->pdc, value);
	    break;

	case PDF_PARAMETER_LAUNCHLINK_OPERATION:
	    if (p->launchlink_operation) {
		pdc_free(p->pdc, p->launchlink_operation);
		p->launchlink_operation = NULL;
	    }
	    p->launchlink_operation = pdc_strdup(p->pdc, value);
	    break;

	case PDF_PARAMETER_LAUNCHLINK_DEFAULTDIR:
	    if (p->launchlink_defaultdir) {
		pdc_free(p->pdc, p->launchlink_defaultdir);
		p->launchlink_defaultdir = NULL;
	    }
	    p->launchlink_defaultdir = pdc_strdup(p->pdc, value);
	    break;

        case PDF_PARAMETER_PDIUSEBOX:
            p->pdi_usebox = usebox;
            break;

        case PDF_PARAMETER_AUTOSUBSETTING:
        case PDF_PARAMETER_AUTOCIDFONT:
        case PDF_PARAMETER_UNICODEMAP:
            pdc_warning(p->pdc, PDF_E_UNSUPP_UNICODE, 0, 0, 0, 0);
            break;

	default:
	    pdc_error(p->pdc, PDC_E_PAR_UNKNOWNKEY, key, 0, 0, 0);
	    break;
    } /* switch */
} /* pdf__set_parameter */
예제 #4
0
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);
}
예제 #5
0
파일: p_params.c 프로젝트: AmirAbrams/haiku
PDFLIB_API void PDFLIB_CALL
PDF_set_parameter(PDF *p, const char *key, const char *value)
{
    static const char fn[] = "PDF_set_parameter";
    pdc_usebox usebox = use_none;
    pdc_text_format textformat = pdc_auto;
    int i, k;

    if (key == NULL || !*key)
	pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "key", 0, 0, 0);

    i = get_index(key);

    if (!pdf_enter_api(p, fn, (pdf_state) pdf_state_all,
	"(p[%p], \"%s\", \"%s\")\n", (void *) p, key, value))
	return;

    if (i == -1)
	pdc_error(p->pdc, PDC_E_PAR_UNKNOWNKEY, key, 0, 0, 0);

    if ((p->state_stack[p->state_sp] & parms[i].set_scope) == 0)
	pdc_error(p->pdc, PDF_E_DOC_SCOPE_SET, key, pdf_current_scope(p), 0, 0);

    if (value == NULL)
	pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "value", 0, 0, 0);

    switch (i)
    {
        case PDF_PARAMETER_PDIUSEBOX:
        case PDF_PARAMETER_VIEWAREA:
        case PDF_PARAMETER_VIEWCLIP:
        case PDF_PARAMETER_PRINTAREA:
        case PDF_PARAMETER_PRINTCLIP:
            k = pdc_get_keycode(value, pdf_usebox_keylist);
            if (k == PDC_KEY_NOTFOUND)
                pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
            usebox = (pdc_usebox) k;
            break;

        case PDF_PARAMETER_TEXTFORMAT:
        case PDF_PARAMETER_HYPERTEXTFORMAT:
            k = pdc_get_keycode(value, pdf_textformat_keylist);
            if (k == PDC_KEY_NOTFOUND)
                pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
            textformat = (pdc_text_format) k;
            break;
    }

    switch (i)
    {
        case PDF_PARAMETER_SEARCHPATH:
        case PDF_PARAMETER_FONTAFM:
	case PDF_PARAMETER_FONTPFM:
        case PDF_PARAMETER_FONTOUTLINE:
        case PDF_PARAMETER_HOSTFONT:
        case PDF_PARAMETER_ENCODING:
        case PDF_PARAMETER_ICCPROFILE:
        case PDF_PARAMETER_STANDARDOUTPUTINTENT:
	{
            pdf_add_resource(p, key, value);
            break;
        }

	case PDF_PARAMETER_FLUSH:
	    if (p->binding != NULL && strcmp(p->binding, "C++"))
		break;

	    if (!strcmp(value, "none"))
		p->flush = pdf_flush_none;
	    else if (!strcmp(value, "page"))
                p->flush = (pdf_flush_state) (p->flush | pdf_flush_page);
	    else if (!strcmp(value, "content"))
                p->flush = (pdf_flush_state) (p->flush | pdf_flush_content);
	    else if (!strcmp(value, "heavy"))
                p->flush = (pdf_flush_state) (p->flush | pdf_flush_heavy);
	    else
		pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);

	    break;

	case PDF_PARAMETER_DEBUG:
	{
	    const unsigned char *c;

	    for (c = (const unsigned char *) value; *c; c++) {
		p->debug[(int) *c] = 1;

		if (*c == 't') {
		    pdc_set_trace(p->pdc, "PDFlib " PDFLIB_VERSIONSTRING);
		}
	    }
	    break;
	}

	case PDF_PARAMETER_NODEBUG:
	{
	    const unsigned char *c;

	    for (c = (const unsigned char *) value; *c; c++) {
		if (*c == 't')
		    pdc_set_trace(p->pdc, NULL);

		p->debug[(int) *c] = 0;
	    }
	    break;
	}

        case PDF_PARAMETER_BINDING:
            if (!p->binding)
                p->binding = pdc_strdup(p->pdc, value);
            break;

        case PDF_PARAMETER_HASTOBEPOS:
            p->hastobepos = pdf_bool_value(p, key, value);
            break;

	case PDF_PARAMETER_UNDERLINE:
	    p->underline = pdf_bool_value(p, key, value);
	    break;

	case PDF_PARAMETER_OVERLINE:
	    p->overline = pdf_bool_value(p, key, value);
	    break;

	case PDF_PARAMETER_STRIKEOUT:
	    p->strikeout = pdf_bool_value(p, key, value);
	    break;

        case PDF_PARAMETER_KERNING:
            pdc_warning(p->pdc, PDF_E_UNSUPP_KERNING, 0, 0, 0, 0);
            break;

        case PDF_PARAMETER_AUTOSUBSETTING:
            pdc_warning(p->pdc, PDF_E_UNSUPP_SUBSET, 0, 0, 0, 0);
            break;

        case PDF_PARAMETER_AUTOCIDFONT:
            pdc_warning(p->pdc, PDF_E_UNSUPP_UNICODE, 0, 0, 0, 0);
            break;

        case PDF_PARAMETER_UNICODEMAP:
            pdc_warning(p->pdc, PDF_E_UNSUPP_UNICODE, 0, 0, 0, 0);
            break;

	case PDF_PARAMETER_MASTERPASSWORD:
	    pdc_warning(p->pdc, PDF_E_UNSUPP_CRYPT, 0, 0, 0, 0);
	    break;

	case PDF_PARAMETER_USERPASSWORD:
            pdc_warning(p->pdc, PDF_E_UNSUPP_CRYPT, 0, 0, 0, 0);
	    break;

	case PDF_PARAMETER_PERMISSIONS:
            pdc_warning(p->pdc, PDF_E_UNSUPP_CRYPT, 0, 0, 0, 0);
	    break;

	case PDF_PARAMETER_COMPATIBILITY:

	    if (!strcmp(value, "1.3"))
		p->compatibility = PDC_1_3;
	    else if (!strcmp(value, "1.4"))
		p->compatibility = PDC_1_4;
	    else if (!strcmp(value, "1.5"))
		p->compatibility = PDC_1_5;
	    else
		pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
	    break;

	case PDF_PARAMETER_PDFX:
	    pdc_warning(p->pdc, PDF_E_UNSUPP_PDFX, 0, 0, 0, 0);

	    break;


        case PDF_PARAMETER_RESOURCEFILE:
            if (p->resourcefilename)
            {
                pdc_free(p->pdc, p->resourcefilename);
                p->resourcefilename = NULL;
            }
            p->resourcefilename = pdc_strdup(p->pdc, value);
            p->resfilepending = pdc_true;
            break;

	case PDF_PARAMETER_PREFIX:
            if (p->prefix)
            {
                pdc_free(p->pdc, p->prefix);
                p->prefix = NULL;
            }
            /* because of downward compatibility */
            p->prefix = pdc_strdup(p->pdc, &value[value[0] == '/' ? 1 : 0]);
	    break;

	case PDF_PARAMETER_WARNING:
	    pdc_set_warnings(p->pdc, pdf_bool_value(p, key, value));
	    break;

        case PDF_PARAMETER_OPENWARNING:
            p->debug['o'] = (char) pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_FONTWARNING:
            p->debug['F'] = (char) pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_ICCWARNING:
            p->debug['I'] = (char) pdf_bool_value(p, key, value);
            break;

	case PDF_PARAMETER_IMAGEWARNING:
	    p->debug['i'] = (char) pdf_bool_value(p, key, value);
	    break;

        case PDF_PARAMETER_PDIWARNING:
            p->debug['p'] = (char) pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_HONORICCPROFILE:
            p->debug['e'] = (char) pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_GLYPHWARNING:
            p->debug['g'] = (char) pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_RENDERINGINTENT:
            k = pdc_get_keycode(value, gs_renderingintents);
            if (k == PDC_KEY_NOTFOUND)
                pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
            p->rendintent = (pdf_renderingintent) k;
            break;

        case PDF_PARAMETER_PRESERVEOLDPANTONENAMES:
            p->preserveoldpantonenames = pdf_bool_value(p, key, value);
            break;

        case PDF_PARAMETER_SPOTCOLORLOOKUP:
            p->spotcolorlookup = pdf_bool_value(p, key, value);
            break;

	case PDF_PARAMETER_INHERITGSTATE:
	    p->inheritgs = pdf_bool_value(p, key, value);
	    break;

	case PDF_PARAMETER_PDISTRICT:
	    p->pdi_strict = pdf_bool_value(p, key, value);
	    break;

	case PDF_PARAMETER_PDIUSEBOX:
            p->pdi_usebox = usebox;
            break;

	case PDF_PARAMETER_PASSTHROUGH:
	    p->debug['P'] = (char) !pdf_bool_value(p, key, value);
	    break;

	case PDF_PARAMETER_HIDETOOLBAR:
	    if (pdf_bool_value(p, key, value))
		p->ViewerPreferences.flags |= HideToolbar;
	    break;

	case PDF_PARAMETER_HIDEMENUBAR:
	    if (pdf_bool_value(p, key, value))
		p->ViewerPreferences.flags |= HideMenubar;
	    break;

	case PDF_PARAMETER_HIDEWINDOWUI:
	    if (pdf_bool_value(p, key, value))
		p->ViewerPreferences.flags |= HideWindowUI;
	    break;

	case PDF_PARAMETER_FITWINDOW:
	    if (pdf_bool_value(p, key, value))
		p->ViewerPreferences.flags |= FitWindow;
	    break;

	case PDF_PARAMETER_CENTERWINDOW:
	    if (pdf_bool_value(p, key, value))
		p->ViewerPreferences.flags |= CenterWindow;
	    break;

	case PDF_PARAMETER_DISPLAYDOCTITLE:
	    if (pdf_bool_value(p, key, value))
		p->ViewerPreferences.flags |= DisplayDocTitle;
	    break;

	case PDF_PARAMETER_NONFULLSCREENPAGEMODE:
	    if (!strcmp(value, "useoutlines")) {
		p->ViewerPreferences.flags |= NonFullScreenPageModeOutlines;
		p->ViewerPreferences.flags &= ~NonFullScreenPageModeThumbs;
	    } else if (!strcmp(value, "usethumbs")) {
		p->ViewerPreferences.flags &= ~NonFullScreenPageModeOutlines;
		p->ViewerPreferences.flags |= NonFullScreenPageModeThumbs;
	    } else if (!strcmp(value, "usenone")) {
		p->ViewerPreferences.flags &= ~NonFullScreenPageModeOutlines;
		p->ViewerPreferences.flags &= ~NonFullScreenPageModeThumbs;
	    } else {
		pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
	    }

	    break;

	case PDF_PARAMETER_DIRECTION:
	    if (!strcmp(value, "r2l")) {
		p->ViewerPreferences.flags |= DirectionR2L;
	    } else if (!strcmp(value, "l2r")) {
		p->ViewerPreferences.flags &= ~DirectionR2L;
	    } else {
		pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
	    }
	    break;

	case PDF_PARAMETER_VIEWAREA:
            p->ViewerPreferences.ViewArea = usebox;
	    break;

	case PDF_PARAMETER_VIEWCLIP:
            p->ViewerPreferences.ViewClip = usebox;
            break;

	case PDF_PARAMETER_PRINTAREA:
            p->ViewerPreferences.PrintArea = usebox;
            break;

	case PDF_PARAMETER_PRINTCLIP:
            p->ViewerPreferences.PrintClip = usebox;
            break;

        case PDF_PARAMETER_TOPDOWN:
            if (pdf_bool_value(p, key, value))
                p->ydirection = (float) -1.0;
            else
                p->ydirection = (float) 1.0;
            break;

        case PDF_PARAMETER_USERCOORDINATES:
            p->usercoordinates = pdf_bool_value(p, key, value);
            break;

	case PDF_PARAMETER_OPENACTION:
	    pdf_cleanup_destination(p, &p->open_action);

	    pdf_parse_destination_optlist(p,
                value, &p->open_action, 1, pdf_openaction);
	    break;

	case PDF_PARAMETER_OPENMODE:
	    if (!strcmp(value, "none")) {
		p->open_mode = open_none;
	    } else if (!strcmp(value, "bookmarks")) {
		p->open_mode = open_bookmarks;
	    } else if (!strcmp(value, "thumbnails")) {
		p->open_mode = open_thumbnails;
	    } else if (!strcmp(value, "fullscreen")) {
		p->open_mode = open_fullscreen;
	    } else {
		pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
	    }
	    break;

	case PDF_PARAMETER_BOOKMARKDEST:
	    pdf_cleanup_destination(p, &p->bookmark_dest);

	    pdf_parse_destination_optlist(p,
                value, &p->bookmark_dest, 0, pdf_bookmark);
	    break;

	case PDF_PARAMETER_FILLRULE:
	    if (!strcmp(value, "winding")) {
		p->fillrule = pdf_fill_winding;
	    } else if (!strcmp(value, "evenodd")) {
		p->fillrule = pdf_fill_evenodd;
	    } else {
		pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
	    }
	    break;

        case PDF_PARAMETER_TEXTFORMAT:
            p->textformat = textformat;
            break;

        case PDF_PARAMETER_HYPERTEXTFORMAT:
            p->hypertextformat = textformat;
            break;

        case PDF_PARAMETER_HYPERTEXTENCODING:
        {
            pdc_encoding enc;

            if (!*value)
            {
                enc = pdc_unicode;
            }
            else
            {
                enc = pdf_find_encoding(p, (const char *) value);
                if (enc == pdc_invalidenc)
                    enc = pdf_insert_encoding(p, (const char *) value);
                if (enc < 0 && enc != pdc_unicode)
                    pdc_error(p->pdc, PDC_E_PAR_ILLPARAM, value, key, 0, 0);
            }
            p->hypertextencoding = enc;
            break;
        }

	/* deprecated */
	case PDF_PARAMETER_NATIVEUNICODE:
	    (void) pdf_bool_value(p, key, value);
	    break;

	case PDF_PARAMETER_TRANSITION:
	    pdf_set_transition(p, value);
	    break;

	case PDF_PARAMETER_BASE:
	    if (p->base) {
		pdc_free(p->pdc, p->base);
		p->base = NULL;
	    }

	    p->base = pdc_strdup(p->pdc, value);
	    break;

	case PDF_PARAMETER_LAUNCHLINK_PARAMETERS:
	    if (p->launchlink_parameters) {
		pdc_free(p->pdc, p->launchlink_parameters);
		p->launchlink_parameters = NULL;
	    }
	    p->launchlink_parameters = pdc_strdup(p->pdc, value);
	    break;

	case PDF_PARAMETER_LAUNCHLINK_OPERATION:
	    if (p->launchlink_operation) {
		pdc_free(p->pdc, p->launchlink_operation);
		p->launchlink_operation = NULL;
	    }
	    p->launchlink_operation = pdc_strdup(p->pdc, value);
	    break;

	case PDF_PARAMETER_LAUNCHLINK_DEFAULTDIR:
	    if (p->launchlink_defaultdir) {
		pdc_free(p->pdc, p->launchlink_defaultdir);
		p->launchlink_defaultdir = NULL;
	    }
	    p->launchlink_defaultdir = pdc_strdup(p->pdc, value);
	    break;

	case PDF_PARAMETER_TRACE:
	    if (pdf_bool_value(p, key, value)) {
		p->debug['t'] = 1;
		pdc_set_trace(p->pdc, "PDFlib " PDFLIB_VERSIONSTRING);
	    } else {
		pdc_set_trace(p->pdc, NULL);
		p->debug['t'] = 0;
	    }
	    break;

	case PDF_PARAMETER_TRACEFILE:
	    pdc_set_tracefile(p->pdc, value);
	    break;

	case PDF_PARAMETER_TRACEMSG:
	    /* do nothing -- client-supplied string will show up in the trace */
	    break;

	case PDF_PARAMETER_SERIAL:
	case PDF_PARAMETER_LICENSE:
	    break;

	case PDF_PARAMETER_LICENSEFILE:
	    break;

	default:
	    pdc_error(p->pdc, PDC_E_PAR_UNKNOWNKEY, key, 0, 0, 0);
	    break;
    } /* switch */
} /* PDF_set_parameter */