diff --git a/fontnik.js b/fontnik.js new file mode 100644 index 000000000..aa2db1533 --- /dev/null +++ b/fontnik.js @@ -0,0 +1,3 @@ +"use strict"; + +module.exports = require('./index.js'); diff --git a/proto/glyphs.proto b/proto/glyphs.proto index 24c2826b8..bbbf9391f 100644 --- a/proto/glyphs.proto +++ b/proto/glyphs.proto @@ -10,7 +10,7 @@ option optimize_for = LITE_RUNTIME; message glyph { required uint32 id = 1; - // A signed distance field of the glyph with a border of 3 pixels. + // A signed distance field of a glyph with buffer documented in metadata. optional bytes bitmap = 2; // Glyph metrics. @@ -21,11 +21,14 @@ message glyph { required uint32 advance = 7; } -// Stores fontstack information and a list of faces. +// Stores a face with glyphs and metadata. message fontstack { required string name = 1; required string range = 2; repeated glyph glyphs = 3; + + optional sint32 ascender = 4; + optional sint32 descender = 5; } message glyphs { diff --git a/src/glyphs.cpp b/src/glyphs.cpp index fa7ea832b..3f6d946f9 100644 --- a/src/glyphs.cpp +++ b/src/glyphs.cpp @@ -547,6 +547,10 @@ void RangeAsync(uv_work_t* req) { double size = 24 * scale_factor; FT_Set_Char_Size(ft_face, 0, static_cast(size * (1 << 6)), 0, 0); + // Set ascender and descender in 26.6 fractional pixels. + fontstack_writer.add_sint32(4, static_cast(ft_face->size->metrics.ascender / 64)); + fontstack_writer.add_sint32(5, static_cast(ft_face->size->metrics.descender / 64)); + for (std::vector::size_type x = 0; x != baton->chars.size(); x++) { FT_ULong char_code = baton->chars[x]; sdf_glyph_foundry::glyph_info glyph; diff --git a/test/fontnik.test.js b/test/fontnik.test.js index a1505c3ce..74c9d7a04 100644 --- a/test/fontnik.test.js +++ b/test/fontnik.test.js @@ -241,6 +241,8 @@ test('range', function(t) { var vt = new Glyphs(new Protobuf(new Uint8Array(data))); t.equal(vt.stacks.hasOwnProperty('?'), true); t.equal(vt.stacks['?'].hasOwnProperty('name'), true); + t.equal(vt.stacks['?'].hasOwnProperty('ascender'), true); + t.equal(vt.stacks['?'].hasOwnProperty('descender'), true); t.equal(vt.stacks['?'].name, '?'); t.end(); }); @@ -251,6 +253,12 @@ test('range', function(t) { t.error(err); var vt = new Glyphs(new Protobuf(new Uint8Array(data))); var glyphs = vt.stacks['Osaka Regular'].glyphs; + var stack = vt.stacks['Osaka Regular']; + + t.equal(stack.name, 'Osaka Regular'); + t.equal(stack.ascender, 24); + t.equal(stack.descender, -6); + var keys = Object.keys(glyphs); var glyph; diff --git a/test/format/glyphs.js b/test/format/glyphs.js index e119d654f..4a99ed742 100644 --- a/test/format/glyphs.js +++ b/test/format/glyphs.js @@ -41,6 +41,12 @@ Glyphs.prototype.readFontstack = function() { } else if (tag == 3) { var glyph = this.readGlyph(); fontstack.glyphs[glyph.id] = glyph; + } else if (tag == 4) { + var ascender = buffer.readSVarint(); + fontstack.ascender = ascender; + } else if (tag == 5) { + var descender = buffer.readSVarint(); + fontstack.descender = descender; } else { buffer.skip(val); }