mirror of
https://github.com/VARCem/PDCurses.git
synced 2026-09-23 23:35:20 +00:00
TTF and 16-bit Unicode output for SDL 1.2, after Laura Michaels. ("make
WIDE=Y" builds against SDL_ttf, if available.)
This commit is contained in:
@@ -19,9 +19,18 @@ SLIBS = $(shell sdl-config --libs)
|
||||
SFLAGS += -DHAVE_VSNPRINTF -DHAVE_VSSCANF
|
||||
|
||||
ifeq ($(DEBUG),Y)
|
||||
CFLAGS = -g -Wall -DPDCDEBUG
|
||||
CFLAGS = -g -Wall -DPDCDEBUG -fPIC
|
||||
else
|
||||
CFLAGS = -O2 -Wall
|
||||
CFLAGS = -O2 -Wall -fPIC
|
||||
endif
|
||||
|
||||
ifeq ($(WIDE),Y)
|
||||
CFLAGS += -DPDC_WIDE
|
||||
SLIBS += -lSDL_ttf
|
||||
endif
|
||||
|
||||
ifeq ($(UTF8),Y)
|
||||
CFLAGS += -DPDC_FORCE_UTF8
|
||||
endif
|
||||
|
||||
BUILD = $(CC) $(CFLAGS) -I$(PDCURSES_SRCDIR)
|
||||
|
||||
@@ -12,12 +12,23 @@ osdir = $(PDCURSES_SRCDIR)/sdl1
|
||||
|
||||
PDCURSES_SDL_H = $(osdir)/pdcsdl.h
|
||||
|
||||
SLIBS = -lSDL
|
||||
|
||||
ifeq ($(DEBUG),Y)
|
||||
CFLAGS = -g -Wall -DPDCDEBUG
|
||||
else
|
||||
CFLAGS = -O2 -Wall
|
||||
endif
|
||||
|
||||
ifeq ($(WIDE),Y)
|
||||
CFLAGS += -DPDC_WIDE
|
||||
SLIBS += -lSDL_ttf
|
||||
endif
|
||||
|
||||
ifeq ($(UTF8),Y)
|
||||
CFLAGS += -DPDC_FORCE_UTF8
|
||||
endif
|
||||
|
||||
CC = gcc
|
||||
BUILD = $(CC) $(CFLAGS) -I$(PDCURSES_SRCDIR)
|
||||
LDFLAGS = -mwindows $(LIBCURSES)
|
||||
@@ -34,13 +45,13 @@ ifeq ($(DLL),Y)
|
||||
LIBFLAGS = -Wl,--out-implib,libpdcurses.a -shared -o
|
||||
LIBCURSES = pdcurses.dll
|
||||
CLEAN = $(LIBCURSES) *.a $(DEFFILE)
|
||||
POST = -lSDL
|
||||
POST = $(SLIBS)
|
||||
else
|
||||
LIBEXE = ar
|
||||
LIBFLAGS = rcv
|
||||
LIBCURSES = libpdcurses.a
|
||||
CLEAN = *.a
|
||||
LDFLAGS += -lSDL
|
||||
LDFLAGS += $(SLIBS)
|
||||
endif
|
||||
|
||||
DEMOS += sdltest.exe
|
||||
|
||||
@@ -12,7 +12,7 @@ Building
|
||||
assumes a working sdl-config, and GNU make. It builds the library
|
||||
libpdcurses.a (dynamic lib not implemented).
|
||||
|
||||
With MinGW, run "make -f Makefile.mng". This assumes SDL is installed
|
||||
- With MinGW, run "make -f Makefile.mng". This assumes SDL is installed
|
||||
in the standard directories. The MinGW makefile accepts the optional
|
||||
parameters "DLL=Y" and "DEBUG=Y", as with the console version. (Wide-
|
||||
character support is not yet implemented for SDL.) Both makefiles
|
||||
|
||||
@@ -121,7 +121,7 @@ int PDC_clearclipboard(void)
|
||||
{
|
||||
PDC_LOG(("PDC_clearclipboard() - called\n"));
|
||||
|
||||
if (pdc_SDL_clipboard)
|
||||
if (pdc_SDL_clipboard)
|
||||
{
|
||||
free(pdc_SDL_clipboard);
|
||||
pdc_SDL_clipboard = NULL;
|
||||
|
||||
106
sdl1/pdcdisp.c
106
sdl1/pdcdisp.c
@@ -17,24 +17,43 @@ chtype acs_map[128] =
|
||||
A(28), A(29), A(30), A(31), ' ', '!', '"', '#', '$', '%', '&',
|
||||
'\'', '(', ')', '*',
|
||||
|
||||
# ifdef PDC_WIDE
|
||||
0x2192, 0x2190, 0x2191, 0x2193,
|
||||
# else
|
||||
A(0x1a), A(0x1b), A(0x18), A(0x19),
|
||||
# endif
|
||||
|
||||
'/',
|
||||
|
||||
# ifdef PDC_WIDE
|
||||
0x2588,
|
||||
# else
|
||||
0xdb,
|
||||
# endif
|
||||
|
||||
'1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=',
|
||||
'>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
|
||||
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
|
||||
|
||||
# ifdef PDC_WIDE
|
||||
0x2666, 0x2592,
|
||||
# else
|
||||
A(0x04), 0xb1,
|
||||
# endif
|
||||
|
||||
'b', 'c', 'd', 'e',
|
||||
|
||||
# ifdef PDC_WIDE
|
||||
0x00b0, 0x00b1, 0x2591, 0x00a4, 0x2518, 0x2510, 0x250c, 0x2514,
|
||||
0x253c, 0x23ba, 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524,
|
||||
0x2534, 0x252c, 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3,
|
||||
0x00b7,
|
||||
# else
|
||||
0xf8, 0xf1, 0xb0, A(0x0f), 0xd9, 0xbf, 0xda, 0xc0, 0xc5, 0x2d,
|
||||
0x2d, 0xc4, 0x2d, 0x5f, 0xc3, 0xb4, 0xc1, 0xc2, 0xb3, 0xf3,
|
||||
0xf2, 0xe3, 0xd8, 0x9c, 0xf9,
|
||||
# endif
|
||||
|
||||
A(127)
|
||||
};
|
||||
@@ -60,7 +79,7 @@ void PDC_update_rects(void)
|
||||
{
|
||||
if (rectcount)
|
||||
{
|
||||
/* if the maximum number of rects has been reached, we're
|
||||
/* if the maximum number of rects has been reached, we're
|
||||
probably better off doing a full screen update */
|
||||
|
||||
if (rectcount == MAXRECT)
|
||||
@@ -100,13 +119,16 @@ static void _set_attr(chtype ch)
|
||||
|
||||
if (newfg != foregr)
|
||||
{
|
||||
SDL_SetPalette(pdc_font, SDL_LOGPAL,
|
||||
#ifndef PDC_WIDE
|
||||
SDL_SetPalette(pdc_font, SDL_LOGPAL,
|
||||
pdc_color + newfg, pdc_flastc, 1);
|
||||
#endif
|
||||
foregr = newfg;
|
||||
}
|
||||
|
||||
if (newbg != backgr)
|
||||
{
|
||||
#ifndef PDC_WIDE
|
||||
if (newbg == -1)
|
||||
SDL_SetColorKey(pdc_font, SDL_SRCCOLORKEY, 0);
|
||||
else
|
||||
@@ -117,7 +139,7 @@ static void _set_attr(chtype ch)
|
||||
SDL_SetPalette(pdc_font, SDL_LOGPAL,
|
||||
pdc_color + newbg, 0, 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
backgr = newbg;
|
||||
}
|
||||
|
||||
@@ -132,6 +154,9 @@ void PDC_gotoyx(int row, int col)
|
||||
SDL_Rect src, dest;
|
||||
chtype ch;
|
||||
int oldrow, oldcol;
|
||||
#ifdef PDC_WIDE
|
||||
Uint16 chstr[2] = {0, 0};
|
||||
#endif
|
||||
|
||||
PDC_LOG(("PDC_gotoyx() - called: row %d col %d from row %d col %d\n",
|
||||
row, col, SP->cursrow, SP->curscol));
|
||||
@@ -149,8 +174,8 @@ void PDC_gotoyx(int row, int col)
|
||||
if (!SP->visibility)
|
||||
return;
|
||||
|
||||
/* draw a new cursor by overprinting the existing character in
|
||||
reverse, either the full cell (when visibility == 2) or the
|
||||
/* draw a new cursor by overprinting the existing character in
|
||||
reverse, either the full cell (when visibility == 2) or the
|
||||
lowest quarter of it (when visibility == 1) */
|
||||
|
||||
ch = curscr->_y[row][col] ^ A_REVERSE;
|
||||
@@ -167,10 +192,29 @@ void PDC_gotoyx(int row, int col)
|
||||
dest.y = (row + 1) * pdc_fheight - src.h + pdc_yoffset;
|
||||
dest.x = col * pdc_fwidth + pdc_xoffset;
|
||||
|
||||
#ifdef PDC_WIDE
|
||||
chstr[0] = ch & A_CHARTEXT;
|
||||
|
||||
pdc_font = TTF_RenderUNICODE_Solid(pdc_ttffont, chstr, pdc_color[foregr]);
|
||||
if (pdc_font)
|
||||
{
|
||||
dest.h = src.h;
|
||||
dest.w = src.w;
|
||||
src.x = 0;
|
||||
src.y = 0;
|
||||
SDL_SetColorKey(pdc_font, 0, 0);
|
||||
SDL_SetPalette(pdc_font, SDL_LOGPAL, pdc_color + backgr, 0, 1);
|
||||
SDL_BlitSurface(pdc_font, &src, pdc_screen, &dest);
|
||||
SDL_FreeSurface(pdc_font);
|
||||
pdc_font = NULL;
|
||||
}
|
||||
#else
|
||||
|
||||
src.x = (ch & 0xff) % 32 * pdc_fwidth;
|
||||
src.y = (ch & 0xff) / 32 * pdc_fheight + (pdc_fheight - src.h);
|
||||
|
||||
SDL_BlitSurface(pdc_font, &src, pdc_screen, &dest);
|
||||
#endif
|
||||
|
||||
if (oldrow != row || oldcol != col)
|
||||
{
|
||||
@@ -186,12 +230,33 @@ void PDC_gotoyx(int row, int col)
|
||||
static void _highlight(SDL_Rect *src, SDL_Rect *dest, chtype ch)
|
||||
{
|
||||
short col = SP->line_color;
|
||||
#ifdef PDC_WIDE
|
||||
Uint16 chstr[2] = {'_', 0};
|
||||
#endif
|
||||
|
||||
if (SP->mono)
|
||||
return;
|
||||
|
||||
if (ch & A_UNDERLINE)
|
||||
{
|
||||
#ifdef PDC_WIDE
|
||||
if (col == -1)
|
||||
col = foregr;
|
||||
|
||||
pdc_font = TTF_RenderUNICODE_Solid(pdc_ttffont, chstr, pdc_color[col]);
|
||||
if (pdc_font)
|
||||
{
|
||||
src->x = 0;
|
||||
src->y = 0;
|
||||
|
||||
if (backgr != -1)
|
||||
SDL_SetColorKey(pdc_font, SDL_SRCCOLORKEY, 0);
|
||||
|
||||
SDL_BlitSurface(pdc_font, src, pdc_screen, dest);
|
||||
SDL_FreeSurface(pdc_font);
|
||||
pdc_font = NULL;
|
||||
}
|
||||
#else
|
||||
if (col != -1)
|
||||
SDL_SetPalette(pdc_font, SDL_LOGPAL,
|
||||
pdc_color + col, pdc_flastc, 1);
|
||||
@@ -210,6 +275,7 @@ static void _highlight(SDL_Rect *src, SDL_Rect *dest, chtype ch)
|
||||
if (col != -1)
|
||||
SDL_SetPalette(pdc_font, SDL_LOGPAL,
|
||||
pdc_color + foregr, pdc_flastc, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ch & (A_LEFTLINE|A_RIGHTLINE))
|
||||
@@ -240,6 +306,9 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
|
||||
{
|
||||
SDL_Rect src, dest, lastrect;
|
||||
int j;
|
||||
#ifdef PDC_WIDE
|
||||
Uint16 chstr[2] = {0, 0};
|
||||
#endif
|
||||
|
||||
PDC_LOG(("PDC_transform_line() - called: lineno=%d\n", lineno));
|
||||
|
||||
@@ -268,17 +337,23 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
|
||||
else
|
||||
if (lastrect.y != dest.y)
|
||||
uprect[rectcount++] = dest;
|
||||
}
|
||||
}
|
||||
else
|
||||
uprect[rectcount++] = dest;
|
||||
|
||||
dest.w = pdc_fwidth;
|
||||
|
||||
#ifdef PDC_WIDE
|
||||
src.x = 0;
|
||||
src.y = 0;
|
||||
#endif
|
||||
|
||||
for (j = 0; j < len; j++)
|
||||
{
|
||||
chtype ch = srcp[j];
|
||||
|
||||
_set_attr(ch);
|
||||
|
||||
#ifdef CHTYPE_LONG
|
||||
if (ch & A_ALTCHARSET && !(ch & 0xff80))
|
||||
ch = (ch & (A_ATTRIBUTES ^ A_ALTCHARSET)) | acs_map[ch & 0x7f];
|
||||
@@ -286,10 +361,29 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
|
||||
if (backgr == -1)
|
||||
SDL_LowerBlit(pdc_tileback, &dest, pdc_screen, &dest);
|
||||
|
||||
#ifdef PDC_WIDE
|
||||
chstr[0] = ch & A_CHARTEXT;
|
||||
pdc_font = TTF_RenderUNICODE_Solid(pdc_ttffont, chstr,
|
||||
pdc_color[foregr]);
|
||||
|
||||
if (pdc_font)
|
||||
{
|
||||
if (backgr != -1)
|
||||
{
|
||||
SDL_SetColorKey(pdc_font, 0, 0);
|
||||
SDL_SetPalette(pdc_font, SDL_LOGPAL,
|
||||
pdc_color + backgr, 0, 1);
|
||||
}
|
||||
SDL_BlitSurface(pdc_font, &src, pdc_screen, &dest);
|
||||
SDL_FreeSurface(pdc_font);
|
||||
pdc_font = NULL;
|
||||
}
|
||||
#else
|
||||
src.x = (ch & 0xff) % 32 * pdc_fwidth;
|
||||
src.y = (ch & 0xff) / 32 * pdc_fheight;
|
||||
|
||||
SDL_LowerBlit(pdc_font, &src, pdc_screen, &dest);
|
||||
#endif
|
||||
|
||||
if (ch & (A_UNDERLINE|A_LEFTLINE|A_RIGHTLINE))
|
||||
_highlight(&src, &dest, ch);
|
||||
|
||||
@@ -3,9 +3,25 @@
|
||||
#include "pdcsdl.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#ifndef PDC_WIDE
|
||||
#include "deffont.h"
|
||||
#endif
|
||||
#include "deficon.h"
|
||||
|
||||
#ifdef PDC_WIDE
|
||||
# ifndef PDC_FONT_PATH
|
||||
# ifdef _WIN32
|
||||
#define PDC_FONT_PATH "C:/Windows/Fonts/lucon.ttf"
|
||||
# elif defined(__APPLE__)
|
||||
#define PDC_FONT_PATH "/Library/Fonts/Courier New.ttf"
|
||||
# else
|
||||
#define PDC_FONT_PATH "/usr/share/fonts/truetype/freefont/FreeMono.ttf"
|
||||
# endif
|
||||
# endif
|
||||
TTF_Font *pdc_ttffont = NULL;
|
||||
int pdc_font_size = 18;
|
||||
#endif
|
||||
|
||||
SDL_Surface *pdc_screen = NULL, *pdc_font = NULL, *pdc_icon = NULL,
|
||||
*pdc_back = NULL, *pdc_tileback = NULL;
|
||||
int pdc_sheight = 0, pdc_swidth = 0, pdc_yoffset = 0, pdc_xoffset = 0;
|
||||
@@ -19,12 +35,31 @@ bool pdc_own_screen;
|
||||
|
||||
static struct {short f, b;} atrtab[PDC_COLOR_PAIRS];
|
||||
|
||||
static void _clean(void)
|
||||
{
|
||||
#ifdef PDC_WIDE
|
||||
if (pdc_ttffont)
|
||||
{
|
||||
TTF_CloseFont(pdc_ttffont);
|
||||
TTF_Quit();
|
||||
}
|
||||
#endif
|
||||
SDL_FreeSurface(pdc_tileback);
|
||||
SDL_FreeSurface(pdc_back);
|
||||
SDL_FreeSurface(pdc_icon);
|
||||
SDL_FreeSurface(pdc_font);
|
||||
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void PDC_retile(void)
|
||||
{
|
||||
if (pdc_tileback)
|
||||
SDL_FreeSurface(pdc_tileback);
|
||||
|
||||
pdc_tileback = SDL_DisplayFormat(pdc_screen);
|
||||
if (pdc_tileback == NULL)
|
||||
return;
|
||||
|
||||
if (pdc_back)
|
||||
{
|
||||
@@ -83,9 +118,42 @@ int PDC_scr_open(int argc, char **argv)
|
||||
return ERR;
|
||||
}
|
||||
|
||||
atexit(SDL_Quit);
|
||||
atexit(_clean);
|
||||
}
|
||||
|
||||
#ifdef PDC_WIDE
|
||||
if (!pdc_ttffont)
|
||||
{
|
||||
const char *ptsz, *fname;
|
||||
|
||||
if (TTF_Init() == -1)
|
||||
{
|
||||
fprintf(stderr, "Could not start SDL_TTF: %s\n", SDL_GetError());
|
||||
return ERR;
|
||||
}
|
||||
|
||||
ptsz = getenv("PDC_FONT_SIZE");
|
||||
if (ptsz != NULL)
|
||||
pdc_font_size = atoi(ptsz);
|
||||
if (pdc_font_size <= 0)
|
||||
pdc_font_size = 18;
|
||||
|
||||
fname = getenv("PDC_FONT");
|
||||
pdc_ttffont = TTF_OpenFont(fname ? fname : PDC_FONT_PATH,
|
||||
pdc_font_size);
|
||||
}
|
||||
|
||||
if (!pdc_ttffont)
|
||||
{
|
||||
fprintf(stderr, "Could not load font\n");
|
||||
return ERR;
|
||||
}
|
||||
|
||||
TTF_SetFontKerning(pdc_ttffont, 0);
|
||||
TTF_SetFontHinting(pdc_ttffont, TTF_HINTING_MONO);
|
||||
|
||||
SP->mono = FALSE;
|
||||
#else
|
||||
if (!pdc_font)
|
||||
{
|
||||
const char *fname = getenv("PDC_FONT");
|
||||
@@ -102,6 +170,7 @@ int PDC_scr_open(int argc, char **argv)
|
||||
}
|
||||
|
||||
SP->mono = !pdc_font->format->palette;
|
||||
#endif
|
||||
|
||||
if (!SP->mono && !pdc_back)
|
||||
{
|
||||
@@ -118,11 +187,15 @@ int PDC_scr_open(int argc, char **argv)
|
||||
else
|
||||
SP->orig_attr = FALSE;
|
||||
|
||||
#ifdef PDC_WIDE
|
||||
TTF_SizeText(pdc_ttffont, "W", &pdc_fwidth, &pdc_fheight);
|
||||
#else
|
||||
pdc_fheight = pdc_font->h / 8;
|
||||
pdc_fwidth = pdc_font->w / 32;
|
||||
|
||||
if (!SP->mono)
|
||||
pdc_flastc = pdc_font->format->palette->ncolors - 1;
|
||||
#endif
|
||||
|
||||
if (pdc_own_screen && !pdc_icon)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,14 @@
|
||||
#include <curspriv.h>
|
||||
|
||||
#include <SDL.h>
|
||||
#ifdef PDC_WIDE
|
||||
#include <SDL_ttf.h>
|
||||
#endif
|
||||
|
||||
#ifdef PDC_WIDE
|
||||
PDCEX TTF_Font *pdc_ttffont;
|
||||
PDCEX int pdc_font_size;
|
||||
#endif
|
||||
PDCEX SDL_Surface *pdc_screen, *pdc_font, *pdc_icon, *pdc_back;
|
||||
PDCEX int pdc_sheight, pdc_swidth, pdc_yoffset, pdc_xoffset;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user