37#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
41#ifdef TT_CONFIG_OPTION_COLOR_LAYERS
47#define BASE_GLYPH_SIZE 6U
48#define BASE_GLYPH_PAINT_RECORD_SIZE 6U
49#define LAYER_V1_LIST_PAINT_OFFSET_SIZE 4U
50#define LAYER_V1_LIST_NUM_LAYERS_SIZE 4U
51#define COLOR_STOP_SIZE 6U
52#define VAR_IDX_BASE_SIZE 4U
56#define COLRV0_HEADER_SIZE 14U
58#define COLRV1_HEADER_SIZE 34U
61#define ENSURE_READ_BYTES( byte_size ) \
62 if ( p < colr->paints_start_v1 || \
63 p > (FT_Byte*)colr->table + colr->table_size - byte_size ) \
67 typedef enum FT_PaintFormat_Internal_
69 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SOLID = 3,
70 FT_COLR_PAINTFORMAT_INTERNAL_VAR_LINEAR_GRADIENT = 5,
71 FT_COLR_PAINTFORMAT_INTERNAL_VAR_RADIAL_GRADIENT = 7,
72 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SWEEP_GRADIENT = 9,
73 FT_COLR_PAINTFORMAT_INTERNAL_VAR_TRANSFORM = 13,
74 FT_COLR_PAINTFORMAT_INTERNAL_VAR_TRANSLATE = 15,
75 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE = 17,
76 FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER = 18,
77 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE_CENTER = 19,
78 FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM = 20,
79 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE_UNIFORM = 21,
80 FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM_CENTER = 22,
81 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE_UNIFORM_CENTER = 23,
82 FT_COLR_PAINTFORMAT_INTERNAL_VAR_ROTATE = 25,
83 FT_COLR_PAINTFORMAT_INTERNAL_ROTATE_CENTER = 26,
84 FT_COLR_PAINTFORMAT_INTERNAL_VAR_ROTATE_CENTER = 27,
85 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SKEW = 29,
86 FT_COLR_PAINTFORMAT_INTERNAL_SKEW_CENTER = 30,
87 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SKEW_CENTER = 31,
89 } FT_PaintFormat_Internal;
92 typedef struct BaseGlyphRecord_
95 FT_UShort first_layer_index;
101 typedef struct BaseGlyphV1Record_
105 FT_ULong paint_offset;
113 FT_UShort num_base_glyphs;
114 FT_UShort num_layers;
116 FT_Byte* base_glyphs;
119 FT_ULong num_base_glyphs_v1;
121 FT_Byte* base_glyphs_v1;
123 FT_ULong num_layers_v1;
133 FT_Byte* paints_start_v1;
135#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
137 GX_ItemVarStoreRec var_store;
138 GX_DeltaSetIdxMapRec delta_set_idx_map;
155#define FT_COMPONENT ttcolr
158 FT_LOCAL_DEF( FT_Error )
159 tt_face_load_colr( TT_Face face,
163 FT_Memory memory = face->root.memory;
165 FT_Byte* table = NULL;
172 FT_ULong base_glyph_offset, layer_offset;
173 FT_ULong base_glyphs_offset_v1, num_base_glyphs_v1;
174 FT_ULong layer_offset_v1, num_layers_v1, clip_list_offset;
176#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
177 FT_ULong colr_offset_in_stream;
183 return FT_THROW( Invalid_File_Format );
185 error = face->goto_table( face, TTAG_COLR, stream, &table_size );
189#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
190 colr_offset_in_stream = FT_STREAM_POS();
193 if ( table_size < COLRV0_HEADER_SIZE )
196 if ( FT_FRAME_EXTRACT( table_size, table ) )
201 if ( FT_NEW( colr ) )
204 colr->version = FT_NEXT_USHORT( p );
205 if ( colr->version != 0 && colr->version != 1 )
208 colr->num_base_glyphs = FT_NEXT_USHORT( p );
209 base_glyph_offset = FT_NEXT_ULONG( p );
211 if ( table_size <= base_glyph_offset )
213 if ( ( table_size - base_glyph_offset ) / BASE_GLYPH_SIZE
214 < colr->num_base_glyphs )
217 layer_offset = FT_NEXT_ULONG( p );
218 colr->num_layers = FT_NEXT_USHORT( p );
220 if ( table_size <= layer_offset )
222 if ( ( table_size - layer_offset ) / LAYER_SIZE
226 if ( colr->version == 1 )
228 if ( table_size < COLRV1_HEADER_SIZE )
231 base_glyphs_offset_v1 = FT_NEXT_ULONG( p );
233 if ( table_size - 4 <= base_glyphs_offset_v1 )
236 p1 = (FT_Byte*)( table + base_glyphs_offset_v1 );
237 num_base_glyphs_v1 = FT_PEEK_ULONG( p1 );
239 if ( ( table_size - base_glyphs_offset_v1 ) / BASE_GLYPH_PAINT_RECORD_SIZE
240 < num_base_glyphs_v1 )
243 colr->num_base_glyphs_v1 = num_base_glyphs_v1;
244 colr->base_glyphs_v1 = p1;
246 layer_offset_v1 = FT_NEXT_ULONG( p );
248 if ( table_size <= layer_offset_v1 )
251 if ( layer_offset_v1 )
253 if ( table_size - 4 <= layer_offset_v1 )
256 p1 = (FT_Byte*)( table + layer_offset_v1 );
257 num_layers_v1 = FT_PEEK_ULONG( p1 );
259 if ( ( table_size - layer_offset_v1 ) / LAYER_V1_LIST_PAINT_OFFSET_SIZE
263 colr->num_layers_v1 = num_layers_v1;
264 colr->layers_v1 = p1;
266 colr->paints_start_v1 =
267 FT_MIN( colr->base_glyphs_v1 +
268 colr->num_base_glyphs_v1 * BASE_GLYPH_PAINT_RECORD_SIZE,
270 colr->num_layers_v1 * LAYER_V1_LIST_PAINT_OFFSET_SIZE );
274 colr->num_layers_v1 = 0;
276 colr->paints_start_v1 =
277 colr->base_glyphs_v1 +
278 colr->num_base_glyphs_v1 * BASE_GLYPH_PAINT_RECORD_SIZE;
281 clip_list_offset = FT_NEXT_ULONG( p );
283 if ( table_size <= clip_list_offset )
286 if ( clip_list_offset )
287 colr->clip_list = (FT_Byte*)( table + clip_list_offset );
291#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
292 colr->var_store.dataCount = 0;
293 colr->var_store.varData = NULL;
294 colr->var_store.axisCount = 0;
295 colr->var_store.regionCount = 0;
296 colr->var_store.varRegionList = 0;
298 colr->delta_set_idx_map.mapCount = 0;
299 colr->delta_set_idx_map.outerIndex = NULL;
300 colr->delta_set_idx_map.innerIndex = NULL;
302 if ( face->variation_support & TT_FACE_FLAG_VAR_FVAR )
304 FT_ULong var_idx_map_offset, var_store_offset;
306 FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm;
309 var_idx_map_offset = FT_NEXT_ULONG( p );
311 if ( var_idx_map_offset >= table_size )
314 var_store_offset = FT_NEXT_ULONG( p );
315 if ( table_size <= var_store_offset )
318 if ( var_store_offset )
324 if ( mm->get_mm_var( FT_FACE( face ), NULL ) )
328 error = mm->load_item_var_store(
330 colr_offset_in_stream + var_store_offset,
332 if ( error != FT_Err_Ok )
336 if ( colr->var_store.axisCount && var_idx_map_offset )
338 error = mm->load_delta_set_idx_map(
340 colr_offset_in_stream + var_idx_map_offset,
341 &colr->delta_set_idx_map,
344 if ( error != FT_Err_Ok )
351 colr->base_glyphs = (FT_Byte*)( table + base_glyph_offset );
352 colr->layers = (FT_Byte*)( table + layer_offset );
354 colr->table_size = table_size;
361#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
363 FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm;
366 mm->done_delta_set_idx_map( FT_FACE( face ),
367 &colr->delta_set_idx_map );
368 mm->done_item_var_store( FT_FACE( face ),
373 error = FT_THROW( Invalid_Table );
376 FT_FRAME_RELEASE( table );
384 tt_face_free_colr( TT_Face face )
386 FT_Stream stream = face->root.stream;
387 FT_Memory memory = face->root.memory;
389 Colr* colr = (Colr*)face->colr;
394#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
396 FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm;
399 mm->done_delta_set_idx_map( FT_FACE( face ),
400 &colr->delta_set_idx_map );
401 mm->done_item_var_store( FT_FACE( face ),
405 FT_FRAME_RELEASE( colr->table );
412 find_base_glyph_record( FT_Byte* base_glyph_begin,
413 FT_UInt num_base_glyph,
415 BaseGlyphRecord* record )
418 FT_UInt max = num_base_glyph;
423 FT_UInt mid = min + ( max - min ) / 2;
424 FT_Byte* p = base_glyph_begin + mid * BASE_GLYPH_SIZE;
426 FT_UShort gid = FT_NEXT_USHORT( p );
429 if ( gid < glyph_id )
431 else if (gid > glyph_id )
436 record->first_layer_index = FT_NEXT_USHORT( p );
437 record->num_layers = FT_NEXT_USHORT( p );
447 FT_LOCAL_DEF( FT_Bool )
448 tt_face_get_colr_layer( TT_Face face,
450 FT_UInt *aglyph_index,
451 FT_UInt *acolor_index,
452 FT_LayerIterator* iterator )
454 Colr* colr = (Colr*)face->colr;
455 BaseGlyphRecord glyph_record;
469 if ( !find_base_glyph_record( colr->base_glyphs,
470 colr->num_base_glyphs,
475 if ( glyph_record.num_layers )
476 iterator->num_layers = glyph_record.num_layers;
480 offset = LAYER_SIZE * glyph_record.first_layer_index;
481 if ( offset + LAYER_SIZE * glyph_record.num_layers > colr->table_size )
484 iterator->p = colr->layers + offset;
487 if ( iterator->layer >= iterator->num_layers ||
488 iterator->p < colr->layers ||
489 iterator->p >= ( (FT_Byte*)colr->table + colr->table_size ) )
492 *aglyph_index = FT_NEXT_USHORT( iterator->p );
493 *acolor_index = FT_NEXT_USHORT( iterator->p );
495 if ( *aglyph_index >= (FT_UInt)( FT_FACE( face )->num_glyphs ) ||
496 ( *acolor_index != 0xFFFF &&
497 *acolor_index >= face->palette_data.num_palette_entries ) )
507 read_color_line( Colr* colr,
508 FT_Byte* color_line_p,
509 FT_ColorLine* colorline,
510 FT_Bool read_variable )
512 FT_Byte* p = color_line_p;
513 FT_PaintExtend paint_extend;
516 ENSURE_READ_BYTES( 3 );
518 paint_extend = (FT_PaintExtend)FT_NEXT_BYTE( p );
519 if ( paint_extend > FT_COLR_PAINT_EXTEND_REFLECT )
522 colorline->extend = paint_extend;
524 colorline->color_stop_iterator.num_color_stops = FT_NEXT_USHORT( p );
525 colorline->color_stop_iterator.p = p;
526 colorline->color_stop_iterator.current_color_stop = 0;
527 colorline->color_stop_iterator.read_variable = read_variable;
541 get_child_table_pointer ( Colr* colr,
544 FT_Byte** child_table_pointer )
546 FT_UInt32 paint_offset;
547 FT_Byte* child_table_p;
550 if ( !child_table_pointer )
553 if ( *p < colr->paints_start_v1 ||
554 *p > (FT_Byte*)colr->table + colr->table_size - 1 - 3 )
557 paint_offset = FT_NEXT_UOFF3( *p );
561 child_table_p = (FT_Byte*)( paint_base + paint_offset );
563 if ( child_table_p < colr->paints_start_v1 ||
564 child_table_p >= ( (FT_Byte*)colr->table + colr->table_size ) )
567 *child_table_pointer = child_table_p;
572#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
575 get_deltas_for_var_index_base ( TT_Face face,
577 FT_ULong var_index_base,
579 FT_ItemVarDelta* deltas )
581 FT_UInt outer_index = 0;
582 FT_UInt inner_index = 0;
583 FT_ULong loop_var_index = var_index_base;
585 FT_Service_MultiMasters mm = (FT_Service_MultiMasters)face->mm;
590 if ( var_index_base == 0xFFFFFFFF )
592 for ( i = 0; i < num_deltas; ++i )
597 for ( i = 0; i < num_deltas; ++i )
599 loop_var_index = var_index_base + i;
601 if ( colr->delta_set_idx_map.innerIndex )
603 if ( loop_var_index >= colr->delta_set_idx_map.mapCount )
604 loop_var_index = colr->delta_set_idx_map.mapCount - 1;
606 outer_index = colr->delta_set_idx_map.outerIndex[loop_var_index];
607 inner_index = colr->delta_set_idx_map.innerIndex[loop_var_index];
612 inner_index = loop_var_index;
615 deltas[i] = mm->get_item_delta( FT_FACE( face ), &colr->var_store,
616 outer_index, inner_index );
626 read_paint( TT_Face face,
629 FT_COLR_Paint* apaint )
631 FT_Byte* paint_base = p;
632 FT_Byte* child_table_p = NULL;
633 FT_Bool do_read_var = FALSE;
635#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
636 FT_ULong var_index_base = 0;
638 FT_ItemVarDelta item_deltas[6] = { 0, 0, 0, 0, 0, 0 };
644 if ( !p || !colr || !colr->table )
649 if ( p < colr->paints_start_v1 ||
650 p > (FT_Byte*)colr->table + colr->table_size - 2 )
653 apaint->format = (FT_PaintFormat)FT_NEXT_BYTE( p );
655 if ( apaint->format >= FT_COLR_PAINT_FORMAT_MAX )
658 if ( apaint->format == FT_COLR_PAINTFORMAT_COLR_LAYERS )
662 FT_UInt32 first_layer_index;
665 ENSURE_READ_BYTES( 5 );
666 num_layers = FT_NEXT_BYTE( p );
667 if ( num_layers > colr->num_layers_v1 )
670 first_layer_index = FT_NEXT_ULONG( p );
671 if ( first_layer_index + num_layers > colr->num_layers_v1 )
674 apaint->u.colr_layers.layer_iterator.num_layers = num_layers;
675 apaint->u.colr_layers.layer_iterator.layer = 0;
677 apaint->u.colr_layers.layer_iterator.p =
679 LAYER_V1_LIST_NUM_LAYERS_SIZE +
680 LAYER_V1_LIST_PAINT_OFFSET_SIZE * first_layer_index;
685 else if ( apaint->format == FT_COLR_PAINTFORMAT_SOLID ||
686 (FT_PaintFormat_Internal)apaint->format ==
687 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SOLID )
689 ENSURE_READ_BYTES( 4 );
690 apaint->u.solid.color.palette_index = FT_NEXT_USHORT( p );
691 apaint->u.solid.color.alpha = FT_NEXT_SHORT( p );
693#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
694 if ( (FT_PaintFormat_Internal)apaint->format ==
695 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SOLID )
697 ENSURE_READ_BYTES( 4 );
698 var_index_base = FT_NEXT_ULONG( p );
700 if ( !get_deltas_for_var_index_base( face, colr, var_index_base, 1,
704 apaint->u.solid.color.alpha += (FT_F2Dot14)item_deltas[0];
708 apaint->format = FT_COLR_PAINTFORMAT_SOLID;
713 else if ( apaint->format == FT_COLR_PAINTFORMAT_COLR_GLYPH )
715 ENSURE_READ_BYTES(2);
716 apaint->u.colr_glyph.glyphID = FT_NEXT_USHORT( p );
728 if ( !get_child_table_pointer( colr, paint_base, &p, &child_table_p ) )
731 if ( apaint->format == FT_COLR_PAINTFORMAT_LINEAR_GRADIENT ||
733 ( (FT_PaintFormat_Internal)apaint->format ==
734 FT_COLR_PAINTFORMAT_INTERNAL_VAR_LINEAR_GRADIENT ) ) )
736 if ( !read_color_line( colr,
738 &apaint->u.linear_gradient.colorline,
747 ENSURE_READ_BYTES( 12 );
748 apaint->u.linear_gradient.p0.x = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
749 apaint->u.linear_gradient.p0.y = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
750 apaint->u.linear_gradient.p1.x = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
751 apaint->u.linear_gradient.p1.y = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
752 apaint->u.linear_gradient.p2.x = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
753 apaint->u.linear_gradient.p2.y = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
755#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
758 ENSURE_READ_BYTES( 4 );
759 var_index_base = FT_NEXT_ULONG ( p );
761 if ( !get_deltas_for_var_index_base( face, colr, var_index_base, 6,
765 apaint->u.linear_gradient.p0.x += INT_TO_FIXED( item_deltas[0] );
766 apaint->u.linear_gradient.p0.y += INT_TO_FIXED( item_deltas[1] );
767 apaint->u.linear_gradient.p1.x += INT_TO_FIXED( item_deltas[2] );
768 apaint->u.linear_gradient.p1.y += INT_TO_FIXED( item_deltas[3] );
769 apaint->u.linear_gradient.p2.x += INT_TO_FIXED( item_deltas[4] );
770 apaint->u.linear_gradient.p2.y += INT_TO_FIXED( item_deltas[5] );
774 apaint->format = FT_COLR_PAINTFORMAT_LINEAR_GRADIENT;
779 else if ( apaint->format == FT_COLR_PAINTFORMAT_RADIAL_GRADIENT ||
781 ( (FT_PaintFormat_Internal)apaint->format ==
782 FT_COLR_PAINTFORMAT_INTERNAL_VAR_RADIAL_GRADIENT ) ) )
787 if ( !read_color_line( colr,
789 &apaint->u.radial_gradient.colorline,
799 ENSURE_READ_BYTES( 12 );
801 apaint->u.radial_gradient.c0.x = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
802 apaint->u.radial_gradient.c0.y = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
804 tmp = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
805 apaint->u.radial_gradient.r0 = tmp < 0 ? FT_INT_MAX : tmp;
807 apaint->u.radial_gradient.c1.x = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
808 apaint->u.radial_gradient.c1.y = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
810 tmp = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
811 apaint->u.radial_gradient.r1 = tmp < 0 ? FT_INT_MAX : tmp;
813#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
816 ENSURE_READ_BYTES( 4 );
817 var_index_base = FT_NEXT_ULONG ( p );
819 if ( !get_deltas_for_var_index_base( face, colr, var_index_base, 6,
823 apaint->u.radial_gradient.c0.x += INT_TO_FIXED( item_deltas[0] );
824 apaint->u.radial_gradient.c0.y += INT_TO_FIXED( item_deltas[1] );
827 apaint->u.radial_gradient.r0 += INT_TO_FIXED( item_deltas[2] );
829 apaint->u.radial_gradient.c1.x += INT_TO_FIXED( item_deltas[3] );
830 apaint->u.radial_gradient.c1.y += INT_TO_FIXED( item_deltas[4] );
832 apaint->u.radial_gradient.r1 += INT_TO_FIXED( item_deltas[5] );
836 apaint->format = FT_COLR_PAINTFORMAT_RADIAL_GRADIENT;
841 else if ( apaint->format == FT_COLR_PAINTFORMAT_SWEEP_GRADIENT ||
843 ( (FT_PaintFormat_Internal)apaint->format ==
844 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SWEEP_GRADIENT ) ) )
846 if ( !read_color_line( colr,
848 &apaint->u.sweep_gradient.colorline,
852 ENSURE_READ_BYTES( 8 );
854 apaint->u.sweep_gradient.center.x =
855 INT_TO_FIXED( FT_NEXT_SHORT( p ) );
856 apaint->u.sweep_gradient.center.y =
857 INT_TO_FIXED( FT_NEXT_SHORT( p ) );
859 apaint->u.sweep_gradient.start_angle =
860 F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) );
861 apaint->u.sweep_gradient.end_angle =
862 F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) );
864#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
867 ENSURE_READ_BYTES( 4 );
868 var_index_base = FT_NEXT_ULONG ( p );
870 if ( !get_deltas_for_var_index_base( face, colr, var_index_base, 4,
875 apaint->u.sweep_gradient.center.x += INT_TO_FIXED( item_deltas[0] );
876 apaint->u.sweep_gradient.center.y += INT_TO_FIXED( item_deltas[1] );
878 apaint->u.sweep_gradient.start_angle +=
879 F2DOT14_TO_FIXED( item_deltas[2] );
880 apaint->u.sweep_gradient.end_angle +=
881 F2DOT14_TO_FIXED( item_deltas[3] );
884 apaint->format = FT_COLR_PAINTFORMAT_SWEEP_GRADIENT;
889 if ( apaint->format == FT_COLR_PAINTFORMAT_GLYPH )
891 ENSURE_READ_BYTES( 2 );
892 apaint->u.glyph.paint.p = child_table_p;
893 apaint->u.glyph.paint.insert_root_transform = 0;
894 apaint->u.glyph.glyphID = FT_NEXT_USHORT( p );
899 else if ( apaint->format == FT_COLR_PAINTFORMAT_TRANSFORM ||
900 (FT_PaintFormat_Internal)apaint->format ==
901 FT_COLR_PAINTFORMAT_INTERNAL_VAR_TRANSFORM )
903 apaint->u.transform.paint.p = child_table_p;
904 apaint->u.transform.paint.insert_root_transform = 0;
906 if ( !get_child_table_pointer( colr, paint_base, &p, &child_table_p ) )
915 ENSURE_READ_BYTES( 24 );
916 apaint->u.transform.affine.xx = FT_NEXT_LONG( p );
917 apaint->u.transform.affine.yx = FT_NEXT_LONG( p );
918 apaint->u.transform.affine.xy = FT_NEXT_LONG( p );
919 apaint->u.transform.affine.yy = FT_NEXT_LONG( p );
920 apaint->u.transform.affine.dx = FT_NEXT_LONG( p );
921 apaint->u.transform.affine.dy = FT_NEXT_LONG( p );
923#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
924 if ( (FT_PaintFormat_Internal)apaint->format ==
925 FT_COLR_PAINTFORMAT_INTERNAL_VAR_TRANSFORM )
927 ENSURE_READ_BYTES( 4 );
928 var_index_base = FT_NEXT_ULONG( p );
930 if ( !get_deltas_for_var_index_base( face, colr, var_index_base, 6,
934 apaint->u.transform.affine.xx += (FT_Fixed)item_deltas[0];
935 apaint->u.transform.affine.yx += (FT_Fixed)item_deltas[1];
936 apaint->u.transform.affine.xy += (FT_Fixed)item_deltas[2];
937 apaint->u.transform.affine.yy += (FT_Fixed)item_deltas[3];
938 apaint->u.transform.affine.dx += (FT_Fixed)item_deltas[4];
939 apaint->u.transform.affine.dy += (FT_Fixed)item_deltas[5];
943 apaint->format = FT_COLR_PAINTFORMAT_TRANSFORM;
948 else if ( apaint->format == FT_COLR_PAINTFORMAT_TRANSLATE ||
949 (FT_PaintFormat_Internal)apaint->format ==
950 FT_COLR_PAINTFORMAT_INTERNAL_VAR_TRANSLATE )
952 apaint->u.translate.paint.p = child_table_p;
953 apaint->u.translate.paint.insert_root_transform = 0;
955 ENSURE_READ_BYTES( 4 );
956 apaint->u.translate.dx = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
957 apaint->u.translate.dy = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
959#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
960 if ( (FT_PaintFormat_Internal)apaint->format ==
961 FT_COLR_PAINTFORMAT_INTERNAL_VAR_TRANSLATE )
963 ENSURE_READ_BYTES( 4 );
964 var_index_base = FT_NEXT_ULONG( p );
966 if ( !get_deltas_for_var_index_base( face, colr, var_index_base, 2,
970 apaint->u.translate.dx += INT_TO_FIXED( item_deltas[0] );
971 apaint->u.translate.dy += INT_TO_FIXED( item_deltas[1] );
975 apaint->format = FT_COLR_PAINTFORMAT_TRANSLATE;
980 else if ( apaint->format >= FT_COLR_PAINTFORMAT_SCALE &&
981 (FT_PaintFormat_Internal)apaint->format <=
982 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE_UNIFORM_CENTER )
984 apaint->u.scale.paint.p = child_table_p;
985 apaint->u.scale.paint.insert_root_transform = 0;
988 ENSURE_READ_BYTES( 2 );
989 apaint->u.scale.scale_x = F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) );
992 if ( apaint->format == FT_COLR_PAINTFORMAT_SCALE ||
993 (FT_PaintFormat_Internal)apaint->format ==
994 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE ||
995 (FT_PaintFormat_Internal)apaint->format ==
996 FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER ||
997 (FT_PaintFormat_Internal)apaint->format ==
998 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE_CENTER )
1000 ENSURE_READ_BYTES( 2 );
1001 apaint->u.scale.scale_y = F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) );
1004 apaint->u.scale.scale_y = apaint->u.scale.scale_x;
1008 if ( (FT_PaintFormat_Internal)apaint->format ==
1009 FT_COLR_PAINTFORMAT_INTERNAL_SCALE_CENTER ||
1010 (FT_PaintFormat_Internal)apaint->format ==
1011 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE_CENTER ||
1012 (FT_PaintFormat_Internal)apaint->format ==
1013 FT_COLR_PAINTFORMAT_INTERNAL_SCALE_UNIFORM_CENTER ||
1014 (FT_PaintFormat_Internal)apaint->format ==
1015 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE_UNIFORM_CENTER )
1017 ENSURE_READ_BYTES( 4 );
1018 apaint->u.scale.center_x = INT_TO_FIXED( FT_NEXT_SHORT ( p ) );
1019 apaint->u.scale.center_y = INT_TO_FIXED( FT_NEXT_SHORT ( p ) );
1023 apaint->u.scale.center_x = 0;
1024 apaint->u.scale.center_y = 0;
1029#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
1030 if ( (FT_PaintFormat_Internal)apaint->format ==
1031 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE ||
1032 (FT_PaintFormat_Internal)apaint->format ==
1033 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE_CENTER ||
1034 (FT_PaintFormat_Internal)apaint->format ==
1035 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE_UNIFORM ||
1036 (FT_PaintFormat_Internal)apaint->format ==
1037 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE_UNIFORM_CENTER )
1039 ENSURE_READ_BYTES( 4 );
1040 var_index_base = FT_NEXT_ULONG( p );
1042 if ( (FT_PaintFormat_Internal)apaint->format ==
1043 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE )
1045 if ( !get_deltas_for_var_index_base( face, colr, var_index_base, 2,
1049 apaint->u.scale.scale_x += F2DOT14_TO_FIXED( item_deltas[0] );
1050 apaint->u.scale.scale_y += F2DOT14_TO_FIXED( item_deltas[1] );
1053 if ( (FT_PaintFormat_Internal)apaint->format ==
1054 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE_CENTER )
1056 if ( !get_deltas_for_var_index_base( face, colr, var_index_base, 4,
1060 apaint->u.scale.scale_x += F2DOT14_TO_FIXED( item_deltas[0] );
1061 apaint->u.scale.scale_y += F2DOT14_TO_FIXED( item_deltas[1] );
1062 apaint->u.scale.center_x += INT_TO_FIXED( item_deltas[2] );
1063 apaint->u.scale.center_y += INT_TO_FIXED( item_deltas[3] );
1066 if ( (FT_PaintFormat_Internal)apaint->format ==
1067 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE_UNIFORM )
1069 if ( !get_deltas_for_var_index_base( face, colr, var_index_base, 1,
1073 apaint->u.scale.scale_x += F2DOT14_TO_FIXED( item_deltas[0] );
1074 apaint->u.scale.scale_y += F2DOT14_TO_FIXED( item_deltas[0] );
1077 if ( (FT_PaintFormat_Internal)apaint->format ==
1078 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SCALE_UNIFORM_CENTER )
1080 if ( !get_deltas_for_var_index_base( face, colr, var_index_base, 3,
1084 apaint->u.scale.scale_x += F2DOT14_TO_FIXED( item_deltas[0] );
1085 apaint->u.scale.scale_y += F2DOT14_TO_FIXED( item_deltas[0] );
1086 apaint->u.scale.center_x += INT_TO_FIXED( item_deltas[1] );
1087 apaint->u.scale.center_y += INT_TO_FIXED( item_deltas[2] );
1094 apaint->format = FT_COLR_PAINTFORMAT_SCALE;
1099 else if ( apaint->format == FT_COLR_PAINTFORMAT_ROTATE ||
1100 (FT_PaintFormat_Internal)apaint->format ==
1101 FT_COLR_PAINTFORMAT_INTERNAL_ROTATE_CENTER ||
1102 (FT_PaintFormat_Internal)apaint->format ==
1103 FT_COLR_PAINTFORMAT_INTERNAL_VAR_ROTATE ||
1104 (FT_PaintFormat_Internal)apaint->format ==
1105 FT_COLR_PAINTFORMAT_INTERNAL_VAR_ROTATE_CENTER )
1107 apaint->u.rotate.paint.p = child_table_p;
1108 apaint->u.rotate.paint.insert_root_transform = 0;
1110 ENSURE_READ_BYTES( 2 );
1111 apaint->u.rotate.angle = F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) );
1113 if ( (FT_PaintFormat_Internal)apaint->format ==
1114 FT_COLR_PAINTFORMAT_INTERNAL_ROTATE_CENTER ||
1115 (FT_PaintFormat_Internal)apaint->format ==
1116 FT_COLR_PAINTFORMAT_INTERNAL_VAR_ROTATE_CENTER )
1118 ENSURE_READ_BYTES( 4 );
1119 apaint->u.rotate.center_x = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
1120 apaint->u.rotate.center_y = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
1124 apaint->u.rotate.center_x = 0;
1125 apaint->u.rotate.center_y = 0;
1128#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
1129 if ( (FT_PaintFormat_Internal)apaint->format ==
1130 FT_COLR_PAINTFORMAT_INTERNAL_VAR_ROTATE ||
1131 (FT_PaintFormat_Internal)apaint->format ==
1132 FT_COLR_PAINTFORMAT_INTERNAL_VAR_ROTATE_CENTER )
1134 FT_UInt num_deltas = 0;
1137 ENSURE_READ_BYTES( 4 );
1138 var_index_base = FT_NEXT_ULONG( p );
1140 if ( (FT_PaintFormat_Internal)apaint->format ==
1141 FT_COLR_PAINTFORMAT_INTERNAL_VAR_ROTATE_CENTER )
1143 if ( (FT_PaintFormat_Internal)apaint->format ==
1144 FT_COLR_PAINTFORMAT_INTERNAL_VAR_ROTATE )
1147 if ( num_deltas > 0 )
1149 if ( !get_deltas_for_var_index_base( face, colr, var_index_base,
1150 num_deltas, item_deltas ) )
1153 apaint->u.rotate.angle += F2DOT14_TO_FIXED( item_deltas[0] );
1155 if ( num_deltas == 3 )
1157 apaint->u.rotate.center_x += INT_TO_FIXED( item_deltas[1] );
1158 apaint->u.rotate.center_y += INT_TO_FIXED( item_deltas[2] );
1164 apaint->format = FT_COLR_PAINTFORMAT_ROTATE;
1170 else if ( apaint->format == FT_COLR_PAINTFORMAT_SKEW ||
1171 (FT_PaintFormat_Internal)apaint->format ==
1172 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SKEW ||
1173 (FT_PaintFormat_Internal)apaint->format ==
1174 FT_COLR_PAINTFORMAT_INTERNAL_SKEW_CENTER ||
1175 (FT_PaintFormat_Internal)apaint->format ==
1176 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SKEW_CENTER )
1178 apaint->u.skew.paint.p = child_table_p;
1179 apaint->u.skew.paint.insert_root_transform = 0;
1181 ENSURE_READ_BYTES( 4 );
1182 apaint->u.skew.x_skew_angle = F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) );
1183 apaint->u.skew.y_skew_angle = F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) );
1185 if ( (FT_PaintFormat_Internal)apaint->format ==
1186 FT_COLR_PAINTFORMAT_INTERNAL_SKEW_CENTER ||
1187 (FT_PaintFormat_Internal)apaint->format ==
1188 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SKEW_CENTER )
1190 ENSURE_READ_BYTES( 4 );
1191 apaint->u.skew.center_x = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
1192 apaint->u.skew.center_y = INT_TO_FIXED( FT_NEXT_SHORT( p ) );
1196 apaint->u.skew.center_x = 0;
1197 apaint->u.skew.center_y = 0;
1201#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
1202 if ( (FT_PaintFormat_Internal)apaint->format ==
1203 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SKEW ||
1204 (FT_PaintFormat_Internal)apaint->format ==
1205 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SKEW_CENTER )
1207 ENSURE_READ_BYTES( 4 );
1208 var_index_base = FT_NEXT_ULONG( p );
1210 if ( (FT_PaintFormat_Internal)apaint->format ==
1211 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SKEW )
1213 if ( !get_deltas_for_var_index_base( face, colr, var_index_base, 2,
1217 apaint->u.skew.x_skew_angle += F2DOT14_TO_FIXED( item_deltas[0] );
1218 apaint->u.skew.y_skew_angle += F2DOT14_TO_FIXED( item_deltas[1] );
1221 if ( (FT_PaintFormat_Internal)apaint->format ==
1222 FT_COLR_PAINTFORMAT_INTERNAL_VAR_SKEW_CENTER )
1224 if ( !get_deltas_for_var_index_base( face, colr, var_index_base, 4,
1228 apaint->u.skew.x_skew_angle += F2DOT14_TO_FIXED( item_deltas[0] );
1229 apaint->u.skew.y_skew_angle += F2DOT14_TO_FIXED( item_deltas[1] );
1230 apaint->u.skew.center_x += INT_TO_FIXED( item_deltas[2] );
1231 apaint->u.skew.center_y += INT_TO_FIXED( item_deltas[3] );
1236 apaint->format = FT_COLR_PAINTFORMAT_SKEW;
1241 else if ( apaint->format == FT_COLR_PAINTFORMAT_COMPOSITE )
1243 FT_UInt composite_mode;
1246 apaint->u.composite.source_paint.p = child_table_p;
1247 apaint->u.composite.source_paint.insert_root_transform = 0;
1249 ENSURE_READ_BYTES( 1 );
1250 composite_mode = FT_NEXT_BYTE( p );
1251 if ( composite_mode >= FT_COLR_COMPOSITE_MAX )
1254 apaint->u.composite.composite_mode = (FT_Composite_Mode)composite_mode;
1256 if ( !get_child_table_pointer( colr, paint_base, &p, &child_table_p ) )
1259 apaint->u.composite.backdrop_paint.p =
1261 apaint->u.composite.backdrop_paint.insert_root_transform =
1272 find_base_glyph_v1_record( FT_Byte * base_glyph_begin,
1273 FT_UInt num_base_glyph,
1275 BaseGlyphV1Record *record )
1278 FT_UInt max = num_base_glyph;
1283 FT_UInt mid = min + ( max - min ) / 2;
1291 FT_Byte *p = base_glyph_begin + 4 + mid * BASE_GLYPH_PAINT_RECORD_SIZE;
1293 gid = FT_NEXT_USHORT( p );
1295 if ( gid < glyph_id )
1297 else if (gid > glyph_id )
1302 record->paint_offset = FT_NEXT_ULONG ( p );
1311 FT_LOCAL_DEF( FT_Bool )
1312 tt_face_get_colr_glyph_paint( TT_Face face,
1314 FT_Color_Root_Transform root_transform,
1315 FT_OpaquePaint* opaque_paint )
1317 Colr* colr = (Colr*)face->colr;
1318 BaseGlyphV1Record base_glyph_v1_record;
1321 if ( !colr || !colr->table )
1324 if ( colr->version < 1 || !colr->num_base_glyphs_v1 ||
1325 !colr->base_glyphs_v1 )
1328 if ( opaque_paint->p )
1331 if ( !find_base_glyph_v1_record( colr->base_glyphs_v1,
1332 colr->num_base_glyphs_v1,
1334 &base_glyph_v1_record ) )
1337 if ( !base_glyph_v1_record.paint_offset ||
1338 base_glyph_v1_record.paint_offset > colr->table_size )
1341 p = (FT_Byte*)( colr->base_glyphs_v1 +
1342 base_glyph_v1_record.paint_offset );
1343 if ( p >= ( (FT_Byte*)colr->table + colr->table_size ) )
1346 opaque_paint->p = p;
1348 if ( root_transform == FT_COLOR_INCLUDE_ROOT_TRANSFORM )
1349 opaque_paint->insert_root_transform = 1;
1351 opaque_paint->insert_root_transform = 0;
1357 FT_LOCAL_DEF( FT_Bool )
1358 tt_face_get_color_glyph_clipbox( TT_Face face,
1360 FT_ClipBox* clip_box )
1364 FT_Byte *p, *p1, *clip_base, *limit;
1366 FT_Byte clip_list_format;
1367 FT_ULong num_clip_boxes, i;
1368 FT_UShort gid_start, gid_end;
1369 FT_UInt32 clip_box_offset;
1372 const FT_Byte num_corners = 4;
1373 FT_Vector corners[4];
1375 FT_BBox font_clip_box;
1378 colr = (Colr*)face->colr;
1382 if ( !colr->clip_list )
1385 p = colr->clip_list;
1391 limit = (FT_Byte*)colr->table + colr->table_size;
1394 if ( p > limit - ( 1 + 4 ) )
1398 clip_list_format = FT_NEXT_BYTE ( p );
1402 if ( !( clip_list_format == 1 ) )
1405 num_clip_boxes = FT_NEXT_ULONG( p );
1409 if ( colr->table_size / ( 2 + 2 + 3 ) < num_clip_boxes ||
1410 p > limit - ( 2 + 2 + 3 ) * num_clip_boxes )
1413 for ( i = 0; i < num_clip_boxes; ++i )
1415 gid_start = FT_NEXT_USHORT( p );
1416 gid_end = FT_NEXT_USHORT( p );
1417 clip_box_offset = FT_NEXT_UOFF3( p );
1419 if ( base_glyph >= gid_start && base_glyph <= gid_end )
1421 p1 = (FT_Byte*)( clip_base + clip_box_offset );
1424 if ( p1 > limit - 1 )
1427 format = FT_NEXT_BYTE( p1 );
1433 if ( p1 > limit - ( 2 + 2 + 2 + 2 ) )
1440 font_clip_box.xMin = FT_MulFix( FT_NEXT_SHORT( p1 ),
1441 face->root.size->metrics.x_scale );
1442 font_clip_box.yMin = FT_MulFix( FT_NEXT_SHORT( p1 ),
1443 face->root.size->metrics.y_scale );
1444 font_clip_box.xMax = FT_MulFix( FT_NEXT_SHORT( p1 ),
1445 face->root.size->metrics.x_scale );
1446 font_clip_box.yMax = FT_MulFix( FT_NEXT_SHORT( p1 ),
1447 face->root.size->metrics.y_scale );
1449#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
1452 FT_ULong var_index_base = 0;
1454 FT_ItemVarDelta item_deltas[4] = { 0, 0, 0, 0 };
1458 if ( p1 > limit - 4 )
1461 var_index_base = FT_NEXT_ULONG( p1 );
1463 if ( !get_deltas_for_var_index_base( face, colr, var_index_base, 4,
1467 font_clip_box.xMin +=
1468 FT_MulFix( item_deltas[0], face->root.size->metrics.x_scale );
1469 font_clip_box.yMin +=
1470 FT_MulFix( item_deltas[1], face->root.size->metrics.y_scale );
1471 font_clip_box.xMax +=
1472 FT_MulFix( item_deltas[2], face->root.size->metrics.x_scale );
1473 font_clip_box.yMax +=
1474 FT_MulFix( item_deltas[3], face->root.size->metrics.y_scale );
1482 corners[0].x = font_clip_box.xMin;
1483 corners[1].x = font_clip_box.xMin;
1484 corners[2].x = font_clip_box.xMax;
1485 corners[3].x = font_clip_box.xMax;
1487 corners[0].y = font_clip_box.yMin;
1488 corners[1].y = font_clip_box.yMax;
1489 corners[2].y = font_clip_box.yMax;
1490 corners[3].y = font_clip_box.yMin;
1492 for ( j = 0; j < num_corners; ++j )
1494 if ( face->root.internal->transform_flags & 1 )
1495 FT_Vector_Transform( &corners[j],
1496 &face->root.internal->transform_matrix );
1498 if ( face->root.internal->transform_flags & 2 )
1500 corners[j].x += face->root.internal->transform_delta.x;
1501 corners[j].y += face->root.internal->transform_delta.y;
1505 clip_box->bottom_left = corners[0];
1506 clip_box->top_left = corners[1];
1507 clip_box->top_right = corners[2];
1508 clip_box->bottom_right = corners[3];
1518 FT_LOCAL_DEF( FT_Bool )
1519 tt_face_get_paint_layers( TT_Face face,
1520 FT_LayerIterator* iterator,
1521 FT_OpaquePaint* opaque_paint )
1524 FT_Byte* p_first_layer = NULL;
1525 FT_Byte* p_paint = NULL;
1526 FT_UInt32 paint_offset;
1531 if ( iterator->layer == iterator->num_layers )
1534 colr = (Colr*)face->colr;
1551 iterator->layer * LAYER_V1_LIST_PAINT_OFFSET_SIZE -
1552 LAYER_V1_LIST_NUM_LAYERS_SIZE;
1553 if ( p_first_layer < (FT_Byte*)colr->layers_v1 )
1555 if ( p_first_layer >= (FT_Byte*)(
1556 colr->layers_v1 + LAYER_V1_LIST_NUM_LAYERS_SIZE +
1557 colr->num_layers_v1 * LAYER_V1_LIST_PAINT_OFFSET_SIZE ) )
1564 if ( p < colr->layers_v1 ||
1565 p > (FT_Byte*)colr->table + colr->table_size - 4 )
1570 opaque_paint->insert_root_transform =
1573 p_paint = (FT_Byte*)( colr->layers_v1 + paint_offset );
1575 if ( p_paint < colr->paints_start_v1 ||
1576 p_paint >= ( (FT_Byte*)colr->table + colr->table_size ) )
1579 opaque_paint->p = p_paint;
1589 FT_LOCAL_DEF( FT_Bool )
1590 tt_face_get_colorline_stops( TT_Face face,
1591 FT_ColorStop* color_stop,
1592 FT_ColorStopIterator *iterator )
1594 Colr* colr = (Colr*)face->colr;
1597 FT_ULong var_index_base;
1598 FT_Byte* last_entry_p = NULL;
1599 FT_UInt entry_size = COLOR_STOP_SIZE;
1602 if ( !colr || !colr->table || !iterator )
1605 if ( iterator->current_color_stop >= iterator->num_color_stops )
1608 if ( iterator->read_variable )
1609 entry_size += VAR_IDX_BASE_SIZE;
1616 iterator->p + ( iterator->num_color_stops - 1 -
1617 iterator->current_color_stop ) * entry_size;
1618 if ( iterator->p < colr->paints_start_v1 ||
1619 last_entry_p > (FT_Byte*)colr->table +
1620 colr->table_size - entry_size )
1626 color_stop->stop_offset = F2DOT14_TO_FIXED( FT_NEXT_SHORT( p ) );
1628 color_stop->color.palette_index = FT_NEXT_USHORT( p );
1630 color_stop->color.alpha = FT_NEXT_SHORT( p );
1632 if ( iterator->read_variable )
1637 var_index_base = FT_NEXT_ULONG( p );
1639#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
1641 FT_Int item_deltas[2];
1644 if ( !get_deltas_for_var_index_base( face, colr,
1650 color_stop->stop_offset += F2DOT14_TO_FIXED( item_deltas[0] );
1651 color_stop->color.alpha += (FT_F2Dot14)item_deltas[1];
1654 FT_UNUSED( var_index_base );
1659 iterator->current_color_stop++;
1665 FT_LOCAL_DEF( FT_Bool )
1666 tt_face_get_paint( TT_Face face,
1667 FT_OpaquePaint opaque_paint,
1668 FT_COLR_Paint* paint )
1670 Colr* colr = (Colr*)face->colr;
1671 FT_OpaquePaint next_paint;
1672 FT_Matrix ft_root_scale;
1674 if ( !colr || !colr->base_glyphs_v1 || !colr->table )
1677 if ( opaque_paint.insert_root_transform )
1691 paint->format = FT_COLR_PAINTFORMAT_TRANSFORM;
1693 next_paint.p = opaque_paint.p;
1694 next_paint.insert_root_transform = 0;
1695 paint->u.transform.paint = next_paint;
1701 ft_root_scale.xx = ( face->root.size->metrics.x_scale + 32 ) >> 6;
1702 ft_root_scale.xy = 0;
1703 ft_root_scale.yx = 0;
1704 ft_root_scale.yy = ( face->root.size->metrics.y_scale + 32 ) >> 6;
1706 if ( face->root.internal->transform_flags & 1 )
1707 FT_Matrix_Multiply( &face->root.internal->transform_matrix,
1710 paint->u.transform.affine.xx = ft_root_scale.xx;
1711 paint->u.transform.affine.xy = ft_root_scale.xy;
1712 paint->u.transform.affine.yx = ft_root_scale.yx;
1713 paint->u.transform.affine.yy = ft_root_scale.yy;
1721 if ( face->root.internal->transform_flags & 2 )
1723 paint->u.transform.affine.dx =
1724 face->root.internal->transform_delta.x * ( 1 << 10 );
1725 paint->u.transform.affine.dy =
1726 face->root.internal->transform_delta.y * ( 1 << 10 );
1730 paint->u.transform.affine.dx = 0;
1731 paint->u.transform.affine.dy = 0;
1737 return read_paint( face, colr, opaque_paint.p, paint );
1741 FT_LOCAL_DEF( FT_Error )
1742 tt_face_colr_blend_layer( TT_Face face,
1743 FT_UInt color_index,
1744 FT_GlyphSlot dstSlot,
1745 FT_GlyphSlot srcSlot )
1750 FT_Byte b, g, r, alpha;
1757 if ( !dstSlot->bitmap.buffer )
1761 dstSlot->bitmap_left = srcSlot->bitmap_left;
1762 dstSlot->bitmap_top = srcSlot->bitmap_top;
1764 dstSlot->bitmap.width = srcSlot->bitmap.width;
1765 dstSlot->bitmap.rows = srcSlot->bitmap.rows;
1766 dstSlot->bitmap.pixel_mode = FT_PIXEL_MODE_BGRA;
1767 dstSlot->bitmap.pitch = (int)dstSlot->bitmap.width * 4;
1768 dstSlot->bitmap.num_grays = 256;
1770 size = dstSlot->bitmap.rows * (
unsigned int)dstSlot->bitmap.pitch;
1772 error = ft_glyphslot_alloc_bitmap( dstSlot, size );
1776 FT_MEM_ZERO( dstSlot->bitmap.buffer, size );
1781 FT_Int x_min, x_max, y_min, y_max;
1784 x_min = FT_MIN( dstSlot->bitmap_left, srcSlot->bitmap_left );
1785 x_max = FT_MAX( dstSlot->bitmap_left + (FT_Int)dstSlot->bitmap.width,
1786 srcSlot->bitmap_left + (FT_Int)srcSlot->bitmap.width );
1788 y_min = FT_MIN( dstSlot->bitmap_top - (FT_Int)dstSlot->bitmap.rows,
1789 srcSlot->bitmap_top - (FT_Int)srcSlot->bitmap.rows );
1790 y_max = FT_MAX( dstSlot->bitmap_top, srcSlot->bitmap_top );
1792 if ( x_min != dstSlot->bitmap_left ||
1793 x_max != dstSlot->bitmap_left + (FT_Int)dstSlot->bitmap.width ||
1794 y_min != dstSlot->bitmap_top - (FT_Int)dstSlot->bitmap.rows ||
1795 y_max != dstSlot->bitmap_top )
1797 FT_Memory memory = face->root.memory;
1799 FT_UInt width = (FT_UInt)( x_max - x_min );
1800 FT_UInt rows = (FT_UInt)( y_max - y_min );
1801 FT_UInt pitch = width * 4;
1803 FT_Byte* buf = NULL;
1808 size = rows * pitch;
1809 if ( FT_ALLOC( buf, size ) )
1812 p = dstSlot->bitmap.buffer;
1814 (int)pitch * ( y_max - dstSlot->bitmap_top ) +
1815 4 * ( dstSlot->bitmap_left - x_min );
1817 for ( y = 0; y < dstSlot->bitmap.rows; y++ )
1819 FT_MEM_COPY( q, p, dstSlot->bitmap.width * 4 );
1821 p += dstSlot->bitmap.pitch;
1825 ft_glyphslot_set_bitmap( dstSlot, buf );
1827 dstSlot->bitmap_top = y_max;
1828 dstSlot->bitmap_left = x_min;
1830 dstSlot->bitmap.width = width;
1831 dstSlot->bitmap.rows = rows;
1832 dstSlot->bitmap.pitch = (int)pitch;
1834 dstSlot->internal->flags |= FT_GLYPH_OWN_BITMAP;
1835 dstSlot->format = FT_GLYPH_FORMAT_BITMAP;
1839 if ( color_index == 0xFFFF )
1841 if ( face->have_foreground_color )
1843 b = face->foreground_color.blue;
1844 g = face->foreground_color.green;
1845 r = face->foreground_color.red;
1846 alpha = face->foreground_color.alpha;
1850 if ( face->palette_data.palette_flags &&
1851 ( face->palette_data.palette_flags[face->palette_index] &
1852 FT_PALETTE_FOR_DARK_BACKGROUND ) )
1872 b = face->palette[color_index].blue;
1873 g = face->palette[color_index].green;
1874 r = face->palette[color_index].red;
1875 alpha = face->palette[color_index].alpha;
1879 src = srcSlot->bitmap.buffer;
1880 dst = dstSlot->bitmap.buffer +
1881 dstSlot->bitmap.pitch * ( dstSlot->bitmap_top - srcSlot->bitmap_top ) +
1882 4 * ( srcSlot->bitmap_left - dstSlot->bitmap_left );
1884 for ( y = 0; y < srcSlot->bitmap.rows; y++ )
1886 for ( x = 0; x < srcSlot->bitmap.width; x++ )
1889 int fa = alpha * aa / 255;
1891 int fb = b * fa / 255;
1892 int fg = g * fa / 255;
1893 int fr = r * fa / 255;
1897 int bb = dst[4 * x + 0];
1898 int bg = dst[4 * x + 1];
1899 int br = dst[4 * x + 2];
1900 int ba = dst[4 * x + 3];
1903 dst[4 * x + 0] = (FT_Byte)( bb * ba2 / 255 + fb );
1904 dst[4 * x + 1] = (FT_Byte)( bg * ba2 / 255 + fg );
1905 dst[4 * x + 2] = (FT_Byte)( br * ba2 / 255 + fr );
1906 dst[4 * x + 3] = (FT_Byte)( ba * ba2 / 255 + fa );
1909 src += srcSlot->bitmap.pitch;
1910 dst += dstSlot->bitmap.pitch;
1919 typedef int tt_colr_dummy_;