1C*PGPTXT -- write text at arbitrary position and angle
2C%void cpgptxt(float x, float y, float angle, float fjust, \
3C% const char *text);
4C+
5      SUBROUTINE PGPTXT (X, Y, ANGLE, FJUST, TEXT)
6      REAL X, Y, ANGLE, FJUST
7      CHARACTER*(*) TEXT
8C
9C Primitive routine for drawing text. The text may be drawn at any
10C angle with the horizontal, and may be centered or left- or right-
11C justified at a specified position.  Routine PGTEXT provides a
12C simple interface to PGPTXT for horizontal strings. Text is drawn
13C using the current values of attributes color-index, line-width,
14C character-height, and character-font.  Text is NOT subject to
15C clipping at the edge of the window.
16C
17C Arguments:
18C  X      (input)  : world x-coordinate.
19C  Y      (input)  : world y-coordinate. The string is drawn with the
20C                    baseline of all the characters passing through
21C                    point (X,Y); the positioning of the string along
22C                    this line is controlled by argument FJUST.
23C  ANGLE  (input)  : angle, in degrees, that the baseline is to make
24C                    with the horizontal, increasing counter-clockwise
25C                    (0.0 is horizontal).
26C  FJUST  (input)  : controls horizontal justification of the string.
27C                    If FJUST = 0.0, the string will be left-justified
28C                    at the point (X,Y); if FJUST = 0.5, it will be
29C                    centered, and if FJUST = 1.0, it will be right
30C                    justified. [Other values of FJUST give other
31C                    justifications.]
32C  TEXT   (input)  : the character string to be plotted.
33C--
34C (2-May-1983)
35C 31-Jan-1985 - convert to Fortran-77 standard...
36C 13-Feb-1988 - correct a PGBBUF/PGEBUF mismatch if string is blank.
37C 16-Oct-1993 - erase background of opaque text.
38C-----------------------------------------------------------------------
39      INCLUDE 'pgplot.inc'
40      INTEGER CI, I, L, GRTRIM
41      REAL D, XP, YP
42      REAL XBOX(4), YBOX(4)
43      LOGICAL PGNOTO
44C
45      IF (PGNOTO('PGPTXT')) RETURN
46      CALL PGBBUF
47C
48      L = GRTRIM(TEXT)
49      D = 0.0
50      IF (FJUST.NE.0.0) CALL GRLEN(TEXT(1:L),D)
51      XP = PGXORG(PGID)+X*PGXSCL(PGID) - D*FJUST*COS(ANGLE/57.29578)
52      YP = PGYORG(PGID)+Y*PGYSCL(PGID) - D*FJUST*SIN(ANGLE/57.29578)
53      IF (PGTBCI(PGID).GE.0) THEN
54          CALL GRQTXT (ANGLE, XP, YP, TEXT(1:L), XBOX, YBOX)
55          DO 25 I=1,4
56              XBOX(I) = (XBOX(I)-PGXORG(PGID))/PGXSCL(PGID)
57              YBOX(I) = (YBOX(I)-PGYORG(PGID))/PGYSCL(PGID)
58   25     CONTINUE
59          CALL PGQCI(CI)
60          CALL PGSCI(PGTBCI(PGID))
61          CALL GRFA(4, XBOX, YBOX)
62          CALL PGSCI(CI)
63      END IF
64      CALL GRTEXT(.TRUE. ,ANGLE, .TRUE., XP, YP, TEXT(1:L))
65   30 CALL PGEBUF
66      END
67