Add function `FT_Get_GlyphLayers' to access `COLR' table data. * include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec): Move this structure to... * include/freetype/freetype.h (FT_Glyph_LayerRec): ... this header file. (FT_Glyph_Layer): New typedef. Update code to use it where appropriate. * src/base/ftobjs.c (FT_Get_GlyphLayers): New function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
diff --git a/ChangeLog b/ChangeLog
index b590def..4b726e5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2018-05-16 Werner Lemberg <wl@gnu.org>
+
+ Add function `FT_Get_GlyphLayers' to access `COLR' table data.
+
+ * include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec): Move this
+ structure to...
+ * include/freetype/freetype.h (FT_Glyph_LayerRec): ... this
+ header file.
+ (FT_Glyph_Layer): New typedef.
+ Update code to use it where appropriate.
+
+ * src/base/ftobjs.c (FT_Get_GlyphLayers): New function.
+
2018-05-15 Alexei Podtelezhnikov <apodtele@gmail.com>
[base] Fix mono bitmap presetting (#53896).
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index 9664404..4151b06 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -3986,6 +3986,101 @@ FT_BEGIN_HEADER
FT_Matrix *p_transform );
+ /**********************************************************************
+ *
+ * @type:
+ * FT_Glyph_Layer
+ *
+ * @description:
+ * A handle to an @FT_Glyph_LayerRec structure to model a given
+ * colored glyph layer.
+ */
+ typedef struct FT_Glyph_LayerRec_* FT_Glyph_Layer;
+
+
+ /**********************************************************************
+ *
+ * @struct:
+ * FT_Glyph_LayerRec
+ *
+ * @description:
+ * This structure models a given colored glyph layer as defined in the
+ * OpenType `COLR' table. It is used by @FT_Get_GlyphLayers.
+ *
+ * @fields:
+ * glyph_index ::
+ * The glyph index of the current glyph layer.
+ *
+ * color_index ::
+ * The color index into the font face's color palette, which can be
+ * retrieved with @FT_Palette_Select. The value 0xFFFF is special; it
+ * doesn't reference a palette entry but indicates that the text
+ * foreground color should be used instead (to be set up by the
+ * application outside of FreeType).
+ */
+ typedef struct FT_Glyph_LayerRec_
+ {
+ FT_UShort glyph_index;
+ FT_UShort color_index;
+
+ } FT_Glyph_LayerRec;
+
+
+ /*************************************************************************
+ *
+ * @func:
+ * FT_Get_GlyphLayers
+ *
+ * @description:
+ * This is an interface to the `COLR' table in OpenType fonts to
+ * retrieve the colored glyph layers array associated with the current
+ * glyph slot.
+ *
+ * https://docs.microsoft.com/en-us/typography/opentype/spec/colr
+ *
+ * The glyph layer data for a given glyph slot, if present, provides an
+ * alternative, multi-colour glyph representation: Instead of rendering
+ * the outline or bitmap in the glyph slot, glyphs with the indices and
+ * colors returned in the @FT_GlyphLayer array are rendered layer by
+ * layer.
+ *
+ * @input:
+ * glyph ::
+ * The source glyph slot.
+ *
+ * @output:
+ * anum_layers ::
+ * The number of colored glyph layers for `glyph'.
+ *
+ * alayers ::
+ * An @FT_GlyphLayer array with `anum_layers' elements. NULL if there
+ * aren't glyph layers.
+ *
+ * The elements are ordered in the z~direction from bottom to top; an
+ * element `n' should be rendered with the associated palette color
+ * and blended on top of the already rendered layers (elements 0, 1,
+ * ..., n-1).
+ *
+ * @return:
+ * FreeType error code. 0~means success.
+ *
+ * @note:
+ * The data in `alayers' is owned and managed by the glyph slot.
+ *
+ * This function is necessary if you want to handle glyph layers by
+ * yourself. In particular, functions that operate with @FT_GlyphRec
+ * objects (like @FT_Get_Glyph or @FT_Glyph_To_Bitmap) don't have access
+ * to this information.
+ *
+ * @FT_Render_Glyph, however, handles colored glyph layers
+ * automatically.
+ */
+ FT_EXPORT( FT_Error )
+ FT_Get_GlyphLayers( FT_GlyphSlot glyph,
+ FT_UShort *anum_layers,
+ FT_Glyph_Layer *alayers );
+
+
/*************************************************************************/
/* */
/* <Enum> */
diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h
index 3013883..a8d987f 100644
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -384,19 +384,11 @@ FT_BEGIN_HEADER
} FT_Face_InternalRec;
- typedef struct FT_Glyph_LayerRec_
- {
- FT_UShort glyph_index;
- FT_UShort color_index;
-
- } FT_Glyph_LayerRec;
-
-
typedef struct FT_Colr_InternalRec_
{
- FT_Glyph_LayerRec* layers;
- FT_UShort num_layers;
- FT_Int load_flags;
+ FT_Glyph_Layer layers;
+ FT_UShort num_layers;
+ FT_Int load_flags;
} FT_Colr_InternalRec, *FT_Colr_Internal;
diff --git a/include/freetype/internal/sfnt.h b/include/freetype/internal/sfnt.h
index f543535..d28b682 100644
--- a/include/freetype/internal/sfnt.h
+++ b/include/freetype/internal/sfnt.h
@@ -452,10 +452,10 @@ FT_BEGIN_HEADER
/* color layer information exists for `idx'. */
/* */
typedef FT_Error
- (*TT_Load_Colr_Layer_Func)( TT_Face face,
- FT_Int idx,
- FT_Glyph_LayerRec* *layers,
- FT_UShort* num_layers );
+ (*TT_Load_Colr_Layer_Func)( TT_Face face,
+ FT_Int idx,
+ FT_Glyph_Layer *layers,
+ FT_UShort* num_layers );
/*************************************************************************/
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 05e2a03..d7768dd 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -4531,8 +4531,8 @@
TT_Face ttface = (TT_Face)face;
SFNT_Service sfnt = (SFNT_Service)ttface->sfnt;
- FT_Glyph_LayerRec* glyph_layers =
- slot->internal->color_layers->layers;
+ FT_Glyph_Layer glyph_layers =
+ slot->internal->color_layers->layers;
FT_Int idx;
@@ -5461,4 +5461,29 @@
}
+ /* documentation is in freetype.h */
+
+ FT_EXPORT_DEF( FT_Error )
+ FT_Get_GlyphLayers( FT_GlyphSlot glyph,
+ FT_UShort *anum_layers,
+ FT_Glyph_Layer *alayers )
+ {
+ if ( !glyph )
+ return FT_THROW( Invalid_Argument );
+
+ if ( glyph->internal->color_layers )
+ {
+ *anum_layers = glyph->internal->color_layers->num_layers;
+ *alayers = glyph->internal->color_layers->layers;
+ }
+ else
+ {
+ *anum_layers = 0;
+ *alayers = NULL;
+ }
+
+ return FT_Err_Ok;
+ }
+
+
/* END */
diff --git a/src/sfnt/ttcolr.c b/src/sfnt/ttcolr.c
index 67d320b..24d350e 100644
--- a/src/sfnt/ttcolr.c
+++ b/src/sfnt/ttcolr.c
@@ -290,10 +290,10 @@
FT_LOCAL_DEF( FT_Error )
- tt_face_load_colr_layers( TT_Face face,
- FT_Int glyph_id,
- FT_Glyph_LayerRec* *ret_layers,
- FT_UShort* ret_num_layers )
+ tt_face_load_colr_layers( TT_Face face,
+ FT_Int glyph_id,
+ FT_Glyph_Layer *ret_layers,
+ FT_UShort* ret_num_layers )
{
FT_Error error;
FT_Memory memory = face->root.memory;
@@ -302,10 +302,10 @@
Colr* colr = &colr_and_cpal->colr;
Cpal* cpal = &colr_and_cpal->cpal;
- BaseGlyphRecord glyph_record;
- FT_Glyph_LayerRec* layers;
- int layer_idx;
- FT_Byte* layer_record_ptr;
+ BaseGlyphRecord glyph_record;
+ FT_Glyph_Layer layers;
+ int layer_idx;
+ FT_Byte* layer_record_ptr;
if ( !ret_layers || !ret_num_layers )
diff --git a/src/sfnt/ttcolr.h b/src/sfnt/ttcolr.h
index 84062c0..1c58153 100644
--- a/src/sfnt/ttcolr.h
+++ b/src/sfnt/ttcolr.h
@@ -37,10 +37,10 @@ FT_BEGIN_HEADER
tt_face_free_colr( TT_Face face );
FT_LOCAL( FT_Error )
- tt_face_load_colr_layers( TT_Face face,
- FT_Int glyph_id,
- FT_Glyph_LayerRec* *ret_layers,
- FT_UShort* ret_num_layers );
+ tt_face_load_colr_layers( TT_Face face,
+ FT_Int glyph_id,
+ FT_Glyph_Layer *ret_layers,
+ FT_UShort* ret_num_layers );
FT_LOCAL( FT_Error )
tt_face_colr_blend_layer( TT_Face face,
diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c
index 0bd9af7..95ba68d 100644
--- a/src/truetype/ttgload.c
+++ b/src/truetype/ttgload.c
@@ -2894,15 +2894,15 @@
/* The outline based algorithm took care of metrics. */
/* Read additional color info if requested. */
- if ( ( load_flags & FT_LOAD_COLOR ) &&
- ( (TT_Face)(glyph->face) )->colr_and_cpal )
+ if ( ( load_flags & FT_LOAD_COLOR ) &&
+ ( (TT_Face)glyph->face )->colr_and_cpal )
{
TT_Face face = (TT_Face)glyph->face;
FT_Memory memory = face->root.memory;
SFNT_Service sfnt = (SFNT_Service)face->sfnt;
- FT_Glyph_LayerRec* glyph_layers;
- FT_UShort num_glyph_layers;
+ FT_Glyph_Layer glyph_layers;
+ FT_UShort num_glyph_layers;
error = sfnt->load_colr_layer( face,