67a6df5b421672ffd64ae899afcd1901a5f73aca
[platform/upstream/harfbuzz.git] / src / hb-ot-layout-jstf-table.hh
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
30 #include "hb-open-type-private.hh"
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 {
57   inline bool sanitize (hb_sanitize_context_t *c) {
58     TRACE_SANITIZE (this);
59     return TRACE_RETURN (c->check_struct (this) &&
60                          shrinkageEnableGSUB.sanitize (c, this) &&
61                          shrinkageDisableGSUB.sanitize (c, this) &&
62                          shrinkageEnableGPOS.sanitize (c, this) &&
63                          shrinkageDisableGPOS.sanitize (c, this) &&
64                          shrinkageJstfMax.sanitize (c, this) &&
65                          extensionEnableGSUB.sanitize (c, this) &&
66                          extensionDisableGSUB.sanitize (c, this) &&
67                          extensionEnableGPOS.sanitize (c, this) &&
68                          extensionDisableGPOS.sanitize (c, this) &&
69                          extensionJstfMax.sanitize (c, this));
70   }
71
72   protected:
73   OffsetTo<JstfModList>
74                 shrinkageEnableGSUB;    /* Offset to Shrinkage Enable GSUB
75                                          * JstfModList table--from beginning of
76                                          * JstfPriority table--may be NULL */
77   OffsetTo<JstfModList>
78                 shrinkageDisableGSUB;   /* Offset to Shrinkage Disable GSUB
79                                          * JstfModList table--from beginning of
80                                          * JstfPriority table--may be NULL */
81   OffsetTo<JstfModList>
82                 shrinkageEnableGPOS;    /* Offset to Shrinkage Enable GPOS
83                                          * JstfModList table--from beginning of
84                                          * JstfPriority table--may be NULL */
85   OffsetTo<JstfModList>
86                 shrinkageDisableGPOS;   /* Offset to Shrinkage Disable GPOS
87                                          * JstfModList table--from beginning of
88                                          * JstfPriority table--may be NULL */
89   OffsetTo<JstfMax>
90                 shrinkageJstfMax;       /* Offset to Shrinkage JstfMax table--
91                                          * from beginning of JstfPriority table
92                                          * --may be NULL */
93   OffsetTo<JstfModList>
94                 extensionEnableGSUB;    /* Offset to Extension Enable GSUB
95                                          * JstfModList table--from beginning of
96                                          * JstfPriority table--may be NULL */
97   OffsetTo<JstfModList>
98                 extensionDisableGSUB;   /* Offset to Extension Disable GSUB
99                                          * JstfModList table--from beginning of
100                                          * JstfPriority table--may be NULL */
101   OffsetTo<JstfModList>
102                 extensionEnableGPOS;    /* Offset to Extension Enable GPOS
103                                          * JstfModList table--from beginning of
104                                          * JstfPriority table--may be NULL */
105   OffsetTo<JstfModList>
106                 extensionDisableGPOS;   /* Offset to Extension Disable GPOS
107                                          * JstfModList table--from beginning of
108                                          * JstfPriority table--may be NULL */
109   OffsetTo<JstfMax>
110                 extensionJstfMax;       /* Offset to Extension JstfMax table--
111                                          * from beginning of JstfPriority table
112                                          * --may be NULL */
113
114   public:
115   DEFINE_SIZE_STATIC (20);
116 };
117
118
119 /*
120  * JstfLangSys -- Justification Language System Table
121  */
122
123 struct JstfLangSys : OffsetListOf<JstfPriority>
124 {
125   inline bool sanitize (hb_sanitize_context_t *c,
126                         const Record<JstfLangSys>::sanitize_closure_t * = NULL) {
127     TRACE_SANITIZE (this);
128     return TRACE_RETURN (OffsetListOf<JstfPriority>::sanitize (c));
129   }
130 };
131
132
133 /*
134  * ExtenderGlyphs -- Extender Glyph Table
135  */
136
137 typedef SortedArrayOf<GlyphID> ExtenderGlyphs;
138
139
140 /*
141  * JstfScript -- The Justification Table
142  */
143
144 struct JstfScript
145 {
146   inline unsigned int get_lang_sys_count (void) const
147   { return langSys.len; }
148   inline const Tag& get_lang_sys_tag (unsigned int i) const
149   { return langSys.get_tag (i); }
150   inline unsigned int get_lang_sys_tags (unsigned int start_offset,
151                                          unsigned int *lang_sys_count /* IN/OUT */,
152                                          hb_tag_t     *lang_sys_tags /* OUT */) const
153   { return langSys.get_tags (start_offset, lang_sys_count, lang_sys_tags); }
154   inline const JstfLangSys& get_lang_sys (unsigned int i) const
155   {
156     if (i == Index::NOT_FOUND_INDEX) return get_default_lang_sys ();
157     return this+langSys[i].offset;
158   }
159   inline bool find_lang_sys_index (hb_tag_t tag, unsigned int *index) const
160   { return langSys.find_index (tag, index); }
161
162   inline bool has_default_lang_sys (void) const { return defaultLangSys != 0; }
163   inline const JstfLangSys& get_default_lang_sys (void) const { return this+defaultLangSys; }
164
165   inline bool sanitize (hb_sanitize_context_t *c,
166                         const Record<JstfScript>::sanitize_closure_t * = NULL) {
167     TRACE_SANITIZE (this);
168     return TRACE_RETURN (extenderGlyphs.sanitize (c, this) &&
169                          defaultLangSys.sanitize (c, this) &&
170                          langSys.sanitize (c, this));
171   }
172
173   protected:
174   OffsetTo<ExtenderGlyphs>
175                 extenderGlyphs; /* Offset to ExtenderGlyph table--from beginning
176                                  * of JstfScript table-may be NULL */
177   OffsetTo<JstfLangSys>
178                 defaultLangSys; /* Offset to DefaultJstfLangSys table--from
179                                  * beginning of JstfScript table--may be Null */
180   RecordArrayOf<JstfLangSys>
181                 langSys;        /* Array of JstfLangSysRecords--listed
182                                  * alphabetically by LangSysTag */
183   public:
184   DEFINE_SIZE_ARRAY (6, langSys);
185 };
186
187
188 /*
189  * JSTF -- The Justification Table
190  */
191
192 struct JSTF
193 {
194   static const hb_tag_t tableTag        = HB_OT_TAG_JSTF;
195
196   inline unsigned int get_script_count (void) const
197   { return scriptList.len; }
198   inline const Tag& get_script_tag (unsigned int i) const
199   { return scriptList.get_tag (i); }
200   inline unsigned int get_script_tags (unsigned int start_offset,
201                                        unsigned int *script_count /* IN/OUT */,
202                                        hb_tag_t     *script_tags /* OUT */) const
203   { return scriptList.get_tags (start_offset, script_count, script_tags); }
204   inline const JstfScript& get_script (unsigned int i) const
205   { return this+scriptList[i].offset; }
206   inline bool find_script_index (hb_tag_t tag, unsigned int *index) const
207   { return scriptList.find_index (tag, index); }
208
209   inline bool sanitize (hb_sanitize_context_t *c) {
210     TRACE_SANITIZE (this);
211     return TRACE_RETURN (version.sanitize (c) && likely (version.major == 1) &&
212                          scriptList.sanitize (c, this));
213   }
214
215   protected:
216   FixedVersion  version;        /* Version of the JSTF table--initially set
217                                  * to 0x00010000u */
218   RecordArrayOf<JstfScript>
219                 scriptList;     /* Array of JstfScripts--listed
220                                  * alphabetically by ScriptTag */
221   public:
222   DEFINE_SIZE_ARRAY (6, scriptList);
223 };
224
225
226 } /* namespace OT */
227
228
229 #endif /* HB_OT_LAYOUT_JSTF_TABLE_HH */