From b896f16bcf9206d8ed37f5775992a7488c81bdfd Mon Sep 17 00:00:00 2001
From: patacongo
Date: Wed, 20 Jul 2011 02:13:08 +0000
Subject: [PATCH] Use a handle instead of an ID in each font lookup; this saves
doing the font set lookup each time
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3802 42af7a65-404d-4744-a932-0658087f49c3
---
ChangeLog | 5 ++
Documentation/NXGraphicsSubsystem.html | 95 +++++++++++++++------
graphics/nxfonts/nxfonts_bitmaps.c | 45 ++++------
graphics/nxfonts/nxfonts_getfont.c | 110 +++++++++++++------------
include/nuttx/nxfonts.h | 36 +++++---
5 files changed, 176 insertions(+), 115 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 36c6d86415..be575b565d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1928,3 +1928,8 @@
not being coordinated correctly.
* configs/stm3210e-eval/nsh2: Enable FAT long file name support
* sched/sem_timedwait.c: Add the standard sem_timedwait() interface.
+ * graphics/nxfonts/nxfonts_getfont.c, nxfonts_bitmap.c,
+ Makefile.source, and include/nuttx/nxfonts.h: Support for multiple
+ fonts included. A new interface, nxf_getfonthandle() takes a font
+ ID and returns a handle that is now used at all other font interfaces
+ to specify which of the multiple fonts to use.
diff --git a/Documentation/NXGraphicsSubsystem.html b/Documentation/NXGraphicsSubsystem.html
index 9342552663..dd206ed04c 100644
--- a/Documentation/NXGraphicsSubsystem.html
+++ b/Documentation/NXGraphicsSubsystem.html
@@ -153,9 +153,10 @@
@@ -2365,7 +2366,7 @@ struct nx_fontmetric_s
struct nx_fontbitmap_s
{
struct nx_fontmetric_s metric; /* Character metrics */
- FAR const uint8_t *bitmap; /* Pointer to the character bitmap */
+ FAR const uint8_t *bitmap; /* Pointer to the character bitmap */
};
@@ -2396,13 +2397,36 @@ struct nx_font_s
};
-
+
+Function Prototype:
+
+#include <nuttx/nxfonts.h>
+
+NXHANDLE nxf_getfonthandle(enum nx_fontid_e fontid);
+
+
+ Description:
+ Given a numeric font ID, return a handle that may be subsequently be used to access the font data sets.
+
+
+ Input Parameters:
+
+ fontid
+ - Identifies the font set to use
+
+
+
+ Returned Value:
+ A handle that may be subsequently be used to access the font data sets.
+
+
+
Function Prototype:
#include <nuttx/nxglib.h>
#include <nuttx/nxfonts.h>
-FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid);
+FAR const struct nx_font_s *nxf_getfontset(NXHANDLE handle);
Description:
@@ -2411,8 +2435,8 @@ FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid);
Input Parameters:
- fontid
- - Identifies the font set to get
+
handle
+ - A font handle previously returned by
nxf_getfonthandle()
.
@@ -2420,13 +2444,13 @@ FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid);
An instance of struct nx_font_s
describing the font set.
-
+
Function Prototype:
#include <nuttx/nxglib.h>
#include <nuttx/nxfonts.h>
-FAR const struct nx_fontbitmap_s *nxf_getbitmap(uint16_t ch, enum nx_fontid_e fontid);
+FAR const struct nx_fontbitmap_s *nxf_getbitmap(NXHANDLE handle, uint16_t ch);
Description:
@@ -2436,9 +2460,9 @@ FAR const struct nx_fontbitmap_s *nxf_getbitmap(uint16_t ch, enum nx_fontid_e fo
Input Parameters:
ch
- -
-
fontid
- - Identifies the font set to use
+
- The char code for the requested bitmap.
+
handle
+ - A font handle previously returned by
nxf_getfonthandle()
.
@@ -2446,7 +2470,7 @@ FAR const struct nx_fontbitmap_s *nxf_getbitmap(uint16_t ch, enum nx_fontid_e fo
An instance of struct nx_fontbitmap_s
describing the glyph.
-
+
Function Prototype:
#include <nuttx/nxglib.h>
@@ -2505,13 +2529,27 @@ int nxf_convert_32bpp(FAR uint32_t *dest, uint16_t height,
-apps/examples/nx
.
+
apps/examples/nx*
.
No sample code is provided in this document.
- However, an example can be found in the NuttX source tree at apps/examples/nx
.
- That code is intended to test NX.
- Since it is test code, it is designed to exercise functionality and does not necessarily
- represent best NX coding practices.
+ However, examples can be found in the NuttX source tree at the follow locations:
+ That example code is intended to test NX.
+ Since it is test code, it is designed to exercise functionality and does not necessarily represent best NX coding practices.
+
+ apps/examples/nx
.
+ This is a test of windows, optionally with toolbars.
+ Two windows are created, re-sized, moved, raise lowered.
+ Simulated mouse and keyboard input is provided.
+
+ apps/examples/nxhello
.
+ This is intended to be simplest NX test:
+ It simply displays the words "Hello, World!" centered on the display.
+
+ apps/examples/nxtext
.
+ This illustrates how fonts may be managed to provide scrolling text windows.
+ Pop-up windows are included to verify the clipping and re-drawing of the text display.
+
+
In its current form, the NX graphics system provides a low level of graphics and window
@@ -2963,13 +3001,17 @@ make
nx_requestbkgd() |
-
|
- NO |
+
+ Verified by apps/examples/nxtext and apps/examples/nxhello .
+ |
+ YES |
nx_releasebkgd() |
-
|
- NO |
+
+ Verified by apps/examples/nxtext and apps/examples/nxhello .
+ |
+ YES |
nx_getposition() |
@@ -3142,6 +3184,11 @@ make
Special Setup/Notes |
Verified |
+
+ nxf_getfonthandle() |
+
|
+ YES |
+
nxf_getfontset() |
|
@@ -3170,7 +3217,7 @@ make
nxf_convert_16bpp() |
|
- NO |
+ YES |
nxf_convert_24bpp() |
diff --git a/graphics/nxfonts/nxfonts_bitmaps.c b/graphics/nxfonts/nxfonts_bitmaps.c
index 78f27e5e94..edd6703c45 100644
--- a/graphics/nxfonts/nxfonts_bitmaps.c
+++ b/graphics/nxfonts/nxfonts_bitmaps.c
@@ -1620,41 +1620,30 @@ NXFONT_DEFMETRIC(255),
};
#endif
-static const struct nx_fontset_s NXF_SYMNAME(NXFONTS_PREFIX,7bitfonts) =
-{
- NXFONT_MIN7BIT, /* First glyph code */
- NXFONT_N7BITFONTS, /* Number of bitmap glyphs */
- NXF_SYMNAME(NXFONTS_PREFIX,7bitmaps) /* List of glyphs */
-};
-
-#if CONFIG_NXFONTS_CHARBITS >= 8
-static const struct nx_fontset_s NXF_SYMNAME(NXFONTS_PREFIX,8bitfonts) =
-{
- NXFONT_MIN8BIT, /* First glyph code */
- NXFONT_N8BITFONTS, /* Number of bitmap glyphs */
- NXF_SYMNAME(NXFONTS_PREFIX,8bitmaps) /* List of glyphs */
-};
-#endif
-
-static const struct nx_font_s NXF_SYMNAME(NXFONTS_PREFIX,fonts) =
-{
- NXFONT_MAXHEIGHT, /* Max. height of a glyph in rows */
- NXFONT_MAXWIDTH, /* Max. width of a glyph in pixels */
- CONFIG_NXFONTS_CHARBITS, /* Max number of bits per character code */
- NXFONT_SPACEWIDTH, /* The width of a space in pixels */
-};
-
/****************************************************************************
* Public Data
****************************************************************************/
const struct nx_fontpackage_s NXF_SYMNAME(NXFONTS_PREFIX,package) =
{
- NXFONT_ID, /* The font ID */
- &NXF_SYMNAME(NXFONTS_PREFIX,fonts), /* Font set metrics */
- &NXF_SYMNAME(NXFONTS_PREFIX,7bitfonts) /* Fonts for 7-bit encoding */
+ NXFONT_ID, /* The font ID */
+ { /* Font set metrics: */
+ NXFONT_MAXHEIGHT, /* Max. height of a glyph in rows */
+ NXFONT_MAXWIDTH, /* Max. width of a glyph in pixels */
+ CONFIG_NXFONTS_CHARBITS, /* Max number of bits per character code */
+ NXFONT_SPACEWIDTH, /* The width of a space in pixels */
+ },
+ { /* Fonts for 7-bit encoding */
+ NXFONT_MIN7BIT, /* First glyph code */
+ NXFONT_N7BITFONTS, /* Number of bitmap glyphs */
+ NXF_SYMNAME(NXFONTS_PREFIX,7bitmaps) /* List of glyphs */
+ }
#if CONFIG_NXFONTS_CHARBITS >= 8
- , &NXF_SYMNAME(NXFONTS_PREFIX,8bitfonts) /* Fonts for 8-bit encoding */
+, { /* Fonts for 8-bit encoding */
+ NXFONT_MIN8BIT, /* First glyph code */
+ NXFONT_N8BITFONTS, /* Number of bitmap glyphs */
+ NXF_SYMNAME(NXFONTS_PREFIX,8bitmaps) /* List of glyphs */
+ }
#endif
};
diff --git a/graphics/nxfonts/nxfonts_getfont.c b/graphics/nxfonts/nxfonts_getfont.c
index 22b842a96e..964a0c26eb 100644
--- a/graphics/nxfonts/nxfonts_getfont.c
+++ b/graphics/nxfonts/nxfonts_getfont.c
@@ -43,6 +43,7 @@
#include
#include
+#include
#include
#include "nxfonts_internal.h"
@@ -79,43 +80,6 @@ static FAR const struct nx_fontpackage_s *g_fontpackages[] =
* Private Functions
****************************************************************************/
-/****************************************************************************
- * Name: nxf_findpackage
- *
- * Description:
- * Find the font package associated with the provided font ID.
- *
- * Input Parameters:
- * fontid: Identifies the font set to get
- *
- ****************************************************************************/
-
-static FAR const struct nx_fontpackage_s *nxf_findpackage(enum nx_fontid_e fontid)
-{
- FAR const struct nx_fontpackage_s **pkglist;
- FAR const struct nx_fontpackage_s *package;
-
- /* Handle the default font package */
-
- if (fontid == FONTID_DEFAULT)
- {
- fontid = NXFONT_DEFAULT;
- }
-
- /* Then search for the font package with this ID */
-
- for (pkglist = g_fontpackages; *pkglist; pkglist++)
- {
- package = *pkglist;
- if (package->id == fontid)
- {
- return package;
- }
- }
-
- return NULL;
-}
-
/****************************************************************************
* Name: nxf_getglyphset
*
@@ -140,14 +104,14 @@ static inline FAR const struct nx_fontset_s *
{
/* Select the 7-bit font set */
- fontset = package->font7;
+ fontset = &package->font7;
}
else if (ch < 256)
{
#if CONFIG_NXFONTS_CHARBITS >= 8
/* Select the 8-bit font set */
- fontset = package->font8;
+ fontset = &package->font8;
#else
gdbg("8-bit font support disabled: %d\n", ch);
return NULL;
@@ -177,26 +141,66 @@ static inline FAR const struct nx_fontset_s *
****************************************************************************/
/****************************************************************************
- * Name: nxf_getfontset
+ * Name: nxf_getfonthandle
*
* Description:
- * Return information about the current font set
+ * Given a numeric font ID, return a handle that may be subsequently be
+ * used to access the font data sets.
*
* Input Parameters:
* fontid: Identifies the font set to get
*
****************************************************************************/
-FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid)
+NXHANDLE nxf_getfonthandle(enum nx_fontid_e fontid)
{
+ FAR const struct nx_fontpackage_s **pkglist;
+ FAR const struct nx_fontpackage_s *package;
+
+ /* Handle the default font package */
+
+ if (fontid == FONTID_DEFAULT)
+ {
+ fontid = NXFONT_DEFAULT;
+ }
+
+ /* Then search for the font package with this ID */
+
+ for (pkglist = g_fontpackages; *pkglist; pkglist++)
+ {
+ package = *pkglist;
+ if (package->id == fontid)
+ {
+ return (NXHANDLE)package;
+ }
+ }
+
+ return (NXHANDLE)NULL;
+}
+
+/****************************************************************************
+ * Name: nxf_getfontset
+ *
+ * Description:
+ * Return information about the current font set
+ *
+ * Input Parameters:
+ * handle: A font handle previously returned by nxf_getfonthandle
+ *
+ ****************************************************************************/
+
+FAR const struct nx_font_s *nxf_getfontset(NXHANDLE handle)
+{
+ FAR const struct nx_fontpackage_s *package =
+ (FAR const struct nx_fontpackage_s *)handle;
+
/* Find the font package associated with this font ID */
- FAR const struct nx_fontpackage_s *package = nxf_findpackage(fontid);
if (package)
{
/* Found... return the font set metrics for this font package */
- return package->metrics;
+ return &package->metrics;
}
return NULL;
@@ -209,23 +213,23 @@ FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid)
* Return font bitmap information for the selected character encoding.
*
* Input Parameters:
- * ch: Character code
- * fontid: Identifies the font set to use
+ * handle: A font handle previously returned by nxf_getfonthandle
+ * ch: Character code whose bitmap is requested
+ *
+ * Returned Value:
+ * An instance of struct nx_fontbitmap_s describing the glyph.
*
****************************************************************************/
-FAR const struct nx_fontbitmap_s *nxf_getbitmap(uint16_t ch,
- enum nx_fontid_e fontid)
+FAR const struct nx_fontbitmap_s *nxf_getbitmap(NXHANDLE handle, uint16_t ch)
{
- /* Find the font package associated with this font ID */
-
- FAR const struct nx_fontpackage_s *package;
+ FAR const struct nx_fontpackage_s *package =
+ (FAR const struct nx_fontpackage_s *)handle;
FAR const struct nx_fontset_s *fontset;
FAR const struct nx_fontbitmap_s *bm = NULL;
- /* Get the font package associated with the font ID */
+ /* Verify that the handle is a font package */
- package = nxf_findpackage(fontid);
if (package)
{
/* Now get the fontset from the package */
diff --git a/include/nuttx/nxfonts.h b/include/nuttx/nxfonts.h
index f0416f1100..94c94e597f 100644
--- a/include/nuttx/nxfonts.h
+++ b/include/nuttx/nxfonts.h
@@ -43,6 +43,8 @@
#include
#include
+
+#include
#include
/****************************************************************************
@@ -116,11 +118,11 @@ struct nx_font_s
struct nx_fontpackage_s
{
- uint8_t id; /* The font ID */
- FAR const struct nx_font_s *metrics; /* Font set metrics */
- FAR const struct nx_fontset_s *font7; /* Fonts for 7-bit encoding */
+ uint8_t id; /* The font ID */
+ FAR const struct nx_font_s metrics; /* Font set metrics */
+ FAR const struct nx_fontset_s font7; /* Fonts for 7-bit encoding */
#if CONFIG_NXFONTS_CHARBITS >= 8
- FAR const struct nx_fontset_s *font8; /* Fonts for 8-bit encoding */
+ FAR const struct nx_fontset_s font8; /* Fonts for 8-bit encoding */
#endif
};
@@ -141,17 +143,31 @@ extern "C" {
****************************************************************************/
/****************************************************************************
- * Name: nxf_getfontset
+ * Name: nxf_getfonthandle
*
* Description:
- * Return information about the current font set
+ * Given a numeric font ID, return a handle that may be subsequently be
+ * used to access the font data sets.
*
* Input Parameters:
* fontid: Identifies the font set to get
*
****************************************************************************/
-EXTERN FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid);
+EXTERN NXHANDLE nxf_getfonthandle(enum nx_fontid_e fontid);
+
+/****************************************************************************
+ * Name: nxf_getfontset
+ *
+ * Description:
+ * Return information about the current font set
+ *
+ * Input Parameters:
+ * handle: A font handle previously returned by nxf_getfonthandle()
+ *
+ ****************************************************************************/
+
+EXTERN FAR const struct nx_font_s *nxf_getfontset(NXHANDLE handle);
/****************************************************************************
* Name: nxf_getbitmap
@@ -160,8 +176,8 @@ EXTERN FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid);
* Return font bitmap information for the selected character encoding.
*
* Input Parameters:
- * ch: Character code
- * fontid: Identifies the font set to use
+ * handle: A font handle previously returned by nxf_getfonthandle()
+ * ch: Character code whose bitmap is requested
*
* Returned Value:
* An instance of struct nx_fontbitmap_s describing the glyph.
@@ -169,7 +185,7 @@ EXTERN FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid);
****************************************************************************/
EXTERN FAR const struct nx_fontbitmap_s *
- nxf_getbitmap(uint16_t ch, enum nx_fontid_e fontid);
+ nxf_getbitmap(NXHANDLE handle, uint16_t ch);
/****************************************************************************
* Name: nxf_convert_*bpp