static void pdf_load_builtin_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname, int has_descriptor) { FT_Face face; const char *clean_name = clean_font_name(fontname); fontdesc->font = fz_load_system_font(ctx, fontname, 0, 0, !has_descriptor); if (!fontdesc->font) { unsigned char *data; unsigned int len; data = pdf_lookup_builtin_font(clean_name, &len); if (!data) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find builtin font: '%s'", fontname); fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1); } if (!strcmp(clean_name, "Symbol") || !strcmp(clean_name, "ZapfDingbats")) fontdesc->flags |= PDF_FD_SYMBOLIC; face = fontdesc->font->ft_face; fontdesc->ascent = 1000.0f * face->ascender / face->units_per_EM; fontdesc->descent = 1000.0f * face->descender / face->units_per_EM; }
static void pdf_load_builtin_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname) { unsigned char *data; unsigned int len; #ifdef _WIN32 /* SumatraPDF: prefer system fonts unless a base font is explicitly requested */ char *clean_name = clean_font_name(fontname); if (!pdf_lookup_builtin_font(fontname, &len) && /* cf. http://code.google.com/p/sumatrapdf/issues/detail?id=2173 */ (clean_name == fontname || strncmp(clean_name, "Times-", 6) != 0)) { void pdf_load_windows_font(fz_context *ctx, pdf_font_desc *font, char *fontname); /* TODO: the metrics for Times-Roman and Courier don't match those of Windows' Times New Roman and Courier New; for some reason, Poppler doesn't seem to have this problem */ fz_try(ctx) { pdf_load_windows_font(ctx, fontdesc, fontname); } fz_catch(ctx) { } printf(" fontdesc->font=%p\n",fontdesc->font); if (fontdesc->font) return; }
static void pdf_load_builtin_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname) { unsigned char *data; unsigned int len; data = pdf_lookup_builtin_font(fontname, &len); if (!data) fz_throw(ctx, "cannot find builtin font: '%s'", fontname); fontdesc->font = fz_new_font_from_memory(ctx, data, len, 0, 1); /* RJW: "cannot load freetype font from memory" */ if (!strcmp(fontname, "Symbol") || !strcmp(fontname, "ZapfDingbats")) fontdesc->flags |= PDF_FD_SYMBOLIC; }
static void pdf_load_builtin_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname) { unsigned char *data; unsigned int len; fontname = clean_font_name(fontname); data = pdf_lookup_builtin_font(fontname, &len); if (!data) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find builtin font: '%s'", fontname); fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1); if (!strcmp(fontname, "Symbol") || !strcmp(fontname, "ZapfDingbats")) fontdesc->flags |= PDF_FD_SYMBOLIC; }
fz_font * fz_load_html_font(fz_context *ctx, fz_html_font_set *set, const char *family, const char *variant, const char *style, const char *weight) { unsigned char *data; unsigned int size; int is_mono = !strcmp(family, "monospace"); int is_sans = !strcmp(family, "sans-serif"); int is_bold = !strcmp(weight, "bold") || !strcmp(weight, "bolder") || atoi(weight) > 400; int is_italic = !strcmp(style, "italic") || !strcmp(style, "oblique"); int idx = is_mono * 8 + is_sans * 4 + is_bold * 2 + is_italic; if (!set->fonts[idx]) { data = pdf_lookup_builtin_font(ctx, font_names[idx], &size); if (!data) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load html font: %s", font_names[idx]); set->fonts[idx] = fz_new_font_from_memory(ctx, font_names[idx], data, size, 0, 1); } return set->fonts[idx]; }
/* TODO: the metrics for Times-Roman and Courier don't match those of Windows' Times New Roman and Courier New; for some reason, Poppler doesn't seem to have this problem */ fz_try(ctx) { pdf_load_windows_font(ctx, fontdesc, fontname); } fz_catch(ctx) { } printf(" fontdesc->font=%p\n",fontdesc->font); if (fontdesc->font) return; } #endif fontname = clean_font_name(fontname); data = pdf_lookup_builtin_font(fontname, &len); if (!data) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find builtin font: '%s'", fontname); fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, 0, 1); if (!strcmp(fontname, "Symbol") || !strcmp(fontname, "ZapfDingbats")) fontdesc->flags |= PDF_FD_SYMBOLIC; } static void pdf_load_substitute_font(fz_context *ctx, pdf_font_desc *fontdesc, char *fontname, int mono, int serif, int bold, int italic) { unsigned char *data; unsigned int len;
unsigned char * pdf_lookup_substitute_font(int mono, int serif, int bold, int italic, unsigned int *len) { #ifdef NODROIDFONT if (mono) { if (bold) { if (italic) return pdf_lookup_builtin_font("Courier-BoldOblique", len); else return pdf_lookup_builtin_font("Courier-Bold", len); } else { if (italic) return pdf_lookup_builtin_font("Courier-Oblique", len); else return pdf_lookup_builtin_font("Courier", len); } } else if (serif) { if (bold) { if (italic) return pdf_lookup_builtin_font("Times-BoldItalic", len); else return pdf_lookup_builtin_font("Times-Bold", len); } else { if (italic) return pdf_lookup_builtin_font("Times-Italic", len); else return pdf_lookup_builtin_font("Times-Roman", len); } } else { if (bold) { if (italic) return pdf_lookup_builtin_font("Helvetica-BoldOblique", len); else return pdf_lookup_builtin_font("Helvetica-Bold", len); } else { if (italic) return pdf_lookup_builtin_font("Helvetica-Oblique", len); else return pdf_lookup_builtin_font("Helvetica", len); } } #else if (mono) { *len = sizeof pdf_font_DroidSansMono; return (unsigned char*) pdf_font_DroidSansMono; } else { *len = sizeof pdf_font_DroidSans; return (unsigned char*) pdf_font_DroidSans; } #endif }