src/otlayout/otlgsub.c, src/otlayout/otlgsub.h, src/otlayout/otlparse.c, src/otlayout/otlparse.h, src/otlayout/otlutils.h: updating the OpenType Layout code, adding support fot the first GSUB lookups. Nothing that really compiles for now though * src/autohint/ahhint.c: disabled serif stem width quantization. It produces slightly better shapes though this is not distinguishable with many fonts.BRANCH-2-1-5
parent
6c99355440
commit
100317c335
8 changed files with 554 additions and 4 deletions
@ -0,0 +1,142 @@ |
||||
#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_Parse_Err_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->num_glyphs ) |
||||
otl_parser_error( parser, OTL_Err_Parser_Internal ); |
||||
|
||||
return in->str[ in->cursor ].gindex; |
||||
} |
||||
|
||||
|
||||
OTL_LOCALDEF( void ) |
||||
otl_parser_error( OTL_Parser parser, |
||||
OTL_ParseError error; ) |
||||
{ |
||||
parser->error = error; |
||||
otl_longjmp( parser->jump_buffer, 1 ); |
||||
} |
||||
|
||||
#define OTL_PARSER_UNCOVERED(x) otl_parser_error( x, OTL_Parse_Err_UncoveredGlyph ); |
||||
|
||||
OTL_LOCAL( void ) |
||||
otl_parser_check_property( OTL_Parser parser, |
||||
OTL_UInt gindex, |
||||
OTL_UInt flags, |
||||
OTL_UInt *aproperty ); |
||||
|
||||
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 == NULL || |
||||
out == NULL || |
||||
in->length == 0 || |
||||
in->cursor >= in->length ) |
||||
{ |
||||
/* report as internal error, since these should */ |
||||
/* never happen !! */ |
||||
otl_parser_error( parser, OTL_Err_Parse_Internal ); |
||||
} |
||||
|
||||
OTL_STRING_ENSURE( out, 1, parser ); |
||||
glyph = out->glyphs + out->length; |
||||
in_glyph = in->glyphs + in->cursor; |
||||
|
||||
glyph->gindex = gindex; |
||||
glyph->property = in_glyph->property; |
||||
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, property; |
||||
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 == NULL || |
||||
out == NULL || |
||||
in->length == 0 || |
||||
in->cursor >= in->length ) |
||||
{ |
||||
/* report as internal error, since these should */ |
||||
/* never happen !! */ |
||||
otl_parser_error( parser, OTL_Err_Parse_Internal ); |
||||
} |
||||
|
||||
OTL_STRING_ENSURE( out, count, parser ); |
||||
glyph = out->glyphs + out->length; |
||||
in_glyph = in->glyphs + in->cursor; |
||||
|
||||
glyph->gindex = gindex; |
||||
|
||||
lig_component = in_glyph->lig_component; |
||||
lig_id = in_glyph->lid_id; |
||||
property = in_glyph->property; |
||||
|
||||
for ( ; count > 0; count-- ) |
||||
{ |
||||
glyph->gindex = OTL_NEXT_USHORT(p); |
||||
glyph->property = property; |
||||
glyph->lig_component = lig_component; |
||||
glyph->lig_id = lig_id; |
||||
|
||||
out->length ++; |
||||
} |
||||
|
||||
out->cursor = out->length; |
||||
in->cursor += 1; |
||||
} |
||||
|
||||
|
||||
|
@ -0,0 +1,99 @@ |
||||
#ifndef __OTL_PARSER_H__ |
||||
#define __OTL_PARSER_H__ |
||||
|
||||
#include "otlayout.h" |
||||
#include "otlgdef.h" |
||||
#include "otlgsub.h" |
||||
#include "otlgpos.h" |
||||
|
||||
OTL_BEGIN_HEADER |
||||
|
||||
typedef struct OTL_ParserRec_* OTL_Parser; |
||||
|
||||
typedef struct OTL_StringRec_* OTL_String; |
||||
|
||||
typedef struct OTL_StringGlyphRec_ |
||||
{ |
||||
OTL_UInt gindex; |
||||
OTL_UInt properties; |
||||
OTL_UInt lig_component; |
||||
OTL_UInt lig_id; |
||||
|
||||
} OTL_StringGlyphRec, *OTL_StringGlyph; |
||||
|
||||
typedef struct OTL_StringRec_ |
||||
{ |
||||
OTL_StringGlyph glyphs; |
||||
OTL_UInt cursor; |
||||
OTL_UInt length; |
||||
OTL_UInt capacity; |
||||
|
||||
} OTL_StringRec; |
||||
|
||||
typedef struct OTL_ParserRec_ |
||||
{ |
||||
OTL_Bytes tab_gdef; |
||||
OTL_Bytes tab_gsub; |
||||
OTL_Bytes tab_gpos; |
||||
OTL_Bytes tab_base; |
||||
OTL_Bytes tab_jstf; |
||||
|
||||
OTL_Alternate alternate; /* external alternate handler */ |
||||
|
||||
OTL_UInt context_len; |
||||
OTL_UInt markup_flags; |
||||
|
||||
OTL_jmp_buf jump_buffer; |
||||
OTL_Memory memory; |
||||
OTL_Error error; |
||||
|
||||
OTL_StringRec strings[2]; |
||||
OTL_String str_in; |
||||
OTL_String str_out; |
||||
|
||||
} OTL_ParserRec; |
||||
|
||||
typedef enum |
||||
{ |
||||
OTL_Err_Parser_Ok = 0, |
||||
OTL_Err_Parser_InvalidData, |
||||
OTL_Err_Parser_UncoveredGlyph |
||||
|
||||
} OTL_ParseError; |
||||
|
||||
OTL_LOCAL( OTL_UInt ) |
||||
otl_parser_get_gindex( OTL_Parser parser ); |
||||
|
||||
|
||||
OTL_LOCAL( void ) |
||||
otl_parser_error( OTL_Parser parser, OTL_ParserError error ); |
||||
|
||||
#define OTL_PARSER_UNCOVERED(x) \ |
||||
otl_parser_error( x, OTL_Err_Parser_UncoveredGlyph ) |
||||
|
||||
OTL_LOCAL( void ) |
||||
otl_parser_check_property( OTL_Parser parser, |
||||
OTL_UInt gindex, |
||||
OTL_UInt flags, |
||||
OTL_UInt *aproperty ); |
||||
|
||||
/* copy current input glyph to output */ |
||||
OTL_LOCAL( void ) |
||||
otl_parser_copy_1( OTL_Parser parser ); |
||||
|
||||
/* copy current input glyph to output, replacing its index */ |
||||
OTL_LOCAL( void ) |
||||
otl_parser_replace_1( OTL_Parser parser, |
||||
OTL_UInt gindex ); |
||||
|
||||
/* copy current input glyph to output, replacing it by several indices */ |
||||
/* read directly from the table */ |
||||
OTL_LOCAL( void ) |
||||
otl_parser_replace_n( OTL_Parser parser, |
||||
OTL_UInt count, |
||||
OTL_Bytes indices ); |
||||
|
||||
OTL_END_HEADER |
||||
|
||||
#endif /* __OTL_PARSER_H__ */ |
||||
|
@ -0,0 +1,33 @@ |
||||
#ifndef __OTLAYOUT_UTILS_H__ |
||||
#define __OTLAYOUT_UTILS_H__ |
||||
|
||||
#include "otlayout.h" |
||||
|
||||
OTL_BEGIN_HEADER |
||||
|
||||
OTL_LOCAL( OTL_Error ) |
||||
otl_mem_alloc( OTL_Pointer* pblock, |
||||
OTL_ULong size, |
||||
OTL_Memory memory ); |
||||
|
||||
OTL_LOCAL( void ) |
||||
otl_mem_free( OTL_Pointer* pblock, |
||||
OTL_Memory memory ); |
||||
|
||||
OTL_LOCAL( OTL_Error ) |
||||
otl_mem_realloc( OTL_Pointer *pblock, |
||||
OTL_ULong cur_size, |
||||
OTL_ULong new_size, |
||||
OTL_Memory memory ); |
||||
|
||||
#define OTL_MEM_ALLOC(p,s) otl_mem_alloc( (void**)&(p), (s), memory ) |
||||
#define OTL_MEM_FREE(p) otl_mem_free( (void**)&(p), memory ) |
||||
#define OTL_MEM_REALLOC(p,c,n) otl_mem_realloc( (void**)&(p), (c), (s), memory ) |
||||
|
||||
#define OTL_MEM_NEW(p) OTL_MEM_ALLOC(p,sizeof(*(p))) |
||||
#define OTL_MEM_NEW_ARRAY(p,c) OTL_MEM_ALLOC(p,(c)*sizeof(*(p))) |
||||
#define OTL_MEM_RENEW_ARRAY(p,c,n) OTL_MEM_REALLOC(p,(c)*sizeof(*(p)),(n)*sizeof(*(p))) |
||||
|
||||
OTL_END_HEADER |
||||
|
||||
#endif /* __OTLAYOUT_UTILS_H__ */ |
Loading…
Reference in new issue