Search code examples
fontsfile-formatcompact-font-format

Which offsets does the "offSize" field in a CFF font header apply to?


The "Compact Font Format Specification" explains (on page 13) that the offSize field in the header "specifies the size of all offsets (0) relative to the start of CFF data." Various offsets are mentioned in the document, but most (all?) of them either have their own, separate offSize field (e.g. in table 7 on page 12) or they are encoded as dict data operands (e.g. the charset field in the Top DICT, in table 9 on page 15).

Which offsets actually use the offSize field from the header?


Solution

  • I followed the hint from Peter Constable's comment: The FreeType implementation of CFF reads the offSize field, but then just checks the value for validity and does not even store it for later use. From this I assume that this field is just some odd (historical?) artefact, and is not actually used.

    The code in question is in the file src/cff/cffload.c, starting at line 2243. The variable absolute_offset corresponds to offSize in the spec:

    {
      FT_Byte  absolute_offset;
    
    
      if ( FT_READ_BYTE( absolute_offset ) )
        goto Exit;
    
      if ( font->version_major != 1 ||
           font->header_size < 4    ||
           absolute_offset > 4      )
      {
        FT_TRACE2(( "  not a CFF font header\n" ));
        error = FT_THROW( Unknown_File_Format );
        goto Exit;
      }
    }
    

    Update. I just discovered that the offSize field has been removed in version 2 of the CFF format. This is another hint that the field may be unused.