49#define FT_COMPONENT glyph
60 FT_CALLBACK_DEF( FT_Error )
61 ft_bitmap_glyph_init( FT_Glyph bitmap_glyph,
64 FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph;
65 FT_Error error = FT_Err_Ok;
66 FT_Library library = FT_GLYPH( glyph )->library;
69 if ( slot->format != FT_GLYPH_FORMAT_BITMAP )
71 error = FT_THROW( Invalid_Glyph_Format );
75 glyph->left = slot->bitmap_left;
76 glyph->top = slot->bitmap_top;
79 if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
81 glyph->bitmap = slot->bitmap;
82 slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
86 FT_Bitmap_Init( &glyph->bitmap );
87 error = FT_Bitmap_Copy( library, &slot->bitmap, &glyph->bitmap );
95 FT_CALLBACK_DEF( FT_Error )
96 ft_bitmap_glyph_copy( FT_Glyph bitmap_source,
97 FT_Glyph bitmap_target )
99 FT_Library library = bitmap_source->library;
100 FT_BitmapGlyph source = (FT_BitmapGlyph)bitmap_source;
101 FT_BitmapGlyph target = (FT_BitmapGlyph)bitmap_target;
104 target->left = source->left;
105 target->top = source->top;
107 return FT_Bitmap_Copy( library, &source->bitmap, &target->bitmap );
111 FT_CALLBACK_DEF(
void )
112 ft_bitmap_glyph_done( FT_Glyph bitmap_glyph )
114 FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph;
115 FT_Library library = FT_GLYPH( glyph )->library;
118 FT_Bitmap_Done( library, &glyph->bitmap );
122 FT_CALLBACK_DEF(
void )
123 ft_bitmap_glyph_bbox( FT_Glyph bitmap_glyph,
126 FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph;
129 cbox->xMin = glyph->left * 64;
130 cbox->xMax = cbox->xMin + (FT_Pos)( glyph->bitmap.width * 64 );
131 cbox->yMax = glyph->top * 64;
132 cbox->yMin = cbox->yMax - (FT_Pos)( glyph->bitmap.rows * 64 );
137 ft_bitmap_glyph_class,
139 sizeof ( FT_BitmapGlyphRec ),
140 FT_GLYPH_FORMAT_BITMAP,
142 ft_bitmap_glyph_init,
143 ft_bitmap_glyph_done,
144 ft_bitmap_glyph_copy,
146 ft_bitmap_glyph_bbox,
160 FT_CALLBACK_DEF( FT_Error )
161 ft_outline_glyph_init( FT_Glyph outline_glyph,
164 FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph;
165 FT_Error error = FT_Err_Ok;
166 FT_Library library = FT_GLYPH( glyph )->library;
167 FT_Outline* source = &slot->outline;
168 FT_Outline* target = &glyph->outline;
172 if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
174 error = FT_THROW( Invalid_Glyph_Format );
179 error = FT_Outline_New( library,
180 (FT_UInt)source->n_points,
186 FT_Outline_Copy( source, target );
193 FT_CALLBACK_DEF(
void )
194 ft_outline_glyph_done( FT_Glyph outline_glyph )
196 FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph;
199 FT_Outline_Done( FT_GLYPH( glyph )->library, &glyph->outline );
203 FT_CALLBACK_DEF( FT_Error )
204 ft_outline_glyph_copy( FT_Glyph outline_source,
205 FT_Glyph outline_target )
207 FT_OutlineGlyph source = (FT_OutlineGlyph)outline_source;
208 FT_OutlineGlyph target = (FT_OutlineGlyph)outline_target;
210 FT_Library library = FT_GLYPH( source )->library;
213 error = FT_Outline_New( library,
214 (FT_UInt)source->outline.n_points,
215 source->outline.n_contours,
218 FT_Outline_Copy( &source->outline, &target->outline );
224 FT_CALLBACK_DEF(
void )
225 ft_outline_glyph_transform( FT_Glyph outline_glyph,
226 const FT_Matrix* matrix,
227 const FT_Vector* delta )
229 FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph;
233 FT_Outline_Transform( &glyph->outline, matrix );
236 FT_Outline_Translate( &glyph->outline, delta->x, delta->y );
240 FT_CALLBACK_DEF(
void )
241 ft_outline_glyph_bbox( FT_Glyph outline_glyph,
244 FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph;
247 FT_Outline_Get_CBox( &glyph->outline, bbox );
251 FT_CALLBACK_DEF( FT_Error )
252 ft_outline_glyph_prepare( FT_Glyph outline_glyph,
255 FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph;
258 slot->format = FT_GLYPH_FORMAT_OUTLINE;
259 slot->outline = glyph->outline;
260 slot->outline.flags &= ~FT_OUTLINE_OWNER;
267 ft_outline_glyph_class,
269 sizeof ( FT_OutlineGlyphRec ),
270 FT_GLYPH_FORMAT_OUTLINE,
272 ft_outline_glyph_init,
273 ft_outline_glyph_done,
274 ft_outline_glyph_copy,
275 ft_outline_glyph_transform,
276 ft_outline_glyph_bbox,
277 ft_outline_glyph_prepare
281#ifdef FT_CONFIG_OPTION_SVG
292 FT_CALLBACK_DEF( FT_Error )
293 ft_svg_glyph_init( FT_Glyph svg_glyph,
297 FT_SVG_Document document;
298 FT_SvgGlyph glyph = (FT_SvgGlyph)svg_glyph;
300 FT_Error error = FT_Err_Ok;
301 FT_Memory memory = FT_GLYPH( glyph )->library->memory;
304 if ( slot->format != FT_GLYPH_FORMAT_SVG )
306 error = FT_THROW( Invalid_Glyph_Format );
310 if ( slot->other == NULL )
312 error = FT_THROW( Invalid_Slot_Handle );
316 document = (FT_SVG_Document)slot->other;
318 if ( document->svg_document_length == 0 )
320 error = FT_THROW( Invalid_Slot_Handle );
325 doc_length = document->svg_document_length;
326 if ( FT_QALLOC( glyph->svg_document, doc_length ) )
328 glyph->svg_document_length = doc_length;
330 glyph->glyph_index = slot->glyph_index;
332 glyph->metrics = document->metrics;
333 glyph->units_per_EM = document->units_per_EM;
335 glyph->start_glyph_id = document->start_glyph_id;
336 glyph->end_glyph_id = document->end_glyph_id;
338 glyph->transform = document->transform;
339 glyph->delta = document->delta;
342 FT_MEM_COPY( glyph->svg_document, document->svg_document, doc_length );
349 FT_CALLBACK_DEF(
void )
350 ft_svg_glyph_done( FT_Glyph svg_glyph )
352 FT_SvgGlyph glyph = (FT_SvgGlyph)svg_glyph;
353 FT_Memory memory = svg_glyph->library->memory;
357 FT_FREE( glyph->svg_document );
361 FT_CALLBACK_DEF( FT_Error )
362 ft_svg_glyph_copy( FT_Glyph svg_source,
363 FT_Glyph svg_target )
365 FT_SvgGlyph source = (FT_SvgGlyph)svg_source;
366 FT_SvgGlyph target = (FT_SvgGlyph)svg_target;
368 FT_Error error = FT_Err_Ok;
369 FT_Memory memory = FT_GLYPH( source )->library->memory;
372 if ( svg_source->format != FT_GLYPH_FORMAT_SVG )
374 error = FT_THROW( Invalid_Glyph_Format );
378 if ( source->svg_document_length == 0 )
380 error = FT_THROW( Invalid_Slot_Handle );
384 target->glyph_index = source->glyph_index;
386 target->svg_document_length = source->svg_document_length;
388 target->metrics = source->metrics;
389 target->units_per_EM = source->units_per_EM;
391 target->start_glyph_id = source->start_glyph_id;
392 target->end_glyph_id = source->end_glyph_id;
394 target->transform = source->transform;
395 target->delta = source->delta;
398 if ( FT_QALLOC( target->svg_document, target->svg_document_length ) )
402 FT_MEM_COPY( target->svg_document,
403 source->svg_document,
404 target->svg_document_length );
411 FT_CALLBACK_DEF(
void )
412 ft_svg_glyph_transform( FT_Glyph svg_glyph,
413 const FT_Matrix* _matrix,
414 const FT_Vector* _delta )
416 FT_SvgGlyph glyph = (FT_SvgGlyph)svg_glyph;
417 FT_Matrix* matrix = (FT_Matrix*)_matrix;
418 FT_Vector* delta = (FT_Vector*)_delta;
420 FT_Matrix tmp_matrix;
429 tmp_matrix.xx = 0x10000;
432 tmp_matrix.yy = 0x10000;
434 matrix = &tmp_matrix;
445 a = glyph->transform;
447 FT_Matrix_Multiply( &b, &a );
449 x = ADD_LONG( ADD_LONG( FT_MulFix( matrix->xx, glyph->delta.x ),
450 FT_MulFix( matrix->xy, glyph->delta.y ) ),
452 y = ADD_LONG( ADD_LONG( FT_MulFix( matrix->yx, glyph->delta.x ),
453 FT_MulFix( matrix->yy, glyph->delta.y ) ),
459 glyph->transform = a;
463 FT_CALLBACK_DEF( FT_Error )
464 ft_svg_glyph_prepare( FT_Glyph svg_glyph,
467 FT_SvgGlyph glyph = (FT_SvgGlyph)svg_glyph;
469 FT_Error error = FT_Err_Ok;
470 FT_Memory memory = svg_glyph->library->memory;
472 FT_SVG_Document document = NULL;
475 if ( FT_NEW( document ) )
478 document->svg_document = glyph->svg_document;
479 document->svg_document_length = glyph->svg_document_length;
481 document->metrics = glyph->metrics;
482 document->units_per_EM = glyph->units_per_EM;
484 document->start_glyph_id = glyph->start_glyph_id;
485 document->end_glyph_id = glyph->end_glyph_id;
487 document->transform = glyph->transform;
488 document->delta = glyph->delta;
490 slot->format = FT_GLYPH_FORMAT_SVG;
491 slot->glyph_index = glyph->glyph_index;
492 slot->other = document;
501 sizeof ( FT_SvgGlyphRec ),
507 ft_svg_glyph_transform,
524 ft_new_glyph( FT_Library library,
525 const FT_Glyph_Class* clazz,
528 FT_Memory memory = library->memory;
530 FT_Glyph glyph = NULL;
535 if ( !FT_ALLOC( glyph, clazz->glyph_size ) )
537 glyph->library = library;
538 glyph->clazz = clazz;
539 glyph->format = clazz->glyph_format;
550 FT_EXPORT_DEF( FT_Error )
551 FT_Glyph_Copy( FT_Glyph source,
556 const FT_Glyph_Class* clazz;
560 if ( !target || !source || !source->clazz )
562 error = FT_THROW( Invalid_Argument );
568 if ( !source || !source->clazz )
570 error = FT_THROW( Invalid_Argument );
574 clazz = source->clazz;
575 error = ft_new_glyph( source->library, clazz, © );
579 copy->advance = source->advance;
580 copy->format = source->format;
582 if ( clazz->glyph_copy )
583 error = clazz->glyph_copy( source, copy );
586 FT_Done_Glyph( copy );
597 FT_EXPORT( FT_Error )
598 FT_New_Glyph( FT_Library library,
599 FT_Glyph_Format format,
602 const FT_Glyph_Class* clazz = NULL;
604 if ( !library || !aglyph )
605 return FT_THROW( Invalid_Argument );
608 if ( format == FT_GLYPH_FORMAT_BITMAP )
609 clazz = &ft_bitmap_glyph_class;
612 else if ( format == FT_GLYPH_FORMAT_OUTLINE )
613 clazz = &ft_outline_glyph_class;
615#ifdef FT_CONFIG_OPTION_SVG
617 else if ( format == FT_GLYPH_FORMAT_SVG )
618 clazz = &ft_svg_glyph_class;
624 FT_Renderer render = FT_Lookup_Renderer( library, format, 0 );
628 clazz = &render->glyph_class;
632 return FT_THROW( Invalid_Glyph_Format );
635 return ft_new_glyph( library, clazz, aglyph );
641 FT_EXPORT_DEF( FT_Error )
642 FT_Get_Glyph( FT_GlyphSlot slot,
650 return FT_THROW( Invalid_Slot_Handle );
653 return FT_THROW( Invalid_Argument );
656 error = FT_New_Glyph( slot->library, slot->format, &glyph );
661 if ( slot->advance.x >= 0x8000L * 64 ||
662 slot->advance.x <= -0x8000L * 64 )
664 FT_ERROR((
"FT_Get_Glyph: advance width too large\n" ));
665 error = FT_THROW( Invalid_Argument );
668 if ( slot->advance.y >= 0x8000L * 64 ||
669 slot->advance.y <= -0x8000L * 64 )
671 FT_ERROR((
"FT_Get_Glyph: advance height too large\n" ));
672 error = FT_THROW( Invalid_Argument );
676 glyph->advance.x = slot->advance.x * 1024;
677 glyph->advance.y = slot->advance.y * 1024;
680 error = glyph->clazz->glyph_init( glyph, slot );
686 FT_Done_Glyph( glyph );
699 FT_EXPORT_DEF( FT_Error )
700 FT_Glyph_Transform( FT_Glyph glyph,
701 const FT_Matrix* matrix,
702 const FT_Vector* delta )
704 FT_Error error = FT_Err_Ok;
707 if ( !glyph || !glyph->clazz )
708 error = FT_THROW( Invalid_Argument );
711 const FT_Glyph_Class* clazz = glyph->clazz;
714 if ( clazz->glyph_transform )
717 clazz->glyph_transform( glyph, matrix, delta );
721 FT_Vector_Transform( &glyph->advance, matrix );
724 error = FT_THROW( Invalid_Glyph_Format );
732 FT_EXPORT_DEF(
void )
733 FT_Glyph_Get_CBox( FT_Glyph glyph,
737 const FT_Glyph_Class* clazz;
743 acbox->xMin = acbox->yMin = acbox->xMax = acbox->yMax = 0;
745 if ( !glyph || !glyph->clazz )
748 clazz = glyph->clazz;
749 if ( !clazz->glyph_bbox )
753 clazz->glyph_bbox( glyph, acbox );
756 if ( bbox_mode == FT_GLYPH_BBOX_GRIDFIT ||
757 bbox_mode == FT_GLYPH_BBOX_PIXELS )
759 acbox->xMin = FT_PIX_FLOOR( acbox->xMin );
760 acbox->yMin = FT_PIX_FLOOR( acbox->yMin );
761 acbox->xMax = FT_PIX_CEIL_LONG( acbox->xMax );
762 acbox->yMax = FT_PIX_CEIL_LONG( acbox->yMax );
766 if ( bbox_mode == FT_GLYPH_BBOX_TRUNCATE ||
767 bbox_mode == FT_GLYPH_BBOX_PIXELS )
779 FT_EXPORT_DEF( FT_Error )
780 FT_Glyph_To_Bitmap( FT_Glyph* the_glyph,
781 FT_Render_Mode render_mode,
782 const FT_Vector* origin,
785 FT_GlyphSlotRec dummy;
786 FT_GlyphSlot_InternalRec dummy_internal;
787 FT_Error error = FT_Err_Ok;
789 FT_BitmapGlyph bitmap = NULL;
790 const FT_Glyph_Class* clazz;
802 clazz = glyph->clazz;
803 library = glyph->library;
804 if ( !library || !clazz )
808 if ( clazz == &ft_bitmap_glyph_class )
811 if ( !clazz->glyph_prepare )
818 FT_ZERO( &dummy_internal );
819 dummy.internal = &dummy_internal;
820 dummy.library = library;
821 dummy.format = clazz->glyph_format;
824 error = ft_new_glyph( library, &ft_bitmap_glyph_class, &b );
827 bitmap = (FT_BitmapGlyph)b;
832 FT_Glyph_Transform( glyph, NULL, origin );
838 error = clazz->glyph_prepare( glyph, &dummy );
840 error = FT_Render_Glyph_Internal( glyph->library, &dummy, render_mode );
842#ifdef FT_CONFIG_OPTION_SVG
843 if ( clazz == &ft_svg_glyph_class )
845 FT_Memory memory = library->memory;
848 FT_FREE( dummy.other );
853 if ( !destroy && origin )
860 FT_Glyph_Transform( glyph, NULL, &v );
868 error = ft_bitmap_glyph_init( (FT_Glyph)bitmap, &dummy );
873 bitmap->root.advance = glyph->advance;
876 FT_Done_Glyph( glyph );
878 *the_glyph = FT_GLYPH( bitmap );
881 if ( error && bitmap )
882 FT_Done_Glyph( FT_GLYPH( bitmap ) );
887 error = FT_THROW( Invalid_Argument );
894 FT_EXPORT_DEF(
void )
895 FT_Done_Glyph( FT_Glyph glyph )
899 FT_Memory memory = glyph->library->memory;
900 const FT_Glyph_Class* clazz = glyph->clazz;
903 if ( clazz->glyph_done )
904 clazz->glyph_done( glyph );