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

[layout] hb_ot_layout_lookup_get_glyph_alternates, a new API #2471

Closed
wants to merge 3 commits into from

Conversation

ebraminio
Copy link
Collaborator

@ebraminio ebraminio commented Jun 16, 2020

Fixes #673

As #673 (comment) proposal, let's see how it goes.

Used the following to find a font having alternates,
#include "src/harfbuzz.cc"

int main(int argc, char **argv) {
  hb_blob_t *blob = hb_blob_create_from_file (argv[1]);
  unsigned count = hb_face_count (blob);
  for (unsigned i = 0; i < count; ++i) {
    hb_face_t *face = hb_face_create (blob, 0);
    unsigned glyph_count = hb_face_get_glyph_count (face);
    unsigned lookup_count = hb_ot_layout_table_get_lookup_count (face, HB_OT_TAG_GSUB);
    for (unsigned lookup = 0; lookup < lookup_count; ++lookup)
      for (unsigned gid = 0; gid < glyph_count; ++gid)
	if (hb_ot_layout_lookup_get_alternates (face, lookup, gid, 0, nullptr, nullptr))
	{
	  printf ("%s\n", argv[1]);
	  goto done;
	}
    done:
    hb_face_destroy (face);
  }
  hb_blob_destroy (blob);
  return 0;
}

@ebraminio
Copy link
Collaborator Author

just to mention, it works with Rana Kufi also very well as it was the font I was using for testing initially.

@behdad
Copy link
Member

behdad commented Jun 18, 2020

Thanks @ebraminio. This is very nice!

Generally we push most of the parameters from the API down to where they are populated. Instead you pull out the internal array and copy in the public API. Any particular reason you did it that way? If not, I prefer it if you do it the way other methods are done. Thanks again!

@ebraminio
Copy link
Collaborator Author

PTAL

@ebraminio ebraminio force-pushed the gsub-alternate branch 4 times, most recently from fca8a9a to 8b0b80d Compare June 18, 2020 04:26
An API to retrieve one-to-one alternates from a given GSUB lookup index.
@behdad
Copy link
Member

behdad commented Jun 18, 2020

Quick show of hands if name should be get_alternates, get_glyph_alternates, or get_alternate_glyphs?

I feel like get_alternates is wrong because it implies it returns alternates to a lookup.

The get_glyph_alternates rightly specifies that this is a lookup method that returns certain data about a glyph.

The get_alternate_glyphs doesn't specify the input, but the output.

As of now I prefer the second one, get_glyph_alternates.

@jfkthame
Copy link
Collaborator

Quick show of hands if name should be get_alternates, get_glyph_alternates, or get_alternate_glyphs?

I feel like get_alternates is wrong because it implies it returns alternates to a lookup.

The get_glyph_alternates rightly specifies that this is a lookup method that returns certain data about a glyph.

The get_alternate_glyphs doesn't specify the input, but the output.

As of now I prefer the second one, get_glyph_alternates.

Yeah, get_glyph_alternates sounds OK to me.

Does this handle alternates referenced via an Extension subtable?

@behdad
Copy link
Member

behdad commented Jun 18, 2020

Does this handle alternates referenced via an Extension subtable?

Doesn't. I'll address that in my review.

@ebraminio ebraminio changed the title [layout] hb_ot_layout_lookup_get_alternates, a new API [layout] hb_ot_layout_lookup_get_glyph_alternates, a new API Jun 18, 2020
@behdad behdad mentioned this pull request Jun 19, 2020
@behdad
Copy link
Member

behdad commented Jun 19, 2020

Continuing in #2473

@behdad behdad closed this Jun 19, 2020
@ebraminio ebraminio deleted the gsub-alternate branch June 19, 2020 03:45
behdad added a commit that referenced this pull request Jun 19, 2020
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.

Add API to get glyph alternates
3 participants