rplot 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,121 @@
1
+ #ifndef RUBY_PLOT
2
+ #define RUBY_PLOT
3
+
4
+ #include <ruby.h>
5
+ #include <plot.h>
6
+ #include <stdio.h>
7
+ #include "rplot_exceptions.h"
8
+
9
+ /* 4 base functions */
10
+
11
+ static VALUE new_pl (VALUE self, VALUE type, VALUE in_path, VALUE out_path, VALUE err_path);
12
+ //static VALUE select_pl (VALUE self);
13
+ static VALUE delete_pl (VALUE self);
14
+ static VALUE parampl (VALUE self, VALUE param, VALUE value);
15
+
16
+ /* Setup functions */
17
+
18
+ static VALUE openpl (VALUE self);
19
+ static VALUE bgcolor (VALUE self, VALUE red, VALUE green, VALUE blue);
20
+ static VALUE bgcolorname (VALUE self, VALUE name);
21
+ static VALUE erase (VALUE self);
22
+ static VALUE space (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1);
23
+ static VALUE fspace (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1);
24
+ static VALUE space2 (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2);
25
+ static VALUE fspace2 (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2);
26
+ static VALUE havecap (VALUE self, VALUE s);
27
+ static VALUE flushpl (VALUE self);
28
+ static VALUE closepl (VALUE self);
29
+
30
+ /* Object-drawing functions */
31
+
32
+ static VALUE alabel (VALUE self, VALUE horiz_justify, VALUE vert_justify, VALUE s);
33
+ static VALUE arc (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1);
34
+ static VALUE farc (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1);
35
+ static VALUE arcrel (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1);
36
+ static VALUE farcrel (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1);
37
+ static VALUE bezier2 (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2);
38
+ static VALUE fbezier2 (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2);
39
+ static VALUE bezier2rel (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2);
40
+ static VALUE fbezier2rel (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2);
41
+ static VALUE bezier3 (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3);
42
+ static VALUE fbezier3 (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3);
43
+ static VALUE bezier3rel (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3);
44
+ static VALUE fbezier3rel (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3);
45
+ static VALUE box (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2);
46
+ static VALUE fbox (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2);
47
+ static VALUE boxrel (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2);
48
+ static VALUE fboxrel (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2);
49
+ static VALUE circle (VALUE self, VALUE xc, VALUE yc, VALUE r);
50
+ static VALUE fcircle (VALUE self, VALUE xc, VALUE yc, VALUE r);
51
+ static VALUE circlerel (VALUE self, VALUE xc, VALUE yc, VALUE r);
52
+ static VALUE fcirclerel (VALUE self, VALUE xc, VALUE yc, VALUE r);
53
+ static VALUE cont (VALUE self, VALUE x, VALUE y);
54
+ static VALUE fcont (VALUE self, VALUE x, VALUE y);
55
+ static VALUE contrel (VALUE self, VALUE x, VALUE y);
56
+ static VALUE fcontrel (VALUE self, VALUE x, VALUE y);
57
+ static VALUE ellarc (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1);
58
+ static VALUE fellarc (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1);
59
+ static VALUE ellarcrel (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1);
60
+ static VALUE fellarcrel (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1);
61
+ static VALUE ellipse (VALUE self, VALUE xc, VALUE yc, VALUE rx, VALUE ry, VALUE angle);
62
+ static VALUE fellipse (VALUE self, VALUE xc, VALUE yc, VALUE rx, VALUE ry, VALUE angle);
63
+ static VALUE ellipserel (VALUE self, VALUE xc, VALUE yc, VALUE rx, VALUE ry, VALUE angle);
64
+ static VALUE fellipserel (VALUE self, VALUE xc, VALUE yc, VALUE rx, VALUE ry, VALUE angle);
65
+ static VALUE endpath (VALUE self);
66
+ static VALUE label (VALUE self, VALUE s);
67
+ static VALUE labelwidth (VALUE self, VALUE s);
68
+ static VALUE flabelwidth (VALUE self, VALUE s);
69
+ static VALUE line (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2);
70
+ static VALUE fline (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2);
71
+ static VALUE linerel (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2);
72
+ static VALUE flinerel (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2);
73
+ static VALUE marker (VALUE self, VALUE x, VALUE y, VALUE type, VALUE size);
74
+ static VALUE fmarker (VALUE self, VALUE x, VALUE y, VALUE type, VALUE size);
75
+ static VALUE markerrel (VALUE self, VALUE x, VALUE y, VALUE type, VALUE size);
76
+ static VALUE fmarkerrel (VALUE self, VALUE x, VALUE y, VALUE type, VALUE size);
77
+ static VALUE point (VALUE self, VALUE x, VALUE y);
78
+ static VALUE fpoint (VALUE self, VALUE x, VALUE y);
79
+ static VALUE pointrel (VALUE self, VALUE x, VALUE y);
80
+ static VALUE fpointrel (VALUE self, VALUE x, VALUE y);
81
+
82
+ /* Attribute-setting functions */
83
+
84
+ static VALUE capmod (VALUE self, VALUE s);
85
+ static VALUE color (VALUE self, VALUE red, VALUE green, VALUE blue);
86
+ static VALUE colorname (VALUE self, VALUE name);
87
+ static VALUE fillcolor (VALUE self, VALUE red, VALUE green, VALUE blue);
88
+ static VALUE fillcolorname (VALUE self, VALUE name);
89
+ static VALUE fillmod (VALUE self, VALUE s);
90
+ static VALUE filltype (VALUE self, VALUE level);
91
+ static VALUE fmiterlimit (VALUE self, VALUE limit);
92
+ static VALUE fontname (VALUE self, VALUE font_name);
93
+ static VALUE ffontname (VALUE self, VALUE font_name);
94
+ static VALUE fontsize (VALUE self, VALUE size);
95
+ static VALUE ffontsize (VALUE self, VALUE size);
96
+ static VALUE joinmod (VALUE self, VALUE s);
97
+ static VALUE linedash (VALUE self, VALUE n, VALUE dashes, VALUE offset);
98
+ static VALUE flinedash (VALUE self, VALUE n, VALUE dashes, VALUE offset);
99
+ static VALUE linemod (VALUE self, VALUE s);
100
+ static VALUE linewidth (VALUE self, VALUE size);
101
+ static VALUE flinewidth (VALUE self, VALUE size);
102
+ static VALUE move (VALUE self, VALUE x, VALUE y);
103
+ static VALUE fmove (VALUE self, VALUE x, VALUE y);
104
+ static VALUE moverel (VALUE self, VALUE x, VALUE y);
105
+ static VALUE fmoverel (VALUE self, VALUE x, VALUE y);
106
+ static VALUE pencolor (VALUE self, VALUE red, VALUE green, VALUE blue);
107
+ static VALUE pencolorname (VALUE self, VALUE name);
108
+ static VALUE restorestate (VALUE self);
109
+ static VALUE savestate (VALUE self);
110
+ static VALUE textangle (VALUE self, VALUE angle);
111
+ static VALUE ftextangle (VALUE self, VALUE angle);
112
+
113
+ /* Mapping functions */
114
+
115
+ static VALUE fconcat (VALUE self, VALUE m0, VALUE m1, VALUE m2, VALUE m3, VALUE tx, VALUE ty);
116
+ static VALUE frotate (VALUE self, VALUE theta);
117
+ static VALUE fscale (VALUE self, VALUE sx, VALUE sy);
118
+ static VALUE ftranslate (VALUE self, VALUE tx, VALUE ty);
119
+
120
+ #endif
121
+
@@ -0,0 +1,13 @@
1
+ #ifndef RUBY_PLOT_EXCEPTIONS
2
+ #define RUBY_PLOT_EXCEPTIONS
3
+
4
+ #include "rplot.h"
5
+
6
+ static VALUE create_plotter_error;
7
+ static VALUE select_plotter_error;
8
+ static VALUE open_plotter_error;
9
+ static VALUE close_plotter_error;
10
+ static VALUE delete_plotter_error;
11
+ static VALUE operation_plotter_error;
12
+
13
+ #endif
@@ -0,0 +1,1421 @@
1
+ #require 'ext/rplot'
2
+ require File.expand_path('../../ext/rplot', __FILE__)
3
+ # This class rappresents a Plotter.
4
+ #
5
+
6
+ # The graphical objects that libplot can draw include paths, circles
7
+ # and ellipses, points, markers, and <i>adjusted labels</i> (justified
8
+ # text strings). A path is a sequence of line segments, circular arcs,
9
+ # elliptic arcs, quadratic Bezier curves, and/or cubic Bezier
10
+ # curves. Paths may be open or closed. User-specified filling of
11
+ # paths, circles, and ellipses is supported (fill rule and fill color,
12
+ # as well as pen color, may be specified). There is support for
13
+ # maintaining a Postscript-style stack of graphics contexts, i.e., a
14
+ # stack of drawing attribute sets. Path-related attributes include
15
+ # line thickness, line type, cap type, and join type, and text-related
16
+ # attributes include font name, font size, and text angle.
17
+ #
18
+ # The fundamental abstraction provided is that of a Plotter. A Plotter
19
+ # is an object with an interface for the drawing of vector graphics
20
+ # which is similar to the interface provided by a traditional pen
21
+ # plotter. There are many types of Plotter, which differ in the output
22
+ # format they produce. Any number of Plotters, of the same or
23
+ # different types, may exist simultaneously in an application.
24
+ #
25
+ # The drawing operations supported by Plotters of different types are
26
+ # identical, in agreement with the principle of device
27
+ # independence. So a graphics application that is linked with libplot
28
+ # may easily be written so as to produce output in any or all of the
29
+ # supported output formats.
30
+ #
31
+ # The following are the currently supported types of Plotter:
32
+ #
33
+ # [X Plotters] An X Plotter, when opened, pops up a window on an X
34
+ # Window System display and draws graphics in it. The
35
+ # window will be <i>spun off</i> when the Plotter is
36
+ # closed; if it is subsequently reopened, a new window
37
+ # will be popped up. A spun-off window will remain on the
38
+ # screen but will vanish if you type +q+ or click your
39
+ # mouse in it. Future releases may permit X Plotters,
40
+ # when reopened, to reuse an existing window.
41
+ #
42
+ # [X Drawable Plotters] An X Drawable Plotter draws graphics in one or
43
+ # two specified drawables associated with an X
44
+ # Window System display. A _drawable_ is either
45
+ # a window or a pixmap.
46
+ #
47
+ # [PNM Plotters] A PNM Plotter produces a single page of output in
48
+ # <i>portable anymap</i> format, and directs it to a
49
+ # file or other specified output stream. There are
50
+ # three types of portable anymap: PBM (portable bitmap,
51
+ # for monochrome graphics), PGM (portable graymap), and
52
+ # PPM (portable pixmap, for colored graphics). The
53
+ # output file will be in whichever of these three
54
+ # formats is most appropriate. The file may be viewed
55
+ # or edited with many applications, such as the free
56
+ # image display application xv.
57
+ #
58
+ # [GIF Plotters] A GIF Plotter produces a single page of output in a
59
+ # pseudo-GIF format. Unlike true GIF format, the
60
+ # pseudo-GIF format does not use LZW compression: it
61
+ # uses run-length encoding instead. So it does not
62
+ # transgress the Unisys patent that restricts the use
63
+ # of LZW compression. However, the output file may be
64
+ # viewed or edited with any application that
65
+ # understands GIF format, such as xv. The creation of
66
+ # animated pseudo-GIFs is supported.
67
+ #
68
+ # [Illustrator Plotters] An Illustrator Plotter produces a single page
69
+ # of output in the format used by Adobe
70
+ # Illustrator, and directs it to a file or
71
+ # other specified output stream. The file may
72
+ # be edited with Adobe Illustrator (version 5,
73
+ # and more recent versions), or other
74
+ # applications.
75
+ #
76
+ # [Postscript Plotters] A Postscript Plotter produces Postscript
77
+ # output and directs it to a file or other
78
+ # specified output stream. If only a single
79
+ # page of graphics is drawn on the Plotter then
80
+ # its output is in EPS (encapsulated Postscript)
81
+ # format, so it may be included in another
82
+ # document. It may also be edited with the idraw
83
+ # drawing editor.
84
+ #
85
+ # [Fig Plotters] A Fig Plotter produces a single page of output in Fig
86
+ # format and directs it to a file or other specified
87
+ # output stream. The output may be edited with the xfig
88
+ # drawing editor. The xfig editor will export drawings
89
+ # in various other formats for inclusion in documents.
90
+ #
91
+ # [PCL Plotters] A PCL Plotter produces output in PCL 5 format and
92
+ # directs it to a file or other specified output
93
+ # stream. PCL 5 is a powerful version of
94
+ # Hewlett--Packard's Printer Control Language, which
95
+ # supports vector graphics. The output may be sent to a
96
+ # PCL 5 device such as a LaserJet printer or high-end
97
+ # inkjet.
98
+ #
99
+ # [HP-GL Plotters] An HP-GL Plotter produces output in the
100
+ # Hewlett--Packard Graphics Language (by default, in
101
+ # HP-GL/2), and directs it to a file or other
102
+ # specified output stream. The output may be imported
103
+ # into another application, or sent to a plotter.
104
+ #
105
+ # [Tektronix Plotters] A Tektronix Plotter produces output in
106
+ # Tektronix 4014 format and directs it to a file
107
+ # or other specified output stream. The output
108
+ # may be displayed on any Tektronix 4014
109
+ # emulator. Such an emulator is built into xterm,
110
+ # the X Window System terminal emulation program.
111
+ # The MS-DOS version of kermit also includes such
112
+ # an emulator.
113
+ #
114
+ # [Metafile Plotters] A Metafile Plotter produces output in GNU
115
+ # graphics metafile format and directs it to a
116
+ # file or other specified output stream. This
117
+ # format is an extended version of the
118
+ # <i>plot(5)</i> format found on some other
119
+ # operating systems.
120
+ #
121
+ # A distinction among these types of Plotter is that all except X and
122
+ # X Drawable Plotters write graphics to a file or other output
123
+ # stream. An X Plotter pops up its own windows, and an X Drawable
124
+ # Plotter draws graphics in one or two X drawables.
125
+ #
126
+ # Another distinction is that the first four types of Plotter (X, X
127
+ # Drawable, PNM, and GIF) produce bitmap output, while the remaining
128
+ # types produce output in a vector graphics format. In bitmap output
129
+ # the structure of the graphical objects is lost, but in a vector
130
+ # format it is retained.
131
+ #
132
+ # An additional distinction is that X, X Drawable, Tektronix and
133
+ # Metafile Plotters are real-time. This means that they draw graphics
134
+ # or write to an output stream as the drawing operations are invoked
135
+ # on them. The remaining types of Plotter are not real-time, since
136
+ # their output streams can only be emitted after all functions have
137
+ # been called. For PNM and GIF Plotters, this is because the bitmap
138
+ # must be constructed before it is written out. For Illustrator and
139
+ # Postscript Plotters, it is because a <i>bounding box</i> line must
140
+ # be placed at the head of the output file. For a Fig Plotter, it is
141
+ # because color definitions must be placed at the head of the output
142
+ # file.
143
+ #
144
+ # The most important operations supported by any Plotter are +open+
145
+ # and +close+, which open and close it. Graphics may be drawn, and
146
+ # drawing attributes set, only within an +open+...+close+ pair or as
147
+ # block passed to +draw+ method. The graphics produced within each
148
+ # +open+...+close+ pair constitute a _page_. In principle, any Plotter
149
+ # may be opened and closed arbitrarily many times. An X Plotter
150
+ # displays each page in a separate X window, and Postscript, PCL, and
151
+ # HP-GL Plotters render each page as a separate physical page. X
152
+ # Drawable Plotters and Tektronix Plotters manipulate a single
153
+ # drawable or display, on which pages are displayed in succession.
154
+ # Plotters that do not draw in real time (PNM, GIF, Illustrator,
155
+ # Postscript, Fig, PCL, and HP-GL Plotters) may wait until their
156
+ # existence comes to an end (i.e., until they are deleted) before
157
+ # outputting their pages of graphics.
158
+ #
159
+ # In the current release of libplot, Postscript Plotters delay
160
+ # outputting graphics in this way, but PCL and HP-GL Plotters output
161
+ # each page of graphics individually, i.e., when closepl is
162
+ # invoked. PNM, GIF, Illustrator and Fig Plotters are similar, but
163
+ # output only the first page. That is because PNM, GIF, Illustrator
164
+ # and Fig formats support only a single page of graphics.
165
+ #
166
+ # There are several other basic operations which any Plotter
167
+ # supports. The <i>graphics display</i> drawn in by a Plotter is a
168
+ # square or rectangular region on a display device. But when using any
169
+ # Plotter to draw graphics, a user will specify the coordinates of
170
+ # graphical objects in device-independent <i>user coordinates</i>,
171
+ # rather than in device coordinates. A Plotter relates the user
172
+ # coordinate system to the device coordinate system by performing an
173
+ # affine transformation, which must be specified by the user.
174
+ #
175
+ # Immediately after invoking +open+ to open a Plotter, an application
176
+ # should invoke the +space+ operation to initialize this
177
+ # transformation. This invocation specifies the rectangular region (in
178
+ # user coordinates) that will be mapped by the Plotter to the graphics
179
+ # display. The affine transformation may be updated at any later time
180
+ # by invoking +space+ again, or by invoking +concat+. The +concat+
181
+ # method will _concatenate_ (i.e., compose) the current affine
182
+ # transformation with any specified affine transformation. This sort
183
+ # of concatenation is a capability familiar from, e.g., Postscript.
184
+ #
185
+ # Each Plotter maintains a Postscript-style stack of graphics
186
+ # contexts. This makes possible the rapid, efficient drawing of
187
+ # complicated pages of graphics. A graphics context includes the
188
+ # current affine transformation from the user coordinate system to the
189
+ # device coordinate system. It also includes such modal drawing
190
+ # attributes as graphics cursor position, linemode, line thickness,
191
+ # pen and fill colors, and the font used for drawing text. The state
192
+ # of any uncompleted path (if any) is included as well, since paths
193
+ # may be drawn incrementally, one portion (line segment or arc) at a
194
+ # time. The current graphics context is pushed onto the stack by
195
+ # calling +savestate+, and popped off by calling +restorestate+.
196
+ #
197
+ # To permit vector graphics animation, any page of graphics may be
198
+ # split into _frames_. A frame is ended, and a new frame is begun, by
199
+ # invoking the +erase+ method. On a Plotter that does real-time
200
+ # plotting (i.e., an X, X Drawable, Tektronix, or Metafile Plotter),
201
+ # this erases all plotted objects from the graphics display, allowing
202
+ # a new frame to be drawn. Displaying a sequence of frames in
203
+ # succession creates the illusion of smooth animation.
204
+ #
205
+ # On most Plotters that do not do real-time plotting (i.e., PNM,
206
+ # Illustrator, Postscript, Fig, PCL, or HP-GL Plotters), invoking
207
+ # +erase+ deletes all plotted objects from an internal buffer. For
208
+ # this reason, most Plotters that do not do real-time plotting will
209
+ # display only the final frame of any multiframe page.
210
+ #
211
+ # GIF Plotters are in a class by themselves. Even though they do not
212
+ # do real time plotting, a GIF Plotter can produce multi-image output,
213
+ # i.e., an animated pseudo-GIF file, from a multiframe page. As noted
214
+ # above, the pseudo-GIF file produced by a GIF Plotter will contain
215
+ # only the first page of graphics. But if this page consists of
216
+ # multiple frames, then each invocation of erase, after the first,
217
+ # will be treated by default as a separator between successive images.
218
+ class Plotter < Rplot
219
+
220
+ # Creates a Plotter of type +type+, where +type+ may be _X_,
221
+ # _Xdrawable_, _pnm_, _gif_, _ai_, _ps_, _fig_, _pcl_, _hpgl_,
222
+ # _tek_, or _meta_. The Plotter will have input path +in_path+,
223
+ # output path +out_path+, and error path +err_path+. Any or all of
224
+ # these three may be +nil+. Currently, all Plotters are write-only,
225
+ # so +in_path+ is ignored. X Plotters and X Drawable Plotters write
226
+ # graphics to an X Window System display rather than to an output
227
+ # stream, so if +type+ is _X_ or _Xdrawable_ then +out_path+ is
228
+ # ignored as well. Error messages (if any) are written to the stream
229
+ # created with +err_path+, unless +err_path+ is +nil+.
230
+ #
231
+ # +OpenPlotterError+ exception will be raise if the Plotter could
232
+ # not be create.
233
+ def initialize(type, out_path, in_path = nil, err_path = nil)
234
+ super(type, in_path, out_path, err_path)
235
+ end
236
+
237
+ # Delete the Plotter.
238
+ #
239
+ # +DeletePlotterError+ exception will be raise if the Plotter could
240
+ # not be delete.
241
+ def delete
242
+ super
243
+ end
244
+
245
+ # Sets the value of the device driver parameters. The parameter
246
+ # values in effect at the time any Plotter is created are copied
247
+ # into it. Unrecognized parameters are ignored.
248
+ #
249
+ # The list of the recognized parameters:
250
+ #
251
+ # [DISPLAY] (Default +nil+.) The X Window System display on which
252
+ # the graphics display will be popped up, as an X
253
+ # window. This is relevant only to X Plotters.
254
+ #
255
+ # [BITMAPSIZE] (Default "570x570".) The size of the graphics display
256
+ # in terms of pixels. This is relevant only to X
257
+ # Plotters, PNM Plotters, and GIF Plotters. For X
258
+ # Plotters, the value of this parameter will
259
+ # automatically, if it is not set, be taken from the X
260
+ # resource Xplot.geometry. This is for backward
261
+ # compatibility.
262
+ #
263
+ # [PAGESIZE] (Default "letter".) The size of the page on which the
264
+ # graphics display will be positioned. This is relevant
265
+ # only to Illustrator, Postscript, Fig, PCL, and HP-GL
266
+ # Plotters. "letter" means an 8.5in by 11in page. Any ISO
267
+ # page size in the range "a0"..."a4" or ANSI page size in
268
+ # the range "a"..."e" may be specified ("letter" is an
269
+ # alias for "a" and "tabloid" is an alias for
270
+ # "b"). "legal", "ledger", and "b5" are recognized page
271
+ # sizes also. For Illustrator and Postscript Plotters,
272
+ # the graphics display will be a square region centered
273
+ # on the specified page and occupying its full width,
274
+ # with allowance being made for margins. For Fig
275
+ # Plotters, the graphics display will be a square region
276
+ # of the same size, positioned in the upper left corner
277
+ # of an xfig display. For PCL and HP-GL Plotters, the
278
+ # graphics display will be a square region of the same
279
+ # size, but may be positioned differently. For PCL
280
+ # Plotters, fine control over its positioning on the page
281
+ # may be accomplished by setting the PCL_XOFFSET and
282
+ # PCL_YOFFSET parameters. For HP-GL Plotters,
283
+ # +HPGL_XOFFSET+ and +HPGL_YOFFSET+ are used similarly.
284
+ #
285
+ # [BG_COLOR] (Default "white".) The initial background color of the
286
+ # graphics display, when drawing each page of
287
+ # graphics. This is relevant to X Plotters, PNM Plotters,
288
+ # GIF Plotters, and X Drawable Plotters (for the last,
289
+ # the background color shows up only if erase is
290
+ # invoked). The background color may be changed at any
291
+ # later time by invoking the bgcolor (or bgcolorname) and
292
+ # erase operations. An unrecognized color name sets the
293
+ # background color to the default.
294
+ #
295
+ # [GIF_ANIMATION] (Default "yes".) Relevant only to GIF
296
+ # Plotters. "yes" means that the erase operation
297
+ # will have special semantics: with the exception of
298
+ # its first invocation, it will act as a separator
299
+ # between successive images in the written-out
300
+ # pseudo-GIF file. "no" means that erase should act
301
+ # as it does on other Plotters that do not write
302
+ # graphics in real time, i.e., it should erase the
303
+ # image under construction by filling it with the
304
+ # background color. If "no" is specified, the
305
+ # pseudo-GIF file will contain only a single image.
306
+ #
307
+ # [GIF_DELAY] (Default "0".) Relevant only to GIF Plotters. The
308
+ # delay, in hundredths of a second, after each image in
309
+ # a written-out animated pseudo-GIF file. The value
310
+ # should be an integer in the range "0"..."65535".
311
+ #
312
+ # [GIF_ITERATIONS] (Default "0".) Relevant only to GIF Plotters. The
313
+ # number of times that an animated pseudo-GIF file
314
+ # should be _looped_. The value should be an
315
+ # integer in the range "0"..."65535".
316
+ #
317
+ # [HPGL_ASSIGN_COLORS] (Default "no".) Relevant only to HP-GL
318
+ # Plotters, and only if the value of
319
+ # +HPGL_VERSION+ is "2". "no" means to draw
320
+ # with a fixed set of pens, specified by
321
+ # setting the +HPGL_PENS+ parameter. "yes"
322
+ # means that pen colors will not restricted to
323
+ # the palette specified in +HPGL_PENS+: colors
324
+ # will be assigned to <i>logical pens</i> in
325
+ # the range #1...#31, as needed. Other than
326
+ # color LaserJet printers and DesignJet
327
+ # plotters, not many HP-GL/2 devices allow the
328
+ # assignment of colors to logical pens. So this
329
+ # parameter should be used with caution.
330
+ #
331
+ # [HPGL_OPAQUE_MODE] (Default "yes".) Relevant only to HP-GL
332
+ # Plotters, and only if the value of HPGL_VERSION
333
+ # is "2". "yes" means that the HP-GL/2 output
334
+ # device should be switched into opaque mode,
335
+ # rather than transparent mode. This allows
336
+ # objects to be filled with opaque white and
337
+ # other opaque colors. It also allows the drawing
338
+ # of visible white lines, which by convention are
339
+ # drawn with pen #0. Not all HP-GL/2 devices
340
+ # support opaque mode or the use of pen #0 to
341
+ # draw visible white lines. In particular,
342
+ # HP-GL/2 pen plotters do not. Some older HP-GL/2
343
+ # devices reportedly malfunction if asked to
344
+ # switch into opaque mode. If the output of an
345
+ # HP-GL Plotter is to be sent to such a device, a
346
+ # "no" value is recommended.
347
+ #
348
+ # [HPGL_PENS] (Default
349
+ # "+1=black:2=red:3=green:4=yellow:5=blue:6=magenta:7=cyan+"
350
+ # if the value of +HPGL_VERSION+ is "1.5" or "2" and
351
+ # "1=black" if the value of HPGL_VERSION is
352
+ # "1"). Relevant only to HP-GL Plotters. The set of
353
+ # available pens; the format should be
354
+ # self-explanatory. The color for any pen in the range
355
+ # #1...#31 may be specified. For information on what
356
+ # color names are recognized, see section Specifying
357
+ # Colors by Name. Pen #1 must always be present, though
358
+ # it need not be black. Any other pen in the range
359
+ # #1...#31 may be omitted.
360
+ #
361
+ # [HPGL_ROTATE] (Default "0".) Relevant only to HP-GL Plotters. The
362
+ # angle, in degrees, by which the graphics display
363
+ # should be rotated on the page relative to the
364
+ # default orientation. Recognized values are "0",
365
+ # "90", "180", and "270"; "no" and "yes" are
366
+ # equivalent to "0" and "90" respectively. This
367
+ # parameter is provided to facilitate switching
368
+ # between portrait and landscape orientations. For
369
+ # HP-GL devices this is frequently a concern, since
370
+ # some HP-GL devices (_plotters_) draw with a default
371
+ # landscape orientation, and others (_printers_) draw
372
+ # with a default portrait orientation. "180" and "270"
373
+ # are supported only if +HPGL_VERSION+ is "2".
374
+ #
375
+ # [HPGL_VERSION] (Default "2".) Relevant only to HP-GL Plotters. "1"
376
+ # means that the output should be generic HP-GL,
377
+ # "1.5" means that the output should be suitable for
378
+ # the HP7550A graphics plotter and the HP758x,
379
+ # HP7595A and HP7596A drafting plotters (HP-GL with
380
+ # some HP-GL/2 extensions), and "2" means that the
381
+ # output should be modern HP-GL/2. If the version is
382
+ # less than "2" then the only available fonts will be
383
+ # vector fonts, and all paths will be drawn with a
384
+ # default thickness, so that invoking capmod,
385
+ # joinmod, and fmiterlimit will have no effect. Also,
386
+ # the <i>nonzero winding number rule</i> will not be
387
+ # supported when filling paths, so invoking fillmod
388
+ # will have no effect. Additionally, if the version
389
+ # is "1" then the filling of arbitrary paths will not
390
+ # be supported (circles and rectangles aligned with
391
+ # the coordinate axes may be filled, however).
392
+ #
393
+ # [HPGL_XOFFSET, HPGL_YOFFSET] (Defaults "0.0cm" and "0.0cm".)
394
+ # Relevant only to HP-GL
395
+ # Plotters. Adjustments, in the x and y
396
+ # directions, of the position of the
397
+ # graphics display on the page. They
398
+ # may be specified in centimeters,
399
+ # millimeters, or inches. For example,
400
+ # an offset could be specified as "2cm"
401
+ # or "1.2in".
402
+ #
403
+ # [INTERLACE] (Default "no".) Relevant only to GIF Plotters. If the
404
+ # value is "yes", the pseudo-GIF output file will be
405
+ # interlaced. That means that it will be displayed in an
406
+ # interlaced (nonlinear) way by many applications.
407
+ #
408
+ # [MAX_LINE_LENGTH] (Default "500".) The maximum number of points
409
+ # that a path may contain, before it is flushed to
410
+ # the display device. If this flushing occurs,
411
+ # the path will be split into two or more
412
+ # sub-paths, though the splitting should not be
413
+ # noticeable. Splitting will not be performed if
414
+ # the path is filled. This parameter is relevant
415
+ # to all Plotters except Tektronix and Metafile
416
+ # Plotters. The reason for splitting long paths is
417
+ # that some display devices (e.g., old Postscript
418
+ # printers and HP-GL pen plotters) have limited
419
+ # buffer sizes. It is not relevant to Tektronix or
420
+ # Metafile Plotters, since they draw paths in real
421
+ # time and have no buffer limitations.
422
+ #
423
+ # [META_PORTABLE] (Default "no".) Relevant only to Metafile
424
+ # Plotters. "yes" means that the output should be in
425
+ # a portable (human-readable) version of the
426
+ # metafile format, rather than the default (binary)
427
+ # version. See section The Graphics Metafile Format.
428
+ #
429
+ # [PCL_ASSIGN_COLORS] (Default "no".) Relevant only to PCL
430
+ # Plotters. "no" means to draw with a fixed set
431
+ # of pens. "yes" means that pen colors will not
432
+ # restricted to this palette: colors will be
433
+ # assigned to <i>logical pens</i>, as
434
+ # needed. Other than color LaserJet printers,
435
+ # not many PCL 5 devices allow the assignment of
436
+ # colors to logical pens. So this parameter
437
+ # should be used with caution.
438
+ #
439
+ # [PCL_BEZIERS] (Default "yes".) Relevant only to PCL
440
+ # Plotters. "yes" means that when drawing Bezier
441
+ # curves, the special <i>Bezier instructions</i> will
442
+ # be used. "no" means that these instructions will not
443
+ # be used. Instead, each Bezier curve will be
444
+ # approximated and drawn as a polygonal line. Other
445
+ # than the LaserJet III, which was Hewlett--Packard's
446
+ # first PCL 5 printer, all Hewlett--Packard's PCL 5
447
+ # printers support the Bezier instructions.
448
+ #
449
+ # [PCL_ROTATE] (Default "0".) Relevant only to PCL Plotters. The
450
+ # angle, in degrees, by which the graphics display
451
+ # should be rotated on the page relative to the default
452
+ # orientation. Recognized values are "0", "90", "180",
453
+ # and "270"; "no" and "yes" are equivalent to "0" and
454
+ # "90" respectively. This parameter is provided to
455
+ # facilitate switching between portrait and landscape
456
+ # orientations. For PCL 5 devices this is frequently a
457
+ # concern, since some PCL 5 devices (_plotters_) draw
458
+ # with a default landscape orientation, and others
459
+ # (_printers_) draw with a default portrait
460
+ # orientation.
461
+ #
462
+ # [PCL_XOFFSET, PCL_YOFFSET] (Defaults "0.0cm" and "0.0cm".)
463
+ # Relevant only to PCL
464
+ # Plotters. Adjustments, in the x and y
465
+ # directions, of the position of the
466
+ # graphics display on the page. They may
467
+ # be specified in centimeters,
468
+ # millimeters, or inches. For example, an
469
+ # offset could be specified as "2cm" or
470
+ # "1.2in".
471
+ #
472
+ # [PNM_PORTABLE] (Default "no".) Relevant only to PNM
473
+ # Plotters. "yes" means that the output should be in
474
+ # a portable (human-readable) version of PBM/PGM/PPM
475
+ # format, rather than the default (binary)
476
+ # version. `Portable' is something of a misnomer,
477
+ # since binary PBM/PGM/PPM files are also portable,
478
+ # in the sense that they are machine-independent.
479
+ #
480
+ # [TERM] (Default +nil+.) Relevant only to Tektronix Plotters. If
481
+ # the value is _xterm_, _xterms_, or _kterm_, it is taken as
482
+ # a sign that the current application is running in an X
483
+ # Window System VT100 terminal emulator: an xterm. Before
484
+ # drawing graphics, a Tektronix Plotter will emit an escape
485
+ # sequence that causes the terminal emulator's auxiliary
486
+ # Tektronix window, which is normally hidden, to pop up.
487
+ # After the graphics are drawn, an escape sequence that
488
+ # returns control to the original VT100 window will be
489
+ # emitted. The Tektronix window will remain on the screen. If
490
+ # the value is _kermit_, _ansi.sys_, _ansissys_, _ansi.sysk_,
491
+ # or _ansisysk_, it is taken as a sign that the current
492
+ # application is running in the VT100 terminal emulator
493
+ # provided by the MS-DOS version of kermit. Before drawing
494
+ # graphics, a Tektronix Plotter will emit an escape sequence
495
+ # that switches the terminal emulator to Tektronix
496
+ # mode. Also, some of the Tektronix control codes emitted by
497
+ # the Plotter will be kermit-specific. There will be a
498
+ # limited amount of color support, which is not normally the
499
+ # case (the 16 ansi.sys colors will be supported). The
500
+ # _dotdotdashed_ line style will be supported, which is also
501
+ # not normally the case. After drawing graphics, the Plotter
502
+ # will emit an escape sequence that returns the emulator to
503
+ # VT100 mode. The key sequence <i>ALT minus</i> may be
504
+ # employed manually within kermit to switch between the two
505
+ # modes.
506
+ #
507
+ # [TRANSPARENT_COLOR] (Default "none".) Relevant only to GIF
508
+ # Plotters. If the value is a recognized color
509
+ # name, that color, if it appears in the
510
+ # pseudo-GIF output file, will be treated as
511
+ # transparent by most applications that display
512
+ # GIF files. For information on what names are
513
+ # recognized, see section Specifying Colors by
514
+ # Name. If +TRANSPARENT_COLOR+ is set and an
515
+ # animated pseudo-GIF file is produced, the
516
+ # <i>restore to background</i> disposal method
517
+ # will be used for each image in the
518
+ # file. Otherwise, the _unspecified_ disposal
519
+ # method will be used.
520
+ #
521
+ # [USE_DOUBLE_BUFFERING] (Default "no".) Relevant only to X Plotters
522
+ # and X Drawable Plotters. If the value is
523
+ # "yes", a double buffering scheme will be
524
+ # used when drawing graphics. Each frame of
525
+ # graphics, within a +open+...+close+ pair,
526
+ # will be written to an off-screen buffer
527
+ # rather than to the Plotter's display. When
528
+ # erase is invoked to end a frame, or when
529
+ # closepl is invoked, the contents of the
530
+ # off-screen buffer will be copied to the
531
+ # Plotter's display, pixel by pixel. If
532
+ # successive frames differ only slightly,
533
+ # this will create the illusion of smooth
534
+ # animation. Some X displays provide special
535
+ # hardware support for double buffering. If
536
+ # this support is available, the X Plotter
537
+ # will detect its presence, and will draw
538
+ # graphics using the appropriate extension to
539
+ # the X11 protocol (either DBE or MBX). In
540
+ # this case the animation will be
541
+ # significantly faster; on high-end graphics
542
+ # hardware, at least.
543
+ #
544
+ # [VANISH_ON_DELETE] (Default "no".) Relevant only to X Plotters. If
545
+ # the value is "yes", when a Plotter is deleted,
546
+ # the window or windows that it has popped up
547
+ # will vanish. Otherwise, each such window will
548
+ # remain on the screen until it is removed by the
549
+ # user (by typing "q" in it, or by clicking with
550
+ # a mouse).
551
+ #
552
+ # [XDRAWABLE_COLORMAP] (Default +nil+.) Relevant only to X Drawable
553
+ # Plotters. If the value is non-nil, it should
554
+ # be a Colormap *, a pointer to a colormap from
555
+ # which colors should be allocated. nil
556
+ # indicates that the colormap to be used should
557
+ # be the default colormap of the default screen
558
+ # of the X display.
559
+ #
560
+ # [XDRAWABLE_DISPLAY] (Default +nil+.) Relevant only to X Drawable
561
+ # Plotters. The value should be a Display *, a
562
+ # pointer to the X display with which the
563
+ # drawable(s) to be drawn in are associated.
564
+ #
565
+ # [XDRAWABLE_DRAWABLE1, XDRAWABLE_DRAWABLE2] (Default +nil+.)
566
+ # Relevant only to X
567
+ # Drawable Plotters. If
568
+ # set, the value of each
569
+ # of these parameters
570
+ # should be a Drawable *,
571
+ # a pointer to a drawable
572
+ # to be drawn in. A
573
+ # _drawable_ is either a
574
+ # window or a pixmap. At
575
+ # the time an X Drawable
576
+ # Plotter is created, at
577
+ # least one of the two
578
+ # parameters must be
579
+ # set. X Drawable
580
+ # Plotters support
581
+ # simultaneous drawing in
582
+ # two drawables because
583
+ # it is often useful to
584
+ # be able to draw
585
+ # graphics simultaneously
586
+ # in both an X window and
587
+ # its background
588
+ # pixmap. If two
589
+ # drawables are
590
+ # specified, they must
591
+ # have the same
592
+ # dimensions and depth,
593
+ # and be associated with
594
+ # the same screen of the
595
+ # X display.
596
+ def self.params(options = {})
597
+ options.each do |k,v|
598
+ Rplot.param(k.to_s.upcase, v.to_s)
599
+ end
600
+ end
601
+
602
+ # Create a new plotter that live inside the +block+ passed to
603
+ # +draw+. Operations in +block+ are wrapped between +open+, +erase+
604
+ # and +delete+ methods.
605
+ def self.draw(type, out_path, in_path = nil, err_path = nil)
606
+ plotter = Plotter.new(type, out_path, in_path, err_path)
607
+ plotter.open
608
+ plotter.erase
609
+ yield(plotter)
610
+ plotter.delete
611
+ end
612
+
613
+ # Wrap Plotter operations between +open+, +erase+ and +delete+
614
+ # methods.
615
+ def draw
616
+ self.open
617
+ self.erase
618
+ yield
619
+ self.delete
620
+ end
621
+
622
+
623
+ #-----------------#
624
+ # Setup functions #
625
+ #-----------------#
626
+
627
+
628
+ # Open a Plotter, i.e., begins a page of graphics. This resets the
629
+ # Plotter's drawing attributes to their default values. A negative
630
+ # return value indicates the Plotter could not be opened. Currently,
631
+ # an X Plotter pops up a new window on an X Window System display
632
+ # for each page of graphics, i.e., with each invocation of
633
+ # +open+. Future releases may support window re-use.
634
+ #
635
+ # +OpenPlotterError+ exception will be raise if the Plotter could
636
+ # not be open.
637
+ def open
638
+ super
639
+ end
640
+
641
+ # Sets the background color for the Plotter's graphics display,
642
+ # using a 48-bit RGB color model. The arguments red, green and blue
643
+ # specify the red, green and blue intensities of the background
644
+ # color. Each is an integer in the range 0x0000...0xffff, i.e.,
645
+ # 0...65535. The choice (0, 0, 0) signifies black, and the choice
646
+ # (65535, 65535, 65535) signifies white. bgcolor affects only
647
+ # Plotters that produce bitmaps, i.e., X Plotters, X Drawable
648
+ # Plotters, PNM Plotters, and GIF Plotters. Its effect is simple:
649
+ # the next time the erase operation is invoked on such a Plotter,
650
+ # its display will be filled with the specified color. If the first
651
+ # parameter is a string, it is considered as color name. +green+ and
652
+ # +blue+ parameters may be +nil+. If +:erase+ option is passed then
653
+ # call +erase+ too.
654
+ def bgcolor(red_or_name, green = nil, blue = nil, options = {})
655
+ if red_or_name.class == Fixnum && green.class == Fixnum && blue.class == Fixnum
656
+ super(red_or_name, green, blue)
657
+ else
658
+ self.bgcolorname(red_or_name.to_s)
659
+ end
660
+ erase if options[:erase]
661
+ end
662
+
663
+ # +erase+ begins the next frame of a multiframe page, by clearing
664
+ # all previously plotted objects from the graphics display, and
665
+ # filling it with the background color (if any). It is frequently
666
+ # useful to invoke erase at the beginning of each page, i.e.,
667
+ # immediately after invoking +open+. That is because some Plotters
668
+ # are persistent, in the sense that objects drawn within an
669
+ # +open+...+close+ pair remain on the graphics display even after a
670
+ # new page is begun by a subsequent invocation of +open+. Currently,
671
+ # only X Drawable Plotters and Tektronix Plotters are
672
+ # persistent. Future releases may support optional persistence for X
673
+ # Plotters also. On X Plotters and X Drawable Plotters the effects
674
+ # of invoking erase will be altogether different if the device
675
+ # driver parameter +USE_DOUBLE_BUFFERING+ is set to "yes". In this
676
+ # case, objects will be written to an off-screen buffer rather than
677
+ # to the graphics display, and invoking erase will (1) copy the
678
+ # contents of this buffer to the display, and (2) erase the buffer
679
+ # by filling it with the background color. This <i>double
680
+ # buffering</i> feature facilitates smooth animation.
681
+ def erase
682
+ super
683
+ end
684
+
685
+ # +space+ take two pairs of arguments, specifying the positions of
686
+ # the lower left corner and upper right corner of the graphics
687
+ # display, in user coordinates. In other words, calling +space+ sets
688
+ # the affine transformation from user coordinates to device
689
+ # coordinates. One of these operations must be performed at the
690
+ # beginning of each page of graphics, i.e., immediately after +open+
691
+ # is invoked. Default is 0,0,1,1.
692
+ def space(x0, y0, x1, y1)
693
+ fspace(x0.to_f, y0.to_f, x1.to_f, y1.to_f)
694
+ end
695
+
696
+ # +space2+ are extended versions of +space+, and may be used
697
+ # instead. Their arguments are the three defining vertices of an
698
+ # <i>affine window</i> (a drawing parallelogram), in user
699
+ # coordinates. The specified vertices are the lower left, the lower
700
+ # right, and the upper left. This window will be mapped affinely
701
+ # onto the graphics display.
702
+ def space2(x0, y0, x1, y1, x2, y2)
703
+ fspace2(x0.to_f, y0.to_f, x1.to_f, y1.to_f, x2.to_f, y2.to_f)
704
+ end
705
+
706
+ # +havecap+ tests whether or not a Plotter, which need not be open,
707
+ # has a specified capability. The return value is 0, 1, or 2,
708
+ # signifying no/yes/maybe. For unrecognized capabilities the return
709
+ # value is zero. Recognized capabilities include: [WIDE_LINES] The
710
+ # ability to draw lines with a non-default thickness [DASH_ARRAY]
711
+ # The ability to draw in arbitrary dashing styles, as requested by
712
+ # the linedash function) [SETTABLE_BACKGROUND] The ability to set
713
+ # the color of the background [SOLID_FILL] The "HERSHEY_FONTS",
714
+ # "PS_FONTS", "PCL_FONTS", and "STICK_FONTS" capabilities indicate
715
+ # whether or not fonts of a particular class are supported. All
716
+ # Plotters except Tektronix Plotters have the "SOLID_FILL"
717
+ # capability, meaning they can fill paths with solid color. Each
718
+ # such Plotter has at least one of the "EVEN_ODD_FILL" and
719
+ # "NONZERO_WINDING_NUMBER_FILL" capabilities. These indicate the
720
+ # supported rules for determining the _inside_ of a path. The
721
+ # _maybe_ value is returned for most capabilities by Metafile
722
+ # Plotters, which do no drawing themselves. The output of a Metafile
723
+ # Plotter must be translated to another format, or displayed, by
724
+ # invoking plot.
725
+ def havecap(s)
726
+ super(s.to_s)
727
+ end
728
+
729
+ # +flush+ flushes (i.e., pushes onward) all plotting commands to the
730
+ # display device. This is useful only if the currently selected
731
+ # Plotter does real-time plotting, since it may be used to ensure
732
+ # that all previously plotted objects have been sent to the display
733
+ # and are visible to the user. It has no effect on Plotters that do
734
+ # not do real-time plotting.
735
+ def flush
736
+ super
737
+ end
738
+
739
+ # +close+ closes a Plotter, i.e., ends a page of graphics.
740
+ #
741
+ # +ClosePlotterError+ exception will be raise if the Plotter could
742
+ # not be close.
743
+ def close
744
+ super
745
+ end
746
+
747
+
748
+ #--------------------------#
749
+ # Object-drawing functions #
750
+ #--------------------------#
751
+
752
+
753
+ # +alabel+ takes three arguments +horiz_justify+, +vert_justify+,
754
+ # and +s+, which specify an <i>adjusted label</i>, i.e., a justified
755
+ # text string. The path under construction (if any) is ended, and
756
+ # the string +s+ is drawn according to the specified
757
+ # justifications. If +horiz_justify+ is equal to +"l"+, +"c"+, or
758
+ # +"r"+, then the string will be drawn with left, center or right
759
+ # justification, relative to the current graphics cursor
760
+ # position. If +vert_justify+ is equal to +"b"+, +"x"+, +"c"+, or
761
+ # +"t"+, then the bottom, baseline, center or top of the string will
762
+ # be placed even with the current graphics cursor position. The
763
+ # graphics cursor is moved to the right end of the string if left
764
+ # justification is specified, and to the left end if right
765
+ # justification is specified. The string may contain escape
766
+ # sequences of various sorts, though it should not contain line
767
+ # feeds or carriage returns. In fact it should include only
768
+ # printable characters, from the byte ranges 0x20...0x7e and
769
+ # 0xa0...0xff. The string may be plotted at a nonzero angle, if
770
+ # textangle has been called.
771
+ def alabel(horiz_justify, vert_justify, s)
772
+ horiz_justify = horiz_justify.getbyte(0) if horiz_justify.class == String
773
+ vert_justify = vert_justify.getbyte(0) if vert_justify.class == String
774
+ super(horiz_justify, vert_justify, s.to_s)
775
+ end
776
+
777
+ # +arc+ take six arguments specifying the beginning (x0, y0), end
778
+ # (x1, y1), and center (xc, yc) of a circular arc. If the graphics
779
+ # cursor is at (x0, y0) and a path is under construction, then the
780
+ # arc is added to the path. Otherwise the current path (if any) is
781
+ # ended, and the arc begins a new path. In all cases the graphics
782
+ # cursor is moved to (x1, y1). The direction of the arc (clockwise
783
+ # or counterclockwise) is determined by the convention that the arc,
784
+ # centered at (xc, yc), sweep through an angle of at most 180
785
+ # degrees. If the three points appear to be collinear, the direction
786
+ # is taken to be counterclockwise. If (xc, yc) is not equidistant
787
+ # from (x0, y0) and (x1, y1) as it should be, it is corrected by
788
+ # being moved to the closest point on the perpendicular bisector of
789
+ # the line segment joining (x0, y0) and (x1, y1). If +:rel+ option
790
+ # is passed use cursor-relative coordinates.
791
+ def arc(xc, yc, x0, y0, x1, y1, options = {})
792
+ if options[:rel]
793
+ farcrel(xc, yc, x0, y0, x1, y1)
794
+ else
795
+ farc(xc, yc, x0, y0, x1, y1)
796
+ end
797
+ end
798
+
799
+ # +bezier2+ take six arguments specifying the beginning p0=(x0, y0)
800
+ # and end p2=(x2, y2) of a quadratic Bezier curve, and its
801
+ # intermediate control point p1=(x1, y1). If the graphics cursor is
802
+ # at p0 and a path is under construction, then the curve is added to
803
+ # the path. Otherwise the current path (if any) is ended, and the
804
+ # curve begins a new path. In all cases the graphics cursor is moved
805
+ # to p2. If +:rel+ option is passed use cursor-relative coordinates.
806
+ # The quadratic Bezier curve is tangent at p0 to the line segment
807
+ # joining p0 to p1, and is tangent at p2 to the line segment joining
808
+ # p1 to p2. So it fits snugly into a triangle with vertices p0, p1,
809
+ # and p2. When using a PCL Plotter to draw Bezier curves on a
810
+ # LaserJet III, you should set the parameter PCL_BEZIERS to
811
+ # "no". That is because the LaserJet III, which was
812
+ # Hewlett--Packard's first PCL 5 printer, does not recognize the
813
+ # Bezier instructions supported by later PCL 5 printers.
814
+ def bezier2(x0, y0, x1, y1, x2, y2, options = {})
815
+ if options[:rel]
816
+ fbezier2rel(x0, y0, x1, y1, x2, y2)
817
+ else
818
+ fbezier2(x0, y0, x1, y1, x2, y2)
819
+ end
820
+ end
821
+
822
+ # +bezier3+ take eight arguments specifying the beginning p0=(x0,
823
+ # y0) and end p3=(x3, y3) of a cubic Bezier curve, and its
824
+ # intermediate control points p1=(x1, y1) and p2=(x2, y2). If the
825
+ # graphics cursor is at p0 and a path is under construction, then
826
+ # the curve is added to the path. Otherwise the current path (if
827
+ # any) is ended, and the curve begins a new path. In all cases the
828
+ # graphics cursor is moved to p3. If +:rel+ option is passed use
829
+ # cursor-relative coordinates. The cubic Bezier curve is tangent at
830
+ # p0 to the line segment joining p0 to p1, and is tangent at p3 to
831
+ # the line segment joining p2 to p3. So it fits snugly into a
832
+ # quadrangle with vertices p0, p1, p2, and p3. When using a PCL
833
+ # Plotter to draw Bezier curves on a LaserJet III, you should set
834
+ # the parameter PCL_BEZIERS to "no". That is because the LaserJet
835
+ # III, which was Hewlett--Packard's first PCL 5 printer, does not
836
+ # recognize the Bezier instructions supported by later PCL 5
837
+ # printers.
838
+ def bezier3(x0, y0, x1, y1, x2, y2, x3, y3, options = {})
839
+ if options[:rel]
840
+ fbezier3rel(x0, y0, x1, y1, x2, y2, x3, y3)
841
+ else
842
+ fbezier3(x0, y0, x1, y1, x2, y2, x3, y3)
843
+ end
844
+ end
845
+
846
+ # +box+ take four arguments specifying the lower left corner (x1,
847
+ # y1) and upper right corner (x2, y2) of a _box_, or rectangle. The
848
+ # path under construction (if any) is ended, and the box is drawn as
849
+ # a new path. This path is also ended, and the graphics cursor is
850
+ # moved to the midpoint of the box. If +:rel+ option is passed use
851
+ # cursor-relative coordinates.
852
+ def box(x1, y1, x2, y2, options = {})
853
+ if options[:rel]
854
+ fboxrel(x1, y1, x2, y2)
855
+ else
856
+ fbox(x1, y1, x2, y2)
857
+ end
858
+ end
859
+
860
+ # +circle+ take three arguments specifying the center (xc, yc) and
861
+ # radius (r) of a circle. The path under construction (if any) is
862
+ # ended, and the circle is drawn. The graphics cursor is moved to
863
+ # (xc, yc). If +:rel+ option is passed use cursor-relative
864
+ # coordinates.
865
+ def circle(xc, yc, r, options = {})
866
+ if options[:rel]
867
+ fcirclerel(xc, yc, r)
868
+ else
869
+ fcircle(xc, yc, r)
870
+ end
871
+ end
872
+
873
+ # +cont+ take two arguments specifying the coordinates (x, y) of a
874
+ # point. If a path is under construction, the line segment from the
875
+ # current graphics cursor position to the point (x, y) is added to
876
+ # it. Otherwise the line segment begins a new path. In all cases the
877
+ # graphics cursor is moved to (x, y). If +:rel+ option is passed use
878
+ # cursor-relative coordinates.
879
+ def cont(x, y, options = {})
880
+ if options[:rel]
881
+ fcontrel(x, y)
882
+ else
883
+ fcont(x, y)
884
+ end
885
+ end
886
+
887
+ # +ellarc+ take six arguments specifying the three points
888
+ # pc=(xc,yc), p0=(x0,y0), and p1=(x1,y1) that define a so-called
889
+ # quarter ellipse. This is an elliptic arc from p0 to p1 with center
890
+ # pc. If the graphics cursor is at point p0 and a path is under
891
+ # construction, the quarter-ellipse is added to it. Otherwise the
892
+ # path under construction (if any) is ended, and the quarter-ellipse
893
+ # begins a new path. In all cases the graphics cursor is moved to
894
+ # p1. The quarter-ellipse is an affinely transformed version of a
895
+ # quarter circle. It is drawn so as to have control points p0, p1,
896
+ # and p0+p1-pc. This means that it is tangent at p0 to the line
897
+ # segment joining p0 to p0+p1-pc, and is tangent at p1 to the line
898
+ # segment joining p1 to p0+p1-pc. So it fits snugly into a triangle
899
+ # with these three control points as vertices. Notice that the third
900
+ # control point is the reflection of pc through the line joining p0
901
+ # and p1. If +:rel+ option is passed use cursor-relative
902
+ # coordinates.
903
+ def ellarc(xc, yc, x0, y0, x1, y1, options = {})
904
+ if options[:rel]
905
+ fellarcrel(xc, yc, x0, y0, x1, y1)
906
+ else
907
+ fellarc(xc, yc, x0, y0, x1, y1)
908
+ end
909
+ end
910
+
911
+ # +ellipse+ take five arguments specifying the center (xc, yc) of an
912
+ # ellipse, the lengths of its semiaxes (rx and ry), and the
913
+ # inclination of the first semiaxis in the counterclockwise
914
+ # direction from the x axis in the user coordinate system. The path
915
+ # under construction (if any) is ended, and the ellipse is
916
+ # drawn. The graphics cursor is moved to (xc, yc). If +:rel+ option
917
+ # is passed use cursor-relative coordinates.
918
+ def ellipse(xc, yc, rx, ry, angle, options = {})
919
+ if options[:rel]
920
+ fellipserel(xc, yc, rx, ry, angle)
921
+ else
922
+ fellipse(xc, yc, rx, ry, angle)
923
+ end
924
+ end
925
+
926
+ # +endpath+ terminates the path under construction, if any. A path
927
+ # is constructed by one or more successive calls to +cont+, +line+,
928
+ # +arc+, +ellarc+, +bezier2+ and +bezier3+. The path will also be
929
+ # terminated if any non-path object is drawn, if any path-related
930
+ # drawing attribute is set, or if +move+ is invoked to set the
931
+ # cursor position. So +endpath+ is almost redundant. However, if a
932
+ # Plotter plots objects in real time, calling +endpath+ will ensure
933
+ # that a constructed path is drawn on the graphics display without
934
+ # delay.
935
+ def endpath()
936
+ super
937
+ end
938
+
939
+ # +label+ takes a single string argument +s+ and draws the text
940
+ # contained in +s+ at the current graphics cursor position. The text
941
+ # is left justified, and the graphics cursor is moved to the right
942
+ # end of the string. This function is provided for backward
943
+ # compatibility; the function call <tt>label(s)</tt> is equivalent
944
+ # to <tt>alabel('l', 'x', s)</tt>.
945
+ def label(s)
946
+ super(s)
947
+ end
948
+
949
+ # +labelwidth+ compute and return the width of a string in the
950
+ # current font, in the user coordinate system. The string is not
951
+ # plotted.
952
+ def labelwidth(s)
953
+ flabelwidth(s)
954
+ end
955
+
956
+ # +line+ take four arguments specifying the start point (x1, y1) and
957
+ # end point (x2, y2) of a line segment. If the graphics cursor is at
958
+ # (x1, y1) and a path is under construction, the line segment is
959
+ # added to it. Otherwise the path under construction (if any) is
960
+ # ended, and the line segment begins a new path. In all cases the
961
+ # graphics cursor is moved to (x2, y2). If +:rel+ option is passed
962
+ # use cursor-relative coordinates.
963
+ def line(x1, y1, x2, y2, options = {})
964
+ if options[:rel]
965
+ flinerel(x1, y1, x2, y2)
966
+ else
967
+ fline(x1, y1, x2, y2)
968
+ end
969
+ end
970
+
971
+ # +marker+ take four arguments specifying the location (x,y) of a
972
+ # marker symbol, its type, and its size in user coordinates. The
973
+ # path under construction (if any) is ended, and the marker symbol
974
+ # is plotted. The graphics cursor is moved to (x,y). If +:rel+
975
+ # option is passed use cursor-relative coordinates for the position
976
+ # (x,y). Marker symbol types 0 through 31 are taken from a standard
977
+ # set, and marker symbol types 32 and above are interpreted as the
978
+ # index of a character in the current text font. These are the
979
+ # symbols:
980
+ # 1. dot
981
+ # 2. plus (+)
982
+ # 3. asterisk (*)
983
+ # 4. circle
984
+ # 5. cross
985
+ # 6. square
986
+ # 7. triangle
987
+ # 8. diamond
988
+ # 9. star
989
+ # 10. inverted triangle
990
+ # 11. starburst
991
+ # 12. fancy plus
992
+ # 13. fancy cross
993
+ # 14. fancy square
994
+ # 15. fancy diamond
995
+ # 16. filled circle
996
+ # 17. filled square
997
+ # 18. filled triangle
998
+ # 19. filled diamond
999
+ # 20. filled inverted triangle
1000
+ # 21. filled fancy square
1001
+ # 22. filled fancy diamond
1002
+ # 23. half filled circle
1003
+ # 24. half filled square
1004
+ # 25. half filled triangle
1005
+ # 26. half filled diamond
1006
+ # 27. half filled inverted triangle
1007
+ # 28. half filled fancy square
1008
+ # 29. half filled fancy diamond
1009
+ # 30. octagon
1010
+ # 31. filled octagon
1011
+ # The interpretation of marker symbols 1 through 5 is the same as in
1012
+ # the well known GKS (Graphical Kernel System). Symbols 32 and up
1013
+ # are interpreted as characters in a certain text font.
1014
+ def marker(x, y, type, size, options = {})
1015
+ if options[:rel]
1016
+ fmarkerrel(x, y, type, size)
1017
+ else
1018
+ fmarker(x, y, type, size)
1019
+ end
1020
+ end
1021
+
1022
+ # +point+ take two arguments specifying the coordinates (x, y) of a
1023
+ # point. The path under construction (if any) is ended, and the
1024
+ # point is plotted. (Plotters that produce bitmaps draw points as
1025
+ # single pixels. Other Plotters draw them as small solid circles,
1026
+ # usually the smallest that can be plotted.) The graphics cursor is
1027
+ # moved to (x, y). If +:rel+ option is passed use cursor-relative
1028
+ # coordinates.
1029
+ def point(x, y, options = {})
1030
+ if options[:rel]
1031
+ fpointrel(x, y)
1032
+ else
1033
+ fpoint(x, y)
1034
+ end
1035
+ end
1036
+
1037
+
1038
+ #-----------------------------#
1039
+ # Attribute-setting functions #
1040
+ #-----------------------------#
1041
+
1042
+
1043
+ # +capmod+ sets the cap mode (i.e., cap style) for all paths
1044
+ # subsequently drawn on the graphics display. Recognized styles are
1045
+ # _butt_ (the default), _round_, and _projecting_. The three styles
1046
+ # are visibly distinct only if the line thickness is fairly
1047
+ # large. Butt caps do not extend beyond the end of the path. The
1048
+ # other two kinds do, however. Round caps are filled semicircles,
1049
+ # and projecting caps are filled rectangular regions that extend a
1050
+ # distance equal to half the line width beyond the end of the
1051
+ # path. PCL and HP-GL Plotters support a fourth cap mode,
1052
+ # _triangular_. Plotters other than PCL and HP-GL Plotters treat
1053
+ # _triangular_ as equivalent to _round_. This function has no effect
1054
+ # on Tektronix Plotters. Also, it has no effect on HP-GL Plotters if
1055
+ # the parameter HPGL_VERSION is set to a value less than "2" (the
1056
+ # default).
1057
+ def capmod(s)
1058
+ super(s)
1059
+ end
1060
+
1061
+ # +color+ is a convenience function. Calling +color+ is equivalent
1062
+ # to calling both +pencolor+ and +fillcolor+, to set both the the
1063
+ # pen color and fill color of all objects subsequently drawn on the
1064
+ # graphics display. Note that the physical fill color depends also
1065
+ # on the fill fraction, which is specified by calling +filltype+. If
1066
+ # the first parameter is a string, it is considered as color
1067
+ # name. +green+ and +blue+ parameters may be +nil+.
1068
+ def color(red_or_name, green = nil, blue = nil)
1069
+ if red_or_name.class == Fixnum && green.class == Fixnum && blue.class == Fixnum
1070
+ super(red_or_name, green, blue)
1071
+ else
1072
+ colorname(red_or_name.to_s)
1073
+ end
1074
+ end
1075
+
1076
+ # +fillcolor+ sets the fill color of all objects subsequently drawn
1077
+ # on the graphics display, using a 48-bit RGB color model. The
1078
+ # arguments red, green and blue specify the red, green and blue
1079
+ # intensities of the fill color. Each is an integer in the range
1080
+ # 0x0000...0xffff, i.e., 0...65535. The choice (0, 0, 0) signifies
1081
+ # black, and the choice (65535, 65535, 65535) signifies white. Note
1082
+ # that the physical fill color depends also on the fill fraction,
1083
+ # which is specified by calling +filltype+. If the first parameter
1084
+ # is a string, it is considered as color name. +green+ and +blue+
1085
+ # parameters may be +nil+.
1086
+ def fillcolor(red_or_name, green = nil, blue = nil)
1087
+ if red_or_name.class == Fixnum && green.class == Fixnum && blue.class == Fixnum
1088
+ super(red_or_name, green, blue)
1089
+ else
1090
+ fillcolorname(red_or_name.to_s)
1091
+ end
1092
+ end
1093
+
1094
+ # +fillmod+ sets the fill mode, i.e., fill rule, for all objects
1095
+ # subsequently drawn on the graphics display. The fill rule affects
1096
+ # only filled, self-intersecting paths: it determines which points
1097
+ # are _inside_. Two rules are supported: _even-odd_ (the default for
1098
+ # all Plotters), and _nonzero-winding_. For the distinction, see the
1099
+ # Postscript Language Reference Manual. _alternate_ is an alias for
1100
+ # _even-odd_ and _winding_ is an alias for _nonzero-winding_. Fig
1101
+ # Plotters do not support the _nonzero-winding_ fill rule, because
1102
+ # xfig itself does not support it. Also, HPGL Plotters do not
1103
+ # support it if HPGL_VERSION is set to a value less than "2" (the
1104
+ # default). The LaserJet III, which was Hewlett--Packard's first PCL
1105
+ # 5 printer, did not support the _nonzero-winding_ fill
1106
+ # rule. However, all later PCL 5 printers from Hewlett--Packard
1107
+ # support it.
1108
+ def fillmod(s)
1109
+ super(s)
1110
+ end
1111
+
1112
+ # +filltype+ sets the fill fraction for all subsequently drawn
1113
+ # objects. A value of 0 for level indicates that objects should be
1114
+ # unfilled, or transparent. This is the default. A value in the
1115
+ # range 0x0001...0xffff, i.e., 1...65535, indicates that objects
1116
+ # should be filled. A value of 1 signifies 100% filling (the fill
1117
+ # color will simply be the color specified by calling fillcolor or
1118
+ # fillcolorname). If <tt>level=0xffff</tt>, the fill color will be
1119
+ # white. Values between 0x0001 and 0xffff are interpreted as
1120
+ # specifying a desaturation, or gray level. For example, 0x8000
1121
+ # specifies 50% filling (the fill color will be intermediate between
1122
+ # the color specified by calling fillcolor or fillcolorname, and
1123
+ # white). Tektronix Plotters do not support filling, and HP-GL
1124
+ # Plotters support filling of arbitrary paths only if the parameter
1125
+ # HPGL_VERSION is equal to "1.5" or "2" (the default). (If the
1126
+ # version is "1" then only circles and rectangles aligned with the
1127
+ # coordinate axes may be filled.) Opaque filling, including white
1128
+ # filling, is supported only if the parameter HPGL_VERSION is "2"
1129
+ # and the parameter HPGL_OPAQUE_MODE is "yes" (the default).
1130
+ def filltype(level)
1131
+ super(level)
1132
+ end
1133
+
1134
+ # +fmiterlimit+ sets the miter limit for all paths subsequently
1135
+ # drawn on the graphics display. The miter limit controls the
1136
+ # treatment of corners, if the join mode is set to _miter_ (the
1137
+ # default). At a join point of a path, the <i>miter length</i> is
1138
+ # defined to be the distance between the inner corner and the outer
1139
+ # corner. The miter limit is the maximum value that will be
1140
+ # tolerated for the miter length divided by the line thickness. If
1141
+ # this value is exceeded, the miter will be cut off: the _bevel_
1142
+ # join mode will be used instead. Examples of typical values for
1143
+ # limit are 10.43 (the default, which cuts off miters if the join
1144
+ # angle is less than 11 degrees), 2.0 (the same, for 60 degrees),
1145
+ # and 1.414 (the same, for 90 degrees). In general, the miter limit
1146
+ # is the cosecant of one-half the minimum angle for mitered
1147
+ # joins. The minimum meaningful value for limit is 1.0, which
1148
+ # converts all mitered joins to beveled joins, irrespective of join
1149
+ # angle. Specifying a value less than 1.0 resets the limit to the
1150
+ # default. This function has no effect on X Drawable Plotters or X
1151
+ # Plotters, since the X Window System miter limit, which is also
1152
+ # 10.43, cannot be altered. It also has no effect on Tektronix
1153
+ # Plotters or Fig Plotters, or on HP-GL Plotters if the parameter
1154
+ # HPGL_VERSION is set to a value less than "2" (the default).
1155
+ def fmiterlimit(limit)
1156
+ super(limit)
1157
+ end
1158
+
1159
+ # +fontname+ take a single case-insensitive string argument,
1160
+ # <tt>font_name</tt>, specifying the name of the font to be used for
1161
+ # all text strings subsequently drawn on the graphics display. (The
1162
+ # font for plotting strings is fully specified by calling
1163
+ # +fontname+, +fontsize+, and +textangle+.) The size of the font in
1164
+ # user coordinates is returned. The default font name depends on the
1165
+ # type of Plotter. It is "Helvetica" for all Plotters except PNM,
1166
+ # GIF, HP-GL, Tektronix and Metafile Plotters, for which it is
1167
+ # "HersheySerif". If the argument <tt>font_name</tt> is +nil+ or the
1168
+ # empty string, or the font is not available, the default font name
1169
+ # will be used. Which fonts are available also depends on the type
1170
+ # of Plotter.
1171
+ def fontname(font_name)
1172
+ ffontname(font_name)
1173
+ end
1174
+
1175
+ # +fontsize+ take a single argument, interpreted as the size, in the
1176
+ # user coordinate system, of the font to be used for all text
1177
+ # strings subsequently drawn on the graphics display. (The font for
1178
+ # plotting strings is fully specified by calling fontname, fontsize,
1179
+ # and textangle.) The size of the font in user coordinates is
1180
+ # returned. A negative value for size sets the size to the default,
1181
+ # which depends on the type of Plotter. Typically, the default font
1182
+ # size is 1/50 times the size (i.e., minimum dimension) of the
1183
+ # display.
1184
+ def fontsize(size)
1185
+ ffontsize(size)
1186
+ end
1187
+
1188
+ # +joinmod+ sets the join mode (i.e., join style) for all paths
1189
+ # subsequently drawn on the graphics display. Recognized styles are
1190
+ # _miter_ (the default), _round_, and _bevel_. The three styles are
1191
+ # visibly distinct only if the line thickness is fairly
1192
+ # large. Mitered joins are sharp, rounded joins are round, and
1193
+ # beveled joins are squared off. However, unusually sharp joins are
1194
+ # never mitered: instead, they are beveled. The angle at which
1195
+ # beveling replaces mitering may be specified by calling
1196
+ # fmiterlimit. PCL and HP-GL Plotters support a fourth join mode,
1197
+ # _triangular_. Plotters other than PCL and HP-GL Plotters treat
1198
+ # _triangular_ as equivalent to _round_. This function has no effect
1199
+ # on Tektronix Plotters. Also, it has no effect on HP-GL Plotters if
1200
+ # the parameter HPGL_VERSION is set to a value less than "2" (the
1201
+ # default).
1202
+ def joinmod(s)
1203
+ super(s)
1204
+ end
1205
+
1206
+ # +linedash+ set the line style for all paths, circles, and ellipses
1207
+ # subsequently drawn on the graphics display. They provide much
1208
+ # finer control of dash patterns than the +linemod+ function (see
1209
+ # below) provides. Dashes should be an array of length +n+. Its
1210
+ # elements, which should be positive, are interpreted as distances
1211
+ # in the user coordinate system. Along any path, circle, or ellipse,
1212
+ # the elements dashes[0]...dashes[n-1] alternately specify the
1213
+ # length of a dash and the length of a gap between dashes. When the
1214
+ # end of the array is reached, the reading of the array wraps around
1215
+ # to the beginning. If the array is empty, i.e., n equals zero,
1216
+ # there is no dashing: the drawn line is solid. The offset argument
1217
+ # specifies the _phase_ of the dash pattern relative to the start of
1218
+ # the path. It is interpreted as the distance into the dash pattern
1219
+ # at which the dashing should begin. For example, if offset equals
1220
+ # zero then the path will begin with a dash, of length dashes[0] in
1221
+ # user space. If offset equals dashes[0] then the path will begin
1222
+ # with a gap of length dashes[1], and so forth. offset is allowed to
1223
+ # be negative. Not all Plotters fully support linedash and
1224
+ # flinedash. HP-GL and PCL Plotters cannot dash with a nonzero
1225
+ # offset, and in the dash patterns used by X and X Drawable
1226
+ # Plotters, each dash and each gap has a maximum length of 255
1227
+ # pixels. linedash and flinedash have no effect on Tektronix and Fig
1228
+ # Plotters, and they have no effect on HP-GL Plotters for which the
1229
+ # parameter HPGL_VERSION is less than "2" (the default; see section
1230
+ # Device driver parameters). Warning: If the map from the user
1231
+ # coordinate system to the device coordinate system is not uniform,
1232
+ # each dash in a dashed path should ideally be drawn on the graphics
1233
+ # display with a length that depends on its direction. But
1234
+ # currently, only Postscript Plotters do this. Other Plotters always
1235
+ # draw any specified dash with the same length, irrespective of its
1236
+ # direction. The length that is used is the minimum length, in the
1237
+ # device coordinate system, that can correspond to the specified
1238
+ # dash length in the user coordinate system.
1239
+ def linedash(dashes, offset)
1240
+ flinedash(dashes.size, dashes, offset)
1241
+ end
1242
+
1243
+ # +linemod+ sets the line style for all paths, circles, and ellipses
1244
+ # subsequently drawn on the graphics display. The supported line
1245
+ # styles are _solid_, _dotted_, _dotdashed_, _shortdashed_,
1246
+ # _longdashed_, _dotdotdashed_, _dotdotdotdashed_, and
1247
+ # _disconnected_. The first seven correspond to the following dash
1248
+ # patterns:
1249
+ #
1250
+ # "solid" --------------------------------
1251
+ # "dotted" - - - - - - - -
1252
+ # "dotdashed" ---- - ---- - ---- -
1253
+ # "shortdashed" ---- ---- ---- ----
1254
+ # "longdashed" ------- ------- -------
1255
+ # "dotdotdashed" ---- - - ---- - -
1256
+ # "dotdotdotdashed" ---- - - - ---- - - -
1257
+ #
1258
+ # In the preceding patterns, each hyphen stands for one line
1259
+ # thickness. This is the case for sufficiently thick lines, at
1260
+ # least. So for sufficiently thick lines, the distance over which a
1261
+ # dash pattern repeats is scaled proportionately to the line
1262
+ # thickness. The _disconnected_ line style is special. A
1263
+ # _disconnected_ path is rendered as a set of filled circles, each
1264
+ # of which has diameter equal to the nominal line thickness. One of
1265
+ # these circles is centered on each of the juncture points of the
1266
+ # path (i.e., the endpoints of the line segments or arcs from which
1267
+ # it is constructed). Circles and ellipses with _disconnected_ line
1268
+ # style are invisible. Disconnected paths, circles, and ellipses are
1269
+ # not filled. All line styles are supported by all Plotters, with
1270
+ # the following exceptions. HP-GL Plotters do not support the
1271
+ # _dotdotdotdashed_ style unless the parameter HPGL_VERSION is set
1272
+ # to "2" (the default). Tektronix Plotters do not support the
1273
+ # _dotdotdotdashed_ style, and do not support the _dotdotdashed_
1274
+ # style unless the parameter TERM is set to _kermit_.
1275
+ def linemod(s)
1276
+ super(s)
1277
+ end
1278
+
1279
+ # +linewidth+ set the thickness, in the user coordinate system, of
1280
+ # all paths, circles, and ellipses subsequently drawn on the
1281
+ # graphics display. A negative value resets the thickness to the
1282
+ # default. The default thickness depends on the type of Plotter. For
1283
+ # most Plotters, it is 1/850 times the size (i.e., minimum
1284
+ # dimension) of the display. But for Plotters that produce bitmaps,
1285
+ # i.e., X Plotters, X Drawable Plotters, PNM Plotters, and GIF
1286
+ # Plotters, it is zero. By convention, a zero-thickness line is the
1287
+ # thinnest line that can be drawn. However, the drawing editors
1288
+ # idraw and xfig treat zero-thickness lines as invisible. So when
1289
+ # producing editable graphics with a Postscript or Fig Plotter,
1290
+ # using a zero line thickness may not be desirable. Tektronix
1291
+ # Plotters do not support drawing with other than a default
1292
+ # thickness, and HP-GL Plotters do not support doing so if the
1293
+ # parameter HPGL_VERSION is set to a value less than "2" (the
1294
+ # default; see section Device driver parameters). *Warning*: If the
1295
+ # map from the user coordinate system to the device coordinate
1296
+ # system is not uniform, each line segment in a polygonal path
1297
+ # should ideally be drawn on the graphics display with a thickness
1298
+ # that depends on its direction. But currently, only Postscript
1299
+ # Plotters do this. Other Plotters draw all line segments in a path
1300
+ # with the same thickness. The thickness that is used is the minimum
1301
+ # thickness, in the device coordinate system, that can correspond to
1302
+ # the thickness of the path in the user coordinate system.
1303
+ def linewidth(size)
1304
+ flinewidth(size)
1305
+ end
1306
+
1307
+ # +move+ take two arguments specifying the coordinates (x, y) of a
1308
+ # point to which the graphics cursor should be moved. The path under
1309
+ # construction (if any) is ended, and the graphics cursor is moved
1310
+ # to (x, y). This is equivalent to lifting the pen on a plotter and
1311
+ # moving it to a new position, without drawing any line. If +:rel+
1312
+ # option is passed use cursor-relative coordinates.
1313
+ def move(x, y, options = {})
1314
+ if options[:rel]
1315
+ fmoverel(x, y)
1316
+ else
1317
+ fmove(x, y)
1318
+ end
1319
+ end
1320
+
1321
+ # +pencolor+ sets the pen color of all objects subsequently drawn on
1322
+ # the graphics display, using a 48-bit RGB color model. The
1323
+ # arguments red, green and blue specify the red, green and blue
1324
+ # intensities of the pen color. Each is an integer in the range
1325
+ # 0x0000...0xffff, i.e., 0...65535. The choice (0, 0, 0) signifies
1326
+ # black, and the choice (65535, 65535, 65535) signifies white. HP-GL
1327
+ # Plotters support drawing with a white pen only if the value of the
1328
+ # parameter HPGL_VERSION is "2" (the default), and the value of the
1329
+ # parameter HPGL_OPAQUE_MODE is "yes" (the default). If the first
1330
+ # parameter is a string, it is considered as color name. +green+ and
1331
+ # +blue+ parameters may be +nil+.
1332
+ def pencolor(red_or_name, green = nil, blue = nil)
1333
+ if red_or_name.class == Fixnum && green.class == Fixnum && blue.class == Fixnum
1334
+ super(red_or_name, green, blue)
1335
+ else
1336
+ pencolorname(red_or_name.to_s)
1337
+ end
1338
+ end
1339
+
1340
+ # +restorestate+ pops the current graphics context off the stack of
1341
+ # drawing states. The graphics context consists largely of libplot's
1342
+ # drawing attributes, which are set by the attribute functions
1343
+ # documented in this doc. So popping off the graphics context
1344
+ # restores the drawing attributes to values they previously had. A
1345
+ # path under construction is regarded as part of the graphics
1346
+ # context. For this reason, calling +restorestate+ automatically
1347
+ # calls +endpath+ to terminate the path under construction, if
1348
+ # any. All graphics contexts on the stack are popped off when
1349
+ # +close+ is called, as if +restorestate+ had been called
1350
+ # repeatedly.
1351
+ def restorestate()
1352
+ super
1353
+ end
1354
+
1355
+ # +savestate+ pushes the current graphics context onto the stack of
1356
+ # drawing states. The graphics context consists largely of libplot's
1357
+ # drawing attributes, which are set by the attribute functions
1358
+ # documented in this doc. A path under construction, if any, is
1359
+ # regarded as part of the graphics context. That is because paths
1360
+ # may be drawn incrementally, one line segment or arc at a
1361
+ # time. When a graphics context is returned to, the path under
1362
+ # construction may be continued.
1363
+ def savestate()
1364
+ super
1365
+ end
1366
+
1367
+ # +textangle+ take one argument, which specifies the +angle+ in
1368
+ # degrees counterclockwise from the x (horizontal) axis in the user
1369
+ # coordinate system, for text strings subsequently drawn on the
1370
+ # graphics display. The default angle is zero. (The font for
1371
+ # plotting strings is fully specified by calling +fontname+,
1372
+ # +fontsize+, and +textangle+.) The size of the font for plotting
1373
+ # strings, in user coordinates, is returned.
1374
+ def textangle(angle)
1375
+ ftextangle(angle)
1376
+ end
1377
+
1378
+
1379
+ #-------------------#
1380
+ # Mapping functions #
1381
+ #-------------------#
1382
+
1383
+
1384
+ # Apply a Postscript-style transformation matrix, i.e., affine map,
1385
+ # to the user coordinate system. That is, apply the linear
1386
+ # transformation defined by the two-by-two matrix <tt>[m0 m1 m2
1387
+ # m3]</tt> to the user coordinate system, and also translate by +tx+
1388
+ # units in the x direction and +ty+ units in the y direction,
1389
+ # relative to the former user coordinate system. The following three
1390
+ # functions (+rotate+, +scale+, +translate+) are convenience
1391
+ # functions that are special cases of +concat+.
1392
+ def concat(m0, m1, m2, m3, tx, ty)
1393
+ fconcat(m0, m1, m2, m3, tx, ty)
1394
+ end
1395
+
1396
+ # Rotate the user coordinate system axes about their origin by
1397
+ # +theta+ degrees, with respect to their former orientation. The
1398
+ # position of the user coordinate origin and the size of the x and y
1399
+ # units remain unchanged.
1400
+ def rotate(theta)
1401
+ frotate(theta)
1402
+ end
1403
+
1404
+ # Make the x and y units in the user coordinate system be the size
1405
+ # of +sx+ and +sy+ units in the former user coordinate system. The
1406
+ # position of the user coordinate origin and the orientation of the
1407
+ # coordinate axes are unchanged.
1408
+ def scale(sx, sy)
1409
+ fscale(sx, sy)
1410
+ end
1411
+
1412
+ # Move the origin of the user coordinate system by +tx+ units in the
1413
+ # x direction and +ty+ units in the y direction, relative to the
1414
+ # former user coordinate system. The size of the x and y units and
1415
+ # the orientation of the coordinate axes are unchanged.
1416
+ def translate(tx, ty)
1417
+ ftranslate(tx, ty)
1418
+ end
1419
+
1420
+ end
1421
+