iforce2d Chris
/
ubxDistanceMeter
Displays distance to start location on OLED screen.
u8g_font.c@0:972874f31c98, 2018-03-07 (annotated)
- Committer:
- iforce2d
- Date:
- Wed Mar 07 12:49:14 2018 +0000
- Revision:
- 0:972874f31c98
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iforce2d | 0:972874f31c98 | 1 | /* |
iforce2d | 0:972874f31c98 | 2 | |
iforce2d | 0:972874f31c98 | 3 | u8g_font.c |
iforce2d | 0:972874f31c98 | 4 | |
iforce2d | 0:972874f31c98 | 5 | U8G Font High Level Interface |
iforce2d | 0:972874f31c98 | 6 | |
iforce2d | 0:972874f31c98 | 7 | Universal 8bit Graphics Library |
iforce2d | 0:972874f31c98 | 8 | |
iforce2d | 0:972874f31c98 | 9 | Copyright (c) 2011, olikraus@gmail.com |
iforce2d | 0:972874f31c98 | 10 | All rights reserved. |
iforce2d | 0:972874f31c98 | 11 | |
iforce2d | 0:972874f31c98 | 12 | Redistribution and use in source and binary forms, with or without modification, |
iforce2d | 0:972874f31c98 | 13 | are permitted provided that the following conditions are met: |
iforce2d | 0:972874f31c98 | 14 | |
iforce2d | 0:972874f31c98 | 15 | * Redistributions of source code must retain the above copyright notice, this list |
iforce2d | 0:972874f31c98 | 16 | of conditions and the following disclaimer. |
iforce2d | 0:972874f31c98 | 17 | |
iforce2d | 0:972874f31c98 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this |
iforce2d | 0:972874f31c98 | 19 | list of conditions and the following disclaimer in the documentation and/or other |
iforce2d | 0:972874f31c98 | 20 | materials provided with the distribution. |
iforce2d | 0:972874f31c98 | 21 | |
iforce2d | 0:972874f31c98 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
iforce2d | 0:972874f31c98 | 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
iforce2d | 0:972874f31c98 | 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
iforce2d | 0:972874f31c98 | 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
iforce2d | 0:972874f31c98 | 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
iforce2d | 0:972874f31c98 | 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
iforce2d | 0:972874f31c98 | 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
iforce2d | 0:972874f31c98 | 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
iforce2d | 0:972874f31c98 | 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
iforce2d | 0:972874f31c98 | 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
iforce2d | 0:972874f31c98 | 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
iforce2d | 0:972874f31c98 | 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
iforce2d | 0:972874f31c98 | 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
iforce2d | 0:972874f31c98 | 35 | |
iforce2d | 0:972874f31c98 | 36 | |
iforce2d | 0:972874f31c98 | 37 | */ |
iforce2d | 0:972874f31c98 | 38 | |
iforce2d | 0:972874f31c98 | 39 | #include "u8g.h" |
iforce2d | 0:972874f31c98 | 40 | |
iforce2d | 0:972874f31c98 | 41 | /* font api */ |
iforce2d | 0:972874f31c98 | 42 | |
iforce2d | 0:972874f31c98 | 43 | /* pointer to the start adress of the glyph, points to progmem area */ |
iforce2d | 0:972874f31c98 | 44 | typedef void * u8g_glyph_t; |
iforce2d | 0:972874f31c98 | 45 | |
iforce2d | 0:972874f31c98 | 46 | /* size of the font data structure, there is no struct or class... */ |
iforce2d | 0:972874f31c98 | 47 | #define U8G_FONT_DATA_STRUCT_SIZE 17 |
iforce2d | 0:972874f31c98 | 48 | |
iforce2d | 0:972874f31c98 | 49 | /* |
iforce2d | 0:972874f31c98 | 50 | ... instead the fields of the font data structure are accessed directly by offset |
iforce2d | 0:972874f31c98 | 51 | font information |
iforce2d | 0:972874f31c98 | 52 | offset |
iforce2d | 0:972874f31c98 | 53 | 0 font format |
iforce2d | 0:972874f31c98 | 54 | 1 FONTBOUNDINGBOX width unsigned |
iforce2d | 0:972874f31c98 | 55 | 2 FONTBOUNDINGBOX height unsigned |
iforce2d | 0:972874f31c98 | 56 | 3 FONTBOUNDINGBOX x-offset signed |
iforce2d | 0:972874f31c98 | 57 | 4 FONTBOUNDINGBOX y-offset signed |
iforce2d | 0:972874f31c98 | 58 | 5 capital A height unsigned |
iforce2d | 0:972874f31c98 | 59 | 6 start 'A' |
iforce2d | 0:972874f31c98 | 60 | 8 start 'a' |
iforce2d | 0:972874f31c98 | 61 | 10 encoding start |
iforce2d | 0:972874f31c98 | 62 | 11 encoding end |
iforce2d | 0:972874f31c98 | 63 | 12 descent 'g' negative: below baseline |
iforce2d | 0:972874f31c98 | 64 | 13 font max ascent |
iforce2d | 0:972874f31c98 | 65 | 14 font min decent negative: below baseline |
iforce2d | 0:972874f31c98 | 66 | 15 font xascent |
iforce2d | 0:972874f31c98 | 67 | 16 font xdecent negative: below baseline |
iforce2d | 0:972874f31c98 | 68 | |
iforce2d | 0:972874f31c98 | 69 | */ |
iforce2d | 0:972874f31c98 | 70 | |
iforce2d | 0:972874f31c98 | 71 | /* use case: What is the width and the height of the minimal box into which string s fints? */ |
iforce2d | 0:972874f31c98 | 72 | void u8g_font_GetStrSize(const void *font, const char *s, u8g_uint_t *width, u8g_uint_t *height); |
iforce2d | 0:972874f31c98 | 73 | void u8g_font_GetStrSizeP(const void *font, const char *s, u8g_uint_t *width, u8g_uint_t *height); |
iforce2d | 0:972874f31c98 | 74 | |
iforce2d | 0:972874f31c98 | 75 | /* use case: lower left edge of a minimal box is known, what is the correct x, y position for the string draw procedure */ |
iforce2d | 0:972874f31c98 | 76 | void u8g_font_AdjustXYToDraw(const void *font, const char *s, u8g_uint_t *x, u8g_uint_t *y); |
iforce2d | 0:972874f31c98 | 77 | void u8g_font_AdjustXYToDrawP(const void *font, const char *s, u8g_uint_t *x, u8g_uint_t *y); |
iforce2d | 0:972874f31c98 | 78 | |
iforce2d | 0:972874f31c98 | 79 | /* use case: Baseline origin known, return minimal box */ |
iforce2d | 0:972874f31c98 | 80 | 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); |
iforce2d | 0:972874f31c98 | 81 | |
iforce2d | 0:972874f31c98 | 82 | /* procedures */ |
iforce2d | 0:972874f31c98 | 83 | |
iforce2d | 0:972874f31c98 | 84 | /*========================================================================*/ |
iforce2d | 0:972874f31c98 | 85 | /* low level byte and word access */ |
iforce2d | 0:972874f31c98 | 86 | |
iforce2d | 0:972874f31c98 | 87 | /* removed NOINLINE, because it leads to smaller code, might also be faster */ |
iforce2d | 0:972874f31c98 | 88 | //static uint8_t u8g_font_get_byte(const u8g_fntpgm_uint8_t *font, uint8_t offset) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 89 | static uint8_t u8g_font_get_byte(const u8g_fntpgm_uint8_t *font, uint8_t offset) |
iforce2d | 0:972874f31c98 | 90 | { |
iforce2d | 0:972874f31c98 | 91 | font += offset; |
iforce2d | 0:972874f31c98 | 92 | return u8g_pgm_read( (u8g_pgm_uint8_t *)font ); |
iforce2d | 0:972874f31c98 | 93 | } |
iforce2d | 0:972874f31c98 | 94 | |
iforce2d | 0:972874f31c98 | 95 | static uint16_t u8g_font_get_word(const u8g_fntpgm_uint8_t *font, uint8_t offset) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 96 | static uint16_t u8g_font_get_word(const u8g_fntpgm_uint8_t *font, uint8_t offset) |
iforce2d | 0:972874f31c98 | 97 | { |
iforce2d | 0:972874f31c98 | 98 | uint16_t pos; |
iforce2d | 0:972874f31c98 | 99 | font += offset; |
iforce2d | 0:972874f31c98 | 100 | pos = u8g_pgm_read( (u8g_pgm_uint8_t *)font ); |
iforce2d | 0:972874f31c98 | 101 | font++; |
iforce2d | 0:972874f31c98 | 102 | pos <<= 8; |
iforce2d | 0:972874f31c98 | 103 | pos += u8g_pgm_read( (u8g_pgm_uint8_t *)font); |
iforce2d | 0:972874f31c98 | 104 | return pos; |
iforce2d | 0:972874f31c98 | 105 | } |
iforce2d | 0:972874f31c98 | 106 | |
iforce2d | 0:972874f31c98 | 107 | /*========================================================================*/ |
iforce2d | 0:972874f31c98 | 108 | /* direct access on the font */ |
iforce2d | 0:972874f31c98 | 109 | |
iforce2d | 0:972874f31c98 | 110 | static uint8_t u8g_font_GetFormat(const u8g_fntpgm_uint8_t *font) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 111 | static uint8_t u8g_font_GetFormat(const u8g_fntpgm_uint8_t *font) |
iforce2d | 0:972874f31c98 | 112 | { |
iforce2d | 0:972874f31c98 | 113 | return u8g_font_get_byte(font, 0); |
iforce2d | 0:972874f31c98 | 114 | } |
iforce2d | 0:972874f31c98 | 115 | |
iforce2d | 0:972874f31c98 | 116 | static uint8_t u8g_font_GetFontGlyphStructureSize(const u8g_fntpgm_uint8_t *font) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 117 | static uint8_t u8g_font_GetFontGlyphStructureSize(const u8g_fntpgm_uint8_t *font) |
iforce2d | 0:972874f31c98 | 118 | { |
iforce2d | 0:972874f31c98 | 119 | switch(u8g_font_GetFormat(font)) |
iforce2d | 0:972874f31c98 | 120 | { |
iforce2d | 0:972874f31c98 | 121 | case 0: return 6; |
iforce2d | 0:972874f31c98 | 122 | case 1: return 3; |
iforce2d | 0:972874f31c98 | 123 | case 2: return 6; |
iforce2d | 0:972874f31c98 | 124 | } |
iforce2d | 0:972874f31c98 | 125 | return 3; |
iforce2d | 0:972874f31c98 | 126 | } |
iforce2d | 0:972874f31c98 | 127 | |
iforce2d | 0:972874f31c98 | 128 | static uint8_t u8g_font_GetBBXWidth(const void *font) |
iforce2d | 0:972874f31c98 | 129 | { |
iforce2d | 0:972874f31c98 | 130 | return u8g_font_get_byte(font, 1); |
iforce2d | 0:972874f31c98 | 131 | } |
iforce2d | 0:972874f31c98 | 132 | |
iforce2d | 0:972874f31c98 | 133 | static uint8_t u8g_font_GetBBXHeight(const void *font) |
iforce2d | 0:972874f31c98 | 134 | { |
iforce2d | 0:972874f31c98 | 135 | return u8g_font_get_byte(font, 2); |
iforce2d | 0:972874f31c98 | 136 | } |
iforce2d | 0:972874f31c98 | 137 | |
iforce2d | 0:972874f31c98 | 138 | static int8_t u8g_font_GetBBXOffX(const void *font) |
iforce2d | 0:972874f31c98 | 139 | { |
iforce2d | 0:972874f31c98 | 140 | return u8g_font_get_byte(font, 3); |
iforce2d | 0:972874f31c98 | 141 | } |
iforce2d | 0:972874f31c98 | 142 | |
iforce2d | 0:972874f31c98 | 143 | static int8_t u8g_font_GetBBXOffY(const void *font) |
iforce2d | 0:972874f31c98 | 144 | { |
iforce2d | 0:972874f31c98 | 145 | return u8g_font_get_byte(font, 4); |
iforce2d | 0:972874f31c98 | 146 | } |
iforce2d | 0:972874f31c98 | 147 | |
iforce2d | 0:972874f31c98 | 148 | uint8_t u8g_font_GetCapitalAHeight(const void *font) |
iforce2d | 0:972874f31c98 | 149 | { |
iforce2d | 0:972874f31c98 | 150 | return u8g_font_get_byte(font, 5); |
iforce2d | 0:972874f31c98 | 151 | } |
iforce2d | 0:972874f31c98 | 152 | |
iforce2d | 0:972874f31c98 | 153 | uint16_t u8g_font_GetEncoding65Pos(const void *font) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 154 | uint16_t u8g_font_GetEncoding65Pos(const void *font) |
iforce2d | 0:972874f31c98 | 155 | { |
iforce2d | 0:972874f31c98 | 156 | return u8g_font_get_word(font, 6); |
iforce2d | 0:972874f31c98 | 157 | } |
iforce2d | 0:972874f31c98 | 158 | |
iforce2d | 0:972874f31c98 | 159 | uint16_t u8g_font_GetEncoding97Pos(const void *font) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 160 | uint16_t u8g_font_GetEncoding97Pos(const void *font) |
iforce2d | 0:972874f31c98 | 161 | { |
iforce2d | 0:972874f31c98 | 162 | return u8g_font_get_word(font, 8); |
iforce2d | 0:972874f31c98 | 163 | } |
iforce2d | 0:972874f31c98 | 164 | |
iforce2d | 0:972874f31c98 | 165 | uint8_t u8g_font_GetFontStartEncoding(const void *font) |
iforce2d | 0:972874f31c98 | 166 | { |
iforce2d | 0:972874f31c98 | 167 | return u8g_font_get_byte(font, 10); |
iforce2d | 0:972874f31c98 | 168 | } |
iforce2d | 0:972874f31c98 | 169 | |
iforce2d | 0:972874f31c98 | 170 | uint8_t u8g_font_GetFontEndEncoding(const void *font) |
iforce2d | 0:972874f31c98 | 171 | { |
iforce2d | 0:972874f31c98 | 172 | return u8g_font_get_byte(font, 11); |
iforce2d | 0:972874f31c98 | 173 | } |
iforce2d | 0:972874f31c98 | 174 | |
iforce2d | 0:972874f31c98 | 175 | int8_t u8g_font_GetLowerGDescent(const void *font) |
iforce2d | 0:972874f31c98 | 176 | { |
iforce2d | 0:972874f31c98 | 177 | return u8g_font_get_byte(font, 12); |
iforce2d | 0:972874f31c98 | 178 | } |
iforce2d | 0:972874f31c98 | 179 | |
iforce2d | 0:972874f31c98 | 180 | int8_t u8g_font_GetFontAscent(const void *font) |
iforce2d | 0:972874f31c98 | 181 | { |
iforce2d | 0:972874f31c98 | 182 | return u8g_font_get_byte(font, 13); |
iforce2d | 0:972874f31c98 | 183 | } |
iforce2d | 0:972874f31c98 | 184 | |
iforce2d | 0:972874f31c98 | 185 | int8_t u8g_font_GetFontDescent(const void *font) |
iforce2d | 0:972874f31c98 | 186 | { |
iforce2d | 0:972874f31c98 | 187 | return u8g_font_get_byte(font, 14); |
iforce2d | 0:972874f31c98 | 188 | } |
iforce2d | 0:972874f31c98 | 189 | |
iforce2d | 0:972874f31c98 | 190 | int8_t u8g_font_GetFontXAscent(const void *font) |
iforce2d | 0:972874f31c98 | 191 | { |
iforce2d | 0:972874f31c98 | 192 | return u8g_font_get_byte(font, 15); |
iforce2d | 0:972874f31c98 | 193 | } |
iforce2d | 0:972874f31c98 | 194 | |
iforce2d | 0:972874f31c98 | 195 | int8_t u8g_font_GetFontXDescent(const void *font) |
iforce2d | 0:972874f31c98 | 196 | { |
iforce2d | 0:972874f31c98 | 197 | return u8g_font_get_byte(font, 16); |
iforce2d | 0:972874f31c98 | 198 | } |
iforce2d | 0:972874f31c98 | 199 | |
iforce2d | 0:972874f31c98 | 200 | |
iforce2d | 0:972874f31c98 | 201 | /* return the data start for a font and the glyph pointer */ |
iforce2d | 0:972874f31c98 | 202 | static uint8_t *u8g_font_GetGlyphDataStart(const void *font, u8g_glyph_t g) |
iforce2d | 0:972874f31c98 | 203 | { |
iforce2d | 0:972874f31c98 | 204 | return ((u8g_fntpgm_uint8_t *)g) + u8g_font_GetFontGlyphStructureSize(font); |
iforce2d | 0:972874f31c98 | 205 | } |
iforce2d | 0:972874f31c98 | 206 | |
iforce2d | 0:972874f31c98 | 207 | /* calculate the overall length of the font, only used to create the picture for the google wiki */ |
iforce2d | 0:972874f31c98 | 208 | size_t u8g_font_GetSize(const void *font) |
iforce2d | 0:972874f31c98 | 209 | { |
iforce2d | 0:972874f31c98 | 210 | uint8_t *p = (uint8_t *)(font); |
iforce2d | 0:972874f31c98 | 211 | uint8_t font_format = u8g_font_GetFormat(font); |
iforce2d | 0:972874f31c98 | 212 | uint8_t data_structure_size = u8g_font_GetFontGlyphStructureSize(font); |
iforce2d | 0:972874f31c98 | 213 | uint8_t start, end; |
iforce2d | 0:972874f31c98 | 214 | uint8_t i; |
iforce2d | 0:972874f31c98 | 215 | uint8_t mask = 255; |
iforce2d | 0:972874f31c98 | 216 | |
iforce2d | 0:972874f31c98 | 217 | start = u8g_font_GetFontStartEncoding(font); |
iforce2d | 0:972874f31c98 | 218 | end = u8g_font_GetFontEndEncoding(font); |
iforce2d | 0:972874f31c98 | 219 | |
iforce2d | 0:972874f31c98 | 220 | if ( font_format == 1 ) |
iforce2d | 0:972874f31c98 | 221 | mask = 15; |
iforce2d | 0:972874f31c98 | 222 | |
iforce2d | 0:972874f31c98 | 223 | p += U8G_FONT_DATA_STRUCT_SIZE; /* skip font general information */ |
iforce2d | 0:972874f31c98 | 224 | |
iforce2d | 0:972874f31c98 | 225 | i = start; |
iforce2d | 0:972874f31c98 | 226 | for(;;) |
iforce2d | 0:972874f31c98 | 227 | { |
iforce2d | 0:972874f31c98 | 228 | if ( u8g_pgm_read((u8g_pgm_uint8_t *)(p)) == 255 ) |
iforce2d | 0:972874f31c98 | 229 | { |
iforce2d | 0:972874f31c98 | 230 | p += 1; |
iforce2d | 0:972874f31c98 | 231 | } |
iforce2d | 0:972874f31c98 | 232 | else |
iforce2d | 0:972874f31c98 | 233 | { |
iforce2d | 0:972874f31c98 | 234 | p += u8g_pgm_read( ((u8g_pgm_uint8_t *)(p)) + 2 ) & mask; |
iforce2d | 0:972874f31c98 | 235 | p += data_structure_size; |
iforce2d | 0:972874f31c98 | 236 | } |
iforce2d | 0:972874f31c98 | 237 | if ( i == end ) |
iforce2d | 0:972874f31c98 | 238 | break; |
iforce2d | 0:972874f31c98 | 239 | i++; |
iforce2d | 0:972874f31c98 | 240 | } |
iforce2d | 0:972874f31c98 | 241 | |
iforce2d | 0:972874f31c98 | 242 | return p - (uint8_t *)font; |
iforce2d | 0:972874f31c98 | 243 | } |
iforce2d | 0:972874f31c98 | 244 | |
iforce2d | 0:972874f31c98 | 245 | /*========================================================================*/ |
iforce2d | 0:972874f31c98 | 246 | /* u8g interface, font access */ |
iforce2d | 0:972874f31c98 | 247 | |
iforce2d | 0:972874f31c98 | 248 | uint8_t u8g_GetFontBBXWidth(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 249 | { |
iforce2d | 0:972874f31c98 | 250 | return u8g_font_GetBBXWidth(u8g->font); |
iforce2d | 0:972874f31c98 | 251 | } |
iforce2d | 0:972874f31c98 | 252 | |
iforce2d | 0:972874f31c98 | 253 | uint8_t u8g_GetFontBBXHeight(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 254 | { |
iforce2d | 0:972874f31c98 | 255 | return u8g_font_GetBBXHeight(u8g->font); |
iforce2d | 0:972874f31c98 | 256 | } |
iforce2d | 0:972874f31c98 | 257 | |
iforce2d | 0:972874f31c98 | 258 | int8_t u8g_GetFontBBXOffX(u8g_t *u8g) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 259 | int8_t u8g_GetFontBBXOffX(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 260 | { |
iforce2d | 0:972874f31c98 | 261 | return u8g_font_GetBBXOffX(u8g->font); |
iforce2d | 0:972874f31c98 | 262 | } |
iforce2d | 0:972874f31c98 | 263 | |
iforce2d | 0:972874f31c98 | 264 | int8_t u8g_GetFontBBXOffY(u8g_t *u8g) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 265 | int8_t u8g_GetFontBBXOffY(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 266 | { |
iforce2d | 0:972874f31c98 | 267 | return u8g_font_GetBBXOffY(u8g->font); |
iforce2d | 0:972874f31c98 | 268 | } |
iforce2d | 0:972874f31c98 | 269 | |
iforce2d | 0:972874f31c98 | 270 | uint8_t u8g_GetFontCapitalAHeight(u8g_t *u8g) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 271 | uint8_t u8g_GetFontCapitalAHeight(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 272 | { |
iforce2d | 0:972874f31c98 | 273 | return u8g_font_GetCapitalAHeight(u8g->font); |
iforce2d | 0:972874f31c98 | 274 | } |
iforce2d | 0:972874f31c98 | 275 | |
iforce2d | 0:972874f31c98 | 276 | /*========================================================================*/ |
iforce2d | 0:972874f31c98 | 277 | /* glyph handling */ |
iforce2d | 0:972874f31c98 | 278 | |
iforce2d | 0:972874f31c98 | 279 | static void u8g_CopyGlyphDataToCache(u8g_t *u8g, u8g_glyph_t g) |
iforce2d | 0:972874f31c98 | 280 | { |
iforce2d | 0:972874f31c98 | 281 | uint8_t tmp; |
iforce2d | 0:972874f31c98 | 282 | switch( u8g_font_GetFormat(u8g->font) ) |
iforce2d | 0:972874f31c98 | 283 | { |
iforce2d | 0:972874f31c98 | 284 | case 0: |
iforce2d | 0:972874f31c98 | 285 | case 2: |
iforce2d | 0:972874f31c98 | 286 | /* |
iforce2d | 0:972874f31c98 | 287 | format 0 |
iforce2d | 0:972874f31c98 | 288 | glyph information |
iforce2d | 0:972874f31c98 | 289 | offset |
iforce2d | 0:972874f31c98 | 290 | 0 BBX width unsigned |
iforce2d | 0:972874f31c98 | 291 | 1 BBX height unsigned |
iforce2d | 0:972874f31c98 | 292 | 2 data size unsigned (BBX width + 7)/8 * BBX height |
iforce2d | 0:972874f31c98 | 293 | 3 DWIDTH signed |
iforce2d | 0:972874f31c98 | 294 | 4 BBX xoffset signed |
iforce2d | 0:972874f31c98 | 295 | 5 BBX yoffset signed |
iforce2d | 0:972874f31c98 | 296 | byte 0 == 255 indicates empty glyph |
iforce2d | 0:972874f31c98 | 297 | */ |
iforce2d | 0:972874f31c98 | 298 | u8g->glyph_width = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 0 ); |
iforce2d | 0:972874f31c98 | 299 | u8g->glyph_height = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 1 ); |
iforce2d | 0:972874f31c98 | 300 | u8g->glyph_dx = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 3 ); |
iforce2d | 0:972874f31c98 | 301 | u8g->glyph_x = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 4 ); |
iforce2d | 0:972874f31c98 | 302 | u8g->glyph_y = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 5 ); |
iforce2d | 0:972874f31c98 | 303 | break; |
iforce2d | 0:972874f31c98 | 304 | case 1: |
iforce2d | 0:972874f31c98 | 305 | default: |
iforce2d | 0:972874f31c98 | 306 | /* |
iforce2d | 0:972874f31c98 | 307 | format 1 |
iforce2d | 0:972874f31c98 | 308 | 0 BBX xoffset signed --> upper 4 Bit |
iforce2d | 0:972874f31c98 | 309 | 0 BBX yoffset signed --> lower 4 Bit |
iforce2d | 0:972874f31c98 | 310 | 1 BBX width unsigned --> upper 4 Bit |
iforce2d | 0:972874f31c98 | 311 | 1 BBX height unsigned --> lower 4 Bit |
iforce2d | 0:972874f31c98 | 312 | 2 data size unsigned -(BBX width + 7)/8 * BBX height --> lower 4 Bit |
iforce2d | 0:972874f31c98 | 313 | 2 DWIDTH signed --> upper 4 Bit |
iforce2d | 0:972874f31c98 | 314 | byte 0 == 255 indicates empty glyph |
iforce2d | 0:972874f31c98 | 315 | */ |
iforce2d | 0:972874f31c98 | 316 | |
iforce2d | 0:972874f31c98 | 317 | tmp = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 0 ); |
iforce2d | 0:972874f31c98 | 318 | u8g->glyph_y = tmp & 15; |
iforce2d | 0:972874f31c98 | 319 | u8g->glyph_y-=2; |
iforce2d | 0:972874f31c98 | 320 | tmp >>= 4; |
iforce2d | 0:972874f31c98 | 321 | u8g->glyph_x = tmp; |
iforce2d | 0:972874f31c98 | 322 | |
iforce2d | 0:972874f31c98 | 323 | tmp = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 1 ); |
iforce2d | 0:972874f31c98 | 324 | u8g->glyph_height = tmp & 15; |
iforce2d | 0:972874f31c98 | 325 | tmp >>= 4; |
iforce2d | 0:972874f31c98 | 326 | u8g->glyph_width = tmp; |
iforce2d | 0:972874f31c98 | 327 | |
iforce2d | 0:972874f31c98 | 328 | tmp = u8g_pgm_read( ((u8g_pgm_uint8_t *)g) + 2 ); |
iforce2d | 0:972874f31c98 | 329 | tmp >>= 4; |
iforce2d | 0:972874f31c98 | 330 | u8g->glyph_dx = tmp; |
iforce2d | 0:972874f31c98 | 331 | |
iforce2d | 0:972874f31c98 | 332 | |
iforce2d | 0:972874f31c98 | 333 | break; |
iforce2d | 0:972874f31c98 | 334 | } |
iforce2d | 0:972874f31c98 | 335 | } |
iforce2d | 0:972874f31c98 | 336 | |
iforce2d | 0:972874f31c98 | 337 | //void u8g_FillEmptyGlyphCache(u8g_t *u8g) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 338 | static void u8g_FillEmptyGlyphCache(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 339 | { |
iforce2d | 0:972874f31c98 | 340 | u8g->glyph_dx = 0; |
iforce2d | 0:972874f31c98 | 341 | u8g->glyph_width = 0; |
iforce2d | 0:972874f31c98 | 342 | u8g->glyph_height = 0; |
iforce2d | 0:972874f31c98 | 343 | u8g->glyph_x = 0; |
iforce2d | 0:972874f31c98 | 344 | u8g->glyph_y = 0; |
iforce2d | 0:972874f31c98 | 345 | } |
iforce2d | 0:972874f31c98 | 346 | |
iforce2d | 0:972874f31c98 | 347 | /* |
iforce2d | 0:972874f31c98 | 348 | Find (with some speed optimization) and return a pointer to the glyph data structure |
iforce2d | 0:972874f31c98 | 349 | Also uncompress (format 1) and copy the content of the data structure to the u8g structure |
iforce2d | 0:972874f31c98 | 350 | */ |
iforce2d | 0:972874f31c98 | 351 | u8g_glyph_t u8g_GetGlyph(u8g_t *u8g, uint8_t requested_encoding) |
iforce2d | 0:972874f31c98 | 352 | { |
iforce2d | 0:972874f31c98 | 353 | uint8_t *p = (uint8_t *)(u8g->font); |
iforce2d | 0:972874f31c98 | 354 | uint8_t font_format = u8g_font_GetFormat(u8g->font); |
iforce2d | 0:972874f31c98 | 355 | uint8_t data_structure_size = u8g_font_GetFontGlyphStructureSize(u8g->font); |
iforce2d | 0:972874f31c98 | 356 | uint8_t start, end; |
iforce2d | 0:972874f31c98 | 357 | uint16_t pos; |
iforce2d | 0:972874f31c98 | 358 | uint8_t i; |
iforce2d | 0:972874f31c98 | 359 | uint8_t mask = 255; |
iforce2d | 0:972874f31c98 | 360 | |
iforce2d | 0:972874f31c98 | 361 | if ( font_format == 1 ) |
iforce2d | 0:972874f31c98 | 362 | mask = 15; |
iforce2d | 0:972874f31c98 | 363 | |
iforce2d | 0:972874f31c98 | 364 | start = u8g_font_GetFontStartEncoding(u8g->font); |
iforce2d | 0:972874f31c98 | 365 | end = u8g_font_GetFontEndEncoding(u8g->font); |
iforce2d | 0:972874f31c98 | 366 | |
iforce2d | 0:972874f31c98 | 367 | pos = u8g_font_GetEncoding97Pos(u8g->font); |
iforce2d | 0:972874f31c98 | 368 | if ( requested_encoding >= 97 && pos > 0 ) |
iforce2d | 0:972874f31c98 | 369 | { |
iforce2d | 0:972874f31c98 | 370 | p+= pos; |
iforce2d | 0:972874f31c98 | 371 | start = 97; |
iforce2d | 0:972874f31c98 | 372 | } |
iforce2d | 0:972874f31c98 | 373 | else |
iforce2d | 0:972874f31c98 | 374 | { |
iforce2d | 0:972874f31c98 | 375 | pos = u8g_font_GetEncoding65Pos(u8g->font); |
iforce2d | 0:972874f31c98 | 376 | if ( requested_encoding >= 65 && pos > 0 ) |
iforce2d | 0:972874f31c98 | 377 | { |
iforce2d | 0:972874f31c98 | 378 | p+= pos; |
iforce2d | 0:972874f31c98 | 379 | start = 65; |
iforce2d | 0:972874f31c98 | 380 | } |
iforce2d | 0:972874f31c98 | 381 | else |
iforce2d | 0:972874f31c98 | 382 | p += U8G_FONT_DATA_STRUCT_SIZE; /* skip font general information */ |
iforce2d | 0:972874f31c98 | 383 | } |
iforce2d | 0:972874f31c98 | 384 | |
iforce2d | 0:972874f31c98 | 385 | if ( requested_encoding > end ) |
iforce2d | 0:972874f31c98 | 386 | { |
iforce2d | 0:972874f31c98 | 387 | u8g_FillEmptyGlyphCache(u8g); |
iforce2d | 0:972874f31c98 | 388 | return NULL; /* not found */ |
iforce2d | 0:972874f31c98 | 389 | } |
iforce2d | 0:972874f31c98 | 390 | |
iforce2d | 0:972874f31c98 | 391 | i = start; |
iforce2d | 0:972874f31c98 | 392 | if ( i <= end ) |
iforce2d | 0:972874f31c98 | 393 | { |
iforce2d | 0:972874f31c98 | 394 | for(;;) |
iforce2d | 0:972874f31c98 | 395 | { |
iforce2d | 0:972874f31c98 | 396 | if ( u8g_pgm_read((u8g_pgm_uint8_t *)(p)) == 255 ) |
iforce2d | 0:972874f31c98 | 397 | { |
iforce2d | 0:972874f31c98 | 398 | p += 1; |
iforce2d | 0:972874f31c98 | 399 | } |
iforce2d | 0:972874f31c98 | 400 | else |
iforce2d | 0:972874f31c98 | 401 | { |
iforce2d | 0:972874f31c98 | 402 | if ( i == requested_encoding ) |
iforce2d | 0:972874f31c98 | 403 | { |
iforce2d | 0:972874f31c98 | 404 | u8g_CopyGlyphDataToCache(u8g, p); |
iforce2d | 0:972874f31c98 | 405 | return p; |
iforce2d | 0:972874f31c98 | 406 | } |
iforce2d | 0:972874f31c98 | 407 | p += u8g_pgm_read( ((u8g_pgm_uint8_t *)(p)) + 2 ) & mask; |
iforce2d | 0:972874f31c98 | 408 | p += data_structure_size; |
iforce2d | 0:972874f31c98 | 409 | } |
iforce2d | 0:972874f31c98 | 410 | if ( i == end ) |
iforce2d | 0:972874f31c98 | 411 | break; |
iforce2d | 0:972874f31c98 | 412 | i++; |
iforce2d | 0:972874f31c98 | 413 | } |
iforce2d | 0:972874f31c98 | 414 | } |
iforce2d | 0:972874f31c98 | 415 | |
iforce2d | 0:972874f31c98 | 416 | u8g_FillEmptyGlyphCache(u8g); |
iforce2d | 0:972874f31c98 | 417 | |
iforce2d | 0:972874f31c98 | 418 | return NULL; |
iforce2d | 0:972874f31c98 | 419 | } |
iforce2d | 0:972874f31c98 | 420 | |
iforce2d | 0:972874f31c98 | 421 | uint8_t u8g_IsGlyph(u8g_t *u8g, uint8_t requested_encoding) |
iforce2d | 0:972874f31c98 | 422 | { |
iforce2d | 0:972874f31c98 | 423 | if ( u8g_GetGlyph(u8g, requested_encoding) != NULL ) |
iforce2d | 0:972874f31c98 | 424 | return 1; |
iforce2d | 0:972874f31c98 | 425 | return 0; |
iforce2d | 0:972874f31c98 | 426 | } |
iforce2d | 0:972874f31c98 | 427 | |
iforce2d | 0:972874f31c98 | 428 | int8_t u8g_GetGlyphDeltaX(u8g_t *u8g, uint8_t requested_encoding) |
iforce2d | 0:972874f31c98 | 429 | { |
iforce2d | 0:972874f31c98 | 430 | if ( u8g_GetGlyph(u8g, requested_encoding) == NULL ) |
iforce2d | 0:972874f31c98 | 431 | return 0; /* should never happen, so return something */ |
iforce2d | 0:972874f31c98 | 432 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 433 | } |
iforce2d | 0:972874f31c98 | 434 | |
iforce2d | 0:972874f31c98 | 435 | |
iforce2d | 0:972874f31c98 | 436 | /*========================================================================*/ |
iforce2d | 0:972874f31c98 | 437 | /* glyph drawing procedures */ |
iforce2d | 0:972874f31c98 | 438 | |
iforce2d | 0:972874f31c98 | 439 | #ifdef OBSOLETE |
iforce2d | 0:972874f31c98 | 440 | /* |
iforce2d | 0:972874f31c98 | 441 | Draw a glyph |
iforce2d | 0:972874f31c98 | 442 | x,y: left baseline position of the glyph |
iforce2d | 0:972874f31c98 | 443 | */ |
iforce2d | 0:972874f31c98 | 444 | int8_t u8g_DrawGlyphDir(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t encoding) |
iforce2d | 0:972874f31c98 | 445 | { |
iforce2d | 0:972874f31c98 | 446 | u8g_glyph_t g; |
iforce2d | 0:972874f31c98 | 447 | uint8_t w, h, i, j; |
iforce2d | 0:972874f31c98 | 448 | const u8g_pgm_uint8_t *data; |
iforce2d | 0:972874f31c98 | 449 | uint8_t bytes_per_line; |
iforce2d | 0:972874f31c98 | 450 | u8g_uint_t ix, iy; |
iforce2d | 0:972874f31c98 | 451 | |
iforce2d | 0:972874f31c98 | 452 | g = u8g_GetGlyph(u8g, encoding); |
iforce2d | 0:972874f31c98 | 453 | if ( g == NULL ) |
iforce2d | 0:972874f31c98 | 454 | return 0; |
iforce2d | 0:972874f31c98 | 455 | w = u8g->glyph_width; |
iforce2d | 0:972874f31c98 | 456 | h = u8g->glyph_height; |
iforce2d | 0:972874f31c98 | 457 | |
iforce2d | 0:972874f31c98 | 458 | bytes_per_line = w; |
iforce2d | 0:972874f31c98 | 459 | bytes_per_line += 7; |
iforce2d | 0:972874f31c98 | 460 | bytes_per_line /= 8; |
iforce2d | 0:972874f31c98 | 461 | |
iforce2d | 0:972874f31c98 | 462 | data = u8g_font_GetGlyphDataStart(u8g->font, g); |
iforce2d | 0:972874f31c98 | 463 | |
iforce2d | 0:972874f31c98 | 464 | switch(dir) |
iforce2d | 0:972874f31c98 | 465 | { |
iforce2d | 0:972874f31c98 | 466 | case 0: |
iforce2d | 0:972874f31c98 | 467 | x += u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 468 | y -= u8g->glyph_y; |
iforce2d | 0:972874f31c98 | 469 | y--; |
iforce2d | 0:972874f31c98 | 470 | //u8g_DrawFrame(u8g, x, y-h+1, w, h); |
iforce2d | 0:972874f31c98 | 471 | if ( u8g_IsBBXIntersection(u8g, x, y-h+1, w, h) == 0 ) |
iforce2d | 0:972874f31c98 | 472 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 473 | |
iforce2d | 0:972874f31c98 | 474 | iy = y; |
iforce2d | 0:972874f31c98 | 475 | iy -= h; |
iforce2d | 0:972874f31c98 | 476 | iy++; |
iforce2d | 0:972874f31c98 | 477 | |
iforce2d | 0:972874f31c98 | 478 | for( j = 0; j < h; j++ ) |
iforce2d | 0:972874f31c98 | 479 | { |
iforce2d | 0:972874f31c98 | 480 | ix = x; |
iforce2d | 0:972874f31c98 | 481 | for( i = 0; i < bytes_per_line; i++ ) |
iforce2d | 0:972874f31c98 | 482 | { |
iforce2d | 0:972874f31c98 | 483 | u8g_Draw8Pixel(u8g, ix, iy, dir, u8g_pgm_read(data)); |
iforce2d | 0:972874f31c98 | 484 | data++; |
iforce2d | 0:972874f31c98 | 485 | ix+=8; |
iforce2d | 0:972874f31c98 | 486 | } |
iforce2d | 0:972874f31c98 | 487 | iy++; |
iforce2d | 0:972874f31c98 | 488 | } |
iforce2d | 0:972874f31c98 | 489 | break; |
iforce2d | 0:972874f31c98 | 490 | case 1: |
iforce2d | 0:972874f31c98 | 491 | x += u8g->glyph_y; |
iforce2d | 0:972874f31c98 | 492 | x++; |
iforce2d | 0:972874f31c98 | 493 | y += u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 494 | //printf("enc %d, dir %d, x %d, y %d, w %d, h %d\n", encoding, dir, x, y, w, h); |
iforce2d | 0:972874f31c98 | 495 | //u8g_DrawFrame(u8g, x, y, h, w); |
iforce2d | 0:972874f31c98 | 496 | if ( u8g_IsBBXIntersection(u8g, x, y, h, w) == 0 ) |
iforce2d | 0:972874f31c98 | 497 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 498 | |
iforce2d | 0:972874f31c98 | 499 | ix = x; |
iforce2d | 0:972874f31c98 | 500 | ix += h; |
iforce2d | 0:972874f31c98 | 501 | ix--; |
iforce2d | 0:972874f31c98 | 502 | for( j = 0; j < h; j++ ) |
iforce2d | 0:972874f31c98 | 503 | { |
iforce2d | 0:972874f31c98 | 504 | iy = y; |
iforce2d | 0:972874f31c98 | 505 | for( i = 0; i < bytes_per_line; i++ ) |
iforce2d | 0:972874f31c98 | 506 | { |
iforce2d | 0:972874f31c98 | 507 | u8g_Draw8Pixel(u8g, ix, iy, dir, u8g_pgm_read(data)); |
iforce2d | 0:972874f31c98 | 508 | data++; |
iforce2d | 0:972874f31c98 | 509 | iy+=8; |
iforce2d | 0:972874f31c98 | 510 | } |
iforce2d | 0:972874f31c98 | 511 | ix--; |
iforce2d | 0:972874f31c98 | 512 | } |
iforce2d | 0:972874f31c98 | 513 | break; |
iforce2d | 0:972874f31c98 | 514 | case 2: |
iforce2d | 0:972874f31c98 | 515 | x -= u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 516 | y += u8g->glyph_y; |
iforce2d | 0:972874f31c98 | 517 | y++; |
iforce2d | 0:972874f31c98 | 518 | if ( u8g_IsBBXIntersection(u8g, x-w-1, y, w, h) == 0 ) |
iforce2d | 0:972874f31c98 | 519 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 520 | |
iforce2d | 0:972874f31c98 | 521 | iy = y; |
iforce2d | 0:972874f31c98 | 522 | iy += h; |
iforce2d | 0:972874f31c98 | 523 | iy--; |
iforce2d | 0:972874f31c98 | 524 | for( j = 0; j < h; j++ ) |
iforce2d | 0:972874f31c98 | 525 | { |
iforce2d | 0:972874f31c98 | 526 | ix = x; |
iforce2d | 0:972874f31c98 | 527 | for( i = 0; i < bytes_per_line; i++ ) |
iforce2d | 0:972874f31c98 | 528 | { |
iforce2d | 0:972874f31c98 | 529 | u8g_Draw8Pixel(u8g, ix, iy, dir, u8g_pgm_read(data)); |
iforce2d | 0:972874f31c98 | 530 | data++; |
iforce2d | 0:972874f31c98 | 531 | ix-=8; |
iforce2d | 0:972874f31c98 | 532 | } |
iforce2d | 0:972874f31c98 | 533 | iy--; |
iforce2d | 0:972874f31c98 | 534 | } |
iforce2d | 0:972874f31c98 | 535 | break; |
iforce2d | 0:972874f31c98 | 536 | case 3: |
iforce2d | 0:972874f31c98 | 537 | x -= u8g->glyph_y; |
iforce2d | 0:972874f31c98 | 538 | x--; |
iforce2d | 0:972874f31c98 | 539 | y -= u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 540 | |
iforce2d | 0:972874f31c98 | 541 | if ( u8g_IsBBXIntersection(u8g, x-h-1, y-w-1, h, w) == 0 ) |
iforce2d | 0:972874f31c98 | 542 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 543 | |
iforce2d | 0:972874f31c98 | 544 | ix = x; |
iforce2d | 0:972874f31c98 | 545 | ix -= h; |
iforce2d | 0:972874f31c98 | 546 | ix++; |
iforce2d | 0:972874f31c98 | 547 | |
iforce2d | 0:972874f31c98 | 548 | for( j = 0; j < h; j++ ) |
iforce2d | 0:972874f31c98 | 549 | { |
iforce2d | 0:972874f31c98 | 550 | iy = y; |
iforce2d | 0:972874f31c98 | 551 | for( i = 0; i < bytes_per_line; i++ ) |
iforce2d | 0:972874f31c98 | 552 | { |
iforce2d | 0:972874f31c98 | 553 | u8g_Draw8Pixel(u8g, ix, iy, dir, u8g_pgm_read(data)); |
iforce2d | 0:972874f31c98 | 554 | data++; |
iforce2d | 0:972874f31c98 | 555 | iy-=8; |
iforce2d | 0:972874f31c98 | 556 | } |
iforce2d | 0:972874f31c98 | 557 | ix++; |
iforce2d | 0:972874f31c98 | 558 | } |
iforce2d | 0:972874f31c98 | 559 | break; |
iforce2d | 0:972874f31c98 | 560 | } |
iforce2d | 0:972874f31c98 | 561 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 562 | } |
iforce2d | 0:972874f31c98 | 563 | #endif |
iforce2d | 0:972874f31c98 | 564 | |
iforce2d | 0:972874f31c98 | 565 | int8_t u8g_draw_glyph(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding) |
iforce2d | 0:972874f31c98 | 566 | { |
iforce2d | 0:972874f31c98 | 567 | const u8g_pgm_uint8_t *data; |
iforce2d | 0:972874f31c98 | 568 | uint8_t w, h; |
iforce2d | 0:972874f31c98 | 569 | uint8_t i, j; |
iforce2d | 0:972874f31c98 | 570 | u8g_uint_t ix, iy; |
iforce2d | 0:972874f31c98 | 571 | |
iforce2d | 0:972874f31c98 | 572 | { |
iforce2d | 0:972874f31c98 | 573 | u8g_glyph_t g = u8g_GetGlyph(u8g, encoding); |
iforce2d | 0:972874f31c98 | 574 | if ( g == NULL ) |
iforce2d | 0:972874f31c98 | 575 | return 0; |
iforce2d | 0:972874f31c98 | 576 | data = u8g_font_GetGlyphDataStart(u8g->font, g); |
iforce2d | 0:972874f31c98 | 577 | } |
iforce2d | 0:972874f31c98 | 578 | |
iforce2d | 0:972874f31c98 | 579 | w = u8g->glyph_width; |
iforce2d | 0:972874f31c98 | 580 | h = u8g->glyph_height; |
iforce2d | 0:972874f31c98 | 581 | |
iforce2d | 0:972874f31c98 | 582 | x += u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 583 | y -= u8g->glyph_y; |
iforce2d | 0:972874f31c98 | 584 | y--; |
iforce2d | 0:972874f31c98 | 585 | |
iforce2d | 0:972874f31c98 | 586 | if ( u8g_IsBBXIntersection(u8g, x, y-h+1, w, h) == 0 ) |
iforce2d | 0:972874f31c98 | 587 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 588 | |
iforce2d | 0:972874f31c98 | 589 | /* now, w is reused as bytes per line */ |
iforce2d | 0:972874f31c98 | 590 | w += 7; |
iforce2d | 0:972874f31c98 | 591 | w /= 8; |
iforce2d | 0:972874f31c98 | 592 | |
iforce2d | 0:972874f31c98 | 593 | iy = y; |
iforce2d | 0:972874f31c98 | 594 | iy -= h; |
iforce2d | 0:972874f31c98 | 595 | iy++; |
iforce2d | 0:972874f31c98 | 596 | |
iforce2d | 0:972874f31c98 | 597 | for( j = 0; j < h; j++ ) |
iforce2d | 0:972874f31c98 | 598 | { |
iforce2d | 0:972874f31c98 | 599 | ix = x; |
iforce2d | 0:972874f31c98 | 600 | for( i = 0; i < w; i++ ) |
iforce2d | 0:972874f31c98 | 601 | { |
iforce2d | 0:972874f31c98 | 602 | u8g_Draw8Pixel(u8g, ix, iy, 0, u8g_pgm_read(data)); |
iforce2d | 0:972874f31c98 | 603 | data++; |
iforce2d | 0:972874f31c98 | 604 | ix+=8; |
iforce2d | 0:972874f31c98 | 605 | } |
iforce2d | 0:972874f31c98 | 606 | iy++; |
iforce2d | 0:972874f31c98 | 607 | } |
iforce2d | 0:972874f31c98 | 608 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 609 | } |
iforce2d | 0:972874f31c98 | 610 | |
iforce2d | 0:972874f31c98 | 611 | int8_t u8g_DrawGlyph(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding) |
iforce2d | 0:972874f31c98 | 612 | { |
iforce2d | 0:972874f31c98 | 613 | y += u8g->font_calc_vref(u8g); |
iforce2d | 0:972874f31c98 | 614 | return u8g_draw_glyph(u8g, x, y, encoding); |
iforce2d | 0:972874f31c98 | 615 | } |
iforce2d | 0:972874f31c98 | 616 | |
iforce2d | 0:972874f31c98 | 617 | int8_t u8g_draw_glyph90(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding) |
iforce2d | 0:972874f31c98 | 618 | { |
iforce2d | 0:972874f31c98 | 619 | const u8g_pgm_uint8_t *data; |
iforce2d | 0:972874f31c98 | 620 | uint8_t w, h; |
iforce2d | 0:972874f31c98 | 621 | uint8_t i, j; |
iforce2d | 0:972874f31c98 | 622 | u8g_uint_t ix, iy; |
iforce2d | 0:972874f31c98 | 623 | |
iforce2d | 0:972874f31c98 | 624 | { |
iforce2d | 0:972874f31c98 | 625 | u8g_glyph_t g = u8g_GetGlyph(u8g, encoding); |
iforce2d | 0:972874f31c98 | 626 | if ( g == NULL ) |
iforce2d | 0:972874f31c98 | 627 | return 0; |
iforce2d | 0:972874f31c98 | 628 | data = u8g_font_GetGlyphDataStart(u8g->font, g); |
iforce2d | 0:972874f31c98 | 629 | } |
iforce2d | 0:972874f31c98 | 630 | |
iforce2d | 0:972874f31c98 | 631 | w = u8g->glyph_width; |
iforce2d | 0:972874f31c98 | 632 | h = u8g->glyph_height; |
iforce2d | 0:972874f31c98 | 633 | |
iforce2d | 0:972874f31c98 | 634 | x += u8g->glyph_y; |
iforce2d | 0:972874f31c98 | 635 | x++; |
iforce2d | 0:972874f31c98 | 636 | y += u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 637 | |
iforce2d | 0:972874f31c98 | 638 | if ( u8g_IsBBXIntersection(u8g, x, y, h, w) == 0 ) |
iforce2d | 0:972874f31c98 | 639 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 640 | |
iforce2d | 0:972874f31c98 | 641 | /* now, w is reused as bytes per line */ |
iforce2d | 0:972874f31c98 | 642 | w += 7; |
iforce2d | 0:972874f31c98 | 643 | w /= 8; |
iforce2d | 0:972874f31c98 | 644 | |
iforce2d | 0:972874f31c98 | 645 | ix = x; |
iforce2d | 0:972874f31c98 | 646 | ix += h; |
iforce2d | 0:972874f31c98 | 647 | ix--; |
iforce2d | 0:972874f31c98 | 648 | for( j = 0; j < h; j++ ) |
iforce2d | 0:972874f31c98 | 649 | { |
iforce2d | 0:972874f31c98 | 650 | iy = y; |
iforce2d | 0:972874f31c98 | 651 | for( i = 0; i < w; i++ ) |
iforce2d | 0:972874f31c98 | 652 | { |
iforce2d | 0:972874f31c98 | 653 | u8g_Draw8Pixel(u8g, ix, iy, 1, u8g_pgm_read(data)); |
iforce2d | 0:972874f31c98 | 654 | data++; |
iforce2d | 0:972874f31c98 | 655 | iy+=8; |
iforce2d | 0:972874f31c98 | 656 | } |
iforce2d | 0:972874f31c98 | 657 | ix--; |
iforce2d | 0:972874f31c98 | 658 | } |
iforce2d | 0:972874f31c98 | 659 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 660 | } |
iforce2d | 0:972874f31c98 | 661 | |
iforce2d | 0:972874f31c98 | 662 | int8_t u8g_DrawGlyph90(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding) |
iforce2d | 0:972874f31c98 | 663 | { |
iforce2d | 0:972874f31c98 | 664 | x -= u8g->font_calc_vref(u8g); |
iforce2d | 0:972874f31c98 | 665 | return u8g_draw_glyph90(u8g, x, y, encoding); |
iforce2d | 0:972874f31c98 | 666 | } |
iforce2d | 0:972874f31c98 | 667 | |
iforce2d | 0:972874f31c98 | 668 | |
iforce2d | 0:972874f31c98 | 669 | int8_t u8g_draw_glyph180(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding) |
iforce2d | 0:972874f31c98 | 670 | { |
iforce2d | 0:972874f31c98 | 671 | const u8g_pgm_uint8_t *data; |
iforce2d | 0:972874f31c98 | 672 | uint8_t w, h; |
iforce2d | 0:972874f31c98 | 673 | uint8_t i, j; |
iforce2d | 0:972874f31c98 | 674 | u8g_uint_t ix, iy; |
iforce2d | 0:972874f31c98 | 675 | |
iforce2d | 0:972874f31c98 | 676 | { |
iforce2d | 0:972874f31c98 | 677 | u8g_glyph_t g = u8g_GetGlyph(u8g, encoding); |
iforce2d | 0:972874f31c98 | 678 | if ( g == NULL ) |
iforce2d | 0:972874f31c98 | 679 | return 0; |
iforce2d | 0:972874f31c98 | 680 | data = u8g_font_GetGlyphDataStart(u8g->font, g); |
iforce2d | 0:972874f31c98 | 681 | } |
iforce2d | 0:972874f31c98 | 682 | |
iforce2d | 0:972874f31c98 | 683 | w = u8g->glyph_width; |
iforce2d | 0:972874f31c98 | 684 | h = u8g->glyph_height; |
iforce2d | 0:972874f31c98 | 685 | |
iforce2d | 0:972874f31c98 | 686 | x -= u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 687 | y += u8g->glyph_y; |
iforce2d | 0:972874f31c98 | 688 | y++; |
iforce2d | 0:972874f31c98 | 689 | |
iforce2d | 0:972874f31c98 | 690 | if ( u8g_IsBBXIntersection(u8g, x-(w-1), y, w, h) == 0 ) |
iforce2d | 0:972874f31c98 | 691 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 692 | |
iforce2d | 0:972874f31c98 | 693 | /* now, w is reused as bytes per line */ |
iforce2d | 0:972874f31c98 | 694 | w += 7; |
iforce2d | 0:972874f31c98 | 695 | w /= 8; |
iforce2d | 0:972874f31c98 | 696 | |
iforce2d | 0:972874f31c98 | 697 | iy = y; |
iforce2d | 0:972874f31c98 | 698 | iy += h; |
iforce2d | 0:972874f31c98 | 699 | iy--; |
iforce2d | 0:972874f31c98 | 700 | for( j = 0; j < h; j++ ) |
iforce2d | 0:972874f31c98 | 701 | { |
iforce2d | 0:972874f31c98 | 702 | ix = x; |
iforce2d | 0:972874f31c98 | 703 | for( i = 0; i < w; i++ ) |
iforce2d | 0:972874f31c98 | 704 | { |
iforce2d | 0:972874f31c98 | 705 | u8g_Draw8Pixel(u8g, ix, iy, 2, u8g_pgm_read(data)); |
iforce2d | 0:972874f31c98 | 706 | data++; |
iforce2d | 0:972874f31c98 | 707 | ix-=8; |
iforce2d | 0:972874f31c98 | 708 | } |
iforce2d | 0:972874f31c98 | 709 | iy--; |
iforce2d | 0:972874f31c98 | 710 | } |
iforce2d | 0:972874f31c98 | 711 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 712 | } |
iforce2d | 0:972874f31c98 | 713 | |
iforce2d | 0:972874f31c98 | 714 | int8_t u8g_DrawGlyph180(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding) |
iforce2d | 0:972874f31c98 | 715 | { |
iforce2d | 0:972874f31c98 | 716 | y -= u8g->font_calc_vref(u8g); |
iforce2d | 0:972874f31c98 | 717 | return u8g_draw_glyph180(u8g, x, y, encoding); |
iforce2d | 0:972874f31c98 | 718 | } |
iforce2d | 0:972874f31c98 | 719 | |
iforce2d | 0:972874f31c98 | 720 | |
iforce2d | 0:972874f31c98 | 721 | int8_t u8g_draw_glyph270(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding) |
iforce2d | 0:972874f31c98 | 722 | { |
iforce2d | 0:972874f31c98 | 723 | const u8g_pgm_uint8_t *data; |
iforce2d | 0:972874f31c98 | 724 | uint8_t w, h; |
iforce2d | 0:972874f31c98 | 725 | uint8_t i, j; |
iforce2d | 0:972874f31c98 | 726 | u8g_uint_t ix, iy; |
iforce2d | 0:972874f31c98 | 727 | |
iforce2d | 0:972874f31c98 | 728 | { |
iforce2d | 0:972874f31c98 | 729 | u8g_glyph_t g = u8g_GetGlyph(u8g, encoding); |
iforce2d | 0:972874f31c98 | 730 | if ( g == NULL ) |
iforce2d | 0:972874f31c98 | 731 | return 0; |
iforce2d | 0:972874f31c98 | 732 | data = u8g_font_GetGlyphDataStart(u8g->font, g); |
iforce2d | 0:972874f31c98 | 733 | } |
iforce2d | 0:972874f31c98 | 734 | |
iforce2d | 0:972874f31c98 | 735 | w = u8g->glyph_width; |
iforce2d | 0:972874f31c98 | 736 | h = u8g->glyph_height; |
iforce2d | 0:972874f31c98 | 737 | |
iforce2d | 0:972874f31c98 | 738 | x -= u8g->glyph_y; |
iforce2d | 0:972874f31c98 | 739 | x--; |
iforce2d | 0:972874f31c98 | 740 | y -= u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 741 | |
iforce2d | 0:972874f31c98 | 742 | if ( u8g_IsBBXIntersection(u8g, x-(h-1), y-(w-1), h, w) == 0 ) |
iforce2d | 0:972874f31c98 | 743 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 744 | |
iforce2d | 0:972874f31c98 | 745 | |
iforce2d | 0:972874f31c98 | 746 | /* now, w is reused as bytes per line */ |
iforce2d | 0:972874f31c98 | 747 | w += 7; |
iforce2d | 0:972874f31c98 | 748 | w /= 8; |
iforce2d | 0:972874f31c98 | 749 | |
iforce2d | 0:972874f31c98 | 750 | ix = x; |
iforce2d | 0:972874f31c98 | 751 | ix -= h; |
iforce2d | 0:972874f31c98 | 752 | ix++; |
iforce2d | 0:972874f31c98 | 753 | |
iforce2d | 0:972874f31c98 | 754 | for( j = 0; j < h; j++ ) |
iforce2d | 0:972874f31c98 | 755 | { |
iforce2d | 0:972874f31c98 | 756 | iy = y; |
iforce2d | 0:972874f31c98 | 757 | for( i = 0; i < w; i++ ) |
iforce2d | 0:972874f31c98 | 758 | { |
iforce2d | 0:972874f31c98 | 759 | u8g_Draw8Pixel(u8g, ix, iy, 3, u8g_pgm_read(data)); |
iforce2d | 0:972874f31c98 | 760 | data++; |
iforce2d | 0:972874f31c98 | 761 | iy-=8; |
iforce2d | 0:972874f31c98 | 762 | } |
iforce2d | 0:972874f31c98 | 763 | ix++; |
iforce2d | 0:972874f31c98 | 764 | } |
iforce2d | 0:972874f31c98 | 765 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 766 | } |
iforce2d | 0:972874f31c98 | 767 | |
iforce2d | 0:972874f31c98 | 768 | int8_t u8g_DrawGlyph270(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding) |
iforce2d | 0:972874f31c98 | 769 | { |
iforce2d | 0:972874f31c98 | 770 | x += u8g->font_calc_vref(u8g); |
iforce2d | 0:972874f31c98 | 771 | return u8g_draw_glyph270(u8g, x, y, encoding); |
iforce2d | 0:972874f31c98 | 772 | } |
iforce2d | 0:972874f31c98 | 773 | |
iforce2d | 0:972874f31c98 | 774 | |
iforce2d | 0:972874f31c98 | 775 | |
iforce2d | 0:972874f31c98 | 776 | #ifdef OBSOLETE |
iforce2d | 0:972874f31c98 | 777 | /* |
iforce2d | 0:972874f31c98 | 778 | Draw a glyph |
iforce2d | 0:972874f31c98 | 779 | x,y: lower left corner of the font bounding box |
iforce2d | 0:972874f31c98 | 780 | */ |
iforce2d | 0:972874f31c98 | 781 | int8_t u8g_DrawGlyphFontBBX(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t encoding) |
iforce2d | 0:972874f31c98 | 782 | { |
iforce2d | 0:972874f31c98 | 783 | /* TODO: apply "dir" */ |
iforce2d | 0:972874f31c98 | 784 | x -= u8g_GetFontBBXOffX(u8g); |
iforce2d | 0:972874f31c98 | 785 | y += u8g_GetFontBBXOffY(u8g); |
iforce2d | 0:972874f31c98 | 786 | return u8g_DrawGlyphDir(u8g, x, y, dir, encoding); |
iforce2d | 0:972874f31c98 | 787 | } |
iforce2d | 0:972874f31c98 | 788 | #endif |
iforce2d | 0:972874f31c98 | 789 | |
iforce2d | 0:972874f31c98 | 790 | /*========================================================================*/ |
iforce2d | 0:972874f31c98 | 791 | /* string drawing procedures */ |
iforce2d | 0:972874f31c98 | 792 | |
iforce2d | 0:972874f31c98 | 793 | |
iforce2d | 0:972874f31c98 | 794 | u8g_uint_t u8g_DrawStr(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s) |
iforce2d | 0:972874f31c98 | 795 | { |
iforce2d | 0:972874f31c98 | 796 | u8g_uint_t t = 0; |
iforce2d | 0:972874f31c98 | 797 | int8_t d; |
iforce2d | 0:972874f31c98 | 798 | |
iforce2d | 0:972874f31c98 | 799 | //u8g_uint_t u8g_GetStrWidth(u8g, s); |
iforce2d | 0:972874f31c98 | 800 | //u8g_font_GetFontAscent(u8g->font)-u8g_font_GetFontDescent(u8g->font); |
iforce2d | 0:972874f31c98 | 801 | |
iforce2d | 0:972874f31c98 | 802 | y += u8g->font_calc_vref(u8g); |
iforce2d | 0:972874f31c98 | 803 | |
iforce2d | 0:972874f31c98 | 804 | while( *s != '\0' ) |
iforce2d | 0:972874f31c98 | 805 | { |
iforce2d | 0:972874f31c98 | 806 | d = u8g_draw_glyph(u8g, x, y, *s); |
iforce2d | 0:972874f31c98 | 807 | x += d; |
iforce2d | 0:972874f31c98 | 808 | t += d; |
iforce2d | 0:972874f31c98 | 809 | s++; |
iforce2d | 0:972874f31c98 | 810 | } |
iforce2d | 0:972874f31c98 | 811 | return t; |
iforce2d | 0:972874f31c98 | 812 | } |
iforce2d | 0:972874f31c98 | 813 | |
iforce2d | 0:972874f31c98 | 814 | u8g_uint_t u8g_DrawStr90(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s) |
iforce2d | 0:972874f31c98 | 815 | { |
iforce2d | 0:972874f31c98 | 816 | u8g_uint_t t = 0; |
iforce2d | 0:972874f31c98 | 817 | int8_t d; |
iforce2d | 0:972874f31c98 | 818 | |
iforce2d | 0:972874f31c98 | 819 | x -= u8g->font_calc_vref(u8g); |
iforce2d | 0:972874f31c98 | 820 | |
iforce2d | 0:972874f31c98 | 821 | while( *s != '\0' ) |
iforce2d | 0:972874f31c98 | 822 | { |
iforce2d | 0:972874f31c98 | 823 | d = u8g_draw_glyph90(u8g, x, y, *s); |
iforce2d | 0:972874f31c98 | 824 | y += d; |
iforce2d | 0:972874f31c98 | 825 | t += d; |
iforce2d | 0:972874f31c98 | 826 | s++; |
iforce2d | 0:972874f31c98 | 827 | } |
iforce2d | 0:972874f31c98 | 828 | return t; |
iforce2d | 0:972874f31c98 | 829 | } |
iforce2d | 0:972874f31c98 | 830 | |
iforce2d | 0:972874f31c98 | 831 | u8g_uint_t u8g_DrawStr180(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s) |
iforce2d | 0:972874f31c98 | 832 | { |
iforce2d | 0:972874f31c98 | 833 | u8g_uint_t t = 0; |
iforce2d | 0:972874f31c98 | 834 | int8_t d; |
iforce2d | 0:972874f31c98 | 835 | |
iforce2d | 0:972874f31c98 | 836 | y -= u8g->font_calc_vref(u8g); |
iforce2d | 0:972874f31c98 | 837 | |
iforce2d | 0:972874f31c98 | 838 | while( *s != '\0' ) |
iforce2d | 0:972874f31c98 | 839 | { |
iforce2d | 0:972874f31c98 | 840 | d = u8g_draw_glyph180(u8g, x, y, *s); |
iforce2d | 0:972874f31c98 | 841 | x -= d; |
iforce2d | 0:972874f31c98 | 842 | t += d; |
iforce2d | 0:972874f31c98 | 843 | s++; |
iforce2d | 0:972874f31c98 | 844 | } |
iforce2d | 0:972874f31c98 | 845 | return t; |
iforce2d | 0:972874f31c98 | 846 | } |
iforce2d | 0:972874f31c98 | 847 | |
iforce2d | 0:972874f31c98 | 848 | u8g_uint_t u8g_DrawStr270(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s) |
iforce2d | 0:972874f31c98 | 849 | { |
iforce2d | 0:972874f31c98 | 850 | u8g_uint_t t = 0; |
iforce2d | 0:972874f31c98 | 851 | int8_t d; |
iforce2d | 0:972874f31c98 | 852 | |
iforce2d | 0:972874f31c98 | 853 | x += u8g->font_calc_vref(u8g); |
iforce2d | 0:972874f31c98 | 854 | |
iforce2d | 0:972874f31c98 | 855 | while( *s != '\0' ) |
iforce2d | 0:972874f31c98 | 856 | { |
iforce2d | 0:972874f31c98 | 857 | d = u8g_draw_glyph270(u8g, x, y, *s); |
iforce2d | 0:972874f31c98 | 858 | y -= d; |
iforce2d | 0:972874f31c98 | 859 | t += d; |
iforce2d | 0:972874f31c98 | 860 | s++; |
iforce2d | 0:972874f31c98 | 861 | } |
iforce2d | 0:972874f31c98 | 862 | return t; |
iforce2d | 0:972874f31c98 | 863 | } |
iforce2d | 0:972874f31c98 | 864 | |
iforce2d | 0:972874f31c98 | 865 | u8g_uint_t u8g_DrawStrDir(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, const char *s) |
iforce2d | 0:972874f31c98 | 866 | { |
iforce2d | 0:972874f31c98 | 867 | switch(dir) |
iforce2d | 0:972874f31c98 | 868 | { |
iforce2d | 0:972874f31c98 | 869 | case 0: |
iforce2d | 0:972874f31c98 | 870 | return u8g_DrawStr(u8g, x, y, s); |
iforce2d | 0:972874f31c98 | 871 | case 1: |
iforce2d | 0:972874f31c98 | 872 | return u8g_DrawStr90(u8g, x, y, s); |
iforce2d | 0:972874f31c98 | 873 | case 2: |
iforce2d | 0:972874f31c98 | 874 | return u8g_DrawStr180(u8g, x, y, s); |
iforce2d | 0:972874f31c98 | 875 | case 3: |
iforce2d | 0:972874f31c98 | 876 | return u8g_DrawStr270(u8g, x, y, s); |
iforce2d | 0:972874f31c98 | 877 | } |
iforce2d | 0:972874f31c98 | 878 | return 0; |
iforce2d | 0:972874f31c98 | 879 | } |
iforce2d | 0:972874f31c98 | 880 | |
iforce2d | 0:972874f31c98 | 881 | u8g_uint_t u8g_DrawStrP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s) |
iforce2d | 0:972874f31c98 | 882 | { |
iforce2d | 0:972874f31c98 | 883 | u8g_uint_t t = 0; |
iforce2d | 0:972874f31c98 | 884 | int8_t d; |
iforce2d | 0:972874f31c98 | 885 | uint8_t c; |
iforce2d | 0:972874f31c98 | 886 | |
iforce2d | 0:972874f31c98 | 887 | y += u8g->font_calc_vref(u8g); |
iforce2d | 0:972874f31c98 | 888 | |
iforce2d | 0:972874f31c98 | 889 | for(;;) |
iforce2d | 0:972874f31c98 | 890 | { |
iforce2d | 0:972874f31c98 | 891 | c = u8g_pgm_read(s); |
iforce2d | 0:972874f31c98 | 892 | if ( c == '\0' ) |
iforce2d | 0:972874f31c98 | 893 | break; |
iforce2d | 0:972874f31c98 | 894 | d = u8g_draw_glyph(u8g, x, y, c); |
iforce2d | 0:972874f31c98 | 895 | x += d; |
iforce2d | 0:972874f31c98 | 896 | t += d; |
iforce2d | 0:972874f31c98 | 897 | s++; |
iforce2d | 0:972874f31c98 | 898 | } |
iforce2d | 0:972874f31c98 | 899 | return t; |
iforce2d | 0:972874f31c98 | 900 | } |
iforce2d | 0:972874f31c98 | 901 | |
iforce2d | 0:972874f31c98 | 902 | u8g_uint_t u8g_DrawStr90P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s) |
iforce2d | 0:972874f31c98 | 903 | { |
iforce2d | 0:972874f31c98 | 904 | u8g_uint_t t = 0; |
iforce2d | 0:972874f31c98 | 905 | int8_t d; |
iforce2d | 0:972874f31c98 | 906 | |
iforce2d | 0:972874f31c98 | 907 | x -= u8g->font_calc_vref(u8g); |
iforce2d | 0:972874f31c98 | 908 | |
iforce2d | 0:972874f31c98 | 909 | while( *s != '\0' ) |
iforce2d | 0:972874f31c98 | 910 | { |
iforce2d | 0:972874f31c98 | 911 | d = u8g_DrawGlyph90(u8g, x, y, u8g_pgm_read(s)); |
iforce2d | 0:972874f31c98 | 912 | y += d; |
iforce2d | 0:972874f31c98 | 913 | t += d; |
iforce2d | 0:972874f31c98 | 914 | s++; |
iforce2d | 0:972874f31c98 | 915 | } |
iforce2d | 0:972874f31c98 | 916 | return t; |
iforce2d | 0:972874f31c98 | 917 | } |
iforce2d | 0:972874f31c98 | 918 | |
iforce2d | 0:972874f31c98 | 919 | u8g_uint_t u8g_DrawStr180P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s) |
iforce2d | 0:972874f31c98 | 920 | { |
iforce2d | 0:972874f31c98 | 921 | u8g_uint_t t = 0; |
iforce2d | 0:972874f31c98 | 922 | int8_t d; |
iforce2d | 0:972874f31c98 | 923 | |
iforce2d | 0:972874f31c98 | 924 | y -= u8g->font_calc_vref(u8g); |
iforce2d | 0:972874f31c98 | 925 | |
iforce2d | 0:972874f31c98 | 926 | while( *s != '\0' ) |
iforce2d | 0:972874f31c98 | 927 | { |
iforce2d | 0:972874f31c98 | 928 | d = u8g_DrawGlyph180(u8g, x, y, u8g_pgm_read(s)); |
iforce2d | 0:972874f31c98 | 929 | x -= d; |
iforce2d | 0:972874f31c98 | 930 | t += d; |
iforce2d | 0:972874f31c98 | 931 | s++; |
iforce2d | 0:972874f31c98 | 932 | } |
iforce2d | 0:972874f31c98 | 933 | return t; |
iforce2d | 0:972874f31c98 | 934 | } |
iforce2d | 0:972874f31c98 | 935 | |
iforce2d | 0:972874f31c98 | 936 | u8g_uint_t u8g_DrawStr270P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s) |
iforce2d | 0:972874f31c98 | 937 | { |
iforce2d | 0:972874f31c98 | 938 | u8g_uint_t t = 0; |
iforce2d | 0:972874f31c98 | 939 | int8_t d; |
iforce2d | 0:972874f31c98 | 940 | |
iforce2d | 0:972874f31c98 | 941 | x += u8g->font_calc_vref(u8g); |
iforce2d | 0:972874f31c98 | 942 | |
iforce2d | 0:972874f31c98 | 943 | while( *s != '\0' ) |
iforce2d | 0:972874f31c98 | 944 | { |
iforce2d | 0:972874f31c98 | 945 | d = u8g_DrawGlyph270(u8g, x, y, u8g_pgm_read(s)); |
iforce2d | 0:972874f31c98 | 946 | y -= d; |
iforce2d | 0:972874f31c98 | 947 | t += d; |
iforce2d | 0:972874f31c98 | 948 | s++; |
iforce2d | 0:972874f31c98 | 949 | } |
iforce2d | 0:972874f31c98 | 950 | return t; |
iforce2d | 0:972874f31c98 | 951 | } |
iforce2d | 0:972874f31c98 | 952 | |
iforce2d | 0:972874f31c98 | 953 | u8g_uint_t u8g_DrawStrFontBBX(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, const char *s) |
iforce2d | 0:972874f31c98 | 954 | { |
iforce2d | 0:972874f31c98 | 955 | x -= u8g_GetFontBBXOffX(u8g); |
iforce2d | 0:972874f31c98 | 956 | y += u8g_GetFontBBXOffY(u8g); |
iforce2d | 0:972874f31c98 | 957 | return u8g_DrawStrDir(u8g, x, y, dir, s); |
iforce2d | 0:972874f31c98 | 958 | } |
iforce2d | 0:972874f31c98 | 959 | |
iforce2d | 0:972874f31c98 | 960 | /* still used by picgen.c, dir argument is ignored */ |
iforce2d | 0:972874f31c98 | 961 | int8_t u8g_DrawGlyphFontBBX(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t encoding) |
iforce2d | 0:972874f31c98 | 962 | { |
iforce2d | 0:972874f31c98 | 963 | x -= u8g_GetFontBBXOffX(u8g); |
iforce2d | 0:972874f31c98 | 964 | y += u8g_GetFontBBXOffY(u8g); |
iforce2d | 0:972874f31c98 | 965 | u8g_draw_glyph(u8g, x, y, encoding); |
iforce2d | 0:972874f31c98 | 966 | return 0; |
iforce2d | 0:972874f31c98 | 967 | } |
iforce2d | 0:972874f31c98 | 968 | |
iforce2d | 0:972874f31c98 | 969 | |
iforce2d | 0:972874f31c98 | 970 | /*========================================================================*/ |
iforce2d | 0:972874f31c98 | 971 | /* set ascent/descent for reference point calculation */ |
iforce2d | 0:972874f31c98 | 972 | |
iforce2d | 0:972874f31c98 | 973 | void u8g_UpdateRefHeight(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 974 | { |
iforce2d | 0:972874f31c98 | 975 | uint16_t ls; |
iforce2d | 0:972874f31c98 | 976 | if ( u8g->font == NULL ) |
iforce2d | 0:972874f31c98 | 977 | return; |
iforce2d | 0:972874f31c98 | 978 | if ( u8g->font_height_mode == U8G_FONT_HEIGHT_MODE_TEXT ) |
iforce2d | 0:972874f31c98 | 979 | { |
iforce2d | 0:972874f31c98 | 980 | u8g->font_ref_ascent = u8g_font_GetCapitalAHeight(u8g->font); |
iforce2d | 0:972874f31c98 | 981 | u8g->font_ref_descent = u8g_font_GetLowerGDescent(u8g->font); |
iforce2d | 0:972874f31c98 | 982 | } |
iforce2d | 0:972874f31c98 | 983 | else if ( u8g->font_height_mode == U8G_FONT_HEIGHT_MODE_XTEXT ) |
iforce2d | 0:972874f31c98 | 984 | { |
iforce2d | 0:972874f31c98 | 985 | u8g->font_ref_ascent = u8g_font_GetFontXAscent(u8g->font); |
iforce2d | 0:972874f31c98 | 986 | u8g->font_ref_descent = u8g_font_GetFontXDescent(u8g->font); |
iforce2d | 0:972874f31c98 | 987 | } |
iforce2d | 0:972874f31c98 | 988 | else |
iforce2d | 0:972874f31c98 | 989 | { |
iforce2d | 0:972874f31c98 | 990 | u8g->font_ref_ascent = u8g_font_GetFontAscent(u8g->font); |
iforce2d | 0:972874f31c98 | 991 | u8g->font_ref_descent = u8g_font_GetFontDescent(u8g->font); |
iforce2d | 0:972874f31c98 | 992 | } |
iforce2d | 0:972874f31c98 | 993 | |
iforce2d | 0:972874f31c98 | 994 | ls = u8g->font_ref_ascent - u8g->font_ref_descent; |
iforce2d | 0:972874f31c98 | 995 | if ( u8g->font_line_spacing_factor != 64 ) |
iforce2d | 0:972874f31c98 | 996 | { |
iforce2d | 0:972874f31c98 | 997 | ls &= 255; |
iforce2d | 0:972874f31c98 | 998 | ls *= u8g->font_line_spacing_factor; |
iforce2d | 0:972874f31c98 | 999 | ls >>= 6; |
iforce2d | 0:972874f31c98 | 1000 | } |
iforce2d | 0:972874f31c98 | 1001 | u8g->line_spacing = ls; |
iforce2d | 0:972874f31c98 | 1002 | } |
iforce2d | 0:972874f31c98 | 1003 | |
iforce2d | 0:972874f31c98 | 1004 | void u8g_SetFontRefHeightText(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 1005 | { |
iforce2d | 0:972874f31c98 | 1006 | u8g->font_height_mode = U8G_FONT_HEIGHT_MODE_TEXT; |
iforce2d | 0:972874f31c98 | 1007 | u8g_UpdateRefHeight(u8g); |
iforce2d | 0:972874f31c98 | 1008 | } |
iforce2d | 0:972874f31c98 | 1009 | |
iforce2d | 0:972874f31c98 | 1010 | void u8g_SetFontRefHeightExtendedText(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 1011 | { |
iforce2d | 0:972874f31c98 | 1012 | u8g->font_height_mode = U8G_FONT_HEIGHT_MODE_XTEXT; |
iforce2d | 0:972874f31c98 | 1013 | u8g_UpdateRefHeight(u8g); |
iforce2d | 0:972874f31c98 | 1014 | } |
iforce2d | 0:972874f31c98 | 1015 | |
iforce2d | 0:972874f31c98 | 1016 | |
iforce2d | 0:972874f31c98 | 1017 | void u8g_SetFontRefHeightAll(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 1018 | { |
iforce2d | 0:972874f31c98 | 1019 | u8g->font_height_mode = U8G_FONT_HEIGHT_MODE_ALL; |
iforce2d | 0:972874f31c98 | 1020 | u8g_UpdateRefHeight(u8g); |
iforce2d | 0:972874f31c98 | 1021 | } |
iforce2d | 0:972874f31c98 | 1022 | |
iforce2d | 0:972874f31c98 | 1023 | /* factor = 64: linespaceing == ascent and descent */ |
iforce2d | 0:972874f31c98 | 1024 | void u8g_SetFontLineSpacingFactor(u8g_t *u8g, uint8_t factor) |
iforce2d | 0:972874f31c98 | 1025 | { |
iforce2d | 0:972874f31c98 | 1026 | u8g->font_line_spacing_factor = factor; |
iforce2d | 0:972874f31c98 | 1027 | u8g_UpdateRefHeight(u8g); |
iforce2d | 0:972874f31c98 | 1028 | } |
iforce2d | 0:972874f31c98 | 1029 | |
iforce2d | 0:972874f31c98 | 1030 | |
iforce2d | 0:972874f31c98 | 1031 | |
iforce2d | 0:972874f31c98 | 1032 | /*========================================================================*/ |
iforce2d | 0:972874f31c98 | 1033 | /* callback procedures to correct the y position */ |
iforce2d | 0:972874f31c98 | 1034 | |
iforce2d | 0:972874f31c98 | 1035 | u8g_uint_t u8g_font_calc_vref_font(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 1036 | { |
iforce2d | 0:972874f31c98 | 1037 | return 0; |
iforce2d | 0:972874f31c98 | 1038 | } |
iforce2d | 0:972874f31c98 | 1039 | |
iforce2d | 0:972874f31c98 | 1040 | void u8g_SetFontPosBaseline(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 1041 | { |
iforce2d | 0:972874f31c98 | 1042 | u8g->font_calc_vref = u8g_font_calc_vref_font; |
iforce2d | 0:972874f31c98 | 1043 | } |
iforce2d | 0:972874f31c98 | 1044 | |
iforce2d | 0:972874f31c98 | 1045 | |
iforce2d | 0:972874f31c98 | 1046 | u8g_uint_t u8g_font_calc_vref_bottom(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 1047 | { |
iforce2d | 0:972874f31c98 | 1048 | /* y += (u8g_uint_t)(u8g_int_t)(u8g->font_ref_descent); */ |
iforce2d | 0:972874f31c98 | 1049 | return (u8g_uint_t)(u8g_int_t)(u8g->font_ref_descent); |
iforce2d | 0:972874f31c98 | 1050 | } |
iforce2d | 0:972874f31c98 | 1051 | |
iforce2d | 0:972874f31c98 | 1052 | void u8g_SetFontPosBottom(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 1053 | { |
iforce2d | 0:972874f31c98 | 1054 | u8g->font_calc_vref = u8g_font_calc_vref_bottom; |
iforce2d | 0:972874f31c98 | 1055 | } |
iforce2d | 0:972874f31c98 | 1056 | |
iforce2d | 0:972874f31c98 | 1057 | u8g_uint_t u8g_font_calc_vref_top(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 1058 | { |
iforce2d | 0:972874f31c98 | 1059 | u8g_uint_t tmp; |
iforce2d | 0:972874f31c98 | 1060 | /* reference pos is one pixel above the upper edge of the reference glyph */ |
iforce2d | 0:972874f31c98 | 1061 | |
iforce2d | 0:972874f31c98 | 1062 | /* |
iforce2d | 0:972874f31c98 | 1063 | y += (u8g_uint_t)(u8g_int_t)(u8g->font_ref_ascent); |
iforce2d | 0:972874f31c98 | 1064 | y++; |
iforce2d | 0:972874f31c98 | 1065 | */ |
iforce2d | 0:972874f31c98 | 1066 | tmp = (u8g_uint_t)(u8g_int_t)(u8g->font_ref_ascent); |
iforce2d | 0:972874f31c98 | 1067 | tmp++; |
iforce2d | 0:972874f31c98 | 1068 | return tmp; |
iforce2d | 0:972874f31c98 | 1069 | } |
iforce2d | 0:972874f31c98 | 1070 | |
iforce2d | 0:972874f31c98 | 1071 | void u8g_SetFontPosTop(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 1072 | { |
iforce2d | 0:972874f31c98 | 1073 | u8g->font_calc_vref = u8g_font_calc_vref_top; |
iforce2d | 0:972874f31c98 | 1074 | } |
iforce2d | 0:972874f31c98 | 1075 | |
iforce2d | 0:972874f31c98 | 1076 | u8g_uint_t u8g_font_calc_vref_center(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 1077 | { |
iforce2d | 0:972874f31c98 | 1078 | int8_t tmp; |
iforce2d | 0:972874f31c98 | 1079 | tmp = u8g->font_ref_ascent; |
iforce2d | 0:972874f31c98 | 1080 | tmp -= u8g->font_ref_descent; |
iforce2d | 0:972874f31c98 | 1081 | tmp /= 2; |
iforce2d | 0:972874f31c98 | 1082 | tmp += u8g->font_ref_descent; |
iforce2d | 0:972874f31c98 | 1083 | /* y += (u8g_uint_t)(u8g_int_t)(tmp); */ |
iforce2d | 0:972874f31c98 | 1084 | return tmp; |
iforce2d | 0:972874f31c98 | 1085 | } |
iforce2d | 0:972874f31c98 | 1086 | |
iforce2d | 0:972874f31c98 | 1087 | void u8g_SetFontPosCenter(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 1088 | { |
iforce2d | 0:972874f31c98 | 1089 | u8g->font_calc_vref = u8g_font_calc_vref_center; |
iforce2d | 0:972874f31c98 | 1090 | } |
iforce2d | 0:972874f31c98 | 1091 | |
iforce2d | 0:972874f31c98 | 1092 | /*========================================================================*/ |
iforce2d | 0:972874f31c98 | 1093 | /* string pixel width calculation */ |
iforce2d | 0:972874f31c98 | 1094 | |
iforce2d | 0:972874f31c98 | 1095 | char u8g_font_get_char(const void *s) |
iforce2d | 0:972874f31c98 | 1096 | { |
iforce2d | 0:972874f31c98 | 1097 | return *(const char *)(s); |
iforce2d | 0:972874f31c98 | 1098 | } |
iforce2d | 0:972874f31c98 | 1099 | |
iforce2d | 0:972874f31c98 | 1100 | char u8g_font_get_charP(const void *s) |
iforce2d | 0:972874f31c98 | 1101 | { |
iforce2d | 0:972874f31c98 | 1102 | return u8g_pgm_read(s); |
iforce2d | 0:972874f31c98 | 1103 | } |
iforce2d | 0:972874f31c98 | 1104 | |
iforce2d | 0:972874f31c98 | 1105 | typedef char (*u8g_font_get_char_fn)(const void *s); |
iforce2d | 0:972874f31c98 | 1106 | |
iforce2d | 0:972874f31c98 | 1107 | |
iforce2d | 0:972874f31c98 | 1108 | u8g_uint_t u8g_font_calc_str_pixel_width(u8g_t *u8g, const char *s, u8g_font_get_char_fn get_char ) |
iforce2d | 0:972874f31c98 | 1109 | { |
iforce2d | 0:972874f31c98 | 1110 | u8g_uint_t w; |
iforce2d | 0:972874f31c98 | 1111 | uint8_t enc; |
iforce2d | 0:972874f31c98 | 1112 | |
iforce2d | 0:972874f31c98 | 1113 | /* reset the total minimal width to zero, this will be expanded during calculation */ |
iforce2d | 0:972874f31c98 | 1114 | w = 0; |
iforce2d | 0:972874f31c98 | 1115 | |
iforce2d | 0:972874f31c98 | 1116 | enc = get_char(s); |
iforce2d | 0:972874f31c98 | 1117 | |
iforce2d | 0:972874f31c98 | 1118 | /* check for empty string, width is already 0 */ |
iforce2d | 0:972874f31c98 | 1119 | if ( enc == '\0' ) |
iforce2d | 0:972874f31c98 | 1120 | { |
iforce2d | 0:972874f31c98 | 1121 | return w; |
iforce2d | 0:972874f31c98 | 1122 | } |
iforce2d | 0:972874f31c98 | 1123 | |
iforce2d | 0:972874f31c98 | 1124 | /* get the glyph information of the first char. This must be valid, because we already checked for the empty string */ |
iforce2d | 0:972874f31c98 | 1125 | /* if *s is not inside the font, then the cached parameters of the glyph are all zero */ |
iforce2d | 0:972874f31c98 | 1126 | u8g_GetGlyph(u8g, enc); |
iforce2d | 0:972874f31c98 | 1127 | |
iforce2d | 0:972874f31c98 | 1128 | /* strlen(s) == 1: width = width(s[0]) */ |
iforce2d | 0:972874f31c98 | 1129 | /* strlen(s) == 2: width = - offx(s[0]) + deltax(s[0]) + offx(s[1]) + width(s[1]) */ |
iforce2d | 0:972874f31c98 | 1130 | /* strlen(s) == 3: width = - offx(s[0]) + deltax(s[0]) + deltax(s[1]) + offx(s[2]) + width(s[2]) */ |
iforce2d | 0:972874f31c98 | 1131 | |
iforce2d | 0:972874f31c98 | 1132 | /* assume that the string has size 2 or more, than start with negative offset-x */ |
iforce2d | 0:972874f31c98 | 1133 | /* for string with size 1, this will be nullified after the loop */ |
iforce2d | 0:972874f31c98 | 1134 | w = -u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 1135 | for(;;) |
iforce2d | 0:972874f31c98 | 1136 | { |
iforce2d | 0:972874f31c98 | 1137 | |
iforce2d | 0:972874f31c98 | 1138 | /* check and stop if the end of the string is reached */ |
iforce2d | 0:972874f31c98 | 1139 | s++; |
iforce2d | 0:972874f31c98 | 1140 | if ( get_char(s) == '\0' ) |
iforce2d | 0:972874f31c98 | 1141 | break; |
iforce2d | 0:972874f31c98 | 1142 | |
iforce2d | 0:972874f31c98 | 1143 | /* if there are still more characters, add the delta to the next glyph */ |
iforce2d | 0:972874f31c98 | 1144 | w += u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 1145 | |
iforce2d | 0:972874f31c98 | 1146 | /* store the encoding in a local variable, used also after the for(;;) loop */ |
iforce2d | 0:972874f31c98 | 1147 | enc = get_char(s); |
iforce2d | 0:972874f31c98 | 1148 | |
iforce2d | 0:972874f31c98 | 1149 | /* load the next glyph information */ |
iforce2d | 0:972874f31c98 | 1150 | u8g_GetGlyph(u8g, enc); |
iforce2d | 0:972874f31c98 | 1151 | } |
iforce2d | 0:972874f31c98 | 1152 | |
iforce2d | 0:972874f31c98 | 1153 | /* finally calculate the width of the last char */ |
iforce2d | 0:972874f31c98 | 1154 | /* here is another exception, if the last char is a black, use the dx value instead */ |
iforce2d | 0:972874f31c98 | 1155 | if ( enc != ' ' ) |
iforce2d | 0:972874f31c98 | 1156 | { |
iforce2d | 0:972874f31c98 | 1157 | /* if g was not updated in the for loop (strlen() == 1), then the initial offset x gets removed */ |
iforce2d | 0:972874f31c98 | 1158 | w += u8g->glyph_width; |
iforce2d | 0:972874f31c98 | 1159 | w += u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 1160 | } |
iforce2d | 0:972874f31c98 | 1161 | else |
iforce2d | 0:972874f31c98 | 1162 | { |
iforce2d | 0:972874f31c98 | 1163 | w += u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 1164 | } |
iforce2d | 0:972874f31c98 | 1165 | |
iforce2d | 0:972874f31c98 | 1166 | |
iforce2d | 0:972874f31c98 | 1167 | return w; |
iforce2d | 0:972874f31c98 | 1168 | } |
iforce2d | 0:972874f31c98 | 1169 | |
iforce2d | 0:972874f31c98 | 1170 | u8g_uint_t u8g_GetStrPixelWidth(u8g_t *u8g, const char *s) |
iforce2d | 0:972874f31c98 | 1171 | { |
iforce2d | 0:972874f31c98 | 1172 | return u8g_font_calc_str_pixel_width(u8g, s, u8g_font_get_char); |
iforce2d | 0:972874f31c98 | 1173 | } |
iforce2d | 0:972874f31c98 | 1174 | |
iforce2d | 0:972874f31c98 | 1175 | u8g_uint_t u8g_GetStrPixelWidthP(u8g_t *u8g, const u8g_pgm_uint8_t *s) |
iforce2d | 0:972874f31c98 | 1176 | { |
iforce2d | 0:972874f31c98 | 1177 | return u8g_font_calc_str_pixel_width(u8g, (const char *)s, u8g_font_get_charP); |
iforce2d | 0:972874f31c98 | 1178 | } |
iforce2d | 0:972874f31c98 | 1179 | |
iforce2d | 0:972874f31c98 | 1180 | int8_t u8g_GetStrX(u8g_t *u8g, const char *s) |
iforce2d | 0:972874f31c98 | 1181 | { |
iforce2d | 0:972874f31c98 | 1182 | u8g_GetGlyph(u8g, *s); |
iforce2d | 0:972874f31c98 | 1183 | return u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 1184 | } |
iforce2d | 0:972874f31c98 | 1185 | |
iforce2d | 0:972874f31c98 | 1186 | int8_t u8g_GetStrXP(u8g_t *u8g, const u8g_pgm_uint8_t *s) |
iforce2d | 0:972874f31c98 | 1187 | { |
iforce2d | 0:972874f31c98 | 1188 | u8g_GetGlyph(u8g, u8g_pgm_read(s)); |
iforce2d | 0:972874f31c98 | 1189 | return u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 1190 | } |
iforce2d | 0:972874f31c98 | 1191 | |
iforce2d | 0:972874f31c98 | 1192 | /*========================================================================*/ |
iforce2d | 0:972874f31c98 | 1193 | /* string width calculation */ |
iforce2d | 0:972874f31c98 | 1194 | |
iforce2d | 0:972874f31c98 | 1195 | u8g_uint_t u8g_GetStrWidth(u8g_t *u8g, const char *s) |
iforce2d | 0:972874f31c98 | 1196 | { |
iforce2d | 0:972874f31c98 | 1197 | u8g_uint_t w; |
iforce2d | 0:972874f31c98 | 1198 | uint8_t encoding; |
iforce2d | 0:972874f31c98 | 1199 | |
iforce2d | 0:972874f31c98 | 1200 | /* reset the total width to zero, this will be expanded during calculation */ |
iforce2d | 0:972874f31c98 | 1201 | w = 0; |
iforce2d | 0:972874f31c98 | 1202 | |
iforce2d | 0:972874f31c98 | 1203 | for(;;) |
iforce2d | 0:972874f31c98 | 1204 | { |
iforce2d | 0:972874f31c98 | 1205 | encoding = *s; |
iforce2d | 0:972874f31c98 | 1206 | if ( encoding == 0 ) |
iforce2d | 0:972874f31c98 | 1207 | break; |
iforce2d | 0:972874f31c98 | 1208 | |
iforce2d | 0:972874f31c98 | 1209 | /* load glyph information */ |
iforce2d | 0:972874f31c98 | 1210 | u8g_GetGlyph(u8g, encoding); |
iforce2d | 0:972874f31c98 | 1211 | w += u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 1212 | |
iforce2d | 0:972874f31c98 | 1213 | /* goto next char */ |
iforce2d | 0:972874f31c98 | 1214 | s++; |
iforce2d | 0:972874f31c98 | 1215 | } |
iforce2d | 0:972874f31c98 | 1216 | |
iforce2d | 0:972874f31c98 | 1217 | return w; |
iforce2d | 0:972874f31c98 | 1218 | } |
iforce2d | 0:972874f31c98 | 1219 | |
iforce2d | 0:972874f31c98 | 1220 | |
iforce2d | 0:972874f31c98 | 1221 | u8g_uint_t u8g_GetStrWidthP(u8g_t *u8g, const u8g_pgm_uint8_t *s) |
iforce2d | 0:972874f31c98 | 1222 | { |
iforce2d | 0:972874f31c98 | 1223 | u8g_uint_t w; |
iforce2d | 0:972874f31c98 | 1224 | uint8_t encoding; |
iforce2d | 0:972874f31c98 | 1225 | |
iforce2d | 0:972874f31c98 | 1226 | /* reset the total width to zero, this will be expanded during calculation */ |
iforce2d | 0:972874f31c98 | 1227 | w = 0; |
iforce2d | 0:972874f31c98 | 1228 | |
iforce2d | 0:972874f31c98 | 1229 | for(;;) |
iforce2d | 0:972874f31c98 | 1230 | { |
iforce2d | 0:972874f31c98 | 1231 | encoding = u8g_pgm_read(s); |
iforce2d | 0:972874f31c98 | 1232 | if ( encoding == 0 ) |
iforce2d | 0:972874f31c98 | 1233 | break; |
iforce2d | 0:972874f31c98 | 1234 | |
iforce2d | 0:972874f31c98 | 1235 | /* load glyph information */ |
iforce2d | 0:972874f31c98 | 1236 | u8g_GetGlyph(u8g, encoding); |
iforce2d | 0:972874f31c98 | 1237 | w += u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 1238 | |
iforce2d | 0:972874f31c98 | 1239 | /* goto next char */ |
iforce2d | 0:972874f31c98 | 1240 | s++; |
iforce2d | 0:972874f31c98 | 1241 | } |
iforce2d | 0:972874f31c98 | 1242 | |
iforce2d | 0:972874f31c98 | 1243 | return w; |
iforce2d | 0:972874f31c98 | 1244 | } |
iforce2d | 0:972874f31c98 | 1245 | |
iforce2d | 0:972874f31c98 | 1246 | |
iforce2d | 0:972874f31c98 | 1247 | /*========================================================================*/ |
iforce2d | 0:972874f31c98 | 1248 | /* calculation of font/glyph/string characteristics */ |
iforce2d | 0:972874f31c98 | 1249 | |
iforce2d | 0:972874f31c98 | 1250 | |
iforce2d | 0:972874f31c98 | 1251 | /* |
iforce2d | 0:972874f31c98 | 1252 | Description: |
iforce2d | 0:972874f31c98 | 1253 | Calculate parameter for the minimal bounding box on a given string |
iforce2d | 0:972874f31c98 | 1254 | Output |
iforce2d | 0:972874f31c98 | 1255 | buf->y_min extend of the lower left edge if the string below (y_min<0) or above (y_min>0) baseline (descent) |
iforce2d | 0:972874f31c98 | 1256 | buf->y_max extend of the upper left edge if the string below (y_min<0) or above (y_min>0) baseline (ascent) |
iforce2d | 0:972874f31c98 | 1257 | buf->w the width of the string |
iforce2d | 0:972874f31c98 | 1258 | */ |
iforce2d | 0:972874f31c98 | 1259 | struct u8g_str_size_struct |
iforce2d | 0:972874f31c98 | 1260 | { |
iforce2d | 0:972874f31c98 | 1261 | int8_t y_min; /* descent */ |
iforce2d | 0:972874f31c98 | 1262 | int8_t y_max; /* ascent */ |
iforce2d | 0:972874f31c98 | 1263 | int8_t x, y; /* the reference point of the font (negated!) */ |
iforce2d | 0:972874f31c98 | 1264 | u8g_uint_t w; /* width of the overall string */ |
iforce2d | 0:972874f31c98 | 1265 | }; |
iforce2d | 0:972874f31c98 | 1266 | typedef struct u8g_str_size_struct u8g_str_size_t; |
iforce2d | 0:972874f31c98 | 1267 | |
iforce2d | 0:972874f31c98 | 1268 | static void u8g_font_calc_str_min_box(u8g_t *u8g, const char *s, u8g_str_size_t *buf) |
iforce2d | 0:972874f31c98 | 1269 | { |
iforce2d | 0:972874f31c98 | 1270 | /* u8g_glyph_t g; */ |
iforce2d | 0:972874f31c98 | 1271 | int8_t tmp; |
iforce2d | 0:972874f31c98 | 1272 | |
iforce2d | 0:972874f31c98 | 1273 | /* reset the total minimal width to zero, this will be expanded during calculation */ |
iforce2d | 0:972874f31c98 | 1274 | buf->w = 0; |
iforce2d | 0:972874f31c98 | 1275 | |
iforce2d | 0:972874f31c98 | 1276 | /* check for empty string, width is already 0, but also reset y_min and y_max to 0 */ |
iforce2d | 0:972874f31c98 | 1277 | if ( *s == '\0' ) |
iforce2d | 0:972874f31c98 | 1278 | { |
iforce2d | 0:972874f31c98 | 1279 | buf->y_min = 0; |
iforce2d | 0:972874f31c98 | 1280 | buf->y_max = 0; |
iforce2d | 0:972874f31c98 | 1281 | buf->x = 0; |
iforce2d | 0:972874f31c98 | 1282 | buf->y = 0; |
iforce2d | 0:972874f31c98 | 1283 | return; |
iforce2d | 0:972874f31c98 | 1284 | } |
iforce2d | 0:972874f31c98 | 1285 | |
iforce2d | 0:972874f31c98 | 1286 | /* reset y_min to the largest possible value. Later we search for the smallest value */ |
iforce2d | 0:972874f31c98 | 1287 | /* y_min contains the position [pixel] of the lower left edge of the glyph above (y_min>0) or below (y_min<0) baseline */ |
iforce2d | 0:972874f31c98 | 1288 | buf->y_min = 127; |
iforce2d | 0:972874f31c98 | 1289 | /* reset y_max to the smallest possible value. Later we search for the highest value */ |
iforce2d | 0:972874f31c98 | 1290 | /* y_max contains the position [pixel] of the upper left edge of the glyph above (y_max>0) or below (y_max<0) baseline */ |
iforce2d | 0:972874f31c98 | 1291 | buf->y_max = -128; |
iforce2d | 0:972874f31c98 | 1292 | |
iforce2d | 0:972874f31c98 | 1293 | /* get the glyph information of the first char. This must be valid, because we already checked for the empty string */ |
iforce2d | 0:972874f31c98 | 1294 | u8g_GetGlyph(u8g, *s); |
iforce2d | 0:972874f31c98 | 1295 | |
iforce2d | 0:972874f31c98 | 1296 | /* strlen(s) == 1: width = width(s[0]) */ |
iforce2d | 0:972874f31c98 | 1297 | /* strlen(s) == 2: width = - offx(s[0]) + deltax(s[0]) + offx(s[1]) + width(s[1]) */ |
iforce2d | 0:972874f31c98 | 1298 | /* strlen(s) == 3: width = - offx(s[0]) + deltax(s[0]) + deltax(s[1]) + offx(s[2]) + width(s[2]) */ |
iforce2d | 0:972874f31c98 | 1299 | |
iforce2d | 0:972874f31c98 | 1300 | /* assume that the string has size 2 or more, than start with negative offset-x */ |
iforce2d | 0:972874f31c98 | 1301 | /* for string with size 1, this will be nullified after the loop */ |
iforce2d | 0:972874f31c98 | 1302 | // buf->w = - u8g_font_GetGlyphBBXOffX(u8g->font, g); |
iforce2d | 0:972874f31c98 | 1303 | buf->w = - u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 1304 | |
iforce2d | 0:972874f31c98 | 1305 | /* Also copy the position of the first glyph. This is the reference point of the string (negated) */ |
iforce2d | 0:972874f31c98 | 1306 | buf->x = u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 1307 | buf->y = u8g->glyph_y; |
iforce2d | 0:972874f31c98 | 1308 | |
iforce2d | 0:972874f31c98 | 1309 | for(;;) |
iforce2d | 0:972874f31c98 | 1310 | { |
iforce2d | 0:972874f31c98 | 1311 | |
iforce2d | 0:972874f31c98 | 1312 | /* calculated y position of the upper left corner (y_max) and lower left corner (y_min) of the string */ |
iforce2d | 0:972874f31c98 | 1313 | /* relative to the base line */ |
iforce2d | 0:972874f31c98 | 1314 | |
iforce2d | 0:972874f31c98 | 1315 | tmp = u8g->glyph_y; |
iforce2d | 0:972874f31c98 | 1316 | if ( buf->y_min > tmp ) |
iforce2d | 0:972874f31c98 | 1317 | buf->y_min = tmp; |
iforce2d | 0:972874f31c98 | 1318 | |
iforce2d | 0:972874f31c98 | 1319 | tmp +=u8g->glyph_height; |
iforce2d | 0:972874f31c98 | 1320 | if ( buf->y_max < tmp ) |
iforce2d | 0:972874f31c98 | 1321 | buf->y_max = tmp; |
iforce2d | 0:972874f31c98 | 1322 | |
iforce2d | 0:972874f31c98 | 1323 | /* check and stop if the end of the string is reached */ |
iforce2d | 0:972874f31c98 | 1324 | s++; |
iforce2d | 0:972874f31c98 | 1325 | if ( *s == '\0' ) |
iforce2d | 0:972874f31c98 | 1326 | break; |
iforce2d | 0:972874f31c98 | 1327 | |
iforce2d | 0:972874f31c98 | 1328 | /* if there are still more characters, add the delta to the next glyph */ |
iforce2d | 0:972874f31c98 | 1329 | buf->w += u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 1330 | |
iforce2d | 0:972874f31c98 | 1331 | /* load the next glyph information */ |
iforce2d | 0:972874f31c98 | 1332 | u8g_GetGlyph(u8g, *s); |
iforce2d | 0:972874f31c98 | 1333 | } |
iforce2d | 0:972874f31c98 | 1334 | |
iforce2d | 0:972874f31c98 | 1335 | /* finally calculate the width of the last char */ |
iforce2d | 0:972874f31c98 | 1336 | /* if g was not updated in the for loop (strlen() == 1), then the initial offset x gets removed */ |
iforce2d | 0:972874f31c98 | 1337 | buf->w += u8g->glyph_width; |
iforce2d | 0:972874f31c98 | 1338 | // buf->w += u8g_font_GetGlyphBBXOffX(u8g->font, g); |
iforce2d | 0:972874f31c98 | 1339 | |
iforce2d | 0:972874f31c98 | 1340 | buf->w += u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 1341 | } |
iforce2d | 0:972874f31c98 | 1342 | |
iforce2d | 0:972874f31c98 | 1343 | /* calculate minimal box */ |
iforce2d | 0:972874f31c98 | 1344 | void u8g_font_box_min(u8g_t *u8g, const char *s, u8g_str_size_t *buf) |
iforce2d | 0:972874f31c98 | 1345 | { |
iforce2d | 0:972874f31c98 | 1346 | u8g_font_calc_str_min_box(u8g, s, buf); |
iforce2d | 0:972874f31c98 | 1347 | } |
iforce2d | 0:972874f31c98 | 1348 | |
iforce2d | 0:972874f31c98 | 1349 | /* calculate gA box, but do not calculate the overall width */ |
iforce2d | 0:972874f31c98 | 1350 | void u8g_font_box_left_gA(u8g_t *u8g, const char *s, u8g_str_size_t *buf) |
iforce2d | 0:972874f31c98 | 1351 | { |
iforce2d | 0:972874f31c98 | 1352 | |
iforce2d | 0:972874f31c98 | 1353 | } |
iforce2d | 0:972874f31c98 | 1354 | |
iforce2d | 0:972874f31c98 | 1355 | /* calculate gA box, including overall width */ |
iforce2d | 0:972874f31c98 | 1356 | void u8g_font_box_all_gA(u8g_t *u8g, const char *s, u8g_str_size_t *buf) |
iforce2d | 0:972874f31c98 | 1357 | { |
iforce2d | 0:972874f31c98 | 1358 | |
iforce2d | 0:972874f31c98 | 1359 | } |
iforce2d | 0:972874f31c98 | 1360 | |
iforce2d | 0:972874f31c98 | 1361 | |
iforce2d | 0:972874f31c98 | 1362 | 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) |
iforce2d | 0:972874f31c98 | 1363 | { |
iforce2d | 0:972874f31c98 | 1364 | /* |
iforce2d | 0:972874f31c98 | 1365 | u8g_glyph_t g; |
iforce2d | 0:972874f31c98 | 1366 | g = |
iforce2d | 0:972874f31c98 | 1367 | */ |
iforce2d | 0:972874f31c98 | 1368 | u8g_GetGlyph(u8g, *s); |
iforce2d | 0:972874f31c98 | 1369 | *x += u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 1370 | *width = buf->w; |
iforce2d | 0:972874f31c98 | 1371 | *y -= buf->y_max; |
iforce2d | 0:972874f31c98 | 1372 | /* +1 because y_max is a height, this compensates the next step */ |
iforce2d | 0:972874f31c98 | 1373 | //*y += 1; |
iforce2d | 0:972874f31c98 | 1374 | /* because the reference point is one below the string, this compensates the previous step */ |
iforce2d | 0:972874f31c98 | 1375 | //*y -= 1; |
iforce2d | 0:972874f31c98 | 1376 | *height = buf->y_max; |
iforce2d | 0:972874f31c98 | 1377 | *height -= buf->y_min; |
iforce2d | 0:972874f31c98 | 1378 | } |
iforce2d | 0:972874f31c98 | 1379 | |
iforce2d | 0:972874f31c98 | 1380 | |
iforce2d | 0:972874f31c98 | 1381 | 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) |
iforce2d | 0:972874f31c98 | 1382 | { |
iforce2d | 0:972874f31c98 | 1383 | u8g_str_size_t buf; |
iforce2d | 0:972874f31c98 | 1384 | |
iforce2d | 0:972874f31c98 | 1385 | if ( *s == '\0' ) |
iforce2d | 0:972874f31c98 | 1386 | { |
iforce2d | 0:972874f31c98 | 1387 | *width= 0; |
iforce2d | 0:972874f31c98 | 1388 | *height = 0; |
iforce2d | 0:972874f31c98 | 1389 | return; |
iforce2d | 0:972874f31c98 | 1390 | } |
iforce2d | 0:972874f31c98 | 1391 | |
iforce2d | 0:972874f31c98 | 1392 | u8g_font_calc_str_min_box(u8g, s, &buf); |
iforce2d | 0:972874f31c98 | 1393 | u8g_font_get_str_box_fill_args(u8g, s, &buf, x, y, width, height); |
iforce2d | 0:972874f31c98 | 1394 | } |
iforce2d | 0:972874f31c98 | 1395 | |
iforce2d | 0:972874f31c98 | 1396 | |
iforce2d | 0:972874f31c98 | 1397 | 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) |
iforce2d | 0:972874f31c98 | 1398 | { |
iforce2d | 0:972874f31c98 | 1399 | u8g_str_size_t buf; |
iforce2d | 0:972874f31c98 | 1400 | uint8_t cap_a; |
iforce2d | 0:972874f31c98 | 1401 | |
iforce2d | 0:972874f31c98 | 1402 | if ( *s == '\0' ) |
iforce2d | 0:972874f31c98 | 1403 | { |
iforce2d | 0:972874f31c98 | 1404 | *width= 0; |
iforce2d | 0:972874f31c98 | 1405 | *height = 0; |
iforce2d | 0:972874f31c98 | 1406 | return; |
iforce2d | 0:972874f31c98 | 1407 | } |
iforce2d | 0:972874f31c98 | 1408 | |
iforce2d | 0:972874f31c98 | 1409 | cap_a = u8g_font_GetCapitalAHeight(u8g->font); |
iforce2d | 0:972874f31c98 | 1410 | u8g_font_calc_str_min_box(u8g, s, &buf); |
iforce2d | 0:972874f31c98 | 1411 | if ( buf.y_max < cap_a ) |
iforce2d | 0:972874f31c98 | 1412 | buf.y_max = cap_a; |
iforce2d | 0:972874f31c98 | 1413 | u8g_font_get_str_box_fill_args(u8g, s, &buf, x, y, width, height); |
iforce2d | 0:972874f31c98 | 1414 | } |
iforce2d | 0:972874f31c98 | 1415 | |
iforce2d | 0:972874f31c98 | 1416 | void u8g_SetFont(u8g_t *u8g, const u8g_fntpgm_uint8_t *font) |
iforce2d | 0:972874f31c98 | 1417 | { |
iforce2d | 0:972874f31c98 | 1418 | if ( u8g->font != font ) |
iforce2d | 0:972874f31c98 | 1419 | { |
iforce2d | 0:972874f31c98 | 1420 | u8g->font = font; |
iforce2d | 0:972874f31c98 | 1421 | u8g_UpdateRefHeight(u8g); |
iforce2d | 0:972874f31c98 | 1422 | u8g_SetFontPosBaseline(u8g); |
iforce2d | 0:972874f31c98 | 1423 | } |
iforce2d | 0:972874f31c98 | 1424 | } |
iforce2d | 0:972874f31c98 | 1425 | |
iforce2d | 0:972874f31c98 | 1426 | /*========================================================================*/ |
iforce2d | 0:972874f31c98 | 1427 | /* anti aliasing fonts */ |
iforce2d | 0:972874f31c98 | 1428 | |
iforce2d | 0:972874f31c98 | 1429 | int8_t u8g_draw_aa_glyph(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding) |
iforce2d | 0:972874f31c98 | 1430 | { |
iforce2d | 0:972874f31c98 | 1431 | const u8g_pgm_uint8_t *data; |
iforce2d | 0:972874f31c98 | 1432 | uint8_t w, h; |
iforce2d | 0:972874f31c98 | 1433 | uint8_t i, j; |
iforce2d | 0:972874f31c98 | 1434 | u8g_uint_t ix, iy; |
iforce2d | 0:972874f31c98 | 1435 | |
iforce2d | 0:972874f31c98 | 1436 | { |
iforce2d | 0:972874f31c98 | 1437 | u8g_glyph_t g = u8g_GetGlyph(u8g, encoding); |
iforce2d | 0:972874f31c98 | 1438 | if ( g == NULL ) |
iforce2d | 0:972874f31c98 | 1439 | return 0; |
iforce2d | 0:972874f31c98 | 1440 | data = u8g_font_GetGlyphDataStart(u8g->font, g); |
iforce2d | 0:972874f31c98 | 1441 | } |
iforce2d | 0:972874f31c98 | 1442 | |
iforce2d | 0:972874f31c98 | 1443 | w = u8g->glyph_width; |
iforce2d | 0:972874f31c98 | 1444 | h = u8g->glyph_height; |
iforce2d | 0:972874f31c98 | 1445 | |
iforce2d | 0:972874f31c98 | 1446 | x += u8g->glyph_x; |
iforce2d | 0:972874f31c98 | 1447 | y -= u8g->glyph_y; |
iforce2d | 0:972874f31c98 | 1448 | y--; |
iforce2d | 0:972874f31c98 | 1449 | |
iforce2d | 0:972874f31c98 | 1450 | if ( u8g_IsBBXIntersection(u8g, x, y-h+1, w, h) == 0 ) |
iforce2d | 0:972874f31c98 | 1451 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 1452 | |
iforce2d | 0:972874f31c98 | 1453 | /* now, w is reused as bytes per line */ |
iforce2d | 0:972874f31c98 | 1454 | w += 3; |
iforce2d | 0:972874f31c98 | 1455 | w /= 4; |
iforce2d | 0:972874f31c98 | 1456 | |
iforce2d | 0:972874f31c98 | 1457 | iy = y; |
iforce2d | 0:972874f31c98 | 1458 | iy -= h; |
iforce2d | 0:972874f31c98 | 1459 | iy++; |
iforce2d | 0:972874f31c98 | 1460 | |
iforce2d | 0:972874f31c98 | 1461 | for( j = 0; j < h; j++ ) |
iforce2d | 0:972874f31c98 | 1462 | { |
iforce2d | 0:972874f31c98 | 1463 | ix = x; |
iforce2d | 0:972874f31c98 | 1464 | for( i = 0; i < w; i++ ) |
iforce2d | 0:972874f31c98 | 1465 | { |
iforce2d | 0:972874f31c98 | 1466 | u8g_Draw4TPixel(u8g, ix, iy, 0, u8g_pgm_read(data)); |
iforce2d | 0:972874f31c98 | 1467 | data++; |
iforce2d | 0:972874f31c98 | 1468 | ix+=4; |
iforce2d | 0:972874f31c98 | 1469 | } |
iforce2d | 0:972874f31c98 | 1470 | iy++; |
iforce2d | 0:972874f31c98 | 1471 | } |
iforce2d | 0:972874f31c98 | 1472 | return u8g->glyph_dx; |
iforce2d | 0:972874f31c98 | 1473 | } |
iforce2d | 0:972874f31c98 | 1474 | |
iforce2d | 0:972874f31c98 | 1475 | int8_t u8g_DrawAAGlyph(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding) |
iforce2d | 0:972874f31c98 | 1476 | { |
iforce2d | 0:972874f31c98 | 1477 | y += u8g->font_calc_vref(u8g); |
iforce2d | 0:972874f31c98 | 1478 | return u8g_draw_aa_glyph(u8g, x, y, encoding); |
iforce2d | 0:972874f31c98 | 1479 | } |
iforce2d | 0:972874f31c98 | 1480 | |
iforce2d | 0:972874f31c98 | 1481 | u8g_uint_t u8g_DrawAAStr(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s) |
iforce2d | 0:972874f31c98 | 1482 | { |
iforce2d | 0:972874f31c98 | 1483 | u8g_uint_t t = 0; |
iforce2d | 0:972874f31c98 | 1484 | int8_t d; |
iforce2d | 0:972874f31c98 | 1485 | |
iforce2d | 0:972874f31c98 | 1486 | if ( u8g_font_GetFormat(u8g->font) != 2 ) |
iforce2d | 0:972874f31c98 | 1487 | return 0; |
iforce2d | 0:972874f31c98 | 1488 | //u8g_uint_t u8g_GetStrWidth(u8g, s); |
iforce2d | 0:972874f31c98 | 1489 | //u8g_font_GetFontAscent(u8g->font)-u8g_font_GetFontDescent(u8g->font); |
iforce2d | 0:972874f31c98 | 1490 | |
iforce2d | 0:972874f31c98 | 1491 | y += u8g->font_calc_vref(u8g); |
iforce2d | 0:972874f31c98 | 1492 | |
iforce2d | 0:972874f31c98 | 1493 | while( *s != '\0' ) |
iforce2d | 0:972874f31c98 | 1494 | { |
iforce2d | 0:972874f31c98 | 1495 | d = u8g_draw_aa_glyph(u8g, x, y, *s); |
iforce2d | 0:972874f31c98 | 1496 | x += d; |
iforce2d | 0:972874f31c98 | 1497 | t += d; |
iforce2d | 0:972874f31c98 | 1498 | s++; |
iforce2d | 0:972874f31c98 | 1499 | } |
iforce2d | 0:972874f31c98 | 1500 | return t; |
iforce2d | 0:972874f31c98 | 1501 | } |
iforce2d | 0:972874f31c98 | 1502 |