Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions array.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ before you include this file in *one* C/C++ file to create the implementation.
#define array_create( type ) ARRAY_CAST( (void*)internal_array_create( sizeof( type ), NULL ) )
#define array_create_memctx( type, memctx ) ARRAY_CAST( (void*)internal_array_create( sizeof( type ), (memctx) ) )
#define array_destroy( array ) internal_array_destroy( (struct internal_array_t*) (array) )
#define array_clear( array ) internal_array_clear( (struct internal_array_t*) (array) )
#define array_add( array, item ) ARRAY_CAST( internal_array_add( (struct internal_array_t*) (array), (void*) (item), (int)sizeof( *item ) ) )
#define array_remove( array, index ) internal_array_remove( (struct internal_array_t*) (array), (index) )
#define array_remove_ordered( array, index ) internal_array_remove_ordered( (struct internal_array_t*) (array), (index) )
Expand Down Expand Up @@ -71,6 +72,7 @@ struct internal_array_t;

struct internal_array_t* internal_array_create( int item_size, void* memctx );
void internal_array_destroy( struct internal_array_t* array );
void internal_array_clear( struct internal_array_t* array );
void* internal_array_add( struct internal_array_t* array, void* item, int item_size );
void internal_array_remove( struct internal_array_t* array, int index );
void internal_array_remove_ordered( struct internal_array_t* array, int index );
Expand Down Expand Up @@ -171,6 +173,11 @@ void internal_array_destroy( struct internal_array_t* array ) {
}


void internal_array_clear( struct internal_array_t* array ) {
array->count = 0;
}


void* internal_array_add( struct internal_array_t* array, void* item, int item_size ) {
ARRAY_ASSERT( item_size == array->item_size, "Invalid item" );
if( array->count >= array->capacity ) {
Expand Down
27 changes: 17 additions & 10 deletions pixelfont.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ before include the file to create the implementation.
#define PIXELFONT_U8 unsigned char
#endif

#ifndef PIXELFONT_U16
#define PIXELFONT_U16 unsigned short
#endif

#ifndef PIXELFONT_U32
#define PIXELFONT_U32 unsigned int
#endif
Expand Down Expand Up @@ -83,7 +87,7 @@ typedef struct pixelfont_builder_t pixelfont_builder_t;
pixelfont_builder_t* pixelfont_builder_create( int height, int baseline, int line_spacing, void* memctx );
void pixelfont_builder_destroy( pixelfont_builder_t* builder );

void pixelfont_builder_glyph( pixelfont_builder_t* builder, int glyph, int pixels_stride, PIXELFONT_U8* pixels, int width, int lead, int trail );
void pixelfont_builder_glyph( pixelfont_builder_t* builder, int glyph, int width, PIXELFONT_U8* pixels, int lead, int trail );
void pixelfont_builder_kerning( pixelfont_builder_t* builder, int glyph, int follower, int adjust );

pixelfont_t* pixelfont_builder_font( pixelfont_builder_t* builder );
Expand Down Expand Up @@ -142,12 +146,12 @@ void PIXELFONT_FUNC_NAME( pixelfont_t const* font, int x, int y, char const* tex
char const* tstr = str;
while( *tstr != '\n' && *tstr != '\0' && ( wrap_width <= 0 || line_width <= wrap_width ) )
{
if( *tstr <= ' ' )
if( *tstr <= ' ' || ( tstr > str && tstr[-1] == '-' ) )
{
last_space_char_count = line_char_count;
last_space_width = line_width;
}
PIXELFONT_U8 const* g = font->glyphs + font->offsets[ (int) *tstr ];
PIXELFONT_U8 const* g = font->glyphs + font->offsets[ (uint8_t)( *tstr ) ];
line_width += (PIXELFONT_I8) *g++;
int w = *g++;
g += font->height * w;
Expand Down Expand Up @@ -181,7 +185,7 @@ void PIXELFONT_FUNC_NAME( pixelfont_t const* font, int x, int y, char const* tex

for( int c = 0; c < line_char_count; ++c )
{
PIXELFONT_U8 const* g = font->glyphs + font->offsets[ (int) *str ];
PIXELFONT_U8 const* g = font->glyphs + font->offsets[ (uint8_t)( *str ) ];
x += (PIXELFONT_I8) *g++;
int w = *g++;
int h = font->height;
Expand Down Expand Up @@ -221,7 +225,11 @@ void PIXELFONT_FUNC_NAME( pixelfont_t const* font, int x, int y, char const* tex
last_x_on_line = xp;
max_x = x > max_x ? x : max_x;
x = xp;
y += font->line_spacing + vspacing;
if( *str ) {
y += font->line_spacing + vspacing;
} else {
y += font->height;
}
if( *str == '\n' ) ++str;
if( *str && skip_space && *str <= ' ' ) ++str;
}
Expand Down Expand Up @@ -326,7 +334,7 @@ void pixelfont_builder_destroy( pixelfont_builder_t* builder )
}


void pixelfont_builder_glyph( pixelfont_builder_t* builder, int glyph, int pixels_stride, PIXELFONT_U8* pixels, int width, int lead, int trail )
void pixelfont_builder_glyph( pixelfont_builder_t* builder, int glyph, int width, PIXELFONT_U8* pixels, int lead, int trail )
{
if( glyph < 0 || glyph > 255 ) return;

Expand All @@ -339,9 +347,7 @@ void pixelfont_builder_glyph( pixelfont_builder_t* builder, int glyph, int pixel
if( pixels && width > 0 )
{
builder->glyphs[ glyph ].pixels = (PIXELFONT_U8*) PIXELFONT_MALLOC( builder->memctx, width * builder->height * sizeof( PIXELFONT_U8 ) );
for( int y = 0; y < builder->height; ++y )
for( int x = 0; x < width; ++x )
builder->glyphs[ glyph ].pixels[ x + y * width ] = pixels[ x + y * pixels_stride ];
PIXELFONT_MEMCPY( builder->glyphs[ glyph ].pixels, pixels, width * builder->height * sizeof( PIXELFONT_U8 ) );
builder->glyphs[ glyph ].lead = lead < -127 ? -127 : lead > 127 ? 127 : lead;
builder->glyphs[ glyph ].trail = trail < -127 ? -127 : trail > 127 ? 127 : trail;
builder->glyphs[ glyph ].width = width < 0 ? 0 : width > 255 ? 255 : width;
Expand Down Expand Up @@ -406,7 +412,7 @@ pixelfont_t* pixelfont_builder_font( pixelfont_builder_t* builder )

PIXELFONT_U32 offsets[ 256 ];
memset( offsets, 0, sizeof( offsets ) );
PIXELFONT_U32 current_offset = 0;
int current_offset = 1;
int total_width = 0;
int glyph_count = 0;
for( int i = 0; i < sizeof( builder->glyphs ) / sizeof( *builder->glyphs ); ++i )
Expand All @@ -421,6 +427,7 @@ pixelfont_t* pixelfont_builder_font( pixelfont_builder_t* builder )
}

size_t size_in_bytes = sizeof( pixelfont_t ) - sizeof( PIXELFONT_U8 ); // base size excluding final placeholder byte
size_in_bytes += 1; // skip first slot in array, as we use 0 for "no glyph" marker
size_in_bytes += glyph_count + 2 * builder->kernings_count; // kerning pair count for each glyph + all kerning data
size_in_bytes += 3 * glyph_count; // lead, trail and width for each glyph
size_in_bytes += total_width * builder->height; // pixel data for all glyphs
Expand Down
2 changes: 1 addition & 1 deletion thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ thread_tls_t thread_tls_create( void )

pthread_key_t tls;
if( pthread_key_create( &tls, NULL ) == 0 )
return (thread_tls_t) tls;
return (thread_tls_t) (uintptr_t) tls;
else
return NULL;

Expand Down
Loading