1 /**************************************************************************** 2 * 3 * wofftypes.h 4 * 5 * Basic WOFF/WOFF2 type definitions and interface (specification 6 * only). 7 * 8 * Copyright (C) 1996-2020 by 9 * David Turner, Robert Wilhelm, and Werner Lemberg. 10 * 11 * This file is part of the FreeType project, and may only be used, 12 * modified, and distributed under the terms of the FreeType project 13 * license, LICENSE.TXT. By continuing to use, modify, or distribute 14 * this file you indicate that you have read the license and 15 * understand and accept it fully. 16 * 17 */ 18 19 20 #ifndef WOFFTYPES_H_ 21 #define WOFFTYPES_H_ 22 23 24 #include <freetype/tttables.h> 25 #include <freetype/internal/ftobjs.h> 26 27 28 FT_BEGIN_HEADER 29 30 31 /************************************************************************** 32 * 33 * @struct: 34 * WOFF_HeaderRec 35 * 36 * @description: 37 * WOFF file format header. 38 * 39 * @fields: 40 * See 41 * 42 * https://www.w3.org/TR/WOFF/#WOFFHeader 43 */ 44 typedef struct WOFF_HeaderRec_ 45 { 46 FT_ULong signature; 47 FT_ULong flavor; 48 FT_ULong length; 49 FT_UShort num_tables; 50 FT_UShort reserved; 51 FT_ULong totalSfntSize; 52 FT_UShort majorVersion; 53 FT_UShort minorVersion; 54 FT_ULong metaOffset; 55 FT_ULong metaLength; 56 FT_ULong metaOrigLength; 57 FT_ULong privOffset; 58 FT_ULong privLength; 59 60 } WOFF_HeaderRec, *WOFF_Header; 61 62 63 /************************************************************************** 64 * 65 * @struct: 66 * WOFF_TableRec 67 * 68 * @description: 69 * This structure describes a given table of a WOFF font. 70 * 71 * @fields: 72 * Tag :: 73 * A four-bytes tag describing the table. 74 * 75 * Offset :: 76 * The offset of the table from the start of the WOFF font in its 77 * resource. 78 * 79 * CompLength :: 80 * Compressed table length (in bytes). 81 * 82 * OrigLength :: 83 * Uncompressed table length (in bytes). 84 * 85 * CheckSum :: 86 * The table checksum. This value can be ignored. 87 * 88 * OrigOffset :: 89 * The uncompressed table file offset. This value gets computed while 90 * constructing the (uncompressed) SFNT header. It is not contained in 91 * the WOFF file. 92 */ 93 typedef struct WOFF_TableRec_ 94 { 95 FT_ULong Tag; /* table ID */ 96 FT_ULong Offset; /* table file offset */ 97 FT_ULong CompLength; /* compressed table length */ 98 FT_ULong OrigLength; /* uncompressed table length */ 99 FT_ULong CheckSum; /* uncompressed checksum */ 100 101 FT_ULong OrigOffset; /* uncompressed table file offset */ 102 /* (not in the WOFF file) */ 103 } WOFF_TableRec, *WOFF_Table; 104 105 106 /************************************************************************** 107 * 108 * @struct: 109 * WOFF2_TtcFontRec 110 * 111 * @description: 112 * Metadata for a TTC font entry in WOFF2. 113 * 114 * @fields: 115 * flavor :: 116 * TTC font flavor. 117 * 118 * num_tables :: 119 * Number of tables in TTC, indicating number of elements in 120 * `table_indices`. 121 * 122 * table_indices :: 123 * Array of table indices for each TTC font. 124 */ 125 typedef struct WOFF2_TtcFontRec_ 126 { 127 FT_ULong flavor; 128 FT_UShort num_tables; 129 FT_UShort* table_indices; 130 131 } WOFF2_TtcFontRec, *WOFF2_TtcFont; 132 133 134 /************************************************************************** 135 * 136 * @struct: 137 * WOFF2_HeaderRec 138 * 139 * @description: 140 * WOFF2 file format header. 141 * 142 * @fields: 143 * See 144 * 145 * https://www.w3.org/TR/WOFF2/#woff20Header 146 * 147 * @note: 148 * We don't care about the fields `reserved`, `majorVersion` and 149 * `minorVersion`, so they are not included. The `totalSfntSize` field 150 * does not necessarily represent the actual size of the uncompressed 151 * SFNT font stream, so that is used as a reference value instead. 152 */ 153 typedef struct WOFF2_HeaderRec_ 154 { 155 FT_ULong signature; 156 FT_ULong flavor; 157 FT_ULong length; 158 FT_UShort num_tables; 159 FT_ULong totalSfntSize; 160 FT_ULong totalCompressedSize; 161 FT_ULong metaOffset; 162 FT_ULong metaLength; 163 FT_ULong metaOrigLength; 164 FT_ULong privOffset; 165 FT_ULong privLength; 166 167 FT_ULong uncompressed_size; /* uncompressed brotli stream size */ 168 FT_ULong compressed_offset; /* compressed stream offset */ 169 FT_ULong header_version; /* version of original TTC Header */ 170 FT_UShort num_fonts; /* number of fonts in TTC */ 171 FT_ULong actual_sfnt_size; /* actual size of sfnt stream */ 172 173 WOFF2_TtcFont ttc_fonts; /* metadata for fonts in a TTC */ 174 175 } WOFF2_HeaderRec, *WOFF2_Header; 176 177 178 /************************************************************************** 179 * 180 * @struct: 181 * WOFF2_TableRec 182 * 183 * @description: 184 * This structure describes a given table of a WOFF2 font. 185 * 186 * @fields: 187 * See 188 * 189 * https://www.w3.org/TR/WOFF2/#table_dir_format 190 */ 191 typedef struct WOFF2_TableRec_ 192 { 193 FT_Byte FlagByte; /* table type and flags */ 194 FT_ULong Tag; /* table file offset */ 195 FT_ULong dst_length; /* uncompressed table length */ 196 FT_ULong TransformLength; /* transformed length */ 197 198 FT_ULong flags; /* calculated flags */ 199 FT_ULong src_offset; /* compressed table offset */ 200 FT_ULong src_length; /* compressed table length */ 201 FT_ULong dst_offset; /* uncompressed table offset */ 202 203 } WOFF2_TableRec, *WOFF2_Table; 204 205 206 /************************************************************************** 207 * 208 * @struct: 209 * WOFF2_InfoRec 210 * 211 * @description: 212 * Metadata for WOFF2 font that may be required for reconstruction of 213 * sfnt tables. 214 * 215 * @fields: 216 * header_checksum :: 217 * Checksum of SFNT offset table. 218 * 219 * num_glyphs :: 220 * Number of glyphs in the font. 221 * 222 * num_hmetrics :: 223 * `numberOfHMetrics` field in the 'hhea' table. 224 * 225 * x_mins :: 226 * `xMin` values of glyph bounding box. 227 * 228 * glyf_table :: 229 * A pointer to the `glyf' table record. 230 * 231 * loca_table :: 232 * A pointer to the `loca' table record. 233 * 234 * head_table :: 235 * A pointer to the `head' table record. 236 */ 237 typedef struct WOFF2_InfoRec_ 238 { 239 FT_ULong header_checksum; 240 FT_UShort num_glyphs; 241 FT_UShort num_hmetrics; 242 FT_Short* x_mins; 243 244 WOFF2_Table glyf_table; 245 WOFF2_Table loca_table; 246 WOFF2_Table head_table; 247 248 } WOFF2_InfoRec, *WOFF2_Info; 249 250 251 /************************************************************************** 252 * 253 * @struct: 254 * WOFF2_SubstreamRec 255 * 256 * @description: 257 * This structure stores information about a substream in the transformed 258 * 'glyf' table in a WOFF2 stream. 259 * 260 * @fields: 261 * start :: 262 * Beginning of the substream relative to uncompressed table stream. 263 * 264 * offset :: 265 * Offset of the substream relative to uncompressed table stream. 266 * 267 * size :: 268 * Size of the substream. 269 */ 270 typedef struct WOFF2_SubstreamRec_ 271 { 272 FT_ULong start; 273 FT_ULong offset; 274 FT_ULong size; 275 276 } WOFF2_SubstreamRec, *WOFF2_Substream; 277 278 279 /************************************************************************** 280 * 281 * @struct: 282 * WOFF2_PointRec 283 * 284 * @description: 285 * This structure stores information about a point in the transformed 286 * 'glyf' table in a WOFF2 stream. 287 * 288 * @fields: 289 * x :: 290 * x-coordinate of point. 291 * 292 * y :: 293 * y-coordinate of point. 294 * 295 * on_curve :: 296 * Set if point is on-curve. 297 */ 298 typedef struct WOFF2_PointRec_ 299 { 300 FT_Int x; 301 FT_Int y; 302 FT_Bool on_curve; 303 304 } WOFF2_PointRec, *WOFF2_Point; 305 306 307 FT_END_HEADER 308 309 #endif /* WOFFTYPES_H_ */ 310 311 312 /* END */ 313