Text

Text can be added to a figure using the text(); command. The first two parameters are a coordinate pair giving the position at which the text should start. For subsequent lines of text the coordinates can be omitted in which case the line is positioned below the previous line. The third parameter is the actual text to be printed. There is also an optional fourth parameter which allows the text to be centered on the coordinates or end at the coordinates. Specialized text labels are also generated using the label(); and ticklabel( ); commands and the following discussion applies to them as well.

The appearance of the text is affected by several set-able parameters. The size of the letters is determined by set(FONTWIDTH , size_in_cm); while the ratio of height to width is set using set(FONTASPECT , height_div_width);. Alternatively, the size of the text can be changed from its current value by using set(FONTMULT , multiplier);. The spacing between letters can be modified using set(FONTSPACE , space_in_cm);. The text is ordinarily printed horizontally but this may be changed by using set(FONTDIR , angle_in_deg);. The width of the line used to draw the text is set using set(LINEWIDTH , width); and the colour is set using set(LINECOLOUR , colour_number );. The text is printed using Hershey stroked fonts. There are two available font families simplex and complex. The complex font is chosen using set(FONT , COMPLEX);. Greek and Italic text is selected by using special characters in the text string. Thus Greek may be selected by enclosing a string with '!' as in '!abc! while italics are selected using '#'. Super and sub scripts are handled in the same way by enclosing the super/sub script with '∧' or '_' respectively. The position and size of the super/sub script relative to ordinary text may be modified using the set(SCRIPTSCALE , ratio); and set(SCRIPTSHIFT , fraction ); commands respectively. Characters from the symbol font may be included in the text string by enclosing the symbol number with '$'.

The various text possibilities are explored in the two following demo files. The third demo file is a table of all the available text characters included in the font files.

/* This file illustrates some of the capabilities of the */
/* text() command to annotate figures */
/* Several fonts are available including full Greek. */
/* Text can be any size, orientation and colour. */ 
 
#include <splot.h>
main()
   {
   text(2.63,23,"The default position for the next line");
   /* change to complex font for next line */
   set(FONT,COMPLEX);
   text("right below the previous line");
   set(FONT,SIMPLEX);
   text("There is a complete set of Greek characters"); 
   text("!abcdefghijklmnopqrstuvxyz!");
   set(FONT,COMPLEX);
   text("!ABCDEFGHIJKLMNOPQRSTUVWXYZ!");
   set(FONT,SIMPLEX);
   set(LINECOLOUR,GREEN);
   /* optional change of script scale and position */
   set(SCRIPTSCALE,1);
   set(SCRIPTSHIFT,1);
   text("Here are ^super^ and _sub_ scripts");
   set(LINECOLOUR,RED);
   text("and #Italics# in different colours");
   set(LINECOLOUR,BLACK);
   text("Letters can be large, small, tall, short");
   text("fat, thin, vertical and angled.");
   set(FONTMULT,2);
   text(2.94,9.56,"Large");
   set(FONTMULT,0.30);
   text(8.90,9.71,"small");
   set(FONTWIDTH,1.0);
   set(FONTASPECT,3);
   text(13.10,9.71,"Tall");
   set(FONTASPECT,0.5);
   text(17.05,9.71,"Short");
   set(FONTASPECT,2);
   set(LINEWIDTH,0.01);
   text(2.94,7.29,"Thin");
   set(LINEWIDTH,0.2);
   text(9.02,7.29,"Fat"); 
   set(LINEWIDTH,0.05);
   set(FONTDIR,90);
   text(3.63,1.26,"Vertical");
   set(FONTDIR,130);
   text(11.28,1.44,"Angled");
   }



























































/* This file illustrates some of the capabilities of the */
/* text() command to annotate figures */
 
#include <splot.h>
main()
   {
   text(2,23,"The spacing between letters can be changed");
   set(FONTSPACE,0.5);
   text("to be further apart than usual");
   set(FONTSPACE,-0.2);
   text("or closer together.");
   set(FONTSPACE,0);
   text("The size and position of super/sub scripts can");
   text(2,17.38,"be varied as in");
   set(SCRIPTSHIFT,0.7);
   set(SCRIPTSCALE,0.5);
   text(8.94,17.38,"X_1_\b^2^,");
   set(SCRIPTSHIFT,1.0);
   set(SCRIPTSCALE,0.7);
   text(10.19,17.38,"X_1_\b^2^,");
   set(SCRIPTSHIFT,1.5);
   set(SCRIPTSCALE,1.0);
   text(11.4,17.38,"X_1_\b^2^.");
   text(2.10,15.81,"Note how the superscript was placed above");
   text("the subscript using the backspace char \\b.");
   text("Enter degree sign using '<ALT X> 127'");
   text("Use a \\ before special characters: \_\^\$\#\!\"");
   text("Symbols: $0 1 2 3 4 5 6 7 8 9 : ; < = > $"); 
  
   text(2,8,"The default text insertion point is LEFT");
   text(17,6,"but can be set to RIGHT",RIGHT);
   text(10,4,"Or CENTER",CENTER);
   }



























































/* This file displays all the available characters */
 
#include <splot.h>       
#define ROMAN 1
#define GREEK 0
#define ITALIC 0
int i,j;
char c[10];

main()
   {
   set(PAGEROT,ON);
#if ROMAN
   text(13.67,19.14,"Roman",CENTER);
   text(7.5,18,"Simplex",CENTER);
   text(19,18,"Complex",CENTER);
   gsave();
   scale(1.2,1.2);
   translate(1,-11);
   set(FONTWIDTH,0.5);
   set(FONTASPECT,1.5);
   table(0);
   translate(10,0);
   set(FONT,COMPLEX);
   table(0);
   set(FONT,SIMPLEX);
#endif
#if GREEK
   text(13.67,19.14,"Greek",CENTER);
   text(7.5,18,"Simplex",CENTER);
   text(19,18,"Complex",CENTER);
   gsave();
   scale(1.2,1.2);
   translate(1,-11);
   set(FONTWIDTH,0.5);
   set(FONTASPECT,1.5);
   table(1);
   translate(10,0);
   set(FONT,COMPLEX);
   table(1);
   set(FONT,SIMPLEX);
#endif
#if ITALIC
   text(7.5,18,"Italics Simplex/Complex",CENTER);
   text(19,18,"Symbols",CENTER);
   gsave();
   scale(1.2,1.2);
   translate(1,-11);
   set(FONTWIDTH,0.5);
   set(FONTASPECT,1.5);
   table(2);
   translate(10,0);
   table(3);
#endif
   grestore();
   }

table(int special)
   {
   /* label rows and columns */
   c[1] = '\0';
   for (i = 0; i < 10;i++)
      {
      c[0] = '0' + i;
      tputs(2 + i * 0.7,24.5,c,0);
      }
   c[0] = ' ';
   c[2] = '0';
   c[3] = '\0';
   for (j = 3;j < 10;j++)
      {
      c[1] = '0' + j;
      tputs(0,26 - j,c,0);
      }
   c[0] = '1';
   c[2] = '0';
   c[3] = '\0';
   for (j = 10;j < 13;j++)
      {
      c[1] = '0' + j - 10;
      tputs(0,26 - j,c,0);
      }
   /* prepend each char with '\' so that even special chars get printed */
   c[0] = '\\';
   c[2] = '\0';
   box(1.29,23.77,9.07,13.36);
   stroke();
   /* fill in table */
   for (j = 3;j < 13;j++)
      {
      for (i = 0; i < 10;i++)
	 {
	 c[1] = j * 10 + i;
	 if (c[1] == 'b')
	    tputs(2 + i * 0.7,26 - j,"b",special);
	 else
	    tputs(2 + i * 0.7,26 -j,c,special);
	 }
      }
   }

tputs(double x,double y,char *c,int special) 
   {
   char tmp[10];
   switch(special)
      {
      case 0:
	 text(x,y,c);
	 break;
      case 1:
	 /* greek */
	 strcpy(tmp,"!");
	 strcat(tmp,c);
	 strcat(tmp,"!");
	 text(x,y,tmp);
	 break;
      case 2:
	 /* italics */
	 strcpy(tmp,"#");
	 strcat(tmp,c);
	 strcat(tmp,"#");
	 text(x,y,tmp);
	 break;
      case 3:
	 /* symbols */
	 strcpy(tmp,"$");
	 strcat(tmp,c);
	 strcat(tmp,"$");
	 text(x,y,tmp);
	 break;
      }
   }