static cairo_status_t cairo_truetype_font_write_offset_table (cairo_truetype_font_t *font) { cairo_status_t status; unsigned char *table_buffer; size_t table_buffer_length; unsigned short search_range, entry_selector, range_shift; search_range = 1; entry_selector = 0; while (search_range * 2 <= font->num_tables) { search_range *= 2; entry_selector++; } search_range *= 16; range_shift = font->num_tables * 16 - search_range; cairo_truetype_font_write_be32 (font, SFNT_VERSION); cairo_truetype_font_write_be16 (font, font->num_tables); cairo_truetype_font_write_be16 (font, search_range); cairo_truetype_font_write_be16 (font, entry_selector); cairo_truetype_font_write_be16 (font, range_shift); /* Allocate space for the table directory. Each directory entry * will be filled in by cairo_truetype_font_update_entry() after * the table is written. */ table_buffer_length = font->num_tables * 16; status = cairo_truetype_font_allocate_write_buffer (font, table_buffer_length, &table_buffer); if (status) return status; return font->status; }
static cairo_status_t cairo_truetype_font_write_loca_table (cairo_truetype_font_t *font, unsigned long tag) { unsigned int i; tt_head_t header; unsigned long size; cairo_status_t status; if (font->status) return font->status; size = sizeof(tt_head_t); status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font, TT_TAG_head, 0, (unsigned char*) &header, &size); if (unlikely (status)) return _cairo_truetype_font_set_error (font, status); if (be16_to_cpu (header.index_to_loc_format) == 0) { for (i = 0; i < font->base.num_glyphs + 1; i++) cairo_truetype_font_write_be16 (font, font->glyphs[i].location / 2); } else { for (i = 0; i < font->base.num_glyphs + 1; i++) cairo_truetype_font_write_be32 (font, font->glyphs[i].location); } return font->status; }
static cairo_status_t cairo_truetype_font_write_cmap_table (cairo_truetype_font_t *font, unsigned long tag) { unsigned int i; cairo_truetype_font_write_be16 (font, 0); /* Table version */ cairo_truetype_font_write_be16 (font, 2); /* Num tables */ cairo_truetype_font_write_be16 (font, 3); /* Platform */ cairo_truetype_font_write_be16 (font, 0); /* Encoding */ cairo_truetype_font_write_be32 (font, 20); /* Offset to start of table */ cairo_truetype_font_write_be16 (font, 1); /* Platform */ cairo_truetype_font_write_be16 (font, 0); /* Encoding */ cairo_truetype_font_write_be32 (font, 52); /* Offset to start of table */ /* Output a format 4 encoding table. */ cairo_truetype_font_write_be16 (font, 4); /* Format */ cairo_truetype_font_write_be16 (font, 32); /* Length */ cairo_truetype_font_write_be16 (font, 0); /* Version */ cairo_truetype_font_write_be16 (font, 4); /* 2*segcount */ cairo_truetype_font_write_be16 (font, 4); /* searchrange */ cairo_truetype_font_write_be16 (font, 1); /* entry selector */ cairo_truetype_font_write_be16 (font, 0); /* rangeshift */ cairo_truetype_font_write_be16 (font, 0xf000 + font->base.num_glyphs - 1); /* end count[0] */ cairo_truetype_font_write_be16 (font, 0xffff); /* end count[1] */ cairo_truetype_font_write_be16 (font, 0); /* reserved */ cairo_truetype_font_write_be16 (font, 0xf000); /* startCode[0] */ cairo_truetype_font_write_be16 (font, 0xffff); /* startCode[1] */ cairo_truetype_font_write_be16 (font, 0x1000); /* delta[0] */ cairo_truetype_font_write_be16 (font, 1); /* delta[1] */ cairo_truetype_font_write_be16 (font, 0); /* rangeOffset[0] */ cairo_truetype_font_write_be16 (font, 0); /* rangeOffset[1] */ /* Output a format 6 encoding table. */ cairo_truetype_font_write_be16 (font, 6); cairo_truetype_font_write_be16 (font, 10 + 2 * font->base.num_glyphs); cairo_truetype_font_write_be16 (font, 0); cairo_truetype_font_write_be16 (font, 0); /* First character */ cairo_truetype_font_write_be16 (font, font->base.num_glyphs); for (i = 0; i < font->base.num_glyphs; i++) cairo_truetype_font_write_be16 (font, i); return font->status; }
static cairo_status_t cairo_truetype_font_write_cmap_table (cairo_truetype_font_t *font, unsigned long tag) { int i; unsigned int j; int range_offset; int num_ranges; int entry_selector; int length; num_ranges = ARRAY_LENGTH (winansi_unicode_ranges); length = 16 + (num_ranges + 1)*8; for (i = 0; i < num_ranges; i++) length += (winansi_unicode_ranges[i].end - winansi_unicode_ranges[i].start + 1)*2; entry_selector = 0; while ((1 << entry_selector) <= (num_ranges + 1)) entry_selector++; entry_selector--; cairo_truetype_font_write_be16 (font, 0); /* Table version */ cairo_truetype_font_write_be16 (font, 1); /* Num tables */ cairo_truetype_font_write_be16 (font, 3); /* Platform */ cairo_truetype_font_write_be16 (font, 1); /* Encoding */ cairo_truetype_font_write_be32 (font, 12); /* Offset to start of table */ /* Output a format 4 encoding table for the winansi encoding */ cairo_truetype_font_write_be16 (font, 4); /* Format */ cairo_truetype_font_write_be16 (font, length); /* Length */ cairo_truetype_font_write_be16 (font, 0); /* Version */ cairo_truetype_font_write_be16 (font, num_ranges*2 + 2); /* 2*segcount */ cairo_truetype_font_write_be16 (font, (1 << (entry_selector + 1))); /* searchrange */ cairo_truetype_font_write_be16 (font, entry_selector); /* entry selector */ cairo_truetype_font_write_be16 (font, num_ranges*2 + 2 - (1 << (entry_selector + 1))); /* rangeshift */ for (i = 0; i < num_ranges; i++) cairo_truetype_font_write_be16 (font, winansi_unicode_ranges[i].end); /* end count[] */ cairo_truetype_font_write_be16 (font, 0xffff); /* end count[] */ cairo_truetype_font_write_be16 (font, 0); /* reserved */ for (i = 0; i < num_ranges; i++) cairo_truetype_font_write_be16 (font, winansi_unicode_ranges[i].start); /* startCode[] */ cairo_truetype_font_write_be16 (font, 0xffff); /* startCode[] */ for (i = 0; i < num_ranges; i++) cairo_truetype_font_write_be16 (font, 0x0000); /* delta[] */ cairo_truetype_font_write_be16 (font, 1); /* delta[] */ range_offset = num_ranges*2 + 2; for (i = 0; i < num_ranges; i++) { cairo_truetype_font_write_be16 (font, range_offset); /* rangeOffset[] */ range_offset += (winansi_unicode_ranges[i].end - winansi_unicode_ranges[i].start + 1)*2 - 2; } cairo_truetype_font_write_be16 (font, 0); /* rangeOffset[] */ for (i = 0; i < num_ranges; i++) { for (j = winansi_unicode_ranges[i].start; j < winansi_unicode_ranges[i].end + 1; j++) { int ch = _cairo_unicode_to_winansi (j); int glyph; if (ch > 0) glyph = font->scaled_font_subset->latin_to_subset_glyph_index[ch]; else glyph = 0; cairo_truetype_font_write_be16 (font, glyph); } } return font->status; }