mirror of
https://github.com/mapbox/node-fontnik.git
synced 2026-01-25 16:02:44 +00:00
first draft of new proto spec with face metadata
This commit is contained in:
parent
30b6e1b021
commit
331fb5ffaf
@ -1,14 +1,14 @@
|
||||
// Protocol Version 1
|
||||
|
||||
package llmr.glyphs;
|
||||
package mbgl.glyphs;
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
// Stores a glyph with metrics and optional SDF bitmap information.
|
||||
message glyph {
|
||||
message Glyph {
|
||||
required uint32 id = 1;
|
||||
|
||||
// A signed distance field of the glyph with a border of 3 pixels.
|
||||
// Signed distance field of a glyph with buffer documented in metadata.
|
||||
optional bytes bitmap = 2;
|
||||
|
||||
// Glyph metrics.
|
||||
@ -17,19 +17,33 @@ message glyph {
|
||||
required sint32 left = 5;
|
||||
required sint32 top = 6;
|
||||
required uint32 advance = 7;
|
||||
optional uint32 ascender = 8;
|
||||
optional uint32 descender = 9;
|
||||
}
|
||||
|
||||
// Stores fontstack information and a list of faces.
|
||||
message fontstack {
|
||||
required string name = 1;
|
||||
required string range = 2;
|
||||
repeated glyph glyphs = 3;
|
||||
// Store a face with glyphs and optional metadata.
|
||||
message Face {
|
||||
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 uint32 granularity = 5;
|
||||
optional float offset = 6;
|
||||
optional uint32 radius = 7;
|
||||
}
|
||||
|
||||
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 {
|
||||
repeated fontstack stacks = 1;
|
||||
|
||||
message Glyphs {
|
||||
repeated Face faces = 1;
|
||||
extensions 16 to 8191;
|
||||
}
|
||||
|
||||
@ -286,7 +286,7 @@ void RangeAsync(uv_work_t* req) {
|
||||
|
||||
FT_Face ft_face = 0;
|
||||
|
||||
llmr::glyphs::glyphs glyphs;
|
||||
mbgl::glyphs::Glyphs glyphs;
|
||||
|
||||
int num_faces = 0;
|
||||
for (int i = 0; ft_face == 0 || i < num_faces; ++i) {
|
||||
@ -296,15 +296,27 @@ void RangeAsync(uv_work_t* req) {
|
||||
return;
|
||||
}
|
||||
|
||||
llmr::glyphs::fontstack *mutable_fontstack = glyphs.add_stacks();
|
||||
mbgl::glyphs::Face *mutable_face = glyphs.add_faces();
|
||||
// mutable_face->set_range(std::to_string(baton->start) + "-" + std::to_string(baton->end));
|
||||
mutable_face->set_family_name(ft_face->family_name);
|
||||
|
||||
if (ft_face->style_name) {
|
||||
mutable_fontstack->set_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_face->set_style_name(ft_face->style_name);
|
||||
}
|
||||
|
||||
mutable_fontstack->set_range(std::to_string(baton->start) + "-" + std::to_string(baton->end));
|
||||
mutable_face->set_ascender(ft_face->ascender);
|
||||
mutable_face->set_descender(ft_face->descender);
|
||||
mutable_face->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);
|
||||
mutable_metadata.set_granularity(granularity);
|
||||
mutable_metadata.set_offset(offset_size);
|
||||
mutable_metadata.set_radius(radius_size);
|
||||
|
||||
// Set character sizes.
|
||||
double size = char_size * scale_factor;
|
||||
@ -322,15 +334,14 @@ void RangeAsync(uv_work_t* req) {
|
||||
glyph.glyph_index = char_index;
|
||||
RenderSDF(glyph, char_size, buffer_size, cutoff_size, ft_face);
|
||||
|
||||
// Add glyph to fontstack.
|
||||
llmr::glyphs::glyph *mutable_glyph = mutable_fontstack->add_glyphs();
|
||||
// Add glyph to face.
|
||||
mbgl::glyphs::Glyph *mutable_glyph = mutable_face->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);
|
||||
mutable_glyph->set_advance(glyph.advance);
|
||||
mutable_glyph->set_ascender(glyph.ascender);
|
||||
|
||||
if (glyph.width > 0) {
|
||||
mutable_glyph->set_bitmap(glyph.bitmap);
|
||||
|
||||
@ -63,13 +63,13 @@ void RenderSDF(glyph_info &glyph,
|
||||
float cutoff,
|
||||
FT_Face ft_face);
|
||||
|
||||
const static int granularity = 1;
|
||||
const static float offset_size = 0.5;
|
||||
const static int radius_size = 1;
|
||||
|
||||
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;
|
||||
const static int granularity = 1;
|
||||
|
||||
const static float offset_size = 0.5;
|
||||
const static int radius_size = 1;
|
||||
|
||||
} // ns node_fontnik
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user