diff options
Diffstat (limited to 'include/gdisp')
-rw-r--r-- | include/gdisp/fonts.h | 67 | ||||
-rw-r--r-- | include/gdisp/gdisp.h | 83 | ||||
-rw-r--r-- | include/gdisp/lld/emulation.c | 187 | ||||
-rw-r--r-- | include/gdisp/lld/gdisp_lld.h | 40 | ||||
-rw-r--r-- | include/gdisp/lld/gdisp_lld_msgs.h | 21 | ||||
-rw-r--r-- | include/gdisp/options.h | 59 |
6 files changed, 79 insertions, 378 deletions
diff --git a/include/gdisp/fonts.h b/include/gdisp/fonts.h deleted file mode 100644 index 76bd0926..00000000 --- a/include/gdisp/fonts.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file include/gdisp/fonts.h - * @brief GDISP internal font definitions. - * @details This is not generally needed by an application. It is used - * by the low level drivers that need to understand a font. - * - * @addtogroup GDISP - * @{ - */ - -#ifndef _GDISP_FONTS_H -#define _GDISP_FONTS_H - -/* Don't test against GFX_USE_GDISP as we may want to use this in other non-GDISP utilities. */ - -/** - * @brief The type of a font column. - * @note Set by defining @p GDISP_MAX_FNT_HEIGHT appropriately. - */ -#if GDISP_MAX_FONT_HEIGHT == 16 - typedef uint16_t fontcolumn_t; -#elif GDISP_MAX_FONT_HEIGHT == 32 - typedef uint32_t fontcolumn_t; -#else - #error "GDISP: GDISP_MAX_FONT_HEIGHT must be either 16 or 32" -#endif - -/** - * @brief Internal font structure. - * @note This structure is followed by: - * 1. An array of character widths (uint8_t) - * 2. An array of column data offsets (relative to the font structure) - * 3. Each characters array of column data (fontcolumn_t) - * Each sub-structure must be padded to a multiple of 8 bytes - * to allow the tables to work across many different compilers. - */ -struct font { - const char * name; - uint8_t height; - uint8_t charPadding; - uint8_t lineSpacing; - uint8_t descenderHeight; - uint8_t minWidth; - uint8_t maxWidth; - char minChar; - char maxChar; - uint8_t xscale; - uint8_t yscale; - const uint8_t *widthTable; - const uint16_t *offsetTable; - const fontcolumn_t *dataTable; -}; - -#define _getCharWidth(f,c) (((c) < (f)->minChar || (c) > (f)->maxChar) ? 0 : (f)->widthTable[(c) - (f)->minChar]) -#define _getCharOffset(f,c) ((f)->offsetTable[(c) - (f)->minChar]) -#define _getCharData(f,c) (&(f)->dataTable[_getCharOffset(f, c)]) - -#endif /* _GDISP_FONTS_H */ -/** @} */ - diff --git a/include/gdisp/gdisp.h b/include/gdisp/gdisp.h index ca1844fd..b82c9f3c 100644 --- a/include/gdisp/gdisp.h +++ b/include/gdisp/gdisp.h @@ -37,12 +37,6 @@ typedef int16_t coord_t; #if GFX_USE_GDISP || defined(__DOXYGEN__) /*===========================================================================*/ -/* Include the low level driver configuration information */ -/*===========================================================================*/ - -#include "gdisp_lld_config.h" - -/*===========================================================================*/ /* Type definitions */ /*===========================================================================*/ @@ -55,7 +49,11 @@ typedef struct point_t { /** * @brief Type for the text justification. */ -typedef enum justify {justifyLeft, justifyCenter, justifyRight} justify_t; +typedef enum justify { + justifyLeft = 0, + justifyCenter = 1, + justifyRight = 2 +} justify_t; /** * @brief Type for the font metric. */ @@ -63,7 +61,7 @@ typedef enum fontmetric {fontHeight, fontDescendersHeight, fontLineSpacing, font /** * @brief The type of a font. */ -typedef const struct font *font_t; +typedef const struct mf_font_s* font_t; /** * @brief Type for the screen orientation. */ @@ -476,35 +474,6 @@ extern "C" { void gdispFillArc(coord_t x, coord_t y, coord_t radius, coord_t startangle, coord_t endangle, color_t color); #endif - /* Basic Text Rendering Functions */ - - #if GDISP_NEED_TEXT || defined(__DOXYGEN__) - /** - * @brief Draw a text character. - * - * @param[in] x,y The position for the text - * @param[in] c The character to draw - * @param[in] font The font to use - * @param[in] color The color to use - * - * @api - */ - void gdispDrawChar(coord_t x, coord_t y, char c, font_t font, color_t color); - - /** - * @brief Draw a text character with a filled background. - * - * @param[in] x,y The position for the text - * @param[in] c The character to draw - * @param[in] font The font to use - * @param[in] color The color to use - * @param[in] bgcolor The background color to use - * - * @api - */ - void gdispFillChar(coord_t x, coord_t y, char c, font_t font, color_t color, color_t bgcolor); - #endif - /* Read a pixel Function */ #if GDISP_NEED_PIXELREAD || defined(__DOXYGEN__) @@ -587,8 +556,6 @@ extern "C" { #define gdispFillArc(x, y, radius, sangle, eangle, color) gdisp_lld_fill_arc(x, y, radius, sangle, eangle, color) #define gdispDrawEllipse(x, y, a, b, color) gdisp_lld_draw_ellipse(x, y, a, b, color) #define gdispFillEllipse(x, y, a, b, color) gdisp_lld_fill_ellipse(x, y, a, b, color) - #define gdispDrawChar(x, y, c, font, color) gdisp_lld_draw_char(x, y, c, font, color) - #define gdispFillChar(x, y, c, font, color, bgcolor) gdisp_lld_fill_char(x, y, c, font, color, bgcolor) #define gdispGetPixelColor(x, y) gdisp_lld_get_pixel_color(x, y) #define gdispVerticalScroll(x, y, cx, cy, lines, bgcolor) gdisp_lld_vertical_scroll(x, y, cx, cy, lines, bgcolor) #define gdispControl(what, value) gdisp_lld_control(what, value) @@ -648,10 +615,35 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color); void gdispFillConvexPoly(coord_t tx, coord_t ty, const point *pntarray, unsigned cnt, color_t color); #endif -/* Extra Text Functions */ +/* Text Functions */ #if GDISP_NEED_TEXT || defined(__DOXYGEN__) /** + * @brief Draw a text character. + * + * @param[in] x,y The position for the text + * @param[in] c The character to draw + * @param[in] font The font to use + * @param[in] color The color to use + * + * @api + */ + void gdispDrawChar(coord_t x, coord_t y, uint16_t c, font_t font, color_t color); + + /** + * @brief Draw a text character with a filled background. + * + * @param[in] x,y The position for the text + * @param[in] c The character to draw + * @param[in] font The font to use + * @param[in] color The color to use + * @param[in] bgcolor The background color to use + * + * @api + */ + void gdispFillChar(coord_t x, coord_t y, uint16_t c, font_t font, color_t color, color_t bgcolor); + + /** * @brief Draw a text string. * * @param[in] x,y The position for the text @@ -762,6 +754,17 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color); void gdispCloseFont(font_t font); /** + * @brief Make a scaled copy of an existing font. + * @details Allocates memory for new font metadata using gfxAlloc, remember to close font after use! + * @return A new font or NULL if out of memory. + * + * @param[in] font The base font to use. + * @param[in] scale_x The scale factor in horizontal direction. + * @param[in] scale_y The scale factor in vertical direction. + */ + font_t gdispScaleFont(font_t font, uint8_t scale_x, uint8_t scale_y); + + /** * @brief Get the name of the specified font. * @returns The name of the font. * diff --git a/include/gdisp/lld/emulation.c b/include/gdisp/lld/emulation.c index c897a92d..cb0c9c4b 100644 --- a/include/gdisp/lld/emulation.c +++ b/include/gdisp/lld/emulation.c @@ -461,185 +461,6 @@ GDISPDriver GDISP; } #endif -#if GDISP_NEED_TEXT && !GDISP_HARDWARE_TEXT - #include "gdisp/fonts.h" -#endif - -#if GDISP_NEED_TEXT && !GDISP_HARDWARE_TEXT - void gdisp_lld_draw_char(coord_t x, coord_t y, char c, font_t font, color_t color) { - const fontcolumn_t *ptr; - fontcolumn_t column; - coord_t width, height, xscale, yscale; - coord_t i, j, xs, ys; - - /* Check we actually have something to print */ - width = _getCharWidth(font, c); - if (!width) return; - - xscale = font->xscale; - yscale = font->yscale; - height = font->height * yscale; - width *= xscale; - - ptr = _getCharData(font, c); - - /* Loop through the data and display. The font data is LSBit first, down the column */ - for(i=0; i < width; i+=xscale) { - /* Get the font bitmap data for the column */ - column = *ptr++; - - /* Draw each pixel */ - for(j=0; j < height; j+=yscale, column >>= 1) { - if (column & 0x01) { - for(xs=0; xs < xscale; xs++) - for(ys=0; ys < yscale; ys++) - gdisp_lld_draw_pixel(x+i+xs, y+j+ys, color); - } - } - } - } -#endif - -#if GDISP_NEED_TEXT && !GDISP_HARDWARE_TEXTFILLS - void gdisp_lld_fill_char(coord_t x, coord_t y, char c, font_t font, color_t color, color_t bgcolor) { - coord_t width, height; - coord_t xscale, yscale; - - /* Check we actually have something to print */ - width = _getCharWidth(font, c); - if (!width) return; - - xscale = font->xscale; - yscale = font->yscale; - height = font->height * yscale; - width *= xscale; - - /* Method 1: Use background fill and then draw the text */ - #if GDISP_HARDWARE_TEXT || GDISP_SOFTWARE_TEXTFILLDRAW - - /* Fill the area */ - gdisp_lld_fill_area(x, y, width, height, bgcolor); - - /* Draw the text */ - gdisp_lld_draw_char(x, y, c, font, color); - - /* Method 2: Create a single column bitmap and then blit it */ - #elif GDISP_HARDWARE_BITFILLS && GDISP_SOFTWARE_TEXTBLITCOLUMN - { - const fontcolumn_t *ptr; - fontcolumn_t column; - coord_t i, j, xs, ys; - - /* Working buffer for fast non-transparent text rendering [patch by Badger] - This needs to be larger than the largest character we can print. - Assume the max is double sized by one column. - */ - static pixel_t buf[sizeof(fontcolumn_t)*8*2]; - - #if GDISP_NEED_VALIDATION - /* Check our buffer is big enough */ - if ((unsigned)height > sizeof(buf)/sizeof(buf[0])) return; - #endif - - ptr = _getCharData(font, c); - - /* Loop through the data and display. The font data is LSBit first, down the column */ - for(i = 0; i < width; i+=xscale) { - /* Get the font bitmap data for the column */ - column = *ptr++; - - /* Draw each pixel */ - for(j = 0; j < height; j+=yscale, column >>= 1) { - if (column & 0x01) { - for(ys=0; ys < yscale; ys++) - gdispPackPixels(buf, 1, j+ys, 0, color); - } else { - for(ys=0; ys < yscale; ys++) - gdispPackPixels(buf, 1, j+ys, 0, bgcolor); - } - } - - for(xs=0; xs < xscale; xs++) - gdisp_lld_blit_area_ex(x+i+xs, y, 1, height, 0, 0, 1, buf); - } - } - - /* Method 3: Create a character bitmap and then blit it */ - #elif GDISP_HARDWARE_BITFILLS - { - const fontcolumn_t *ptr; - fontcolumn_t column; - coord_t i, j, xs, ys; - - /* Working buffer for fast non-transparent text rendering [patch by Badger] - This needs to be larger than the largest character we can print. - Assume the max is double sized. - */ - static pixel_t buf[20*(sizeof(fontcolumn_t)*8)*2]; - - #if GDISP_NEED_VALIDATION - /* Check our buffer is big enough */ - if ((unsigned)(width * height) > sizeof(buf)/sizeof(buf[0])) return; - #endif - - ptr = _getCharData(font, c); - - /* Loop through the data and display. The font data is LSBit first, down the column */ - for(i = 0; i < width; i+=xscale) { - /* Get the font bitmap data for the column */ - column = *ptr++; - - /* Draw each pixel */ - for(j = 0; j < height; j+=yscale, column >>= 1) { - if (column & 0x01) { - for(xs=0; xs < xscale; xs++) - for(ys=0; ys < yscale; ys++) - gdispPackPixels(buf, width, i+xs, j+ys, color); - } else { - for(xs=0; xs < xscale; xs++) - for(ys=0; ys < yscale; ys++) - gdispPackPixels(buf, width, i+xs, j+ys, bgcolor); - } - } - } - - /* [Patch by Badger] Write all in one stroke */ - gdisp_lld_blit_area_ex(x, y, width, height, 0, 0, width, buf); - } - - /* Method 4: Draw pixel by pixel */ - #else - { - const fontcolumn_t *ptr; - fontcolumn_t column; - coord_t i, j, xs, ys; - - ptr = _getCharData(font, c); - - /* Loop through the data and display. The font data is LSBit first, down the column */ - for(i = 0; i < width; i+=xscale) { - /* Get the font bitmap data for the column */ - column = *ptr++; - - /* Draw each pixel */ - for(j = 0; j < height; j+=yscale, column >>= 1) { - if (column & 0x01) { - for(xs=0; xs < xscale; xs++) - for(ys=0; ys < yscale; ys++) - gdisp_lld_draw_pixel(x+i+xs, y+j+ys, color); - } else { - for(xs=0; xs < xscale; xs++) - for(ys=0; ys < yscale; ys++) - gdisp_lld_draw_pixel(x+i+xs, y+j+ys, bgcolor); - } - } - } - } - #endif - } -#endif - - #if GDISP_NEED_CONTROL && !GDISP_HARDWARE_CONTROL void gdisp_lld_control(unsigned what, void *value) { (void)what; @@ -707,14 +528,6 @@ void *gdisp_lld_query(unsigned what) { gdisp_lld_fill_circle(msg->fillarc.x, msg->fillarc.y, msg->fillarc.radius, msg->fillarc.startangle, msg->fillarc.endangle, msg->fillarc.color); break; #endif - #if GDISP_NEED_TEXT - case GDISP_LLD_MSG_DRAWCHAR: - gdisp_lld_draw_char(msg->drawchar.x, msg->drawchar.y, msg->drawchar.c, msg->drawchar.font, msg->drawchar.color); - break; - case GDISP_LLD_MSG_FILLCHAR: - gdisp_lld_fill_char(msg->fillchar.x, msg->fillchar.y, msg->fillchar.c, msg->fillchar.font, msg->fillchar.color, msg->fillchar.bgcolor); - break; - #endif #if GDISP_NEED_PIXELREAD case GDISP_LLD_MSG_GETPIXELCOLOR: msg->getpixelcolor.result = gdisp_lld_get_pixel_color(msg->getpixelcolor.x, msg->getpixelcolor.y); diff --git a/include/gdisp/lld/gdisp_lld.h b/include/gdisp/lld/gdisp_lld.h index afd166ae..98c7569c 100644 --- a/include/gdisp/lld/gdisp_lld.h +++ b/include/gdisp/lld/gdisp_lld.h @@ -107,22 +107,6 @@ #endif /** - * @brief Hardware accelerated text drawing. - * @details If set to @p FALSE software emulation is used. - */ - #ifndef GDISP_HARDWARE_TEXT - #define GDISP_HARDWARE_TEXT FALSE - #endif - - /** - * @brief Hardware accelerated text drawing with a filled background. - * @details If set to @p FALSE software emulation is used. - */ - #ifndef GDISP_HARDWARE_TEXTFILLS - #define GDISP_HARDWARE_TEXTFILLS FALSE - #endif - - /** * @brief Hardware accelerated scrolling. * @details If set to @p FALSE there is no support for scrolling. */ @@ -167,26 +151,6 @@ * @name GDISP software algorithm choices * @{ */ - /** - * @brief For filled text drawing, use a background fill and then draw - * the text instead of using a blit or direct pixel drawing. - * @details If set to @p TRUE background fill and then text draw is used. - * @note This is ignored if hardware accelerated text is supported. - */ - #ifndef GDISP_SOFTWARE_TEXTFILLDRAW - #define GDISP_SOFTWARE_TEXTFILLDRAW FALSE - #endif - - /** - * @brief For filled text drawing, when using a bitmap blit - * use a column by column buffer rather than a full character - * buffer to save memory at a small performance cost. - * @details If set to @p TRUE background fill one character column at a time. - * @note This is ignored if software text using blit is not being used. - */ - #ifndef GDISP_SOFTWARE_TEXTBLITCOLUMN - #define GDISP_SOFTWARE_TEXTBLITCOLUMN FALSE - #endif /** @} */ /** @@ -281,8 +245,8 @@ extern "C" { /* Text Rendering Functions */ #if GDISP_NEED_TEXT - extern void gdisp_lld_draw_char(coord_t x, coord_t y, char c, font_t font, color_t color); - extern void gdisp_lld_fill_char(coord_t x, coord_t y, char c, font_t font, color_t color, color_t bgcolor); + extern void gdisp_lld_draw_char(coord_t x, coord_t y, uint16_t c, font_t font, color_t color); + extern void gdisp_lld_fill_char(coord_t x, coord_t y, uint16_t c, font_t font, color_t color, color_t bgcolor); #endif /* Pixel readback */ diff --git a/include/gdisp/lld/gdisp_lld_msgs.h b/include/gdisp/lld/gdisp_lld_msgs.h index f2e0e66e..2c199cbe 100644 --- a/include/gdisp/lld/gdisp_lld_msgs.h +++ b/include/gdisp/lld/gdisp_lld_msgs.h @@ -42,10 +42,6 @@ typedef enum gdisp_msgaction { GDISP_LLD_MSG_DRAWARC, GDISP_LLD_MSG_FILLARC, #endif - #if GDISP_NEED_TEXT - GDISP_LLD_MSG_DRAWCHAR, - GDISP_LLD_MSG_FILLCHAR, - #endif #if GDISP_NEED_PIXELREAD GDISP_LLD_MSG_GETPIXELCOLOR, #endif @@ -151,23 +147,6 @@ typedef union gdisp_lld_msg { coord_t startangle, endangle; color_t color; } fillarc; - struct gdisp_lld_msg_drawchar { - gfxQueueItem qi; - gdisp_msgaction_t action; // GDISP_LLD_MSG_DRAWCHAR - coord_t x, y; - char c; - font_t font; - color_t color; - } drawchar; - struct gdisp_lld_msg_fillchar { - gfxQueueItem qi; - gdisp_msgaction_t action; // GDISP_LLD_MSG_FILLCHAR - coord_t x, y; - char c; - font_t font; - color_t color; - color_t bgcolor; - } fillchar; struct gdisp_lld_msg_getpixelcolor { gfxQueueItem qi; gdisp_msgaction_t action; // GDISP_LLD_MSG_GETPIXELCOLOR diff --git a/include/gdisp/options.h b/include/gdisp/options.h index 30587530..d5818284 100644 --- a/include/gdisp/options.h +++ b/include/gdisp/options.h @@ -182,6 +182,36 @@ #endif /** * @} + * + * @name GDISP Text Rendering Options + * @{ + */ + /** + * @brief Enable UTF-8 support for text rendering. + * @details Defaults to FALSE + */ + #ifndef GDISP_NEED_UTF8 + #define GDISP_NEED_UTF8 FALSE + #endif + + /** + * @brief Enable kerning for font rendering (improves character placement). + * @details Defaults to FALSE + */ + #ifndef GDISP_NEED_TEXT_KERNING + #define GDISP_NEED_TEXT_KERNING FALSE + #endif + + /** + * @brief Enable antialiased font support + * @details Defaults to FALSE + */ + #ifndef GDISP_NEED_ANTIALIAS + #define GDISP_NEED_ANTIALIAS FALSE + #endif + +/** + * @} * * @name GDISP Multi-Threading Options * @{ @@ -220,21 +250,6 @@ * @brief Predefined built in fonts * @note Turning off the ones you are not using can save program size. */ - #ifndef GDISP_INCLUDE_FONT_SMALL - #define GDISP_INCLUDE_FONT_SMALL TRUE - #endif - #ifndef GDISP_INCLUDE_FONT_LARGER - #define GDISP_INCLUDE_FONT_LARGER TRUE - #endif - #ifndef GDISP_INCLUDE_FONT_UI1 - #define GDISP_INCLUDE_FONT_UI1 TRUE - #endif - #ifndef GDISP_INCLUDE_FONT_UI2 - #define GDISP_INCLUDE_FONT_UI2 TRUE - #endif - #ifndef GDISP_INCLUDE_FONT_LARGENUMBERS - #define GDISP_INCLUDE_FONT_LARGENUMBERS TRUE - #endif /** * @} @@ -242,16 +257,6 @@ * @name GDISP Optional Sizing Parameters * @{ */ - /** - * @brief The maximum height of a font. - * @details Either 16 or 32. Defaults to 16 - * @note Setting this to 32 causes the font tables to take - * twice the internal program memory. Don't do it unless - * you realy must define an unscaled font larger than 16 bits high. - */ - #ifndef GDISP_MAX_FONT_HEIGHT - #define GDISP_MAX_FONT_HEIGHT 16 - #endif /** * @} * @@ -291,6 +296,10 @@ /* #define GDISP_USE_GPIO */ /** @} */ +#if GFX_USE_GDISP + #include "gdisp_lld_config.h" +#endif + #endif /* _GDISP_OPTIONS_H */ /** @} */ |