Ejemplo n.º 1
0
void
pdc_put_pdfunistring(pdc_output *out, const char *text)
{
    int len;

    len = (int) pdc_strlen(text) - 1;	/* subtract a null byte... */

    /* ...and possibly another one */
    if (pdc_is_unicode(text))
	len--;

    pdc_put_pdfstring(out, text, len);
}
Ejemplo n.º 2
0
void
pdf_put_hypertext(PDF *p, const char *text)
{
    int convflags = PDC_CONV_WITHBOM | PDC_CONV_TRYBYTES;
    int inlen = (int) pdc_strlen(text);
    int outlen;

    char *newtext = pdf_convert_pdfstring(p, text, inlen, convflags, &outlen);

    pdc_put_pdfstring(p->out, newtext, outlen);

    if (newtext != text)
        pdc_free(p->pdc, newtext);
}
Ejemplo n.º 3
0
/* normalized file name according PDF specification */
void
pdc_put_pdffilename(pdc_output *out, const char *text, int len)
{
    static const char *fn = "pdc_put_pdffilename";
    pdc_byte *btext = (pdc_byte *) text;
    pdc_bool isuni = pdc_is_utf16be_unicode(btext);
    char *ttext;
    pdc_byte c, cp, cpp;
    int i, ia = 0, j = 0;

    ttext = (char *) pdc_calloc(out->pdc, (size_t) (len + 4), fn);

    if (isuni)
    {
        ttext[0] = PDF_BOM0;
        ttext[1] = PDF_BOM1;
        ia = 2;
        j = 2;
    }

    /* absolute path name:
     * r:\pdfdocs\spec.pdf -> /r/pdfdocs/spec.pdf
     * pclib/eng:\pdfdocs\spec.pdf -> /pclib/eng/pdfdocs/spec.pdf
     */
    cp = 0x7F;
    for (i = ia; i < len; i++)
    {
        c = btext[i];
        if (c == PDF_COLON && (!isuni || cp == 0))
        {
            if (isuni)
            {
                ttext[j] = 0;
                j++;
            }
            ttext[j] = PDF_SLASH;
            j++;

            break;
        }
        cp = c;
    }

    cp = 0x7F;
    cpp = 0x7F;
    for (i = ia; i < len; i++)
    {
        c = btext[i];

        if ((c == PDF_BACKSLASH || c == PDF_SLASH || c == PDF_COLON) &&
            (!isuni || cp == 0))
        {
            /* convert to slash, but avoid multiple slashes */
            if (cpp != PDF_SLASH)
            {
                c = PDF_SLASH;
            }
            else
            {
                if (isuni)
                    j--;
                continue;
            }
        }

        ttext[j] = c;
        j++;

        cp = c;
        if (c)
            cpp = c;
    }

    len = j;

    pdc_put_pdfstring(out, ttext, len);

    pdc_free(out->pdc, ttext);
}
Ejemplo n.º 4
0
/* normalized file name according PDF specification */
void
pdc_put_pdffilename(pdc_output *out, const char *text, int len)
{
    static const char *fn = "pdc_put_pdffilename";
    char *ttext;

#if defined(WIN32) || defined(MAC)
    int i, j = 0, k = 0;
#endif

    if (!len)
        len = (int) strlen(text);

    ttext = (char *) pdc_malloc(out->pdc, (size_t) (len + 4), fn);
    strcpy(ttext, text);

#if defined(WIN32)

    /* absolute path name */
    if (strchr(ttext, PDF_COLON) != NULL || text[0] == PDF_BACKSLASH)
    {
        ttext[j] = PDF_SLASH;
        j++;
    }
    for (i = k; i < len; i++)
    {
        if (text[i] == PDF_BACKSLASH)
            ttext[j] = PDF_SLASH;
        else if (text[i] == PDF_COLON)
            continue;
        else
            ttext[j] = text[i];
        j++;
    }
    len = j;

#elif defined(MAC)

    /* absolute path name */
    if (text[0] != PDF_COLON)
    {
        ttext[j] = PDF_SLASH;
        j++;
    }
    else
    {
        k = 1;
    }
    for (i = k; i < len; i++)
    {
        if (text[i] == PDF_COLON)
            ttext[j] = PDF_SLASH;
        else
            ttext[j] = text[i];
        j++;
    }
    len = j;

#endif

    pdc_put_pdfstring(out, ttext, len);

    pdc_free(out->pdc, ttext);
}