Behdad Esfahbod | 6c48f20 | 2013-09-09 15:43:10 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013 Google, Inc. |
| 3 | * |
| 4 | * This is part of HarfBuzz, a text shaping library. |
| 5 | * |
| 6 | * Permission is hereby granted, without written agreement and without |
| 7 | * license or royalty fees, to use, copy, modify, and distribute this |
| 8 | * software and its documentation for any purpose, provided that the |
| 9 | * above copyright notice and the following two paragraphs appear in |
| 10 | * all copies of this software. |
| 11 | * |
| 12 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 13 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 14 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 15 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 16 | * DAMAGE. |
| 17 | * |
| 18 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 21 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 22 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 23 | * |
| 24 | * Google Author(s): Behdad Esfahbod |
| 25 | */ |
| 26 | |
| 27 | #ifndef HB_OT_LAYOUT_JSTF_TABLE_HH |
| 28 | #define HB_OT_LAYOUT_JSTF_TABLE_HH |
| 29 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 30 | #include "hb-open-type.hh" |
Behdad Esfahbod | 6c48f20 | 2013-09-09 15:43:10 -0400 | [diff] [blame] | 31 | #include "hb-ot-layout-gpos-table.hh" |
| 32 | |
| 33 | |
| 34 | namespace OT { |
| 35 | |
| 36 | |
| 37 | /* |
| 38 | * JstfModList -- Justification Modification List Tables |
| 39 | */ |
| 40 | |
| 41 | typedef IndexArray JstfModList; |
| 42 | |
| 43 | |
| 44 | /* |
| 45 | * JstfMax -- Justification Maximum Table |
| 46 | */ |
| 47 | |
| 48 | typedef OffsetListOf<PosLookup> JstfMax; |
| 49 | |
| 50 | |
| 51 | /* |
| 52 | * JstfPriority -- Justification Priority Table |
| 53 | */ |
| 54 | |
| 55 | struct JstfPriority |
| 56 | { |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 57 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 58 | { |
Behdad Esfahbod | 6c48f20 | 2013-09-09 15:43:10 -0400 | [diff] [blame] | 59 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 60 | return_trace (c->check_struct (this) && |
| 61 | shrinkageEnableGSUB.sanitize (c, this) && |
| 62 | shrinkageDisableGSUB.sanitize (c, this) && |
| 63 | shrinkageEnableGPOS.sanitize (c, this) && |
| 64 | shrinkageDisableGPOS.sanitize (c, this) && |
| 65 | shrinkageJstfMax.sanitize (c, this) && |
| 66 | extensionEnableGSUB.sanitize (c, this) && |
| 67 | extensionDisableGSUB.sanitize (c, this) && |
| 68 | extensionEnableGPOS.sanitize (c, this) && |
| 69 | extensionDisableGPOS.sanitize (c, this) && |
| 70 | extensionJstfMax.sanitize (c, this)); |
Behdad Esfahbod | 6c48f20 | 2013-09-09 15:43:10 -0400 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | protected: |
| 74 | OffsetTo<JstfModList> |
| 75 | shrinkageEnableGSUB; /* Offset to Shrinkage Enable GSUB |
| 76 | * JstfModList table--from beginning of |
| 77 | * JstfPriority table--may be NULL */ |
| 78 | OffsetTo<JstfModList> |
| 79 | shrinkageDisableGSUB; /* Offset to Shrinkage Disable GSUB |
| 80 | * JstfModList table--from beginning of |
| 81 | * JstfPriority table--may be NULL */ |
| 82 | OffsetTo<JstfModList> |
| 83 | shrinkageEnableGPOS; /* Offset to Shrinkage Enable GPOS |
| 84 | * JstfModList table--from beginning of |
| 85 | * JstfPriority table--may be NULL */ |
| 86 | OffsetTo<JstfModList> |
| 87 | shrinkageDisableGPOS; /* Offset to Shrinkage Disable GPOS |
| 88 | * JstfModList table--from beginning of |
| 89 | * JstfPriority table--may be NULL */ |
| 90 | OffsetTo<JstfMax> |
| 91 | shrinkageJstfMax; /* Offset to Shrinkage JstfMax table-- |
| 92 | * from beginning of JstfPriority table |
| 93 | * --may be NULL */ |
| 94 | OffsetTo<JstfModList> |
| 95 | extensionEnableGSUB; /* Offset to Extension Enable GSUB |
| 96 | * JstfModList table--from beginning of |
| 97 | * JstfPriority table--may be NULL */ |
| 98 | OffsetTo<JstfModList> |
| 99 | extensionDisableGSUB; /* Offset to Extension Disable GSUB |
| 100 | * JstfModList table--from beginning of |
| 101 | * JstfPriority table--may be NULL */ |
| 102 | OffsetTo<JstfModList> |
| 103 | extensionEnableGPOS; /* Offset to Extension Enable GPOS |
| 104 | * JstfModList table--from beginning of |
| 105 | * JstfPriority table--may be NULL */ |
| 106 | OffsetTo<JstfModList> |
| 107 | extensionDisableGPOS; /* Offset to Extension Disable GPOS |
| 108 | * JstfModList table--from beginning of |
| 109 | * JstfPriority table--may be NULL */ |
| 110 | OffsetTo<JstfMax> |
| 111 | extensionJstfMax; /* Offset to Extension JstfMax table-- |
| 112 | * from beginning of JstfPriority table |
| 113 | * --may be NULL */ |
| 114 | |
| 115 | public: |
| 116 | DEFINE_SIZE_STATIC (20); |
| 117 | }; |
| 118 | |
| 119 | |
| 120 | /* |
| 121 | * JstfLangSys -- Justification Language System Table |
| 122 | */ |
| 123 | |
| 124 | struct JstfLangSys : OffsetListOf<JstfPriority> |
| 125 | { |
| 126 | inline bool sanitize (hb_sanitize_context_t *c, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 127 | const Record<JstfLangSys>::sanitize_closure_t * = nullptr) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 128 | { |
Behdad Esfahbod | 6c48f20 | 2013-09-09 15:43:10 -0400 | [diff] [blame] | 129 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 130 | return_trace (OffsetListOf<JstfPriority>::sanitize (c)); |
Behdad Esfahbod | 6c48f20 | 2013-09-09 15:43:10 -0400 | [diff] [blame] | 131 | } |
| 132 | }; |
| 133 | |
| 134 | |
| 135 | /* |
| 136 | * ExtenderGlyphs -- Extender Glyph Table |
| 137 | */ |
| 138 | |
| 139 | typedef SortedArrayOf<GlyphID> ExtenderGlyphs; |
| 140 | |
| 141 | |
| 142 | /* |
| 143 | * JstfScript -- The Justification Table |
| 144 | */ |
| 145 | |
| 146 | struct JstfScript |
| 147 | { |
| 148 | inline unsigned int get_lang_sys_count (void) const |
| 149 | { return langSys.len; } |
| 150 | inline const Tag& get_lang_sys_tag (unsigned int i) const |
| 151 | { return langSys.get_tag (i); } |
| 152 | inline unsigned int get_lang_sys_tags (unsigned int start_offset, |
| 153 | unsigned int *lang_sys_count /* IN/OUT */, |
| 154 | hb_tag_t *lang_sys_tags /* OUT */) const |
| 155 | { return langSys.get_tags (start_offset, lang_sys_count, lang_sys_tags); } |
| 156 | inline const JstfLangSys& get_lang_sys (unsigned int i) const |
| 157 | { |
| 158 | if (i == Index::NOT_FOUND_INDEX) return get_default_lang_sys (); |
| 159 | return this+langSys[i].offset; |
| 160 | } |
| 161 | inline bool find_lang_sys_index (hb_tag_t tag, unsigned int *index) const |
| 162 | { return langSys.find_index (tag, index); } |
| 163 | |
| 164 | inline bool has_default_lang_sys (void) const { return defaultLangSys != 0; } |
| 165 | inline const JstfLangSys& get_default_lang_sys (void) const { return this+defaultLangSys; } |
| 166 | |
| 167 | inline bool sanitize (hb_sanitize_context_t *c, |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 168 | const Record<JstfScript>::sanitize_closure_t * = nullptr) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 169 | { |
Behdad Esfahbod | 6c48f20 | 2013-09-09 15:43:10 -0400 | [diff] [blame] | 170 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 171 | return_trace (extenderGlyphs.sanitize (c, this) && |
| 172 | defaultLangSys.sanitize (c, this) && |
| 173 | langSys.sanitize (c, this)); |
Behdad Esfahbod | 6c48f20 | 2013-09-09 15:43:10 -0400 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | protected: |
| 177 | OffsetTo<ExtenderGlyphs> |
| 178 | extenderGlyphs; /* Offset to ExtenderGlyph table--from beginning |
| 179 | * of JstfScript table-may be NULL */ |
| 180 | OffsetTo<JstfLangSys> |
| 181 | defaultLangSys; /* Offset to DefaultJstfLangSys table--from |
| 182 | * beginning of JstfScript table--may be Null */ |
| 183 | RecordArrayOf<JstfLangSys> |
| 184 | langSys; /* Array of JstfLangSysRecords--listed |
| 185 | * alphabetically by LangSysTag */ |
| 186 | public: |
| 187 | DEFINE_SIZE_ARRAY (6, langSys); |
| 188 | }; |
| 189 | |
| 190 | |
| 191 | /* |
Ebrahim Byagowi | a02c3ee | 2018-04-12 13:38:19 +0430 | [diff] [blame] | 192 | * JSTF -- Justification |
| 193 | * https://docs.microsoft.com/en-us/typography/opentype/spec/jstf |
Behdad Esfahbod | 6c48f20 | 2013-09-09 15:43:10 -0400 | [diff] [blame] | 194 | */ |
| 195 | |
| 196 | struct JSTF |
| 197 | { |
| 198 | static const hb_tag_t tableTag = HB_OT_TAG_JSTF; |
| 199 | |
| 200 | inline unsigned int get_script_count (void) const |
| 201 | { return scriptList.len; } |
| 202 | inline const Tag& get_script_tag (unsigned int i) const |
| 203 | { return scriptList.get_tag (i); } |
| 204 | inline unsigned int get_script_tags (unsigned int start_offset, |
| 205 | unsigned int *script_count /* IN/OUT */, |
| 206 | hb_tag_t *script_tags /* OUT */) const |
| 207 | { return scriptList.get_tags (start_offset, script_count, script_tags); } |
| 208 | inline const JstfScript& get_script (unsigned int i) const |
| 209 | { return this+scriptList[i].offset; } |
| 210 | inline bool find_script_index (hb_tag_t tag, unsigned int *index) const |
| 211 | { return scriptList.find_index (tag, index); } |
| 212 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 213 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 214 | { |
Behdad Esfahbod | 6c48f20 | 2013-09-09 15:43:10 -0400 | [diff] [blame] | 215 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 216 | return_trace (version.sanitize (c) && |
| 217 | likely (version.major == 1) && |
| 218 | scriptList.sanitize (c, this)); |
Behdad Esfahbod | 6c48f20 | 2013-09-09 15:43:10 -0400 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | protected: |
Behdad Esfahbod | 9a13ed4 | 2016-02-22 11:44:45 +0900 | [diff] [blame] | 222 | FixedVersion<>version; /* Version of the JSTF table--initially set |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 223 | * to 0x00010000u */ |
Behdad Esfahbod | 6c48f20 | 2013-09-09 15:43:10 -0400 | [diff] [blame] | 224 | RecordArrayOf<JstfScript> |
| 225 | scriptList; /* Array of JstfScripts--listed |
| 226 | * alphabetically by ScriptTag */ |
| 227 | public: |
| 228 | DEFINE_SIZE_ARRAY (6, scriptList); |
| 229 | }; |
| 230 | |
| 231 | |
| 232 | } /* namespace OT */ |
| 233 | |
| 234 | |
| 235 | #endif /* HB_OT_LAYOUT_JSTF_TABLE_HH */ |