feat.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (c) 2009-2017 The OTS Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef OTS_FEAT_H_
  5. #define OTS_FEAT_H_
  6. #include <vector>
  7. #include <unordered_set>
  8. #include "ots.h"
  9. #include "graphite.h"
  10. namespace ots {
  11. class OpenTypeFEAT : public Table {
  12. public:
  13. explicit OpenTypeFEAT(Font* font, uint32_t tag)
  14. : Table(font, tag, tag) { }
  15. bool Parse(const uint8_t* data, size_t length);
  16. bool Serialize(OTSStream* out);
  17. bool IsValidFeatureId(uint32_t id) const;
  18. private:
  19. struct FeatureDefn : public TablePart<OpenTypeFEAT> {
  20. explicit FeatureDefn(OpenTypeFEAT* parent)
  21. : TablePart<OpenTypeFEAT>(parent) { }
  22. bool ParsePart(Buffer& table);
  23. bool SerializePart(OTSStream* out) const;
  24. uint32_t id;
  25. uint16_t numSettings;
  26. uint16_t reserved;
  27. uint32_t offset;
  28. uint16_t flags;
  29. static const uint16_t HAS_DEFAULT_SETTING = 0x4000;
  30. static const uint16_t RESERVED = 0x3F00;
  31. static const uint16_t DEFAULT_SETTING = 0x00FF;
  32. uint16_t label;
  33. };
  34. struct FeatureSettingDefn : public TablePart<OpenTypeFEAT> {
  35. explicit FeatureSettingDefn(OpenTypeFEAT* parent)
  36. : TablePart<OpenTypeFEAT>(parent) { }
  37. bool ParsePart(Buffer& table) { return ParsePart(table, true); }
  38. bool ParsePart(Buffer& table, bool used);
  39. bool SerializePart(OTSStream* out) const;
  40. int16_t value;
  41. uint16_t label;
  42. };
  43. uint32_t version;
  44. uint16_t numFeat;
  45. uint16_t reserved;
  46. uint32_t reserved2;
  47. std::vector<FeatureDefn> features;
  48. std::vector<FeatureSettingDefn> featSettings;
  49. std::unordered_set<uint32_t> feature_ids;
  50. };
  51. } // namespace ots
  52. #endif // OTS_FEAT_H_