* graphics/nxterm/nxterm_font.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/kmalloc.h>
#include "nxterm.h"
* Private Functions
****************************************************************************/
* Name: nxterm_fontsize
****************************************************************************/
static int nxterm_fontsize(FAR struct nxterm_state_s *priv, uint8_t ch,
FAR struct nxgl_size_s *size)
{
FAR const struct nx_fontbitmap_s *fbm;
NXHANDLE hfont;
hfont = nxf_cache_getfonthandle(priv->fcache);
DEBUGASSERT(hfont != NULL);
fbm = nxf_getbitmap(hfont, ch);
if (fbm)
{
size->w = fbm->metric.width + fbm->metric.xoffset;
size->h = fbm->metric.height + fbm->metric.yoffset;
return OK;
}
return -ENOENT;
}
* Name: nxterm_fillspace
****************************************************************************/
static void nxterm_fillspace(FAR struct nxterm_state_s *priv,
FAR const struct nxgl_rect_s *rect,
FAR const struct nxterm_bitmap_s *bm)
{
#if 0
struct nxgl_rect_s bounds;
struct nxgl_rect_s intersection;
int ret;
bounds.pt1.x = bm->pos.x;
bounds.pt1.y = bm->pos.y;
bounds.pt2.x = bm->pos.x + priv->spwidth - 1;
bounds.pt2.y = bm->pos.y + priv->fheight - 1;
#
if (rect != NULL)
{
nxgl_rectintersect(&intersection, rect, &bounds);
}
else
{
nxgl_rectcopy(&intersection, &bounds);
}
if (!nxgl_nullrect(&intersection))
{
* character from the display. NOTE: This region might actually
* be obscured... NX will handle that case.
*/
ret = priv->ops->fill(priv, &intersection, priv->wndo.wcolor);
if (ret < 0)
{
gerr("ERROR: fill() method failed: %d\n", ret);
}
}
#endif
}
* Public Functions
****************************************************************************/
* Name: nxterm_addchar
*
* Description:
* This is part of the nxterm_putc logic. It creates and positions a
* the character and renders (or re-uses) a glyph for font.
*
****************************************************************************/
FAR const struct nxterm_bitmap_s *
nxterm_addchar(FAR struct nxterm_state_s *priv, uint8_t ch)
{
FAR struct nxterm_bitmap_s *bm = NULL;
FAR const struct nxfonts_glyph_s *glyph;
if (priv->nchars < priv->maxchars)
{
bm = &priv->bm[priv->nchars];
bm->code = ch;
bm->flags = 0;
bm->pos.x = priv->fpos.x;
bm->pos.y = priv->fpos.y;
glyph = nxf_cache_getglyph(priv->fcache, ch);
if (!glyph)
{
* Just mark this as a space.
*/
bm->flags |= BMFLAGS_NOGLYPH;
priv->fpos.x += priv->spwidth;
}
else
{
priv->fpos.x += glyph->width;
}
priv->nchars++;
}
return bm;
}
* Name: nxterm_hidechar
*
* Description:
* Erase a character from the window.
*
****************************************************************************/
int nxterm_hidechar(FAR struct nxterm_state_s *priv,
FAR const struct nxterm_bitmap_s *bm)
{
struct nxgl_rect_s bounds;
struct nxgl_size_s fsize;
int ret;
* character will have been rendered as a space, and no display
* modification is required (not an error).
*/
ret = nxterm_fontsize(priv, bm->code, &fsize);
if (ret < 0)
{
return OK;
}
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;
* 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);
}
* Name: nxterm_backspace
*
* Description:
* Remove the last character from the window.
*
****************************************************************************/
int nxterm_backspace(FAR struct nxterm_state_s *priv)
{
FAR struct nxterm_bitmap_s *bm;
int ndx;
int ret = -ENOENT;
if (priv->nchars > 0)
{
ndx = priv->nchars - 1;
bm = &priv->bm[ndx];
ret = nxterm_hidechar(priv, bm);
priv->fpos.x = bm->pos.x;
priv->fpos.y = bm->pos.y;
priv->nchars = ndx;
}
return ret;
}
* Name: nxterm_home
*
* Description:
* Set the next character position to the top-left corner of the display.
*
****************************************************************************/
void nxterm_home(FAR struct nxterm_state_s *priv)
{
priv->fpos.x = priv->spwidth;
priv->fpos.y = CONFIG_NXTERM_LINESEPARATION;
}
* Name: nxterm_newline
*
* Description:
* Set the next character position to the beginning of the next line.
*
****************************************************************************/
void nxterm_newline(FAR struct nxterm_state_s *priv)
{
priv->fpos.x = priv->spwidth;
priv->fpos.y += (priv->fheight + CONFIG_NXTERM_LINESEPARATION);
}
* Name: nxterm_fillchar
*
* Description:
* This implements the character display. It is part of the nxterm_putc
* operation but may also be used when redrawing an existing display.
*
****************************************************************************/
void nxterm_fillchar(FAR struct nxterm_state_s *priv,
FAR const struct nxgl_rect_s *rect,
FAR const struct nxterm_bitmap_s *bm)
{
FAR const struct nxfonts_glyph_s *glyph;
struct nxgl_rect_s bounds;
struct nxgl_rect_s intersection;
struct nxgl_size_s fsize;
int ret;
if (BM_ISSPACE(bm))
{
nxterm_fillspace(priv, rect, bm);
return;
}
ret = nxterm_fontsize(priv, bm->code, &fsize);
if (ret < 0)
{
* 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;
}
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;
if (rect != NULL)
{
nxgl_rectintersect(&intersection, rect, &bounds);
}
else
{
nxgl_rectcopy(&intersection, &bounds);
}
if (!nxgl_nullrect(&intersection))
{
FAR const void *src;
glyph = nxf_cache_getglyph(priv->fcache, bm->code);
if (!glyph)
{
return;
}
src = (FAR const void *)glyph->bitmap;
ret = priv->ops->bitmap(priv, &intersection, &src,
&bm->pos, (unsigned int)glyph->stride);
DEBUGASSERT(ret >= 0);
}
}