removed most of the kerning features from the u8g2 core, kept kerning with DrawExtendedUTF8

This commit is contained in:
olikraus 2016-08-15 22:02:23 +02:00
parent 2b5e7ed41a
commit dfb425eb29
8 changed files with 4754 additions and 6162 deletions

View File

@ -308,8 +308,8 @@ struct u8g2_struct
/* information about the current font */
const uint8_t *font; /* current font for all text procedures */
const u8g2_kerning_t *kerning; /* can be NULL */
u8g2_get_kerning_cb get_kerning_cb;
// removed: const u8g2_kerning_t *kerning; /* can be NULL */
// removed: u8g2_get_kerning_cb get_kerning_cb;
u8g2_font_calc_vref_fnptr font_calc_vref;
u8g2_font_decode_t font_decode; /* new font decode structure */
@ -592,8 +592,8 @@ void u8g2_DrawTriangle(u8g2_t *u8g2, int16_t x0, int16_t y0, int16_t x1, int16_t
/*==========================================*/
/* u8g2_kerning.c */
uint8_t u8g2_GetNullKerning(u8g2_t *u8g2, uint16_t e1, uint16_t e2);
uint8_t u8g2_GetKerning(u8g2_t *u8g2, uint16_t e1, uint16_t e2);
//uint8_t u8g2_GetNullKerning(u8g2_t *u8g2, uint16_t e1, uint16_t e2);
uint8_t u8g2_GetKerning(u8g2_t *u8g2, u8g2_kerning_t *kerning, uint16_t e1, uint16_t e2);
/*==========================================*/
@ -615,11 +615,14 @@ u8g2_uint_t u8g2_DrawGlyph(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, uint16_t
void u8g2_SetFontDirection(u8g2_t *u8g2, uint8_t dir);
u8g2_uint_t u8g2_DrawStr(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, const char *str);
u8g2_uint_t u8g2_DrawUTF8(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, const char *str);
u8g2_uint_t u8g2_DrawExtendedUTF8(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, uint8_t to_left, u8g2_kerning_t *kerning, const char *str);
#define u8g2_GetMaxCharHeight(u8g2) ((u8g2)->font_info.max_char_height)
#define u8g2_GetMaxCharWidth(u8g2) ((u8g2)->font_info.max_char_width)
#define u8g2_GetAscent(u8g2) ((u8g2)->font_ref_ascent)
#define u8g2_GetDescent(u8g2) ((u8g2)->font_ref_descent)
#define u8g2_GetFontAscent(u8g2) ((u8g2)->font_ref_ascent)
#define u8g2_GetFontDescent(u8g2) ((u8g2)->font_ref_descent)
u8g2_uint_t u8g2_GetStrWidth(u8g2_t *u8g2, const char *s);
u8g2_uint_t u8g2_GetUTF8Width(u8g2_t *u8g2, const char *str);

View File

@ -714,9 +714,8 @@ u8g2_uint_t u8g2_DrawGlyph(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, uint16_t
static u8g2_uint_t u8g2_draw_string(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, const char *str) U8G2_NOINLINE;
static u8g2_uint_t u8g2_draw_string(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, const char *str)
{
uint16_t e_prev = 0x0ffff;
uint16_t e;
u8g2_uint_t delta, sum, k;
u8g2_uint_t delta, sum;
u8x8_utf8_init(u8g2_GetU8x8(u8g2));
sum = 0;
for(;;)
@ -727,29 +726,6 @@ static u8g2_uint_t u8g2_draw_string(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y,
str++;
if ( e != 0x0fffe )
{
k = u8g2->get_kerning_cb(u8g2, e_prev, e);
e_prev = e;
#ifdef U8G2_WITH_FONT_ROTATION
switch(u8g2->font_decode.dir)
{
case 0:
x -= k;
break;
case 1:
y -= k;
break;
case 2:
x += k;
break;
case 3:
y += k;
break;
}
#else
x -= k;
#endif
delta = u8g2_DrawGlyph(u8g2, x, y, e);
#ifdef U8G2_WITH_FONT_ROTATION
@ -801,56 +777,56 @@ u8g2_uint_t u8g2_DrawUTF8(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, const char
}
#ifdef OBSOLETE
/* UTF-8 version */
u8g2_uint_t u8g2_DrawStr(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, const char *str)
u8g2_uint_t u8g2_DrawExtendedUTF8(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, uint8_t to_left, u8g2_kerning_t *kerning, const char *str)
{
u8g2->u8x8.next_cb = u8x8_utf8_next;
uint16_t e_prev = 0x0ffff;
uint16_t e;
u8g2_uint_t delta, sum;
u8g2_uint_t delta, sum, k;
u8x8_utf8_init(u8g2_GetU8x8(u8g2));
sum = 0;
/*
source: https://en.wikipedia.org/wiki/UTF-8
Bits from to bytes Byte 1 Byte 2 Byte 3 Byte 4 Byte 5 Byte 6
7 U+0000 U+007F 1 0xxxxxxx
11 U+0080 U+07FF 2 110xxxxx 10xxxxxx
16 U+0800 U+FFFF 3 1110xxxx 10xxxxxx 10xxxxxx
21 U+10000 U+1FFFFF 4 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
26 U+200000 U+3FFFFFF 5 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
31 U+4000000 U+7FFFFFFF 6 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
*/
for(;;)
{
e = u8x8_get_encoding_from_utf8_string(&str);
if ( e == 0 )
e = u8g2->u8x8.next_cb(u8g2_GetU8x8(u8g2), (uint8_t)*str);
if ( e == 0x0ffff )
break;
delta = u8g2_DrawGlyph(u8g2, x, y, e);
#ifdef U8G2_WITH_FONT_ROTATION
switch(u8g2->font_decode.dir)
str++;
if ( e != 0x0fffe )
{
case 0:
x += delta;
break;
case 1:
y += delta;
break;
case 2:
delta = u8g2_GetGlyphWidth(u8g2, e);
if ( to_left )
{
k = u8g2_GetKerning(u8g2, kerning, e, e_prev);
delta -= k;
x -= delta;
break;
case 3:
y -= delta;
break;
}
else
{
k = u8g2_GetKerning(u8g2, kerning, e_prev, e);
delta -= k;
}
e_prev = e;
u8g2_DrawGlyph(u8g2, x, y, e);
if ( to_left )
{
}
else
{
x += delta;
x -= k;
}
sum += delta;
}
#else
x += delta;
#endif
sum += delta;
}
return sum;
}
#endif
/*===============================================*/
@ -1029,26 +1005,6 @@ u8g2_uint_t u8g2_GetUTF8Width(u8g2_t *u8g2, const char *str)
}
#ifdef OBSOLETE
u8g2_uint_t u8g2_GetStrWidth(u8g2_t *u8g2, const char *s)
{
uint16_t e;
u8g2_uint_t w;
/* reset the total width to zero, this will be expanded during calculation */
w = 0;
for(;;)
{
e = u8x8_get_encoding_from_utf8_string(&s);
if ( e == 0 )
break;
w += u8g2_GetGlyphWidth(u8g2, e);
}
return w;
}
#endif
void u8g2_SetFontDirection(u8g2_t *u8g2, uint8_t dir)
{

View File

@ -36,40 +36,42 @@
#include "u8g2.h"
/* this function is used as "u8g2_get_kerning_cb" */
/*
uint8_t u8g2_GetNullKerning(u8g2_t *u8g2, uint16_t e1, uint16_t e2)
{
return 0;
}
*/
/* this function is used as "u8g2_get_kerning_cb" */
uint8_t u8g2_GetKerning(u8g2_t *u8g2, uint16_t e1, uint16_t e2)
uint8_t u8g2_GetKerning(u8g2_t *u8g2, u8g2_kerning_t *kerning, uint16_t e1, uint16_t e2)
{
uint16_t i1, i2, cnt, end;
if ( u8g2->kerning == NULL )
if ( kerning == NULL )
return 0;
/* search for the encoding in the first table */
cnt = u8g2->kerning->first_table_cnt;
cnt = kerning->first_table_cnt;
cnt--; /* ignore the last element of the table, which is 0x0ffff */
for( i1 = 0; i1 < cnt; i1++ )
{
if ( u8g2->kerning->first_encoding_table[i1] == e1 )
if ( kerning->first_encoding_table[i1] == e1 )
break;
}
if ( i1 >= cnt )
return 0; /* e1 not part of the kerning table, return 0 */
/* get the upper index for i2 */
end = u8g2->kerning->index_to_second_table[i1+1];
for( i2 = u8g2->kerning->index_to_second_table[i1]; i2 < end; i2++ )
end = kerning->index_to_second_table[i1+1];
for( i2 = kerning->index_to_second_table[i1]; i2 < end; i2++ )
{
if ( u8g2->kerning->second_encoding_table[i2] == e2 )
if ( kerning->second_encoding_table[i2] == e2 )
break;
}
if ( i2 >= end )
return 0; /* e2 not part of any pair with e1, return 0 */
return u8g2->kerning->kerning_values[i2];
return kerning->kerning_values[i2];
}

View File

@ -44,8 +44,8 @@
void u8g2_SetupBuffer(u8g2_t *u8g2, uint8_t *buf, uint8_t tile_buf_height, u8g2_draw_ll_hvline_cb ll_hvline_cb, const u8g2_cb_t *u8g2_cb)
{
u8g2->font = NULL;
u8g2->kerning = NULL;
u8g2->get_kerning_cb = u8g2_GetNullKerning;
//u8g2->kerning = NULL;
//u8g2->get_kerning_cb = u8g2_GetNullKerning;
//u8g2->ll_hvline = u8g2_ll_hvline_vertical_top_lsb;
u8g2->ll_hvline = ll_hvline_cb;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
CFLAGS = -g -Wall -I../../../csrc/. `sdl-config --cflags`
SRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c ) main.c
OBJ = $(SRC:.c=.o)
helloworld: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) `sdl-config --libs` -o u8g2_sdl
clean:
-rm $(OBJ) u8g2_sdl

View File

@ -0,0 +1,82 @@
#include "u8g2.h"
#include <stdio.h>
u8g2_t u8g2;
void draw(int x, int y)
{
char *list[] = {"|", ">", "-|", "lazydog|", "lazydog!", "lazy|dog"};
u8g2_uint_t fh, w;
u8g2_DrawLine(&u8g2, 120, 0, 120, 63);
u8g2_SetFont(&u8g2, u8g2_font_6x10_tr);
//u8g2_SetFont(&u8g2, u8g2_font_helvB08_tf);
u8g2_SetFontPosTop(&u8g2);
fh = u8g2_GetFontAscent(&u8g2) - u8g2_GetFontDescent(&u8g2);
int i;
for (i = 0; i < sizeof(list)/sizeof(char*); i++) {
w = u8g2_GetStrWidth(&u8g2, list[i]);
u8g2_DrawStr(&u8g2, 120 - w, fh * i, list[i]);
//u8g2.setCursor(0,fh * i);
//u8g2.print(w);
}
}
int main(void)
{
int x, y;
int k;
int i;
u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0);
u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
//u8g2_SetFont(&u8g2, u8g2_font_helvB18_tr);
u8g2_SetFont(&u8g2, u8g2_font_helvB18_tf);
x = 50;
y = 30;
for(;;)
{
u8g2_FirstPage(&u8g2);
i = 0;
do
{
draw(x,y);
/*
u8g2_SetFontDirection(&u8g2, 0);
u8g2_DrawUTF8(&u8g2, x, y, "WAV");
u8g2_SetFontDirection(&u8g2, 1);
u8g2_DrawUTF8(&u8g2, x, y, "WAV");
u8g2_SetFontDirection(&u8g2, 2);
u8g2_DrawUTF8(&u8g2, x, y, "WAV");
u8g2_SetFontDirection(&u8g2, 3);
u8g2_DrawUTF8(&u8g2, x, y, "WAV");
*/
} while( u8g2_NextPage(&u8g2) );
do
{
k = u8g_sdl_get_key();
} while( k < 0 );
if ( k == 273 ) y -= 7;
if ( k == 274 ) y += 7;
if ( k == 276 ) x -= 7;
if ( k == 275 ) x += 7;
if ( k == 'e' ) y -= 1;
if ( k == 'x' ) y += 1;
if ( k == 's' ) x -= 1;
if ( k == 'd' ) x += 1;
if ( k == 'q' ) break;
}
return 0;
}

View File

@ -115,9 +115,9 @@ static int bdf_is_glyph_overlap(uint8_t *font, uint16_t e1, uint16_t e2, uint8_t
if ( is_save )
{
char buf[64];
sprintf(buf, "glyph_intersection_%u_%u_%u.tga", e1, e2, kerning_test);
tga_save(buf);
//char buf[64];
//sprintf(buf, "glyph_intersection_%u_%u_%u.tga", e1, e2, kerning_test);
//tga_save(buf);
}
return tga_is_pixel_intersection();
@ -180,7 +180,7 @@ void bdf_calculate_all_kerning(bf_t *bf, const char *filename, const char *fontn
if ( bg_second->target_data != NULL && bg_second->is_excluded_from_kerning == 0 )
{
kerning = bdf_calculate_kerning(bf->target_data, bg_first->encoding, bg_second->encoding, min_distance_in_per_cent_of_char_width);
if ( kerning > 0 )
if ( kerning > 1 )
{
if ( is_first_encoding_added == 0 )
{