2001-06-27 21:46:12 +02:00
|
|
|
/* pcfread.c
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
FreeType font driver for pcf fonts
|
|
|
|
|
2014-12-08 16:01:50 +01:00
|
|
|
Copyright 2000-2010, 2012-2014 by
|
2001-06-27 21:46:12 +02:00
|
|
|
Francesco Zappa Nardelli
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <ft2build.h>
|
|
|
|
|
|
|
|
#include FT_INTERNAL_DEBUG_H
|
|
|
|
#include FT_INTERNAL_STREAM_H
|
|
|
|
#include FT_INTERNAL_OBJECTS_H
|
|
|
|
|
2001-03-20 12:14:24 +01:00
|
|
|
#include "pcf.h"
|
2003-01-22 23:45:28 +01:00
|
|
|
#include "pcfread.h"
|
2001-01-01 18:24:31 +01:00
|
|
|
|
Complete redesign of error codes. Please check ftmoderr.h for more
details.
* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed. Replaced with files
local to the module. All extra error codes have been moved to
`fterrors.h'.
* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.
* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.
* include/freetype/ftmoderr.h: New file, defining the module error
offsets. Its structure is similar to `fterrors.h'.
* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.
* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.
All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.
All make files have been updated to include the local error files.
* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.
* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
|
|
|
#include "pcferror.h"
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2018-06-03 09:01:17 +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.
|
|
|
|
*/
|
2001-01-01 18:24:31 +01:00
|
|
|
#undef FT_COMPONENT
|
|
|
|
#define FT_COMPONENT trace_pcfread
|
|
|
|
|
|
|
|
|
2008-11-29 10:31:44 +01:00
|
|
|
#ifdef FT_DEBUG_LEVEL_TRACE
|
2004-04-21 16:30:37 +02:00
|
|
|
static const char* const tableNames[] =
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2017-01-06 11:47:55 +01:00
|
|
|
"properties",
|
|
|
|
"accelerators",
|
|
|
|
"metrics",
|
|
|
|
"bitmaps",
|
|
|
|
"ink metrics",
|
|
|
|
"encodings",
|
|
|
|
"swidths",
|
|
|
|
"glyph names",
|
|
|
|
"BDF accelerators"
|
2001-01-01 18:24:31 +01:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static
|
2001-01-01 18:24:31 +01:00
|
|
|
const FT_Frame_Field pcf_toc_header[] =
|
|
|
|
{
|
|
|
|
#undef FT_STRUCTURE
|
|
|
|
#define FT_STRUCTURE PCF_TocRec
|
|
|
|
|
|
|
|
FT_FRAME_START( 8 ),
|
|
|
|
FT_FRAME_ULONG_LE( version ),
|
|
|
|
FT_FRAME_ULONG_LE( count ),
|
|
|
|
FT_FRAME_END
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static
|
2001-01-01 18:24:31 +01:00
|
|
|
const FT_Frame_Field pcf_table_header[] =
|
|
|
|
{
|
|
|
|
#undef FT_STRUCTURE
|
|
|
|
#define FT_STRUCTURE PCF_TableRec
|
|
|
|
|
|
|
|
FT_FRAME_START( 16 ),
|
|
|
|
FT_FRAME_ULONG_LE( type ),
|
|
|
|
FT_FRAME_ULONG_LE( format ),
|
2014-12-08 16:01:50 +01:00
|
|
|
FT_FRAME_ULONG_LE( size ), /* rounded up to a multiple of 4 */
|
2001-01-01 18:24:31 +01:00
|
|
|
FT_FRAME_ULONG_LE( offset ),
|
|
|
|
FT_FRAME_END
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Error
|
|
|
|
pcf_read_TOC( FT_Stream stream,
|
|
|
|
PCF_Face face )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
PCF_Toc toc = &face->toc;
|
|
|
|
PCF_Table tables;
|
|
|
|
|
2013-06-04 10:30:48 +02:00
|
|
|
FT_Memory memory = FT_FACE( face )->memory;
|
2002-02-06 12:22:56 +01:00
|
|
|
FT_UInt n;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2014-12-08 16:01:50 +01:00
|
|
|
FT_ULong size;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2014-12-08 16:01:50 +01:00
|
|
|
|
|
|
|
if ( FT_STREAM_SEEK( 0 ) ||
|
|
|
|
FT_STREAM_READ_FIELDS( pcf_toc_header, toc ) )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Cannot_Open_Resource );
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2015-10-08 23:17:41 +02:00
|
|
|
if ( toc->version != PCF_FILE_VERSION ||
|
|
|
|
toc->count == 0 )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_File_Format );
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2015-10-10 06:54:46 +02:00
|
|
|
if ( stream->size < 16 )
|
|
|
|
return FT_THROW( Invalid_File_Format );
|
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
/* we need 16 bytes per TOC entry, */
|
|
|
|
/* and there can be most 9 tables */
|
|
|
|
if ( toc->count > ( stream->size >> 4 ) ||
|
|
|
|
toc->count > 9 )
|
2015-10-08 23:17:41 +02:00
|
|
|
{
|
|
|
|
FT_TRACE0(( "pcf_read_TOC: adjusting number of tables"
|
|
|
|
" (from %d to %d)\n",
|
2016-12-29 06:03:40 +01:00
|
|
|
toc->count,
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_MIN( stream->size >> 4, 9 ) ));
|
|
|
|
toc->count = FT_MIN( stream->size >> 4, 9 );
|
2015-10-08 23:17:41 +02:00
|
|
|
}
|
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
if ( FT_NEW_ARRAY( face->toc.tables, toc->count ) )
|
2017-01-06 11:47:55 +01:00
|
|
|
return error;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
tables = face->toc.tables;
|
2001-12-05 02:22:05 +01:00
|
|
|
for ( n = 0; n < toc->count; n++ )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2002-03-20 11:49:31 +01:00
|
|
|
if ( FT_STREAM_READ_FIELDS( pcf_table_header, tables ) )
|
2001-01-01 18:24:31 +01:00
|
|
|
goto Exit;
|
|
|
|
tables++;
|
|
|
|
}
|
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
/* Sort tables and check for overlaps. Because they are almost */
|
|
|
|
/* always ordered already, an in-place bubble sort with simultaneous */
|
|
|
|
/* boundary checking seems appropriate. */
|
|
|
|
tables = face->toc.tables;
|
|
|
|
|
|
|
|
for ( n = 0; n < toc->count - 1; n++ )
|
|
|
|
{
|
|
|
|
FT_UInt i, have_change;
|
|
|
|
|
|
|
|
|
|
|
|
have_change = 0;
|
|
|
|
|
|
|
|
for ( i = 0; i < toc->count - 1 - n; i++ )
|
|
|
|
{
|
|
|
|
PCF_TableRec tmp;
|
|
|
|
|
|
|
|
|
|
|
|
if ( tables[i].offset > tables[i + 1].offset )
|
|
|
|
{
|
|
|
|
tmp = tables[i];
|
|
|
|
tables[i] = tables[i + 1];
|
|
|
|
tables[i + 1] = tmp;
|
|
|
|
|
|
|
|
have_change = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ( tables[i].size > tables[i + 1].offset ) ||
|
|
|
|
( tables[i].offset > tables[i + 1].offset - tables[i].size ) )
|
2014-11-06 13:30:28 +01:00
|
|
|
{
|
|
|
|
error = FT_THROW( Invalid_Offset );
|
|
|
|
goto Exit;
|
|
|
|
}
|
2006-07-08 23:31:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !have_change )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-08 16:01:50 +01:00
|
|
|
/*
|
2018-06-03 09:01:17 +02:00
|
|
|
* We now check whether the `size' and `offset' values are reasonable:
|
|
|
|
* `offset' + `size' must not exceed the stream size.
|
2014-12-08 16:01:50 +01:00
|
|
|
*
|
2018-06-03 09:01:17 +02:00
|
|
|
* Note, however, that X11's `pcfWriteFont' routine (used by the
|
|
|
|
* `bdftopcf' program to create PCF font files) has two special
|
|
|
|
* features.
|
2014-12-08 16:01:50 +01:00
|
|
|
*
|
2018-06-03 09:01:17 +02:00
|
|
|
* - 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.
|
2014-12-08 16:01:50 +01:00
|
|
|
*
|
2018-06-03 09:01:17 +02:00
|
|
|
* - 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.
|
2014-12-08 16:01:50 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-11-06 22:32:46 +01:00
|
|
|
tables = face->toc.tables;
|
2014-12-08 16:01:50 +01:00
|
|
|
size = stream->size;
|
|
|
|
|
|
|
|
for ( n = 0; n < toc->count - 1; n++ )
|
2014-11-06 22:32:46 +01:00
|
|
|
{
|
|
|
|
/* we need two checks to avoid overflow */
|
2014-12-08 16:01:50 +01:00
|
|
|
if ( ( tables->size > size ) ||
|
|
|
|
( tables->offset > size - tables->size ) )
|
2014-11-06 22:32:46 +01:00
|
|
|
{
|
|
|
|
error = FT_THROW( Invalid_Table );
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
tables++;
|
|
|
|
}
|
|
|
|
|
2014-12-13 07:42:51 +01:00
|
|
|
/* only check `tables->offset' for last table element ... */
|
2014-12-08 16:01:50 +01:00
|
|
|
if ( ( tables->offset > size ) )
|
|
|
|
{
|
|
|
|
error = FT_THROW( Invalid_Table );
|
|
|
|
goto Exit;
|
|
|
|
}
|
2014-12-13 07:42:51 +01:00
|
|
|
/* ... and adjust `tables->size' to the real value if necessary */
|
|
|
|
if ( tables->size > size - tables->offset )
|
|
|
|
tables->size = size - tables->offset;
|
2014-12-08 16:01:50 +01:00
|
|
|
|
2008-11-29 10:31:44 +01:00
|
|
|
#ifdef FT_DEBUG_LEVEL_TRACE
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
{
|
2002-02-06 12:22:56 +01:00
|
|
|
FT_UInt i, j;
|
|
|
|
const char* name = "?";
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
|
2004-06-22 08:24:09 +02:00
|
|
|
FT_TRACE4(( "pcf_read_TOC:\n" ));
|
|
|
|
|
|
|
|
FT_TRACE4(( " number of tables: %ld\n", face->toc.count ));
|
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
tables = face->toc.tables;
|
|
|
|
for ( i = 0; i < toc->count; i++ )
|
|
|
|
{
|
2006-07-08 23:31:24 +02:00
|
|
|
for ( j = 0; j < sizeof ( tableNames ) / sizeof ( tableNames[0] );
|
|
|
|
j++ )
|
2018-08-09 04:17:35 +02:00
|
|
|
if ( tables[i].type == (FT_UInt)( 1 << j ) )
|
2001-12-05 02:22:05 +01:00
|
|
|
name = tableNames[j];
|
2002-03-31 08:56:56 +02:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE4(( " %d: type=%s, format=0x%X,"
|
|
|
|
" size=%ld (0x%lX), offset=%ld (0x%lX)\n",
|
2001-01-01 18:24:31 +01:00
|
|
|
i, name,
|
|
|
|
tables[i].format,
|
2001-06-27 21:46:12 +02:00
|
|
|
tables[i].size, tables[i].size,
|
2004-06-22 08:24:09 +02:00
|
|
|
tables[i].offset, tables[i].offset ));
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-03-14 11:21:17 +01:00
|
|
|
return FT_Err_Ok;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
Exit:
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( face->toc.tables );
|
2001-01-01 18:24:31 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
#define PCF_METRIC_SIZE 12
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static
|
2001-01-01 18:24:31 +01:00
|
|
|
const FT_Frame_Field pcf_metric_header[] =
|
|
|
|
{
|
|
|
|
#undef FT_STRUCTURE
|
|
|
|
#define FT_STRUCTURE PCF_MetricRec
|
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
FT_FRAME_START( PCF_METRIC_SIZE ),
|
2001-01-01 18:24:31 +01:00
|
|
|
FT_FRAME_SHORT_LE( leftSideBearing ),
|
|
|
|
FT_FRAME_SHORT_LE( rightSideBearing ),
|
|
|
|
FT_FRAME_SHORT_LE( characterWidth ),
|
|
|
|
FT_FRAME_SHORT_LE( ascent ),
|
|
|
|
FT_FRAME_SHORT_LE( descent ),
|
|
|
|
FT_FRAME_SHORT_LE( attributes ),
|
|
|
|
FT_FRAME_END
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static
|
2001-01-01 18:24:31 +01:00
|
|
|
const FT_Frame_Field pcf_metric_msb_header[] =
|
|
|
|
{
|
|
|
|
#undef FT_STRUCTURE
|
|
|
|
#define FT_STRUCTURE PCF_MetricRec
|
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
FT_FRAME_START( PCF_METRIC_SIZE ),
|
2001-01-01 18:24:31 +01:00
|
|
|
FT_FRAME_SHORT( leftSideBearing ),
|
|
|
|
FT_FRAME_SHORT( rightSideBearing ),
|
|
|
|
FT_FRAME_SHORT( characterWidth ),
|
|
|
|
FT_FRAME_SHORT( ascent ),
|
|
|
|
FT_FRAME_SHORT( descent ),
|
|
|
|
FT_FRAME_SHORT( attributes ),
|
|
|
|
FT_FRAME_END
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
#define PCF_COMPRESSED_METRIC_SIZE 5
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static
|
2001-01-01 18:24:31 +01:00
|
|
|
const FT_Frame_Field pcf_compressed_metric_header[] =
|
|
|
|
{
|
|
|
|
#undef FT_STRUCTURE
|
|
|
|
#define FT_STRUCTURE PCF_Compressed_MetricRec
|
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
FT_FRAME_START( PCF_COMPRESSED_METRIC_SIZE ),
|
2001-01-01 18:24:31 +01:00
|
|
|
FT_FRAME_BYTE( leftSideBearing ),
|
|
|
|
FT_FRAME_BYTE( rightSideBearing ),
|
|
|
|
FT_FRAME_BYTE( characterWidth ),
|
|
|
|
FT_FRAME_BYTE( ascent ),
|
|
|
|
FT_FRAME_BYTE( descent ),
|
|
|
|
FT_FRAME_END
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Error
|
|
|
|
pcf_get_metric( FT_Stream stream,
|
|
|
|
FT_ULong format,
|
|
|
|
PCF_Metric metric )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2013-03-14 11:21:17 +01:00
|
|
|
FT_Error error = FT_Err_Ok;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) )
|
|
|
|
{
|
2002-03-31 08:56:56 +02:00
|
|
|
const FT_Frame_Field* fields;
|
|
|
|
|
|
|
|
|
2002-02-06 12:22:56 +01:00
|
|
|
/* parsing normal metrics */
|
2016-12-25 22:55:25 +01:00
|
|
|
fields = ( PCF_BYTE_ORDER( format ) == MSBFirst )
|
2002-03-31 08:56:56 +02:00
|
|
|
? pcf_metric_msb_header
|
|
|
|
: pcf_metric_header;
|
2002-02-06 12:22:56 +01:00
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
/* the following sets `error' but doesn't return in case of failure */
|
2002-03-31 08:56:56 +02:00
|
|
|
(void)FT_STREAM_READ_FIELDS( fields, metric );
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
else
|
2002-02-06 12:22:56 +01:00
|
|
|
{
|
|
|
|
PCF_Compressed_MetricRec compr;
|
|
|
|
|
|
|
|
|
|
|
|
/* parsing compressed metrics */
|
2002-03-20 11:49:31 +01:00
|
|
|
if ( FT_STREAM_READ_FIELDS( pcf_compressed_metric_header, &compr ) )
|
2002-02-06 12:22:56 +01:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
metric->leftSideBearing = (FT_Short)( compr.leftSideBearing - 0x80 );
|
|
|
|
metric->rightSideBearing = (FT_Short)( compr.rightSideBearing - 0x80 );
|
|
|
|
metric->characterWidth = (FT_Short)( compr.characterWidth - 0x80 );
|
|
|
|
metric->ascent = (FT_Short)( compr.ascent - 0x80 );
|
|
|
|
metric->descent = (FT_Short)( compr.descent - 0x80 );
|
|
|
|
metric->attributes = 0;
|
|
|
|
}
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE5(( " width=%d,"
|
|
|
|
" lsb=%d, rsb=%d,"
|
|
|
|
" ascent=%d, descent=%d,"
|
|
|
|
" attributes=%d\n",
|
|
|
|
metric->characterWidth,
|
|
|
|
metric->leftSideBearing,
|
|
|
|
metric->rightSideBearing,
|
|
|
|
metric->ascent,
|
|
|
|
metric->descent,
|
|
|
|
metric->attributes ));
|
|
|
|
|
2002-02-06 12:22:56 +01:00
|
|
|
Exit:
|
2001-01-01 18:24:31 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
|
|
|
|
static FT_Error
|
2002-02-06 12:22:56 +01:00
|
|
|
pcf_seek_to_table_type( FT_Stream stream,
|
|
|
|
PCF_Table tables,
|
2009-07-31 17:32:11 +02:00
|
|
|
FT_ULong ntables, /* same as PCF_Toc->count */
|
2002-02-06 12:22:56 +01:00
|
|
|
FT_ULong type,
|
|
|
|
FT_ULong *aformat,
|
|
|
|
FT_ULong *asize )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2013-03-14 17:50:49 +01:00
|
|
|
FT_Error error = FT_ERR( Invalid_File_Format );
|
2009-07-31 17:32:11 +02:00
|
|
|
FT_ULong i;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
for ( i = 0; i < ntables; i++ )
|
|
|
|
if ( tables[i].type == type )
|
|
|
|
{
|
2006-07-08 23:31:24 +02:00
|
|
|
if ( stream->pos > tables[i].offset )
|
|
|
|
{
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Stream_Skip );
|
2003-04-23 21:48:24 +02:00
|
|
|
goto Fail;
|
|
|
|
}
|
2002-02-06 12:22:56 +01:00
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
if ( FT_STREAM_SKIP( tables[i].offset - stream->pos ) )
|
|
|
|
{
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Stream_Skip );
|
2003-04-23 21:48:24 +02:00
|
|
|
goto Fail;
|
|
|
|
}
|
2002-02-06 12:22:56 +01:00
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
*asize = tables[i].size;
|
2002-02-06 12:22:56 +01:00
|
|
|
*aformat = tables[i].format;
|
2002-03-31 08:56:56 +02:00
|
|
|
|
2013-03-14 11:21:17 +01:00
|
|
|
return FT_Err_Ok;
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
|
2003-04-23 21:48:24 +02:00
|
|
|
Fail:
|
2007-01-15 07:42:40 +01:00
|
|
|
*asize = 0;
|
2003-04-23 21:48:24 +02:00
|
|
|
return error;
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Bool
|
2002-02-06 12:22:56 +01:00
|
|
|
pcf_has_table_type( PCF_Table tables,
|
2009-07-31 17:32:11 +02:00
|
|
|
FT_ULong ntables, /* same as PCF_Toc->count */
|
2002-02-06 12:22:56 +01:00
|
|
|
FT_ULong type )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2009-07-31 17:32:11 +02:00
|
|
|
FT_ULong i;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
for ( i = 0; i < ntables; i++ )
|
|
|
|
if ( tables[i].type == type )
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
#define PCF_PROPERTY_SIZE 9
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static
|
2001-01-01 18:24:31 +01:00
|
|
|
const FT_Frame_Field pcf_property_header[] =
|
|
|
|
{
|
|
|
|
#undef FT_STRUCTURE
|
|
|
|
#define FT_STRUCTURE PCF_ParsePropertyRec
|
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
FT_FRAME_START( PCF_PROPERTY_SIZE ),
|
2018-08-09 04:17:35 +02:00
|
|
|
FT_FRAME_LONG_LE( name ),
|
|
|
|
FT_FRAME_BYTE ( isString ),
|
|
|
|
FT_FRAME_LONG_LE( value ),
|
2001-01-01 18:24:31 +01:00
|
|
|
FT_FRAME_END
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static
|
2001-01-01 18:24:31 +01:00
|
|
|
const FT_Frame_Field pcf_property_msb_header[] =
|
|
|
|
{
|
|
|
|
#undef FT_STRUCTURE
|
|
|
|
#define FT_STRUCTURE PCF_ParsePropertyRec
|
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
FT_FRAME_START( PCF_PROPERTY_SIZE ),
|
2018-08-09 04:17:35 +02:00
|
|
|
FT_FRAME_LONG( name ),
|
|
|
|
FT_FRAME_BYTE( isString ),
|
|
|
|
FT_FRAME_LONG( value ),
|
2001-01-01 18:24:31 +01:00
|
|
|
FT_FRAME_END
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-01-22 23:45:28 +01:00
|
|
|
FT_LOCAL_DEF( PCF_Property )
|
2002-02-06 12:22:56 +01:00
|
|
|
pcf_find_property( PCF_Face face,
|
|
|
|
const FT_String* prop )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
|
|
|
PCF_Property properties = face->properties;
|
|
|
|
FT_Bool found = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
2016-02-15 12:54:40 +01:00
|
|
|
for ( i = 0; i < face->nprops && !found; i++ )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
* README.UNX: updated the Unix-specific quick-compilation guide to
warn about the GNU Make requirement at compile time..
* include/freetype/config/ftstdlib.h,
include/freetype/config/ftconfig.h,
include/freetype/config/ftheader.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h,
src/autohint/ahoptim.c,
src/base/ftdbgmem.c, src/base/ftdebug.c,
src/base/ftmac.c, src/base/ftobjs.c,
src/base/ftsystem.c,
src/cache/ftcimage.c, src/cache/ftcsbits.c,
src/cff/cffdriver.c, src/cff/cffload.c, src/cff/cffobjs.c,
src/cid/cidload.c, src/cid/cidparse.c, src/cid/cidriver.c,
src/pcf/pcfdriver.c, src/pcf/pcfread.c,
src/psaux/t1cmap.c, src/psaux/t1decode.c,
src/pshinter/pshalgo1.c, src/pshinter/pshalgo2.c,
src/pshinter/pshrec.c,
src/psnames/psmodule.c,
src/raster/ftraster.c,
src/sfnt/sfdriver.c, src/sfnt/ttload.c, src/sfnt/ttpost.c,
src/smooth/ftgrays.c,
src/type1/t1afm.c, src/type1/t1driver.c, src/type1/t1gload.c,
src/type1/t1load.c, src/type1/t1objs.c, src/type1/t1parse.c:
added the new configuration file "ftstdlib.h" used to define
aliases for all ISO C library functions used by the engine
(e.g. strlen, qsort, setjmp, etc...)
this eases the porting of FreeType 2 to exotic environments like
XFree86 modules/extensions..
also removed many #include <string.h>, #include <stdlib.h>, etc...
from the engine's sources where they're not needed..
2002-04-12 11:31:48 +02:00
|
|
|
if ( !ft_strcmp( properties[i].name, prop ) )
|
2001-01-01 18:24:31 +01:00
|
|
|
found = 1;
|
|
|
|
}
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( found )
|
|
|
|
return properties + i - 1;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Error
|
|
|
|
pcf_get_properties( FT_Stream stream,
|
|
|
|
PCF_Face face )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2015-04-12 05:54:19 +02:00
|
|
|
PCF_ParseProperty props = NULL;
|
2011-06-14 19:48:33 +02:00
|
|
|
PCF_Property properties = NULL;
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_ULong nprops, orig_nprops, i;
|
2001-01-01 18:24:31 +01:00
|
|
|
FT_ULong format, size;
|
|
|
|
FT_Error error;
|
2013-06-04 10:30:48 +02:00
|
|
|
FT_Memory memory = FT_FACE( face )->memory;
|
2001-01-01 18:24:31 +01:00
|
|
|
FT_ULong string_size;
|
2015-04-12 05:54:19 +02:00
|
|
|
FT_String* strings = NULL;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2002-02-06 12:22:56 +01:00
|
|
|
error = pcf_seek_to_table_type( stream,
|
|
|
|
face->toc.tables,
|
|
|
|
face->toc.count,
|
|
|
|
PCF_PROPERTIES,
|
|
|
|
&format,
|
|
|
|
&size );
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( error )
|
|
|
|
goto Bail;
|
|
|
|
|
* include/freetype/internal/ftstream.h,
src/base/ftstream.c, src/cff/cffload.c, src/pcf/pcfread.c,
src/sfnt/ttcmap.c, src/sfnt/ttcmap0.c, src/sfnt/ttload.c,
src/sfnt/ttpost.c, src/sfnt/ttsbit.c,
src/truetype/ttgload.c, src/truetype/ttpload.c,
src/winfonts/winfnt.c:
changed the definitions of stream macros. Examples:
NEXT_Byte => FT_NEXT_BYTE
NEXT_Short => FT_NEXT_SHORT
NEXT_UShortLE => FT_NEXT_USHORT_LE
READ_Short => FT_READ_SHORT
GET_Long => FT_GET_LONG
etc..
also introduced the FT_PEEK_XXXX functions..
2002-03-22 13:55:23 +01:00
|
|
|
if ( FT_READ_ULONG_LE( format ) )
|
2001-01-01 18:24:31 +01:00
|
|
|
goto Bail;
|
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE4(( "pcf_get_properties:\n"
|
|
|
|
" format: 0x%lX (%s)\n",
|
|
|
|
format,
|
|
|
|
PCF_BYTE_ORDER( format ) == MSBFirst ? "MSB" : "LSB" ));
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) )
|
|
|
|
goto Bail;
|
|
|
|
|
|
|
|
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
|
2017-01-06 11:47:55 +01:00
|
|
|
(void)FT_READ_ULONG( orig_nprops );
|
2001-01-01 18:24:31 +01:00
|
|
|
else
|
2017-01-06 11:47:55 +01:00
|
|
|
(void)FT_READ_ULONG_LE( orig_nprops );
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( error )
|
|
|
|
goto Bail;
|
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE4(( " number of properties: %ld\n", orig_nprops ));
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
/* rough estimate */
|
2017-01-06 11:47:55 +01:00
|
|
|
if ( orig_nprops > size / PCF_PROPERTY_SIZE )
|
2006-07-08 23:31:24 +02:00
|
|
|
{
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Table );
|
2006-07-08 23:31:24 +02:00
|
|
|
goto Bail;
|
|
|
|
}
|
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
/* as a heuristic limit to avoid excessive allocation in */
|
|
|
|
/* gzip bombs (i.e., very small, invalid input data that */
|
|
|
|
/* pretends to expand to an insanely large file) we only */
|
|
|
|
/* load the first 256 properties */
|
|
|
|
if ( orig_nprops > 256 )
|
|
|
|
{
|
|
|
|
FT_TRACE0(( "pcf_get_properties:"
|
|
|
|
" only loading first 256 properties\n" ));
|
|
|
|
nprops = 256;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nprops = orig_nprops;
|
|
|
|
|
2009-07-31 17:37:56 +02:00
|
|
|
face->nprops = (int)nprops;
|
2006-07-08 23:31:24 +02:00
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
if ( FT_NEW_ARRAY( props, nprops ) )
|
2001-01-01 18:24:31 +01:00
|
|
|
goto Bail;
|
|
|
|
|
|
|
|
for ( i = 0; i < nprops; i++ )
|
|
|
|
{
|
|
|
|
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
|
2001-03-11 14:11:43 +01:00
|
|
|
{
|
2002-03-20 11:49:31 +01:00
|
|
|
if ( FT_STREAM_READ_FIELDS( pcf_property_msb_header, props + i ) )
|
2001-03-11 14:11:43 +01:00
|
|
|
goto Bail;
|
|
|
|
}
|
2001-01-01 18:24:31 +01:00
|
|
|
else
|
2001-03-11 14:11:43 +01:00
|
|
|
{
|
2002-03-20 11:49:31 +01:00
|
|
|
if ( FT_STREAM_READ_FIELDS( pcf_property_header, props + i ) )
|
2001-03-11 14:11:43 +01:00
|
|
|
goto Bail;
|
|
|
|
}
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
/* this skip will only work if we really have an extremely large */
|
|
|
|
/* number of properties; it will fail for fake data, avoiding an */
|
|
|
|
/* unnecessarily large allocation later on */
|
|
|
|
if ( FT_STREAM_SKIP( ( orig_nprops - nprops ) * PCF_PROPERTY_SIZE ) )
|
|
|
|
{
|
|
|
|
error = FT_THROW( Invalid_Stream_Skip );
|
|
|
|
goto Bail;
|
|
|
|
}
|
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
/* pad the property array */
|
|
|
|
/* */
|
|
|
|
/* clever here - nprops is the same as the number of odd-units read, */
|
|
|
|
/* as only isStringProp are odd length (Keith Packard) */
|
|
|
|
/* */
|
2017-01-06 11:47:55 +01:00
|
|
|
if ( orig_nprops & 3 )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2017-01-06 11:47:55 +01:00
|
|
|
i = 4 - ( orig_nprops & 3 );
|
2009-03-12 09:07:49 +01:00
|
|
|
if ( FT_STREAM_SKIP( i ) )
|
|
|
|
{
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Stream_Skip );
|
2009-03-12 09:07:49 +01:00
|
|
|
goto Bail;
|
|
|
|
}
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
|
* include/freetype/internal/ftstream.h,
src/base/ftstream.c, src/cff/cffload.c, src/pcf/pcfread.c,
src/sfnt/ttcmap.c, src/sfnt/ttcmap0.c, src/sfnt/ttload.c,
src/sfnt/ttpost.c, src/sfnt/ttsbit.c,
src/truetype/ttgload.c, src/truetype/ttpload.c,
src/winfonts/winfnt.c:
changed the definitions of stream macros. Examples:
NEXT_Byte => FT_NEXT_BYTE
NEXT_Short => FT_NEXT_SHORT
NEXT_UShortLE => FT_NEXT_USHORT_LE
READ_Short => FT_READ_SHORT
GET_Long => FT_GET_LONG
etc..
also introduced the FT_PEEK_XXXX functions..
2002-03-22 13:55:23 +01:00
|
|
|
(void)FT_READ_ULONG( string_size );
|
2001-01-01 18:24:31 +01:00
|
|
|
else
|
* include/freetype/internal/ftstream.h,
src/base/ftstream.c, src/cff/cffload.c, src/pcf/pcfread.c,
src/sfnt/ttcmap.c, src/sfnt/ttcmap0.c, src/sfnt/ttload.c,
src/sfnt/ttpost.c, src/sfnt/ttsbit.c,
src/truetype/ttgload.c, src/truetype/ttpload.c,
src/winfonts/winfnt.c:
changed the definitions of stream macros. Examples:
NEXT_Byte => FT_NEXT_BYTE
NEXT_Short => FT_NEXT_SHORT
NEXT_UShortLE => FT_NEXT_USHORT_LE
READ_Short => FT_READ_SHORT
GET_Long => FT_GET_LONG
etc..
also introduced the FT_PEEK_XXXX functions..
2002-03-22 13:55:23 +01:00
|
|
|
(void)FT_READ_ULONG_LE( string_size );
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( error )
|
|
|
|
goto Bail;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE4(( " string size: %ld\n", string_size ));
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
/* rough estimate */
|
2017-01-06 11:47:55 +01:00
|
|
|
if ( string_size > size - orig_nprops * PCF_PROPERTY_SIZE )
|
2006-07-08 23:31:24 +02:00
|
|
|
{
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Table );
|
2006-07-08 23:31:24 +02:00
|
|
|
goto Bail;
|
|
|
|
}
|
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
/* the strings in the `strings' array are PostScript strings, */
|
|
|
|
/* which can have a maximum length of 65536 characters each */
|
|
|
|
if ( string_size > 16777472 ) /* 256 * (65536 + 1) */
|
|
|
|
{
|
|
|
|
FT_TRACE0(( "pcf_get_properties:"
|
|
|
|
" loading only 16777472 bytes of strings array\n" ));
|
|
|
|
string_size = 16777472;
|
|
|
|
}
|
|
|
|
|
2012-02-25 14:21:01 +01:00
|
|
|
/* allocate one more byte so that we have a final null byte */
|
|
|
|
if ( FT_NEW_ARRAY( strings, string_size + 1 ) )
|
2001-01-01 18:24:31 +01:00
|
|
|
goto Bail;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2002-02-24 06:26:57 +01:00
|
|
|
error = FT_Stream_Read( stream, (FT_Byte*)strings, string_size );
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( error )
|
|
|
|
goto Bail;
|
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
if ( FT_NEW_ARRAY( properties, nprops ) )
|
2001-01-01 18:24:31 +01:00
|
|
|
goto Bail;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
face->properties = properties;
|
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE4(( "\n" ));
|
2001-01-01 18:24:31 +01:00
|
|
|
for ( i = 0; i < nprops; i++ )
|
|
|
|
{
|
2018-08-09 04:17:35 +02:00
|
|
|
FT_Long name_offset = props[i].name;
|
2006-07-08 23:31:24 +02:00
|
|
|
|
|
|
|
|
2018-08-09 04:17:35 +02:00
|
|
|
if ( ( name_offset < 0 ) ||
|
|
|
|
( (FT_ULong)name_offset > string_size ) )
|
2006-07-08 23:31:24 +02:00
|
|
|
{
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Offset );
|
2006-07-08 23:31:24 +02:00
|
|
|
goto Bail;
|
|
|
|
}
|
|
|
|
|
2007-02-12 15:55:03 +01:00
|
|
|
if ( FT_STRDUP( properties[i].name, strings + name_offset ) )
|
2001-01-01 18:24:31 +01:00
|
|
|
goto Bail;
|
2004-06-22 08:24:09 +02:00
|
|
|
|
|
|
|
FT_TRACE4(( " %s:", properties[i].name ));
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
properties[i].isString = props[i].isString;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( props[i].isString )
|
|
|
|
{
|
2018-08-09 04:17:35 +02:00
|
|
|
FT_Long value_offset = props[i].value;
|
2006-07-08 23:31:24 +02:00
|
|
|
|
|
|
|
|
2018-08-09 04:17:35 +02:00
|
|
|
if ( ( value_offset < 0 ) ||
|
|
|
|
( (FT_ULong)value_offset > string_size ) )
|
2006-07-08 23:31:24 +02:00
|
|
|
{
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_Offset );
|
2006-07-08 23:31:24 +02:00
|
|
|
goto Bail;
|
|
|
|
}
|
|
|
|
|
2007-02-12 15:55:03 +01:00
|
|
|
if ( FT_STRDUP( properties[i].value.atom, strings + value_offset ) )
|
2001-01-01 18:24:31 +01:00
|
|
|
goto Bail;
|
2004-06-22 08:24:09 +02:00
|
|
|
|
|
|
|
FT_TRACE4(( " `%s'\n", properties[i].value.atom ));
|
2001-06-27 21:46:12 +02:00
|
|
|
}
|
2001-01-01 18:24:31 +01:00
|
|
|
else
|
2004-06-22 08:24:09 +02:00
|
|
|
{
|
2018-08-09 04:17:35 +02:00
|
|
|
properties[i].value.l = props[i].value;
|
2004-06-22 08:24:09 +02:00
|
|
|
|
2009-07-31 17:30:23 +02:00
|
|
|
FT_TRACE4(( " %d\n", properties[i].value.l ));
|
2004-06-22 08:24:09 +02:00
|
|
|
}
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2013-03-14 11:21:17 +01:00
|
|
|
error = FT_Err_Ok;
|
2007-01-16 07:11:27 +01:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
Bail:
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( props );
|
|
|
|
FT_FREE( strings );
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Error
|
|
|
|
pcf_get_metrics( FT_Stream stream,
|
|
|
|
PCF_Face face )
|
|
|
|
{
|
2013-06-04 10:30:48 +02:00
|
|
|
FT_Error error;
|
|
|
|
FT_Memory memory = FT_FACE( face )->memory;
|
2006-07-08 23:31:24 +02:00
|
|
|
FT_ULong format, size;
|
2015-04-12 05:54:19 +02:00
|
|
|
PCF_Metric metrics = NULL;
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_ULong nmetrics, orig_nmetrics, i;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
|
2002-02-06 12:22:56 +01:00
|
|
|
error = pcf_seek_to_table_type( stream,
|
2002-02-08 07:23:50 +01:00
|
|
|
face->toc.tables,
|
|
|
|
face->toc.count,
|
|
|
|
PCF_METRICS,
|
|
|
|
&format,
|
|
|
|
&size );
|
2001-06-27 21:46:12 +02:00
|
|
|
if ( error )
|
2001-01-01 18:24:31 +01:00
|
|
|
return error;
|
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
if ( FT_READ_ULONG_LE( format ) )
|
|
|
|
goto Bail;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE4(( "pcf_get_metrics:\n"
|
|
|
|
" format: 0x%lX (%s, %s)\n",
|
|
|
|
format,
|
|
|
|
PCF_BYTE_ORDER( format ) == MSBFirst ? "MSB" : "LSB",
|
|
|
|
PCF_FORMAT_MATCH( format, PCF_COMPRESSED_METRICS ) ?
|
|
|
|
"compressed" : "uncompressed" ));
|
|
|
|
|
2002-03-31 08:56:56 +02:00
|
|
|
if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) &&
|
2001-01-01 18:24:31 +01:00
|
|
|
!PCF_FORMAT_MATCH( format, PCF_COMPRESSED_METRICS ) )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_File_Format );
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) )
|
|
|
|
{
|
|
|
|
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
|
2017-01-06 11:47:55 +01:00
|
|
|
(void)FT_READ_ULONG( orig_nmetrics );
|
2001-01-01 18:24:31 +01:00
|
|
|
else
|
2017-01-06 11:47:55 +01:00
|
|
|
(void)FT_READ_ULONG_LE( orig_nmetrics );
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
|
2017-01-06 11:47:55 +01:00
|
|
|
(void)FT_READ_USHORT( orig_nmetrics );
|
2001-01-01 18:24:31 +01:00
|
|
|
else
|
2017-01-06 11:47:55 +01:00
|
|
|
(void)FT_READ_USHORT_LE( orig_nmetrics );
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
2006-07-08 23:31:24 +02:00
|
|
|
if ( error )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_File_Format );
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE4(( " number of metrics: %ld\n", orig_nmetrics ));
|
2006-07-08 23:31:24 +02:00
|
|
|
|
|
|
|
/* rough estimate */
|
|
|
|
if ( PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) )
|
|
|
|
{
|
2017-01-06 11:47:55 +01:00
|
|
|
if ( orig_nmetrics > size / PCF_METRIC_SIZE )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Table );
|
2006-07-08 23:31:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-06 11:47:55 +01:00
|
|
|
if ( orig_nmetrics > size / PCF_COMPRESSED_METRIC_SIZE )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Table );
|
2006-07-08 23:31:24 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
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 )
|
|
|
|
{
|
|
|
|
FT_TRACE0(( "pcf_get_metrics:"
|
|
|
|
" only loading first 65536 metrics\n" ));
|
|
|
|
nmetrics = 65536;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nmetrics = orig_nmetrics;
|
|
|
|
|
|
|
|
face->nmetrics = nmetrics;
|
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
if ( FT_NEW_ARRAY( face->metrics, nmetrics ) )
|
2017-01-06 11:47:55 +01:00
|
|
|
return error;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
metrics = face->metrics;
|
2017-01-06 11:47:55 +01:00
|
|
|
|
|
|
|
FT_TRACE4(( "\n" ));
|
2014-11-21 12:06:40 +01:00
|
|
|
for ( i = 0; i < nmetrics; i++, metrics++ )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE5(( " idx %ld:", i ));
|
2014-11-21 12:06:40 +01:00
|
|
|
error = pcf_get_metric( stream, format, metrics );
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2014-11-21 12:06:40 +01:00
|
|
|
metrics->bits = 0;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
if ( error )
|
|
|
|
break;
|
2014-11-21 12:06:40 +01:00
|
|
|
|
|
|
|
/* sanity checks -- those values are used in `PCF_Glyph_Load' to */
|
|
|
|
/* compute a glyph's bitmap dimensions, thus setting them to zero in */
|
|
|
|
/* case of an error disables this particular glyph only */
|
|
|
|
if ( metrics->rightSideBearing < metrics->leftSideBearing ||
|
2017-01-06 11:47:55 +01:00
|
|
|
metrics->ascent < -metrics->descent )
|
2014-11-21 12:06:40 +01:00
|
|
|
{
|
|
|
|
metrics->characterWidth = 0;
|
|
|
|
metrics->leftSideBearing = 0;
|
|
|
|
metrics->rightSideBearing = 0;
|
|
|
|
metrics->ascent = 0;
|
|
|
|
metrics->descent = 0;
|
|
|
|
|
|
|
|
FT_TRACE0(( "pcf_get_metrics:"
|
|
|
|
" invalid metrics for glyph %d\n", i ));
|
|
|
|
}
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( error )
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( face->metrics );
|
2006-07-08 23:31:24 +02:00
|
|
|
|
|
|
|
Bail:
|
2001-01-01 18:24:31 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Error
|
|
|
|
pcf_get_bitmaps( FT_Stream stream,
|
|
|
|
PCF_Face face )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2013-06-04 10:30:48 +02:00
|
|
|
FT_Error error;
|
|
|
|
FT_Memory memory = FT_FACE( face )->memory;
|
2018-08-08 04:49:55 +02:00
|
|
|
FT_ULong* offsets = NULL;
|
|
|
|
FT_ULong bitmapSizes[GLYPHPADOPTIONS];
|
2001-01-01 18:24:31 +01:00
|
|
|
FT_ULong format, size;
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_ULong nbitmaps, orig_nbitmaps, i, sizebitmaps = 0;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
|
2002-02-06 12:22:56 +01:00
|
|
|
error = pcf_seek_to_table_type( stream,
|
|
|
|
face->toc.tables,
|
|
|
|
face->toc.count,
|
|
|
|
PCF_BITMAPS,
|
|
|
|
&format,
|
|
|
|
&size );
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( error )
|
|
|
|
return error;
|
|
|
|
|
2002-03-20 11:49:31 +01:00
|
|
|
error = FT_Stream_EnterFrame( stream, 8 );
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( error )
|
|
|
|
return error;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
* include/freetype/internal/ftstream.h,
src/base/ftstream.c, src/cff/cffload.c, src/pcf/pcfread.c,
src/sfnt/ttcmap.c, src/sfnt/ttcmap0.c, src/sfnt/ttload.c,
src/sfnt/ttpost.c, src/sfnt/ttsbit.c,
src/truetype/ttgload.c, src/truetype/ttpload.c,
src/winfonts/winfnt.c:
changed the definitions of stream macros. Examples:
NEXT_Byte => FT_NEXT_BYTE
NEXT_Short => FT_NEXT_SHORT
NEXT_UShortLE => FT_NEXT_USHORT_LE
READ_Short => FT_READ_SHORT
GET_Long => FT_GET_LONG
etc..
also introduced the FT_PEEK_XXXX functions..
2002-03-22 13:55:23 +01:00
|
|
|
format = FT_GET_ULONG_LE();
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
|
2017-01-06 11:47:55 +01:00
|
|
|
orig_nbitmaps = FT_GET_ULONG();
|
2001-01-01 18:24:31 +01:00
|
|
|
else
|
2017-01-06 11:47:55 +01:00
|
|
|
orig_nbitmaps = FT_GET_ULONG_LE();
|
2002-02-06 12:22:56 +01:00
|
|
|
|
2002-03-20 11:49:31 +01:00
|
|
|
FT_Stream_ExitFrame( stream );
|
2002-02-06 12:22:56 +01:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE4(( "pcf_get_bitmaps:\n"
|
|
|
|
" format: 0x%lX\n"
|
|
|
|
" (%s, %s,\n"
|
2017-12-05 12:06:29 +01:00
|
|
|
" padding=%d bit%s, scanning=%d bit%s)\n",
|
2017-01-06 11:47:55 +01:00
|
|
|
format,
|
|
|
|
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",
|
|
|
|
8 << PCF_GLYPH_PAD_INDEX( format ),
|
2017-12-05 12:06:29 +01:00
|
|
|
( 8 << PCF_GLYPH_PAD_INDEX( format ) ) == 1 ? "" : "s",
|
|
|
|
8 << PCF_SCAN_UNIT_INDEX( format ),
|
|
|
|
( 8 << PCF_SCAN_UNIT_INDEX( format ) ) == 1 ? "" : "s" ));
|
2017-01-06 11:47:55 +01:00
|
|
|
|
2002-02-06 12:22:56 +01:00
|
|
|
if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_File_Format );
|
2002-02-06 12:22:56 +01:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE4(( " number of bitmaps: %ld\n", orig_nbitmaps ));
|
2006-07-08 23:31:24 +02:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
/* see comment in `pcf_get_metrics' */
|
|
|
|
if ( orig_nbitmaps > 65536 )
|
|
|
|
{
|
|
|
|
FT_TRACE0(( "pcf_get_bitmaps:"
|
|
|
|
" only loading first 65536 bitmaps\n" ));
|
|
|
|
nbitmaps = 65536;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nbitmaps = orig_nbitmaps;
|
2006-07-08 23:31:24 +02:00
|
|
|
|
2015-02-22 08:25:16 +01:00
|
|
|
if ( nbitmaps != face->nmetrics )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_File_Format );
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
if ( FT_NEW_ARRAY( offsets, nbitmaps ) )
|
2001-01-01 18:24:31 +01:00
|
|
|
return error;
|
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE5(( "\n" ));
|
2001-01-01 18:24:31 +01:00
|
|
|
for ( i = 0; i < nbitmaps; i++ )
|
2001-06-27 21:46:12 +02:00
|
|
|
{
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
|
2018-08-08 04:49:55 +02:00
|
|
|
(void)FT_READ_ULONG( offsets[i] );
|
2001-01-01 18:24:31 +01:00
|
|
|
else
|
2018-08-08 04:49:55 +02:00
|
|
|
(void)FT_READ_ULONG_LE( offsets[i] );
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2018-08-08 04:49:55 +02:00
|
|
|
FT_TRACE5(( " bitmap %lu: offset %lu (0x%lX)\n",
|
2004-06-22 08:24:09 +02:00
|
|
|
i, offsets[i], offsets[i] ));
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
if ( error )
|
|
|
|
goto Bail;
|
|
|
|
|
|
|
|
for ( i = 0; i < GLYPHPADOPTIONS; i++ )
|
2001-06-27 21:46:12 +02:00
|
|
|
{
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
|
2018-08-08 04:49:55 +02:00
|
|
|
(void)FT_READ_ULONG( bitmapSizes[i] );
|
2001-01-01 18:24:31 +01:00
|
|
|
else
|
2018-08-08 04:49:55 +02:00
|
|
|
(void)FT_READ_ULONG_LE( bitmapSizes[i] );
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( error )
|
|
|
|
goto Bail;
|
|
|
|
|
2018-08-08 04:49:55 +02:00
|
|
|
sizebitmaps = bitmapSizes[PCF_GLYPH_PAD_INDEX( format )];
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2018-08-08 04:49:55 +02:00
|
|
|
FT_TRACE4(( " %ld-bit padding implies a size of %lu\n",
|
2017-01-06 11:47:55 +01:00
|
|
|
8 << i, bitmapSizes[i] ));
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
|
2018-08-08 04:49:55 +02:00
|
|
|
FT_TRACE4(( " %lu bitmaps, using %ld-bit padding\n",
|
2001-01-01 18:24:31 +01:00
|
|
|
nbitmaps,
|
2017-01-06 11:47:55 +01:00
|
|
|
8 << PCF_GLYPH_PAD_INDEX( format ) ));
|
2018-08-08 04:49:55 +02:00
|
|
|
FT_TRACE4(( " bitmap size: %lu\n", sizebitmaps ));
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2002-02-19 17:30:15 +01:00
|
|
|
FT_UNUSED( sizebitmaps ); /* only used for debugging */
|
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
/* right now, we only check the bitmap offsets; */
|
|
|
|
/* actual bitmaps are only loaded on demand */
|
2001-01-01 18:24:31 +01:00
|
|
|
for ( i = 0; i < nbitmaps; i++ )
|
2006-07-08 23:31:24 +02:00
|
|
|
{
|
|
|
|
/* rough estimate */
|
2018-08-08 04:49:55 +02:00
|
|
|
if ( offsets[i] > size )
|
2006-07-08 23:31:24 +02:00
|
|
|
{
|
2009-06-26 06:15:41 +02:00
|
|
|
FT_TRACE0(( "pcf_get_bitmaps:"
|
2018-08-08 04:49:55 +02:00
|
|
|
" invalid offset to bitmap data of glyph %lu\n", i ));
|
2006-07-08 23:31:24 +02:00
|
|
|
}
|
|
|
|
else
|
2018-08-08 04:49:55 +02:00
|
|
|
face->metrics[i].bits = stream->pos + offsets[i];
|
2006-07-08 23:31:24 +02:00
|
|
|
}
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
face->bitmapsFormat = format;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
Bail:
|
2006-07-08 23:31:24 +02:00
|
|
|
FT_FREE( offsets );
|
2001-01-01 18:24:31 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-21 23:45:32 +02:00
|
|
|
/*
|
|
|
|
* This file uses X11 terminology for PCF data; an `encoding' in X11 speak
|
|
|
|
* is the same as a character code in FreeType speak.
|
|
|
|
*/
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Error
|
|
|
|
pcf_get_encodings( FT_Stream stream,
|
|
|
|
PCF_Face face )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2013-06-04 10:30:48 +02:00
|
|
|
FT_Error error;
|
|
|
|
FT_Memory memory = FT_FACE( face )->memory;
|
2001-01-01 18:24:31 +01:00
|
|
|
FT_ULong format, size;
|
2018-08-06 10:58:18 +02:00
|
|
|
FT_UShort firstCol, lastCol;
|
|
|
|
FT_UShort firstRow, lastRow;
|
2015-02-22 08:25:16 +01:00
|
|
|
FT_ULong nencoding;
|
2018-07-21 23:45:32 +02:00
|
|
|
FT_UShort defaultCharRow, defaultCharCol;
|
|
|
|
FT_UShort encodingOffset, defaultCharEncodingOffset;
|
2018-08-06 10:58:18 +02:00
|
|
|
FT_UShort i, j;
|
2018-07-21 23:45:32 +02:00
|
|
|
FT_Byte* pos;
|
2015-02-22 08:25:16 +01:00
|
|
|
FT_ULong k;
|
2013-02-02 02:24:00 +01:00
|
|
|
PCF_Encoding encoding = NULL;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
|
2002-02-06 12:22:56 +01:00
|
|
|
error = pcf_seek_to_table_type( stream,
|
2002-03-31 08:56:56 +02:00
|
|
|
face->toc.tables,
|
|
|
|
face->toc.count,
|
|
|
|
PCF_BDF_ENCODINGS,
|
|
|
|
&format,
|
|
|
|
&size );
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( error )
|
|
|
|
return error;
|
|
|
|
|
2002-03-20 11:49:31 +01:00
|
|
|
error = FT_Stream_EnterFrame( stream, 14 );
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( error )
|
|
|
|
return error;
|
2002-02-06 12:22:56 +01:00
|
|
|
|
* include/freetype/internal/ftstream.h,
src/base/ftstream.c, src/cff/cffload.c, src/pcf/pcfread.c,
src/sfnt/ttcmap.c, src/sfnt/ttcmap0.c, src/sfnt/ttload.c,
src/sfnt/ttpost.c, src/sfnt/ttsbit.c,
src/truetype/ttgload.c, src/truetype/ttpload.c,
src/winfonts/winfnt.c:
changed the definitions of stream macros. Examples:
NEXT_Byte => FT_NEXT_BYTE
NEXT_Short => FT_NEXT_SHORT
NEXT_UShortLE => FT_NEXT_USHORT_LE
READ_Short => FT_READ_SHORT
GET_Long => FT_GET_LONG
etc..
also introduced the FT_PEEK_XXXX functions..
2002-03-22 13:55:23 +01:00
|
|
|
format = FT_GET_ULONG_LE();
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2018-07-21 23:45:32 +02:00
|
|
|
/* X11's reference implementation uses the equivalent to */
|
|
|
|
/* `FT_GET_SHORT' for `defaultChar', however this doesn't */
|
|
|
|
/* make sense for most encodings. */
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
|
|
|
|
{
|
2018-08-06 10:58:18 +02:00
|
|
|
firstCol = FT_GET_USHORT();
|
|
|
|
lastCol = FT_GET_USHORT();
|
|
|
|
firstRow = FT_GET_USHORT();
|
|
|
|
lastRow = FT_GET_USHORT();
|
2018-07-21 23:45:32 +02:00
|
|
|
face->defaultChar = FT_GET_USHORT();
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-06 10:58:18 +02:00
|
|
|
firstCol = FT_GET_USHORT_LE();
|
|
|
|
lastCol = FT_GET_USHORT_LE();
|
|
|
|
firstRow = FT_GET_USHORT_LE();
|
|
|
|
lastRow = FT_GET_USHORT_LE();
|
2018-07-21 23:45:32 +02:00
|
|
|
face->defaultChar = FT_GET_USHORT_LE();
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
|
2002-03-20 11:49:31 +01:00
|
|
|
FT_Stream_ExitFrame( stream );
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE4(( "pcf_get_encodings:\n"
|
|
|
|
" format: 0x%lX (%s)\n",
|
|
|
|
format,
|
|
|
|
PCF_BYTE_ORDER( format ) == MSBFirst ? "MSB" : "LSB" ));
|
|
|
|
|
2002-02-06 12:22:56 +01:00
|
|
|
if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_File_Format );
|
2002-02-06 12:22:56 +01:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE4(( " firstCol 0x%X, lastCol 0x%X\n"
|
2018-07-17 19:54:25 +02:00
|
|
|
" firstRow 0x%X, lastRow 0x%X\n"
|
|
|
|
" defaultChar 0x%X\n",
|
2017-01-06 11:47:55 +01:00
|
|
|
firstCol, lastCol,
|
2018-07-17 19:54:25 +02:00
|
|
|
firstRow, lastRow,
|
|
|
|
face->defaultChar ));
|
2017-01-06 11:47:55 +01:00
|
|
|
|
|
|
|
/* sanity checks; we limit numbers of rows and columns to 256 */
|
2018-08-06 10:58:18 +02:00
|
|
|
if ( firstCol > lastCol ||
|
2014-11-06 23:25:05 +01:00
|
|
|
lastCol > 0xFF ||
|
|
|
|
firstRow > lastRow ||
|
|
|
|
lastRow > 0xFF )
|
|
|
|
return FT_THROW( Invalid_Table );
|
|
|
|
|
2015-02-22 08:25:16 +01:00
|
|
|
nencoding = (FT_ULong)( lastCol - firstCol + 1 ) *
|
|
|
|
(FT_ULong)( lastRow - firstRow + 1 );
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2013-02-02 02:24:00 +01:00
|
|
|
if ( FT_NEW_ARRAY( encoding, nencoding ) )
|
2017-01-06 11:47:55 +01:00
|
|
|
return error;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2002-03-20 11:49:31 +01:00
|
|
|
error = FT_Stream_EnterFrame( stream, 2 * nencoding );
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( error )
|
|
|
|
goto Bail;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE5(( "\n" ));
|
|
|
|
|
2018-07-21 23:45:32 +02:00
|
|
|
defaultCharRow = face->defaultChar >> 8;
|
|
|
|
defaultCharCol = face->defaultChar & 0xFF;
|
|
|
|
|
|
|
|
/* validate default character */
|
2018-08-06 10:58:18 +02:00
|
|
|
if ( defaultCharRow < firstRow ||
|
|
|
|
defaultCharRow > lastRow ||
|
|
|
|
defaultCharCol < firstCol ||
|
|
|
|
defaultCharCol > lastCol )
|
2018-07-21 23:45:32 +02:00
|
|
|
{
|
2018-08-06 10:58:18 +02:00
|
|
|
face->defaultChar = firstRow * 256U + firstCol;
|
2018-07-21 23:45:32 +02:00
|
|
|
FT_TRACE0(( "pcf_get_encodings:"
|
2018-08-06 10:58:18 +02:00
|
|
|
" Invalid default character set to %u\n",
|
2018-07-21 23:45:32 +02:00
|
|
|
face->defaultChar ));
|
2018-07-24 09:59:23 +02:00
|
|
|
|
|
|
|
defaultCharRow = face->defaultChar >> 8;
|
|
|
|
defaultCharCol = face->defaultChar & 0xFF;
|
2018-07-21 23:45:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* FreeType mandates that glyph index 0 is the `undefined glyph', */
|
|
|
|
/* which PCF calls the `default character'. For this reason, we */
|
|
|
|
/* swap the positions of glyph index 0 and the index corresponding */
|
|
|
|
/* to `defaultChar' in case they are different. */
|
|
|
|
|
|
|
|
/* `stream->cursor' still points at the beginning of the frame; */
|
|
|
|
/* we can thus easily get the offset to the default character */
|
|
|
|
pos = stream->cursor +
|
2018-08-06 10:58:18 +02:00
|
|
|
2 * ( ( defaultCharRow - firstRow ) * ( lastCol - firstCol + 1 ) +
|
|
|
|
defaultCharCol - firstCol );
|
2018-07-21 23:45:32 +02:00
|
|
|
|
|
|
|
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
|
|
|
|
defaultCharEncodingOffset = FT_PEEK_USHORT( pos );
|
|
|
|
else
|
|
|
|
defaultCharEncodingOffset = FT_PEEK_USHORT_LE( pos );
|
|
|
|
|
2018-07-22 13:06:20 +02:00
|
|
|
if ( defaultCharEncodingOffset >= face->nmetrics )
|
|
|
|
{
|
|
|
|
FT_TRACE0(( "pcf_get_encodings:"
|
|
|
|
" Invalid glyph index for default character,"
|
|
|
|
" setting to zero\n" ));
|
|
|
|
defaultCharEncodingOffset = 0;
|
|
|
|
}
|
|
|
|
|
2018-07-21 23:45:32 +02:00
|
|
|
if ( defaultCharEncodingOffset )
|
|
|
|
{
|
|
|
|
/* do the swapping */
|
|
|
|
PCF_MetricRec tmp = face->metrics[defaultCharEncodingOffset];
|
|
|
|
|
|
|
|
|
|
|
|
face->metrics[defaultCharEncodingOffset] = face->metrics[0];
|
|
|
|
face->metrics[0] = tmp;
|
|
|
|
}
|
|
|
|
|
2013-02-02 02:24:00 +01:00
|
|
|
k = 0;
|
|
|
|
for ( i = firstRow; i <= lastRow; i++ )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2013-02-02 02:24:00 +01:00
|
|
|
for ( j = firstCol; j <= lastCol; j++ )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2016-06-26 08:27:29 +02:00
|
|
|
/* X11's reference implementation uses the equivalent to */
|
|
|
|
/* `FT_GET_SHORT', however PCF fonts with more than 32768 */
|
2018-07-21 23:45:32 +02:00
|
|
|
/* characters (e.g., `unifont.pcf') clearly show that an */
|
2016-06-26 08:27:29 +02:00
|
|
|
/* unsigned value is needed. */
|
2013-02-02 02:24:00 +01:00
|
|
|
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
|
2016-06-26 08:27:29 +02:00
|
|
|
encodingOffset = FT_GET_USHORT();
|
2013-02-02 02:24:00 +01:00
|
|
|
else
|
2016-06-26 08:27:29 +02:00
|
|
|
encodingOffset = FT_GET_USHORT_LE();
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2016-06-26 08:27:29 +02:00
|
|
|
if ( encodingOffset != 0xFFFFU )
|
2013-02-02 02:24:00 +01:00
|
|
|
{
|
2018-07-21 23:45:32 +02:00
|
|
|
if ( encodingOffset == defaultCharEncodingOffset )
|
|
|
|
encodingOffset = 0;
|
|
|
|
else if ( encodingOffset == 0 )
|
|
|
|
encodingOffset = defaultCharEncodingOffset;
|
|
|
|
|
2018-08-06 10:58:18 +02:00
|
|
|
encoding[k].enc = i * 256U + j;
|
2016-06-26 08:27:29 +02:00
|
|
|
encoding[k].glyph = encodingOffset;
|
2004-06-22 08:24:09 +02:00
|
|
|
|
2018-08-06 10:58:18 +02:00
|
|
|
FT_TRACE5(( " code %u (0x%04X): idx %u\n",
|
2013-02-02 02:24:00 +01:00
|
|
|
encoding[k].enc, encoding[k].enc, encoding[k].glyph ));
|
2004-06-22 08:24:09 +02:00
|
|
|
|
2013-02-02 02:24:00 +01:00
|
|
|
k++;
|
|
|
|
}
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
}
|
2002-03-20 11:49:31 +01:00
|
|
|
FT_Stream_ExitFrame( stream );
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2013-02-02 02:24:00 +01:00
|
|
|
if ( FT_RENEW_ARRAY( encoding, nencoding, k ) )
|
2001-01-01 18:24:31 +01:00
|
|
|
goto Bail;
|
|
|
|
|
2013-02-02 02:24:00 +01:00
|
|
|
face->nencodings = k;
|
2001-01-01 18:24:31 +01:00
|
|
|
face->encodings = encoding;
|
|
|
|
|
|
|
|
return error;
|
|
|
|
|
|
|
|
Bail:
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( encoding );
|
2001-01-01 18:24:31 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static
|
2001-01-01 18:24:31 +01:00
|
|
|
const FT_Frame_Field pcf_accel_header[] =
|
|
|
|
{
|
|
|
|
#undef FT_STRUCTURE
|
|
|
|
#define FT_STRUCTURE PCF_AccelRec
|
|
|
|
|
|
|
|
FT_FRAME_START( 20 ),
|
|
|
|
FT_FRAME_BYTE ( noOverlap ),
|
|
|
|
FT_FRAME_BYTE ( constantMetrics ),
|
|
|
|
FT_FRAME_BYTE ( terminalFont ),
|
|
|
|
FT_FRAME_BYTE ( constantWidth ),
|
|
|
|
FT_FRAME_BYTE ( inkInside ),
|
|
|
|
FT_FRAME_BYTE ( inkMetrics ),
|
|
|
|
FT_FRAME_BYTE ( drawDirection ),
|
|
|
|
FT_FRAME_SKIP_BYTES( 1 ),
|
2018-08-09 04:17:35 +02:00
|
|
|
FT_FRAME_LONG_LE ( fontAscent ),
|
|
|
|
FT_FRAME_LONG_LE ( fontDescent ),
|
|
|
|
FT_FRAME_LONG_LE ( maxOverlap ),
|
2001-01-01 18:24:31 +01:00
|
|
|
FT_FRAME_END
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static
|
2001-01-01 18:24:31 +01:00
|
|
|
const FT_Frame_Field pcf_accel_msb_header[] =
|
|
|
|
{
|
|
|
|
#undef FT_STRUCTURE
|
|
|
|
#define FT_STRUCTURE PCF_AccelRec
|
|
|
|
|
|
|
|
FT_FRAME_START( 20 ),
|
|
|
|
FT_FRAME_BYTE ( noOverlap ),
|
|
|
|
FT_FRAME_BYTE ( constantMetrics ),
|
|
|
|
FT_FRAME_BYTE ( terminalFont ),
|
|
|
|
FT_FRAME_BYTE ( constantWidth ),
|
|
|
|
FT_FRAME_BYTE ( inkInside ),
|
|
|
|
FT_FRAME_BYTE ( inkMetrics ),
|
|
|
|
FT_FRAME_BYTE ( drawDirection ),
|
|
|
|
FT_FRAME_SKIP_BYTES( 1 ),
|
2018-08-09 04:17:35 +02:00
|
|
|
FT_FRAME_LONG ( fontAscent ),
|
|
|
|
FT_FRAME_LONG ( fontDescent ),
|
|
|
|
FT_FRAME_LONG ( maxOverlap ),
|
2001-01-01 18:24:31 +01:00
|
|
|
FT_FRAME_END
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-06-27 21:46:12 +02:00
|
|
|
static FT_Error
|
|
|
|
pcf_get_accel( FT_Stream stream,
|
|
|
|
PCF_Face face,
|
|
|
|
FT_ULong type )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
|
|
|
FT_ULong format, size;
|
2013-06-04 10:30:48 +02:00
|
|
|
FT_Error error;
|
2001-01-01 18:24:31 +01:00
|
|
|
PCF_Accel accel = &face->accel;
|
|
|
|
|
|
|
|
|
2002-02-06 12:22:56 +01:00
|
|
|
error = pcf_seek_to_table_type( stream,
|
|
|
|
face->toc.tables,
|
|
|
|
face->toc.count,
|
|
|
|
type,
|
|
|
|
&format,
|
|
|
|
&size );
|
2001-06-27 21:46:12 +02:00
|
|
|
if ( error )
|
2001-01-01 18:24:31 +01:00
|
|
|
goto Bail;
|
|
|
|
|
2006-07-08 23:31:24 +02:00
|
|
|
if ( FT_READ_ULONG_LE( format ) )
|
|
|
|
goto Bail;
|
2002-02-06 12:22:56 +01:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE4(( "pcf_get_accel%s:\n"
|
|
|
|
" format: 0x%lX (%s, %s)\n",
|
|
|
|
type == PCF_BDF_ACCELERATORS ? " (getting BDF accelerators)"
|
|
|
|
: "",
|
|
|
|
format,
|
|
|
|
PCF_BYTE_ORDER( format ) == MSBFirst ? "MSB" : "LSB",
|
|
|
|
PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) ?
|
|
|
|
"accelerated" : "not accelerated" ));
|
|
|
|
|
2002-03-31 08:56:56 +02:00
|
|
|
if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) &&
|
2001-01-01 18:24:31 +01:00
|
|
|
!PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) )
|
|
|
|
goto Bail;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-03-11 14:11:43 +01:00
|
|
|
if ( PCF_BYTE_ORDER( format ) == MSBFirst )
|
|
|
|
{
|
2002-03-20 11:49:31 +01:00
|
|
|
if ( FT_STREAM_READ_FIELDS( pcf_accel_msb_header, accel ) )
|
2001-03-11 14:11:43 +01:00
|
|
|
goto Bail;
|
|
|
|
}
|
2001-01-01 18:24:31 +01:00
|
|
|
else
|
2001-03-11 14:11:43 +01:00
|
|
|
{
|
2002-03-20 11:49:31 +01:00
|
|
|
if ( FT_STREAM_READ_FIELDS( pcf_accel_header, accel ) )
|
2001-03-11 14:11:43 +01:00
|
|
|
goto Bail;
|
|
|
|
}
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE5(( " noOverlap=%s, constantMetrics=%s,"
|
|
|
|
" terminalFont=%s, constantWidth=%s\n"
|
|
|
|
" inkInside=%s, inkMetrics=%s, drawDirection=%s\n"
|
2018-08-09 04:17:35 +02:00
|
|
|
" fontAscent=%ld, fontDescent=%ld, maxOverlap=%ld\n",
|
2017-01-06 11:47:55 +01:00
|
|
|
accel->noOverlap ? "yes" : "no",
|
|
|
|
accel->constantMetrics ? "yes" : "no",
|
|
|
|
accel->terminalFont ? "yes" : "no",
|
|
|
|
accel->constantWidth ? "yes" : "no",
|
|
|
|
accel->inkInside ? "yes" : "no",
|
|
|
|
accel->inkMetrics ? "yes" : "no",
|
|
|
|
accel->drawDirection ? "RTL" : "LTR",
|
|
|
|
accel->fontAscent,
|
|
|
|
accel->fontDescent,
|
|
|
|
accel->maxOverlap ));
|
|
|
|
|
2018-08-09 04:17:35 +02:00
|
|
|
/* sanity checks */
|
|
|
|
if ( FT_ABS( accel->fontAscent ) > 0x7FFF )
|
2017-05-29 21:04:27 +02:00
|
|
|
{
|
2018-08-09 04:17:35 +02:00
|
|
|
accel->fontAscent = accel->fontAscent < 0 ? -0x7FFF : 0x7FFF;
|
|
|
|
FT_TRACE0(( "pfc_get_accel: clamping font ascent to value %d\n",
|
2017-05-29 21:04:27 +02:00
|
|
|
accel->fontAscent ));
|
|
|
|
}
|
2018-08-09 04:17:35 +02:00
|
|
|
if ( FT_ABS( accel->fontDescent ) > 0x7FFF )
|
2017-05-29 21:04:27 +02:00
|
|
|
{
|
2018-08-09 04:17:35 +02:00
|
|
|
accel->fontDescent = accel->fontDescent < 0 ? -0x7FFF : 0x7FFF;
|
|
|
|
FT_TRACE0(( "pfc_get_accel: clamping font descent to value %d\n",
|
2017-05-29 21:04:27 +02:00
|
|
|
accel->fontDescent ));
|
|
|
|
}
|
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE5(( " minbounds:" ));
|
2002-04-16 15:39:17 +02:00
|
|
|
error = pcf_get_metric( stream,
|
|
|
|
format & ( ~PCF_FORMAT_MASK ),
|
|
|
|
&(accel->minbounds) );
|
2001-06-27 21:46:12 +02:00
|
|
|
if ( error )
|
2001-01-01 18:24:31 +01:00
|
|
|
goto Bail;
|
2002-02-06 12:22:56 +01:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE5(( " maxbounds:" ));
|
2002-04-16 15:39:17 +02:00
|
|
|
error = pcf_get_metric( stream,
|
|
|
|
format & ( ~PCF_FORMAT_MASK ),
|
|
|
|
&(accel->maxbounds) );
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( error )
|
|
|
|
goto Bail;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( PCF_FORMAT_MATCH( format, PCF_ACCEL_W_INKBOUNDS ) )
|
|
|
|
{
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE5(( " ink minbounds:" ));
|
2002-04-16 15:39:17 +02:00
|
|
|
error = pcf_get_metric( stream,
|
|
|
|
format & ( ~PCF_FORMAT_MASK ),
|
|
|
|
&(accel->ink_minbounds) );
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( error )
|
|
|
|
goto Bail;
|
2002-02-06 12:22:56 +01:00
|
|
|
|
2017-01-06 11:47:55 +01:00
|
|
|
FT_TRACE5(( " ink maxbounds:" ));
|
2002-04-16 15:39:17 +02:00
|
|
|
error = pcf_get_metric( stream,
|
|
|
|
format & ( ~PCF_FORMAT_MASK ),
|
|
|
|
&(accel->ink_maxbounds) );
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( error )
|
|
|
|
goto Bail;
|
2001-06-27 21:46:12 +02:00
|
|
|
}
|
2001-01-01 18:24:31 +01:00
|
|
|
else
|
|
|
|
{
|
2017-01-06 11:47:55 +01:00
|
|
|
accel->ink_minbounds = accel->minbounds;
|
2001-01-01 18:24:31 +01:00
|
|
|
accel->ink_maxbounds = accel->maxbounds;
|
|
|
|
}
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
Bail:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-13 11:19:27 +01:00
|
|
|
static FT_Error
|
|
|
|
pcf_interpret_style( PCF_Face pcf )
|
|
|
|
{
|
2013-03-14 11:21:17 +01:00
|
|
|
FT_Error error = FT_Err_Ok;
|
2003-11-13 11:19:27 +01:00
|
|
|
FT_Face face = FT_FACE( pcf );
|
|
|
|
FT_Memory memory = face->memory;
|
|
|
|
|
|
|
|
PCF_Property prop;
|
|
|
|
|
2009-07-31 17:32:12 +02:00
|
|
|
size_t nn, len;
|
|
|
|
char* strings[4] = { NULL, NULL, NULL, NULL };
|
|
|
|
size_t lengths[4];
|
2003-11-13 11:19:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
face->style_flags = 0;
|
|
|
|
|
|
|
|
prop = pcf_find_property( pcf, "SLANT" );
|
|
|
|
if ( prop && prop->isString &&
|
|
|
|
( *(prop->value.atom) == 'O' || *(prop->value.atom) == 'o' ||
|
|
|
|
*(prop->value.atom) == 'I' || *(prop->value.atom) == 'i' ) )
|
|
|
|
{
|
|
|
|
face->style_flags |= FT_STYLE_FLAG_ITALIC;
|
2007-02-12 22:44:10 +01:00
|
|
|
strings[2] = ( *(prop->value.atom) == 'O' ||
|
|
|
|
*(prop->value.atom) == 'o' ) ? (char *)"Oblique"
|
|
|
|
: (char *)"Italic";
|
2003-11-13 11:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
prop = pcf_find_property( pcf, "WEIGHT_NAME" );
|
|
|
|
if ( prop && prop->isString &&
|
|
|
|
( *(prop->value.atom) == 'B' || *(prop->value.atom) == 'b' ) )
|
|
|
|
{
|
|
|
|
face->style_flags |= FT_STYLE_FLAG_BOLD;
|
2013-06-04 10:30:48 +02:00
|
|
|
strings[1] = (char*)"Bold";
|
2003-11-13 11:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
prop = pcf_find_property( pcf, "SETWIDTH_NAME" );
|
|
|
|
if ( prop && prop->isString &&
|
|
|
|
*(prop->value.atom) &&
|
|
|
|
!( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
|
2013-06-04 10:30:48 +02:00
|
|
|
strings[3] = (char*)( prop->value.atom );
|
2003-11-13 11:19:27 +01:00
|
|
|
|
|
|
|
prop = pcf_find_property( pcf, "ADD_STYLE_NAME" );
|
|
|
|
if ( prop && prop->isString &&
|
|
|
|
*(prop->value.atom) &&
|
|
|
|
!( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) )
|
2013-06-04 10:30:48 +02:00
|
|
|
strings[0] = (char*)( prop->value.atom );
|
2003-11-13 11:19:27 +01:00
|
|
|
|
2007-02-12 22:44:10 +01:00
|
|
|
for ( len = 0, nn = 0; nn < 4; nn++ )
|
2004-07-28 02:09:02 +02:00
|
|
|
{
|
2007-02-12 15:55:03 +01:00
|
|
|
lengths[nn] = 0;
|
2007-02-12 22:44:10 +01:00
|
|
|
if ( strings[nn] )
|
2007-02-12 15:55:03 +01:00
|
|
|
{
|
2007-02-12 22:44:10 +01:00
|
|
|
lengths[nn] = ft_strlen( strings[nn] );
|
|
|
|
len += lengths[nn] + 1;
|
2007-02-12 15:55:03 +01:00
|
|
|
}
|
2004-07-28 02:09:02 +02:00
|
|
|
}
|
2007-02-12 15:55:03 +01:00
|
|
|
|
|
|
|
if ( len == 0 )
|
2003-11-13 11:19:27 +01:00
|
|
|
{
|
2013-06-04 10:30:48 +02:00
|
|
|
strings[0] = (char*)"Regular";
|
2007-02-12 22:44:10 +01:00
|
|
|
lengths[0] = ft_strlen( strings[0] );
|
|
|
|
len = lengths[0] + 1;
|
2007-02-12 15:55:03 +01:00
|
|
|
}
|
2003-11-13 11:19:27 +01:00
|
|
|
|
2007-02-12 15:55:03 +01:00
|
|
|
{
|
|
|
|
char* s;
|
2003-11-13 11:19:27 +01:00
|
|
|
|
2007-02-12 15:55:03 +01:00
|
|
|
|
|
|
|
if ( FT_ALLOC( face->style_name, len ) )
|
2003-11-13 11:19:27 +01:00
|
|
|
return error;
|
|
|
|
|
2007-02-12 15:55:03 +01:00
|
|
|
s = face->style_name;
|
2003-11-13 11:19:27 +01:00
|
|
|
|
2007-02-12 22:44:10 +01:00
|
|
|
for ( nn = 0; nn < 4; nn++ )
|
2003-11-13 11:19:27 +01:00
|
|
|
{
|
2007-02-12 15:55:03 +01:00
|
|
|
char* src = strings[nn];
|
|
|
|
|
2007-02-12 22:44:10 +01:00
|
|
|
|
2007-02-12 23:08:15 +01:00
|
|
|
len = lengths[nn];
|
|
|
|
|
2016-12-26 17:08:17 +01:00
|
|
|
if ( !src )
|
2007-02-12 15:55:03 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* separate elements with a space */
|
2007-02-12 22:44:10 +01:00
|
|
|
if ( s != face->style_name )
|
2007-02-12 15:55:03 +01:00
|
|
|
*s++ = ' ';
|
|
|
|
|
2007-02-12 22:44:10 +01:00
|
|
|
ft_memcpy( s, src, len );
|
2007-02-12 15:55:03 +01:00
|
|
|
|
2007-02-12 22:44:10 +01:00
|
|
|
/* need to convert spaces to dashes for */
|
|
|
|
/* add_style_name and setwidth_name */
|
|
|
|
if ( nn == 0 || nn == 3 )
|
2007-02-12 15:55:03 +01:00
|
|
|
{
|
2009-07-31 17:32:12 +02:00
|
|
|
size_t mm;
|
2007-02-12 15:55:03 +01:00
|
|
|
|
2007-02-12 22:44:10 +01:00
|
|
|
|
|
|
|
for ( mm = 0; mm < len; mm++ )
|
2013-06-04 10:30:48 +02:00
|
|
|
if ( s[mm] == ' ' )
|
2007-02-12 15:55:03 +01:00
|
|
|
s[mm] = '-';
|
|
|
|
}
|
2003-11-13 11:19:27 +01:00
|
|
|
|
2007-02-12 15:55:03 +01:00
|
|
|
s += len;
|
|
|
|
}
|
|
|
|
*s = 0;
|
2003-11-13 11:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_LOCAL_DEF( FT_Error )
|
2001-06-27 21:46:12 +02:00
|
|
|
pcf_load_font( FT_Stream stream,
|
2015-10-13 18:26:18 +02:00
|
|
|
PCF_Face face,
|
|
|
|
FT_Long face_index )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2015-10-13 18:26:18 +02:00
|
|
|
FT_Face root = FT_FACE( face );
|
2013-08-01 12:20:20 +02:00
|
|
|
FT_Error error;
|
2013-06-04 10:30:48 +02:00
|
|
|
FT_Memory memory = FT_FACE( face )->memory;
|
2001-01-01 18:24:31 +01:00
|
|
|
FT_Bool hasBDFAccelerators;
|
|
|
|
|
|
|
|
|
|
|
|
error = pcf_read_TOC( stream, face );
|
|
|
|
if ( error )
|
2002-03-21 16:02:54 +01:00
|
|
|
goto Exit;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2015-10-13 18:26:18 +02:00
|
|
|
root->num_faces = 1;
|
|
|
|
root->face_index = 0;
|
|
|
|
|
|
|
|
/* If we are performing a simple font format check, exit immediately. */
|
|
|
|
if ( face_index < 0 )
|
|
|
|
return FT_Err_Ok;
|
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
error = pcf_get_properties( stream, face );
|
|
|
|
if ( error )
|
2002-03-21 16:02:54 +01:00
|
|
|
goto Exit;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
/* Use the old accelerators if no BDF accelerators are in the file. */
|
2002-02-06 12:22:56 +01:00
|
|
|
hasBDFAccelerators = pcf_has_table_type( face->toc.tables,
|
2002-02-08 07:23:50 +01:00
|
|
|
face->toc.count,
|
|
|
|
PCF_BDF_ACCELERATORS );
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( !hasBDFAccelerators )
|
|
|
|
{
|
|
|
|
error = pcf_get_accel( stream, face, PCF_ACCELERATORS );
|
2001-06-27 21:46:12 +02:00
|
|
|
if ( error )
|
2002-03-21 16:02:54 +01:00
|
|
|
goto Exit;
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
/* metrics */
|
|
|
|
error = pcf_get_metrics( stream, face );
|
|
|
|
if ( error )
|
2002-03-21 16:02:54 +01:00
|
|
|
goto Exit;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
/* bitmaps */
|
|
|
|
error = pcf_get_bitmaps( stream, face );
|
|
|
|
if ( error )
|
2002-03-21 16:02:54 +01:00
|
|
|
goto Exit;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
|
|
|
/* encodings */
|
|
|
|
error = pcf_get_encodings( stream, face );
|
|
|
|
if ( error )
|
2002-03-21 16:02:54 +01:00
|
|
|
goto Exit;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
/* BDF style accelerators (i.e. bounds based on encoded glyphs) */
|
|
|
|
if ( hasBDFAccelerators )
|
|
|
|
{
|
|
|
|
error = pcf_get_accel( stream, face, PCF_BDF_ACCELERATORS );
|
|
|
|
if ( error )
|
2002-03-21 16:02:54 +01:00
|
|
|
goto Exit;
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: TO DO: inkmetrics and glyph_names are missing */
|
|
|
|
|
|
|
|
/* now construct the face object */
|
|
|
|
{
|
|
|
|
PCF_Property prop;
|
|
|
|
|
|
|
|
|
2013-12-25 08:50:50 +01:00
|
|
|
root->face_flags |= FT_FACE_FLAG_FIXED_SIZES |
|
2018-06-06 13:23:54 +02:00
|
|
|
FT_FACE_FLAG_HORIZONTAL;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
if ( face->accel.constantWidth )
|
|
|
|
root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
|
|
|
|
|
2016-12-17 20:47:42 +01:00
|
|
|
if ( FT_SET_ERROR( pcf_interpret_style( face ) ) )
|
|
|
|
goto Exit;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2002-02-06 12:22:56 +01:00
|
|
|
prop = pcf_find_property( face, "FAMILY_NAME" );
|
2003-11-13 11:19:27 +01:00
|
|
|
if ( prop && prop->isString )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2017-01-09 11:30:32 +01:00
|
|
|
|
|
|
|
#ifdef PCF_CONFIG_OPTION_LONG_FAMILY_NAMES
|
|
|
|
|
|
|
|
PCF_Driver driver = (PCF_Driver)FT_FACE_DRIVER( face );
|
|
|
|
|
|
|
|
|
|
|
|
if ( !driver->no_long_family_names )
|
2016-09-30 08:11:52 +02:00
|
|
|
{
|
2017-01-09 11:30:32 +01:00
|
|
|
/* Prepend the foundry name plus a space to the family name. */
|
|
|
|
/* There are many fonts just called `Fixed' which look */
|
|
|
|
/* completely different, and which have nothing to do with each */
|
|
|
|
/* other. When selecting `Fixed' in KDE or Gnome one gets */
|
|
|
|
/* results that appear rather random, the style changes often if */
|
|
|
|
/* one changes the size and one cannot select some fonts at all. */
|
|
|
|
/* */
|
|
|
|
/* We also check whether we have `wide' characters; all put */
|
|
|
|
/* together, we get family names like `Sony Fixed' or `Misc */
|
|
|
|
/* Fixed Wide'. */
|
|
|
|
|
|
|
|
PCF_Property foundry_prop, point_size_prop, average_width_prop;
|
|
|
|
|
|
|
|
int l = ft_strlen( prop->value.atom ) + 1;
|
|
|
|
int wide = 0;
|
|
|
|
|
|
|
|
|
|
|
|
foundry_prop = pcf_find_property( face, "FOUNDRY" );
|
|
|
|
point_size_prop = pcf_find_property( face, "POINT_SIZE" );
|
|
|
|
average_width_prop = pcf_find_property( face, "AVERAGE_WIDTH" );
|
|
|
|
|
|
|
|
if ( point_size_prop && average_width_prop )
|
2016-09-30 08:11:52 +02:00
|
|
|
{
|
2017-01-09 11:30:32 +01:00
|
|
|
if ( average_width_prop->value.l >= point_size_prop->value.l )
|
|
|
|
{
|
|
|
|
/* This font is at least square shaped or even wider */
|
|
|
|
wide = 1;
|
|
|
|
l += ft_strlen( " Wide" );
|
|
|
|
}
|
2016-09-30 08:11:52 +02:00
|
|
|
}
|
|
|
|
|
2017-01-09 11:30:32 +01:00
|
|
|
if ( foundry_prop && foundry_prop->isString )
|
|
|
|
{
|
|
|
|
l += ft_strlen( foundry_prop->value.atom ) + 1;
|
2016-09-30 08:11:52 +02:00
|
|
|
|
2017-01-09 11:30:32 +01:00
|
|
|
if ( FT_NEW_ARRAY( root->family_name, l ) )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
ft_strcpy( root->family_name, foundry_prop->value.atom );
|
|
|
|
ft_strcat( root->family_name, " " );
|
|
|
|
ft_strcat( root->family_name, prop->value.atom );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( FT_NEW_ARRAY( root->family_name, l ) )
|
|
|
|
goto Exit;
|
2016-09-30 08:11:52 +02:00
|
|
|
|
2017-01-09 11:30:32 +01:00
|
|
|
ft_strcpy( root->family_name, prop->value.atom );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( wide )
|
|
|
|
ft_strcat( root->family_name, " Wide" );
|
2016-09-30 08:11:52 +02:00
|
|
|
}
|
|
|
|
else
|
2017-01-09 11:30:32 +01:00
|
|
|
|
|
|
|
#endif /* PCF_CONFIG_OPTION_LONG_FAMILY_NAMES */
|
|
|
|
|
2016-09-30 08:11:52 +02:00
|
|
|
{
|
2017-01-09 11:30:32 +01:00
|
|
|
if ( FT_STRDUP( root->family_name, prop->value.atom ) )
|
2016-09-30 08:11:52 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
else
|
2003-11-13 11:19:27 +01:00
|
|
|
root->family_name = NULL;
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2018-07-22 12:49:25 +02:00
|
|
|
root->num_glyphs = (FT_Long)face->nmetrics;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-01-01 18:24:31 +01:00
|
|
|
root->num_fixed_sizes = 1;
|
2002-03-22 14:52:37 +01:00
|
|
|
if ( FT_NEW_ARRAY( root->available_sizes, 1 ) )
|
2002-03-21 16:02:54 +01:00
|
|
|
goto Exit;
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2001-12-23 02:38:53 +01:00
|
|
|
{
|
2003-07-01 09:28:55 +02:00
|
|
|
FT_Bitmap_Size* bsize = root->available_sizes;
|
2004-02-08 17:30:37 +01:00
|
|
|
FT_Short resolution_x = 0, resolution_y = 0;
|
2003-07-01 09:28:55 +02:00
|
|
|
|
|
|
|
|
2016-09-28 19:06:21 +02:00
|
|
|
FT_ZERO( bsize );
|
2003-07-01 09:28:55 +02:00
|
|
|
|
2015-09-19 07:58:03 +02:00
|
|
|
/* for simplicity, we take absolute values of integer properties */
|
|
|
|
|
* include/freetype/freetype.h (FT_Select_Size): Rename the second
argument from `idx' to `strike_index'.
(FT_Size_Request_Type): Add FT_SIZE_REQUEST_TYPE_MAX to the end of
this enum.
* include/freetype/internal/ftobjs.h (FT_REQUEST_WIDTH,
FT_REQUEST_HEIGHT): New macros to get the width and height of a
request, in fractional pixels.
* include/freetype/internal/ftobjs.h (FT_Select_Metrics,
FT_Request_Metrics), src/base/ftobjs.c (FT_Select_Metrics,
FT_Request_Metrics): New base functions to set the font metrics. They
were part of FT_Select_Size/FT_Request_Size and are made independent
functions so that metrics are not set again and again.
* src/base/ftobjs.c (FT_Select_Size, FT_Request_Size): Metrics are set
only when driver's size_select/size_request is NULL. That is, drivers
should set the metrics themselves.
(FT_Match_Size): Round before matching. This was what we did and it
does cause some problems without rounding.
* src/cff/cffobjs.c (cff_size_select), src/truetype/ttdriver.c
(tt_size_select): Set the font metrics.
s/index/strike_index/.
The scaled metrics are always preferred over strikes' metrics, even
when some strike is selected. This is done because the strikes'
metrics are not reliable, e.g., the sign of the descender is wrong for
some fonts.
* src/cff/cffobjs.c (cff_size_request), src/truetype/ttdriver.c
(tt_size_request): Set the font metrics.
Call cff_size_select/tt_size_select when some strike is matched.
* src/bdf/bdfdrivr.c, src/cff/cffobjs.c, src/cid/cidobjs.c,
src/pcf/pcfdrivr.c, src/truetype/ttdriver.c, src/type1/t1objs.c,
src/type1/t1objs.h, src/type42/t42objs.c, src/winfonts/winfnt.c:
Set the font metrics.
s/index/strike_index/.
* src/tools/test_afm.c, src/psaux/psconv.c: Older versions of these
files were committed. Just a catch-up.
(PS_Conv_ToFixed): Remove the `goto'.
(PS_Conv_ASCIIHexDecode, PS_Conv_EexecDecode): Speed up a little.
* src/sfnt/ttsbit.c (tt_face_load_sbit_strikes,
tt_face_load_strike_metrics), src/sfnt/ttsbit0.c
(tt_face_load_sbit_strikes, tt_face_load_strike_metrics): The
advertised metrics in `available_sizes' are different from those
actually used.
2006-01-23 15:12:40 +01:00
|
|
|
#if 0
|
|
|
|
bsize->height = face->accel.maxbounds.ascent << 6;
|
|
|
|
#endif
|
2003-07-01 09:28:55 +02:00
|
|
|
|
2018-08-09 04:17:35 +02:00
|
|
|
#ifdef FT_DEBUG_LEVEL_TRACE
|
|
|
|
if ( face->accel.fontAscent + face->accel.fontDescent < 0 )
|
|
|
|
FT_TRACE0(( "pcf_load_font: negative height\n" ));
|
|
|
|
#endif
|
|
|
|
if ( FT_ABS( face->accel.fontAscent +
|
|
|
|
face->accel.fontDescent ) > 0x7FFF )
|
|
|
|
{
|
|
|
|
bsize->height = 0x7FFF;
|
|
|
|
FT_TRACE0(( "pcf_load_font: clamping height to value %d\n",
|
|
|
|
bsize->height ));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bsize->height = FT_ABS( (FT_Short)( face->accel.fontAscent +
|
|
|
|
face->accel.fontDescent ) );
|
2015-09-17 13:42:59 +02:00
|
|
|
|
2003-07-01 09:28:55 +02:00
|
|
|
prop = pcf_find_property( face, "AVERAGE_WIDTH" );
|
2003-11-13 11:19:27 +01:00
|
|
|
if ( prop )
|
2015-09-17 13:42:59 +02:00
|
|
|
{
|
2018-08-09 04:17:35 +02:00
|
|
|
#ifdef FT_DEBUG_LEVEL_TRACE
|
|
|
|
if ( prop->value.l < 0 )
|
|
|
|
FT_TRACE0(( "pcf_load_font: negative average width\n" ));
|
|
|
|
#endif
|
|
|
|
if ( ( FT_ABS( prop->value.l ) > 0x7FFFL * 10 - 5 ) )
|
2017-05-29 21:04:27 +02:00
|
|
|
{
|
|
|
|
bsize->width = 0x7FFF;
|
2018-08-09 04:17:35 +02:00
|
|
|
FT_TRACE0(( "pcf_load_font: clamping average width to value %d\n",
|
2017-05-29 21:04:27 +02:00
|
|
|
bsize->width ));
|
|
|
|
}
|
|
|
|
else
|
2018-08-09 04:17:35 +02:00
|
|
|
bsize->width = FT_ABS( (FT_Short)( ( prop->value.l + 5 ) / 10 ) );
|
2015-09-17 13:42:59 +02:00
|
|
|
}
|
2004-02-08 17:30:37 +01:00
|
|
|
else
|
2017-05-29 21:04:27 +02:00
|
|
|
{
|
|
|
|
/* this is a heuristical value */
|
2018-08-09 04:17:35 +02:00
|
|
|
bsize->width = (FT_Short)FT_MulDiv( bsize->height, 2, 3 );
|
2017-05-29 21:04:27 +02:00
|
|
|
}
|
2003-07-01 09:28:55 +02:00
|
|
|
|
2002-02-06 12:22:56 +01:00
|
|
|
prop = pcf_find_property( face, "POINT_SIZE" );
|
2003-11-13 11:19:27 +01:00
|
|
|
if ( prop )
|
2015-09-17 13:42:59 +02:00
|
|
|
{
|
2018-08-09 04:17:35 +02:00
|
|
|
#ifdef FT_DEBUG_LEVEL_TRACE
|
|
|
|
if ( prop->value.l < 0 )
|
|
|
|
FT_TRACE0(( "pcf_load_font: negative point size\n" ));
|
|
|
|
#endif
|
2004-02-08 17:30:37 +01:00
|
|
|
/* convert from 722.7 decipoints to 72 points per inch */
|
2018-08-09 04:17:35 +02:00
|
|
|
if ( FT_ABS( prop->value.l ) > 0x504C2L ) /* 0x7FFF * 72270/7200 */
|
2017-05-29 21:04:27 +02:00
|
|
|
{
|
|
|
|
bsize->size = 0x7FFF;
|
|
|
|
FT_TRACE0(( "pcf_load_font: clamping point size to value %d\n",
|
|
|
|
bsize->size ));
|
|
|
|
}
|
|
|
|
else
|
2018-08-09 04:17:35 +02:00
|
|
|
bsize->size = FT_MulDiv( FT_ABS( prop->value.l ),
|
|
|
|
64 * 7200,
|
|
|
|
72270L );
|
2015-09-17 13:42:59 +02:00
|
|
|
}
|
2002-02-06 12:22:56 +01:00
|
|
|
|
2004-02-08 17:30:37 +01:00
|
|
|
prop = pcf_find_property( face, "PIXEL_SIZE" );
|
|
|
|
if ( prop )
|
2015-09-17 13:42:59 +02:00
|
|
|
{
|
2018-08-09 04:17:35 +02:00
|
|
|
#ifdef FT_DEBUG_LEVEL_TRACE
|
|
|
|
if ( prop->value.l < 0 )
|
|
|
|
FT_TRACE0(( "pcf_load_font: negative pixel size\n" ));
|
|
|
|
#endif
|
|
|
|
if ( FT_ABS( prop->value.l ) > 0x7FFF )
|
2017-05-29 21:04:27 +02:00
|
|
|
{
|
2018-08-09 04:17:35 +02:00
|
|
|
bsize->y_ppem = 0x7FFF << 6;
|
2017-05-29 21:04:27 +02:00
|
|
|
FT_TRACE0(( "pcf_load_font: clamping pixel size to value %d\n",
|
|
|
|
bsize->y_ppem ));
|
|
|
|
}
|
|
|
|
else
|
2018-08-09 04:17:35 +02:00
|
|
|
bsize->y_ppem = FT_ABS( (FT_Short)prop->value.l ) << 6;
|
2015-09-17 13:42:59 +02:00
|
|
|
}
|
2004-02-08 17:30:37 +01:00
|
|
|
|
2003-07-01 09:28:55 +02:00
|
|
|
prop = pcf_find_property( face, "RESOLUTION_X" );
|
2003-11-13 11:19:27 +01:00
|
|
|
if ( prop )
|
2015-09-17 13:42:59 +02:00
|
|
|
{
|
2018-08-09 04:17:35 +02:00
|
|
|
#ifdef FT_DEBUG_LEVEL_TRACE
|
|
|
|
if ( prop->value.l < 0 )
|
|
|
|
FT_TRACE0(( "pcf_load_font: negative X resolution\n" ));
|
|
|
|
#endif
|
|
|
|
if ( FT_ABS( prop->value.l ) > 0x7FFF )
|
2017-05-29 21:04:27 +02:00
|
|
|
{
|
|
|
|
resolution_x = 0x7FFF;
|
2018-08-09 04:17:35 +02:00
|
|
|
FT_TRACE0(( "pcf_load_font: clamping X resolution to value %d\n",
|
2017-05-29 21:04:27 +02:00
|
|
|
resolution_x ));
|
|
|
|
}
|
|
|
|
else
|
2018-08-09 04:17:35 +02:00
|
|
|
resolution_x = FT_ABS( (FT_Short)prop->value.l );
|
2015-09-17 13:42:59 +02:00
|
|
|
}
|
2001-01-01 18:24:31 +01:00
|
|
|
|
2003-07-01 09:28:55 +02:00
|
|
|
prop = pcf_find_property( face, "RESOLUTION_Y" );
|
2003-11-13 11:19:27 +01:00
|
|
|
if ( prop )
|
2015-09-17 13:42:59 +02:00
|
|
|
{
|
2018-08-09 04:17:35 +02:00
|
|
|
#ifdef FT_DEBUG_LEVEL_TRACE
|
|
|
|
if ( prop->value.l < 0 )
|
|
|
|
FT_TRACE0(( "pcf_load_font: negative Y resolution\n" ));
|
|
|
|
#endif
|
|
|
|
if ( FT_ABS( prop->value.l ) > 0x7FFF )
|
2017-05-29 21:04:27 +02:00
|
|
|
{
|
|
|
|
resolution_y = 0x7FFF;
|
|
|
|
FT_TRACE0(( "pcf_load_font: clamping Y resolution to value %d\n",
|
|
|
|
resolution_y ));
|
|
|
|
}
|
|
|
|
else
|
2018-08-09 04:17:35 +02:00
|
|
|
resolution_y = FT_ABS( (FT_Short)prop->value.l );
|
2015-09-17 13:42:59 +02:00
|
|
|
}
|
2003-07-01 09:28:55 +02:00
|
|
|
|
2004-02-08 17:30:37 +01:00
|
|
|
if ( bsize->y_ppem == 0 )
|
|
|
|
{
|
|
|
|
bsize->y_ppem = bsize->size;
|
|
|
|
if ( resolution_y )
|
2015-09-17 16:22:40 +02:00
|
|
|
bsize->y_ppem = FT_MulDiv( bsize->y_ppem, resolution_y, 72 );
|
2004-02-08 17:30:37 +01:00
|
|
|
}
|
|
|
|
if ( resolution_x && resolution_y )
|
2015-09-17 16:22:40 +02:00
|
|
|
bsize->x_ppem = FT_MulDiv( bsize->y_ppem,
|
|
|
|
resolution_x,
|
|
|
|
resolution_y );
|
2004-02-08 17:30:37 +01:00
|
|
|
else
|
|
|
|
bsize->x_ppem = bsize->y_ppem;
|
2003-07-01 09:28:55 +02:00
|
|
|
}
|
2001-01-01 18:24:31 +01:00
|
|
|
|
* src/winfonts/winfnt.c (FNT_Load_Glyph): Use first_char in
computation of glyph_index.
(FNT_Size_Set_Pixels): To find a strike, first check pixel_height
only, then try to find a better hit by comparing pixel_width also.
Without this fix it isn't possible to access all strikes.
Also compute metrics.max_advance to be in sync with other bitmap
drivers.
* src/base/ftobjs.c (FT_Set_Char_Size): Remove redundant code.
(FT_Set_Pixel_Size): Assign value to `metrics' after validation of
arguments.
Synchronize computation of height and width for bitmap strikes. The
`width' field in the FT_Bitmap_Size structure is now only useful to
enumerate different strikes. The `max_advance' field of the
FT_Size_Metrics structure should be used to get the (maximum) width
of a strike.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Don't use AVERAGE_WIDTH for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/pcf/pcfread.c (pcf_load_font): Don't use RESOLUTION_X for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/truetype/ttdriver.c (Set_Pixel_Sizes): Pass only single
argument to function.
* src/psnames/psmodule.c (ps_unicode_value): Handle `.' after
`uniXXXX' and `uXXXX[X[X]]'.
* src/bdf/bdfdrivr.c: s/FT_Err_/BDF_Err/.
* src/cache/ftccache.c, src/cache/ftcsbits.c, src/cache/ftlru.c:
s/FT_Err_/FTC_Err_/.
* src/cff/cffcmap.c: s/FT_Err_/CFF_Err_/.
* src/pcf/pcfdrivr.c: s/FT_Err_/PCF_Err_/.
* src/psaux/t1cmap.c: Include psauxerr.h.
s/FT_Err_/PSaux_Err_/.
* src/pshinter/pshnterr.h: New file.
* src/pshinter/rules.mk: Updated.
* src/pshinter/pshalgo.c, src/pshinter/pshrec.c: Include pshnterr.h.
s/FT_Err_/PSH_Err_/.
* src/pfr/pfrdrivr.c, src/pfr/pfrobjs.c, src/pfr/pfrsbit.c:
s/FT_Err_/PFR_Err_/.
* src/sfnt/sfdriver.c, src/sfnt/sfobjs.c, src/sfnt/ttcmap0.c,
src/sfnt/ttload.c: s/FT_Err_/SFNT_Err_/.
* src/truetype/ttgload.c: s/FT_Err_/TT_Err_/.
* src/gzip/ftgzip.c: Load FT_MODULE_ERRORS_H and define
FT_ERR_PREFIX and FT_ERR_BASE.
s/FT_Err_/Gzip_Err_/.
2003-06-22 17:33:53 +02:00
|
|
|
/* set up charset */
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2015-04-12 05:54:19 +02:00
|
|
|
PCF_Property charset_registry, charset_encoding;
|
2002-03-31 08:56:56 +02:00
|
|
|
|
|
|
|
|
2002-02-06 12:22:56 +01:00
|
|
|
charset_registry = pcf_find_property( face, "CHARSET_REGISTRY" );
|
|
|
|
charset_encoding = pcf_find_property( face, "CHARSET_ENCODING" );
|
2002-03-31 08:56:56 +02:00
|
|
|
|
2003-11-13 11:19:27 +01:00
|
|
|
if ( charset_registry && charset_registry->isString &&
|
|
|
|
charset_encoding && charset_encoding->isString )
|
2001-01-01 18:24:31 +01:00
|
|
|
{
|
2007-02-12 22:44:10 +01:00
|
|
|
if ( FT_STRDUP( face->charset_encoding,
|
|
|
|
charset_encoding->value.atom ) ||
|
|
|
|
FT_STRDUP( face->charset_registry,
|
|
|
|
charset_registry->value.atom ) )
|
2003-11-13 11:19:27 +01:00
|
|
|
goto Exit;
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
}
|
2001-06-27 21:46:12 +02:00
|
|
|
}
|
2002-03-31 08:56:56 +02:00
|
|
|
|
2002-03-21 16:02:54 +01:00
|
|
|
Exit:
|
2002-03-31 08:56:56 +02:00
|
|
|
if ( error )
|
2002-03-21 16:02:54 +01:00
|
|
|
{
|
2006-07-08 23:31:24 +02:00
|
|
|
/* This is done to respect the behaviour of the original */
|
2002-03-31 08:56:56 +02:00
|
|
|
/* PCF font driver. */
|
2013-03-14 10:27:35 +01:00
|
|
|
error = FT_THROW( Invalid_File_Format );
|
2002-03-21 16:02:54 +01:00
|
|
|
}
|
2002-03-31 08:56:56 +02:00
|
|
|
|
2002-03-21 16:02:54 +01:00
|
|
|
return error;
|
2001-01-01 18:24:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* END */
|