freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft-devel] Dynalab SJIS cmap


From: mpsuzuki
Subject: Re: [ft-devel] Dynalab SJIS cmap
Date: Tue, 8 Jan 2008 15:20:28 +0900

Hi,

On Wed, 02 Jan 2008 11:15:10 +0100 (CET)
Werner LEMBERG <address@hidden> wrote:
>> >Hmm.  If so many fonts are broken, it's probably worth to add a
>> >hack to FreeType's cmap support so that they can be successfully
>> >handled.  What do you think?  Can you investigate?
>> 
>> Yes, of course. Now I'm investigating the problem.
>
>Thanks.

Just I've found the scenario how FreeType2 recognizes
Dynalab cmap format2 subtable (used as SJIS cmap).
Here is brief report.

In cmap format2 subtable of (some) Dynalab fonts, there
is an empty sub-header (usually the second sub-header)
whose code_count == 0 && first_code == 0 && delta == 0,
but its offset != 0. I guess, Dynalab expected that
if code_count is zero, TrueType interpreter does not
case other contents in sub-header. But,
freetype2/src/sfnt/ttcmap.c:tt_cmap2_validate()
prioritizes the offset, than code_count. Aslike:


  FT_CALLBACK_DEF( FT_Error )
  tt_cmap2_validate( FT_Byte*      table,
                     FT_Validator  valid )
  {

    ...

    /* parse sub-headers */
    for ( n = 0; n <= max_subs; n++ )
    {    

      ...

      first_code = TT_NEXT_USHORT( p );
      code_count = TT_NEXT_USHORT( p );
      delta      = TT_NEXT_SHORT( p );
      offset     = TT_NEXT_USHORT( p );

      ...

      /* check offset */
      if ( offset != 0 )
      {
        ids = p - 2 + offset;
        if ( ids < glyph_ids || ids + code_count*2 > table + length )
          FT_INVALID_OFFSET;


If offset != 0, it tries to validate the value of offset
is correct. Other 3 parameters (code_count, first_code,
delta) are set to zero, so the validation finds the
inconsistency between offset and other parameters, so
an error is returned.

If we interrupt and skip the validation for the sub-header
whose code_count is zero, FreeType2 can escape the error.
The patch is simple:

Index: src/sfnt/ttcmap.c
===================================================================
RCS file: /cvsroot/freetype/freetype2/src/sfnt/ttcmap.c,v
retrieving revision 1.75
diff -u -r1.75 ttcmap.c
--- src/sfnt/ttcmap.c   20 Oct 2007 16:15:07 -0000      1.75
+++ src/sfnt/ttcmap.c   8 Jan 2008 06:16:05 -0000
@@ -328,6 +328,10 @@
       delta      = TT_NEXT_SHORT( p );
       offset     = TT_NEXT_USHORT( p );
 
+      /* many Dynalab fonts have empty sub-header */
+      if ( 0 == code_count )
+        continue;
+
       /* check range within 0..255 */
       if ( valid->level >= FT_VALIDATE_PARANOID )
       {

Yet I've not checked SJIS cmap obtained by this patch is 
correct, I will continue the investigation. And I have to
consider such sub-header including broken value (I think,
if code_count is zero, offset must be zero either. So
paranoid validator should return an error).

Regards,
mpsuzuki


By the way, at present, Dynalab fonts for MacOS has Apple
SJIS cmap but lacks Microsoft SJIS cmap (thus, ftview cannot
specify Apple SJIS cmap by "-e" option). Does anybody wants
FT_Encoding tag to specify Apple SJIS?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]