Add support for multiple fonts

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3801 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2011-07-19 22:45:15 +00:00
parent f1f08a4297
commit 21e170a558
6 changed files with 193 additions and 69 deletions

View File

@ -88,7 +88,7 @@ endif
all: mklibgraphics
.PHONY : context depend clean distclean mklibgraphics gensources gen1bppsources \
gen2bppsource gen4bppsource gen8bppsource gen16bppsource gen24bppsource \
gen32bppsources
gen32bppsources genfontsources
gen1bppsources:
@$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=1 EXTRADEFINES=$(EXTRADEFINES)
@ -118,7 +118,12 @@ gen32bppsources:
@$(MAKE) -C nxglib -f Makefile.sources TOPDIR=$(TOPDIR) NXGLIB_BITSPERPIXEL=32 EXTRADEFINES=$(EXTRADEFINES)
@$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_BITSPERPIXEL=32 EXTRADEFINES=$(EXTRADEFINES)
gensources: gen1bppsources gen2bppsource gen4bppsource gen8bppsource gen16bppsource gen24bppsource gen32bppsources
genfontsources:
ifeq ($(CONFIG_NXFONT_SANS23X27),y)
@$(MAKE) -C nxfonts -f Makefile.sources TOPDIR=$(TOPDIR) NXFONTS_FONTID=1 EXTRADEFINES=$(EXTRADEFINES)
endif
gensources: gen1bppsources gen2bppsource gen4bppsource gen8bppsource gen16bppsource gen24bppsource gen32bppsources genfontsources
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)

View File

@ -33,9 +33,17 @@
#
############################################################################
NXFONTS_ASRCS =
NXFCONV_CSRC = nxfonts_convert_1bpp.c nxfonts_convert_2bpp.c \
NXFCONV_ASRCS =
NXFCONV_CSRCS = nxfonts_convert_1bpp.c nxfonts_convert_2bpp.c \
nxfonts_convert_4bpp.c nxfonts_convert_8bpp.c \
nxfonts_convert_16bpp.c nxfonts_convert_24bpp.c \
nxfonts_convert_32bpp.c
NXFONTS_CSRCS = nxfonts_bitmaps.c nxfonts_getfont.c $(NXFCONV_CSRC)
NXFSET_ASRCS =
NXFSET_CSRCS =
ifeq ($(CONFIG_NXFONT_SANS23X27),y)
NXFSET_CSRCS += nxfonts_bitmaps_sans23x27.c
endif
NXFONTS_ASRCS = $(NXFCONV_ASRCS) $(NXFSET_ASRCS)
NXFONTS_CSRCS = nxfonts_getfont.c $(NXFCONV_CSRCS) $(NXFSET_CSRCS)

View File

@ -36,54 +36,65 @@
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
ifdef NXFONTS_BITSPERPIXEL
ifeq ($(NXFONTS_BITSPERPIXEL),1)
NXFONTS_SUFFIX := _1bpp
CONV_CSRC := nxfonts_convert_1bpp.c
GEN_CSRC := nxfonts_convert_1bpp.c
endif
ifeq ($(NXFONTS_BITSPERPIXEL),2)
NXFONTS_SUFFIX := _2bpp
CONV_CSRC := nxfonts_convert_2bpp.c
GEN_CSRC := nxfonts_convert_2bpp.c
endif
ifeq ($(NXFONTS_BITSPERPIXEL),4)
NXFONTS_SUFFIX := _4bpp
CONV_CSRC := nxfonts_convert_4bpp.c
GEN_CSRC := nxfonts_convert_4bpp.c
endif
ifeq ($(NXFONTS_BITSPERPIXEL),8)
NXFONTS_SUFFIX := _8bpp
CONV_CSRC := nxfonts_convert_8bpp.c
GEN_CSRC := nxfonts_convert_8bpp.c
endif
ifeq ($(NXFONTS_BITSPERPIXEL),16)
NXFONTS_SUFFIX := _16bpp
CONV_CSRC := nxfonts_convert_16bpp.c
GEN_CSRC := nxfonts_convert_16bpp.c
endif
ifeq ($(NXFONTS_BITSPERPIXEL),24)
NXFONTS_SUFFIX := _24bpp
CONV_CSRC := nxfonts_convert_24bpp.c
GEN_CSRC := nxfonts_convert_24bpp.c
endif
ifeq ($(NXFONTS_BITSPERPIXEL),32)
NXFONTS_SUFFIX := _32bpp
CONV_CSRC := nxfonts_convert_32bpp.c
GEN_CSRC := nxfonts_convert_32bpp.c
endif
DEPENDENCY := nxfonts_convert.c
CPPFLAGS += -DNXFONTS_BITSPERPIXEL=$(NXFONTS_BITSPERPIXEL)
CPPFLAGS += -DNXFONTS_SUFFIX=$(NXFONTS_SUFFIX)
endif
CONV_TMP = $(CONV_CSRC:.c=.i)
ifdef NXFONTS_FONTID
ifeq ($(NXFONTS_FONTID),1)
NXFONTS_PREFIX := g_sans23x27_
GEN_CSRC = nxfonts_bitmaps_sans23x27.c
endif
GEN_CSRCS = $(CONV_CSRC)
DEPENDENCY := nxfonts_bitmaps.c
CPPFLAGS += -DNXFONTS_FONTID=$(NXFONTS_FONTID)
CPPFLAGS += -DNXFONTS_PREFIX=$(NXFONTS_PREFIX)
endif
all: $(GEN_CSRCS)
GEN_TMP = $(GEN_CSRC:.c=.i)
all: $(GEN_CSRC)
.PHONY : clean distclean
$(CONV_CSRC) : nxfonts_convert.c
ifneq ($(NXFONTS_BITSPERPIXEL),)
@$(call PREPROCESS, $<, $(CONV_TMP))
@cat $(CONV_TMP) | sed -e "/^#/d" >$@
@rm -f $(CONV_TMP)
endif
$(GEN_CSRC) : $(DEPENDENCY)
@$(call PREPROCESS, $<, $(GEN_TMP))
@cat $(GEN_TMP) | sed -e "/^#/d" >$@
@rm -f $(GEN_TMP)
clean:
@rm -f *~ .*.swp *.i
distclean: clean
@rm -f nxfonts_convert_*bpp.c
@rm -f nxfonts_bitmaps_*.c

View File

@ -1,5 +1,5 @@
/****************************************************************************
* graphics/nxfonts/nxfonts_bitmap.h
* graphics/nxfonts/nxfonts_bitmaps.c
*
* Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
@ -46,10 +46,10 @@
/* Pick the fontset */
#ifdef CONFIG_NXFONT_SANS23X27
#if NXFONTS_FONTID == 1
# include "nxfonts_sans23x27.h"
#else
# include "nxfonts_sans23x27.h"
# error "No font ID specified"
#endif
/****************************************************************************
@ -64,6 +64,7 @@
static const uint8_t NXFONT_CONCAT(g_bitmap_,n)[] = NXFONT_CONCAT(NXFONT_BITMAP_,n)
#define NXFONT_DEFMETRIC(n) \
{ NXFONT_CONCAT(NXFONT_METRICS_,n), NXFONT_CONCAT(g_bitmap_,n) }
#define NXF_SYMNAME(a,b) NXFONT_CONCAT(a,b)
/****************************************************************************
* Private Data
@ -841,7 +842,7 @@ NXFONT_DEFBITMAP(255);
#endif
#endif
static const struct nx_fontbitmap_s g_7bitmaps[NXFONT_N7BITFONTS] =
static const struct nx_fontbitmap_s NXF_SYMNAME(NXFONTS_PREFIX,7bitmaps)[NXFONT_N7BITFONTS] =
{
#if NXFONT_MIN7BIT <= 0 && NXFONT_MAX7BIT >= 0
NXFONT_DEFMETRIC(0),
@ -1230,7 +1231,7 @@ NXFONT_DEFMETRIC(127),
};
#if CONFIG_NXFONTS_CHARBITS >= 8
static const struct nx_fontbitmap_s g_8bitmaps[NXFONT_N8BITFONTS] =
static const struct nx_fontbitmap_s NXF_SYMNAME(NXFONTS_PREFIX,8bitmaps)[NXFONT_N8BITFONTS] =
{
#if NXFONT_MIN8BIT <= 128 && NXFONT_MAX8BIT >= 128
NXFONT_DEFMETRIC(128),
@ -1619,32 +1620,42 @@ 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
****************************************************************************/
struct nx_fontset_s g_7bitfonts =
const struct nx_fontpackage_s NXF_SYMNAME(NXFONTS_PREFIX,package) =
{
NXFONT_MIN7BIT, /* First glyph code */
NXFONT_N7BITFONTS, /* Number of bitmap glyphs */
g_7bitmaps /* List of glyphs */
};
NXFONT_ID, /* The font ID */
&NXF_SYMNAME(NXFONTS_PREFIX,fonts), /* Font set metrics */
&NXF_SYMNAME(NXFONTS_PREFIX,7bitfonts) /* Fonts for 7-bit encoding */
#if CONFIG_NXFONTS_CHARBITS >= 8
struct nx_fontset_s g_8bitfonts =
{
NXFONT_MIN8BIT, /* First glyph code */
NXFONT_N8BITFONTS, /* Number of bitmap glyphs */
g_8bitmaps /* List of glyphs */
};
, &NXF_SYMNAME(NXFONTS_PREFIX,8bitfonts) /* Fonts for 8-bit encoding */
#endif
struct nx_font_s g_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 */
};
/****************************************************************************

View File

@ -59,6 +59,18 @@
* Private Data
****************************************************************************/
#ifdef CONFIG_NXFONT_SANS23X27
extern const struct nx_fontpackage_s g_sans23x27_package;
#endif
static FAR const struct nx_fontpackage_s *g_fontpackages[] =
{
#ifdef CONFIG_NXFONT_SANS23X27
&g_sans23x27_package,
#endif
NULL
};
/****************************************************************************
* Public Data
****************************************************************************/
@ -67,6 +79,43 @@
* 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
*
@ -75,36 +124,51 @@
* character encoding.
*
* Input Parameters:
* ch - character code
* ch: character code
* package: The selected font package
*
****************************************************************************/
static inline FAR const struct nx_fontset_s *nxf_getglyphset(uint16_t ch)
static inline FAR const struct nx_fontset_s *
nxf_getglyphset(uint16_t ch, FAR const struct nx_fontpackage_s *package)
{
FAR const struct nx_fontset_s *fontset;
/* Select the 7- or 8-bit font set */
if (ch < 128)
{
if (ch >= g_7bitfonts.first && ch < g_7bitfonts.first + g_7bitfonts.nchars)
{
return &g_7bitfonts;
}
gdbg("No bitmap for 7-bit code %d\n", ch);
/* Select the 7-bit font set */
fontset = package->font7;
}
else if (ch < 256)
{
#if CONFIG_NXFONTS_CHARBITS >= 8
if (ch >= g_8bitfonts.first && ch < g_8bitfonts.first + g_8bitfonts.nchars)
{
return &g_8bitfonts;
}
gdbg("No bitmap for 8-bit code %d\n", ch);
/* Select the 8-bit font set */
fontset = package->font8;
#else
gdbg("8-bit font support disabled: %d\n", ch);
return NULL;
#endif
}
else
{
/* Someday, perhaps 16-bit fonts will go here */
gdbg("16-bit font not currently supported\n");
return NULL;
}
/* Then verify that the character actually resides in the font */
if (ch >= fontset->first && ch < fontset->first +fontset->nchars)
{
return fontset;
}
gdbg("No bitmap for code %02x\n", ch);
return NULL;
}
@ -125,7 +189,17 @@ static inline FAR const struct nx_fontset_s *nxf_getglyphset(uint16_t ch)
FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid)
{
return &g_fonts;
/* 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 NULL;
}
/****************************************************************************
@ -143,12 +217,27 @@ FAR const struct nx_font_s *nxf_getfontset(enum nx_fontid_e fontid)
FAR const struct nx_fontbitmap_s *nxf_getbitmap(uint16_t ch,
enum nx_fontid_e fontid)
{
FAR const struct nx_fontset_s *set = nxf_getglyphset(ch);
FAR const struct nx_fontbitmap_s *bm = NULL;
/* Find the font package associated with this font ID */
if (set)
FAR const struct nx_fontpackage_s *package;
FAR const struct nx_fontset_s *fontset;
FAR const struct nx_fontbitmap_s *bm = NULL;
/* Get the font package associated with the font ID */
package = nxf_findpackage(fontid);
if (package)
{
bm = &set->bitmap[ch - set->first];
/* Now get the fontset from the package */
fontset = nxf_getglyphset(ch, package);
if (fontset)
{
/* Then get the bitmap from the font set */
bm = &fontset->bitmap[ch - fontset->first];
}
}
return bm;
}

View File

@ -1,7 +1,7 @@
/****************************************************************************
* include/nuttx/nxfonts.h
*
* Copyright (C) 2008, 2009 Gregory Nutt. All rights reserved.
* Copyright (C) 2008, 2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -64,9 +64,9 @@
enum nx_fontid_e
{
FONTID_DEFAULT = 0 /* The default font */
FONTID_DEFAULT = 0 /* The default font */
#ifdef CONFIG_NXFONT_SANS23X27
, FONTID_SANS23X27 /* The 23x27 sans serif font */
, FONTID_SANS23X27 = 1 /* The 23x27 sans serif font */
#endif
};
@ -116,11 +116,11 @@ struct nx_font_s
struct nx_fontpackage_s
{
uint8_t id; /* The font ID */
struct nx_font_s metrics; /* Font set metrics */
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
struct nx_fontset_s font8; /* Fonts for 8-bit encoding */
FAR const struct nx_fontset_s *font8; /* Fonts for 8-bit encoding */
#endif
};