From f748e11645a3361f94d6fb10ce59febbaa5ba8ca Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Sat, 18 Feb 2017 19:54:33 +0100 Subject: [PATCH 01/12] bootstraping structure --- src/Makefile.sources | 1 + src/hb-ot-base-table.hh | 238 ++++++++++++++++++++++++++++++++++++ src/hb-ot-font.cc | 1 + src/hb-ot-layout-private.hh | 2 + 4 files changed, 242 insertions(+) create mode 100644 src/hb-ot-base-table.hh diff --git a/src/Makefile.sources b/src/Makefile.sources index 6363cf930..20ce77b80 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -68,6 +68,7 @@ HB_NODIST_headers = \ HB_FALLBACK_sources = hb-fallback-shape.cc HB_OT_sources = \ + hb-ot-base-table.hh \ hb-ot-font.cc \ hb-ot-layout.cc \ hb-ot-layout-common-private.hh \ diff --git a/src/hb-ot-base-table.hh b/src/hb-ot-base-table.hh new file mode 100644 index 000000000..8ad01fe32 --- /dev/null +++ b/src/hb-ot-base-table.hh @@ -0,0 +1,238 @@ +/* + * Copyright © 2016 Elie Roux + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + */ + +#ifndef HB_OT_BASE_TABLE_HH +#define HB_OT_BASE_TABLE_HH + +#include "hb-open-type-private.hh" +#include "hb-ot-layout-common-private.hh" + +#define HB_OT_TAG_BASE HB_TAG('B','A','S','E') + +// https://www.microsoft.com/typography/otspec/baselinetags.htm + +#define HB_OT_TAG_BASE_HANG HB_TAG('h','a','n','g') +#define HB_OT_TAG_BASE_ICFB HB_TAG('i','c','f','b') +#define HB_OT_TAG_BASE_ICFT HB_TAG('i','c','f','t') +#define HB_OT_TAG_BASE_IDEO HB_TAG('i','d','e','o') +#define HB_OT_TAG_BASE_IDTB HB_TAG('i','d','t','b') +#define HB_OT_TAG_BASE_MATH HB_TAG('m','a','t','h') +#define HB_OT_TAG_BASE_ROMN HB_TAG('r','o','m','n') + +namespace OT { + +/* + * BASE -- The BASE Table + */ + +struct BaseCoordFormat1 { + protected: + USHORT baseCoordFormat; + SHORT coordinate; + + public: + DEFINE_SIZE_STATIC (4); +}; + +struct BaseCoordFormat2 { + protected: + USHORT baseCoordFormat; + SHORT coordinate; + USHORT referenceGlyph; + USHORT baseCoordPoint; + + public: + DEFINE_SIZE_STATIC (8); +}; + +struct BaseCoordFormat3 { + protected: + USHORT baseCoordFormat; + SHORT coordinate; + OffsetTo deviceTable; + + public: + DEFINE_SIZE_STATIC (6); +}; + +struct BaseCoord { + protected: + union { + USHORT baseCoordFormat; + BaseCoordFormat1 format1; + BaseCoordFormat2 format2; + BaseCoordFormat3 format3; + } u; + + public: + DEFINE_SIZE_MIN (4); +}; + +struct FeatMinMaxRecord { + protected: + Tag featureTableTag; + OffsetTo minCoord; + OffsetTo maxCoord; + + public: + DEFINE_SIZE_STATIC (8); + +}; + +struct MinMaxTable { + protected: + OffsetTo minCoord; + OffsetTo maxCoord; + USHORT featMinMaxCount; + ArrayOf featMinMaxRecordTable; + + public: + DEFINE_SIZE_ARRAY (6, featMinMaxRecordTable); + +}; + +struct BaseLangSysRecord { + protected: + Tag baseLangSysTag; + OffsetTo minMax; + + public: + DEFINE_SIZE_STATIC (6); + +}; + +struct BaseValuesTable { + protected: + USHORT defaultIndex; + USHORT baseCoordCount; + ArrayOf baseCoordTable; + + public: + DEFINE_SIZE_ARRAY (4, baseCoordTable); + +}; + +struct BaseScriptTable { + protected: + OffsetTo baseValues; + OffsetTo defaultMinMax; + USHORT baseLangSysCount; + ArrayOf baseLangSysRecordTable; + + public: + DEFINE_SIZE_ARRAY (6, baseLangSysRecordTable); +}; + + +struct BaseScriptRecord { + + protected: + Tag baseScriptTag; + OffsetTo baseScript; + + public: + DEFINE_SIZE_STATIC (4); +}; + +struct BaseScriptList { + + protected: + USHORT baseScriptCount; + ArrayOf baseScriptRecordTable; + + public: + DEFINE_SIZE_ARRAY (2, baseScriptRecordTable); + +}; + +struct BaselineTag { + + protected: + Tag tag; + + public: + DEFINE_SIZE_STATIC (4); + +}; + +struct BaseTagList +{ + + protected: + USHORT baseTagCount; + ArrayOf BaseTagListTable; + + public: + DEFINE_SIZE_STATIC (4); +}; + +struct VertAxis +{ + + protected: + OffsetTo baseTagList; + OffsetTo baseScriptList; + + public: + DEFINE_SIZE_STATIC (4); +}; + +struct HorizAxis +{ + + protected: + OffsetTo baseTagList; + OffsetTo baseScriptList; + + public: + DEFINE_SIZE_STATIC (4); +}; + +struct BASE +{ + static const hb_tag_t tableTag = HB_OT_TAG_BASE; + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (version.sanitize (c) && + likely (version.major == 1)); + } + + protected: + FixedVersion<>version; /* Version of the BASE table: 1.0 or 1.1 */ + OffsetTo horizAxis; + OffsetTo vertAxis; + //LOffsetTo itemVarStore; + + public: + DEFINE_SIZE_MIN (6); +}; + + +} /* namespace OT */ + + +#endif /* HB_OT_BASE_TABLE_HH */ diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 009db20ae..9abdc6757 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -30,6 +30,7 @@ #include "hb-font-private.hh" +#include "hb-ot-base-table.hh" #include "hb-ot-cmap-table.hh" #include "hb-ot-cbdt-table.hh" #include "hb-ot-glyf-table.hh" diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh index 071a439d6..ee8e1373e 100644 --- a/src/hb-ot-layout-private.hh +++ b/src/hb-ot-layout-private.hh @@ -122,6 +122,7 @@ hb_ot_layout_position_finish_offsets (hb_font_t *font, */ namespace OT { + struct BASE; struct GDEF; struct GSUB; struct GPOS; @@ -162,6 +163,7 @@ struct hb_ot_layout_t const struct OT::GPOS *gpos; /* TODO Move the following out of this struct. */ + OT::hb_lazy_table_loader_t base; OT::hb_lazy_table_loader_t math; OT::hb_lazy_table_loader_t fvar; OT::hb_lazy_table_loader_t avar; From d0b97353e930d9b258f42f1cc1ac1a75306b76a8 Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Sun, 19 Feb 2017 08:48:22 +0100 Subject: [PATCH 02/12] hb-ot-base-table.hh -> hb-ot-layout-base-table.hh per https://github.com/behdad/harfbuzz/issues/418#issuecomment-280873811 --- src/Makefile.sources | 2 +- src/hb-ot-font.cc | 2 +- src/{hb-ot-base-table.hh => hb-ot-layout-base-table.hh} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/{hb-ot-base-table.hh => hb-ot-layout-base-table.hh} (100%) diff --git a/src/Makefile.sources b/src/Makefile.sources index 20ce77b80..0f83f6ebd 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -68,9 +68,9 @@ HB_NODIST_headers = \ HB_FALLBACK_sources = hb-fallback-shape.cc HB_OT_sources = \ - hb-ot-base-table.hh \ hb-ot-font.cc \ hb-ot-layout.cc \ + hb-ot-layout-base-table.hh \ hb-ot-layout-common-private.hh \ hb-ot-layout-gdef-table.hh \ hb-ot-layout-gpos-table.hh \ diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 9abdc6757..acbda8de5 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -30,7 +30,7 @@ #include "hb-font-private.hh" -#include "hb-ot-base-table.hh" +#include "hb-ot-layout-base-table.hh" #include "hb-ot-cmap-table.hh" #include "hb-ot-cbdt-table.hh" #include "hb-ot-glyf-table.hh" diff --git a/src/hb-ot-base-table.hh b/src/hb-ot-layout-base-table.hh similarity index 100% rename from src/hb-ot-base-table.hh rename to src/hb-ot-layout-base-table.hh From f131f00b1779b44633223915e17cbce358ad063a Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Sun, 19 Feb 2017 10:12:22 +0100 Subject: [PATCH 03/12] compile, move into hb-ot-layout.cc --- src/hb-ot-font.cc | 1 - src/hb-ot-layout-base-table.hh | 57 +++++++++++++++++++++++++--------- src/hb-ot-layout.cc | 1 + 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index acbda8de5..009db20ae 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -30,7 +30,6 @@ #include "hb-font-private.hh" -#include "hb-ot-layout-base-table.hh" #include "hb-ot-cmap-table.hh" #include "hb-ot-cbdt-table.hh" #include "hb-ot-glyf-table.hh" diff --git a/src/hb-ot-layout-base-table.hh b/src/hb-ot-layout-base-table.hh index 8ad01fe32..b3c0927b1 100644 --- a/src/hb-ot-layout-base-table.hh +++ b/src/hb-ot-layout-base-table.hh @@ -109,7 +109,7 @@ struct MinMaxTable { ArrayOf featMinMaxRecordTable; public: - DEFINE_SIZE_ARRAY (6, featMinMaxRecordTable); + DEFINE_SIZE_ARRAY (8, featMinMaxRecordTable); }; @@ -127,10 +127,10 @@ struct BaseValuesTable { protected: USHORT defaultIndex; USHORT baseCoordCount; - ArrayOf baseCoordTable; + OffsetArrayOf baseCoordTable; public: - DEFINE_SIZE_ARRAY (4, baseCoordTable); + DEFINE_SIZE_ARRAY (6, baseCoordTable); }; @@ -142,7 +142,7 @@ struct BaseScriptTable { ArrayOf baseLangSysRecordTable; public: - DEFINE_SIZE_ARRAY (6, baseLangSysRecordTable); + DEFINE_SIZE_ARRAY (8, baseLangSysRecordTable); }; @@ -153,7 +153,7 @@ struct BaseScriptRecord { OffsetTo baseScript; public: - DEFINE_SIZE_STATIC (4); + DEFINE_SIZE_STATIC (6); }; struct BaseScriptList { @@ -163,7 +163,7 @@ struct BaseScriptList { ArrayOf baseScriptRecordTable; public: - DEFINE_SIZE_ARRAY (2, baseScriptRecordTable); + DEFINE_SIZE_ARRAY (4, baseScriptRecordTable); }; @@ -182,10 +182,10 @@ struct BaseTagList protected: USHORT baseTagCount; - ArrayOf BaseTagListTable; + ArrayOf baseTagListTable; public: - DEFINE_SIZE_STATIC (4); + DEFINE_SIZE_ARRAY (4, baseTagListTable); }; struct VertAxis @@ -210,6 +210,32 @@ struct HorizAxis DEFINE_SIZE_STATIC (4); }; + +struct BASEFormat1_1 +{ + + protected: + FixedVersion<>version; + OffsetTo horizAxis; + OffsetTo vertAxis; + LOffsetTo itemVarStore; + + public: + DEFINE_SIZE_STATIC (12); +}; + +struct BASEFormat1_0 +{ + + protected: + FixedVersion<>version; + OffsetTo horizAxis; + OffsetTo vertAxis; + + public: + DEFINE_SIZE_STATIC (8); +}; + struct BASE { static const hb_tag_t tableTag = HB_OT_TAG_BASE; @@ -217,18 +243,19 @@ struct BASE inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - return_trace (version.sanitize (c) && - likely (version.major == 1)); + return_trace (u.version.sanitize (c) && + likely (u.version.major == 1)); } protected: - FixedVersion<>version; /* Version of the BASE table: 1.0 or 1.1 */ - OffsetTo horizAxis; - OffsetTo vertAxis; - //LOffsetTo itemVarStore; + union { + FixedVersion<>version; /* Version of the BASE table: 1.0 or 1.1 */ + BASEFormat1_0 format1_0; + BASEFormat1_1 format1_1; + } u; public: - DEFINE_SIZE_MIN (6); + DEFINE_SIZE_UNION (4, version); }; diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index a1682a5f9..3511810ac 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -31,6 +31,7 @@ #include "hb-open-type-private.hh" #include "hb-ot-layout-private.hh" +#include "hb-ot-layout-base-table.hh" #include "hb-ot-layout-gdef-table.hh" #include "hb-ot-layout-gsub-table.hh" #include "hb-ot-layout-gpos-table.hh" From 1d30c6d935535743c73b2d18abcc6ae86a1cfc5b Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Sat, 25 Feb 2017 16:19:35 +0100 Subject: [PATCH 04/12] BASE: sanitize --- src/hb-ot-layout-base-table.hh | 151 ++++++++++++++++++++++++++++++++- 1 file changed, 148 insertions(+), 3 deletions(-) diff --git a/src/hb-ot-layout-base-table.hh b/src/hb-ot-layout-base-table.hh index b3c0927b1..691b9db1c 100644 --- a/src/hb-ot-layout-base-table.hh +++ b/src/hb-ot-layout-base-table.hh @@ -48,6 +48,13 @@ namespace OT { */ struct BaseCoordFormat1 { + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this)); + } + protected: USHORT baseCoordFormat; SHORT coordinate; @@ -57,6 +64,13 @@ struct BaseCoordFormat1 { }; struct BaseCoordFormat2 { + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this)); + } + protected: USHORT baseCoordFormat; SHORT coordinate; @@ -68,6 +82,13 @@ struct BaseCoordFormat2 { }; struct BaseCoordFormat3 { + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && deviceTable.sanitize (c, this)); + } + protected: USHORT baseCoordFormat; SHORT coordinate; @@ -78,6 +99,20 @@ struct BaseCoordFormat3 { }; struct BaseCoord { + + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + if (!u.baseCoordFormat.sanitize (c)) return_trace (false); + switch (u.baseCoordFormat) { + case 1: return_trace (u.format1.sanitize (c)); + case 2: return_trace (u.format2.sanitize (c)); + case 3: return_trace (u.format3.sanitize (c)); + default:return_trace (true); + } + } + protected: union { USHORT baseCoordFormat; @@ -91,6 +126,15 @@ struct BaseCoord { }; struct FeatMinMaxRecord { + + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + minCoord.sanitize (c, base) && + maxCoord.sanitize (c, base)); + } + protected: Tag featureTableTag; OffsetTo minCoord; @@ -102,6 +146,16 @@ struct FeatMinMaxRecord { }; struct MinMaxTable { + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + minCoord.sanitize (c, this) && + maxCoord.sanitize (c, this) && + featMinMaxRecordTable.sanitize (c, this)); + } + protected: OffsetTo minCoord; OffsetTo maxCoord; @@ -114,6 +168,14 @@ struct MinMaxTable { }; struct BaseLangSysRecord { + + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + minMax.sanitize (c, base)); + } + protected: Tag baseLangSysTag; OffsetTo minMax; @@ -124,6 +186,14 @@ struct BaseLangSysRecord { }; struct BaseValuesTable { + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + baseCoordTable.sanitize (c, this)); + } + protected: USHORT defaultIndex; USHORT baseCoordCount; @@ -135,6 +205,16 @@ struct BaseValuesTable { }; struct BaseScriptTable { + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + baseValues.sanitize (c, this) && + defaultMinMax.sanitize (c, this) && + baseLangSysRecordTable.sanitize (c, this)); + } + protected: OffsetTo baseValues; OffsetTo defaultMinMax; @@ -148,6 +228,13 @@ struct BaseScriptTable { struct BaseScriptRecord { + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + baseScript.sanitize (c, base)); + } + protected: Tag baseScriptTag; OffsetTo baseScript; @@ -158,6 +245,13 @@ struct BaseScriptRecord { struct BaseScriptList { + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + baseScriptRecordTable.sanitize (c, this)); + } + protected: USHORT baseScriptCount; ArrayOf baseScriptRecordTable; @@ -169,6 +263,12 @@ struct BaseScriptList { struct BaselineTag { + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this)); + } + protected: Tag tag; @@ -180,6 +280,13 @@ struct BaselineTag { struct BaseTagList { + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + baseTagListTable.sanitize (c, this)); + } + protected: USHORT baseTagCount; ArrayOf baseTagListTable; @@ -191,6 +298,14 @@ struct BaseTagList struct VertAxis { + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + baseTagList.sanitize (c, this) && + baseScriptList.sanitize (c, this)); + } + protected: OffsetTo baseTagList; OffsetTo baseScriptList; @@ -202,6 +317,14 @@ struct VertAxis struct HorizAxis { + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + baseTagList.sanitize (c, this) && + baseScriptList.sanitize (c, this)); + } + protected: OffsetTo baseTagList; OffsetTo baseScriptList; @@ -214,6 +337,15 @@ struct HorizAxis struct BASEFormat1_1 { + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + horizAxis.sanitize (c, this) && + vertAxis.sanitize (c, this) && + itemVarStore.sanitize (c, this)); + } + protected: FixedVersion<>version; OffsetTo horizAxis; @@ -227,6 +359,14 @@ struct BASEFormat1_1 struct BASEFormat1_0 { + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + horizAxis.sanitize (c, this) && + vertAxis.sanitize (c, this)); + } + protected: FixedVersion<>version; OffsetTo horizAxis; @@ -240,11 +380,16 @@ struct BASE { static const hb_tag_t tableTag = HB_OT_TAG_BASE; - inline bool sanitize (hb_sanitize_context_t *c) const + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); - return_trace (u.version.sanitize (c) && - likely (u.version.major == 1)); + if (!u.version.sanitize (c)) return_trace (false); + if (!likely(u.version.major == 1)) return_trace (false); + switch (u.version.minor) { + case 0: return_trace (u.format1_0.sanitize (c)); + case 1: return_trace (u.format1_1.sanitize (c)); + default:return_trace (true); + } } protected: From a0bdd546c584eb7c7ea3ca7e19a178723e6fe77f Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Sat, 25 Feb 2017 16:34:58 +0100 Subject: [PATCH 05/12] factorize horiz+vertAxis --- src/hb-ot-layout-base-table.hh | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/src/hb-ot-layout-base-table.hh b/src/hb-ot-layout-base-table.hh index 691b9db1c..059c8f718 100644 --- a/src/hb-ot-layout-base-table.hh +++ b/src/hb-ot-layout-base-table.hh @@ -100,7 +100,6 @@ struct BaseCoordFormat3 { struct BaseCoord { - inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -295,7 +294,7 @@ struct BaseTagList DEFINE_SIZE_ARRAY (4, baseTagListTable); }; -struct VertAxis +struct Axis { inline bool sanitize (hb_sanitize_context_t *c) const @@ -314,26 +313,6 @@ struct VertAxis DEFINE_SIZE_STATIC (4); }; -struct HorizAxis -{ - - inline bool sanitize (hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && - baseTagList.sanitize (c, this) && - baseScriptList.sanitize (c, this)); - } - - protected: - OffsetTo baseTagList; - OffsetTo baseScriptList; - - public: - DEFINE_SIZE_STATIC (4); -}; - - struct BASEFormat1_1 { @@ -348,8 +327,8 @@ struct BASEFormat1_1 protected: FixedVersion<>version; - OffsetTo horizAxis; - OffsetTo vertAxis; + OffsetTo horizAxis; + OffsetTo vertAxis; LOffsetTo itemVarStore; public: @@ -369,8 +348,8 @@ struct BASEFormat1_0 protected: FixedVersion<>version; - OffsetTo horizAxis; - OffsetTo vertAxis; + OffsetTo horizAxis; + OffsetTo vertAxis; public: DEFINE_SIZE_STATIC (8); From 499b4bef2a5b6d49374ab4977509d1fbf7bd6038 Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Sat, 25 Feb 2017 16:48:22 +0100 Subject: [PATCH 06/12] BASE: more consistent naming (with spec and Harfbuzz code base) --- src/hb-ot-layout-base-table.hh | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/hb-ot-layout-base-table.hh b/src/hb-ot-layout-base-table.hh index 059c8f718..f811c4ab2 100644 --- a/src/hb-ot-layout-base-table.hh +++ b/src/hb-ot-layout-base-table.hh @@ -144,7 +144,7 @@ struct FeatMinMaxRecord { }; -struct MinMaxTable { +struct MinMax { inline bool sanitize (hb_sanitize_context_t *c) const { @@ -152,17 +152,17 @@ struct MinMaxTable { return_trace (c->check_struct (this) && minCoord.sanitize (c, this) && maxCoord.sanitize (c, this) && - featMinMaxRecordTable.sanitize (c, this)); + featMinMaxRecords.sanitize (c, this)); } protected: OffsetTo minCoord; OffsetTo maxCoord; USHORT featMinMaxCount; - ArrayOf featMinMaxRecordTable; + ArrayOf featMinMaxRecords; public: - DEFINE_SIZE_ARRAY (8, featMinMaxRecordTable); + DEFINE_SIZE_ARRAY (8, featMinMaxRecords); }; @@ -177,33 +177,33 @@ struct BaseLangSysRecord { protected: Tag baseLangSysTag; - OffsetTo minMax; + OffsetTo minMax; public: DEFINE_SIZE_STATIC (6); }; -struct BaseValuesTable { +struct BaseValues { inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && - baseCoordTable.sanitize (c, this)); + baseCoords.sanitize (c, this)); } protected: USHORT defaultIndex; USHORT baseCoordCount; - OffsetArrayOf baseCoordTable; + OffsetArrayOf baseCoords; public: - DEFINE_SIZE_ARRAY (6, baseCoordTable); + DEFINE_SIZE_ARRAY (6, baseCoords); }; -struct BaseScriptTable { +struct BaseScript { inline bool sanitize (hb_sanitize_context_t *c) const { @@ -211,17 +211,17 @@ struct BaseScriptTable { return_trace (c->check_struct (this) && baseValues.sanitize (c, this) && defaultMinMax.sanitize (c, this) && - baseLangSysRecordTable.sanitize (c, this)); + baseLangSysRecords.sanitize (c, this)); } protected: - OffsetTo baseValues; - OffsetTo defaultMinMax; + OffsetTo baseValues; + OffsetTo defaultMinMax; USHORT baseLangSysCount; - ArrayOf baseLangSysRecordTable; + ArrayOf baseLangSysRecords; public: - DEFINE_SIZE_ARRAY (8, baseLangSysRecordTable); + DEFINE_SIZE_ARRAY (8, baseLangSysRecords); }; @@ -236,7 +236,7 @@ struct BaseScriptRecord { protected: Tag baseScriptTag; - OffsetTo baseScript; + OffsetTo baseScript; public: DEFINE_SIZE_STATIC (6); @@ -248,15 +248,15 @@ struct BaseScriptList { { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && - baseScriptRecordTable.sanitize (c, this)); + baseScriptRecords.sanitize (c, this)); } protected: USHORT baseScriptCount; - ArrayOf baseScriptRecordTable; + ArrayOf baseScriptRecords; public: - DEFINE_SIZE_ARRAY (4, baseScriptRecordTable); + DEFINE_SIZE_ARRAY (4, baseScriptRecords); }; @@ -283,15 +283,15 @@ struct BaseTagList { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && - baseTagListTable.sanitize (c, this)); + baselineTags.sanitize (c, this)); } protected: USHORT baseTagCount; - ArrayOf baseTagListTable; + ArrayOf baselineTags; public: - DEFINE_SIZE_ARRAY (4, baseTagListTable); + DEFINE_SIZE_ARRAY (4, baselineTags); }; struct Axis From bd15567ed6a3667e6f8332b7374aece6a6f2361b Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Sat, 25 Feb 2017 17:08:01 +0100 Subject: [PATCH 07/12] BASE: align member's names --- src/hb-ot-layout-base-table.hh | 70 +++++++++++++++++----------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/hb-ot-layout-base-table.hh b/src/hb-ot-layout-base-table.hh index f811c4ab2..75b3f2e88 100644 --- a/src/hb-ot-layout-base-table.hh +++ b/src/hb-ot-layout-base-table.hh @@ -57,7 +57,7 @@ struct BaseCoordFormat1 { protected: USHORT baseCoordFormat; - SHORT coordinate; + SHORT coordinate; public: DEFINE_SIZE_STATIC (4); @@ -73,7 +73,7 @@ struct BaseCoordFormat2 { protected: USHORT baseCoordFormat; - SHORT coordinate; + SHORT coordinate; USHORT referenceGlyph; USHORT baseCoordPoint; @@ -90,9 +90,9 @@ struct BaseCoordFormat3 { } protected: - USHORT baseCoordFormat; - SHORT coordinate; - OffsetTo deviceTable; + USHORT baseCoordFormat; + SHORT coordinate; + OffsetTo deviceTable; public: DEFINE_SIZE_STATIC (6); @@ -114,7 +114,7 @@ struct BaseCoord { protected: union { - USHORT baseCoordFormat; + USHORT baseCoordFormat; BaseCoordFormat1 format1; BaseCoordFormat2 format2; BaseCoordFormat3 format3; @@ -135,7 +135,7 @@ struct FeatMinMaxRecord { } protected: - Tag featureTableTag; + Tag featureTableTag; OffsetTo minCoord; OffsetTo maxCoord; @@ -156,9 +156,9 @@ struct MinMax { } protected: - OffsetTo minCoord; - OffsetTo maxCoord; - USHORT featMinMaxCount; + OffsetTo minCoord; + OffsetTo maxCoord; + USHORT featMinMaxCount; ArrayOf featMinMaxRecords; public: @@ -176,8 +176,8 @@ struct BaseLangSysRecord { } protected: - Tag baseLangSysTag; - OffsetTo minMax; + Tag baseLangSysTag; + OffsetTo minMax; public: DEFINE_SIZE_STATIC (6); @@ -194,9 +194,9 @@ struct BaseValues { } protected: - USHORT defaultIndex; - USHORT baseCoordCount; - OffsetArrayOf baseCoords; + USHORT defaultIndex; + USHORT baseCoordCount; + OffsetArrayOf baseCoords; public: DEFINE_SIZE_ARRAY (6, baseCoords); @@ -215,10 +215,10 @@ struct BaseScript { } protected: - OffsetTo baseValues; - OffsetTo defaultMinMax; - USHORT baseLangSysCount; - ArrayOf baseLangSysRecords; + OffsetTo baseValues; + OffsetTo defaultMinMax; + USHORT baseLangSysCount; + ArrayOf baseLangSysRecords; public: DEFINE_SIZE_ARRAY (8, baseLangSysRecords); @@ -235,8 +235,8 @@ struct BaseScriptRecord { } protected: - Tag baseScriptTag; - OffsetTo baseScript; + Tag baseScriptTag; + OffsetTo baseScript; public: DEFINE_SIZE_STATIC (6); @@ -252,7 +252,7 @@ struct BaseScriptList { } protected: - USHORT baseScriptCount; + USHORT baseScriptCount; ArrayOf baseScriptRecords; public: @@ -287,8 +287,8 @@ struct BaseTagList } protected: - USHORT baseTagCount; - ArrayOf baselineTags; + USHORT baseTagCount; + ArrayOf baselineTags; public: DEFINE_SIZE_ARRAY (4, baselineTags); @@ -306,8 +306,8 @@ struct Axis } protected: - OffsetTo baseTagList; - OffsetTo baseScriptList; + OffsetTo baseTagList; + OffsetTo baseScriptList; public: DEFINE_SIZE_STATIC (4); @@ -326,9 +326,9 @@ struct BASEFormat1_1 } protected: - FixedVersion<>version; - OffsetTo horizAxis; - OffsetTo vertAxis; + FixedVersion<> version; + OffsetTo horizAxis; + OffsetTo vertAxis; LOffsetTo itemVarStore; public: @@ -347,9 +347,9 @@ struct BASEFormat1_0 } protected: - FixedVersion<>version; - OffsetTo horizAxis; - OffsetTo vertAxis; + FixedVersion<> version; + OffsetTo horizAxis; + OffsetTo vertAxis; public: DEFINE_SIZE_STATIC (8); @@ -373,9 +373,9 @@ struct BASE protected: union { - FixedVersion<>version; /* Version of the BASE table: 1.0 or 1.1 */ - BASEFormat1_0 format1_0; - BASEFormat1_1 format1_1; + FixedVersion<> version; /* Version of the BASE table: 1.0 or 1.1 */ + BASEFormat1_0 format1_0; + BASEFormat1_1 format1_1; } u; public: From d34e35b47457e757781b1769a1fbaf107ec6e32f Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Sat, 25 Feb 2017 20:41:05 +0100 Subject: [PATCH 08/12] BASE: WIP: more access functions --- src/hb-ot-layout-base-table.hh | 218 +++++++++++++++++++++++++++++---- 1 file changed, 194 insertions(+), 24 deletions(-) diff --git a/src/hb-ot-layout-base-table.hh b/src/hb-ot-layout-base-table.hh index 75b3f2e88..c4d9ad14e 100644 --- a/src/hb-ot-layout-base-table.hh +++ b/src/hb-ot-layout-base-table.hh @@ -43,12 +43,17 @@ namespace OT { +#define NO_COORD -32767 + /* * BASE -- The BASE Table */ struct BaseCoordFormat1 { + inline SHORT get_coord () const + { return coordinate; } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -65,6 +70,9 @@ struct BaseCoordFormat1 { struct BaseCoordFormat2 { + inline SHORT get_coord () const + { return coordinate; } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -83,6 +91,9 @@ struct BaseCoordFormat2 { struct BaseCoordFormat3 { + inline SHORT get_coord (void ) const + { return coordinate; } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -100,6 +111,18 @@ struct BaseCoordFormat3 { struct BaseCoord { + inline hb_position_t get_value (hb_font_t *font, hb_direction_t dir) const + { + SHORT coord; + switch (u.baseCoordFormat) { + case 1: coord = u.format1.get_coord(); + case 2: coord = u.format2.get_coord(); + case 3: coord = u.format3.get_coord(); + default: return 0; + } + return font->em_scale (coord, dir); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -126,6 +149,21 @@ struct BaseCoord { struct FeatMinMaxRecord { + inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir) const + { + if (unlikely(minCoord == Null(OffsetTo))) return NO_COORD; + return (this+minCoord).get_value(font, dir); + } + + inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir) const + { + if (unlikely(maxCoord == Null(OffsetTo))) return NO_COORD; + return (this+maxCoord).get_value(font, dir); + } + + inline Tag get_tag () const + { return featureTableTag; } + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); @@ -146,6 +184,42 @@ struct FeatMinMaxRecord { struct MinMax { + inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir) const + { + if (unlikely(minCoord == Null(OffsetTo))) return NO_COORD; + return (this+minCoord).get_value(font, dir); + } + + inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir) const + { + if (unlikely(maxCoord == Null(OffsetTo))) return NO_COORD; + return (this+maxCoord).get_value(font, dir); + } + + inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir, Tag featureTableTag) const + { + for (unsigned int i = 0; i < featMinMaxCount; i++) + { + if (featMinMaxRecords[i].get_tag() == featureTableTag) + return featMinMaxRecords[i].get_min_value(font, dir); + // we could take advantage of alphabetical order by comparing Tags, not currently possible + //if (featMinMaxRecords[i].get_tag() > featureTableTag) + // break; + } + return get_min_value (font, dir); + } + + inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir, Tag featureTableTag) const + { + for (unsigned int i = 0; i < featMinMaxCount; i++) + { + if (featMinMaxRecords[i].get_tag() == featureTableTag) + return featMinMaxRecords[i].get_max_value(font, dir); + // we could use alphabetical order to break here + } + return get_min_value (font, dir); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -153,13 +227,14 @@ struct MinMax { minCoord.sanitize (c, this) && maxCoord.sanitize (c, this) && featMinMaxRecords.sanitize (c, this)); + // TODO: test alphabetical order? } protected: OffsetTo minCoord; OffsetTo maxCoord; USHORT featMinMaxCount; - ArrayOf featMinMaxRecords; + ArrayOf featMinMaxRecords; /* All FeatMinMaxRecords are listed alphabetically */ public: DEFINE_SIZE_ARRAY (8, featMinMaxRecords); @@ -168,16 +243,32 @@ struct MinMax { struct BaseLangSysRecord { + inline Tag get_tag(void) const + { return baseLangSysTag; } + + inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir) const + { return (this+minMax).get_min_value(font, dir); } + + inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir) const + { return (this+minMax).get_max_value(font, dir); } + + inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir, Tag featureTableTag) const + { return (this+minMax).get_min_value(font, dir, featureTableTag); } + + inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir, Tag featureTableTag) const + { return (this+minMax).get_max_value(font, dir, featureTableTag); } + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && + minMax != Null(OffsetTo) && minMax.sanitize (c, base)); } protected: Tag baseLangSysTag; - OffsetTo minMax; + OffsetTo minMax; // not supposed to be NULL public: DEFINE_SIZE_STATIC (6); @@ -205,6 +296,62 @@ struct BaseValues { struct BaseScript { + inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir) const + { + if (unlikely(defaultMinMax == Null(OffsetTo))) return NO_COORD; + return (this+defaultMinMax).get_min_value(font, dir); + } + + inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir) const + { + if (unlikely(defaultMinMax == Null(OffsetTo))) return NO_COORD; + return (this+defaultMinMax).get_max_value(font, dir); + } + + inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir, Tag baseLangSysTag) const + { + for (unsigned int i = 0; i < baseLangSysCount; i++) + { + if (baseLangSysRecords[i].get_tag() == baseLangSysTag) + return baseLangSysRecords[i].get_min_value(font, dir); + // we could use alphabetical order to break here + } + return get_min_value (font, dir); + } + + inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir, Tag baseLangSysTag) const + { + for (unsigned int i = 0; i < baseLangSysCount; i++) + { + if (baseLangSysRecords[i].get_tag() == baseLangSysTag) + return baseLangSysRecords[i].get_max_value(font, dir); + // we could use alphabetical order to break here + } + return get_max_value (font, dir); + } + + inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir, Tag baseLangSysTag, Tag featureTableTag) const + { + for (unsigned int i = 0; i < baseLangSysCount; i++) + { + if (baseLangSysRecords[i].get_tag() == baseLangSysTag) + return baseLangSysRecords[i].get_min_value(font, dir, featureTableTag); + // we could use alphabetical order to break here + } + return get_min_value (font, dir); + } + + inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir, Tag baseLangSysTag, Tag featureTableTag) const + { + for (unsigned int i = 0; i < baseLangSysCount; i++) + { + if (baseLangSysRecords[i].get_tag() == baseLangSysTag) + return baseLangSysRecords[i].get_max_value(font, dir); + // we could use alphabetical order to break here + } + return get_max_value (font, dir); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -227,6 +374,16 @@ struct BaseScript { struct BaseScriptRecord { + inline const BaseScript *get_baseScript (void) const + { + return &(this+baseScript); + } + + inline bool get_tag (void) const + { + return baseScriptTag; + } + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); @@ -244,6 +401,22 @@ struct BaseScriptRecord { struct BaseScriptList { + inline const BaseScript *get_baseScript_from_tag (Tag baseScriptTag) const + { + for (unsigned int i = 0; i < baseScriptCount; i++) + if (baseScriptRecords[i].get_tag() == baseScriptTag) + return baseScriptRecords[i].get_baseScript(); + // we could use alphabetical order to break here + return NULL; + } + + inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir, Tag baseScriptTag) const + { + const BaseScript *baseScript = get_baseScript_from_tag (baseScriptTag); + if (baseScript == NULL) return NO_COORD; + return baseScript->get_min_value(font, dir); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -260,35 +433,26 @@ struct BaseScriptList { }; -struct BaselineTag { +struct BaseTagList +{ - inline bool sanitize (hb_sanitize_context_t *c, const void *base) const + inline bool hasTag(Tag tag) const + { + for (unsigned int i = 0; i < baseTagCount; i++) + if (baselineTags[i] == tag) + return true; + return false; + } + + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); return_trace (c->check_struct (this)); } protected: - Tag tag; - - public: - DEFINE_SIZE_STATIC (4); - -}; - -struct BaseTagList -{ - - inline bool sanitize (hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - return_trace (c->check_struct (this) && - baselineTags.sanitize (c, this)); - } - - protected: - USHORT baseTagCount; - ArrayOf baselineTags; + USHORT baseTagCount; + ArrayOf baselineTags; // must be in alphabetical order public: DEFINE_SIZE_ARRAY (4, baselineTags); @@ -297,6 +461,12 @@ struct BaseTagList struct Axis { + inline bool hasTag(Tag tag) const + { + if (unlikely(baseTagList == Null(OffsetTo))) return false; + return (this+baseTagList).hasTag(tag); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); From 3963315f1b2eae2504bc683760245c827cd1ef16 Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Sun, 26 Feb 2017 15:07:53 +0100 Subject: [PATCH 09/12] BASE: first complete version --- src/hb-ot-layout-base-table.hh | 448 +++++++++++++++++++++++---------- 1 file changed, 319 insertions(+), 129 deletions(-) diff --git a/src/hb-ot-layout-base-table.hh b/src/hb-ot-layout-base-table.hh index c4d9ad14e..9be403e53 100644 --- a/src/hb-ot-layout-base-table.hh +++ b/src/hb-ot-layout-base-table.hh @@ -43,7 +43,9 @@ namespace OT { -#define NO_COORD -32767 +#define NO_COORD Null(SHORT)//SHORT((short int) -32767) + +#define NOT_INDEXED ((unsigned int) -1) /* * BASE -- The BASE Table @@ -51,7 +53,7 @@ namespace OT { struct BaseCoordFormat1 { - inline SHORT get_coord () const + inline SHORT get_coord (void) const { return coordinate; } inline bool sanitize (hb_sanitize_context_t *c) const @@ -70,7 +72,7 @@ struct BaseCoordFormat1 { struct BaseCoordFormat2 { - inline SHORT get_coord () const + inline SHORT get_coord (void) const { return coordinate; } inline bool sanitize (hb_sanitize_context_t *c) const @@ -91,7 +93,7 @@ struct BaseCoordFormat2 { struct BaseCoordFormat3 { - inline SHORT get_coord (void ) const + inline SHORT get_coord (void) const { return coordinate; } inline bool sanitize (hb_sanitize_context_t *c) const @@ -111,17 +113,8 @@ struct BaseCoordFormat3 { struct BaseCoord { - inline hb_position_t get_value (hb_font_t *font, hb_direction_t dir) const - { - SHORT coord; - switch (u.baseCoordFormat) { - case 1: coord = u.format1.get_coord(); - case 2: coord = u.format2.get_coord(); - case 3: coord = u.format3.get_coord(); - default: return 0; - } - return font->em_scale (coord, dir); - } + inline SHORT get_coord (void) const + { return u.format1.get_coord(); } inline bool sanitize (hb_sanitize_context_t *c) const { @@ -131,7 +124,7 @@ struct BaseCoord { case 1: return_trace (u.format1.sanitize (c)); case 2: return_trace (u.format2.sanitize (c)); case 3: return_trace (u.format3.sanitize (c)); - default:return_trace (true); + default:return_trace (false); } } @@ -149,16 +142,16 @@ struct BaseCoord { struct FeatMinMaxRecord { - inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir) const - { - if (unlikely(minCoord == Null(OffsetTo))) return NO_COORD; - return (this+minCoord).get_value(font, dir); + inline SHORT get_min_value (void) const + { + if (minCoord == Null(OffsetTo)) return NO_COORD; + return (this+minCoord).get_coord(); } - inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir) const - { - if (unlikely(maxCoord == Null(OffsetTo))) return NO_COORD; - return (this+maxCoord).get_value(font, dir); + inline SHORT get_max_value (void) const + { + if (minCoord == Null(OffsetTo)) return NO_COORD; + return (this+maxCoord).get_coord(); } inline Tag get_tag () const @@ -184,41 +177,39 @@ struct FeatMinMaxRecord { struct MinMax { - inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir) const - { - if (unlikely(minCoord == Null(OffsetTo))) return NO_COORD; - return (this+minCoord).get_value(font, dir); - } - - inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir) const - { - if (unlikely(maxCoord == Null(OffsetTo))) return NO_COORD; - return (this+maxCoord).get_value(font, dir); - } - - inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir, Tag featureTableTag) const + inline unsigned int get_feature_tag_index (Tag featureTableTag) const { - for (unsigned int i = 0; i < featMinMaxCount; i++) - { - if (featMinMaxRecords[i].get_tag() == featureTableTag) - return featMinMaxRecords[i].get_min_value(font, dir); - // we could take advantage of alphabetical order by comparing Tags, not currently possible - //if (featMinMaxRecords[i].get_tag() > featureTableTag) - // break; + Tag tag; + int cmp; + // taking advantage of alphabetical order + for (unsigned int i = 0; i < featMinMaxCount; i++) { + tag = featMinMaxRecords[i].get_tag(); + cmp = tag.cmp(featureTableTag); + if (cmp == 0) return i; + if (cmp > 0) return NOT_INDEXED; } - return get_min_value (font, dir); + return NOT_INDEXED; } - inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir, Tag featureTableTag) const + inline SHORT get_min_value (unsigned int featureTableTagIndex) const { - for (unsigned int i = 0; i < featMinMaxCount; i++) - { - if (featMinMaxRecords[i].get_tag() == featureTableTag) - return featMinMaxRecords[i].get_max_value(font, dir); - // we could use alphabetical order to break here + if (featureTableTagIndex == NOT_INDEXED) { + if (minCoord == Null(OffsetTo)) return NO_COORD; + return (this+minCoord).get_coord(); } - return get_min_value (font, dir); - } + if (unlikely(featureTableTagIndex >= featMinMaxCount)) return NO_COORD; + return featMinMaxRecords[featureTableTagIndex].get_min_value(); + } + + inline SHORT get_max_value (unsigned int featureTableTagIndex) const + { + if (featureTableTagIndex == NOT_INDEXED) { + if (minCoord == Null(OffsetTo)) return NO_COORD; + return (this+maxCoord).get_coord(); + } + if (unlikely(featureTableTagIndex >= featMinMaxCount)) return NO_COORD; + return featMinMaxRecords[featureTableTagIndex].get_max_value(); + } inline bool sanitize (hb_sanitize_context_t *c) const { @@ -234,7 +225,7 @@ struct MinMax { OffsetTo minCoord; OffsetTo maxCoord; USHORT featMinMaxCount; - ArrayOf featMinMaxRecords; /* All FeatMinMaxRecords are listed alphabetically */ + ArrayOf featMinMaxRecords; public: DEFINE_SIZE_ARRAY (8, featMinMaxRecords); @@ -246,17 +237,14 @@ struct BaseLangSysRecord { inline Tag get_tag(void) const { return baseLangSysTag; } - inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir) const - { return (this+minMax).get_min_value(font, dir); } + inline unsigned int get_feature_tag_index (Tag featureTableTag) const + { (this+minMax).get_feature_tag_index(featureTableTag); } - inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir) const - { return (this+minMax).get_max_value(font, dir); } + inline SHORT get_min_value (unsigned int featureTableTagIndex) const + { (this+minMax).get_min_value(featureTableTagIndex); } - inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir, Tag featureTableTag) const - { return (this+minMax).get_min_value(font, dir, featureTableTag); } - - inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir, Tag featureTableTag) const - { return (this+minMax).get_max_value(font, dir, featureTableTag); } + inline SHORT get_max_value (unsigned int featureTableTagIndex) const + { (this+minMax).get_max_value(featureTableTagIndex); } inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { @@ -277,15 +265,25 @@ struct BaseLangSysRecord { struct BaseValues { + inline const unsigned int get_default_base_tag_index (void) const + { return defaultIndex; } + + inline SHORT get_base_coord (unsigned int baselineTagIndex) const + { + if (unlikely(baselineTagIndex >= baseCoordCount)) return NO_COORD; + return (this+baseCoords[baselineTagIndex]).get_coord(); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && + defaultIndex <= baseCoordCount && baseCoords.sanitize (c, this)); } protected: - USHORT defaultIndex; + Index defaultIndex; USHORT baseCoordCount; OffsetArrayOf baseCoords; @@ -296,62 +294,56 @@ struct BaseValues { struct BaseScript { - inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir) const + inline unsigned int get_lang_tag_index (Tag baseLangSysTag) const { - if (unlikely(defaultMinMax == Null(OffsetTo))) return NO_COORD; - return (this+defaultMinMax).get_min_value(font, dir); - } - - inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir) const - { - if (unlikely(defaultMinMax == Null(OffsetTo))) return NO_COORD; - return (this+defaultMinMax).get_max_value(font, dir); - } - - inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir, Tag baseLangSysTag) const - { - for (unsigned int i = 0; i < baseLangSysCount; i++) - { - if (baseLangSysRecords[i].get_tag() == baseLangSysTag) - return baseLangSysRecords[i].get_min_value(font, dir); - // we could use alphabetical order to break here + Tag tag; + int cmp; + for (unsigned int i = 0; i < baseLangSysCount; i++) { + tag = baseLangSysRecords[i].get_tag(); + // taking advantage of alphabetical order + cmp = tag.cmp(baseLangSysTag); + if (cmp == 0) return i; + if (cmp > 0) return NOT_INDEXED; } - return get_min_value (font, dir); + return NOT_INDEXED; } - inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir, Tag baseLangSysTag) const + inline unsigned int get_feature_tag_index (unsigned int baseLangSysIndex, Tag featureTableTag) const { - for (unsigned int i = 0; i < baseLangSysCount; i++) - { - if (baseLangSysRecords[i].get_tag() == baseLangSysTag) - return baseLangSysRecords[i].get_max_value(font, dir); - // we could use alphabetical order to break here + if (baseLangSysIndex == NOT_INDEXED) { + if (unlikely(defaultMinMax)) return NOT_INDEXED; + return (this+defaultMinMax).get_feature_tag_index(featureTableTag); } - return get_max_value (font, dir); + if (unlikely(baseLangSysIndex >= baseLangSysCount)) return NOT_INDEXED; + return baseLangSysRecords[baseLangSysIndex].get_feature_tag_index(featureTableTag); } - inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir, Tag baseLangSysTag, Tag featureTableTag) const + inline SHORT get_min_value (unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const { - for (unsigned int i = 0; i < baseLangSysCount; i++) - { - if (baseLangSysRecords[i].get_tag() == baseLangSysTag) - return baseLangSysRecords[i].get_min_value(font, dir, featureTableTag); - // we could use alphabetical order to break here + if (baseLangSysIndex == NOT_INDEXED) { + if (unlikely(defaultMinMax == Null(OffsetTo))) return NO_COORD; + return (this+defaultMinMax).get_min_value(featureTableTagIndex); } - return get_min_value (font, dir); + if (unlikely(baseLangSysIndex >= baseLangSysCount)) return NO_COORD; + return baseLangSysRecords[baseLangSysIndex].get_max_value(featureTableTagIndex); } - inline hb_position_t get_max_value (hb_font_t *font, hb_direction_t dir, Tag baseLangSysTag, Tag featureTableTag) const + inline SHORT get_max_value (unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const { - for (unsigned int i = 0; i < baseLangSysCount; i++) - { - if (baseLangSysRecords[i].get_tag() == baseLangSysTag) - return baseLangSysRecords[i].get_max_value(font, dir); - // we could use alphabetical order to break here + if (baseLangSysIndex == NOT_INDEXED) { + if (unlikely(defaultMinMax == Null(OffsetTo))) return NO_COORD; + return (this+defaultMinMax).get_min_value(featureTableTagIndex); } - return get_max_value (font, dir); + if (unlikely(baseLangSysIndex >= baseLangSysCount)) return NO_COORD; + return baseLangSysRecords[baseLangSysIndex].get_max_value(featureTableTagIndex); } + inline unsigned int get_default_base_tag_index (void) const + { return (this+baseValues).get_default_base_tag_index(); } + + inline SHORT get_base_coord (unsigned int baselineTagIndex) const + { return (this+baseValues).get_base_coord(baselineTagIndex); } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -374,20 +366,32 @@ struct BaseScript { struct BaseScriptRecord { - inline const BaseScript *get_baseScript (void) const - { - return &(this+baseScript); - } - inline bool get_tag (void) const - { - return baseScriptTag; - } + { return baseScriptTag; } + + inline unsigned int get_default_base_tag_index(void) const + { return (this+baseScript).get_default_base_tag_index(); } + + inline SHORT get_base_coord(unsigned int baselineTagIndex) const + { return (this+baseScript).get_base_coord(baselineTagIndex); } + + inline unsigned int get_lang_tag_index (Tag baseLangSysTag) const + { return (this+baseScript).get_lang_tag_index(baseLangSysTag); } + + inline unsigned int get_feature_tag_index (unsigned int baseLangSysIndex, Tag featureTableTag) const + { return (this+baseScript).get_feature_tag_index(baseLangSysIndex, featureTableTag); } + + inline SHORT get_max_value (unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const + { return (this+baseScript).get_max_value(baseLangSysIndex, featureTableTagIndex); } + + inline SHORT get_min_value (unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const + { return (this+baseScript).get_min_value(baseLangSysIndex, featureTableTagIndex); } inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); return_trace (c->check_struct (this) && + baseScript != Null(OffsetTo) && baseScript.sanitize (c, base)); } @@ -401,20 +405,48 @@ struct BaseScriptRecord { struct BaseScriptList { - inline const BaseScript *get_baseScript_from_tag (Tag baseScriptTag) const + inline unsigned int get_base_script_index (Tag baseScriptTag) const { for (unsigned int i = 0; i < baseScriptCount; i++) if (baseScriptRecords[i].get_tag() == baseScriptTag) - return baseScriptRecords[i].get_baseScript(); - // we could use alphabetical order to break here - return NULL; + return i; + return NOT_INDEXED; } - inline hb_position_t get_min_value (hb_font_t *font, hb_direction_t dir, Tag baseScriptTag) const + inline unsigned int get_default_base_tag_index (unsigned int baseScriptIndex) const + { + if (unlikely(baseScriptIndex >= baseScriptCount)) return NOT_INDEXED; + return baseScriptRecords[baseScriptIndex].get_default_base_tag_index(); + } + + inline SHORT get_base_coord(unsigned int baseScriptIndex, unsigned int baselineTagIndex) const { - const BaseScript *baseScript = get_baseScript_from_tag (baseScriptTag); - if (baseScript == NULL) return NO_COORD; - return baseScript->get_min_value(font, dir); + if (unlikely(baseScriptIndex >= baseScriptCount)) return NO_COORD; + return baseScriptRecords[baseScriptIndex].get_base_coord(baselineTagIndex); + } + + inline unsigned int get_lang_tag_index (unsigned int baseScriptIndex, Tag baseLangSysTag) const + { + if (unlikely(baseScriptIndex >= baseScriptCount)) return NOT_INDEXED; + return baseScriptRecords[baseScriptIndex].get_lang_tag_index(baseLangSysTag); + } + + inline unsigned int get_feature_tag_index (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, Tag featureTableTag) const + { + if (unlikely(baseScriptIndex >= baseScriptCount)) return NOT_INDEXED; + return baseScriptRecords[baseScriptIndex].get_feature_tag_index(baseLangSysIndex, featureTableTag); + } + + inline SHORT get_max_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const + { + if (unlikely(baseScriptIndex >= baseScriptCount)) return NO_COORD; + return baseScriptRecords[baseScriptIndex].get_max_value(baseLangSysIndex, featureTableTagIndex); + } + + inline SHORT get_min_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const + { + if (unlikely(baseScriptIndex >= baseScriptCount)) return NO_COORD; + return baseScriptRecords[baseScriptIndex].get_min_value(baseLangSysIndex, featureTableTagIndex); } inline bool sanitize (hb_sanitize_context_t *c) const @@ -436,12 +468,12 @@ struct BaseScriptList { struct BaseTagList { - inline bool hasTag(Tag tag) const + inline unsigned int get_tag_index(Tag baselineTag) const { for (unsigned int i = 0; i < baseTagCount; i++) - if (baselineTags[i] == tag) - return true; - return false; + if (baselineTags[i] == baselineTag) + return i; + return NOT_INDEXED; } inline bool sanitize (hb_sanitize_context_t *c) const @@ -452,7 +484,7 @@ struct BaseTagList protected: USHORT baseTagCount; - ArrayOf baselineTags; // must be in alphabetical order + SortedArrayOf baselineTags; public: DEFINE_SIZE_ARRAY (4, baselineTags); @@ -461,10 +493,46 @@ struct BaseTagList struct Axis { - inline bool hasTag(Tag tag) const + inline unsigned int get_base_tag_index(Tag baselineTag) const { - if (unlikely(baseTagList == Null(OffsetTo))) return false; - return (this+baseTagList).hasTag(tag); + if (unlikely(baseTagList == Null(OffsetTo))) return NOT_INDEXED; + return (this+baseTagList).get_tag_index(baselineTag); + } + + inline unsigned int get_default_base_tag_index_for_script_index (unsigned int baseScriptIndex) const + { + if (unlikely(baseScriptList == Null(OffsetTo))) return NOT_INDEXED; + return (this+baseScriptList).get_default_base_tag_index(baseScriptIndex); + } + + inline SHORT get_base_coord(unsigned int baseScriptIndex, unsigned int baselineTagIndex) const + { + if (unlikely(baseScriptList == Null(OffsetTo))) return NO_COORD; + return (this+baseScriptList).get_base_coord(baseScriptIndex, baselineTagIndex); + } + + inline unsigned int get_lang_tag_index (unsigned int baseScriptIndex, Tag baseLangSysTag) const + { + if (unlikely(baseScriptList == Null(OffsetTo))) return NOT_INDEXED; + return (this+baseScriptList).get_lang_tag_index(baseScriptIndex, baseLangSysTag); + } + + inline unsigned int get_feature_tag_index (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, Tag featureTableTag) const + { + if (unlikely(baseScriptList == Null(OffsetTo))) return NOT_INDEXED; + return (this+baseScriptList).get_feature_tag_index(baseScriptIndex, baseLangSysIndex, featureTableTag); + } + + inline SHORT get_max_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const + { + if (unlikely(baseScriptList == Null(OffsetTo))) return NO_COORD; + return (this+baseScriptList).get_max_value(baseScriptIndex, baseLangSysIndex, featureTableTagIndex); + } + + inline SHORT get_min_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const + { + if (unlikely(baseScriptList == Null(OffsetTo))) return NO_COORD; + return (this+baseScriptList).get_min_value(baseScriptIndex, baseLangSysIndex, featureTableTagIndex); } inline bool sanitize (hb_sanitize_context_t *c) const @@ -508,6 +576,104 @@ struct BASEFormat1_1 struct BASEFormat1_0 { + inline bool has_vert_axis(void) + { return vertAxis != Null(OffsetTo); } + + inline bool has_horiz_axis(void) + { return horizAxis != Null(OffsetTo); } + + // horizontal axis base coords: + + inline unsigned int get_horiz_base_tag_index(Tag baselineTag) const + { + if (unlikely(horizAxis == Null(OffsetTo))) return NOT_INDEXED; + return (this+horizAxis).get_base_tag_index(baselineTag); + } + + inline unsigned int get_horiz_default_base_tag_index_for_script_index (unsigned int baseScriptIndex) const + { + if (unlikely(horizAxis == Null(OffsetTo))) return NOT_INDEXED; + return (this+horizAxis).get_default_base_tag_index_for_script_index(baseScriptIndex); + } + + inline SHORT get_horiz_base_coord(unsigned int baseScriptIndex, unsigned int baselineTagIndex) const + { + if (unlikely(horizAxis == Null(OffsetTo))) return NO_COORD; + return (this+horizAxis).get_base_coord(baseScriptIndex, baselineTagIndex); + } + + // vertical axis base coords: + + inline unsigned int get_vert_base_tag_index(Tag baselineTag) const + { + if (unlikely(vertAxis == Null(OffsetTo))) return NOT_INDEXED; + return (this+vertAxis).get_base_tag_index(baselineTag); + } + + inline unsigned int get_vert_default_base_tag_index_for_script_index (unsigned int baseScriptIndex) const + { + if (unlikely(vertAxis == Null(OffsetTo))) return NOT_INDEXED; + return (this+vertAxis).get_default_base_tag_index_for_script_index(baseScriptIndex); + } + + inline SHORT get_vert_base_coord(unsigned int baseScriptIndex, unsigned int baselineTagIndex) const + { + if (vertAxis == Null(OffsetTo)) return NO_COORD; + return (this+vertAxis).get_base_coord(baseScriptIndex, baselineTagIndex); + } + + // horizontal axis min/max coords: + + inline unsigned int get_horiz_lang_tag_index (unsigned int baseScriptIndex, Tag baseLangSysTag) const + { + if (unlikely(horizAxis == Null(OffsetTo))) return NOT_INDEXED; + return (this+horizAxis).get_lang_tag_index (baseScriptIndex, baseLangSysTag); + } + + inline unsigned int get_horiz_feature_tag_index (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, Tag featureTableTag) const + { + if (unlikely(horizAxis == Null(OffsetTo))) return NOT_INDEXED; + return (this+horizAxis).get_feature_tag_index (baseScriptIndex, baseLangSysIndex, featureTableTag); + } + + inline SHORT get_horiz_max_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const + { + if (unlikely(horizAxis == Null(OffsetTo))) return NO_COORD; + return (this+horizAxis).get_max_value (baseScriptIndex, baseLangSysIndex, featureTableTagIndex); + } + + inline SHORT get_horiz_min_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const + { + if (unlikely(horizAxis == Null(OffsetTo))) return NO_COORD; + return (this+horizAxis).get_min_value (baseScriptIndex, baseLangSysIndex, featureTableTagIndex); + } + + // vertical axis min/max coords: + + inline unsigned int get_vert_lang_tag_index (unsigned int baseScriptIndex, Tag baseLangSysTag) const + { + if (unlikely(vertAxis == Null(OffsetTo))) return NOT_INDEXED; + return (this+vertAxis).get_lang_tag_index (baseScriptIndex, baseLangSysTag); + } + + inline unsigned int get_vert_feature_tag_index (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, Tag featureTableTag) const + { + if (unlikely(vertAxis == Null(OffsetTo))) return NOT_INDEXED; + return (this+vertAxis).get_feature_tag_index (baseScriptIndex, baseLangSysIndex, featureTableTag); + } + + inline SHORT get_vert_max_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const + { + if (unlikely(vertAxis == Null(OffsetTo))) return NO_COORD; + return (this+vertAxis).get_max_value (baseScriptIndex, baseLangSysIndex, featureTableTagIndex); + } + + inline SHORT get_vert_min_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const + { + if (unlikely(vertAxis == Null(OffsetTo))) return NO_COORD; + return (this+vertAxis).get_min_value (baseScriptIndex, baseLangSysIndex, featureTableTagIndex); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -529,6 +695,30 @@ struct BASE { static const hb_tag_t tableTag = HB_OT_TAG_BASE; + inline bool has_vert_axis(void) + { return u.format1_0.has_vert_axis(); } + + inline bool has_horiz_axis(void) + { return u.format1_0.has_horiz_axis(); } + + inline unsigned int get_horiz_base_tag_index(Tag baselineTag) const + { return u.format1_0.get_horiz_base_tag_index(baselineTag); } + + inline unsigned int get_horiz_default_base_tag_index_for_script_index (unsigned int baseScriptIndex) const + { return u.format1_0.get_horiz_default_base_tag_index_for_script_index(baseScriptIndex); } + + inline SHORT get_horiz_base_coord(unsigned int baseScriptIndex, unsigned int baselineTagIndex) const + { return u.format1_0.get_horiz_base_coord(baseScriptIndex, baselineTagIndex); } + + inline unsigned int get_vert_base_tag_index(Tag baselineTag) const + { return u.format1_0.get_vert_base_tag_index(baselineTag); } + + inline unsigned int get_vert_default_base_tag_index_for_script_index (unsigned int baseScriptIndex) const + { return u.format1_0.get_vert_default_base_tag_index_for_script_index(baseScriptIndex); } + + inline SHORT get_vert_base_coord(unsigned int baseScriptIndex, unsigned int baselineTagIndex) const + { return u.format1_0.get_vert_base_coord(baseScriptIndex, baselineTagIndex); } + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); @@ -537,7 +727,7 @@ struct BASE switch (u.version.minor) { case 0: return_trace (u.format1_0.sanitize (c)); case 1: return_trace (u.format1_1.sanitize (c)); - default:return_trace (true); + default:return_trace (false); } } From f72726c52b104a71ebf5b39fa1e3eb9febd446fc Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Sun, 26 Feb 2017 15:08:43 +0100 Subject: [PATCH 10/12] BASE: add function in main BASE object --- src/hb-ot-layout-base-table.hh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/hb-ot-layout-base-table.hh b/src/hb-ot-layout-base-table.hh index 9be403e53..c60ce6de5 100644 --- a/src/hb-ot-layout-base-table.hh +++ b/src/hb-ot-layout-base-table.hh @@ -719,6 +719,30 @@ struct BASE inline SHORT get_vert_base_coord(unsigned int baseScriptIndex, unsigned int baselineTagIndex) const { return u.format1_0.get_vert_base_coord(baseScriptIndex, baselineTagIndex); } + inline unsigned int get_horiz_lang_tag_index (unsigned int baseScriptIndex, Tag baseLangSysTag) const + { return u.format1_0.get_horiz_lang_tag_index(baseScriptIndex, baseLangSysTag); } + + inline unsigned int get_horiz_feature_tag_index (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, Tag featureTableTag) const + { return u.format1_0.get_horiz_feature_tag_index(baseScriptIndex, baseLangSysIndex, featureTableTag); } + + inline SHORT get_horiz_max_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const + { return u.format1_0.get_horiz_max_value(baseScriptIndex, baseLangSysIndex, featureTableTagIndex); } + + inline SHORT get_horiz_min_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const + { return u.format1_0.get_horiz_min_value(baseScriptIndex, baseLangSysIndex, featureTableTagIndex); } + + inline unsigned int get_vert_lang_tag_index (unsigned int baseScriptIndex, Tag baseLangSysTag) const + { return u.format1_0.get_vert_lang_tag_index(baseScriptIndex, baseLangSysTag); } + + inline unsigned int get_vert_feature_tag_index (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, Tag featureTableTag) const + { return u.format1_0.get_vert_feature_tag_index(baseScriptIndex, baseLangSysIndex, featureTableTag); } + + inline SHORT get_vert_max_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const + { return u.format1_0.get_vert_max_value(baseScriptIndex, baseLangSysIndex, featureTableTagIndex); } + + inline SHORT get_vert_min_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const + { return u.format1_0.get_vert_min_value(baseScriptIndex, baseLangSysIndex, featureTableTagIndex); } + inline bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); From e65aaaa00a3b5ac811b5c73b5186cd7d65731f7b Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Sun, 5 Mar 2017 14:53:39 +0100 Subject: [PATCH 11/12] BASE: start api --- src/Makefile.sources | 2 ++ src/hb-ot-base.cc | 58 ++++++++++++++++++++++++++++++++++ src/hb-ot-base.h | 56 ++++++++++++++++++++++++++++++++ src/hb-ot-layout-base-table.hh | 15 ++------- 4 files changed, 118 insertions(+), 13 deletions(-) create mode 100644 src/hb-ot-base.cc create mode 100644 src/hb-ot-base.h diff --git a/src/Makefile.sources b/src/Makefile.sources index 0f83f6ebd..db7305659 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -68,6 +68,7 @@ HB_NODIST_headers = \ HB_FALLBACK_sources = hb-fallback-shape.cc HB_OT_sources = \ + hb-ot-base.cc \ hb-ot-font.cc \ hb-ot-layout.cc \ hb-ot-layout-base-table.hh \ @@ -121,6 +122,7 @@ HB_OT_headers = \ hb-ot-font.h \ hb-ot-layout.h \ hb-ot-math.h \ + hb-ot-base.h \ hb-ot-shape.h \ hb-ot-tag.h \ hb-ot-var.h \ diff --git a/src/hb-ot-base.cc b/src/hb-ot-base.cc new file mode 100644 index 000000000..27e0b208a --- /dev/null +++ b/src/hb-ot-base.cc @@ -0,0 +1,58 @@ +/* + * Copyright © 2017 Elie Roux + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + */ + +#include "hb-open-type-private.hh" + +#include "hb-ot-layout-private.hh" +#include "hb-ot-layout-base-table.hh" + +static inline const OT::BASE& +_get_base (hb_face_t *face) +{ + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::BASE); + hb_ot_layout_t * layout = hb_ot_layout_from_face (face); + return *(layout->base.get ()); +} + +/* + * OT::BASE + */ + +/** + * hb_ot_base_has_data: + * @face: #hb_face_t to test + * + * This function allows to verify the presence of an OpenType BASE table on the + * face. + * + * Return value: true if face has a BASE table, false otherwise + * + * Since: XXX + **/ +hb_bool_t +hb_ot_base_has_data (hb_face_t *face) +{ + return &_get_base (face) != &OT::Null(OT::BASE); +} diff --git a/src/hb-ot-base.h b/src/hb-ot-base.h new file mode 100644 index 000000000..9d82d2289 --- /dev/null +++ b/src/hb-ot-base.h @@ -0,0 +1,56 @@ +/* + * Copyright © 2017 Elie Roux + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + */ + +#ifndef HB_OT_H_IN +#error "Include instead." +#endif + +#ifndef HB_OT_BASE_H +#define HB_OT_BASE_H + +#include "hb.h" + +HB_BEGIN_DECLS + +#define HB_OT_TAG_BASE HB_TAG('B','A','S','E') + +// https://www.microsoft.com/typography/otspec/baselinetags.htm + +#define HB_OT_TAG_BASE_HANG HB_TAG('h','a','n','g') +#define HB_OT_TAG_BASE_ICFB HB_TAG('i','c','f','b') +#define HB_OT_TAG_BASE_ICFT HB_TAG('i','c','f','t') +#define HB_OT_TAG_BASE_IDEO HB_TAG('i','d','e','o') +#define HB_OT_TAG_BASE_IDTB HB_TAG('i','d','t','b') +#define HB_OT_TAG_BASE_MATH HB_TAG('m','a','t','h') +#define HB_OT_TAG_BASE_ROMN HB_TAG('r','o','m','n') + +/* Methods */ + +HB_EXTERN hb_bool_t +hb_ot_base_has_data (hb_face_t *face); + +HB_END_DECLS + +#endif /* HB_OT_BASE_H */ diff --git a/src/hb-ot-layout-base-table.hh b/src/hb-ot-layout-base-table.hh index c60ce6de5..0d1e197e1 100644 --- a/src/hb-ot-layout-base-table.hh +++ b/src/hb-ot-layout-base-table.hh @@ -28,18 +28,7 @@ #include "hb-open-type-private.hh" #include "hb-ot-layout-common-private.hh" - -#define HB_OT_TAG_BASE HB_TAG('B','A','S','E') - -// https://www.microsoft.com/typography/otspec/baselinetags.htm - -#define HB_OT_TAG_BASE_HANG HB_TAG('h','a','n','g') -#define HB_OT_TAG_BASE_ICFB HB_TAG('i','c','f','b') -#define HB_OT_TAG_BASE_ICFT HB_TAG('i','c','f','t') -#define HB_OT_TAG_BASE_IDEO HB_TAG('i','d','e','o') -#define HB_OT_TAG_BASE_IDTB HB_TAG('i','d','t','b') -#define HB_OT_TAG_BASE_MATH HB_TAG('m','a','t','h') -#define HB_OT_TAG_BASE_ROMN HB_TAG('r','o','m','n') +#include "hb-ot-base.h" namespace OT { @@ -743,7 +732,7 @@ struct BASE inline SHORT get_vert_min_value (unsigned int baseScriptIndex, unsigned int baseLangSysIndex, unsigned int featureTableTagIndex) const { return u.format1_0.get_vert_min_value(baseScriptIndex, baseLangSysIndex, featureTableTagIndex); } - inline bool sanitize (hb_sanitize_context_t *c, const void *base) const + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); if (!u.version.sanitize (c)) return_trace (false); From 3ebcd5a381e2de27a0cfb5af3359331f0b7e7108 Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Sun, 5 Mar 2017 16:26:01 +0100 Subject: [PATCH 12/12] first working version! --- src/hb-ot-layout.cc | 2 ++ src/hb-ot.h | 1 + 2 files changed, 3 insertions(+) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 3511810ac..d393f5ca6 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -57,6 +57,7 @@ _hb_ot_layout_create (hb_face_t *face) layout->gpos = OT::Sanitizer::lock_instance (layout->gpos_blob); layout->math.init (face); + layout->base.init (face); layout->fvar.init (face); layout->avar.init (face); @@ -185,6 +186,7 @@ _hb_ot_layout_destroy (hb_ot_layout_t *layout) hb_blob_destroy (layout->gpos_blob); layout->math.fini (); + layout->base.fini (); layout->fvar.fini (); layout->avar.fini (); diff --git a/src/hb-ot.h b/src/hb-ot.h index 2120a3efa..272208e38 100644 --- a/src/hb-ot.h +++ b/src/hb-ot.h @@ -33,6 +33,7 @@ #include "hb-ot-font.h" #include "hb-ot-layout.h" #include "hb-ot-math.h" +#include "hb-ot-base.h" #include "hb-ot-tag.h" #include "hb-ot-shape.h" #include "hb-ot-var.h"