aboutsummaryrefslogtreecommitdiff
path: root/fontconfig/src
diff options
context:
space:
mode:
Diffstat (limited to 'fontconfig/src')
-rw-r--r--fontconfig/src/fccfg.c13
-rw-r--r--fontconfig/src/fcftint.h108
-rw-r--r--fontconfig/src/fcmatrix.c240
-rw-r--r--fontconfig/src/fcpat.c10
-rw-r--r--fontconfig/src/ftglue.c522
5 files changed, 453 insertions, 440 deletions
diff --git a/fontconfig/src/fccfg.c b/fontconfig/src/fccfg.c
index d6300515e..d948ab8d5 100644
--- a/fontconfig/src/fccfg.c
+++ b/fontconfig/src/fccfg.c
@@ -1689,10 +1689,19 @@ static FcChar8 *
FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file)
{
FcChar8 *path;
+ int size;
if (!dir)
dir = (FcChar8 *) "";
- path = malloc (strlen ((char *) dir) + 1 + strlen ((char *) file) + 1);
+
+ size = strlen ((char *) dir) + 1 + strlen ((char *) file) + 1;
+ /*
+ * workaround valgrind warning because glibc takes advantage of how it knows memory is
+ * allocated to implement strlen by reading in groups of 4
+ */
+ size = (size + 3) & ~3;
+
+ path = malloc (size);
if (!path)
return 0;
@@ -1711,7 +1720,7 @@ FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file)
#endif
strcat ((char *) path, (char *) file);
- FcMemAlloc (FC_MEM_STRING, strlen ((char *) path) + 1);
+ FcMemAlloc (FC_MEM_STRING, size);
if (access ((char *) path, R_OK) == 0)
return path;
diff --git a/fontconfig/src/fcftint.h b/fontconfig/src/fcftint.h
index f32d87c8b..b0f9ff960 100644
--- a/fontconfig/src/fcftint.h
+++ b/fontconfig/src/fcftint.h
@@ -1,54 +1,54 @@
-/*
- * Copyright © 2007 Keith Packard
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting documentation, and
- * that the name of the copyright holders not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. The copyright holders make no representations
- * about the suitability of this software for any purpose. It is provided "as
- * is" without express or implied warranty.
- *
- * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
- * OF THIS SOFTWARE.
- */
-
-#ifndef _FCFTINT_H_
-#define _FCFTINT_H_
-
-#include <fontconfig/fcfreetype.h>
-
-#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun)
-#define FcPrivate __attribute__((__visibility__("hidden")))
-#define HAVE_GNUC_ATTRIBUTE 1
-#include "fcftalias.h"
-#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
-#define FcPrivate __hidden
-#else /* not gcc >= 3.3 and not Sun Studio >= 8 */
-#define FcPrivate
-#endif
-
-/* fcfreetype.c */
-FcPrivate FcBool
-FcFreeTypeIsExclusiveLang (const FcChar8 *lang);
-
-FcPrivate FcBool
-FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
-
-FcPrivate FcChar32
-FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map);
-
-FcPrivate FcChar32
-FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map);
-
-FcPrivate const FcCharMap *
-FcFreeTypeGetPrivateMap (FT_Encoding encoding);
-
-#endif /* _FCFTINT_H_ */
+/*
+ * Copyright © 2007 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifndef _FCFTINT_H_
+#define _FCFTINT_H_
+
+#include <fontconfig/fcfreetype.h>
+
+#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun)
+#define FcPrivate __attribute__((__visibility__("hidden")))
+#define HAVE_GNUC_ATTRIBUTE 1
+#include "fcftalias.h"
+#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
+#define FcPrivate __hidden
+#else /* not gcc >= 3.3 and not Sun Studio >= 8 */
+#define FcPrivate
+#endif
+
+/* fcfreetype.c */
+FcPrivate FcBool
+FcFreeTypeIsExclusiveLang (const FcChar8 *lang);
+
+FcPrivate FcBool
+FcFreeTypeHasLang (FcPattern *pattern, const FcChar8 *lang);
+
+FcPrivate FcChar32
+FcFreeTypeUcs4ToPrivate (FcChar32 ucs4, const FcCharMap *map);
+
+FcPrivate FcChar32
+FcFreeTypePrivateToUcs4 (FcChar32 private, const FcCharMap *map);
+
+FcPrivate const FcCharMap *
+FcFreeTypeGetPrivateMap (FT_Encoding encoding);
+
+#endif /* _FCFTINT_H_ */
diff --git a/fontconfig/src/fcmatrix.c b/fontconfig/src/fcmatrix.c
index 1d6e2f6b0..2daa0044f 100644
--- a/fontconfig/src/fcmatrix.c
+++ b/fontconfig/src/fcmatrix.c
@@ -1,120 +1,120 @@
-/*
- * fontconfig/src/fcmatrix.c
- *
- * Copyright © 2000 Tuomas J. Lukka
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Tuomas Lukka not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. Tuomas Lukka makes no
- * representations about the suitability of this software for any purpose. It
- * is provided "as is" without express or implied warranty.
- *
- * TUOMAS LUKKA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL TUOMAS LUKKA BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include "fcint.h"
-#include <math.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-const FcMatrix FcIdentityMatrix = { 1, 0, 0, 1 };
-
-FcMatrix *
-FcMatrixCopy (const FcMatrix *mat)
-{
- FcMatrix *r;
- if(!mat)
- return 0;
- r = (FcMatrix *) malloc (sizeof (*r) );
- if (!r)
- return 0;
- FcMemAlloc (FC_MEM_MATRIX, sizeof (FcMatrix));
- *r = *mat;
- return r;
-}
-
-void
-FcMatrixFree (FcMatrix *mat)
-{
- if (mat != &FcIdentityMatrix)
- {
- FcMemFree (FC_MEM_MATRIX, sizeof (FcMatrix));
- free (mat);
- }
-}
-
-FcBool
-FcMatrixEqual (const FcMatrix *mat1, const FcMatrix *mat2)
-{
- if(mat1 == mat2) return FcTrue;
- if(mat1 == 0 || mat2 == 0) return FcFalse;
- return mat1->xx == mat2->xx &&
- mat1->xy == mat2->xy &&
- mat1->yx == mat2->yx &&
- mat1->yy == mat2->yy;
-}
-
-void
-FcMatrixMultiply (FcMatrix *result, const FcMatrix *a, const FcMatrix *b)
-{
- FcMatrix r;
-
- r.xx = a->xx * b->xx + a->xy * b->yx;
- r.xy = a->xx * b->xy + a->xy * b->yy;
- r.yx = a->yx * b->xx + a->yy * b->yx;
- r.yy = a->yx * b->xy + a->yy * b->yy;
- *result = r;
-}
-
-void
-FcMatrixRotate (FcMatrix *m, double c, double s)
-{
- FcMatrix r;
-
- /*
- * X Coordinate system is upside down, swap to make
- * rotations counterclockwise
- */
- r.xx = c;
- r.xy = -s;
- r.yx = s;
- r.yy = c;
- FcMatrixMultiply (m, &r, m);
-}
-
-void
-FcMatrixScale (FcMatrix *m, double sx, double sy)
-{
- FcMatrix r;
-
- r.xx = sx;
- r.xy = 0;
- r.yx = 0;
- r.yy = sy;
- FcMatrixMultiply (m, &r, m);
-}
-
-void
-FcMatrixShear (FcMatrix *m, double sh, double sv)
-{
- FcMatrix r;
-
- r.xx = 1;
- r.xy = sh;
- r.yx = sv;
- r.yy = 1;
- FcMatrixMultiply (m, &r, m);
-}
-#define __fcmatrix__
-#include "fcaliastail.h"
-#undef __fcmatrix__
+/*
+ * fontconfig/src/fcmatrix.c
+ *
+ * Copyright © 2000 Tuomas J. Lukka
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Tuomas Lukka not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission. Tuomas Lukka makes no
+ * representations about the suitability of this software for any purpose. It
+ * is provided "as is" without express or implied warranty.
+ *
+ * TUOMAS LUKKA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL TUOMAS LUKKA BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "fcint.h"
+#include <math.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+const FcMatrix FcIdentityMatrix = { 1, 0, 0, 1 };
+
+FcMatrix *
+FcMatrixCopy (const FcMatrix *mat)
+{
+ FcMatrix *r;
+ if(!mat)
+ return 0;
+ r = (FcMatrix *) malloc (sizeof (*r) );
+ if (!r)
+ return 0;
+ FcMemAlloc (FC_MEM_MATRIX, sizeof (FcMatrix));
+ *r = *mat;
+ return r;
+}
+
+void
+FcMatrixFree (FcMatrix *mat)
+{
+ if (mat != &FcIdentityMatrix)
+ {
+ FcMemFree (FC_MEM_MATRIX, sizeof (FcMatrix));
+ free (mat);
+ }
+}
+
+FcBool
+FcMatrixEqual (const FcMatrix *mat1, const FcMatrix *mat2)
+{
+ if(mat1 == mat2) return FcTrue;
+ if(mat1 == 0 || mat2 == 0) return FcFalse;
+ return mat1->xx == mat2->xx &&
+ mat1->xy == mat2->xy &&
+ mat1->yx == mat2->yx &&
+ mat1->yy == mat2->yy;
+}
+
+void
+FcMatrixMultiply (FcMatrix *result, const FcMatrix *a, const FcMatrix *b)
+{
+ FcMatrix r;
+
+ r.xx = a->xx * b->xx + a->xy * b->yx;
+ r.xy = a->xx * b->xy + a->xy * b->yy;
+ r.yx = a->yx * b->xx + a->yy * b->yx;
+ r.yy = a->yx * b->xy + a->yy * b->yy;
+ *result = r;
+}
+
+void
+FcMatrixRotate (FcMatrix *m, double c, double s)
+{
+ FcMatrix r;
+
+ /*
+ * X Coordinate system is upside down, swap to make
+ * rotations counterclockwise
+ */
+ r.xx = c;
+ r.xy = -s;
+ r.yx = s;
+ r.yy = c;
+ FcMatrixMultiply (m, &r, m);
+}
+
+void
+FcMatrixScale (FcMatrix *m, double sx, double sy)
+{
+ FcMatrix r;
+
+ r.xx = sx;
+ r.xy = 0;
+ r.yx = 0;
+ r.yy = sy;
+ FcMatrixMultiply (m, &r, m);
+}
+
+void
+FcMatrixShear (FcMatrix *m, double sh, double sv)
+{
+ FcMatrix r;
+
+ r.xx = 1;
+ r.xy = sh;
+ r.yx = sv;
+ r.yy = 1;
+ FcMatrixMultiply (m, &r, m);
+}
+#define __fcmatrix__
+#include "fcaliastail.h"
+#undef __fcmatrix__
diff --git a/fontconfig/src/fcpat.c b/fontconfig/src/fcpat.c
index 0fb2e506c..0d2402043 100644
--- a/fontconfig/src/fcpat.c
+++ b/fontconfig/src/fcpat.c
@@ -1057,9 +1057,13 @@ FcStrStaticName (const FcChar8 *name)
if (b->hash == hash && !strcmp ((char *)name, (char *) (b + 1)))
return (FcChar8 *) (b + 1);
size = sizeof (struct objectBucket) + strlen ((char *)name) + 1;
- b = malloc (size + sizeof (int));
- /* workaround glibc bug which reads strlen in groups of 4 */
- FcMemAlloc (FC_MEM_STATICSTR, size + sizeof (int));
+ /*
+ * workaround valgrind warning because glibc takes advantage of how it knows memory is
+ * allocated to implement strlen by reading in groups of 4
+ */
+ size = (size + 3) & ~3;
+ b = malloc (size);
+ FcMemAlloc (FC_MEM_STATICSTR, size);
if (!b)
return NULL;
b->next = 0;
diff --git a/fontconfig/src/ftglue.c b/fontconfig/src/ftglue.c
index 1eca304cf..91cb532b9 100644
--- a/fontconfig/src/ftglue.c
+++ b/fontconfig/src/ftglue.c
@@ -1,261 +1,261 @@
-/* ftglue.c: Glue code for compiling the OpenType code from
- * FreeType 1 using only the public API of FreeType 2
- *
- * By David Turner, The FreeType Project (www.freetype.org)
- *
- * This code is explicitely put in the public domain
- *
- * See ftglue.h for more information.
- */
-
-#include "ftglue.h"
-
-#if 0
-#include <stdio.h>
-#define LOG(x) ftglue_log x
-
-static void
-ftglue_log( const char* format, ... )
-{
- va_list ap;
-
- va_start( ap, format );
- vfprintf( stderr, format, ap );
- va_end( ap );
-}
-
-#else
-#define LOG(x) do {} while (0)
-#endif
-
-/* only used internally */
-static FT_Pointer
-ftglue_qalloc( FT_Memory memory,
- FT_ULong size,
- FT_Error *perror )
-{
- FT_Error error = 0;
- FT_Pointer block = NULL;
-
- if ( size > 0 )
- {
- block = memory->alloc( memory, size );
- if ( !block )
- error = FT_Err_Out_Of_Memory;
- }
-
- *perror = error;
- return block;
-}
-
-#undef QALLOC /* just in case */
-#define QALLOC(ptr,size) ( (ptr) = ftglue_qalloc( memory, (size), &error ), error != 0 )
-#define FREE(_ptr) \
- do { \
- if ( (_ptr) ) \
- { \
- ftglue_free( memory, _ptr ); \
- _ptr = NULL; \
- } \
- } while (0)
-
-
-static void
-ftglue_free( FT_Memory memory,
- FT_Pointer block )
-{
- if ( block )
- memory->free( memory, block );
-}
-
-FTGLUE_APIDEF( FT_Long )
-ftglue_stream_pos( FT_Stream stream )
-{
- LOG(( "ftglue:stream:pos() -> %ld\n", stream->pos ));
- return stream->pos;
-}
-
-
-FTGLUE_APIDEF( FT_Error )
-ftglue_stream_seek( FT_Stream stream,
- FT_Long pos )
-{
- FT_Error error = 0;
-
- stream->pos = pos;
- if ( stream->read )
- {
- if ( stream->read( stream, pos, 0, 0 ) )
- error = FT_Err_Invalid_Stream_Operation;
- }
- else if ( pos > stream->size )
- error = FT_Err_Invalid_Stream_Operation;
-
- LOG(( "ftglue:stream:seek(%ld) -> %d\n", pos, error ));
- return error;
-}
-
-
-FTGLUE_APIDEF( FT_Error )
-ftglue_stream_frame_enter( FT_Stream stream,
- FT_ULong count )
-{
- FT_Error error = FT_Err_Ok;
- FT_ULong read_bytes;
-
- if ( stream->read )
- {
- /* allocate the frame in memory */
- FT_Memory memory = stream->memory;
-
-
- if ( QALLOC( stream->base, count ) )
- goto Exit;
-
- /* read it */
- read_bytes = stream->read( stream, stream->pos,
- stream->base, count );
- if ( read_bytes < count )
- {
- FREE( stream->base );
- error = FT_Err_Invalid_Stream_Operation;
- }
- stream->cursor = stream->base;
- stream->limit = stream->cursor + count;
- stream->pos += read_bytes;
- }
- else
- {
- /* check current and new position */
- if ( stream->pos >= stream->size ||
- stream->pos + count > stream->size )
- {
- error = FT_Err_Invalid_Stream_Operation;
- goto Exit;
- }
-
- /* set cursor */
- stream->cursor = stream->base + stream->pos;
- stream->limit = stream->cursor + count;
- stream->pos += count;
- }
-
-Exit:
- LOG(( "ftglue:stream:frame_enter(%ld) -> %d\n", count, error ));
- return error;
-}
-
-
-FTGLUE_APIDEF( void )
-ftglue_stream_frame_exit( FT_Stream stream )
-{
- if ( stream->read )
- {
- FT_Memory memory = stream->memory;
-
- FREE( stream->base );
- }
- stream->cursor = 0;
- stream->limit = 0;
-
- LOG(( "ftglue:stream:frame_exit()\n" ));
-}
-
-
-FTGLUE_APIDEF( FT_Error )
-ftglue_face_goto_table( FT_Face face,
- FT_ULong the_tag,
- FT_Stream stream )
-{
- FT_Error error;
-
- LOG(( "ftglue_face_goto_table( %p, %c%c%c%c, %p )\n",
- face,
- (int)((the_tag >> 24) & 0xFF),
- (int)((the_tag >> 16) & 0xFF),
- (int)((the_tag >> 8) & 0xFF),
- (int)(the_tag & 0xFF),
- stream ));
-
- if ( !FT_IS_SFNT(face) )
- {
- LOG(( "not a SFNT face !!\n" ));
- error = FT_Err_Invalid_Face_Handle;
- }
- else
- {
- /* parse the directory table directly, without using
- * FreeType's built-in data structures
- */
- FT_ULong offset = 0, sig;
- FT_UInt count, nn;
-
- if ( FILE_Seek( 0 ) || ACCESS_Frame( 4 ) )
- goto Exit;
-
- sig = GET_Tag4();
-
- FORGET_Frame();
-
- if ( sig == FT_MAKE_TAG( 't', 't', 'c', 'f' ) )
- {
- /* deal with TrueType collections */
-
- LOG(( ">> This is a TrueType Collection\n" ));
-
- if ( FILE_Seek( 12 + face->face_index*4 ) ||
- ACCESS_Frame( 4 ) )
- goto Exit;
-
- offset = GET_ULong();
-
- FORGET_Frame();
- }
-
- LOG(( "TrueType offset = %ld\n", offset ));
-
- if ( FILE_Seek( offset+4 ) ||
- ACCESS_Frame( 2 ) )
- goto Exit;
-
- count = GET_UShort();
-
- FORGET_Frame();
-
- if ( FILE_Seek( offset+12 ) ||
- ACCESS_Frame( count*16 ) )
- goto Exit;
-
- for ( nn = 0; nn < count; nn++ )
- {
- FT_ULong tag = GET_ULong();
- FT_ULong checksum = GET_ULong();
- FT_ULong start = GET_ULong();
- FT_ULong size = GET_ULong();
-
- FT_UNUSED(checksum);
- FT_UNUSED(size);
-
- if ( tag == the_tag )
- {
- LOG(( "TrueType table (start: %ld) (size: %ld)\n", start, size ));
- error = ftglue_stream_seek( stream, start );
- goto FoundIt;
- }
- }
- error = FT_Err_Table_Missing;
-
- FoundIt:
- FORGET_Frame();
- }
-
-Exit:
- LOG(( "TrueType error=%d\n", error ));
-
- return error;
-}
-
-#undef QALLOC
-#define __ftglue__
-#include "fcaliastail.h"
-#undef __ftglue__
+/* ftglue.c: Glue code for compiling the OpenType code from
+ * FreeType 1 using only the public API of FreeType 2
+ *
+ * By David Turner, The FreeType Project (www.freetype.org)
+ *
+ * This code is explicitely put in the public domain
+ *
+ * See ftglue.h for more information.
+ */
+
+#include "ftglue.h"
+
+#if 0
+#include <stdio.h>
+#define LOG(x) ftglue_log x
+
+static void
+ftglue_log( const char* format, ... )
+{
+ va_list ap;
+
+ va_start( ap, format );
+ vfprintf( stderr, format, ap );
+ va_end( ap );
+}
+
+#else
+#define LOG(x) do {} while (0)
+#endif
+
+/* only used internally */
+static FT_Pointer
+ftglue_qalloc( FT_Memory memory,
+ FT_ULong size,
+ FT_Error *perror )
+{
+ FT_Error error = 0;
+ FT_Pointer block = NULL;
+
+ if ( size > 0 )
+ {
+ block = memory->alloc( memory, size );
+ if ( !block )
+ error = FT_Err_Out_Of_Memory;
+ }
+
+ *perror = error;
+ return block;
+}
+
+#undef QALLOC /* just in case */
+#define QALLOC(ptr,size) ( (ptr) = ftglue_qalloc( memory, (size), &error ), error != 0 )
+#define FREE(_ptr) \
+ do { \
+ if ( (_ptr) ) \
+ { \
+ ftglue_free( memory, _ptr ); \
+ _ptr = NULL; \
+ } \
+ } while (0)
+
+
+static void
+ftglue_free( FT_Memory memory,
+ FT_Pointer block )
+{
+ if ( block )
+ memory->free( memory, block );
+}
+
+FTGLUE_APIDEF( FT_Long )
+ftglue_stream_pos( FT_Stream stream )
+{
+ LOG(( "ftglue:stream:pos() -> %ld\n", stream->pos ));
+ return stream->pos;
+}
+
+
+FTGLUE_APIDEF( FT_Error )
+ftglue_stream_seek( FT_Stream stream,
+ FT_Long pos )
+{
+ FT_Error error = 0;
+
+ stream->pos = pos;
+ if ( stream->read )
+ {
+ if ( stream->read( stream, pos, 0, 0 ) )
+ error = FT_Err_Invalid_Stream_Operation;
+ }
+ else if ( pos > stream->size )
+ error = FT_Err_Invalid_Stream_Operation;
+
+ LOG(( "ftglue:stream:seek(%ld) -> %d\n", pos, error ));
+ return error;
+}
+
+
+FTGLUE_APIDEF( FT_Error )
+ftglue_stream_frame_enter( FT_Stream stream,
+ FT_ULong count )
+{
+ FT_Error error = FT_Err_Ok;
+ FT_ULong read_bytes;
+
+ if ( stream->read )
+ {
+ /* allocate the frame in memory */
+ FT_Memory memory = stream->memory;
+
+
+ if ( QALLOC( stream->base, count ) )
+ goto Exit;
+
+ /* read it */
+ read_bytes = stream->read( stream, stream->pos,
+ stream->base, count );
+ if ( read_bytes < count )
+ {
+ FREE( stream->base );
+ error = FT_Err_Invalid_Stream_Operation;
+ }
+ stream->cursor = stream->base;
+ stream->limit = stream->cursor + count;
+ stream->pos += read_bytes;
+ }
+ else
+ {
+ /* check current and new position */
+ if ( stream->pos >= stream->size ||
+ stream->pos + count > stream->size )
+ {
+ error = FT_Err_Invalid_Stream_Operation;
+ goto Exit;
+ }
+
+ /* set cursor */
+ stream->cursor = stream->base + stream->pos;
+ stream->limit = stream->cursor + count;
+ stream->pos += count;
+ }
+
+Exit:
+ LOG(( "ftglue:stream:frame_enter(%ld) -> %d\n", count, error ));
+ return error;
+}
+
+
+FTGLUE_APIDEF( void )
+ftglue_stream_frame_exit( FT_Stream stream )
+{
+ if ( stream->read )
+ {
+ FT_Memory memory = stream->memory;
+
+ FREE( stream->base );
+ }
+ stream->cursor = 0;
+ stream->limit = 0;
+
+ LOG(( "ftglue:stream:frame_exit()\n" ));
+}
+
+
+FTGLUE_APIDEF( FT_Error )
+ftglue_face_goto_table( FT_Face face,
+ FT_ULong the_tag,
+ FT_Stream stream )
+{
+ FT_Error error;
+
+ LOG(( "ftglue_face_goto_table( %p, %c%c%c%c, %p )\n",
+ face,
+ (int)((the_tag >> 24) & 0xFF),
+ (int)((the_tag >> 16) & 0xFF),
+ (int)((the_tag >> 8) & 0xFF),
+ (int)(the_tag & 0xFF),
+ stream ));
+
+ if ( !FT_IS_SFNT(face) )
+ {
+ LOG(( "not a SFNT face !!\n" ));
+ error = FT_Err_Invalid_Face_Handle;
+ }
+ else
+ {
+ /* parse the directory table directly, without using
+ * FreeType's built-in data structures
+ */
+ FT_ULong offset = 0, sig;
+ FT_UInt count, nn;
+
+ if ( FILE_Seek( 0 ) || ACCESS_Frame( 4 ) )
+ goto Exit;
+
+ sig = GET_Tag4();
+
+ FORGET_Frame();
+
+ if ( sig == FT_MAKE_TAG( 't', 't', 'c', 'f' ) )
+ {
+ /* deal with TrueType collections */
+
+ LOG(( ">> This is a TrueType Collection\n" ));
+
+ if ( FILE_Seek( 12 + face->face_index*4 ) ||
+ ACCESS_Frame( 4 ) )
+ goto Exit;
+
+ offset = GET_ULong();
+
+ FORGET_Frame();
+ }
+
+ LOG(( "TrueType offset = %ld\n", offset ));
+
+ if ( FILE_Seek( offset+4 ) ||
+ ACCESS_Frame( 2 ) )
+ goto Exit;
+
+ count = GET_UShort();
+
+ FORGET_Frame();
+
+ if ( FILE_Seek( offset+12 ) ||
+ ACCESS_Frame( count*16 ) )
+ goto Exit;
+
+ for ( nn = 0; nn < count; nn++ )
+ {
+ FT_ULong tag = GET_ULong();
+ FT_ULong checksum = GET_ULong();
+ FT_ULong start = GET_ULong();
+ FT_ULong size = GET_ULong();
+
+ FT_UNUSED(checksum);
+ FT_UNUSED(size);
+
+ if ( tag == the_tag )
+ {
+ LOG(( "TrueType table (start: %ld) (size: %ld)\n", start, size ));
+ error = ftglue_stream_seek( stream, start );
+ goto FoundIt;
+ }
+ }
+ error = FT_Err_Table_Missing;
+
+ FoundIt:
+ FORGET_Frame();
+ }
+
+Exit:
+ LOG(( "TrueType error=%d\n", error ));
+
+ return error;
+}
+
+#undef QALLOC
+#define __ftglue__
+#include "fcaliastail.h"
+#undef __ftglue__