1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * by Oracle in the LICENSE file that accompanied this code.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 // This file is available under and governed by the GNU General Public
  26 // License version 2 only, as published by the Free Software Foundation.
  27 // However, the following notice accompanied the original version of this
  28 // file:
  29 //
  30 /*
  31  * Copyright © 2013  Google, Inc.
  32  *
  33  *  This is part of HarfBuzz, a text shaping library.
  34  *
  35  * Permission is hereby granted, without written agreement and without
  36  * license or royalty fees, to use, copy, modify, and distribute this
  37  * software and its documentation for any purpose, provided that the
  38  * above copyright notice and the following two paragraphs appear in
  39  * all copies of this software.
  40  *
  41  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
  42  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  43  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
  44  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
  45  * DAMAGE.
  46  *
  47  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
  48  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  49  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  50  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
  51  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  52  *
  53  * Google Author(s): Behdad Esfahbod
  54  */
  55 
  56 #ifndef HB_OT_LAYOUT_JSTF_TABLE_HH
  57 #define HB_OT_LAYOUT_JSTF_TABLE_HH
  58 
  59 #include "hb-open-type-private.hh"
  60 #include "hb-ot-layout-gpos-table.hh"
  61 
  62 
  63 namespace OT {
  64 
  65 
  66 /*
  67  * JstfModList -- Justification Modification List Tables
  68  */
  69 
  70 typedef IndexArray JstfModList;
  71 
  72 
  73 /*
  74  * JstfMax -- Justification Maximum Table
  75  */
  76 
  77 typedef OffsetListOf<PosLookup> JstfMax;
  78 
  79 
  80 /*
  81  * JstfPriority -- Justification Priority Table
  82  */
  83 
  84 struct JstfPriority
  85 {
  86   inline bool sanitize (hb_sanitize_context_t *c) const
  87   {
  88     TRACE_SANITIZE (this);
  89     return_trace (c->check_struct (this) &&
  90                   shrinkageEnableGSUB.sanitize (c, this) &&
  91                   shrinkageDisableGSUB.sanitize (c, this) &&
  92                   shrinkageEnableGPOS.sanitize (c, this) &&
  93                   shrinkageDisableGPOS.sanitize (c, this) &&
  94                   shrinkageJstfMax.sanitize (c, this) &&
  95                   extensionEnableGSUB.sanitize (c, this) &&
  96                   extensionDisableGSUB.sanitize (c, this) &&
  97                   extensionEnableGPOS.sanitize (c, this) &&
  98                   extensionDisableGPOS.sanitize (c, this) &&
  99                   extensionJstfMax.sanitize (c, this));
 100   }
 101 
 102   protected:
 103   OffsetTo<JstfModList>
 104                 shrinkageEnableGSUB;    /* Offset to Shrinkage Enable GSUB
 105                                          * JstfModList table--from beginning of
 106                                          * JstfPriority table--may be NULL */
 107   OffsetTo<JstfModList>
 108                 shrinkageDisableGSUB;   /* Offset to Shrinkage Disable GSUB
 109                                          * JstfModList table--from beginning of
 110                                          * JstfPriority table--may be NULL */
 111   OffsetTo<JstfModList>
 112                 shrinkageEnableGPOS;    /* Offset to Shrinkage Enable GPOS
 113                                          * JstfModList table--from beginning of
 114                                          * JstfPriority table--may be NULL */
 115   OffsetTo<JstfModList>
 116                 shrinkageDisableGPOS;   /* Offset to Shrinkage Disable GPOS
 117                                          * JstfModList table--from beginning of
 118                                          * JstfPriority table--may be NULL */
 119   OffsetTo<JstfMax>
 120                 shrinkageJstfMax;       /* Offset to Shrinkage JstfMax table--
 121                                          * from beginning of JstfPriority table
 122                                          * --may be NULL */
 123   OffsetTo<JstfModList>
 124                 extensionEnableGSUB;    /* Offset to Extension Enable GSUB
 125                                          * JstfModList table--from beginning of
 126                                          * JstfPriority table--may be NULL */
 127   OffsetTo<JstfModList>
 128                 extensionDisableGSUB;   /* Offset to Extension Disable GSUB
 129                                          * JstfModList table--from beginning of
 130                                          * JstfPriority table--may be NULL */
 131   OffsetTo<JstfModList>
 132                 extensionEnableGPOS;    /* Offset to Extension Enable GPOS
 133                                          * JstfModList table--from beginning of
 134                                          * JstfPriority table--may be NULL */
 135   OffsetTo<JstfModList>
 136                 extensionDisableGPOS;   /* Offset to Extension Disable GPOS
 137                                          * JstfModList table--from beginning of
 138                                          * JstfPriority table--may be NULL */
 139   OffsetTo<JstfMax>
 140                 extensionJstfMax;       /* Offset to Extension JstfMax table--
 141                                          * from beginning of JstfPriority table
 142                                          * --may be NULL */
 143 
 144   public:
 145   DEFINE_SIZE_STATIC (20);
 146 };
 147 
 148 
 149 /*
 150  * JstfLangSys -- Justification Language System Table
 151  */
 152 
 153 struct JstfLangSys : OffsetListOf<JstfPriority>
 154 {
 155   inline bool sanitize (hb_sanitize_context_t *c,
 156                         const Record<JstfLangSys>::sanitize_closure_t * = NULL) const
 157   {
 158     TRACE_SANITIZE (this);
 159     return_trace (OffsetListOf<JstfPriority>::sanitize (c));
 160   }
 161 };
 162 
 163 
 164 /*
 165  * ExtenderGlyphs -- Extender Glyph Table
 166  */
 167 
 168 typedef SortedArrayOf<GlyphID> ExtenderGlyphs;
 169 
 170 
 171 /*
 172  * JstfScript -- The Justification Table
 173  */
 174 
 175 struct JstfScript
 176 {
 177   inline unsigned int get_lang_sys_count (void) const
 178   { return langSys.len; }
 179   inline const Tag& get_lang_sys_tag (unsigned int i) const
 180   { return langSys.get_tag (i); }
 181   inline unsigned int get_lang_sys_tags (unsigned int start_offset,
 182                                          unsigned int *lang_sys_count /* IN/OUT */,
 183                                          hb_tag_t     *lang_sys_tags /* OUT */) const
 184   { return langSys.get_tags (start_offset, lang_sys_count, lang_sys_tags); }
 185   inline const JstfLangSys& get_lang_sys (unsigned int i) const
 186   {
 187     if (i == Index::NOT_FOUND_INDEX) return get_default_lang_sys ();
 188     return this+langSys[i].offset;
 189   }
 190   inline bool find_lang_sys_index (hb_tag_t tag, unsigned int *index) const
 191   { return langSys.find_index (tag, index); }
 192 
 193   inline bool has_default_lang_sys (void) const { return defaultLangSys != 0; }
 194   inline const JstfLangSys& get_default_lang_sys (void) const { return this+defaultLangSys; }
 195 
 196   inline bool sanitize (hb_sanitize_context_t *c,
 197                         const Record<JstfScript>::sanitize_closure_t * = NULL) const
 198   {
 199     TRACE_SANITIZE (this);
 200     return_trace (extenderGlyphs.sanitize (c, this) &&
 201                   defaultLangSys.sanitize (c, this) &&
 202                   langSys.sanitize (c, this));
 203   }
 204 
 205   protected:
 206   OffsetTo<ExtenderGlyphs>
 207                 extenderGlyphs; /* Offset to ExtenderGlyph table--from beginning
 208                                  * of JstfScript table-may be NULL */
 209   OffsetTo<JstfLangSys>
 210                 defaultLangSys; /* Offset to DefaultJstfLangSys table--from
 211                                  * beginning of JstfScript table--may be Null */
 212   RecordArrayOf<JstfLangSys>
 213                 langSys;        /* Array of JstfLangSysRecords--listed
 214                                  * alphabetically by LangSysTag */
 215   public:
 216   DEFINE_SIZE_ARRAY (6, langSys);
 217 };
 218 
 219 
 220 /*
 221  * JSTF -- The Justification Table
 222  */
 223 
 224 struct JSTF
 225 {
 226   static const hb_tag_t tableTag        = HB_OT_TAG_JSTF;
 227 
 228   inline unsigned int get_script_count (void) const
 229   { return scriptList.len; }
 230   inline const Tag& get_script_tag (unsigned int i) const
 231   { return scriptList.get_tag (i); }
 232   inline unsigned int get_script_tags (unsigned int start_offset,
 233                                        unsigned int *script_count /* IN/OUT */,
 234                                        hb_tag_t     *script_tags /* OUT */) const
 235   { return scriptList.get_tags (start_offset, script_count, script_tags); }
 236   inline const JstfScript& get_script (unsigned int i) const
 237   { return this+scriptList[i].offset; }
 238   inline bool find_script_index (hb_tag_t tag, unsigned int *index) const
 239   { return scriptList.find_index (tag, index); }
 240 
 241   inline bool sanitize (hb_sanitize_context_t *c) const
 242   {
 243     TRACE_SANITIZE (this);
 244     return_trace (version.sanitize (c) &&
 245                   likely (version.major == 1) &&
 246                   scriptList.sanitize (c, this));
 247   }
 248 
 249   protected:
 250   FixedVersion  version;        /* Version of the JSTF table--initially set
 251                                  * to 0x00010000u */
 252   RecordArrayOf<JstfScript>
 253                 scriptList;     /* Array of JstfScripts--listed
 254                                  * alphabetically by ScriptTag */
 255   public:
 256   DEFINE_SIZE_ARRAY (6, scriptList);
 257 };
 258 
 259 
 260 } /* namespace OT */
 261 
 262 
 263 #endif /* HB_OT_LAYOUT_JSTF_TABLE_HH */