summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/base/ftobjs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/freetype/src/base/ftobjs.c')
-rw-r--r--src/3rdparty/freetype/src/base/ftobjs.c692
1 files changed, 518 insertions, 174 deletions
diff --git a/src/3rdparty/freetype/src/base/ftobjs.c b/src/3rdparty/freetype/src/base/ftobjs.c
index c060bbbc87..89a25bc732 100644
--- a/src/3rdparty/freetype/src/base/ftobjs.c
+++ b/src/3rdparty/freetype/src/base/ftobjs.c
@@ -4,7 +4,7 @@
*
* The FreeType private base classes (body).
*
- * Copyright (C) 1996-2020 by
+ * Copyright (C) 1996-2023 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used,
@@ -19,6 +19,7 @@
#include <freetype/ftlist.h>
#include <freetype/ftoutln.h>
#include <freetype/ftfntfmt.h>
+#include <freetype/otsvg.h>
#include <freetype/internal/ftvalid.h>
#include <freetype/internal/ftobjs.h>
@@ -27,6 +28,7 @@
#include <freetype/internal/ftstream.h>
#include <freetype/internal/sfnt.h> /* for SFNT_Load_Table_Func */
#include <freetype/internal/psaux.h> /* for PS_Driver */
+#include <freetype/internal/svginterface.h>
#include <freetype/tttables.h>
#include <freetype/tttags.h>
@@ -78,6 +80,9 @@
#pragma warning( pop )
#endif
+ /* This array must stay in sync with the @FT_Pixel_Mode enumeration */
+ /* (in file `ftimage.h`). */
+
static const char* const pixel_modes[] =
{
"none",
@@ -87,7 +92,8 @@
"gray 4-bit bitmap",
"LCD 8-bit bitmap",
"vertical LCD 8-bit bitmap",
- "BGRA 32-bit color image bitmap"
+ "BGRA 32-bit color image bitmap",
+ "SDF 8-bit bitmap"
};
#endif /* FT_DEBUG_LEVEL_TRACE */
@@ -193,6 +199,7 @@
FT_Error error;
FT_Memory memory;
FT_Stream stream = NULL;
+ FT_UInt mode;
*astream = NULL;
@@ -204,49 +211,56 @@
return FT_THROW( Invalid_Argument );
memory = library->memory;
+ mode = args->flags &
+ ( FT_OPEN_MEMORY | FT_OPEN_STREAM | FT_OPEN_PATHNAME );
- if ( FT_NEW( stream ) )
- goto Exit;
-
- stream->memory = memory;
-
- if ( args->flags & FT_OPEN_MEMORY )
+ if ( mode == FT_OPEN_MEMORY )
{
/* create a memory-based stream */
+ if ( FT_NEW( stream ) )
+ goto Exit;
+
FT_Stream_OpenMemory( stream,
(const FT_Byte*)args->memory_base,
(FT_ULong)args->memory_size );
+ stream->memory = memory;
}
#ifndef FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT
- else if ( args->flags & FT_OPEN_PATHNAME )
+ else if ( mode == FT_OPEN_PATHNAME )
{
/* create a normal system stream */
+ if ( FT_NEW( stream ) )
+ goto Exit;
+
+ stream->memory = memory;
error = FT_Stream_Open( stream, args->pathname );
- stream->pathname.pointer = args->pathname;
+ if ( error )
+ FT_FREE( stream );
}
- else if ( ( args->flags & FT_OPEN_STREAM ) && args->stream )
+ else if ( ( mode == FT_OPEN_STREAM ) && args->stream )
{
/* use an existing, user-provided stream */
/* in this case, we do not need to allocate a new stream object */
/* since the caller is responsible for closing it himself */
- FT_FREE( stream );
- stream = args->stream;
+ stream = args->stream;
+ stream->memory = memory;
+ error = FT_Err_Ok;
}
#endif
else
+ {
error = FT_THROW( Invalid_Argument );
+ if ( ( args->flags & FT_OPEN_STREAM ) && args->stream )
+ FT_Stream_Close( args->stream );
+ }
- if ( error )
- FT_FREE( stream );
- else
- stream->memory = memory; /* just to be certain */
-
- *astream = stream;
+ if ( !error )
+ *astream = stream;
Exit:
return error;
@@ -316,6 +330,19 @@
if ( !error && clazz->init_slot )
error = clazz->init_slot( slot );
+#ifdef FT_CONFIG_OPTION_SVG
+ /* if SVG table exists, allocate the space in `slot->other` */
+ if ( slot->face->face_flags & FT_FACE_FLAG_SVG )
+ {
+ FT_SVG_Document document = NULL;
+
+
+ if ( FT_NEW( document ) )
+ goto Exit;
+ slot->other = document;
+ }
+#endif
+
Exit:
return error;
}
@@ -360,7 +387,18 @@
FT_Pos width, height, pitch;
- if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
+ if ( slot->format == FT_GLYPH_FORMAT_SVG )
+ {
+ FT_Module module;
+ SVG_Service svg_service;
+
+
+ module = FT_Get_Module( slot->library, "ot-svg" );
+ svg_service = (SVG_Service)module->clazz->module_interface;
+
+ return (FT_Bool)svg_service->preset_slot( module, slot, FALSE );
+ }
+ else if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
return 1;
if ( origin )
@@ -470,7 +508,7 @@
case FT_PIXEL_MODE_LCD_V:
height *= 3;
- /* fall through */
+ FALL_THROUGH;
case FT_PIXEL_MODE_GRAY:
default:
@@ -523,7 +561,7 @@
else
slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
- (void)FT_ALLOC( slot->bitmap.buffer, size );
+ FT_MEM_ALLOC( slot->bitmap.buffer, size );
return error;
}
@@ -535,6 +573,8 @@
ft_glyphslot_free_bitmap( slot );
/* clear all public fields in the glyph slot */
+ slot->glyph_index = 0;
+
FT_ZERO( &slot->metrics );
FT_ZERO( &slot->outline );
@@ -550,11 +590,32 @@
slot->subglyphs = NULL;
slot->control_data = NULL;
slot->control_len = 0;
- slot->other = NULL;
- slot->format = FT_GLYPH_FORMAT_NONE;
+
+#ifndef FT_CONFIG_OPTION_SVG
+ slot->other = NULL;
+#else
+ if ( !( slot->face->face_flags & FT_FACE_FLAG_SVG ) )
+ slot->other = NULL;
+ else
+ {
+ if ( slot->internal->flags & FT_GLYPH_OWN_GZIP_SVG )
+ {
+ FT_Memory memory = slot->face->memory;
+ FT_SVG_Document doc = (FT_SVG_Document)slot->other;
+
+
+ FT_FREE( doc->svg_document );
+ slot->internal->flags &= ~FT_GLYPH_OWN_GZIP_SVG;
+ }
+ }
+#endif
+
+ slot->format = FT_GLYPH_FORMAT_NONE;
slot->linearHoriAdvance = 0;
slot->linearVertAdvance = 0;
+ slot->advance.x = 0;
+ slot->advance.y = 0;
slot->lsb_delta = 0;
slot->rsb_delta = 0;
}
@@ -567,6 +628,24 @@
FT_Driver_Class clazz = driver->clazz;
FT_Memory memory = driver->root.memory;
+#ifdef FT_CONFIG_OPTION_SVG
+ if ( slot->face->face_flags & FT_FACE_FLAG_SVG )
+ {
+ /* Free memory in case SVG was there. */
+ /* `slot->internal` might be NULL in out-of-memory situations. */
+ if ( slot->internal && slot->internal->flags & FT_GLYPH_OWN_GZIP_SVG )
+ {
+ FT_SVG_Document doc = (FT_SVG_Document)slot->other;
+
+
+ FT_FREE( doc->svg_document );
+
+ slot->internal->flags &= ~FT_GLYPH_OWN_GZIP_SVG;
+ }
+
+ FT_FREE( slot->other );
+ }
+#endif
if ( clazz->done_slot )
clazz->done_slot( slot );
@@ -734,6 +813,29 @@
}
+ /* documentation is in freetype.h */
+
+ FT_EXPORT_DEF( void )
+ FT_Get_Transform( FT_Face face,
+ FT_Matrix* matrix,
+ FT_Vector* delta )
+ {
+ FT_Face_Internal internal;
+
+
+ if ( !face )
+ return;
+
+ internal = face->internal;
+
+ if ( matrix )
+ *matrix = internal->transform_matrix;
+
+ if ( delta )
+ *delta = internal->transform_delta;
+ }
+
+
static FT_Renderer
ft_lookup_glyph_renderer( FT_GlyphSlot slot );
@@ -819,6 +921,11 @@
library = driver->root.library;
hinter = library->auto_hinter;
+ /* undefined scale means no scale */
+ if ( face->size->metrics.x_ppem == 0 ||
+ face->size->metrics.y_ppem == 0 )
+ load_flags |= FT_LOAD_NO_SCALE;
+
/* resolve load flags dependencies */
if ( load_flags & FT_LOAD_NO_RECURSE )
@@ -908,11 +1015,22 @@
FT_AutoHinter_Interface hinting;
- /* try to load embedded bitmaps first if available */
- /* */
- /* XXX: This is really a temporary hack that should disappear */
- /* promptly with FreeType 2.1! */
- /* */
+ /* XXX: The use of the `FT_LOAD_XXX_ONLY` flags is not very */
+ /* elegant. */
+
+ /* try to load SVG documents if available */
+ if ( ( load_flags & FT_LOAD_NO_SVG ) == 0 &&
+ FT_HAS_SVG( face ) )
+ {
+ error = driver->clazz->load_glyph( slot, face->size,
+ glyph_index,
+ load_flags | FT_LOAD_SVG_ONLY );
+
+ if ( !error && slot->format == FT_GLYPH_FORMAT_SVG )
+ goto Load_Ok;
+ }
+
+ /* try to load embedded bitmaps if available */
if ( FT_HAS_FIXED_SIZES( face ) &&
( load_flags & FT_LOAD_NO_BITMAP ) == 0 )
{
@@ -1056,35 +1174,46 @@
#ifdef FT_DEBUG_LEVEL_TRACE
FT_TRACE5(( "FT_Load_Glyph: index %d, flags 0x%x\n",
glyph_index, load_flags ));
- FT_TRACE5(( " x advance: %f\n", slot->advance.x / 64.0 ));
- FT_TRACE5(( " y advance: %f\n", slot->advance.y / 64.0 ));
- FT_TRACE5(( " linear x advance: %f\n",
- slot->linearHoriAdvance / 65536.0 ));
- FT_TRACE5(( " linear y advance: %f\n",
- slot->linearVertAdvance / 65536.0 ));
- FT_TRACE5(( "\n" ));
- FT_TRACE5(( " bitmap %dx%d, %s (mode %d)\n",
+ FT_TRACE5(( " bitmap %dx%d %s, %s (mode %d)\n",
slot->bitmap.width,
slot->bitmap.rows,
+ slot->outline.points ?
+ slot->bitmap.buffer ? "rendered"
+ : "preset"
+ :
+ slot->internal->flags & FT_GLYPH_OWN_BITMAP ? "owned"
+ : "unowned",
pixel_modes[slot->bitmap.pixel_mode],
slot->bitmap.pixel_mode ));
FT_TRACE5(( "\n" ));
+ FT_TRACE5(( " x advance: %f\n", (double)slot->advance.x / 64 ));
+ FT_TRACE5(( " y advance: %f\n", (double)slot->advance.y / 64 ));
+ FT_TRACE5(( " linear x advance: %f\n",
+ (double)slot->linearHoriAdvance / 65536 ));
+ FT_TRACE5(( " linear y advance: %f\n",
+ (double)slot->linearVertAdvance / 65536 ));
{
FT_Glyph_Metrics* metrics = &slot->metrics;
FT_TRACE5(( " metrics:\n" ));
- FT_TRACE5(( " width: %f\n", metrics->width / 64.0 ));
- FT_TRACE5(( " height: %f\n", metrics->height / 64.0 ));
+ FT_TRACE5(( " width: %f\n", (double)metrics->width / 64 ));
+ FT_TRACE5(( " height: %f\n", (double)metrics->height / 64 ));
FT_TRACE5(( "\n" ));
- FT_TRACE5(( " horiBearingX: %f\n", metrics->horiBearingX / 64.0 ));
- FT_TRACE5(( " horiBearingY: %f\n", metrics->horiBearingY / 64.0 ));
- FT_TRACE5(( " horiAdvance: %f\n", metrics->horiAdvance / 64.0 ));
+ FT_TRACE5(( " horiBearingX: %f\n",
+ (double)metrics->horiBearingX / 64 ));
+ FT_TRACE5(( " horiBearingY: %f\n",
+ (double)metrics->horiBearingY / 64 ));
+ FT_TRACE5(( " horiAdvance: %f\n",
+ (double)metrics->horiAdvance / 64 ));
FT_TRACE5(( "\n" ));
- FT_TRACE5(( " vertBearingX: %f\n", metrics->vertBearingX / 64.0 ));
- FT_TRACE5(( " vertBearingY: %f\n", metrics->vertBearingY / 64.0 ));
- FT_TRACE5(( " vertAdvance: %f\n", metrics->vertAdvance / 64.0 ));
+ FT_TRACE5(( " vertBearingX: %f\n",
+ (double)metrics->vertBearingX / 64 ));
+ FT_TRACE5(( " vertBearingY: %f\n",
+ (double)metrics->vertBearingY / 64 ));
+ FT_TRACE5(( " vertAdvance: %f\n",
+ (double)metrics->vertAdvance / 64 ));
}
#endif
@@ -1117,9 +1246,13 @@
/* destructor for sizes list */
static void
destroy_size( FT_Memory memory,
- FT_Size size,
- FT_Driver driver )
+ void* size_,
+ void* driver_ )
{
+ FT_Size size = (FT_Size)size_;
+ FT_Driver driver = (FT_Driver)driver_;
+
+
/* finalize client-specific data */
if ( size->generic.finalizer )
size->generic.finalizer( size );
@@ -1165,10 +1298,12 @@
/* destructor for faces list */
static void
destroy_face( FT_Memory memory,
- FT_Face face,
- FT_Driver driver )
+ void* face_,
+ void* driver_ )
{
- FT_Driver_Class clazz = driver->clazz;
+ FT_Face face = (FT_Face)face_;
+ FT_Driver driver = (FT_Driver)driver_;
+ FT_Driver_Class clazz = driver->clazz;
/* discard auto-hinting data */
@@ -1182,7 +1317,7 @@
/* discard all sizes for this face */
FT_List_Finalize( &face->sizes_list,
- (FT_List_Destructor)destroy_size,
+ destroy_size,
memory,
driver );
face->size = NULL;
@@ -1218,7 +1353,7 @@
Destroy_Driver( FT_Driver driver )
{
FT_List_Finalize( &driver->faces_list,
- (FT_List_Destructor)destroy_face,
+ destroy_face,
driver->root.memory,
driver );
}
@@ -1367,7 +1502,7 @@
static FT_Error
open_face( FT_Driver driver,
FT_Stream *astream,
- FT_Bool external_stream,
+ FT_Bool *anexternal_stream,
FT_Long face_index,
FT_Int num_params,
FT_Parameter* params,
@@ -1393,7 +1528,7 @@
face->stream = *astream;
/* set the FT_FACE_FLAG_EXTERNAL_STREAM bit for FT_Done_Face */
- if ( external_stream )
+ if ( *anexternal_stream )
face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
if ( FT_NEW( internal ) )
@@ -1423,7 +1558,10 @@
(FT_Int)face_index,
num_params,
params );
- *astream = face->stream; /* Stream may have been changed. */
+ /* Stream may have been changed. */
+ *astream = face->stream;
+ *anexternal_stream =
+ ( face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0;
if ( error )
goto Fail;
@@ -1547,14 +1685,13 @@
static void
memory_stream_close( FT_Stream stream )
{
- FT_Memory memory = stream->memory;
+ FT_Memory memory = (FT_Memory)stream->descriptor.pointer;
FT_FREE( stream->base );
-
stream->size = 0;
- stream->base = NULL;
stream->close = NULL;
+ FT_FREE( stream );
}
@@ -1585,7 +1722,8 @@
FT_Stream_OpenMemory( stream, base, size );
- stream->close = close;
+ stream->descriptor.pointer = memory;
+ stream->close = close;
*astream = stream;
@@ -1606,28 +1744,37 @@
{
FT_Open_Args args;
FT_Error error;
- FT_Stream stream = NULL;
FT_Memory memory = library->memory;
+ args.driver = NULL;
+ args.flags = 0;
+
+ if ( driver_name )
+ {
+ args.driver = FT_Get_Module( library, driver_name );
+ if ( !args.driver )
+ {
+ FT_FREE( base );
+ return FT_THROW( Missing_Module );
+ }
+
+ args.flags = args.flags | FT_OPEN_DRIVER;
+ }
+
+ /* `memory_stream_close` also frees the stream object. */
error = new_memory_stream( library,
base,
size,
memory_stream_close,
- &stream );
+ &args.stream );
if ( error )
{
FT_FREE( base );
return error;
}
- args.flags = FT_OPEN_STREAM;
- args.stream = stream;
- if ( driver_name )
- {
- args.flags = args.flags | FT_OPEN_DRIVER;
- args.driver = FT_Get_Module( library, driver_name );
- }
+ args.flags |= FT_OPEN_STREAM;
#ifdef FT_MACINTOSH
/* At this point, the face index has served its purpose; */
@@ -1639,21 +1786,7 @@
face_index &= 0x7FFF0000L; /* retain GX data */
#endif
- error = ft_open_face_internal( library, &args, face_index, aface, 0 );
-
- if ( !error )
- (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
- else
-#ifdef FT_MACINTOSH
- FT_Stream_Free( stream, 0 );
-#else
- {
- FT_Stream_Close( stream );
- FT_FREE( stream );
- }
-#endif
-
- return error;
+ return ft_open_face_internal( library, &args, face_index, aface, 0 );
}
@@ -1782,7 +1915,7 @@
if ( error )
goto Exit;
- if ( FT_ALLOC( sfnt_ps, (FT_Long)length ) )
+ if ( FT_QALLOC( sfnt_ps, (FT_Long)length ) )
goto Exit;
error = FT_Stream_Read( stream, (FT_Byte *)sfnt_ps, length );
@@ -1796,7 +1929,7 @@
sfnt_ps,
length,
FT_MIN( face_index, 0 ),
- is_sfnt_cid ? "cid" : "type1",
+ is_sfnt_cid ? "t1cid" : "type1",
aface );
Exit:
{
@@ -1892,7 +2025,7 @@
goto Exit;
}
- if ( FT_ALLOC( pfb_data, (FT_Long)pfb_len + 2 ) )
+ if ( FT_QALLOC( pfb_data, (FT_Long)pfb_len + 2 ) )
goto Exit;
pfb_data[0] = 0x80;
@@ -1956,7 +2089,7 @@
{
FT_TRACE3(( " Write POST fragment #%d header (4-byte) to buffer"
" %p + 0x%08lx\n",
- i, pfb_data, pfb_lenpos ));
+ i, (void*)pfb_data, pfb_lenpos ));
if ( pfb_lenpos + 3 > pfb_len + 2 )
goto Exit2;
@@ -1971,7 +2104,7 @@
FT_TRACE3(( " Write POST fragment #%d header (6-byte) to buffer"
" %p + 0x%08lx\n",
- i, pfb_data, pfb_pos ));
+ i, (void*)pfb_data, pfb_pos ));
if ( pfb_pos + 6 > pfb_len + 2 )
goto Exit2;
@@ -1994,7 +2127,7 @@
FT_TRACE3(( " Load POST fragment #%d (%ld byte) to buffer"
" %p + 0x%08lx\n",
- i, rlen, pfb_data, pfb_pos ));
+ i, rlen, (void*)pfb_data, pfb_pos ));
error = FT_Stream_Read( stream, (FT_Byte *)pfb_data + pfb_pos, rlen );
if ( error )
@@ -2057,7 +2190,7 @@
FT_Byte* sfnt_data = NULL;
FT_Error error;
FT_ULong flag_offset;
- FT_Long rlen;
+ FT_ULong rlen;
int is_cff;
FT_Long face_index_in_resource = 0;
@@ -2072,11 +2205,11 @@
if ( error )
goto Exit;
- if ( FT_READ_LONG( rlen ) )
+ if ( FT_READ_ULONG( rlen ) )
goto Exit;
- if ( rlen < 1 )
+ if ( !rlen )
return FT_THROW( Cannot_Open_Resource );
- if ( (FT_ULong)rlen > FT_MAC_RFORK_MAX_LEN )
+ if ( rlen > FT_MAC_RFORK_MAX_LEN )
return FT_THROW( Invalid_Offset );
error = open_face_PS_from_sfnt_stream( library,
@@ -2092,10 +2225,11 @@
if ( error )
goto Exit;
- if ( FT_ALLOC( sfnt_data, rlen ) )
+ if ( FT_QALLOC( sfnt_data, rlen ) )
return error;
- error = FT_Stream_Read( stream, (FT_Byte *)sfnt_data, (FT_ULong)rlen );
- if ( error ) {
+ error = FT_Stream_Read( stream, (FT_Byte *)sfnt_data, rlen );
+ if ( error )
+ {
FT_FREE( sfnt_data );
goto Exit;
}
@@ -2103,7 +2237,7 @@
is_cff = rlen > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 );
error = open_face_from_buffer( library,
sfnt_data,
- (FT_ULong)rlen,
+ rlen,
face_index_in_resource,
is_cff ? "cff" : "truetype",
aface );
@@ -2407,6 +2541,16 @@
#endif
+ /* only use lower 31 bits together with sign bit */
+ if ( face_index > 0 )
+ face_index &= 0x7FFFFFFFL;
+ else
+ {
+ face_index = -face_index;
+ face_index &= 0x7FFFFFFFL;
+ face_index = -face_index;
+ }
+
#ifdef FT_DEBUG_LEVEL_TRACE
FT_TRACE3(( "FT_Open_Face: " ));
if ( face_index < 0 )
@@ -2422,7 +2566,7 @@
/* test for valid `library' delayed to `FT_Stream_New' */
- if ( ( !aface && face_index >= 0 ) || !args )
+ if ( !args )
return FT_THROW( Invalid_Argument );
external_stream = FT_BOOL( ( args->flags & FT_OPEN_STREAM ) &&
@@ -2433,6 +2577,14 @@
if ( error )
goto Fail3;
+ /* Do this error check after `FT_Stream_New` to ensure that the */
+ /* 'close' callback is called. */
+ if ( !aface && face_index >= 0 )
+ {
+ error = FT_THROW( Invalid_Argument );
+ goto Fail3;
+ }
+
memory = library->memory;
/* If the font driver is specified in the `args' structure, use */
@@ -2454,7 +2606,7 @@
params = args->params;
}
- error = open_face( driver, &stream, external_stream, face_index,
+ error = open_face( driver, &stream, &external_stream, face_index,
num_params, params, &face );
if ( !error )
goto Success;
@@ -2490,7 +2642,7 @@
params = args->params;
}
- error = open_face( driver, &stream, external_stream, face_index,
+ error = open_face( driver, &stream, &external_stream, face_index,
num_params, params, &face );
if ( !error )
goto Success;
@@ -2566,7 +2718,7 @@
FT_TRACE4(( "FT_Open_Face: New face object, adding to list\n" ));
/* add the face object to its driver's list */
- if ( FT_NEW( node ) )
+ if ( FT_QNEW( node ) )
goto Fail;
node->data = face;
@@ -2681,10 +2833,10 @@
#ifdef FT_DEBUG_LEVEL_TRACE
if ( !error && face_index < 0 )
{
- FT_TRACE3(( "FT_Open_Face: The font has %ld face%s\n"
- " and %ld named instance%s for face %ld\n",
+ FT_TRACE3(( "FT_Open_Face: The font has %ld face%s\n",
face->num_faces,
- face->num_faces == 1 ? "" : "s",
+ face->num_faces == 1 ? "" : "s" ));
+ FT_TRACE3(( " and %ld named instance%s for face %ld\n",
face->style_flags >> 16,
( face->style_flags >> 16 ) == 1 ? "" : "s",
-face_index - 1 ));
@@ -2722,8 +2874,8 @@
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
- FT_Attach_Stream( FT_Face face,
- FT_Open_Args* parameters )
+ FT_Attach_Stream( FT_Face face,
+ const FT_Open_Args* parameters )
{
FT_Stream stream;
FT_Error error;
@@ -2851,7 +3003,7 @@
memory = face->memory;
/* Allocate new size object and perform basic initialisation */
- if ( FT_ALLOC( size, clazz->size_object_size ) || FT_NEW( node ) )
+ if ( FT_ALLOC( size, clazz->size_object_size ) || FT_QNEW( node ) )
goto Exit;
size->face = face;
@@ -3088,10 +3240,12 @@
}
- FT_BASE_DEF( void )
+ FT_BASE_DEF( FT_Error )
FT_Request_Metrics( FT_Face face,
FT_Size_Request req )
{
+ FT_Error error = FT_Err_Ok;
+
FT_Size_Metrics* metrics;
@@ -3146,34 +3300,49 @@
scaled_h = FT_REQUEST_HEIGHT( req );
/* determine scales */
- if ( req->width )
+ if ( req->height || !req->width )
{
- metrics->x_scale = FT_DivFix( scaled_w, w );
-
- if ( req->height )
+ if ( h == 0 )
{
- metrics->y_scale = FT_DivFix( scaled_h, h );
-
- if ( req->type == FT_SIZE_REQUEST_TYPE_CELL )
- {
- if ( metrics->y_scale > metrics->x_scale )
- metrics->y_scale = metrics->x_scale;
- else
- metrics->x_scale = metrics->y_scale;
- }
+ FT_ERROR(( "FT_Request_Metrics: Divide by zero\n" ));
+ error = FT_ERR( Divide_By_Zero );
+ goto Exit;
}
- else
+
+ metrics->y_scale = FT_DivFix( scaled_h, h );
+ }
+
+ if ( req->width )
+ {
+ if ( w == 0 )
{
- metrics->y_scale = metrics->x_scale;
- scaled_h = FT_MulDiv( scaled_w, h, w );
+ FT_ERROR(( "FT_Request_Metrics: Divide by zero\n" ));
+ error = FT_ERR( Divide_By_Zero );
+ goto Exit;
}
+
+ metrics->x_scale = FT_DivFix( scaled_w, w );
}
else
{
- metrics->x_scale = metrics->y_scale = FT_DivFix( scaled_h, h );
+ metrics->x_scale = metrics->y_scale;
scaled_w = FT_MulDiv( scaled_h, w, h );
}
+ if ( !req->height )
+ {
+ metrics->y_scale = metrics->x_scale;
+ scaled_h = FT_MulDiv( scaled_w, h, w );
+ }
+
+ if ( req->type == FT_SIZE_REQUEST_TYPE_CELL )
+ {
+ if ( metrics->y_scale > metrics->x_scale )
+ metrics->y_scale = metrics->x_scale;
+ else
+ metrics->x_scale = metrics->y_scale;
+ }
+
Calculate_Ppem:
/* calculate the ppems */
if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL )
@@ -3182,8 +3351,18 @@
scaled_h = FT_MulFix( face->units_per_EM, metrics->y_scale );
}
- metrics->x_ppem = (FT_UShort)( ( scaled_w + 32 ) >> 6 );
- metrics->y_ppem = (FT_UShort)( ( scaled_h + 32 ) >> 6 );
+ scaled_w = ( scaled_w + 32 ) >> 6;
+ scaled_h = ( scaled_h + 32 ) >> 6;
+ if ( scaled_w > (FT_Long)FT_USHORT_MAX ||
+ scaled_h > (FT_Long)FT_USHORT_MAX )
+ {
+ FT_ERROR(( "FT_Request_Metrics: Resulting ppem size too large\n" ));
+ error = FT_ERR( Invalid_Pixel_Size );
+ goto Exit;
+ }
+
+ metrics->x_ppem = (FT_UShort)scaled_w;
+ metrics->y_ppem = (FT_UShort)scaled_h;
ft_recompute_scaled_metrics( face, metrics );
}
@@ -3193,6 +3372,9 @@
metrics->x_scale = 1L << 16;
metrics->y_scale = 1L << 16;
}
+
+ Exit:
+ return error;
}
@@ -3234,15 +3416,19 @@
FT_TRACE5(( " x scale: %ld (%f)\n",
- metrics->x_scale, metrics->x_scale / 65536.0 ));
+ metrics->x_scale, (double)metrics->x_scale / 65536 ));
FT_TRACE5(( " y scale: %ld (%f)\n",
- metrics->y_scale, metrics->y_scale / 65536.0 ));
- FT_TRACE5(( " ascender: %f\n", metrics->ascender / 64.0 ));
- FT_TRACE5(( " descender: %f\n", metrics->descender / 64.0 ));
- FT_TRACE5(( " height: %f\n", metrics->height / 64.0 ));
- FT_TRACE5(( " max advance: %f\n", metrics->max_advance / 64.0 ));
- FT_TRACE5(( " x ppem: %d\n", metrics->x_ppem ));
- FT_TRACE5(( " y ppem: %d\n", metrics->y_ppem ));
+ metrics->y_scale, (double)metrics->y_scale / 65536 ));
+ FT_TRACE5(( " ascender: %f\n",
+ (double)metrics->ascender / 64 ));
+ FT_TRACE5(( " descender: %f\n",
+ (double)metrics->descender / 64 ));
+ FT_TRACE5(( " height: %f\n",
+ (double)metrics->height / 64 ));
+ FT_TRACE5(( " max advance: %f\n",
+ (double)metrics->max_advance / 64 ));
+ FT_TRACE5(( " x ppem: %d\n", metrics->x_ppem ));
+ FT_TRACE5(( " y ppem: %d\n", metrics->y_ppem ));
}
#endif
@@ -3256,7 +3442,7 @@
FT_Request_Size( FT_Face face,
FT_Size_Request req )
{
- FT_Error error = FT_Err_Ok;
+ FT_Error error;
FT_Driver_Class clazz;
FT_ULong strike_index;
@@ -3264,6 +3450,9 @@
if ( !face )
return FT_THROW( Invalid_Face_Handle );
+ if ( !face->size )
+ return FT_THROW( Invalid_Size_Handle );
+
if ( !req || req->width < 0 || req->height < 0 ||
req->type >= FT_SIZE_REQUEST_TYPE_MAX )
return FT_THROW( Invalid_Argument );
@@ -3292,13 +3481,15 @@
*/
error = FT_Match_Size( face, req, 0, &strike_index );
if ( error )
- return error;
+ goto Exit;
return FT_Select_Size( face, (FT_Int)strike_index );
}
else
{
- FT_Request_Metrics( face, req );
+ error = FT_Request_Metrics( face, req );
+ if ( error )
+ goto Exit;
FT_TRACE5(( "FT_Request_Size:\n" ));
}
@@ -3309,18 +3500,23 @@
FT_TRACE5(( " x scale: %ld (%f)\n",
- metrics->x_scale, metrics->x_scale / 65536.0 ));
+ metrics->x_scale, (double)metrics->x_scale / 65536 ));
FT_TRACE5(( " y scale: %ld (%f)\n",
- metrics->y_scale, metrics->y_scale / 65536.0 ));
- FT_TRACE5(( " ascender: %f\n", metrics->ascender / 64.0 ));
- FT_TRACE5(( " descender: %f\n", metrics->descender / 64.0 ));
- FT_TRACE5(( " height: %f\n", metrics->height / 64.0 ));
- FT_TRACE5(( " max advance: %f\n", metrics->max_advance / 64.0 ));
- FT_TRACE5(( " x ppem: %d\n", metrics->x_ppem ));
- FT_TRACE5(( " y ppem: %d\n", metrics->y_ppem ));
+ metrics->y_scale, (double)metrics->y_scale / 65536 ));
+ FT_TRACE5(( " ascender: %f\n",
+ (double)metrics->ascender / 64 ));
+ FT_TRACE5(( " descender: %f\n",
+ (double)metrics->descender / 64 ));
+ FT_TRACE5(( " height: %f\n",
+ (double)metrics->height / 64 ));
+ FT_TRACE5(( " max advance: %f\n",
+ (double)metrics->max_advance / 64 ));
+ FT_TRACE5(( " x ppem: %d\n", metrics->x_ppem ));
+ FT_TRACE5(( " y ppem: %d\n", metrics->y_ppem ));
}
#endif
+ Exit:
return error;
}
@@ -3645,9 +3841,9 @@
FT_CharMap last_charmap = face->charmaps[face->num_charmaps - 1];
- if ( FT_RENEW_ARRAY( face->charmaps,
- face->num_charmaps,
- face->num_charmaps - 1 ) )
+ if ( FT_QRENEW_ARRAY( face->charmaps,
+ face->num_charmaps,
+ face->num_charmaps - 1 ) )
return;
/* remove it from our list of charmaps */
@@ -3679,7 +3875,7 @@
FT_CharMap charmap,
FT_CMap *acmap )
{
- FT_Error error = FT_Err_Ok;
+ FT_Error error;
FT_Face face;
FT_Memory memory;
FT_CMap cmap = NULL;
@@ -3704,9 +3900,9 @@
}
/* add it to our list of charmaps */
- if ( FT_RENEW_ARRAY( face->charmaps,
- face->num_charmaps,
- face->num_charmaps + 1 ) )
+ if ( FT_QRENEW_ARRAY( face->charmaps,
+ face->num_charmaps,
+ face->num_charmaps + 1 ) )
goto Fail;
face->charmaps[face->num_charmaps++] = (FT_CharMap)cmap;
@@ -4400,7 +4596,7 @@
FT_ListNode node = NULL;
- if ( FT_NEW( node ) )
+ if ( FT_QNEW( node ) )
goto Exit;
{
@@ -4412,8 +4608,7 @@
render->glyph_format = clazz->glyph_format;
/* allocate raster object if needed */
- if ( clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE &&
- clazz->raster_class->raster_new )
+ if ( clazz->raster_class && clazz->raster_class->raster_new )
{
error = clazz->raster_class->raster_new( memory, &render->raster );
if ( error )
@@ -4423,6 +4618,11 @@
render->render = clazz->render_glyph;
}
+#ifdef FT_CONFIG_OPTION_SVG
+ if ( clazz->glyph_format == FT_GLYPH_FORMAT_SVG )
+ render->render = clazz->render_glyph;
+#endif
+
/* add to list */
node->data = module;
FT_List_Add( &library->renderers, node );
@@ -4460,8 +4660,7 @@
/* release raster object, if any */
- if ( render->clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE &&
- render->raster )
+ if ( render->raster )
render->clazz->raster_class->raster_done( render->raster );
/* remove from list */
@@ -4556,9 +4755,6 @@
switch ( slot->format )
{
- case FT_GLYPH_FORMAT_BITMAP: /* already a bitmap, don't do anything */
- break;
-
default:
if ( slot->internal->load_flags & FT_LOAD_COLOR )
{
@@ -4646,7 +4842,7 @@
else
renderer = FT_Lookup_Renderer( library, slot->format, &node );
- error = FT_ERR( Unimplemented_Feature );
+ error = FT_ERR( Cannot_Render_Glyph );
while ( renderer )
{
error = renderer->render( renderer, slot, render_mode, NULL );
@@ -4662,6 +4858,11 @@
/* format. */
renderer = FT_Lookup_Renderer( library, slot->format, &node );
}
+
+ /* it is not an error if we cannot render a bitmap glyph */
+ if ( FT_ERR_EQ( error, Cannot_Render_Glyph ) &&
+ slot->format == FT_GLYPH_FORMAT_BITMAP )
+ error = FT_Err_Ok;
}
}
@@ -4734,11 +4935,11 @@
/* we use FT_TRACE7 in this block */
if ( !error &&
- ft_trace_levels[trace_checksum] >= 7 )
+ ft_trace_levels[trace_checksum] >= 7 &&
+ slot->bitmap.buffer )
{
if ( slot->bitmap.rows < 128U &&
- slot->bitmap.width < 128U &&
- slot->bitmap.buffer )
+ slot->bitmap.width < 128U )
{
int rows = (int)slot->bitmap.rows;
int width = (int)slot->bitmap.width;
@@ -5149,16 +5350,16 @@
if ( cur == limit )
{
- FT_ERROR(( "%s: can't find module `%s'\n",
- func_name, module_name ));
+ FT_TRACE2(( "%s: can't find module `%s'\n",
+ func_name, module_name ));
return FT_THROW( Missing_Module );
}
/* check whether we have a service interface */
if ( !cur[0]->clazz->get_interface )
{
- FT_ERROR(( "%s: module `%s' doesn't support properties\n",
- func_name, module_name ));
+ FT_TRACE2(( "%s: module `%s' doesn't support properties\n",
+ func_name, module_name ));
return FT_THROW( Unimplemented_Feature );
}
@@ -5167,8 +5368,8 @@
FT_SERVICE_ID_PROPERTIES );
if ( !interface )
{
- FT_ERROR(( "%s: module `%s' doesn't support properties\n",
- func_name, module_name ));
+ FT_TRACE2(( "%s: module `%s' doesn't support properties\n",
+ func_name, module_name ));
return FT_THROW( Unimplemented_Feature );
}
@@ -5181,8 +5382,8 @@
if ( missing_func )
{
- FT_ERROR(( "%s: property service of module `%s' is broken\n",
- func_name, module_name ));
+ FT_TRACE2(( "%s: property service of module `%s' is broken\n",
+ func_name, module_name ));
return FT_THROW( Unimplemented_Feature );
}
@@ -5292,10 +5493,12 @@
if ( !memory || !alibrary )
return FT_THROW( Invalid_Argument );
+#ifndef FT_DEBUG_LOGGING
#ifdef FT_DEBUG_LEVEL_ERROR
/* init debugging support */
ft_debug_init();
-#endif
+#endif /* FT_DEBUG_LEVEL_ERROR */
+#endif /* !FT_DEBUG_LOGGING */
/* first of all, allocate the library object */
if ( FT_NEW( library ) )
@@ -5567,4 +5770,145 @@
}
+ /* documentation is in freetype.h */
+
+ FT_EXPORT_DEF( FT_Bool )
+ FT_Get_Color_Glyph_Paint( FT_Face face,
+ FT_UInt base_glyph,
+ FT_Color_Root_Transform root_transform,
+ FT_OpaquePaint* paint )
+ {
+ TT_Face ttface;
+ SFNT_Service sfnt;
+
+
+ if ( !face || !paint )
+ return 0;
+
+ if ( !FT_IS_SFNT( face ) )
+ return 0;
+
+ ttface = (TT_Face)face;
+ sfnt = (SFNT_Service)ttface->sfnt;
+
+ if ( sfnt->get_colr_layer )
+ return sfnt->get_colr_glyph_paint( ttface,
+ base_glyph,
+ root_transform,
+ paint );
+ else
+ return 0;
+ }
+
+
+ /* documentation is in ftcolor.h */
+
+ FT_EXPORT_DEF( FT_Bool )
+ FT_Get_Color_Glyph_ClipBox( FT_Face face,
+ FT_UInt base_glyph,
+ FT_ClipBox* clip_box )
+ {
+ TT_Face ttface;
+ SFNT_Service sfnt;
+
+
+ if ( !face || !clip_box )
+ return 0;
+
+ if ( !FT_IS_SFNT( face ) )
+ return 0;
+
+ ttface = (TT_Face)face;
+ sfnt = (SFNT_Service)ttface->sfnt;
+
+ if ( sfnt->get_color_glyph_clipbox )
+ return sfnt->get_color_glyph_clipbox( ttface,
+ base_glyph,
+ clip_box );
+ else
+ return 0;
+ }
+
+
+ /* documentation is in freetype.h */
+
+ FT_EXPORT_DEF( FT_Bool )
+ FT_Get_Paint_Layers( FT_Face face,
+ FT_LayerIterator* layer_iterator,
+ FT_OpaquePaint* paint )
+ {
+ TT_Face ttface;
+ SFNT_Service sfnt;
+
+
+ if ( !face || !paint || !layer_iterator )
+ return 0;
+
+ if ( !FT_IS_SFNT( face ) )
+ return 0;
+
+ ttface = (TT_Face)face;
+ sfnt = (SFNT_Service)ttface->sfnt;
+
+ if ( sfnt->get_paint_layers )
+ return sfnt->get_paint_layers( ttface, layer_iterator, paint );
+ else
+ return 0;
+ }
+
+
+ /* documentation is in freetype.h */
+
+ FT_EXPORT_DEF( FT_Bool )
+ FT_Get_Paint( FT_Face face,
+ FT_OpaquePaint opaque_paint,
+ FT_COLR_Paint* paint )
+ {
+ TT_Face ttface;
+ SFNT_Service sfnt;
+
+
+ if ( !face || !paint )
+ return 0;
+
+ if ( !FT_IS_SFNT( face ) )
+ return 0;
+
+ ttface = (TT_Face)face;
+ sfnt = (SFNT_Service)ttface->sfnt;
+
+ if ( sfnt->get_paint )
+ return sfnt->get_paint( ttface, opaque_paint, paint );
+ else
+ return 0;
+ }
+
+
+ /* documentation is in freetype.h */
+
+ FT_EXPORT_DEF( FT_Bool )
+ FT_Get_Colorline_Stops ( FT_Face face,
+ FT_ColorStop * color_stop,
+ FT_ColorStopIterator *iterator )
+ {
+ TT_Face ttface;
+ SFNT_Service sfnt;
+
+
+ if ( !face || !color_stop || !iterator )
+ return 0;
+
+ if ( !FT_IS_SFNT( face ) )
+ return 0;
+
+ ttface = (TT_Face)face;
+ sfnt = (SFNT_Service)ttface->sfnt;
+
+ if ( sfnt->get_colorline_stops )
+ return sfnt->get_colorline_stops ( ttface, color_stop, iterator );
+ else
+ return 0;
+ }
+
+
/* END */