rmagick 1.7.4 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rmagick might be problematic. Click here for more details.

Files changed (130) hide show
  1. data/ChangeLog +10 -2
  2. data/README.html +284 -290
  3. data/README.txt +298 -307
  4. data/configure +180 -11
  5. data/configure.ac +18 -2
  6. data/doc/comtasks.html +1 -1
  7. data/doc/constants.html +15 -10
  8. data/doc/css/ref.css +67 -0
  9. data/doc/draw.html +1 -1
  10. data/doc/ex/InitialCoords.rb +24 -0
  11. data/doc/ex/NewCoordSys.rb +33 -0
  12. data/doc/ex/OrigCoordSys.rb +19 -0
  13. data/doc/ex/PreserveAspectRatio.rb +206 -0
  14. data/doc/ex/RotateScale.rb +38 -0
  15. data/doc/ex/Skew.rb +39 -0
  16. data/doc/ex/Use01.rb +17 -0
  17. data/doc/ex/Use02.rb +22 -0
  18. data/doc/ex/Use03.rb +17 -0
  19. data/doc/ex/ViewBox.rb +34 -0
  20. data/doc/ex/arcs01.rb +29 -0
  21. data/doc/ex/arcs02.rb +62 -0
  22. data/doc/ex/baseline_shift01.rb +19 -0
  23. data/doc/ex/bounding_box.rb +31 -37
  24. data/doc/ex/circle01.rb +18 -0
  25. data/doc/ex/cubic01.rb +46 -0
  26. data/doc/ex/cubic02.rb +95 -0
  27. data/doc/ex/drop_shadow.rb +1 -1
  28. data/doc/ex/ellipse01.rb +23 -0
  29. data/doc/ex/evenodd.rb +44 -0
  30. data/doc/ex/font_styles.rb +29 -0
  31. data/doc/ex/group.rb +27 -0
  32. data/doc/ex/image.rb +47 -0
  33. data/doc/ex/images/big-duck.gif +0 -0
  34. data/doc/ex/images/duck.gif +0 -0
  35. data/doc/ex/images/duck0.gif +0 -0
  36. data/doc/ex/images/duck1.gif +0 -0
  37. data/doc/ex/images/duck10.gif +0 -0
  38. data/doc/ex/images/duck11.gif +0 -0
  39. data/doc/ex/images/duck12.gif +0 -0
  40. data/doc/ex/images/duck13.gif +0 -0
  41. data/doc/ex/images/duck14.gif +0 -0
  42. data/doc/ex/images/duck15.gif +0 -0
  43. data/doc/ex/images/duck2.gif +0 -0
  44. data/doc/ex/images/duck3.gif +0 -0
  45. data/doc/ex/images/duck4.gif +0 -0
  46. data/doc/ex/images/duck5.gif +0 -0
  47. data/doc/ex/images/duck6.gif +0 -0
  48. data/doc/ex/images/duck7.gif +0 -0
  49. data/doc/ex/images/duck8.gif +0 -0
  50. data/doc/ex/images/duck9.gif +0 -0
  51. data/doc/ex/line01.rb +24 -0
  52. data/doc/ex/nested_rvg.rb +22 -0
  53. data/doc/ex/nonzero.rb +44 -0
  54. data/doc/ex/polygon01.rb +24 -0
  55. data/doc/ex/polyline01.rb +24 -0
  56. data/doc/ex/quad01.rb +37 -0
  57. data/doc/ex/rect01.rb +16 -0
  58. data/doc/ex/rect02.rb +23 -0
  59. data/doc/ex/rvg_clippath.rb +15 -0
  60. data/doc/ex/rvg_linecap.rb +44 -0
  61. data/doc/ex/rvg_linejoin.rb +42 -0
  62. data/doc/ex/rvg_opacity.rb +20 -0
  63. data/doc/ex/rvg_pattern.rb +27 -0
  64. data/doc/ex/rvg_stroke_dasharray.rb +13 -0
  65. data/doc/ex/sepiatone.rb +15 -0
  66. data/doc/ex/shadow.rb +37 -0
  67. data/doc/ex/smile.rb +9 -9
  68. data/doc/ex/stroke_fill.rb +12 -0
  69. data/doc/ex/text01.rb +18 -0
  70. data/doc/ex/text_styles.rb +22 -0
  71. data/doc/ex/texture_fill_to_border.rb +3 -3
  72. data/doc/ex/texture_floodfill.rb +3 -2
  73. data/doc/ex/tref01.rb +26 -0
  74. data/doc/ex/triangle01.rb +17 -0
  75. data/doc/ex/tspan01.rb +19 -0
  76. data/doc/ex/tspan02.rb +20 -0
  77. data/doc/ex/tspan03.rb +22 -0
  78. data/doc/ex/writing_mode01.rb +28 -0
  79. data/doc/ex/writing_mode02.rb +27 -0
  80. data/doc/ilist.html +1 -1
  81. data/doc/image1.html +66 -30
  82. data/doc/image2.html +1 -1
  83. data/doc/image3.html +274 -49
  84. data/doc/imageattrs.html +87 -10
  85. data/doc/imusage.html +1 -1
  86. data/doc/index.html +80 -39
  87. data/doc/info.html +149 -13
  88. data/doc/magick.html +1 -1
  89. data/doc/rvg.html +890 -0
  90. data/doc/rvgclip.html +249 -0
  91. data/doc/rvggroup.html +305 -0
  92. data/doc/rvgimage.html +288 -0
  93. data/doc/rvgpattern.html +456 -0
  94. data/doc/rvgshape.html +376 -0
  95. data/doc/rvgstyle.html +269 -0
  96. data/doc/rvgtext.html +464 -0
  97. data/doc/rvgtspan.html +237 -0
  98. data/doc/rvgtut.html +512 -0
  99. data/doc/rvguse.html +145 -0
  100. data/doc/rvgxform.html +294 -0
  101. data/doc/struct.html +9 -71
  102. data/doc/usage.html +22 -7
  103. data/ext/RMagick/MANIFEST +94 -2
  104. data/ext/RMagick/rmagick.h +10 -4
  105. data/ext/RMagick/rmagick_config.h.in +8 -2
  106. data/ext/RMagick/rmdraw.c +2 -2
  107. data/ext/RMagick/rmfill.c +2 -2
  108. data/ext/RMagick/rmilist.c +3 -3
  109. data/ext/RMagick/rmimage.c +152 -5
  110. data/ext/RMagick/rminfo.c +208 -2
  111. data/ext/RMagick/rmmain.c +14 -5
  112. data/ext/RMagick/rmutil.c +83 -22
  113. data/lib/RMagick.rb +2 -2
  114. data/lib/rvg/clippath.rb +46 -0
  115. data/lib/rvg/container.rb +129 -0
  116. data/lib/rvg/deep_equal.rb +54 -0
  117. data/lib/rvg/describable.rb +51 -0
  118. data/lib/rvg/embellishable.rb +395 -0
  119. data/lib/rvg/misc.rb +729 -0
  120. data/lib/rvg/paint.rb +48 -0
  121. data/lib/rvg/pathdata.rb +129 -0
  122. data/lib/rvg/rvg.rb +279 -0
  123. data/lib/rvg/stretchable.rb +150 -0
  124. data/lib/rvg/stylable.rb +116 -0
  125. data/lib/rvg/text.rb +185 -0
  126. data/lib/rvg/transformable.rb +131 -0
  127. data/lib/rvg/units.rb +64 -0
  128. data/rmagick.gemspec +1 -1
  129. data/uninstall.rb +3 -2
  130. metadata +96 -3
@@ -0,0 +1,237 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml">
5
+ <head>
6
+ <meta name="generator" content=
7
+ "HTML Tidy for Linux/x86 (vers 1st March 2005), see www.w3.org" />
8
+
9
+ <title>RMagick: RVG Reference: RVG::Tspan Class</title>
10
+ <meta http-equiv="Content-Type" content=
11
+ "text/html; charset=us-ascii" />
12
+ <meta name="GENERATOR" content="Quanta Plus" />
13
+ <meta name="Copyright" content=
14
+ "Copyright (C) 2005 by Timothy P. Hunter" />
15
+ <link rel="stylesheet" type="text/css" href="css/doc.css" />
16
+ <script type="text/javascript" src="scripts/doc.js">
17
+ </script>
18
+ <script type="text/javascript">
19
+ //<![CDATA[
20
+ //]]>
21
+ </script>
22
+ <style type="text/css">
23
+ /*<![CDATA[*/
24
+ }
25
+ /*]]>*/
26
+ </style>
27
+ </head>
28
+
29
+ <body>
30
+ <h6 id="header">RMagick User's Guide and Reference</h6>
31
+
32
+ <div class="nav">
33
+ &laquo;&nbsp;<a href="rvgtext.html">Prev</a> | <a href=
34
+ "index.html">Contents</a> | <a href=
35
+ "rvguse.html">Next</a>&nbsp;&raquo;
36
+ </div>
37
+
38
+ <h1>class RVG::Tspan <span class="superclass">&lt;
39
+ TextBase</span></h1>
40
+
41
+ <div id="toc">
42
+ <h2>Table of Contents</h2>
43
+
44
+ <h3>class methods</h3>
45
+
46
+ <ul>
47
+ <li><a href="#new">new</a></li>
48
+ </ul>
49
+
50
+ <h3>instance methods</h3>
51
+
52
+ <div>
53
+ <div class="toccol">
54
+ <ul>
55
+ <li><a href="#d">d</a></li>
56
+
57
+ <li><a href="#rotate">rotate</a></li>
58
+
59
+ <li><a href="#tspan">tspan</a></li>
60
+ </ul>
61
+ </div>
62
+
63
+ <h3>shared methods</h3>
64
+
65
+ <p>In addition to the methods listed above, <code>class
66
+ RVG::Tspan</code> also implements the <a href=
67
+ "rvgstyle.html">styles</a> method.</p>
68
+ </div>
69
+ </div>
70
+
71
+ <h2 class="methods">class methods</h2>
72
+
73
+ <div class="sig">
74
+ <h3 id="new">new</h3>
75
+
76
+ <p>RVG::Tspan.new(<span class="arg">text</span>=nil,
77
+ <span class="arg">x</span>=0, <span class="arg">y</span>=0) [
78
+ <span class="arg">{ |tspan| ...}</span> ] -&gt; aTspan</p>
79
+ </div>
80
+
81
+ <div class="desc">
82
+ <h4>Description</h4>
83
+
84
+ <p>This method may be invoked indirectly via the <a href=
85
+ "rvgtext.html#tspan">tspan</a> method in
86
+ <code>RVG::Text</code>.</p>
87
+
88
+ <p>Tspan objects are containers, so this method yields to a
89
+ block if one is present. The only objects that a tspan can
90
+ contain are other tspans. Styles defined on a tspan propogate
91
+ to any tspans contained within it.</p>
92
+
93
+ <h4>Arguments</h4>
94
+
95
+ <p>All arguments are optional.</p>
96
+
97
+ <dl>
98
+ <dt>text</dt>
99
+
100
+ <dd>A string. If present, this string is drawn at the current
101
+ text position. By default the string is positioned with the
102
+ lower-left corner of the first glyph at the current text
103
+ position. Use the <a href="#text_anchor">:text_anchor</a>
104
+ style to override this behavior. After the string is
105
+ rendered, the current text position is moved to the end of
106
+ the string.</dd>
107
+
108
+ <dt>x, y</dt>
109
+
110
+ <dd>Specify a new current text position within the current
111
+ user coordinate system.</dd>
112
+ </dl>
113
+
114
+ <h4>Examples</h4>
115
+
116
+ <p><a href="javascript:popup('tspan01.rb.html')"><img src=
117
+ "ex/tspan01.gif" title="Click to see the example script" alt=
118
+ "tspan example" /></a></p>
119
+ </div>
120
+
121
+ <h2 class="methods">instance methods</h2>
122
+
123
+ <div class='sig'>
124
+ <h3 id='d'>d</h3>
125
+
126
+ <p><span class="arg">tspan</span>.d(<span class=
127
+ "arg">dx</span>[, <span class="arg">dy</span>=0]) [
128
+ <span class="arg">{ |self| ...}</span> ] -&gt; <span class=
129
+ "arg">self</span></p>
130
+ </div>
131
+
132
+ <div class="desc">
133
+ <h4>Description</h4>
134
+
135
+ <p>The <span class="arg">dx</span> and <span class=
136
+ "arg">dy</span> arguments are added to the the current text
137
+ position to form a new current text position. Yields to a block
138
+ if one is present.</p>
139
+
140
+ <h4>Arguments</h4>
141
+
142
+ <dl>
143
+ <dt>dx, dy</dt>
144
+
145
+ <dd>The distance, in the user coordinate system, to be added
146
+ to the current text position.</dd>
147
+ </dl>
148
+
149
+ <h4>Example</h4>
150
+
151
+ <p><a href="javascript:popup('tspan02.rb.html')"><img src=
152
+ "ex/tspan02.gif" title="Click to see the example script" alt=
153
+ "tspan example 2" /></a></p>
154
+
155
+ <h4>Returns</h4>
156
+
157
+ <p>self</p>
158
+ </div>
159
+
160
+ <div class='sig'>
161
+ <h3 id='rotate'>rotate</h3>
162
+
163
+ <p><span class="arg">tspan</span>.rotate(<span class=
164
+ "arg">degrees</span>) [ <span class="arg">{ |self| ...}</span>
165
+ ] -&gt; <span class="arg">self</span></p>
166
+ </div>
167
+
168
+ <div class="desc">
169
+ <h4>Description</h4>
170
+
171
+ <p>Rotates the text about the current text position by the
172
+ specified number of <span class="arg">degrees</span>. Yields to
173
+ a block if one is present.</p>
174
+
175
+ <h4>Arguments</h4>
176
+
177
+ <dl>
178
+ <dt>degrees</dt>
179
+
180
+ <dd>The amount of rotation</dd>
181
+ </dl>
182
+
183
+ <h4>Example</h4>
184
+
185
+ <p><a href="javascript:popup('tspan03.rb.html')"><img src=
186
+ "ex/tspan03.gif" title="Click to see the example script" alt=
187
+ "tspan example 3" /></a></p>
188
+
189
+ <h4>Returns</h4>
190
+
191
+ <p>self</p>
192
+ </div>
193
+
194
+ <div class='sig'>
195
+ <h3 id='tspan'>tspan</h3>
196
+
197
+ <p><span class="arg">tspan</span>.tspan(<span class=
198
+ "arg">string</span>=0, <span class="arg">x</span>=nil,
199
+ <span class="arg">y</span>=0) [ <span class="arg">{ |tspan|
200
+ ...}</span> ] -&gt; aTspan</p>
201
+ </div>
202
+
203
+ <div class="desc">
204
+ <h4>Description</h4>
205
+
206
+ <p>Calls <a href="#new">RVG::Tspan.new</a> to construct a tspan
207
+ and adds it to the tspan. Yields to a block if one is present,
208
+ passing the new tspan as an argument. Styles defined on the
209
+ container tspan propogate to the contained tspan.</p>
210
+
211
+ <h4>Arguments</h4>
212
+
213
+ <dl>
214
+ <dt>string</dt>
215
+
216
+ <dd>A text string.</dd>
217
+
218
+ <dt>x, y</dt>
219
+
220
+ <dd>A new initial text position</dd>
221
+ </dl>
222
+
223
+ <h4>Returns</h4>
224
+
225
+ <p>The new tspan, so other <code>RVG::Tspan</code> methods can
226
+ be chained to it.</p>
227
+ </div>
228
+
229
+ <p class="spacer">&nbsp;</p>
230
+
231
+ <div class="nav">
232
+ &laquo; <a href="rvgtext.html">Prev</a> | <a href=
233
+ "index.html">Contents</a> | <a href="rvguse.html">Next</a>
234
+ &raquo;
235
+ </div>
236
+ </body>
237
+ </html>
@@ -0,0 +1,512 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+
5
+ <html xmlns="http://www.w3.org/1999/xhtml">
6
+ <!-- $Id: rvgtut.html,v 1.5 2005/04/24 15:17:12 rmagick Exp $ -->
7
+
8
+ <head>
9
+ <meta name="generator" content=
10
+ "HTML Tidy for Linux/x86 (vers 1st March 2005), see www.w3.org" />
11
+
12
+ <title>RMagick: RVG Tutorial</title>
13
+ <meta name="GENERATOR" content="Quanta Plus" />
14
+ <link rel="stylesheet" type="text/css" href="css/doc.css" />
15
+ <style type="text/css">
16
+ /*<![CDATA[*/
17
+ img {
18
+ padding-bottom:1em;
19
+ padding-top:1em;
20
+ }
21
+ /*]]>*/
22
+ </style>
23
+ </head>
24
+
25
+ <body>
26
+ <h6 id="header">RMagick User's Guide and Reference</h6>
27
+
28
+ <div class="nav">
29
+ &laquo;&nbsp;<a href="constants.html">Prev</a> | <a href=
30
+ "index.html">Contents</a> | <a href=
31
+ "rvg.html">Next</a>&nbsp;&raquo;
32
+ </div>
33
+
34
+ <h1>Drawing with RVG</h1>
35
+
36
+ <div id="toc">
37
+ <h2>A tutorial</h2>
38
+ </div>
39
+
40
+ <div style="position:relative;">
41
+ <p><img src="ex/images/duck.gif" alt="duck|type" width="180"
42
+ height="180" /></p>
43
+
44
+ <div style="position:absolute; left: 200px;top:1em">
45
+ <h3>Introduction</h3>
46
+
47
+ <p>RVG is the newest addition to RMagick. RVG (Ruby Vector
48
+ Graphics) is a facade for RMagick's <a href=
49
+ "draw.html">Draw</a> class that supplies a drawing API based
50
+ on the <a href="http://www.w3.org/Graphics/SVG/">Scalable
51
+ Vector Graphics</a> W3C recommendation.</p>
52
+
53
+ <p>RVG is a <em>scalable</em> <em>vector</em> drawing
54
+ library. <em>Scalable</em> means that drawings are not fixed
55
+ to a single size in pixels. The same drawing can be rendered
56
+ for a screen display or for printing. <em>Vector</em> images
57
+ are drawn using geometric objects like lines and circles.
58
+ Unlike raster images, vector images don't get "pixelated"
59
+ when you make them bigger.</p>As an introduction to the RVG
60
+ library, let's see how to draw this little duck on the left.
61
+ Here is the complete program.
62
+ </div>
63
+ </div>
64
+ <pre class="example">
65
+ 1 require 'rvg/rvg'
66
+ 2 include Magick
67
+ 3
68
+ 4 RVG::dpi = 72
69
+ 5
70
+ 6 rvg = RVG.new(2.5.in, 2.5.in).viewbox(0,0,250,250) do |canvas|
71
+ 7 canvas.background_fill = 'white'
72
+ 8
73
+ 9 canvas.g.translate(100, 150).rotate(-30).styles(:fill=&gt;'yellow',
74
+ 10 :stroke=&gt;'black', :stroke_width=&gt;2) do |body|
75
+ 11 body.ellipse(50, 30)
76
+ 12 body.rect(45, 20, -20, -10).skewX(-35)
77
+ 13 end
78
+ 14
79
+ 15 canvas.g.translate(130, 83).styles(:stroke=&gt;'black', :stroke_width=&gt;2) do |head|
80
+ 16 head.circle(30).styles(:fill=&gt;'yellow')
81
+ 17 head.circle(5, 10, -5).styles(:fill=&gt;'black')
82
+ 18 head.polygon(30,0, 70,5, 30,10, 62,25, 23,20).styles(:fill=&gt;'orange')
83
+ 19 end
84
+ 20
85
+ 21 foot = RVG::Group.new do |_foot|
86
+ 22 _foot.path('M0,0 v30 l30,10 l5,-10, l-5,-10 l-30,10z').
87
+ 23 styles(:stroke_width=&gt;2, :fill=&gt;'orange', :stroke=&gt;'black')
88
+ 24 end
89
+ 25 canvas.use(foot).translate(75, 188).rotate(15)
90
+ 26 canvas.use(foot).translate(100, 185).rotate(-15)
91
+ 27
92
+ 28 canvas.text(125, 30) do |title|
93
+ 29 title.tspan("duck|").styles(:text_anchor=&gt;'end', :font_size=&gt;20,
94
+ 30 :font_family=&gt;'Helvetica', :fill=&gt;'black')
95
+ 31 title.tspan("type").styles(:font_size=&gt;22,
96
+ 32 :font_family=&gt;'Times', :font_style=&gt;'italic', :fill=&gt;'red')
97
+ 33 end
98
+ 34 canvas.rect(249,249).styles(:stroke=&gt;'blue', :fill=&gt;'none')
99
+ 35 end
100
+ 36
101
+ 37 rvg.draw.write('duck.gif')
102
+ </pre>
103
+
104
+ <h2>Summary</h2>
105
+
106
+ <p>All drawings follow the same 3 steps:</p>
107
+
108
+ <ol>
109
+ <li>Create an RVG object. Specify the width and height of the
110
+ final image. The <code>RVG.new</code> method yields to a
111
+ block.</li>
112
+
113
+ <li>Within the block, call methods on the RVG object to specify
114
+ a background, add shapes, text, or raster images, or add groups
115
+ of shapes, text, or raster images.</li>
116
+
117
+ <li>Call the <code>draw</code> method to draw the shapes, text,
118
+ or raster images onto the background.</li>
119
+ </ol>
120
+
121
+ <p>I'll step through the example line-by-line.</p>
122
+
123
+ <h2>Lines 1-3</h2>
124
+ <pre class="example">
125
+ 1 require 'rvg/rvg'
126
+ 2 include Magick
127
+ </pre>
128
+
129
+ <p>These are just the usual Ruby code to load the RVG extension.
130
+ To save some typing, I've included the Magick module into
131
+ Object's namespace.</p>
132
+
133
+ <h2>Lines 4-6</h2>
134
+ <pre class="example">
135
+ 4 RVG::dpi = 72
136
+ 5
137
+ 6 rvg = RVG.new(2.5.in, 2.5.in).viewbox(0,0,250,250) do |canvas|
138
+ </pre>
139
+
140
+ <p><code>RVG::dpi</code> enables the use of <em>unit methods</em>
141
+ in RVG. When you set <code>RVG::dpi</code> to a non-nil value,
142
+ RVG adds a number of conversion methods to the Fixnum and Float
143
+ classes . These methods allow you to specify measurements in
144
+ units such as inches, millimeters, and centimeters. <em>DPI</em>
145
+ stands for "dots per inch," the image resolution. Here I set
146
+ <code>RVG::dpi</code> to 72, a common value for displays.</p>
147
+
148
+ <p>The <code>RVG.new</code> method accepts 2 parameters. These
149
+ parameters specify the width and height of the final image in
150
+ pixels. Since I've defined <code>RVG::dpi</code>, I can specify
151
+ these values in inches using the <code>in</code> conversion
152
+ method. At 72dpi, the final image will be 2.5*72=180 pixels on a
153
+ side.</p>
154
+
155
+ <p>By default, RVG uses pixels as its unit of measurement, but
156
+ since I'm drawing a scalable picture I don't want to confine
157
+ myself to pixels. The <code>viewbox</code> method defines a
158
+ coordinate system with a logical unit. <code>Viewbox</code> takes
159
+ 4 parameters, <code>min_x</code>, <code>min_y</code>,
160
+ <code>width</code>, and <code>height</code>. On line 6 I define
161
+ my coordinate system to have its origin at (0,0) and a width and
162
+ height of 250 units. By using my own coordinate system, I can
163
+ later change the size of the image to 5 inches square or 1 inch
164
+ square just by changing the arguments to <code>new</code>.</p>
165
+
166
+ <div style="position:relative">
167
+ <p><img src="ex/images/duck0.gif" alt=
168
+ "default coordinate system" width="180" height="180" /></p>
169
+
170
+ <div style="position:absolute; left:200px;top:0;">
171
+ <p><strong>The default coordinate system</strong></p>
172
+
173
+ <p>By default, the RVG coordinate system has its origin in
174
+ the upper-left corner. The x-axis proceeds to the right. The
175
+ y-axis proceeds downwards. The image on the left shows the
176
+ axes of this coordinate system. I've added a light-blue
177
+ "graph-paper" background to the example images to help
178
+ associate the coordinate arguments to the actual locations in
179
+ the image. Just remember that the axes and graph-paper
180
+ background are not actually part of the image I'm
181
+ producing.</p>
182
+ </div>
183
+ </div>
184
+
185
+ <p>The RVG class is one of the <em>container</em> classes defined
186
+ by RVG. Container objects can contain graphic objects such as
187
+ circles and lines, text, raster images, and other container
188
+ objects. The outermost container is always an RVG object. I will
189
+ add all the graphic objects that form the duck to this
190
+ container.</p>
191
+
192
+ <p>Container constructors normally yield to a block. However,
193
+ here I've chained <code>viewbox</code> to <code>new</code>, so
194
+ <code>viewbox</code> takes responsibility for yielding and passes
195
+ the new instance of RVG to the <code>canvas</code> argument.</p>
196
+
197
+ <h2>Line 7</h2>
198
+ <pre class="example">
199
+ 7 canvas.background_fill = 'white'
200
+ </pre>
201
+
202
+ <p>By default, RVG graphics are drawn on a transparent
203
+ background. This is convenient when you want to display your
204
+ image over another image. You can override the default background
205
+ color by assigning a color to the <code>background_fill=</code>
206
+ attribute. Here I set the background color to "white."</p>
207
+
208
+ <h2>Lines 9-13</h2>
209
+ <pre class="example">
210
+ 9 canvas.g.translate(100, 150).rotate(-30).styles(:fill=&gt;'yellow',
211
+ 10 :stroke=&gt;'black', :stroke_width=&gt;2) do |body|
212
+ 11 body.ellipse(50, 30)
213
+ 12 body.rect(45, 20, -20, -10).skewX(-35)
214
+ 13 end
215
+ </pre>
216
+
217
+ <p>There's a lot going on in these few lines - seven method calls
218
+ - so let's take it one method at a time.</p>
219
+
220
+ <h3>Groups</h3>
221
+
222
+ <p><code>Group</code> is the second container class in RVG. The
223
+ purpose of a group is to associate a set of coordinate system
224
+ transformations and a set of styles with the graphic objects
225
+ within the group. To create a Group object within another
226
+ container, call the <code>g</code> method on the container. The
227
+ <code>g</code> method yields if a block is present. In this
228
+ example, there is no block associated with <code>g</code>, so
229
+ <code>g</code> returns the new group. The <code>g</code> method
230
+ adds the group to the content of the container, so when the
231
+ container is drawn the graphic objects in the group will be drawn
232
+ as well. The three methods chained to <code>g</code> -
233
+ <code>translate</code>, <code>rotate</code>, and
234
+ <code>styles</code> - modify the group by adding <em>coordinate
235
+ system transforms</em> and by modifying the default
236
+ <em>styles</em>.</p>
237
+
238
+ <p>(Okay, there <em>is</em> a block, but there are 3 method calls
239
+ between <code>g</code> and the block. I'll explain more
240
+ later.)</p>
241
+
242
+ <h3>Transforms</h3>
243
+
244
+ <p>I'm going to use this group to contain the ellipse that forms
245
+ the duck's body and the rectangle that forms the wing. I could
246
+ just specify x- and y-coordinates to position these shapes
247
+ relative to the origin, but it's easier to move the origin to
248
+ where I want to draw the shapes. This is the purpose of the
249
+ <code>translate</code> method. This method moves the origin to
250
+ the (x,y) position specified by its arguments. I call
251
+ <code>translate</code> on the group object, and since the content
252
+ of the group gets the coordinate system transformations specified
253
+ for the group, the ellipse and the rectangle will be drawn on a
254
+ coordinate system with the origin at (100, 150) relative to the
255
+ old coordinate system.</p>
256
+
257
+ <p>Also, I want the duck's body to slant upward, so I use the
258
+ <code>rotate</code> method to rotate the axes. The argument to
259
+ <code>rotate</code> is the number of degrees of rotation. A
260
+ negative number indicates counter-clockwise rotation.</p>
261
+
262
+ <p>After translating and rotating the coordinate system, the axes
263
+ look like this:</p>
264
+
265
+ <div style="position:relative">
266
+ <p><img src="ex/images/duck1.gif" width="180" height="180" alt=
267
+ "duck body" /></p>
268
+
269
+ <div style="position:absolute; left:200px;top:0">
270
+ <p><strong>The other transform methods</strong></p>
271
+
272
+ <p>There are six transform methods. In addition to
273
+ <code>translate</code> and <code>rotate</code>, there's
274
+ <code>scale</code>, <code>skewX</code>, <code>skewY</code>,
275
+ and <code>matrix</code>. When groups are nested, any
276
+ transforms defined on the inner group(s) are added to the
277
+ outer transforms.</p>
278
+ </div>
279
+ </div>
280
+
281
+ <h3>Styles</h3>
282
+
283
+ <p>Recall that the <code>styles</code> method modifies the
284
+ default group styles. The <code>styles</code> method takes a hash
285
+ as an argument. The hash keys are style names, and the hash
286
+ values are, well, style values. In this example there are three
287
+ style names. The :fill style sets the fill color to 'yellow'. The
288
+ :stroke style sets the outline color to 'black'. The
289
+ :stroke_width style sets the width of the outline to 2. The
290
+ <code>styles</code> method is a real workhorse. It's defined in
291
+ almost every class in RVG and there are many other style names in
292
+ addition to these three..</p>
293
+
294
+ <h3>Basic shapes</h3>
295
+
296
+ <p>The group contains two basic shapes, an ellipse and a
297
+ rectangle. I add the ellipse to the group with the
298
+ <code>ellipse</code> method. <code>Ellipse</code> has four
299
+ parameters. The first two, the radius on the x-axis and the
300
+ radius on the y-axis, are required. The last two are the (x,y)
301
+ coordinate of the center. When these are omitted, as here, they
302
+ default to (0,0). I add the rectange with the <code>rect</code>
303
+ method, which also has four parameters. The first two are the
304
+ width and height of the rectangle. The last two are the (x,y)
305
+ coordinate of the upper-left corner. Both of these methods return
306
+ <code>self</code>, so you can chain other methods to them.</p>
307
+
308
+ <p>Here's what the group looks like when rendered. The ellipse is
309
+ centered on the origin. The upper-left corner of the rectangle is
310
+ slightly up and to the left of the origin.</p>
311
+
312
+ <p><img src="ex/images/duck3.gif" alt="default coordinate system"
313
+ width="180" height="180" /></p>
314
+
315
+ <h3>SkewX</h3>
316
+
317
+ <p>Everybody knows that a wing doesn't look like a rectangle! A
318
+ wing looks like a slanted parallelogram. (Well, it does in this
319
+ example!) Fortunately, I can use the transform methods on shapes
320
+ as well as containers. The <code>skewX</code> method makes it
321
+ easy for us to give the rectangle a slant. The <code>skewX</code>
322
+ method is another transform. It takes a single argument, the
323
+ number of degrees to skew the x-axis. Since all the shape
324
+ constructors, including <code>rect</code>, return
325
+ <code>self</code>, I can chain <code>skewX</code> directly to
326
+ <code>rect</code> and limit the effect of the transform to just
327
+ the rectangle. The result looks like this. (I've drawn in the
328
+ axes for the wing coordinate system.)</p>
329
+
330
+ <p><img src="ex/images/duck4.gif" width="180" height="180" alt=
331
+ "duck wing" /></p>
332
+
333
+ <p>That's it for the body. Let's tie up one loose end before I
334
+ move on. I said earlier that container constructors (such as
335
+ <code>g</code>) yield to a block if present. In this case,
336
+ though, there are three intervening method calls -
337
+ <code>translate</code>, <code>rotate</code>, and
338
+ <code>styles</code> - between <code>g</code> and the block. The
339
+ <code>style</code> method and the transform methods will all
340
+ yield when there is an associated block, so I can easily chain
341
+ them to a container constructor and still use a block argument to
342
+ define the graphic objects in the group. Method chaining is a
343
+ common RVG idiom. You'll see it a lot in the examples.</p>
344
+
345
+ <p>The next group draws the head.</p>
346
+
347
+ <h2>Lines 15-19</h2>
348
+ <pre class="example">
349
+ 15 canvas.g.translate(130, 83).styles(:stroke=&gt;'black', :stroke_width=&gt;2) do |head|
350
+ 16 head.circle(30).styles(:fill=&gt;'yellow')
351
+ 17 head.circle(5, 10, -5).styles(:fill=&gt;'black')
352
+ 18 head.polygon(30,0, 70,5, 30,10, 62,25, 23,20).styles(:fill=&gt;'orange')
353
+ 19 end
354
+ </pre>
355
+
356
+ <p>This section is very similar to the previous one. I'm defining
357
+ a group to contain the graphic objects that draw the duck's head,
358
+ eye, and beak. First I use the translate method to move the
359
+ origin to (130,83):</p>
360
+
361
+ <p><img src="ex/images/duck6.gif" width="180" height="180" alt=
362
+ "duck head" /></p>
363
+
364
+ <p>Notice that I can use <code>styles</code> on shapes as well as
365
+ containers. In this group each shape has its own fill color. (The
366
+ styles defined on the group propogate to the contained shapes,
367
+ unless you override them.) The yellow circle forms the head. The
368
+ <code>circle</code> method takes 3 parameters. The first
369
+ parameter is the radius of the circle. The other two parameters
370
+ are the (x,y) coordinate of the center. If omitted, as here, they
371
+ default to (0,0). I use a small black circle for the eye.</p>
372
+
373
+ <p>Last, I use the <code>polygon</code> method to draw the beak.
374
+ This method draws a polygon from a series of (x,y) coordinates.
375
+ If the last coordinate is not the same as the first,
376
+ <code>polygon</code> implicitly adds it to close the polygon.
377
+ Again, I use <code>styles</code> to set the fill color to
378
+ orange.</p>
379
+
380
+ <p><img src="ex/images/duck8.gif" width="180" height="180" alt=
381
+ "duck head final" /></p>
382
+
383
+ <h2>Lines 21-24</h2>
384
+ <pre class="example">
385
+ 21 foot = RVG::Group.new do |_foot|
386
+ 22 _foot.path('M0,0 v30 l30,10 l5,-10, l-5,-10 l-30,10z').
387
+ 23 styles(:stroke_width=&gt;2, :fill=&gt;'orange', :stroke=&gt;'black')
388
+ 24 end
389
+ </pre>
390
+
391
+ <p>Here I create a group by directly calling <code>new</code>
392
+ instead of calling the <code>g</code> method on a container. The
393
+ graphic objects within the group are not (yet) contained within
394
+ the canvas and so will not be drawn when the canvas is drawn. You
395
+ might think of the foot as not being attached to anything, like
396
+ this:</p>
397
+
398
+ <p><img src="ex/images/duck9.gif" width="180" height="180" alt=
399
+ "duck foot" /></p>
400
+
401
+ <h2>Lines 25-26</h2>
402
+ <pre class="example">
403
+ 25 canvas.use(foot).translate(75, 188).rotate(15)
404
+ 26 canvas.use(foot).translate(100, 185).rotate(-15)
405
+ </pre>
406
+
407
+ <p>To add the group to the canvas I use the <code>use</code>
408
+ method. The use method can accept any container or graphic object
409
+ as an argument. Optionally you can specify an (x,y) coordinate
410
+ that specifies where to position the objects. In this example,
411
+ however, I let those arguments default to (0,0) and use
412
+ <code>translate</code> to position the feet. Here's how the left
413
+ foot attaches to the duck:</p>
414
+
415
+ <p><img src="ex/images/duck10.gif" width="180" height="180" alt=
416
+ "duck foot 2" /></p>
417
+
418
+ <p>Of course, the duck is walking, so I have to give the foot a
419
+ little slant with <code>rotate</code>:</p>
420
+
421
+ <p><img src="ex/images/duck11.gif" width="180" height="180" alt=
422
+ "duck foot 3" /></p>
423
+
424
+ <p>Attaching the right foot is easy. Call <code>use</code> again
425
+ but give different arguments to <code>translate</code> and
426
+ <code>rotate</code>:</p>
427
+
428
+ <p><img src="ex/images/duck12.gif" width="180" height="180" alt=
429
+ "final duck foot" /></p>
430
+
431
+ <h2>Lines 28-33</h2>
432
+ <pre class="example">
433
+ 28 canvas.text(125, 30) do |title|
434
+ 29 title.tspan("duck|").styles(:text_anchor=&gt;'end', :font_size=&gt;20,
435
+ 30 :font_family=&gt;'Helvetica', :fill=&gt;'black')
436
+ 31 title.tspan("type").styles(:font_size=&gt;22,
437
+ 32 :font_family=&gt;'Times', :font_style=&gt;'italic', :fill=&gt;'red')
438
+ 33 end
439
+ </pre>
440
+
441
+ <p>All I need now is a title for the picture. Text in RVG is a
442
+ job for the <code>text</code> method. Like the shape methods,
443
+ <code>text</code> can be used with any container object.
444
+ <code>Text</code> itself is a container, except that it can only
445
+ contain text-related objects. The <code>text</code> method takes
446
+ 2 or 3 arguments, an (x,y) pair and optionally a string. The
447
+ (x,y) pair define a <em>current text position</em> at which
448
+ rendering starts. If there is a string argument, it will be
449
+ rendered starting at the current text position. Rendering text
450
+ changes the current text position to the end of the text.</p>
451
+
452
+ <p>In the example, text is used as a container. Text objects can
453
+ contain Tspan objects. Each tspan can specify its own styles. By
454
+ default each tspan is rendered starting at the current text
455
+ position.</p>
456
+
457
+ <p>As usual, I can change the appearance of the text with
458
+ <code>styles</code>. Here I choose a font, a font style (the
459
+ default is "normal"), its size in points, and the color.</p>
460
+
461
+ <p><img src="ex/images/duck14.gif" width="180" height="180" alt=
462
+ "duck title" /></p>
463
+
464
+ <h2>Line 34</h2>
465
+ <pre class="example">
466
+ 34 canvas.rect(249,249).styles(:stroke=&gt;'blue', :fill=&gt;'none')
467
+ </pre>
468
+
469
+ <p>I'm almost done. All I need to do it add a blue border. (I'm
470
+ going to remove the graph paper background because we don't need
471
+ it any more.)</p>
472
+
473
+ <p><img src="ex/images/duck15.gif" width="180" height="180" alt=
474
+ "duck with border" /></p>
475
+
476
+ <h2>Line 37</h2>
477
+ <pre class="example">
478
+ 37 rvg.draw.write('duck.gif')
479
+ </pre>
480
+
481
+ <p>The <code>draw</code> method call doesn't occupy a lot of
482
+ space - just 4 letters - but does a lot of work. The
483
+ <code>draw</code> method goes through all the graphics objects
484
+ that I've added to the outermost RVG container and draws them on
485
+ the background. When the drawing is complete, <code>draw</code>
486
+ returns the drawing in the form of an RMagick Image object. You
487
+ can use any Image class methods on the drawing. Here I simply
488
+ write the image to a GIF file.</p>
489
+
490
+ <h2>Scalable graphics</h2>
491
+
492
+ <p>Are RVG images really scalable? Let's try. Change the RVG.new
493
+ call to make an image that's 4 times as big. That's 5 inches on a
494
+ side:</p>
495
+ <pre class="example">
496
+ 6 rvg = RVG.new(5.in, 5.in).viewbox(0,0,250,250) do |canvas|
497
+ </pre>
498
+
499
+ <p>Change nothing else. Run the program again and see what you
500
+ get.</p>
501
+
502
+ <p><img src="ex/images/big-duck.gif" width="360" height="360"
503
+ alt="big duck" /></p>
504
+
505
+ <p class="spacer">&nbsp;</p>
506
+
507
+ <div class="nav">
508
+ &laquo; <a href="constants.html">Prev</a> | <a href=
509
+ "index.html">Contents</a> | <a href="rvg.html">Next</a> &raquo;
510
+ </div>
511
+ </body>
512
+ </html>