Changeset 215081 in webkit


Ignore:
Timestamp:
Apr 6, 2017 5:59:57 PM (7 years ago)
Author:
mmaxfield@apple.com
Message:

Make FontWithFeatures test font pass OTS
https://bugs.webkit.org/show_bug.cgi?id=169788

Reviewed by Tim Horton.

Tools:

OTS, or the OpenType Sanitizer, is a check which tells if fonts are properly formed.
Previously, our FontWithFeatures test font did not pass this check. This patch updates
the font to pass the checks. Now, we can use this font on other platforms, and
contribute the font to the W3C for testing the CSS Fonts level 3 spec.

  • FontWithFeatures/FontWithFeatures/FontCreator.cpp:

(Generator::appendCFFTable):
(Generator::Feature::operator<):
(Generator::appendGSUBTable):
(Generator::appendOS2Table):
(Generator::appendFormat4CMAPTable):
(Generator::appendHEADTable):
(Generator::appendHHEATable):
(Generator::NameRecord::operator<):
(Generator::appendNameSubtable):
(Generator::appendNAMETable):

LayoutTests:

Updated font to the one which passes the tests.

  • css3/resources/FontWithFeatures.otf:
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r215079 r215081  
     12017-04-06  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Make FontWithFeatures test font pass OTS
     4        https://bugs.webkit.org/show_bug.cgi?id=169788
     5
     6        Reviewed by Tim Horton.
     7
     8        Updated font to the one which passes the tests.
     9
     10        * css3/resources/FontWithFeatures.otf:
     11
    1122017-04-06  Jiewen Tan  <jiewen_tan@apple.com>
    213
  • trunk/Tools/ChangeLog

    r215080 r215081  
     12017-04-06  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Make FontWithFeatures test font pass OTS
     4        https://bugs.webkit.org/show_bug.cgi?id=169788
     5
     6        Reviewed by Tim Horton.
     7
     8        OTS, or the OpenType Sanitizer, is a check which tells if fonts are properly formed.
     9        Previously, our FontWithFeatures test font did not pass this check. This patch updates
     10        the font to pass the checks. Now, we can use this font on other platforms, and
     11        contribute the font to the W3C for testing the CSS Fonts level 3 spec.
     12
     13        * FontWithFeatures/FontWithFeatures/FontCreator.cpp:
     14        (Generator::appendCFFTable):
     15        (Generator::Feature::operator<):
     16        (Generator::appendGSUBTable):
     17        (Generator::appendOS2Table):
     18        (Generator::appendFormat4CMAPTable):
     19        (Generator::appendHEADTable):
     20        (Generator::appendHHEATable):
     21        (Generator::NameRecord::operator<):
     22        (Generator::appendNameSubtable):
     23        (Generator::appendNAMETable):
     24
    1252017-04-06  Alexey Proskuryakov  <ap@apple.com>
    226
  • trunk/Tools/FontWithFeatures/FontWithFeatures/FontCreator.cpp

    r190848 r215081  
    613613        append32(clampTo<int32_t>(0)); // Bounding box x
    614614        result.push_back(operand32Bit);
    615         append32(clampTo<int32_t>(0)); // Bounding box y
     615        append32(clampTo<int32_t>(-1)); // Bounding box y
    616616        result.push_back(operand32Bit);
    617617        append32(clampTo<int32_t>(unitsPerEm)); // Bounding box max x
     
    822822    }
    823823
     824    struct Feature {
     825        bool operator<(const Feature& o) const
     826        {
     827            return tag < o.tag;
     828        }
     829
     830        std::array<char, 5> tag;
     831        uint16_t glyphToReplace;
     832    };
     833
    824834    void appendGSUBTable()
    825835    {
    826         std::vector<std::array<char, 5>> features {{"liga"}, {"clig"}, {"dlig"}, {"hlig"}, {"calt"}, {"subs"}, {"sups"}, {"smcp"}, {"c2sc"}, {"pcap"}, {"c2pc"}, {"unic"}, {"titl"}, {"lnum"}, {"onum"}, {"pnum"}, {"tnum"}, {"frac"}, {"afrc"}, {"ordn"}, {"zero"}, {"hist"}, {"jp78"}, {"jp83"}, {"jp90"}, {"jp04"}, {"smpl"}, {"trad"}, {"fwid"}, {"pwid"}, {"ruby"}};
     836        std::vector<Feature> features {{{"liga"}, 3}, {{"clig"}, 4}, {{"dlig"}, 5}, {{"hlig"}, 6}, {{"calt"}, 7}, {{"subs"}, 8}, {{"sups"}, 9}, {{"smcp"}, 10}, {{"c2sc"}, 11}, {{"pcap"}, 12}, {{"c2pc"}, 13}, {{"unic"}, 14}, {{"titl"}, 15}, {{"lnum"}, 16}, {{"onum"}, 17}, {{"pnum"}, 18}, {{"tnum"}, 19}, {{"frac"}, 20}, {{"afrc"}, 21}, {{"ordn"}, 22}, {{"zero"}, 23}, {{"hist"}, 24}, {{"jp78"}, 25}, {{"jp83"}, 26}, {{"jp90"}, 27}, {{"jp04"}, 28}, {{"smpl"}, 29}, {{"trad"}, 30}, {{"fwid"}, 31}, {{"pwid"}, 32}, {{"ruby"}, 33}};
     837        std::sort(features.begin(), features.end());
    827838        auto tableLocation = result.size();
    828839        auto headerSize = 10;
     
    851862        for (unsigned i = 0; i < features.size(); ++i) {
    852863            auto& code = features[i];
    853             append32BitCode(code.data()); // Feature name
     864            append32BitCode(code.tag.data()); // Feature name
    854865            append16(featureListSize + featureTableSize * i); // Offset of feature table, relative to beginning of FeatureList table
    855866        }
     
    881892
    882893        for (unsigned i = 0; i < features.size(); ++i)
    883             appendSubstitutionSubtable(subtableRecordLocations[i], 3 + i, 1);
     894            appendSubstitutionSubtable(subtableRecordLocations[i], features[i].glyphToReplace, 1);
    884895    }
    885896
     
    914925        append16(0xFFFF); // Last unicode index
    915926        append16(clampTo<int16_t>(unitsPerEm)); // Typographical ascender
    916         append16(clampTo<int16_t>(1)); // Typographical descender
     927        append16(clampTo<int16_t>(-1)); // Typographical descender
    917928        append16(clampTo<int16_t>(unitsPerEm / 10)); // Typographical line gap
    918929        append16(clampTo<uint16_t>(unitsPerEm)); // Windows-specific ascent
    919         append16(clampTo<uint16_t>(1)); // Windows-specific descent
     930        append16(clampTo<uint16_t>(0)); // Windows-specific descent
    920931        append32(0xFF10FC07); // Bitmask for supported codepages (Part 1). Report all pages as supported.
    921932        append32(0x0000FFFF); // Bitmask for supported codepages (Part 2). Report all pages as supported.
     
    980991        append16(0); // idRangeOffset
    981992        append16(0);
     993        append16(0);
    982994
    983995        // Fonts strive to hold 2^16 glyphs, but with the current encoding scheme, we write 8 bytes per codepoint into this subtable.
     
    10251037        append32(0); // Last half of modification date
    10261038        append16(clampTo<int16_t>(0)); // bounding box x
    1027         append16(clampTo<int16_t>(0)); // bounding box y
     1039        append16(clampTo<int16_t>(-1)); // bounding box y
    10281040        append16(clampTo<int16_t>(unitsPerEm)); // bounding box max x
    10291041        append16(clampTo<int16_t>(unitsPerEm)); // bounding box max y
     
    10391051        append32(0x00010000); // Version
    10401052        append16(clampTo<int16_t>(unitsPerEm)); // ascent
    1041         append16(clampTo<int16_t>(1)); // descent
     1053        append16(clampTo<int16_t>(-1)); // descent
    10421054        // WebKit SVG font rendering has hard coded the line gap to be 1/10th of the font size since 2008 (see r29719).
    10431055        append16(clampTo<int16_t>(unitsPerEm / 10)); // line gap
     
    10831095    }
    10841096
    1085     void appendNameSubtable(const std::string& s, uint16_t nameIdentifier)
     1097    struct NameRecord {
     1098        bool operator<(const NameRecord& o) const
     1099        {
     1100            return nameIdentifier < o.nameIdentifier;
     1101        }
     1102
     1103        uint16_t nameIdentifier;
     1104        std::string value;
     1105    };
     1106
     1107    void appendNameSubtable(const NameRecord& nameRecord)
    10861108    {
    10871109        append16(0); // Unicode
    10881110        append16(3); // Unicode version 2.0 or later
    10891111        append16(0); // Language
    1090         append16(nameIdentifier); // Name identifier
    1091         append16(s.length() * 2); // Code units get 2 bytes each
     1112        append16(nameRecord.nameIdentifier); // Name identifier
     1113        append16(nameRecord.value.length() * 2); // Code units get 2 bytes each
    10921114        append16(m_nameOffset); // Offset into name data
    1093         m_nameOffset += s.size() * 2; // Code units get 2 bytes each
     1115        m_nameOffset += nameRecord.value.size() * 2; // Code units get 2 bytes each
    10941116    }
    10951117
     
    11101132        append16(6 + 12 * numberOfRecords); // Offset in bytes to the beginning of name character strings
    11111133
    1112         appendNameSubtable(familyName, 1); // 1: Font Family.
    1113         appendNameSubtable(familyName, 2); // 2: Font Subfamily.
    1114         appendNameSubtable(familyName, 3); // 3: Unique subfamily identification.
    1115         appendNameSubtable(familyName, 4); // 4: Full name of the font.
    1116         appendNameSubtable(version, 5); // 5: Version of the name table.
    1117         appendNameSubtable(familyName, 6); // 6: PostScript name of the font.
     1134        std::vector<NameRecord> nameRecords = { { 1, familyName }, { 2, familyName }, { 3, familyName }, { 4, familyName }, { 5, version }, { 6, familyName } };
    11181135        for (FeatureType& type : featureDescription) {
    1119             appendNameSubtable(type.name, m_baseStringIndex + type.stringIndex);
     1136            nameRecords.push_back({ static_cast<uint16_t>(m_baseStringIndex + type.stringIndex), type.name });
    11201137            for (FeatureSelector& selector : type.selectors)
    1121                 appendNameSubtable(selector.name, m_baseStringIndex + selector.stringIndex);
    1122         }
    1123 
    1124         append2ByteASCIIString(familyName);
    1125         append2ByteASCIIString(familyName);
    1126         append2ByteASCIIString(familyName);
    1127         append2ByteASCIIString(familyName);
    1128         append2ByteASCIIString(version);
    1129         append2ByteASCIIString(familyName);
    1130         for (FeatureType& type : featureDescription) {
    1131             append2ByteASCIIString(type.name);
    1132             for (FeatureSelector& selector : type.selectors)
    1133                 append2ByteASCIIString(selector.name);
    1134         }
     1138                nameRecords.push_back({ static_cast<uint16_t>(m_baseStringIndex + selector.stringIndex), selector.name });
     1139        }
     1140        std::sort(nameRecords.begin(), nameRecords.end());
     1141
     1142        for (auto& nameRecord : nameRecords)
     1143            appendNameSubtable(nameRecord);
     1144
     1145        for (auto& nameRecord : nameRecords)
     1146            append2ByteASCIIString(nameRecord.value);
    11351147    }
    11361148   
Note: See TracChangeset for help on using the changeset viewer.