diff --git a/src/glyphs.cpp b/src/glyphs.cpp index 27b1bc821..260c25d00 100644 --- a/src/glyphs.cpp +++ b/src/glyphs.cpp @@ -313,21 +313,21 @@ void RangeAsync(uv_work_t* req) { if (!char_index) continue; glyph.glyph_index = char_index; - RenderSDF(glyph, 24, 3, 0.25, ft_face); - - // Add glyph to fontstack. - llmr::glyphs::glyph *mutable_glyph = mutable_fontstack->add_glyphs(); - mutable_glyph->set_id(char_code); - mutable_glyph->set_width(glyph.width); - mutable_glyph->set_height(glyph.height); - mutable_glyph->set_left(glyph.left); - mutable_glyph->set_top(glyph.top - glyph.ascender); - mutable_glyph->set_advance(glyph.advance); - - if (glyph.width > 0) { - mutable_glyph->set_bitmap(glyph.bitmap); - } + if(RenderSDF(glyph, 24, 3, 0.25, ft_face)) { + // Add glyph to fontstack. + llmr::glyphs::glyph *mutable_glyph = mutable_fontstack->add_glyphs(); + mutable_glyph->set_id(char_code); + mutable_glyph->set_width(glyph.width); + mutable_glyph->set_height(glyph.height); + mutable_glyph->set_left(glyph.left); + mutable_glyph->set_top(glyph.top - glyph.ascender); + mutable_glyph->set_advance(glyph.advance); + + if (glyph.width > 0) { + mutable_glyph->set_bitmap(glyph.bitmap); + } + } } if (ft_face) { FT_Done_Face(ft_face); @@ -525,7 +525,7 @@ double MinDistanceToLineSegment(const Tree &tree, return std::sqrt(sqaured_distance); } -void RenderSDF(glyph_info &glyph, +bool RenderSDF(glyph_info &glyph, int size, int buffer, float cutoff, @@ -533,7 +533,7 @@ void RenderSDF(glyph_info &glyph, { if (FT_Load_Glyph (ft_face, glyph.glyph_index, FT_LOAD_NO_HINTING)) { - return; + return false; } int advance = ft_face->glyph->metrics.horiAdvance / 64; @@ -559,7 +559,7 @@ void RenderSDF(glyph_info &glyph, if (ft_face->glyph->format == FT_GLYPH_FORMAT_OUTLINE) { // Decompose outline into bezier curves and line segments FT_Outline outline = ft_face->glyph->outline; - if (FT_Outline_Decompose(&outline, &func_interface, &user)) return; + if (FT_Outline_Decompose(&outline, &func_interface, &user)) return false; if (!user.ring.empty()) { CloseRing(user.ring); @@ -567,10 +567,10 @@ void RenderSDF(glyph_info &glyph, } if (user.rings.empty()) { - return; + return false; } } else { - return; + return false; } // Calculate the real glyph bbox. @@ -602,7 +602,7 @@ void RenderSDF(glyph_info &glyph, } } - if (bbox_xmax - bbox_xmin == 0 || bbox_ymax - bbox_ymin == 0) return; + if (bbox_xmax - bbox_xmin == 0 || bbox_ymax - bbox_ymin == 0) return false; glyph.left = bbox_xmin; glyph.top = bbox_ymax; @@ -666,6 +666,8 @@ void RenderSDF(glyph_info &glyph, glyph.bitmap[i] = static_cast(255 - n); } } + + return true; } } // ns node_fontnik diff --git a/src/glyphs.hpp b/src/glyphs.hpp index 2be358e01..f28b01944 100644 --- a/src/glyphs.hpp +++ b/src/glyphs.hpp @@ -29,7 +29,7 @@ NAN_METHOD(Range); void RangeAsync(uv_work_t* req); void AfterRange(uv_work_t* req); struct glyph_info; -void RenderSDF(glyph_info &glyph, +bool RenderSDF(glyph_info &glyph, int size, int buffer, float cutoff, diff --git a/test/expected/range.json b/test/expected/range.json index 813a004f2..ccf6b6ce9 100644 --- a/test/expected/range.json +++ b/test/expected/range.json @@ -2,14 +2,6 @@ "stacks": { "Open Sans Regular": { "glyphs": { - "32": { - "id": 32, - "width": 0, - "height": 0, - "left": 0, - "top": -26, - "advance": 6 - }, "33": { "id": 33, "width": 3, @@ -762,14 +754,6 @@ "top": -16, "advance": 13 }, - "160": { - "id": 160, - "width": 0, - "height": 0, - "left": 0, - "top": -26, - "advance": 6 - }, "161": { "id": 161, "width": 3, diff --git a/test/fixtures/range.0.256.pbf b/test/fixtures/range.0.256.pbf index 5d15689fc..377f56a11 100644 Binary files a/test/fixtures/range.0.256.pbf and b/test/fixtures/range.0.256.pbf differ diff --git a/test/fontnik.test.js b/test/fontnik.test.js index 4685a9ee9..41a394b10 100644 --- a/test/fontnik.test.js +++ b/test/fontnik.test.js @@ -7,7 +7,6 @@ var test = require('tape'); var fs = require('fs'); var path = require('path'); var zlib = require('zlib'); -var zdata = fs.readFileSync(__dirname + '/fixtures/range.0.256.pbf'); var Protobuf = require('pbf'); var Glyphs = require('./format/glyphs'); var UPDATE = process.env.UPDATE; @@ -99,14 +98,8 @@ test('load', function(t) { }); test('range', function(t) { - var data; - zlib.inflate(zdata, function(err, d) { - if (err) throw err; - data = d; - }); - t.test('ranges', function(t) { - fontnik.range({font: opensans, start: 0, end: 256}, function(err, res) { + fontnik.range({font: opensans, start: 0, end: 256}, function(err, data) { t.error(err); t.ok(data); @@ -146,9 +139,9 @@ test('range', function(t) { }); t.test('shortrange', function(t) { - fontnik.range({font: opensans, start: 34, end: 38}, function(err, res) { + fontnik.range({font: opensans, start: 34, end: 38}, function(err, data) { t.error(err); - var vt = new Glyphs(new Protobuf(new Uint8Array(res))); + var vt = new Glyphs(new Protobuf(new Uint8Array(data))); t.equal(vt.stacks.hasOwnProperty('Open Sans Regular'), true); var codes = Object.keys(vt.stacks['Open Sans Regular'].glyphs); t.deepEqual(codes, ['34','35','36','37','38']);