[cid] Improve tracing messages; formatting.

This commit is contained in:
Werner Lemberg 2023-05-06 16:41:13 +02:00
parent 9127c68f59
commit b5e57b041b
3 changed files with 56 additions and 49 deletions

View File

@ -157,6 +157,7 @@ FT_BEGIN_HEADER
* A handle to a function used to select a new fixed size. It is used * A handle to a function used to select a new fixed size. It is used
* only if @FT_FACE_FLAG_FIXED_SIZES is set. Can be set to 0 if the * only if @FT_FACE_FLAG_FIXED_SIZES is set. Can be set to 0 if the
* scaling done in the base layer suffices. * scaling done in the base layer suffices.
*
* @note: * @note:
* Most function pointers, with the exception of `load_glyph`, can be set * Most function pointers, with the exception of `load_glyph`, can be set
* to 0 to indicate a default behaviour. * to 0 to indicate a default behaviour.

View File

@ -41,35 +41,36 @@
/* /*
* A helper function to compute FD number (fd_select), * A helper function to compute FD number (`fd_select`), the offset to the
* the offset to the head of the glyph data (off1), * head of the glyph data (`off1`), and the offset to the and of the glyph
* and the offset to the and of the glyph data (off2). * data (`off2`).
* *
* The number how many times cid_get_offset() is invoked * The number how many times `cid_get_offset` is invoked can be controlled
* can be controlled by the number how many non-NULL * by the number of non-NULL arguments. If `fd_select` is non-NULL but
* arguments are given. If fd_select is non-NULL but * `off1` and `off2` are NULL, `cid_get_offset` is invoked only for
* off1 and off2 are NULL, cid_get_offset() is invoked * `fd_select`; `off1` and `off2` are not validated.
* only for fd_select, off1/off2 are not validated.
* *
*/ */
FT_LOCAL_DEF( FT_Error ) FT_LOCAL_DEF( FT_Error )
cid_compute_fd_and_offsets( CID_Face face, cid_compute_fd_and_offsets( CID_Face face,
FT_UInt glyph_index, FT_UInt glyph_index,
FT_ULong* fd_select_p, FT_ULong* fd_select_p,
FT_ULong* off1_p, FT_ULong* off1_p,
FT_ULong* off2_p ) FT_ULong* off2_p )
{ {
FT_Error error = FT_Err_Ok; FT_Error error = FT_Err_Ok;
CID_FaceInfo cid = &face->cid;
FT_Stream stream = face->cid_stream; CID_FaceInfo cid = &face->cid;
FT_Stream stream = face->cid_stream;
FT_UInt entry_len = cid->fd_bytes + cid->gd_bytes; FT_UInt entry_len = cid->fd_bytes + cid->gd_bytes;
FT_Byte* p;
FT_Bool need_frame_exit = 0; FT_Byte* p;
FT_ULong fd_select, off1, off2; FT_Bool need_frame_exit = 0;
FT_ULong fd_select, off1, off2;
/* For ordinary fonts read the CID font dictionary index */ /* For ordinary fonts, read the CID font dictionary index */
/* and charstring offset from the CIDMap. */ /* and charstring offset from the CIDMap. */
if ( FT_STREAM_SEEK( cid->data_offset + cid->cidmap_offset + if ( FT_STREAM_SEEK( cid->data_offset + cid->cidmap_offset +
glyph_index * entry_len ) || glyph_index * entry_len ) ||
@ -78,20 +79,18 @@
need_frame_exit = 1; need_frame_exit = 1;
p = (FT_Byte*)stream->cursor; p = (FT_Byte*)stream->cursor;
fd_select = cid_get_offset( &p, cid->fd_bytes ); fd_select = cid_get_offset( &p, cid->fd_bytes );
off1 = cid_get_offset( &p, cid->gd_bytes ); off1 = cid_get_offset( &p, cid->gd_bytes );
p += cid->fd_bytes; p += cid->fd_bytes;
off2 = cid_get_offset( &p, cid->gd_bytes ); off2 = cid_get_offset( &p, cid->gd_bytes );
if (fd_select_p) if ( fd_select_p )
*fd_select_p = fd_select; *fd_select_p = fd_select;
if ( off1_p )
if (off1_p)
*off1_p = off1; *off1_p = off1;
if ( off2_p )
if (off2_p)
*off2_p = off2; *off2_p = off2;
if ( fd_select >= cid->num_dicts ) if ( fd_select >= cid->num_dicts )
@ -101,36 +100,46 @@
* has no charstring to be rendered, similar to GID = 0xFFFF * has no charstring to be rendered, similar to GID = 0xFFFF
* in TrueType fonts. * in TrueType fonts.
*/ */
if ( (cid->fd_bytes == 1 && fd_select == 0xFFU ) || if ( ( cid->fd_bytes == 1 && fd_select == 0xFFU ) ||
(cid->fd_bytes == 2 && fd_select == 0xFFFFU ) ) ( cid->fd_bytes == 2 && fd_select == 0xFFFFU ) )
{ {
FT_TRACE1(( "cid_load_glyph: fail for glyph_index=%d, " FT_TRACE1(( "cid_load_glyph: fail for glyph index %d:\n",
"FD number %ld is the max integer fitting into %d byte%s\n", glyph_index ));
glyph_index, fd_select, cid->fd_bytes, FT_TRACE1(( " FD number %ld is the maximum\n",
cid->fd_bytes == 1 ? "" : "s" )); fd_select ));
FT_TRACE1(( " integer fitting into %d byte%s\n",
cid->fd_bytes, cid->fd_bytes == 1 ? "" : "s" ));
} }
else else
{ {
FT_TRACE0(( "cid_load_glyph: fail for glyph_index=%d, " FT_TRACE0(( "cid_load_glyph: fail for glyph index %d:\n",
"FD number %ld > number of dicts %d\n", glyph_index ));
glyph_index, fd_select, cid->num_dicts )); FT_TRACE0(( " FD number %ld is larger\n",
fd_select ));
FT_TRACE0(( " than number of dictionaries (%d)\n",
cid->num_dicts ));
} }
error = FT_THROW( Invalid_Offset ); error = FT_THROW( Invalid_Offset );
goto Exit; goto Exit;
} }
else if ( off2 > stream->size ) else if ( off2 > stream->size )
{ {
FT_TRACE0(( "cid_load_glyph: fail for glyph_index=%d, " FT_TRACE0(( "cid_load_glyph: fail for glyph index %d:\n",
"end of the glyph data is beyond the data stream\n",
glyph_index )); glyph_index ));
FT_TRACE0(( " end of the glyph data\n" ));
FT_TRACE0(( " is beyond the data stream\n" ));
error = FT_THROW( Invalid_Offset ); error = FT_THROW( Invalid_Offset );
goto Exit; goto Exit;
} }
else if ( off1 > off2 ) else if ( off1 > off2 )
{ {
FT_TRACE0(( "cid_load_glyph: fail for glyph_index=%d, " FT_TRACE0(( "cid_load_glyph: fail for glyph index %d:\n",
"the end position of glyph data is set before the start position\n",
glyph_index )); glyph_index ));
FT_TRACE0(( " the end position of glyph data\n" ));
FT_TRACE0(( " is set before the start position\n" ));
error = FT_THROW( Invalid_Offset ); error = FT_THROW( Invalid_Offset );
} }

View File

@ -153,16 +153,13 @@
/* /*
* Currently, FreeType does not support an incrementally- * Currently, FreeType does not support incrementally-defined, CID-keyed
* defined CID-keyed font that stores the glyph description * fonts that store the glyph description data in a `/GlyphDirectory`
* data in /GlyphDirectory array or dictionary. * array or dictionary. Fonts loaded by the incremental loading feature
* Thus the font loaded by the incremental loading feature * are thus not handled here.
* is not handled in here.
*/ */
error = cid_compute_fd_and_offsets( face, glyph_index, error = cid_compute_fd_and_offsets( face, glyph_index,
NULL, NULL, NULL ); NULL, NULL, NULL );
if ( error ) if ( error )
*cid = 0; *cid = 0;
else else