/* GnarlPlot font header V1.20 2/2/08
   Copyright 2008 Jeffrey Lee
   This file is part of GnarlPlot.
   GnarlPlot is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
   GnarlPlot is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   You should have received a copy of the GNU General Public License
   along with GnarlPlot.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef _GP_FONT_H
#define _GP_FONT_H

#include "spr.h"

#define GP_FONT_UP 1 /* Font can be scaled up */
#define GP_FONT_DOWN 2 /* Font can be scaled down */
#define GP_FONT_LAST 4 /* Last entry in a font definition group */

typedef struct _gp_font_def {
	int width; /* Base width of font */
	int flags; /* Font flags */
	int id; /* User ID for passing to the loader func */
	gp_spr **(*load)(struct _gp_font_def *f); /* Load the font from disc and return a pointer to 256 sprites, or null */
} gp_font_def; /* Font definition */

typedef struct _gp_font {
	gp_font_def *style; /* Font style */
	int width; /* Width of the font */
	int height; /* Height of the font */
	int fgcol; /* Font foreground colour (24bit) */
	int bgcol; /* Background colour (24bit), or -1 for masked */
	int ps; /* Pixel size used by the sprites */
	gp_spr *f[256]; /* Full sprite listing; unprintable chars are mapped to space */
	struct _gp_font *next; /* Next font in the list */
	int nref; /* Number of references to this handle */
	int age; /* Font age; used to decide which unused fonts should be recycled */
} gp_font; /* Font handle */

extern int gp_font_old; /* Number of unused fonts to keep in memory before recycling, default = 5 */

extern gp_font *gp_loadfont(gp_font_def *style,int width,int fgcol,int bgcol,int ps); /* Return a font handle for the specified font. style must be a pointer to an array of font definitions, the last entry of which is marked with the GP_FONT_LAST flag. The definitions must occur in increasing size order. */
extern void gp_freefont(gp_font *h); /* Stop using a font handle */

extern gp_spr **gp_loadfont_paint(gp_font_def *d); /* Load a !Paint sprite file as a font. d->id must be a pointer to the file name, and sprite names should be the ASCII codes of the letters they represent */

extern int gp_font_puts(const gp_font *h,const char *t,int l,gp_screen *s,int x,int y); /* Write l characters from t to (x,y) in screen s, returning the end x position. Doesn't check for the screen edge, control characters, etc. */
extern int gp_font_puts_scaled(const gp_font *h,const char *t,int l,gp_screen *s,int x,int y,f1616 sc); /* Plot a font scaled to sc times its size */
extern int gp_font_getwidth(const gp_font *h,const char *t,int l,f1616 sc); /* Return width of string at given scale */

extern void gp_font_flush(); /* Flush all unused fonts from the font cache */

#endif
