mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-31 19:10:26 +01:00
type1: Use correct glyph advance when subsetting type 1 fonts
Previously the glyph advance in font 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
This commit is contained in:
parent
34fd094b3b
commit
edcefa87ed
4 changed files with 26 additions and 25 deletions
|
|
@ -3849,6 +3849,8 @@ _cairo_pdf_surface_emit_to_unicode_stream (cairo_pdf_surface_t *surface,
|
||||||
return _cairo_pdf_surface_close_stream (surface);
|
return _cairo_pdf_surface_close_stream (surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PDF_UNITS_PER_EM 1000
|
||||||
|
|
||||||
static cairo_status_t
|
static cairo_status_t
|
||||||
_cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t *surface,
|
_cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t *surface,
|
||||||
cairo_scaled_font_subset_t *font_subset,
|
cairo_scaled_font_subset_t *font_subset,
|
||||||
|
|
@ -4088,7 +4090,7 @@ _cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t *surface,
|
||||||
" /ItalicAngle 0\n"
|
" /ItalicAngle 0\n"
|
||||||
" /Ascent %ld\n"
|
" /Ascent %ld\n"
|
||||||
" /Descent %ld\n"
|
" /Descent %ld\n"
|
||||||
" /CapHeight 500\n"
|
" /CapHeight %ld\n"
|
||||||
" /StemV 80\n"
|
" /StemV 80\n"
|
||||||
" /StemH 80\n"
|
" /StemH 80\n"
|
||||||
" /FontFile %u 0 R\n"
|
" /FontFile %u 0 R\n"
|
||||||
|
|
@ -4097,12 +4099,13 @@ _cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t *surface,
|
||||||
descriptor.id,
|
descriptor.id,
|
||||||
tag,
|
tag,
|
||||||
subset->base_font,
|
subset->base_font,
|
||||||
subset->x_min,
|
(long)(subset->x_min*PDF_UNITS_PER_EM),
|
||||||
subset->y_min,
|
(long)(subset->y_min*PDF_UNITS_PER_EM),
|
||||||
subset->x_max,
|
(long)(subset->x_max*PDF_UNITS_PER_EM),
|
||||||
subset->y_max,
|
(long)(subset->y_max*PDF_UNITS_PER_EM),
|
||||||
subset->ascent,
|
(long)(subset->ascent*PDF_UNITS_PER_EM),
|
||||||
subset->descent,
|
(long)(subset->descent*PDF_UNITS_PER_EM),
|
||||||
|
(long)(subset->y_max*PDF_UNITS_PER_EM),
|
||||||
stream.id);
|
stream.id);
|
||||||
|
|
||||||
_cairo_pdf_surface_update_object (surface, subset_resource);
|
_cairo_pdf_surface_update_object (surface, subset_resource);
|
||||||
|
|
@ -4123,8 +4126,8 @@ _cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t *surface,
|
||||||
|
|
||||||
for (i = 0; i < font_subset->num_glyphs; i++)
|
for (i = 0; i < font_subset->num_glyphs; i++)
|
||||||
_cairo_output_stream_printf (surface->output,
|
_cairo_output_stream_printf (surface->output,
|
||||||
" %d",
|
" %ld",
|
||||||
subset->widths[i]);
|
(long)(subset->widths[i]*PDF_UNITS_PER_EM));
|
||||||
|
|
||||||
_cairo_output_stream_printf (surface->output,
|
_cairo_output_stream_printf (surface->output,
|
||||||
" ]\n");
|
" ]\n");
|
||||||
|
|
@ -4186,8 +4189,6 @@ _cairo_pdf_surface_emit_type1_fallback_font (cairo_pdf_surface_t *surface,
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PDF_UNITS_PER_EM 1000
|
|
||||||
|
|
||||||
static cairo_status_t
|
static cairo_status_t
|
||||||
_cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t *surface,
|
_cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t *surface,
|
||||||
cairo_scaled_font_subset_t *font_subset)
|
cairo_scaled_font_subset_t *font_subset)
|
||||||
|
|
|
||||||
|
|
@ -451,9 +451,9 @@ _cairo_truetype_subset_fini (cairo_truetype_subset_t *truetype_subset);
|
||||||
|
|
||||||
typedef struct _cairo_type1_subset {
|
typedef struct _cairo_type1_subset {
|
||||||
char *base_font;
|
char *base_font;
|
||||||
int *widths;
|
double *widths;
|
||||||
long x_min, y_min, x_max, y_max;
|
double x_min, y_min, x_max, y_max;
|
||||||
long ascent, descent;
|
double ascent, descent;
|
||||||
char *data;
|
char *data;
|
||||||
unsigned long header_length;
|
unsigned long header_length;
|
||||||
unsigned long data_length;
|
unsigned long data_length;
|
||||||
|
|
|
||||||
|
|
@ -727,20 +727,20 @@ _cairo_type1_fallback_init_internal (cairo_type1_subset_t *type1_subset,
|
||||||
goto fail1;
|
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)) {
|
if (unlikely (type1_subset->widths == NULL)) {
|
||||||
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||||
goto fail2;
|
goto fail2;
|
||||||
}
|
}
|
||||||
for (i = 0; i < font->scaled_font_subset->num_glyphs; i++)
|
for (i = 0; i < font->scaled_font_subset->num_glyphs; i++)
|
||||||
type1_subset->widths[i] = font->widths[i];
|
type1_subset->widths[i] = (double)font->widths[i]/1000;
|
||||||
|
|
||||||
type1_subset->x_min = (int) font->x_min;
|
type1_subset->x_min = (double)font->x_min/1000;
|
||||||
type1_subset->y_min = (int) font->y_min;
|
type1_subset->y_min = (double)font->y_min/1000;
|
||||||
type1_subset->x_max = (int) font->x_max;
|
type1_subset->x_max = (double)font->x_max/1000;
|
||||||
type1_subset->y_max = (int) font->y_max;
|
type1_subset->y_max = (double)font->y_max/1000;
|
||||||
type1_subset->ascent = (int) font->y_max;
|
type1_subset->ascent = (double)font->y_max/1000;
|
||||||
type1_subset->descent = (int) font->y_min;
|
type1_subset->descent = (double)font->y_min/1000;
|
||||||
|
|
||||||
length = font->header_size + font->data_size +
|
length = font->header_size + font->data_size +
|
||||||
font->trailer_size;
|
font->trailer_size;
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ typedef struct _cairo_type1_font_subset {
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int subset_index;
|
int subset_index;
|
||||||
int width;
|
double width;
|
||||||
char *name;
|
char *name;
|
||||||
} *glyphs;
|
} *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;
|
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);
|
error = FT_Get_Glyph_Name(font->face, i, buffer, sizeof buffer);
|
||||||
if (error != FT_Err_Ok) {
|
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))
|
if (unlikely (type1_subset->base_font == NULL))
|
||||||
goto fail1;
|
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))
|
if (unlikely (type1_subset->widths == NULL))
|
||||||
goto fail2;
|
goto fail2;
|
||||||
for (i = 0; i < font.base.num_glyphs; i++) {
|
for (i = 0; i < font.base.num_glyphs; i++) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue