-
Notifications
You must be signed in to change notification settings - Fork 681
Closed
Description
Now that we have COLR/CPAL tables parsing, it would be nice if we expose some of it as a public API for clients so they won't need to write their own font parsing logic. All what is needed here is signature of public APIs we like to have (which of course is not that easy...). Some useful links:
- https://codereview.chromium.org/1984943002/
- https://bugzilla.mozilla.org/show_bug.cgi?id=889401
- https://bug889401.bmoattachments.org/attachment.cgi?id=8424617
- http://msdn.microsoft.com/en-us/goglobal/bb688099.aspx
- http://msdn.microsoft.com/en-us/library/windows/desktop/hh802480%28v=vs.85%29.aspx
- http://www.getcodesamples.com/src/712F9685/B41B1957
- https://gist.github.com/egtra/6045976
- https://github.com/wine-mirror/wine/blob/5ec6b8f807f61ee77b9a96d94798c8e3f3db7af4/dlls/dwrite/dwrite_private.h#L220-L238
- http://savannah.nongnu.org/bugs/?44689
- ShaoYuZhang/freetype@27d9e6f
- ShaoYuZhang/freetype@27d9e6f#diff-b4b664c297e0aefa0ecc9dd995dffdf2R30
Using our current CPAL/COLR structs helpers (private API) it can be implemented like this:
const OT::COLR &colr = _get_colr(font->face);
const OT::CPAL &cpal = _get_cpal(font->face);
FT_Face ftface = hb_ft_font_get_face (font);
for (unsigned int i = 0; i < buffer->len; ++i)
{
hb_codepoint_t code_point = buffer->info[i].codepoint;
FT_Load_Glyph (ftface, code_point, FT_LOAD_DEFAULT);
FT_GlyphSlot slot = ftface->glyph;
FT_Render_Glyph (slot, FT_RENDER_MODE_NORMAL);
int width = slot->bitmap.width;
int height = slot->bitmap.rows;
int left = slot->bitmap_left;
int top = slot->bitmap_top;
unsigned char* image = (unsigned char*) calloc (width * height * 16, sizeof(char));
unsigned int first_layer_index, num_layers;
if (colr.get_base_glyph_record (code_point, first_layer_index, num_layers))
{
for (unsigned int j = 0; j < num_layers; ++j)
{
hb_codepoint_t glyph_id;
unsigned int color_index;
colr.get_layer_record(first_layer_index + j, glyph_id, color_index);
uint32_t color = cpal.get_color_record_argb(color_index, 0);
FT_Load_Glyph(ftface, glyph_id, FT_LOAD_DEFAULT);
FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
drawBitmap(&slot->bitmap,
slot->bitmap_left - left,
top - slot->bitmap_top,
image, width, height,
color);
}
}
}(considering #859 is merged)
Metadata
Metadata
Assignees
Labels
No labels