huhuang03 / sfntly

Automatically exported from code.google.com/p/sfntly
0 stars 0 forks source link

C++ Tables (font and cmap) in wrong order #29

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
OTS santizer rejected fonts serialized by C++ library because wrong order of 
font tables. And because of wrong ordered cmap tables.

This font could not be loaded in web browser (except IE) after I changed 
comparator classes it started to work.

Jan Hruby

Original issue reported on code.google.com by jhruby....@gmail.com on 28 Jan 2013 at 6:44

GoogleCodeExporter commented 9 years ago
I ran into this problem as well. This bug is especially problematic because it 
generates fonts that will be rejected by the OTS sanitizer 
(<https://code.google.com/p/ots/source/browse/trunk/src/ots.cc#425>), which is 
used by a bunch of browsers to determine whether or not to allow a font.

I think the problem is that the comparator in header.cc 
<https://code.google.com/p/sfntly/source/browse/trunk/cpp/src/sfntly/table/heade
r.cc?r=89#63> causes the headers to be sorted in reverse order:

bool HeaderComparatorByTag::operator() (const HeaderPtr lhs,
                                        const HeaderPtr rhs) {
  return lhs->tag_ > rhs->tag_;
}

Switching the ">" to a "<" fixes the problem. Note that this is probably a 
mis-port of the 
com.google.typography.font.sfntly.table.Header.COMPARATOR_BY_TAG 
<https://code.google.com/p/sfntly/source/browse/trunk/java/src/com/google/typogr
aphy/font/sfntly/table/Header.java?r=104#53>, which sorts like:

  public static final Comparator<Header> COMPARATOR_BY_TAG = new Comparator<Header>() {
    @Override
    public int compare(Header h1, Header h2) {
      return h1.tag - h2.tag;
    } 

Original comment by mprud...@gmail.com on 22 Dec 2013 at 3:06