summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/cache/ftcsbits.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/freetype/src/cache/ftcsbits.c')
-rw-r--r--src/3rdparty/freetype/src/cache/ftcsbits.c165
1 files changed, 78 insertions, 87 deletions
diff --git a/src/3rdparty/freetype/src/cache/ftcsbits.c b/src/3rdparty/freetype/src/cache/ftcsbits.c
index 018f1ecdb7..9929a0bcc3 100644
--- a/src/3rdparty/freetype/src/cache/ftcsbits.c
+++ b/src/3rdparty/freetype/src/cache/ftcsbits.c
@@ -1,33 +1,32 @@
-/***************************************************************************/
-/* */
-/* ftcsbits.c */
-/* */
-/* FreeType sbits manager (body). */
-/* */
-/* Copyright 2000-2018 by */
-/* David Turner, Robert Wilhelm, and Werner Lemberg. */
-/* */
-/* This file is part of the FreeType project, and may only be used, */
-/* modified, and distributed under the terms of the FreeType project */
-/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
-/* this file you indicate that you have read the license and */
-/* understand and accept it fully. */
-/* */
-/***************************************************************************/
-
-
-#include <ft2build.h>
-#include FT_CACHE_H
+/****************************************************************************
+ *
+ * ftcsbits.c
+ *
+ * FreeType sbits manager (body).
+ *
+ * Copyright (C) 2000-2023 by
+ * David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT. By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
+
+
+#include <freetype/ftcache.h>
#include "ftcsbits.h"
-#include FT_INTERNAL_OBJECTS_H
-#include FT_INTERNAL_DEBUG_H
-#include FT_ERRORS_H
+#include <freetype/internal/ftobjs.h>
+#include <freetype/internal/ftdebug.h>
+#include <freetype/fterrors.h>
#include "ftccback.h"
#include "ftcerror.h"
#undef FT_COMPONENT
-#define FT_COMPONENT trace_cache
+#define FT_COMPONENT cache
/*************************************************************************/
@@ -53,10 +52,8 @@
pitch = -pitch;
size = (FT_ULong)pitch * bitmap->rows;
- if ( !size )
- return FT_Err_Ok;
- if ( !FT_ALLOC( sbit->buffer, size ) )
+ if ( !FT_QALLOC( sbit->buffer, size ) )
FT_MEM_COPY( sbit->buffer, bitmap->buffer, size );
return error;
@@ -91,14 +88,14 @@
/*
- * This function tries to load a small bitmap within a given FTC_SNode.
- * Note that it returns a non-zero error code _only_ in the case of
- * out-of-memory condition. For all other errors (e.g., corresponding
- * to a bad font file), this function will mark the sbit as `unavailable'
- * and return a value of 0.
+ * This function tries to load a small bitmap within a given FTC_SNode.
+ * Note that it returns a non-zero error code _only_ in the case of
+ * out-of-memory condition. For all other errors (e.g., corresponding
+ * to a bad font file), this function will mark the sbit as `unavailable'
+ * and return a value of 0.
*
- * You should also read the comment within the @ftc_snode_compare
- * function below to see how out-of-memory is handled during a lookup.
+ * You should also read the comment within the @ftc_snode_compare
+ * function below to see how out-of-memory is handled during a lookup.
*/
static FT_Error
ftc_snode_load( FTC_SNode snode,
@@ -109,13 +106,12 @@
FT_Error error;
FTC_GNode gnode = FTC_GNODE( snode );
FTC_Family family = gnode->family;
- FT_Memory memory = manager->memory;
FT_Face face;
FTC_SBit sbit;
FTC_SFamilyClass clazz;
- if ( (FT_UInt)(gindex - gnode->gindex) >= snode->count )
+ if ( gindex - gnode->gindex >= snode->count )
{
FT_ERROR(( "ftc_snode_load: invalid glyph index" ));
return FT_THROW( Invalid_Argument );
@@ -124,8 +120,6 @@
sbit = snode->sbits + ( gindex - gnode->gindex );
clazz = (FTC_SFamilyClass)family->clazz;
- sbit->buffer = 0;
-
error = clazz->family_load_glyph( family, gindex, manager, &face );
if ( error )
goto BadGlyph;
@@ -144,12 +138,13 @@
goto BadGlyph;
}
- /* Check whether our values fit into 8-bit containers! */
+ /* Check whether our values fit into 8/16-bit containers! */
/* If this is not the case, our bitmap is too large */
/* and we will leave it as `missing' with sbit.buffer = 0 */
#define CHECK_CHAR( d ) ( temp = (FT_Char)d, (FT_Int) temp == (FT_Int) d )
#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, (FT_UInt)temp == (FT_UInt)d )
+#define CHECK_SHRT( d ) ( temp = (FT_Short)d, (FT_Int)temp == (FT_Int) d )
/* horizontal advance in pixels */
xadvance = ( slot->advance.x + 32 ) >> 6;
@@ -157,7 +152,7 @@
if ( !CHECK_BYTE( bitmap->rows ) ||
!CHECK_BYTE( bitmap->width ) ||
- !CHECK_CHAR( bitmap->pitch ) ||
+ !CHECK_SHRT( bitmap->pitch ) ||
!CHECK_CHAR( slot->bitmap_left ) ||
!CHECK_CHAR( slot->bitmap_top ) ||
!CHECK_CHAR( xadvance ) ||
@@ -170,16 +165,25 @@
sbit->width = (FT_Byte)bitmap->width;
sbit->height = (FT_Byte)bitmap->rows;
- sbit->pitch = (FT_Char)bitmap->pitch;
+ sbit->pitch = (FT_Short)bitmap->pitch;
sbit->left = (FT_Char)slot->bitmap_left;
sbit->top = (FT_Char)slot->bitmap_top;
sbit->xadvance = (FT_Char)xadvance;
sbit->yadvance = (FT_Char)yadvance;
sbit->format = (FT_Byte)bitmap->pixel_mode;
- sbit->max_grays = (FT_Byte)(bitmap->num_grays - 1);
+ sbit->max_grays = (FT_Byte)( bitmap->num_grays - 1 );
- /* copy the bitmap into a new buffer -- ignore error */
- error = ftc_sbit_copy_bitmap( sbit, bitmap, memory );
+ if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
+ {
+ /* take the bitmap ownership */
+ sbit->buffer = bitmap->buffer;
+ slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
+ }
+ else
+ {
+ /* copy the bitmap into a new buffer -- ignore error */
+ error = ftc_sbit_copy_bitmap( sbit, bitmap, manager->memory );
+ }
/* now, compute size */
if ( asize )
@@ -229,7 +233,7 @@
goto Exit;
}
- if ( !FT_NEW( snode ) )
+ if ( !FT_QNEW( snode ) )
{
FT_UInt count, start;
@@ -244,7 +248,9 @@
snode->count = count;
for ( node_count = 0; node_count < count; node_count++ )
{
- snode->sbits[node_count].width = 255;
+ snode->sbits[node_count].width = 255;
+ snode->sbits[node_count].height = 0;
+ snode->sbits[node_count].buffer = NULL;
}
error = ftc_snode_load( snode,
@@ -336,10 +342,10 @@
FT_Bool result;
- if (list_changed)
+ if ( list_changed )
*list_changed = FALSE;
- result = FT_BOOL( gnode->family == gquery->family &&
- (FT_UInt)( gindex - gnode->gindex ) < snode->count );
+ result = FT_BOOL( gnode->family == gquery->family &&
+ gindex - gnode->gindex < snode->count );
if ( result )
{
/* check if we need to load the glyph bitmap now */
@@ -347,34 +353,34 @@
/*
- * The following code illustrates what to do when you want to
- * perform operations that may fail within a lookup function.
+ * The following code illustrates what to do when you want to
+ * perform operations that may fail within a lookup function.
*
- * Here, we want to load a small bitmap on-demand; we thus
- * need to call the `ftc_snode_load' function which may return
- * a non-zero error code only when we are out of memory (OOM).
+ * Here, we want to load a small bitmap on-demand; we thus
+ * need to call the `ftc_snode_load' function which may return
+ * a non-zero error code only when we are out of memory (OOM).
*
- * The correct thing to do is to use @FTC_CACHE_TRYLOOP and
- * @FTC_CACHE_TRYLOOP_END in order to implement a retry loop
- * that is capable of flushing the cache incrementally when
- * an OOM errors occur.
+ * The correct thing to do is to use @FTC_CACHE_TRYLOOP and
+ * @FTC_CACHE_TRYLOOP_END in order to implement a retry loop
+ * that is capable of flushing the cache incrementally when
+ * an OOM errors occur.
*
- * However, we need to `lock' the node before this operation to
- * prevent it from being flushed within the loop.
+ * However, we need to `lock' the node before this operation to
+ * prevent it from being flushed within the loop.
*
- * When we exit the loop, we unlock the node, then check the `error'
- * variable. If it is non-zero, this means that the cache was
- * completely flushed and that no usable memory was found to load
- * the bitmap.
+ * When we exit the loop, we unlock the node, then check the `error'
+ * variable. If it is non-zero, this means that the cache was
+ * completely flushed and that no usable memory was found to load
+ * the bitmap.
*
- * We then prefer to return a value of 0 (i.e., NO MATCH). This
- * ensures that the caller will try to allocate a new node.
- * This operation consequently _fail_ and the lookup function
- * returns the appropriate OOM error code.
+ * We then prefer to return a value of 0 (i.e., NO MATCH). This
+ * ensures that the caller will try to allocate a new node.
+ * This operation consequently _fail_ and the lookup function
+ * returns the appropriate OOM error code.
*
- * Note that `buffer == NULL && width == 255' is a hack used to
- * tag `unavailable' bitmaps in the array. We should never try
- * to load these.
+ * Note that `buffer == NULL && width == 255' is a hack used to
+ * tag `unavailable' bitmaps in the array. We should never try
+ * to load these.
*
*/
@@ -391,7 +397,7 @@
{
error = ftc_snode_load( snode, cache->manager, gindex, &size );
}
- FTC_CACHE_TRYLOOP_END( list_changed );
+ FTC_CACHE_TRYLOOP_END( list_changed )
ftcsnode->ref_count--; /* unlock the node */
@@ -405,19 +411,4 @@
return result;
}
-
-#ifdef FTC_INLINE
-
- FT_LOCAL_DEF( FT_Bool )
- FTC_SNode_Compare( FTC_SNode snode,
- FTC_GQuery gquery,
- FTC_Cache cache,
- FT_Bool* list_changed )
- {
- return ftc_snode_compare( FTC_NODE( snode ), gquery,
- cache, list_changed );
- }
-
-#endif
-
/* END */