123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500 |
- #include "u8g.h"
- typedef void * u8g_glyph_t;
- #define U8G_FONT_DATA_STRUCT_SIZE 17
- void u8g_font_GetStrSize(const void *font, const char *s, u8g_uint_t *width, u8g_uint_t *height);
- void u8g_font_GetStrSizeP(const void *font, const char *s, u8g_uint_t *width, u8g_uint_t *height);
- void u8g_font_AdjustXYToDraw(const void *font, const char *s, u8g_uint_t *x, u8g_uint_t *y);
- void u8g_font_AdjustXYToDrawP(const void *font, const char *s, u8g_uint_t *x, u8g_uint_t *y);
- void u8g_font_GetStrMinBox(u8g_t *u8g, const void *font, const char *s, u8g_uint_t *x, u8g_uint_t *y, u8g_uint_t *width, u8g_uint_t *height);
- static uint8_t u8g_font_get_byte(const u8g_fntpgm_uint8_t *font, uint8_t offset)
- {
- font += offset;
- return u8g_pgm_read( (u8g_pgm_uint8_t *)font );
- }
- static uint16_t u8g_font_get_word(const u8g_fntpgm_uint8_t *font, uint8_t offset) U8G_NOINLINE;
- static uint16_t u8g_font_get_word(const u8g_fntpgm_uint8_t *font, uint8_t offset)
- {
- uint16_t pos;
- font += offset;
- pos = u8g_pgm_read( (u8g_pgm_uint8_t *)font );
- font++;
- pos <<= 8;
- pos += u8g_pgm_read( (u8g_pgm_uint8_t *)font);
- return pos;
- }
- static uint8_t u8g_font_GetFormat(const u8g_fntpgm_uint8_t *font) U8G_NOINLINE;
- static uint8_t u8g_font_GetFormat(const u8g_fntpgm_uint8_t *font)
- {
- return u8g_font_get_byte(font, 0);
- }
- static uint8_t u8g_font_GetFontGlyphStructureSize(const u8g_fntpgm_uint8_t *font) U8G_NOINLINE;
- static uint8_t u8g_font_GetFontGlyphStructureSize(const u8g_fntpgm_uint8_t *font)
- {
- switch(u8g_font_GetFormat(font))
- {
- case 0: return 6;
- case 1: return 3;
- case 2: return 6;
- }
- return 3;
- }
- static uint8_t u8g_font_GetBBXWidth(const void *font)
- {
- return u8g_font_get_byte(font, 1);
- }
- static uint8_t u8g_font_GetBBXHeight(const void *font)
- {
- return u8g_font_get_byte(font, 2);
- }
- static int8_t u8g_font_GetBBXOffX(const void *font)
- {
- return u8g_font_get_byte(font, 3);
- }
- static int8_t u8g_font_GetBBXOffY(const void *font)
- {
- return u8g_font_get_byte(font, 4);
- }
- uint8_t u8g_font_GetCapitalAHeight(const void *font)
- {
- return u8g_font_get_byte(font, 5);
- }
- uint16_t u8g_font_GetEncoding65Pos(const void *font) U8G_NOINLINE;
- uint16_t u8g_font_GetEncoding65Pos(const void *font)
- {
- return u8g_font_get_word(font, 6);
- }
- uint16_t u8g_font_GetEncoding97Pos(const void *font) U8G_NOINLINE;
- uint16_t u8g_font_GetEncoding97Pos(const void *font)
- {
- return u8g_font_get_word(font, 8);
- }
- uint8_t u8g_font_GetFontStartEncoding(const void *font)
- {
- return u8g_font_get_byte(font, 10);
- }
- uint8_t u8g_font_GetFontEndEncoding(const void *font)
- {
- return u8g_font_get_byte(font, 11);
- }
- int8_t u8g_font_GetLowerGDescent(const void *font)
- {
- return u8g_font_get_byte(font, 12);
- }
- int8_t u8g_font_GetFontAscent(const void *font)
- {
- return u8g_font_get_byte(font, 13);
- }
- int8_t u8g_font_GetFontDescent(const void *font)
- {
- return u8g_font_get_byte(font, 14);
- }
- int8_t u8g_font_GetFontXAscent(const void *font)
- {
- return u8g_font_get_byte(font, 15);
- }
- int8_t u8g_font_GetFontXDescent(const void *font)
- {
- return u8g_font_get_byte(font, 16);
- }
- static uint8_t *u8g_font_GetGlyphDataStart(const void *font, u8g_glyph_t g)
- {
- return ((u8g_fntpgm_uint8_t *)g) + u8g_font_GetFontGlyphStructureSize(font);
- }
- size_t u8g_font_GetSize(const void *font)
- {
- uint8_t *p = (uint8_t *)(font);
- uint8_t font_format = u8g_font_GetFormat(font);
- uint8_t data_structure_size = u8g_font_GetFontGlyphStructureSize(font);
- uint8_t start, end;
- uint8_t i;
- uint8_t mask = 255;
-
- start = u8g_font_GetFontStartEncoding(font);
- end = u8g_font_GetFontEndEncoding(font);
- if ( font_format == 1 )
- mask = 15;
- p += U8G_FONT_DATA_STRUCT_SIZE;
- i = start;
- for(;;)
- {
- if ( u8g_pgm_read((u8g_pgm_uint8_t *)(p)) == 255 )
- {
- p += 1;
- }
- else
- {
- p += u8g_pgm_read( ((u8g_pgm_uint8_t *)(p)) + 2 ) & mask;
- p += data_structure_size;
- }
- if ( i == end )
- break;
- i++;
- }
-
- return p - (uint8_t *)font;
- }
- uint8_t u8g_GetFontBBXWidth(u8g_t *u8g)
- {
- return u8g_font_GetBBXWidth(u8g->font);
- }
- uint8_t u8g_GetFontBBXHeight(u8g_t *u8g)
- {
- return u8g_font_GetBBXHeight(u8g->font);
- }
- int8_t u8g_GetFontBBXOffX(u8g_t *u8g) U8G_NOINLINE;
- int8_t u8g_GetFontBBXOffX(u8g_t *u8g)
- {
- return u8g_font_GetBBXOffX(u8g->font);
- }
- int8_t u8g_GetFontBBXOffY(u8g_t *u8g) U8G_NOINLINE;
- int8_t u8g_GetFontBBXOffY(u8g_t *u8g)
- {
- return u8g_font_GetBBXOffY(u8g->font);
- }
- uint8_t u8g_GetFontCapitalAHeight(u8g_t *u8g) U8G_NOINLINE;
- uint8_t u8g_GetFontCapitalAHeight(u8g_t *u8g)
- {
- return u8g_font_GetCapitalAHeight(u8g->font);
- }
- static void u8g_CopyGlyphDataToCache(u8g_t *u8g, u8g_glyph_t g)
- {
- uint8_t tmp;
- switch( u8g_font_GetFormat(u8g->font) )
- {
- case 0:
- case 2:
-
- u8g->glyph_width = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 0 );
- u8g->glyph_height = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 1 );
- u8g->glyph_dx = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 3 );
- u8g->glyph_x = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 4 );
- u8g->glyph_y = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 5 );
- break;
- case 1:
- default:
-
-
- tmp = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 0 );
- u8g->glyph_y = tmp & 15;
- u8g->glyph_y-=2;
- tmp >>= 4;
- u8g->glyph_x = tmp;
-
- tmp = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 1 );
- u8g->glyph_height = tmp & 15;
- tmp >>= 4;
- u8g->glyph_width = tmp;
-
- tmp = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 2 );
- tmp >>= 4;
- u8g->glyph_dx = tmp;
-
-
- break;
- }
- }
- static void u8g_FillEmptyGlyphCache(u8g_t *u8g)
- {
- u8g->glyph_dx = 0;
- u8g->glyph_width = 0;
- u8g->glyph_height = 0;
- u8g->glyph_x = 0;
- u8g->glyph_y = 0;
- }
- u8g_glyph_t u8g_GetGlyph(u8g_t *u8g, uint8_t requested_encoding)
- {
- uint8_t *p = (uint8_t *)(u8g->font);
- uint8_t font_format = u8g_font_GetFormat(u8g->font);
- uint8_t data_structure_size = u8g_font_GetFontGlyphStructureSize(u8g->font);
- uint8_t start, end;
- uint16_t pos;
- uint8_t i;
- uint8_t mask = 255;
- if ( font_format == 1 )
- mask = 15;
-
- start = u8g_font_GetFontStartEncoding(u8g->font);
- end = u8g_font_GetFontEndEncoding(u8g->font);
- pos = u8g_font_GetEncoding97Pos(u8g->font);
- if ( requested_encoding >= 97 && pos > 0 )
- {
- p+= pos;
- start = 97;
- }
- else
- {
- pos = u8g_font_GetEncoding65Pos(u8g->font);
- if ( requested_encoding >= 65 && pos > 0 )
- {
- p+= pos;
- start = 65;
- }
- else
- p += U8G_FONT_DATA_STRUCT_SIZE;
- }
-
- if ( requested_encoding > end )
- {
- u8g_FillEmptyGlyphCache(u8g);
- return NULL;
- }
-
- i = start;
- if ( i <= end )
- {
- for(;;)
- {
- if ( u8g_pgm_read((u8g_pgm_uint8_t *)(p)) == 255 )
- {
- p += 1;
- }
- else
- {
- if ( i == requested_encoding )
- {
- u8g_CopyGlyphDataToCache(u8g, p);
- return p;
- }
- p += u8g_pgm_read( ((u8g_pgm_uint8_t *)(p)) + 2 ) & mask;
- p += data_structure_size;
- }
- if ( i == end )
- break;
- i++;
- }
- }
-
- u8g_FillEmptyGlyphCache(u8g);
-
- return NULL;
- }
- uint8_t u8g_IsGlyph(u8g_t *u8g, uint8_t requested_encoding)
- {
- if ( u8g_GetGlyph(u8g, requested_encoding) != NULL )
- return 1;
- return 0;
- }
- int8_t u8g_GetGlyphDeltaX(u8g_t *u8g, uint8_t requested_encoding)
- {
- if ( u8g_GetGlyph(u8g, requested_encoding) == NULL )
- return 0;
- return u8g->glyph_dx;
- }
- #ifdef OBSOLETE
- int8_t u8g_DrawGlyphDir(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t encoding)
- {
- u8g_glyph_t g;
- uint8_t w, h, i, j;
- const u8g_pgm_uint8_t *data;
- uint8_t bytes_per_line;
- u8g_uint_t ix, iy;
- g = u8g_GetGlyph(u8g, encoding);
- if ( g == NULL )
- return 0;
- w = u8g->glyph_width;
- h = u8g->glyph_height;
- bytes_per_line = w;
- bytes_per_line += 7;
- bytes_per_line /= 8;
-
- data = u8g_font_GetGlyphDataStart(u8g->font, g);
- switch(dir)
- {
- case 0:
- x += u8g->glyph_x;
- y -= u8g->glyph_y;
- y--;
-
- if ( u8g_IsBBXIntersection(u8g, x, y-h+1, w, h) == 0 )
- return u8g->glyph_dx;
-
- iy = y;
- iy -= h;
- iy++;
-
- for( j = 0; j < h; j++ )
- {
- ix = x;
- for( i = 0; i < bytes_per_line; i++ )
- {
- u8g_Draw8Pixel(u8g, ix, iy, dir, u8g_pgm_read(data));
- data++;
- ix+=8;
- }
- iy++;
- }
- break;
- case 1:
- x += u8g->glyph_y;
- x++;
- y += u8g->glyph_x;
-
-
- if ( u8g_IsBBXIntersection(u8g, x, y, h, w) == 0 )
- return u8g->glyph_dx;
-
- ix = x;
- ix += h;
- ix--;
- for( j = 0; j < h; j++ )
- {
- iy = y;
- for( i = 0; i < bytes_per_line; i++ )
- {
- u8g_Draw8Pixel(u8g, ix, iy, dir, u8g_pgm_read(data));
- data++;
- iy+=8;
- }
- ix--;
- }
- break;
- case 2:
- x -= u8g->glyph_x;
- y += u8g->glyph_y;
- y++;
- if ( u8g_IsBBXIntersection(u8g, x-w-1, y, w, h) == 0 )
- return u8g->glyph_dx;
-
- iy = y;
- iy += h;
- iy--;
- for( j = 0; j < h; j++ )
- {
- ix = x;
- for( i = 0; i < bytes_per_line; i++ )
- {
- u8g_Draw8Pixel(u8g, ix, iy, dir, u8g_pgm_read(data));
- data++;
- ix-=8;
- }
- iy--;
- }
- break;
- case 3:
- x -= u8g->glyph_y;
- x--;
- y -= u8g->glyph_x;
-
- if ( u8g_IsBBXIntersection(u8g, x-h-1, y-w-1, h, w) == 0 )
- return u8g->glyph_dx;
-
- ix = x;
- ix -= h;
- ix++;
-
- for( j = 0; j < h; j++ )
- {
- iy = y;
- for( i = 0; i < bytes_per_line; i++ )
- {
- u8g_Draw8Pixel(u8g, ix, iy, dir, u8g_pgm_read(data));
- data++;
- iy-=8;
- }
- ix++;
- }
- break;
- }
- return u8g->glyph_dx;
- }
- #endif
- int8_t u8g_draw_glyph(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding)
- {
- const u8g_pgm_uint8_t *data;
- uint8_t w, h;
- uint8_t i, j;
- u8g_uint_t ix, iy;
- {
- u8g_glyph_t g = u8g_GetGlyph(u8g, encoding);
- if ( g == NULL )
- return 0;
- data = u8g_font_GetGlyphDataStart(u8g->font, g);
- }
-
- w = u8g->glyph_width;
- h = u8g->glyph_height;
-
- x += u8g->glyph_x;
- y -= u8g->glyph_y;
- y--;
-
- if ( u8g_IsBBXIntersection(u8g, x, y-h+1, w, h) == 0 )
- return u8g->glyph_dx;
-
- w += 7;
- w /= 8;
-
- iy = y;
- iy -= h;
- iy++;
- for( j = 0; j < h; j++ )
- {
- ix = x;
- for( i = 0; i < w; i++ )
- {
- u8g_Draw8Pixel(u8g, ix, iy, 0, u8g_pgm_read(data));
- data++;
- ix+=8;
- }
- iy++;
- }
- return u8g->glyph_dx;
- }
- int8_t u8g_DrawGlyph(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding)
- {
- y += u8g->font_calc_vref(u8g);
- return u8g_draw_glyph(u8g, x, y, encoding);
- }
- int8_t u8g_draw_glyph90(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding)
- {
- const u8g_pgm_uint8_t *data;
- uint8_t w, h;
- uint8_t i, j;
- u8g_uint_t ix, iy;
- {
- u8g_glyph_t g = u8g_GetGlyph(u8g, encoding);
- if ( g == NULL )
- return 0;
- data = u8g_font_GetGlyphDataStart(u8g->font, g);
- }
-
- w = u8g->glyph_width;
- h = u8g->glyph_height;
-
- x += u8g->glyph_y;
- x++;
- y += u8g->glyph_x;
-
- if ( u8g_IsBBXIntersection(u8g, x, y, h, w) == 0 )
- return u8g->glyph_dx;
-
- w += 7;
- w /= 8;
-
- ix = x;
- ix += h;
- ix--;
- for( j = 0; j < h; j++ )
- {
- iy = y;
- for( i = 0; i < w; i++ )
- {
- u8g_Draw8Pixel(u8g, ix, iy, 1, u8g_pgm_read(data));
- data++;
- iy+=8;
- }
- ix--;
- }
- return u8g->glyph_dx;
- }
- int8_t u8g_DrawGlyph90(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding)
- {
- x -= u8g->font_calc_vref(u8g);
- return u8g_draw_glyph90(u8g, x, y, encoding);
- }
- int8_t u8g_draw_glyph180(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding)
- {
- const u8g_pgm_uint8_t *data;
- uint8_t w, h;
- uint8_t i, j;
- u8g_uint_t ix, iy;
- {
- u8g_glyph_t g = u8g_GetGlyph(u8g, encoding);
- if ( g == NULL )
- return 0;
- data = u8g_font_GetGlyphDataStart(u8g->font, g);
- }
-
- w = u8g->glyph_width;
- h = u8g->glyph_height;
-
- x -= u8g->glyph_x;
- y += u8g->glyph_y;
- y++;
-
- if ( u8g_IsBBXIntersection(u8g, x-(w-1), y, w, h) == 0 )
- return u8g->glyph_dx;
-
- w += 7;
- w /= 8;
-
- iy = y;
- iy += h;
- iy--;
- for( j = 0; j < h; j++ )
- {
- ix = x;
- for( i = 0; i < w; i++ )
- {
- u8g_Draw8Pixel(u8g, ix, iy, 2, u8g_pgm_read(data));
- data++;
- ix-=8;
- }
- iy--;
- }
- return u8g->glyph_dx;
- }
- int8_t u8g_DrawGlyph180(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding)
- {
- y -= u8g->font_calc_vref(u8g);
- return u8g_draw_glyph180(u8g, x, y, encoding);
- }
- int8_t u8g_draw_glyph270(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding)
- {
- const u8g_pgm_uint8_t *data;
- uint8_t w, h;
- uint8_t i, j;
- u8g_uint_t ix, iy;
- {
- u8g_glyph_t g = u8g_GetGlyph(u8g, encoding);
- if ( g == NULL )
- return 0;
- data = u8g_font_GetGlyphDataStart(u8g->font, g);
- }
-
- w = u8g->glyph_width;
- h = u8g->glyph_height;
-
- x -= u8g->glyph_y;
- x--;
- y -= u8g->glyph_x;
-
- if ( u8g_IsBBXIntersection(u8g, x-(h-1), y-(w-1), h, w) == 0 )
- return u8g->glyph_dx;
-
-
- w += 7;
- w /= 8;
-
- ix = x;
- ix -= h;
- ix++;
-
- for( j = 0; j < h; j++ )
- {
- iy = y;
- for( i = 0; i < w; i++ )
- {
- u8g_Draw8Pixel(u8g, ix, iy, 3, u8g_pgm_read(data));
- data++;
- iy-=8;
- }
- ix++;
- }
- return u8g->glyph_dx;
- }
- int8_t u8g_DrawGlyph270(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding)
- {
- x += u8g->font_calc_vref(u8g);
- return u8g_draw_glyph270(u8g, x, y, encoding);
- }
- #ifdef OBSOLETE
- int8_t u8g_DrawGlyphFontBBX(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t encoding)
- {
-
- x -= u8g_GetFontBBXOffX(u8g);
- y += u8g_GetFontBBXOffY(u8g);
- return u8g_DrawGlyphDir(u8g, x, y, dir, encoding);
- }
- #endif
- u8g_uint_t u8g_DrawStr(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s)
- {
- u8g_uint_t t = 0;
- int8_t d;
-
-
-
-
- y += u8g->font_calc_vref(u8g);
-
- while( *s != '\0' )
- {
- d = u8g_draw_glyph(u8g, x, y, *s);
- x += d;
- t += d;
- s++;
- }
- return t;
- }
- u8g_uint_t u8g_DrawStr90(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s)
- {
- u8g_uint_t t = 0;
- int8_t d;
-
- x -= u8g->font_calc_vref(u8g);
- while( *s != '\0' )
- {
- d = u8g_draw_glyph90(u8g, x, y, *s);
- y += d;
- t += d;
- s++;
- }
- return t;
- }
- u8g_uint_t u8g_DrawStr180(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s)
- {
- u8g_uint_t t = 0;
- int8_t d;
- y -= u8g->font_calc_vref(u8g);
-
- while( *s != '\0' )
- {
- d = u8g_draw_glyph180(u8g, x, y, *s);
- x -= d;
- t += d;
- s++;
- }
- return t;
- }
- u8g_uint_t u8g_DrawStr270(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s)
- {
- u8g_uint_t t = 0;
- int8_t d;
- x += u8g->font_calc_vref(u8g);
- while( *s != '\0' )
- {
- d = u8g_draw_glyph270(u8g, x, y, *s);
- y -= d;
- t += d;
- s++;
- }
- return t;
- }
- u8g_uint_t u8g_DrawStrDir(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, const char *s)
- {
- switch(dir)
- {
- case 0:
- return u8g_DrawStr(u8g, x, y, s);
- case 1:
- return u8g_DrawStr90(u8g, x, y, s);
- case 2:
- return u8g_DrawStr180(u8g, x, y, s);
- case 3:
- return u8g_DrawStr270(u8g, x, y, s);
- }
- return 0;
- }
- u8g_uint_t u8g_DrawStrP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s)
- {
- u8g_uint_t t = 0;
- int8_t d;
- uint8_t c;
-
- y += u8g->font_calc_vref(u8g);
-
- for(;;)
- {
- c = u8g_pgm_read(s);
- if ( c == '\0' )
- break;
- d = u8g_draw_glyph(u8g, x, y, c);
- x += d;
- t += d;
- s++;
- }
- return t;
- }
- u8g_uint_t u8g_DrawStr90P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s)
- {
- u8g_uint_t t = 0;
- int8_t d;
-
- x -= u8g->font_calc_vref(u8g);
- while( *s != '\0' )
- {
- d = u8g_DrawGlyph90(u8g, x, y, u8g_pgm_read(s));
- y += d;
- t += d;
- s++;
- }
- return t;
- }
- u8g_uint_t u8g_DrawStr180P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s)
- {
- u8g_uint_t t = 0;
- int8_t d;
- y -= u8g->font_calc_vref(u8g);
-
- while( *s != '\0' )
- {
- d = u8g_DrawGlyph180(u8g, x, y, u8g_pgm_read(s));
- x -= d;
- t += d;
- s++;
- }
- return t;
- }
- u8g_uint_t u8g_DrawStr270P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s)
- {
- u8g_uint_t t = 0;
- int8_t d;
- x += u8g->font_calc_vref(u8g);
- while( *s != '\0' )
- {
- d = u8g_DrawGlyph270(u8g, x, y, u8g_pgm_read(s));
- y -= d;
- t += d;
- s++;
- }
- return t;
- }
- u8g_uint_t u8g_DrawStrFontBBX(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, const char *s)
- {
- x -= u8g_GetFontBBXOffX(u8g);
- y += u8g_GetFontBBXOffY(u8g);
- return u8g_DrawStrDir(u8g, x, y, dir, s);
- }
- int8_t u8g_DrawGlyphFontBBX(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t encoding)
- {
- x -= u8g_GetFontBBXOffX(u8g);
- y += u8g_GetFontBBXOffY(u8g);
- u8g_draw_glyph(u8g, x, y, encoding);
- return 0;
- }
- void u8g_UpdateRefHeight(u8g_t *u8g)
- {
- uint16_t ls;
- if ( u8g->font == NULL )
- return;
- if ( u8g->font_height_mode == U8G_FONT_HEIGHT_MODE_TEXT )
- {
- u8g->font_ref_ascent = u8g_font_GetCapitalAHeight(u8g->font);
- u8g->font_ref_descent = u8g_font_GetLowerGDescent(u8g->font);
- }
- else if ( u8g->font_height_mode == U8G_FONT_HEIGHT_MODE_XTEXT )
- {
- u8g->font_ref_ascent = u8g_font_GetFontXAscent(u8g->font);
- u8g->font_ref_descent = u8g_font_GetFontXDescent(u8g->font);
- }
- else
- {
- u8g->font_ref_ascent = u8g_font_GetFontAscent(u8g->font);
- u8g->font_ref_descent = u8g_font_GetFontDescent(u8g->font);
- }
-
- ls = u8g->font_ref_ascent - u8g->font_ref_descent;
- if ( u8g->font_line_spacing_factor != 64 )
- {
- ls &= 255;
- ls *= u8g->font_line_spacing_factor;
- ls >>= 6;
- }
- u8g->line_spacing = ls;
- }
- void u8g_SetFontRefHeightText(u8g_t *u8g)
- {
- u8g->font_height_mode = U8G_FONT_HEIGHT_MODE_TEXT;
- u8g_UpdateRefHeight(u8g);
- }
- void u8g_SetFontRefHeightExtendedText(u8g_t *u8g)
- {
- u8g->font_height_mode = U8G_FONT_HEIGHT_MODE_XTEXT;
- u8g_UpdateRefHeight(u8g);
- }
- void u8g_SetFontRefHeightAll(u8g_t *u8g)
- {
- u8g->font_height_mode = U8G_FONT_HEIGHT_MODE_ALL;
- u8g_UpdateRefHeight(u8g);
- }
- void u8g_SetFontLineSpacingFactor(u8g_t *u8g, uint8_t factor)
- {
- u8g->font_line_spacing_factor = factor;
- u8g_UpdateRefHeight(u8g);
- }
- u8g_uint_t u8g_font_calc_vref_font(u8g_t *u8g)
- {
- return 0;
- }
- void u8g_SetFontPosBaseline(u8g_t *u8g)
- {
- u8g->font_calc_vref = u8g_font_calc_vref_font;
- }
- u8g_uint_t u8g_font_calc_vref_bottom(u8g_t *u8g)
- {
-
- return (u8g_uint_t)(u8g_int_t)(u8g->font_ref_descent);
- }
- void u8g_SetFontPosBottom(u8g_t *u8g)
- {
- u8g->font_calc_vref = u8g_font_calc_vref_bottom;
- }
- u8g_uint_t u8g_font_calc_vref_top(u8g_t *u8g)
- {
- u8g_uint_t tmp;
-
-
- tmp = (u8g_uint_t)(u8g_int_t)(u8g->font_ref_ascent);
- tmp++;
- return tmp;
- }
- void u8g_SetFontPosTop(u8g_t *u8g)
- {
- u8g->font_calc_vref = u8g_font_calc_vref_top;
- }
- u8g_uint_t u8g_font_calc_vref_center(u8g_t *u8g)
- {
- int8_t tmp;
- tmp = u8g->font_ref_ascent;
- tmp -= u8g->font_ref_descent;
- tmp /= 2;
- tmp += u8g->font_ref_descent;
-
- return tmp;
- }
- void u8g_SetFontPosCenter(u8g_t *u8g)
- {
- u8g->font_calc_vref = u8g_font_calc_vref_center;
- }
- char u8g_font_get_char(const void *s)
- {
- return *(const char *)(s);
- }
- char u8g_font_get_charP(const void *s)
- {
- return u8g_pgm_read(s);
- }
- typedef char (*u8g_font_get_char_fn)(const void *s);
- u8g_uint_t u8g_font_calc_str_pixel_width(u8g_t *u8g, const char *s, u8g_font_get_char_fn get_char )
- {
- u8g_uint_t w;
- uint8_t enc;
-
-
- w = 0;
-
- enc = get_char(s);
-
-
- if ( enc == '\0' )
- {
- return w;
- }
-
-
-
- u8g_GetGlyph(u8g, enc);
-
-
-
-
-
-
- w = -u8g->glyph_x;
- for(;;)
- {
-
-
- s++;
- if ( get_char(s) == '\0' )
- break;
-
-
- w += u8g->glyph_dx;
-
-
- enc = get_char(s);
-
-
- u8g_GetGlyph(u8g, enc);
- }
-
-
-
- if ( enc != ' ' )
- {
-
- w += u8g->glyph_width;
- w += u8g->glyph_x;
- }
- else
- {
- w += u8g->glyph_dx;
- }
-
-
- return w;
- }
- u8g_uint_t u8g_GetStrPixelWidth(u8g_t *u8g, const char *s)
- {
- return u8g_font_calc_str_pixel_width(u8g, s, u8g_font_get_char);
- }
- u8g_uint_t u8g_GetStrPixelWidthP(u8g_t *u8g, const u8g_pgm_uint8_t *s)
- {
- return u8g_font_calc_str_pixel_width(u8g, (const char *)s, u8g_font_get_charP);
- }
- int8_t u8g_GetStrX(u8g_t *u8g, const char *s)
- {
- u8g_GetGlyph(u8g, *s);
- return u8g->glyph_x;
- }
- int8_t u8g_GetStrXP(u8g_t *u8g, const u8g_pgm_uint8_t *s)
- {
- u8g_GetGlyph(u8g, u8g_pgm_read(s));
- return u8g->glyph_x;
- }
- u8g_uint_t u8g_GetStrWidth(u8g_t *u8g, const char *s)
- {
- u8g_uint_t w;
- uint8_t encoding;
-
-
- w = 0;
-
- for(;;)
- {
- encoding = *s;
- if ( encoding == 0 )
- break;
-
- u8g_GetGlyph(u8g, encoding);
- w += u8g->glyph_dx;
-
-
- s++;
- }
-
- return w;
- }
- u8g_uint_t u8g_GetStrWidthP(u8g_t *u8g, const u8g_pgm_uint8_t *s)
- {
- u8g_uint_t w;
- uint8_t encoding;
-
-
- w = 0;
-
- for(;;)
- {
- encoding = u8g_pgm_read(s);
- if ( encoding == 0 )
- break;
-
- u8g_GetGlyph(u8g, encoding);
- w += u8g->glyph_dx;
-
-
- s++;
- }
-
- return w;
- }
- struct u8g_str_size_struct
- {
- int8_t y_min;
- int8_t y_max;
- int8_t x, y;
- u8g_uint_t w;
- };
- typedef struct u8g_str_size_struct u8g_str_size_t;
- static void u8g_font_calc_str_min_box(u8g_t *u8g, const char *s, u8g_str_size_t *buf)
- {
-
- int8_t tmp;
-
-
- buf->w = 0;
-
-
- if ( *s == '\0' )
- {
- buf->y_min = 0;
- buf->y_max = 0;
- buf->x = 0;
- buf->y = 0;
- return;
- }
-
-
-
- buf->y_min = 127;
-
-
- buf->y_max = -128;
-
- u8g_GetGlyph(u8g, *s);
-
-
-
-
-
-
-
- buf->w = - u8g->glyph_x;
-
-
- buf->x = u8g->glyph_x;
- buf->y = u8g->glyph_y;
-
- for(;;)
- {
-
-
-
-
- tmp = u8g->glyph_y;
- if ( buf->y_min > tmp )
- buf->y_min = tmp;
-
- tmp +=u8g->glyph_height;
- if ( buf->y_max < tmp )
- buf->y_max = tmp;
-
-
- s++;
- if ( *s == '\0' )
- break;
-
-
- buf->w += u8g->glyph_dx;
-
-
- u8g_GetGlyph(u8g, *s);
- }
-
-
-
- buf->w += u8g->glyph_width;
-
-
- buf->w += u8g->glyph_x;
- }
- void u8g_font_box_min(u8g_t *u8g, const char *s, u8g_str_size_t *buf)
- {
- u8g_font_calc_str_min_box(u8g, s, buf);
- }
- void u8g_font_box_left_gA(u8g_t *u8g, const char *s, u8g_str_size_t *buf)
- {
-
- }
- void u8g_font_box_all_gA(u8g_t *u8g, const char *s, u8g_str_size_t *buf)
- {
-
- }
- static void u8g_font_get_str_box_fill_args(u8g_t *u8g, const char *s, u8g_str_size_t *buf, u8g_uint_t *x, u8g_uint_t *y, u8g_uint_t *width, u8g_uint_t *height)
- {
-
-
- u8g_GetGlyph(u8g, *s);
- *x += u8g->glyph_x;
- *width = buf->w;
- *y -= buf->y_max;
-
-
-
-
- *height = buf->y_max;
- *height -= buf->y_min;
- }
- void u8g_GetStrMinBox(u8g_t *u8g, const char *s, u8g_uint_t *x, u8g_uint_t *y, u8g_uint_t *width, u8g_uint_t *height)
- {
- u8g_str_size_t buf;
-
- if ( *s == '\0' )
- {
- *width= 0;
- *height = 0;
- return;
- }
-
- u8g_font_calc_str_min_box(u8g, s, &buf);
- u8g_font_get_str_box_fill_args(u8g, s, &buf, x, y, width, height);
- }
- void u8g_GetStrAMinBox(u8g_t *u8g, const char *s, u8g_uint_t *x, u8g_uint_t *y, u8g_uint_t *width, u8g_uint_t *height)
- {
- u8g_str_size_t buf;
- uint8_t cap_a;
-
- if ( *s == '\0' )
- {
- *width= 0;
- *height = 0;
- return;
- }
-
- cap_a = u8g_font_GetCapitalAHeight(u8g->font);
- u8g_font_calc_str_min_box(u8g, s, &buf);
- if ( buf.y_max < cap_a )
- buf.y_max = cap_a;
- u8g_font_get_str_box_fill_args(u8g, s, &buf, x, y, width, height);
- }
- void u8g_SetFont(u8g_t *u8g, const u8g_fntpgm_uint8_t *font)
- {
- if ( u8g->font != font )
- {
- u8g->font = font;
- u8g_UpdateRefHeight(u8g);
- u8g_SetFontPosBaseline(u8g);
- }
- }
- int8_t u8g_draw_aa_glyph(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding)
- {
- const u8g_pgm_uint8_t *data;
- uint8_t w, h;
- uint8_t i, j;
- u8g_uint_t ix, iy;
- {
- u8g_glyph_t g = u8g_GetGlyph(u8g, encoding);
- if ( g == NULL )
- return 0;
- data = u8g_font_GetGlyphDataStart(u8g->font, g);
- }
-
- w = u8g->glyph_width;
- h = u8g->glyph_height;
-
- x += u8g->glyph_x;
- y -= u8g->glyph_y;
- y--;
-
- if ( u8g_IsBBXIntersection(u8g, x, y-h+1, w, h) == 0 )
- return u8g->glyph_dx;
-
- w += 3;
- w /= 4;
-
- iy = y;
- iy -= h;
- iy++;
- for( j = 0; j < h; j++ )
- {
- ix = x;
- for( i = 0; i < w; i++ )
- {
- u8g_Draw4TPixel(u8g, ix, iy, 0, u8g_pgm_read(data));
- data++;
- ix+=4;
- }
- iy++;
- }
- return u8g->glyph_dx;
- }
- int8_t u8g_DrawAAGlyph(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding)
- {
- y += u8g->font_calc_vref(u8g);
- return u8g_draw_aa_glyph(u8g, x, y, encoding);
- }
- u8g_uint_t u8g_DrawAAStr(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s)
- {
- u8g_uint_t t = 0;
- int8_t d;
- if ( u8g_font_GetFormat(u8g->font) != 2 )
- return 0;
-
-
-
- y += u8g->font_calc_vref(u8g);
-
- while( *s != '\0' )
- {
- d = u8g_draw_aa_glyph(u8g, x, y, *s);
- x += d;
- t += d;
- s++;
- }
- return t;
- }
|