PLplot
5.15.0
Toggle main menu visibility
Loading...
Searching...
No Matches
cdtext.c
Go to the documentation of this file.
1
//
2
// cdtext is an example program that uses the text attribute commands
3
// cdSetTextPath and cdSetTextOrient
4
//
5
//
6
// cdtext.c: test program for the cgmdraw module.
7
//
8
// Written by G. Edward Johnson <mailto:lorax@nist.gov>
9
// Date: May 1996
10
// Copyright: cd software produced by NIST, an agency of the
11
// U.S. government, is by statute not subject to copyright
12
// in the United States. Recipients of this software assume all
13
// responsibilities associated with its operation, modification
14
// and maintenance.
15
//
16
//
17
18
19
#include <stdio.h>
20
#include <math.h>
21
#include <string.h>
22
#include <stdlib.h>
23
#include "
defines.h
"
24
#include "
cd.h
"
25
26
27
int
main
()
28
{
29
// you must create a pointer to the image(s) that you will be using
30
// not suprisingly, it is of type cdImagePtr
31
cdImagePtr
im;
32
33
// this is a pointer to the output file you will be using
34
FILE *outf;
35
36
// these will be index's into the color palette containing
37
// the corresponding colors
38
int
black, white, blue;
39
40
41
// Create an image 800 pixels wide by 400 pixels high
42
im =
cdImageCreate
( 800, 400 );
43
44
// allocate some colors (isn't this fun?)
45
// the first color allocated is the background color
46
white =
cdImageColorAllocate
( im, 255, 255, 255 );
47
black =
cdImageColorAllocate
( im, 0, 0, 0 );
48
blue =
cdImageColorAllocate
( im, 0, 0, 255 );
49
50
51
// set the text attributes
52
// font, colorindex, and size respectivily
53
54
// font is the style the text is written in. 1 is for Times,
55
// 5 is for Helvetica.
56
// we will have black text for this one
57
// Size is a tough one, but larger numbers give larger text.
58
//
59
if
( !(
cdSetTextAttrib
( im, 5, black, 20 ) ) )
60
return
1;
61
62
// Set some line attributes, lets make lines solid, width 1, and blue
63
//
64
if
( !(
cdSetLineAttrib
( im, 1, 1, blue ) ) )
65
return
1;
66
67
// Draw a couple of grid lines
68
if
( !(
cdLine
( im, 0, 200, 799, 200 ) ) )
69
return
1;
70
if
( !(
cdLine
( im, 200, 0, 200, 399 ) ) )
71
return
1;
72
if
( !(
cdLine
( im, 600, 0, 600, 399 ) ) )
73
return
1;
74
75
76
// Show Text going left, up, down, and right, all starting
77
// from the same point
78
79
// Text going to the left
80
if
( !(
cdSetTextPath
( im, 1 ) ) )
81
return
1;
82
if
( !(
cdText
( im, 200, 200,
"Text Left"
) ) )
83
return
1;
84
85
// Text going UP
86
if
( !(
cdSetTextPath
( im, 2 ) ) )
87
return
1;
88
if
( !(
cdText
( im, 200, 200,
"Text Up"
) ) )
89
return
1;
90
91
// Text going DOWN
92
if
( !(
cdSetTextPath
( im, 3 ) ) )
93
return
1;
94
if
( !(
cdText
( im, 200, 200,
"Text Down"
) ) )
95
return
1;
96
97
// Text going to the RIGHT
98
if
( !(
cdSetTextPath
( im, 0 ) ) )
99
return
1;
100
if
( !(
cdText
( im, 200, 200,
"Text Right"
) ) )
101
return
1;
102
103
// Show text going at an angle of 0, 45, 90, 135, 180 Degrees
104
//
105
106
// Text at no angle
107
if
( !(
cdText
( im, 600, 200,
"CGM Draw"
) ) )
108
return
1;
109
110
// Text, 45 Degree Angle
111
if
( !(
cdSetTextOrient
( im, -1, 1, 1, 1 ) ) )
112
return
1;
113
if
( !(
cdText
( im, 600, 200,
"CGM Draw"
) ) )
114
return
1;
115
116
// Text, 90 Degree Angle
117
if
( !(
cdSetTextOrient
( im, -1, 0, 0, 1 ) ) )
118
return
1;
119
if
( !(
cdText
( im, 600, 200,
"CGM Draw"
) ) )
120
return
1;
121
122
// Text, 135 Degree Angle
123
if
( !(
cdSetTextOrient
( im, -1, -1, -1, 1 ) ) )
124
return
1;
125
if
( !(
cdText
( im, 600, 200,
"CGM Draw"
) ) )
126
return
1;
127
128
// Text, 180 Degree Angle
129
if
( !(
cdSetTextOrient
( im, 0, -1, -1, 0 ) ) )
130
return
1;
131
if
( !(
cdText
( im, 600, 200,
"CGM Draw"
) ) )
132
return
1;
133
134
// Skewed Text, No Angle
135
if
( !(
cdSetTextOrient
( im, 1, 1, 1, 0 ) ) )
136
{
137
return
1;
138
}
139
if
( !(
cdSetTextAttrib
( im, -1, -1, 40 ) ) )
140
{
141
return
1;
142
}
143
if
( !(
cdText
( im, 300, 300,
"CGM Draw"
) ) )
144
{
145
return
1;
146
}
147
// show some lines around it
148
if
( !(
cdLine
( im, 300, 300, 500, 300 ) ) )
149
return
1;
150
if
( !(
cdLine
( im, 300, 300, 340, 340 ) ) )
151
return
1;
152
153
// reset the text to 0 angle
154
if
( !(
cdSetTextOrient
( im, 0, 1, 1, 0 ) ) )
155
return
1;
156
157
158
if
( !(
cdSetTextAttrib
( im, 5, -1, 20 ) ) )
159
return
1;
160
if
( !(
cdText
( im, 5, 5,
"G. Edward Johnson"
) ) )
161
return
1;
162
163
// now write the file out, lets call it cdtext.cgm
164
outf = fopen(
"cdtext.cgm"
,
"wb"
);
165
if
( !outf )
166
return
1;
167
cdImageCgm
( im, outf );
168
fclose( outf );
169
outf = 0;
170
171
// Remember to destroy the image when you are done
172
cdImageDestroy
( im );
173
im = 0;
174
175
printf(
"CGM Text Example!!!\n"
);
176
177
return
0;
178
}
cdSetLineAttrib
int cdSetLineAttrib(cdImagePtr im, int lntype, int lnwidth, int lncolor)
Definition
cd.c:1652
cdImageCgm
int cdImageCgm(cdImagePtr im, FILE *out)
Definition
cd.c:560
cdLine
int cdLine(cdImagePtr im, int x1, int y1, int x2, int y2)
Definition
cd.c:2116
cdSetTextAttrib
int cdSetTextAttrib(cdImagePtr im, int font, int color, int height)
Definition
cd.c:1720
cdSetTextOrient
int cdSetTextOrient(cdImagePtr im, int xup, int yup, int xbase, int ybase)
Definition
cd.c:1409
cdImageColorAllocate
int cdImageColorAllocate(cdImagePtr im, int r, int g, int b)
Definition
cd.c:1966
cdText
int cdText(cdImagePtr im, int x, int y, const char *ts)
Definition
cd.c:2945
cdImageDestroy
int cdImageDestroy(cdImagePtr im)
Definition
cd.c:1766
cdSetTextPath
int cdSetTextPath(cdImagePtr im, int tpath)
Definition
cd.c:1357
cdImageCreate
cdImagePtr cdImageCreate(int sx, int sy)
Definition
cd.c:31
cd.h
cdImagePtr
cdImage * cdImagePtr
Definition
cd.h:123
main
int main()
Definition
cdtext.c:27
defines.h
lib
nistcd
cdtext.c
Generated on
for PLplot by
1.17.0