1 /* 2 * Copyright (C) 1998-2004 David Turner and Werner Lemberg 3 * Copyright (C) 2006 Behdad Esfahbod 4 * 5 * This is part of HarfBuzz, an OpenType Layout engine library. 6 * 7 * Permission is hereby granted, without written agreement and without 8 * license or royalty fees, to use, copy, modify, and distribute this 9 * software and its documentation for any purpose, provided that the 10 * above copyright notice and the following two paragraphs appear in 11 * all copies of this software. 12 * 13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 17 * DAMAGE. 18 * 19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 24 */ 25 26 #ifndef HARFBUZZ_GSUB_PRIVATE_H 27 #define HARFBUZZ_GSUB_PRIVATE_H 28 29 #include "harfbuzz-impl.h" 30 #include "harfbuzz-stream-private.h" 31 #include "harfbuzz-gsub.h" 32 33 HB_BEGIN_HEADER 34 35 36 typedef union HB_GSUB_SubTable_ HB_GSUB_SubTable; 37 38 /* LookupType 1 */ 39 40 struct HB_SingleSubstFormat1_ 41 { 42 HB_Short DeltaGlyphID; /* constant added to get 43 substitution glyph index */ 44 }; 45 46 typedef struct HB_SingleSubstFormat1_ HB_SingleSubstFormat1; 47 48 49 struct HB_SingleSubstFormat2_ 50 { 51 HB_UShort GlyphCount; /* number of glyph IDs in 52 Substitute array */ 53 HB_UShort* Substitute; /* array of substitute glyph IDs */ 54 }; 55 56 typedef struct HB_SingleSubstFormat2_ HB_SingleSubstFormat2; 57 58 59 struct HB_SingleSubst_ 60 { 61 HB_UShort SubstFormat; /* 1 or 2 */ 62 HB_Coverage Coverage; /* Coverage table */ 63 64 union 65 { 66 HB_SingleSubstFormat1 ssf1; 67 HB_SingleSubstFormat2 ssf2; 68 } ssf; 69 }; 70 71 typedef struct HB_SingleSubst_ HB_SingleSubst; 72 73 74 /* LookupType 2 */ 75 76 struct HB_Sequence_ 77 { 78 HB_UShort GlyphCount; /* number of glyph IDs in the 79 Substitute array */ 80 HB_UShort* Substitute; /* string of glyph IDs to 81 substitute */ 82 }; 83 84 typedef struct HB_Sequence_ HB_Sequence; 85 86 87 struct HB_MultipleSubst_ 88 { 89 HB_UShort SubstFormat; /* always 1 */ 90 HB_Coverage Coverage; /* Coverage table */ 91 HB_UShort SequenceCount; /* number of Sequence tables */ 92 HB_Sequence* Sequence; /* array of Sequence tables */ 93 }; 94 95 typedef struct HB_MultipleSubst_ HB_MultipleSubst; 96 97 98 /* LookupType 3 */ 99 100 struct HB_AlternateSet_ 101 { 102 HB_UShort GlyphCount; /* number of glyph IDs in the 103 Alternate array */ 104 HB_UShort* Alternate; /* array of alternate glyph IDs */ 105 }; 106 107 typedef struct HB_AlternateSet_ HB_AlternateSet; 108 109 110 struct HB_AlternateSubst_ 111 { 112 HB_UShort SubstFormat; /* always 1 */ 113 HB_Coverage Coverage; /* Coverage table */ 114 HB_UShort AlternateSetCount; 115 /* number of AlternateSet tables */ 116 HB_AlternateSet* AlternateSet; /* array of AlternateSet tables */ 117 }; 118 119 typedef struct HB_AlternateSubst_ HB_AlternateSubst; 120 121 122 /* LookupType 4 */ 123 124 struct HB_Ligature_ 125 { 126 HB_UShort LigGlyph; /* glyphID of ligature 127 to substitute */ 128 HB_UShort ComponentCount; /* number of components in ligature */ 129 HB_UShort* Component; /* array of component glyph IDs */ 130 }; 131 132 typedef struct HB_Ligature_ HB_Ligature; 133 134 135 struct HB_LigatureSet_ 136 { 137 HB_UShort LigatureCount; /* number of Ligature tables */ 138 HB_Ligature* Ligature; /* array of Ligature tables */ 139 }; 140 141 typedef struct HB_LigatureSet_ HB_LigatureSet; 142 143 144 struct HB_LigatureSubst_ 145 { 146 HB_UShort SubstFormat; /* always 1 */ 147 HB_Coverage Coverage; /* Coverage table */ 148 HB_UShort LigatureSetCount; /* number of LigatureSet tables */ 149 HB_LigatureSet* LigatureSet; /* array of LigatureSet tables */ 150 }; 151 152 typedef struct HB_LigatureSubst_ HB_LigatureSubst; 153 154 155 /* needed by both lookup type 5 and 6 */ 156 157 struct HB_SubstLookupRecord_ 158 { 159 HB_UShort SequenceIndex; /* index into current 160 glyph sequence */ 161 HB_UShort LookupListIndex; /* Lookup to apply to that pos. */ 162 }; 163 164 typedef struct HB_SubstLookupRecord_ HB_SubstLookupRecord; 165 166 167 /* LookupType 5 */ 168 169 struct HB_SubRule_ 170 { 171 HB_UShort GlyphCount; /* total number of input glyphs */ 172 HB_UShort SubstCount; /* number of SubstLookupRecord 173 tables */ 174 HB_UShort* Input; /* array of input glyph IDs */ 175 HB_SubstLookupRecord* SubstLookupRecord; 176 /* array of SubstLookupRecord 177 tables */ 178 }; 179 180 typedef struct HB_SubRule_ HB_SubRule; 181 182 183 struct HB_SubRuleSet_ 184 { 185 HB_UShort SubRuleCount; /* number of SubRule tables */ 186 HB_SubRule* SubRule; /* array of SubRule tables */ 187 }; 188 189 typedef struct HB_SubRuleSet_ HB_SubRuleSet; 190 191 192 struct HB_ContextSubstFormat1_ 193 { 194 HB_Coverage Coverage; /* Coverage table */ 195 HB_UShort SubRuleSetCount; /* number of SubRuleSet tables */ 196 HB_SubRuleSet* SubRuleSet; /* array of SubRuleSet tables */ 197 }; 198 199 typedef struct HB_ContextSubstFormat1_ HB_ContextSubstFormat1; 200 201 202 struct HB_SubClassRule_ 203 { 204 HB_UShort GlyphCount; /* total number of context classes */ 205 HB_UShort SubstCount; /* number of SubstLookupRecord 206 tables */ 207 HB_UShort* Class; /* array of classes */ 208 HB_SubstLookupRecord* SubstLookupRecord; 209 /* array of SubstLookupRecord 210 tables */ 211 }; 212 213 typedef struct HB_SubClassRule_ HB_SubClassRule; 214 215 216 struct HB_SubClassSet_ 217 { 218 HB_UShort SubClassRuleCount; 219 /* number of SubClassRule tables */ 220 HB_SubClassRule* SubClassRule; /* array of SubClassRule tables */ 221 }; 222 223 typedef struct HB_SubClassSet_ HB_SubClassSet; 224 225 226 /* The `MaxContextLength' field is not defined in the TTO specification 227 but simplifies the implementation of this format. It holds the 228 maximal context length used in the context rules. */ 229 230 struct HB_ContextSubstFormat2_ 231 { 232 HB_UShort MaxContextLength; 233 /* maximal context length */ 234 HB_Coverage Coverage; /* Coverage table */ 235 HB_ClassDefinition ClassDef; /* ClassDef table */ 236 HB_UShort SubClassSetCount; 237 /* number of SubClassSet tables */ 238 HB_SubClassSet* SubClassSet; /* array of SubClassSet tables */ 239 }; 240 241 typedef struct HB_ContextSubstFormat2_ HB_ContextSubstFormat2; 242 243 244 struct HB_ContextSubstFormat3_ 245 { 246 HB_UShort GlyphCount; /* number of input glyphs */ 247 HB_UShort SubstCount; /* number of SubstLookupRecords */ 248 HB_Coverage* Coverage; /* array of Coverage tables */ 249 HB_SubstLookupRecord* SubstLookupRecord; 250 /* array of substitution lookups */ 251 }; 252 253 typedef struct HB_ContextSubstFormat3_ HB_ContextSubstFormat3; 254 255 256 struct HB_ContextSubst_ 257 { 258 HB_UShort SubstFormat; /* 1, 2, or 3 */ 259 260 union 261 { 262 HB_ContextSubstFormat1 csf1; 263 HB_ContextSubstFormat2 csf2; 264 HB_ContextSubstFormat3 csf3; 265 } csf; 266 }; 267 268 typedef struct HB_ContextSubst_ HB_ContextSubst; 269 270 271 /* LookupType 6 */ 272 273 struct HB_ChainSubRule_ 274 { 275 HB_UShort BacktrackGlyphCount; 276 /* total number of backtrack glyphs */ 277 HB_UShort* Backtrack; /* array of backtrack glyph IDs */ 278 HB_UShort InputGlyphCount; 279 /* total number of input glyphs */ 280 HB_UShort* Input; /* array of input glyph IDs */ 281 HB_UShort LookaheadGlyphCount; 282 /* total number of lookahead glyphs */ 283 HB_UShort* Lookahead; /* array of lookahead glyph IDs */ 284 HB_UShort SubstCount; /* number of SubstLookupRecords */ 285 HB_SubstLookupRecord* SubstLookupRecord; 286 /* array of SubstLookupRecords */ 287 }; 288 289 typedef struct HB_ChainSubRule_ HB_ChainSubRule; 290 291 292 struct HB_ChainSubRuleSet_ 293 { 294 HB_UShort ChainSubRuleCount; 295 /* number of ChainSubRule tables */ 296 HB_ChainSubRule* ChainSubRule; /* array of ChainSubRule tables */ 297 }; 298 299 typedef struct HB_ChainSubRuleSet_ HB_ChainSubRuleSet; 300 301 302 struct HB_ChainContextSubstFormat1_ 303 { 304 HB_Coverage Coverage; /* Coverage table */ 305 HB_UShort ChainSubRuleSetCount; 306 /* number of ChainSubRuleSet tables */ 307 HB_ChainSubRuleSet* ChainSubRuleSet; 308 /* array of ChainSubRuleSet tables */ 309 }; 310 311 typedef struct HB_ChainContextSubstFormat1_ HB_ChainContextSubstFormat1; 312 313 314 struct HB_ChainSubClassRule_ 315 { 316 HB_UShort BacktrackGlyphCount; 317 /* total number of backtrack 318 classes */ 319 HB_UShort* Backtrack; /* array of backtrack classes */ 320 HB_UShort InputGlyphCount; 321 /* total number of context classes */ 322 HB_UShort* Input; /* array of context classes */ 323 HB_UShort LookaheadGlyphCount; 324 /* total number of lookahead 325 classes */ 326 HB_UShort* Lookahead; /* array of lookahead classes */ 327 HB_UShort SubstCount; /* number of SubstLookupRecords */ 328 HB_SubstLookupRecord* SubstLookupRecord; 329 /* array of substitution lookups */ 330 }; 331 332 typedef struct HB_ChainSubClassRule_ HB_ChainSubClassRule; 333 334 335 struct HB_ChainSubClassSet_ 336 { 337 HB_UShort ChainSubClassRuleCount; 338 /* number of ChainSubClassRule 339 tables */ 340 HB_ChainSubClassRule* ChainSubClassRule; 341 /* array of ChainSubClassRule 342 tables */ 343 }; 344 345 typedef struct HB_ChainSubClassSet_ HB_ChainSubClassSet; 346 347 348 /* The `MaxXXXLength' fields are not defined in the TTO specification 349 but simplifies the implementation of this format. It holds the 350 maximal context length used in the specific context rules. */ 351 352 struct HB_ChainContextSubstFormat2_ 353 { 354 HB_Coverage Coverage; /* Coverage table */ 355 356 HB_UShort MaxBacktrackLength; 357 /* maximal backtrack length */ 358 HB_ClassDefinition BacktrackClassDef; 359 /* BacktrackClassDef table */ 360 HB_UShort MaxInputLength; 361 /* maximal input length */ 362 HB_ClassDefinition InputClassDef; 363 /* InputClassDef table */ 364 HB_UShort MaxLookaheadLength; 365 /* maximal lookahead length */ 366 HB_ClassDefinition LookaheadClassDef; 367 /* LookaheadClassDef table */ 368 369 HB_UShort ChainSubClassSetCount; 370 /* number of ChainSubClassSet 371 tables */ 372 HB_ChainSubClassSet* ChainSubClassSet; 373 /* array of ChainSubClassSet 374 tables */ 375 }; 376 377 typedef struct HB_ChainContextSubstFormat2_ HB_ChainContextSubstFormat2; 378 379 380 struct HB_ChainContextSubstFormat3_ 381 { 382 HB_UShort BacktrackGlyphCount; 383 /* number of backtrack glyphs */ 384 HB_Coverage* BacktrackCoverage; 385 /* array of backtrack Coverage 386 tables */ 387 HB_UShort InputGlyphCount; 388 /* number of input glyphs */ 389 HB_Coverage* InputCoverage; 390 /* array of input coverage 391 tables */ 392 HB_UShort LookaheadGlyphCount; 393 /* number of lookahead glyphs */ 394 HB_Coverage* LookaheadCoverage; 395 /* array of lookahead coverage 396 tables */ 397 HB_UShort SubstCount; /* number of SubstLookupRecords */ 398 HB_SubstLookupRecord* SubstLookupRecord; 399 /* array of substitution lookups */ 400 }; 401 402 typedef struct HB_ChainContextSubstFormat3_ HB_ChainContextSubstFormat3; 403 404 405 struct HB_ChainContextSubst_ 406 { 407 HB_UShort SubstFormat; /* 1, 2, or 3 */ 408 409 union 410 { 411 HB_ChainContextSubstFormat1 ccsf1; 412 HB_ChainContextSubstFormat2 ccsf2; 413 HB_ChainContextSubstFormat3 ccsf3; 414 } ccsf; 415 }; 416 417 typedef struct HB_ChainContextSubst_ HB_ChainContextSubst; 418 419 420 #if 0 421 /* LookupType 7 */ 422 struct HB_ExtensionSubst_ 423 { 424 HB_UShort SubstFormat; /* always 1 */ 425 HB_UShort LookuptType; /* lookup-type of referenced subtable */ 426 HB_GSUB_SubTable *subtable; /* referenced subtable */ 427 }; 428 429 typedef struct HB_ExtensionSubst_ HB_ExtensionSubst; 430 #endif 431 432 433 /* LookupType 8 */ 434 struct HB_ReverseChainContextSubst_ 435 { 436 HB_UShort SubstFormat; /* always 1 */ 437 HB_Coverage Coverage; /* coverage table for input glyphs */ 438 HB_UShort BacktrackGlyphCount; /* number of backtrack glyphs */ 439 HB_Coverage* BacktrackCoverage; /* array of backtrack Coverage 440 tables */ 441 HB_UShort LookaheadGlyphCount; /* number of lookahead glyphs */ 442 HB_Coverage* LookaheadCoverage; /* array of lookahead Coverage 443 tables */ 444 HB_UShort GlyphCount; /* number of Glyph IDs */ 445 HB_UShort* Substitute; /* array of substitute Glyph ID */ 446 }; 447 448 typedef struct HB_ReverseChainContextSubst_ HB_ReverseChainContextSubst; 449 450 451 union HB_GSUB_SubTable_ 452 { 453 HB_SingleSubst single; 454 HB_MultipleSubst multiple; 455 HB_AlternateSubst alternate; 456 HB_LigatureSubst ligature; 457 HB_ContextSubst context; 458 HB_ChainContextSubst chain; 459 HB_ReverseChainContextSubst reverse; 460 }; 461 462 463 464 465 HB_INTERNAL HB_Error 466 _HB_GSUB_Load_SubTable( HB_GSUB_SubTable* st, 467 HB_Stream stream, 468 HB_UShort lookup_type ); 469 470 HB_INTERNAL void 471 _HB_GSUB_Free_SubTable( HB_GSUB_SubTable* st, 472 HB_UShort lookup_type ); 473 474 HB_END_HEADER 475 476 #endif /* HARFBUZZ_GSUB_PRIVATE_H */ 477