2012-03-27 04:21:47 +02:00
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* nuttx/graphics/nxterm/nxterm_font.c
|
2012-03-27 04:21:47 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2012-03-31 00:49:08 +02:00
|
|
|
#include <string.h>
|
2012-03-30 20:42:40 +02:00
|
|
|
#include <assert.h>
|
2012-03-31 18:26:32 +02:00
|
|
|
#include <errno.h>
|
2012-03-27 04:21:47 +02:00
|
|
|
#include <debug.h>
|
|
|
|
|
2012-03-31 00:49:08 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
#include "nxterm.h"
|
2012-03-27 04:21:47 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-04-08 16:32:05 +02:00
|
|
|
* Pre-processor Definitions
|
2012-03-27 04:21:47 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Select renderer -- Some additional logic would be required to support
|
|
|
|
* pixel depths that are not directly addressable (1,2,4, and 24).
|
|
|
|
*/
|
|
|
|
|
2014-09-20 22:18:08 +02:00
|
|
|
#if CONFIG_NXTERM_BPP == 1
|
2012-03-27 04:21:47 +02:00
|
|
|
# define RENDERER nxf_convert_1bpp
|
2014-09-20 22:18:08 +02:00
|
|
|
#elif CONFIG_NXTERM_BPP == 2
|
2012-03-27 04:21:47 +02:00
|
|
|
# define RENDERER nxf_convert_2bpp
|
2014-09-20 22:18:08 +02:00
|
|
|
#elif CONFIG_NXTERM_BPP == 4
|
2012-03-27 04:21:47 +02:00
|
|
|
# define RENDERER nxf_convert_4bpp
|
2014-09-20 22:18:08 +02:00
|
|
|
#elif CONFIG_NXTERM_BPP == 8
|
2012-03-27 04:21:47 +02:00
|
|
|
# define RENDERER nxf_convert_8bpp
|
2014-09-20 22:18:08 +02:00
|
|
|
#elif CONFIG_NXTERM_BPP == 16
|
2012-03-27 04:21:47 +02:00
|
|
|
# define RENDERER nxf_convert_16bpp
|
2014-09-20 22:18:08 +02:00
|
|
|
#elif CONFIG_NXTERM_BPP == 24
|
2012-03-27 04:21:47 +02:00
|
|
|
# define RENDERER nxf_convert_24bpp
|
2014-09-20 22:18:08 +02:00
|
|
|
#elif CONFIG_NXTERM_BPP == 32
|
2012-03-27 04:21:47 +02:00
|
|
|
# define RENDERER nxf_convert_32bpp
|
|
|
|
#else
|
2014-09-20 22:18:08 +02:00
|
|
|
# error "Unsupported CONFIG_NXTERM_BPP"
|
2012-03-27 04:21:47 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* Name: nxterm_freeglyph
|
2012-03-27 04:21:47 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
static void nxterm_freeglyph(FAR struct nxterm_glyph_s *glyph)
|
2012-03-27 04:21:47 +02:00
|
|
|
{
|
|
|
|
if (glyph->bitmap)
|
|
|
|
{
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free(glyph->bitmap);
|
2012-03-27 04:21:47 +02:00
|
|
|
}
|
2014-09-20 23:53:28 +02:00
|
|
|
memset(glyph, 0, sizeof(struct nxterm_glyph_s));
|
2012-03-27 04:21:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* Name: nxterm_allocglyph
|
2012-03-27 04:21:47 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
static inline FAR struct nxterm_glyph_s *
|
|
|
|
nxterm_allocglyph(FAR struct nxterm_state_s *priv)
|
2012-03-27 04:21:47 +02:00
|
|
|
{
|
2014-09-20 23:53:28 +02:00
|
|
|
FAR struct nxterm_glyph_s *glyph = NULL;
|
|
|
|
FAR struct nxterm_glyph_s *luglyph = NULL;
|
2012-03-27 04:21:47 +02:00
|
|
|
uint8_t luusecnt;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Search through the glyph cache looking for an unused glyph. Also, keep
|
|
|
|
* track of the least used glyph as well. We need that if we have to replace
|
|
|
|
* a glyph in the cache.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < priv->maxglyphs; i++)
|
|
|
|
{
|
|
|
|
/* Is this glyph in use? */
|
|
|
|
|
|
|
|
glyph = &priv->glyph[i];
|
|
|
|
if (!glyph->usecnt)
|
|
|
|
{
|
|
|
|
/* No.. return this glyph with a use count of one */
|
|
|
|
|
|
|
|
glyph->usecnt = 1;
|
|
|
|
return glyph;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Yes.. check for the least recently used */
|
|
|
|
|
|
|
|
if (!luglyph || glyph->usecnt < luglyph->usecnt)
|
|
|
|
{
|
|
|
|
luglyph = glyph;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get here, the glyph cache is full. We replace the least used
|
|
|
|
* glyph with the one we need now. (luglyph can't be NULL).
|
|
|
|
*/
|
2014-04-14 00:22:22 +02:00
|
|
|
|
2012-03-27 04:21:47 +02:00
|
|
|
luusecnt = luglyph->usecnt;
|
2014-09-20 23:53:28 +02:00
|
|
|
nxterm_freeglyph(luglyph);
|
2012-03-27 04:21:47 +02:00
|
|
|
|
|
|
|
/* But lets decrement all of the usecnts so that the new one one be so
|
|
|
|
* far behind in the counts as the older ones.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (luusecnt > 1)
|
|
|
|
{
|
|
|
|
uint8_t decr = luusecnt - 1;
|
2014-04-14 00:22:22 +02:00
|
|
|
|
2012-03-27 04:21:47 +02:00
|
|
|
for (i = 0; i < priv->maxglyphs; i++)
|
|
|
|
{
|
|
|
|
/* Is this glyph in use? */
|
|
|
|
|
|
|
|
glyph = &priv->glyph[i];
|
|
|
|
if (glyph->usecnt > decr)
|
|
|
|
{
|
|
|
|
glyph->usecnt -= decr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then return the least used glyph */
|
|
|
|
|
|
|
|
luglyph->usecnt = 1;
|
|
|
|
return luglyph;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* Name: nxterm_findglyph
|
2012-03-27 04:21:47 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
static FAR struct nxterm_glyph_s *
|
|
|
|
nxterm_findglyph(FAR struct nxterm_state_s *priv, uint8_t ch)
|
2012-03-27 04:21:47 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* First, try to find the glyph in the cache of pre-rendered glyphs */
|
|
|
|
|
|
|
|
for (i = 0; i < priv->maxglyphs; i++)
|
|
|
|
{
|
2014-09-20 23:53:28 +02:00
|
|
|
FAR struct nxterm_glyph_s *glyph = &priv->glyph[i];
|
2012-03-27 04:21:47 +02:00
|
|
|
if (glyph->usecnt > 0 && glyph->code == ch)
|
|
|
|
{
|
|
|
|
/* Increment the use count (unless it is already at the max) */
|
|
|
|
|
|
|
|
if (glyph->usecnt < MAX_USECNT)
|
|
|
|
{
|
|
|
|
glyph->usecnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And return the glyph that we found */
|
|
|
|
|
|
|
|
return glyph;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* Name: nxterm_renderglyph
|
2012-03-27 04:21:47 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
static inline FAR struct nxterm_glyph_s *
|
|
|
|
nxterm_renderglyph(FAR struct nxterm_state_s *priv,
|
2012-03-27 04:21:47 +02:00
|
|
|
FAR const struct nx_fontbitmap_s *fbm, uint8_t ch)
|
|
|
|
{
|
2014-09-20 23:53:28 +02:00
|
|
|
FAR struct nxterm_glyph_s *glyph = NULL;
|
2012-03-27 04:21:47 +02:00
|
|
|
FAR nxgl_mxpixel_t *ptr;
|
2014-09-20 22:18:08 +02:00
|
|
|
#if CONFIG_NXTERM_BPP < 8
|
2012-03-27 04:21:47 +02:00
|
|
|
nxgl_mxpixel_t pixel;
|
|
|
|
#endif
|
2012-03-31 00:49:08 +02:00
|
|
|
int bmsize;
|
2012-03-27 04:21:47 +02:00
|
|
|
int row;
|
|
|
|
int col;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Allocate the glyph (always succeeds) */
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
glyph = nxterm_allocglyph(priv);
|
2012-03-27 04:21:47 +02:00
|
|
|
glyph->code = ch;
|
|
|
|
|
|
|
|
/* Get the dimensions of the glyph */
|
|
|
|
|
|
|
|
glyph->width = fbm->metric.width + fbm->metric.xoffset;
|
|
|
|
glyph->height = fbm->metric.height + fbm->metric.yoffset;
|
|
|
|
|
2012-03-28 21:29:30 +02:00
|
|
|
/* Get the physical width of the glyph in bytes */
|
2012-03-27 04:21:47 +02:00
|
|
|
|
2014-09-20 22:18:08 +02:00
|
|
|
glyph->stride = (glyph->width * CONFIG_NXTERM_BPP + 7) / 8;
|
2012-03-28 21:29:30 +02:00
|
|
|
|
|
|
|
/* Allocate memory to hold the glyph with its offsets */
|
|
|
|
|
2012-03-31 00:49:08 +02:00
|
|
|
bmsize = glyph->stride * glyph->height;
|
2014-09-01 01:26:36 +02:00
|
|
|
glyph->bitmap = (FAR uint8_t *)kmm_malloc(bmsize);
|
2012-03-27 04:21:47 +02:00
|
|
|
|
|
|
|
if (glyph->bitmap)
|
|
|
|
{
|
2012-03-28 21:29:30 +02:00
|
|
|
/* Initialize the glyph memory to the background color using the
|
|
|
|
* hard-coded bits-per-pixel (BPP).
|
|
|
|
*
|
|
|
|
* TODO: The rest of NX is configured to support multiple devices
|
|
|
|
* with differing BPP. They logic should be extended to support
|
|
|
|
* differing BPP's as well.
|
|
|
|
*/
|
2012-03-27 04:21:47 +02:00
|
|
|
|
2014-09-20 22:18:08 +02:00
|
|
|
#if CONFIG_NXTERM_BPP < 8
|
2013-12-15 14:25:49 +01:00
|
|
|
pixel = priv->wndo.wcolor[0];
|
2012-03-28 21:29:30 +02:00
|
|
|
|
2014-09-20 22:18:08 +02:00
|
|
|
# if CONFIG_NXTERM_BPP == 1
|
2012-03-28 21:29:30 +02:00
|
|
|
|
2012-03-27 04:21:47 +02:00
|
|
|
/* Pack 1-bit pixels into a 2-bits */
|
|
|
|
|
|
|
|
pixel &= 0x01;
|
2012-03-28 21:29:30 +02:00
|
|
|
pixel = (pixel) << 1 | pixel;
|
|
|
|
|
2012-03-27 04:21:47 +02:00
|
|
|
# endif
|
2014-09-20 22:18:08 +02:00
|
|
|
# if CONFIG_NXTERM_BPP < 4
|
2012-03-28 21:29:30 +02:00
|
|
|
|
2012-03-27 04:21:47 +02:00
|
|
|
/* Pack 2-bit pixels into a nibble */
|
|
|
|
|
|
|
|
pixel &= 0x03;
|
2012-03-28 21:29:30 +02:00
|
|
|
pixel = (pixel) << 2 | pixel;
|
|
|
|
|
2012-03-27 04:21:47 +02:00
|
|
|
# endif
|
|
|
|
|
|
|
|
/* Pack 4-bit nibbles into a byte */
|
|
|
|
|
|
|
|
pixel &= 0x0f;
|
|
|
|
pixel = (pixel) << 4 | pixel;
|
|
|
|
|
|
|
|
ptr = (FAR nxgl_mxpixel_t *)glyph->bitmap;
|
|
|
|
for (row = 0; row < glyph->height; row++)
|
|
|
|
{
|
|
|
|
for (col = 0; col < glyph->stride; col++)
|
|
|
|
{
|
|
|
|
/* Transfer the packed bytes into the buffer */
|
|
|
|
|
|
|
|
*ptr++ = pixel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-20 22:18:08 +02:00
|
|
|
#elif CONFIG_NXTERM_BPP == 24
|
2012-03-27 04:21:47 +02:00
|
|
|
# error "Additional logic is needed here for 24bpp support"
|
|
|
|
|
2014-09-20 22:18:08 +02:00
|
|
|
#else /* CONFIG_NXTERM_BPP = {8,16,32} */
|
2012-03-27 04:21:47 +02:00
|
|
|
|
|
|
|
ptr = (FAR nxgl_mxpixel_t *)glyph->bitmap;
|
|
|
|
for (row = 0; row < glyph->height; row++)
|
|
|
|
{
|
|
|
|
/* Just copy the color value into the glyph memory */
|
|
|
|
|
|
|
|
for (col = 0; col < glyph->width; col++)
|
|
|
|
{
|
|
|
|
*ptr++ = priv->wndo.wcolor[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Then render the glyph into the allocated memory */
|
|
|
|
|
2015-10-08 17:10:22 +02:00
|
|
|
ret = RENDERER((FAR nxgl_mxpixel_t *)glyph->bitmap,
|
2012-03-27 04:21:47 +02:00
|
|
|
glyph->height, glyph->width, glyph->stride,
|
|
|
|
fbm, priv->wndo.fcolor[0]);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Actually, the RENDERER never returns a failure */
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
gdbg("nxterm_renderglyph: RENDERER failed\n");
|
|
|
|
nxterm_freeglyph(glyph);
|
2012-03-27 04:21:47 +02:00
|
|
|
glyph = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return glyph;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* Name: nxterm_fontsize
|
2012-03-27 04:21:47 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
static int nxterm_fontsize(NXHANDLE hfont, uint8_t ch, FAR struct nxgl_size_s *size)
|
2012-03-27 04:21:47 +02:00
|
|
|
{
|
|
|
|
FAR const struct nx_fontbitmap_s *fbm;
|
|
|
|
|
|
|
|
/* No, it is not cached... Does the code map to a font? */
|
|
|
|
|
|
|
|
fbm = nxf_getbitmap(hfont, ch);
|
|
|
|
if (fbm)
|
|
|
|
{
|
|
|
|
/* Yes.. return the font size */
|
|
|
|
|
|
|
|
size->w = fbm->metric.width + fbm->metric.xoffset;
|
|
|
|
size->h = fbm->metric.height + fbm->metric.yoffset;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* Name: nxterm_getglyph
|
2012-03-27 04:21:47 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
static FAR struct nxterm_glyph_s *
|
|
|
|
nxterm_getglyph(NXHANDLE hfont, FAR struct nxterm_state_s *priv, uint8_t ch)
|
2012-03-27 04:21:47 +02:00
|
|
|
{
|
2014-09-20 23:53:28 +02:00
|
|
|
FAR struct nxterm_glyph_s *glyph;
|
2012-03-27 04:21:47 +02:00
|
|
|
FAR const struct nx_fontbitmap_s *fbm;
|
|
|
|
|
|
|
|
/* First, try to find the glyph in the cache of pre-rendered glyphs */
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
glyph = nxterm_findglyph(priv, ch);
|
2012-03-27 04:21:47 +02:00
|
|
|
if (glyph)
|
|
|
|
{
|
|
|
|
/* We found it in the cache .. return the cached glyph */
|
|
|
|
|
|
|
|
return glyph;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No, it is not cached... Does the code map to a font? */
|
|
|
|
|
|
|
|
fbm = nxf_getbitmap(hfont, ch);
|
|
|
|
if (fbm)
|
|
|
|
{
|
|
|
|
/* Yes.. render the glyph */
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
glyph = nxterm_renderglyph(priv, fbm, ch);
|
2012-03-27 04:21:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return glyph;
|
|
|
|
}
|
|
|
|
|
2012-03-30 20:42:40 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-03-27 04:21:47 +02:00
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* Name: nxterm_addchar
|
2012-03-27 04:21:47 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2014-09-20 23:53:28 +02:00
|
|
|
* This is part of the nxterm_putc logic. It creates and positions a
|
2012-03-27 04:21:47 +02:00
|
|
|
* the character and renders (or re-uses) a glyph for font.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
FAR const struct nxterm_bitmap_s *
|
|
|
|
nxterm_addchar(NXHANDLE hfont, FAR struct nxterm_state_s *priv, uint8_t ch)
|
2012-03-27 04:21:47 +02:00
|
|
|
{
|
2014-09-20 23:53:28 +02:00
|
|
|
FAR struct nxterm_bitmap_s *bm = NULL;
|
|
|
|
FAR struct nxterm_glyph_s *glyph;
|
2012-03-27 04:21:47 +02:00
|
|
|
|
|
|
|
/* Is there space for another character on the display? */
|
|
|
|
|
|
|
|
if (priv->nchars < priv->maxchars)
|
|
|
|
{
|
2012-03-27 18:59:15 +02:00
|
|
|
/* Yes, setup the bitmap information */
|
2012-03-27 04:21:47 +02:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
bm = &priv->bm[priv->nchars];
|
|
|
|
bm->code = ch;
|
|
|
|
bm->flags = 0;
|
|
|
|
bm->pos.x = priv->fpos.x;
|
|
|
|
bm->pos.y = priv->fpos.y;
|
2012-03-27 04:21:47 +02:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
/* Find (or create) the matching glyph */
|
2012-03-27 04:21:47 +02:00
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
glyph = nxterm_getglyph(hfont, priv, ch);
|
2012-03-27 18:59:15 +02:00
|
|
|
if (!glyph)
|
|
|
|
{
|
|
|
|
/* No, there is no font for this code. Just mark this as a space. */
|
2012-03-27 04:21:47 +02:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
bm->flags |= BMFLAGS_NOGLYPH;
|
2012-03-27 04:21:47 +02:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
/* Set up the next character position */
|
2012-03-27 04:21:47 +02:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
priv->fpos.x += priv->spwidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Set up the next character position */
|
2012-03-27 04:21:47 +02:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
priv->fpos.x += glyph->width;
|
|
|
|
}
|
2012-03-27 04:21:47 +02:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
/* Success.. increment nchars to retain this character */
|
2012-03-27 04:21:47 +02:00
|
|
|
|
2012-03-27 18:59:15 +02:00
|
|
|
priv->nchars++;
|
2012-03-27 04:21:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
|
2012-03-31 18:26:32 +02:00
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* Name: nxterm_hidechar
|
2012-03-31 18:26:32 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Erase a character from the window.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2014-09-20 23:53:28 +02:00
|
|
|
int nxterm_hidechar(FAR struct nxterm_state_s *priv,
|
|
|
|
FAR const struct nxterm_bitmap_s *bm)
|
2012-03-31 18:26:32 +02:00
|
|
|
{
|
|
|
|
struct nxgl_rect_s bounds;
|
|
|
|
struct nxgl_size_s fsize;
|
|
|
|
int ret;
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
/* Get the size of the font glyph. If nxterm_fontsize, then the
|
2012-03-31 18:26:32 +02:00
|
|
|
* character will have been rendered as a space, and no display
|
|
|
|
* modification is required (not an error).
|
|
|
|
*/
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
ret = nxterm_fontsize(priv->font, bm->code, &fsize);
|
2012-03-31 18:26:32 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* It was rendered as a space. */
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Construct a bounding box for the glyph */
|
|
|
|
|
|
|
|
bounds.pt1.x = bm->pos.x;
|
|
|
|
bounds.pt1.y = bm->pos.y;
|
|
|
|
bounds.pt2.x = bm->pos.x + fsize.w - 1;
|
|
|
|
bounds.pt2.y = bm->pos.y + fsize.h - 1;
|
|
|
|
|
|
|
|
/* Fill the bitmap region with the background color, erasing the
|
|
|
|
* character from the display. NOTE: This region might actually
|
|
|
|
* be obscured... NX will handle that case.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return priv->ops->fill(priv, &bounds, priv->wndo.wcolor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* Name: nxterm_backspace
|
2012-03-31 18:26:32 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Remove the last character from the window.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
int nxterm_backspace(FAR struct nxterm_state_s *priv)
|
2012-03-31 18:26:32 +02:00
|
|
|
{
|
2014-09-20 23:53:28 +02:00
|
|
|
FAR struct nxterm_bitmap_s *bm;
|
2012-03-31 18:26:32 +02:00
|
|
|
int ndx;
|
|
|
|
int ret = -ENOENT;
|
|
|
|
|
|
|
|
/* Is there a character on the display? */
|
|
|
|
|
|
|
|
if (priv->nchars > 0)
|
|
|
|
{
|
|
|
|
/* Yes.. Get the index to the last bitmap on the display */
|
|
|
|
|
|
|
|
ndx = priv->nchars - 1;
|
|
|
|
bm = &priv->bm[ndx];
|
|
|
|
|
|
|
|
/* Erase the character from the display */
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
ret = nxterm_hidechar(priv, bm);
|
2012-03-31 18:26:32 +02:00
|
|
|
|
|
|
|
/* The current position to the location where the last character was */
|
2014-04-14 00:22:22 +02:00
|
|
|
|
2012-03-31 18:26:32 +02:00
|
|
|
priv->fpos.x = bm->pos.x;
|
|
|
|
priv->fpos.y = bm->pos.y;
|
|
|
|
|
|
|
|
/* Decrement nchars to discard this character */
|
|
|
|
|
|
|
|
priv->nchars = ndx;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-03-27 04:21:47 +02:00
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* Name: nxterm_home
|
2012-03-27 04:21:47 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set the next character position to the top-left corner of the display.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
void nxterm_home(FAR struct nxterm_state_s *priv)
|
2012-03-27 04:21:47 +02:00
|
|
|
{
|
|
|
|
/* The first character is one space from the left */
|
|
|
|
|
|
|
|
priv->fpos.x = priv->spwidth;
|
|
|
|
|
2014-09-20 22:18:08 +02:00
|
|
|
/* And CONFIG_NXTERM_LINESEPARATION lines from the top */
|
2012-03-27 04:21:47 +02:00
|
|
|
|
2014-09-20 22:18:08 +02:00
|
|
|
priv->fpos.y = CONFIG_NXTERM_LINESEPARATION;
|
2012-03-27 04:21:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* Name: nxterm_newline
|
2012-03-27 04:21:47 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set the next character position to the beginning of the next line.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
void nxterm_newline(FAR struct nxterm_state_s *priv)
|
2012-03-27 04:21:47 +02:00
|
|
|
{
|
|
|
|
/* Carriage return: The first character is one space from the left */
|
|
|
|
|
|
|
|
priv->fpos.x = priv->spwidth;
|
|
|
|
|
2014-09-20 22:18:08 +02:00
|
|
|
/* Linefeed: Down the max font height + CONFIG_NXTERM_LINESEPARATION */
|
2012-03-27 04:21:47 +02:00
|
|
|
|
2014-09-20 22:18:08 +02:00
|
|
|
priv->fpos.y += (priv->fheight + CONFIG_NXTERM_LINESEPARATION);
|
2012-03-27 04:21:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* Name: nxterm_fillchar
|
2012-03-27 04:21:47 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2014-09-20 23:53:28 +02:00
|
|
|
* This implements the character display. It is part of the nxterm_putc
|
2012-03-27 04:21:47 +02:00
|
|
|
* operation but may also be used when redrawing an existing display.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
void nxterm_fillchar(FAR struct nxterm_state_s *priv,
|
2012-03-27 04:21:47 +02:00
|
|
|
FAR const struct nxgl_rect_s *rect,
|
2014-09-20 23:53:28 +02:00
|
|
|
FAR const struct nxterm_bitmap_s *bm)
|
2012-03-27 04:21:47 +02:00
|
|
|
{
|
2014-09-20 23:53:28 +02:00
|
|
|
FAR struct nxterm_glyph_s *glyph;
|
2012-03-27 04:21:47 +02:00
|
|
|
struct nxgl_rect_s bounds;
|
|
|
|
struct nxgl_rect_s intersection;
|
|
|
|
struct nxgl_size_s fsize;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Handle the special case of spaces which have no glyph bitmap */
|
|
|
|
|
|
|
|
if (BM_ISSPACE(bm))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the size of the font glyph (which may not have been created yet) */
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
ret = nxterm_fontsize(priv->font, bm->code, &fsize);
|
2012-03-27 04:21:47 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* This would mean that there is no bitmap for the character code and
|
|
|
|
* that the font would be rendered as a space. But this case should
|
|
|
|
* never happen here because the BM_ISSPACE() should have already
|
|
|
|
* found all such cases.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Construct a bounding box for the glyph */
|
|
|
|
|
|
|
|
bounds.pt1.x = bm->pos.x;
|
|
|
|
bounds.pt1.y = bm->pos.y;
|
|
|
|
bounds.pt2.x = bm->pos.x + fsize.w - 1;
|
|
|
|
bounds.pt2.y = bm->pos.y + fsize.h - 1;
|
|
|
|
|
|
|
|
/* Should this also be clipped to a region in the window? */
|
|
|
|
|
|
|
|
if (rect)
|
|
|
|
{
|
|
|
|
/* Get the intersection of the redraw region and the character bitmap */
|
|
|
|
|
|
|
|
nxgl_rectintersect(&intersection, rect, &bounds);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The intersection is the whole glyph */
|
|
|
|
|
|
|
|
nxgl_rectcopy(&intersection, &bounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for empty intersections */
|
|
|
|
|
|
|
|
if (!nxgl_nullrect(&intersection))
|
|
|
|
{
|
|
|
|
FAR const void *src;
|
|
|
|
|
|
|
|
/* Find (or create) the glyph that goes with this font */
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
glyph = nxterm_getglyph(priv->font, priv, bm->code);
|
2012-03-27 04:21:47 +02:00
|
|
|
if (!glyph)
|
|
|
|
{
|
|
|
|
/* Shouldn't happen */
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Blit the font bitmap into the window */
|
|
|
|
|
|
|
|
src = (FAR const void *)glyph->bitmap;
|
|
|
|
ret = priv->ops->bitmap(priv, &intersection, &src,
|
|
|
|
&bm->pos, (unsigned int)glyph->stride);
|
2012-03-30 00:20:47 +02:00
|
|
|
DEBUGASSERT(ret >= 0);
|
2012-03-27 04:21:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|