1 #include "otlparse.h" 2 #include "otlutils.h" 3 4 static void 5 otl_string_ensure( OTL_String string, 6 OTL_UInt count, 7 OTL_Parser parser ) 8 { 9 count += string->length; 10 11 if ( count > string->capacity ) 12 { 13 OTL_UInt old_count = string->capacity; 14 OTL_UInt new_count = old_count; 15 OTL_Memory memory = parser->memory; 16 17 while ( new_count < count ) 18 new_count += (new_count >> 1) + 16; 19 20 if ( OTL_MEM_RENEW_ARRAY( string->glyphs, old_count, new_count ) ) 21 otl_parser_error( parser, OTL_Parse_Err_Memory ); 22 23 string->capacity = new_count; 24 } 25 } 26 27 #define OTL_STRING_ENSURE(str,count,parser) \ 28 OTL_BEGIN_STMNT \ 29 if ( (str)->length + (count) > (str)>capacity ) \ 30 otl_string_ensure( str, count, parser ); \ 31 OTL_END_STMNT 32 33 34 OTL_LOCALDEF( OTL_UInt ) 35 otl_parser_get_gindex( OTL_Parser parser ) 36 { 37 OTL_String in = parser->str_in; 38 39 if ( in->cursor >= in->num_glyphs ) 40 otl_parser_error( parser, OTL_Err_Parser_Internal ); 41 42 return in->str[ in->cursor ].gindex; 43 } 44 45 46 OTL_LOCALDEF( void ) 47 otl_parser_error( OTL_Parser parser, 48 OTL_ParseError error; ) 49 { 50 parser->error = error; 51 otl_longjmp( parser->jump_buffer, 1 ); 52 } 53 54 #define OTL_PARSER_UNCOVERED(x) otl_parser_error( x, OTL_Parse_Err_UncoveredGlyph ); 55 56 OTL_LOCAL( void ) 57 otl_parser_check_property( OTL_Parser parser, 58 OTL_UInt gindex, 59 OTL_UInt flags, 60 OTL_UInt *aproperty ); 61 62 OTL_LOCALDEF( void ) 63 otl_parser_replace_1( OTL_Parser parser, 64 OTL_UInt gindex ) 65 { 66 OTL_String in = parser->str_in; 67 OTL_String out = parser->str_out; 68 OTL_StringGlyph glyph, in_glyph; 69 70 /* sanity check */ 71 if ( in == NULL || 72 out == NULL || 73 in->length == 0 || 74 in->cursor >= in->length ) 75 { 76 /* report as internal error, since these should */ 77 /* never happen !! */ 78 otl_parser_error( parser, OTL_Err_Parse_Internal ); 79 } 80 81 OTL_STRING_ENSURE( out, 1, parser ); 82 glyph = out->glyphs + out->length; 83 in_glyph = in->glyphs + in->cursor; 84 85 glyph->gindex = gindex; 86 glyph->property = in_glyph->property; 87 glyph->lig_component = in_glyph->lig_component; 88 glyph->lig_id = in_glyph->lig_id; 89 90 out->length += 1; 91 out->cursor = out->length; 92 in->cursor += 1; 93 } 94 95 OTL_LOCALDEF( void ) 96 otl_parser_replace_n( OTL_Parser parser, 97 OTL_UInt count, 98 OTL_Bytes indices ) 99 { 100 OTL_UInt lig_component, lig_id, property; 101 OTL_String in = parser->str_in; 102 OTL_String out = parser->str_out; 103 OTL_StringGlyph glyph, in_glyph; 104 OTL_Bytes p = indices; 105 106 /* sanity check */ 107 if ( in == NULL || 108 out == NULL || 109 in->length == 0 || 110 in->cursor >= in->length ) 111 { 112 /* report as internal error, since these should */ 113 /* never happen !! */ 114 otl_parser_error( parser, OTL_Err_Parse_Internal ); 115 } 116 117 OTL_STRING_ENSURE( out, count, parser ); 118 glyph = out->glyphs + out->length; 119 in_glyph = in->glyphs + in->cursor; 120 121 glyph->gindex = gindex; 122 123 lig_component = in_glyph->lig_component; 124 lig_id = in_glyph->lid_id; 125 property = in_glyph->property; 126 127 for ( ; count > 0; count-- ) 128 { 129 glyph->gindex = OTL_NEXT_USHORT(p); 130 glyph->property = property; 131 glyph->lig_component = lig_component; 132 glyph->lig_id = lig_id; 133 134 out->length ++; 135 } 136 137 out->cursor = out->length; 138 in->cursor += 1; 139 } 140 141 142 143