Skip to content

Commit 8dbbbf4

Browse files
committed
Expose metadata in protobuf
Pull what's applicable from #97 into this commit.
1 parent 7ceb3de commit 8dbbbf4

3 files changed

Lines changed: 49 additions & 13 deletions

File tree

proto/glyphs.proto

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ option optimize_for = LITE_RUNTIME;
1010
message glyph {
1111
required uint32 id = 1;
1212

13-
// A signed distance field of the glyph with a border of 3 pixels.
13+
// A signed distance field of a glyph with buffer documented in metadata.
1414
optional bytes bitmap = 2;
1515

1616
// Glyph metrics.
@@ -21,11 +21,25 @@ message glyph {
2121
required uint32 advance = 7;
2222
}
2323

24-
// Stores fontstack information and a list of faces.
24+
// Stores a face with glyphs and optional metadata.
2525
message fontstack {
26-
required string name = 1;
27-
required string range = 2;
28-
repeated glyph glyphs = 3;
26+
repeated Glyph glyphs = 1;
27+
28+
// Store SDF metadata.
29+
message Metadata {
30+
optional uint32 size = 1;
31+
optional uint32 buffer = 2;
32+
optional float cutoff = 3;
33+
optional float scale = 4;
34+
}
35+
36+
optional Metadata metadata = 2;
37+
38+
optional string family_name = 3;
39+
optional string style_name = 4;
40+
optional double ascender = 5;
41+
optional double descender = 6;
42+
optional double line_height = 7;
2943
}
3044

3145
message glyphs {

src/glyphs.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,29 @@ void RangeAsync(uv_work_t* req) {
309309
if (ft_face->family_name) {
310310
llmr::glyphs::fontstack* mutable_fontstack = glyphs.add_stacks();
311311
if (ft_face->style_name) {
312-
mutable_fontstack->set_name(std::string(ft_face->family_name) + " " + std::string(ft_face->style_name));
312+
mutable_fontstack->set_family_name(std::string(ft_face->family_name) + " " + std::string(ft_face->style_name));
313313
} else {
314-
mutable_fontstack->set_name(std::string(ft_face->family_name));
314+
mutable_fontstack->set_family_name(std::string(ft_face->family_name));
315315
}
316316

317-
mutable_fontstack->set_range(std::to_string(baton->start) + "-" + std::to_string(baton->end));
317+
// TODO mutable_fontstack->set_range(std::to_string(baton->start) + "-" + std::to_string(baton->end));
318+
mutable_fontstack->set_family_name(ft_face->family_name);
319+
mutable_fontstack->set_style_name(ft_face->style_name);
320+
mutable_fontstack->set_ascender(ft_face->ascender);
321+
mutable_fontstack->set_descender(ft_face->descender);
322+
mutable_fontstack->set_line_height(ft_face->height);
323+
324+
// Add metadata to face.
325+
mbgl::glyphs::Face::Metadata mutable_metadata = mutable_face->metadata();
326+
mutable_metadata.set_size(char_size);
327+
mutable_metadata.set_buffer(buffer_size);
328+
mutable_metadata.set_cutoff(cutoff_size);
329+
mutable_metadata.set_scale(scale_factor);
318330

319331
const double scale_factor = 1.0;
320332

321333
// Set character sizes.
322-
double size = 24 * scale_factor;
334+
double size = char_size * scale_factor;
323335
FT_Set_Char_Size(ft_face, 0, static_cast<FT_F26Dot6>(size * (1 << 6)), 0, 0);
324336

325337
for (std::vector<uint32_t>::size_type x = 0; x != baton->chars.size(); x++) {
@@ -332,7 +344,7 @@ void RangeAsync(uv_work_t* req) {
332344
if (!char_index) continue;
333345

334346
glyph.glyph_index = char_index;
335-
sdf_glyph_foundry::RenderSDF(glyph, 24, 3, 0.25, ft_face);
347+
sdf_glyph_foundry::RenderSDF(glyph, char_size, buffer_size, cutoff_size, ft_face);
336348

337349
// Add glyph to fontstack.
338350
llmr::glyphs::glyph* mutable_glyph = mutable_fontstack->add_glyphs();

src/glyphs.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef NODE_FONTNIK_GLYPHS_HPP
2-
#define NODE_FONTNIK_GLYPHS_HPP
1+
#pragma once
32

43
#include "glyphs.pb.h"
54
#include <nan.h>
@@ -15,4 +14,15 @@ void AfterRange(uv_work_t* req);
1514

1615
} // namespace node_fontnik
1716

18-
#endif // NODE_FONTNIK_GLYPHS_HPP
17+
void RenderSDF(glyph_info &glyph,
18+
int size,
19+
int buffer,
20+
float cutoff,
21+
FT_Face ft_face);
22+
23+
const static int char_size = 24;
24+
const static int buffer_size = 3;
25+
const static float cutoff_size = 0.25;
26+
const static float scale_factor = 1.0;
27+
28+
} // namespace node_fontnik

0 commit comments

Comments
 (0)