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