Exemplo n.º 1
0
pdc_bool
pdf_get_metrics_tt(PDF *p, pdf_font *font, const char *fontname,
                   pdc_encoding enc, const char *filename)
{
    pdc_bool logg1 = pdc_logg_is_enabled(p->pdc, 1, trc_font);
    pdc_bool logg2 = pdc_logg_is_enabled(p->pdc, 2, trc_font);
    int filesize = 0;
    double kbfilesize = 0;
    int foundglyphs, flags = 0;
    tt_file *ttf;
    pdc_bool retval;
    pdc_encoding enc_req;
    pdc_encodingvector *ev = NULL;
    pdc_bool isotf;
    int errcode = 0;

    (void) logg2;

    /*
     * Initialisation
     */
    ttf = fnt_new_tt(p->pdc, &font->ft);
    ttf->filename = filename;
    ttf->fontname = fontname;
    ttf->verbose = font->verbose;
    ttf->incore = pdc_true;
    ttf->monospace = font->opt.monospace;
    filesize = font->ft.filelen;
    kbfilesize = filesize / 1024.0;

    /*
     * Read font file
     */
    retval = fnt_read_tt(ttf);
    if (retval == pdc_false)
        goto PDF_TRUETYPE_ERROR2;

    /*
     * Font type
     */
    if (ttf->tab_CFF_)
    {
        isotf = pdc_true;
        font->ft.m.type = fnt_Type1C;
	font->cff_offset = (long) ttf->tab_CFF_->offset;
	font->cff_length = ttf->tab_CFF_->length;
    }
    else
    {
        isotf = pdc_false;
        font->ft.m.type = fnt_TrueType;
        TT_IOCHECK(ttf, tt_tag2idx(ttf, fnt_str_glyf) != -1);
        TT_IOCHECK(ttf, tt_tag2idx(ttf, fnt_str_loca) != -1);
    }

    /* Number of Glyphs */
    if (ttf->numGlyphs <= 1)
    {
        errcode = FNT_E_TT_NOGLYFDESC;
        goto PDF_TRUETYPE_ERROR1;
    }


    /*
     * Encoding
     */
    if (isotf)
    {
        /* OpenType font with CFF table */
        if (ttf->charcoll != cc_none)
        {
            /* CID font */
            if (font->ft.m.charcoll != cc_none)
            {
                if (!ttf->regisadobe)
                {
                    errcode = PDF_E_CJK_UNSUPP_REGISTRY;
                    goto PDF_TRUETYPE_ERROR1;
                }

                if (font->ft.m.charcoll != ttf->charcoll)
                {
                    errcode = PDF_E_CJK_UNSUPP_CHARCOLL;
                    goto PDF_TRUETYPE_ERROR1;
                }


                if (font->outcmapname != NULL)
                    enc = pdc_cid;

                if (logg1)
                    pdc_logg(p->pdc, "\tCID font ordering: \"%s\"\n",
                             fnt_get_ordering_cid(ttf->charcoll));
            }
            else if (enc == pdc_unicode || enc == pdc_glyphid)
            {
                font->ft.m.charcoll = ttf->charcoll;
                font->supplement = ttf->supplement;
            }
            else
            {
                errcode = PDF_E_FONT_ONLY_CMAP;
                goto PDF_TRUETYPE_ERROR1;
            }
        }
        else if (font->ft.m.charcoll != cc_none)
        {
            /* SID font */
            errcode = PDF_E_FONT_UNSUPP_CMAP;
            goto PDF_TRUETYPE_ERROR1;
        }
    }
    else
    {
        if (font->ft.m.charcoll != cc_none)
        {
            int i;
            pdc_bool iscjk = pdc_false;

            for (i = 0; i < PDC_NUMCHARCOLL; i++)
            {
                if (ttf->tab_OS_2->charcolls[i])
                    iscjk = pdc_true;

                if (ttf->tab_OS_2->charcolls[i] == font->ft.m.charcoll)
                    break;
            }
            if (i == PDC_NUMCHARCOLL)
            {
                if (iscjk)
                {
                    /* CJK font */
                    errcode = PDF_E_CJK_UNSUPP_CHARCOLL;
                    goto PDF_TRUETYPE_ERROR1;
                }
                else
                {
                    /* no CJK font */
                    errcode = PDF_E_FONT_UNSUPP_CMAP;
                    goto PDF_TRUETYPE_ERROR1;
                }
            }
            else
            {
                if (font->outcmapname != NULL)
                {
                    ttf->charcoll = font->ft.m.charcoll;
                    enc = pdc_cid;
                }
            }
        }
    }

    /* encoding vector */
    enc_req = fnt_get_tt_encoding_key(ttf, enc);
    if (enc_req == pdc_invalidenc)
    {
        errcode = FNT_E_TT_BADCMAP;
        goto PDF_TRUETYPE_ERROR1;
    }
    else if (enc_req != enc)
    {
        if (strcmp(font->encapiname, "auto"))
        {
            pdc_warning(p->pdc, PDF_E_FONT_FORCEENC,
                        pdf_get_encoding_name(p, enc_req, NULL),
                        0, 0, 0);
        }
        enc = enc_req;
    }
    if (enc >= 0)
        ev = pdc_get_encoding_vector(p->pdc, enc);
    font->ft.enc = enc;
    font->ft.issymbfont = ttf->issymbol;
    font->hasnomac = !ttf->tab_cmap || !ttf->tab_cmap->mac;


    /* builtin encoding */
    if (enc == pdc_builtin)
    {
        if (font->ft.issymbfont == pdc_false)
        {
            errcode = PDF_E_FONT_BADENC;
            goto PDF_TRUETYPE_ERROR1;
        }
        else
        {
            /* encoding vector for builtin */
            ev = pdf_create_font_encoding(p, enc, font, fontname, pdc_true);
            font->symenc = font->ft.enc;
        }
    }

    {
        /* optimizing PDF output */
        if (enc == pdc_ebcdic ||
            enc == pdc_ebcdic_37 ||
            enc == pdc_ebcdic_winansi)
            font->towinansi = pdc_winansi;

    }

    /* /FontName in FontDescriptor */
    font->ft.m.name = pdc_strdup(p->pdc, ttf->tab_name->englishname4);

    /* /BaseFont name */
    font->ft.name = pdc_strdup(p->pdc, ttf->tab_name->englishname6);


#define PDF_RESTRICTED_TT_EMBEDDING	0x02
    /* check embedding flags */
    if ((font->opt.embedding) && ttf->tab_OS_2 &&
	ttf->tab_OS_2->fsType == PDF_RESTRICTED_TT_EMBEDDING)
    {
        errcode = FNT_E_TT_EMBED;
        goto PDF_TRUETYPE_ERROR1;
    }


    if (logg1)
    {
        pdc_logg(p->pdc,
            "\tFull font name: \"%s\"\n"
            "\tPostScript font name: \"%s\"\n"
            "\tFont embedding: %s\n"
            "\tVertical font: %s\n",
            font->ft.name, font->ft.m.name,
            PDC_BOOLSTR(font->opt.embedding),
            PDC_BOOLSTR(font->ft.vertical));

        if (ttf->tab_name->producer != NULL)
            pdc_logg(p->pdc, "\tFont producer: \"%s\"\n",
                     ttf->tab_name->producer);

        pdc_logg(p->pdc, "\tNumber of Glyphs: %d\n", ttf->numGlyphs);
    }

    /* Save font values */
    fnt_set_tt_fontvalues(ttf);

    /* Flags for creating font arrays */
    flags = TT_FONT_code2gid | TT_FONT_m_widths;



    /* Create font mapping and width arrays */
    foundglyphs = fnt_set_tt_fontarrays(ttf, flags);

   /***********************************/
    if (font->symenc != pdc_invalidenc)
        font->ft.enc = pdc_builtin;
   /***********************************/

    if (!foundglyphs)
    {
        errcode = PDF_E_FONT_BADENC;
        goto PDF_TRUETYPE_ERROR1;
    }


    fnt_delete_tt(ttf);

    if (!pdf_make_fontflag(p, font))
        return pdc_false;

    return pdc_true;

    PDF_TRUETYPE_ERROR1:
    pdc_set_errmsg(p->pdc, errcode, 0, 0, 0, 0);

    PDF_TRUETYPE_ERROR2:
    fnt_delete_tt(ttf);

    return pdc_false;
}
Exemplo n.º 2
0
pdc_bool
pdf_check_pfm_encoding(PDF *p, pdf_font *font, pdc_encoding enc)
{
    const char *encname =
        pdc_errprintf(p->pdc, "%.*s", PDC_ERR_MAXSTRLEN,
                      pdf_get_encoding_name(p, enc, font));
    const char *intencname = NULL;
    pdc_encoding intenc = pdc_invalidenc;
    pdc_bool issymbfont = pdc_undef;

    pdc_logg_cond(p->pdc, 2, trc_font,
        "\tFont internal charset (dfCharSet): %d\n", font->ft.enc);

    /* Font encoding */
    intencname = pdc_get_keyword(font->ft.enc, pdf_charset_keylist);
    if (intencname == NULL)
    {
        pdc_set_errmsg(p->pdc, PDF_E_T1_BADCHARSET,
            pdc_errprintf(p->pdc, "%d", font->ft.enc), 0, 0, 0);
        return pdc_false;
    }

    if (strlen(intencname))
    {
        int codepage = 0;

        pdc_logg_cond(p->pdc, 2, trc_font,
            "\tFont internal encoding \"%s\" found\n", intencname);

        intenc = pdc_find_encoding(p->pdc, intencname);
        if (intenc == pdc_invalidenc)
            intenc = pdc_insert_encoding(p->pdc, intencname, &codepage,
                                         pdc_true);

        font->ft.issymbfont = pdc_false;
    }
    else
    {
        pdc_logg_cond(p->pdc, 2, trc_font, "\tSymbol font\n");

        font->ft.issymbfont = pdc_true;
        intenc = pdc_builtin;

        /* auto */
        if (!strcmp(font->encapiname, "auto"))
        {
            issymbfont = pdc_true;
            enc = pdc_builtin;
        }
    }

    /* builtin */
    if (enc == pdc_builtin)
        issymbfont = pdc_true;

    /* unicode */
    if (enc == pdc_unicode)
    {
        font->unibyte = pdc_true;
        issymbfont = pdc_false;
        enc = intenc;
    }

    /* encoding is subset of 8-bit encoding */
    if (enc >= pdc_winansi && intenc >= pdc_winansi)
    {
        if (pdc_is_encoding_subset(p->pdc, pdc_get_encoding_vector(p->pdc, enc),
                                   pdc_get_encoding_vector(p->pdc, intenc)))
        {
            if (enc != pdc_winansi && intenc == pdc_winansi &&
                strcmp(encname, "iso8859-1"))
            {
                font->towinansi = intenc;
            }
            else
            {
                enc = intenc;
            }
            issymbfont = pdc_false;
        }
    }

    /* illegal encoding */
    if (issymbfont == pdc_undef || font->ft.issymbfont == pdc_undef)
    {
        pdc_set_errmsg(p->pdc, PDF_E_FONT_BADENC, 0, 0, 0, 0);
        return pdc_false;
    }

    font->ft.enc = enc;
    if (issymbfont && !font->ft.issymbfont)
    {
        pdc_warning(p->pdc, PDF_E_FONT_FORCEENC,
                    pdf_get_encoding_name(p, intenc, NULL),
                    0, 0, 0);
        font->ft.enc = intenc;
    }
    if (!issymbfont && font->ft.issymbfont)
    {
        pdc_warning(p->pdc, PDF_E_FONT_FORCEENC,
                    pdf_get_encoding_name(p, pdc_builtin, NULL),
                    0, 0, 0);
        font->ft.enc = pdc_builtin;
        font->towinansi = pdc_invalidenc;
    }

    if (font->towinansi != pdc_invalidenc)
        pdf_transform_fontwidths(p, font,
                        pdc_get_encoding_vector(p->pdc, font->ft.enc),
                        pdc_get_encoding_vector(p->pdc, font->towinansi));

    return pdc_true;
}
Exemplo n.º 3
0
const char *
pdf__get_parameter(PDF *p, const char *key, double mod)
{
    int i = -1;
    int imod = (int) mod;
    const char *result = "";
    pdf_ppt *ppt;

    i = pdf_get_index(p, key, pdc_false);

    if (parms[i].mod_zero && mod != 0)
	pdc_error(p->pdc, PDC_E_PAR_ILLPARAM,
	    pdc_errprintf(p->pdc, "%f", mod), key, 0, 0);

    ppt = p->curr_ppt;

    switch (i)
    {
        case PDF_PARAMETER_CAPHEIGHTFAKED:
        case PDF_PARAMETER_ASCENDERFAKED:
        case PDF_PARAMETER_DESCENDERFAKED:
        case PDF_PARAMETER_XHEIGHTFAKED:
            if (p->pdc->hastobepos) imod -= 1;
            pdf_check_handle(p, imod, pdc_fonthandle);
            break;
    }

    switch (i)
    {
         case PDF_PARAMETER_BINDING:
            result = p->pdc->binding;
            break;

        case PDF_PARAMETER_OBJORIENT:
            result = PDC_BOOLSTR(p->pdc->objorient);
            break;

        case PDF_PARAMETER_HASTOBEPOS:
            result = PDC_BOOLSTR(p->pdc->hastobepos);
            break;

        case PDF_PARAMETER_PTFRUN:
            result = PDC_BOOLSTR(p->pdc->ptfrun);
            break;

        case PDF_PARAMETER_SMOKERUN:
            result = PDC_BOOLSTR(p->pdc->smokerun);
            break;

        case PDF_PARAMETER_UNICAPLANG:
            result = PDC_BOOLSTR(p->pdc->unicaplang);
            break;


        case PDF_PARAMETER_CONFIGURATION:
            result = "lite";
            break;

        case PDF_PARAMETER_PRODUCT:
            result = "PDFlib Lite";
            break;

        case PDF_PARAMETER_ERRORPOLICY:
            result = pdc_get_keyword(p->errorpolicy, pdf_errpol_keylist);
            break;

        case PDF_PARAMETER_PDIUSEBOX:
            result = pdc_get_keyword(p->pdi_usebox, pdf_usebox_keylist);
            break;

        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:
            result = pdc_find_resource_nr(p->pdc, key, imod);
            break;

	case PDF_PARAMETER_FONTNAME:
            result = pdf_get_font_char_option(p, fo_fontname);
	    break;

        case PDF_PARAMETER_FONTENCODING:
            result = pdf_get_font_char_option(p, fo_encoding);
            break;

        case PDF_PARAMETER_FONTSTYLE:
            result = pdf_get_font_char_option(p, fo_fontstyle);
            break;

        case PDF_PARAMETER_ASCENDERFAKED:
            result = PDC_BOOLSTR(pdf_font_get_is_faked(&p->fonts[imod],
                                 font_ascender));
            break;

        case PDF_PARAMETER_DESCENDERFAKED:
            result = PDC_BOOLSTR(pdf_font_get_is_faked(&p->fonts[imod],
                                 font_descender));
            break;

        case PDF_PARAMETER_CAPHEIGHTFAKED:
            result = PDC_BOOLSTR(pdf_font_get_is_faked(&p->fonts[imod],
                                 font_capheight));
            break;

        case PDF_PARAMETER_XHEIGHTFAKED:
            result = PDC_BOOLSTR(pdf_font_get_is_faked(&p->fonts[imod],
                                 font_xheight));
            break;


        case PDF_PARAMETER_UNDERLINE:
            result = PDC_BOOLSTR((int) pdf_get_tstate(p, to_underline));
            break;

	case PDF_PARAMETER_OVERLINE:
            result = PDC_BOOLSTR((int) pdf_get_tstate(p, to_overline));
	    break;

	case PDF_PARAMETER_STRIKEOUT:
            result = PDC_BOOLSTR((int) pdf_get_tstate(p, to_strikeout));
	    break;

        /* deprecated */
	case PDF_PARAMETER_INHERITGSTATE:
            result = PDC_BOOLSTR(pdc_false);
	    break;

	case PDF_PARAMETER_SCOPE:
            result = pdf_current_scope(p);
	    break;

        case PDF_PARAMETER_TEXTFORMAT:
            result = pdc_get_keyword(p->textformat, pdf_textformat_keylist);
            break;

        case PDF_PARAMETER_HYPERTEXTFORMAT:
            result = pdc_get_keyword(p->hypertextformat,pdf_textformat_keylist);
            break;

        case PDF_PARAMETER_HYPERTEXTENCODING:
            result = pdf_get_encoding_name(p, p->hypertextencoding, NULL);
            break;

        case PDF_PARAMETER_RESOURCEFILE:
            result = pdc_get_resourcefile(p->pdc);
            break;

        /* deprecated */
        case PDF_PARAMETER_WARNING:
            result = PDC_BOOLSTR(0);
            break;

        case PDF_PARAMETER_OPENWARNING:
            result = PDC_BOOLSTR((int) p->debug[(int) 'o']);
            break;

        case PDF_PARAMETER_FONTWARNING:
            result = PDC_BOOLSTR((int) p->debug[(int) 'F']);
            break;

        case PDF_PARAMETER_ICCWARNING:
            result = PDC_BOOLSTR((int) p->debug[(int) 'I']);
            break;

        case PDF_PARAMETER_IMAGEWARNING:
            result = PDC_BOOLSTR((int) p->debug[(int) 'i']);
            break;

        case PDF_PARAMETER_PDIWARNING:
            result = PDC_BOOLSTR((int) p->debug[(int) 'p']);
            break;

        case PDF_PARAMETER_HONORICCPROFILE:
            result = PDC_BOOLSTR((int) p->debug[(int) 'e']);
            break;

        case PDF_PARAMETER_GLYPHWARNING:
            result = PDC_BOOLSTR((int) p->debug[(int) 'g']);
            break;

        case PDF_PARAMETER_RENDERINGINTENT:
            result = pdc_get_keyword(p->rendintent,
                                     pdf_renderingintent_pdfkeylist);
            break;

        case PDF_PARAMETER_PRESERVEOLDPANTONENAMES:
            result = PDC_BOOLSTR(p->preserveoldpantonenames);
            break;

        case PDF_PARAMETER_SPOTCOLORLOOKUP:
            result = PDC_BOOLSTR(p->spotcolorlookup);
            break;

        case PDF_PARAMETER_PDISTRICT:
            result = PDC_BOOLSTR(p->pdi_strict);
            break;

        case PDF_PARAMETER_TOPDOWN:
            result = PDC_BOOLSTR((p->ydirection == -1.0));
            break;

        case PDF_PARAMETER_USERCOORDINATES:
            result = PDC_BOOLSTR(p->usercoordinates);
            break;

        case PDF_PARAMETER_USEHYPERTEXTENCODING:
            result = PDC_BOOLSTR(p->usehyptxtenc);
            break;



        case PDF_PARAMETER_FILLRULE:
            result = pdc_get_keyword(ppt->fillrule, pdf_fillrule_keylist);
            break;



        case PDF_PARAMETER_COMPATIBILITY:
            result = pdc_get_keyword(p->compatibility,
                                     pdf_compatibility_keylist);
            break;

        case PDF_PARAMETER_STRING:
            pdf_check_handle(p, imod, pdc_stringhandle);
            result = pdf_get_utilstring(p, imod);
            break;

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

    return result ? result : "";
} /* pdf__get_parameter */
Exemplo n.º 4
0
pdc_bool
pdf_process_metrics_data(
    PDF *p,
    pdf_font *font,
    const char *fontname)
{
    static const char fn[] = "pdf_process_metrics_data";
    fnt_font_metric *ftm = &font->ft.m;
    int width = 0;
    pdc_ushort uv;
    pdc_encoding enc = font->ft.enc;
    pdc_encodingvector *ev = NULL;
    int /* nalloc, */ foundglyphs = 0, i, j = 0, k;

    (void) j;

    /* Unallowed encoding */
    if (enc == pdc_cid || enc < pdc_builtin)
    {

	pdc_set_errmsg(p->pdc, PDF_E_FONT_BADENC, 0, 0, 0, 0);

        return pdc_false;
    }

    /* Determine the default character width (width of space character) */
    if (font->opt.monospace)
    {
        ftm->defwidth = font->opt.monospace;
    }
    else
    {
        width = fnt_get_glyphwidth((int) PDF_DEFAULT_CHAR, &font->ft);
        if (width != FNT_MISSING_WIDTH)
            ftm->defwidth = width;
        else
            ftm->defwidth = FNT_DEFAULT_WIDTH;
    }

    /* builtin font */
    if (font->ft.issymbfont == pdc_true && enc != pdc_builtin &&
        !strcmp(font->encapiname, "auto"))
    {
        enc = pdc_builtin;
        font->ft.enc = enc;
    }

    /* optimizing PDF output */
    if (enc == pdc_ebcdic ||
        enc == pdc_ebcdic_37 ||
        enc == pdc_ebcdic_winansi)
        font->towinansi = pdc_winansi;

    /* glyph name list for incore fonts */
    /* nalloc = font->ft.numglyphs + AFM_GLYPH_SUPPL; */

    /*
     * Generate character width according to the chosen encoding
     */

    {
        font->ft.numcodes = 256;
        font->ft.code2gid = (pdc_ushort *) pdc_calloc(p->pdc,
                                 font->ft.numcodes  * sizeof (pdc_ushort), fn);

        ftm->numwidths = font->ft.numcodes;
        ftm->widths = (int *)pdc_calloc(p->pdc,
                                        font->ft.numcodes * sizeof(int), fn);

        /* Given 8-bit encoding */
        if (enc >= 0)
        {
            ev = pdc_get_encoding_vector(p->pdc, enc);
            for (k = 0; k < font->ft.numcodes; k++)
            {
                uv = ev->codes[k];
                ftm->widths[k] = ftm->defwidth;
                if (uv)
                {
                    uv = pdc_get_alter_glyphname(uv, font->missingglyphs, NULL);
                    if (uv)
                    {
                        for (i = 0; i < ftm->numglwidths; i++)
                        {
                            if (ftm->glw[i].unicode == uv)
                            {
                                j = i + 1;
                                ftm->widths[k] = ftm->glw[i].width;
                                font->ft.code2gid[k] = (pdc_ushort) j;
                                foundglyphs++;
                            }
                        }
                    }
                }
            }

            if (ftm->ciw != NULL)
            {
                pdc_free(p->pdc, ftm->ciw);
                ftm->ciw = NULL;
            }

            pdc_logg_cond(p->pdc, 2, trc_font,
                "\t\t%d glyphs could be mapped to Unicode\n", foundglyphs);

            /* No characters found */
            if (!foundglyphs)
            {
                if (font->ft.issymbfont == pdc_false)
                {
                    pdc_set_errmsg(p->pdc, PDF_E_FONT_BADENC, 0, 0, 0, 0);
                    return pdc_false;
                }
                else
                {
                    /* We enforce builtin encoding */
                    pdc_warning(p->pdc, PDF_E_FONT_FORCEENC,
                                pdf_get_encoding_name(p, pdc_builtin, font),
                                0, 0, 0);
                    enc = pdc_builtin;
                    font->ft.enc = enc;
                    font->towinansi = pdc_invalidenc;
                }
            }
            else if (foundglyphs < PDF_MIN_GLYPHS)
            {
                pdc_warning(p->pdc, PDF_E_FONT_INAPPROPENC,
                            pdc_errprintf(p->pdc, "%d", foundglyphs), 0, 0, 0);
            }
        }

        /* built-in encoding */
        if (enc == pdc_builtin)
        {
            if (ftm->glw == NULL)
            {
                pdc_set_errmsg(p->pdc, PDF_E_FONT_BADENC, 0, 0, 0, 0);
                return pdc_false;
            }

            /* encoding for builtin */
            ev = pdf_create_font_encoding(p, enc, font, fontname, pdc_true);
            font->symenc = font->ft.enc;

           /***************************/
            font->ft.enc = pdc_builtin;
           /***************************/

            for (i = 0; i < font->ft.numcodes; i++)
            {
                ftm->widths[i] = ftm->defwidth;
            }

            for (i = 0; i < font->ft.numglyphs; i++)
            {
                pdc_short code = ftm->glw[i].code;

                if (code >= 0 && code < font->ft.numcodes)
                {
                    j = i + 1;
                    ftm->widths[code] = ftm->glw[i].width;
                    font->ft.code2gid[code] = (pdc_ushort) j;
                    if (ev != NULL)
                    {
                        ev->codes[code] = ftm->glw[i].unicode;
                    }
                }
            }
        }
    }


    if (ftm->glw != NULL)
    {
        pdc_free(p->pdc, ftm->glw);
        ftm->glw = NULL;
    }

    return pdc_true;
}
Exemplo n.º 5
0
PDFLIB_API const char * PDFLIB_CALL
PDF_get_parameter(PDF *p, const char *key, float mod)
{
    static const char fn[] = "PDF_get_parameter";
    int i = -1;
    const char *result = "";

    /* some parameters can be retrieved with p == 0.
    */
    if (key != NULL && (i = get_index(key)) != -1)
    {
	switch (i)
	{
	    case PDF_PARAMETER_VERSION:
		result = PDFLIB_VERSIONSTRING;
		return result;

	    case PDF_PARAMETER_PDI:
		result = "false";
		return result;
	} /* switch */
    }

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

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

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

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

    if (parms[i].mod_zero && mod != (float) 0)
	pdc_error(p->pdc, PDC_E_PAR_ILLPARAM,
	    pdc_errprintf(p->pdc, "%f", mod), key, 0, 0);

    switch (i)
    {
	case PDF_PARAMETER_FONTNAME:
	    result = pdf_get_fontname(p);
	    break;

        case PDF_PARAMETER_FONTSTYLE:
            result = pdf_get_fontstyle(p);
            break;

        case PDF_PARAMETER_FONTENCODING:
            result = pdf_get_fontencoding(p);
            break;

	case PDF_PARAMETER_UNDERLINE:
            result = PDC_BOOLSTR(p->underline);
	    break;

	case PDF_PARAMETER_OVERLINE:
            result = PDC_BOOLSTR(p->overline);
	    break;

	case PDF_PARAMETER_STRIKEOUT:
            result = PDC_BOOLSTR(p->strikeout);
	    break;

	case PDF_PARAMETER_INHERITGSTATE:
            result = PDC_BOOLSTR(p->inheritgs);
	    break;

	case PDF_PARAMETER_SCOPE:
	    switch (p->state_stack[p->state_sp]) {
		case pdf_state_object:	result = "object";	break;
		case pdf_state_document:result = "document";	break;
		case pdf_state_page:	result = "page";	break;
		case pdf_state_pattern:	result = "pattern";	break;
		case pdf_state_template:result = "template";	break;
		case pdf_state_path:	result = "path";	break;
		default:		result = "(unknown)";	break;
	    }
	    break;

        case PDF_PARAMETER_TEXTFORMAT:
            result = pdc_get_keyword(p->textformat, pdf_textformat_keylist);
            break;

        case PDF_PARAMETER_HYPERTEXTFORMAT:
            result = pdc_get_keyword(p->hypertextformat,pdf_textformat_keylist);
            break;

        case PDF_PARAMETER_HYPERTEXTENCODING:
            result = pdf_get_encoding_name(p, p->hypertextencoding);
            break;

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

    pdc_trace(p->pdc, "[%s]\n", result);
    return result;
} /* PDF_get_parameter */
Exemplo n.º 6
0
pdc_bool
pdf_check_pfm_encoding(PDF *p, pdc_font *font, const char *fontname,
                       pdc_encoding enc)
{
    const char *encname;
    pdc_encoding enc_old = enc;
    int islatin1 = 0;

    /* Font encoding */
    switch (font->encoding)
    {
        case PFM_ANSI_CHARSET:
            font->encoding = pdc_winansi;
            font->isstdlatin = pdc_true;
            break;

        case PFM_SYMBOL_CHARSET:
            font->encoding = pdc_builtin;
            font->isstdlatin = pdc_false;
            break;

        default:
            pdc_set_errmsg(p->pdc, PDF_E_T1_BADCHARSET,
                pdc_errprintf(p->pdc, "%d", font->encoding), fontname, 0, 0);

            if (font->verbose == pdc_true)
                pdc_error(p->pdc, -1, 0, 0, 0, 0);

            return pdc_false;
    }

    /* iso8859-1 */
    if (enc > 0)
    {
        islatin1 = !strcmp(pdf_get_encoding_name(p, enc), "iso8859-1");
        if (font->encoding == pdc_winansi)
            font->encoding = enc;
    }

    /* Unicode encoding */
    if (enc == pdc_unicode)
    {
        enc = pdf_find_encoding(p, "iso8859-1");
        font->encoding = enc;
        islatin1 = 1;
    }

    /* Unallowed encoding */
    encname = pdc_errprintf(p->pdc, "%s", pdf_get_encoding_name(p, enc_old));
    if (enc < pdc_builtin)
    {
        pdc_set_errmsg(p->pdc, PDF_E_FONT_BADENC, fontname, encname, 0, 0);

        if (font->verbose == pdc_true)
            pdc_error(p->pdc, -1, 0, 0, 0, 0);

        return pdc_false;
    }

    if (font->verbose == pdc_true)
    {
        if (enc != pdc_winansi && !islatin1 &&
            font->encoding != pdc_builtin)
        {
            pdc_warning(p->pdc, PDF_E_FONT_FORCEENC,
                pdf_get_encoding_name(p, pdc_winansi), encname, fontname, 0);
        }
        if (enc != pdc_builtin && font->encoding == pdc_builtin)
        {
            pdc_warning(p->pdc, PDF_E_FONT_FORCEENC,
                pdf_get_encoding_name(p, pdc_builtin), encname, fontname, 0);
        }
    }

    return pdc_true;
}