Skip to content

Commit

Permalink
Expose metadata in protobuf
Browse files Browse the repository at this point in the history
Pull what's applicable from #97 into
this commit.
  • Loading branch information
tristen committed Aug 5, 2019
1 parent 7ceb3de commit 8dbbbf4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
24 changes: 19 additions & 5 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,25 @@ message glyph {
required uint32 advance = 7;
}

// Stores fontstack information and a list of faces.
// Stores a face with glyphs and optional metadata.
message fontstack {
required string name = 1;
required string range = 2;
repeated glyph glyphs = 3;
repeated Glyph glyphs = 1;

// Store SDF metadata.
message Metadata {
optional uint32 size = 1;
optional uint32 buffer = 2;
optional float cutoff = 3;
optional float scale = 4;
}

optional Metadata metadata = 2;

optional string family_name = 3;
optional string style_name = 4;
optional double ascender = 5;
optional double descender = 6;
optional double line_height = 7;
}

message glyphs {
Expand Down
22 changes: 17 additions & 5 deletions src/glyphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,29 @@ void RangeAsync(uv_work_t* req) {
if (ft_face->family_name) {
llmr::glyphs::fontstack* mutable_fontstack = glyphs.add_stacks();
if (ft_face->style_name) {
mutable_fontstack->set_name(std::string(ft_face->family_name) + " " + std::string(ft_face->style_name));
mutable_fontstack->set_family_name(std::string(ft_face->family_name) + " " + std::string(ft_face->style_name));
} else {
mutable_fontstack->set_name(std::string(ft_face->family_name));
mutable_fontstack->set_family_name(std::string(ft_face->family_name));
}

mutable_fontstack->set_range(std::to_string(baton->start) + "-" + std::to_string(baton->end));
// TODO mutable_fontstack->set_range(std::to_string(baton->start) + "-" + std::to_string(baton->end));
mutable_fontstack->set_family_name(ft_face->family_name);
mutable_fontstack->set_style_name(ft_face->style_name);
mutable_fontstack->set_ascender(ft_face->ascender);
mutable_fontstack->set_descender(ft_face->descender);
mutable_fontstack->set_line_height(ft_face->height);

// Add metadata to face.
mbgl::glyphs::Face::Metadata mutable_metadata = mutable_face->metadata();
mutable_metadata.set_size(char_size);
mutable_metadata.set_buffer(buffer_size);
mutable_metadata.set_cutoff(cutoff_size);
mutable_metadata.set_scale(scale_factor);

const double scale_factor = 1.0;

// Set character sizes.
double size = 24 * scale_factor;
double size = char_size * scale_factor;
FT_Set_Char_Size(ft_face, 0, static_cast<FT_F26Dot6>(size * (1 << 6)), 0, 0);

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

glyph.glyph_index = char_index;
sdf_glyph_foundry::RenderSDF(glyph, 24, 3, 0.25, ft_face);
sdf_glyph_foundry::RenderSDF(glyph, char_size, buffer_size, cutoff_size, ft_face);

// Add glyph to fontstack.
llmr::glyphs::glyph* mutable_glyph = mutable_fontstack->add_glyphs();
Expand Down
16 changes: 13 additions & 3 deletions src/glyphs.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef NODE_FONTNIK_GLYPHS_HPP
#define NODE_FONTNIK_GLYPHS_HPP
#pragma once

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

} // namespace node_fontnik

#endif // NODE_FONTNIK_GLYPHS_HPP
void RenderSDF(glyph_info &glyph,
int size,
int buffer,
float cutoff,
FT_Face ft_face);

const static int char_size = 24;
const static int buffer_size = 3;
const static float cutoff_size = 0.25;
const static float scale_factor = 1.0;

} // namespace node_fontnik

0 comments on commit 8dbbbf4

Please sign in to comment.