Пример #1
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);
}
Пример #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
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 */