Edit

kc3-lang/freetype/src/otlayout/otlparse.c

Branch :

  • Browse

    Commit

  • Author : Werner Lemberg
    Date : 2004-08-12 23:50:37
    Hash : 1ac8f434
    Message : * src/otlayout/otcommn.c: Use OTL_CHECK everywhere. (otl_coverage_validate): Initialize `p', s/count/num_glyphs/. s/start_cover/start_coverage/. (otl_coverage_get_index): Return OTL_Long, not OTL_Int. Remove unused variables. (otl_class_definition_validate): s/count/num_glyphs/. Remove unused variables. (otl_class_definition_get_value, otl_device_table_get_start, otl_device_table_get_end, otl_device_table_get_delta, otl_lookup_get_table, otl_lookup_list_get_count, otl_lookup_list_get_lookup, otl_lookup_list_get_table, otl_feature_get_lookups, otl_feature_list_get_count, otl_feature_list_get_feature, otl_lang_get_count, otl_lang_get_req_feature, otl_lang_get_features): Commented out temporarily until we really need it. (otl_lookup_validate): Removed. (otl_lookup_table_validate): Renamed to ... (otl_lookup_validate): This. Update callers. (otl_lookup_list_validate): Remove already commented out definition and move the other definition up. (otl_feature_validate): Add parameter to pass number of lookups. Update callers. Check lookup indices. (otl_feature_list_validate): Add parameter to pass lookup table. Update callers. (otl_lang_validate): Add parameter to pass number of features. Update callers. Handle req_feature and check feature indices. (otl_script_validate): Add parameter to pass number of features. Update callers. (otl_script_list_validate): Add parameter to pass feature table. Update callers. * src/otlayout/otcommn.h: s/LOCALDEF/LOCAL/. Comment out the same functions as in otcommn.c. (otl_script_list_get_script): Removed. * src/otlayout/otlgsub.c (otl_gsub_lookup1_apply): Change `index' to type OTL_Long. (otl_gsub_lookup2_apply, otl_gsub_lookup3_apply): Change `index' to type OTL_Long. Fix test. (otl_gsub_validate): Fix order of validation. * src/otlayout/otlgpos.c (otl_gpos_validate): Fix order of validation.

  • src/otlayout/otlparse.c
  • #include "otlparse.h"
    #include "otlutils.h"
    
    
      static void
      otl_string_ensure( OTL_String  string,
                         OTL_UInt    count,
                         OTL_Parser  parser )
      {
        count += string->length;
    
        if ( count > string->capacity )
        {
          OTL_UInt    old_count = string->capacity;
          OTL_UInt    new_count = old_count;
          OTL_Memory  memory    = parser->memory;
    
          while ( new_count < count )
            new_count += (new_count >> 1) + 16;
    
          if ( OTL_MEM_RENEW_ARRAY( string->glyphs, old_count, new_count ) )
            otl_parser_error( parser, OTL_Err_Parser_Memory );
    
          string->capacity = new_count;
        }
      }
    
    
    #define  OTL_STRING_ENSURE(str,count,parser)                   \
               OTL_BEGIN_STMNT                                     \
                 if ( (str)->length + (count) > (str)->capacity )  \
                   otl_string_ensure( str, count, parser );        \
               OTL_END_STMNT
    
    
      OTL_LOCALDEF( OTL_UInt )
      otl_parser_get_gindex( OTL_Parser  parser )
      {
        OTL_String  in = parser->str_in;
    
        if ( in->cursor >= in->length )
          otl_parser_error( parser, OTL_Err_Parser_Internal );
    
        return in->glyphs[ in->cursor ].gindex;
      }
    
    
      OTL_LOCALDEF( void )
      otl_parser_error( OTL_Parser      parser,
                        OTL_ParseError  error )
      {
        parser->error = error;
        otl_longjmp( parser->jump_buffer, 1 );
      }
    
    
      OTL_LOCALDEF( void )
      otl_parser_check_property( OTL_Parser  parser,
                                 OTL_UInt    gindex,
                                 OTL_UInt   *aproperty )
      {
        /* XXX: to do */
      }
    
    
      OTL_LOCALDEF( void )
      otl_parser_replace_1( OTL_Parser  parser,
                            OTL_UInt    gindex )
      {
        OTL_String       in  = parser->str_in;
        OTL_String       out = parser->str_out;
        OTL_StringGlyph  glyph, in_glyph;
    
        /* sanity check */
        if ( in == 0                  ||
             out == 0                 ||
             in->length == 0          ||
             in->cursor >= in->length )
        {
          /* report as internal error, since these should */
          /* never happen !!                              */
          otl_parser_error( parser, OTL_Err_Parser_Internal );
        }
    
        OTL_STRING_ENSURE( out, 1, parser );
        glyph    = out->glyphs + out->length;
        in_glyph = in->glyphs  + in->cursor;
    
        glyph->gindex        = gindex;
        glyph->properties    = in_glyph->properties;
        glyph->lig_component = in_glyph->lig_component;
        glyph->lig_id        = in_glyph->lig_id;
    
        out->length += 1;
        out->cursor  = out->length;
        in->cursor  += 1;
      }
    
    
      OTL_LOCALDEF( void )
      otl_parser_replace_n( OTL_Parser  parser,
                            OTL_UInt    count,
                            OTL_Bytes   indices )
      {
        OTL_UInt         lig_component, lig_id, properties;
        OTL_String       in  = parser->str_in;
        OTL_String       out = parser->str_out;
        OTL_StringGlyph  glyph, in_glyph;
        OTL_Bytes        p = indices;
    
        /* sanity check */
        if ( in == 0                  ||
             out == 0                 ||
             in->length == 0          ||
             in->cursor >= in->length )
        {
          /* report as internal error, since these should */
          /* never happen !!                              */
          otl_parser_error( parser, OTL_Err_Parser_Internal );
        }
    
        OTL_STRING_ENSURE( out, count, parser );
        glyph    = out->glyphs + out->length;
        in_glyph = in->glyphs  + in->cursor;
    
        glyph->gindex = in_glyph->gindex;
    
        lig_component = in_glyph->lig_component;
        lig_id        = in_glyph->lig_id;
        properties    = in_glyph->properties;
    
        for ( ; count > 0; count-- )
        {
          glyph->gindex        = OTL_NEXT_USHORT(p);
          glyph->properties    = properties;
          glyph->lig_component = lig_component;
          glyph->lig_id        = lig_id;
    
          out->length ++;
        }
    
        out->cursor  = out->length;
        in->cursor  += 1;
      }