1 /****************************************************************************
5 * FreeType's glyph color management (specification).
7 * Copyright (C) 2018-2023 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
10 * This file is part of the FreeType project, and may only be used,
11 * modified, and distributed under the terms of the FreeType project
12 * license, LICENSE.TXT. By continuing to use, modify, or distribute
13 * this file you indicate that you have read the license and
14 * understand and accept it fully.
22 #include <freetype/freetype.h>
25 #error "freetype.h of FreeType 1 has been loaded!"
26 #error "Please fix the directory search order for header files"
27 #error "so that freetype.h of FreeType 2 is found first."
34 /**************************************************************************
40 * Glyph Color Management
43 * Retrieving and manipulating OpenType's 'CPAL' table data.
46 * The functions described here allow access and manipulation of color
47 * palette entries in OpenType's 'CPAL' tables.
51 /**************************************************************************
57 * This structure models a BGRA color value of a 'CPAL' palette entry.
59 * The used color space is sRGB; the colors are not pre-multiplied, and
60 * alpha values must be explicitly set.
73 * Alpha value, giving the red, green, and blue color's opacity.
78 typedef struct FT_Color_
88 /**************************************************************************
94 * A list of bit field constants used in the `palette_flags` array of the
95 * @FT_Palette_Data structure to indicate for which background a palette
96 * with a given index is usable.
99 * FT_PALETTE_FOR_LIGHT_BACKGROUND ::
100 * The palette is appropriate to use when displaying the font on a
101 * light background such as white.
103 * FT_PALETTE_FOR_DARK_BACKGROUND ::
104 * The palette is appropriate to use when displaying the font on a dark
105 * background such as black.
110 #define FT_PALETTE_FOR_LIGHT_BACKGROUND 0x01
111 #define FT_PALETTE_FOR_DARK_BACKGROUND 0x02
114 /**************************************************************************
120 * This structure holds the data of the 'CPAL' table.
124 * The number of palettes.
126 * palette_name_ids ::
127 * An optional read-only array of palette name IDs with `num_palettes`
128 * elements, corresponding to entries like 'dark' or 'light' in the
129 * font's 'name' table.
131 * An empty name ID in the 'CPAL' table gets represented as value
134 * `NULL` if the font's 'CPAL' table doesn't contain appropriate data.
137 * An optional read-only array of palette flags with `num_palettes`
138 * elements. Possible values are an ORed combination of
139 * @FT_PALETTE_FOR_LIGHT_BACKGROUND and
140 * @FT_PALETTE_FOR_DARK_BACKGROUND.
142 * `NULL` if the font's 'CPAL' table doesn't contain appropriate data.
144 * num_palette_entries ::
145 * The number of entries in a single palette. All palettes have the
148 * palette_entry_name_ids ::
149 * An optional read-only array of palette entry name IDs with
150 * `num_palette_entries`. In each palette, entries with the same index
151 * have the same function. For example, index~0 might correspond to
152 * string 'outline' in the font's 'name' table to indicate that this
153 * palette entry is used for outlines, index~1 might correspond to
154 * 'fill' to indicate the filling color palette entry, etc.
156 * An empty entry name ID in the 'CPAL' table gets represented as value
159 * `NULL` if the font's 'CPAL' table doesn't contain appropriate data.
162 * Use function @FT_Get_Sfnt_Name to map name IDs and entry name IDs to
165 * Use function @FT_Palette_Select to get the colors associated with a
171 typedef struct FT_Palette_Data_ {
172 FT_UShort num_palettes;
173 const FT_UShort* palette_name_ids;
174 const FT_UShort* palette_flags;
176 FT_UShort num_palette_entries;
177 const FT_UShort* palette_entry_name_ids;
182 /**************************************************************************
185 * FT_Palette_Data_Get
188 * Retrieve the face's color palette data.
192 * The source face handle.
196 * A pointer to an @FT_Palette_Data structure.
199 * FreeType error code. 0~means success.
202 * All arrays in the returned @FT_Palette_Data structure are read-only.
204 * This function always returns an error if the config macro
205 * `TT_CONFIG_OPTION_COLOR_LAYERS` is not defined in `ftoption.h`.
210 FT_EXPORT( FT_Error )
211 FT_Palette_Data_Get( FT_Face face,
212 FT_Palette_Data *apalette );
215 /**************************************************************************
221 * This function has two purposes.
223 * (1) It activates a palette for rendering color glyphs, and
225 * (2) it retrieves all (unmodified) color entries of this palette. This
226 * function returns a read-write array, which means that a calling
227 * application can modify the palette entries on demand.
229 * A corollary of (2) is that calling the function, then modifying some
230 * values, then calling the function again with the same arguments resets
231 * all color entries to the original 'CPAL' values; all user modifications
236 * The source face handle.
243 * An array of color entries for a palette with index `palette_index`,
244 * having `num_palette_entries` elements (as found in the
245 * `FT_Palette_Data` structure). If `apalette` is set to `NULL`, no
246 * array gets returned (and no color entries can be modified).
248 * In case the font doesn't support color palettes, `NULL` is returned.
251 * FreeType error code. 0~means success.
254 * The array pointed to by `apalette_entries` is owned and managed by
257 * This function always returns an error if the config macro
258 * `TT_CONFIG_OPTION_COLOR_LAYERS` is not defined in `ftoption.h`.
263 FT_EXPORT( FT_Error )
264 FT_Palette_Select( FT_Face face,
265 FT_UShort palette_index,
266 FT_Color* *apalette );
269 /**************************************************************************
272 * FT_Palette_Set_Foreground_Color
275 * 'COLR' uses palette index 0xFFFF to indicate a 'text foreground
276 * color'. This function sets this value.
280 * The source face handle.
282 * foreground_color ::
283 * An `FT_Color` structure to define the text foreground color.
286 * FreeType error code. 0~means success.
289 * If this function isn't called, the text foreground color is set to
290 * white opaque (BGRA value 0xFFFFFFFF) if
291 * @FT_PALETTE_FOR_DARK_BACKGROUND is present for the current palette,
292 * and black opaque (BGRA value 0x000000FF) otherwise, including the case
293 * that no palette types are available in the 'CPAL' table.
295 * This function always returns an error if the config macro
296 * `TT_CONFIG_OPTION_COLOR_LAYERS` is not defined in `ftoption.h`.
301 FT_EXPORT( FT_Error )
302 FT_Palette_Set_Foreground_Color( FT_Face face,
303 FT_Color foreground_color );
306 /**************************************************************************
312 * Glyph Layer Management
315 * Retrieving and manipulating OpenType's 'COLR' table data.
318 * The functions described here allow access of colored glyph layer data
319 * in OpenType's 'COLR' tables.
323 /**************************************************************************
329 * This iterator object is needed for @FT_Get_Color_Glyph_Layer.
333 * The number of glyph layers for the requested glyph index. Will be
334 * set by @FT_Get_Color_Glyph_Layer.
337 * The current layer. Will be set by @FT_Get_Color_Glyph_Layer.
340 * An opaque pointer into 'COLR' table data. The caller must set this
341 * to `NULL` before the first call of @FT_Get_Color_Glyph_Layer.
343 typedef struct FT_LayerIterator_
352 /**************************************************************************
355 * FT_Get_Color_Glyph_Layer
358 * This is an interface to the 'COLR' table in OpenType fonts to
359 * iteratively retrieve the colored glyph layers associated with the
360 * current glyph slot.
362 * https://docs.microsoft.com/en-us/typography/opentype/spec/colr
364 * The glyph layer data for a given glyph index, if present, provides an
365 * alternative, multi-color glyph representation: Instead of rendering
366 * the outline or bitmap with the given glyph index, glyphs with the
367 * indices and colors returned by this function are rendered layer by
370 * The returned elements are ordered in the z~direction from bottom to
371 * top; the 'n'th element should be rendered with the associated palette
372 * color and blended on top of the already rendered layers (elements 0,
377 * A handle to the parent face object.
380 * The glyph index the colored glyph layers are associated with.
384 * An @FT_LayerIterator object. For the first call you should set
385 * `iterator->p` to `NULL`. For all following calls, simply use the
390 * The glyph index of the current layer.
393 * The color index into the font face's color palette of the current
394 * layer. The value 0xFFFF is special; it doesn't reference a palette
395 * entry but indicates that the text foreground color should be used
396 * instead (to be set up by the application outside of FreeType).
398 * The color palette can be retrieved with @FT_Palette_Select.
401 * Value~1 if everything is OK. If there are no more layers (or if there
402 * are no layers at all), value~0 gets returned. In case of an error,
403 * value~0 is returned also.
406 * This function is necessary if you want to handle glyph layers by
407 * yourself. In particular, functions that operate with @FT_GlyphRec
408 * objects (like @FT_Get_Glyph or @FT_Glyph_To_Bitmap) don't have access
409 * to this information.
411 * Note that @FT_Render_Glyph is able to handle colored glyph layers
412 * automatically if the @FT_LOAD_COLOR flag is passed to a previous call
413 * to @FT_Load_Glyph. [This is an experimental feature.]
418 * FT_LayerIterator iterator;
420 * FT_Bool have_layers;
421 * FT_UInt layer_glyph_index;
422 * FT_UInt layer_color_index;
425 * error = FT_Palette_Select( face, palette_index, &palette );
430 * have_layers = FT_Get_Color_Glyph_Layer( face,
432 * &layer_glyph_index,
433 * &layer_color_index,
436 * if ( palette && have_layers )
440 * FT_Color layer_color;
443 * if ( layer_color_index == 0xFFFF )
444 * layer_color = text_foreground_color;
446 * layer_color = palette[layer_color_index];
448 * // Load and render glyph `layer_glyph_index', then
449 * // blend resulting pixmap (using color `layer_color')
450 * // with previously created pixmaps.
452 * } while ( FT_Get_Color_Glyph_Layer( face,
454 * &layer_glyph_index,
455 * &layer_color_index,
464 FT_Get_Color_Glyph_Layer( FT_Face face,
466 FT_UInt *aglyph_index,
467 FT_UInt *acolor_index,
468 FT_LayerIterator* iterator );
471 /**************************************************************************
477 * Enumeration describing the different paint format types of the v1
478 * extensions to the 'COLR' table, see
479 * 'https://github.com/googlefonts/colr-gradients-spec'.
481 * The enumeration values loosely correspond with the format numbers of
482 * the specification: FreeType always returns a fully specified 'Paint'
483 * structure for the 'Transform', 'Translate', 'Scale', 'Rotate', and
484 * 'Skew' table types even though the specification has different formats
485 * depending on whether or not a center is specified, whether the scale
486 * is uniform in x and y~direction or not, etc. Also, only non-variable
487 * format identifiers are listed in this enumeration; as soon as support
488 * for variable 'COLR' v1 fonts is implemented, interpolation is
489 * performed dependent on axis coordinates, which are configured on the
490 * @FT_Face through @FT_Set_Var_Design_Coordinates. This implies that
491 * always static, readily interpolated values are returned in the 'Paint'
497 typedef enum FT_PaintFormat_
499 FT_COLR_PAINTFORMAT_COLR_LAYERS = 1,
500 FT_COLR_PAINTFORMAT_SOLID = 2,
501 FT_COLR_PAINTFORMAT_LINEAR_GRADIENT = 4,
502 FT_COLR_PAINTFORMAT_RADIAL_GRADIENT = 6,
503 FT_COLR_PAINTFORMAT_SWEEP_GRADIENT = 8,
504 FT_COLR_PAINTFORMAT_GLYPH = 10,
505 FT_COLR_PAINTFORMAT_COLR_GLYPH = 11,
506 FT_COLR_PAINTFORMAT_TRANSFORM = 12,
507 FT_COLR_PAINTFORMAT_TRANSLATE = 14,
508 FT_COLR_PAINTFORMAT_SCALE = 16,
509 FT_COLR_PAINTFORMAT_ROTATE = 24,
510 FT_COLR_PAINTFORMAT_SKEW = 28,
511 FT_COLR_PAINTFORMAT_COMPOSITE = 32,
512 FT_COLR_PAINT_FORMAT_MAX = 33,
513 FT_COLR_PAINTFORMAT_UNSUPPORTED = 255
518 /**************************************************************************
521 * FT_ColorStopIterator
524 * This iterator object is needed for @FT_Get_Colorline_Stops. It keeps
525 * state while iterating over the stops of an @FT_ColorLine, representing
526 * the `ColorLine` struct of the v1 extensions to 'COLR', see
527 * 'https://github.com/googlefonts/colr-gradients-spec'. Do not manually
528 * modify fields of this iterator.
532 * The number of color stops for the requested glyph index. Set by
535 * current_color_stop ::
536 * The current color stop. Set by @FT_Get_Colorline_Stops.
539 * An opaque pointer into 'COLR' table data. Set by @FT_Get_Paint.
540 * Updated by @FT_Get_Colorline_Stops.
543 * A boolean keeping track of whether variable color lines are to be
544 * read. Set by @FT_Get_Paint.
549 typedef struct FT_ColorStopIterator_
551 FT_UInt num_color_stops;
552 FT_UInt current_color_stop;
556 FT_Bool read_variable;
558 } FT_ColorStopIterator;
561 /**************************************************************************
567 * A structure representing a `ColorIndex` value of the 'COLR' v1
568 * extensions, see 'https://github.com/googlefonts/colr-gradients-spec'.
572 * The palette index into a 'CPAL' palette.
575 * Alpha transparency value multiplied with the value from 'CPAL'.
580 typedef struct FT_ColorIndex_
582 FT_UInt16 palette_index;
588 /**************************************************************************
594 * A structure representing a `ColorStop` value of the 'COLR' v1
595 * extensions, see 'https://github.com/googlefonts/colr-gradients-spec'.
599 * The stop offset along the gradient, expressed as a 16.16 fixed-point
603 * The color information for this stop, see @FT_ColorIndex.
608 typedef struct FT_ColorStop_
610 FT_Fixed stop_offset;
616 /**************************************************************************
622 * An enumeration representing the 'Extend' mode of the 'COLR' v1
623 * extensions, see 'https://github.com/googlefonts/colr-gradients-spec'.
624 * It describes how the gradient fill continues at the other boundaries.
629 typedef enum FT_PaintExtend_
631 FT_COLR_PAINT_EXTEND_PAD = 0,
632 FT_COLR_PAINT_EXTEND_REPEAT = 1,
633 FT_COLR_PAINT_EXTEND_REFLECT = 2
638 /**************************************************************************
644 * A structure representing a `ColorLine` value of the 'COLR' v1
645 * extensions, see 'https://github.com/googlefonts/colr-gradients-spec'.
646 * It describes a list of color stops along the defined gradient.
650 * The extend mode at the outer boundaries, see @FT_PaintExtend.
652 * color_stop_iterator ::
653 * The @FT_ColorStopIterator used to enumerate and retrieve the
654 * actual @FT_ColorStop's.
659 typedef struct FT_ColorLine_
661 FT_PaintExtend extend;
662 FT_ColorStopIterator color_stop_iterator;
667 /**************************************************************************
673 * A structure used to store a 2x3 matrix. Coefficients are in
674 * 16.16 fixed-point format. The computation performed is
677 * x' = x*xx + y*xy + dx
678 * y' = x*yx + y*yy + dy
683 * Matrix coefficient.
686 * Matrix coefficient.
692 * Matrix coefficient.
695 * Matrix coefficient.
703 typedef struct FT_Affine_23_
711 /**************************************************************************
717 * An enumeration listing the 'COLR' v1 composite modes used in
718 * @FT_PaintComposite. For more details on each paint mode, see
719 * 'https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators'.
724 typedef enum FT_Composite_Mode_
726 FT_COLR_COMPOSITE_CLEAR = 0,
727 FT_COLR_COMPOSITE_SRC = 1,
728 FT_COLR_COMPOSITE_DEST = 2,
729 FT_COLR_COMPOSITE_SRC_OVER = 3,
730 FT_COLR_COMPOSITE_DEST_OVER = 4,
731 FT_COLR_COMPOSITE_SRC_IN = 5,
732 FT_COLR_COMPOSITE_DEST_IN = 6,
733 FT_COLR_COMPOSITE_SRC_OUT = 7,
734 FT_COLR_COMPOSITE_DEST_OUT = 8,
735 FT_COLR_COMPOSITE_SRC_ATOP = 9,
736 FT_COLR_COMPOSITE_DEST_ATOP = 10,
737 FT_COLR_COMPOSITE_XOR = 11,
738 FT_COLR_COMPOSITE_PLUS = 12,
739 FT_COLR_COMPOSITE_SCREEN = 13,
740 FT_COLR_COMPOSITE_OVERLAY = 14,
741 FT_COLR_COMPOSITE_DARKEN = 15,
742 FT_COLR_COMPOSITE_LIGHTEN = 16,
743 FT_COLR_COMPOSITE_COLOR_DODGE = 17,
744 FT_COLR_COMPOSITE_COLOR_BURN = 18,
745 FT_COLR_COMPOSITE_HARD_LIGHT = 19,
746 FT_COLR_COMPOSITE_SOFT_LIGHT = 20,
747 FT_COLR_COMPOSITE_DIFFERENCE = 21,
748 FT_COLR_COMPOSITE_EXCLUSION = 22,
749 FT_COLR_COMPOSITE_MULTIPLY = 23,
750 FT_COLR_COMPOSITE_HSL_HUE = 24,
751 FT_COLR_COMPOSITE_HSL_SATURATION = 25,
752 FT_COLR_COMPOSITE_HSL_COLOR = 26,
753 FT_COLR_COMPOSITE_HSL_LUMINOSITY = 27,
754 FT_COLR_COMPOSITE_MAX = 28
759 /**************************************************************************
765 * A structure representing an offset to a `Paint` value stored in any
766 * of the paint tables of a 'COLR' v1 font. Compare Offset<24> there.
767 * When 'COLR' v1 paint tables represented by FreeType objects such as
768 * @FT_PaintColrLayers, @FT_PaintComposite, or @FT_PaintTransform
769 * reference downstream nested paint tables, we do not immediately
770 * retrieve them but encapsulate their location in this type. Use
771 * @FT_Get_Paint to retrieve the actual @FT_COLR_Paint object that
772 * describes the details of the respective paint table.
776 * An internal offset to a Paint table, needs to be set to NULL before
777 * passing this struct as an argument to @FT_Get_Paint.
779 * insert_root_transform ::
780 * An internal boolean to track whether an initial root transform is
781 * to be provided. Do not set this value.
786 typedef struct FT_Opaque_Paint_
789 FT_Bool insert_root_transform;
793 /**************************************************************************
799 * A structure representing a `PaintColrLayers` table of a 'COLR' v1
800 * font. This table describes a set of layers that are to be composited
801 * with composite mode `FT_COLR_COMPOSITE_SRC_OVER`. The return value
802 * of this function is an @FT_LayerIterator initialized so that it can
803 * be used with @FT_Get_Paint_Layers to retrieve the @FT_OpaquePaint
804 * objects as references to each layer.
808 * The layer iterator that describes the layers of this paint.
813 typedef struct FT_PaintColrLayers_
815 FT_LayerIterator layer_iterator;
817 } FT_PaintColrLayers;
820 /**************************************************************************
826 * A structure representing a `PaintSolid` value of the 'COLR' v1
827 * extensions, see 'https://github.com/googlefonts/colr-gradients-spec'.
828 * Using a `PaintSolid` value means that the glyph layer filled with
829 * this paint is solid-colored and does not contain a gradient.
833 * The color information for this solid paint, see @FT_ColorIndex.
838 typedef struct FT_PaintSolid_
845 /**************************************************************************
848 * FT_PaintLinearGradient
851 * A structure representing a `PaintLinearGradient` value of the 'COLR'
853 * 'https://github.com/googlefonts/colr-gradients-spec'. The glyph
854 * layer filled with this paint is drawn filled with a linear gradient.
858 * The @FT_ColorLine information for this paint, i.e., the list of
859 * color stops along the gradient.
862 * The starting point of the gradient definition in font units
863 * represented as a 16.16 fixed-point `FT_Vector`.
866 * The end point of the gradient definition in font units
867 * represented as a 16.16 fixed-point `FT_Vector`.
870 * Optional point~p2 to rotate the gradient in font units
871 * represented as a 16.16 fixed-point `FT_Vector`.
872 * Otherwise equal to~p0.
877 typedef struct FT_PaintLinearGradient_
879 FT_ColorLine colorline;
881 /* TODO: Potentially expose those as x0, y0 etc. */
886 } FT_PaintLinearGradient;
889 /**************************************************************************
892 * FT_PaintRadialGradient
895 * A structure representing a `PaintRadialGradient` value of the 'COLR'
897 * 'https://github.com/googlefonts/colr-gradients-spec'. The glyph
898 * layer filled with this paint is drawn filled with a radial gradient.
902 * The @FT_ColorLine information for this paint, i.e., the list of
903 * color stops along the gradient.
906 * The center of the starting point of the radial gradient in font
907 * units represented as a 16.16 fixed-point `FT_Vector`.
910 * The radius of the starting circle of the radial gradient in font
911 * units represented as a 16.16 fixed-point value.
914 * The center of the end point of the radial gradient in font units
915 * represented as a 16.16 fixed-point `FT_Vector`.
918 * The radius of the end circle of the radial gradient in font
919 * units represented as a 16.16 fixed-point value.
924 typedef struct FT_PaintRadialGradient_
926 FT_ColorLine colorline;
933 } FT_PaintRadialGradient;
936 /**************************************************************************
939 * FT_PaintSweepGradient
942 * A structure representing a `PaintSweepGradient` value of the 'COLR'
944 * 'https://github.com/googlefonts/colr-gradients-spec'. The glyph
945 * layer filled with this paint is drawn filled with a sweep gradient
946 * from `start_angle` to `end_angle`.
950 * The @FT_ColorLine information for this paint, i.e., the list of
951 * color stops along the gradient.
954 * The center of the sweep gradient in font units represented as a
955 * vector of 16.16 fixed-point values.
958 * The start angle of the sweep gradient in 16.16 fixed-point
959 * format specifying degrees divided by 180.0 (as in the
960 * spec). Multiply by 180.0f to receive degrees value. Values are
961 * given counter-clockwise, starting from the (positive) y~axis.
964 * The end angle of the sweep gradient in 16.16 fixed-point
965 * format specifying degrees divided by 180.0 (as in the
966 * spec). Multiply by 180.0f to receive degrees value. Values are
967 * given counter-clockwise, starting from the (positive) y~axis.
972 typedef struct FT_PaintSweepGradient_
974 FT_ColorLine colorline;
977 FT_Fixed start_angle;
980 } FT_PaintSweepGradient;
983 /**************************************************************************
989 * A structure representing a 'COLR' v1 `PaintGlyph` paint table.
993 * An opaque paint object pointing to a `Paint` table that serves as
994 * the fill for the glyph ID.
997 * The glyph ID from the 'glyf' table, which serves as the contour
998 * information that is filled with paint.
1003 typedef struct FT_PaintGlyph_
1005 FT_OpaquePaint paint;
1011 /**************************************************************************
1017 * A structure representing a 'COLR' v1 `PaintColorGlyph` paint table.
1021 * The glyph ID from the `BaseGlyphV1List` table that is drawn for
1027 typedef struct FT_PaintColrGlyph_
1031 } FT_PaintColrGlyph;
1034 /**************************************************************************
1040 * A structure representing a 'COLR' v1 `PaintTransform` paint table.
1044 * An opaque paint that is subject to being transformed.
1047 * A 2x3 transformation matrix in @FT_Affine23 format containing
1048 * 16.16 fixed-point values.
1053 typedef struct FT_PaintTransform_
1055 FT_OpaquePaint paint;
1058 } FT_PaintTransform;
1061 /**************************************************************************
1067 * A structure representing a 'COLR' v1 `PaintTranslate` paint table.
1068 * Used for translating downstream paints by a given x and y~delta.
1072 * An @FT_OpaquePaint object referencing the paint that is to be
1076 * Translation in x~direction in font units represented as a
1077 * 16.16 fixed-point value.
1080 * Translation in y~direction in font units represented as a
1081 * 16.16 fixed-point value.
1086 typedef struct FT_PaintTranslate_
1088 FT_OpaquePaint paint;
1093 } FT_PaintTranslate;
1096 /**************************************************************************
1102 * A structure representing all of the 'COLR' v1 'PaintScale*' paint
1103 * tables. Used for scaling downstream paints by a given x and y~scale,
1104 * with a given center. This structure is used for all 'PaintScale*'
1105 * types that are part of specification; fields of this structure are
1106 * filled accordingly. If there is a center, the center values are set,
1107 * otherwise they are set to the zero coordinate. If the source font
1108 * file has 'PaintScaleUniform*' set, the scale values are set
1109 * accordingly to the same value.
1113 * An @FT_OpaquePaint object referencing the paint that is to be
1117 * Scale factor in x~direction represented as a
1118 * 16.16 fixed-point value.
1121 * Scale factor in y~direction represented as a
1122 * 16.16 fixed-point value.
1125 * x~coordinate of center point to scale from represented as a
1126 * 16.16 fixed-point value.
1129 * y~coordinate of center point to scale from represented as a
1130 * 16.16 fixed-point value.
1135 typedef struct FT_PaintScale_
1137 FT_OpaquePaint paint;
1148 /**************************************************************************
1154 * A structure representing a 'COLR' v1 `PaintRotate` paint table. Used
1155 * for rotating downstream paints with a given center and angle.
1159 * An @FT_OpaquePaint object referencing the paint that is to be
1163 * The rotation angle that is to be applied in degrees divided by
1164 * 180.0 (as in the spec) represented as a 16.16 fixed-point
1165 * value. Multiply by 180.0f to receive degrees value.
1168 * The x~coordinate of the pivot point of the rotation in font
1169 * units represented as a 16.16 fixed-point value.
1172 * The y~coordinate of the pivot point of the rotation in font
1173 * units represented as a 16.16 fixed-point value.
1179 typedef struct FT_PaintRotate_
1181 FT_OpaquePaint paint;
1191 /**************************************************************************
1197 * A structure representing a 'COLR' v1 `PaintSkew` paint table. Used
1198 * for skewing or shearing downstream paints by a given center and
1203 * An @FT_OpaquePaint object referencing the paint that is to be
1207 * The skewing angle in x~direction in degrees divided by 180.0
1208 * (as in the spec) represented as a 16.16 fixed-point
1209 * value. Multiply by 180.0f to receive degrees.
1212 * The skewing angle in y~direction in degrees divided by 180.0
1213 * (as in the spec) represented as a 16.16 fixed-point
1214 * value. Multiply by 180.0f to receive degrees.
1217 * The x~coordinate of the pivot point of the skew in font units
1218 * represented as a 16.16 fixed-point value.
1221 * The y~coordinate of the pivot point of the skew in font units
1222 * represented as a 16.16 fixed-point value.
1227 typedef struct FT_PaintSkew_
1229 FT_OpaquePaint paint;
1231 FT_Fixed x_skew_angle;
1232 FT_Fixed y_skew_angle;
1240 /**************************************************************************
1246 * A structure representing a 'COLR' v1 `PaintComposite` paint table.
1247 * Used for compositing two paints in a 'COLR' v1 directed acyclic graph.
1251 * An @FT_OpaquePaint object referencing the source that is to be
1255 * An @FT_Composite_Mode enum value determining the composition
1259 * An @FT_OpaquePaint object referencing the backdrop paint that
1260 * `source_paint` is composited onto.
1265 typedef struct FT_PaintComposite_
1267 FT_OpaquePaint source_paint;
1268 FT_Composite_Mode composite_mode;
1269 FT_OpaquePaint backdrop_paint;
1271 } FT_PaintComposite;
1274 /**************************************************************************
1280 * A union object representing format and details of a paint table of a
1281 * 'COLR' v1 font, see
1282 * 'https://github.com/googlefonts/colr-gradients-spec'. Use
1283 * @FT_Get_Paint to retrieve a @FT_COLR_Paint for an @FT_OpaquePaint
1288 * The gradient format for this Paint structure.
1291 * Union of all paint table types:
1293 * * @FT_PaintColrLayers
1296 * * @FT_PaintLinearGradient
1297 * * @FT_PaintRadialGradient
1298 * * @FT_PaintSweepGradient
1299 * * @FT_PaintTransform
1300 * * @FT_PaintTranslate
1303 * * @FT_PaintComposite
1304 * * @FT_PaintColrGlyph
1309 typedef struct FT_COLR_Paint_
1311 FT_PaintFormat format;
1315 FT_PaintColrLayers colr_layers;
1316 FT_PaintGlyph glyph;
1317 FT_PaintSolid solid;
1318 FT_PaintLinearGradient linear_gradient;
1319 FT_PaintRadialGradient radial_gradient;
1320 FT_PaintSweepGradient sweep_gradient;
1321 FT_PaintTransform transform;
1322 FT_PaintTranslate translate;
1323 FT_PaintScale scale;
1324 FT_PaintRotate rotate;
1326 FT_PaintComposite composite;
1327 FT_PaintColrGlyph colr_glyph;
1334 /**************************************************************************
1337 * FT_Color_Root_Transform
1340 * An enumeration to specify whether @FT_Get_Color_Glyph_Paint is to
1341 * return a root transform to configure the client's graphics context
1345 * FT_COLOR_INCLUDE_ROOT_TRANSFORM ::
1346 * Do include the root transform as the initial @FT_COLR_Paint object.
1348 * FT_COLOR_NO_ROOT_TRANSFORM ::
1349 * Do not output an initial root transform.
1354 typedef enum FT_Color_Root_Transform_
1356 FT_COLOR_INCLUDE_ROOT_TRANSFORM,
1357 FT_COLOR_NO_ROOT_TRANSFORM,
1359 FT_COLOR_ROOT_TRANSFORM_MAX
1361 } FT_Color_Root_Transform;
1364 /**************************************************************************
1370 * A structure representing a 'COLR' v1 'ClipBox' table. 'COLR' v1
1371 * glyphs may optionally define a clip box for aiding allocation or
1372 * defining a maximum drawable region. Use @FT_Get_Color_Glyph_ClipBox
1377 * The bottom left corner of the clip box as an @FT_Vector with
1378 * fixed-point coordinates in 26.6 format.
1381 * The top left corner of the clip box as an @FT_Vector with
1382 * fixed-point coordinates in 26.6 format.
1385 * The top right corner of the clip box as an @FT_Vector with
1386 * fixed-point coordinates in 26.6 format.
1389 * The bottom right corner of the clip box as an @FT_Vector with
1390 * fixed-point coordinates in 26.6 format.
1395 typedef struct FT_ClipBox_
1397 FT_Vector bottom_left;
1399 FT_Vector top_right;
1400 FT_Vector bottom_right;
1405 /**************************************************************************
1408 * FT_Get_Color_Glyph_Paint
1411 * This is the starting point and interface to color gradient
1412 * information in a 'COLR' v1 table in OpenType fonts to recursively
1413 * retrieve the paint tables for the directed acyclic graph of a colored
1414 * glyph, given a glyph ID.
1416 * https://github.com/googlefonts/colr-gradients-spec
1418 * In a 'COLR' v1 font, each color glyph defines a directed acyclic
1419 * graph of nested paint tables, such as `PaintGlyph`, `PaintSolid`,
1420 * `PaintLinearGradient`, `PaintRadialGradient`, and so on. Using this
1421 * function and specifying a glyph ID, one retrieves the root paint
1422 * table for this glyph ID.
1424 * This function allows control whether an initial root transform is
1425 * returned to configure scaling, transform, and translation correctly
1426 * on the client's graphics context. The initial root transform is
1427 * computed and returned according to the values configured for @FT_Size
1428 * and @FT_Set_Transform on the @FT_Face object, see below for details
1429 * of the `root_transform` parameter. This has implications for a
1430 * client 'COLR' v1 implementation: When this function returns an
1431 * initially computed root transform, at the time of executing the
1432 * @FT_PaintGlyph operation, the contours should be retrieved using
1433 * @FT_Load_Glyph at unscaled, untransformed size. This is because the
1434 * root transform applied to the graphics context will take care of
1437 * Alternatively, to allow hinting of contours, at the time of executing
1438 * @FT_Load_Glyph, the current graphics context transformation matrix
1439 * can be decomposed into a scaling matrix and a remainder, and
1440 * @FT_Load_Glyph can be used to retrieve the contours at scaled size.
1441 * Care must then be taken to blit or clip to the graphics context with
1442 * taking this remainder transformation into account.
1446 * A handle to the parent face object.
1449 * The glyph index for which to retrieve the root paint table.
1452 * Specifies whether an initially computed root is returned by the
1453 * @FT_PaintTransform operation to account for the activated size
1454 * (see @FT_Activate_Size) and the configured transform and translate
1455 * (see @FT_Set_Transform).
1457 * This root transform is returned before nodes of the glyph graph of
1458 * the font are returned. Subsequent @FT_COLR_Paint structures
1459 * contain unscaled and untransformed values. The inserted root
1460 * transform enables the client application to apply an initial
1461 * transform to its graphics context. When executing subsequent
1462 * FT_COLR_Paint operations, values from @FT_COLR_Paint operations
1463 * will ultimately be correctly scaled because of the root transform
1464 * applied to the graphics context. Use
1465 * @FT_COLOR_INCLUDE_ROOT_TRANSFORM to include the root transform, use
1466 * @FT_COLOR_NO_ROOT_TRANSFORM to not include it. The latter may be
1467 * useful when traversing the 'COLR' v1 glyph graph and reaching a
1468 * @FT_PaintColrGlyph. When recursing into @FT_PaintColrGlyph and
1469 * painting that inline, no additional root transform is needed as it
1470 * has already been applied to the graphics context at the beginning
1471 * of drawing this glyph.
1475 * The @FT_OpaquePaint object that references the actual paint table.
1477 * The respective actual @FT_COLR_Paint object is retrieved via
1481 * Value~1 if everything is OK. If no color glyph is found, or the root
1482 * paint could not be retrieved, value~0 gets returned. In case of an
1483 * error, value~0 is returned also.
1488 FT_EXPORT( FT_Bool )
1489 FT_Get_Color_Glyph_Paint( FT_Face face,
1491 FT_Color_Root_Transform root_transform,
1492 FT_OpaquePaint* paint );
1495 /**************************************************************************
1498 * FT_Get_Color_Glyph_ClipBox
1501 * Search for a 'COLR' v1 clip box for the specified `base_glyph` and
1502 * fill the `clip_box` parameter with the 'COLR' v1 'ClipBox' information
1507 * A handle to the parent face object.
1510 * The glyph index for which to retrieve the clip box.
1514 * The clip box for the requested `base_glyph` if one is found. The
1515 * clip box is computed taking scale and transformations configured on
1516 * the @FT_Face into account. @FT_ClipBox contains @FT_Vector values
1520 * Value~1 if a clip box is found. If no clip box is found or an error
1521 * occured, value~0 is returned.
1524 * To retrieve the clip box in font units, reset scale to units-per-em
1525 * and remove transforms configured using @FT_Set_Transform.
1530 FT_EXPORT( FT_Bool )
1531 FT_Get_Color_Glyph_ClipBox( FT_Face face,
1533 FT_ClipBox* clip_box );
1536 /**************************************************************************
1539 * FT_Get_Paint_Layers
1542 * Access the layers of a `PaintColrLayers` table.
1544 * If the root paint of a color glyph, or a nested paint of a 'COLR'
1545 * glyph is a `PaintColrLayers` table, this function retrieves the
1546 * layers of the `PaintColrLayers` table.
1548 * The @FT_PaintColrLayers object contains an @FT_LayerIterator, which
1549 * is used here to iterate over the layers. Each layer is returned as
1550 * an @FT_OpaquePaint object, which then can be used with @FT_Get_Paint
1551 * to retrieve the actual paint object.
1555 * A handle to the parent face object.
1559 * The @FT_LayerIterator from an @FT_PaintColrLayers object, for which
1560 * the layers are to be retrieved. The internal state of the iterator
1561 * is incremented after one call to this function for retrieving one
1566 * The @FT_OpaquePaint object that references the actual paint table.
1567 * The respective actual @FT_COLR_Paint object is retrieved via
1571 * Value~1 if everything is OK. Value~0 gets returned when the paint
1572 * object can not be retrieved or any other error occurs.
1577 FT_EXPORT( FT_Bool )
1578 FT_Get_Paint_Layers( FT_Face face,
1579 FT_LayerIterator* iterator,
1580 FT_OpaquePaint* paint );
1583 /**************************************************************************
1586 * FT_Get_Colorline_Stops
1589 * This is an interface to color gradient information in a 'COLR' v1
1590 * table in OpenType fonts to iteratively retrieve the gradient and
1591 * solid fill information for colored glyph layers for a specified glyph
1594 * https://github.com/googlefonts/colr-gradients-spec
1598 * A handle to the parent face object.
1602 * The retrieved @FT_ColorStopIterator, configured on an @FT_ColorLine,
1603 * which in turn got retrieved via paint information in
1604 * @FT_PaintLinearGradient or @FT_PaintRadialGradient.
1608 * Color index and alpha value for the retrieved color stop.
1611 * Value~1 if everything is OK. If there are no more color stops,
1612 * value~0 gets returned. In case of an error, value~0 is returned
1618 FT_EXPORT( FT_Bool )
1619 FT_Get_Colorline_Stops( FT_Face face,
1620 FT_ColorStop* color_stop,
1621 FT_ColorStopIterator* iterator );
1624 /**************************************************************************
1630 * Access the details of a paint using an @FT_OpaquePaint opaque paint
1631 * object, which internally stores the offset to the respective `Paint`
1632 * object in the 'COLR' table.
1636 * A handle to the parent face object.
1639 * The opaque paint object for which the underlying @FT_COLR_Paint
1640 * data is to be retrieved.
1644 * The specific @FT_COLR_Paint object containing information coming
1645 * from one of the font's `Paint*` tables.
1648 * Value~1 if everything is OK. Value~0 if no details can be found for
1649 * this paint or any other error occured.
1654 FT_EXPORT( FT_Bool )
1655 FT_Get_Paint( FT_Face face,
1656 FT_OpaquePaint opaque_paint,
1657 FT_COLR_Paint* paint );
1664 #endif /* FTCOLOR_H_ */