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

[ot-font] Implement reading glyph names #568

Merged
merged 2 commits into from
Oct 25, 2017
Merged

[ot-font] Implement reading glyph names #568

merged 2 commits into from
Oct 25, 2017

Conversation

khaledhosny
Copy link
Collaborator

Turns out we already have support for “post” table, it just needed to be activated and put in use.

Might not be the best way to handle this, as I don’t really think I totally understand how parsing tables in HarfBuzz works.

@twardoch
Copy link

In CFF-based fonts, glyph names are stored inside the CFF table, not the post table. It seems that this PR doesn't take it into account, right??

@twardoch
Copy link

Also: decoding CFF may a bit be expensive, so I'm not sure if it should be done in HB (especially since it will most likely be parsed again during the imaging step)

@khaledhosny
Copy link
Collaborator Author

khaledhosny commented Oct 16, 2017

Yes, HarfBuzz ot font functions do not currently parse CFF table.

@behdad
Copy link
Member

behdad commented Oct 17, 2017

Thanks for this! I'll review it soon.

BTW, CFF doesn't have to be slow... We'll eventually implement it.

Copy link
Member

@behdad behdad left a comment

Choose a reason for hiding this comment

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

Thanks again. If you update with review comments, I can merge and then improve it over time. I like to make it significantly faster...


if (version.to_int () == 0x00010000)
{
strncpy(buffer, format1_glyph_names[glyph], buffer_length);
Copy link
Member

Choose a reason for hiding this comment

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

You don't check glyph before accessing format1_glyph_names array.

return false;

unsigned int index = v2.glyphNameIndex[glyph];
if (index > 257)
Copy link
Member

Choose a reason for hiding this comment

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

I'd write >= 258...

if (i == index - 258)
{
name_length = MIN (name_length, buffer_length);
memcpy (buffer, data + 1, name_length);
Copy link
Member

Choose a reason for hiding this comment

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

This can access past the blob end...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hopefully fixed now.

@twardoch
Copy link

Good to know that CFF performance isn't potentially a showstopper. BTW, I'm glad that with CFF2, Adobe followed my suggestion to remove glyph names from the table and use "post". I remember that initially they planned to keep names in CFF2, but having them in "post" regardless of the outline flavor is much better (especially since we now have all those color glyph flavors and when intermixing them with monochrome flavors, keeping track of where glyph names should be when would have been very annoying).

Turns out we already have support for “post” table, it just needed to be
activated and put in use.
inline bool get_glyph_name (hb_codepoint_t glyph,
char *name, unsigned int size) const
{
if (unlikely (!name) || unlikely(!size))
Copy link
Member

Choose a reason for hiding this comment

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

We just need to check for size.

Copy link
Member

Choose a reason for hiding this comment

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

Humm. Returning false doesn't sound quite right. Don't know. Maybe doesn't matter.

if (glyph >= NUM_FORMAT1_NAMES)
return false;

strncpy(buffer, format1_names[glyph], buffer_length);
Copy link
Member

Choose a reason for hiding this comment

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

From man strncpy:

       strncpy() produces an unterminated string in dest.  If buf  has  length
       buflen, you can force termination using something like the following:

           strncpy(buf, str, buflen - 1);
           if (buflen > 0)
               buf[buflen - 1]= '\0';

return false;

strncpy(buffer, format1_names[glyph], buffer_length);
buffer[buffer_length] = '\0';
Copy link
Member

Choose a reason for hiding this comment

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

Ok I see you have this. But it should be buffer_length - 1, no? I prefer checking for zero here as well. Maybe just here, not in the caller.

@behdad behdad merged commit d9e166f into harfbuzz:master Oct 25, 2017
@behdad
Copy link
Member

behdad commented Oct 25, 2017

I merged and am fixing the rest myself. Thanks Khaled, this has been long overdue!

@khaledhosny khaledhosny deleted the ot-font-glyph-names branch October 26, 2017 00:06
behdad added a commit that referenced this pull request Oct 30, 2017
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.

3 participants