summaryrefslogtreecommitdiff
path: root/src/cairo-cff-subset.c
diff options
context:
space:
mode:
authorAdrian Johnson <ajohnson@redneon.com>2010-05-16 17:47:13 +0930
committerAdrian Johnson <ajohnson@redneon.com>2010-05-16 20:52:31 +0930
commit562c323ae8689907d7a62a7c2f5c10fb8d055608 (patch)
tree1acb0f3d9980453e36e672a25036e46255491a47 /src/cairo-cff-subset.c
parentedcefa87ed0a8ff59b54ef9251182ce68f9158ba (diff)
cff: Use correct glyph advance when subsetting cff fonts
Previously the glyph advance in font units was used for the widths in the PDF font dictionary. This only works for cff fonts that use a [0.001 0 0 0.001 0 0] font matrix.
Diffstat (limited to 'src/cairo-cff-subset.c')
-rw-r--r--src/cairo-cff-subset.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/cairo-cff-subset.c b/src/cairo-cff-subset.c
index 1978bf06..a4a434f7 100644
--- a/src/cairo-cff-subset.c
+++ b/src/cairo-cff-subset.c
@@ -118,6 +118,7 @@ typedef struct _cairo_cff_font {
cairo_array_t local_sub_index;
int num_glyphs;
cairo_bool_t is_cid;
+ int units_per_em;
/* CID Font Data */
int *fdselect;
@@ -1773,6 +1774,9 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t *scaled_font_subset,
font->y_max = (int16_t) be16_to_cpu (head.y_max);
font->ascent = (int16_t) be16_to_cpu (hhea.ascender);
font->descent = (int16_t) be16_to_cpu (hhea.descender);
+ font->units_per_em = (int16_t) be16_to_cpu (head.units_per_em);
+ if (font->units_per_em == 0)
+ font->units_per_em = 1000;
font->font_name = NULL;
status = _cairo_truetype_read_font_name (scaled_font_subset->scaled_font,
@@ -1956,20 +1960,20 @@ _cairo_cff_subset_init (cairo_cff_subset_t *cff_subset,
cff_subset->font_name = NULL;
}
- cff_subset->widths = calloc (sizeof (int), font->scaled_font_subset->num_glyphs);
+ cff_subset->widths = calloc (sizeof (double), font->scaled_font_subset->num_glyphs);
if (unlikely (cff_subset->widths == NULL)) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto fail3;
}
for (i = 0; i < font->scaled_font_subset->num_glyphs; i++)
- cff_subset->widths[i] = font->widths[i];
+ cff_subset->widths[i] = (double)font->widths[i]/font->units_per_em;
- cff_subset->x_min = font->x_min;
- cff_subset->y_min = font->y_min;
- cff_subset->x_max = font->x_max;
- cff_subset->y_max = font->y_max;
- cff_subset->ascent = font->ascent;
- cff_subset->descent = font->descent;
+ cff_subset->x_min = (double)font->x_min/font->units_per_em;
+ cff_subset->y_min = (double)font->y_min/font->units_per_em;
+ cff_subset->x_max = (double)font->x_max/font->units_per_em;
+ cff_subset->y_max = (double)font->y_max/font->units_per_em;
+ cff_subset->ascent = (double)font->ascent/font->units_per_em;
+ cff_subset->descent = (double)font->descent/font->units_per_em;
cff_subset->data = malloc (length);
if (unlikely (cff_subset->data == NULL)) {
@@ -2213,21 +2217,21 @@ _cairo_cff_fallback_init (cairo_cff_subset_t *cff_subset,
goto fail2;
}
- cff_subset->widths = calloc (sizeof (int), font->scaled_font_subset->num_glyphs);
+ cff_subset->widths = calloc (sizeof (double), font->scaled_font_subset->num_glyphs);
if (unlikely (cff_subset->widths == NULL)) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto fail3;
}
for (i = 0; i < font->scaled_font_subset->num_glyphs; i++)
- cff_subset->widths[i] = type2_subset.widths[i];
-
- cff_subset->x_min = type2_subset.x_min;
- cff_subset->y_min = type2_subset.y_min;
- cff_subset->x_max = type2_subset.x_max;
- cff_subset->y_max = type2_subset.y_max;
- cff_subset->ascent = type2_subset.y_max;
- cff_subset->descent = type2_subset.y_min;
+ cff_subset->widths[i] = (double)type2_subset.widths[i]/1000;
+
+ cff_subset->x_min = (double)type2_subset.x_min/1000;
+ cff_subset->y_min = (double)type2_subset.y_min/1000;
+ cff_subset->x_max = (double)type2_subset.x_max/1000;
+ cff_subset->y_max = (double)type2_subset.y_max/1000;
+ cff_subset->ascent = (double)type2_subset.y_max/1000;
+ cff_subset->descent = (double)type2_subset.y_min/1000;
cff_subset->data = malloc (length);
if (unlikely (cff_subset->data == NULL)) {