2018-06-03 09:01:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* ttcolr.c
|
|
|
|
*
|
2018-06-14 11:32:47 +02:00
|
|
|
* TrueType and OpenType colored glyph layer support (body).
|
2018-06-03 09:01:17 +02:00
|
|
|
*
|
2021-01-17 07:18:48 +01:00
|
|
|
* Copyright (C) 2018-2021 by
|
2020-12-16 15:44:34 +01:00
|
|
|
* David Turner, Robert Wilhelm, Dominik Röttsches, and Werner Lemberg.
|
2018-06-03 09:01:17 +02:00
|
|
|
*
|
2018-06-14 11:32:47 +02:00
|
|
|
* Originally written by Shao Yu Zhang <shaozhang@fb.com>.
|
2018-06-03 09:01:17 +02:00
|
|
|
*
|
|
|
|
* This file is part of the FreeType project, and may only be used,
|
|
|
|
* modified, and distributed under the terms of the FreeType project
|
|
|
|
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
|
|
|
* this file you indicate that you have read the license and
|
|
|
|
* understand and accept it fully.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
2018-06-14 11:32:47 +02:00
|
|
|
* `COLR' table specification:
|
2018-06-03 09:01:17 +02:00
|
|
|
*
|
|
|
|
* https://www.microsoft.com/typography/otspec/colr.htm
|
|
|
|
*
|
|
|
|
*/
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
|
|
|
|
|
2020-06-08 13:31:55 +02:00
|
|
|
#include <freetype/internal/ftdebug.h>
|
|
|
|
#include <freetype/internal/ftstream.h>
|
|
|
|
#include <freetype/tttags.h>
|
|
|
|
#include <freetype/ftcolor.h>
|
2020-12-16 15:44:34 +01:00
|
|
|
#include <freetype/config/integer-types.h>
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef TT_CONFIG_OPTION_COLOR_LAYERS
|
|
|
|
|
|
|
|
#include "ttcolr.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* NOTE: These are the table sizes calculated through the specs. */
|
2020-12-16 15:44:34 +01:00
|
|
|
#define BASE_GLYPH_SIZE 6U
|
2021-06-28 15:29:49 +02:00
|
|
|
#define BASE_GLYPH_PAINT_RECORD_SIZE 6U
|
2020-12-16 15:44:34 +01:00
|
|
|
#define LAYER_V1_LIST_PAINT_OFFSET_SIZE 4U
|
|
|
|
#define LAYER_V1_LIST_NUM_LAYERS_SIZE 4U
|
|
|
|
#define COLOR_STOP_SIZE 6U
|
|
|
|
#define LAYER_SIZE 4U
|
|
|
|
#define COLR_HEADER_SIZE 14U
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
|
|
|
|
|
2021-06-22 14:01:19 +02:00
|
|
|
typedef enum FT_PaintFormat_Internal_
|
|
|
|
{
|
|
|
|
FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER = 18,
|
|
|
|
FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM = 20,
|
|
|
|
FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM_CENTER = 22,
|
|
|
|
FT_COLR_PAINTFORMAT_INTERNAL_ROTATE_CENTER = 26,
|
|
|
|
FT_COLR_PAINTFORMAT_INTERNAL_SKEW_CENTER = 30
|
|
|
|
|
|
|
|
} FT_PaintFormat_Internal;
|
|
|
|
|
|
|
|
|
2020-12-16 15:44:34 +01:00
|
|
|
typedef struct BaseGlyphRecord_
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
{
|
|
|
|
FT_UShort gid;
|
|
|
|
FT_UShort first_layer_index;
|
|
|
|
FT_UShort num_layers;
|
|
|
|
|
|
|
|
} BaseGlyphRecord;
|
|
|
|
|
|
|
|
|
2020-12-16 15:44:34 +01:00
|
|
|
typedef struct BaseGlyphV1Record_
|
|
|
|
{
|
|
|
|
FT_UShort gid;
|
|
|
|
/* Offset from start of BaseGlyphV1List, i.e., from base_glyphs_v1. */
|
|
|
|
FT_ULong paint_offset;
|
|
|
|
|
|
|
|
} BaseGlyphV1Record;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct Colr_
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
{
|
2018-06-13 08:46:27 +02:00
|
|
|
FT_UShort version;
|
|
|
|
FT_UShort num_base_glyphs;
|
|
|
|
FT_UShort num_layers;
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
|
2018-06-13 08:46:27 +02:00
|
|
|
FT_Byte* base_glyphs;
|
|
|
|
FT_Byte* layers;
|
|
|
|
|
2020-12-16 15:44:34 +01:00
|
|
|
FT_ULong num_base_glyphs_v1;
|
|
|
|
/* Points at beginning of BaseGlyphV1List. */
|
|
|
|
FT_Byte* base_glyphs_v1;
|
|
|
|
|
|
|
|
FT_ULong num_layers_v1;
|
|
|
|
FT_Byte* layers_v1;
|
|
|
|
|
2021-06-28 15:29:49 +02:00
|
|
|
/*
|
|
|
|
* Paint tables start at the minimum of the end of the LayerList and the
|
|
|
|
* end of the BaseGlyphList. Record this location in a field here for
|
|
|
|
* safety checks when accessing paint tables.
|
|
|
|
*/
|
|
|
|
FT_Byte* paints_start_v1;
|
|
|
|
|
2020-12-16 15:44:34 +01:00
|
|
|
/* The memory that backs up the `COLR' table. */
|
2018-06-16 22:16:03 +02:00
|
|
|
void* table;
|
|
|
|
FT_ULong table_size;
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
|
2018-06-13 08:46:27 +02:00
|
|
|
} Colr;
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
|
|
|
|
|
2018-06-03 09:01:17 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* The macro FT_COMPONENT is used in trace mode. It is an implicit
|
|
|
|
* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
|
|
|
|
* messages during execution.
|
|
|
|
*/
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
#undef FT_COMPONENT
|
2018-08-15 18:13:17 +02:00
|
|
|
#define FT_COMPONENT ttcolr
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
|
|
|
|
|
2018-06-13 08:46:27 +02:00
|
|
|
FT_LOCAL_DEF( FT_Error )
|
|
|
|
tt_face_load_colr( TT_Face face,
|
|
|
|
FT_Stream stream )
|
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
FT_Memory memory = face->root.memory;
|
|
|
|
|
|
|
|
FT_Byte* table = NULL;
|
|
|
|
FT_Byte* p = NULL;
|
2020-12-16 15:44:34 +01:00
|
|
|
/* Needed for reading array lengths in referenced tables. */
|
|
|
|
FT_Byte* p1 = NULL;
|
2018-06-13 08:46:27 +02:00
|
|
|
|
|
|
|
Colr* colr = NULL;
|
|
|
|
|
|
|
|
FT_ULong base_glyph_offset, layer_offset;
|
2020-12-16 15:44:34 +01:00
|
|
|
FT_ULong base_glyphs_offset_v1, num_base_glyphs_v1;
|
|
|
|
FT_ULong layer_offset_v1, num_layers_v1;
|
2018-06-13 08:46:27 +02:00
|
|
|
FT_ULong table_size;
|
|
|
|
|
|
|
|
|
|
|
|
/* `COLR' always needs `CPAL' */
|
|
|
|
if ( !face->cpal )
|
|
|
|
return FT_THROW( Invalid_File_Format );
|
|
|
|
|
|
|
|
error = face->goto_table( face, TTAG_COLR, stream, &table_size );
|
|
|
|
if ( error )
|
|
|
|
goto NoColr;
|
|
|
|
|
|
|
|
if ( table_size < COLR_HEADER_SIZE )
|
|
|
|
goto InvalidTable;
|
|
|
|
|
|
|
|
if ( FT_FRAME_EXTRACT( table_size, table ) )
|
|
|
|
goto NoColr;
|
|
|
|
|
|
|
|
p = table;
|
|
|
|
|
|
|
|
if ( FT_NEW( colr ) )
|
|
|
|
goto NoColr;
|
|
|
|
|
|
|
|
colr->version = FT_NEXT_USHORT( p );
|
2020-12-16 15:44:34 +01:00
|
|
|
if ( colr->version != 0 && colr->version != 1 )
|
2018-06-13 08:46:27 +02:00
|
|
|
goto InvalidTable;
|
|
|
|
|
|
|
|
colr->num_base_glyphs = FT_NEXT_USHORT( p );
|
|
|
|
base_glyph_offset = FT_NEXT_ULONG( p );
|
|
|
|
|
|
|
|
if ( base_glyph_offset >= table_size )
|
|
|
|
goto InvalidTable;
|
|
|
|
if ( colr->num_base_glyphs * BASE_GLYPH_SIZE >
|
|
|
|
table_size - base_glyph_offset )
|
|
|
|
goto InvalidTable;
|
|
|
|
|
|
|
|
layer_offset = FT_NEXT_ULONG( p );
|
|
|
|
colr->num_layers = FT_NEXT_USHORT( p );
|
|
|
|
|
|
|
|
if ( layer_offset >= table_size )
|
|
|
|
goto InvalidTable;
|
|
|
|
if ( colr->num_layers * LAYER_SIZE > table_size - layer_offset )
|
|
|
|
goto InvalidTable;
|
|
|
|
|
2020-12-16 15:44:34 +01:00
|
|
|
if ( colr->version == 1 )
|
|
|
|
{
|
|
|
|
base_glyphs_offset_v1 = FT_NEXT_ULONG( p );
|
|
|
|
|
|
|
|
if ( base_glyphs_offset_v1 >= table_size )
|
|
|
|
goto InvalidTable;
|
|
|
|
|
|
|
|
p1 = (FT_Byte*)( table + base_glyphs_offset_v1 );
|
|
|
|
num_base_glyphs_v1 = FT_PEEK_ULONG( p1 );
|
|
|
|
|
2021-06-28 15:29:49 +02:00
|
|
|
if ( num_base_glyphs_v1 * BASE_GLYPH_PAINT_RECORD_SIZE >
|
2020-12-16 15:44:34 +01:00
|
|
|
table_size - base_glyphs_offset_v1 )
|
|
|
|
goto InvalidTable;
|
|
|
|
|
|
|
|
colr->num_base_glyphs_v1 = num_base_glyphs_v1;
|
|
|
|
colr->base_glyphs_v1 = p1;
|
|
|
|
|
|
|
|
layer_offset_v1 = FT_NEXT_ULONG( p );
|
|
|
|
|
2021-06-29 19:51:32 +02:00
|
|
|
if ( layer_offset_v1 >= table_size )
|
2020-12-16 15:44:34 +01:00
|
|
|
goto InvalidTable;
|
|
|
|
|
2021-06-29 19:51:32 +02:00
|
|
|
if ( layer_offset_v1 )
|
|
|
|
{
|
|
|
|
p1 = (FT_Byte*)( table + layer_offset_v1 );
|
|
|
|
num_layers_v1 = FT_PEEK_ULONG( p1 );
|
|
|
|
|
|
|
|
if ( num_layers_v1 * LAYER_V1_LIST_PAINT_OFFSET_SIZE >
|
|
|
|
table_size - layer_offset_v1 )
|
|
|
|
goto InvalidTable;
|
|
|
|
|
|
|
|
colr->num_layers_v1 = num_layers_v1;
|
|
|
|
colr->layers_v1 = p1;
|
|
|
|
|
|
|
|
colr->paints_start_v1 =
|
|
|
|
FT_MIN( colr->base_glyphs_v1 +
|
|
|
|
colr->num_base_glyphs_v1 * BASE_GLYPH_PAINT_RECORD_SIZE,
|
|
|
|
colr->layers_v1 +
|
|
|
|
colr->num_layers_v1 * LAYER_V1_LIST_PAINT_OFFSET_SIZE );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
colr->num_layers_v1 = 0;
|
|
|
|
colr->layers_v1 = 0;
|
|
|
|
colr->paints_start_v1 =
|
|
|
|
colr->base_glyphs_v1 +
|
|
|
|
colr->num_base_glyphs_v1 * BASE_GLYPH_PAINT_RECORD_SIZE;
|
|
|
|
}
|
2020-12-16 15:44:34 +01:00
|
|
|
}
|
|
|
|
|
2018-06-13 08:46:27 +02:00
|
|
|
colr->base_glyphs = (FT_Byte*)( table + base_glyph_offset );
|
|
|
|
colr->layers = (FT_Byte*)( table + layer_offset );
|
|
|
|
colr->table = table;
|
2018-06-16 22:16:03 +02:00
|
|
|
colr->table_size = table_size;
|
2018-06-13 08:46:27 +02:00
|
|
|
|
|
|
|
face->colr = colr;
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
|
|
|
|
InvalidTable:
|
|
|
|
error = FT_THROW( Invalid_Table );
|
|
|
|
|
|
|
|
NoColr:
|
|
|
|
FT_FRAME_RELEASE( table );
|
|
|
|
FT_FREE( colr );
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FT_LOCAL_DEF( void )
|
|
|
|
tt_face_free_colr( TT_Face face )
|
|
|
|
{
|
|
|
|
FT_Stream stream = face->root.stream;
|
|
|
|
FT_Memory memory = face->root.memory;
|
|
|
|
|
|
|
|
Colr* colr = (Colr*)face->colr;
|
|
|
|
|
|
|
|
|
|
|
|
if ( colr )
|
|
|
|
{
|
|
|
|
FT_FRAME_RELEASE( colr->table );
|
|
|
|
FT_FREE( colr );
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static FT_Bool
|
|
|
|
find_base_glyph_record( FT_Byte* base_glyph_begin,
|
2021-05-29 09:50:29 +02:00
|
|
|
FT_UInt num_base_glyph,
|
2018-05-30 09:34:57 +02:00
|
|
|
FT_UInt glyph_id,
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
BaseGlyphRecord* record )
|
|
|
|
{
|
2021-05-29 09:50:29 +02:00
|
|
|
FT_UInt min = 0;
|
2021-06-01 21:25:31 +02:00
|
|
|
FT_UInt max = num_base_glyph;
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
|
|
|
|
|
2021-06-01 21:25:31 +02:00
|
|
|
while ( min < max )
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
{
|
2021-05-29 09:50:29 +02:00
|
|
|
FT_UInt mid = min + ( max - min ) / 2;
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
FT_Byte* p = base_glyph_begin + mid * BASE_GLYPH_SIZE;
|
|
|
|
|
2018-05-15 17:01:22 +02:00
|
|
|
FT_UShort gid = FT_NEXT_USHORT( p );
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
if ( gid < glyph_id )
|
|
|
|
min = mid + 1;
|
|
|
|
else if (gid > glyph_id )
|
2021-06-01 21:25:31 +02:00
|
|
|
max = mid;
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
record->gid = gid;
|
|
|
|
record->first_layer_index = FT_NEXT_USHORT( p );
|
|
|
|
record->num_layers = FT_NEXT_USHORT( p );
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-02 11:41:44 +02:00
|
|
|
FT_LOCAL_DEF( FT_Bool )
|
2018-06-14 21:02:49 +02:00
|
|
|
tt_face_get_colr_layer( TT_Face face,
|
|
|
|
FT_UInt base_glyph,
|
2018-07-02 11:41:44 +02:00
|
|
|
FT_UInt *aglyph_index,
|
2018-06-14 21:02:49 +02:00
|
|
|
FT_UInt *acolor_index,
|
|
|
|
FT_LayerIterator* iterator )
|
|
|
|
{
|
2018-07-02 11:41:44 +02:00
|
|
|
Colr* colr = (Colr*)face->colr;
|
2018-06-14 21:02:49 +02:00
|
|
|
BaseGlyphRecord glyph_record;
|
|
|
|
|
|
|
|
|
2018-06-19 07:15:21 +02:00
|
|
|
if ( !colr )
|
|
|
|
return 0;
|
|
|
|
|
2018-06-14 21:02:49 +02:00
|
|
|
if ( !iterator->p )
|
|
|
|
{
|
2018-06-16 22:16:03 +02:00
|
|
|
FT_ULong offset;
|
|
|
|
|
|
|
|
|
2018-06-14 21:02:49 +02:00
|
|
|
/* first call to function */
|
|
|
|
iterator->layer = 0;
|
|
|
|
|
|
|
|
if ( !find_base_glyph_record( colr->base_glyphs,
|
|
|
|
colr->num_base_glyphs,
|
|
|
|
base_glyph,
|
|
|
|
&glyph_record ) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ( glyph_record.num_layers )
|
|
|
|
iterator->num_layers = glyph_record.num_layers;
|
|
|
|
else
|
|
|
|
return 0;
|
2018-06-16 22:16:03 +02:00
|
|
|
|
|
|
|
offset = LAYER_SIZE * glyph_record.first_layer_index;
|
|
|
|
if ( offset + LAYER_SIZE * glyph_record.num_layers > colr->table_size )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
iterator->p = colr->layers + offset;
|
2018-06-14 21:02:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( iterator->layer >= iterator->num_layers )
|
|
|
|
return 0;
|
|
|
|
|
2018-07-02 11:41:44 +02:00
|
|
|
*aglyph_index = FT_NEXT_USHORT( iterator->p );
|
2018-06-14 21:02:49 +02:00
|
|
|
*acolor_index = FT_NEXT_USHORT( iterator->p );
|
|
|
|
|
2018-07-04 11:49:47 +02:00
|
|
|
if ( *aglyph_index >= (FT_UInt)( FT_FACE( face )->num_glyphs ) ||
|
2018-06-14 21:02:49 +02:00
|
|
|
( *acolor_index != 0xFFFF &&
|
|
|
|
*acolor_index >= face->palette_data.num_palette_entries ) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
iterator->layer++;
|
|
|
|
|
2018-07-02 11:41:44 +02:00
|
|
|
return 1;
|
2018-06-14 21:02:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-16 15:52:24 +01:00
|
|
|
static FT_Bool
|
2021-04-02 06:55:29 +02:00
|
|
|
read_color_line( FT_Byte* color_line_p,
|
2020-12-16 15:52:24 +01:00
|
|
|
FT_ColorLine *colorline )
|
|
|
|
{
|
2021-04-02 06:55:29 +02:00
|
|
|
FT_Byte* p = color_line_p;
|
2020-12-16 15:52:24 +01:00
|
|
|
FT_PaintExtend paint_extend;
|
|
|
|
|
|
|
|
|
2021-05-29 09:50:29 +02:00
|
|
|
paint_extend = (FT_PaintExtend)FT_NEXT_BYTE( p );
|
2020-12-16 15:52:24 +01:00
|
|
|
if ( paint_extend > FT_COLR_PAINT_EXTEND_REFLECT )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
colorline->extend = paint_extend;
|
|
|
|
|
|
|
|
colorline->color_stop_iterator.num_color_stops = FT_NEXT_USHORT( p );
|
|
|
|
colorline->color_stop_iterator.p = p;
|
|
|
|
colorline->color_stop_iterator.current_color_stop = 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-02 06:55:29 +02:00
|
|
|
/*
|
|
|
|
* Read a paint offset for `FT_Paint*` objects that have them and check
|
|
|
|
* whether it is within reasonable limits within the font and the COLR
|
|
|
|
* table.
|
|
|
|
*
|
|
|
|
* Return 1 on success, 0 on failure.
|
|
|
|
*/
|
|
|
|
static FT_Bool
|
|
|
|
get_child_table_pointer ( Colr* colr,
|
|
|
|
FT_Byte* paint_base,
|
|
|
|
FT_Byte** p,
|
|
|
|
FT_Byte** child_table_pointer )
|
|
|
|
{
|
|
|
|
FT_UInt32 paint_offset;
|
|
|
|
FT_Byte* child_table_p;
|
|
|
|
|
|
|
|
|
|
|
|
if ( !child_table_pointer )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
paint_offset = FT_NEXT_UOFF3( *p );
|
|
|
|
if ( !paint_offset )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
child_table_p = (FT_Byte*)( paint_base + paint_offset );
|
|
|
|
|
2021-06-28 15:29:49 +02:00
|
|
|
if ( child_table_p < colr->paints_start_v1 ||
|
2021-04-02 06:55:29 +02:00
|
|
|
child_table_p >= ( (FT_Byte*)colr->table + colr->table_size ) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*child_table_pointer = child_table_p;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-16 15:52:24 +01:00
|
|
|
static FT_Bool
|
|
|
|
read_paint( Colr* colr,
|
|
|
|
FT_Byte* p,
|
|
|
|
FT_COLR_Paint* apaint )
|
|
|
|
{
|
2021-04-02 06:55:29 +02:00
|
|
|
FT_Byte* paint_base = p;
|
|
|
|
FT_Byte* child_table_p = NULL;
|
2020-12-16 15:52:24 +01:00
|
|
|
|
|
|
|
|
2021-04-02 06:55:29 +02:00
|
|
|
if ( !p || !colr || !colr->table )
|
|
|
|
return 0;
|
|
|
|
|
2021-06-28 15:29:49 +02:00
|
|
|
if ( p < colr->paints_start_v1 ||
|
2021-04-16 11:35:29 +02:00
|
|
|
p >= ( (FT_Byte*)colr->table + colr->table_size ) )
|
2021-04-19 11:49:16 +02:00
|
|
|
return 0;
|
2021-04-16 11:35:29 +02:00
|
|
|
|
2021-05-29 09:50:29 +02:00
|
|
|
apaint->format = (FT_PaintFormat)FT_NEXT_BYTE( p );
|
2020-12-16 15:52:24 +01:00
|
|
|
|
|
|
|
if ( apaint->format >= FT_COLR_PAINT_FORMAT_MAX )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ( apaint->format == FT_COLR_PAINTFORMAT_COLR_LAYERS )
|
|
|
|
{
|
|
|
|
/* Initialize layer iterator/ */
|
|
|
|
FT_Byte num_layers;
|
|
|
|
FT_UInt32 first_layer_index;
|
|
|
|
|
|
|
|
|
|
|
|
num_layers = FT_NEXT_BYTE( p );
|
|
|
|
if ( num_layers > colr->num_layers_v1 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
first_layer_index = FT_NEXT_ULONG( p );
|
|
|
|
if ( first_layer_index + num_layers > colr->num_layers_v1 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
apaint->u.colr_layers.layer_iterator.num_layers = num_layers;
|
|
|
|
apaint->u.colr_layers.layer_iterator.layer = 0;
|
|
|
|
/* TODO: Check whether pointer is outside colr? */
|
|
|
|
apaint->u.colr_layers.layer_iterator.p =
|
|
|
|
colr->layers_v1 +
|
|
|
|
LAYER_V1_LIST_NUM_LAYERS_SIZE +
|
|
|
|
LAYER_V1_LIST_PAINT_OFFSET_SIZE * first_layer_index;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ( apaint->format == FT_COLR_PAINTFORMAT_SOLID )
|
|
|
|
{
|
2021-05-29 09:50:29 +02:00
|
|
|
apaint->u.solid.color.palette_index = FT_NEXT_USHORT( p );
|
|
|
|
apaint->u.solid.color.alpha = FT_NEXT_SHORT( p );
|
2021-04-02 06:55:29 +02:00
|
|
|
|
|
|
|
return 1;
|
2020-12-16 15:52:24 +01:00
|
|
|
}
|
|
|
|
|
2021-04-02 06:55:29 +02:00
|
|
|
else if ( apaint->format == FT_COLR_PAINTFORMAT_COLR_GLYPH )
|
2020-12-16 15:52:24 +01:00
|
|
|
{
|
2021-04-02 06:55:29 +02:00
|
|
|
apaint->u.colr_glyph.glyphID = FT_NEXT_USHORT( p );
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grouped below here are all paint formats that have an offset to a
|
|
|
|
* child paint table as the first entry (for example, a color line or a
|
|
|
|
* child paint table). Retrieve that and determine whether that paint
|
|
|
|
* offset is valid first.
|
|
|
|
*/
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-04-02 06:55:29 +02:00
|
|
|
if ( !get_child_table_pointer( colr, paint_base, &p, &child_table_p ) )
|
|
|
|
return 0;
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-04-02 06:55:29 +02:00
|
|
|
if ( apaint->format == FT_COLR_PAINTFORMAT_LINEAR_GRADIENT )
|
|
|
|
{
|
|
|
|
if ( !read_color_line( child_table_p,
|
2020-12-16 15:52:24 +01:00
|
|
|
&apaint->u.linear_gradient.colorline ) )
|
|
|
|
return 0;
|
|
|
|
|
2021-05-29 09:50:29 +02:00
|
|
|
apaint->u.linear_gradient.p0.x = FT_NEXT_SHORT( p );
|
|
|
|
apaint->u.linear_gradient.p0.y = FT_NEXT_SHORT( p );
|
|
|
|
apaint->u.linear_gradient.p1.x = FT_NEXT_SHORT( p );
|
|
|
|
apaint->u.linear_gradient.p1.y = FT_NEXT_SHORT( p );
|
|
|
|
apaint->u.linear_gradient.p2.x = FT_NEXT_SHORT( p );
|
|
|
|
apaint->u.linear_gradient.p2.y = FT_NEXT_SHORT( p );
|
2021-04-02 06:55:29 +02:00
|
|
|
|
|
|
|
return 1;
|
2020-12-16 15:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
else if ( apaint->format == FT_COLR_PAINTFORMAT_RADIAL_GRADIENT )
|
|
|
|
{
|
2021-04-02 06:55:29 +02:00
|
|
|
if ( !read_color_line( child_table_p,
|
2021-02-10 18:24:13 +01:00
|
|
|
&apaint->u.radial_gradient.colorline ) )
|
2020-12-16 15:52:24 +01:00
|
|
|
return 0;
|
|
|
|
|
2021-05-29 09:50:29 +02:00
|
|
|
apaint->u.radial_gradient.c0.x = FT_NEXT_SHORT( p );
|
|
|
|
apaint->u.radial_gradient.c0.y = FT_NEXT_SHORT( p );
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-05-29 09:50:29 +02:00
|
|
|
apaint->u.radial_gradient.r0 = FT_NEXT_USHORT( p );
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-05-29 09:50:29 +02:00
|
|
|
apaint->u.radial_gradient.c1.x = FT_NEXT_SHORT( p );
|
|
|
|
apaint->u.radial_gradient.c1.y = FT_NEXT_SHORT( p );
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-05-29 09:50:29 +02:00
|
|
|
apaint->u.radial_gradient.r1 = FT_NEXT_USHORT( p );
|
2021-04-02 06:55:29 +02:00
|
|
|
|
|
|
|
return 1;
|
2020-12-16 15:52:24 +01:00
|
|
|
}
|
|
|
|
|
2021-02-10 18:24:13 +01:00
|
|
|
else if ( apaint->format == FT_COLR_PAINTFORMAT_SWEEP_GRADIENT )
|
|
|
|
{
|
2021-04-02 06:55:29 +02:00
|
|
|
if ( !read_color_line( child_table_p,
|
2021-02-10 18:24:13 +01:00
|
|
|
&apaint->u.sweep_gradient.colorline ) )
|
|
|
|
return 0;
|
|
|
|
|
2021-05-29 09:50:29 +02:00
|
|
|
apaint->u.sweep_gradient.center.x = FT_NEXT_SHORT( p );
|
|
|
|
apaint->u.sweep_gradient.center.y = FT_NEXT_SHORT( p );
|
2021-02-10 18:24:13 +01:00
|
|
|
|
|
|
|
apaint->u.sweep_gradient.start_angle = FT_NEXT_LONG( p );
|
|
|
|
apaint->u.sweep_gradient.end_angle = FT_NEXT_LONG( p );
|
2021-04-02 06:55:29 +02:00
|
|
|
|
|
|
|
return 1;
|
2021-02-10 18:24:13 +01:00
|
|
|
}
|
|
|
|
|
2021-04-02 06:55:29 +02:00
|
|
|
if ( apaint->format == FT_COLR_PAINTFORMAT_GLYPH )
|
2020-12-16 15:52:24 +01:00
|
|
|
{
|
2021-04-02 06:55:29 +02:00
|
|
|
apaint->u.glyph.paint.p = child_table_p;
|
|
|
|
apaint->u.glyph.paint.insert_root_transform = 0;
|
|
|
|
apaint->u.glyph.glyphID = FT_NEXT_USHORT( p );
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-04-02 06:55:29 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-06-22 20:50:48 +02:00
|
|
|
else if ( apaint->format == FT_COLR_PAINTFORMAT_TRANSFORM )
|
2021-04-02 06:55:29 +02:00
|
|
|
{
|
2021-06-22 20:50:48 +02:00
|
|
|
apaint->u.transform.paint.p = child_table_p;
|
|
|
|
apaint->u.transform.paint.insert_root_transform = 0;
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-06-22 20:50:48 +02:00
|
|
|
apaint->u.transform.affine.xx = FT_NEXT_LONG( p );
|
|
|
|
apaint->u.transform.affine.yx = FT_NEXT_LONG( p );
|
|
|
|
apaint->u.transform.affine.xy = FT_NEXT_LONG( p );
|
|
|
|
apaint->u.transform.affine.yy = FT_NEXT_LONG( p );
|
|
|
|
apaint->u.transform.affine.dx = FT_NEXT_LONG( p );
|
|
|
|
apaint->u.transform.affine.dy = FT_NEXT_LONG( p );
|
2021-04-02 06:55:29 +02:00
|
|
|
|
|
|
|
return 1;
|
2020-12-16 15:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
else if ( apaint->format == FT_COLR_PAINTFORMAT_TRANSLATE )
|
|
|
|
{
|
2021-04-02 06:55:29 +02:00
|
|
|
apaint->u.translate.paint.p = child_table_p;
|
2021-01-20 12:04:50 +01:00
|
|
|
apaint->u.translate.paint.insert_root_transform = 0;
|
2020-12-16 15:52:24 +01:00
|
|
|
|
|
|
|
apaint->u.translate.dx = FT_NEXT_LONG( p );
|
|
|
|
apaint->u.translate.dy = FT_NEXT_LONG( p );
|
2021-04-02 06:55:29 +02:00
|
|
|
|
|
|
|
return 1;
|
2020-12-16 15:52:24 +01:00
|
|
|
}
|
|
|
|
|
2021-06-22 14:01:19 +02:00
|
|
|
else if ( apaint->format ==
|
|
|
|
FT_COLR_PAINTFORMAT_SCALE ||
|
|
|
|
(FT_PaintFormat_Internal)apaint->format ==
|
|
|
|
FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER ||
|
|
|
|
(FT_PaintFormat_Internal)apaint->format ==
|
|
|
|
FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM ||
|
|
|
|
(FT_PaintFormat_Internal)apaint->format ==
|
|
|
|
FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM_CENTER )
|
|
|
|
{
|
|
|
|
apaint->u.scale.paint.p = child_table_p;
|
|
|
|
apaint->u.scale.paint.insert_root_transform = 0;
|
|
|
|
|
|
|
|
/* All scale paints get at least one scale value. */
|
|
|
|
apaint->u.scale.scale_x = FT_NEXT_LONG( p );
|
|
|
|
|
|
|
|
/* Non-uniform ones read an extra y value. */
|
|
|
|
if ( apaint->format ==
|
|
|
|
FT_COLR_PAINTFORMAT_SCALE ||
|
|
|
|
(FT_PaintFormat_Internal)apaint->format ==
|
|
|
|
FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER )
|
|
|
|
apaint->u.scale.scale_y = FT_NEXT_LONG( p );
|
|
|
|
else
|
|
|
|
apaint->u.scale.scale_y = apaint->u.scale.scale_x;
|
|
|
|
|
|
|
|
/* Scale paints that have a center read center coordinates, */
|
|
|
|
/* otherwise the center is (0,0). */
|
|
|
|
if ( (FT_PaintFormat_Internal)apaint->format ==
|
|
|
|
FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER ||
|
|
|
|
(FT_PaintFormat_Internal)apaint->format ==
|
|
|
|
FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM_CENTER )
|
|
|
|
{
|
|
|
|
apaint->u.scale.center_x = FT_NEXT_LONG ( p );
|
|
|
|
apaint->u.scale.center_y = FT_NEXT_LONG ( p );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
apaint->u.scale.center_x = 0;
|
|
|
|
apaint->u.scale.center_y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FT 'COLR' v1 API output format always returns fully defined */
|
|
|
|
/* structs; we thus set the format to the public API value. */
|
|
|
|
apaint->format = FT_COLR_PAINTFORMAT_SCALE;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-12-16 15:52:24 +01:00
|
|
|
else if ( apaint->format == FT_COLR_PAINTFORMAT_ROTATE )
|
|
|
|
{
|
2021-04-02 06:55:29 +02:00
|
|
|
apaint->u.rotate.paint.p = child_table_p;
|
2021-01-20 12:04:50 +01:00
|
|
|
apaint->u.rotate.paint.insert_root_transform = 0;
|
2020-12-16 15:52:24 +01:00
|
|
|
|
|
|
|
apaint->u.rotate.angle = FT_NEXT_LONG( p );
|
|
|
|
|
|
|
|
apaint->u.rotate.center_x = FT_NEXT_LONG( p );
|
|
|
|
apaint->u.rotate.center_y = FT_NEXT_LONG( p );
|
2021-04-02 06:55:29 +02:00
|
|
|
|
|
|
|
return 1;
|
2020-12-16 15:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
else if ( apaint->format == FT_COLR_PAINTFORMAT_SKEW )
|
|
|
|
{
|
2021-04-02 06:55:29 +02:00
|
|
|
apaint->u.skew.paint.p = child_table_p;
|
2021-01-20 12:04:50 +01:00
|
|
|
apaint->u.skew.paint.insert_root_transform = 0;
|
2020-12-16 15:52:24 +01:00
|
|
|
|
|
|
|
apaint->u.skew.x_skew_angle = FT_NEXT_LONG( p );
|
|
|
|
apaint->u.skew.y_skew_angle = FT_NEXT_LONG( p );
|
|
|
|
|
|
|
|
apaint->u.skew.center_x = FT_NEXT_LONG( p );
|
|
|
|
apaint->u.skew.center_y = FT_NEXT_LONG( p );
|
2021-04-02 06:55:29 +02:00
|
|
|
|
|
|
|
return 1;
|
2020-12-16 15:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
else if ( apaint->format == FT_COLR_PAINTFORMAT_COMPOSITE )
|
|
|
|
{
|
2021-04-02 06:55:29 +02:00
|
|
|
FT_UInt composite_mode;
|
2020-12-16 15:52:24 +01:00
|
|
|
|
|
|
|
|
2021-04-02 06:55:29 +02:00
|
|
|
apaint->u.composite.source_paint.p = child_table_p;
|
|
|
|
apaint->u.composite.source_paint.insert_root_transform = 0;
|
2020-12-16 15:52:24 +01:00
|
|
|
|
|
|
|
composite_mode = FT_NEXT_BYTE( p );
|
|
|
|
if ( composite_mode >= FT_COLR_COMPOSITE_MAX )
|
|
|
|
return 0;
|
|
|
|
|
2021-05-29 09:50:29 +02:00
|
|
|
apaint->u.composite.composite_mode = (FT_Composite_Mode)composite_mode;
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-04-02 06:55:29 +02:00
|
|
|
if ( !get_child_table_pointer( colr, paint_base, &p, &child_table_p ) )
|
|
|
|
return 0;
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-01-20 12:04:50 +01:00
|
|
|
apaint->u.composite.backdrop_paint.p =
|
2021-04-02 06:55:29 +02:00
|
|
|
child_table_p;
|
2021-01-20 12:04:50 +01:00
|
|
|
apaint->u.composite.backdrop_paint.insert_root_transform =
|
|
|
|
0;
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-04-02 06:55:29 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-04-02 06:55:29 +02:00
|
|
|
return 0;
|
2020-12-16 15:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-16 15:44:34 +01:00
|
|
|
static FT_Bool
|
2021-06-01 21:25:31 +02:00
|
|
|
find_base_glyph_v1_record( FT_Byte * base_glyph_begin,
|
|
|
|
FT_UInt num_base_glyph,
|
|
|
|
FT_UInt glyph_id,
|
|
|
|
BaseGlyphV1Record *record )
|
2020-12-16 15:44:34 +01:00
|
|
|
{
|
2021-05-29 09:50:29 +02:00
|
|
|
FT_UInt min = 0;
|
2021-06-01 21:25:31 +02:00
|
|
|
FT_UInt max = num_base_glyph;
|
2020-12-16 15:44:34 +01:00
|
|
|
|
|
|
|
|
2021-06-01 21:25:31 +02:00
|
|
|
while ( min < max )
|
2020-12-16 15:44:34 +01:00
|
|
|
{
|
2021-05-29 09:50:29 +02:00
|
|
|
FT_UInt mid = min + ( max - min ) / 2;
|
2020-12-16 15:44:34 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* `base_glyph_begin` is the beginning of `BaseGlyphV1List`;
|
|
|
|
* skip `numBaseGlyphV1Records` by adding 4 to start binary search
|
|
|
|
* in the array of `BaseGlyphV1Record`.
|
|
|
|
*/
|
2021-06-28 15:29:49 +02:00
|
|
|
FT_Byte *p = base_glyph_begin + 4 + mid * BASE_GLYPH_PAINT_RECORD_SIZE;
|
2020-12-16 15:44:34 +01:00
|
|
|
|
|
|
|
FT_UShort gid = FT_NEXT_USHORT( p );
|
|
|
|
|
|
|
|
|
|
|
|
if ( gid < glyph_id )
|
|
|
|
min = mid + 1;
|
|
|
|
else if (gid > glyph_id )
|
2021-06-01 21:25:31 +02:00
|
|
|
max = mid;
|
2020-12-16 15:44:34 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
record->gid = gid;
|
|
|
|
record->paint_offset = FT_NEXT_ULONG ( p );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-08 18:23:16 +02:00
|
|
|
FT_LOCAL_DEF( FT_Bool )
|
2021-01-20 12:04:50 +01:00
|
|
|
tt_face_get_colr_glyph_paint( TT_Face face,
|
|
|
|
FT_UInt base_glyph,
|
|
|
|
FT_Color_Root_Transform root_transform,
|
|
|
|
FT_OpaquePaint* opaque_paint )
|
2020-12-16 15:44:34 +01:00
|
|
|
{
|
2021-01-20 12:04:50 +01:00
|
|
|
Colr* colr = (Colr*)face->colr;
|
2020-12-16 15:44:34 +01:00
|
|
|
BaseGlyphV1Record base_glyph_v1_record;
|
|
|
|
FT_Byte* p;
|
|
|
|
|
2021-01-20 12:04:50 +01:00
|
|
|
if ( !colr || !colr->table )
|
2021-01-15 10:09:00 +01:00
|
|
|
return 0;
|
|
|
|
|
2020-12-16 15:44:34 +01:00
|
|
|
if ( colr->version < 1 || !colr->num_base_glyphs_v1 ||
|
|
|
|
!colr->base_glyphs_v1 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ( opaque_paint->p )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ( !find_base_glyph_v1_record( colr->base_glyphs_v1,
|
|
|
|
colr->num_base_glyphs_v1,
|
|
|
|
base_glyph,
|
|
|
|
&base_glyph_v1_record ) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ( !base_glyph_v1_record.paint_offset ||
|
|
|
|
base_glyph_v1_record.paint_offset > colr->table_size )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
p = (FT_Byte*)( colr->base_glyphs_v1 +
|
|
|
|
base_glyph_v1_record.paint_offset );
|
|
|
|
if ( p >= ( (FT_Byte*)colr->table + colr->table_size ) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
opaque_paint->p = p;
|
|
|
|
|
2021-01-20 12:04:50 +01:00
|
|
|
if ( root_transform == FT_COLOR_INCLUDE_ROOT_TRANSFORM )
|
|
|
|
opaque_paint->insert_root_transform = 1;
|
|
|
|
else
|
|
|
|
opaque_paint->insert_root_transform = 0;
|
|
|
|
|
2020-12-16 15:44:34 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-16 16:06:42 +01:00
|
|
|
FT_LOCAL_DEF( FT_Bool )
|
|
|
|
tt_face_get_paint_layers( TT_Face face,
|
|
|
|
FT_LayerIterator* iterator,
|
|
|
|
FT_OpaquePaint* opaque_paint )
|
|
|
|
{
|
|
|
|
FT_Byte* p = NULL;
|
|
|
|
FT_Byte* p_first_layer = NULL;
|
2021-04-16 11:35:29 +02:00
|
|
|
FT_Byte* p_paint = NULL;
|
2020-12-16 16:06:42 +01:00
|
|
|
FT_UInt32 paint_offset;
|
|
|
|
|
|
|
|
Colr* colr;
|
|
|
|
|
|
|
|
|
|
|
|
if ( iterator->layer == iterator->num_layers )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
colr = (Colr*)face->colr;
|
|
|
|
if ( !colr )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have an iterator pointing at a paint offset as part of the
|
|
|
|
* `paintOffset` array in `LayerV1List`.
|
|
|
|
*/
|
|
|
|
p = iterator->p;
|
|
|
|
|
2021-06-08 13:29:11 +02:00
|
|
|
/*
|
|
|
|
* First ensure that p is within COLRv1.
|
|
|
|
*/
|
2021-06-28 15:29:49 +02:00
|
|
|
if ( p < colr->layers_v1 ||
|
2021-06-08 13:29:11 +02:00
|
|
|
p >= ( (FT_Byte*)colr->table + colr->table_size ) )
|
|
|
|
return 0;
|
|
|
|
|
2020-12-16 16:06:42 +01:00
|
|
|
/*
|
|
|
|
* Do a cursor sanity check of the iterator. Counting backwards from
|
|
|
|
* where it stands, we need to end up at a position after the beginning
|
|
|
|
* of the `LayerV1List` table and not after the end of the
|
|
|
|
* `LayerV1List`.
|
|
|
|
*/
|
|
|
|
p_first_layer = p -
|
|
|
|
iterator->layer * LAYER_V1_LIST_PAINT_OFFSET_SIZE -
|
|
|
|
LAYER_V1_LIST_NUM_LAYERS_SIZE;
|
|
|
|
if ( p_first_layer < (FT_Byte*)colr->layers_v1 )
|
|
|
|
return 0;
|
|
|
|
if ( p_first_layer >= (FT_Byte*)(
|
|
|
|
colr->layers_v1 + LAYER_V1_LIST_NUM_LAYERS_SIZE +
|
|
|
|
colr->num_layers_v1 * LAYER_V1_LIST_PAINT_OFFSET_SIZE ) )
|
|
|
|
return 0;
|
|
|
|
|
2021-01-20 12:04:50 +01:00
|
|
|
paint_offset =
|
|
|
|
FT_NEXT_ULONG( p );
|
|
|
|
opaque_paint->insert_root_transform =
|
|
|
|
0;
|
2021-04-16 11:35:29 +02:00
|
|
|
|
|
|
|
p_paint = (FT_Byte*)( colr->layers_v1 + paint_offset );
|
|
|
|
|
2021-06-28 15:29:49 +02:00
|
|
|
if ( p_paint < colr->paints_start_v1 ||
|
2021-04-16 11:35:29 +02:00
|
|
|
p_paint >= ( (FT_Byte*)colr->table + colr->table_size ) )
|
2021-04-19 11:49:16 +02:00
|
|
|
return 0;
|
2021-04-16 11:35:29 +02:00
|
|
|
|
|
|
|
opaque_paint->p = p_paint;
|
2020-12-16 16:06:42 +01:00
|
|
|
|
|
|
|
iterator->p = p;
|
|
|
|
|
|
|
|
iterator->layer++;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-08 18:23:16 +02:00
|
|
|
FT_LOCAL_DEF( FT_Bool )
|
2020-12-16 16:02:22 +01:00
|
|
|
tt_face_get_colorline_stops( TT_Face face,
|
|
|
|
FT_ColorStop* color_stop,
|
|
|
|
FT_ColorStopIterator *iterator )
|
|
|
|
{
|
|
|
|
Colr* colr = (Colr*)face->colr;
|
|
|
|
|
|
|
|
FT_Byte* p;
|
|
|
|
|
|
|
|
|
2021-04-02 06:55:29 +02:00
|
|
|
if ( !colr || !colr->table )
|
2021-01-15 10:09:00 +01:00
|
|
|
return 0;
|
|
|
|
|
2020-12-16 16:02:22 +01:00
|
|
|
if ( iterator->current_color_stop >= iterator->num_color_stops )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ( iterator->p +
|
|
|
|
( ( iterator->num_color_stops - iterator->current_color_stop ) *
|
|
|
|
COLOR_STOP_SIZE ) >
|
|
|
|
( (FT_Byte *)colr->table + colr->table_size ) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Iterator points at first `ColorStop` of `ColorLine`. */
|
|
|
|
p = iterator->p;
|
|
|
|
|
2021-05-29 09:50:29 +02:00
|
|
|
color_stop->stop_offset = FT_NEXT_SHORT( p );
|
2020-12-16 16:02:22 +01:00
|
|
|
|
2021-05-29 09:50:29 +02:00
|
|
|
color_stop->color.palette_index = FT_NEXT_USHORT( p );
|
2020-12-16 16:02:22 +01:00
|
|
|
|
2021-05-29 09:50:29 +02:00
|
|
|
color_stop->color.alpha = FT_NEXT_SHORT( p );
|
2020-12-16 16:02:22 +01:00
|
|
|
|
|
|
|
iterator->p = p;
|
|
|
|
iterator->current_color_stop++;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-16 15:52:24 +01:00
|
|
|
FT_LOCAL_DEF( FT_Bool )
|
|
|
|
tt_face_get_paint( TT_Face face,
|
|
|
|
FT_OpaquePaint opaque_paint,
|
|
|
|
FT_COLR_Paint* paint )
|
|
|
|
{
|
2021-01-20 12:04:50 +01:00
|
|
|
Colr* colr = (Colr*)face->colr;
|
|
|
|
FT_OpaquePaint next_paint;
|
|
|
|
FT_Matrix ft_root_scale;
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-01-20 12:04:50 +01:00
|
|
|
if ( !colr || !colr->base_glyphs_v1 || !colr->table )
|
|
|
|
return 0;
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-01-20 12:04:50 +01:00
|
|
|
if ( opaque_paint.insert_root_transform )
|
|
|
|
{
|
|
|
|
/* 'COLR' v1 glyph information is returned in unscaled coordinates,
|
|
|
|
* i.e., `FT_Size` is not applied or multiplied into the values. When
|
|
|
|
* client applications draw color glyphs, they can request to include
|
|
|
|
* a top-level transform, which includes the active `x_scale` and
|
|
|
|
* `y_scale` information for scaling the glyph, as well the additional
|
|
|
|
* transform and translate configured through `FT_Set_Transform`.
|
|
|
|
* This allows client applications to apply this top-level transform
|
|
|
|
* to the graphics context first and only once, then have gradient and
|
|
|
|
* contour scaling applied correctly when performing the additional
|
|
|
|
* drawing operations for subsequenct paints. Prepare this initial
|
|
|
|
* transform here.
|
|
|
|
*/
|
2021-06-22 20:50:48 +02:00
|
|
|
paint->format = FT_COLR_PAINTFORMAT_TRANSFORM;
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-01-20 12:04:50 +01:00
|
|
|
next_paint.p = opaque_paint.p;
|
|
|
|
next_paint.insert_root_transform = 0;
|
2021-06-22 20:50:48 +02:00
|
|
|
paint->u.transform.paint = next_paint;
|
2021-01-15 10:09:00 +01:00
|
|
|
|
2021-01-20 12:04:50 +01:00
|
|
|
/* `x_scale` and `y_scale` are in 26.6 format, representing the scale
|
|
|
|
* factor to get from font units to requested size. However, expected
|
2021-02-10 18:24:13 +01:00
|
|
|
* return values are in 16.16, so we shift accordingly with rounding.
|
2021-01-20 12:04:50 +01:00
|
|
|
*/
|
|
|
|
ft_root_scale.xx = ( face->root.size->metrics.x_scale + 32 ) >> 6;
|
|
|
|
ft_root_scale.xy = 0;
|
|
|
|
ft_root_scale.yx = 0;
|
|
|
|
ft_root_scale.yy = ( face->root.size->metrics.y_scale + 32 ) >> 6;
|
|
|
|
|
|
|
|
if ( face->root.internal->transform_flags & 1 )
|
|
|
|
FT_Matrix_Multiply( &face->root.internal->transform_matrix,
|
|
|
|
&ft_root_scale );
|
|
|
|
|
2021-06-22 20:50:48 +02:00
|
|
|
paint->u.transform.affine.xx = ft_root_scale.xx;
|
|
|
|
paint->u.transform.affine.xy = ft_root_scale.xy;
|
|
|
|
paint->u.transform.affine.yx = ft_root_scale.yx;
|
|
|
|
paint->u.transform.affine.yy = ft_root_scale.yy;
|
2021-01-20 12:04:50 +01:00
|
|
|
|
|
|
|
/* The translation is specified in 26.6 format and, according to the
|
|
|
|
* documentation of `FT_Set_Translate`, is performed on the character
|
|
|
|
* size given in the last call to `FT_Set_Char_Size`. The
|
2021-06-22 20:50:48 +02:00
|
|
|
* 'PaintTransform' paint table's `FT_Affine23` format expects
|
2021-01-20 12:04:50 +01:00
|
|
|
* values in 16.16 format, thus we need to shift by 10 bits.
|
|
|
|
*/
|
|
|
|
if ( face->root.internal->transform_flags & 2 )
|
|
|
|
{
|
2021-06-22 20:50:48 +02:00
|
|
|
paint->u.transform.affine.dx =
|
2021-01-20 12:04:50 +01:00
|
|
|
face->root.internal->transform_delta.x << 10;
|
2021-06-22 20:50:48 +02:00
|
|
|
paint->u.transform.affine.dy =
|
2021-01-20 12:04:50 +01:00
|
|
|
face->root.internal->transform_delta.y << 10;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-22 20:50:48 +02:00
|
|
|
paint->u.transform.affine.dx = 0;
|
|
|
|
paint->u.transform.affine.dy = 0;
|
2021-01-20 12:04:50 +01:00
|
|
|
}
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-01-20 12:04:50 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2020-12-16 15:52:24 +01:00
|
|
|
|
2021-01-20 12:04:50 +01:00
|
|
|
return read_paint( colr, opaque_paint.p, paint );
|
2020-12-16 15:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
FT_LOCAL_DEF( FT_Error )
|
|
|
|
tt_face_colr_blend_layer( TT_Face face,
|
2018-05-30 09:34:57 +02:00
|
|
|
FT_UInt color_index,
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
FT_GlyphSlot dstSlot,
|
|
|
|
FT_GlyphSlot srcSlot )
|
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
|
|
|
|
FT_UInt x, y;
|
|
|
|
FT_Byte b, g, r, alpha;
|
|
|
|
|
2018-05-30 09:34:57 +02:00
|
|
|
FT_ULong size;
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
FT_Byte* src;
|
|
|
|
FT_Byte* dst;
|
|
|
|
|
|
|
|
|
|
|
|
if ( !dstSlot->bitmap.buffer )
|
|
|
|
{
|
|
|
|
/* Initialize destination of color bitmap */
|
|
|
|
/* with the size of first component. */
|
|
|
|
dstSlot->bitmap_left = srcSlot->bitmap_left;
|
|
|
|
dstSlot->bitmap_top = srcSlot->bitmap_top;
|
|
|
|
|
|
|
|
dstSlot->bitmap.width = srcSlot->bitmap.width;
|
|
|
|
dstSlot->bitmap.rows = srcSlot->bitmap.rows;
|
|
|
|
dstSlot->bitmap.pixel_mode = FT_PIXEL_MODE_BGRA;
|
2018-05-30 09:34:57 +02:00
|
|
|
dstSlot->bitmap.pitch = (int)dstSlot->bitmap.width * 4;
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
dstSlot->bitmap.num_grays = 256;
|
|
|
|
|
2018-05-30 09:34:57 +02:00
|
|
|
size = dstSlot->bitmap.rows * (unsigned int)dstSlot->bitmap.pitch;
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
|
|
|
|
error = ft_glyphslot_alloc_bitmap( dstSlot, size );
|
|
|
|
if ( error )
|
|
|
|
return error;
|
|
|
|
|
|
|
|
FT_MEM_ZERO( dstSlot->bitmap.buffer, size );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Resize destination if needed such that new component fits. */
|
|
|
|
FT_Int x_min, x_max, y_min, y_max;
|
|
|
|
|
|
|
|
|
|
|
|
x_min = FT_MIN( dstSlot->bitmap_left, srcSlot->bitmap_left );
|
|
|
|
x_max = FT_MAX( dstSlot->bitmap_left + (FT_Int)dstSlot->bitmap.width,
|
|
|
|
srcSlot->bitmap_left + (FT_Int)srcSlot->bitmap.width );
|
|
|
|
|
|
|
|
y_min = FT_MIN( dstSlot->bitmap_top - (FT_Int)dstSlot->bitmap.rows,
|
|
|
|
srcSlot->bitmap_top - (FT_Int)srcSlot->bitmap.rows );
|
|
|
|
y_max = FT_MAX( dstSlot->bitmap_top, srcSlot->bitmap_top );
|
|
|
|
|
|
|
|
if ( x_min != dstSlot->bitmap_left ||
|
|
|
|
x_max != dstSlot->bitmap_left + (FT_Int)dstSlot->bitmap.width ||
|
|
|
|
y_min != dstSlot->bitmap_top - (FT_Int)dstSlot->bitmap.rows ||
|
|
|
|
y_max != dstSlot->bitmap_top )
|
|
|
|
{
|
|
|
|
FT_Memory memory = face->root.memory;
|
|
|
|
|
2018-05-30 09:34:57 +02:00
|
|
|
FT_UInt width = (FT_UInt)( x_max - x_min );
|
|
|
|
FT_UInt rows = (FT_UInt)( y_max - y_min );
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
FT_UInt pitch = width * 4;
|
|
|
|
|
2018-06-10 21:43:51 +02:00
|
|
|
FT_Byte* buf = NULL;
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
FT_Byte* p;
|
|
|
|
FT_Byte* q;
|
|
|
|
|
|
|
|
|
|
|
|
size = rows * pitch;
|
|
|
|
if ( FT_ALLOC( buf, size ) )
|
|
|
|
return error;
|
|
|
|
|
|
|
|
p = dstSlot->bitmap.buffer;
|
|
|
|
q = buf +
|
2018-05-30 09:34:57 +02:00
|
|
|
(int)pitch * ( y_max - dstSlot->bitmap_top ) +
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
4 * ( dstSlot->bitmap_left - x_min );
|
|
|
|
|
|
|
|
for ( y = 0; y < dstSlot->bitmap.rows; y++ )
|
|
|
|
{
|
|
|
|
FT_MEM_COPY( q, p, dstSlot->bitmap.width * 4 );
|
|
|
|
|
|
|
|
p += dstSlot->bitmap.pitch;
|
|
|
|
q += pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
ft_glyphslot_set_bitmap( dstSlot, buf );
|
|
|
|
|
|
|
|
dstSlot->bitmap_top = y_max;
|
|
|
|
dstSlot->bitmap_left = x_min;
|
|
|
|
|
|
|
|
dstSlot->bitmap.width = width;
|
|
|
|
dstSlot->bitmap.rows = rows;
|
2018-05-30 09:34:57 +02:00
|
|
|
dstSlot->bitmap.pitch = (int)pitch;
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
|
|
|
|
dstSlot->internal->flags |= FT_GLYPH_OWN_BITMAP;
|
|
|
|
dstSlot->format = FT_GLYPH_FORMAT_BITMAP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-12 06:07:40 +02:00
|
|
|
if ( color_index == 0xFFFF )
|
|
|
|
{
|
|
|
|
if ( face->have_foreground_color )
|
|
|
|
{
|
|
|
|
b = face->foreground_color.blue;
|
|
|
|
g = face->foreground_color.green;
|
|
|
|
r = face->foreground_color.red;
|
|
|
|
alpha = face->foreground_color.alpha;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-02 11:50:04 +02:00
|
|
|
if ( face->palette_data.palette_flags &&
|
|
|
|
( face->palette_data.palette_flags[face->palette_index] &
|
2018-06-21 00:21:09 +02:00
|
|
|
FT_PALETTE_FOR_DARK_BACKGROUND ) )
|
2018-06-12 06:07:40 +02:00
|
|
|
{
|
|
|
|
/* white opaque */
|
|
|
|
b = 0xFF;
|
|
|
|
g = 0xFF;
|
|
|
|
r = 0xFF;
|
|
|
|
alpha = 0xFF;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* black opaque */
|
|
|
|
b = 0x00;
|
|
|
|
g = 0x00;
|
|
|
|
r = 0x00;
|
|
|
|
alpha = 0xFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
else
|
|
|
|
{
|
2018-06-12 06:07:40 +02:00
|
|
|
b = face->palette[color_index].blue;
|
|
|
|
g = face->palette[color_index].green;
|
|
|
|
r = face->palette[color_index].red;
|
|
|
|
alpha = face->palette[color_index].alpha;
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX Convert if srcSlot.bitmap is not grey? */
|
|
|
|
src = srcSlot->bitmap.buffer;
|
|
|
|
dst = dstSlot->bitmap.buffer +
|
|
|
|
dstSlot->bitmap.pitch * ( dstSlot->bitmap_top - srcSlot->bitmap_top ) +
|
|
|
|
4 * ( srcSlot->bitmap_left - dstSlot->bitmap_left );
|
|
|
|
|
|
|
|
for ( y = 0; y < srcSlot->bitmap.rows; y++ )
|
|
|
|
{
|
|
|
|
for ( x = 0; x < srcSlot->bitmap.width; x++ )
|
|
|
|
{
|
|
|
|
int aa = src[x];
|
|
|
|
int fa = alpha * aa / 255;
|
|
|
|
|
|
|
|
int fb = b * fa / 255;
|
|
|
|
int fg = g * fa / 255;
|
|
|
|
int fr = r * fa / 255;
|
|
|
|
|
|
|
|
int ba2 = 255 - fa;
|
|
|
|
|
|
|
|
int bb = dst[4 * x + 0];
|
|
|
|
int bg = dst[4 * x + 1];
|
|
|
|
int br = dst[4 * x + 2];
|
|
|
|
int ba = dst[4 * x + 3];
|
|
|
|
|
|
|
|
|
2018-05-30 09:34:57 +02:00
|
|
|
dst[4 * x + 0] = (FT_Byte)( bb * ba2 / 255 + fb );
|
|
|
|
dst[4 * x + 1] = (FT_Byte)( bg * ba2 / 255 + fg );
|
|
|
|
dst[4 * x + 2] = (FT_Byte)( br * ba2 / 255 + fr );
|
|
|
|
dst[4 * x + 3] = (FT_Byte)( ba * ba2 / 255 + fa );
|
[sfnt] Preliminary support of coloured layer outlines.
This commit enables OpenType's COLR/CPAL table handling; a typical
application are color emojis that can be scaled to any size.
If the color palette does not exist or is invalid, the rendering
step rasterizes the outline instead. The current implementation
assumes that the foreground is black.
Enable this by defining option TT_CONFIG_OPTION_COLOR_LAYERS.
There are still some issues with metrics; additionally, an API to
fetch color layers is missing.
* devel/ftoption.h, include/freetype/config/ftoption.h
(TT_CONFIG_OPTION_COLOR_LAYERS): New macro.
* include/freetype/internal/ftobjs.h (FT_Glyph_LayerRec,
FT_Colr_InternalRec): New structures.
(FT_Slot_InternalRec): Add `color_layers' field.
* include/freetype/internal/sfnt.h (TT_Load_Colr_Layer_Func,
TT_Blend_Colr_Func): New function types.
(SFNT_Interface): Add `load_colr', `free_colr', `load_colr_layer',
and `colr_blend' fields.
* include/freetype/internal/tttypes.h (TT_FaceRec): Add
`colr_and_cpal' field.
* include/freetype/internal/tttags. (TTAG_COLR, TTAG_CPAL): New
macros.
* src/sfnt/ttcolr.c, src/sfnt/ttcolr.h: New files.
* src/base/ftobjs.c (ft_glyphslot_done, FT_Render_Glyph_Internal):
Handle glyph color layers.
* src/sfnt/Jamfile (_sources), src/sfnt/rules.mk (SFNT_DRV_SRC): Add
`ttcolr.c'.
* src/sfnt/sfdriver.c: Include `ttcolr.h'.
(PUT_COLOR_LAYERS): New macro.
Update call to `FT_DEFINE_SFNT_INTERFACE'.
* src/sfnt/sfnt.c: Include `ttcolr.c'.
* src/sfnt/sfobjs.c (sfnt_load_face): Load `COLR' and `CPAL' tables.
(sfnt_done_face): Updated.
* src/truetype/ttgload.c (TT_Load_Glyph): Handle color layers.
2018-05-13 03:25:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
src += srcSlot->bitmap.pitch;
|
|
|
|
dst += dstSlot->bitmap.pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* !TT_CONFIG_OPTION_COLOR_LAYERS */
|
|
|
|
|
|
|
|
/* ANSI C doesn't like empty source files */
|
|
|
|
typedef int _tt_colr_dummy;
|
|
|
|
|
|
|
|
#endif /* !TT_CONFIG_OPTION_COLOR_LAYERS */
|
|
|
|
|
|
|
|
/* EOF */
|