Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose ascender/descender metadata properties in protobuf #160

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

tristen
Copy link
Member

@tristen tristen commented Aug 5, 2019

Pull what's applicable from #97 into this commit.

Pull what's applicable from #97 into
this commit.
@springmeyer
Copy link
Contributor

springmeyer commented Aug 26, 2019

The branch is passing now on travis since I fixed this minor issue (#161) and merged that fix into this branch. The next steps I see for this work are:

src/glyphs.cpp Outdated
@@ -315,6 +315,8 @@ void RangeAsync(uv_work_t* req) {
}

mutable_fontstack->set_range(std::to_string(baton->start) + "-" + std::to_string(baton->end));
mutable_fontstack->set_ascender(ft_face->ascender);
mutable_fontstack->set_descender(ft_face->descender);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I am currently testing the generated glyphs from this pr in MBGL, I am trying to fix the dis-alignment of texts with mixed fonts (Noto Sans CJK and Arial Unicode MS Regular). In order to fix it, I need to shift back the top value in the metrics in MBGL. Since the top value was generated from:
double top = static_cast<double>(glyph.top) - glyph.ascender;
In order to do so, I need the ascender in the metrics to be 26.6 pixel format instead of unscaled font units.
So I think ascender and descender are better to be set from ft_face->size->metrics.ascender and ft_face->size->metrics.descender.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 @zmiao excited to learn you are digging into this work!

So I think ascender and descender are better to be set from ft_face->size-metrics.ascender and ft_face->size->metrics.descender.

Feel free to make those modifications to this pull request if that's more accurate!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tristen thanks for the reply, I updated this pr.

@zmiao
Copy link

zmiao commented Sep 17, 2019

Some experimenting rendering results after applying the ascender value in MBGL for fixing the dis-alignment of mixed fonts:

After fix Before fix
Screen Shot 2019-09-17 at 6 43 29 PM Screen Shot 2019-09-17 at 6 44 50 PM
Screen Shot 2019-09-17 at 6 51 54 PM Screen Shot 2019-09-17 at 6 51 20 PM

Next step for testing would be trying to figure out how to deal with issues in mapbox/mapbox-gl-js#8560

@zmiao
Copy link

zmiao commented Oct 8, 2019

@tristen @springmeyer
in the source code

node-fontnik/src/glyphs.cpp

Lines 297 to 310 in d65c204

for (int i = 0; ft_face == 0 || i < num_faces; ++i) {
ft_face_guard face_guard(&ft_face);
FT_Error face_error = FT_New_Memory_Face(library, reinterpret_cast<FT_Byte const*>(baton->font_data), static_cast<FT_Long>(baton->font_size), i, &ft_face);
if (face_error) {
baton->error_name = std::string("could not open font");
return;
}
if (num_faces == 0) {
num_faces = ft_face->num_faces;
}
if (ft_face->family_name) {
llmr::glyphs::fontstack* mutable_fontstack = glyphs.add_stacks();
, each font-face equals to a new fontstack in the pbf. So what does font-face mean? Does it imply a new font type?

I am confused because that I tried to use the executable build-glyphs to generate the pbf data from one .ttc file that containing multiple fonts, but finally the output is still the general ranges pbf, nothing is font related. Did I miss something, how can I generate font-specific pbf data if the *.ttc has multiple fonts inside? For example, the NotoSansCJK.ttc in https://www.google.com/get/noto/help/cjk/ has 36 OTF font files in total.

@springmeyer
Copy link
Contributor

👋 @zmiao thanks for asking. This was also a confusion for me when I first considered .ttc behavior. My understanding is this:

  • The node-fontnik code that handles reading faces was originally ported from code from mapnik, which supports .ttc
  • But the ttc support in node-fontnik was never tested
  • And downstream libraries on top of node-fontnik explicitly do not support ttc
  • So, its unclear to what extent the ttc support in node-fontnik is working or not

A little bit of this history is evident in #125

So, overall, to support ttc would need someone to comprehensively test and perhaps fix issues in the entire dependency chain: node-fontnik -> fontmachine -> core-fonts -> api-styles -> mapbox-gl. Because several of those repos are private, if you have questions about them it would make most sense to discuss more in tickets at those repos.

@zmiao
Copy link

zmiao commented Oct 8, 2019

@springmeyer Thanks for the explanation, it is really helpful.

So based on your comments, right now we do not support generating pbf from multi-face ttc, but the weird thing is if I upload the ttc file via MapboxStudio, I could get multiple fonts, how did it work? I assume MapboxStudio uses the same node-fontnik engine, right?

@springmeyer
Copy link
Contributor

Interesting @zmiao - I would have assumed you'd get an error due to this line: https://github.com/mapbox/fontmachine/blob/0e5eaab3fd99153083f08278d7a55792d2b6f3ce/index.js#L32

I assume MapboxStudio uses the same node-fontnik engine, right?

Yes, the backend of Mapbox Studio uses node-fontnik@0.5.3

@zmiao
Copy link

zmiao commented Oct 8, 2019

@springmeyer It was my bad. Actually for my case, I uploaded one otf file, but I got two fonts without any error prompt, I am wondering why it works?

And also if I use bin/build-glyphs to generate pbf from ttc file, I didn't get any errors neither, just have to wait for a very long while.

@zmiao zmiao removed their assignment Oct 9, 2019
@tristen tristen changed the title [WIP] Expose metadata in protobuf Expose metadata in protobuf Oct 30, 2019
@tristen tristen changed the title Expose metadata in protobuf Expose ascender/descender metadata properties in protobuf Oct 30, 2019
@tmpsantos
Copy link

Hi all, this has been stalled for a while. Do we have plans to merge it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants