static void pdf_type3_protocol(PDF *p, pdf_font *font, pdc_encodingvector *ev) { /* logging protocol */ if (pdc_logg_is_enabled(p->pdc, 2, trc_font)) { char *glyphname; pdc_ushort uv = 0; int gid, code, width = 0; for (gid = 0; gid < font->t3font->next_glyph; gid++) { glyphname = NULL; pdc_logg(p->pdc, "\t\tGlyph%4d: ", gid); if (ev != NULL) { code = font->ft.gid2code[gid]; uv = ev->codes[code]; if (glyphname == NULL) glyphname = ev->chars[code]; width = fnt_get_glyphwidth(code, &font->ft); pdc_logg(p->pdc, "code=%3d ", code); } if (width == FNT_MISSING_WIDTH) width = 0; pdc_logg(p->pdc, "U+%04X width=%4d \"%s\"\n", uv, width, glyphname); } } }
void fnt_font_logg_widths(pdc_core *pdc, fnt_font *font) { if (font != NULL && pdc_logg_is_enabled(pdc, 2, trc_font)) { int code, width; for (code = 0; code < PDC_NUM_UNIVAL; code++) { width = fnt_get_glyphwidth(code, font); if (width == FNT_MISSING_WIDTH) break; pdc_logg(pdc, "\t\tWidth[%d]: %d\n", code, width); } } }
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; }