/* Stats_Char.rexx  */
/* Get statistics for character at entry cursor location. */
/* Cursor must be positioned on the character being surveyed. */
/* Height = fontsize; BaselineY = top y + line height + border & shadow. */

/* Requires Toaster_CG v4.03 */
/* By Ross Fenmore © 1995 Light Source Video & Graphics */

SIGNAL ON ERROR
SIGNAL ON SYNTAX

CALL addlib(CG_AREXX,0)


type=get_line(type)
IF type='NotALine' THEN type='PS_Brush'


text=get_char()
ascii=c2d(text)
charnum=get_char(spot)
name=get_char(face)
width=get_char(size)
fontsize=get_font(size)

height=get_line(tall)
linecoords=get_line(spot)
PARSE var linecoords x y

pagetype=get_page('type')
IF (pagetype='Crawl') THEN DO

	call req_tell("This is a CRAWL page.","No character statistics available at this time.")

	call remlib(CG_AREXX)

	exit

END

charX=0

SELECT 

	WHEN type='Text' THEN DO

		charX=getcharX(charnum,x)

		string1="Character: "||'"'text'"'||"     ASCII: "||ascii||"     Char#: "||charnum
		string2="Font: "||name
		string3=insert("Width: "||width,"Height: "||fontsize,20,20," ")
		string4=insert("X Pos: "||charX,"BaselineY: "||y+height,20,20," ")

		call req_tell(string1,string2,string3,string4)
	END	

	WHEN (type='Box') THEN DO
		boxcoords=get_rect(spot)
		boxsize=get_rect(size)
		PARSE var boxcoords bx by
		PARSE var boxsize bw bh

		typestring="Line Type: "||type
		lhystring="LineHeight: "||height||"    BaselineY: "||y+height
		bxystring=type||" Upper left coordinates: "||boxcoords
		bwhstring=type||"Width: "||bw||"    "||type||"Height: "||bh

		call req_tell(typestring,lhystring,bxystring,bwhstring)
	END

	WHEN (type='Brush')|(type='PS_Brush') THEN DO
		boxcoords=get_rect(spot)
		boxsize=get_rect(size)
		PARSE var boxcoords bx by
		PARSE var boxsize bw bh
		typestring="Line Type: "||type
		lhystring=insert("BaselineY: "||y+height,"LineHeight: "||height,20,20," ")
		bxystring="Upper Left: "||boxcoords||"   "||type||"Width: "||bw||"    "||type||"Height: "||bh

		call req_tell(typestring,name,lhystring,bxystring)
	END


END


call remlib(CG_AREXX)

exit

/* Calculate the upper left coodinates of current character */
/* ARGS: restorespot = current cursor location in line */
/*       lineX = upper left x coordinate of line */

GETCHARX:
PARSE arg restorespot,lineX


charX=lineX
current_char=1

DO WHILE current_char <= restorespot
	
	call set_char(spot,current_char)
	charwidth=get_char(size)
	charX=charX+charwidth+1
	current_char=current_char+1

END

call set_char(spot,restorespot+1)

RETURN charX

ERROR:
SYNTAX:
errorcode = rc
line=SIGL
text='"'errortext(errorcode)'"'
call req_tell("ERROR= "||errorcode,"On line# "||line,text)
exit
