Skip to content
Open
3 changes: 3 additions & 0 deletions fontnik.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";

module.exports = require('./index.js');
7 changes: 5 additions & 2 deletions proto/glyphs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/glyphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ void RangeAsync(uv_work_t* req) {
double size = 24 * scale_factor;
FT_Set_Char_Size(ft_face, 0, static_cast<FT_F26Dot6>(size * (1 << 6)), 0, 0);

// Set ascender and descender in 26.6 fractional pixels.
fontstack_writer.add_sint32(4, static_cast<std::int32_t>(ft_face->size->metrics.ascender / 64));
fontstack_writer.add_sint32(5, static_cast<std::int32_t>(ft_face->size->metrics.descender / 64));

for (std::vector<uint32_t>::size_type x = 0; x != baton->chars.size(); x++) {
FT_ULong char_code = baton->chars[x];
sdf_glyph_foundry::glyph_info glyph;
Expand Down
8 changes: 8 additions & 0 deletions test/fontnik.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions test/format/glyphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down