[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master c7dd4d0 1/7: [ftdump] Print CID-keyed font prop
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] master c7dd4d0 1/7: [ftdump] Print CID-keyed font properties if available. |
Date: |
Fri, 5 May 2023 12:47:58 -0400 (EDT) |
branch: master
commit c7dd4d0c7ce7f5f2a15fc2e4239b69d4492ac3b2
Author: suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
Commit: suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
[ftdump] Print CID-keyed font properties if available.
* src/ftdump.c
(load_glyph): New boolean flag to switch
Print_CID_Loadable() or Print_CID_Implemented().
(FT_CID_MAX): New macro.
(Print_UInt_Range): New function to print 2 numbers
with a separator if needed.
(Print_CID_Implemented): New function to print the
implemented CIDs in a compressed syntax. If a case
`gid_N < gid_M && CID_N > CID_M' is found, ftdump
aborts and guide the user to file the issue.
(Print_CIDs): New function to print the CIDs. If
the font is in t1cid driver, only max CID is cared.
For other drivers, Print_CID_Implemented() is used.
(Print_ROS_From_Face): New function to print the
Registry, Ordering, and Supplement of the CID-keyed
fonts, if available. Also Print_CIDs() is invoked.
(main): Invoke Print_ROS_From_Face().
---
src/ftdump.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 136 insertions(+)
diff --git a/src/ftdump.c b/src/ftdump.c
index 2361289..13e3a83 100644
--- a/src/ftdump.c
+++ b/src/ftdump.c
@@ -24,6 +24,7 @@
#include <freetype/tttags.h>
#include <freetype/t1tables.h>
+#include <freetype/ftcid.h>
/* error messages */
#undef FTERRORS_H_
@@ -480,6 +481,139 @@
}
+ /*
+ * FreeType 2 API supports 32-bit gid, but
+ * the CIDFont does not support 32-bit CID,
+ * because of the 64k limit of the array
+ * and dictionary objects in PostScript.
+ */
+#ifndef FT_CID_MAX
+#define FT_CID_MAX 0xFFFFU
+#endif
+ /*
+ * Print a range specified by 2 integers.
+ */
+ static void
+ Print_UInt_Range( FT_UInt from,
+ FT_UInt to,
+ char* is_first )
+ {
+ if (!(*is_first))
+ printf(",");
+
+ if ( from == to )
+ printf( "%d", from );
+ else if ( from < to )
+ printf( "%d-%d", from, to );
+
+ *is_first = 0;
+ }
+
+
+ /*
+ * Print implemented CIDs by calling
+ * FT_Get_CID_From_Glyph_Index() for all GIDs.
+ *
+ */
+ static void
+ Print_CID_Implemented( FT_Face face )
+ {
+ FT_UInt gid = 0, max_gid = FT_UINT_MAX;
+ FT_UInt cid = 0, rng_from = 0, rng_to = 0;
+ char is_first_rng = 1;
+
+
+ if ( (FT_ULong)face->num_glyphs < FT_UINT_MAX )
+ max_gid = (FT_UInt)face->num_glyphs;
+
+ for ( gid = 0; gid <= max_gid; gid ++ )
+ {
+ if ( FT_Get_CID_From_Glyph_Index( face, gid, &cid ) )
+ continue;
+
+ if ( FT_CID_MAX < cid )
+ {
+ fprintf( stderr, "gid=%d resulted too large CID=%d, ignore it\n", gid,
cid );
+ break;
+ }
+
+ if ( rng_to == cid )
+ continue;
+ else if ( cid < rng_to )
+ {
+ fprintf( stderr, "Unordered GID-CID map is found, please file your
issue on "
+
"https://gitlab.freedesktop.org/groups/freetype/-/issues\n" );
+ exit( 1 );
+ }
+ else if ( rng_to + 1 == cid )
+ {
+ rng_to = cid;
+ continue;
+ }
+
+ /* Found a gap (rng_to + 1 < cid), print the last range */
+ Print_UInt_Range( rng_from, rng_to, &is_first_rng );
+ rng_to = rng_from = cid;
+ }
+
+ Print_UInt_Range( rng_from, rng_to, &is_first_rng );
+
+ printf("\n");
+ }
+
+
+ /*
+ * Print implemented CIDs in a compressed format.
+ */
+ static void
+ Print_CIDs( FT_Face face )
+ {
+ if ( face->num_glyphs < 0 )
+ return;
+
+ printf("\n");
+ printf("%s\n", Name_Field( "Implemented CIDs" ) );
+ printf(" ");
+
+ Print_CID_Implemented( face );
+ }
+
+
+ /*
+ * Print_CIDFontInfo_Dictionary() might be conventional,
+ * but other tables, like gcid, can have ROS info too.
+ */
+ static void
+ Print_ROS_From_Face( FT_Face face )
+ {
+ const FT_String* module_name = FT_FACE_DRIVER_NAME( face );
+ const char* r = NULL;
+ const char* o = NULL;
+ FT_Int s = -1;
+
+
+ if ( FT_Get_CID_Registry_Ordering_Supplement( face, &r, &o, &s ) )
+ return;
+
+ printf( "\n" );
+ if ( !ft_strcmp( module_name, "cff" ) ||
+ !ft_strcmp( module_name, "t1cid") )
+ printf( "/CIDSystemInfo dictionary\n" );
+ else /* some fonts can have a ROS info out of /CIDSysteInfo dict */
+ printf( "CID info\n" );
+
+ if ( r )
+ printf("%s%s\n", Name_Field( "Registry" ), r );
+
+ if ( o )
+ printf("%s%s\n", Name_Field( "Ordering" ), o );
+
+ printf("%s%d\n", Name_Field( "Supplement" ), s );
+
+ Print_CIDs( face );
+ }
+
+
static void
Print_FontPrivate_Dictionary( PS_Private fp )
{
@@ -1350,6 +1484,8 @@
Print_Charmaps( face );
}
+ Print_ROS_From_Face( face );
+
if ( FT_HAS_MULTIPLE_MASTERS( face ) )
{
printf( "\n" );
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master c7dd4d0 1/7: [ftdump] Print CID-keyed font properties if available.,
Werner Lemberg <=