//		  ÚÄÄÄÄÄÄÄ¿
//	ÄÄÄÄÄÄÄÄÄ>³ AVNER ³
//	ÄÄÄÄÄÄÄÄÄ>³  BEN  ³ÄÄÄÄÄÄ> Software Engineering Method
//		  ÀÄÄÄÄÄÄÄÙ
//	10 Dov-Hoz st. Tel-Aviv 63416 Israel tel. 972-3-221535

// The Screen NAVigator, ver 1.20 August 1990
// Copyright (c) 1990 by Avner Ben
// Snav is not, and never was, free software.
// for conditions for use refer to file "copyrigh.txt"

// The Screen Navigator is an object-oriented device-independent
// character-graphics driver package, written in the C++ language,
// distributed in the form of C++ source code.
// For further information refer to the documentation files.

// The user may not omit this text, from the beginning of the file, to
// the line of asterisks below.

/***************************************************************************/

// package nucleus part 2 - headers
// This file defines the "computer-alphabet" object, and offers an
// extended-ASCII implementation, as on the IBM-PC.
// for data-structure logic, refer to file "article".

// History:

// 28.7.89  avner ben coded.
// 7.9.90   avner ben - last update.
// for further details refer to documentation.

// Site history (of this copy):
// __.__.__ ____________ : __________________.

#ifndef SNAV1_H
#define SNAV1_H

#ifndef SNAV0_H
#include "/mtad/snav/snav0.hpp"
#endif

class computer_alphabet
{
	private :
		char	*name;
		int	numchars;	// including zero
		int	*grafc; 	// array of [numchars][2]
		int	index[16][16];	// access by weight:intersection
		 // temp store to avoid returning by value
		weight_d tmpwgt;
		intersection tmpdirs;

	public :
		computer_alphabet(char *name, int bufsize, int *data);
		 // bufsize: number of characters supported, including bin zero
		 // data: ptr to zero-terminated integer array, arranged in
		 // successions of four integers representing:
		 //	 unsigned character (ascii/other) num,
		 //	 character's intersection(),
		 //	 character's weight_d.y(),
		 //	 character's weight_d.x();
		computer_alphabet(computer_alphabet &other);
		~computer_alphabet(void);
		 // free internal character storage
		void poke_c(char c, intersection avdir, weight_d wgt);
		 // modify default character attributes, updating index

		// access method services:
		intersection &cdir(char inc)
		 // retrieve direction set defined for character (temporary result!)
		 // cdir('|') returns [Up,Down]
		 { tmpdirs=(*(grafc+(unsigned char)inc*2)); return tmpdirs; }
		weight_d &cweight(char inc)
		 // retrieve weight distribution of char (temporary result!)
		 // cweight('³') returns 0:1
		 { tmpwgt.set(*(grafc+(unsigned char)inc*2+1)); return tmpwgt; }
		int cwidth(char inc, axis &dim);
		 // retrieve width of char in dimension (short version of cweight)
		 // cwidth('³',VDIM) returns 1
		char get_c(intersection &avdir, weight_d &wgt);
		 // retrieve character by attributes, or a close match
		 // get_c(RTDIR+LTDIR+UPDIR,1:1) returns 'Á'
		char translate(char c, weight_d &wgt);
		 // translate character to target width, as close as possible
		 // translate('Á',2:1) returns 'Ï'

		// character connectivity
		boolean ccont(char cfrom, char cto, direction &dirfrom);
		 // test if two characters connect in a direction.
		 // ccont('Ã','-',RTDIR) returns TRUE
		 // ccont('Ã','-',LTDIR) returns FALSE
		char carrw(char *env, direction dir, weight_d wgt, int len,
		 int pos, boolean directed=FALSE);
		 //  draw one character within an arc.
		 //  env:	 "environment" sorrownding current page position,
		 //		 ordered: current char, then neighbours, arranged
		 //		 in (direction++ order)
		 //  dir:	 direction of arc being charted.
		 //  wgt:	 arc width.
		 //  len:	 total arc length planned.
		 //  pos:	 current position from arc start (starting at 1).
		 //  directed:	 if true, last char (pos==len) is an arrowhead.
		char *cearrw(char *env, direction &dir, weight_d &wgt, int len,
		 int pos, boolean directed);
		 // version of carrw that trims exess from the environment
		 // to make some procedures use this instead, #define ENV_MODIFY
		char ctrim(char c, direction &extradir);
		 // trim char in protruding direction, if present
		 // ctrim('Ã',RTDIR) returns '³'
		char celong(char c, direction &elongdir);
		 // elongate char in this direction, if not already present
		 // celong('³',RTDIR) returns 'Ã'

		//miscelanous:
		computer_alphabet& operator=(computer_alphabet &other);
		int list(FILE *outf);
		 // print the index (originally intended for debugging)
		void inverse(axis &dim);
		 // invert the semigraphic alphabet on axis (e.g. latin=>semitic)
};

#ifndef SNAV_C
extern computer_alphabet *alph;
 // system defined default alphabet (ascii_pc).
 // all your inquiries to the current alphabet object must
 // be of the type: alph->function(args);
 // if you overload your own alphabet, make sure to preserve this address!
extern int ascii_pc_data[];
 // in-memory file to pass to the constructor of an ascii_pc type alphabet.
 // Used by system to initialize the default alphabet.
#endif

#endif
