summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/pcf/pcfread.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/freetype/src/pcf/pcfread.c')
-rw-r--r--src/3rdparty/freetype/src/pcf/pcfread.c490
1 files changed, 278 insertions, 212 deletions
diff --git a/src/3rdparty/freetype/src/pcf/pcfread.c b/src/3rdparty/freetype/src/pcf/pcfread.c
index 537da0dc79..f167bcb8ae 100644
--- a/src/3rdparty/freetype/src/pcf/pcfread.c
+++ b/src/3rdparty/freetype/src/pcf/pcfread.c
@@ -25,11 +25,10 @@ THE SOFTWARE.
*/
-#include <ft2build.h>
-#include FT_INTERNAL_DEBUG_H
-#include FT_INTERNAL_STREAM_H
-#include FT_INTERNAL_OBJECTS_H
+#include <freetype/internal/ftdebug.h>
+#include <freetype/internal/ftstream.h>
+#include <freetype/internal/ftobjs.h>
#include "pcf.h"
#include "pcfread.h"
@@ -37,14 +36,14 @@ THE SOFTWARE.
#include "pcferror.h"
- /*************************************************************************/
- /* */
- /* 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. */
- /* */
+ /**************************************************************************
+ *
+ * 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_pcfread
+#define FT_COMPONENT pcfread
#ifdef FT_DEBUG_LEVEL_TRACE
@@ -122,13 +121,13 @@ THE SOFTWARE.
toc->count > 9 )
{
FT_TRACE0(( "pcf_read_TOC: adjusting number of tables"
- " (from %d to %d)\n",
+ " (from %ld to %ld)\n",
toc->count,
FT_MIN( stream->size >> 4, 9 ) ));
toc->count = FT_MIN( stream->size >> 4, 9 );
}
- if ( FT_NEW_ARRAY( face->toc.tables, toc->count ) )
+ if ( FT_QNEW_ARRAY( face->toc.tables, toc->count ) )
return error;
tables = face->toc.tables;
@@ -178,23 +177,23 @@ THE SOFTWARE.
}
/*
- * We now check whether the `size' and `offset' values are reasonable:
- * `offset' + `size' must not exceed the stream size.
+ * We now check whether the `size' and `offset' values are reasonable:
+ * `offset' + `size' must not exceed the stream size.
*
- * Note, however, that X11's `pcfWriteFont' routine (used by the
- * `bdftopcf' program to create PDF font files) has two special
- * features.
+ * Note, however, that X11's `pcfWriteFont' routine (used by the
+ * `bdftopcf' program to create PCF font files) has two special
+ * features.
*
- * - It always assigns the accelerator table a size of 100 bytes in the
- * TOC, regardless of its real size, which can vary between 34 and 72
- * bytes.
+ * - It always assigns the accelerator table a size of 100 bytes in the
+ * TOC, regardless of its real size, which can vary between 34 and 72
+ * bytes.
*
- * - Due to the way the routine is designed, it ships out the last font
- * table with its real size, ignoring the TOC's size value. Since
- * the TOC size values are always rounded up to a multiple of 4, the
- * difference can be up to three bytes for all tables except the
- * accelerator table, for which the difference can be as large as 66
- * bytes.
+ * - Due to the way the routine is designed, it ships out the last font
+ * table with its real size, ignoring the TOC's size value. Since
+ * the TOC size values are always rounded up to a multiple of 4, the
+ * difference can be up to three bytes for all tables except the
+ * accelerator table, for which the difference can be as large as 66
+ * bytes.
*
*/
@@ -239,10 +238,10 @@ THE SOFTWARE.
{
for ( j = 0; j < sizeof ( tableNames ) / sizeof ( tableNames[0] );
j++ )
- if ( tables[i].type == (FT_UInt)( 1 << j ) )
+ if ( tables[i].type == 1UL << j )
name = tableNames[j];
- FT_TRACE4(( " %d: type=%s, format=0x%X,"
+ FT_TRACE4(( " %d: type=%s, format=0x%lX,"
" size=%ld (0x%lX), offset=%ld (0x%lX)\n",
i, name,
tables[i].format,
@@ -502,8 +501,8 @@ THE SOFTWARE.
if ( FT_READ_ULONG_LE( format ) )
goto Bail;
- FT_TRACE4(( "pcf_get_properties:\n"
- " format: 0x%lX (%s)\n",
+ FT_TRACE4(( "pcf_get_properties:\n" ));
+ FT_TRACE4(( " format: 0x%lX (%s)\n",
format,
PCF_BYTE_ORDER( format ) == MSBFirst ? "MSB" : "LSB" ));
@@ -541,7 +540,7 @@ THE SOFTWARE.
face->nprops = (int)nprops;
- if ( FT_NEW_ARRAY( props, nprops ) )
+ if ( FT_QNEW_ARRAY( props, nprops ) )
goto Bail;
for ( i = 0; i < nprops; i++ )
@@ -608,13 +607,13 @@ THE SOFTWARE.
}
/* allocate one more byte so that we have a final null byte */
- if ( FT_NEW_ARRAY( strings, string_size + 1 ) )
+ if ( FT_QALLOC( strings, string_size + 1 ) ||
+ FT_STREAM_READ( strings, string_size ) )
goto Bail;
- error = FT_Stream_Read( stream, (FT_Byte*)strings, string_size );
- if ( error )
- goto Bail;
+ strings[string_size] = '\0';
+ /* zero out in case of failure */
if ( FT_NEW_ARRAY( properties, nprops ) )
goto Bail;
@@ -661,7 +660,7 @@ THE SOFTWARE.
{
properties[i].value.l = props[i].value;
- FT_TRACE4(( " %d\n", properties[i].value.l ));
+ FT_TRACE4(( " %ld\n", properties[i].value.l ));
}
}
@@ -698,8 +697,8 @@ THE SOFTWARE.
if ( FT_READ_ULONG_LE( format ) )
goto Bail;
- FT_TRACE4(( "pcf_get_metrics:\n"
- " format: 0x%lX (%s, %s)\n",
+ FT_TRACE4(( "pcf_get_metrics:\n" ));
+ FT_TRACE4(( " format: 0x%lX (%s, %s)\n",
format,
PCF_BYTE_ORDER( format ) == MSBFirst ? "MSB" : "LSB",
PCF_FORMAT_MATCH( format, PCF_COMPRESSED_METRICS ) ?
@@ -743,33 +742,39 @@ THE SOFTWARE.
if ( !orig_nmetrics )
return FT_THROW( Invalid_Table );
- /* PCF is a format from ancient times; Unicode was in its */
- /* infancy, and widely used two-byte character sets for CJK */
- /* scripts (Big 5, GB 2312, JIS X 0208, etc.) did have at most */
- /* 15000 characters. Even the more exotic CNS 11643 and CCCII */
- /* standards, which were essentially three-byte character sets, */
- /* provided less then 65536 assigned characters. */
- /* */
- /* While technically possible to have a larger number of glyphs */
- /* in PCF files, we thus limit the number to 65536. */
- if ( orig_nmetrics > 65536 )
+ /*
+ * PCF is a format from ancient times; Unicode was in its infancy, and
+ * widely used two-byte character sets for CJK scripts (Big 5, GB 2312,
+ * JIS X 0208, etc.) did have at most 15000 characters. Even the more
+ * exotic CNS 11643 and CCCII standards, which were essentially
+ * three-byte character sets, provided less then 65536 assigned
+ * characters.
+ *
+ * While technically possible to have a larger number of glyphs in PCF
+ * files, we thus limit the number to 65535, taking into account that we
+ * synthesize the metrics of glyph 0 to be a copy of the `default
+ * character', and that 0xFFFF in the encodings array indicates a
+ * missing glyph.
+ */
+ if ( orig_nmetrics > 65534 )
{
FT_TRACE0(( "pcf_get_metrics:"
- " only loading first 65536 metrics\n" ));
- nmetrics = 65536;
+ " only loading first 65534 metrics\n" ));
+ nmetrics = 65534;
}
else
nmetrics = orig_nmetrics;
- face->nmetrics = nmetrics;
+ face->nmetrics = nmetrics + 1;
- if ( FT_NEW_ARRAY( face->metrics, nmetrics ) )
+ if ( FT_QNEW_ARRAY( face->metrics, face->nmetrics ) )
return error;
- metrics = face->metrics;
+ /* we handle glyph index 0 later on */
+ metrics = face->metrics + 1;
FT_TRACE4(( "\n" ));
- for ( i = 0; i < nmetrics; i++, metrics++ )
+ for ( i = 1; i < face->nmetrics; i++, metrics++ )
{
FT_TRACE5(( " idx %ld:", i ));
error = pcf_get_metric( stream, format, metrics );
@@ -792,7 +797,7 @@ THE SOFTWARE.
metrics->descent = 0;
FT_TRACE0(( "pcf_get_metrics:"
- " invalid metrics for glyph %d\n", i ));
+ " invalid metrics for glyph %ld\n", i ));
}
}
@@ -808,12 +813,10 @@ THE SOFTWARE.
pcf_get_bitmaps( FT_Stream stream,
PCF_Face face )
{
- FT_Error error;
- FT_Memory memory = FT_FACE( face )->memory;
- FT_Long* offsets = NULL;
- FT_Long bitmapSizes[GLYPHPADOPTIONS];
- FT_ULong format, size;
- FT_ULong nbitmaps, orig_nbitmaps, i, sizebitmaps = 0;
+ FT_Error error;
+ FT_ULong bitmapSizes[GLYPHPADOPTIONS];
+ FT_ULong format, size, pos;
+ FT_ULong nbitmaps, orig_nbitmaps, i, sizebitmaps = 0;
error = pcf_seek_to_table_type( stream,
@@ -837,17 +840,16 @@ THE SOFTWARE.
FT_Stream_ExitFrame( stream );
- FT_TRACE4(( "pcf_get_bitmaps:\n"
- " format: 0x%lX\n"
- " (%s, %s,\n"
- " padding=%d bit%s, scanning=%d bit%s)\n",
- format,
+ FT_TRACE4(( "pcf_get_bitmaps:\n" ));
+ FT_TRACE4(( " format: 0x%lX\n", format ));
+ FT_TRACE4(( " (%s, %s,\n",
PCF_BYTE_ORDER( format ) == MSBFirst
? "most significant byte first"
: "least significant byte first",
PCF_BIT_ORDER( format ) == MSBFirst
? "most significant bit first"
- : "least significant bit first",
+ : "least significant bit first" ));
+ FT_TRACE4(( " padding=%d bit%s, scanning=%d bit%s)\n",
8 << PCF_GLYPH_PAD_INDEX( format ),
( 8 << PCF_GLYPH_PAD_INDEX( format ) ) == 1 ? "" : "s",
8 << PCF_SCAN_UNIT_INDEX( format ),
@@ -859,31 +861,46 @@ THE SOFTWARE.
FT_TRACE4(( " number of bitmaps: %ld\n", orig_nbitmaps ));
/* see comment in `pcf_get_metrics' */
- if ( orig_nbitmaps > 65536 )
+ if ( orig_nbitmaps > 65534 )
{
FT_TRACE0(( "pcf_get_bitmaps:"
- " only loading first 65536 bitmaps\n" ));
- nbitmaps = 65536;
+ " only loading first 65534 bitmaps\n" ));
+ nbitmaps = 65534;
}
else
nbitmaps = orig_nbitmaps;
- if ( nbitmaps != face->nmetrics )
+ /* no extra bitmap for glyph 0 */
+ if ( nbitmaps != face->nmetrics - 1 )
return FT_THROW( Invalid_File_Format );
- if ( FT_NEW_ARRAY( offsets, nbitmaps ) )
- return error;
+ /* start position of bitmap data */
+ pos = stream->pos + nbitmaps * 4 + 4 * 4;
FT_TRACE5(( "\n" ));
- for ( i = 0; i < nbitmaps; i++ )
+ for ( i = 1; i <= nbitmaps; i++ )
{
+ FT_ULong offset;
+
+
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
- (void)FT_READ_LONG( offsets[i] );
+ (void)FT_READ_ULONG( offset );
else
- (void)FT_READ_LONG_LE( offsets[i] );
+ (void)FT_READ_ULONG_LE( offset );
+
+ FT_TRACE5(( " bitmap %lu: offset %lu (0x%lX)\n",
+ i, offset, offset ));
- FT_TRACE5(( " bitmap %ld: offset %ld (0x%lX)\n",
- i, offsets[i], offsets[i] ));
+ /* right now, we only check the offset with a rough estimate; */
+ /* actual bitmaps are only loaded on demand */
+ if ( offset > size )
+ {
+ FT_TRACE0(( "pcf_get_bitmaps:"
+ " invalid offset to bitmap data of glyph %lu\n", i ));
+ face->metrics[i].bits = pos;
+ }
+ else
+ face->metrics[i].bits = pos + offset;
}
if ( error )
goto Bail;
@@ -891,62 +908,84 @@ THE SOFTWARE.
for ( i = 0; i < GLYPHPADOPTIONS; i++ )
{
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
- (void)FT_READ_LONG( bitmapSizes[i] );
+ (void)FT_READ_ULONG( bitmapSizes[i] );
else
- (void)FT_READ_LONG_LE( bitmapSizes[i] );
+ (void)FT_READ_ULONG_LE( bitmapSizes[i] );
if ( error )
goto Bail;
- sizebitmaps = (FT_ULong)bitmapSizes[PCF_GLYPH_PAD_INDEX( format )];
+ sizebitmaps = bitmapSizes[PCF_GLYPH_PAD_INDEX( format )];
- FT_TRACE4(( " %ld-bit padding implies a size of %ld\n",
+ FT_TRACE4(( " %d-bit padding implies a size of %lu\n",
8 << i, bitmapSizes[i] ));
}
- FT_TRACE4(( " %ld bitmaps, using %ld-bit padding\n",
+ FT_TRACE4(( " %lu bitmaps, using %d-bit padding\n",
nbitmaps,
8 << PCF_GLYPH_PAD_INDEX( format ) ));
- FT_TRACE4(( " bitmap size: %ld\n", sizebitmaps ));
+ FT_TRACE4(( " bitmap size: %lu\n", sizebitmaps ));
FT_UNUSED( sizebitmaps ); /* only used for debugging */
- /* right now, we only check the bitmap offsets; */
- /* actual bitmaps are only loaded on demand */
- for ( i = 0; i < nbitmaps; i++ )
- {
- /* rough estimate */
- if ( ( offsets[i] < 0 ) ||
- ( (FT_ULong)offsets[i] > size ) )
- {
- FT_TRACE0(( "pcf_get_bitmaps:"
- " invalid offset to bitmap data of glyph %ld\n", i ));
- }
- else
- face->metrics[i].bits = stream->pos + (FT_ULong)offsets[i];
- }
-
face->bitmapsFormat = format;
Bail:
- FT_FREE( offsets );
return error;
}
+ /*
+ * This file uses X11 terminology for PCF data; an `encoding' in X11 speak
+ * is the same as a character code in FreeType speak.
+ */
+#define PCF_ENC_SIZE 10
+
+ static
+ const FT_Frame_Field pcf_enc_header[] =
+ {
+#undef FT_STRUCTURE
+#define FT_STRUCTURE PCF_EncRec
+
+ FT_FRAME_START( PCF_ENC_SIZE ),
+ FT_FRAME_USHORT_LE( firstCol ),
+ FT_FRAME_USHORT_LE( lastCol ),
+ FT_FRAME_USHORT_LE( firstRow ),
+ FT_FRAME_USHORT_LE( lastRow ),
+ FT_FRAME_USHORT_LE( defaultChar ),
+ FT_FRAME_END
+ };
+
+
+ static
+ const FT_Frame_Field pcf_enc_msb_header[] =
+ {
+#undef FT_STRUCTURE
+#define FT_STRUCTURE PCF_EncRec
+
+ FT_FRAME_START( PCF_ENC_SIZE ),
+ FT_FRAME_USHORT( firstCol ),
+ FT_FRAME_USHORT( lastCol ),
+ FT_FRAME_USHORT( firstRow ),
+ FT_FRAME_USHORT( lastRow ),
+ FT_FRAME_USHORT( defaultChar ),
+ FT_FRAME_END
+ };
+
+
static FT_Error
pcf_get_encodings( FT_Stream stream,
PCF_Face face )
{
- FT_Error error;
- FT_Memory memory = FT_FACE( face )->memory;
- FT_ULong format, size;
- int firstCol, lastCol;
- int firstRow, lastRow;
- FT_ULong nencoding;
- FT_UShort encodingOffset;
- int i, j;
- FT_ULong k;
- PCF_Encoding encoding = NULL;
+ FT_Error error;
+ FT_Memory memory = FT_FACE( face )->memory;
+ FT_ULong format, size;
+ PCF_Enc enc = &face->enc;
+ FT_ULong nencoding;
+ FT_UShort* offset;
+ FT_UShort defaultCharRow, defaultCharCol;
+ FT_UShort encodingOffset, defaultCharEncodingOffset;
+ FT_UShort i, j;
+ FT_Byte* pos;
error = pcf_seek_to_table_type( stream,
@@ -956,105 +995,143 @@ THE SOFTWARE.
&format,
&size );
if ( error )
- return error;
+ goto Bail;
- error = FT_Stream_EnterFrame( stream, 14 );
- if ( error )
- return error;
+ if ( FT_READ_ULONG_LE( format ) )
+ goto Bail;
- format = FT_GET_ULONG_LE();
+ FT_TRACE4(( "pcf_get_encodings:\n" ));
+ FT_TRACE4(( " format: 0x%lX (%s)\n",
+ format,
+ PCF_BYTE_ORDER( format ) == MSBFirst ? "MSB" : "LSB" ));
+
+ if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) &&
+ !PCF_FORMAT_MATCH( format, PCF_BDF_ENCODINGS ) )
+ return FT_THROW( Invalid_File_Format );
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
{
- firstCol = FT_GET_SHORT();
- lastCol = FT_GET_SHORT();
- firstRow = FT_GET_SHORT();
- lastRow = FT_GET_SHORT();
- face->defaultChar = FT_GET_SHORT();
+ if ( FT_STREAM_READ_FIELDS( pcf_enc_msb_header, enc ) )
+ goto Bail;
}
else
{
- firstCol = FT_GET_SHORT_LE();
- lastCol = FT_GET_SHORT_LE();
- firstRow = FT_GET_SHORT_LE();
- lastRow = FT_GET_SHORT_LE();
- face->defaultChar = FT_GET_SHORT_LE();
+ if ( FT_STREAM_READ_FIELDS( pcf_enc_header, enc ) )
+ goto Bail;
}
- FT_Stream_ExitFrame( stream );
+ FT_TRACE4(( " firstCol 0x%X, lastCol 0x%X\n",
+ enc->firstCol, enc->lastCol ));
+ FT_TRACE4(( " firstRow 0x%X, lastRow 0x%X\n",
+ enc->firstRow, enc->lastRow ));
+ FT_TRACE4(( " defaultChar 0x%X\n",
+ enc->defaultChar ));
- FT_TRACE4(( "pcf_get_encodings:\n"
- " format: 0x%lX (%s)\n",
- format,
- PCF_BYTE_ORDER( format ) == MSBFirst ? "MSB" : "LSB" ));
+ /* sanity checks; we limit numbers of rows and columns to 256 */
+ if ( enc->firstCol > enc->lastCol ||
+ enc->lastCol > 0xFF ||
+ enc->firstRow > enc->lastRow ||
+ enc->lastRow > 0xFF )
+ return FT_THROW( Invalid_Table );
- if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) )
- return FT_THROW( Invalid_File_Format );
+ FT_TRACE5(( "\n" ));
- FT_TRACE4(( " firstCol 0x%X, lastCol 0x%X\n"
- " firstRow 0x%X, lastRow 0x%X\n",
- firstCol, lastCol,
- firstRow, lastRow ));
+ defaultCharRow = enc->defaultChar >> 8;
+ defaultCharCol = enc->defaultChar & 0xFF;
- /* sanity checks; we limit numbers of rows and columns to 256 */
- if ( firstCol < 0 ||
- firstCol > lastCol ||
- lastCol > 0xFF ||
- firstRow < 0 ||
- firstRow > lastRow ||
- lastRow > 0xFF )
- return FT_THROW( Invalid_Table );
+ /* validate default character */
+ if ( defaultCharRow < enc->firstRow ||
+ defaultCharRow > enc->lastRow ||
+ defaultCharCol < enc->firstCol ||
+ defaultCharCol > enc->lastCol )
+ {
+ enc->defaultChar = enc->firstRow * 256U + enc->firstCol;
+ FT_TRACE0(( "pcf_get_encodings:"
+ " Invalid default character set to %u\n",
+ enc->defaultChar ));
- nencoding = (FT_ULong)( lastCol - firstCol + 1 ) *
- (FT_ULong)( lastRow - firstRow + 1 );
+ defaultCharRow = enc->firstRow;
+ defaultCharCol = enc->firstCol;
+ }
- if ( FT_NEW_ARRAY( encoding, nencoding ) )
- return error;
+ nencoding = (FT_ULong)( enc->lastCol - enc->firstCol + 1 ) *
+ (FT_ULong)( enc->lastRow - enc->firstRow + 1 );
error = FT_Stream_EnterFrame( stream, 2 * nencoding );
if ( error )
goto Bail;
- FT_TRACE5(( "\n" ));
+ /*
+ * FreeType mandates that glyph index 0 is the `undefined glyph', which
+ * PCF calls the `default character'. However, FreeType needs glyph
+ * index 0 to be used for the undefined glyph only, which is is not the
+ * case for PCF. For this reason, we add one slot for glyph index 0 and
+ * simply copy the default character to it.
+ *
+ * `stream->cursor' still points to the beginning of the frame; we can
+ * thus easily get the offset to the default character.
+ */
+ pos = stream->cursor +
+ 2 * ( ( defaultCharRow - enc->firstRow ) *
+ ( enc->lastCol - enc->firstCol + 1 ) +
+ defaultCharCol - enc->firstCol );
- k = 0;
- for ( i = firstRow; i <= lastRow; i++ )
+ if ( PCF_BYTE_ORDER( format ) == MSBFirst )
+ defaultCharEncodingOffset = FT_PEEK_USHORT( pos );
+ else
+ defaultCharEncodingOffset = FT_PEEK_USHORT_LE( pos );
+
+ if ( defaultCharEncodingOffset == 0xFFFF )
+ {
+ FT_TRACE0(( "pcf_get_encodings:"
+ " No glyph for default character,\n" ));
+ FT_TRACE0(( " "
+ " setting it to the first glyph of the font\n" ));
+ defaultCharEncodingOffset = 1;
+ }
+ else
{
- for ( j = firstCol; j <= lastCol; j++ )
+ defaultCharEncodingOffset++;
+
+ if ( defaultCharEncodingOffset >= face->nmetrics )
+ {
+ FT_TRACE0(( "pcf_get_encodings:"
+ " Invalid glyph index for default character,\n" ));
+ FT_TRACE0(( " "
+ " setting it to the first glyph of the font\n" ));
+ defaultCharEncodingOffset = 1;
+ }
+ }
+
+ /* copy metrics of default character to index 0 */
+ face->metrics[0] = face->metrics[defaultCharEncodingOffset];
+
+ if ( FT_QNEW_ARRAY( enc->offset, nencoding ) )
+ goto Bail;
+
+ /* now loop over all values */
+ offset = enc->offset;
+ for ( i = enc->firstRow; i <= enc->lastRow; i++ )
+ {
+ for ( j = enc->firstCol; j <= enc->lastCol; j++ )
{
/* X11's reference implementation uses the equivalent to */
/* `FT_GET_SHORT', however PCF fonts with more than 32768 */
- /* characters (e.g. `unifont.pcf') clearly show that an */
+ /* characters (e.g., `unifont.pcf') clearly show that an */
/* unsigned value is needed. */
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
encodingOffset = FT_GET_USHORT();
else
encodingOffset = FT_GET_USHORT_LE();
- if ( encodingOffset != 0xFFFFU )
- {
- encoding[k].enc = i * 256 + j;
- encoding[k].glyph = encodingOffset;
-
- FT_TRACE5(( " code %d (0x%04X): idx %d\n",
- encoding[k].enc, encoding[k].enc, encoding[k].glyph ));
-
- k++;
- }
+ /* everything is off by 1 due to the artificial glyph 0 */
+ *offset++ = encodingOffset == 0xFFFF ? 0xFFFF
+ : encodingOffset + 1;
}
}
FT_Stream_ExitFrame( stream );
- if ( FT_RENEW_ARRAY( encoding, nencoding, k ) )
- goto Bail;
-
- face->nencodings = k;
- face->encodings = encoding;
-
- return error;
-
Bail:
- FT_FREE( encoding );
return error;
}
@@ -1125,10 +1202,10 @@ THE SOFTWARE.
if ( FT_READ_ULONG_LE( format ) )
goto Bail;
- FT_TRACE4(( "pcf_get_accel%s:\n"
- " format: 0x%lX (%s, %s)\n",
+ FT_TRACE4(( "pcf_get_accel%s:\n",
type == PCF_BDF_ACCELERATORS ? " (getting BDF accelerators)"
- : "",
+ : "" ));
+ FT_TRACE4(( " format: 0x%lX (%s, %s)\n",
format,
PCF_BYTE_ORDER( format ) == MSBFirst ? "MSB" : "LSB",
PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) ?
@@ -1150,16 +1227,16 @@ THE SOFTWARE.
}
FT_TRACE5(( " noOverlap=%s, constantMetrics=%s,"
- " terminalFont=%s, constantWidth=%s\n"
- " inkInside=%s, inkMetrics=%s, drawDirection=%s\n"
- " fontAscent=%ld, fontDescent=%ld, maxOverlap=%ld\n",
+ " terminalFont=%s, constantWidth=%s\n",
accel->noOverlap ? "yes" : "no",
accel->constantMetrics ? "yes" : "no",
accel->terminalFont ? "yes" : "no",
- accel->constantWidth ? "yes" : "no",
+ accel->constantWidth ? "yes" : "no" ));
+ FT_TRACE5(( " inkInside=%s, inkMetrics=%s, drawDirection=%s\n",
accel->inkInside ? "yes" : "no",
accel->inkMetrics ? "yes" : "no",
- accel->drawDirection ? "RTL" : "LTR",
+ accel->drawDirection ? "RTL" : "LTR" ));
+ FT_TRACE5(( " fontAscent=%ld, fontDescent=%ld, maxOverlap=%ld\n",
accel->fontAscent,
accel->fontDescent,
accel->maxOverlap ));
@@ -1168,13 +1245,13 @@ THE SOFTWARE.
if ( FT_ABS( accel->fontAscent ) > 0x7FFF )
{
accel->fontAscent = accel->fontAscent < 0 ? -0x7FFF : 0x7FFF;
- FT_TRACE0(( "pfc_get_accel: clamping font ascent to value %d\n",
+ FT_TRACE0(( "pfc_get_accel: clamping font ascent to value %ld\n",
accel->fontAscent ));
}
if ( FT_ABS( accel->fontDescent ) > 0x7FFF )
{
accel->fontDescent = accel->fontDescent < 0 ? -0x7FFF : 0x7FFF;
- FT_TRACE0(( "pfc_get_accel: clamping font descent to value %d\n",
+ FT_TRACE0(( "pfc_get_accel: clamping font descent to value %ld\n",
accel->fontDescent ));
}
@@ -1228,9 +1305,8 @@ THE SOFTWARE.
PCF_Property prop;
- size_t nn, len;
- char* strings[4] = { NULL, NULL, NULL, NULL };
- size_t lengths[4];
+ const char* strings[4] = { NULL, NULL, NULL, NULL };
+ size_t lengths[4], nn, len;
face->style_flags = 0;
@@ -1242,8 +1318,8 @@ THE SOFTWARE.
{
face->style_flags |= FT_STYLE_FLAG_ITALIC;
strings[2] = ( *(prop->value.atom) == 'O' ||
- *(prop->value.atom) == 'o' ) ? (char *)"Oblique"
- : (char *)"Italic";
+ *(prop->value.atom) == 'o' ) ? "Oblique"
+ : "Italic";
}
prop = pcf_find_property( pcf, "WEIGHT_NAME" );
@@ -1251,20 +1327,20 @@ THE SOFTWARE.
( *(prop->value.atom) == 'B' || *(prop->value.atom) == 'b' ) )
{
face->style_flags |= FT_STYLE_FLAG_BOLD;
- strings[1] = (char*)"Bold";
+ strings[1] = "Bold";
}
prop = pcf_find_property( pcf, "SETWIDTH_NAME" );
if ( prop && prop->isString &&
*(prop->value.atom) &&
!( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
- strings[3] = (char*)( prop->value.atom );
+ strings[3] = (const char*)( prop->value.atom );
prop = pcf_find_property( pcf, "ADD_STYLE_NAME" );
if ( prop && prop->isString &&
*(prop->value.atom) &&
!( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
- strings[0] = (char*)( prop->value.atom );
+ strings[0] = (const char*)( prop->value.atom );
for ( len = 0, nn = 0; nn < 4; nn++ )
{
@@ -1278,7 +1354,7 @@ THE SOFTWARE.
if ( len == 0 )
{
- strings[0] = (char*)"Regular";
+ strings[0] = "Regular";
lengths[0] = ft_strlen( strings[0] );
len = lengths[0] + 1;
}
@@ -1287,14 +1363,14 @@ THE SOFTWARE.
char* s;
- if ( FT_ALLOC( face->style_name, len ) )
+ if ( FT_QALLOC( face->style_name, len ) )
return error;
s = face->style_name;
for ( nn = 0; nn < 4; nn++ )
{
- char* src = strings[nn];
+ const char* src = strings[nn];
len = lengths[nn];
@@ -1397,8 +1473,7 @@ THE SOFTWARE.
root->face_flags |= FT_FACE_FLAG_FIXED_SIZES |
- FT_FACE_FLAG_HORIZONTAL |
- FT_FACE_FLAG_FAST_GLYPHS;
+ FT_FACE_FLAG_HORIZONTAL;
if ( face->accel.constantWidth )
root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
@@ -1452,7 +1527,7 @@ THE SOFTWARE.
{
l += ft_strlen( foundry_prop->value.atom ) + 1;
- if ( FT_NEW_ARRAY( root->family_name, l ) )
+ if ( FT_QALLOC( root->family_name, l ) )
goto Exit;
ft_strcpy( root->family_name, foundry_prop->value.atom );
@@ -1461,7 +1536,7 @@ THE SOFTWARE.
}
else
{
- if ( FT_NEW_ARRAY( root->family_name, l ) )
+ if ( FT_QALLOC( root->family_name, l ) )
goto Exit;
ft_strcpy( root->family_name, prop->value.atom );
@@ -1482,17 +1557,10 @@ THE SOFTWARE.
else
root->family_name = NULL;
- /*
- * Note: We shift all glyph indices by +1 since we must
- * respect the convention that glyph 0 always corresponds
- * to the `missing glyph'.
- *
- * This implies bumping the number of `available' glyphs by 1.
- */
- root->num_glyphs = (FT_Long)( face->nmetrics + 1 );
+ root->num_glyphs = (FT_Long)face->nmetrics;
root->num_fixed_sizes = 1;
- if ( FT_NEW_ARRAY( root->available_sizes, 1 ) )
+ if ( FT_NEW( root->available_sizes ) )
goto Exit;
{
@@ -1500,8 +1568,6 @@ THE SOFTWARE.
FT_Short resolution_x = 0, resolution_y = 0;
- FT_ZERO( bsize );
-
/* for simplicity, we take absolute values of integer properties */
#if 0
@@ -1542,7 +1608,7 @@ THE SOFTWARE.
else
{
/* this is a heuristical value */
- bsize->width = (FT_Short)FT_MulDiv( bsize->height, 2, 3 );
+ bsize->width = ( bsize->height * 2 + 1 ) / 3;
}
prop = pcf_find_property( face, "POINT_SIZE" );
@@ -1556,7 +1622,7 @@ THE SOFTWARE.
if ( FT_ABS( prop->value.l ) > 0x504C2L ) /* 0x7FFF * 72270/7200 */
{
bsize->size = 0x7FFF;
- FT_TRACE0(( "pcf_load_font: clamping point size to value %d\n",
+ FT_TRACE0(( "pcf_load_font: clamping point size to value %ld\n",
bsize->size ));
}
else
@@ -1575,7 +1641,7 @@ THE SOFTWARE.
if ( FT_ABS( prop->value.l ) > 0x7FFF )
{
bsize->y_ppem = 0x7FFF << 6;
- FT_TRACE0(( "pcf_load_font: clamping pixel size to value %d\n",
+ FT_TRACE0(( "pcf_load_font: clamping pixel size to value %ld\n",
bsize->y_ppem ));
}
else