diff --git a/demos/Makefile b/demos/Makefile deleted file mode 100644 index 17b9a0ff5..000000000 --- a/demos/Makefile +++ /dev/null @@ -1,288 +0,0 @@ -all: exes - -#################################################################### -# -# TOP is the directory where the main FreeType source is found, -# as well as the 'config.mk' file -# -# TOP2 is the directory is the top of the demonstration -# programs directory -# - -ifndef TOP - TOP := .. -endif - -ifndef TOP2 - TOP2 := $(TOP)/demos -endif - -###################################################################### -# -# MY_CONFIG_MK points to the current "config.mk" to use. It is -# defined by default as $(TOP)/config.mk -# -ifndef CONFIG_MK - CONFIG_MK := $(TOP)/config.mk -endif - -#################################################################### -# -# Check that we have a working `config.mk' in the above directory. -# If not, issue a warning message, then stop there.. -# -ifeq ($(wildcard $(CONFIG_MK)),) - no_config_mk := 1 -endif - -ifdef no_config_mk - exes: - @echo Please compile the library before the demo programs! - clean distclean: - @echo "I need \`$(TOP)/config.mk' to do that!" -else - - #################################################################### - # - # Good, now include the `config.mk' in order to know how to build - # object files from sources, as well as other things (compiler flags) - # - include $(CONFIG_MK) - - - #################################################################### - # - # Define a few important variables now - # - TOP_ := $(TOP)$(SEP) - TOP2_ := $(TOP2)$(SEP) - SRC_ := $(TOP)$(SEP)src$(SEP) - - BIN_ := bin$(SEP) - OBJ_ := obj$(SEP) - - GRAPH_DIR := graph - - ifeq ($(TOP),..) - SRC_DIR := src - else - SRC_DIR := $(TOP2_)src - endif - - SRC_DIR_ := $(SRC_DIR)$(SEP) - - FT_INCLUDES := $(BUILD) $(TOP_)config $(TOP_)include $(SRC_) $(SRC_DIR) - - COMPILE = $(CC) $(CFLAGS) $(INCLUDES:%=$I%) - FTLIB := $(TOP_)$(LIB_DIR)$(SEP)$(LIBRARY).$A - - # the default commands used to link the executables. These can - # be re-defined for platform-specific stuff.. - # - LINK = $(CC) $T$@ $< $(FTLIB) $(EFENCE) $(LDFLAGS) - - # the program "src/ftstring.c" used the math library which isn't linked - # with the program by default on Unix, we thus add it whenever appropriate - # - ifeq ($(PLATFORM),unix) - LINK += -lm - endif - - COMMON_LINK = $(LINK) $(COMMON_OBJ) - GRAPH_LINK = $(COMMON_LINK) $(GRAPH_LIB) - GRAPH_LINK2 = $(GRAPH_LINK) $(EXTRA_GRAPH_OBJS) - - .PHONY: exes clean distclean - - ################################################################### - # - # Include the rules needed to compile the graphics sub-system. - # This will also select which graphics driver to compile to the - # sub-system.. - # - include $(GRAPH_DIR)/rules.mk - - #################################################################### - # - # Detect DOS-like platforms, currently DOS, Win 3.1, Win32 & OS/2 - # - ifneq ($(findstring $(PLATFORM),os2 win16 win32 dos),) - DOSLIKE := 1 - endif - - - ################################################################### - # - # Clean-up rules. Because the `del' command on DOS-like platforms - # cannot take a long list of arguments, we simply erase the directory - # contents. - # - ifdef DOSLIKE - - clean_demo: - -del obj\*.$O 2> nul - -del $(subst /,\,$(TOP2))\src\*.bak 2> nul - - distclean_demo: clean_demo - -del obj\*.lib 2> nul - -del bin\*.exe 2> nul - - else - - clean_demo: - -$(DELETE) $(OBJ_)*.$O - -$(DELETE) $(SRC_)*.bak graph$(SEP)*.bak - -$(DELETE) $(SRC_)*~ graph$(SEP)*~ - - distclean_demo: clean_demo - -$(DELETE) $(EXES:%=$(BIN_)%$E) - -$(DELETE) $(GRAPH_LIB) - - endif - - clean: clean_demo - distclean: distclean_demo - - #################################################################### - # - # Compute the executable suffix to use, and put it in `E'. - # It is ".exe" on DOS-ish platforms, and nothing otherwise. - # - ifdef DOSLIKE - E := .exe - else - E := - endif - - ################################################################### - # - # The list of demonstration programs to build. - # -# EXES := ftlint ftview fttimer compos ftstring memtest ftmulti - EXES := ftlint ftview fttimer ftstring memtest ftmulti - - ifneq ($(findstring $(PLATFORM),os2 unix win32),) - EXES += ttdebug - endif - - exes: $(EXES:%=$(BIN_)%$E) - - - INCLUDES := $(FT_INCLUDES) - - #################################################################### - # - # Rules for compiling object files for text-only demos - # - COMMON_OBJ := $(OBJ_)common.$O - $(COMMON_OBJ): $(SRC_DIR_)common.c - ifdef DOSLIKE - $(COMPILE) $T$@ $< $DEXPAND_WILDCARDS - else - $(COMPILE) $T$@ $< - endif - - - $(OBJ_)%.$O: $(SRC_DIR_)%.c $(FTLIB) - $(COMPILE) $T$@ $< - - $(OBJ_)ftlint.$O: $(SRC_DIR_)ftlint.c - $(COMPILE) $T$@ $< - - $(OBJ_)compos.$O: $(SRC_DIR_)compos.c - $(COMPILE) $T$@ $< - - $(OBJ_)memtest.$O: $(SRC_DIR_)memtest.c - $(COMPILE) $T$@ $< - - $(OBJ_)fttry.$O: $(SRC_DIR_)fttry.c - $(COMPILE) $T$@ $< - - - $(OBJ_)ftview.$O: $(SRC_DIR_)ftview.c $(GRAPH_LIB) - $(COMPILE) $(GRAPH_INCLUDES:%=$I%) $T$@ $< - - $(OBJ_)ftmulti.$O: $(SRC_DIR_)ftmulti.c $(GRAPH_LIB) - $(COMPILE) $(GRAPH_INCLUDES:%=$I%) $T$@ $< - - $(OBJ_)ftstring.$O: $(SRC_DIR_)ftstring.c $(GRAPH_LIB) - $(COMPILE) $(GRAPH_INCLUDES:%=$I%) $T$@ $< - - $(OBJ_)fttimer.$O: $(SRC_DIR_)fttimer.c $(GRAPH_LIB) - $(COMPILE) $(GRAPH_INCLUDES:%=$I%) $T$@ $< - - - -# $(OBJ_)ftsbit.$O: $(SRC_DIR)/ftsbit.c $(GRAPH_LIB) -# $(COMPILE) $T$@ $< - - - #################################################################### - # - # Special rule to compile the `t1dump' program as it includes - # the Type1 source path - # - $(OBJ_)t1dump.$O: $(SRC_DIR)/t1dump.c - $(COMPILE) $T$@ $< - - - #################################################################### - # - # Special rule to compile the `ttdebug' program as it includes - # the TrueType source path and needs extra flags for correct keyboard - # handling on Unix - - # POSIX TERMIOS: Do not define if you use OLD U*ix like 4.2BSD. - # - # detect a Unix system - ifeq ($(PLATFORM),unix) - EXTRAFLAGS = $DUNIX $DHAVE_POSIX_TERMIOS - endif - - $(OBJ_)ttdebug.$O: $(SRC_DIR)/ttdebug.c - $(COMPILE) $T$@ $< $(EXTRAFLAGS) - - - #################################################################### - # - # Rules used to link the executables. Note that they could be - # over-ridden by system-specific things.. - # - $(BIN_)ftlint$E: $(OBJ_)ftlint.$O $(FTLIB) $(COMMON_OBJ) - $(COMMON_LINK) - - $(BIN_)memtest$E: $(OBJ_)memtest.$O $(FTLIB) $(COMMON_OBJ) - $(COMMON_LINK) - - $(BIN_)compos$E: $(OBJ_)compos.$O $(FTLIB) $(COMMON_OBJ) - $(COMMON_LINK) - - $(BIN_)fttry$E: $(OBJ_)fttry.$O $(FTLIB) - $(LINK) - - $(BIN_)ftsbit$E: $(OBJ_)ftsbit.$O $(FTLIB) - $(LINK) - - $(BIN_)t1dump$E: $(OBJ_)t1dump.$O $(FTLIB) - $(LINK) - - $(BIN_)ttdebug$E: $(OBJ_)ttdebug.$O $(FTLIB) - $(LINK) - - - $(BIN_)ftview$E: $(OBJ_)ftview.$O $(FTLIB) $(GRAPH_LIB) $(COMMON_OBJ) - $(GRAPH_LINK) - - $(BIN_)ftmulti$E: $(OBJ_)ftmulti.$O $(FTLIB) $(GRAPH_LIB) $(COMMON_OBJ) - $(GRAPH_LINK) - - $(BIN_)ftstring$E: $(OBJ_)ftstring.$O $(FTLIB) $(GRAPH_LIB) $(COMMON_OBJ) - $(GRAPH_LINK) - - $(BIN_)fttimer$E: $(OBJ_)fttimer.$O $(FTLIB) $(GRAPH_LIB) $(COMMON_OBJ) - $(GRAPH_LINK) - - -endif - -# EOF diff --git a/demos/bin/README b/demos/bin/README deleted file mode 100644 index 9a574c13f..000000000 --- a/demos/bin/README +++ /dev/null @@ -1 +0,0 @@ -This directory contains all executables for the FreeType demo programs diff --git a/demos/graph/graph.h b/demos/graph/graph.h deleted file mode 100644 index e09667db3..000000000 --- a/demos/graph/graph.h +++ /dev/null @@ -1,632 +0,0 @@ -/*************************************************************************** - * - * graph.h - * - * Graphics Subsystem interface - * - * Copyright 1999 - The FreeType Development Team - www.freetype.org - * - * - * - * - ***************************************************************************/ - -#ifndef GRAPH_H -#define GRAPH_H - -#include "grevents.h" - - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - /******** ********/ - /******** GENERAL DEFINITIONS AND BLITTING ROUTINES ********/ - /******** ********/ - /******** ********/ - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - - - /* define the global error variable */ - extern int grError; - - /* initialisation */ - extern int grInit( void ); - - /* finalisation */ - extern void grDone( void ); - - - /* pixel mode constants */ - typedef enum grPixelMode - { - gr_pixel_mode_none = 0, - gr_pixel_mode_mono, /* monochrome bitmaps */ - gr_pixel_mode_pal4, /* 4-bit paletted - 16 colors */ - gr_pixel_mode_pal8, /* 8-bit paletted - 256 colors */ - gr_pixel_mode_gray, /* 8-bit gray levels */ - gr_pixel_mode_rgb555, /* 15-bits mode - 32768 colors */ - gr_pixel_mode_rgb565, /* 16-bits mode - 65536 colors */ - gr_pixel_mode_rgb24, /* 24-bits mode - 16 million colors */ - gr_pixel_mode_rgb32, /* 32-bits mode - 16 million colors */ - - gr_pixel_mode_max /* don't remove */ - - } grPixelMode; - - - /* forward declaration of the surface class */ - typedef struct grSurface_ grSurface; - - - /********************************************************************* - * - * - * grBitmap - * - * - * a simple bitmap descriptor - * - * - * rows :: height in pixels - * width :: width in pixels - * pitch :: + or - the number of bytes per row - * mode :: pixel mode of bitmap buffer - * grays :: number of grays in palette for PAL8 mode. 0 otherwise - * buffer :: pointer to pixel buffer - * - * - * the 'pitch' is positive for downward flows, and negative otherwise - * Its absolute value is always the number of bytes taken by each - * bitmap row. - * - * All drawing operations will be performed within the first - * "width" pixels of each row (clipping is always performed). - * - ********************************************************************/ - - typedef struct grBitmap_ - { - int rows; - int width; - int pitch; - grPixelMode mode; - int grays; - char* buffer; - - } grBitmap; - - - - typedef long grPos; - typedef char grBool; - - typedef struct grVector_ - { - grPos x; - grPos y; - - } grVector; - - - typedef union grColor_ - { - long value; - unsigned char chroma[4]; - - } grColor; - - - - /********************************************************************** - * - * - * grNewBitmap - * - * - * creates a new bitmap - * - * - * pixel_mode :: the target surface's pixel_mode - * num_grays :: number of grays levels for PAL8 pixel mode - * width :: width in pixels - * height :: height in pixels - * - * - * bit :: descriptor of the new bitmap - * - * - * Error code. 0 means success. - * - * - * This function really allocates a pixel buffer, zero it, then - * returns a descriptor for it. - * - * Call grDoneBitmap when you're done with it.. - * - **********************************************************************/ - - extern int grNewBitmap( grPixelMode pixel_mode, - int num_grays, - int width, - int height, - grBitmap *bit ); - - - /********************************************************************** - * - * - * grBlitGlyphToBitmap - * - * - * writes a given glyph bitmap to a target surface. - * - * - * target :: handle to target bitmap - * glyph :: handle to source glyph bitmap - * x :: position of left-most pixel of glyph image in target surface - * y :: position of top-most pixel of glyph image in target surface - * color :: color to be used to draw a monochrome glyph - * - * - * Error code. 0 means success - * - * - * There are only two supported source pixel modes : monochrome - * and gray. The 8-bit images can have any number of grays between - * 2 and 128, and conversions to the target surface is handled - * _automatically_. - * - * Note however that you should avoid blitting a gray glyph to a gray - * bitmap with fewer levels of grays, as this would much probably - * give unpleasant results.. - * - * This function performs clipping - * - **********************************************************************/ - - extern int grBlitGlyphToBitmap( grBitmap* target, - grBitmap* glyph, - grPos x, - grPos y, - grColor color ); - - - /********************************************************************** - * - * - * grFillRectangle - * - * - * this function is used to fill a given rectangle on a surface - * - * - * surface :: handle to target surface - * x :: x coordinate of the top-left corner of the rectangle - * y :: y coordinate of the top-left corner of the rectangle - * width :: rectangle width in pixels - * height :: rectangle height in pixels - * color :: fill color - * - **********************************************************************/ - - extern void grFillRectangle( grBitmap* surface, - grPos x, - grPos y, - grPos width, - grPos height, - grColor color ); - - - - /********************************************************************** - * - * - * grWriteCellChar - * - * - * The graphics sub-system contains an internal Latin1 8x8 font - * which can be used to display simple strings of text without - * using FreeType. - * - * This function writes a single 8x8 character on the target bitmap. - * - * - * target :: handle to target surface - * x :: x pixel position of character cell's top left corner - * y :: y pixel position of character cell's top left corner - * charcode :: Latin-1 character code - * color :: color to be used to draw the character - * - **********************************************************************/ - - extern - void grWriteCellChar( grBitmap* target, - int x, - int y, - int charcode, - grColor color ); - - - /********************************************************************** - * - * - * grWriteCellString - * - * - * The graphics sub-system contains an internal Latin1 8x8 font - * which can be used to display simple strings of text without - * using FreeType. - * - * This function writes a string with the internal font - * - * - * target :: handle to target bitmap - * x :: x pixel position of string's top left corner - * y :: y pixel position of string's top left corner - * string :: Latin-1 text string - * color :: color to be used to draw the character - * - **********************************************************************/ - - extern - void grWriteCellString( grBitmap* target, - int x, - int y, - const char* string, - grColor color ); - - /********************************************************************** - * - * - * grDoneBitmap - * - * - * destroys a bitmap - * - * - * bitmap :: handle to bitmap descriptor - * - * - * This function does NOT release the bitmap descriptor, only - * the pixel buffer. - * - **********************************************************************/ - - extern void grDoneBitmap( grBitmap* bit ); - - - - - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - /******** ********/ - /******** DEVICE-SPECIFIC DEFINITIONS AND ROUTINES ********/ - /******** ********/ - /******** ********/ - /*************************************************************************/ - /*************************************************************************/ - /*************************************************************************/ - - - /* forward declaration - the definition of grDevice is not visible */ - /* to clients.. */ - typedef struct grDevice_ grDevice; - - - /********************************************************************** - * - * - * grDeviceChain - * - * - * a simple structure used to implement a linked list of - * graphics device descriptors. The list is called a - * "device chain" - * - * - * name :: ASCII name of the device, e.g. "x11", "os2pm", etc.. - * device :: handle to the device descriptor. - * next :: next element in chain - * - * - * the 'device' field is a blind pointer; it is thus unusable by - * client applications.. - * - **********************************************************************/ - - typedef struct grDeviceChain_ grDeviceChain; - - struct grDeviceChain_ - { - const char* name; - grDevice* device; - grDeviceChain* next; - }; - - - /********************************************************************** - * - * - * grInitDevices - * - * - * This function is in charge of initialising all system-specific - * devices. A device is responsible for creating and managing one - * or more "surfaces". A surface is either a window or a screen, - * depending on the system. - * - * - * a pointer to the first element of a device chain. The chain can - * be parsed to find the available devices on the current system - * - * - * If a device cannot be initialised correctly, it is not part of - * the device chain returned by this function. For example, if an - * X11 device was compiled in the library, it will be part of - * the returned device chain only if a connection to the display - * could be establisged - * - * If no driver could be initialised, this function returns NULL. - * - **********************************************************************/ - - extern - grDeviceChain* grInitDevices( void ); - - - - /********************************************************************** - * - * - * grGetDeviceModes - * - * - * queries the available pixel modes for a device. - * - * - * device_name :: name of device to be used. 0 for the default - * device. For a list of available devices, see - * grInitDevices. - * - * - * num_modes :: number of available modes. 0 in case of error, - * which really is an invalid device name. - * - * pixel_modes :: array of available pixel modes for this device - * this table is internal to the device and should - * not be freed by client applications. - * - * - * error code. 0 means success. invalid device name otherwise - * - * - * All drivers are _required_ to support at least the following - * pixel formats : - * - * - gr_pixel_mode_mono : i.e. monochrome bitmaps - * - gr_pixel_mode_gray : with any number of gray levels between - * 2 and 256. - * - * the pixel modes do not provide the number of grays in the case - * of "gray" devices. You should try to create a surface with the - * maximal number (256, that is) and see the value returned in - * the bitmap descriptor. - * - **********************************************************************/ - - extern void grGetDeviceModes( const char* device_name, - int *num_modes, - grPixelMode* *pixel_modes ); - - - - /********************************************************************** - * - * - * grNewSurface - * - * - * creates a new device-specific surface. A surface is either - * a window or a screen, depending on the device. - * - * - * device :: name of the device to use. A value of NULL means - * the default device (which depends on the system). - * for a list of available devices, see grInitDevices. - * - * - * bitmap :: handle to a bitmap descriptor containing the - * requested pixel mode, number of grays and dimensions - * for the surface. the bitmap's 'pitch' and 'buffer' - * fields are ignored on input. - * - * On output, the bitmap describes the surface's image - * completely. It is possible to write directly in it - * with grBlitGlyphToBitmap, even though the use of - * grBlitGlyphToSurface is recommended. - * - * - * handle to the corresponding surface object. 0 in case of error - * - * - * All drivers are _required_ to support at least the following - * pixel formats : - * - * - gr_pixel_mode_mono : i.e. monochrome bitmaps - * - gr_pixel_mode_gray : with any number of gray levels between - * 2 and 256. - * - * This function might change the bitmap descriptor's fields. For - * example, when displaying a full-screen surface, the bitmap's - * dimensions will be set to those of the screen (e.g. 640x480 - * or 800x600); also, the bitmap's 'buffer' field might point to - * the Video Ram depending on the mode requested.. - * - * The surface contains a copy of the returned bitmap descriptor, - * you can thus discard the 'bitmap' parameter after the call. - * - **********************************************************************/ - - extern grSurface* grNewSurface( const char* device, - grBitmap* bitmap ); - - - - /********************************************************************** - * - * - * grRefreshRectangle - * - * - * this function is used to indicate that a given surface rectangle - * was modified and thus needs re-painting. It really is useful for - * windowed or gray surfaces. - * - * - * surface :: handle to target surface - * x :: x coordinate of the top-left corner of the rectangle - * y :: y coordinate of the top-left corner of the rectangle - * width :: rectangle width in pixels - * height :: rectangle height in pixels - * - **********************************************************************/ - - extern void grRefreshRectangle( grSurface* surface, - grPos x, - grPos y, - grPos width, - grPos height ); - - - /********************************************************************** - * - * - * grRefreshSurface - * - * - * a variation of grRefreshRectangle which repaints the whole surface - * to the screen. - * - * - * surface :: handle to target surface - * - **********************************************************************/ - - extern void grRefreshSurface( grSurface* surface ); - - - - /********************************************************************** - * - * - * grWriteSurfaceChar - * - * - * This function is equivalent to calling grWriteCellChar on the - * surface's bitmap, then invoking grRefreshRectangle. - * - * The graphics sub-system contains an internal Latin1 8x8 font - * which can be used to display simple strings of text without - * using FreeType. - * - * This function writes a single 8x8 character on the target bitmap. - * - * - * target :: handle to target surface - * x :: x pixel position of character cell's top left corner - * y :: y pixel position of character cell's top left corner - * charcode :: Latin-1 character code - * color :: color to be used to draw the character - * - **********************************************************************/ - - extern - void grWriteSurfaceChar( grSurface* target, - int x, - int y, - int charcode, - grColor color ); - - - /********************************************************************** - * - * - * grWriteSurfaceString - * - * - * This function is equivalent to calling grWriteCellString on the - * surface's bitmap, then invoking grRefreshRectangle. - * - * The graphics sub-system contains an internal Latin1 8x8 font - * which can be used to display simple strings of text without - * using FreeType. - * - * This function writes a string with the internal font - * - * - * target :: handle to target bitmap - * x :: x pixel position of string's top left corner - * y :: y pixel position of string's top left corner - * string :: Latin-1 text string - * color :: color to be used to draw the character - * - **********************************************************************/ - - extern - void grWriteSurfaceString( grSurface* target, - int x, - int y, - const char* string, - grColor color ); - - - /********************************************************************** - * - * - * grSetTitle - * - * - * set the window title of a given windowed surface. - * - * - * surface :: handle to target surface - * title_string :: the new title - * - **********************************************************************/ - - extern void grSetTitle( grSurface* surface, - const char* title_string ); - - - - - /********************************************************************** - * - * - * grListenSurface - * - * - * listen the events for a given surface - * - * - * surface :: handle to target surface - * event_mask :: the event mask (mode) - * - * - * event :: the returned event - * - * - * XXX : For now, only keypresses are supported. - * - **********************************************************************/ - - extern - int grListenSurface( grSurface* surface, - int event_mask, - grEvent *event ); - - -#endif /* GRAPH_H */ diff --git a/demos/graph/grblit.c b/demos/graph/grblit.c deleted file mode 100644 index b8d1b6e84..000000000 --- a/demos/graph/grblit.c +++ /dev/null @@ -1,1268 +0,0 @@ -/****************************************************************************/ -/* */ -/* The FreeType project -- a free and portable quality TrueType renderer. */ -/* */ -/* Copyright 1996-1999 by */ -/* D. Turner, R.Wilhelm, and W. Lemberg */ -/* */ -/* blitter.c: Support for blitting of bitmaps with various depth. */ -/* */ -/****************************************************************************/ - -#include "grblit.h" -#include "grobjs.h" - - static - int compute_clips( grBlitter* blit, - int x_offset, - int y_offset ) - { - int xmin, ymin, xmax, ymax, width, height, target_width; - - /* perform clipping and setup variables */ - width = blit->source.width; - height = blit->source.rows; - - switch ( blit->source.mode ) - { - case gr_pixel_mode_mono: - width = (width + 7) & -8; - break; - - case gr_pixel_mode_pal4: - width = (width + 1) & -2; - break; - - default: - ; - } - - xmin = x_offset; - ymin = y_offset; - xmax = xmin + width-1; - ymax = ymin + height-1; - - /* clip if necessary */ - if ( width == 0 || height == 0 || - xmax < 0 || xmin >= blit->target.width || - ymax < 0 || ymin >= blit->target.rows ) - return 1; - - /* set up clipping and cursors */ - blit->yread = 0; - if ( ymin < 0 ) - { - blit->yread -= ymin; - height += ymin; - blit->ywrite = 0; - } - else - blit->ywrite = ymin; - - if ( ymax >= blit->target.rows ) - height -= ymax - blit->target.rows + 1; - - blit->xread = 0; - if ( xmin < 0 ) - { - blit->xread -= xmin; - width += xmin; - blit->xwrite = 0; - } - else - blit->xwrite = xmin; - - target_width = blit->target.width; - - switch ( blit->target.mode ) - { - case gr_pixel_mode_mono: - target_width = (target_width + 7) & -8; - break; - case gr_pixel_mode_pal4: - target_width = (target_width + 1) & -2; - break; - - default: - ; - } - - blit->right_clip = xmax - target_width + 1; - if ( blit->right_clip > 0 ) - width -= blit->right_clip; - else - blit->right_clip = 0; - - blit->width = width; - blit->height = height; - - /* set read and write to the top-left corner of the read */ - /* and write areas before clipping. */ - - blit->read = (unsigned char*)blit->source.buffer; - blit->write = (unsigned char*)blit->target.buffer; - - blit->read_line = blit->source.pitch; - blit->write_line = blit->target.pitch; - - if ( blit->read_line < 0 ) - blit->read -= (blit->source.rows-1) * blit->read_line; - - if ( blit->write_line < 0 ) - blit->write -= (blit->target.rows-1) * blit->write_line; - - /* now go to the start line. Note that we do not move the */ - /* x position yet, as this is dependent on the pixel format */ - blit->read += blit->yread * blit->read_line; - blit->write += blit->ywrite * blit->write_line; - - return 0; - } - - -/**************************************************************************/ -/* */ -/* blit_mono_to_mono */ -/* */ -/**************************************************************************/ - - static - void blit_mono_to_mono( grBlitter* blit, - grColor color ) - { - int shift, left_clip, x, y; - byte* read; - byte* write; - - (void)color; /* unused argument */ - - left_clip = ( blit->xread > 0 ); - shift = ( blit->xwrite - blit->xread ) & 7; - - read = blit->read + (blit->xread >> 3); - write = blit->write + (blit->xwrite >> 3); - - if ( shift == 0 ) - { - y = blit->height; - do - { - byte* _read = read; - byte* _write = write; - - x = blit->width; - - do - { - *_write++ |= *_read++; - x -= 8; - } while ( x > 0 ); - - read += blit->read_line; - write += blit->write_line; - y--; - } while ( y > 0 ); - } - else - { - int first, last, count; - - - first = blit->xwrite >> 3; - last = (blit->xwrite + blit->width-1) >> 3; - - count = last - first; - - if ( blit->right_clip ) - count++; - - y = blit->height; - - do - { - unsigned char* _read = read; - unsigned char* _write = write; - unsigned char old; - int shift2 = (8-shift); - - if ( left_clip ) - old = (*_read++) << shift2; - else - old = 0; - - x = count; - while ( x > 0 ) - { - unsigned char val; - - val = *_read++; - *_write++ |= ( (val >> shift) | old ); - old = val << shift2; - x--; - } - - if ( !blit->right_clip ) - *_write |= old; - - read += blit->read_line; - write += blit->write_line; - y--; - - } while ( y > 0 ); - } - } - - -/**************************************************************************/ -/* */ -/* blit_mono_to_pal8 */ -/* */ -/**************************************************************************/ - - static - void blit_mono_to_pal8( grBlitter* blit, - grColor color ) - { - int x, y; - unsigned int left_mask; - unsigned char* read; - unsigned char* write; - - read = blit->read + (blit->xread >> 3); - write = blit->write + blit->xwrite; - - left_mask = 0x80 >> (blit->xread & 7); - - y = blit->height; - do - { - unsigned char* _read = read; - unsigned char* _write = write; - unsigned int mask = left_mask; - unsigned int val = *_read; - - - x = blit->width; - do - { - if ( mask == 0x80 ) - val = *_read++; - - if ( val & mask ) - *_write = (unsigned char)color.value; - - mask >>= 1; - if ( mask == 0 ) - mask = 0x80; - - _write++; - x--; - } while ( x > 0 ); - - read += blit->read_line; - write += blit->write_line; - y--; - } while ( y > 0 ); - } - - -/**************************************************************************/ -/* */ -/* blit_mono_to_pal4 */ -/* */ -/**************************************************************************/ - - static - void blit_mono_to_pal4( grBlitter* blit, - grColor color ) - { - int x, y, phase; - unsigned int left_mask; - unsigned char* read; - unsigned char* write; - unsigned char col; - - - col = color.value & 15; - read = blit->read + (blit->xread >> 3); - write = blit->write + (blit->xwrite >> 1); - - /* now begin blit */ - left_mask = 0x80 >> (blit->xread & 7); - phase = blit->xwrite & 1; - - y = blit->height; - do - { - unsigned char* _read = read; - unsigned char* _write = write; - unsigned int mask = left_mask; - int _phase = phase; - unsigned int val = *_read; - - x = blit->width; - do - { - if ( mask == 0x80 ) - val = *_read++; - - if ( val & mask ) - { - if ( _phase ) - *_write = (*_write & 0xF0) | col; - else - *_write = (*_write & 0x0F) | (col << 4); - } - - mask >>= 1; - if ( mask == 0 ) - mask = 0x80; - - _write += _phase; - _phase ^= 1; - x--; - } while ( x > 0 ); - - read += blit->read_line; - write += blit->write_line; - y--; - } while ( y > 0 ); - } - - -/**************************************************************************/ -/* */ -/* blit_mono_to_rgb16 */ -/* */ -/**************************************************************************/ - - static - void blit_mono_to_rgb16( grBlitter* blit, - grColor color ) - { - int x, y; - unsigned int left_mask; - unsigned char* read; - unsigned char* write; - - read = blit->read + (blit->xread >> 3); - write = blit->write + blit->xwrite*2; - - left_mask = 0x80 >> (blit->xread & 7); - - y = blit->height; - do - { - unsigned char* _read = read; - unsigned char* _write = write; - unsigned int mask = left_mask; - unsigned int val = *_read; - - x = blit->width; - do - { - if ( mask == 0x80 ) - val = *_read++; - - if ( val & mask ) - *(short*)_write = (short)color.value; - - mask >>= 1; - if ( mask == 0 ) - mask = 0x80; - - _write +=2; - x--; - } while ( x > 0 ); - - read += blit->read_line; - write += blit->write_line; - y--; - } while ( y > 0 ); - } - - -/**************************************************************************/ -/* */ -/* blit_mono_to_rgb24 */ -/* */ -/**************************************************************************/ - - static - void blit_mono_to_rgb24( grBlitter* blit, - grColor color ) - { - int x, y; - unsigned int left_mask; - unsigned char* read; - unsigned char* write; - - read = blit->read + (blit->xread >> 3); - write = blit->write + blit->xwrite*3; - - left_mask = 0x80 >> (blit->xread & 7); - - y = blit->height; - do - { - unsigned char* _read = read; - unsigned char* _write = write; - unsigned int mask = left_mask; - unsigned int val = *_read; - - x = blit->width; - do - { - if ( mask == 0x80 ) - val = *_read++; - - if ( val & mask ) - { - _write[0] = color.chroma[0]; - _write[1] = color.chroma[1]; - _write[2] = color.chroma[2]; - } - - mask >>= 1; - if ( mask == 0 ) - mask = 0x80; - - _write += 3; - x--; - } while ( x > 0 ); - - read += blit->read_line; - write += blit->write_line; - y--; - } while ( y > 0 ); - } - - -/**************************************************************************/ -/* */ -/* blit_mono_to_rgb32 */ -/* */ -/**************************************************************************/ - - static - void blit_mono_to_rgb32( grBlitter* blit, - grColor color ) - { - int x, y; - unsigned int left_mask; - unsigned char* read; - unsigned char* write; - - read = blit->read + (blit->xread >> 3); - write = blit->write + blit->xwrite*4; - - left_mask = 0x80 >> (blit->xread & 7); - - y = blit->height; - do - { - unsigned char* _read = read; - unsigned char* _write = write; - unsigned int mask = left_mask; - unsigned int val = *_read; - - x = blit->width; - do - { - if ( mask == 0x80 ) - val = *_read++; - - if ( val & mask ) - { - /* this could be greatly optimised as a *(long*)_write = color.value */ - /* but this wouldn't work on 64-bits systems... stupid C types! */ - _write[0] = color.chroma[0]; - _write[1] = color.chroma[1]; - _write[2] = color.chroma[2]; - _write[3] = color.chroma[3]; - } - - mask >>= 1; - if ( mask == 0 ) - mask = 0x80; - - _write += 4; - x--; - } while ( x > 0 ); - - read += blit->read_line; - write += blit->write_line; - y--; - } while ( y > 0 ); - } - - - - static - const grBlitterFunc gr_mono_blitters[gr_pixel_mode_max] = - { - 0, - blit_mono_to_mono, - blit_mono_to_pal4, - blit_mono_to_pal8, - blit_mono_to_pal8, - blit_mono_to_rgb16, - blit_mono_to_rgb16, - blit_mono_to_rgb24, - blit_mono_to_rgb32 - }; - - - /*******************************************************************/ - /* */ - /* Saturation tables */ - /* */ - /*******************************************************************/ - - typedef struct grSaturation_ - { - int count; - const byte* table; - - } grSaturation; - - - static - const byte gr_saturation_5[8] = { 0, 1, 2, 3, 4, 4, 4, 4 }; - - - static - const byte gr_saturation_17[32] = - { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - }; - - - static - grSaturation gr_saturations[ GR_MAX_SATURATIONS ] = - { - { 5, gr_saturation_5 }, - { 17, gr_saturation_17 } - }; - - static - int gr_num_saturations = 2; - - static - grSaturation* gr_last_saturation = gr_saturations; - - - extern - const byte* grGetSaturation( int num_grays ) - { - /* first of all, scan the current saturations table */ - grSaturation* sat = gr_saturations; - grSaturation* limit = sat + gr_num_saturations; - - if ( num_grays < 2 ) - { - grError = gr_err_bad_argument; - return 0; - } - - for ( ; sat < limit; sat++ ) - { - if ( sat->count == num_grays ) - { - gr_last_saturation = sat; - return sat->table; - } - } - - /* not found, simply create a new entry if there is room */ - if (gr_num_saturations < GR_MAX_SATURATIONS) - { - int i; - const byte* table; - - table = (const byte*)grAlloc( (3*num_grays-1)*sizeof(byte) ); - if (!table) return 0; - - sat->count = num_grays; - sat->table = table; - - for ( i = 0; i < num_grays; i++, table++ ) - *(unsigned char*)table = (unsigned char)i; - - for ( i = 2*num_grays-1; i > 0; i--, table++ ) - *(unsigned char*)table = (unsigned char)(num_grays-1); - - gr_num_saturations++; - gr_last_saturation = sat; - return sat->table; - } - grError = gr_err_saturation_overflow; - return 0; - } - - - - /*******************************************************************/ - /* */ - /* conversion tables */ - /* */ - /*******************************************************************/ - - typedef struct grConversion_ - { - int target_grays; - int source_grays; - const byte* table; - - } grConversion; - - - - static - const byte gr_gray5_to_gray17[5] = { 0, 4, 8, 12, 16 }; - - - static - const byte gr_gray5_to_gray128[5] = { 0, 32, 64, 96, 127 }; - - - static - const unsigned char gr_gray17_to_gray128[17] = - { - 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 127 - }; - - static - grConversion gr_conversions[ GR_MAX_CONVERSIONS ] = - { - { 17, 5, gr_gray5_to_gray17 }, - { 128, 5, gr_gray5_to_gray128 }, - { 128, 17, gr_gray17_to_gray128 } - }; - - static - int gr_num_conversions = 3; - - static - grConversion* gr_last_conversion = gr_conversions; - - - extern - const byte* grGetConversion( int target_grays, - int source_grays ) - { - grConversion* conv = gr_conversions; - grConversion* limit = conv + gr_num_conversions; - - if ( target_grays < 2 || source_grays < 2 ) - { - grError = gr_err_bad_argument; - return 0; - } - - /* otherwise, scan table */ - for ( ; conv < limit; conv++ ) - { - if ( conv->target_grays == target_grays && - conv->source_grays == source_grays ) - { - gr_last_conversion = conv; - return conv->table; - } - } - - /* not found, add a new conversion to the table */ - if (gr_num_conversions < GR_MAX_CONVERSIONS) - { - const byte* table; - int n; - - table = (const byte*)grAlloc( source_grays*sizeof(byte) ); - if (!table) - return 0; - - conv->target_grays = target_grays; - conv->source_grays = source_grays; - conv->table = table; - - for ( n = 0; n < source_grays; n++ ) - ((unsigned char*)table)[n] = (unsigned char)(n*(target_grays-1)) / - (source_grays-1); - - gr_num_conversions++; - gr_last_conversion = conv; - return table; - } - grError = gr_err_conversion_overflow; - return 0; - } - - - - -/**************************************************************************/ -/* */ -/* blit_gray_to_gray */ -/* */ -/**************************************************************************/ - - static - void blit_gray_to_gray( grBlitter* blit, - const byte* saturation, - const byte* conversion ) - { - int y; - unsigned char* read; - unsigned char* write; - unsigned char max1; - unsigned char max2; - - max1 = (unsigned char)(blit->source.grays-1); - max2 = (unsigned char)(blit->target.grays-1); - - read = (unsigned char*)blit->read + blit->xread; - write = (unsigned char*)blit->write + blit->xwrite; - - y = blit->height; - do - { - unsigned char* _read = read; - unsigned char* _write = write; - int x = blit->width; - - while (x > 0) - { -#ifdef GR_CONFIG_GRAY_SKIP_WHITE - unsigned char val = *_read; - - if (val) - { - if (val == max) - *_write = max2; - else - *_write = saturation[ (int)*_write + conversion[ *_read ] ]; - } -#else - *_write = saturation[ (int)*_write + conversion[ *_read ] ]; -#endif - _write++; - _read++; - x--; - } - - read += blit->read_line; - write += blit->write_line; - y--; - } - while (y > 0); - } - - -/**************************************************************************/ -/* */ -/* blit_gray_to_gray_simple */ -/* */ -/**************************************************************************/ - - static - void blit_gray_to_gray_simple( grBlitter* blit, - const byte* saturation ) - { - int y; - unsigned char* read; - unsigned char* write; - unsigned char max; - - max = (unsigned char)(blit->source.grays-1); - - read = (unsigned char*)blit->read + blit->xread; - write = (unsigned char*)blit->write + blit->xwrite; - - y = blit->height; - do - { - unsigned char* _read = read; - unsigned char* _write = write; - int x = blit->width; - - while (x > 0) - { -#ifdef GR_CONFIG_GRAY_SKIP_WHITE - unsigned char val = *_read; - - if (val) - { - if (val == max) - *_write = val; - else - *_write = saturation[ (int)*_write + *_read ]; - } -#else - *_write = saturation[ (int)*_write + *_read ]; -#endif - _write++; - _read++; - x--; - } - - read += blit->read_line; - write += blit->write_line; - y--; - } - while (y > 0); - } - - - -#define compose_pixel( a, b, n, max ) \ - { \ - int d, half = max >> 1; \ - \ - d = (int)b.chroma[0] - a.chroma[0]; \ - a.chroma[0] += (n*d + half)/max; \ - \ - d = (int)b.chroma[1] - a.chroma[1]; \ - a.chroma[1] += (n*d + half)/max; \ - \ - d = (int)b.chroma[2] - a.chroma[2]; \ - a.chroma[2] += (n*d + half)/max; \ - } - - -#define extract555( pixel, color ) \ - color.chroma[0] = (pixel >> 10) & 0x1F; \ - color.chroma[1] = (pixel >> 5) & 0x1F; \ - color.chroma[2] = (pixel ) & 0x1F; - - -#define extract565( pixel, color ) \ - color.chroma[0] = (pixel >> 11) & 0x1F; \ - color.chroma[1] = (pixel >> 5) & 0x3F; \ - color.chroma[2] = (pixel ) & 0x1F; - - -#define inject555( color ) \ - ( ( (unsigned short)color.chroma[0] << 10 ) | \ - ( (unsigned short)color.chroma[1] << 5 ) | \ - color.chroma[2] ) - - -#define inject565( color ) \ - ( ( (unsigned short)color.chroma[0] << 11 ) | \ - ( (unsigned short)color.chroma[1] << 5 ) | \ - color.chroma[2] ) - - -/**************************************************************************/ -/* */ -/* blit_gray_to_555 */ -/* */ -/**************************************************************************/ - - static - void blit_gray_to_555( grBlitter* blit, - grColor color, - int max ) - { - int y; - unsigned char* read; - unsigned char* write; - long color2; - - read = blit->read + blit->xread; - write = blit->write + 2*blit->xwrite; - - /* convert color to R:G:B triplet */ - color2 = color.value; - extract555( color2, color ); - - y = blit->height; - do - { - unsigned char* _read = read; - unsigned char* _write = write; - int x = blit->width; - - while (x > 0) - { - unsigned char val; - - val = *_read; - if (val) - { - unsigned short* pixel = (unsigned short*)_write; - - if (val == max) - { - pixel[0] = (short)color2; - } - else - { - /* compose gray value */ - unsigned short pix16 = *pixel; - grColor pix; - - extract555( pix16, pix ); - - compose_pixel( pix, color, val, max ); - *pixel = inject555(pix); - } - } - _write += 2; - _read ++; - x--; - } - - read += blit->read_line; - write += blit->write_line; - y--; - } - while (y > 0); - } - - -/**************************************************************************/ -/* */ -/* blit_gray_to_565 */ -/* */ -/**************************************************************************/ - - static - void blit_gray_to_565( grBlitter* blit, - grColor color, - int max ) - { - int y; - unsigned char* read; - unsigned char* write; - long color2; - - read = blit->read + blit->xread; - write = blit->write + 2*blit->xwrite; - - color2 = color.value; - extract565( color2, color ); - - y = blit->height; - do - { - unsigned char* _read = read; - unsigned char* _write = write; - int x = blit->width; - - while (x > 0) - { - unsigned char val; - - val = *_read; - if (val) - { - unsigned short* pixel = (unsigned short*)_write; - - if (val == max) - { - pixel[0] = (short)color2; - } - else - { - /* compose gray value */ - unsigned short pix16 = *pixel; - grColor pix; - - extract565( pix16, pix ); - - compose_pixel( pix, color, val, max ); - *pixel = inject565( pix ); - } - } - _write +=2; - _read ++; - x--; - } - - read += blit->read_line; - write += blit->write_line; - y--; - } - while (y > 0); - } - - -/**************************************************************************/ -/* */ -/* blit_gray_to_24 */ -/* */ -/**************************************************************************/ - - static - void blit_gray_to_24( grBlitter* blit, - grColor color, - int max ) - { - int y; - unsigned char* read; - unsigned char* write; - - read = blit->read + blit->xread; - write = blit->write + 3*blit->xwrite; - - y = blit->height; - do - { - unsigned char* _read = read; - unsigned char* _write = write; - int x = blit->width; - - while (x > 0) - { - unsigned char val; - - val = *_read; - if (val) - { - if (val == max) - { - _write[0] = color.chroma[0]; - _write[1] = color.chroma[1]; - _write[2] = color.chroma[2]; - } - else - { - /* compose gray value */ - grColor pix; - - pix.chroma[0] = _write[0]; - pix.chroma[1] = _write[1]; - pix.chroma[2] = _write[2]; - - compose_pixel( pix, color, val, max ); - - _write[0] = pix.chroma[0]; - _write[1] = pix.chroma[1]; - _write[2] = pix.chroma[2]; - } - } - _write += 3; - _read ++; - x--; - } - - read += blit->read_line; - write += blit->write_line; - y--; - } - while (y > 0); - } - - -/**************************************************************************/ -/* */ -/* blit_gray_to_32 */ -/* */ -/**************************************************************************/ - - static - void blit_gray_to_32( grBlitter* blit, - grColor color, - int max ) - { - int y; - unsigned char* read; - unsigned char* write; - - read = blit->read + blit->xread; - write = blit->write + 4*blit->xwrite; - - y = blit->height; - do - { - unsigned char* _read = read; - unsigned char* _write = write; - int x = blit->width; - - while (x > 0) - { - unsigned char val; - - val = *_read; - if (val) - { - if (val == max) - { - _write[0] = color.chroma[0]; - _write[1] = color.chroma[1]; - _write[2] = color.chroma[2]; - _write[3] = color.chroma[3]; - } - else - { - /* compose gray value */ - grColor pix; - - pix.chroma[0] = _write[0]; - pix.chroma[1] = _write[1]; - pix.chroma[2] = _write[2]; - - compose_pixel( pix, color, val, max ); - - _write[0] = pix.chroma[0]; - _write[1] = pix.chroma[1]; - _write[2] = pix.chroma[2]; - } - } - _write += 4; - _read ++; - x--; - } - - read += blit->read_line; - write += blit->write_line; - y--; - } - while (y > 0); - } - - - /********************************************************************** - * - * - * grBlitGlyphBitmap - * - * - * writes a given glyph bitmap to a target surface. - * - * - * surface :: handle to target surface - * x :: position of left-most pixel of glyph image in surface - * y :: position of top-most pixel of glyph image in surface - * bitmap :: source glyph image - * - * - * Error code. 0 means success - * - **********************************************************************/ - - typedef void (*grColorGlyphBlitter)( grBlitter* blit, - grColor color, - int max_gray ); - - static - const grColorGlyphBlitter gr_color_blitters[gr_pixel_mode_max] = - { - 0, - 0, - 0, - 0, - blit_gray_to_555, - blit_gray_to_565, - blit_gray_to_24, - blit_gray_to_32 - }; - - - extern int grBlitGlyphToBitmap( grBitmap* target, - grBitmap* glyph, - grPos x, - grPos y, - grColor color ) - { - grBlitter blit; - grPixelMode mode; - - /* check arguments */ - if (!target || !glyph) - { - grError = gr_err_bad_argument; - return -1; - } - - - /* set up blitter and compute clipping. Return immediately if needed */ - blit.source = *glyph; - blit.target = *target; - mode = target->mode; - - if ( compute_clips( &blit, x, y ) ) - return 0; - - - /* handle monochrome bitmap blitting */ - if (glyph->mode == gr_pixel_mode_mono) - { - if ( mode <= gr_pixel_mode_none || mode >= gr_pixel_mode_max ) - { - grError = gr_err_bad_source_depth; - return -1; - } - - gr_mono_blitters[mode]( &blit, color ); - goto End; - } - - /* handle gray bitmap composition */ - if (glyph->mode == gr_pixel_mode_gray && - glyph->grays > 1 ) - { - int target_grays = target->grays; - int source_grays = glyph->grays; - const byte* saturation; - - if ( mode == gr_pixel_mode_gray && target_grays > 1 ) - { - /* rendering into a gray target - use special composition */ - /* routines.. */ - if ( gr_last_saturation->count == target_grays ) - saturation = gr_last_saturation->table; - else - { - saturation = grGetSaturation( target_grays ); - if (!saturation) return -3; - } - - - if ( target_grays == source_grays ) - blit_gray_to_gray_simple( &blit, saturation ); - else - { - const byte* conversion; - - if ( gr_last_conversion->target_grays == target_grays && - gr_last_conversion->source_grays == source_grays ) - conversion = gr_last_conversion->table; - else - { - conversion = grGetConversion( target_grays, source_grays ); - if (!conversion) return -3; - }; - - blit_gray_to_gray( &blit, saturation, conversion ); - } - } - else - { - /* rendering into a color target */ - if ( mode <= gr_pixel_mode_gray || - mode >= gr_pixel_mode_max ) - { - grError = gr_err_bad_target_depth; - return -1; - } - - gr_color_blitters[mode]( &blit, color, source_grays-1 ); - } - goto End; - } - - /* we don't support the blitting of bitmaps of the following */ - /* types : pal4, pal8, rgb555, rgb565, rgb24, rgb32 */ - /* */ - grError = gr_err_bad_source_depth; - return -2; - - End: - return 0; - } - - -/* End */ diff --git a/demos/graph/grblit.h b/demos/graph/grblit.h deleted file mode 100644 index 4d0b6e5a8..000000000 --- a/demos/graph/grblit.h +++ /dev/null @@ -1,25 +0,0 @@ -/****************************************************************************/ -/* */ -/* The FreeType project -- a free and portable quality TrueType renderer. */ -/* */ -/* Copyright 1996-1999 by */ -/* D. Turner, R.Wilhelm, and W. Lemberg */ -/* */ -/* blitter.h: Support for blitting of bitmaps with various depth. */ -/* */ -/****************************************************************************/ - -#ifndef GRBLIT_H -#define GRBLIT_H - -#include "grobjs.h" - - int grBlitMono( grBitmap* target, - grBitmap* source, - int x_offset, - int y_offset, - grColor color ); - - -#endif /* GRBLIT_H */ -/* End */ diff --git a/demos/graph/grconfig.h b/demos/graph/grconfig.h deleted file mode 100644 index 02d8f4dfb..000000000 --- a/demos/graph/grconfig.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef GRCONFIG_H -#define GRCONFIG_H - -#define GR_MAX_SATURATIONS 8 -#define GR_MAX_CONVERSIONS 16 - -#define GR_MAX_DEVICES 8 - -#endif /* GRCONFIG_H */ diff --git a/demos/graph/grdevice.c b/demos/graph/grdevice.c deleted file mode 100644 index 901f4e272..000000000 --- a/demos/graph/grdevice.c +++ /dev/null @@ -1,362 +0,0 @@ -#include "grobjs.h" -#include "grdevice.h" -#include -#include - - grDeviceChain gr_device_chain[ GR_MAX_DEVICES ]; - int gr_num_devices = 0; - - static - grDevice* find_device( const char* device_name ) - { - int index = 0; - - if (device_name) - { - for ( index = gr_num_devices-1; index > 0; index-- ) - if ( strcmp( device_name, gr_device_chain[index].name ) == 0 ) - break; - } - - if ( index < 0 || gr_num_devices <= 0 || !gr_device_chain[index].device ) - { - grError = gr_err_invalid_device; - return 0; - } - - return gr_device_chain[index].device; - } - - - - /********************************************************************** - * - * - * grGetDeviceModes - * - * - * queries the available pixel modes for a device. - * - * - * device_name :: name of device to be used. 0 for the default - * device. For a list of available devices, see - * grInitDevices. - * - * - * num_modes :: number of available modes. 0 in case of error, - * which really is an invalid device name. - * - * pixel_modes :: array of available pixel modes for this device - * this table is internal to the device and should - * not be freed by client applications. - * - * - * error code. 0 means success. invalid device name otherwise - * - * - * All drivers are _required_ to support at least the following - * pixel formats : - * - * - gr_pixel_mode_mono : i.e. monochrome bitmaps - * - gr_pixel_mode_gray : with any number of gray levels between - * 2 and 256. - * - * the pixel modes do not provide the number of grays in the case - * of "gray" devices. You should try to create a surface with the - * maximal number (256, that is) and see the value returned in - * the bitmap descriptor. - * - **********************************************************************/ - - extern void grGetDeviceModes( const char* device_name, - int *num_modes, - grPixelMode* *pixel_modes ) - { - grDevice* device; - - *num_modes = 0; - *pixel_modes = 0; - - device = find_device( device_name ); - if (device) - { - *num_modes = device->num_pixel_modes; - *pixel_modes = device->pixel_modes; - } - } - - - /********************************************************************** - * - * - * grNewSurface - * - * - * creates a new device-specific surface. A surface is either - * a window or a screen, depending on the device. - * - * - * device :: name of the device to use. A value of NULL means - * the default device (which depends on the system). - * for a list of available devices, see grInitDevices. - * - * - * bitmap :: handle to a bitmap descriptor containing the - * requested pixel mode, number of grays and dimensions - * for the surface. the bitmap's 'pitch' and 'buffer' - * fields are ignored on input. - * - * On output, the bitmap describes the surface's image - * completely. It is possible to write directly in it - * with grBlitGlyphToBitmap, even though the use of - * grBlitGlyphToSurface is recommended. - * - * - * handle to the corresponding surface object. 0 in case of error - * - * - * All drivers are _required_ to support at least the following - * pixel formats : - * - * - gr_pixel_mode_mono : i.e. monochrome bitmaps - * - gr_pixel_mode_gray : with any number of gray levels between - * 2 and 256. - * - * This function might change the bitmap descriptor's fields. For - * example, when displaying a full-screen surface, the bitmap's - * dimensions will be set to those of the screen (e.g. 640x480 - * or 800x600); also, the bitmap's 'buffer' field might point to - * the Video Ram depending on the mode requested.. - * - * The surface contains a copy of the returned bitmap descriptor, - * you can thus discard the 'bitmap' parameter after the call. - * - **********************************************************************/ - - extern grSurface* grNewSurface( const char* device_name, - grBitmap* bitmap ) - { - grDevice* device; - grSurface* surface; - - /* Now find the device */ - device = find_device( device_name ); - if (!device) return 0; - - surface = (grSurface*)grAlloc( device->surface_objsize ); - if (!surface) return 0; - - if ( !device->init_surface( surface, bitmap ) ) - { - grFree( surface ); - surface = 0; - } - return surface; - } - - - /********************************************************************** - * - * - * grRefreshRectangle - * - * - * this function is used to indicate that a given surface rectangle - * was modified and thus needs re-painting. It really is useful for - * windowed or gray surfaces. - * - * - * surface :: handle to target surface - * x :: x coordinate of the top-left corner of the rectangle - * y :: y coordinate of the top-left corner of the rectangle - * width :: rectangle width in pixels - * height :: rectangle height in pixels - * - **********************************************************************/ - - extern void grRefreshRectangle( grSurface* surface, - grPos x, - grPos y, - grPos width, - grPos height ) - { - if (surface->refresh_rect) - surface->refresh_rect( surface, x, y, width, height ); - } - - - - /********************************************************************** - * - * - * grWriteSurfaceChar - * - * - * This function is equivalent to calling grWriteCellChar on the - * surface's bitmap, then invoking grRefreshRectangle. - * - * The graphics sub-system contains an internal Latin1 8x8 font - * which can be used to display simple strings of text without - * using FreeType. - * - * This function writes a single 8x8 character on the target bitmap. - * - * - * target :: handle to target surface - * x :: x pixel position of character cell's top left corner - * y :: y pixel position of character cell's top left corner - * charcode :: Latin-1 character code - * color :: color to be used to draw the character - * - **********************************************************************/ - - extern - void grWriteSurfaceChar( grSurface* target, - int x, - int y, - int charcode, - grColor color ) - { - grWriteCellChar( &target->bitmap, x, y, charcode, color ); - if (target->refresh_rect) - target->refresh_rect( target, x, y, 8, 8 ); - } - - - /********************************************************************** - * - * - * grWriteSurfaceString - * - * - * This function is equivalent to calling grWriteCellString on the - * surface's bitmap, then invoking grRefreshRectangle. - * - * The graphics sub-system contains an internal Latin1 8x8 font - * which can be used to display simple strings of text without - * using FreeType. - * - * This function writes a string with the internal font - * - * - * target :: handle to target bitmap - * x :: x pixel position of string's top left corner - * y :: y pixel position of string's top left corner - * string :: Latin-1 text string - * color :: color to be used to draw the character - * - **********************************************************************/ - - extern - void grWriteSurfaceString( grSurface* target, - int x, - int y, - const char* string, - grColor color ) - { - int len; - - len = strlen(string); - grWriteCellString( &target->bitmap, x, y, string, color ); - if (target->refresh_rect) - target->refresh_rect( target, x, y, 8*len, 8 ); - } - - - /********************************************************************** - * - * - * grRefreshSurface - * - * - * a variation of grRefreshRectangle which repaints the whole surface - * to the screen. - * - * - * surface :: handle to target surface - * - **********************************************************************/ - - extern void grRefreshSurface( grSurface* surface ) - { - if (surface->refresh_rect) - surface->refresh_rect( surface, 0, 0, - surface->bitmap.width, - surface->bitmap.rows ); - } - - - - /********************************************************************** - * - * - * grSetTitle - * - * - * set the window title of a given windowed surface. - * - * - * surface :: handle to target surface - * title_string :: the new title - * - **********************************************************************/ - - extern void grSetTitle( grSurface* surface, - const char* title_string ) - { - if (surface->set_title) - surface->set_title( surface, title_string ); - } - - - - - /********************************************************************** - * - * - * grListenSurface - * - * - * listen the events for a given surface - * - * - * surface :: handle to target surface - * event_mask :: the event mask (mode) - * - * - * event :: the returned event - * - * - * XXX : For now, only keypresses are supported. - * - **********************************************************************/ - - extern - int grListenSurface( grSurface* surface, - int event_mask, - grEvent *event ) - { - return surface->listen_event( surface, event_mask, event ); - } - - -#if 0 - static - void gr_done_surface( grSurface* surface ) - { - if (surface) - { - /* first of all, call the device-specific destructor */ - surface->done(surface); - - /* then remove the bitmap if we're owner */ - if (surface->owner) - grFree( surface->bitmap.buffer ); - - surface->owner = 0; - surface->bitmap.buffer = 0; - grFree( surface ); - } - } -#endif - diff --git a/demos/graph/grdevice.h b/demos/graph/grdevice.h deleted file mode 100644 index 9ffea163f..000000000 --- a/demos/graph/grdevice.h +++ /dev/null @@ -1,126 +0,0 @@ -/*************************************************************************** - * - * grdevice.h - * - * Graphics device interface - * - * Copyright 1999 - The FreeType Development Team - www.freetype.org - * - * - ***************************************************************************/ - -#ifndef GRDEVICE_H -#define GRDEVICE_H - -#include "graph.h" - - - /******************************************************************** - * - * - * grDeviceInitFunc - * - * - * Simple device initialiser function - * - * - * error code. 0 means success - * - ********************************************************************/ - - typedef int (*grDeviceInitFunc)( void ); - - - /******************************************************************** - * - * - * grDeviceDoneFunc - * - * - * Simple device finaliser function - * - * - * error code. 0 means success - * - ********************************************************************/ - - typedef void (*grDeviceDoneFunc)( void ); - - - /******************************************************************** - * - * - * grDeviceInitSurfaceFunc - * - * - * initializes a new surface for the device. This may be a window - * or a video screen, depending on the device. - * - * - * surface :: handle to target surface - * - * - * bitmap :: handle to bitmap descriptor - * - ********************************************************************/ - - typedef int (*grDeviceInitSurfaceFunc)( grSurface* surface, - grBitmap* bitmap ); - - - /******************************************************************** - * - * - * grDevice - * - * - * Simple device interface structure - * - * - * surface_objsize :: size in bytes of a single surface object for - * this device. - * - * device_name :: name of device, e.g. "x11", "os2pm", "directx" etc.. - * init :: device initialisation routine - * done :: device finalisation - * new_surface :: function used to create a new surface (screen or - * window) from the device - * - * num_pixel_modes :: the number of pixel modes supported by this - * device. This value _must_ be set to -1 - * default, unless the device provides a - * static set of pixel modes (fullscreen). - * - * pixel_modes :: an array of pixel modes supported by this - * device - * - * - * the fields "num_pixel_modes" and "pixel_modes" must be - * set by the "init" function. - * - * This allows windowed devices to "discover" at run-time the - * available pixel modes they can provide depending on the - * current screen depth. - * - ********************************************************************/ - - struct grDevice_ - { - int surface_objsize; - const char* device_name; /* name of device */ - - grDeviceInitFunc init; - grDeviceDoneFunc done; - - grDeviceInitSurfaceFunc init_surface; - - int num_pixel_modes; - grPixelMode* pixel_modes; - }; - - - extern grDeviceChain gr_device_chain[]; - extern int gr_num_devices; - - -#endif /* GRDEVICE_H */ diff --git a/demos/graph/grevents.h b/demos/graph/grevents.h deleted file mode 100644 index 36dd52d1d..000000000 --- a/demos/graph/grevents.h +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef GREVENTS_H -#define GREVENTS_H - - -#define gr_event_none 0 -#define gr_event_wait 1 -#define gr_event_poll 2 -#define gr_event_flush 3 - -#define gr_mouse_down 0x04 -#define gr_mouse_move 0x08 -#define gr_mouse_up 0x10 -#define gr_mouse_drag 0x20 - -#define gr_key_down 0x40 -#define gr_key_up 0x80 - - -#define gr_event_mouse 0x3C -#define gr_event_key 0xC0 - -#define gr_event_type (gr_event_mouse | gr_event_key) - - - typedef enum grKey_ - { - grKeyNone = 0, - - grKeyF1, - grKeyF2, - grKeyF3, - grKeyF4, - grKeyF5, - grKeyF6, - grKeyF7, - grKeyF8, - grKeyF9, - grKeyF10, - grKeyF11, - grKeyF12, - - grKeyLeft, - grKeyRight, - grKeyUp, - grKeyDown, - - grKeyIns, - grKeyDel, - grKeyHome, - grKeyEnd, - grKeyPageUp, - grKeyPageDown, - - grKeyEsc, - grKeyTab, - grKeyBackSpace, - grKeyReturn, - - grKeyMax, - grKeyForceShort = 0x7FFF /* this forces the grKey to be stored */ - /* on at least one short ! */ - - } grKey; - -#define grKEY(c) ((grKey)(c)) - -#define grKeyAlt ((grKey)0x8000) -#define grKeyCtrl ((grKey)0x4000) -#define grKeyShift ((grKey)0x2000) - -#define grKeyModifiers ((grKey)0xE000) - -#define grKey0 grKEY('0') -#define grKey1 grKEY('1') -#define grKey2 grKEY('2') -#define grKey3 grKEY('3') -#define grKey4 grKEY('4') -#define grKey5 grKEY('5') -#define grKey6 grKEY('6') -#define grKey7 grKEY('7') -#define grKey8 grKEY('8') -#define grKey9 grKEY('9') - - -#define grKeyPlus grKEY('+') -#define grKeyLess grKEY('-') -#define grKeyEqual grKEY('=') -#define grKeyMult grKEY('*') -#define grKeyDollar grKEY('$') -#define grKeySmaller grKEY('<') -#define grKeyGreater grKEY('>') -#define grKeyQuestion grKEY('?') -#define grKeyComma grKEY(',') -#define grKeyDot grKEY('.') -#define grKeySemiColumn grKEY(';') -#define grKeyColumn grKEY(':') -#define grKeyDiv grKEY('/') -#define grKeyExclam grKEY('!') -#define grKeyPercent grKEY('%') -#define grKeyLeftParen grKEY('(') -#define grKeyRightParen grKEY('(') -#define grKeyAt grKEY('@') -#define grKeyUnder grKEY('_') - - - typedef struct grEvent_ - { - int type; - grKey key; - int x, y; - - } grEvent; - - - -#endif /* GREVENTS_H */ - diff --git a/demos/graph/grfont.c b/demos/graph/grfont.c deleted file mode 100644 index 99024231a..000000000 --- a/demos/graph/grfont.c +++ /dev/null @@ -1,358 +0,0 @@ -#include "grfont.h" -#include - - /* font characters */ - - const unsigned char font_8x8[2048] = - { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x99, 0x81, 0x7E, - 0x7E, 0xFF, 0xDB, 0xFF, 0xC3, 0xE7, 0xFF, 0x7E, - 0x6C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38, 0x10, 0x00, - 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x10, 0x00, - 0x38, 0x7C, 0x38, 0xFE, 0xFE, 0x92, 0x10, 0x7C, - 0x00, 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x7C, - 0x00, 0x00, 0x18, 0x3C, 0x3C, 0x18, 0x00, 0x00, - 0xFF, 0xFF, 0xE7, 0xC3, 0xC3, 0xE7, 0xFF, 0xFF, - 0x00, 0x3C, 0x66, 0x42, 0x42, 0x66, 0x3C, 0x00, - 0xFF, 0xC3, 0x99, 0xBD, 0xBD, 0x99, 0xC3, 0xFF, - 0x0F, 0x07, 0x0F, 0x7D, 0xCC, 0xCC, 0xCC, 0x78, - 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18, - 0x3F, 0x33, 0x3F, 0x30, 0x30, 0x70, 0xF0, 0xE0, - 0x7F, 0x63, 0x7F, 0x63, 0x63, 0x67, 0xE6, 0xC0, - 0x99, 0x5A, 0x3C, 0xE7, 0xE7, 0x3C, 0x5A, 0x99, - 0x80, 0xE0, 0xF8, 0xFE, 0xF8, 0xE0, 0x80, 0x00, - 0x02, 0x0E, 0x3E, 0xFE, 0x3E, 0x0E, 0x02, 0x00, - 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x7E, 0x3C, 0x18, - 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00, - 0x7F, 0xDB, 0xDB, 0x7B, 0x1B, 0x1B, 0x1B, 0x00, - 0x3E, 0x63, 0x38, 0x6C, 0x6C, 0x38, 0x86, 0xFC, - 0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x7E, 0x00, - 0x18, 0x3C, 0x7E, 0x18, 0x7E, 0x3C, 0x18, 0xFF, - 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x00, - 0x18, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00, - 0x00, 0x18, 0x0C, 0xFE, 0x0C, 0x18, 0x00, 0x00, - 0x00, 0x30, 0x60, 0xFE, 0x60, 0x30, 0x00, 0x00, - 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xFE, 0x00, 0x00, - 0x00, 0x24, 0x66, 0xFF, 0x66, 0x24, 0x00, 0x00, - 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x00, 0x00, - 0x00, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00, - 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x6C, 0x6C, 0xFE, 0x6C, 0xFE, 0x6C, 0x6C, 0x00, - 0x18, 0x7E, 0xC0, 0x7C, 0x06, 0xFC, 0x18, 0x00, - 0x00, 0xC6, 0xCC, 0x18, 0x30, 0x66, 0xC6, 0x00, - 0x38, 0x6C, 0x38, 0x76, 0xDC, 0xCC, 0x76, 0x00, - 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x18, 0x30, 0x60, 0x60, 0x60, 0x30, 0x18, 0x00, - 0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00, - 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00, - 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, - 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, - 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x80, 0x00, - 0x7C, 0xCE, 0xDE, 0xF6, 0xE6, 0xC6, 0x7C, 0x00, - 0x30, 0x70, 0x30, 0x30, 0x30, 0x30, 0xFC, 0x00, - 0x78, 0xCC, 0x0C, 0x38, 0x60, 0xCC, 0xFC, 0x00, - 0x78, 0xCC, 0x0C, 0x38, 0x0C, 0xCC, 0x78, 0x00, - 0x1C, 0x3C, 0x6C, 0xCC, 0xFE, 0x0C, 0x1E, 0x00, - 0xFC, 0xC0, 0xF8, 0x0C, 0x0C, 0xCC, 0x78, 0x00, - 0x38, 0x60, 0xC0, 0xF8, 0xCC, 0xCC, 0x78, 0x00, - 0xFC, 0xCC, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x00, - 0x78, 0xCC, 0xCC, 0x78, 0xCC, 0xCC, 0x78, 0x00, - 0x78, 0xCC, 0xCC, 0x7C, 0x0C, 0x18, 0x70, 0x00, - 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, - 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x30, - 0x18, 0x30, 0x60, 0xC0, 0x60, 0x30, 0x18, 0x00, - 0x00, 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x00, 0x00, - 0x60, 0x30, 0x18, 0x0C, 0x18, 0x30, 0x60, 0x00, - 0x3C, 0x66, 0x0C, 0x18, 0x18, 0x00, 0x18, 0x00, - 0x7C, 0xC6, 0xDE, 0xDE, 0xDC, 0xC0, 0x7C, 0x00, - 0x30, 0x78, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0x00, - 0xFC, 0x66, 0x66, 0x7C, 0x66, 0x66, 0xFC, 0x00, - 0x3C, 0x66, 0xC0, 0xC0, 0xC0, 0x66, 0x3C, 0x00, - 0xF8, 0x6C, 0x66, 0x66, 0x66, 0x6C, 0xF8, 0x00, - 0xFE, 0x62, 0x68, 0x78, 0x68, 0x62, 0xFE, 0x00, - 0xFE, 0x62, 0x68, 0x78, 0x68, 0x60, 0xF0, 0x00, - 0x3C, 0x66, 0xC0, 0xC0, 0xCE, 0x66, 0x3A, 0x00, - 0xCC, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0xCC, 0x00, - 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, - 0x1E, 0x0C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, 0x00, - 0xE6, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0xE6, 0x00, - 0xF0, 0x60, 0x60, 0x60, 0x62, 0x66, 0xFE, 0x00, - 0xC6, 0xEE, 0xFE, 0xFE, 0xD6, 0xC6, 0xC6, 0x00, - 0xC6, 0xE6, 0xF6, 0xDE, 0xCE, 0xC6, 0xC6, 0x00, - 0x38, 0x6C, 0xC6, 0xC6, 0xC6, 0x6C, 0x38, 0x00, - 0xFC, 0x66, 0x66, 0x7C, 0x60, 0x60, 0xF0, 0x00, - 0x7C, 0xC6, 0xC6, 0xC6, 0xD6, 0x7C, 0x0E, 0x00, - 0xFC, 0x66, 0x66, 0x7C, 0x6C, 0x66, 0xE6, 0x00, - 0x7C, 0xC6, 0xE0, 0x78, 0x0E, 0xC6, 0x7C, 0x00, - 0xFC, 0xB4, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, - 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xFC, 0x00, - 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00, - 0xC6, 0xC6, 0xC6, 0xC6, 0xD6, 0xFE, 0x6C, 0x00, - 0xC6, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0xC6, 0x00, - 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x30, 0x78, 0x00, - 0xFE, 0xC6, 0x8C, 0x18, 0x32, 0x66, 0xFE, 0x00, - 0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x00, - 0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x02, 0x00, - 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00, - 0x10, 0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, - 0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, - 0xE0, 0x60, 0x60, 0x7C, 0x66, 0x66, 0xDC, 0x00, - 0x00, 0x00, 0x78, 0xCC, 0xC0, 0xCC, 0x78, 0x00, - 0x1C, 0x0C, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00, - 0x00, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, - 0x38, 0x6C, 0x64, 0xF0, 0x60, 0x60, 0xF0, 0x00, - 0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, - 0xE0, 0x60, 0x6C, 0x76, 0x66, 0x66, 0xE6, 0x00, - 0x30, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, - 0x0C, 0x00, 0x1C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, - 0xE0, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0xE6, 0x00, - 0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, - 0x00, 0x00, 0xCC, 0xFE, 0xFE, 0xD6, 0xD6, 0x00, - 0x00, 0x00, 0xB8, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, - 0x00, 0x00, 0x78, 0xCC, 0xCC, 0xCC, 0x78, 0x00, - 0x00, 0x00, 0xDC, 0x66, 0x66, 0x7C, 0x60, 0xF0, - 0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0x1E, - 0x00, 0x00, 0xDC, 0x76, 0x62, 0x60, 0xF0, 0x00, - 0x00, 0x00, 0x7C, 0xC0, 0x70, 0x1C, 0xF8, 0x00, - 0x10, 0x30, 0xFC, 0x30, 0x30, 0x34, 0x18, 0x00, - 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, - 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00, - 0x00, 0x00, 0xC6, 0xC6, 0xD6, 0xFE, 0x6C, 0x00, - 0x00, 0x00, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0x00, - 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, - 0x00, 0x00, 0xFC, 0x98, 0x30, 0x64, 0xFC, 0x00, - 0x1C, 0x30, 0x30, 0xE0, 0x30, 0x30, 0x1C, 0x00, - 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00, - 0xE0, 0x30, 0x30, 0x1C, 0x30, 0x30, 0xE0, 0x00, - 0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0x00, - 0x7C, 0xC6, 0xC0, 0xC6, 0x7C, 0x0C, 0x06, 0x7C, - 0x00, 0xCC, 0x00, 0xCC, 0xCC, 0xCC, 0x76, 0x00, - 0x1C, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, - 0x7E, 0x81, 0x3C, 0x06, 0x3E, 0x66, 0x3B, 0x00, - 0xCC, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, - 0xE0, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, - 0x30, 0x30, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, - 0x00, 0x00, 0x7C, 0xC6, 0xC0, 0x78, 0x0C, 0x38, - 0x7E, 0x81, 0x3C, 0x66, 0x7E, 0x60, 0x3C, 0x00, - 0xCC, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, - 0xE0, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, - 0xCC, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, - 0x7C, 0x82, 0x38, 0x18, 0x18, 0x18, 0x3C, 0x00, - 0xE0, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, - 0xC6, 0x10, 0x7C, 0xC6, 0xFE, 0xC6, 0xC6, 0x00, - 0x30, 0x30, 0x00, 0x78, 0xCC, 0xFC, 0xCC, 0x00, - 0x1C, 0x00, 0xFC, 0x60, 0x78, 0x60, 0xFC, 0x00, - 0x00, 0x00, 0x7F, 0x0C, 0x7F, 0xCC, 0x7F, 0x00, - 0x3E, 0x6C, 0xCC, 0xFE, 0xCC, 0xCC, 0xCE, 0x00, - 0x78, 0x84, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, - 0x00, 0xCC, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, - 0x00, 0xE0, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, - 0x78, 0x84, 0x00, 0xCC, 0xCC, 0xCC, 0x76, 0x00, - 0x00, 0xE0, 0x00, 0xCC, 0xCC, 0xCC, 0x76, 0x00, - 0x00, 0xCC, 0x00, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, - 0xC3, 0x18, 0x3C, 0x66, 0x66, 0x3C, 0x18, 0x00, - 0xCC, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0x78, 0x00, - 0x18, 0x18, 0x7E, 0xC0, 0xC0, 0x7E, 0x18, 0x18, - 0x38, 0x6C, 0x64, 0xF0, 0x60, 0xE6, 0xFC, 0x00, - 0xCC, 0xCC, 0x78, 0x30, 0xFC, 0x30, 0xFC, 0x30, - 0xF8, 0xCC, 0xCC, 0xFA, 0xC6, 0xCF, 0xC6, 0xC3, - 0x0E, 0x1B, 0x18, 0x3C, 0x18, 0x18, 0xD8, 0x70, - 0x1C, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, - 0x38, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, - 0x00, 0x1C, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, - 0x00, 0x1C, 0x00, 0xCC, 0xCC, 0xCC, 0x76, 0x00, - 0x00, 0xF8, 0x00, 0xB8, 0xCC, 0xCC, 0xCC, 0x00, - 0xFC, 0x00, 0xCC, 0xEC, 0xFC, 0xDC, 0xCC, 0x00, - 0x3C, 0x6C, 0x6C, 0x3E, 0x00, 0x7E, 0x00, 0x00, - 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x7C, 0x00, 0x00, - 0x18, 0x00, 0x18, 0x18, 0x30, 0x66, 0x3C, 0x00, - 0x00, 0x00, 0x00, 0xFC, 0xC0, 0xC0, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xFC, 0x0C, 0x0C, 0x00, 0x00, - 0xC6, 0xCC, 0xD8, 0x36, 0x6B, 0xC2, 0x84, 0x0F, - 0xC3, 0xC6, 0xCC, 0xDB, 0x37, 0x6D, 0xCF, 0x03, - 0x18, 0x00, 0x18, 0x18, 0x3C, 0x3C, 0x18, 0x00, - 0x00, 0x33, 0x66, 0xCC, 0x66, 0x33, 0x00, 0x00, - 0x00, 0xCC, 0x66, 0x33, 0x66, 0xCC, 0x00, 0x00, - 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, - 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, - 0xDB, 0xF6, 0xDB, 0x6F, 0xDB, 0x7E, 0xD7, 0xED, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0xF8, 0x18, 0x18, 0x18, - 0x18, 0x18, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18, - 0x36, 0x36, 0x36, 0x36, 0xF6, 0x36, 0x36, 0x36, - 0x00, 0x00, 0x00, 0x00, 0xFE, 0x36, 0x36, 0x36, - 0x00, 0x00, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18, - 0x36, 0x36, 0xF6, 0x06, 0xF6, 0x36, 0x36, 0x36, - 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, - 0x00, 0x00, 0xFE, 0x06, 0xF6, 0x36, 0x36, 0x36, - 0x36, 0x36, 0xF6, 0x06, 0xFE, 0x00, 0x00, 0x00, - 0x36, 0x36, 0x36, 0x36, 0xFE, 0x00, 0x00, 0x00, - 0x18, 0x18, 0xF8, 0x18, 0xF8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xF8, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x1F, 0x00, 0x00, 0x00, - 0x18, 0x18, 0x18, 0x18, 0xFF, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xFF, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x1F, 0x18, 0x18, 0x18, - 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, - 0x18, 0x18, 0x18, 0x18, 0xFF, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x1F, 0x18, 0x1F, 0x18, 0x18, 0x18, - 0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36, - 0x36, 0x36, 0x37, 0x30, 0x3F, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x3F, 0x30, 0x37, 0x36, 0x36, 0x36, - 0x36, 0x36, 0xF7, 0x00, 0xFF, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xFF, 0x00, 0xF7, 0x36, 0x36, 0x36, - 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, - 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, - 0x36, 0x36, 0xF7, 0x00, 0xF7, 0x36, 0x36, 0x36, - 0x18, 0x18, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, - 0x36, 0x36, 0x36, 0x36, 0xFF, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x18, 0x18, 0x18, - 0x00, 0x00, 0x00, 0x00, 0xFF, 0x36, 0x36, 0x36, - 0x36, 0x36, 0x36, 0x36, 0x3F, 0x00, 0x00, 0x00, - 0x18, 0x18, 0x1F, 0x18, 0x1F, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x1F, 0x18, 0x1F, 0x18, 0x18, 0x18, - 0x00, 0x00, 0x00, 0x00, 0x3F, 0x36, 0x36, 0x36, - 0x36, 0x36, 0x36, 0x36, 0xFF, 0x36, 0x36, 0x36, - 0x18, 0x18, 0xFF, 0x18, 0xFF, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0xF8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x1F, 0x18, 0x18, 0x18, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, - 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, - 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, - 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x76, 0xDC, 0xC8, 0xDC, 0x76, 0x00, - 0x00, 0x78, 0xCC, 0xF8, 0xCC, 0xF8, 0xC0, 0xC0, - 0x00, 0xFC, 0xCC, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, - 0x00, 0x00, 0xFE, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, - 0xFC, 0xCC, 0x60, 0x30, 0x60, 0xCC, 0xFC, 0x00, - 0x00, 0x00, 0x7E, 0xD8, 0xD8, 0xD8, 0x70, 0x00, - 0x00, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x60, 0xC0, - 0x00, 0x76, 0xDC, 0x18, 0x18, 0x18, 0x18, 0x00, - 0xFC, 0x30, 0x78, 0xCC, 0xCC, 0x78, 0x30, 0xFC, - 0x38, 0x6C, 0xC6, 0xFE, 0xC6, 0x6C, 0x38, 0x00, - 0x38, 0x6C, 0xC6, 0xC6, 0x6C, 0x6C, 0xEE, 0x00, - 0x1C, 0x30, 0x18, 0x7C, 0xCC, 0xCC, 0x78, 0x00, - 0x00, 0x00, 0x7E, 0xDB, 0xDB, 0x7E, 0x00, 0x00, - 0x06, 0x0C, 0x7E, 0xDB, 0xDB, 0x7E, 0x60, 0xC0, - 0x38, 0x60, 0xC0, 0xF8, 0xC0, 0x60, 0x38, 0x00, - 0x78, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, - 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x00, - 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x7E, 0x00, - 0x60, 0x30, 0x18, 0x30, 0x60, 0x00, 0xFC, 0x00, - 0x18, 0x30, 0x60, 0x30, 0x18, 0x00, 0xFC, 0x00, - 0x0E, 0x1B, 0x1B, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0xD8, 0xD8, 0x70, - 0x18, 0x18, 0x00, 0x7E, 0x00, 0x18, 0x18, 0x00, - 0x00, 0x76, 0xDC, 0x00, 0x76, 0xDC, 0x00, 0x00, - 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, - 0x0F, 0x0C, 0x0C, 0x0C, 0xEC, 0x6C, 0x3C, 0x1C, - 0x58, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, - 0x70, 0x98, 0x30, 0x60, 0xF8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - - - static - grBitmap gr_charcell = - { - 8, /* rows */ - 8, /* width */ - gr_pixel_mode_mono, /* mode */ - 1, /* pitch */ - 0, /* grays */ - 0 /* buffer */ - }; - - void grWriteCellChar( grBitmap* target, - int x, - int y, - int charcode, - grColor color ) - { - if (charcode < 0 || charcode > 255) - return; - - gr_charcell.buffer = (char*)font_8x8 + 8*charcode; - grBlitGlyphToBitmap( target, &gr_charcell, x, y, color ); - } - - - void grWriteCellString( grBitmap* target, - int x, - int y, - const char* string, - grColor color ) - { - while (*string) - { - gr_charcell.buffer = (char*)font_8x8 + 8*(int)(unsigned char)*string++; - grBlitGlyphToBitmap( target, &gr_charcell, x, y, color ); - x += 8; - } - } - - static int gr_cursor_x = 0; - static int gr_cursor_y = 0; - static grBitmap* gr_text_bitmap = 0; - static int gr_margin_right = 0; - static int gr_margin_top = 0; - - extern void grGotobitmap( grBitmap* bitmap ) - { - gr_text_bitmap = bitmap; - } - - extern void grSetMargin( int right, int top ) - { - gr_margin_top = top << 3; - gr_margin_right = right << 3; - } - - extern void grGotoxy ( int x, int y ) - { - gr_cursor_x = x; - gr_cursor_y = y; - } - - extern void grWrite ( const char* string ) - { - if (string) - { - grColor color; - - color.value = 127; - grWriteCellString( gr_text_bitmap, - gr_margin_right + (gr_cursor_x << 3), - gr_margin_top + (gr_cursor_y << 3), - string, - color ); - - gr_cursor_x += strlen(string); - } - } - - extern void grLn() - { - gr_cursor_y ++; - gr_cursor_x = 0; - } - - extern void grWriteln( const char* string ) - { - grWrite( string ); - grLn(); - } - - diff --git a/demos/graph/grfont.h b/demos/graph/grfont.h deleted file mode 100644 index 2697e0040..000000000 --- a/demos/graph/grfont.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef GRFONT_H -#define GRFONT_H - -#include "graph.h" - - extern const unsigned char font_8x8[]; - - extern void grGotobitmap( grBitmap* bitmap ); - extern void grSetMargin( int right, int top ); - extern void grGotoxy ( int x, int y ); - - extern void grWrite ( const char* string ); - extern void grWriteln( const char* string ); - extern void grLn(); - -#endif /* GRFONT_H */ diff --git a/demos/graph/grinit.c b/demos/graph/grinit.c deleted file mode 100644 index 4da1db6cf..000000000 --- a/demos/graph/grinit.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "grobjs.h" -#include "grdevice.h" -#include - -#define GR_INIT_DEVICE_CHAIN ((grDeviceChain*)0) -#define GR_INIT_BUILD - -#ifdef DEVICE_X11 -#include "grx11.h" -#endif - -#ifdef DEVICE_OS2_PM -#include "gros2pm.h" -#endif - -#ifdef DEVICE_WIN32 -#include "grwin32.h" -#endif - -#ifdef macintosh -#include "grmac.h" -#endif - - - /********************************************************************** - * - * - * grInitDevices - * - * - * This function is in charge of initialising all system-specific - * devices. A device is responsible for creating and managing one - * or more "surfaces". A surface is either a window or a screen, - * depending on the system. - * - * - * a pointer to the first element of a device chain. The chain can - * be parsed to find the available devices on the current system - * - * - * If a device cannot be initialised correctly, it is not part of - * the device chain returned by this function. For example, if an - * X11 device was compiled in the library, it will be part of - * the returned device chain only if a connection to the display - * could be establisged - * - * If no driver could be initialised, this function returns NULL. - * - **********************************************************************/ - - extern - grDeviceChain* grInitDevices( void ) - { - grDeviceChain* chain = GR_INIT_DEVICE_CHAIN; - grDeviceChain* cur = gr_device_chain; - - while (chain) - { - /* initialize the device */ - grDevice* device; - - device = chain->device; - if ( device->init() == 0 && - gr_num_devices < GR_MAX_DEVICES ) - - { - /* successful device initialisation - add it to our chain */ - cur->next = 0; - cur->device = device; - cur->name = device->device_name; - - if (cur > gr_device_chain) - cur[-1].next = cur; - - cur++; - gr_num_devices++; - } - chain = chain->next; - } - - return (gr_num_devices > 0 ? gr_device_chain : 0 ); - } - - - diff --git a/demos/graph/grobjs.c b/demos/graph/grobjs.c deleted file mode 100644 index df8512f91..000000000 --- a/demos/graph/grobjs.c +++ /dev/null @@ -1,213 +0,0 @@ -#include "grobjs.h" -#include -#include - - int grError = 0; - - - /******************************************************************** - * - * - * grRealloc - * - * - * Simple memory re-allocation. - * - * - * block :: original memory block address - * size :: new requested block size in bytes - * - * - * the memory block address. 0 in case of error - * - ********************************************************************/ - - char* grAlloc( long size ) - { - char* p; - - p = (char*)malloc(size); - if (!p && size > 0) - { - grError = gr_err_memory; - } - - if (p) - memset( p, 0, size ); - - return p; - } - - - /******************************************************************** - * - * - * grRealloc - * - * - * Simple memory re-allocation. - * - * - * block :: original memory block address - * size :: new requested block size in bytes - * - * - * the memory block address. 0 in case of error - * - ********************************************************************/ - - char* grRealloc( const char* block, long size ) - { - char* p; - - p = realloc( (char*)block, size ); - if (!p && size > 0) - { - grError = gr_err_memory; - } - return p; - } - - - /******************************************************************** - * - * - * grFree - * - * - * Simple memory release - * - * - * block :: target block - * - ********************************************************************/ - - void grFree( const void* block ) - { - if (block) - free( (char*)block ); - } - - - - static - int check_mode( grPixelMode pixel_mode, - int num_grays ) - { - if ( pixel_mode <= gr_pixel_mode_none || - pixel_mode >= gr_pixel_mode_max ) - goto Fail; - - if ( pixel_mode != gr_pixel_mode_gray || - ( num_grays >= 2 && num_grays <= 256 ) ) - return 0; - - Fail: - grError = gr_err_bad_argument; - return grError; - } - - - /********************************************************************** - * - * - * grNewBitmap - * - * - * creates a new bitmap - * - * - * pixel_mode :: the target surface's pixel_mode - * num_grays :: number of grays levels for PAL8 pixel mode - * width :: width in pixels - * height :: height in pixels - * - * - * bit :: descriptor of the new bitmap - * - * - * Error code. 0 means success. - * - **********************************************************************/ - - extern int grNewBitmap( grPixelMode pixel_mode, - int num_grays, - int width, - int height, - grBitmap *bit ) - { - int pitch; - - /* check mode */ - if (check_mode(pixel_mode,num_grays)) - goto Fail; - - /* check dimensions */ - if (width < 0 || height < 0) - { - grError = gr_err_bad_argument; - goto Fail; - } - - bit->width = width; - bit->rows = height; - bit->mode = pixel_mode; - bit->grays = num_grays; - - pitch = width; - - switch (pixel_mode) - { - case gr_pixel_mode_mono : pitch = (width+7) >> 3; break; - case gr_pixel_mode_pal4 : pitch = (width+3) >> 2; break; - - case gr_pixel_mode_pal8 : - case gr_pixel_mode_gray : pitch = width; break; - - case gr_pixel_mode_rgb555: - case gr_pixel_mode_rgb565: pitch = width*2; break; - - case gr_pixel_mode_rgb24 : pitch = width*3; break; - - case gr_pixel_mode_rgb32 : pitch = width*4; break; - - default: - grError = gr_err_bad_target_depth; - return 0; - } - - bit->pitch = pitch; - bit->buffer = grAlloc( (long)bit->pitch * bit->rows ); - if (!bit->buffer) goto Fail; - - return 0; - - Fail: - return grError; - } - - /********************************************************************** - * - * - * grDoneBitmap - * - * - * destroys a bitmap - * - * - * bitmap :: handle to bitmap descriptor - * - * - * This function does NOT release the bitmap descriptor, only - * the pixel buffer. - * - **********************************************************************/ - - extern void grDoneBitmap( grBitmap* bit ) - { - grFree( bit->buffer ); - bit->buffer = 0; - } - - - diff --git a/demos/graph/grobjs.h b/demos/graph/grobjs.h deleted file mode 100644 index 5f99d0510..000000000 --- a/demos/graph/grobjs.h +++ /dev/null @@ -1,186 +0,0 @@ -/*************************************************************************** - * - * grobjs.h - * - * basic object classes defintions - * - * Copyright 1999 - The FreeType Development Team - www.freetype.org - * - * - * - * - ***************************************************************************/ - -#ifndef GROBJS_H -#define GROBJS_H - -#include "graph.h" -#include "grconfig.h" -#include "grtypes.h" - - - typedef struct grBiColor_ - { - grColor foreground; - grColor background; - - int num_levels; - int max_levels; - grColor* levels; - - } grBiColor; - - - - /********************************************************************** - * - * Technical note : explaining how the blitter works. - * - * The blitter is used to "draw" a given source bitmap into - * a given target bitmap. - * - * The function called 'compute_clips' is used to compute clipping - * constraints. These lead us to compute two areas : - * - * - the read area : is the rectangle, within the source bitmap, - * which will be effectively "drawn" in the - * target bitmap. - * - * - the write area : is the rectangle, within the target bitmap, - * which will effectively "receive" the pixels - * from the read area - * - * Note that both areas have the same dimensions, but are - * located in distinct surfaces. - * - * These areas are computed by 'compute_clips' which is called - * by each blitting function. - * - * Note that we use the Y-downwards convention within the blitter - * - **********************************************************************/ - - typedef struct grBlitter_ - { - int width; /* width in pixels of the areas */ - int height; /* height in pixels of the areas */ - - int xread; /* x position of start point in read area */ - int yread; /* y position of start point in read area */ - - int xwrite; /* x position of start point in write area */ - int ywrite; /* y position of start point in write area */ - - int right_clip; /* amount of right clip */ - - unsigned char* read; /* top left corner of read area in source map */ - unsigned char* write; /* top left corner of write area in target map */ - - int read_line; /* byte increment to go down one row in read area */ - int write_line; /* byte increment to go down one row in write area */ - - grBitmap source; /* source bitmap descriptor */ - grBitmap target; /* target bitmap descriptor */ - - } grBlitter; - - - - typedef void (*grBlitterFunc)( grBlitter* blitter, - grColor color ); - - typedef void (*grSetTitleFunc)( grSurface* surface, - const char* title_string ); - - typedef void (*grRefreshRectFunc)( grSurface* surface, - int x, - int y, - int width, - int height ); - - typedef void (*grDoneSurfaceFunc)( grSurface* surface ); - - typedef int (*grListenEventFunc)( grSurface* surface, - int event_mode, - grEvent *event ); - - - - struct grSurface_ - { - grDevice* device; - grBitmap bitmap; - grBool refresh; - grBool owner; - - const byte* saturation; /* used for gray surfaces only */ - grBlitterFunc blit_mono; /* 0 by default, set by grBlit.. */ - - grRefreshRectFunc refresh_rect; - grSetTitleFunc set_title; - grListenEventFunc listen_event; - grDoneSurfaceFunc done; - }; - - - - /******************************************************************** - * - * - * grAlloc - * - * - * Simple memory allocation. The returned block is always zero-ed - * - * - * size :: size in bytes of the requested block - * - * - * the memory block address. 0 in case of error - * - ********************************************************************/ - - extern char* grAlloc( long size ); - - - /******************************************************************** - * - * - * grRealloc - * - * - * Simple memory re-allocation. - * - * - * block :: original memory block address - * size :: new requested block size in bytes - * - * - * the memory block address. 0 in case of error - * - ********************************************************************/ - - extern char* grRealloc( const char* block, long size ); - - - /******************************************************************** - * - * - * grFree - * - * - * Simple memory release - * - * - * block :: target block - * - ********************************************************************/ - - extern void grFree( const void* block ); - - - extern grDevice* gr_devices[]; - extern int gr_num_devices; - extern int gr_max_devices; - -#endif /* GROBJS_H */ diff --git a/demos/graph/grtypes.h b/demos/graph/grtypes.h deleted file mode 100644 index 7c39e2aa6..000000000 --- a/demos/graph/grtypes.h +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************** - * - * grtypes.h - * - * basic type defintions - * - * Copyright 1999 - The FreeType Development Team - www.freetype.org - * - * - * - * - ***************************************************************************/ - -#ifndef GRTYPES_H -#define GRTYPES_H - - typedef unsigned char byte; - -#if 0 - typedef signed char uchar; - - typedef unsigned long ulong; - typedef unsigned short ushort; - typedef unsigned int uint; -#endif - - typedef struct grDimension_ - { - int x; - int y; - - } grDimension; - -#define gr_err_ok 0 -#define gr_err_memory -1 -#define gr_err_bad_argument -2 -#define gr_err_bad_target_depth -3 -#define gr_err_bad_source_depth -4 -#define gr_err_saturation_overflow -5 -#define gr_err_conversion_overflow -6 -#define gr_err_invalid_device -7 - - -#ifdef GR_MAKE_OPTION_SINGLE_OBJECT -#define GR_LOCAL_DECL static -#define GR_LOCAL_FUNC static -#else -#define GR_LOCAL_DECL extern -#define GR_LOCAL_FUNC /* void */ -#endif - -#endif /* GRTYPES_H */ diff --git a/demos/graph/mac/grmac.c b/demos/graph/mac/grmac.c deleted file mode 100644 index 359aac88c..000000000 --- a/demos/graph/mac/grmac.c +++ /dev/null @@ -1,348 +0,0 @@ -/******************************************************************* - * - * grmac.c graphics driver for MacOS platform. 0.1 - * - * This is the driver for displaying inside a window under MacOS, - * used by the graphics utility of the FreeType test suite. - * - * Largely written by Just van Rossum, but derived from grwin32.c. - * Copyright 1999-2000 by Just van Rossum, Antoine Leca, - * David Turner, Robert Wilhelm, and Werner Lemberg. - * - * Borrowing liberally from the other FreeType drivers. - * - * This file is part of the FreeType project, and may only be used - * modified and distributed under the terms of the FreeType project - * license, LICENSE.TXT. By continuing to use, modify or distribute - * this file you indicate that you have read the license and - * understand and accept it fully. - * - ******************************************************************/ - -/* ANSI C */ -#include - -/* Mac Toolbox */ -#include - -/* FT graphics subsystem */ -#include "grmac.h" -#include "grdevice.h" - -/* CodeWarrior's poor excuse for a console */ -#include - - -/* Mac function key definitions. The 0x100 is a kludge, see listen_event(). */ -#define KEY_F1 (0x7A | 0x100) -#define KEY_F2 (0x78 | 0x100) -#define KEY_F3 (0x63 | 0x100) -#define KEY_F4 (0x76 | 0x100) -#define KEY_F5 (0x60 | 0x100) -#define KEY_F6 (0x61 | 0x100) -#define KEY_F7 (0x62 | 0x100) -#define KEY_F8 (0x64 | 0x100) -#define KEY_F9 (0x65 | 0x100) -#define KEY_F10 (0x6D | 0x100) -#define KEY_F11 (0x67 | 0x100) -#define KEY_F12 (0x6F | 0x100) -#define KEY_F13 (0x69 | 0x100) -#define KEY_F14 (0x6B | 0x100) -#define KEY_F15 (0x71 | 0x100) - - -/* Mac to FT key mapping */ - - typedef struct _Translator - { - short mackey; - grKey grkey; - - } Translator; - - static - Translator key_translators[] = - { - { kBackspaceCharCode, grKeyBackSpace }, - { kTabCharCode, grKeyTab }, - { kReturnCharCode, grKeyReturn }, - { kEscapeCharCode, grKeyEsc }, - { kHomeCharCode, grKeyHome }, - { kLeftArrowCharCode, grKeyLeft }, - { kUpArrowCharCode, grKeyUp }, - { kRightArrowCharCode, grKeyRight }, - { kDownArrowCharCode, grKeyDown }, - { kPageUpCharCode, grKeyPageUp }, - { kPageDownCharCode, grKeyPageDown }, - { kEndCharCode, grKeyEnd }, - { kHelpCharCode, grKeyF1 }, /* map Help key to F1... */ - { KEY_F1, grKeyF1 }, - { KEY_F2, grKeyF2 }, - { KEY_F3, grKeyF3 }, - { KEY_F4, grKeyF4 }, - { KEY_F5, grKeyF5 }, - { KEY_F6, grKeyF6 }, - { KEY_F7, grKeyF7 }, - { KEY_F8, grKeyF8 }, - { KEY_F9, grKeyF9 }, - { KEY_F10, grKeyF10 }, - { KEY_F11, grKeyF11 }, - { KEY_F12, grKeyF12 } - }; - - - /* This is a minimalist driver, it is only able to display */ - /* a _single_ window. Moreover, only monochrome and gray */ - /* bitmaps are supported.. */ - - /* pointer to the window. */ - static WindowPtr theWindow = NULL; - - /* the pixmap */ - static PixMap thePixMap; - - - /* destroys the window */ - static - void done_window( ) - { - if ( theWindow ) - { - DisposeWindow ( theWindow ); - } - theWindow = NULL; - } - - /* destroys the surface*/ - static - void done_surface( grSurface* surface ) - { - /* ick! this never gets called... */ - done_window(); - grDoneBitmap( &surface->bitmap ); - } - - static - void refresh_rectangle( grSurface* surface, - int x, - int y, - int w, - int h ) - { - Rect bounds; - SetRect( &bounds, x, y, x+w, y+h ); - if ( theWindow ) - CopyBits( (BitMap*)&thePixMap, &theWindow->portBits, - &bounds, &bounds, srcCopy, theWindow->visRgn ); - } - - static - void set_title( grSurface* surface, const char* title ) - { - Str255 pTitle; - strcpy( (char*)pTitle+1, title ); - pTitle[0] = strlen( title ); - if ( theWindow ) - SetWTitle( theWindow, pTitle ); - } - - static - void listen_event( grSurface* surface, - int event_mask, - grEvent* grevent ) - { - grEvent our_grevent; - EventRecord mac_event; - short theEventMask = keyDownMask | autoKeyMask /* | updateEvtMask */ ; - - our_grevent.type = gr_event_none; - our_grevent.key = grKeyNone; - - for ( ;; ) - /* The event loop. Sorry, but I'm too lazy to split the various events - to proper event handler functions. This whole app is rather ad hoc - anyway, so who cares ;-) */ - { - if ( WaitNextEvent( everyEvent, &mac_event, 10, NULL ) ) - { - switch ( mac_event.what ) - { - case autoKey: - case keyDown: - { - int count = sizeof( key_translators ) / sizeof( key_translators[0] ); - Translator* trans = key_translators; - Translator* limit = trans + count; - short char_code; - - char_code = mac_event.message & charCodeMask; - if ( char_code == kFunctionKeyCharCode ) - /* Le kluge. Add a flag to differentiate the F-keys from normal keys. */ - char_code = 0x100 | ((mac_event.message & keyCodeMask) >> 8); - - our_grevent.key = char_code; - - for ( ; trans < limit; trans++ ) - /* see if the key maps to a special "gr" key */ - if ( char_code == trans->mackey ) - { - our_grevent.key = trans->grkey; - } - our_grevent.type = gr_event_key; - } - if ( our_grevent.key == grKEY('q') || our_grevent.key == grKeyEsc ) - /* destroy the window here, since done_surface() doesn't get called */ - done_window(); - *grevent = our_grevent; - return; - case updateEvt: - if ( theWindow && (WindowPtr)mac_event.message == theWindow ) - { - SetPort( theWindow ); - BeginUpdate( theWindow ); - refresh_rectangle( surface, - 0, 0, - thePixMap.bounds.right, thePixMap.bounds.bottom ); - EndUpdate( theWindow ); - } - else - { - SIOUXHandleOneEvent( &mac_event ); - } - break; - case mouseDown: - { - short part; - WindowPtr wid; - - part = FindWindow( mac_event.where, &wid ); - if ( wid == theWindow ) - { - if ( theWindow && part == inDrag) - DragWindow( wid, mac_event.where, &qd.screenBits.bounds ); - else if (part == inGoAway) - { - if ( TrackGoAway( theWindow, mac_event.where ) ) - { - /* The user clicked the window away, emulate quit event */ - done_window(); - our_grevent.type = gr_event_key; - our_grevent.key = grKeyEsc; - *grevent = our_grevent; - return; - } - } - else if (part == inContent) - { - SelectWindow( theWindow ); - } - } - else - { - SIOUXHandleOneEvent( &mac_event ); - } - } - break; - default: - InitCursor(); - break; - } - } - } - } - - -static -grSurface* init_surface( grSurface* surface, - grBitmap* bitmap ) -{ - Rect bounds; - SetRect(&bounds, 0, 0, bitmap->width, bitmap->rows); - - /* create the bitmap - under MacOS, we support all modes as the GDI */ - /* handles all conversions automatically.. */ - if ( grNewBitmap( bitmap->mode, - bitmap->grays, - bitmap->width, - bitmap->rows, - bitmap ) ) - return 0; - - surface->bitmap = *bitmap; - - /* initialize the PixMap to appropriate values */ - thePixMap.baseAddr = bitmap->buffer; - thePixMap.rowBytes = bitmap->pitch; - if (thePixMap.rowBytes < 0) - thePixMap.rowBytes = -thePixMap.rowBytes; - thePixMap.rowBytes |= 0x8000; /* flag indicating it's a PixMap, not a BitMap */ - thePixMap.bounds = bounds; - thePixMap.pmVersion = 0; - thePixMap.packType = 0; - thePixMap.packSize = 0; - thePixMap.hRes = 72 << 16; - thePixMap.vRes = 72 << 16; - thePixMap.pixelType = 0; - thePixMap.cmpCount = 1; - thePixMap.pmTable = 0; - thePixMap.planeBytes = 0; - thePixMap.pmReserved = 0; - - switch ( bitmap->mode ) - { - case gr_pixel_mode_mono: - thePixMap.cmpSize = 1; - thePixMap.pixelSize = 1; - break; - - case gr_pixel_mode_gray: - thePixMap.cmpSize = 8; - thePixMap.pixelSize = 8; - thePixMap.pmTable = GetCTable(256); /* color palette matching FT's idea - of grayscale. See ftview.rsrc */ - break; - - default: - return 0; /* Unknown mode */ - } - - /* create the window */ - OffsetRect(&bounds, 10, 44); /* place it at a decent location */ - theWindow = NewCWindow(NULL, &bounds, "\p???", 1, 0, (GrafPtr)-1, 1, 0); - - /* fill in surface interface */ - surface->done = (grDoneSurfaceFunc) done_surface; - surface->refresh_rect = (grRefreshRectFunc) refresh_rectangle; - surface->set_title = (grSetTitleFunc) set_title; - surface->listen_event = (grListenEventFunc) listen_event; - - return surface; -} - - - static int init_device( void ) - { - return 0; - } - - static void done_device( void ) - { - /* won't get called either :-( */ - } - - grDevice gr_mac_device = - { - sizeof( grSurface ), - "mac", - - init_device, - done_device, - - (grDeviceInitSurfaceFunc) init_surface, - - 0, - 0 - }; - - -/* End */ diff --git a/demos/graph/mac/grmac.h b/demos/graph/mac/grmac.h deleted file mode 100644 index b62f53abc..000000000 --- a/demos/graph/mac/grmac.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef GRMAC_H -#define GRMAC_H - -#include "grobjs.h" - - extern - grDevice gr_mac_device; - -#ifdef GR_INIT_BUILD - static - grDeviceChain gr_mac_device_chain = - { - "mac", - &gr_mac_device, - GR_INIT_DEVICE_CHAIN - }; - -#undef GR_INIT_DEVICE_CHAIN -#define GR_INIT_DEVICE_CHAIN &gr_mac_device_chain - -#endif /* GR_INIT_BUILD */ - -#endif /* GRMAC_H */ diff --git a/demos/graph/migs.html b/demos/graph/migs.html deleted file mode 100644 index 365b9c97a..000000000 --- a/demos/graph/migs.html +++ /dev/null @@ -1,304 +0,0 @@ - - - - - - - - -
MiGS Overview -
A Minimalist Graphics Subsystem -

-


- -

-Introduction

- -
This document details the design and implementation of MiGS, -the minimalist graphics subsystem used by the FreeType 2 demonstration -programs. Its purpose is mainly to help writers of new demo programs, as -well as developers who would like port the subsystem to other platforms.
- -
-

-I - Design goals

- -
MiGS is a tiny graphics subsystem used to demo text rendering -through the FreeType library. It was mainly written to provide the abilities -to :
- -
    -
      -
    • -draw a monochrome glyph bitmap to many kinds of target surfaces (i.e. really -bitmaps/pixmaps)
    • - -
    • -draw an anti-aliased glyph bitmap, with any level of grays, to many kinds -of target surfaces
    • - -
    • -display a simple window on many systems like X11, OS/2 and Windows
    • - -
    • -accept simple events (keypresses and mouse buttons) in this window.
    • - -
    • -to be portable and present a unified API on all running systems
    • -
    - -


    MiGS uses system-specific "drivers" in order to perform display -and event handling. The blitting functions are not device-specific. MiGS -can be built and/or used with no system-specific features, like for example, -to generate simple GIF, PNG, TIFF, etc.. images without ever needing to -display them.

- -

- -

- -

-II - Surfaces, bitmaps and windows

- -
A surface in MiGS models a drawable region where glyph images -can be rendered, a surface always contains a bitmap descriptor as well -as a few other things that will be described later in this section. -

Some surfaces can be displayed, they are then either called windowed -surfaces or screen surfaces depending on the nature of the device -used to display them. Each device is implemented by a very simple -driver in the MiGS code. Here are a few example devices that are -or could be written to display surfaces : -

- an X11 device -
- a Win 32 GDI device -
- an OS/2 Presentation Manager device -
- a fullscreen SVGALib device on Linux -
- a GGI visual device -
- an OS/2 "Dive" device, or the equivalent Win32 "DirectX" device -

etc.. -

NOTE: For now, only the X11 device was written and tested.. More -devices should come later -

Before explaining how to create a surface, we need to explain how MiGS -manages bitmaps and renders glyph images to them. -

-1. Bitmaps :

- -
A bitmap in MiGS features the following things : -
    -
  • -a width in pixels
  • - -
  • -a height in pixels
  • - -
  • -a pixel mode, which indicates how the pixels are stored in -the surface's buffer
  • - -
  • -a pitch, whose absolute values is the number of bytes taken -by each surface row
  • - -
  • -a number of valid gray levels (see below)
  • - -
  • -a buffer, holding the surface's pixels
  • -
- -


MiGS uses the "Y downwards" convention, which means that -increasing -Y coordinates correspond to lower rows of the bitmap. Hence, -the coordinate (0,0) always corresponds to the bitmap's -top-left -pixel. -

The bitmap's rows can be stored either "downwards" or "upwards" -in the pixel buffer. -

In the first case (downwards), increasing memory addresses in -the pixel buffer correspond to lower rows of the bitmap(e.g. PC video modes), -and the pitch should be equal to the number of bytes -taken by each row. The first pixel buffer byte corresponds to the -upper row. -

In the second case (upwards), increasing memory addresses in -the pixel buffer correspond to upper rows of the bitmap and the pitch -should be equal to the opposite of the number of bytes -taken by each row. The first pixel buffer byte corresponds to the lower -row. -

In all cases, the pitch is the increment to be used -to go from one bitmap row to the one below it. -

The supported pixel modes are : -

    -
  • -1-bit monochrome bitmaps. With "0" as the background, and "1" as the foreground.
  • - -
  • -4-bit color bitmaps, using an arbitrary palette.
  • - -
  • -8-bit color bitmaps, using an arbitrary palette.
  • - -
  • -8-bit gray bitmaps, using a given N number of gray levels in the range -0..N-1.
  • - -
  • -15-bit color bitmaps, also known as RGB555
  • - -
  • -16-bit color bitmaps, also known as RGB565
  • - -
  • -24-bit color bitmaps, also known as RGB
  • - -
  • -32-bit color bitmaps, also known as RGBA (though the A is ignored by MiGS)
  • -
-The bitmap's number of gray levels is only relevant for 8-bit -gray bitmaps, and indicates the range of gray levels that can be -found in the bitmap. If a bitmap as N gray levels, it is said to be N-grayscales, -and the pixels within it must all have values between 0, considered as -the background color, and N-1, considered as the foreground -color. -

N-grayscale bitmaps are crucial for the rendering of anti-aliased text. -
 

- -

-2. Glyph images :

- -
The glyph images that can be drawn on bitmaps through MiGS -are bitmaps themselves, though limited to the following pixel modes : -

1-bit monochrome glyph bitmaps -

These can be drawn on any kind of bitmap. Note that only -the "lit" pixels (i.e. the bits set to 1) are effectively drawn to -the target, as opaque blitting isn't supported (remember, it's a minimalist -library !)
- -


N-grayscales glyph images (with any value of N >= 2) -

These can be drawn to all RGB bitmaps (15, 16, 24 & -32 bits/pixel), as well as any other M-grayscales bitmaps. In the latter -case, the values of N and M need not be equal, as the library is -able to perform automatic conversions on the fly. -

For example, it is possible to render a 5-grayscales glyph image into -a 128-grayscales bitmap. Moreover, it is also possible to render a 17-grayscales -glyph image into a 5-grayscales bitmap, even if this will result in a -loss of quality. This feature is crucial in order to experiment easily -with other anti-aliasing algorithms for FreeType -
 

-Note that you can only draw monochrome bitmaps to the following -pixel modes : monochrome, 4-bit color and 8-bit color.
- -

-3. Windows and Screens:

- -
In order to debug FreeType, displaying a surface in a window -or in full-screen mode, is required. MiGS thus makes a difference between -simple -surfaces, which only contain a bitmap, windowed surfaces, which -are used to display their content in a window, and screen surfaces, -which are used to display their content in a full-screen mode (SVGAlib, -DirectX, GGI or wathever). -

A few important things must be said about non-simple surfaces. -
  -

    -
  • -First, they might contain some system-specific data which is used to manage -the display in a window or on the screen. This must be completely hidden -to MiGS clients. Indeed, rendering to any kind of surface is achieved through -exactly -the same function calls.
  • -
- -
    -
  • -Second, they may contain a bitmap whose pixel mode doesn't correspond to -the screen's depth used to display it. For example, the surface might contain -an 128-grayscale bitmap, while the screen is in RGB24 mode. Some conversion -must be performed to display the surface. This can either happen in the -system-specific graphics library (e.g. on OS/2, a single Presentation Manager -call is used to blit a N-grayscale image to any kind of window) -or in the system-specific part of MiGS (e.g. the X11 MiGS driver must convert -the surface's bitmap into the appropriate X11 image each time a -repaint is requested). Again this must be completely hidden to MiGS clients
  • -
-Surfaces have also a few fields that are only used when displaying them -in Windows : -

a title string -

This is simply a text string that is displayed on the title -bar of the surface's window. It can also appear at the top or bottom of -full-screen surfaces if the MiGS driver supports it. The title string can -be changed with a call to grSetTitle, and is ignored for simple -surfaces.
- -


a refresh flag -

This boolean flag is only used for window surfaces, and some -fullscreen ones (depending on the driver implementation). When set, it -indicates that each glyph image blit must be displayed immediately. By -default, this flag is set to False, which means that demo programs must -call the grRefreshSurface(surface) function to display the whole -contents of a surface one it has been updated. -

The refresh flag can be set with grSetSurfaceRefresh(surface,flag). -Note that a single surface rectangle can be forced to be displayed with -a call to grRefreshRectangle(surface,x,y,w,h) at any time.

-
- -

-4. Devices :

- -
As said before, each device is in charge of displaying a surface -in a given window or screen. Each device is managed through a very simple -driver, described to MiGS through a very simple "grDevice" structure. -

A grDevice contains, among other things, pointers to the functions used -to: -

- refresh/display a given rectangle of the surface to the window/screen -
- listen events (key presses and mouse) and send them back to client -apps. -
- for windowed devices, update the title bar. -

As said before, this is a highly minimalist system.. -
 

-
- -
-

-III - Important implementation issues :

- -
-

-1. Display surface negociation :

- -
A display surface is created with the function grNewScreenSurface -which takes parameters indicating which device should be used, the pixel -dimensions of the requested surface, as well as its pixel mode. -

Because of some device-specific limitations, the resulting surface's -properties might not match exactly those requested for the call. Hence, -a developper should always take care of reading a new display surface's -bitmap descriptor in order to get its real dimensions, pixel -mode and eventually number of grays. -

The function grNewSurface will create a memory surface with the corresponding -bitmap. -
The function grNewBitmapSurface will create a surface from a pre-existing -bitmap. This is useful to draw text on loaded images, for example. -

Any surface (display or not) is destroyed with grDoneSurface.

- -

-

- -

-2. Supporting 8-bit grayscale mode :

- -
It is important, for the debugging of FreeType anti-aliased -renderer(s), that _all_ devices should support the 8-bit gray mode. -The number of gray levels can be fixed or negociated as required by implementation-specific -issues. -

As most existing devices do not provide direct support for such a mode, -each 8-bit surface must thus contain : -

- an internal N-grayscale bitmap, used as the target of all glyph drawings -
- its own device-specific "image", which matches the display depth. -

Each time the device's "refresh_rect" function is called, it should -then : -
- convert the grayscales within the bitmap's rectangle into the image's -buffer and format. -
- display the corresponding image rectangle. -

This scheme is used, for example, by the X11 device.

-
- - - diff --git a/demos/graph/os2/gros2pm.c b/demos/graph/os2/gros2pm.c deleted file mode 100644 index 1aba61cd0..000000000 --- a/demos/graph/os2/gros2pm.c +++ /dev/null @@ -1,754 +0,0 @@ -#include "gros2pm.h" -#include "grdevice.h" - -#define INCL_DOS -#define INCL_WIN -#define INCL_GPI -#define INCL_SUB - -#include -#include -#include -#include -#include - -#define DEBUGxxx - -#ifdef DEBUG -#define LOG(x) LogMessage##x -#else -#define LOG(x) /* rien */ -#endif - -#ifdef DEBUG - static void LogMessage( const char* fmt, ... ) - { - va_list ap; - - va_start( ap, fmt ); - vfprintf( stderr, fmt, ap ); - va_end( ap ); - } -#endif - - typedef struct Translator - { - ULONG os2key; - grKey grkey; - - } Translator; - - - static - Translator key_translators[] = - { - { VK_BACKSPACE, grKeyBackSpace }, - { VK_TAB, grKeyTab }, - { VK_ENTER, grKeyReturn }, - { VK_ESC, grKeyEsc }, - { VK_HOME, grKeyHome }, - { VK_LEFT, grKeyLeft }, - { VK_UP, grKeyUp }, - { VK_RIGHT, grKeyRight }, - { VK_DOWN, grKeyDown }, - { VK_PAGEUP, grKeyPageUp }, - { VK_PAGEDOWN, grKeyPageDown }, - { VK_END, grKeyEnd }, - { VK_F1, grKeyF1 }, - { VK_F2, grKeyF2 }, - { VK_F3, grKeyF3 }, - { VK_F4, grKeyF4 }, - { VK_F5, grKeyF5 }, - { VK_F6, grKeyF6 }, - { VK_F7, grKeyF7 }, - { VK_F8, grKeyF8 }, - { VK_F9, grKeyF9 }, - { VK_F10, grKeyF10 }, - { VK_F11, grKeyF11 }, - { VK_F12, grKeyF12 } - }; - - -#define MAX_PIXEL_MODES 32 - - static HAB gr_anchor; /* device anchor block */ - - typedef POINTL PMBlitPoints[4]; - - typedef struct grPMSurface_ - { - grSurface root; - grBitmap image; - - HAB anchor; /* handle to anchor block for surface's window */ - HWND frame_window; /* handle to window's frame */ - HWND client_window; /* handle to window's client */ - HWND title_window; /* handle to window's title bar */ - - HPS image_ps; /* memory presentation space used to hold */ - /* the surface's content under PM */ - HDC image_dc; /* memory device context for the image */ - - HEV event_lock; /* semaphore used in listen_surface */ - HMTX image_lock; /* a mutex used to synchronise access */ - /* to the memory presentation space */ - /* used to hold the surface */ - - TID message_thread; /* thread used to process this surface's */ - /* messages.. */ - - PBITMAPINFO2 bitmap_header;/* os/2 bitmap descriptor */ - HBITMAP os2_bitmap; /* Handle to OS/2 bitmap contained in image */ - BOOL ready; /* ??? */ - - long shades[256]; /* indices of gray levels in pixel_mode_gray */ - - POINTL surface_blit[4]; /* surface blitting table */ - POINTL magnify_blit[4]; /* magnifier blitting table */ - int magnification; /* level of magnification */ - POINTL magnify_center; - SIZEL magnify_size; - - grEvent event; - - PMBlitPoints blit_points; - - } grPMSurface; - - /* we use a static variable to pass a pointer to the PM Surface */ - /* to the client window. This is a bit ugly, but it makes things */ - /* a lot more simple.. */ - static grPMSurface* the_surface; - - static int window_created = 0; - - - static - void enable_os2_iostreams( void ) - { - PTIB thread_block; - PPIB process_block; - - /* XXX : This is a very nasty hack, it fools OS/2 and let the program */ - /* call PM functions, even though stdin/stdout/stderr are still */ - /* directed to the standard i/o streams.. */ - /* The program must be compiled with WINDOWCOMPAT */ - /* */ - /* Credits go to Michal for finding this !! */ - /* */ - DosGetInfoBlocks( &thread_block, &process_block ); - process_block->pib_ultype = 3; - } - - - - static - int init_device( void ) - { - enable_os2_iostreams(); - - /* create an anchor block. This will allow this thread (i.e. the */ - /* main one) to call Gpi functions.. */ - gr_anchor = WinInitialize(0); - if (!gr_anchor) - { - /* could not initialise Presentation Manager */ - return -1; - } - - return 0; - } - - - - static - void done_device( void ) - { - /* Indicates that we do not use the Presentation Manager, this */ - /* will also release all associated resources.. */ - WinTerminate( gr_anchor ); - } - - - - /* close a given window */ - static - void done_surface( grPMSurface* surface ) - { - LOG(( "Os2PM: done_surface(%08lx)\n", (long)surface )); - - if ( surface->frame_window ) - WinDestroyWindow( surface->frame_window ); - - WinReleasePS( surface->image_ps ); - - grDoneBitmap( &surface->image ); - grDoneBitmap( &surface->root.bitmap ); - } - - - - - -#define LOCK(x) DosRequestMutexSem( x, SEM_INDEFINITE_WAIT ); -#define UNLOCK(x) DosReleaseMutexSem( x ) - - - static - const int pixel_mode_bit_count[] = - { - 0, - 1, /* mono */ - 4, /* pal4 */ - 8, /* pal8 */ - 8, /* grays */ - 15, /* rgb15 */ - 16, /* rgb16 */ - 24, /* rgb24 */ - 32 /* rgb32 */ - }; - - - /************************************************************************ - * - * Technical note : how the OS/2 Presntation Manager driver works - * - * PM is, in my opinion, a bloated and over-engineered graphics - * sub-system, even though it has lots of nice features. Here are - * a few tidbits about it : - * - * - * - under PM, a "bitmap" is a device-specific object whose bits are - * not directly accessible to the client application. This means - * that we must use a scheme like the following to display our - * surfaces : - * - * - hold, for each surface, its own bitmap buffer where the - * rest of the graph library writes directly. - * - * - create a PM bitmap object with the same dimensions (and - * possibly format). - * - * - copy the content of each updated rectangle into the - * PM bitmap with the function 'GpiSetBitmapBits'. - * - * - finally, "blit" the PM bitmap to the screen calling - * 'GpiBlitBlt' - * - * - but there is more : you cannot directly blit a PM bitmap to the - * screen with PM. The 'GpiBlitBlt' only works with presentation - * spaces. This means that we also need to create, for each surface : - * - * - a memory presentation space, used to hold the PM bitmap - * - a "memory device context" for the presentation space - * - * The blit is then performed from the memory presentation space - * to the screen's presentation space.. - * - * - * - because each surface creates its own event-handling thread, - * we must protect the surface's presentation space from concurrent - * accesses (i.e. calls to 'GpiSetBitmapBits' when drawing to the - * surface, and calls to 'GpiBlitBlt' when drawing it on the screen - * are performed in two different threads). - * - * we use a simple mutex to do this. - * - * - * - we also use a semaphore to perform a rendez-vous between the - * main and event-handling threads (needed in "listen_event"). - * - ************************************************************************/ - - static - void RunPMWindow( grPMSurface* surface ); - - - - - static - void refresh_rectangle( grPMSurface* surface, - int x, - int y, - int w, - int h ) - { - LOG(( "Os2PM: refresh_rectangle( %08lx, %d, %d, %d, %d )\n", - (long)surface, x, y, w, h )); - - (void)x; - (void)y; - (void)w; - (void)h; - - /* - convert_rectangle( surface, x, y, w, h ); - */ - DosRequestMutexSem( surface->image_lock, SEM_INDEFINITE_WAIT ); - GpiSetBitmapBits( surface->image_ps, - 0, - surface->root.bitmap.rows, - surface->root.bitmap.buffer, - surface->bitmap_header ); - DosReleaseMutexSem( surface->image_lock ); - - WinInvalidateRect( surface->client_window, NULL, FALSE ); - WinUpdateWindow( surface->frame_window ); - } - - - static - void set_title( grPMSurface* surface, - const char* title ) - { - ULONG rc; - -#if 1 - LOG(( "Os2PM: set_title( %08lx == %08lx, %s )\n", - (long)surface, surface->client_window, title )); -#endif - LOG(( " -- frame = %08lx\n", - (long)surface->frame_window )); - - LOG(( " -- client parent = %08lx\n", - (long)WinQueryWindow( surface->client_window, QW_PARENT ) )); - - rc = WinSetWindowText( surface->client_window, (PSZ)title ); - LOG(( " -- returned rc = %ld\n",rc )); - } - - - - static - void listen_event( grPMSurface* surface, - int event_mask, - grEvent* grevent ) - { - ULONG ulRequestCount; - - (void) event_mask; /* ignored for now */ - - /* the listen_event function blocks until there is an event to process */ - DosWaitEventSem( surface->event_lock, SEM_INDEFINITE_WAIT ); - DosQueryEventSem( surface->event_lock, &ulRequestCount ); - *grevent = surface->event; - DosResetEventSem( surface->event_lock, &ulRequestCount ); - - return; - } - - - static - grPMSurface* init_surface( grPMSurface* surface, - grBitmap* bitmap ) - { - PBITMAPINFO2 bit; - SIZEL sizl = { 0, 0 }; - LONG palette[256]; - - LOG(( "Os2PM: init_surface( %08lx, %08lx )\n", - (long)surface, (long)bitmap )); - - LOG(( " -- input bitmap =\n" )); - LOG(( " -- mode = %d\n", bitmap->mode )); - LOG(( " -- grays = %d\n", bitmap->grays )); - LOG(( " -- width = %d\n", bitmap->width )); - LOG(( " -- height = %d\n", bitmap->rows )); - - /* create the bitmap - under OS/2, we support all modes as PM */ - /* handles all conversions automatically.. */ - if ( grNewBitmap( bitmap->mode, - bitmap->grays, - bitmap->width, - bitmap->rows, - bitmap ) ) - return 0; - - LOG(( " -- output bitmap =\n" )); - LOG(( " -- mode = %d\n", bitmap->mode )); - LOG(( " -- grays = %d\n", bitmap->grays )); - LOG(( " -- width = %d\n", bitmap->width )); - LOG(( " -- height = %d\n", bitmap->rows )); - - bitmap->pitch = -bitmap->pitch; - surface->root.bitmap = *bitmap; - - /* create the image and event lock */ - DosCreateEventSem( NULL, &surface->event_lock, 0, TRUE ); - DosCreateMutexSem( NULL, &surface->image_lock, 0, FALSE ); - - /* create the image's presentation space */ - surface->image_dc = DevOpenDC( gr_anchor, - OD_MEMORY, (PSZ)"*", 0L, 0L, 0L ); - - surface->image_ps = GpiCreatePS( gr_anchor, - surface->image_dc, - &sizl, - PU_PELS | GPIT_MICRO | - GPIA_ASSOC | GPIF_DEFAULT ); - - GpiSetBackMix( surface->image_ps, BM_OVERPAINT ); - - /* create the image's PM bitmap */ - bit = (PBITMAPINFO2)grAlloc( sizeof(BITMAPINFO2) + 256*sizeof(RGB2) ); - surface->bitmap_header = bit; - - bit->cbFix = sizeof( BITMAPINFOHEADER2 ); - bit->cx = surface->root.bitmap.width; - bit->cy = surface->root.bitmap.rows; - bit->cPlanes = 1; - - bit->argbColor[0].bBlue = 255; - bit->argbColor[0].bGreen = 0; - bit->argbColor[0].bRed = 0; - - bit->argbColor[1].bBlue = 0; - bit->argbColor[1].bGreen = 255; - bit->argbColor[1].bRed = 0; - - bit->cBitCount = (bitmap->mode == gr_pixel_mode_gray ? 8 : 1 ); - - if (bitmap->mode == gr_pixel_mode_gray) - { - RGB2* color = bit->argbColor; - int x, count; - - count = bitmap->grays; - for ( x = 0; x < count; x++, color++ ) - { - color->bBlue = - color->bGreen = - color->bRed = (((count-x)*255)/count); - } - } - else - { - RGB2* color = bit->argbColor; - - color[0].bBlue = - color[0].bGreen = - color[0].bRed = 0; - - color[1].bBlue = - color[1].bGreen = - color[1].bRed = 255; - } - - surface->os2_bitmap = GpiCreateBitmap( surface->image_ps, - (PBITMAPINFOHEADER2)bit, - 0L, NULL, NULL ); - - GpiSetBitmap( surface->image_ps, surface->os2_bitmap ); - - bit->cbFix = sizeof( BITMAPINFOHEADER2 ); - GpiQueryBitmapInfoHeader( surface->os2_bitmap, - (PBITMAPINFOHEADER2)bit ); - surface->bitmap_header = bit; - - /* for gr_pixel_mode_gray, create a gray-levels logical palette */ - if ( bitmap->mode == gr_pixel_mode_gray ) - { - int x, count; - - count = bitmap->grays; - for ( x = 0; x < count; x++ ) - palette[x] = (((count-x)*255)/count) * 0x010101; - - /* create logical color table */ - GpiCreateLogColorTable( surface->image_ps, - (ULONG) LCOL_PURECOLOR, - (LONG) LCOLF_CONSECRGB, - (LONG) 0L, - (LONG) count, - (PLONG) palette ); - - /* now, copy the color indexes to surface->shades */ - for ( x = 0; x < count; x++ ) - surface->shades[x] = GpiQueryColorIndex( surface->image_ps, - 0, palette[x] ); - } - - /* set up the blit points array */ - surface->blit_points[1].x = surface->root.bitmap.width; - surface->blit_points[1].y = surface->root.bitmap.rows; - surface->blit_points[3] = surface->blit_points[1]; - - window_created = 0; - - /* Finally, create the event handling thread for the surface's window */ - DosCreateThread( &surface->message_thread, - (PFNTHREAD) RunPMWindow, - (ULONG) surface, - 0UL, - 32920 ); - - /* wait for the window creation */ - for ( ; window_created == 0; ) - - surface->root.done = (grDoneSurfaceFunc) done_surface; - surface->root.refresh_rect = (grRefreshRectFunc) refresh_rectangle; - surface->root.set_title = (grSetTitleFunc) set_title; - surface->root.listen_event = (grListenEventFunc) listen_event; - - /* convert_rectangle( surface, 0, 0, bitmap->width, bitmap->rows ); */ - return surface; - } - - - - MRESULT EXPENTRY Message_Process( HWND handle, - ULONG mess, - MPARAM parm1, - MPARAM parm2 ); - - - static - void RunPMWindow( grPMSurface* surface ) - { - unsigned char class_name[] = "DisplayClass"; - ULONG class_flags; - - static HMQ queue; - QMSG message; - - /* store the current surface pointer in "the_surface". It is a static */ - /* variable that is only used to retrieve the pointer in the client */ - /* window procedure the first time is is called.. */ - the_surface = surface; - - LOG(( "Os2PM: RunPMWindow( %08lx )\n", (long)surface )); - - /* create an anchor to allow this thread to use PM */ - surface->anchor = WinInitialize(0); - if (!surface->anchor) - { - printf( "Error doing WinInitialize()\n" ); - return; - } - - /* create a message queue */ - queue = WinCreateMsgQueue( surface->anchor, 0 ); - if (!queue) - { - printf( "Error doing >inCreateMsgQueue()\n" ); - return; - } - - /* register the window class */ - if ( !WinRegisterClass( surface->anchor, - (PSZ) class_name, - (PFNWP) Message_Process, - CS_SIZEREDRAW, - 0 ) ) - { - printf( "Error doing WinRegisterClass()\n" ); - return; - } - - /* create the PM window */ - class_flags = FCF_TITLEBAR | FCF_MINBUTTON | FCF_DLGBORDER | - FCF_TASKLIST | FCF_SYSMENU; - - LOG(( "Os2PM: RunPMWindow: Creating window\n" )); - surface->frame_window = WinCreateStdWindow( - HWND_DESKTOP, - WS_VISIBLE, - &class_flags, - (PSZ) class_name, - (PSZ) "FreeType Viewer - press F1 for help", - WS_VISIBLE, - 0, 0, - &surface->client_window ); - if (!surface->frame_window) - { - printf( "Error doing WinCreateStdWindow()\n" ); - return; - } - - /* find the title window handle */ - surface->title_window = WinWindowFromID( surface->frame_window, - FID_TITLEBAR ); - LOG (( "Os2PM: RunPMWIndow: Creation succeeded\n" )); - LOG (( " -- frame = %08lx\n", surface->frame_window )); - LOG (( " -- client = %08lx\n", surface->client_window )); - - /* set Window size and position */ - WinSetWindowPos( surface->frame_window, - 0L, - (SHORT) 60, - - (SHORT) WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN ) - - (surface->root.bitmap.rows + 100), - - (SHORT) WinQuerySysValue( HWND_DESKTOP, SV_CYDLGFRAME )*2 + - surface->root.bitmap.width, - - (SHORT) WinQuerySysValue( HWND_DESKTOP, SV_CYTITLEBAR ) + - WinQuerySysValue( HWND_DESKTOP, SV_CYDLGFRAME )*2 + - surface->root.bitmap.rows, - - SWP_SIZE | SWP_MOVE ); - -#if 0 - /* save the handle to the current surface within the window words */ - WinSetWindowPtr( surface->client_window,QWL_USER, surface ); -#endif - - window_created = 1; - - /* run the message queue till the end */ - while ( WinGetMsg( surface->anchor, &message, (HWND)NULL, 0, 0 ) ) - { - WinDispatchMsg( surface->anchor, &message ); - } - - /* clean-up */ - WinDestroyWindow( surface->frame_window ); - surface->frame_window = 0; - - WinDestroyMsgQueue( queue ); - WinTerminate( surface->anchor ); - - /* await death... */ - while ( 1 ) - DosSleep( 100 ); - } - - - - - /* Message processing for our PM Window class */ - MRESULT EXPENTRY Message_Process( HWND handle, - ULONG mess, - MPARAM parm1, - MPARAM parm2 ) - { - static HDC screen_dc; - static HPS screen_ps; - static BOOL minimized; - - SIZEL sizl; - SWP swp; - - grPMSurface* surface; - - /* get the handle to the window's surface -- note that this */ - /* value will be null when the window is created */ - surface = (grPMSurface*)WinQueryWindowPtr( handle, QWL_USER ); - if (!surface) - { - surface = the_surface; - WinSetWindowPtr( handle, QWL_USER, surface ); - } - - switch( mess ) - { - case WM_DESTROY: - /* warn the main thread to quit if it didn't know */ - surface->event.type = gr_event_key; - surface->event.key = grKeyEsc; - DosPostEventSem( surface->event_lock ); - break; - - case WM_CREATE: - /* set original magnification */ - minimized = FALSE; - - /* create Device Context and Presentation Space for screen. */ - screen_dc = WinOpenWindowDC( handle ); - screen_ps = GpiCreatePS( surface->anchor, - screen_dc, - &sizl, - PU_PELS | GPIT_MICRO | - GPIA_ASSOC | GPIF_DEFAULT ); - /* take the input focus */ - WinFocusChange( HWND_DESKTOP, handle, 0L ); - LOG(( "screen_dc and screen_ps have been created\n" )); - break; - - case WM_MINMAXFRAME: - /* to update minimized if changed */ - swp = *((PSWP) parm1); - if ( swp.fl & SWP_MINIMIZE ) - minimized = TRUE; - if ( swp.fl & SWP_RESTORE ) - minimized = FALSE; - return WinDefWindowProc( handle, mess, parm1, parm2 ); - break; - - case WM_ERASEBACKGROUND: - case WM_PAINT: - /* copy the memory image of the screen out to the real screen */ - DosRequestMutexSem( surface->image_lock, SEM_INDEFINITE_WAIT ); - WinBeginPaint( handle, screen_ps, NULL ); - - /* main image and magnified picture */ - GpiBitBlt( screen_ps, - surface->image_ps, - 4L, - surface->blit_points, - ROP_SRCCOPY, BBO_AND ); - - WinEndPaint( screen_ps ); - DosReleaseMutexSem( surface->image_lock ); - break; - - case WM_HELP: /* this really is a F1 Keypress !! */ - surface->event.key = grKeyF1; - goto Do_Key_Event; - - case WM_CHAR: - if ( CHARMSG( &mess )->fs & KC_KEYUP ) - break; - - /* look for a specific vkey */ - { - int count = sizeof( key_translators )/sizeof( key_translators[0] ); - Translator* trans = key_translators; - Translator* limit = trans + count; - - for ( ; trans < limit; trans++ ) - if ( CHARMSG(&mess)->vkey == trans->os2key ) - { - surface->event.key = trans->grkey; - goto Do_Key_Event; - } - } - - /* otherwise, simply record the character code */ - if ( (CHARMSG( &mess )->fs & KC_CHAR) == 0 ) - break; - - surface->event.key = CHARMSG(&mess)->chr; - - Do_Key_Event: - surface->event.type = gr_event_key; - DosPostEventSem( surface->event_lock ); - break; - - default: - return WinDefWindowProc( handle, mess, parm1, parm2 ); - } - - return (MRESULT) FALSE; - } - - - - - grDevice gr_os2pm_device = - { - sizeof( grPMSurface ), - "os2pm", - - init_device, - done_device, - - (grDeviceInitSurfaceFunc) init_surface, - - 0, - 0 - - }; - - diff --git a/demos/graph/os2/gros2pm.def b/demos/graph/os2/gros2pm.def deleted file mode 100644 index 4a77c632c..000000000 --- a/demos/graph/os2/gros2pm.def +++ /dev/null @@ -1,5 +0,0 @@ -NAME WINDOWCOMPAT - -DESCRIPTION 'FreeType Graphics' -HEAPSIZE 8192 -STACKSIZE 40888 diff --git a/demos/graph/os2/gros2pm.h b/demos/graph/os2/gros2pm.h deleted file mode 100644 index 229358025..000000000 --- a/demos/graph/os2/gros2pm.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef GROS2PM_H -#define GROS2PM_H - -#include "grobjs.h" - - extern - grDevice gr_os2pm_device; - -#ifdef GR_INIT_BUILD - static - grDeviceChain gr_os2pm_device_chain = - { - "os2pm", - &gr_os2pm_device, - GR_INIT_DEVICE_CHAIN - }; - -#undef GR_INIT_DEVICE_CHAIN -#define GR_INIT_DEVICE_CHAIN &gr_os2pm_device_chain - -#endif /* GR_INIT_BUILD */ - -#endif /* GROS2PM_H */ diff --git a/demos/graph/os2/rules.mk b/demos/graph/os2/rules.mk deleted file mode 100644 index ffbf0158a..000000000 --- a/demos/graph/os2/rules.mk +++ /dev/null @@ -1,32 +0,0 @@ -#************************************************************************** -#* -#* OS/2 specific rules file, used to compile the OS/2 graphics driver -#* to the graphics subsystem -#* -#************************************************************************** - -ifeq ($(PLATFORM),os2) - -GR_OS2 := $(GRAPH_)os2 -GR_OS2_ := $(GR_OS2)$(SEP) - -# the GRAPH_LINK is expanded each time an executable is linked with the -# graphics library. -# -GRAPH_LINK += $(GR_OS2_)gros2pm.def - -# Add the OS/2 driver object file to the graphics library "graph.a" -# -GRAPH_OBJS += $(OBJ_)gros2pm.$O - -DEVICES += OS2_PM -DEVICE_INCLUDES += $(GR_OS2) - -# the rule used to compile the graphics driver -# -$(OBJ_)gros2pm.$O: $(GR_OS2_)gros2pm.c $(GR_OS2_)gros2pm.h - $(CC) $(CFLAGS) $(GRAPH_INCLUDES:%=$I%) $I$(GR_OS2) $T$@ $< - -endif - - diff --git a/demos/graph/rules.mk b/demos/graph/rules.mk deleted file mode 100644 index 5659d42eb..000000000 --- a/demos/graph/rules.mk +++ /dev/null @@ -1,104 +0,0 @@ -#************************************************************************** -#* -#* FreeType demo utilities sub-Makefile -#* -#* This Makefile is to be included by "freetype/demo/Makefile". Its -#* purpose is to compile MiGS (the Minimalist Graphics Subsystem) -#* -#* It is written for GNU Make. Other make utilities are not -#* supported.. !! -#* -#* -#* The following variables must be defined : -#* -#* CFLAGS : C flags to use when compiling the utilities. This -#* must NOT include the '-c' flag used to specify a -#* simple compilation. -#* -#* IFLAG : include path flag. This is typically "-I" but some -#* compilers use a different convention.. -#* -#* LFLAG : add link directory flag. Usually '-L' but could be -#* different.. -#* -#* OBJ_DIR : target location of the object files -#* -#* UTIL_DIR : location of the utilities sources. I.e. this -#* directory (usually "freetype/demo/graph"). -#* -#* -#* It also defines the following variables -#* -#* SIMPLE_UTILS : list of object files for the non-graphical utilities -#* -#* GRAPH_UTILS : all object files, including the graphics sub-system -#* -#* GRAPH_FLAGS : additional compile flags for graphical apps -#* GRAPH_LINK : additional link flags for graphical apps -#* -#************************************************************************** - -########################################################################## -# -# -# -# -# - -GRAPH_INCLUDES := $(TOP2_)graph -GRAPH_LIB := $(OBJ_)graph.$A -#GRAPH_LINK := $(GRAPH_LIB) - -GRAPH_ := $(TOP2_)graph$(SEP) - -GRAPH_H := $(GRAPH_)graph.h \ - $(GRAPH_)grtypes.h \ - $(GRAPH_)grobjs.h \ - $(GRAPH_)grdevice.h \ - $(GRAPH_)grblit.h - - -GRAPH_OBJS := $(OBJ_)grblit.$O \ - $(OBJ_)grobjs.$O \ - $(OBJ_)grfont.$O \ - $(OBJ_)grdevice.$O \ - $(OBJ_)grinit.$O - - -# Default value for COMPILE_GRAPH_LIB -# this value can be modified by the system-specific graphics drivers.. -# -COMPILE_GRAPH_LIB = ar -r $@ $(GRAPH_OBJS) - -# Add the rules used to detect and compile graphics driver depending -# on the current platform.. -# -include $(wildcard $(TOP2)/graph/*/rules.mk) - -######################################################################### -# -# Build the "graph" library from its objects. This should be changed -# in the future in order to support more systems. Probably something -# like a `config/' hierarchy with a system-specific rules file -# to indicate how to make a library file, but for now, I'll stick to -# unix, Win32 and OS/2-gcc.. -# -# -$(GRAPH_LIB): $(GRAPH_OBJS) - $(COMPILE_GRAPH_LIB) - - -# pattern rule for normal sources -# -$(OBJ_)%.$O: $(GRAPH_)%.c $(GRAPH_H) - $(CC) $(CFLAGS) $(GRAPH_INCLUDES:%=$I%) $T$@ $< - - -# a special rule is used for 'grinit.o' as it needs the definition -# of some macros like "-DDEVICE_X11" or "-DDEVICE_OS2_PM" -# -$(OBJ_)grinit.$O: $(GRAPH_)grinit.c $(GRAPH_H) - $(CC) $(CFLAGS) $(GRAPH_INCLUDES:%=$I%) \ - $(DEVICE_INCLUDES:%=$I%) \ - $(DEVICES:%=$DDEVICE_%) $T$@ $< - diff --git a/demos/graph/win32/grwin32.c b/demos/graph/win32/grwin32.c deleted file mode 100644 index 69b44d4c2..000000000 --- a/demos/graph/win32/grwin32.c +++ /dev/null @@ -1,525 +0,0 @@ -/******************************************************************* - * - * grwin32.c graphics driver for Win32 platform. 0.1 - * - * This is the driver for displaying inside a window under Win32, - * used by the graphics utility of the FreeType test suite. - * - * Written by Antoine Leca. - * Copyright 1999-2000 by Antoine Leca, David Turner - * David Turner, Robert Wilhelm, and Werner Lemberg. - * - * Borrowing liberally from the other FreeType drivers. - * - * This file is part of the FreeType project, and may only be used - * modified and distributed under the terms of the FreeType project - * license, LICENSE.TXT. By continuing to use, modify or distribute - * this file you indicate that you have read the license and - * understand and accept it fully. - * - ******************************************************************/ - -#include -#include -#include - -#define WIN32_LEAN_AND_MEAN -#include - -#include "grwin32.h" -#include "grdevice.h" - - -/* logging facility */ -#include - -#define DEBUGxxx - -#ifdef DEBUG -#define LOG(x) LogMessage##x -#else -#define LOG(x) /* rien */ -#endif - -#ifdef DEBUG - static void LogMessage( const char* fmt, ... ) - { - va_list ap; - - va_start( ap, fmt ); - vfprintf( stderr, fmt, ap ); - va_end( ap ); - } -#endif -/*-------------------*/ - -/* Size of the window. */ -#define WIN_WIDTH 640u -#define WIN_HEIGHT 450u - -/* These values can be changed, but WIN_WIDTH should remain for now a */ -/* multiple of 32 to avoid padding issues. */ - - typedef struct _Translator - { - ULONG winkey; - grKey grkey; - - } Translator; - - static - Translator key_translators[] = - { - { VK_BACK, grKeyBackSpace }, - { VK_TAB, grKeyTab }, - { VK_RETURN, grKeyReturn }, - { VK_ESCAPE, grKeyEsc }, - { VK_HOME, grKeyHome }, - { VK_LEFT, grKeyLeft }, - { VK_UP, grKeyUp }, - { VK_RIGHT, grKeyRight }, - { VK_DOWN, grKeyDown }, - { VK_PRIOR, grKeyPageUp }, - { VK_NEXT, grKeyPageDown }, - { VK_END, grKeyEnd }, - { VK_F1, grKeyF1 }, - { VK_F2, grKeyF2 }, - { VK_F3, grKeyF3 }, - { VK_F4, grKeyF4 }, - { VK_F5, grKeyF5 }, - { VK_F6, grKeyF6 }, - { VK_F7, grKeyF7 }, - { VK_F8, grKeyF8 }, - { VK_F9, grKeyF9 }, - { VK_F10, grKeyF10 }, - { VK_F11, grKeyF11 }, - { VK_F12, grKeyF12 } - }; - - static - Translator syskey_translators[] = - { - { VK_F1, grKeyF1 } - }; - - /* This is a minimalist driver, it is only able to display */ - /* a _single_ window. Moreover, only monochrome and gray */ - /* bitmaps are supported.. */ - - /* handle of the window. */ - static HWND hwndGraphic; - - static int window_width, window_height; - - /* the following variables are used to set the window title lazily */ - static int title_set = 1; - static const char* the_title; - - /* bitmap information */ - static LPBITMAPINFO pbmi; - static HBITMAP hbm; - - /* local event to pass on */ - static grEvent ourevent; - static int eventToProcess = 0; - -/* destroys the surface*/ -static -void done_surface( grSurface* surface ) -{ - /* The graphical window has perhaps already destroyed itself */ - if ( hwndGraphic ) - { - DestroyWindow ( hwndGraphic ); - PostMessage( hwndGraphic, WM_QUIT, 0, 0 ); - } - grDoneBitmap( &surface->bitmap ); - if ( pbmi ) free ( pbmi ); -} - - static - const int pixel_mode_bit_count[] = - { - 0, - 1, /* mono */ - 4, /* pal4 */ - 8, /* pal8 */ - 8, /* grays */ - 15, /* rgb15 */ - 16, /* rgb16 */ - 24, /* rgb24 */ - 32 /* rgb32 */ - }; - - static - void refresh_rectangle( grSurface* surface, - int x, - int y, - int w, - int h ) - { - HDC hDC; - int row_bytes; - - LOG(( "Win32: refresh_rectangle( %08lx, %d, %d, %d, %d )\n", - (long)surface, x, y, w, h )); - (void)x; - (void)y; - (void)w; - (void)h; - - row_bytes = surface->bitmap.pitch; - if (row_bytes < 0) row_bytes = -row_bytes; - - if ( row_bytes*8 != pbmi->bmiHeader.biWidth * pbmi->bmiHeader.biBitCount ) - pbmi->bmiHeader.biWidth = row_bytes * 8 / pbmi->bmiHeader.biBitCount; - - hDC = GetDC ( hwndGraphic ); - SetDIBits ( hDC, hbm, - 0, - surface->bitmap.rows, - surface->bitmap.buffer, - pbmi, - DIB_RGB_COLORS ); - - ReleaseDC ( hwndGraphic, hDC ); - - ShowWindow( hwndGraphic, SW_SHOW ); - InvalidateRect ( hwndGraphic, NULL, FALSE ); - UpdateWindow ( hwndGraphic ); - } - - static - void set_title( grSurface* surface, const char* title ) - { - (void)surface; - - /* the title will be set on the next listen_event, just */ - /* record it there.. */ - the_title = title; - title_set = 0; - } - - static - void listen_event( grSurface* surface, - int event_mask, - grEvent* grevent ) - { - MSG msg; - - (void)surface; - (void)event_mask; - - if ( hwndGraphic && !title_set ) - { - SetWindowText( hwndGraphic, the_title ); - title_set = 1; - } - - eventToProcess = 0; - while (GetMessage( &msg, 0, 0, 0 )) - { - TranslateMessage( &msg ); - DispatchMessage( &msg ); - if (eventToProcess) - break; - } - - *grevent = ourevent; - } - -/* - * set graphics mode - * and create the window class and the message handling. - */ - -/* Declarations of the Windows-specific functions that are below. */ -static BOOL RegisterTheClass ( void ); -static BOOL CreateTheWindow ( int width, int height ); - -static -grSurface* init_surface( grSurface* surface, - grBitmap* bitmap ) -{ - static RGBQUAD black = { 0, 0, 0, 0 }; - static RGBQUAD white = { 0xFF, 0xFF, 0xFF, 0 }; - - if( ! RegisterTheClass() ) return 0; /* if already running, fails. */ - - /* find some memory for the bitmap header */ - if ( (pbmi = malloc ( sizeof ( BITMAPINFO ) + sizeof ( RGBQUAD ) * 256 ) ) - /* 256 should really be 2 if not grayscale */ - == NULL ) - /* lack of memory; fails the process */ - return 0; - - LOG(( "Win32: init_surface( %08lx, %08lx )\n", - (long)surface, (long)bitmap )); - - LOG(( " -- input bitmap =\n" )); - LOG(( " -- mode = %d\n", bitmap->mode )); - LOG(( " -- grays = %d\n", bitmap->grays )); - LOG(( " -- width = %d\n", bitmap->width )); - LOG(( " -- height = %d\n", bitmap->rows )); - - /* create the bitmap - under Win32, we support all modes as the GDI */ - /* handles all conversions automatically.. */ - if ( grNewBitmap( bitmap->mode, - bitmap->grays, - bitmap->width, - bitmap->rows, - bitmap ) ) - return 0; - - LOG(( " -- output bitmap =\n" )); - LOG(( " -- mode = %d\n", bitmap->mode )); - LOG(( " -- grays = %d\n", bitmap->grays )); - LOG(( " -- width = %d\n", bitmap->width )); - LOG(( " -- height = %d\n", bitmap->rows )); - - bitmap->pitch = -bitmap->pitch; - surface->bitmap = *bitmap; - - /* initialize the header to appropriate values */ - memset( pbmi, 0, sizeof ( BITMAPINFO ) + sizeof ( RGBQUAD ) * 256 ); - - switch ( bitmap->mode ) - { - case gr_pixel_mode_mono: - pbmi->bmiHeader.biBitCount = 1; - pbmi->bmiColors[0] = white; - pbmi->bmiColors[1] = black; - break; - - case gr_pixel_mode_gray: - pbmi->bmiHeader.biBitCount = 8; - pbmi->bmiHeader.biClrUsed = bitmap->grays; - { - int count = bitmap->grays; - int x; - RGBQUAD* color = pbmi->bmiColors; - - for ( x = 0; x < count; x++, color++ ) - { - color->rgbRed = - color->rgbGreen = - color->rgbBlue = (((count-x)*255)/count); - color->rgbReserved = 0; - } - } - break; - - default: - free ( pbmi ); - return 0; /* Unknown mode */ - } - - pbmi->bmiHeader.biSize = sizeof ( BITMAPINFOHEADER ); - pbmi->bmiHeader.biWidth = bitmap->width; - pbmi->bmiHeader.biHeight = bitmap->rows; - pbmi->bmiHeader.biPlanes = 1; - - if( ! CreateTheWindow( bitmap->width, bitmap->rows ) ) - { - free ( pbmi ); - return 0; - } - - surface->done = (grDoneSurfaceFunc) done_surface; - surface->refresh_rect = (grRefreshRectFunc) refresh_rectangle; - surface->set_title = (grSetTitleFunc) set_title; - surface->listen_event = (grListenEventFunc) listen_event; - - return surface; -} - - -/* ---- Windows-specific stuff ------------------------------------------- */ - -LRESULT CALLBACK Message_Process( HWND, UINT, WPARAM, LPARAM ); - -static -BOOL RegisterTheClass ( void ) - { - WNDCLASS ourClass = { - /* UINT style */ 0, - /* WNDPROC lpfnWndProc */ Message_Process, - /* int cbClsExtra */ 0, - /* int cbWndExtra */ 0, - /* HANDLE hInstance */ 0, - /* HICON hIcon */ 0, - /* HCURSOR hCursor */ 0, - /* HBRUSH hbrBackground*/ 0, - /* LPCTSTR lpszMenuName */ NULL, - /* LPCTSTR lpszClassName*/ "FreeTypeTestGraphicDriver" - }; - - ourClass.hInstance = GetModuleHandle( NULL ); - ourClass.hIcon = LoadIcon(0, IDI_APPLICATION); - ourClass.hCursor = LoadCursor(0, IDC_ARROW); - ourClass.hbrBackground= GetStockObject(BLACK_BRUSH); - - return RegisterClass(&ourClass) != 0; /* return False if it fails. */ - } - -static -BOOL CreateTheWindow ( int width, int height ) - { - window_width = width; - window_height = height; - - if ( ! (hwndGraphic = CreateWindow( - /* LPCSTR lpszClassName; */ "FreeTypeTestGraphicDriver", - /* LPCSTR lpszWindowName; */ "FreeType Test Graphic Driver", - /* DWORD dwStyle; */ WS_OVERLAPPED | WS_SYSMENU, - /* int x; */ CW_USEDEFAULT, - /* int y; */ CW_USEDEFAULT, - /* int nWidth; */ width + 2*GetSystemMetrics(SM_CXBORDER), - /* int nHeight; */ height+ GetSystemMetrics(SM_CYBORDER) - + GetSystemMetrics(SM_CYCAPTION), - /* HWND hwndParent; */ HWND_DESKTOP, - /* HMENU hmenu; */ 0, - /* HINSTANCE hinst; */ GetModuleHandle( NULL ), - /* void FAR* lpvParam; */ NULL)) - ) - /* creation failed... */ - return 0; - - return 1; - } - - /* Message processing for our Windows class */ -LRESULT CALLBACK Message_Process( HWND handle, UINT mess, - WPARAM wParam, LPARAM lParam ) - { - - switch( mess ) - { - case WM_DESTROY: - /* warn the main thread to quit if it didn't know */ - ourevent.type = gr_event_key; - ourevent.key = grKeyEsc; - eventToProcess = 1; - hwndGraphic = 0; - PostQuitMessage ( 0 ); - DeleteObject ( hbm ); - return 0; - - case WM_CREATE: - { - HDC hDC; - - hDC = GetDC ( handle ); - hbm = CreateDIBitmap ( - /* HDC hdc; handle of device context */ hDC, - /* BITMAPINFOHEADER FAR* lpbmih; addr.of header*/ &pbmi->bmiHeader, - /* DWORD dwInit; CBM_INIT to initialize bitmap */ 0, - /* const void FAR* lpvBits; address of values */ NULL, - /* BITMAPINFO FAR* lpbmi; addr.of bitmap data */ pbmi, - /* UINT fnColorUse; RGB or palette indices */ DIB_RGB_COLORS); - ReleaseDC ( handle, hDC ); - break; - } - - case WM_PAINT: - { - HDC hDC, memDC; - HANDLE oldbm; - PAINTSTRUCT ps; - - hDC = BeginPaint ( handle, &ps ); - memDC = CreateCompatibleDC(hDC); - oldbm = SelectObject(memDC, hbm); - BitBlt ( hDC, 0, 0, window_width, window_height, memDC, 0, 0, SRCCOPY); - ReleaseDC ( handle, hDC ); - SelectObject ( memDC, oldbm ); - DeleteObject ( memDC ); - EndPaint ( handle, &ps ); - return 0; - } - - case WM_SYSKEYDOWN: - { - int count = sizeof( syskey_translators )/sizeof( syskey_translators[0] ); - Translator* trans = syskey_translators; - Translator* limit = trans + count; - for ( ; trans < limit; trans++ ) - if ( wParam == trans->winkey ) - { - ourevent.key = trans->grkey; - goto Do_Key_Event; - } - return DefWindowProc( handle, mess, wParam, lParam ); - } - - - case WM_KEYDOWN: - switch ( wParam ) - { - case VK_ESCAPE: - ourevent.type = gr_event_key; - ourevent.key = grKeyEsc; - eventToProcess = 1; - PostQuitMessage ( 0 ); - return 0; - - default: - /* lookup list of translated keys */ - { - int count = sizeof( key_translators )/sizeof( key_translators[0] ); - Translator* trans = key_translators; - Translator* limit = trans + count; - for ( ; trans < limit; trans++ ) - if ( wParam == trans->winkey ) - { - ourevent.key = trans->grkey; - goto Do_Key_Event; - } - } - - /* the key isn't found, default processing */ - /* return DefWindowProc( handle, mess, wParam, lParam ); */ - return DefWindowProc( handle, mess, wParam, lParam ); - } - - case WM_CHAR: - { - ourevent.key = wParam; - - Do_Key_Event: - ourevent.type = gr_event_key; - eventToProcess = 1; - } - break; - - default: - return DefWindowProc( handle, mess, wParam, lParam ); - } - return 0; - } - - static int init_device( void ) - { - return 0; - } - - static void done_device( void ) - { - } - - grDevice gr_win32_device = - { - sizeof( grSurface ), - "win32", - - init_device, - done_device, - - (grDeviceInitSurfaceFunc) init_surface, - - 0, - 0 - }; - - -/* End */ diff --git a/demos/graph/win32/grwin32.h b/demos/graph/win32/grwin32.h deleted file mode 100644 index 028d1a993..000000000 --- a/demos/graph/win32/grwin32.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef GRWIN32_H -#define GRWIN32_H - -#include "grobjs.h" - - extern - grDevice gr_win32_device; - -#ifdef GR_INIT_BUILD - static - grDeviceChain gr_win32_device_chain = - { - "win32", - &gr_win32_device, - GR_INIT_DEVICE_CHAIN - }; - -#undef GR_INIT_DEVICE_CHAIN -#define GR_INIT_DEVICE_CHAIN &gr_win32_device_chain - -#endif /* GR_INIT_BUILD */ - -#endif /* GRWIN32_H */ diff --git a/demos/graph/win32/rules.mk b/demos/graph/win32/rules.mk deleted file mode 100644 index 2c177c548..000000000 --- a/demos/graph/win32/rules.mk +++ /dev/null @@ -1,52 +0,0 @@ -#************************************************************************** -#* -#* Win32 specific rules file, used to compile the Win32 graphics driver -#* to the graphics subsystem -#* -#************************************************************************** - -ifeq ($(PLATFORM),win32) - -# directory of the Win32 graphics driver -# -GR_WIN32 := $(GRAPH_)win32 -GR_WIN32_ := $(GR_WIN32)$(SEP) - -# Add the Win32 driver object file to the graphics library "graph.a" -# -GRAPH_OBJS += $(OBJ_)grwin32.$O - -DEVICES += WIN32 -DEVICE_INCLUDES += $(GR_WIN32) - -# the rule used to compile the graphics driver -# -$(OBJ_)grwin32.$O: $(GR_WIN32_)grwin32.c $(GR_WIN32_)grwin32.h - $(CC) $(CFLAGS) $(GRAPH_INCLUDES:%=$I%) $I$(GR_WIN32) $T$@ $< - -# Now update COMPILE_GRAPH_LIB according to the compiler used on Win32 -# -ifeq ($(firstword $(CC)),gcc) # test for GCC -LINK = $(CC) $T$@ $< $(FTLIB) -COMMON_LINK = $(LINK) $(COMMON_OBJ) -GRAPH_LINK = $(COMMON_LINK) $(GRAPH_LIB) -luser32 -lgdi32 -endif - -ifeq ($(CC),cl) # test for Visual C++ -COMPILE_GRAPH_LIB = lib /nologo /out:$(GRAPH_LIB) $(GRAPH_OBJS) -LINK = cl /nologo /MD -o $@ $< $(FTLIB) -COMMON_LINK = $(LINK) $(COMMON_OBJ) -GRAPH_LINK = $(COMMON_LINK) $(GRAPH_LIB) user32.lib gdi32.lib -endif - -ifeq ($(CC),lcc) # test for LCC-Win32 -COMPILE_GRAPH_LIB = lcclib /out:$(subst /,\\,$(GRAPH_LIB)) $(subst /,\\,$(GRAPH_OBJS)) -GRAPH_LINK = $(subst /,\\,$(GRAPH_LIB)) user32.lib gdi32.lib -LINK_ROOT = lcclnk -o $(subst /,\\,$@) $(subst /,\\,$<) -LINK = $(LINK_ROOT) $(subst /,\\,$(FTLIB)) -COMMON_LINK = $(LINK_ROOT) $(subst /,\\,$(COMMON_OBJ)) $(subst /,\\,$(FTLIB)) -GRAPH_LINK = $(LINK_ROOT) $(subst /,\\,$(COMMON_OBJ)) $(subst /,\\,$(GRAPH_LIB)) $(subst /,\\,$(FTLIB)) -GRAPH_LINK2 = $(GRAPH_LINK) $(subst /,\\,$(EXTRA_GRAPH_OBJS)) -endif -endif - diff --git a/demos/graph/x11/grx11.c b/demos/graph/x11/grx11.c deleted file mode 100644 index 65f06da98..000000000 --- a/demos/graph/x11/grx11.c +++ /dev/null @@ -1,981 +0,0 @@ -#include "grx11.h" - -#define TEST - -#ifdef TEST -#include "grfont.h" -#endif - -#include -#include -#include -#include -#include -#include -#include - - static void Panic( const char* message ) - { - fprintf( stderr, "%s", message ); - exit(1); - } - - typedef struct Translator - { - KeySym xkey; - grKey grkey; - - } Translator; - - static - Translator key_translators[] = - { - { XK_BackSpace, grKeyBackSpace }, - { XK_Tab, grKeyTab }, - { XK_Return, grKeyReturn }, - { XK_Escape, grKeyEsc }, - { XK_Home, grKeyHome }, - { XK_Left, grKeyLeft }, - { XK_Up, grKeyUp }, - { XK_Right, grKeyRight }, - { XK_Down, grKeyDown }, - { XK_Page_Up, grKeyPageUp }, - { XK_Page_Down, grKeyPageDown }, - { XK_End, grKeyEnd }, - { XK_Begin, grKeyHome }, - { XK_F1, grKeyF1 }, - { XK_F2, grKeyF2 }, - { XK_F3, grKeyF3 }, - { XK_F4, grKeyF4 }, - { XK_F5, grKeyF5 }, - { XK_F6, grKeyF6 }, - { XK_F7, grKeyF7 }, - { XK_F8, grKeyF8 }, - { XK_F9, grKeyF9 }, - { XK_F10, grKeyF10 }, - { XK_F11, grKeyF11 }, - { XK_F12, grKeyF12 } - }; - - -#ifdef TEST - -#define grAlloc malloc - -#endif - - - static Display* display; - static char* displayname = ""; - - static Cursor idle; - static Cursor busy; - -#define MAX_PIXEL_MODES 32 - - typedef XPixmapFormatValues XDepth; - - static int num_pixel_modes = 0; - static grPixelMode pixel_modes[ MAX_PIXEL_MODES ]; - static XDepth pixel_depth[ MAX_PIXEL_MODES ]; - - typedef struct grXSurface_ - { - grSurface root; - grBitmap image; - - Window win; - Visual* visual; - Colormap colormap; - int depth; - XDepth* xdepth; - Bool gray; - - GC gc; - - XColor color[256]; /* gray levels palette for 8-bit modes */ - XImage* ximage; - - int win_org_x; - int win_org_y; - int win_width; - int win_height; - - int image_width; - int image_height; - - } grXSurface; - - - - - /* close a given window */ - static - void done_surface( grXSurface* surface ) - { - XUnmapWindow( display, surface->win ); - } - - - - /* close the device, i.e. the display connection */ - static - void done_device( void ) - { - XCloseDisplay( display ); - } - - - - static - void add_pixel_mode( grPixelMode pixel_mode, - XDepth* depth ) - { - if ( num_pixel_modes >= MAX_PIXEL_MODES ) - Panic( "X11.Too many pixel modes\n" ); - - pixel_modes[ num_pixel_modes ] = pixel_mode; - pixel_depth[ num_pixel_modes ] = *depth; - - num_pixel_modes++; - } - - - - static - int init_device( void ) - { - XDepth dummy; - - XrmInitialize(); - - display = XOpenDisplay( displayname ); - if (!display) - { - return -1; - /* Panic( "Gr:error: cannot open X11 display\n" ); */ - } - - idle = XCreateFontCursor( display, XC_left_ptr ); - busy = XCreateFontCursor( display, XC_watch ); - - num_pixel_modes = 0; - - /* always enable the 8-bit gray levels pixel mode */ - /* even if its display is emulated through a constrained palette */ - /* or another color mode */ - dummy.depth = 8; - dummy.bits_per_pixel = 8; - dummy.scanline_pad = 8; - add_pixel_mode( gr_pixel_mode_gray, &dummy ); - - { - int count; - XDepth* format; - XDepth* formats; - XVisualInfo template; - - formats = XListPixmapFormats( display, &count ); - format = formats; - -#ifdef TEST - printf( "available pixmap formats\n" ); - printf( "depth pixbits scanpad\n" ); -#endif - - while ( count-- > 0 ) - { -#ifdef TEST - printf( " %3d %3d %3d\n", - format->depth, - format->bits_per_pixel, - format->scanline_pad ); -#endif - - if ( format->depth == 1 ) - /* usually, this should be the first format */ - add_pixel_mode( gr_pixel_mode_mono, format ); - - else if ( format->depth == 8 ) - add_pixel_mode( gr_pixel_mode_pal8, format ); - - /* note, the 32-bit modes return a depth of 24, and 32 bits per pixel */ - else if ( format->depth == 24 ) - { -#ifdef TEST - { - int count2; - XVisualInfo* visuals; - XVisualInfo* visual; - const char* string = "unknown"; - - template.depth = format->depth; - visuals = XGetVisualInfo( display, - VisualDepthMask, - &template, - &count2 ); - visual = visuals; - - switch (visual->class) - { - case TrueColor: string = "TrueColor"; break; - case DirectColor: string = "DirectColor"; break; - case PseudoColor: string = "PseudoColor"; break; - case StaticGray : string = "StaticGray"; break; - case StaticColor: string = "StaticColor"; break; - case GrayScale: string = "GrayScale"; break; - } - - printf( "> RGB %04lx:%04lx:%04lx, colors %3d, bits %2d %s\n", - visual->red_mask, - visual->green_mask, - visual->blue_mask, - visual->colormap_size, - visual->bits_per_rgb, - string ); - visual++; - } -#endif - if ( format->bits_per_pixel == 24 ) - add_pixel_mode( gr_pixel_mode_rgb24, format ); - - else if ( format->bits_per_pixel == 32 ) - add_pixel_mode( gr_pixel_mode_rgb32, format ); - } - - else if ( format->depth == 16 ) - { - int count2; - XVisualInfo* visuals; - XVisualInfo* visual; - - template.depth = format->depth; - visuals = XGetVisualInfo( display, - VisualDepthMask, - &template, - &count2 ); - visual = visuals; - - while ( count2-- > 0 ) - { -#ifdef TEST - const char* string = "unknown"; - - switch (visual->class) - { - case TrueColor: string = "TrueColor"; break; - case DirectColor: string = "DirectColor"; break; - case PseudoColor: string = "PseudoColor"; break; - case StaticGray : string = "StaticGray"; break; - case StaticColor: string = "StaticColor"; break; - case GrayScale: string = "GrayScale"; break; - } - - printf( "> RGB %04lx:%04lx:%04lx, colors %3d, bits %2d %s\n", - visual->red_mask, - visual->green_mask, - visual->blue_mask, - visual->colormap_size, - visual->bits_per_rgb, - string ); - -#endif - if ( visual->red_mask == 0xf800 && - visual->green_mask == 0x07e0 && - visual->blue_mask == 0x001f ) - add_pixel_mode( gr_pixel_mode_rgb565, format ); - - else if ( visual->red_mask == 0x7c00 && - visual->green_mask == 0x03e0 && - visual->blue_mask == 0x001f ) - add_pixel_mode( gr_pixel_mode_rgb555, format ); - - /* other 16-bit modes are ignored */ - visual++; - } - - XFree( visuals ); - } - - format++; - } - - XFree( formats ); - } - - gr_x11_device.num_pixel_modes = num_pixel_modes; - gr_x11_device.pixel_modes = pixel_modes; - - return 0; - } - - - - - - - - static - void convert_gray_to_pal8( grXSurface* surface, - int x, - int y, - int w, - int h ) - { - grBitmap* target = &surface->image; - grBitmap* source = &surface->root.bitmap; - byte* write = (byte*)target->buffer + y*target->pitch + x; - byte* read = (byte*)source->buffer + y*source->pitch + x; - XColor* palette = surface->color; - - while (h > 0) - { - byte* _write = write; - byte* _read = read; - byte* limit = _write + w; - - for ( ; _write < limit; _write++, _read++ ) - *_write = (byte) palette[ *_read ].pixel; - - write += target->pitch; - read += source->pitch; - h--; - } - } - - - static - void convert_gray_to_16( grXSurface* surface, - int x, - int y, - int w, - int h ) - { - grBitmap* target = &surface->image; - grBitmap* source = &surface->root.bitmap; - byte* write = (byte*)target->buffer + y*target->pitch + 2*x; - byte* read = (byte*)source->buffer + y*source->pitch + x; - XColor* palette = surface->color; - - while (h > 0) - { - byte* _write = write; - byte* _read = read; - byte* limit = _write + 2*w; - - for ( ; _write < limit; _write += 2, _read++ ) - *(short*)_write = (short)palette[ *_read ].pixel; - - write += target->pitch; - read += source->pitch; - h--; - } - } - - - static - void convert_gray_to_24( grXSurface* surface, - int x, - int y, - int w, - int h ) - { - grBitmap* target = &surface->image; - grBitmap* source = &surface->root.bitmap; - byte* write = (byte*)target->buffer + y*target->pitch + 3*x; - byte* read = (byte*)source->buffer + y*source->pitch + x; - - while (h > 0) - { - byte* _write = write; - byte* _read = read; - byte* limit = _write + 3*w; - - for ( ; _write < limit; _write += 3, _read++ ) - { - XColor* color = surface->color + *_read; - - _write[0] = color->red; - _write[1] = color->green; - _write[2] = color->blue; - } - - write += target->pitch; - read += source->pitch; - h--; - } - } - - - static - void convert_gray_to_32( grXSurface* surface, - int x, - int y, - int w, - int h ) - { - grBitmap* target = &surface->image; - grBitmap* source = &surface->root.bitmap; - byte* write = (byte*)target->buffer + y*target->pitch + 4*x; - byte* read = (byte*)source->buffer + y*source->pitch + x; - - while (h > 0) - { - byte* _write = write; - byte* _read = read; - byte* limit = _write + 4*w; - - if (sizeof(long) > 4) - { - for ( ; _write < limit; _write += 4, _read++ ) - { - byte color = *_read; - - *(unsigned int*)_write = surface->color[color].pixel; - } - } - else - { - for ( ; _write < limit; _write += 4, _read++ ) - { - byte color = *_read; - - *(unsigned long*)_write = surface->color[color].pixel; - } - } - - write += target->pitch; - read += source->pitch; - h--; - } - } - - - static - void convert_rectangle( grXSurface* surface, - int x, - int y, - int w, - int h ) - { - int z; - - /* first of all, clip to the surface's area */ - if ( x >= surface->image.width || - x+w <= 0 || - y >= surface->image.rows || - y+h <= 0 ) - return; - - if ( x < 0 ) - { - w += x; - x = 0; - } - - z = (x + w) - surface->image.width; - if (z > 0) - w -= z; - - z = (y + h) - surface->image.rows; - if (z > 0) - h -= z; - - /* convert the rectangle to the target depth for gray surfaces */ - if (surface->gray) - { - switch (surface->xdepth->bits_per_pixel) - { - case 8 : convert_gray_to_pal8( surface, x, y, w, h ); break; - case 16: convert_gray_to_16 ( surface, x, y, w, h ); break; - case 24: convert_gray_to_24 ( surface, x, y, w, h ); break; - case 32: convert_gray_to_32 ( surface, x, y, w, h ); break; - } - } - } - - - static - void refresh_rectangle( grXSurface* surface, - int x, - int y, - int w, - int h ) - { - if (surface->gray) - convert_rectangle( surface, x, y, w, h ); - - XPutImage( display, - surface->win, - surface->gc, - surface->ximage, - x, y, x, y, w, h ); - } - - - static - void set_title( grXSurface* surface, - const char* title ) - { - XStoreName( display, surface->win, title ); - } - - - - static - grKey KeySymTogrKey( KeySym key ) - { - grKey k; - int count = sizeof(key_translators)/sizeof(key_translators[0]); - Translator* trans = key_translators; - Translator* limit = trans + count; - - k = grKeyNone; - - while ( trans < limit ) - { - if ( trans->xkey == key ) - { - k = trans->grkey; - break; - } - trans++; - } - - return k; - } - - - - static - void listen_event( grXSurface* surface, - int event_mask, - grEvent* grevent ) - { - static char key_buffer[10]; - static int key_cursor = 0; - static int key_number = 0; - static XEvent x_event; - KeySym key; - - int bool_exit; - grKey grkey; - - XComposeStatus compose; - - /* XXXX : For now, ignore the event mask, and only exit when */ - /* a key is pressed.. */ - (void)event_mask; - - bool_exit = key_cursor < key_number; - - XDefineCursor( display, surface->win, idle ); - - while ( !bool_exit ) - { - XNextEvent( display, &x_event ); - - switch ( x_event.type ) - { - case KeyPress: - key_number = XLookupString( &x_event.xkey, - key_buffer, - sizeof ( key_buffer ), - &key, - &compose ); - key_cursor = 0; - - if ( key_number == 0 || - key > 512 ) - { - /* this may be a special key like F1, F2, etc.. */ - grkey = KeySymTogrKey(key); - if (grkey != grKeyNone) - goto Set_Key; - } - else - bool_exit = 1; - break; - - case MappingNotify: - XRefreshKeyboardMapping( &x_event.xmapping ); - break; - - case Expose: - refresh_rectangle( surface, - x_event.xexpose.x, - x_event.xexpose.y, - x_event.xexpose.width, - x_event.xexpose.height ); - break; - - /* You should add more cases to handle mouse events, etc. */ - } - } - - XDefineCursor( display, surface->win, busy ); - XFlush ( display ); - - /* Now, translate the keypress to a grKey */ - /* If this wasn't part of the simple translated keys, simply get the charcode */ - /* from the character buffer */ - grkey = grKEY(key_buffer[key_cursor++]); - - Set_Key: - grevent->type = gr_key_down; - grevent->key = grkey; - } - - - - - grXSurface* init_surface( grXSurface* surface, - grBitmap* bitmap ) - { - int screen; - grBitmap* image; - char grays; - XDepth* format; - int image_depth; - - screen = DefaultScreen( display ); - - surface->colormap = DefaultColormap( display, screen ); - surface->depth = DefaultDepth( display, screen ); - surface->visual = DefaultVisual( display, screen ); - - image = &surface->image; - - /* force the surface image depth to 1 if necessary */ - /* as this should be supported by all windows */ - image_depth = surface->depth; - if (bitmap->mode == gr_pixel_mode_mono) - image_depth = 1; - - grays = ( bitmap->mode == gr_pixel_mode_gray && - bitmap->grays >= 2 ); - - surface->gray = grays; - - /* copy dimensions */ - image->width = bitmap->width; - image->rows = bitmap->rows; - image->mode = bitmap->mode; - image->pitch = 0; - image->grays = 0; - image->buffer = 0; - - /* find the supported format corresponding to the request */ - format = 0; - - if (grays) - { - /* choose the default depth in case of grays rendering */ - int i; - for ( i = 0; i < num_pixel_modes; i++ ) - if ( image_depth == pixel_depth[i].depth ) - { - format = pixel_depth + i; - surface->xdepth = format; - break; - } - } - else - { - /* otherwise, select the format depending on the pixel mode */ - int i; - - format = 0; - for ( i = 0; i < num_pixel_modes; i++ ) - if ( pixel_modes[i] == bitmap->mode ) - { - format = pixel_depth + i; - surface->xdepth = format; - break; - } - } - - if (!format) - { - grError = gr_err_bad_argument; - return 0; - } - - - /* correct surface.depth. This is required because in the case */ - /* of 32-bits pixels, the value of "format.depth" is 24 under X11 */ - if ( format->depth == 24 && - format->bits_per_pixel == 32 ) - image_depth = 32; - - /* allocate surface image */ - { - int bits, over; - - bits = image->width * format->bits_per_pixel; - over = bits % format->scanline_pad; - - if (over) - bits += format->scanline_pad - over; - - if (!grays) - { - image->width = bits; - bitmap->width = bits; - } - image->pitch = bits >> 3; - } - - image->buffer = grAlloc( image->pitch * image->rows ); - if (!image->buffer) return 0; - - /* now, allocate a gray pal8 pixmap, only when we asked */ - /* for an 8-bit pixmap */ - if ( grays ) - { - /* pad pitch to 32 bits */ - bitmap->pitch = (bitmap->width + 3) & -4; - bitmap->buffer = grAlloc( bitmap->pitch * bitmap->rows ); - if (!bitmap->buffer) - Panic( "grX11: could not allocate surface bitmap!\n" ); - } - else /* otherwise */ - { - *bitmap = *image; - } - - surface->root.bitmap = *bitmap; - - /* Now create the surface X11 image */ - surface->ximage = XCreateImage( display, - surface->visual, - format->depth, - format->depth == 1 ? XYBitmap : ZPixmap, - 0, - (char*)image->buffer, - image->width, - image->rows, - 8, - 0 ); - if ( !surface->ximage ) - Panic( "grX11: cannot create surface X11 image\n" ); - - - /* allocate gray levels in the case of gray surface */ - if ( grays ) - { - XColor* color = surface->color; - int i; - - for ( i = 0; i < bitmap->grays; i++, color++ ) - { - color->red = - color->green = - color->blue = 65535 - ( i * 65535 ) / bitmap->grays; - - if ( !XAllocColor( display, surface->colormap, color ) ) - Panic( "ERROR: cannot allocate Color\n" ); - } - } - else if ( image_depth == 1 ) - { - surface->ximage->byte_order = MSBFirst; - surface->ximage->bitmap_bit_order = MSBFirst; - } - - { - XTextProperty xtp; - XSizeHints xsh; - XSetWindowAttributes xswa; - - xswa.border_pixel = BlackPixel( display, screen ); - xswa.background_pixel = WhitePixel( display, screen ); - xswa.cursor = busy; - - xswa.event_mask = KeyPressMask | ExposureMask; - - surface->win = XCreateWindow( display, - RootWindow( display, screen ), - 0, - 0, - image->width, - image->rows, - 10, - surface->depth, - InputOutput, - surface->visual, - CWBackPixel | CWBorderPixel | - CWEventMask | CWCursor, - &xswa ); - - XMapWindow( display, surface->win ); - - surface->gc = XCreateGC( display, RootWindow( display, screen ), 0L, NULL ); - XSetForeground( display, surface->gc, xswa.border_pixel ); - XSetBackground( display, surface->gc, xswa.background_pixel ); - - - /* make window manager happy :-) */ - xtp.value = (unsigned char*)"FreeType"; - xtp.encoding = 31; - xtp.format = 8; - xtp.nitems = strlen( (char*)xtp.value ); - - xsh.x = 0; - xsh.y = 0; - - xsh.width = image->width; - xsh.height = image->rows; - xsh.flags = (PPosition | PSize); - xsh.flags = 0; - - XSetWMProperties( display, surface->win, &xtp, &xtp, NULL, 0, &xsh, NULL, NULL ); - } - - surface->root.done = (grDoneSurfaceFunc) done_surface; - surface->root.refresh_rect = (grRefreshRectFunc) refresh_rectangle; - surface->root.set_title = (grSetTitleFunc) set_title; - surface->root.listen_event = (grListenEventFunc) listen_event; - - convert_rectangle( surface, 0, 0, bitmap->width, bitmap->rows ); - return surface; - } - - - - - grDevice gr_x11_device = - { - sizeof( grXSurface ), - "x11", - - init_device, - done_device, - - (grDeviceInitSurfaceFunc) init_surface, - - 0, - 0 - - }; - -#ifdef TEST - -typedef struct grKeyName -{ - grKey key; - const char* name; - -} grKeyName; - - -static -const grKeyName key_names[] = -{ - { grKeyF1, "F1" }, - { grKeyF2, "F2" }, - { grKeyF3, "F3" }, - { grKeyF4, "F4" }, - { grKeyF5, "F5" }, - { grKeyF6, "F6" }, - { grKeyF7, "F7" }, - { grKeyF8, "F8" }, - { grKeyF9, "F9" }, - { grKeyF10, "F10" }, - { grKeyF11, "F11" }, - { grKeyF12, "F12" }, - { grKeyEsc, "Esc" }, - { grKeyHome, "Home" }, - { grKeyEnd, "End" }, - - { grKeyPageUp, "Page_Up" }, - { grKeyPageDown, "Page_Down" }, - { grKeyLeft, "Left" }, - { grKeyRight, "Right" }, - { grKeyUp, "Up" }, - { grKeyDown, "Down" }, - { grKeyBackSpace, "BackSpace" }, - { grKeyReturn, "Return" } -}; - -#if 0 -int main( void ) -{ - grSurface* surface; - int n; - - grInit(); - surface = grNewScreenSurface( 0, gr_pixel_mode_gray, 320, 400, 128 ); - if (!surface) - Panic("Could not create window\n" ); - else - { - grColor color; - grEvent event; - const char* string; - int x; - - grSetSurfaceRefresh( surface, 1 ); - grSetTitle(surface,"X11 driver demonstration" ); - - for ( x = -10; x < 10; x++ ) - { - for ( n = 0; n < 128; n++ ) - { - color.value = (n*3) & 127; - grWriteCellChar( surface, - x + ((n % 60) << 3), - 80 + (x+10)*8*3 + ((n/60) << 3), n, color ); - } - - } - color.value = 64; - grWriteCellString( surface, 0, 0, "just an example", color ); - - do - { - listen_event((grXSurface*)surface, 0, &event); - - /* return if ESC was pressed */ - if ( event.key == grKeyEsc ) - return 0; - - /* otherwise, display key string */ - color.value = (color.value + 8) & 127; - { - int count = sizeof(key_names)/sizeof(key_names[0]); - grKeyName* name = key_names; - grKeyName* limit = name + count; - const char* kname = 0; - char kname_temp[16]; - - while (name < limit) - { - if ( name->key == event.key ) - { - kname = name->name; - break; - } - name++; - } - - if (!kname) - { - sprintf( kname_temp, "char '%c'", (char)event.key ); - kname = kname_temp; - } - - grWriteCellString( surface, 30, 30, kname, color ); - grRefreshSurface(surface); - paint_rectangle( surface, 0, 0, surface->bitmap.width, surface->bitmap.rows ); - } - } while (1); - } - - return 0; - - -} -#endif /* O */ -#endif /* TEST */ - diff --git a/demos/graph/x11/grx11.h b/demos/graph/x11/grx11.h deleted file mode 100644 index cd77112c0..000000000 --- a/demos/graph/x11/grx11.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef GRX11_H -#define GRX11_H - -#include "grobjs.h" -#include "grdevice.h" - - extern - grDevice gr_x11_device; - -#ifdef GR_INIT_BUILD - static - grDeviceChain gr_x11_device_chain = - { - "x11", - &gr_x11_device, - GR_INIT_DEVICE_CHAIN - }; - -#undef GR_INIT_DEVICE_CHAIN -#define GR_INIT_DEVICE_CHAIN &gr_x11_device_chain - -#endif /* GR_INIT_BUILD */ - -#endif /* GRX11_H */ diff --git a/demos/graph/x11/rules.mk b/demos/graph/x11/rules.mk deleted file mode 100644 index e1dc2b3e8..000000000 --- a/demos/graph/x11/rules.mk +++ /dev/null @@ -1,88 +0,0 @@ -#************************************************************************** -#* -#* X11-specific rules files, used to compile the X11 graphics driver -#* when supported by the current platform -#* -#************************************************************************** - -######################################################################### -# -# Try to detect an X11 setup. -# -# We try to detect the following directories (in that order) in the current -# path: -# -# X11 (usually a symlink to the current release) -# X11R6 -# X11R5 -# -# If the variable X11_PATH is set (to specify unusual locations of X11), no -# other directory is searched. More than one directory must be separated -# with spaces. Example: -# -# make X11_PATH="/usr/openwin /usr/local/X11R6" -# -ifndef X11_PATH - ifneq ($(findstring X11$(SEP)bin,$(PATH)),) - xversion := X11 - else - ifneq ($(findstring X11R6$(SEP)bin,$(PATH)),) - xversion := X11R6 - else - ifneq ($(findstring X11R5$(SEP)bin,$(PATH)),) - xversion := X11R5 - endif - endif - endif - - ifdef xversion - X11_PATH := $(subst ;, ,$(PATH)) $(subst :, ,$(PATH)) - X11_PATH := $(filter %$(xversion)$(SEP)bin,$(X11_PATH)) - X11_PATH := $(X11_PATH:%$(SEP)bin=%) - endif -endif - -########################################################################## -# -# Update some variables to compile the X11 graphics module. Note that -# X11 is available on Unix, or on OS/2. However, it only compiles with -# gcc on the latter platform, which is why it is safe to use the flags -# `-L' and `-l' in GRAPH_LINK -# -ifneq ($(X11_PATH),) - - X11_INCLUDE := $(X11_PATH:%=%$(SEP)include) - X11_LIB := $(X11_PATH:%=%$(SEP)lib) - - # the GRAPH_LINK variable is expanded each time an executable is linked - # against the graphics library. - # - GRAPH_LINK += $(X11_LIB:%=-L%) -lX11 - - # Solaris needs a -lsocket in GRAPH_LINK .. - # - UNAME := $(shell uname) - ifneq ($(findstring $(UNAME),SunOS Solaris),) - GRAPH_LINK += -lsocket - endif - - - # add the X11 driver object file to the graphics library - # - GRAPH_OBJS += $(OBJ_)grx11.$O - - - GR_X11 := $(GRAPH_)x11 - GR_X11_ := $(GR_X11)$(SEP) - - DEVICES += X11 - DEVICE_INCLUDES += $(GR_X11) - - # the rule used to compile the X11 driver - # - $(OBJ_)grx11.$O: $(GR_X11_)grx11.c $(GR_X11_)grx11.h - $(CC) $(CFLAGS) $(GRAPH_INCLUDES:%=$I%) $I$(GR_X11) \ - $(X11_INCLUDE:%=$I%) $T$@ $< -endif - -# EOF diff --git a/demos/graph/xtest.c b/demos/graph/xtest.c deleted file mode 100644 index 7bc806bed..000000000 --- a/demos/graph/xtest.c +++ /dev/null @@ -1,125 +0,0 @@ -#include "graph.h" -#include "grfont.h" /* dispara^itra bientot */ -#include - - -static -void Panic( const char* message ) -{ - fprintf( stderr, "PANIC: %s\n", message ); - exit(1); -} - - -typedef struct grKeyName -{ - grKey key; - const char* name; - -} grKeyName; - - -static -const grKeyName key_names[] = -{ - { grKeyF1, "F1" }, - { grKeyF2, "F2" }, - { grKeyF3, "F3" }, - { grKeyF4, "F4" }, - { grKeyF5, "F5" }, - { grKeyF6, "F6" }, - { grKeyF7, "F7" }, - { grKeyF8, "F8" }, - { grKeyF9, "F9" }, - { grKeyF10, "F10" }, - { grKeyF11, "F11" }, - { grKeyF12, "F12" }, - { grKeyEsc, "Esc" }, - { grKeyHome, "Home" }, - { grKeyEnd, "End" }, - - { grKeyPageUp, "Page_Up" }, - { grKeyPageDown, "Page_Down" }, - { grKeyLeft, "Left" }, - { grKeyRight, "Right" }, - { grKeyUp, "Up" }, - { grKeyDown, "Down" }, - { grKeyBackSpace, "BackSpace" }, - { grKeyReturn, "Return" } -}; - -int main( void ) -{ - grSurface* surface; - int n; - - grInit(); - surface = grNewScreenSurface( 0, gr_pixel_mode_gray, 320, 400, 128 ); - if (!surface) - Panic("Could not create window\n" ); - else - { - grColor color; - grEvent event; - const char* string; - int x; - - grSetSurfaceRefresh( surface, 1 ); - grSetTitle(surface,"X11 driver demonstration" ); - - for ( x = -10; x < 10; x++ ) - { - for ( n = 0; n < 128; n++ ) - { - color.value = (n*3) & 127; - grWriteCellChar( surface, - x + ((n % 60) << 3), - 80 + (x+10)*8*3 + ((n/60) << 3), n, color ); - } - - } - color.value = 64; - grWriteCellString( surface, 0, 0, "just an example", color ); - - do - { - grListenSurface( surface, 0, &event); - - /* return if ESC was pressed */ - if ( event.key == grKeyEsc ) - return 0; - - /* otherwise, display key string */ - color.value = (color.value + 8) & 127; - { - int count = sizeof(key_names)/sizeof(key_names[0]); - grKeyName* name = (grKeyName*)key_names; - grKeyName* limit = name + count; - const char* kname = 0; - char kname_temp[16]; - - while (name < limit) - { - if ( name->key == event.key ) - { - kname = (const char*)name->name; - break; - } - name++; - } - - if (!kname) - { - sprintf( kname_temp, "char '%c'", (char)event.key ); - kname = kname_temp; - } - - grWriteCellString( surface, 30, 30, kname, color ); - grRefreshSurface(surface); - } - } while (1); - } - - return 0; -} - diff --git a/demos/mac/README b/demos/mac/README deleted file mode 100644 index 9674240ae..000000000 --- a/demos/mac/README +++ /dev/null @@ -1,22 +0,0 @@ -This folder contains supporting code and CodeWarrior Pro 4 project -files to build the FreeType demo programs ftlint and ftview for MacOS. - -Building -To build these apps, you'll first need to build the FreeType library -(see config/mac). The applications get built in the demos/bin folder. - -Notes -Since the Mac doesn't have the notion of argc/argv, we'll emulate -this: each file dropped onto the application will be translated -to a command line argument. Both ftlint and ftview take a ppem -value as their first command line argument: for the Mac version -this has been hard-coded into the source. Also: the additional -options for ftview cannot be set. - -Have fun with FreeType on the Mac! - -Just van Rossum, - -DISCLAIMER: this subdirectory is *not* being maintained by the -FreeType team, but by Just van Rossum. It's being released under -the same terms as FreeType (see license.txt). diff --git a/demos/mac/codewarrior/ftlint.prj b/demos/mac/codewarrior/ftlint.prj deleted file mode 100644 index efc66157f..000000000 Binary files a/demos/mac/codewarrior/ftlint.prj and /dev/null differ diff --git a/demos/mac/codewarrior/ftview.prj b/demos/mac/codewarrior/ftview.prj deleted file mode 100644 index bcf3ec3dd..000000000 Binary files a/demos/mac/codewarrior/ftview.prj and /dev/null differ diff --git a/demos/mac/ftlint_m.c b/demos/mac/ftlint_m.c deleted file mode 100644 index 258b0286d..000000000 --- a/demos/mac/ftlint_m.c +++ /dev/null @@ -1,59 +0,0 @@ -/* minimal Mac wrapper for the ftlint.c program */ - - -int original_main( int argc, char** argv ); - -/* We rename the original main() program to original_main, - so we can provide a wrapper around it */ -#define main original_main -#include "ftlint.c" -#undef main - - -#define PPEM "24" /* hard-code the ppem size */ - - -#include -#include "getargv.h" -#include -#include -#include -#include - -static void -init_toolbox() -{ - InitGraf(&qd.thePort); - InitFonts(); - InitWindows(); - TEInit(); - InitDialogs((long)0); - InitMenus(); - InitCursor(); - SIOUXSettings.asktosaveonclose = 0; -} - -int main() -{ - int argc, i; - char** argv; - - init_toolbox(); - - /* put paths of all files dropped onto the app into argv */ - argc = FTMac_GetArgv(&argv); - if (argc < 2) - { - printf("Please drop one or more font files onto the app (but quit first!)\n"); - exit(1); - } - /* move argv[1:] to argv[2:] and fill in the ppem arg */ - for (i = argc; i > 1; i--) - { - argv[i] = argv[i-1]; - } - argc++; - argv[1] = PPEM; - /* call the original main() program */ - original_main(argc, argv); -} diff --git a/demos/mac/ftview_m.c b/demos/mac/ftview_m.c deleted file mode 100644 index c4edc7e60..000000000 --- a/demos/mac/ftview_m.c +++ /dev/null @@ -1,59 +0,0 @@ -/* minimal Mac wrapper for the ftview.c program */ - - -int original_main( int argc, char** argv ); - -/* We rename the original main() program to original_main, - so we can provide a wrapper around it */ -#define main original_main -#include "ftview.c" -#undef main - - -#define PPEM "24" /* hard-code the ppem size */ - - -#include -#include "getargv.h" -#include -#include -#include -#include - -static void -init_toolbox() -{ - InitGraf(&qd.thePort); - InitFonts(); - InitWindows(); - TEInit(); - InitDialogs((long)0); - InitMenus(); - InitCursor(); - SIOUXSettings.asktosaveonclose = 0; -} - -int main() -{ - int argc, i; - char** argv; - - init_toolbox(); - - /* put paths of all files dropped onto the app into argv */ - argc = FTMac_GetArgv(&argv); - if (argc < 2) - { - printf("Please drop one or more font files onto the app (but quit first!)\n"); - exit(1); - } - /* move argv[1:] to argv[2:] and fill in the ppem arg */ - for (i = argc; i > 1; i--) - { - argv[i] = argv[i-1]; - } - argc++; - argv[1] = PPEM; - /* call the original main() program */ - original_main(argc, argv); -} diff --git a/demos/mac/getargv.c b/demos/mac/getargv.c deleted file mode 100644 index 7ff18e03b..000000000 --- a/demos/mac/getargv.c +++ /dev/null @@ -1,312 +0,0 @@ -/*********************************************************** -Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, -The Netherlands. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Stichting Mathematisch -Centrum or CWI not be used in advertising or publicity pertaining to -distribution of the software without specific, written prior permission. - -STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO -THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE -FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -******************************************************************/ - -/* Construct argc and argv for main() by using Apple Events */ -/* From Jack's implementation for STDWIN */ - -/* Modified for use with FreeType from MacPython's macgetargv.c - by Just van Rossum */ - -#include -#include -#include "getargv.h" - -#include -#include -#include -#include -#include -#include -#include - -#ifdef GENERATINGCFM /* Defined to 0 or 1 in Universal headers */ -#define HAVE_UNIVERSAL_HEADERS -#endif - -#ifndef HAVE_UNIVERSAL_HEADERS -#define NewAEEventHandlerProc(x) (x) -#define AEEventHandlerUPP EventHandlerProcPtr -#endif - -static int arg_count; -static char *arg_vector[256]; -static char app_name[256]; -static int app_name_inited; - - -/* Duplicate a string to the heap. */ - -static char * -strdup(char *src) -{ - char *dst = malloc(strlen(src) + 1); - if (dst) - strcpy(dst, src); - return dst; -} - - -/* Given an FSSpec, return the FSSpec of the parent folder */ - -static OSErr -get_folder_parent (FSSpec * fss, FSSpec * parent) -{ - CInfoPBRec rec; - short err; - - * parent = * fss; - rec.hFileInfo.ioNamePtr = parent->name; - rec.hFileInfo.ioVRefNum = parent->vRefNum; - rec.hFileInfo.ioDirID = parent->parID; - rec.hFileInfo.ioFDirIndex = -1; - rec.hFileInfo.ioFVersNum = 0; - if (err = PBGetCatInfoSync (& rec)) - return err; - parent->parID = rec.dirInfo.ioDrParID; -/* parent->name[0] = 0; */ - return 0; -} - - -/* Given an FSSpec return a full, colon-separated pathname */ - -static OSErr -FTMac_GetFullPath (FSSpec *fss, char *buf) -{ - short err; - FSSpec fss_parent, fss_current; - char tmpbuf[256]; - int plen; - - fss_current = *fss; - plen = fss_current.name[0]; - memcpy(buf, &fss_current.name[1], plen); - buf[plen] = 0; - /* Special case for disk names */ - if ( fss_current.parID <= 1 ) { - buf[plen++] = ':'; - buf[plen] = 0; - return 0; - } - while (fss_current.parID > 1) { - /* Get parent folder name */ - if (err = get_folder_parent(&fss_current, &fss_parent)) - return err; - fss_current = fss_parent; - /* Prepend path component just found to buf */ - plen = fss_current.name[0]; - if (strlen(buf) + plen + 1 > 256) { - /* Oops... Not enough space (shouldn't happen) */ - *buf = 0; - return -1; - } - memcpy(tmpbuf, &fss_current.name[1], plen); - tmpbuf[plen] = ':'; - strcpy(&tmpbuf[plen+1], buf); - strcpy(buf, tmpbuf); - } - return 0; -} - - -/* Initialize name of current application */ - -static OSErr -init_app_name() -{ - ProcessSerialNumber currentPSN; - ProcessInfoRec info; - OSErr err; - FSSpec appSpec; - - if ( app_name_inited ) return 0; - currentPSN.highLongOfPSN = 0; - currentPSN.lowLongOfPSN = kCurrentProcess; - info.processInfoLength = sizeof(ProcessInfoRec); - info.processName = NULL; - info.processAppSpec = &appSpec; - if ( err=GetProcessInformation(¤tPSN, &info)) - return err; - strncpy(app_name, (char*)appSpec.name + 1, appSpec.name[0]); - app_name[appSpec.name[0]] = '\0'; - app_name_inited = 1; - return 0; -} - - -/* Check that there aren't any args remaining in the event */ - -static OSErr -get_missing_params(AppleEvent *theAppleEvent) -{ - DescType theType; - Size actualSize; - OSErr err; - - err = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr, typeWildCard, - &theType, nil, 0, &actualSize); - if (err == errAEDescNotFound) - return noErr; - else - return errAEEventNotHandled; -} - -static int got_one; /* Flag that we can stop getting events */ - - -/* Handle the Print or Quit events (by failing) */ - -static pascal OSErr -handle_not(AppleEvent *theAppleEvent, AppleEvent *reply, long refCon) -{ - #pragma unused (reply, refCon) - got_one = 1; - return errAEEventNotHandled; -} - - -/* Handle the Open Application event (by ignoring it) */ - -static pascal OSErr -handle_open_app(AppleEvent *theAppleEvent, AppleEvent *reply, long refCon) -{ - #pragma unused (reply, refCon) -#if 0 - /* Test by Jack: would removing this facilitate debugging? */ - got_one = 1; -#endif - return get_missing_params(theAppleEvent); -} - - -/* Handle the Open Document event, by adding an argument */ - -static pascal OSErr -handle_open_doc(AppleEvent *theAppleEvent, AppleEvent *reply, long refCon) -{ - #pragma unused (reply, refCon) - OSErr err; - AEDescList doclist; - AEKeyword keywd; - DescType rttype; - long i, ndocs, size; - FSSpec fss; - char path[256]; - - got_one = 1; - if (err = AEGetParamDesc(theAppleEvent, - keyDirectObject, typeAEList, &doclist)) - return err; - if (err = get_missing_params(theAppleEvent)) - return err; - if (err = AECountItems(&doclist, &ndocs)) - return err; - for(i = 1; i <= ndocs; i++) { - err = AEGetNthPtr(&doclist, i, typeFSS, - &keywd, &rttype, &fss, sizeof(fss), &size); - if (err) - break; - FTMac_GetFullPath(&fss, path); - arg_vector[arg_count++] = strdup(path); - } - return err; -} - - -/* Install standard core event handlers */ -static AEEventHandlerUPP open_doc_upp; -static AEEventHandlerUPP open_app_upp; -static AEEventHandlerUPP not_upp; - -static void -set_ae_handlers() -{ - open_doc_upp = NewAEEventHandlerProc(handle_open_doc); - open_app_upp = NewAEEventHandlerProc(handle_open_app); - not_upp = NewAEEventHandlerProc(handle_not); - - AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, - open_app_upp, 0L, false); - AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, - open_doc_upp, 0L, false); - AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, - not_upp, 0L, false); - AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, - not_upp, 0L, false); -} - -/* Uninstall standard core event handlers */ - -static void -reset_ae_handlers() -{ - AERemoveEventHandler(kCoreEventClass, kAEOpenApplication, - open_app_upp, false); - AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments, - open_doc_upp, false); - AERemoveEventHandler(kCoreEventClass, kAEPrintDocuments, - not_upp, false); - AERemoveEventHandler(kCoreEventClass, kAEQuitApplication, - not_upp, false); -} - -/* Wait for events until a core event has been handled */ - -static void -event_loop() -{ - EventRecord event; - int n; - int ok; - - got_one = 0; - for (n = 0; n < 100 && !got_one; n++) { - SystemTask(); - ok = GetNextEvent(everyEvent, &event); - if (ok && event.what == kHighLevelEvent) { - AEProcessAppleEvent(&event); - } - } -} - -/* Get the argv vector, return argc. See macgetargv.h for more doco. */ - -int -FTMac_GetArgv(pargv) - char ***pargv; -{ - - arg_count = 0; - (void)init_app_name(); - arg_vector[arg_count++] = strdup(app_name); - - set_ae_handlers(); - event_loop(); - reset_ae_handlers(); - - arg_vector[arg_count] = NULL; - - *pargv = arg_vector; - return arg_count; -} diff --git a/demos/mac/getargv.h b/demos/mac/getargv.h deleted file mode 100644 index a13289dd8..000000000 --- a/demos/mac/getargv.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - - FTMac_GetArgv - - - argc/argv emulation for the Mac. Converts files dropped - onto the application to full paths, and stuff them into - argv. - - - pargv :: a pointer to an argv array. The array doesn't need to - exist before calling this function. - - - The number of files dropped onto the app (ie. argc) -*/ - -int FTMac_GetArgv(char ***pargv); - diff --git a/demos/mac/resource.hqx b/demos/mac/resource.hqx deleted file mode 100644 index cde902da4..000000000 --- a/demos/mac/resource.hqx +++ /dev/null @@ -1,38 +0,0 @@ -(This file must be converted with BinHex 4.0) -:$(*PFfpeFQ0P,R0TG!"6594%8dP8)3%!!!!'[!!!!!!REP0*9#%!!J!!"Vab6'& -e!RX!!!!@EhX0!!YQG'aTER3ZFR0bB`K"ST!!!%9qHJ!!!)!!!!!!#%PXcPl2#BB -!!!!!!!!!!!!!!!!!!!!!!!!"R`!!!!$rrrrrFR0bBe*6483"!,6HlZHdhZmk!!! -"Q3!!!!!!!!%C!!!!!"2I!!!!!!!!!!#2I4%!#"`XG3MLeZTM1d$2c[ec0aXql5S -ShPIL[&U,h14S@fT@KjEj-dK+IjNHBG)R-N9+9!`J2MP%TSHT%#Nd-qT*elC3-#N -4JA)Hkc6qlRVSqDHb&A*3a9&1cdmjhEbBUHN9ad&X+`E&1ceI!Y68j0ki6qFA)(r -b,FRGeI4f6k%5&4RNVXbJD-emb41U6CZldibq,@I[0+0[hAC1Pd8qb1GJMXlkGX[ -Qi$6*5FhCV+hMcp9GjDB!CG6%FFi-Y%hSD+RR#(40DQ1''@VI1VRml-&F9CdAA5b -'mAYaP!drhR!2h3*kJDG9FQ)R4mZIfD4`CM-&4Q9IJU0XbMdc06QfE,r!c)B,BXZ -5lI0h(XbS`)*QmLcRP#B"!!!!$3!,CR4fD@9h,R*cFQ-)3D+3!!"&IRS!!!#!!!! -!!!K*E-kIZJQ'!!!!!!!!!!!!!!!!!!!!&J!!!!!!!!!!rrrrrh*cFQ058d9%!3# -dhZlRY0pi`J!!#Fd!!!!!!!!%V3!!!!#NcJ!!!!!!!!!!i8X,3,6cZVA1c0lNY)[ -f+j[)D@pq&ff8&[hml++YG5DRR()cQTfYCHr*j#YEf5Jc%CLIXrbFjqFX2cmr2dr -ZTpFJfU$ca31a!b+85iiI35I(Bq'a#e!!VJ6J!#F!VSd!Nr('42m&cC%BQfS+kII -X%,b5(HDLA-XlBDbP"ISMY'LUSfGRDkm!HhGl5NUk05!P)laE*h[lM)b!S+!8DhG -VJA4q'GFk-X)*HFCMl1QrCp29l+`h+kl(I3FBqcaJl-h0E-YliEX#cZ%fH-9NHb2 -[J5A*h#if"qk@8jD%["I4@8lH[MDBr'c`$(5cE+ral1fF[*0$mqINR4`FEH`P-!" -ZaYZ$[j86fKM'6M`k&3TTDRc[bEfDM@PAb0Zc`KL$6e6mrPk'RD,L)U0H$fC!XbD -@b[N$+ecGH0iXmEpL-Vhq#F#BEGiV"UHAIc%8q2X*3m(RMaLFRfBcZ16HC5Mdq$C -$iBFh'%`j9aPFlepL+(,[2%241fFBh,*1-"5lGC6"rHBKKZ,Apc&iA0[&81,+GSD -5PlF`P,UiJF(c`PU'dZG@-ALGAFE`cZP&$0iRjc'816k,SHbaD3c[(TR%i(0i(%1 -jJk-BbZmIaP"Klb!'mqlq$"9hpQ@SY+-R3q9YGSBU@fd-96GhBI$GQ-V`h[S1$(l -VNKLUV@R$8(ee!N10PDdBr*HhB+LjY"P$`1*)KX#&B3a"md-BDXeY`&"lGKf'pfI -@BJLHAT1KcY4U$(8R9f@S0l%L3rhaj4JDM#h$d("dDBB24TCJD$5m'%2)8&H'aS0 -G'$iFk-33f[mP3eLrj`cKIA-CQ[4qb"$4mcj$T1-13j6p&N26c1X-dEBV$-h5,c) -dlh+1iD1dd``aUFFC@R3m`Q$TF*!!)6Cj,d2,T*d-VGTZBiKVXjQKGH*kK[L%03` -IakpJ5)KE`["*b`8-LCBj$*r'c'"Sdh`+`fI4%aMD4SeKq$aL"%05q"#'GU%$'*) -Epf0ShkJh3iH'$SD8qTN-(HZQ-eL$daK5DhGNk"58c*!!&Y#@SE0r)N1Ak[%-AIe -D-U6laM"N9)PQX&@+B1KQ$QA),0q)i3ZIqJcfXX%-hEf$'"aHrJ`p22dBHTDX`Y$ -,`mc3fpf(SBqE0d2I)Ti-AjSm'2S9FQ2ibYR%d,q!-m2A1KN-d2PQS$a)(L`2NBI -+`q6KmJKjT$a+(Lf2NFI+iq6amJ4jSMa*RLa2NDI+dq6TmJajTMa,RLh2NHI+mq6 -jmJ*jSEa)AL`[NCI+bq6PmJTjTEa+ALer)kq4emVVj'rPpI)'HD1m5GiXEj'hbYr -*fq6YmJljHhQR[%[H,Hq4pmVlj2hb!IQJI%Jq,2mJ(j'2bXIN(qAMmJRjT(a+2Lf -INFr+2mRRj22b"IPRqD*m5EiXrb*INDr+eq4IjH[b$IQQr*Ym5liYCmQrbhINZr) -pq3rj[T`YjmJ2j)Ib)rQar+HF+cq4RmV2j1IbAr,ImJ[jTIa+cVrAq2IZa#8h`e( -[M,(L!aX+KPXLBSbe5VT9#0!Y3m18p"i1`e(jTiGr6K,QYpFN0E5riJD$A(+l,R' -2l@@cfXefDrGZ2H`TeP*4GUXe[NqQe4`@CXjXRfje1+cr!`IL!!!: diff --git a/demos/obj/README b/demos/obj/README deleted file mode 100644 index f11d2c105..000000000 --- a/demos/obj/README +++ /dev/null @@ -1 +0,0 @@ -This directory contains all the object files generated for the demonstration programs diff --git a/demos/src/common.c b/demos/src/common.c deleted file mode 100644 index 0c963479a..000000000 --- a/demos/src/common.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - * This is a cheap replacement for getopt() because that routine is not - * available on some platforms and behaves differently on other platforms. - * This code was written from scratch without looking at any other - * implementation. - * - * This code is hereby expressly placed in the public domain. - * mleisher@crl.nmsu.edu (Mark Leisher) - * 10 October 1997 - */ - -#ifndef lint -#ifdef __GNUC__ - static char rcsid[] __attribute__ ((unused)) = "$Id$"; -#else - static char rcsid[] = "$Id$"; -#endif -#endif - -#include "common.h" - -#include -#include -#include -#include - - /* - * Externals visible to programs. - */ - - int opterr = 1; - int optind = 1; - char* optarg; - - /* - * Internal variables that are used to detect when the global values - * need to be reset. - */ - - static int cmdac; -#ifdef __STDC__ - static const char* cmdname; - static char* const* cmdav; -#else - static char* cmdname; - static char** cmdav; -#endif - - int -#ifdef __STDC__ - getopt( int ac, char* const* av, const char* pat ) -#else - getopt( ac, av, pat ) - int ac; - char** av; - char* pat; -#endif - { - int opt; -#ifdef __STDC__ - const char* p; - const char* pp; -#else - char* p; - char* pp; -#endif - - /* - * If there is no pattern, indicate the parsing is done. - */ - if ( pat == 0 || *pat == 0 ) - return -1; - - /* - * Always reset the option argument to NULL. - */ - optarg = 0; - - /* - * If the number of arguments or argument list do not match the last - * values seen, reset the internal pointers and the globals. - */ - if ( ac != cmdac || av != cmdav ) - { - optind = 1; - cmdac = ac; - cmdav = av; - - /* - * Determine the command name in case it is needed for warning - * messages. - */ - for ( cmdname = 0, p = av[0]; *p; p++ ) - { - if ( *p == '/' || *p == '\\' ) - cmdname = p; - } - /* - * Skip the path separator if the name was assigned. - */ - if ( cmdname ) - cmdname++; - else - cmdname = av[0]; - } - - /* - * If the next index is greater than or equal to the number of - * arguments, then the command line is done. - */ - if ( optind >= ac ) - return -1; - - /* - * Test the next argument for one of three cases: - * 1. The next argument does not have an initial '-'. - * 2. The next argument is '-'. - * 3. The next argument is '--'. - * - * In either of these cases, command line processing is done. - */ - if ( av[optind][0] != '-' || - strcmp( av[optind], "-" ) == 0 || - strcmp( av[optind], "--" ) == 0 ) - return -1; - - /* - * Point at the next command line argument and increment the - * command line index. - */ - p = av[optind++]; - - /* - * Look for the first character of the command line option. - */ - for ( opt = *(p + 1), pp = pat; *pp && *pp != opt; pp++ ) - ; - - /* - * If nothing in the pattern was recognized, then issue a warning - * and return a '?'. - */ - if ( *pp == 0 ) - { - if ( opterr ) - fprintf( stderr, "%s: illegal option -- %c\n", cmdname, opt ); - return '?'; - } - - /* - * If the option expects an argument, get it. - */ - if ( *(pp + 1) == ':' && (optarg = av[optind]) == 0 ) - { - /* - * If the option argument is NULL, issue a warning and return a '?'. - */ - if ( opterr ) - fprintf( stderr, "%s: option requires an argument -- %c\n", - cmdname, opt ); - opt = '?'; - } - else if ( optarg ) - /* - * Increment the option index past the argument. - */ - optind++; - - /* - * Return the option character. - */ - return opt; - } - - -/****************************************************************************/ -/* */ -/* The FreeType project -- a free and portable quality TrueType renderer. */ -/* */ -/* Copyright 1996-1998 by */ -/* D. Turner, R.Wilhelm, and W. Lemberg */ -/* */ -/* ft_basename(): */ -/* */ -/* a stupid but useful function... */ -/* */ -/* rewritten by DavidT to get rid of GPLed programs in the FreeType demos. */ -/* */ -/****************************************************************************/ - - char* -#ifdef __STDC__ - ft_basename ( const char* name ) -#else - ft_basename ( name ) - char* name; -#endif - { -#ifdef __STDC__ - const char* base; - const char* current; -#else - char* base; - char* current; -#endif - char c; - - base = name; - current = name; - - c = *current; - - while ( c ) - { -#ifndef macintosh - if ( c == '/' || c == '\\' ) -#else - if ( c == ':' ) -#endif - base = current + 1; - - current++; - c = *current; - } - - return (char*)base; - } - - -#ifdef __STDC__ - void Panic( const char* fmt, ... ) -#else - void Panic( fmt ) - const char* fmt; -#endif - { - va_list ap; - - - va_start( ap, fmt ); - vprintf( fmt, ap ); - va_end( ap ); - - exit( 1 ); - } - - -/* End */ diff --git a/demos/src/common.h b/demos/src/common.h deleted file mode 100644 index e1377086f..000000000 --- a/demos/src/common.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This is a cheap replacement for getopt() because that routine is not - * available on some platforms and behaves differently on other platforms. - * - * This code is hereby expressly placed in the public domain. - * mleisher@crl.nmsu.edu (Mark Leisher) - * 10 October 1997 - */ - -#ifndef _H_COMMON -#define _H_COMMON - -/* Note that by default, both functions are implemented in common.c */ - -#ifdef __cplusplus - extern "C" { -#endif - - extern int opterr; - extern int optind; - extern char* optarg; - - extern int getopt( -#ifdef __STDC__ - int argc, - char* const* argv, - const char* pattern -#endif - ); - - - extern char* ft_basename( -#ifdef __STDC__ - const char* name -#endif - ); - - /* print a message and exit */ - extern void Panic ( -#ifdef __STDC__ - const char* fmt, ... -#endif - ); - - -#ifdef __cplusplus - } -#endif - -#endif /* _H_COMMON */ - - -/* End */ diff --git a/demos/src/compos.c b/demos/src/compos.c deleted file mode 100644 index 976d4ab7b..000000000 --- a/demos/src/compos.c +++ /dev/null @@ -1,191 +0,0 @@ -/****************************************************************************/ -/* */ -/* The FreeType project -- a free and portable quality TrueType renderer. */ -/* */ -/* Copyright 1996-1998 by */ -/* D. Turner, R.Wilhelm, and W. Lemberg */ -/* */ -/* compos: this is a very simple program used to test the flag */ -/* FT_LOAD_NO_RECURSE */ -/* */ -/* NOTE: This is just a test program that is used to show off and */ -/* debug the current engine. */ -/* */ -/****************************************************************************/ - -#include - -#include -#include -#include - - -#define gettext( x ) ( x ) - - FT_Error error; - - FT_Library library; - FT_Face face; - FT_Size size; - FT_GlyphSlot slot; - - unsigned int num_glyphs; - int ptsize; - - int Fail; - int Num; - - - - static void Usage( char* name ) - { - printf( "compos: test FT_LOAD_NO_RECURSE load flag - www.freetype.org\n" ); - printf( "------------------------------------------------------------\n" ); - printf( "\n" ); - printf( "Usage: %s fontname[.ttf|.ttc] [fontname2..]\n", name ); - printf( "\n" ); - - exit( 1 ); - } - - - static void Panic( const char* message ) - { - fprintf( stderr, "%s\n error code = 0x%04x\n", message, error ); - exit(1); - } - - - int main( int argc, char** argv ) - { - int i, file_index; - unsigned int id; - char filename[128 + 4]; - char alt_filename[128 + 4]; - char* execname; - char* fname; - - - execname = argv[0]; - - if ( argc < 2 ) - Usage( execname ); - - error = FT_Init_FreeType( &library ); - if (error) Panic( "Could not create library object" ); - - /* Now check all files */ - for ( file_index = 1; file_index < argc; file_index++ ) - { - fname = argv[file_index]; - i = strlen( fname ); - while ( i > 0 && fname[i] != '\\' && fname[i] != '/' ) - { - if ( fname[i] == '.' ) - i = 0; - i--; - } - - filename[128] = '\0'; - alt_filename[128] = '\0'; - - strncpy( filename, fname, 128 ); - strncpy( alt_filename, fname, 128 ); - -#ifndef macintosh - if ( i >= 0 ) - { - strncpy( filename + strlen( filename ), ".ttf", 4 ); - strncpy( alt_filename + strlen( alt_filename ), ".ttc", 4 ); - } -#endif - i = strlen( filename ); - fname = filename; - - while ( i >= 0 ) -#ifndef macintosh - if ( filename[i] == '/' || filename[i] == '\\' ) -#else - if ( filename[i] == ':' ) -#endif - { - fname = filename + i + 1; - i = -1; - } - else - i--; - - printf( "%s:\n", fname ); - - /* Load face */ - error = FT_New_Face( library, filename, 0, &face ); - if (error) - { - if (error == FT_Err_Invalid_File_Format) - printf( "unknown format\n" ); - else - printf( "could not find/open file (error: %d)\n", error ); - continue; - } - - num_glyphs = face->num_glyphs; - slot = face->glyph; - - Fail = 0; - { - for ( id = 0; id < num_glyphs; id++ ) - { - int has_scale; - - error = FT_Load_Glyph( face, id, FT_LOAD_NO_RECURSE ); - if (!error && slot->format == ft_glyph_format_composite) - { - int n; - FT_SubGlyph* subg = slot->subglyphs; - - printf( "%4d:", id ); - for ( n = 0; n < slot->num_subglyphs; n++, subg++ ) - { - has_scale = subg->flags & ( - FT_SUBGLYPH_FLAG_SCALE | - FT_SUBGLYPH_FLAG_XY_SCALE | - FT_SUBGLYPH_FLAG_2X2 ); - - printf( " [%d%c", - subg->index, - subg->flags & FT_SUBGLYPH_FLAG_USE_MY_METRICS ? '*' : ' ' ); - - if ( subg->arg1|subg->arg2 ) - { - if ( subg->flags & FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES ) - printf( "(%d,%d)", subg->arg1, subg->arg2 ); - else - printf( "<%d,%d>", subg->arg1, subg->arg2 ); - } - - if (has_scale) - printf( "-{%0.3f %0.3f %0.3f %0.3f}", - subg->transform.xx/65536.0, - subg->transform.xy/65536.0, - subg->transform.yx/65536.0, - subg->transform.yy/65536.0 ); - printf( "]" ); - } - printf( " adv=%ld lsb=%ld\n", - slot->metrics.horiAdvance, - slot->metrics.horiBearingX ); - } - } - } - - FT_Done_Face( face ); - } - - FT_Done_FreeType(library); - exit( 0 ); /* for safety reasons */ - - return 0; /* never reached */ - } - - -/* End */ diff --git a/demos/src/ftlint.c b/demos/src/ftlint.c deleted file mode 100644 index e16bbcbb5..000000000 --- a/demos/src/ftlint.c +++ /dev/null @@ -1,192 +0,0 @@ -/****************************************************************************/ -/* */ -/* The FreeType project -- a free and portable quality TrueType renderer. */ -/* */ -/* Copyright 1996-1998 by */ -/* D. Turner, R.Wilhelm, and W. Lemberg */ -/* */ -/* ftlint: a simple font tester. This program tries to load all the */ -/* glyphs of a given font. */ -/* */ -/* NOTE: This is just a test program that is used to show off and */ -/* debug the current engine. */ -/* */ -/****************************************************************************/ - -#include - -#include -#include -#include - - -#define gettext( x ) ( x ) - - FT_Error error; - - FT_Library library; - FT_Face face; - FT_Size size; - FT_GlyphSlot slot; - - unsigned int num_glyphs; - int ptsize; - - int Fail; - int Num; - - - - static void Usage( char* name ) - { - printf( "ftlint: simple font tester -- part of the FreeType project\n" ); - printf( "----------------------------------------------------------\n" ); - printf( "\n" ); - printf( "Usage: %s ppem fontname[.ttf|.ttc] [fontname2..]\n", name ); - printf( "\n" ); - - exit( 1 ); - } - - - static void Panic( const char* message ) - { - fprintf( stderr, "%s\n error code = 0x%04x\n", message, error ); - exit(1); - } - - - int main( int argc, char** argv ) - { - int i, file_index; - unsigned int id; - char filename[128 + 4]; - char alt_filename[128 + 4]; - char* execname; - char* fname; - - - execname = argv[0]; - - if ( argc < 3 ) - Usage( execname ); - - if ( sscanf( argv[1], "%d", &ptsize ) != 1 ) - Usage( execname ); - - error = FT_Init_FreeType( &library ); - if (error) Panic( "Could not create library object" ); - - /* Now check all files */ - for ( file_index = 2; file_index < argc; file_index++ ) - { - fname = argv[file_index]; - - /* try to open the file with no extra extension first */ - error = FT_New_Face( library, fname, 0, &face ); - if (!error) - { - printf( "%s: ", fname ); - goto Success; - } - - - if ( error == FT_Err_Unknown_File_Format ) - { - printf( "unknown format\n" ); - continue; - } - - /* ok, we could not load the file, try to add an extension to */ - /* its name if possible.. */ - - i = strlen( fname ); - while ( i > 0 && fname[i] != '\\' && fname[i] != '/' ) - { - if ( fname[i] == '.' ) - i = 0; - i--; - } - - filename[128] = '\0'; - alt_filename[128] = '\0'; - - strncpy( filename, fname, 128 ); - strncpy( alt_filename, fname, 128 ); - -#ifndef macintosh - if ( i >= 0 ) - { - strncpy( filename + strlen( filename ), ".ttf", 4 ); - strncpy( alt_filename + strlen( alt_filename ), ".ttc", 4 ); - } -#endif - i = strlen( filename ); - fname = filename; - - while ( i >= 0 ) -#ifndef macintosh - if ( filename[i] == '/' || filename[i] == '\\' ) -#else - if ( filename[i] == ':' ) -#endif - { - fname = filename + i + 1; - i = -1; - } - else - i--; - - printf( "%s: ", fname ); - - /* Load face */ - error = FT_New_Face( library, filename, 0, &face ); - if (error) - { - if (error == FT_Err_Unknown_File_Format) - printf( "unknown format\n" ); - else - printf( "could not find/open file (error: %d)\n", error ); - continue; - } - if (error) Panic( "Could not open file" ); - - Success: - num_glyphs = face->num_glyphs; - - error = FT_Set_Char_Size( face, ptsize << 6, ptsize << 6, 72, 72 ); - if (error) Panic( "Could not set character size" ); - - Fail = 0; - { - for ( id = 0; id < num_glyphs; id++ ) - { - error = FT_Load_Glyph( face, id, FT_LOAD_DEFAULT ); - if (error) - { - if ( Fail < 10 ) - printf( "glyph %4u: 0x%04x\n" , id, error ); - Fail++; - } - } - } - - if ( Fail == 0 ) - printf( "OK.\n" ); - else - if ( Fail == 1 ) - printf( "1 fail.\n" ); - else - printf( "%d fails.\n", Fail ); - - FT_Done_Face( face ); - } - - FT_Done_FreeType(library); - exit( 0 ); /* for safety reasons */ - - return 0; /* never reached */ - } - - -/* End */ diff --git a/demos/src/ftmulti.c b/demos/src/ftmulti.c deleted file mode 100644 index 7cca05303..000000000 --- a/demos/src/ftmulti.c +++ /dev/null @@ -1,833 +0,0 @@ -/****************************************************************************/ -/* */ -/* The FreeType project -- a free and portable quality TrueType renderer. */ -/* */ -/* Copyright 1996-2000 by */ -/* D. Turner, R.Wilhelm, and W. Lemberg */ -/* */ -/* */ -/* FTMulti- a simple multiple masters font viewer */ -/* */ -/* Press F1 when running this program to have a list of key-bindings */ -/* */ -/****************************************************************************/ - -#include -#include - -#include "common.h" - -#include -#include -#include -#include - -#include "graph.h" -#include "grfont.h" - -#define DIM_X 500 -#define DIM_Y 400 - -#define CENTER_X ( bit.width / 2 ) -#define CENTER_Y ( bit.rows / 2 ) - -#define MAXPTSIZE 500 /* dtp */ - - char Header[128]; - char* new_header = 0; - - const unsigned char* Text = (unsigned char*) - "The quick brown fox jumped over the lazy dog 0123456789 " - "\342\352\356\373\364\344\353\357\366\374\377\340\371\351\350\347 " - "&#~\"\'(-`_^@)=+\260 ABCDEFGHIJKLMNOPQRSTUVWXYZ " - "$\243^\250*\265\371%!\247:/;.,?<>"; - - FT_Library library; /* the FreeType library */ - FT_Face face; /* the font face */ - FT_Size size; /* the font size */ - FT_GlyphSlot glyph; /* the glyph slot */ - - FT_Error error; /* error returned by FreeType? */ - - grSurface* surface; /* current display surface */ - grBitmap bit; /* current display bitmap */ - - int num_glyphs; /* number of glyphs */ - int ptsize; /* current point size */ - - int hinted = 1; /* is glyph hinting active? */ - int antialias = 1; /* is anti-aliasing active? */ - int use_sbits = 1; /* do we use embedded bitmaps? */ - int low_prec = 0; /* force low precision */ - int Num; /* current first glyph index */ - - int res = 72; - - static grColor fore_color = { 255 }; - - int Fail; - unsigned char autorun; - - int graph_init = 0; - - int render_mode = 1; - int use_grays = 1; - - FT_Multi_Master multimaster; - FT_Long design_pos[T1_MAX_MM_AXIS]; - -#define RASTER_BUFF_SIZE 32768 - char raster_buff[RASTER_BUFF_SIZE]; - -#define DEBUGxxx - -#ifdef DEBUG -#define LOG( x ) LogMessage##x -#else -#define LOG( x ) /* empty */ -#endif - -#ifdef DEBUG - static - void LogMessage( const char* fmt, ... ) - { - va_list ap; - - - va_start( ap, fmt ); - vfprintf( stderr, fmt, ap ); - va_end( ap ); - } -#endif - - - /* PanicZ */ - static - void PanicZ( const char* message ) - { - fprintf( stderr, "%s\n error = 0x%04x\n", message, error ); - exit( 1 ); - } - - - /* Clears the Bit bitmap/pixmap */ - static - void Clear_Display( void ) - { - long size = (long)bit.pitch * bit.rows; - - - if ( size < 0 ) - size = -size; - memset( bit.buffer, 0, size ); - } - - - /* Initialize the display bitmap named `bit' */ - static - void Init_Display( void ) - { - grInitDevices(); - - bit.mode = gr_pixel_mode_gray; - bit.width = DIM_X; - bit.rows = DIM_Y; - bit.grays = 256; - - surface = grNewSurface( 0, &bit ); - if ( !surface ) - PanicZ( "could not allocate display surface\n" ); - - graph_init = 1; - } - - -#define MAX_BUFFER 300000 - -#define FLOOR( x ) ( (x) & -64 ) -#define CEIL( x ) ( ( (x) + 63 ) & -64 ) -#define TRUNC( x ) ( (x) >> 6 ) - - static - char bit_buffer[MAX_BUFFER]; - - - /* Render a single glyph with the `grays' component */ - static - FT_Error Render_Glyph( int x_offset, - int y_offset ) - { - grBitmap bit3; - FT_Pos x_top, y_top; - - /* first, render the glyph image into a bitmap */ - if (glyph->format != ft_glyph_format_bitmap) - { - error = FT_Render_Glyph( glyph, antialias ? ft_render_mode_normal : ft_render_mode_mono ); - if (error) return error; - - } - - /* now blit it to our display screen */ - bit3.rows = glyph->bitmap.rows; - bit3.width = glyph->bitmap.width; - bit3.pitch = glyph->bitmap.pitch; - bit3.buffer = glyph->bitmap.buffer; - - switch (glyph->bitmap.pixel_mode) - { - case ft_pixel_mode_mono: - bit3.mode = gr_pixel_mode_mono; - bit3.grays = 0; - break; - - case ft_pixel_mode_grays: - bit3.mode = gr_pixel_mode_gray; - bit3.grays = glyph->bitmap.num_grays; - } - - /* Then, blit the image to the target surface */ - x_top = x_offset + glyph->bitmap_left; - y_top = y_offset - glyph->bitmap_top; - - grBlitGlyphToBitmap( &bit, &bit3, x_top, y_top, fore_color ); - - return 0; - } - - - - static - FT_Error Reset_Scale( int pointSize ) - { - FT_Error error; - - - error = FT_Set_Char_Size( face, pointSize << 6, - pointSize << 6, - res, - res ); - return FT_Err_Ok; - } - - - static - FT_Error LoadChar( int idx, - int hint ) - { - int flags; - - - flags = FT_LOAD_DEFAULT; - - if ( !hint ) - flags |= FT_LOAD_NO_HINTING; - - if ( !use_sbits ) - flags |= FT_LOAD_NO_BITMAP; - - return FT_Load_Glyph( face, idx, flags ); - } - - - static - FT_Error Render_All( int first_glyph, - int ptsize ) - { - FT_F26Dot6 start_x, start_y, step_x, step_y, x, y; - int i; - - FT_Error error; - - - start_x = 4; - start_y = 36 + ptsize; - - step_x = size->metrics.x_ppem + 4; - step_y = size->metrics.y_ppem + 10; - - x = start_x; - y = start_y; - - i = first_glyph; - -#if 0 - while ( i < first_glyph + 1 ) -#else - while ( i < num_glyphs ) -#endif - { - if ( !( error = LoadChar( i, hinted ) ) ) - { -#ifdef DEBUG - if ( i <= first_glyph + 6 ) - { - LOG(( "metrics[%02d] = [%x %x]\n", - i, - glyph->metrics.horiBearingX, - glyph->metrics.horiAdvance )); - - if ( i == first_glyph + 6 ) - LOG(( "-------------------------\n" )); - } -#endif - - Render_Glyph( x, y ); - - x += ( glyph->metrics.horiAdvance >> 6 ) + 1; - - if ( x + size->metrics.x_ppem > bit.width ) - { - x = start_x; - y += step_y; - - if ( y >= bit.rows ) - return FT_Err_Ok; - } - } - else - Fail++; - - i++; - } - - return FT_Err_Ok; - } - - - static - FT_Error Render_Text( int first_glyph, - int ptsize ) - { - FT_F26Dot6 start_x, start_y, step_x, step_y, x, y; - int i; - - FT_Error error; - const unsigned char* p; - - - ptsize=ptsize; - - start_x = 4; - start_y = 32 + size->metrics.y_ppem; - - step_x = size->metrics.x_ppem + 4; - step_y = size->metrics.y_ppem + 10; - - x = start_x; - y = start_y; - - i = first_glyph; - p = Text; - while ( i > 0 && *p ) - { - p++; - i--; - } - - while ( *p ) - { - if ( !( error = LoadChar( FT_Get_Char_Index( face, - (unsigned char)*p ), - hinted ) ) ) - { -#ifdef DEBUG - if ( i <= first_glyph + 6 ) - { - LOG(( "metrics[%02d] = [%x %x]\n", - i, - glyph->metrics.horiBearingX, - glyph->metrics.horiAdvance )); - - if ( i == first_glyph + 6 ) - LOG(( "-------------------------\n" )); - } -#endif - - Render_Glyph( x, y ); - - x += ( glyph->metrics.horiAdvance >> 6 ) + 1; - - if ( x + size->metrics.x_ppem > bit.width ) - { - x = start_x; - y += step_y; - - if ( y >= bit.rows ) - return FT_Err_Ok; - } - } - else - Fail++; - - i++; - p++; - } - - return FT_Err_Ok; - } - - - static - void Help( void ) - { - grEvent dummy_event; - - - Clear_Display(); - - grGotoxy( 0, 0 ); - grSetMargin( 2, 1 ); - grGotobitmap( &bit ); - - grWriteln("FreeType Glyph Viewer - part of the FreeType test suite" ); - grLn(); - grWriteln("This program is used to display all glyphs from one or" ); - grWriteln("several font files, with the FreeType library."); - grLn(); - grWriteln("Use the following keys:"); - grLn(); - grWriteln(" F1 or ? : display this help screen" ); - grWriteln(" a : toggle anti-aliasing" ); - grWriteln(" h : toggle outline hinting" ); - grWriteln(" b : toggle embedded bitmaps" ); - grWriteln(" l : toggle low precision rendering" ); - grWriteln(" space : toggle rendering mode" ); - grLn(); - grWriteln(" Up : increase pointsize by 1 unit" ); - grWriteln(" Down : decrease pointsize by 1 unit" ); - grWriteln(" Page Up : increase pointsize by 10 units" ); - grWriteln(" Page Down : decrease pointsize by 10 units" ); - grLn(); - grWriteln(" Right : increment first glyph index" ); - grWriteln(" Left : decrement first glyph index" ); - grLn(); - grWriteln(" F3 : decrement first axis position by 20" ); - grWriteln(" F4 : increment first axis position by 20" ); - grWriteln(" F5 : decrement second axis position by 20" ); - grWriteln(" F6 : increment second axis position by 20" ); - grWriteln(" F7 : decrement third axis position by 20" ); - grWriteln(" F8 : increment third axis position by 20" ); - grLn(); - grWriteln("press any key to exit this help screen"); - - grRefreshSurface( surface ); - grListenSurface( surface, gr_event_key, &dummy_event ); - } - - - - static - int Process_Event( grEvent* event ) - { - int i, axis; - - switch ( event->key ) - { - case grKeyEsc: /* ESC or q */ - case grKEY( 'q' ): - return 0; - - case grKeyF1: - case grKEY( '?' ): - Help(); - return 1; - - /* mode keys */ - - case grKEY( 'a' ): - antialias = !antialias; - new_header = antialias ? "anti-aliasing is now on" - : "anti-aliasing is now off"; - return 1; - - case grKEY( 'b' ): - use_sbits = !use_sbits; - new_header = use_sbits ? "embedded bitmaps are now used if available" - : "embedded bitmaps are now ignored"; - return 1; - - case grKEY( 'n' ): - case grKEY( 'p' ): - return (int)event->key; - - case grKEY( 'l' ): - low_prec = !low_prec; - new_header = low_prec ? "rendering precision is now forced to low" - : "rendering precision is now normal"; - break; - - case grKEY( 'h' ): - hinted = !hinted; - new_header = hinted ? "glyph hinting is now active" - : "glyph hinting is now ignored"; - break; - - case grKEY( ' ' ): - render_mode ^= 1; - new_header = render_mode ? "rendering all glyphs in font" - : "rendering test text string"; - break; - - /* MM related keys */ - - case grKeyF3: - i = -20; - axis = 0; - goto Do_Axis; - - case grKeyF4: - i = 20; - axis = 0; - goto Do_Axis; - - case grKeyF5: - i = -20; - axis = 1; - goto Do_Axis; - - case grKeyF6: - i = 20; - axis = 1; - goto Do_Axis; - - case grKeyF7: - i = -20; - axis = 2; - goto Do_Axis; - - case grKeyF8: - i = 20; - axis = 2; - goto Do_Axis; - - /* scaling related keys */ - - case grKeyPageUp: - i = 10; - goto Do_Scale; - - case grKeyPageDown: - i = -10; - goto Do_Scale; - - case grKeyUp: - i = 1; - goto Do_Scale; - - case grKeyDown: - i = -1; - goto Do_Scale; - - /* glyph index related keys */ - - case grKeyLeft: - i = -1; - goto Do_Glyph; - - case grKeyRight: - i = 1; - goto Do_Glyph; - - case grKeyF9: - i = -100; - goto Do_Glyph; - - case grKeyF10: - i = 100; - goto Do_Glyph; - - case grKeyF11: - i = -1000; - goto Do_Glyph; - - case grKeyF12: - i = 1000; - goto Do_Glyph; - - default: - ; - } - return 1; - - Do_Axis: - if ( axis < (int)multimaster.num_axis ) - { - FT_MM_Axis* a = multimaster.axis + axis; - FT_Long pos = design_pos[axis]; - - - pos += i; - if ( pos < a->minimum ) pos = a->minimum; - if ( pos > a->maximum ) pos = a->maximum; - - design_pos[axis] = pos; - - FT_Set_MM_Design_Coordinates( face, multimaster.num_axis, design_pos ); - } - return 1; - - Do_Scale: - ptsize += i; - if ( ptsize < 1 ) ptsize = 1; - if ( ptsize > MAXPTSIZE ) ptsize = MAXPTSIZE; - return 1; - - Do_Glyph: - Num += i; - if ( Num < 0 ) Num = 0; - if ( Num >= num_glyphs ) Num = num_glyphs - 1; - return 1; - } - - - static - void usage( char* execname ) - { - fprintf( stderr, "\n" ); - fprintf( stderr, "ftmulti: multiple masters font viewer - part of FreeType\n" ); - fprintf( stderr, "--------------------------------------------------------\n" ); - fprintf( stderr, "\n" ); - fprintf( stderr, "Usage: %s [options below] ppem fontname[.ttf|.ttc] ...\n", - execname ); - fprintf( stderr, "\n" ); - fprintf( stderr, " -r R use resolution R dpi (default: 72 dpi)\n" ); - fprintf( stderr, " -f index specify first glyph index to display\n" ); - fprintf( stderr, "\n" ); - - exit( 1 ); - } - - - int - main( int argc, - char* argv[] ) - { - int old_ptsize, orig_ptsize, file; - int first_glyph = 0; - int XisSetup = 0; - char* execname; - int option; - int file_loaded; - - FT_Error error; - grEvent event; - - execname = ft_basename( argv[0] ); - - while ( 1 ) - { - option = getopt( argc, argv, "f:r:" ); - - if ( option == -1 ) - break; - - switch ( option ) - { - case 'f': - first_glyph = atoi( optarg ); - break; - - case 'r': - res = atoi( optarg ); - if ( res < 1 ) - usage( execname ); - break; - - default: - usage( execname ); - break; - } - } - - argc -= optind; - argv += optind; - - if ( argc <= 1 ) - usage( execname ); - - if ( sscanf( argv[0], "%d", &orig_ptsize ) != 1 ) - orig_ptsize = 64; - - file = 1; - - /* Initialize engine */ - error = FT_Init_FreeType( &library ); - if ( error ) - PanicZ( "Could not initialize FreeType library" ); - - NewFile: - ptsize = orig_ptsize; - hinted = 1; - file_loaded = 0; - - /* Load face */ - error = FT_New_Face( library, argv[file], 0, &face ); - if ( error ) - goto Display_Font; - - /* retrieve multiple master information */ - error = FT_Get_Multi_Master( face, &multimaster ); - if ( error ) - goto Display_Font; - - /* set the current position to the median of each axis */ - { - int n; - - - for ( n = 0; n < (int)multimaster.num_axis; n++ ) - design_pos[n] = - ( multimaster.axis[n].minimum + multimaster.axis[n].maximum ) / 2; - } - - error = FT_Set_MM_Design_Coordinates( face, - multimaster.num_axis, - design_pos ); - if ( error ) - goto Display_Font; - - file_loaded++; - - error = Reset_Scale( ptsize ); - if ( error ) - goto Display_Font; - - num_glyphs = face->num_glyphs; - glyph = face->glyph; - size = face->size; - - Display_Font: - /* initialize graphics if needed */ - if ( !XisSetup ) - { - XisSetup = 1; - Init_Display(); - } - - grSetTitle( surface, "FreeType Glyph Viewer - press F1 for help" ); - old_ptsize = ptsize; - - if ( file_loaded >= 1 ) - { - Fail = 0; - Num = first_glyph; - - if ( Num >= num_glyphs ) - Num = num_glyphs - 1; - - if ( Num < 0 ) - Num = 0; - } - - for ( ;; ) - { - int key; - - - Clear_Display(); - - if ( file_loaded >= 1 ) - { - switch ( render_mode ) - { - case 0: - Render_Text( Num, ptsize ); - break; - - default: - Render_All( Num, ptsize ); - } - - sprintf( Header, "%s %s (file %s)", - face->family_name, - face->style_name, - ft_basename( argv[file] ) ); - - if ( !new_header ) - new_header = Header; - - grWriteCellString( &bit, 0, 0, new_header, fore_color ); - new_header = 0; - - sprintf( Header, "axis: " ); - { - int n; - - - for ( n = 0; n < (int)multimaster.num_axis; n++ ) - { - char temp[32]; - - - sprintf( temp, " %s:%ld", - multimaster.axis[n].name, - design_pos[n] ); - strcat( Header, temp ); - } - } - grWriteCellString( &bit, 0, 16, Header, fore_color ); - - sprintf( Header, "at %d points, first glyph = %d", - ptsize, - Num ); - } - else - { - sprintf( Header, "%s : not an MM font file, or could not be opened", - ft_basename( argv[file] ) ); - } - - grWriteCellString( &bit, 0, 8, Header, fore_color ); - grRefreshSurface( surface ); - - grListenSurface( surface, 0, &event ); - if ( !( key = Process_Event( &event ) ) ) - goto End; - - if ( key == 'n' ) - { - if ( file_loaded >= 1 ) - FT_Done_Face( face ); - - if ( file < argc - 1 ) - file++; - - goto NewFile; - } - - if ( key == 'p' ) - { - if ( file_loaded >= 1 ) - FT_Done_Face( face ); - - if ( file > 1 ) - file--; - - goto NewFile; - } - - if ( ptsize != old_ptsize ) - { - if ( Reset_Scale( ptsize ) ) - PanicZ( "Could not resize font." ); - - old_ptsize = ptsize; - } - } - - End: -#if 0 - grDoneSurface( surface ); - grDone(); -#endif - - printf( "Execution completed successfully.\n" ); - printf( "Fails = %d\n", Fail ); - - exit( 0 ); /* for safety reasons */ - return 0; /* never reached */ -} - - -/* End */ diff --git a/demos/src/ftsbit.c b/demos/src/ftsbit.c deleted file mode 100644 index 11e310839..000000000 --- a/demos/src/ftsbit.c +++ /dev/null @@ -1,313 +0,0 @@ -/****************************************************************************/ -/* */ -/* The FreeType project -- a free and portable quality TrueType renderer. */ -/* */ -/* Copyright 1996-1998 by */ -/* D. Turner, R.Wilhelm, and W. Lemberg */ -/* */ -/* ftsbit: a _very_ simple embedded bitmap dumper for FreeType 1.x. */ -/* */ -/* NOTE: This is just a test program that is used to show off and */ -/* debug the current engine. */ -/* */ -/****************************************************************************/ - - -#include -#include -#include - -#include "freetype.h" - - -#ifdef HAVE_LIBINTL_H - -#ifdef HAVE_LOCALE_H -#include -#endif - -#include -#include "ftxerr18.h" - -#else /* !HAVE_LIBINTL */ - -#define gettext( x ) ( x ) - - /* We ignore error message strings with this function */ - - static char* TT_ErrToString18( FT_Error error ) - { - static char temp[32]; - - sprintf( temp, "0x%04lx", error ); - return temp; - } - -#endif /* !HAVE_LIBINTL */ - - - FT_Error error; - FT_Library engine; - FT_Resource resource; - - FT_Face face; - FT_Size instance; - FT_GlyphSlot glyph; - - unsigned int num_glyphs; - int ptsize; - - int Fail; - int Num; - - - - static void Usage( char* name ) - { - printf( gettext( "ftsbit: simple TrueType 'sbit' dumper -- part of the FreeType project\n" ) ); - printf( "---------------------------------------------------------------------\n" ); - printf( "\n" ); - printf( gettext( "Usage: %s ppem fontname (index)* (index1-index2)*\n\n" ), name ); - printf( gettext( " or %s -a ppem fontname (dumps all glyphs)\n" ), name ); - printf( "\n" ); - - exit( EXIT_FAILURE ); - } - - - - static - void dump_bitmap( FT_GlyphSlot glyph, int glyph_index ) - { - /* Dump the resulting bitmap */ - { - int y; - unsigned char* line = (unsigned char*)glyph->bitmap.buffer; - - printf( "glyph index %d = %dx%d pixels, ", - glyph_index, glyph->bitmap.rows, glyph->bitmap.width ); - - printf( "advance = %d, minBearing = [%d,%d]\n", - glyph->metrics.horiAdvance >> 6, - glyph->metrics.horiBearingX >> 6, - glyph->metrics.horiBearingY >> 6 ); - - for ( y = 0; y < glyph->bitmap.rows; y++, line += glyph->bitmap.cols ) - { - unsigned char* ptr = line; - int x; - unsigned char mask = 0x80; - - for ( x = 0; x < glyph->bitmap.width; x++ ) - { - printf( "%c", (ptr[0] & mask) ? '*' : '.' ); - mask >>= 1; - if (mask == 0) - { - mask = 0x80; - ptr++; - } - } - - printf( "\n" ); - } - } - } - - - - static - void dump_range( FT_GlyphSlot glyph, - int first_glyph, - int last_glyph ) - { - int i; - - for ( i = first_glyph; i <= last_glyph; i++ ) - { - error = FT_Load_Glyph( glyph, - instance, - (unsigned short)i, - FT_LOAD_NO_OUTLINE, - 0 ); - if (error) - { - printf( " no bitmap for glyph %d\n", i ); - printf( gettext( "FreeType error message: %s\n" ), - TT_ErrToString18( error ) ); - continue; - } - - dump_bitmap(glyph,i); - } - } - - - - - int main( int argc, char** argv ) - { - int i; - char filename[128 + 4]; - char alt_filename[128 + 4]; - char* execname; - char* fname; - int dump_all = 0; - - -#ifdef HAVE_LIBINTL_H - setlocale( LC_ALL, "" ); - bindtextdomain( "freetype", LOCALEDIR ); - textdomain( "freetype" ); -#endif - - execname = argv[0]; - - if ( argc < 3 ) - Usage( execname ); - - if ( argv[1][0] == '-' && - argv[1][1] == 'a' ) - { - argv++; - argc--; - dump_all = 1; - } - - if ( sscanf( argv[1], "%d", &ptsize ) != 1 ) - Usage( execname ); - - /* Initialize engine */ - if ( (error = FT_Init_FreeType( &engine )) ) - { - fprintf( stderr, gettext( "Error while initializing engine\n" ) ); - goto Failure; - } - - /* Now check all files */ - fname = argv[2]; - i = strlen( fname ); - while ( i > 0 && fname[i] != '\\' && fname[i] != '/' ) - { - if ( fname[i] == '.' ) - i = 0; - i--; - } - - filename[128] = '\0'; - alt_filename[128] = '\0'; - - strncpy( filename, fname, 128 ); - strncpy( alt_filename, fname, 128 ); - - if ( i >= 0 ) - { - strncpy( filename + strlen( filename ), ".ttf", 4 ); - strncpy( alt_filename + strlen( alt_filename ), ".ttc", 4 ); - } - - /* Load face */ - error = FT_New_Resource( engine, filename, &resource ); - if (error) - { - strcpy( filename, alt_filename ); - error = FT_New_Resource( engine, alt_filename, &resource ); - } - - i = strlen( filename ); - fname = filename; - - while ( i >= 0 ) - if ( filename[i] == '/' || filename[i] == '\\' ) - { - fname = filename + i + 1; - i = -1; - } - else - i--; - - if ( error ) - { - printf( gettext( "Could not find or open file.\n" ) ); - goto Failure; - } - - error = FT_New_Face( resource, 0, &face ); - if (error) - { - printf( gettext( "Could not create face object.\n " ) ); - goto Failure; - } - - /* get face properties */ - num_glyphs = face->num_glyphs; - - /* create instance */ - error = FT_New_Size( face, &instance ); - if ( error ) - { - printf( gettext( "Could not create instance.\n" ) ); - goto Failure; - } - - error = FT_Set_Pixel_Sizes( instance, ptsize, ptsize ); - if (error) - { - printf( gettext( "Could not set character size.\n" ) ); - goto Failure; - } - - glyph = face->slot; - - if (dump_all) - dump_range( glyph, 0, num_glyphs-1 ); - else - { - for ( i = 3; i < argc; i++ ) - { - /* check for range in argument string */ - int range_check = 0; - char* base = argv[i]; - char* cur = base; - int first, last; - - while (*cur) - { - if (*cur == '-') - { - range_check = 1; - break; - } - cur++; - } - - if (range_check) - { - if ( sscanf( argv[i], "%d-%d", &first, &last ) != 2 ) - Usage( execname ); - - dump_range( glyph, first, last ); - } - else - { - if ( sscanf( argv[i], "%d", &first ) != 1 ) - Usage( execname ); - - dump_range( glyph, first, first ); - } - } - } - - FT_Done_FreeType( engine ); - exit( EXIT_SUCCESS ); /* for safety reasons */ - - return 0; /* never reached */ - - Failure: - printf( gettext( "FreeType error message: %s\n" ), - TT_ErrToString18( error ) ); - exit( EXIT_FAILURE ); - } - - -/* End */ diff --git a/demos/src/ftstring.c b/demos/src/ftstring.c deleted file mode 100644 index 2f434aed2..000000000 --- a/demos/src/ftstring.c +++ /dev/null @@ -1,777 +0,0 @@ -/****************************************************************************/ -/* */ -/* The FreeType project -- a free and portable quality TrueType renderer. */ -/* */ -/* Copyright 1996-1999 by */ -/* D. Turner, R.Wilhelm, and W. Lemberg */ -/* */ -/* */ -/* FTString.c - simple text string display */ -/* */ -/****************************************************************************/ - -#include -#include -#include "common.h" - -#include -#include -#include -#include -#include - -#include "graph.h" -#include "grfont.h" - -#define DIM_X 500 -#define DIM_Y 400 - -#define CENTER_X (bit.width/2) -#define CENTER_Y (bit.rows/2) - -#define MAXPTSIZE 500 /* dtp */ - - static char Header[128]; - static char* new_header = 0; - - static char* Text = "The quick brown fox jumps over the lazy dog"; - - static FT_Library library; /* the FreeType library */ - static FT_Face face; /* the font face */ - static FT_Error error; /* error returned by FreeType ? */ - - static grSurface* surface; /* current display surface */ - static grBitmap bit; /* current display bitmap */ - - static int ptsize; /* current point size */ - static int Num; - static int Rotation = 0; - static int Fail; - - static int hinted = 1; /* is glyph hinting active ? */ - static int antialias = 1; /* is anti-aliasing active ? */ - static int use_sbits = 1; /* do we use embedded bitmaps ? */ - static int kerning = 1; - - static int res = 72; /* default resolution in dpi */ - - static grColor fore_color = { 255 }; - - static int graph_init = 0; - static int render_mode = 1; - - static FT_Matrix trans_matrix; - static int transform = 0; - - static FT_Vector string_center; - - typedef struct TGlyph_ - { - FT_UInt glyph_index; /* glyph index in face */ - FT_Vector pos; /* position of glyph origin */ - FT_Glyph image; /* glyph image */ - - } TGlyph, *PGlyph; - -#define FLOOR(x) ((x) & -64) -#define CEIL(x) (((x)+63) & -64) -#define TRUNC(x) ((x) >> 6) - - - -/****************************************************************************/ -/****************************************************************************/ -/****************************************************************************/ -/**** ****/ -/**** U T I L I T Y F U N C T I O N S ****/ -/**** ****/ -/**** ****/ -/****************************************************************************/ -/****************************************************************************/ -/****************************************************************************/ - -#define DEBUGxxx - -#ifdef DEBUG -#define LOG(x) LogMessage##x -#else -#define LOG(x) /* rien */ -#endif - -#ifdef DEBUG - static void LogMessage( const char* fmt, ... ) - { - va_list ap; - - va_start( ap, fmt ); - vfprintf( stderr, fmt, ap ); - va_end( ap ); - } -#endif - - /* PanicZ */ - static void PanicZ( const char* message ) - { - fprintf( stderr, "%s\n error = 0x%04x\n", message, error ); - exit(1); - } - - -/****************************************************************************/ -/****************************************************************************/ -/****************************************************************************/ -/**** ****/ -/**** D I S P L A Y M A N A G E M E N T ****/ -/**** ****/ -/**** ****/ -/****************************************************************************/ -/****************************************************************************/ -/****************************************************************************/ - -#define MAX_GLYPHS 512 - - /*********************************************************************** - * - * The following arrays are used to store the glyph set that makes - * up a string of text.. - * - */ - static TGlyph glyphs[ MAX_GLYPHS ]; - static int num_glyphs; - - - /************************************************************** - * - * Initialise the display surface - * - */ - static int init_display( void ) - { - grInitDevices(); - - bit.mode = gr_pixel_mode_gray; - bit.width = DIM_X; - bit.rows = DIM_Y; - bit.grays = 256; - - surface = grNewSurface( 0, &bit ); - if (!surface) - PanicZ( "could not allocate display surface\n" ); - - graph_init = 1; - return 0; - } - - /************************************************************** - * - * Clears the display surface - * - */ - static void clear_display( void ) - { - long size = (long)bit.pitch * bit.rows; - - if (size < 0) size = -size; - memset( bit.buffer, 0, size ); - } - - - static FT_Error reset_scale( int pointSize ) - { - FT_Error error; - - error = FT_Set_Char_Size( face, pointSize << 6, - pointSize << 6, - res, - res ); - return FT_Err_Ok; - } - - - /************************************************************** - * - * Layout a string of glyphs, the glyphs are untransformed.. - * - */ - static void layout_glyphs( void ) - { - PGlyph glyph = glyphs; - FT_Error error; - int n; - FT_Vector origin; - FT_Pos origin_x = 0; - FT_UInt load_flags; - FT_UInt num_grays; - FT_UInt prev_index = 0; - - load_flags = FT_LOAD_DEFAULT; - if( !hinted ) - load_flags |= FT_LOAD_NO_HINTING; - - num_grays = 256; - if (!antialias) - num_grays = 0; - - for ( n = 0; n < num_glyphs; n++, glyph++ ) - { - /* compute glyph origin */ - if (kerning) - { - if (prev_index) - { - FT_Vector kern; - - FT_Get_Kerning( face, prev_index, glyph->glyph_index, - hinted ? ft_kerning_default : ft_kerning_unfitted, - &kern ); - - origin_x += kern.x; - } - prev_index = glyph->glyph_index; - } - - origin.x = origin_x; - origin.y = 0; - - /* clear existing image if there is one */ - if (glyph->image) - FT_Done_Glyph(glyph->image); - - /* load the glyph image (in its native format) */ - /* for now, we take a monochrome glyph bitmap */ - error = FT_Load_Glyph( face, glyph->glyph_index, - hinted ? FT_LOAD_DEFAULT : FT_LOAD_NO_HINTING ) || - FT_Get_Glyph ( face->glyph, &glyph->image ); - if (error) continue; - - glyph->pos = origin; - - origin_x += face->glyph->advance.x; - } - string_center.x = origin_x / 2; - string_center.y = 0; - - if (transform) - FT_Vector_Transform( &string_center, &trans_matrix ); - } - - /************************************************************** - * - * Renders a given glyph vector set - * - */ - static void render_string( FT_Pos x, FT_Pos y ) - { - PGlyph glyph = glyphs; - grBitmap bit3; - int n; - FT_Vector delta; - - /* first of all, we must compute the general delta for the glyph */ - /* set.. */ - delta.x = (x << 6) - string_center.x; - delta.y = ((bit.rows-y) << 6) - string_center.y; - - for ( n = 0; n < num_glyphs; n++, glyph++ ) - { - FT_Glyph image; - FT_Vector vec; - - if (!glyph->image) - continue; - - /* copy image */ - error = FT_Glyph_Copy( glyph->image, &image ); - if (error) continue; - - /* transform it */ - vec = glyph->pos; - FT_Vector_Transform( &vec, &trans_matrix ); - vec.x += delta.x; - vec.y += delta.y; - error = FT_Glyph_Transform( image, &trans_matrix, &vec ); - if (!error) - { - FT_BBox bbox; - - /* check bounding box, if it's not within the display surface, we */ - /* don't need to render it.. */ - - FT_Glyph_Get_CBox( image, ft_glyph_bbox_pixels, &bbox ); - - if ( bbox.xMax > 0 && bbox.yMax > 0 && - bbox.xMin < bit.width && bbox.yMin < bit.rows ) - { - /* convert to a bitmap - destroy native image */ - error = FT_Glyph_To_Bitmap( &image, - antialias ? ft_render_mode_normal - : ft_render_mode_mono, - 0, 1 ); - if (!error) - { - FT_BitmapGlyph bitmap = (FT_BitmapGlyph)image; - FT_Bitmap* source = &bitmap->bitmap; - FT_Pos x_top, y_top; - - bit3.rows = source->rows; - bit3.width = source->width; - bit3.pitch = source->pitch; - bit3.buffer = source->buffer; - - switch (source->pixel_mode) - { - case ft_pixel_mode_mono: - bit3.mode = gr_pixel_mode_mono; - break; - - case ft_pixel_mode_grays: - bit3.mode = gr_pixel_mode_gray; - bit3.grays = source->num_grays; - break; - - default: - continue; - } - - /* now render the bitmap into the display surface */ - x_top = bitmap->left; - y_top = bit.rows - bitmap->top; - grBlitGlyphToBitmap( &bit, &bit3, x_top, y_top, fore_color ); - } - } - } - FT_Done_Glyph( image ); - } - } - - - /************************************************************** - * - * Convert a string of text into a glyph vector - * - * XXX: For now, we perform a trivial conversion - * - */ - static void prepare_text( const unsigned char* string ) - { - const unsigned char* p = (const unsigned char*)string; - PGlyph glyph = glyphs; - FT_UInt glyph_index; - - num_glyphs = 0; - while (*p) - { - glyph_index = FT_Get_Char_Index( face, (FT_ULong)*p ); - glyph->glyph_index = glyph_index; - glyph++; - num_glyphs++; - if (num_glyphs >= MAX_GLYPHS) - break; - p++; - } - } - - - static void reset_transform( void ) - { - double angle = Rotation*3.14159/64.0; - FT_Fixed cosinus = (FT_Fixed)(cos(angle)*65536.0); - FT_Fixed sinus = (FT_Fixed)(sin(angle)*65536.0); - - transform = (angle != 0); - trans_matrix.xx = cosinus; - trans_matrix.xy = -sinus; - trans_matrix.yx = sinus; - trans_matrix.yy = cosinus; - } - -/****************************************************************************/ -/****************************************************************************/ -/****************************************************************************/ -/**** ****/ -/**** E V E N T H A N D L I N G ****/ -/**** ****/ -/**** ****/ -/****************************************************************************/ -/****************************************************************************/ -/****************************************************************************/ - - - static void Help( ) - { - grEvent dummy_event; - - clear_display(); - grGotoxy( 0, 0 ); - grSetMargin( 2, 1 ); - grGotobitmap( &bit ); - - grWriteln("FreeType String Viewer - part of the FreeType test suite" ); - grLn(); - grWriteln("This program is used to display a string of text using" ); - grWriteln("the new convenience API of the FreeType 2 library."); - grLn(); - grWriteln("Use the following keys :"); - grLn(); - grWriteln(" F1 or ? : display this help screen" ); - grWriteln(" a : toggle anti-aliasing" ); - grWriteln(" h : toggle outline hinting" ); - grWriteln(" k : toggle kerning" ); - grLn(); - grWriteln(" Up : increase pointsize by 1 unit" ); - grWriteln(" Down : decrease pointsize by 1 unit" ); - grWriteln(" Page Up : increase pointsize by 10 units" ); - grWriteln(" Page Down : decrease pointsize by 10 units" ); - grLn(); - grWriteln(" Right : rotate counter-clockwise" ); - grWriteln(" Left : rotate clockwise" ); - grWriteln(" F7 : big rotate counter-clockwise"); - grWriteln(" F8 : big rotate clockwise"); - grLn(); - grWriteln("press any key to exit this help screen"); - - grRefreshSurface( surface ); - grListenSurface( surface, gr_event_key, &dummy_event ); - } - - - static int Process_Event( grEvent* event ) - { - int i; - - switch ( event->key ) - { - case grKeyEsc: /* ESC or q */ - case grKEY('q'): - return 0; - - case grKEY('k'): - kerning = !kerning; - new_header = ( kerning - ? "kerning is now active" - : "kerning is now ignored" ); - return 1; - - case grKEY('a'): - antialias = !antialias; - new_header = ( antialias - ? "anti-aliasing is now on" - : "anti-aliasing is now off" ); - return 1; - - case grKEY('b'): - use_sbits = !use_sbits; - new_header = ( use_sbits - ? "embedded bitmaps are now used when available" - : "embedded bitmaps are now ignored" ); - return 1; - - case grKEY('n'): - case grKEY('p'): - return (int)event->key; - - case grKEY('h'): - hinted = !hinted; - new_header = ( hinted - ? "glyph hinting is now active" - : "glyph hinting is now ignored" ); - break; - - case grKEY(' '): - render_mode ^= 1; - new_header = ( render_mode - ? "rendering all glyphs in font" - : "rendering test text string" ); - break; - - case grKeyF1: - case grKEY('?'): - Help(); - return 1; - -#if 0 - case grKeyF3: i = 16; goto Do_Rotate; - case grKeyF4: i = -16; goto Do_Rotate; - case grKeyF5: i = 1; goto Do_Rotate; - case grKeyF6: i = -1; goto Do_Rotate; -#endif - - case grKeyPageUp: i = 10; goto Do_Scale; - case grKeyPageDown: i = -10; goto Do_Scale; - case grKeyUp: i = 1; goto Do_Scale; - case grKeyDown: i = -1; goto Do_Scale; - - case grKeyLeft: i = -1; goto Do_Rotate; - case grKeyRight: i = 1; goto Do_Rotate; - case grKeyF7: i = -10; goto Do_Rotate; - case grKeyF8: i = 10; goto Do_Rotate; - default: - ; - } - return 1; - - Do_Rotate: - Rotation = (Rotation + i) & 127; - return 1; - - Do_Scale: - ptsize += i; - if (ptsize < 1) ptsize = 1; - if (ptsize > MAXPTSIZE) ptsize = MAXPTSIZE; - return 1; - -#if 0 - Do_Glyph: - Num += i; - if (Num < 0) Num = 0; - if (Num >= num_glyphs) Num = num_glyphs-1; - return 1; -#endif - } - - -/****************************************************************************/ -/****************************************************************************/ -/****************************************************************************/ -/**** ****/ -/**** M A I N P R O G R A M ****/ -/**** ****/ -/**** ****/ -/****************************************************************************/ -/****************************************************************************/ -/****************************************************************************/ - - - static void usage( char* execname ) - { - fprintf( stderr, "\n" ); - fprintf( stderr, "ftstring: string viewer -- part of the FreeType project\n" ); - fprintf( stderr, "-------------------------------------------------------\n" ); - fprintf( stderr, "\n" ); - fprintf( stderr, "Usage: %s [options below] ppem fontname[.ttf|.ttc] ...\n", - execname ); - fprintf( stderr, "\n" ); - fprintf( stderr, " -r R use resolution R dpi (default: 72 dpi)\n" ); - fprintf( stderr, " -m message message to display\n" ); - fprintf( stderr, "\n" ); - - exit( 1 ); - } - - - int main( int argc, char** argv ) - { - int i, old_ptsize, orig_ptsize, file; - int first_glyph = 0; - int XisSetup = 0; - char filename[128 + 4]; - char alt_filename[128 + 4]; - char* execname; - int option; - int file_loaded; - - FT_Error error; - grEvent event; - - execname = ft_basename( argv[0] ); - - while ( 1 ) - { - option = getopt( argc, argv, "m:r:" ); - - if ( option == -1 ) - break; - - switch ( option ) - { - case 'r': - res = atoi( optarg ); - if ( res < 1 ) - usage( execname ); - break; - - case 'm': - if (argc < 3) - usage( execname ); - Text = optarg; - break; - - default: - usage( execname ); - break; - } - } - - argc -= optind; - argv += optind; - - if ( argc <= 1 ) - usage( execname ); - - if ( sscanf( argv[0], "%d", &orig_ptsize ) != 1 ) - orig_ptsize = 64; - - file = 1; - - /* Initialize engine */ - error = FT_Init_FreeType( &library ); - if (error) PanicZ( "Could not initialise FreeType library" ); - - NewFile: - ptsize = orig_ptsize; - hinted = 1; - file_loaded = 0; - -#ifndef macintosh - i = strlen( argv[file] ); - while ( i > 0 && argv[file][i] != '\\' && argv[file][i] != '/' ) - { - if ( argv[file][i] == '.' ) - i = 0; - i--; - } -#endif - - filename[128] = '\0'; - alt_filename[128] = '\0'; - - strncpy( filename, argv[file], 128 ); - strncpy( alt_filename, argv[file], 128 ); - - /* first, try to load the glyph name as-is */ - error = FT_New_Face( library, filename, 0, &face ); - if (!error) goto Success; - -#ifndef macintosh - if ( i >= 0 ) - { - strncpy( filename + strlen( filename ), ".ttf", 4 ); - strncpy( alt_filename + strlen( alt_filename ), ".ttc", 4 ); - } -#endif - - /* if it didn't work, try to add ".ttf" at the end */ - error = FT_New_Face( library, filename, 0, &face ); - if (error) goto Display_Font; - - Success: - /* prepare the text to be rendered */ - prepare_text( (unsigned char*)Text ); - - file_loaded++; - - error = reset_scale( ptsize ); - if (error) goto Display_Font; - - Display_Font: - /* initialise graphics if needed */ - if ( !XisSetup ) - { - XisSetup = 1; - init_display(); - } - - grSetTitle( surface, "FreeType String Viewer - press F1 for help" ); - old_ptsize = ptsize; - - if ( file_loaded >= 1 ) - { - Fail = 0; - Num = first_glyph; - - if ( Num >= num_glyphs ) - Num = num_glyphs-1; - - if ( Num < 0 ) - Num = 0; - } - - for ( ;; ) - { - int key; - - clear_display(); - - if ( file_loaded >= 1 ) - { - /* layout & render string */ - { - reset_transform(); - layout_glyphs(); - render_string( bit.width/2, bit.rows/2 ); - } - - sprintf( Header, "%s %s (file %s)", - face->family_name, - face->style_name, - ft_basename( filename ) ); - - if (!new_header) - new_header = Header; - - grWriteCellString( &bit, 0, 0, new_header, fore_color ); - new_header = 0; - - sprintf( Header, "at %d points, rotation = %d", - ptsize, - Rotation ); - } - else - { - sprintf( Header, "%s : is not a font file or could not be opened", - ft_basename(filename) ); - } - - grWriteCellString( &bit, 0, 8, Header, fore_color ); - grRefreshSurface( surface ); - - grListenSurface( surface, 0, &event ); - if ( !( key = Process_Event( &event ) ) ) - goto Fin; - - if ( key == 'n' ) - { - if (file_loaded >= 1) - FT_Done_Face( face ); - - if ( file < argc - 1 ) - file++; - - goto NewFile; - } - - if ( key == 'p' ) - { - if (file_loaded >= 1) - FT_Done_Face( face ); - - if ( file > 1 ) - file--; - - goto NewFile; - } - - if ( ptsize != old_ptsize ) - { - if ( reset_scale( ptsize ) ) - PanicZ( "Could not resize font." ); - - old_ptsize = ptsize; - } - } - - Fin: -#if 0 - grDoneSurface(surface); - grDone(); -#endif - printf( "Execution completed successfully.\n" ); - printf( "Fails = %d\n", Fail ); - - exit( 0 ); /* for safety reasons */ - return 0; /* never reached */ -} - - -/* End */ - diff --git a/demos/src/fttimer.c b/demos/src/fttimer.c deleted file mode 100644 index b8a5ed1ad..000000000 --- a/demos/src/fttimer.c +++ /dev/null @@ -1,341 +0,0 @@ -/****************************************************************************/ -/* */ -/* The FreeType project - a Free and Portable Quality TrueType Renderer. */ -/* */ -/* Copyright 1996-1998 by */ -/* D. Turner, R.Wilhelm, and W. Lemberg */ -/* */ -/* fttimer: A simple performance benchmark. Now with graylevel rendering */ -/* with the '-g' option. */ -/* */ -/* Be aware that the timer program benchmarks different things */ -/* in each release of the FreeType library. Thus, performance */ -/* should only be compared between similar release numbers. */ -/* */ -/* */ -/* NOTE: This is just a test program that is used to show off and */ -/* debug the current engine. In no way does it shows the final */ -/* high-level interface that client applications will use. */ -/* */ -/****************************************************************************/ - -#include -#include - -#include -#include -#include -#include /* for clock() */ - -/* SunOS 4.1.* does not define CLOCKS_PER_SEC, so include */ -/* to get the HZ macro which is the equivalent. */ -#if defined(__sun__) && !defined(SVR4) && !defined(__SVR4) -#include -#define CLOCKS_PER_SEC HZ -#endif - -#define CHARSIZE 400 /* character point size */ -#define MAX_GLYPHS 512 /* Maximum number of glyphs rendered at one time */ - - char Header[128]; - - FT_Error error; - FT_Library library; - - FT_Face face; - - int num_glyphs; - FT_Glyph glyphs[MAX_GLYPHS]; - - int tab_glyphs; - int cur_glyph; - - int pixel_size = CHARSIZE; - int repeat_count = 1; - - int Fail; - int Num; - - short antialias = 1; /* smooth fonts with gray levels */ - short force_low; - - - static - void Panic( const char* message ) - { - fprintf( stderr, "%s\n", message ); - exit(1); - } - -/*******************************************************************/ -/* */ -/* Get_Time: */ -/* */ -/* Returns the current time in milliseconds. */ -/* */ -/*******************************************************************/ - - long Get_Time( void ) - { - return clock() * 10000 / CLOCKS_PER_SEC; - } - - - -/*******************************************************************/ -/* */ -/* LoadChar: */ -/* */ -/* Loads a glyph into memory. */ -/* */ -/*******************************************************************/ - - FT_Error LoadChar( int idx ) - { - FT_Glyph glyph; - - /* loads the glyph in the glyph slot */ - error = FT_Load_Glyph( face, idx, FT_LOAD_DEFAULT ) || - FT_Get_Glyph ( face->glyph, &glyph ); - if ( !error ) - { - glyphs[cur_glyph++] = glyph; - } - return error; - } - - - -/*******************************************************************/ -/* */ -/* ConvertRaster: */ -/* */ -/* Performs scan conversion. */ -/* */ -/*******************************************************************/ - - FT_Error ConvertRaster( int index ) - { - FT_Glyph bitmap; - FT_Error error; - - bitmap = glyphs[index]; - error = FT_Glyph_To_Bitmap( &bitmap, - antialias ? ft_render_mode_normal - : ft_render_mode_mono, - 0, - 0 ); - if (!error) - FT_Done_Glyph( bitmap ); - - return error; - } - - - static void Usage() - { - fprintf( stderr, "fttimer: simple performance timer -- part of the FreeType project\n" ); - fprintf( stderr, "-----------------------------------------------------------------\n\n" ); - fprintf( stderr, "Usage: fttimer [options] fontname[.ttf|.ttc]\n\n" ); - fprintf( stderr, "options:\n"); - fprintf( stderr, " -r : repeat count to be used (default is 1)\n" ); - fprintf( stderr, " -s : character pixel size (default is 600)\n" ); - fprintf( stderr, " -m : render monochrome glyphs (default is anti-aliased)\n" ); - fprintf( stderr, " -a : use smooth anti-aliaser\n" ); - fprintf( stderr, " -l : force low quality even at small sizes\n" ); - exit(1); - } - - - int main( int argc, char** argv ) - { - int i, total, base, rendered_glyphs; - char filename[128 + 4]; - char alt_filename[128 + 4]; - char* execname; - - long t, t0, tz0; - - - execname = argv[0]; - - antialias = 1; - force_low = 0; - - while ( argc > 1 && argv[1][0] == '-' ) - { - switch ( argv[1][1] ) - { - case 'm': - antialias = 0; - break; - - case 'l': - force_low = 1; - break; - - case 's': - argc--; - argv++; - if ( argc < 2 || - sscanf( argv[1], "%d", &pixel_size ) != 1 ) - Usage(); - break; - - case 'r': - argc--; - argv++; - if ( argc < 2 || - sscanf( argv[1], "%d", &repeat_count ) != 1 ) - Usage(); - if (repeat_count < 1) - repeat_count = 1; - break; - - default: - fprintf( stderr, "Unknown argument '%s'!\n", argv[1] ); - Usage(); - } - argc--; - argv++; - } - - if ( argc != 2 ) - Usage(); - - i = strlen( argv[1] ); - while ( i > 0 && argv[1][i] != '\\' ) - { - if ( argv[1][i] == '.' ) - i = 0; - i--; - } - - filename[128] = '\0'; - alt_filename[128] = '\0'; - - strncpy( filename, argv[1], 128 ); - strncpy( alt_filename, argv[1], 128 ); - - if ( i >= 0 ) - { - strncpy( filename + strlen( filename ), ".ttf", 4 ); - strncpy( alt_filename + strlen( alt_filename ), ".ttc", 4 ); - } - - /* Initialize engine */ - - if ( (error = FT_Init_FreeType( &library )) ) - Panic( "Error while initializing engine" ); - - /* Load face */ - - error = FT_New_Face( library, filename, 0, &face ); - if ( error == FT_Err_Cannot_Open_Stream ) - Panic( "Could not find/open font resource" ); - else if ( error ) - Panic( "Error while opening font resource" ); - - /* get face properties and allocate preload arrays */ - - num_glyphs = face->num_glyphs; - - tab_glyphs = MAX_GLYPHS; - if ( tab_glyphs > num_glyphs ) - tab_glyphs = num_glyphs; - - /* create size */ - - error = FT_Set_Pixel_Sizes( face, pixel_size, pixel_size ); - if ( error ) Panic( "Could not reset instance" ); - - Num = 0; - Fail = 0; - - total = num_glyphs; - base = 0; - - rendered_glyphs = 0; - - t0 = 0; /* Initial time */ - - tz0 = Get_Time(); - - while ( total > 0 ) - { - int repeat; - - /* First, preload 'tab_glyphs' in memory */ - cur_glyph = 0; - - printf( "loading %d glyphs", tab_glyphs ); - - for ( Num = 0; Num < tab_glyphs; Num++ ) - { - error = LoadChar( base + Num ); - if ( error ) - Fail++; - - total--; - } - - base += tab_glyphs; - - if ( tab_glyphs > total ) - tab_glyphs = total; - - printf( ", rendering... " ); - - /* Now, render the loaded glyphs */ - - t = Get_Time(); - - for ( repeat = 0; repeat < repeat_count; repeat++ ) - { - for ( Num = 0; Num < cur_glyph; Num++ ) - { - if ( (error = ConvertRaster( Num )) ) - Fail++; - - else - { - rendered_glyphs ++; - } - } - } - - t = Get_Time() - t; - if ( t < 0 ) - t += 1000 * 60 * 60; - - printf( " = %f s\n", (double)t / 10000 ); - t0 += t; - - /* Now free all loaded outlines */ - for ( Num = 0; Num < cur_glyph; Num++ ) - FT_Done_Glyph( glyphs[Num] ); - } - - tz0 = Get_Time() - tz0; - - FT_Done_Face( face ); - - printf( "\n" ); - printf( "rendered glyphs = %d\n", rendered_glyphs ); - printf( "render time = %f s\n", (double)t0 / 10000 ); - printf( "fails = %d\n", Fail ); - printf( "average glyphs/s = %f\n", - (double)rendered_glyphs / t0 * 10000 ); - - printf( "total timing = %f s\n", (double)tz0 / 10000 ); - printf( "Fails = %d\n", Fail ); - - FT_Done_FreeType( library ); - - exit( 0 ); /* for safety reasons */ - - return 0; /* never reached */ - } - - -/* End */ diff --git a/demos/src/fttry.c b/demos/src/fttry.c deleted file mode 100644 index c0b9cac6f..000000000 --- a/demos/src/fttry.c +++ /dev/null @@ -1,155 +0,0 @@ -/****************************************************************************/ -/* */ -/* The FreeType project -- a free and portable quality TrueType renderer. */ -/* */ -/* Copyright 1996-1998 by */ -/* D. Turner, R.Wilhelm, and W. Lemberg */ -/* */ -/* ftlint: a simple TrueType instruction tester. */ -/* */ -/* NOTE: This is just a test program that is used to show off and */ -/* debug the current engine. */ -/* */ -/****************************************************************************/ - -#include "freetype.h" - -#include -#include -#include - - -#define gettext( x ) ( x ) - - FT_Error error; - - FT_Library library; - FT_Face face; - - unsigned int num_glyphs; - int ptsize; - - int Fail; - int Num; - - - - static void Usage( char* name ) - { - printf( "fttry: simple TrueType instruction tester -- part of the FreeType project\n" ); - printf( "--------------------------------------------------------------------------\n" ); - printf( "\n" ); - printf( "Usage: %s ppem glyph fontname [fontname2..]\n\n", name ); - printf( " or %s -u glyph fontname [fontname2..]\n", name ); - printf( " to load an unscaled glyph\n\n" ); - - exit( 1 ); - } - - - static void Panic( const char* message ) - { - fprintf( stderr, "%s\n error code = 0x%04x\n", message, error ); - exit(1); - } - - int main( int argc, char** argv ) - { - int i, file_index, glyph_index; - char filename[128 + 4]; - char alt_filename[128 + 4]; - char* execname; - char* fname; - int load_unscaled = 0; - - execname = argv[0]; - - if ( argc < 3 ) - Usage( execname ); - - if ( argv[1][0] == '-' && - argv[1][1] == 'u' ) - { - load_unscaled = 1; - } - else - { - if ( sscanf( argv[1], "%d", &ptsize ) != 1 ) - Usage( execname ); - } - argc--; - argv++; - - if ( sscanf( argv[1], "%d", &glyph_index ) != 1 ) - Usage( execname ); - - error = FT_Init_FreeType( &library ); - if (error) Panic( "Could not create library object" ); - - /* Now check all files */ - for ( file_index = 2; file_index < argc; file_index++ ) - { - fname = argv[file_index]; - i = strlen( fname ); - while ( i > 0 && fname[i] != '\\' && fname[i] != '/' ) - { - if ( fname[i] == '.' ) - i = 0; - i--; - } - - filename[128] = '\0'; - alt_filename[128] = '\0'; - - strncpy( filename, fname, 128 ); - strncpy( alt_filename, fname, 128 ); - - if ( i >= 0 ) - { - strncpy( filename + strlen( filename ), ".ttf", 4 ); - strncpy( alt_filename + strlen( alt_filename ), ".ttc", 4 ); - } - - i = strlen( filename ); - fname = filename; - - while ( i >= 0 ) - if ( filename[i] == '/' || filename[i] == '\\' ) - { - fname = filename + i + 1; - i = -1; - } - else - i--; - - printf( "%s: ", fname ); - - /* Load face */ - error = FT_New_Face( library, filename, 0, &face ); - if (error) Panic( "Could not create face object" ); - - num_glyphs = face->num_glyphs; - - error = FT_Set_Char_Size( face, ptsize << 6, 0, 0, 0 ); - if (error) Panic( "Could not set character size" ); - - error = FT_Load_Glyph( face, - glyph_index, - load_unscaled ? FT_LOAD_NO_SCALE - : FT_LOAD_DEFAULT ); - if ( error == 0 ) - printf( "OK.\n" ); - else - printf( "Fail with error 0x%04x\n", error ); - - FT_Done_Face( face ); - } - - FT_Done_FreeType(library); - exit( 0 ); /* for safety reasons */ - - return 0; /* never reached */ - } - - -/* End */ diff --git a/demos/src/ftview.c b/demos/src/ftview.c deleted file mode 100644 index 074a62a5f..000000000 --- a/demos/src/ftview.c +++ /dev/null @@ -1,776 +0,0 @@ -/****************************************************************************/ -/* */ -/* The FreeType project -- a free and portable quality TrueType renderer. */ -/* */ -/* Copyright 1996-2000 by */ -/* D. Turner, R.Wilhelm, and W. Lemberg */ -/* */ -/* */ -/* FTView - a simple font viewer. */ -/* */ -/* This is a new version using the MiGS graphics subsystem for */ -/* blitting and display. */ -/* */ -/* Press F1 when running this program to have a list of key-bindings */ -/* */ -/****************************************************************************/ - - -#include - - /* the following header shouldn't be used in normal programs */ -#include - -#include "common.h" - -#include -#include -#include -#include - -#include "graph.h" -#include "grfont.h" - -#define DIM_X 500 -#define DIM_Y 400 - -#define CENTER_X ( bit.width / 2 ) -#define CENTER_Y ( bit.rows / 2 ) - -#define MAXPTSIZE 500 /* dtp */ - - - char Header[128]; - char* new_header = 0; - - const unsigned char* Text = (unsigned char*) - "The quick brown fox jumped over the lazy dog 0123456789 " - "\342\352\356\373\364\344\353\357\366\374\377\340\371\351\350\347 " - "&#~\"\'(-`_^@)=+\260 ABCDEFGHIJKLMNOPQRSTUVWXYZ " - "$\243^\250*\265\371%!\247:/;.,?<>"; - - FT_Library library; /* the FreeType library */ - FT_Face face; /* the font face */ - FT_Size size; /* the font size */ - FT_GlyphSlot glyph; /* the glyph slot */ - - FT_Error error; /* error code returned by FreeType */ - - grSurface* surface; /* current display surface */ - grBitmap bit; /* current display bitmap */ - - int num_glyphs; /* number of glyphs */ - int ptsize; /* current point size */ - - int hinted = 1; /* is glyph hinting active? */ - int antialias = 1; /* is anti-aliasing active? */ - int use_sbits = 1; /* do we use embedded bitmaps? */ - int low_prec = 0; /* force low precision */ - int Num; /* current first glyph index */ - - int res = 72; - - static grColor fore_color = { 255 }; - - int Fail; - - int graph_init = 0; - - int render_mode = 1; - int debug = 0; - int trace_level = 0; - - -#define RASTER_BUFF_SIZE 32768 - char raster_buff[RASTER_BUFF_SIZE]; - - -#define LOG( x ) LogMessage##x - - static - void LogMessage( const char* fmt, ... ) - { - va_list ap; - - - va_start( ap, fmt ); - vfprintf( stderr, fmt, ap ); - va_end( ap ); - } - - - /* PanicZ */ - static - void PanicZ( const char* message ) - { - fprintf( stderr, "%s\n error = 0x%04x\n", message, error ); - exit( 1 ); - } - - - /* Clears the Bit bitmap/pixmap */ - static - void Clear_Display( void ) - { - long size = (long)bit.pitch * bit.rows; - - - if ( size < 0 ) - size = -size; - memset( bit.buffer, 0, size ); - } - - - /* Initialize the display bitmap `bit' */ - static - void Init_Display( void ) - { - grInitDevices(); - - bit.mode = gr_pixel_mode_gray; - bit.width = DIM_X; - bit.rows = DIM_Y; - bit.grays = 256; - - surface = grNewSurface( 0, &bit ); - if ( !surface ) - PanicZ( "could not allocate display surface\n" ); - - graph_init = 1; - } - - -#define MAX_BUFFER 300000 - -#define FLOOR( x ) ( (x) & -64 ) -#define CEIL( x ) ( ( (x) + 63 ) & -64 ) -#define TRUNC( x ) ( (x) >> 6 ) - - - /* Render a single glyph with the `grays' component */ - static - FT_Error Render_Glyph( int x_offset, - int y_offset ) - { - grBitmap bit3; - FT_Pos x_top, y_top; - - /* first, render the glyph image into a bitmap */ - if (glyph->format != ft_glyph_format_bitmap) - { - error = FT_Render_Glyph( glyph, antialias ? ft_render_mode_normal : ft_render_mode_mono ); - if (error) return error; - - } - - /* now blit it to our display screen */ - bit3.rows = glyph->bitmap.rows; - bit3.width = glyph->bitmap.width; - bit3.pitch = glyph->bitmap.pitch; - bit3.buffer = glyph->bitmap.buffer; - - switch (glyph->bitmap.pixel_mode) - { - case ft_pixel_mode_mono: - bit3.mode = gr_pixel_mode_mono; - bit3.grays = 0; - break; - - case ft_pixel_mode_grays: - bit3.mode = gr_pixel_mode_gray; - bit3.grays = glyph->bitmap.num_grays; - } - - /* Then, blit the image to the target surface */ - x_top = x_offset + glyph->bitmap_left; - y_top = y_offset - glyph->bitmap_top; - - grBlitGlyphToBitmap( &bit, &bit3, x_top, y_top, fore_color ); - - return 0; - } - - - static - FT_Error Reset_Scale( int pointSize ) - { - FT_Error error; - - - error = FT_Set_Char_Size( face, pointSize << 6, - pointSize << 6, - res, - res ); - if ( error ) - { - /* to be written */ - } - - return FT_Err_Ok; - } - - - static - FT_Error LoadChar( int idx, - int hint ) - { - int flags; - - - flags = FT_LOAD_DEFAULT; - - if ( !hint ) - flags |= FT_LOAD_NO_HINTING; - - if ( !use_sbits ) - flags |= FT_LOAD_NO_BITMAP; - - return FT_Load_Glyph( face, idx, flags ); - } - - - static - FT_Error Render_All( int first_glyph, - int ptsize ) - { - FT_F26Dot6 start_x, start_y, step_x, step_y, x, y; - int i; - - FT_Error error; - - - start_x = 4; - start_y = 16 + ptsize ; - - step_x = size->metrics.x_ppem + 4; - step_y = size->metrics.y_ppem + 10; - - x = start_x; - y = start_y; - - i = first_glyph; - -#if 0 - while ( i < first_glyph + 1 ) -#else - while ( i < num_glyphs ) -#endif - { - if ( !( error = LoadChar( i, hinted ) ) ) - { - if ( debug && trace_level > 1 ) - { - if ( i <= first_glyph + 6 ) - { - LOG(( "metrics[%02d] = [%x %x]\n", - i, - glyph->metrics.horiBearingX, - glyph->metrics.horiAdvance )); - - if ( i == first_glyph + 6 ) - LOG(( "-------------------------\n" )); - } - } - - Render_Glyph( x, y ); - - x += ( glyph->metrics.horiAdvance >> 6 ) + 1; - - if ( x + size->metrics.x_ppem > bit.width ) - { - x = start_x; - y += step_y; - - if ( y >= bit.rows ) - return FT_Err_Ok; - } - } - else - Fail++; - - i++; - } - - return FT_Err_Ok; - } - - - static - FT_Error Render_Text( int first_glyph, - int ptsize ) - { - FT_F26Dot6 start_x, start_y, step_x, step_y, x, y; - int i; - - FT_Error error; - const unsigned char* p; - - - start_x = 4; - start_y = 12 + size->metrics.y_ppem; - - step_x = size->metrics.x_ppem + 4; - step_y = size->metrics.y_ppem + 10; - - x = start_x; - y = start_y; - - i = first_glyph; - p = Text; - while ( i > 0 && *p ) - { - p++; - i--; - } - - while ( *p ) - { - if ( !( error = LoadChar( FT_Get_Char_Index( face, - (unsigned char)*p ), - hinted ) ) ) - { - if ( debug && trace_level > 1 ) - { - if ( i <= first_glyph + 6 ) - { - LOG(( "metrics[%02d] = [%x %x]\n", - i, - glyph->metrics.horiBearingX, - glyph->metrics.horiAdvance )); - - if ( i == first_glyph + 6 ) - LOG(( "-------------------------\n" )); - } - } - - Render_Glyph( x, y ); - - x += ( glyph->metrics.horiAdvance >> 6 ) + 1; - - if ( x + size->metrics.x_ppem > bit.width ) - { - x = start_x; - y += step_y; - - if ( y >= bit.rows ) - return FT_Err_Ok; - } - } - else - Fail++; - - i++; - p++; - } - - return FT_Err_Ok; - } - - - static - void Help( void ) - { - grEvent dummy_event; - - - Clear_Display(); - grGotoxy( 0, 0 ); - grSetMargin( 2, 1 ); - grGotobitmap( &bit ); - - grWriteln("FreeType Glyph Viewer - part of the FreeType test suite" ); - grLn(); - grWriteln("This program is used to display all glyphs from one or" ); - grWriteln("several font files, with the FreeType library."); - grLn(); - grWriteln("Use the following keys :"); - grLn(); - grWriteln(" F1 or ? : display this help screen" ); - grWriteln(" a : toggle anti-aliasing" ); - grWriteln(" h : toggle outline hinting" ); - grWriteln(" b : toggle embedded bitmaps" ); - grWriteln(" l : toggle low precision rendering" ); - grWriteln(" space : toggle rendering mode" ); - grLn(); - grWriteln(" Up : increase pointsize by 1 unit" ); - grWriteln(" Down : decrease pointsize by 1 unit" ); - grWriteln(" Page Up : increase pointsize by 10 units" ); - grWriteln(" Page Down : decrease pointsize by 10 units" ); - grLn(); - grWriteln(" Right : increment first glyph index" ); - grWriteln(" Left : decrement first glyph index" ); - grLn(); - grWriteln(" F7 : decrement first glyph index by 10" ); - grWriteln(" F8 : increment first glyph index by 10" ); - grWriteln(" F9 : decrement first glyph index by 100"); - grWriteln(" F10 : increment first glyph index by 100"); - grWriteln(" F11 : decrement first glyph index by 1000"); - grWriteln(" F12 : increment first glyph index by 1000"); - grLn(); - grWriteln("press any key to exit this help screen"); - - grRefreshSurface( surface ); - grListenSurface( surface, gr_event_key, &dummy_event ); - } - - - - static - int Process_Event( grEvent* event ) - { - int i; - - - switch ( event->key ) - { - case grKeyEsc: /* ESC or q */ - case grKEY( 'q' ): - return 0; - - case grKEY( 'a' ): - antialias = !antialias; - new_header = antialias ? "anti-aliasing is now on" - : "anti-aliasing is now off"; - return 1; - - case grKEY( 'b' ): - use_sbits = !use_sbits; - new_header = use_sbits - ? "embedded bitmaps are now used when available" - : "embedded bitmaps are now ignored"; - return 1; - - case grKEY( 'n' ): - case grKEY( 'p' ): - return (int)event->key; - - case grKEY( 'l' ): - low_prec = !low_prec; - new_header = low_prec - ? "rendering precision is now forced to low" - : "rendering precision is now normal"; - break; - - case grKEY( 'h' ): - hinted = !hinted; - new_header = hinted ? "glyph hinting is now active" - : "glyph hinting is now ignored"; - break; - - case grKEY( ' ' ): - render_mode ^= 1; - new_header = render_mode ? "rendering all glyphs in font" - : "rendering test text string" ; - break; - - case grKeyF1: - case grKEY( '?' ): - Help(); - return 1; - -#if 0 - case grKeyF3: i = 16; goto Do_Rotate; - case grKeyF4: i = -16; goto Do_Rotate; - case grKeyF5: i = 1; goto Do_Rotate; - case grKeyF6: i = -1; goto Do_Rotate; -#endif - - case grKeyPageUp: i = 10; goto Do_Scale; - case grKeyPageDown: i = -10; goto Do_Scale; - case grKeyUp: i = 1; goto Do_Scale; - case grKeyDown: i = -1; goto Do_Scale; - - case grKeyLeft: i = -1; goto Do_Glyph; - case grKeyRight: i = 1; goto Do_Glyph; - case grKeyF7: i = -10; goto Do_Glyph; - case grKeyF8: i = 10; goto Do_Glyph; - case grKeyF9: i = -100; goto Do_Glyph; - case grKeyF10: i = 100; goto Do_Glyph; - case grKeyF11: i = -1000; goto Do_Glyph; - case grKeyF12: i = 1000; goto Do_Glyph; - - default: - ; - } - return 1; - -#if 0 - Do_Rotate: - Rotation = ( Rotation + i ) & 1023; - return 1; -#endif - - Do_Scale: - ptsize += i; - if ( ptsize < 1 ) ptsize = 1; - if ( ptsize > MAXPTSIZE ) ptsize = MAXPTSIZE; - return 1; - - Do_Glyph: - Num += i; - if ( Num < 0 ) Num = 0; - if ( Num >= num_glyphs ) Num = num_glyphs - 1; - return 1; - } - - - static - void usage( char* execname ) - { - fprintf( stderr, "\n" ); - fprintf( stderr, "ftview: simple glyph viewer -- part of the FreeType project\n" ); - fprintf( stderr, "-----------------------------------------------------------\n" ); - fprintf( stderr, "\n" ); - fprintf( stderr, "Usage: %s [options below] ppem fontname[.ttf|.ttc] ...\n", - execname ); - fprintf( stderr, "\n" ); - fprintf( stderr, " -d enable debugging messages\n" ); - fprintf( stderr, " -l N set debugging trace level to N (default: 0, max: 7)\n" ); - fprintf( stderr, " -r R use resolution R dpi (default: 72 dpi)\n" ); - fprintf( stderr, " -f index specify first glyph index to display\n" ); - fprintf( stderr, "\n" ); - - exit( 1 ); - } - - - int main( int argc, - char* argv[] ) - { - int i, old_ptsize, orig_ptsize, file; - int first_glyph = 0; - int XisSetup = 0; - char filename[128 + 4]; - char alt_filename[128 + 4]; - char* execname; - int option; - int file_loaded; - - FT_Error error; - grEvent event; - - - execname = ft_basename( argv[0] ); - - while ( 1 ) - { - option = getopt( argc, argv, "df:l:r:" ); - - if ( option == -1 ) - break; - - switch ( option ) - { - case 'd': - debug = 1; - break; - - case 'f': - first_glyph = atoi( optarg ); - break; - - case 'l': - trace_level = atoi( optarg ); - if ( trace_level < 1 || trace_level > 7 ) - usage( execname ); - break; - - case 'r': - res = atoi( optarg ); - if ( res < 1 ) - usage( execname ); - break; - - default: - usage( execname ); - break; - } - } - - argc -= optind; - argv += optind; - - if ( argc <= 1 ) - usage( execname ); - - if ( sscanf( argv[0], "%d", &orig_ptsize ) != 1 ) - orig_ptsize = 64; - - file = 1; - - if ( debug ) - { -#ifdef FT_DEBUG_LEVEL_TRACE - FT_SetTraceLevel( trace_any, (FT_Byte)trace_level ); -#else - trace_level = 0; -#endif - } - - /* Initialize engine */ - error = FT_Init_FreeType( &library ); - if ( error ) - PanicZ( "Could not initialize FreeType library" ); - - NewFile: - ptsize = orig_ptsize; - hinted = 1; - file_loaded = 0; - - filename[128] = '\0'; - alt_filename[128] = '\0'; - - strncpy( filename, argv[file], 128 ); - strncpy( alt_filename, argv[file], 128 ); - - /* try to load the file name as is, first */ - error = FT_New_Face( library, argv[file], 0, &face ); - if ( !error ) - goto Success; - -#ifndef macintosh - i = strlen( argv[file] ); - while ( i > 0 && argv[file][i] != '\\' && argv[file][i] != '/' ) - { - if ( argv[file][i] == '.' ) - i = 0; - i--; - } - - if ( i >= 0 ) - { - strncpy( filename + strlen( filename ), ".ttf", 4 ); - strncpy( alt_filename + strlen( alt_filename ), ".ttc", 4 ); - } -#endif - - /* Load face */ - error = FT_New_Face( library, filename, 0, &face ); - if ( error ) - goto Display_Font; - - Success: - file_loaded++; - - error = Reset_Scale( ptsize ); - if ( error ) - goto Display_Font; - - num_glyphs = face->num_glyphs; - glyph = face->glyph; - size = face->size; - - Display_Font: - /* initialize graphics if needed */ - if ( !XisSetup ) - { - XisSetup = 1; - Init_Display(); - } - - grSetTitle( surface, "FreeType Glyph Viewer - press F1 for help" ); - old_ptsize = ptsize; - - if ( file_loaded >= 1 ) - { - Fail = 0; - Num = first_glyph; - - if ( Num >= num_glyphs ) - Num = num_glyphs - 1; - - if ( Num < 0 ) - Num = 0; - } - - for ( ;; ) - { - int key; - - - Clear_Display(); - - if ( file_loaded >= 1 ) - { - switch ( render_mode ) - { - case 0: - Render_Text( Num, ptsize ); - break; - - default: - Render_All( Num, ptsize ); - } - - sprintf( Header, "%s %s (file `%s')", - face->family_name, - face->style_name, - ft_basename( filename ) ); - - if ( !new_header ) - new_header = Header; - - grWriteCellString( &bit, 0, 0, new_header, fore_color ); - new_header = 0; - - sprintf( Header, "at %d points, first glyph = %d", - ptsize, - Num ); - } - else - sprintf( Header, "`%s': not a font file or could not be opened", - ft_basename( filename ) ); - - grWriteCellString( &bit, 0, 8, Header, fore_color ); - grRefreshSurface( surface ); - - grListenSurface( surface, 0, &event ); - if ( !( key = Process_Event( &event ) ) ) - goto End; - - if ( key == 'n' ) - { - if (file_loaded >= 1) - FT_Done_Face( face ); - - if ( file < argc - 1 ) - file++; - - goto NewFile; - } - - if ( key == 'p' ) - { - if ( file_loaded >= 1 ) - FT_Done_Face( face ); - - if ( file > 1 ) - file--; - - goto NewFile; - } - - if ( ptsize != old_ptsize ) - { - if ( Reset_Scale( ptsize ) ) - PanicZ( "Could not resize font." ); - - old_ptsize = ptsize; - } - } - - End: -#if 0 - grDoneSurface(surface); - grDone(); -#endif - - printf( "Execution completed successfully.\n" ); - printf( "Fails = %d\n", Fail ); - - exit( 0 ); /* for safety reasons */ - return 0; /* never reached */ -} - - -/* End */ diff --git a/demos/src/memtest.c b/demos/src/memtest.c deleted file mode 100644 index ad600598c..000000000 --- a/demos/src/memtest.c +++ /dev/null @@ -1,333 +0,0 @@ -/* memtest.c */ - -#include -#include -#include -#include -#include - - FT_Error error; - - FT_Library library; - FT_Face face; - - unsigned int num_glyphs; - int ptsize; - - int Fail; - int Num; - - - - -/****************************************************************************/ -/****************************************************************************/ -/****************************************************************************/ -/****************************************************************************/ - -/* Our own memory allocator. To check that a single block isn't freed */ -/* several time, we simply do not call "free".. */ - -#define MAX_RECORDED_BLOCKS 1638400 -#define CHECK_DUPLICATES - -typedef struct MyBlock -{ - void* base; - long size; - -} MyBlock; - -static MyBlock my_blocks[ MAX_RECORDED_BLOCKS ]; -static int num_my_blocks = 0; - - -/* record a new block in the table, check for duplicates too */ -static -void record_my_block( void* base, long size ) -{ - if (size <= 0) - { - fprintf( stderr, "adding a block with non-positive length - should not happen \n" ); - exit(1); - } - - if ( num_my_blocks < MAX_RECORDED_BLOCKS ) - { - MyBlock* block; - -#ifdef CHECK_DUPLICATES - MyBlock* limit; - block = my_blocks; - limit = block + num_my_blocks; - for ( ; block < limit; block++ ) - { - if ( block->base == base && block->size != 0 ) - { - fprintf( stderr, "duplicate memory block at %08lx\n", (long)block->base ); - exit(1); - } - } -#endif - - block = my_blocks + num_my_blocks++; - block->base = base; - block->size = size; - } - else - { - fprintf( stderr, "Too many memory blocks -- test exited !!\n" ); - exit(1); - } -} - -/* forget a block, and check that it isn't part of our table already */ -static -void forget_my_block( void* base ) -{ - MyBlock* block = my_blocks + num_my_blocks-1; - - /* we scan in reverse, because transient blocks are always located */ - /* at the end of the table.. (it supposedly faster then..) */ - for ( ; block >= my_blocks; block-- ) - { - if ( block->base == base ) - { - if (block->size > 0) - { - block->size = 0; - return; - } - else - { - fprintf( stderr, "Block at %p released twice \n", base ); - exit(1); - } - } - } - fprintf( stderr, "Trying to release an unallocated block at %p\n", - base ); - exit(1); -} - - -static -void* my_alloc( FT_Memory memory, - long size ) -{ - void* p = malloc(size); - if (p) - record_my_block(p,size); - - memory=memory; - return p; -} - -static -void my_free( FT_Memory memory, void* block ) -{ - memory=memory; - forget_my_block(block); - /* free(block); WE DO NOT REALLY FREE THE BLOCK */ -} - -static -void* my_realloc( FT_Memory memory, - long cur_size, - long new_size, - void* block ) -{ - void* p; - - p = my_alloc( memory, new_size ); - if (p) - { - long size; - - size = cur_size; - if (new_size < size) - size = new_size; - - memcpy( p, block, size ); - my_free( memory, block ); - } - - return p; -} - - -struct FT_MemoryRec_ my_memory = -{ - 0, - my_alloc, - my_free, - my_realloc -}; - -static void dump_mem( void ) -{ - MyBlock* block = my_blocks + num_my_blocks-1; - int bad = 0; - - printf( "total allocated blocks = %d\n", num_my_blocks ); - - /* we scan in reverse, because transient blocks are always located */ - /* at the end of the table.. (it supposedly faster then..) */ - for ( ; block >= my_blocks; block-- ) - { - if (block->size > 0) - { - fprintf( stderr, "%p (%6ld bytes) leaked !!\n", block->base, (long)block->size ); - bad = 1; - } - } - if (!bad) - fprintf( stderr, "no leaked memory block\n\n" ); -} - -/****************************************************************************/ -/****************************************************************************/ -/****************************************************************************/ -/****************************************************************************/ - - - static void Usage( char* name ) - { - printf( "memtest: simple memory tester -- part of the FreeType project\n" ); - printf( "-------------------------------------------------------------\n" ); - printf( "\n" ); - printf( "Usage: %s ppem fontname[.ttf|.ttc] [fontname2..]\n", name ); - printf( "\n" ); - - exit( 1 ); - } - - - static void Panic( const char* message ) - { - fprintf( stderr, "%s\n error code = 0x%04x\n", message, error ); - exit(1); - } - - -int main( int argc, char** argv ) -{ - int i, file_index; - unsigned int id; - char filename[128 + 4]; - char alt_filename[128 + 4]; - char* execname; - char* fname; - - execname = argv[0]; - - if ( argc < 3 ) - Usage( execname ); - - if ( sscanf( argv[1], "%d", &ptsize ) != 1 ) - Usage( execname ); - - /* Create a new library with our own memory manager */ - error = FT_New_Library( &my_memory, &library ); - if (error) Panic( "Could not create library object" ); - - /* the new library has no drivers in it, add the default ones */ - /* (implemented in ftinit.c).. */ - FT_Add_Default_Modules(library); - - - /* Now check all files */ - for ( file_index = 2; file_index < argc; file_index++ ) - { - fname = argv[file_index]; - i = strlen( fname ); - while ( i > 0 && fname[i] != '\\' && fname[i] != '/' ) - { - if ( fname[i] == '.' ) - i = 0; - i--; - } - - filename[128] = '\0'; - alt_filename[128] = '\0'; - - strncpy( filename, fname, 128 ); - strncpy( alt_filename, fname, 128 ); - -#ifndef macintosh - if ( i >= 0 ) - { - strncpy( filename + strlen( filename ), ".ttf", 4 ); - strncpy( alt_filename + strlen( alt_filename ), ".ttc", 4 ); - } -#endif - i = strlen( filename ); - fname = filename; - - while ( i >= 0 ) -#ifndef macintosh - if ( filename[i] == '/' || filename[i] == '\\' ) -#else - if ( filename[i] == ':' ) -#endif - { - fname = filename + i + 1; - i = -1; - } - else - i--; - - printf( "%s: ", fname ); - - /* Load face */ - error = FT_New_Face( library, filename, 0, &face ); - if (error) - { - if (error == FT_Err_Invalid_File_Format) - printf( "unknown format\n" ); - else - printf( "could not find/open file (error: %d)\n", error ); - continue; - } - if (error) Panic( "Could not open file" ); - - num_glyphs = face->num_glyphs; - - error = FT_Set_Char_Size( face, ptsize << 6, ptsize << 6, 72, 72 ); - if (error) Panic( "Could not set character size" ); - - Fail = 0; - { - for ( id = 0; id < num_glyphs; id++ ) - { - error = FT_Load_Glyph( face, id, FT_LOAD_RENDER | FT_LOAD_ANTI_ALIAS ); - if (error) - { - if ( Fail < 10 ) - printf( "glyph %4u: 0x%04x\n" , id, error ); - Fail++; - } - } - } - - if ( Fail == 0 ) - printf( "OK.\n" ); - else - if ( Fail == 1 ) - printf( "1 fail.\n" ); - else - printf( "%d fails.\n", Fail ); - - FT_Done_Face( face ); - } - - FT_Done_FreeType(library); - - dump_mem(); - - exit( 0 ); /* for safety reasons */ - return 0; /* never reached */ -} - - - diff --git a/demos/src/ttdebug.c b/demos/src/ttdebug.c deleted file mode 100644 index 427eca2ca..000000000 --- a/demos/src/ttdebug.c +++ /dev/null @@ -1,1260 +0,0 @@ -#include -#include - -#ifdef UNIX -#ifndef HAVE_POSIX_TERMIOS -#include -#include -#else -#ifndef HAVE_TCGETATTR -#define HAVE_TCGETATTR -#endif /* HAVE_TCGETATTR */ -#ifndef HAVE_TCSETATTR -#define HAVE_TCSETATTR -#endif /* HAVE_TCSETATTR */ -#include -#endif /* HAVE_POSIX_TERMIOS */ -#endif - -/* Define the `getch()' function. On Unix systems, it is an alias */ -/* for `getchar()', and the debugger front end must ensure that the */ -/* `stdin' file descriptor is not in line-by-line input mode. */ -#ifndef UNIX -#include -#else -#define getch getchar -#endif - - -#include -#include -#include -#include - - -FT_Library library; /* root library object */ -FT_Memory memory; /* system object */ -FT_Driver driver; /* truetype driver */ -TT_Face face; /* truetype face */ -TT_Size size; /* truetype size */ -TT_GlyphSlot glyph; /* truetype glyph slot */ -TT_ExecContext exec; /* truetype execution context */ -FT_Error error; - -TT_CodeRange_Tag debug_coderange = tt_coderange_glyph; - - typedef FT_Byte ByteStr[2]; - typedef FT_Byte WordStr[4]; - typedef FT_Byte LongStr[8]; - typedef FT_Byte DebugStr[128]; - - static DebugStr tempStr; - -#undef PACK -#define PACK( x, y ) ((x << 4) | y) - - static const FT_Byte Pop_Push_Count[256] = - { - /* opcodes are gathered in groups of 16 */ - /* please keep the spaces as they are */ - - /* SVTCA y */ PACK( 0, 0 ), - /* SVTCA x */ PACK( 0, 0 ), - /* SPvTCA y */ PACK( 0, 0 ), - /* SPvTCA x */ PACK( 0, 0 ), - /* SFvTCA y */ PACK( 0, 0 ), - /* SFvTCA x */ PACK( 0, 0 ), - /* SPvTL // */ PACK( 2, 0 ), - /* SPvTL + */ PACK( 2, 0 ), - /* SFvTL // */ PACK( 2, 0 ), - /* SFvTL + */ PACK( 2, 0 ), - /* SPvFS */ PACK( 2, 0 ), - /* SFvFS */ PACK( 2, 0 ), - /* GPV */ PACK( 0, 2 ), - /* GFV */ PACK( 0, 2 ), - /* SFvTPv */ PACK( 0, 0 ), - /* ISECT */ PACK( 5, 0 ), - - /* SRP0 */ PACK( 1, 0 ), - /* SRP1 */ PACK( 1, 0 ), - /* SRP2 */ PACK( 1, 0 ), - /* SZP0 */ PACK( 1, 0 ), - /* SZP1 */ PACK( 1, 0 ), - /* SZP2 */ PACK( 1, 0 ), - /* SZPS */ PACK( 1, 0 ), - /* SLOOP */ PACK( 1, 0 ), - /* RTG */ PACK( 0, 0 ), - /* RTHG */ PACK( 0, 0 ), - /* SMD */ PACK( 1, 0 ), - /* ELSE */ PACK( 0, 0 ), - /* JMPR */ PACK( 1, 0 ), - /* SCvTCi */ PACK( 1, 0 ), - /* SSwCi */ PACK( 1, 0 ), - /* SSW */ PACK( 1, 0 ), - - /* DUP */ PACK( 1, 2 ), - /* POP */ PACK( 1, 0 ), - /* CLEAR */ PACK( 0, 0 ), - /* SWAP */ PACK( 2, 2 ), - /* DEPTH */ PACK( 0, 1 ), - /* CINDEX */ PACK( 1, 1 ), - /* MINDEX */ PACK( 1, 0 ), - /* AlignPTS */ PACK( 2, 0 ), - /* INS_$28 */ PACK( 0, 0 ), - /* UTP */ PACK( 1, 0 ), - /* LOOPCALL */ PACK( 2, 0 ), - /* CALL */ PACK( 1, 0 ), - /* FDEF */ PACK( 1, 0 ), - /* ENDF */ PACK( 0, 0 ), - /* MDAP[0] */ PACK( 1, 0 ), - /* MDAP[1] */ PACK( 1, 0 ), - - /* IUP[0] */ PACK( 0, 0 ), - /* IUP[1] */ PACK( 0, 0 ), - /* SHP[0] */ PACK( 0, 0 ), - /* SHP[1] */ PACK( 0, 0 ), - /* SHC[0] */ PACK( 1, 0 ), - /* SHC[1] */ PACK( 1, 0 ), - /* SHZ[0] */ PACK( 1, 0 ), - /* SHZ[1] */ PACK( 1, 0 ), - /* SHPIX */ PACK( 1, 0 ), - /* IP */ PACK( 0, 0 ), - /* MSIRP[0] */ PACK( 2, 0 ), - /* MSIRP[1] */ PACK( 2, 0 ), - /* AlignRP */ PACK( 0, 0 ), - /* RTDG */ PACK( 0, 0 ), - /* MIAP[0] */ PACK( 2, 0 ), - /* MIAP[1] */ PACK( 2, 0 ), - - /* NPushB */ PACK( 0, 0 ), - /* NPushW */ PACK( 0, 0 ), - /* WS */ PACK( 2, 0 ), - /* RS */ PACK( 1, 1 ), - /* WCvtP */ PACK( 2, 0 ), - /* RCvt */ PACK( 1, 1 ), - /* GC[0] */ PACK( 1, 1 ), - /* GC[1] */ PACK( 1, 1 ), - /* SCFS */ PACK( 2, 0 ), - /* MD[0] */ PACK( 2, 1 ), - /* MD[1] */ PACK( 2, 1 ), - /* MPPEM */ PACK( 0, 1 ), - /* MPS */ PACK( 0, 1 ), - /* FlipON */ PACK( 0, 0 ), - /* FlipOFF */ PACK( 0, 0 ), - /* DEBUG */ PACK( 1, 0 ), - - /* LT */ PACK( 2, 1 ), - /* LTEQ */ PACK( 2, 1 ), - /* GT */ PACK( 2, 1 ), - /* GTEQ */ PACK( 2, 1 ), - /* EQ */ PACK( 2, 1 ), - /* NEQ */ PACK( 2, 1 ), - /* ODD */ PACK( 1, 1 ), - /* EVEN */ PACK( 1, 1 ), - /* IF */ PACK( 1, 0 ), - /* EIF */ PACK( 0, 0 ), - /* AND */ PACK( 2, 1 ), - /* OR */ PACK( 2, 1 ), - /* NOT */ PACK( 1, 1 ), - /* DeltaP1 */ PACK( 1, 0 ), - /* SDB */ PACK( 1, 0 ), - /* SDS */ PACK( 1, 0 ), - - /* ADD */ PACK( 2, 1 ), - /* SUB */ PACK( 2, 1 ), - /* DIV */ PACK( 2, 1 ), - /* MUL */ PACK( 2, 1 ), - /* ABS */ PACK( 1, 1 ), - /* NEG */ PACK( 1, 1 ), - /* FLOOR */ PACK( 1, 1 ), - /* CEILING */ PACK( 1, 1 ), - /* ROUND[0] */ PACK( 1, 1 ), - /* ROUND[1] */ PACK( 1, 1 ), - /* ROUND[2] */ PACK( 1, 1 ), - /* ROUND[3] */ PACK( 1, 1 ), - /* NROUND[0] */ PACK( 1, 1 ), - /* NROUND[1] */ PACK( 1, 1 ), - /* NROUND[2] */ PACK( 1, 1 ), - /* NROUND[3] */ PACK( 1, 1 ), - - /* WCvtF */ PACK( 2, 0 ), - /* DeltaP2 */ PACK( 1, 0 ), - /* DeltaP3 */ PACK( 1, 0 ), - /* DeltaCn[0] */ PACK( 1, 0 ), - /* DeltaCn[1] */ PACK( 1, 0 ), - /* DeltaCn[2] */ PACK( 1, 0 ), - /* SROUND */ PACK( 1, 0 ), - /* S45Round */ PACK( 1, 0 ), - /* JROT */ PACK( 2, 0 ), - /* JROF */ PACK( 2, 0 ), - /* ROFF */ PACK( 0, 0 ), - /* INS_$7B */ PACK( 0, 0 ), - /* RUTG */ PACK( 0, 0 ), - /* RDTG */ PACK( 0, 0 ), - /* SANGW */ PACK( 1, 0 ), - /* AA */ PACK( 1, 0 ), - - /* FlipPT */ PACK( 0, 0 ), - /* FlipRgON */ PACK( 2, 0 ), - /* FlipRgOFF */ PACK( 2, 0 ), - /* INS_$83 */ PACK( 0, 0 ), - /* INS_$84 */ PACK( 0, 0 ), - /* ScanCTRL */ PACK( 1, 0 ), - /* SDVPTL[0] */ PACK( 2, 0 ), - /* SDVPTL[1] */ PACK( 2, 0 ), - /* GetINFO */ PACK( 1, 1 ), - /* IDEF */ PACK( 1, 0 ), - /* ROLL */ PACK( 3, 3 ), - /* MAX */ PACK( 2, 1 ), - /* MIN */ PACK( 2, 1 ), - /* ScanTYPE */ PACK( 1, 0 ), - /* InstCTRL */ PACK( 2, 0 ), - /* INS_$8F */ PACK( 0, 0 ), - - /* INS_$90 */ PACK( 0, 0 ), - /* INS_$91 */ PACK( 0, 0 ), - /* INS_$92 */ PACK( 0, 0 ), - /* INS_$93 */ PACK( 0, 0 ), - /* INS_$94 */ PACK( 0, 0 ), - /* INS_$95 */ PACK( 0, 0 ), - /* INS_$96 */ PACK( 0, 0 ), - /* INS_$97 */ PACK( 0, 0 ), - /* INS_$98 */ PACK( 0, 0 ), - /* INS_$99 */ PACK( 0, 0 ), - /* INS_$9A */ PACK( 0, 0 ), - /* INS_$9B */ PACK( 0, 0 ), - /* INS_$9C */ PACK( 0, 0 ), - /* INS_$9D */ PACK( 0, 0 ), - /* INS_$9E */ PACK( 0, 0 ), - /* INS_$9F */ PACK( 0, 0 ), - - /* INS_$A0 */ PACK( 0, 0 ), - /* INS_$A1 */ PACK( 0, 0 ), - /* INS_$A2 */ PACK( 0, 0 ), - /* INS_$A3 */ PACK( 0, 0 ), - /* INS_$A4 */ PACK( 0, 0 ), - /* INS_$A5 */ PACK( 0, 0 ), - /* INS_$A6 */ PACK( 0, 0 ), - /* INS_$A7 */ PACK( 0, 0 ), - /* INS_$A8 */ PACK( 0, 0 ), - /* INS_$A9 */ PACK( 0, 0 ), - /* INS_$AA */ PACK( 0, 0 ), - /* INS_$AB */ PACK( 0, 0 ), - /* INS_$AC */ PACK( 0, 0 ), - /* INS_$AD */ PACK( 0, 0 ), - /* INS_$AE */ PACK( 0, 0 ), - /* INS_$AF */ PACK( 0, 0 ), - - /* PushB[0] */ PACK( 0, 1 ), - /* PushB[1] */ PACK( 0, 2 ), - /* PushB[2] */ PACK( 0, 3 ), - /* PushB[3] */ PACK( 0, 4 ), - /* PushB[4] */ PACK( 0, 5 ), - /* PushB[5] */ PACK( 0, 6 ), - /* PushB[6] */ PACK( 0, 7 ), - /* PushB[7] */ PACK( 0, 8 ), - /* PushW[0] */ PACK( 0, 1 ), - /* PushW[1] */ PACK( 0, 2 ), - /* PushW[2] */ PACK( 0, 3 ), - /* PushW[3] */ PACK( 0, 4 ), - /* PushW[4] */ PACK( 0, 5 ), - /* PushW[5] */ PACK( 0, 6 ), - /* PushW[6] */ PACK( 0, 7 ), - /* PushW[7] */ PACK( 0, 8 ), - - /* MDRP[00] */ PACK( 1, 0 ), - /* MDRP[01] */ PACK( 1, 0 ), - /* MDRP[02] */ PACK( 1, 0 ), - /* MDRP[03] */ PACK( 1, 0 ), - /* MDRP[04] */ PACK( 1, 0 ), - /* MDRP[05] */ PACK( 1, 0 ), - /* MDRP[06] */ PACK( 1, 0 ), - /* MDRP[07] */ PACK( 1, 0 ), - /* MDRP[08] */ PACK( 1, 0 ), - /* MDRP[09] */ PACK( 1, 0 ), - /* MDRP[10] */ PACK( 1, 0 ), - /* MDRP[11] */ PACK( 1, 0 ), - /* MDRP[12] */ PACK( 1, 0 ), - /* MDRP[13] */ PACK( 1, 0 ), - /* MDRP[14] */ PACK( 1, 0 ), - /* MDRP[15] */ PACK( 1, 0 ), - - /* MDRP[16] */ PACK( 1, 0 ), - /* MDRP[17] */ PACK( 1, 0 ), - /* MDRP[18] */ PACK( 1, 0 ), - /* MDRP[19] */ PACK( 1, 0 ), - /* MDRP[20] */ PACK( 1, 0 ), - /* MDRP[21] */ PACK( 1, 0 ), - /* MDRP[22] */ PACK( 1, 0 ), - /* MDRP[23] */ PACK( 1, 0 ), - /* MDRP[24] */ PACK( 1, 0 ), - /* MDRP[25] */ PACK( 1, 0 ), - /* MDRP[26] */ PACK( 1, 0 ), - /* MDRP[27] */ PACK( 1, 0 ), - /* MDRP[28] */ PACK( 1, 0 ), - /* MDRP[29] */ PACK( 1, 0 ), - /* MDRP[30] */ PACK( 1, 0 ), - /* MDRP[31] */ PACK( 1, 0 ), - - /* MIRP[00] */ PACK( 2, 0 ), - /* MIRP[01] */ PACK( 2, 0 ), - /* MIRP[02] */ PACK( 2, 0 ), - /* MIRP[03] */ PACK( 2, 0 ), - /* MIRP[04] */ PACK( 2, 0 ), - /* MIRP[05] */ PACK( 2, 0 ), - /* MIRP[06] */ PACK( 2, 0 ), - /* MIRP[07] */ PACK( 2, 0 ), - /* MIRP[08] */ PACK( 2, 0 ), - /* MIRP[09] */ PACK( 2, 0 ), - /* MIRP[10] */ PACK( 2, 0 ), - /* MIRP[11] */ PACK( 2, 0 ), - /* MIRP[12] */ PACK( 2, 0 ), - /* MIRP[13] */ PACK( 2, 0 ), - /* MIRP[14] */ PACK( 2, 0 ), - /* MIRP[15] */ PACK( 2, 0 ), - - /* MIRP[16] */ PACK( 2, 0 ), - /* MIRP[17] */ PACK( 2, 0 ), - /* MIRP[18] */ PACK( 2, 0 ), - /* MIRP[19] */ PACK( 2, 0 ), - /* MIRP[20] */ PACK( 2, 0 ), - /* MIRP[21] */ PACK( 2, 0 ), - /* MIRP[22] */ PACK( 2, 0 ), - /* MIRP[23] */ PACK( 2, 0 ), - /* MIRP[24] */ PACK( 2, 0 ), - /* MIRP[25] */ PACK( 2, 0 ), - /* MIRP[26] */ PACK( 2, 0 ), - /* MIRP[27] */ PACK( 2, 0 ), - /* MIRP[28] */ PACK( 2, 0 ), - /* MIRP[29] */ PACK( 2, 0 ), - /* MIRP[30] */ PACK( 2, 0 ), - /* MIRP[31] */ PACK( 2, 0 ) - }; - - - static const FT_String* OpStr[256] = { - "SVTCA y", /* Set vectors to coordinate axis y */ - "SVTCA x", /* Set vectors to coordinate axis x */ - "SPvTCA y", /* Set Proj. vec. to coord. axis y */ - "SPvTCA x", /* Set Proj. vec. to coord. axis x */ - "SFvTCA y", /* Set Free. vec. to coord. axis y */ - "SFvTCA x", /* Set Free. vec. to coord. axis x */ - "SPvTL //", /* Set Proj. vec. parallel to segment */ - "SPvTL +", /* Set Proj. vec. normal to segment */ - "SFvTL //", /* Set Free. vec. parallel to segment */ - "SFvTL +", /* Set Free. vec. normal to segment */ - "SPvFS", /* Set Proj. vec. from stack */ - "SFvFS", /* Set Free. vec. from stack */ - "GPV", /* Get projection vector */ - "GFV", /* Get freedom vector */ - "SFvTPv", /* Set free. vec. to proj. vec. */ - "ISECT", /* compute intersection */ - - "SRP0", /* Set reference point 0 */ - "SRP1", /* Set reference point 1 */ - "SRP2", /* Set reference point 2 */ - "SZP0", /* Set Zone Pointer 0 */ - "SZP1", /* Set Zone Pointer 1 */ - "SZP2", /* Set Zone Pointer 2 */ - "SZPS", /* Set all zone pointers */ - "SLOOP", /* Set loop counter */ - "RTG", /* Round to Grid */ - "RTHG", /* Round to Half-Grid */ - "SMD", /* Set Minimum Distance */ - "ELSE", /* Else */ - "JMPR", /* Jump Relative */ - "SCvTCi", /* Set CVT */ - "SSwCi", /* */ - "SSW", /* */ - - "DUP", - "POP", - "CLEAR", - "SWAP", - "DEPTH", - "CINDEX", - "MINDEX", - "AlignPTS", - "INS_$28", - "UTP", - "LOOPCALL", - "CALL", - "FDEF", - "ENDF", - "MDAP[-]", - "MDAP[r]", - - "IUP[y]", - "IUP[x]", - "SHP[0]", - "SHP[1]", - "SHC[0]", - "SHC[1]", - "SHZ[0]", - "SHZ[1]", - "SHPIX", - "IP", - "MSIRP[0]", - "MSIRP[1]", - "AlignRP", - "RTDG", - "MIAP[-]", - "MIAP[r]", - - "NPushB", - "NPushW", - "WS", - "RS", - "WCvtP", - "RCvt", - "GC[0]", - "GC[1]", - "SCFS", - "MD[0]", - "MD[1]", - "MPPEM", - "MPS", - "FlipON", - "FlipOFF", - "DEBUG", - - "LT", - "LTEQ", - "GT", - "GTEQ", - "EQ", - "NEQ", - "ODD", - "EVEN", - "IF", - "EIF", - "AND", - "OR", - "NOT", - "DeltaP1", - "SDB", - "SDS", - - "ADD", - "SUB", - "DIV", - "MUL", - "ABS", - "NEG", - "FLOOR", - "CEILING", - "ROUND[G]", - "ROUND[B]", - "ROUND[W]", - "ROUND[?]", - "NROUND[G]", - "NROUND[B]", - "NROUND[W]", - "NROUND[?]", - - "WCvtF", - "DeltaP2", - "DeltaP3", - "DeltaC1", - "DeltaC2", - "DeltaC3", - "SROUND", - "S45Round", - "JROT", - "JROF", - "ROFF", - "INS_$7B", - "RUTG", - "RDTG", - "SANGW", - "AA", - - "FlipPT", - "FlipRgON", - "FlipRgOFF", - "INS_$83", - "INS_$84", - "ScanCTRL", - "SDPVTL[0]", - "SDPVTL[1]", - "GetINFO", - "IDEF", - "ROLL", - "MAX", - "MIN", - "ScanTYPE", - "IntCTRL", - "INS_$8F", - - "INS_$90", - "INS_$91", - "INS_$92", - "INS_$93", - "INS_$94", - "INS_$95", - "INS_$96", - "INS_$97", - "INS_$98", - "INS_$99", - "INS_$9A", - "INS_$9B", - "INS_$9C", - "INS_$9D", - "INS_$9E", - "INS_$9F", - - "INS_$A0", - "INS_$A1", - "INS_$A2", - "INS_$A3", - "INS_$A4", - "INS_$A5", - "INS_$A6", - "INS_$A7", - "INS_$A8", - "INS_$A9", - "INS_$AA", - "INS_$AB", - "INS_$AC", - "INS_$AD", - "INS_$AE", - "INS_$AF", - - "PushB[0]", - "PushB[1]", - "PushB[2]", - "PushB[3]", - "PushB[4]", - "PushB[5]", - "PushB[6]", - "PushB[7]", - "PushW[0]", - "PushW[1]", - "PushW[2]", - "PushW[3]", - "PushW[4]", - "PushW[5]", - "PushW[6]", - "PushW[7]", - - "MDRP[G]", - "MDRP[B]", - "MDRP[W]", - "MDRP[?]", - "MDRP[rG]", - "MDRP[rB]", - "MDRP[rW]", - "MDRP[r?]", - "MDRP[mG]", - "MDRP[mB]", - "MDRP[mW]", - "MDRP[m?]", - "MDRP[mrG]", - "MDRP[mrB]", - "MDRP[mrW]", - "MDRP[mr?]", - "MDRP[pG]", - "MDRP[pB]", - - "MDRP[pW]", - "MDRP[p?]", - "MDRP[prG]", - "MDRP[prB]", - "MDRP[prW]", - "MDRP[pr?]", - "MDRP[pmG]", - "MDRP[pmB]", - "MDRP[pmW]", - "MDRP[pm?]", - "MDRP[pmrG]", - "MDRP[pmrB]", - "MDRP[pmrW]", - "MDRP[pmr?]", - - "MIRP[G]", - "MIRP[B]", - "MIRP[W]", - "MIRP[?]", - "MIRP[rG]", - "MIRP[rB]", - "MIRP[rW]", - "MIRP[r?]", - "MIRP[mG]", - "MIRP[mB]", - "MIRP[mW]", - "MIRP[m?]", - "MIRP[mrG]", - "MIRP[mrB]", - "MIRP[mrW]", - "MIRP[mr?]", - "MIRP[pG]", - "MIRP[pB]", - - "MIRP[pW]", - "MIRP[p?]", - "MIRP[prG]", - "MIRP[prB]", - "MIRP[prW]", - "MIRP[pr?]", - "MIRP[pmG]", - "MIRP[pmB]", - "MIRP[pmW]", - "MIRP[pm?]", - "MIRP[pmrG]", - "MIRP[pmrB]", - "MIRP[pmrW]", - "MIRP[pmr?]" - }; - - -/********************************************************************* - * - * Init_Keyboard : set the input file descriptor to char-by-char - * mode on Unix.. - * - *********************************************************************/ - -#ifdef UNIX - - struct termios old_termio; - - static - void Init_Keyboard( void ) - { - struct termios termio; - -#ifndef HAVE_TCGETATTR - ioctl( 0, TCGETS, &old_termio ); -#else - tcgetattr( 0, &old_termio ); -#endif - - termio = old_termio; - -/* termio.c_lflag &= ~(ICANON+ECHO+ECHOE+ECHOK+ECHONL+ECHOKE); */ - termio.c_lflag &= ~(ICANON+ECHO+ECHOE+ECHOK+ECHONL); - -#ifndef HAVE_TCSETATTR - ioctl( 0, TCSETS, &termio ); -#else - tcsetattr( 0, TCSANOW, &termio ); -#endif - } - - static - void Reset_Keyboard( void ) - { -#ifndef HAVE_TCSETATTR - ioctl( 0, TCSETS, &old_termio ); -#else - tcsetattr( 0, TCSANOW, &old_termio ); -#endif - - } - -#else - - static - void Init_Keyboard( void ) - { - } - - static - void Reset_Keyboard( void ) - { - } - -#endif - - - void Panic( const char* message ) - { - fprintf( stderr, "%s\n error code = 0x%04x\n", message, error ); - Reset_Keyboard(); - exit(1); - } - - -/****************************************************************** - * - * Function : Calc_Length - * - * Description : Computes the length in bytes of current opcode. - * - *****************************************************************/ - -#define CUR (*exc) - - - static void Calc_Length( TT_ExecContext exc ) - { - CUR.opcode = CUR.code[CUR.IP]; - - switch ( CUR.opcode ) - { - case 0x40: - if ( CUR.IP + 1 >= CUR.codeSize ) - Panic( "code range overflow !!" ); - - CUR.length = CUR.code[CUR.IP + 1] + 2; - break; - - case 0x41: - if ( CUR.IP + 1 >= CUR.codeSize ) - Panic( "code range overflow !!" ); - - CUR.length = CUR.code[CUR.IP + 1] * 2 + 2; - break; - - case 0xB0: - case 0xB1: - case 0xB2: - case 0xB3: - case 0xB4: - case 0xB5: - case 0xB6: - case 0xB7: - CUR.length = CUR.opcode - 0xB0 + 2; - break; - - case 0xB8: - case 0xB9: - case 0xBA: - case 0xBB: - case 0xBC: - case 0xBD: - case 0xBE: - case 0xBF: - CUR.length = (CUR.opcode - 0xB8) * 2 + 3; - break; - - default: - CUR.length = 1; - break; - } - - /* make sure result is in range */ - - if ( CUR.IP + CUR.length > CUR.codeSize ) - Panic( "code range overflow !!" ); - } - - - /* Disassemble the current line */ - /* */ - const FT_String* Cur_U_Line( TT_ExecContext exec ) - { - FT_String s[32]; - FT_Int op, i, n; - - op = exec->code[ exec->IP ]; - - sprintf( tempStr, "%04lx: %02hx %s", exec->IP, op, OpStr[op] ); - - if ( op == 0x40 ) - { - n = exec->code[ exec->IP+1 ]; - sprintf( s, "(%d)", n ); - strncat( tempStr, s, 8 ); - - if ( n > 20 ) n = 20; /* limit output */ - - for ( i = 0; i < n; i++ ) - { - sprintf( s, " $%02hx", exec->code[ exec->IP+i+2 ] ); - strncat( tempStr, s, 8 ); - } - } - else if ( op == 0x41 ) - { - n = exec->code[ exec->IP+1 ]; - sprintf( s, "(%d)", n ); - strncat( tempStr, s, 8 ); - - if (n > 20) n = 20; /* limit output */ - - for ( i = 0; i < n; i++ ) - { - sprintf( s, " $%02hx%02hx", exec->code[ exec->IP+i*2+2 ], - exec->code[ exec->IP+i*2+3 ] ); - strncat( tempStr, s, 8 ); - } - } - else if ( (op & 0xF8) == 0xB0 ) - { - n = op-0xB0; - - for ( i=0; i <= n; i++ ) - { - sprintf( s, " $%02hx", exec->code[ exec->IP+i+1 ] ); - strncat( tempStr, s, 8 ); - } - } - else if ( (op & 0xF8) == 0xB8 ) - { - n = op-0xB8; - - for ( i = 0; i <= n; i++ ) - { - sprintf( s, " $%02hx%02hx", exec->code[ exec->IP+i*2+1 ], - exec->code[ exec->IP+i*2+2 ] ); - strncat( tempStr, s, 8 ); - } - } - - return (FT_String*)tempStr; - } - - - static - int old_tag_to_new( int tag ) - { - int result = tag & 1; - if (tag & FT_Curve_Tag_Touch_X) - result |= 2; - if (tag & FT_Curve_Tag_Touch_Y) - result |= 4; - - return result; - } - - static - FT_Error RunIns( TT_ExecContext exc ) - { - FT_Int A, diff, key; - FT_Long next_IP; - FT_Char ch, oldch = '\0', *temp; - - FT_Error error = 0; - - TT_GlyphZone save; - TT_GlyphZone pts; - - const FT_String* round_str[8] = - { - "to half-grid", - "to grid", - "to double grid", - "down to grid", - "up to grid", - "off", - "super", - "super 45" - }; - - /* only debug the requested code range */ - if (exc->curRange != (FT_Int)debug_coderange) - return TT_RunIns(exc); - - exc->pts.n_points = exc->zp0.n_points; - exc->pts.n_contours = exc->zp0.n_contours; - - pts = exc->pts; - - - save.n_points = pts.n_points; - save.n_contours = pts.n_contours; - - save.org = (FT_Vector*)malloc( 2 * sizeof( FT_F26Dot6 ) * - save.n_points ); - save.cur = (FT_Vector*)malloc( 2 * sizeof( FT_F26Dot6 ) * - save.n_points ); - save.tags = (FT_Byte*)malloc( save.n_points ); - - exc->instruction_trap = 1; - - do - { - if ( CUR.IP < CUR.codeSize ) - { - Calc_Length( exc ); - - CUR.args = CUR.top - (Pop_Push_Count[CUR.opcode] >> 4); - - /* `args' is the top of the stack once arguments have been popped. */ - /* One can also interpret it as the index of the last argument. */ - - /* Print the current line. We use a 80-columns console with the */ - /* following formatting: */ - /* */ - /* [loc]:[addr] [opcode] [disassemby] [a][b]|[c][d] */ - /* */ - - { - char temp[80]; - int n, col, pop; - int args = CUR.args; - - sprintf( temp, "%78c\n", ' ' ); - - /* first letter of location */ - switch ( CUR.curRange ) - { - case tt_coderange_glyph: - temp[0] = 'g'; - break; - case tt_coderange_cvt: - temp[0] = 'c'; - break; - default: - temp[0] = 'f'; - } - - /* current IP */ - sprintf( temp+1, "%04lx: %02x %-36.36s", - CUR.IP, - CUR.opcode, - Cur_U_Line(&CUR) ); - - strncpy( temp+46, " (", 2 ); - - args = CUR.top - 1; - pop = Pop_Push_Count[CUR.opcode] >> 4; - col = 48; - for ( n = 6; n > 0; n-- ) - { - if ( pop == 0 ) - temp[col-1] = (temp[col-1] == '(' ? ' ' : ')' ); - - if ( args < CUR.top && args >= 0 ) - sprintf( temp+col, "%04lx", CUR.stack[args] ); - else - sprintf( temp+col, " " ); - - temp[col+4] = ' '; - col += 5; - pop--; - args--; - } - temp[78] = '\n'; - temp[79] = '\0'; - printf( "%s", temp ); - } - - /* First, check for empty stack and overflow */ - if ( CUR.args < 0 ) - { - printf( "ERROR : Too Few Arguments\n" ); - CUR.error = TT_Err_Too_Few_Arguments; - goto LErrorLabel_; - } - - CUR.new_top = CUR.args + (Pop_Push_Count[CUR.opcode] & 15); - - /* new_top is the new top of the stack, after the instruction's */ - /* execution. top will be set to new_top after the 'case' */ - - if ( CUR.new_top > CUR.stackSize ) - { - printf( "ERROR : Stack overflow\n" ); - CUR.error = TT_Err_Stack_Overflow; - goto LErrorLabel_; - } - } - else - printf( "End of program reached.\n" ); - - key = 0; - do - { - /* read keyboard */ - - ch = getch(); - - switch ( ch ) - { - /* Help - show keybindings */ - case '?': - printf( "TTDebug Help\n\n" ); - printf( "? Show this page\n" ); - printf( "q Quit debugger\n" ); - printf( "n Skip to next instruction\n" ); - printf( "s Step into\n" ); - printf( "v Show vector info\n" ); - printf( "g Show graphics state\n" ); - printf( "p Show points zone\n\n" ); - break; - - /* Show vectors */ - case 'v': - printf( "freedom (%04hx,%04hx)\n", exc->GS.freeVector.x, - exc->GS.freeVector.y ); - printf( "projection (%04hx,%04hx)\n", exc->GS.projVector.x, - exc->GS.projVector.y ); - printf( "dual (%04hx,%04hx)\n\n", exc->GS.dualVector.x, - exc->GS.dualVector.y ); - break; - - /* Show graphics state */ - case 'g': - printf( "rounding %s\n", round_str[exc->GS.round_state] ); - printf( "min dist %04lx\n", exc->GS.minimum_distance ); - printf( "cvt_cutin %04lx\n", exc->GS.control_value_cutin ); - break; - - /* Show points table */ - case 'p': - for ( A = 0; A < exc->pts.n_points; A++ ) - { - printf( "%02hx ", A ); - printf( "%08lx,%08lx - ", pts.org[A].x, pts.org[A].y ); - printf( "%08lx,%08lx\n", pts.cur[A].x, pts.cur[A].y ); - } - printf(( "\n" )); - break; - - default: - key = 1; - } - } while ( !key ); - - MEM_Copy( save.org, pts.org, pts.n_points * sizeof ( FT_Vector ) ); - MEM_Copy( save.cur, pts.cur, pts.n_points * sizeof ( FT_Vector ) ); - MEM_Copy( save.tags, pts.tags, pts.n_points ); - - /* a return indicate the last command */ - if (ch == '\r') - ch = oldch; - - switch ( ch ) - { - /* Quit debugger */ - case 'q': - goto LErrorLabel_; - - /* Step over */ - case 'n': - if ( exc->IP < exc->codeSize ) - { - /* `step over' is equivalent to `step into' except if */ - /* the current opcode is a CALL or LOOPCALL */ - if ( CUR.opcode != 0x2a && CUR.opcode != 0x2b ) - goto Step_into; - - /* otherwise, loop execution until we reach the next opcode */ - next_IP = CUR.IP + CUR.length; - while ( exc->IP != next_IP ) - { - if ( ( error = TT_RunIns( exc ) ) ) - goto LErrorLabel_; - } - } - oldch = ch; - break; - - /* Step into */ - case 's': - if ( exc->IP < exc->codeSize ) - - Step_into: - if ( ( error = TT_RunIns( exc ) ) ) - goto LErrorLabel_; - oldch = ch; - break; - - default: - printf( "unknown command. Press ? for help\n" ); - oldch = '\0'; - } - - for ( A = 0; A < pts.n_points; A++ ) - { - diff = 0; - if ( save.org[A].x != pts.org[A].x ) diff |= 1; - if ( save.org[A].y != pts.org[A].y ) diff |= 2; - if ( save.cur[A].x != pts.cur[A].x ) diff |= 4; - if ( save.cur[A].y != pts.cur[A].y ) diff |= 8; - if ( save.tags[A] != pts.tags[A] ) diff |= 16; - - if ( diff ) - { - printf( "%02hx ", A ); - - if ( diff & 16 ) temp = "(%01hx)"; else temp = " %01hx "; - printf( temp, old_tag_to_new(save.tags[A]) ); - - if ( diff & 1 ) temp = "(%08lx)"; else temp = " %08lx "; - printf( temp, save.org[A].x ); - - if ( diff & 2 ) temp = "(%08lx)"; else temp = " %08lx "; - printf( temp, save.org[A].y ); - - if ( diff & 4 ) temp = "(%08lx)"; else temp = " %08lx "; - printf( temp, save.cur[A].x ); - - if ( diff & 8 ) temp = "(%08lx)"; else temp = " %08lx "; - printf( temp, save.cur[A].y ); - - printf( "\n" ); - - printf( "%02hx ", A ); - - if ( diff & 16 ) temp = "[%01hx]"; else temp = " %01hx "; - printf( temp, old_tag_to_new(pts.tags[A]) ); - - if ( diff & 1 ) temp = "[%08lx]"; else temp = " %08lx "; - printf( temp, pts.org[A].x ); - - if ( diff & 2 ) temp = "[%08lx]"; else temp = " %08lx "; - printf( temp, pts.org[A].y ); - - if ( diff & 4 ) temp = "[%08lx]"; else temp = " %08lx "; - printf( temp, pts.cur[A].x ); - - if ( diff & 8 ) temp = "[%08lx]"; else temp = " %08lx "; - printf( temp, pts.cur[A].y ); - - printf( "\n\n" ); - } - } - } while ( TRUE ); - - LErrorLabel_: - - if (error) - Panic( "error during execution" ); - return error; - } - - - - - - static - void Usage() - { - fprintf( stderr, "ttdebug - a simply TrueType font debugger\n" ); - fprintf( stderr, "(c) The FreeType project - www.freetype.org\n" ); - fprintf( stderr, "-------------------------------------------\n\n" ); - - fprintf( stderr, "usage : ttdebug [options] glyph size fontfile[.ttf]\n\n" ); - - fprintf( stderr, " glyph - glyph index within the font file. Can be negative to query \n" ); - fprintf( stderr, " the debugging of the font 'cvt' program\n\n" ); - - fprintf( stderr, " size - size of glyph in pixels\n\n" ); - - fprintf( stderr, " fontfile - a valid TrueType file.\n\n" ); - - fprintf( stderr, " valid options are:\n\n" ); - fprintf( stderr, " -d : Dump mode. Shows the glyph program and exit immediately\n" ); - fprintf( stderr, " -n : Non-interactive mode. Dumps the execution trace and exit\n" ); - - exit(1); - } - - -int dump_mode; -int non_interactive_mode; -char* file_name; -int glyph_index; -int glyph_size; - - int main( int argc, char** argv ) - { - char valid; - - /* Check number of arguments */ - if ( argc < 4 ) Usage(); - - /* Check options */ - dump_mode = 0; - non_interactive_mode = 0; - - argv++; - while (argv[0][0] == '-') - { - valid = 0; - switch (argv[0][1]) - { - case 'd': - dump_mode = 1; - valid = 1; - break; - - case 'n': - non_interactive_mode = 1; - valid = 1; - break; - - default: - ; - } - - if (valid) - { - argv++; - argc--; - if (argc < 4) Usage(); - } - else - break; - } - - /* Get Glyph index */ - if ( sscanf( argv[0], "%d", &glyph_index ) != 1 ) - { - printf( "invalid glyph index = %s\n", argv[1] ); - Usage(); - } - - /* Get Glyph size */ - if ( sscanf( argv[1], "%d", &glyph_size ) != 1 ) - { - printf( "invalid glyph size = %s\n", argv[1] ); - Usage(); - } - - /* Get file name */ - file_name = argv[2]; - - Init_Keyboard(); - - /* Init library, read face object, get driver, create size */ - error = FT_Init_FreeType( &library ); - if (error) Panic( "could not initialise FreeType library" ); - - memory = library->memory; - driver = (FT_Driver)FT_Get_Module( library, "truetype" ); - if (!driver) Panic( "could not find the TrueType driver in FreeType 2\n" ); - - FT_Set_Debug_Hook( library, - FT_DEBUG_HOOK_TRUETYPE, - (FT_DebugHook_Func)RunIns ); - - error = FT_New_Face( library, file_name, 0, (FT_Face*)&face ); - if (error) Panic( "could not open font resource" ); - - /* find driver and check format */ - if ( face->root.driver != driver ) - { - error = FT_Err_Invalid_File_Format; - Panic( "This is not a TrueType font" ); - } - - size = (TT_Size)face->root.size; - - if (glyph_index < 0) - { - exec = TT_New_Context( face ); - size->debug = 1; - size->context = exec; - - error = FT_Set_Char_Size( (FT_Face)face, glyph_size << 6, glyph_size << 6, 72, 72 ); - if (error) Panic( "could not set character sizes" ); - } - else - { - error = FT_Set_Char_Size( (FT_Face)face, glyph_size << 6, glyph_size << 6, 72, 72 ); - if (error) Panic( "could not set character sizes" ); - - glyph = (TT_GlyphSlot)face->root.glyph; - - /* Now load glyph */ - error = FT_Load_Glyph( (FT_Face)face, glyph_index, FT_LOAD_NO_BITMAP ); - if (error) Panic( "could not load glyph" ); - } - - Reset_Keyboard(); - return 0; - }