GRAPHICS: Format NewFont code with astyle.

This commit is contained in:
Johannes Schickel 2011-07-01 21:20:01 +02:00
parent 8201df7bb6
commit 9e3366d66e
2 changed files with 90 additions and 83 deletions

View file

@ -37,6 +37,14 @@ NewFont::~NewFont() {
} }
} }
int NewFont::getFontHeight() const {
return _desc.height;
}
int NewFont::getMaxCharWidth() const {
return _desc.maxwidth;
}
int NewFont::getCharWidth(byte chr) const { int NewFont::getCharWidth(byte chr) const {
// If no width table is specified, return the maximum width // If no width table is specified, return the maximum width
if (!_desc.width) if (!_desc.width)
@ -49,9 +57,9 @@ int NewFont::getCharWidth(byte chr) const {
} }
template <typename PixelType> template<typename PixelType>
void drawCharIntern(byte *ptr, uint pitch, const bitmap_t *src, int h, int minX, int maxX, const PixelType color) { void drawCharIntern(byte *ptr, uint pitch, const bitmap_t *src, int h, int minX, int maxX, const PixelType color) {
const bitmap_t maxXMask = ~((1 << (16-maxX)) - 1); const bitmap_t maxXMask = ~((1 << (16 - maxX)) - 1);
while (h-- > 0) { while (h-- > 0) {
bitmap_t buffer = READ_UINT16(src); bitmap_t buffer = READ_UINT16(src);
src++; src++;
@ -128,27 +136,27 @@ void NewFont::drawChar(Surface *dst, byte chr, const int tx, const int ty, const
/* builtin C-based proportional/fixed font structure */ /* builtin C-based proportional/fixed font structure */
/* based on The Microwindows Project http://microwindows.org */ /* based on The Microwindows Project http://microwindows.org */
struct NewFontData { struct NewFontData {
char * name; /* font name*/ char *name; /* font name */
int maxwidth; /* max width in pixels*/ int maxwidth; /* max width in pixels */
int height; /* height in pixels*/ int height; /* height in pixels */
int ascent; /* ascent (baseline) height*/ int ascent; /* ascent (baseline) height */
int firstchar; /* first character in bitmap*/ int firstchar; /* first character in bitmap */
int size; /* font size in glyphs*/ int size; /* font size in glyphs */
bitmap_t* bits; /* 16-bit right-padded bitmap data*/ bitmap_t *bits; /* 16-bit right-padded bitmap data */
unsigned long* offset; /* offsets into bitmap data*/ unsigned long *offset; /* offsets into bitmap data */
unsigned char* width; /* character widths or NULL if fixed*/ unsigned char *width; /* character widths or NULL if fixed */
BBX* bbx; /* character bounding box or NULL if fixed */ BBX *bbx; /* character bounding box or NULL if fixed */
int defaultchar; /* default char (not glyph index)*/ int defaultchar; /* default char (not glyph index) */
long bits_size; /* # words of bitmap_t bits*/ long bits_size; /* # words of bitmap_t bits */
/* unused by runtime system, read in by convbdf*/ /* unused by runtime system, read in by convbdf */
char * facename; /* facename of font*/ char *facename; /* facename of font */
char * copyright; /* copyright info for loadable fonts*/ char *copyright; /* copyright info for loadable fonts */
int pixel_size; int pixel_size;
int descent; int descent;
int fbbw, fbbh, fbbx, fbby; int fbbw, fbbh, fbbx, fbby;
}; };
/* END font.h*/ /* END font.h */
#define isprefix(buf,str) (!strncmp(buf, str, strlen(str))) #define isprefix(buf,str) (!strncmp(buf, str, strlen(str)))
#define strequal(s1,s2) (!strcmp(s1, s2)) #define strequal(s1,s2) (!strcmp(s1, s2))
@ -158,13 +166,13 @@ struct NewFontData {
int start_char = 0; int start_char = 0;
int limit_char = 255; int limit_char = 255;
NewFontData* bdf_read_font(Common::SeekableReadStream &fp); NewFontData *bdf_read_font(Common::SeekableReadStream &fp);
int bdf_read_header(Common::SeekableReadStream &fp, NewFontData* pf); int bdf_read_header(Common::SeekableReadStream &fp, NewFontData *pf);
int bdf_read_bitmaps(Common::SeekableReadStream &fp, NewFontData* pf); int bdf_read_bitmaps(Common::SeekableReadStream &fp, NewFontData *pf);
char * bdf_getline(Common::SeekableReadStream &fp, char *buf, int len); char *bdf_getline(Common::SeekableReadStream &fp, char *buf, int len);
bitmap_t bdf_hexval(unsigned char *buf); bitmap_t bdf_hexval(unsigned char *buf);
void free_font(NewFontData* pf) { void free_font(NewFontData *pf) {
if (!pf) if (!pf)
return; return;
free(pf->name); free(pf->name);
@ -177,11 +185,11 @@ void free_font(NewFontData* pf) {
} }
/* build incore structure from .bdf file*/ /* build incore structure from .bdf file*/
NewFontData* bdf_read_font(Common::SeekableReadStream &fp) { NewFontData *bdf_read_font(Common::SeekableReadStream &fp) {
NewFontData* pf; NewFontData *pf;
uint32 pos = fp.pos(); uint32 pos = fp.pos();
pf = (NewFontData*)calloc(1, sizeof(NewFontData)); pf = (NewFontData *)calloc(1, sizeof(NewFontData));
if (!pf) if (!pf)
goto errout; goto errout;
@ -199,13 +207,13 @@ NewFontData* bdf_read_font(Common::SeekableReadStream &fp) {
return pf; return pf;
errout: errout:
free_font(pf); free_font(pf);
return NULL; return NULL;
} }
/* read bdf font header information, return 0 on error*/ /* read bdf font header information, return 0 on error*/
int bdf_read_header(Common::SeekableReadStream &fp, NewFontData* pf) { int bdf_read_header(Common::SeekableReadStream &fp, NewFontData *pf) {
int encoding = 0; int encoding = 0;
int nchars = 0, maxwidth, maxheight; int nchars = 0, maxwidth, maxheight;
int firstchar = 65535; int firstchar = 65535;
@ -320,7 +328,7 @@ int bdf_read_header(Common::SeekableReadStream &fp, NewFontData* pf) {
/* calc default char*/ /* calc default char*/
if (pf->defaultchar < 0 || if (pf->defaultchar < 0 ||
pf->defaultchar < firstchar || pf->defaultchar < firstchar ||
pf->defaultchar > limit_char ) pf->defaultchar > limit_char)
pf->defaultchar = firstchar; pf->defaultchar = firstchar;
/* calc font size (offset/width entries)*/ /* calc font size (offset/width entries)*/
@ -350,7 +358,7 @@ int bdf_read_header(Common::SeekableReadStream &fp, NewFontData* pf) {
} }
/* read bdf font bitmaps, return 0 on error*/ /* read bdf font bitmaps, return 0 on error*/
int bdf_read_bitmaps(Common::SeekableReadStream &fp, NewFontData* pf) { int bdf_read_bitmaps(Common::SeekableReadStream &fp, NewFontData *pf) {
long ofs = 0; long ofs = 0;
int maxwidth = 0; int maxwidth = 0;
int i, k, encoding = 0, width = 0; int i, k, encoding = 0, width = 0;
@ -408,18 +416,18 @@ int bdf_read_bitmaps(Common::SeekableReadStream &fp, NewFontData* pf) {
continue; continue;
/* set bits offset in encode map*/ /* set bits offset in encode map*/
if (pf->offset[encoding-pf->firstchar] != (unsigned long)-1) { if (pf->offset[encoding - pf->firstchar] != (unsigned long)-1) {
warning("Error: duplicate encoding for character %d (0x%02x), ignoring duplicate", warning("Error: duplicate encoding for character %d (0x%02x), ignoring duplicate",
encoding, encoding); encoding, encoding);
continue; continue;
} }
pf->offset[encoding-pf->firstchar] = ofs; pf->offset[encoding - pf->firstchar] = ofs;
pf->width[encoding-pf->firstchar] = width; pf->width[encoding - pf->firstchar] = width;
pf->bbx[encoding-pf->firstchar].w = bbw; pf->bbx[encoding - pf->firstchar].w = bbw;
pf->bbx[encoding-pf->firstchar].h = bbh; pf->bbx[encoding - pf->firstchar].h = bbh;
pf->bbx[encoding-pf->firstchar].x = bbx; pf->bbx[encoding - pf->firstchar].x = bbx;
pf->bbx[encoding-pf->firstchar].y = bby; pf->bbx[encoding - pf->firstchar].y = bby;
if (width > maxwidth) if (width > maxwidth)
maxwidth = width; maxwidth = width;
@ -521,11 +529,10 @@ int bdf_read_bitmaps(Common::SeekableReadStream &fp, NewFontData* pf) {
else else
error("bdf_read_bitmaps: Error while reallocating memory"); error("bdf_read_bitmaps: Error while reallocating memory");
pf->bits_size = ofs; pf->bits_size = ofs;
} } else {
else {
if (ofs > pf->bits_size) { if (ofs > pf->bits_size) {
warning("Warning: DWIDTH spec > max FONTBOUNDINGBOX"); warning("Warning: DWIDTH spec > max FONTBOUNDINGBOX");
if (ofs > pf->bits_size+EXTRA) { if (ofs > pf->bits_size + EXTRA) {
warning("Error: Not enough bits initially allocated"); warning("Error: Not enough bits initially allocated");
return 0; return 0;
} }

View file

@ -44,19 +44,19 @@ struct BBX {
/* builtin C-based proportional/fixed font structure */ /* builtin C-based proportional/fixed font structure */
/* based on The Microwindows Project http://microwindows.org */ /* based on The Microwindows Project http://microwindows.org */
struct FontDesc { struct FontDesc {
const char * name; /* font name*/ const char *name; /* font name */
int maxwidth; /* max width in pixels*/ int maxwidth; /* max width in pixels */
int height; /* height in pixels*/ int height; /* height in pixels */
int fbbw, fbbh, fbbx, fbby; /* max bounding box */ int fbbw, fbbh, fbbx, fbby; /* max bounding box */
int ascent; /* ascent (baseline) height*/ int ascent; /* ascent (baseline) height */
int firstchar; /* first character in bitmap*/ int firstchar; /* first character in bitmap */
int size; /* font size in glyphs*/ int size; /* font size in glyphs */
const bitmap_t* bits; /* 16-bit right-padded bitmap data*/ const bitmap_t *bits; /* 16-bit right-padded bitmap data */
const unsigned long* offset; /* offsets into bitmap data*/ const unsigned long *offset; /* offsets into bitmap data */
const unsigned char* width; /* character widths or NULL if fixed*/ const unsigned char *width; /* character widths or NULL if fixed */
const BBX* bbx; /* character bounding box or NULL if fixed */ const BBX *bbx; /* character bounding box or NULL if fixed */
int defaultchar; /* default char (not glyph index)*/ int defaultchar; /* default char (not glyph index) */
long bits_size; /* # words of bitmap_t bits*/ long bits_size; /* # words of bitmap_t bits */
}; };
struct NewFontData; struct NewFontData;
@ -70,8 +70,8 @@ public:
NewFont(const FontDesc &desc, NewFontData *font = 0) : _desc(desc), _font(font) {} NewFont(const FontDesc &desc, NewFontData *font = 0) : _desc(desc), _font(font) {}
~NewFont(); ~NewFont();
virtual int getFontHeight() const { return _desc.height; } virtual int getFontHeight() const;
virtual int getMaxCharWidth() const { return _desc.maxwidth; } virtual int getMaxCharWidth() const;
virtual int getCharWidth(byte chr) const; virtual int getCharWidth(byte chr) const;
virtual void drawChar(Surface *dst, byte chr, int x, int y, uint32 color) const; virtual void drawChar(Surface *dst, byte chr, int x, int y, uint32 color) const;