Exemple #1
0
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;
}
Exemple #2
0
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;
}
Exemple #3
0
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;
}
Exemple #4
0
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;
}
Exemple #5
0
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;
}