summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-07-20 02:13:08 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-07-20 02:13:08 +0000
commit622a6cc576f1e5b97abcb78441ed04674217bfe6 (patch)
tree985c3306340f9b7edaa060b5ecdfe8e44d24c83c
parent89b5382e22ed897121c864865fdb79acddc9ba14 (diff)
downloadpx4-nuttx-622a6cc576f1e5b97abcb78441ed04674217bfe6.tar.gz
px4-nuttx-622a6cc576f1e5b97abcb78441ed04674217bfe6.tar.bz2
px4-nuttx-622a6cc576f1e5b97abcb78441ed04674217bfe6.zip
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
-rwxr-xr-xapps/ChangeLog.txt3
-rw-r--r--apps/examples/nx/nx_internal.h7
-rw-r--r--apps/examples/nx/nx_kbdin.c2
-rw-r--r--apps/examples/nx/nx_main.c16
-rw-r--r--apps/examples/nxhello/nxhello.h4
-rw-r--r--apps/examples/nxhello/nxhello_bkgd.c6
-rw-r--r--apps/examples/nxhello/nxhello_main.c12
-rw-r--r--apps/examples/nxtext/nxtext_bkgd.c2
-rw-r--r--apps/examples/nxtext/nxtext_internal.h5
-rw-r--r--apps/examples/nxtext/nxtext_main.c15
-rw-r--r--apps/examples/nxtext/nxtext_popup.c2
-rw-r--r--apps/examples/nxtext/nxtext_putc.c4
-rw-r--r--nuttx/ChangeLog5
-rw-r--r--nuttx/Documentation/NXGraphicsSubsystem.html95
-rw-r--r--nuttx/graphics/nxfonts/nxfonts_bitmaps.c45
-rw-r--r--nuttx/graphics/nxfonts/nxfonts_getfont.c108
-rw-r--r--nuttx/include/nuttx/nxfonts.h34
17 files changed, 240 insertions, 125 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index 2da96d02d..e468f49fb 100755
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -77,4 +77,5 @@
* apps/examples/nxhello: The simplest graphics example: It just says
"Hello, World!" in the center of the display. This example can also be
built as an NSH "built-in" command.
-
+ * apps/examples/nx, ntext, and nxhello: All updated to use the new
+ NuttX font interfaces.
diff --git a/apps/examples/nx/nx_internal.h b/apps/examples/nx/nx_internal.h
index 96e84a958..897c09722 100644
--- a/apps/examples/nx/nx_internal.h
+++ b/apps/examples/nx/nx_internal.h
@@ -196,6 +196,7 @@ enum exitcode_e
NXEXIT_LCDINITIALIZE,
NXEXIT_LCDGETDEV,
NXEXIT_NXOPEN,
+ NXEXIT_FONTOPEN,
NXEXIT_NXOPENTOOLBAR,
NXEXIT_NXCONNECT,
NXEXIT_NXSETBGCOLOR,
@@ -251,7 +252,7 @@ struct nxeg_state_s
* Public Variables
****************************************************************************/
-/* The connecton handler */
+/* The connecton handle */
extern NXHANDLE g_hnx;
@@ -262,6 +263,10 @@ extern const struct nx_callback_s g_nxcb;
extern const struct nx_callback_s g_tbcb;
#endif
+/* The font handle */
+
+extern NXHANDLE g_fonthandle;
+
/* The screen resolution */
extern nxgl_coord_t g_xres;
diff --git a/apps/examples/nx/nx_kbdin.c b/apps/examples/nx/nx_kbdin.c
index 66d54b046..b2a40d352 100644
--- a/apps/examples/nx/nx_kbdin.c
+++ b/apps/examples/nx/nx_kbdin.c
@@ -323,7 +323,7 @@ nxeg_getglyph(FAR struct nxeg_state_s *st, uint8_t ch)
{
/* No, it is not cached... Does the code map to a glyph? */
- bm = nxf_getbitmap(ch, NXFONT_DEFAULT);
+ bm = nxf_getbitmap(g_fonthandle, ch);
if (!bm)
{
/* No, there is no glyph for this code. Use space */
diff --git a/apps/examples/nx/nx_main.c b/apps/examples/nx/nx_main.c
index 72e8fe2ca..6d85d0fb7 100644
--- a/apps/examples/nx/nx_main.c
+++ b/apps/examples/nx/nx_main.c
@@ -102,6 +102,10 @@ static const uint8_t g_kbdmsg1[] = "NuttX is cool!";
static const uint8_t g_kbdmsg2[] = "NuttX is fun!";
#endif
+/* The font handle */
+
+NXHANDLE g_fonthandle;
+
/****************************************************************************
* Public Data
****************************************************************************/
@@ -179,7 +183,7 @@ static void nxeg_initstate(FAR struct nxeg_state_s *st, int wnum,
*/
#ifdef CONFIG_NX_KBD
- fontset = nxf_getfontset(NXFONT_DEFAULT);
+ fontset = nxf_getfontset(g_fonthandle);
st->nchars = 0;
st->nglyphs = 0;
st->height = fontset->mxheight;
@@ -637,6 +641,16 @@ int user_start(int argc, char *argv[])
goto errout;
}
+ /* Get the default font handle */
+
+ g_fonthandle = nxf_getfonthandle(NXFONT_DEFAULT);
+ if (!g_fonthandle)
+ {
+ message("user_start: Failed to get font handle: %d\n", errno);
+ g_exitcode = NXEXIT_FONTOPEN;
+ goto errout;
+ }
+
/* Set the background to the configured background color */
message("user_start: Set background color=%d\n", CONFIG_EXAMPLES_NX_BGCOLOR);
diff --git a/apps/examples/nxhello/nxhello.h b/apps/examples/nxhello/nxhello.h
index d5d5c724b..b7343a054 100644
--- a/apps/examples/nxhello/nxhello.h
+++ b/apps/examples/nxhello/nxhello.h
@@ -120,6 +120,7 @@ enum exitcode_e
NXEXIT_LCDINITIALIZE,
NXEXIT_LCDGETDEV,
NXEXIT_NXOPEN,
+ NXEXIT_FONTOPEN,
NXEXIT_NXREQUESTBKGD,
NXEXIT_NXSETBGCOLOR
};
@@ -147,10 +148,11 @@ struct nxhello_bitmap_s
struct nxhello_data_s
{
- /* The NX handle */
+ /* The NX handles */
NXHANDLE hnx;
NXHANDLE hbkgd;
+ NXHANDLE hfont;
/* The screen resolution */
diff --git a/apps/examples/nxhello/nxhello_bkgd.c b/apps/examples/nxhello/nxhello_bkgd.c
index 9ec3e5141..f3c6b8add 100644
--- a/apps/examples/nxhello/nxhello_bkgd.c
+++ b/apps/examples/nxhello/nxhello_bkgd.c
@@ -228,7 +228,7 @@ static void nxhello_center(FAR struct nxgl_point_s *pos,
{
/* Get the font bitmap for this character */
- fbm = nxf_getbitmap(*ptr, NXFONT_DEFAULT);
+ fbm = nxf_getbitmap(g_nxhello.hfont, *ptr);
if (fbm)
{
/* Add the font size */
@@ -353,7 +353,7 @@ void nxhello_hello(NXWINDOW hwnd)
/* Get information about the font we are going to use */
- fontset = nxf_getfontset(NXFONT_DEFAULT);
+ fontset = nxf_getfontset(g_nxhello.hfont);
/* Allocate a bit of memory to hold the largest rendered font */
@@ -377,7 +377,7 @@ void nxhello_hello(NXWINDOW hwnd)
{
/* Get the bitmap font for this ASCII code */
- fbm = nxf_getbitmap(*ptr, NXFONT_DEFAULT);
+ fbm = nxf_getbitmap(g_nxhello.hfont, *ptr);
if (fbm)
{
uint8_t fheight; /* Height of this glyph (in rows) */
diff --git a/apps/examples/nxhello/nxhello_main.c b/apps/examples/nxhello/nxhello_main.c
index 02b2f17a2..98b16bb1d 100644
--- a/apps/examples/nxhello/nxhello_main.c
+++ b/apps/examples/nxhello/nxhello_main.c
@@ -61,6 +61,7 @@
#include <nuttx/arch.h>
#include <nuttx/nx.h>
#include <nuttx/nxglib.h>
+#include <nuttx/nxfonts.h>
#include "nxhello.h"
@@ -101,6 +102,7 @@ struct nxhello_data_s g_nxhello =
{
NULL, /* hnx */
NULL, /* hbkgd */
+ NULL, /* hfont */
0, /* xres */
0, /* yres */
false, /* havpos */
@@ -228,6 +230,16 @@ int MAIN_NAME(int argc, char *argv[])
goto errout;
}
+ /* Get the default font handle */
+
+ g_nxhello.hfont = nxf_getfonthandle(NXFONT_DEFAULT);
+ if (!g_nxhello.hfont)
+ {
+ message("user_start: Failed to get font handle: %d\n", errno);
+ g_nxhello.code = NXEXIT_FONTOPEN;
+ goto errout;
+ }
+
/* Set the background to the configured background color */
message(MAIN_NAME_STRING ": Set background color=%d\n",
diff --git a/apps/examples/nxtext/nxtext_bkgd.c b/apps/examples/nxtext/nxtext_bkgd.c
index e711c84bb..37894e20c 100644
--- a/apps/examples/nxtext/nxtext_bkgd.c
+++ b/apps/examples/nxtext/nxtext_bkgd.c
@@ -402,7 +402,7 @@ FAR struct nxtext_state_s *nxbg_getstate(void)
* state structure
*/
- fontset = nxf_getfontset(NXFONT_DEFAULT);
+ fontset = nxf_getfontset(g_fonthandle);
g_bgstate.fheight = fontset->mxheight;
g_bgstate.fwidth = fontset->mxwidth;
g_bgstate.spwidth = fontset->spwidth;
diff --git a/apps/examples/nxtext/nxtext_internal.h b/apps/examples/nxtext/nxtext_internal.h
index 16f8bb08a..eb7543329 100644
--- a/apps/examples/nxtext/nxtext_internal.h
+++ b/apps/examples/nxtext/nxtext_internal.h
@@ -191,6 +191,7 @@ enum exitcode_e
NXEXIT_LCDINITIALIZE,
NXEXIT_LCDGETDEV,
NXEXIT_NXOPEN,
+ NXEXIT_FONTOPEN,
NXEXIT_NXREQUESTBKGD,
NXEXIT_NXCONNECT,
NXEXIT_NXSETBGCOLOR,
@@ -262,6 +263,10 @@ extern NXHANDLE g_hnx;
extern NXHANDLE g_bgwnd;
+/* The font handle */
+
+extern NXHANDLE g_fonthandle;
+
/* NX callback vtables */
extern const struct nx_callback_s g_bgcb;
diff --git a/apps/examples/nxtext/nxtext_main.c b/apps/examples/nxtext/nxtext_main.c
index 6a53f9d2c..a9d9207e6 100644
--- a/apps/examples/nxtext/nxtext_main.c
+++ b/apps/examples/nxtext/nxtext_main.c
@@ -61,6 +61,7 @@
#include <nuttx/arch.h>
#include <nuttx/nx.h>
#include <nuttx/nxglib.h>
+#include <nuttx/nxfonts.h>
#include "nxtext_internal.h"
@@ -134,6 +135,10 @@ static const char *g_bgmsg[BGMSG_LINES] =
NXHANDLE g_hnx = NULL;
+/* The font handle */
+
+NXHANDLE g_fonthandle = NULL;
+
/* The screen resolution */
nxgl_coord_t g_xres;
@@ -366,6 +371,16 @@ int user_start(int argc, char *argv[])
goto errout;
}
+ /* Get the default font handle */
+
+ g_fonthandle = nxf_getfonthandle(NXFONT_DEFAULT);
+ if (!g_fonthandle)
+ {
+ message("user_start: Failed to get font handle: %d\n", errno);
+ g_exitcode = NXEXIT_FONTOPEN;
+ goto errout;
+ }
+
/* Set the background to the configured background color */
message("user_start: Set background color=%d\n", CONFIG_EXAMPLES_NXTEXT_BGCOLOR);
diff --git a/apps/examples/nxtext/nxtext_popup.c b/apps/examples/nxtext/nxtext_popup.c
index bf9fbae19..8cc72a89e 100644
--- a/apps/examples/nxtext/nxtext_popup.c
+++ b/apps/examples/nxtext/nxtext_popup.c
@@ -304,7 +304,7 @@ static inline void nxpu_initstate(void)
*/
#ifdef CONFIG_NX_KBD
- fontset = nxf_getfontset(NXFONT_DEFAULT);
+ fontset = nxf_getfontset(g_fonthandle);
g_pustate.fheight = fontset->mxheight;
g_pustate.fwidth = fontset->mxwidth;
g_pustate.spwidth = fontset->spwidth;
diff --git a/apps/examples/nxtext/nxtext_putc.c b/apps/examples/nxtext/nxtext_putc.c
index 87da2ad6e..b4e31bb73 100644
--- a/apps/examples/nxtext/nxtext_putc.c
+++ b/apps/examples/nxtext/nxtext_putc.c
@@ -332,7 +332,7 @@ static int nxtext_fontsize(uint8_t ch, FAR struct nxgl_size_s *size)
/* No, it is not cached... Does the code map to a font? */
- fbm = nxf_getbitmap(ch, NXFONT_DEFAULT);
+ fbm = nxf_getbitmap(g_fonthandle, ch);
if (fbm)
{
/* Yes.. return the font size */
@@ -362,7 +362,7 @@ nxtext_getglyph(FAR struct nxtext_state_s *st, uint8_t ch)
{
/* No, it is not cached... Does the code map to a font? */
- fbm = nxf_getbitmap(ch, NXFONT_DEFAULT);
+ fbm = nxf_getbitmap(g_fonthandle, ch);
if (fbm)
{
/* Yes.. render the glyph */
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 36c6d8641..be575b565 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/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/nuttx/Documentation/NXGraphicsSubsystem.html b/nuttx/Documentation/NXGraphicsSubsystem.html
index 934255266..dd206ed04 100644
--- a/nuttx/Documentation/NXGraphicsSubsystem.html
+++ b/nuttx/Documentation/NXGraphicsSubsystem.html
@@ -153,9 +153,10 @@
<p>
<ul>
<i>2.5.1 <a href="#nxfontstypes"><code>NXFONTS Types()</code></a></i><br>
- <i>2.5.2 <a href="#nxfgetfontset"><code>nxf_getfontset()</code></a></i><br>
- <i>2.5.3 <a href="#nxfgetbitmap"><code>nxf_getbitmap()</code></a></i><br>
- <i>2.5.4 <a href="#nxfconvertbpp"><code>nxf_convert_*bpp()</code></a></i>
+ <i>2.5.2 <a href="#nxfgetfonthandle"><code>nxf_getfonthandle()</code></a></i><br>
+ <i>2.5.3 <a href="#nxfgetfontset"><code>nxf_getfontset()</code></a></i><br>
+ <i>2.5.4 <a href="#nxfgetbitmap"><code>nxf_getbitmap()</code></a></i><br>
+ <i>2.5.5 <a href="#nxfconvertbpp"><code>nxf_convert_*bpp()</code></a></i>
</ul>
</p>
<p>
@@ -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 */
};
</pre></ul>
@@ -2396,13 +2397,36 @@ struct nx_font_s
};
</pre></ul>
-<h3>2.5.2 <a name="nxfgetfontset"><code>nxf_getfontset()</code></a></h3>
+<h3>2.5.2 <a name="nxfgetfonthandle"><code>nxf_getfonthandle()</code></a></h3>
+<p><b>Function Prototype:</b></p>
+<ul><pre>
+#include &lt;nuttx/nxfonts.h&gt;
+
+NXHANDLE nxf_getfonthandle(enum nx_fontid_e fontid);
+</pre></ul>
+<p>
+ <b>Description:</b>
+ Given a numeric font ID, return a handle that may be subsequently be used to access the font data sets.
+</p>
+<p>
+ <b>Input Parameters:</b>
+ <ul><dl>
+ <dt><code>fontid</code>
+ <dd>Identifies the font set to use
+ </dl></ul>
+</p>
+<p>
+ <b>Returned Value:</b>
+ A handle that may be subsequently be used to access the font data sets.
+</p>
+
+<h3>2.5.3 <a name="nxfgetfontset"><code>nxf_getfontset()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include &lt;nuttx/nxglib.h&gt;
#include &lt;nuttx/nxfonts.h&gt;
-FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid);
+FAR const struct nx_font_s *nxf_getfontset(NXHANDLE handle);
</pre></ul>
<p>
<b>Description:</b>
@@ -2411,8 +2435,8 @@ FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid);
<p>
<b>Input Parameters:</b>
<ul><dl>
- <dt><code>fontid</code>
- <dd>Identifies the font set to get
+ <dt><code>handle</code>
+ <dd>A font handle previously returned by <code>nxf_getfonthandle()</code>.
</dl></ul>
</p>
<p>
@@ -2420,13 +2444,13 @@ FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid);
An instance of <code>struct nx_font_s</code> describing the font set.
</p>
-<h3>2.5.3 <a name="nxfgetbitmap"><code>nxf_getbitmap()</code></a></h3>
+<h3>2.5.4 <a name="nxfgetbitmap"><code>nxf_getbitmap()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include &lt;nuttx/nxglib.h&gt;
#include &lt;nuttx/nxfonts.h&gt;
-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);
</pre></ul>
<p>
<b>Description:</b>
@@ -2436,9 +2460,9 @@ FAR const struct nx_fontbitmap_s *nxf_getbitmap(uint16_t ch, enum nx_fontid_e fo
<b>Input Parameters:</b>
<ul><dl>
<dt><code>ch</code>
- <dd>
- <dt><code>fontid</code>
- <dd>Identifies the font set to use
+ <dd>The char code for the requested bitmap.
+ <dt><code>handle</code>
+ <dd>A font handle previously returned by <code>nxf_getfonthandle()</code>.
</dl></ul>
</p>
<p>
@@ -2446,7 +2470,7 @@ FAR const struct nx_fontbitmap_s *nxf_getbitmap(uint16_t ch, enum nx_fontid_e fo
An instance of <code>struct nx_fontbitmap_s</code> describing the glyph.
</p>
-<h3>2.5.4 <a name="nxfconvertbpp"><code>nxf_convert_*bpp()</code></a></h3>
+<h3>2.5.5 <a name="nxfconvertbpp"><code>nxf_convert_*bpp()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include &lt;nuttx/nxglib.h&gt;
@@ -2505,13 +2529,27 @@ int nxf_convert_32bpp(FAR uint32_t *dest, uint16_t height,
<h2>2.6 <a name="samplecode">Sample Code</a></h2>
-<p><b><code>apps/examples/nx</code></b>.
+<p><b><code>apps/examples/nx*</code></b>.
No sample code is provided in this document.
- However, an example can be found in the NuttX source tree at <code>apps/examples/nx</code>.
- 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.
</p>
+<ul>
+ <li><code>apps/examples/nx</code>.
+ 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.
+ </li>
+ <li><code>apps/examples/nxhello</code>.
+ This is intended to be simplest NX test:
+ It simply displays the words &quot;Hello, World!&quot; centered on the display.
+ </li>
+ <li><code>apps/examples/nxtext</code>.
+ 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.
+ </li>
+</ul>
<p>
In its current form, the NX graphics system provides a low level of graphics and window
@@ -2963,13 +3001,17 @@ make
</tr>
<tr>
<td align="left" valign="top"><a href="#nxrequestbkgd"><code>nx_requestbkgd()</code></a></td>
- <td><br></td>
- <td align="center" bgcolor="lightgrey">NO</td>
+ <td>
+ Verified by <code>apps/examples/nxtext</code> and <code>apps/examples/nxhello</code>.
+ </td>
+ <td align="center" bgcolor="skyblue">YES</td>
</tr>
<tr>
<td align="left" valign="top"><a href="#nxreleasebkgd"><code>nx_releasebkgd()</code></a></td>
- <td><br></td>
- <td align="center" bgcolor="lightgrey">NO</td>
+ <td>
+ Verified by <code>apps/examples/nxtext</code> and <code>apps/examples/nxhello</code>.
+ </td>
+ <td align="center" bgcolor="skyblue">YES</td>
</tr>
<tr>
<td align="left" valign="top"><a href="#nxgetposition"><code>nx_getposition()</code></a></td>
@@ -3143,6 +3185,11 @@ make
<th width="5%">Verified</th></tr>
</tr>
<tr>
+ <td align="left" valign="top"><a href="#nxfgetfonthandle"><code>nxf_getfonthandle()</code></a></td>
+ <td><br></td>
+ <td align="center" bgcolor="skyblue">YES</td>
+</tr>
+<tr>
<td align="left" valign="top"><a href="#nxfgetfontset"><code>nxf_getfontset()</code></a></td>
<td><br></td>
<td align="center" bgcolor="skyblue">YES</td>
@@ -3170,7 +3217,7 @@ make
<tr>
<td align="left" valign="top"><a href="#nxfconvertbpp"><code>nxf_convert_16bpp()</code></a></td>
<td><br></td>
- <td align="center" bgcolor="lightgrey">NO</td>
+ <td align="center" bgcolor="skyblue">YES</td>
</tr>
<tr>
<td align="left" valign="top"><a href="#nxfconvertbpp"><code>nxf_convert_24bpp()</code></a></td>
diff --git a/nuttx/graphics/nxfonts/nxfonts_bitmaps.c b/nuttx/graphics/nxfonts/nxfonts_bitmaps.c
index 78f27e5e9..edd6703c4 100644
--- a/nuttx/graphics/nxfonts/nxfonts_bitmaps.c
+++ b/nuttx/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/nuttx/graphics/nxfonts/nxfonts_getfont.c b/nuttx/graphics/nxfonts/nxfonts_getfont.c
index 22b842a96..964a0c26e 100644
--- a/nuttx/graphics/nxfonts/nxfonts_getfont.c
+++ b/nuttx/graphics/nxfonts/nxfonts_getfont.c
@@ -43,6 +43,7 @@
#include <stddef.h>
#include <debug.h>
+#include <nuttx/nx.h>
#include <nuttx/nxfonts.h>
#include "nxfonts_internal.h"
@@ -80,43 +81,6 @@ static FAR const struct nx_fontpackage_s *g_fontpackages[] =
****************************************************************************/
/****************************************************************************
- * 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
*
* Description:
@@ -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_getfonthandle
+ *
+ * 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 get
+ *
+ ****************************************************************************/
+
+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:
- * fontid: Identifies the font set to get
+ * handle: A font handle previously returned by nxf_getfonthandle
*
****************************************************************************/
-FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid)
+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/nuttx/include/nuttx/nxfonts.h b/nuttx/include/nuttx/nxfonts.h
index f0416f110..94c94e597 100644
--- a/nuttx/include/nuttx/nxfonts.h
+++ b/nuttx/include/nuttx/nxfonts.h
@@ -43,6 +43,8 @@
#include <nuttx/config.h>
#include <stdint.h>
+
+#include <nuttx/nx.h>
#include <nuttx/nxglib.h>
/****************************************************************************
@@ -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_getfonthandle
+ *
+ * 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 get
+ *
+ ****************************************************************************/
+
+EXTERN NXHANDLE nxf_getfonthandle(enum nx_fontid_e fontid);
+
+/****************************************************************************
* Name: nxf_getfontset
*
* Description:
* Return information about the current font set
*
* Input Parameters:
- * fontid: Identifies the font set to get
+ * handle: A font handle previously returned by nxf_getfonthandle()
*
****************************************************************************/
-EXTERN FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid);
+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