From 650854f4a13a9610055bbd4d97918f5367c08332 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 12 May 2010 23:12:55 +0930 Subject: [PATCH] type1: Use correct glyph advance when subsetting type 1 fonts Previously the glyph advance in fonts units was used for the widths in the PDF font dictionary. This only works for Type 1 fonts that use a [0.001 0 0 0.001 0 0] font matrix. https://bugs.freedesktop.org/show_bug.cgi?id=28061 --- src/cairo-pdf-surface.c | 8 ++++---- src/cairo-scaled-font-subsets-private.h | 2 +- src/cairo-type1-fallback.c | 2 +- src/cairo-type1-subset.c | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c index da51295..03b6d3c 100644 --- a/src/cairo-pdf-surface.c +++ b/src/cairo-pdf-surface.c @@ -3858,6 +3858,8 @@ _cairo_pdf_surface_emit_to_unicode_stream (cairo_pdf_surface_t *surface, return _cairo_pdf_surface_close_stream (surface); } +#define PDF_UNITS_PER_EM 1000 + static cairo_status_t _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t *surface, cairo_scaled_font_subset_t *font_subset, @@ -4132,8 +4134,8 @@ _cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t *surface, for (i = 0; i < font_subset->num_glyphs; i++) _cairo_output_stream_printf (surface->output, - " %d", - subset->widths[i]); + " %ld", + (long)(subset->widths[i]*PDF_UNITS_PER_EM)); _cairo_output_stream_printf (surface->output, " ]\n"); @@ -4195,8 +4197,6 @@ _cairo_pdf_surface_emit_type1_fallback_font (cairo_pdf_surface_t *surface, return status; } -#define PDF_UNITS_PER_EM 1000 - static cairo_status_t _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t *surface, cairo_scaled_font_subset_t *font_subset) diff --git a/src/cairo-scaled-font-subsets-private.h b/src/cairo-scaled-font-subsets-private.h index 9e12a91..bb7892c 100644 --- a/src/cairo-scaled-font-subsets-private.h +++ b/src/cairo-scaled-font-subsets-private.h @@ -451,7 +451,7 @@ _cairo_truetype_subset_fini (cairo_truetype_subset_t *truetype_subset); typedef struct _cairo_type1_subset { char *base_font; - int *widths; + double *widths; long x_min, y_min, x_max, y_max; long ascent, descent; char *data; diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c index 7894f7e..610bc5c 100644 --- a/src/cairo-type1-fallback.c +++ b/src/cairo-type1-fallback.c @@ -727,7 +727,7 @@ _cairo_type1_fallback_init_internal (cairo_type1_subset_t *type1_subset, goto fail1; } - type1_subset->widths = calloc (sizeof (int), font->scaled_font_subset->num_glyphs); + type1_subset->widths = calloc (sizeof (double), font->scaled_font_subset->num_glyphs); if (unlikely (type1_subset->widths == NULL)) { status = _cairo_error (CAIRO_STATUS_NO_MEMORY); goto fail2; diff --git a/src/cairo-type1-subset.c b/src/cairo-type1-subset.c index 3757fff..d92c860 100644 --- a/src/cairo-type1-subset.c +++ b/src/cairo-type1-subset.c @@ -83,7 +83,7 @@ typedef struct _cairo_type1_font_subset { struct { int subset_index; - int width; + double width; char *name; } *glyphs; @@ -566,7 +566,7 @@ cairo_type1_font_subset_get_glyph_names_and_widths (cairo_type1_font_subset_t *f return CAIRO_INT_STATUS_UNSUPPORTED; } - font->glyphs[i].width = font->face->glyph->metrics.horiAdvance; + font->glyphs[i].width = font->face->glyph->linearHoriAdvance / 65536.0; /* 16.16 format */ error = FT_Get_Glyph_Name(font->face, i, buffer, sizeof buffer); if (error != FT_Err_Ok) { @@ -1346,7 +1346,7 @@ _cairo_type1_subset_init (cairo_type1_subset_t *type1_subset, if (unlikely (type1_subset->base_font == NULL)) goto fail1; - type1_subset->widths = calloc (sizeof (int), font.num_glyphs); + type1_subset->widths = calloc (sizeof (double), font.num_glyphs); if (unlikely (type1_subset->widths == NULL)) goto fail2; for (i = 0; i < font.base.num_glyphs; i++) { -- 1.7.0.4