;+
; NAME:  
;	TEXTARRAY
;
; PURPOSE:
;	To create a two dimensional array containing 
;	text in vector font.
;
; CATEGORY:
;	PICO
;
; CALLING SEQUENCE:
;	result=TEXTARRAY(text)
;
; INPUTS:
;	text:  A string containing the text
;
; OPTIONAL INPUTS:
;	None
;
; KEYWORD PARAMETERS:
;	CHARSIZE, CHARTHICK: Normal signification
;		as for other graphical output
;	COLOR:  The color index to be used.
;		Default: 255
;
; OUTPUTS:
;	result: a two dimensional array. The background
;		is 0 whereas the text is written in 
;		the specified color. The textarray
;		can be inserted in an image using 
;		PUT_TEXT.
;
; OPTIONAL OUTPUTS:
;	None
;
; COMMON BLOCKS:
;	None
;
; SIDE EFFECTS:
;	Unknown
;
; RESTRICTIONS:
;	None
;
; PROCEDURE:
;	Straightforward
;
; MODIFICATION HISTORY:
;	V1.0 Alexander Epple, Pic Du Midi, 15-OCT-1995
;	Jun-2000, B. Podlipnik - Add BOLD, XP, YP keywords
;-

FUNCTION textarray, text, xdim, ydim, $
	CHARSIZE=charsize, CHARTHICK=charthick, FONT=font, COLOR=color, BOLD=bold, XP=xp, YP=yp

IF (N_ELEMENTS(charsize) EQ 0) THEN charsize=1
IF (N_ELEMENTS(charthick) EQ 0) THEN charthick=1
IF (N_ELEMENTS(font) EQ 0) THEN font=-1
IF (N_ELEMENTS(color) EQ 0) THEN color=255
if not keyword_set(xp) then xp = 0
if not keyword_set(yp) then yp = 0

olddev=!D.NAME
SET_PLOT,'Z'
xoldsize=!d.x_size & yoldsize=!d.y_size
xdim=STRLEN(text)*charsize*12+xp & ydim=charsize*12+yp
DEVICE,SET_RESOLUTION=[xdim,ydim]
ERASE

XYOUTS,xp,yp,text,/device,charsize=charsize,charthick=charthick,font=font, $
	COLOR=color

if keyword_set(bold) then begin
  xyouts, xp,yp+1,/device,text, charsize=charsize
  xyouts, xp+1,yp,/device,text, charsize=charsize
  xyouts, xp+1,yp+1,/device,text, charsize=charsize
endif

textarr=TVRD()

index=WHERE(REBIN(textarr,xdim,1) GT 0,counts)
IF (counts GT 0) THEN textarr=textarr(0:index(counts-1),*)

index=WHERE(REBIN(textarr,1,ydim) GT 0,counts)
IF (counts GT 0) THEN textarr=textarr(*,0:index(counts-1))

ERASE
DEVICE,set_resolution=[xoldsize,yoldsize]
SET_PLOT,olddev

sz=SIZE(textarr)
xdim=sz(1)
ydim=sz(2)

RETURN,textarr
END
