Skip to content

Commit

Permalink
Return latin to glyph mapping in cairo_scaled_font_subset_t
Browse files Browse the repository at this point in the history
so that font subsetters can include the latin to glyph encoding in the
subsetted font.
  • Loading branch information
Adrian Johnson committed Oct 1, 2010
1 parent 807e690 commit e62891c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/cairo-scaled-font-subsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ typedef struct _cairo_sub_font_collection {
unsigned long *glyphs; /* scaled_font_glyph_index */
char **utf8;
unsigned int glyphs_size;
unsigned long *latin_to_subset_glyph_index;
unsigned int max_glyph;
unsigned int num_glyphs;

Expand Down Expand Up @@ -230,6 +231,9 @@ _cairo_sub_font_glyph_collect (void *entry, void *closure)

collection->glyphs[subset_glyph_index] = scaled_font_glyph_index;
collection->utf8[subset_glyph_index] = sub_font_glyph->utf8;
if (sub_font_glyph->is_latin)
collection->latin_to_subset_glyph_index[sub_font_glyph->latin_character] = subset_glyph_index;

if (subset_glyph_index > collection->max_glyph)
collection->max_glyph = subset_glyph_index;

Expand Down Expand Up @@ -674,6 +678,7 @@ _cairo_sub_font_collect (void *entry, void *closure)
collection->subset_id = i;
collection->num_glyphs = 0;
collection->max_glyph = 0;
memset (collection->latin_to_subset_glyph_index, 0, 256*sizeof(unsigned long));

_cairo_hash_table_foreach (sub_font->sub_font_glyphs,
_cairo_sub_font_glyph_collect, collection);
Expand All @@ -694,6 +699,15 @@ _cairo_sub_font_collect (void *entry, void *closure)
subset.utf8 = collection->utf8;
subset.num_glyphs = collection->num_glyphs;
subset.glyph_names = NULL;

subset.is_latin = FALSE;
if (sub_font->parent->use_latin_subset && i == 0) {
subset.is_latin = TRUE;
subset.latin_to_subset_glyph_index = collection->latin_to_subset_glyph_index;
} else {
subset.latin_to_subset_glyph_index = NULL;
}

/* No need to check for out of memory here. If to_unicode is NULL, the PDF
* surface does not emit an ToUnicode stream */
subset.to_unicode = _cairo_malloc_ab (collection->num_glyphs, sizeof (unsigned long));
Expand Down Expand Up @@ -1005,11 +1019,16 @@ _cairo_scaled_font_subsets_foreach_internal (cairo_scaled_font_subsets_t

collection.glyphs = _cairo_malloc_ab (collection.glyphs_size, sizeof(unsigned long));
collection.utf8 = _cairo_malloc_ab (collection.glyphs_size, sizeof(char *));
if (unlikely (collection.glyphs == NULL || collection.utf8 == NULL)) {
collection.latin_to_subset_glyph_index = _cairo_malloc_ab (256, sizeof(unsigned long));
if (unlikely (collection.glyphs == NULL ||
collection.utf8 == NULL ||
collection.latin_to_subset_glyph_index == NULL)) {
if (collection.glyphs != NULL)
free (collection.glyphs);
if (collection.utf8 != NULL)
free (collection.utf8);
if (collection.latin_to_subset_glyph_index != NULL)
free (collection.latin_to_subset_glyph_index);

return _cairo_error (CAIRO_STATUS_NO_MEMORY);
}
Expand All @@ -1031,6 +1050,7 @@ _cairo_scaled_font_subsets_foreach_internal (cairo_scaled_font_subsets_t
}
free (collection.utf8);
free (collection.glyphs);
free (collection.latin_to_subset_glyph_index);

return collection.status;
}
Expand Down
2 changes: 2 additions & 0 deletions src/cairoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,11 @@ typedef struct _cairo_scaled_font_subset {
unsigned long *to_unicode;
char **utf8;
char **glyph_names;
unsigned long *latin_to_subset_glyph_index;
unsigned int num_glyphs;
cairo_bool_t is_composite;
cairo_bool_t is_scaled;
cairo_bool_t is_latin;
} cairo_scaled_font_subset_t;

struct _cairo_scaled_font_backend {
Expand Down

0 comments on commit e62891c

Please sign in to comment.