Set correct value of `face->num_faces' for WOFF2 fonts. This is being
handled separately because we only load the tables for the requested
font face in `woff2_open_font' and create a single-face sfnt stream.
The full discussion is at:
https://lists.gnu.org/archive/html/freetype-devel/2019-08/msg00000.html
* src/sfnt/sfobjs.c (sfnt_open_font): Add parameter `woff2_num_faces'.
(sfnt_init_face): Introduce var `woff2_num_faces', and change
`face->root.num_faces' if `woff2_num_faces' is set.
* src/sfnt/sfwoff2.c (woff2_open_font): Validate requested face index
and handle negative face indices.
* src/sfnt/sfwoff2.h (woff2_open_font): Add parameter `num_faces' to
declaration.
Add necessary functions to reconstruct loca and hmtx tables (the 2
remaining tables that can have a transform). `woff2_open_font' is now
capable of loading a woff2 font face. This code may still need more
refining and better memory management.
* include/freetype/internal/wofftypes.h (WOFF2_HeaderRec): Add total (final)
size of sfnt stream.
(WOFF2_InfoRec): Add header checksum value.
* src/sfnt/sfobjs.c (sfnt_open_font): Change `face_instance_index' parameter
to its pointer so its value can be modified by `woff2_open_font'.
* src/sfnt/sfwoff2.c: (WRITE_SFNT_BUF_AT): New macro to write into sfnt
buffer at given position.
(write_buf): Add parameter `extend_buf' which allows caller to specify
whether buffer should be reallocated before copying data. Modify macro
`WRITE_SFNT_BUF' accordingly.
(pad4): New function to pad buffer to closest multiple of 4.
(store_loca): Store loca values (provided by `reconstruct_glyf') to output
stream.
(reconstruct_glyf): Calculate loca values and store them.
(reconstruct_hmtx): Reconstruct transformed hmtx table.
(reconstruct_font): Call `reconstruct_hmtx', write table record entries, and
calculate table checksums. Also calculate font checksum and update
`checksumAdjustment' entry in head table.
(woff2_open_font): Open stream for sfnt buffer, swap out input stream and
return.
* src/sfnt/sfwoff2.h (woff2_open_font): Modify parameter to accept pointer
to `face_index'.
Reconstruct `glyf' table if it is transformed in the uncompressed table
stream. Also add necessary structures, macros and functions.
* include/freetype/internal/wofftypes.h (WOFF2_InfoRec,
WOFF2_SubstreamRec, WOFF2_PointRec): New structures.
* src/sfnt/sfwoff2.c (READ_255USHORT, READ_BASE128): Use `FT_SET_ERROR'
to set implicit `error' variable.
(WRITE_SHORT): New macro.
(N_CONTOUR_STREAM, N_POINTS_STREAM, FLAG_STREAM, GLYPH_STREAM,
COMPOSITE_STREAM, BBOX_STREAM, INSTRUCTION_STREAM): New macros to refer
to substreams of the transformed `glyf' tables.
(Read255UShort, ReadBase128): Return errors set by `FT_READ_XXX' macros.
(with_sign, safe_int_addition): New functions to add sign to values
based on a flag and perform safe addition respectively.
(triplet_decode): Decode variable-length (flag, xCoordinate, yCoordinate)
triplet for a simple glyph. See
https://www.w3.org/TR/WOFF2/#triplet_decoding
(store_points): Store decoded points in the glyph buffer.
(compute_bbox): Derive bounding box for a glyph by computing the minimum
and maximum x and y coordinates in the outline.
(reconstruct_glyf): Main routine to reconstruct transformed `glyf' table.
(reconstruct_font): Call `reconstruct_glyf'.
* src/sfnt/sfwoff2.h: Add required constants.
* src/sfnt/woff2tags.h: Move out constants to `sfwoff2.h'.
WOFF2 compressed stream is now uncompressed if Brotli is available. This
data is stored in a separate buffer (uncompressed_buf) because it does
not contain direct table data. Certain tables have transformations
applied to them, and they must be reconstructed before we can write
those tables to the SFNT stream.
`face_index' is now being passed as a parameter to `woff2_open_font'.
* src/sfnt/sfobjs.c (sfnt_open_font): Add parameter
`face_instance_index'.
* src/sfnt/sfwoff2.c (woff2_uncompress): New function.
(woff2_open_font): Call `woff2_uncompress'.
* src/sfnt/sfwoff2.h (woff2_open_font): Modify declaration.
Check for WOFF2 tag, call `woff2_open_font', and implement it to read
header according to specification.
* include/freetype/internal/fttrace.h: Add `sfwoff2.c'.
* src/sfnt/rules.mk: Add `sfwoff2.c'.
* src/sfnt/sfnt.c: Include `sfwoff2.c'.
* src/sfnt/sfobjs.c: Check for `wOF2' tag and call `woff2_open_font'.
* src/sfnt/sfwoff2.c, src/sfnt/sfwoff2.h: New files.