2000-03-28 13:22:31 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ftglyph.c */
|
|
|
|
/* */
|
2000-05-30 18:49:14 +02:00
|
|
|
/* FreeType convenience functions to handle glyphs (body). */
|
2000-03-28 13:22:31 +02:00
|
|
|
/* */
|
2000-05-30 18:49:14 +02:00
|
|
|
/* Copyright 1996-2000 by */
|
2000-03-28 13:22:31 +02:00
|
|
|
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
|
|
|
|
/* */
|
2000-06-05 07:26:15 +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 */
|
2000-03-28 13:22:31 +02:00
|
|
|
/* 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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2000-05-30 18:49:14 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* This file contains the definition of several convenience functions */
|
|
|
|
/* that can be used by client applications to easily retrieve glyph */
|
|
|
|
/* bitmaps and outlines from a given face. */
|
|
|
|
/* */
|
|
|
|
/* These functions should be optional if you are writing a font server */
|
|
|
|
/* or text layout engine on top of FreeType. However, they are pretty */
|
|
|
|
/* handy for many other simple uses of the library. */
|
|
|
|
/* */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
|
2000-05-11 20:23:52 +02:00
|
|
|
#include <freetype/ftglyph.h>
|
2000-07-01 01:12:55 +02:00
|
|
|
#include <freetype/ftoutln.h>
|
2000-05-11 20:23:52 +02:00
|
|
|
#include <freetype/internal/ftobjs.h>
|
2000-03-28 13:22:31 +02:00
|
|
|
|
2000-05-30 18:49:14 +02:00
|
|
|
|
2000-06-03 08:03:11 +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. */
|
|
|
|
/* */
|
|
|
|
#undef FT_COMPONENT
|
|
|
|
#define FT_COMPONENT trace_glyph
|
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/**** ****/
|
|
|
|
/**** Convenience functions ****/
|
|
|
|
/**** ****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
2000-06-03 08:03:11 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* FT_Matrix_Multiply */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* Performs the matrix operation `b = a*b'. */
|
|
|
|
/* */
|
|
|
|
/* <Input> */
|
|
|
|
/* a :: A pointer to matrix `a'. */
|
|
|
|
/* */
|
|
|
|
/* <InOut> */
|
|
|
|
/* b :: A pointer to matrix `b'. */
|
|
|
|
/* */
|
|
|
|
/* <MT-Note> */
|
|
|
|
/* Yes. */
|
|
|
|
/* */
|
2000-07-01 16:06:46 +02:00
|
|
|
/* <Note> */
|
|
|
|
/* The result is undefined if either `a' or `b' is zero. */
|
|
|
|
/* */
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_EXPORT_DEF( void ) FT_Matrix_Multiply( FT_Matrix* a,
|
|
|
|
FT_Matrix* b )
|
2000-05-24 02:31:14 +02:00
|
|
|
{
|
2000-07-01 01:12:55 +02:00
|
|
|
FT_Fixed xx, xy, yx, yy;
|
2000-05-17 01:44:38 +02:00
|
|
|
|
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( !a || !b )
|
|
|
|
return;
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
xx = FT_MulFix( a->xx, b->xx ) + FT_MulFix( a->xy, b->yx );
|
|
|
|
xy = FT_MulFix( a->xx, b->xy ) + FT_MulFix( a->xy, b->yy );
|
|
|
|
yx = FT_MulFix( a->yx, b->xx ) + FT_MulFix( a->yy, b->yx );
|
|
|
|
yy = FT_MulFix( a->yx, b->xy ) + FT_MulFix( a->yy, b->yy );
|
2000-05-30 18:49:14 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
b->xx = xx; b->xy = xy;
|
|
|
|
b->yx = yx; b->yy = yy;
|
2000-03-28 13:22:31 +02:00
|
|
|
}
|
|
|
|
|
2000-05-30 18:49:14 +02:00
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
2000-07-01 01:12:55 +02:00
|
|
|
/* FT_Matrix_Invert */
|
2000-05-30 18:49:14 +02:00
|
|
|
/* */
|
|
|
|
/* <Description> */
|
2000-07-01 01:12:55 +02:00
|
|
|
/* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */
|
2000-05-30 18:49:14 +02:00
|
|
|
/* */
|
2000-07-01 01:12:55 +02:00
|
|
|
/* <InOut> */
|
|
|
|
/* matrix :: A pointer to the target matrix. Remains untouched in */
|
|
|
|
/* case of error. */
|
2000-05-30 18:49:14 +02:00
|
|
|
/* */
|
|
|
|
/* <Return> */
|
|
|
|
/* FreeType error code. 0 means success. */
|
|
|
|
/* */
|
2000-07-01 01:12:55 +02:00
|
|
|
/* <MT-Note> */
|
|
|
|
/* Yes. */
|
2000-05-30 18:49:14 +02:00
|
|
|
/* */
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_EXPORT_DEF( FT_Error ) FT_Matrix_Invert( FT_Matrix* matrix )
|
2000-03-28 13:22:31 +02:00
|
|
|
{
|
2000-07-01 01:12:55 +02:00
|
|
|
FT_Pos delta, xx, yy;
|
2000-05-30 18:49:14 +02:00
|
|
|
|
2000-03-28 13:22:31 +02:00
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( !matrix )
|
|
|
|
return FT_Err_Invalid_Argument;
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
/* compute discriminant */
|
|
|
|
delta = FT_MulFix( matrix->xx, matrix->yy ) -
|
|
|
|
FT_MulFix( matrix->xy, matrix->yx );
|
2000-05-30 18:49:14 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
if ( !delta )
|
|
|
|
return FT_Err_Invalid_Argument; /* matrix can't be inverted */
|
2000-06-02 02:01:14 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
matrix->xy = - FT_DivFix( matrix->xy, delta );
|
|
|
|
matrix->yx = - FT_DivFix( matrix->yx, delta );
|
2000-06-02 02:01:14 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
xx = matrix->xx;
|
|
|
|
yy = matrix->yy;
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
matrix->xx = FT_DivFix( yy, delta );
|
|
|
|
matrix->yy = FT_DivFix( xx, delta );
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/**** ****/
|
|
|
|
/**** FT_BitmapGlyph support ****/
|
|
|
|
/**** ****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
static
|
2000-07-01 16:06:46 +02:00
|
|
|
FT_Error ft_bitmap_copy( FT_Memory memory,
|
|
|
|
FT_Bitmap* source,
|
|
|
|
FT_Bitmap* target )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
FT_Int pitch = source->pitch;
|
|
|
|
FT_ULong size;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
*target = *source;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
if ( pitch < 0 )
|
|
|
|
pitch = -pitch;
|
|
|
|
|
|
|
|
size = (FT_ULong)( pitch * source->rows );
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
if ( !ALLOC( target->buffer, size ) )
|
2000-10-17 16:29:48 +02:00
|
|
|
MEM_Copy( target->buffer, source->buffer, size );
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
return error;
|
2000-07-01 16:06:46 +02:00
|
|
|
}
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
|
|
|
|
static
|
2000-07-01 16:06:46 +02:00
|
|
|
FT_Error ft_bitmap_glyph_init( FT_BitmapGlyph glyph,
|
|
|
|
FT_GlyphSlot slot )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
2000-07-01 16:06:46 +02:00
|
|
|
FT_Error error = FT_Err_Ok;
|
|
|
|
FT_Library library = FT_GLYPH(glyph)->library;
|
|
|
|
FT_Memory memory = library->memory;
|
|
|
|
|
|
|
|
|
|
|
|
if ( slot->format != ft_glyph_format_bitmap )
|
2000-03-28 13:22:31 +02:00
|
|
|
{
|
2000-07-01 01:12:55 +02:00
|
|
|
error = FT_Err_Invalid_Glyph_Format;
|
2000-03-28 13:22:31 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
/* grab the bitmap in the slot - do lazy copying whenever possible */
|
|
|
|
glyph->bitmap = slot->bitmap;
|
|
|
|
glyph->left = slot->bitmap_left;
|
|
|
|
glyph->top = slot->bitmap_top;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
if ( slot->flags & ft_glyph_own_bitmap )
|
|
|
|
slot->flags &= ~ft_glyph_own_bitmap;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* copy the bitmap into a new buffer */
|
|
|
|
error = ft_bitmap_copy( memory, &slot->bitmap, &glyph->bitmap );
|
|
|
|
}
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
Exit:
|
|
|
|
return error;
|
2000-07-01 16:06:46 +02:00
|
|
|
}
|
2000-03-28 13:22:31 +02:00
|
|
|
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
static
|
|
|
|
FT_Error ft_bitmap_glyph_copy( FT_BitmapGlyph source,
|
|
|
|
FT_BitmapGlyph target )
|
|
|
|
{
|
|
|
|
FT_Memory memory = source->root.library->memory;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
target->left = source->left;
|
|
|
|
target->top = source->top;
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
return ft_bitmap_copy( memory, &source->bitmap, &target->bitmap );
|
2000-07-01 16:06:46 +02:00
|
|
|
}
|
2000-06-29 05:14:25 +02:00
|
|
|
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
static
|
2000-07-01 16:06:46 +02:00
|
|
|
void ft_bitmap_glyph_done( FT_BitmapGlyph glyph )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
FT_Memory memory = FT_GLYPH(glyph)->library->memory;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
FREE( glyph->bitmap.buffer );
|
|
|
|
}
|
2000-05-17 01:44:38 +02:00
|
|
|
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
static
|
2000-07-01 16:06:46 +02:00
|
|
|
void ft_bitmap_glyph_bbox( FT_BitmapGlyph glyph,
|
|
|
|
FT_BBox* cbox )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
cbox->xMin = glyph->left << 6;
|
2000-07-01 16:06:46 +02:00
|
|
|
cbox->xMax = cbox->xMin + ( glyph->bitmap.width << 6 );
|
2000-07-01 01:12:55 +02:00
|
|
|
cbox->yMax = glyph->top << 6;
|
2000-10-17 16:29:48 +02:00
|
|
|
cbox->yMin = cbox->yMax - ( glyph->bitmap.rows << 6 );
|
2000-07-01 16:06:46 +02:00
|
|
|
}
|
2000-05-17 01:44:38 +02:00
|
|
|
|
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
const FT_Glyph_Class ft_bitmap_glyph_class =
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
sizeof( FT_BitmapGlyphRec ),
|
|
|
|
ft_glyph_format_bitmap,
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
(FT_Glyph_Init_Func) ft_bitmap_glyph_init,
|
|
|
|
(FT_Glyph_Done_Func) ft_bitmap_glyph_done,
|
|
|
|
(FT_Glyph_Copy_Func) ft_bitmap_glyph_copy,
|
|
|
|
(FT_Glyph_Transform_Func)0,
|
|
|
|
(FT_Glyph_BBox_Func) ft_bitmap_glyph_bbox,
|
|
|
|
(FT_Glyph_Prepare_Func) 0
|
2000-07-01 01:12:55 +02:00
|
|
|
};
|
2000-03-28 13:22:31 +02:00
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/**** ****/
|
|
|
|
/**** FT_OutlineGlyph support ****/
|
|
|
|
/**** ****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
2000-05-30 18:49:14 +02:00
|
|
|
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
static
|
2000-07-01 16:06:46 +02:00
|
|
|
FT_Error ft_outline_glyph_init( FT_OutlineGlyph glyph,
|
|
|
|
FT_GlyphSlot slot )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
2000-07-01 16:06:46 +02:00
|
|
|
FT_Error error = FT_Err_Ok;
|
|
|
|
FT_Library library = FT_GLYPH(glyph)->library;
|
|
|
|
FT_Outline* source = &slot->outline;
|
|
|
|
FT_Outline* target = &glyph->outline;
|
|
|
|
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
/* check format in glyph slot */
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( slot->format != ft_glyph_format_outline )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
error = FT_Err_Invalid_Glyph_Format;
|
2000-05-30 18:49:14 +02:00
|
|
|
goto Exit;
|
2000-03-28 13:22:31 +02:00
|
|
|
}
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
/* allocate new outline */
|
|
|
|
error = FT_Outline_New( library, source->n_points, source->n_contours,
|
|
|
|
&glyph->outline );
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
2000-07-01 01:12:55 +02:00
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
/* copy it */
|
2000-07-01 01:12:55 +02:00
|
|
|
MEM_Copy( target->points, source->points,
|
|
|
|
source->n_points * sizeof ( FT_Vector ) );
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
MEM_Copy( target->tags, source->tags,
|
|
|
|
source->n_points * sizeof ( FT_Byte ) );
|
|
|
|
|
|
|
|
MEM_Copy( target->contours, source->contours,
|
|
|
|
source->n_contours * sizeof ( FT_Short ) );
|
|
|
|
|
|
|
|
/* copy all flags, except the `ft_outline_owner' one */
|
|
|
|
target->flags = source->flags | ft_outline_owner;
|
2000-05-30 18:49:14 +02:00
|
|
|
|
2000-03-28 13:22:31 +02:00
|
|
|
Exit:
|
|
|
|
return error;
|
2000-07-01 16:06:46 +02:00
|
|
|
}
|
|
|
|
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
static
|
|
|
|
void ft_outline_glyph_done( FT_OutlineGlyph glyph )
|
|
|
|
{
|
2000-07-01 16:06:46 +02:00
|
|
|
FT_Outline_Done( FT_GLYPH( glyph )->library, &glyph->outline );
|
2000-03-28 13:22:31 +02:00
|
|
|
}
|
|
|
|
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
static
|
|
|
|
FT_Error ft_outline_glyph_copy( FT_OutlineGlyph source,
|
|
|
|
FT_OutlineGlyph target )
|
2000-03-28 13:22:31 +02:00
|
|
|
{
|
2000-07-01 01:12:55 +02:00
|
|
|
FT_Error error;
|
2000-07-01 16:06:46 +02:00
|
|
|
FT_Library library = FT_GLYPH( source )->library;
|
|
|
|
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
error = FT_Outline_New( library, source->outline.n_points,
|
|
|
|
source->outline.n_contours, &target->outline );
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( !error )
|
2000-07-01 01:12:55 +02:00
|
|
|
FT_Outline_Copy( &source->outline, &target->outline );
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
return error;
|
|
|
|
}
|
2000-03-28 13:22:31 +02:00
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
static
|
|
|
|
void ft_outline_glyph_transform( FT_OutlineGlyph glyph,
|
|
|
|
FT_Matrix* matrix,
|
|
|
|
FT_Vector* delta )
|
|
|
|
{
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( matrix )
|
2000-07-01 01:12:55 +02:00
|
|
|
FT_Outline_Transform( &glyph->outline, matrix );
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
if ( delta )
|
2000-07-01 01:12:55 +02:00
|
|
|
FT_Outline_Translate( &glyph->outline, delta->x, delta->y );
|
|
|
|
}
|
2000-05-30 18:49:14 +02:00
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
static
|
|
|
|
void ft_outline_glyph_bbox( FT_OutlineGlyph glyph,
|
2000-07-01 16:06:46 +02:00
|
|
|
FT_BBox* bbox )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
FT_Outline_Get_CBox( &glyph->outline, bbox );
|
2000-07-01 16:06:46 +02:00
|
|
|
}
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
|
|
|
|
static
|
|
|
|
FT_Error ft_outline_glyph_prepare( FT_OutlineGlyph glyph,
|
|
|
|
FT_GlyphSlot slot )
|
|
|
|
{
|
|
|
|
slot->format = ft_glyph_format_outline;
|
|
|
|
slot->outline = glyph->outline;
|
|
|
|
slot->outline.flags &= ~ft_outline_owner;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
return FT_Err_Ok;
|
2000-07-01 16:06:46 +02:00
|
|
|
}
|
|
|
|
|
2000-06-02 02:01:14 +02:00
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
const FT_Glyph_Class ft_outline_glyph_class =
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
sizeof( FT_OutlineGlyphRec ),
|
|
|
|
ft_glyph_format_outline,
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
(FT_Glyph_Init_Func) ft_outline_glyph_init,
|
|
|
|
(FT_Glyph_Done_Func) ft_outline_glyph_done,
|
|
|
|
(FT_Glyph_Copy_Func) ft_outline_glyph_copy,
|
|
|
|
(FT_Glyph_Transform_Func)ft_outline_glyph_transform,
|
|
|
|
(FT_Glyph_BBox_Func) ft_outline_glyph_bbox,
|
|
|
|
(FT_Glyph_Prepare_Func) ft_outline_glyph_prepare
|
2000-07-01 01:12:55 +02:00
|
|
|
};
|
2000-06-02 02:01:14 +02:00
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/**** ****/
|
|
|
|
/**** FT_Glyph class and API ****/
|
|
|
|
/**** ****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
static
|
2000-07-01 16:06:46 +02:00
|
|
|
FT_Error ft_new_glyph( FT_Library library,
|
|
|
|
const FT_Glyph_Class* clazz,
|
|
|
|
FT_Glyph* aglyph )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
FT_Memory memory = library->memory;
|
|
|
|
FT_Error error;
|
|
|
|
FT_Glyph glyph;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
*aglyph = 0;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
if ( !ALLOC( glyph, clazz->glyph_size ) )
|
|
|
|
{
|
|
|
|
glyph->library = library;
|
|
|
|
glyph->clazz = clazz;
|
|
|
|
glyph->format = clazz->glyph_format;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
*aglyph = glyph;
|
|
|
|
}
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
return error;
|
2000-07-01 16:06:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* FT_Glyph_Copy */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* A function used to copy a glyph image. */
|
|
|
|
/* */
|
|
|
|
/* <Input> */
|
|
|
|
/* source :: A handle to the source glyph object. */
|
|
|
|
/* */
|
|
|
|
/* <Output> */
|
|
|
|
/* target :: A handle to the target glyph object. 0 in case of */
|
|
|
|
/* error. */
|
|
|
|
/* */
|
|
|
|
/* <Return> */
|
|
|
|
/* FreeType error code. 0 means success. */
|
|
|
|
/* */
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_EXPORT_DEF( FT_Error ) FT_Glyph_Copy( FT_Glyph source,
|
2000-07-01 16:06:46 +02:00
|
|
|
FT_Glyph* target )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
FT_Glyph copy;
|
|
|
|
FT_Error error;
|
|
|
|
const FT_Glyph_Class* clazz;
|
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
/* check arguments */
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( !target || !source || !source->clazz )
|
2000-03-28 13:22:31 +02:00
|
|
|
{
|
|
|
|
error = FT_Err_Invalid_Argument;
|
|
|
|
goto Exit;
|
|
|
|
}
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
*target = 0;
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
clazz = source->clazz;
|
|
|
|
error = ft_new_glyph( source->library, clazz, © );
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
2000-07-01 01:12:55 +02:00
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( clazz->glyph_copy )
|
2000-07-01 01:12:55 +02:00
|
|
|
error = clazz->glyph_copy( source, copy );
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
if ( error )
|
2000-07-01 01:12:55 +02:00
|
|
|
FT_Done_Glyph( copy );
|
|
|
|
else
|
|
|
|
*target = copy;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
Exit:
|
|
|
|
return error;
|
2000-07-01 16:06:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* FT_Get_Glyph */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* A function used to extract a glyph image from a slot. */
|
|
|
|
/* */
|
|
|
|
/* <Input> */
|
|
|
|
/* slot :: A handle to the source glyph slot. */
|
|
|
|
/* */
|
|
|
|
/* <Output> */
|
|
|
|
/* aglyph :: A handle to the glyph object. */
|
|
|
|
/* */
|
|
|
|
/* <Return> */
|
|
|
|
/* FreeType error code. 0 means success. */
|
|
|
|
/* */
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_EXPORT_DEF( FT_Error ) FT_Get_Glyph( FT_GlyphSlot slot,
|
|
|
|
FT_Glyph* aglyph )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
FT_Library library = slot->library;
|
|
|
|
FT_Error error;
|
|
|
|
FT_Glyph glyph;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
const FT_Glyph_Class* clazz = 0;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
if ( !slot )
|
|
|
|
return FT_Err_Invalid_Slot_Handle;
|
|
|
|
|
2000-07-04 05:37:18 +02:00
|
|
|
if ( !aglyph )
|
2000-07-01 16:06:46 +02:00
|
|
|
return FT_Err_Invalid_Argument;
|
|
|
|
|
|
|
|
/* if it is a bitmap, that's easy :-) */
|
|
|
|
if ( slot->format == ft_glyph_format_bitmap )
|
2000-07-01 01:12:55 +02:00
|
|
|
clazz = &ft_bitmap_glyph_class;
|
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
/* it it is an outline too */
|
|
|
|
else if ( slot->format == ft_glyph_format_outline )
|
2000-07-01 01:12:55 +02:00
|
|
|
clazz = &ft_outline_glyph_class;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
else
|
2000-03-28 13:22:31 +02:00
|
|
|
{
|
2000-07-01 01:12:55 +02:00
|
|
|
/* try to find a renderer that supports the glyph image format */
|
|
|
|
FT_Renderer render = FT_Lookup_Renderer( library, slot->format, 0 );
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
if ( render )
|
2000-07-01 01:12:55 +02:00
|
|
|
clazz = &render->glyph_class;
|
2000-03-28 13:22:31 +02:00
|
|
|
}
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
if ( !clazz )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
error = FT_Err_Invalid_Glyph_Format;
|
2000-03-28 13:22:31 +02:00
|
|
|
goto Exit;
|
2000-07-01 01:12:55 +02:00
|
|
|
}
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
/* create FT_Glyph object */
|
|
|
|
error = ft_new_glyph( library, clazz, &glyph );
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
/* copy advance while converting it to 16.16 format */
|
2000-07-01 01:12:55 +02:00
|
|
|
glyph->advance.x = slot->advance.x << 10;
|
|
|
|
glyph->advance.y = slot->advance.y << 10;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
/* now import the image from the glyph slot */
|
|
|
|
error = clazz->glyph_init( glyph, slot );
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
/* if an error occurred, destroy the glyph */
|
|
|
|
if ( error )
|
2000-07-01 01:12:55 +02:00
|
|
|
FT_Done_Glyph( glyph );
|
|
|
|
else
|
|
|
|
*aglyph = glyph;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-03-28 13:22:31 +02:00
|
|
|
Exit:
|
|
|
|
return error;
|
2000-07-01 16:06:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* FT_Glyph_Transform */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* Transforms a glyph image if its format is scalable. */
|
|
|
|
/* */
|
|
|
|
/* <Input> */
|
|
|
|
/* glyph :: A handle to the target glyph object. */
|
|
|
|
/* */
|
|
|
|
/* matrix :: A pointer to a 2x2 matrix to apply. */
|
|
|
|
/* */
|
|
|
|
/* delta :: A pointer to a 2d vector to apply. Coordinates are */
|
|
|
|
/* expressed in 1/64th of a pixel. */
|
|
|
|
/* */
|
|
|
|
/* <Return> */
|
|
|
|
/* FreeType error code (the glyph format is not scalable if it is */
|
|
|
|
/* not zero). */
|
|
|
|
/* */
|
|
|
|
/* <Note> */
|
|
|
|
/* The 2x2 transformation matrix is also applied to the glyph's */
|
|
|
|
/* advance vector. */
|
2000-07-04 05:37:18 +02:00
|
|
|
/* */
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_EXPORT_DEF( FT_Error ) FT_Glyph_Transform( FT_Glyph glyph,
|
|
|
|
FT_Matrix* matrix,
|
|
|
|
FT_Vector* delta )
|
2000-03-28 13:22:31 +02:00
|
|
|
{
|
2000-07-01 01:12:55 +02:00
|
|
|
const FT_Glyph_Class* clazz;
|
|
|
|
FT_Error error = FT_Err_Ok;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
if ( !glyph || !glyph->clazz )
|
2000-07-01 01:12:55 +02:00
|
|
|
error = FT_Err_Invalid_Argument;
|
|
|
|
else
|
2000-03-28 13:22:31 +02:00
|
|
|
{
|
2000-07-01 01:12:55 +02:00
|
|
|
clazz = glyph->clazz;
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( clazz->glyph_transform )
|
2000-03-28 13:22:31 +02:00
|
|
|
{
|
2000-07-01 01:12:55 +02:00
|
|
|
/* transform glyph image */
|
|
|
|
clazz->glyph_transform( glyph, matrix, delta );
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
/* transform advance vector */
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( matrix )
|
2000-07-01 01:12:55 +02:00
|
|
|
FT_Vector_Transform( &glyph->advance, matrix );
|
2000-03-28 13:22:31 +02:00
|
|
|
}
|
2000-07-01 01:12:55 +02:00
|
|
|
else
|
|
|
|
error = FT_Err_Invalid_Glyph_Format;
|
|
|
|
}
|
|
|
|
return error;
|
2000-07-01 16:06:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* FT_Glyph_Get_CBox */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* Returns the glyph image's bounding box. */
|
|
|
|
/* */
|
|
|
|
/* <Input> */
|
|
|
|
/* glyph :: A handle to the source glyph object. */
|
|
|
|
/* */
|
2000-10-12 01:31:12 +02:00
|
|
|
/* mode :: The mode which indicates how to interpret the returned */
|
|
|
|
/* bounding box values. */
|
2000-07-01 16:06:46 +02:00
|
|
|
/* */
|
|
|
|
/* <Output> */
|
|
|
|
/* box :: The glyph bounding box. Coordinates are expressed in */
|
|
|
|
/* 1/64th of pixels if it is grid-fitted. */
|
|
|
|
/* */
|
|
|
|
/* <Note> */
|
|
|
|
/* Coordinates are relative to the glyph origin, using the Y-upwards */
|
|
|
|
/* convention. */
|
|
|
|
/* */
|
2000-10-12 01:31:12 +02:00
|
|
|
/* If the glyph has been loaded with FT_LOAD_NO_SCALE, `bbox_mode' */
|
|
|
|
/* must be set to `ft_glyph_bbox_unscaled' to get unscaled font */
|
|
|
|
/* units. */
|
|
|
|
/* */
|
|
|
|
/* If `bbox_mode' is set to `ft_glyph_bbox_subpixels' the bbox */
|
2000-07-01 16:06:46 +02:00
|
|
|
/* coordinates are returned in 26.6 pixels (i.e. 1/64th of pixels). */
|
|
|
|
/* */
|
|
|
|
/* Note that the maximum coordinates are exclusive, which means that */
|
|
|
|
/* one can compute the width and height of the glyph image (be it in */
|
|
|
|
/* integer or 26.6 pixels) as: */
|
|
|
|
/* */
|
|
|
|
/* width = bbox.xMax - bbox.xMin; */
|
|
|
|
/* height = bbox.yMax - bbox.yMin; */
|
|
|
|
/* */
|
2000-10-12 01:31:12 +02:00
|
|
|
/* Note also that for 26.6 coordinates, if `bbox_mode' is set to */
|
|
|
|
/* `ft_glyph_bbox_gridfit', the coordinates will also be grid-fitted, */
|
|
|
|
/* which corresponds to: */
|
2000-07-01 16:06:46 +02:00
|
|
|
/* */
|
|
|
|
/* bbox.xMin = FLOOR(bbox.xMin); */
|
|
|
|
/* bbox.yMin = FLOOR(bbox.yMin); */
|
|
|
|
/* bbox.xMax = CEILING(bbox.xMax); */
|
|
|
|
/* bbox.yMax = CEILING(bbox.yMax); */
|
|
|
|
/* */
|
2000-10-12 01:31:12 +02:00
|
|
|
/* To get the bbox in pixel coordinates, set `bbox_mode' to */
|
|
|
|
/* `ft_glyph_bbox_truncate'. */
|
|
|
|
/* */
|
|
|
|
/* To get the bbox in grid-fitted pixel coordinates, set `bbox_mode' */
|
|
|
|
/* to `ft_glyph_bbox_pixels'. */
|
|
|
|
/* */
|
|
|
|
/* The default value for `bbox_mode' is `ft_glyph_bbox_pixels'. */
|
2000-07-10 02:06:22 +02:00
|
|
|
/* */
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_EXPORT_DEF( void ) FT_Glyph_Get_CBox( FT_Glyph glyph,
|
|
|
|
FT_UInt bbox_mode,
|
|
|
|
FT_BBox* cbox )
|
2000-07-01 16:06:46 +02:00
|
|
|
{
|
2000-07-01 01:12:55 +02:00
|
|
|
const FT_Glyph_Class* clazz;
|
|
|
|
FT_Error error = FT_Err_Ok;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
if ( !cbox || !glyph || !glyph->clazz )
|
2000-07-01 01:12:55 +02:00
|
|
|
error = FT_Err_Invalid_Argument;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clazz = glyph->clazz;
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( !clazz->glyph_bbox )
|
2000-07-01 01:12:55 +02:00
|
|
|
error = FT_Err_Invalid_Glyph_Format;
|
|
|
|
else
|
2000-03-28 13:22:31 +02:00
|
|
|
{
|
2000-07-01 01:12:55 +02:00
|
|
|
/* retrieve bbox in 26.6 coordinates */
|
|
|
|
clazz->glyph_bbox( glyph, cbox );
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
/* perform grid fitting if needed */
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( bbox_mode & ft_glyph_bbox_gridfit )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
cbox->xMin &= -64;
|
|
|
|
cbox->yMin &= -64;
|
2000-07-01 16:06:46 +02:00
|
|
|
cbox->xMax = ( cbox->xMax + 63 ) & -64;
|
|
|
|
cbox->yMax = ( cbox->yMax + 63 ) & -64;
|
2000-07-01 01:12:55 +02:00
|
|
|
}
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
/* convert to integer pixels if needed */
|
2000-08-21 06:43:01 +02:00
|
|
|
if ( bbox_mode & ft_glyph_bbox_truncate )
|
2000-03-28 13:22:31 +02:00
|
|
|
{
|
2000-07-01 01:12:55 +02:00
|
|
|
cbox->xMin >>= 6;
|
|
|
|
cbox->yMin >>= 6;
|
|
|
|
cbox->xMax >>= 6;
|
|
|
|
cbox->yMax >>= 6;
|
2000-03-28 13:22:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-07-01 01:12:55 +02:00
|
|
|
return;
|
2000-03-28 13:22:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* FT_Glyph_To_Bitmap */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* Converts a given glyph object to a bitmap glyph object. */
|
|
|
|
/* */
|
|
|
|
/* <InOut> */
|
|
|
|
/* glyph :: A pointer to a handle to the target glyph. */
|
|
|
|
/* */
|
|
|
|
/* <Input> */
|
|
|
|
/* render_mode :: A set of bit flags that describe how the data is */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* origin :: A pointer to a vector used to translate the glyph */
|
|
|
|
/* image before rendering. Can be 0 (if no */
|
|
|
|
/* translation). The origin is expressed in */
|
|
|
|
/* 26.6 pixels. */
|
|
|
|
/* */
|
|
|
|
/* destroy :: A boolean that indicates that the original glyph */
|
|
|
|
/* image should be destroyed by this function. It is */
|
|
|
|
/* never destroyed in case of error. */
|
|
|
|
/* */
|
|
|
|
/* <Return> */
|
|
|
|
/* FreeType error code. 0 means success. */
|
|
|
|
/* */
|
|
|
|
/* <Note> */
|
|
|
|
/* The glyph image is translated with the `origin' vector before */
|
|
|
|
/* rendering. In case of error, it it translated back to its */
|
|
|
|
/* original position and the glyph is left untouched. */
|
|
|
|
/* */
|
|
|
|
/* The first parameter is a pointer to a FT_Glyph handle, that will */
|
|
|
|
/* be replaced by this function. Typically, you would use (omitting */
|
|
|
|
/* error handling): */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* { */
|
|
|
|
/* FT_Glyph glyph; */
|
|
|
|
/* FT_BitmapGlyph glyph_bitmap; */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* // load glyph */
|
|
|
|
/* error = FT_Load_Char( face, glyph_index, FT_LOAD_DEFAUT ); */
|
|
|
|
/* */
|
|
|
|
/* // extract glyph image */
|
|
|
|
/* error = FT_Get_Glyph( face->glyph, &glyph ); */
|
|
|
|
/* */
|
|
|
|
/* // convert to a bitmap (default render mode + destroy old) */
|
|
|
|
/* if ( glyph->format != ft_glyph_format_bitmap ) */
|
|
|
|
/* { */
|
|
|
|
/* error = FT_Glyph_To_Bitmap( &glyph, ft_render_mode_default, */
|
|
|
|
/* 0, 1 ); */
|
|
|
|
/* if ( error ) // glyph unchanged */
|
|
|
|
/* ... */
|
|
|
|
/* } */
|
|
|
|
/* */
|
|
|
|
/* // access bitmap content by typecasting */
|
|
|
|
/* glyph_bitmap = (FT_BitmapGlyph)glyph; */
|
|
|
|
/* */
|
|
|
|
/* // do funny stuff with it, like blitting/drawing */
|
|
|
|
/* ... */
|
|
|
|
/* */
|
|
|
|
/* // discard glyph image (bitmap or not) */
|
|
|
|
/* FT_Done_Glyph( glyph ); */
|
|
|
|
/* } */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* This function will always fail if the glyph's format isn't */
|
|
|
|
/* scalable. */
|
|
|
|
/* */
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_EXPORT_DEF( FT_Error ) FT_Glyph_To_Bitmap( FT_Glyph* the_glyph,
|
|
|
|
FT_ULong render_mode,
|
|
|
|
FT_Vector* origin,
|
2000-07-01 16:06:46 +02:00
|
|
|
FT_Bool destroy )
|
2000-03-28 13:22:31 +02:00
|
|
|
{
|
2000-07-01 01:12:55 +02:00
|
|
|
FT_GlyphSlotRec dummy;
|
|
|
|
FT_Error error;
|
|
|
|
FT_Glyph glyph;
|
|
|
|
FT_BitmapGlyph bitmap;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
const FT_Glyph_Class* clazz;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* check argument */
|
|
|
|
if ( !the_glyph )
|
2000-07-01 01:12:55 +02:00
|
|
|
goto Bad;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
/* we render the glyph into a glyph bitmap using a `dummy' glyph slot */
|
|
|
|
/* then calling FT_Render_Glyph_Internal() */
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
glyph = *the_glyph;
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( !glyph )
|
2000-07-01 01:12:55 +02:00
|
|
|
goto Bad;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
clazz = glyph->clazz;
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( !clazz || !clazz->glyph_prepare )
|
2000-07-01 01:12:55 +02:00
|
|
|
goto Bad;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
MEM_Set( &dummy, 0, sizeof ( dummy ) );
|
2000-07-01 01:12:55 +02:00
|
|
|
dummy.library = glyph->library;
|
|
|
|
dummy.format = clazz->glyph_format;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
/* if `origin' is set, translate the glyph image */
|
|
|
|
if ( origin )
|
2000-07-01 01:12:55 +02:00
|
|
|
FT_Glyph_Transform( glyph, 0, origin );
|
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
/* create result bitmap glyph */
|
2000-07-01 01:12:55 +02:00
|
|
|
error = ft_new_glyph( glyph->library, &ft_bitmap_glyph_class,
|
|
|
|
(FT_Glyph*)&bitmap );
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( error )
|
|
|
|
goto Exit;
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
/* prepare dummy slot for rendering */
|
2000-08-21 06:43:01 +02:00
|
|
|
error = clazz->glyph_prepare( glyph, &dummy );
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( !error )
|
2000-08-21 06:43:01 +02:00
|
|
|
error = FT_Render_Glyph_Internal( glyph->library, &dummy, render_mode );
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
if ( !destroy && origin )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
FT_Vector v;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
v.x = -origin->x;
|
|
|
|
v.y = -origin->y;
|
|
|
|
FT_Glyph_Transform( glyph, 0, &v );
|
|
|
|
}
|
2000-05-17 01:44:38 +02:00
|
|
|
|
2000-11-03 08:57:51 +01:00
|
|
|
/* in case of success, copy the bitmap to the glyph bitmap */
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( !error )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
error = ft_bitmap_glyph_init( bitmap, &dummy );
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( error )
|
2000-05-30 18:49:14 +02:00
|
|
|
{
|
2000-07-01 16:06:46 +02:00
|
|
|
/* this should never happen, but let's be safe */
|
|
|
|
FT_Done_Glyph( FT_GLYPH( bitmap ) );
|
2000-07-01 01:12:55 +02:00
|
|
|
goto Exit;
|
2000-06-02 02:01:14 +02:00
|
|
|
}
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-11-03 08:57:51 +01:00
|
|
|
/* copy advance */
|
|
|
|
bitmap->root.advance = glyph->advance;
|
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( destroy )
|
2000-07-01 01:12:55 +02:00
|
|
|
FT_Done_Glyph( glyph );
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
*the_glyph = FT_GLYPH( bitmap );
|
2000-07-01 01:12:55 +02:00
|
|
|
}
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
Exit:
|
|
|
|
return error;
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
Bad:
|
|
|
|
error = FT_Err_Invalid_Argument;
|
|
|
|
goto Exit;
|
2000-07-01 16:06:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* FT_Done_Glyph */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* Destroys a given glyph. */
|
|
|
|
/* */
|
|
|
|
/* <Input> */
|
|
|
|
/* glyph :: A handle to the target glyph object. */
|
|
|
|
/* */
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_EXPORT_DEF( void ) FT_Done_Glyph( FT_Glyph glyph )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
2000-07-01 16:06:46 +02:00
|
|
|
if ( glyph )
|
2000-07-01 01:12:55 +02:00
|
|
|
{
|
|
|
|
FT_Memory memory = glyph->library->memory;
|
|
|
|
const FT_Glyph_Class* clazz = glyph->clazz;
|
|
|
|
|
2000-07-01 16:06:46 +02:00
|
|
|
|
|
|
|
if ( clazz->glyph_done )
|
2000-07-01 01:12:55 +02:00
|
|
|
clazz->glyph_done( glyph );
|
2000-07-01 16:06:46 +02:00
|
|
|
|
2000-07-01 01:12:55 +02:00
|
|
|
FREE( glyph );
|
|
|
|
}
|
2000-03-28 13:22:31 +02:00
|
|
|
}
|
2000-05-05 15:11:36 +02:00
|
|
|
|
|
|
|
|
2000-05-30 18:49:14 +02:00
|
|
|
/* END */
|